Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am wondering, how I should store my mesh into memory after loading it from whatever file. I have Questions floating in my head:

  1. Should a mesh could have sub meshes or does the 3d model just store a list of meshes all on the same level
  2. Is there one material assigned to one mesh 1:1?
  3. What do I have to consider, if I want to store skeletal animations?

Btw it's a OpenGL|ES2 iOS game using GLKit.

I came up with some basic struct types: (But I think they are way to simple and I need to add padding or change the vector3 to vector4.)

typedef union _N3DShortVector2 {
    struct { short x, y; };
    struct { short s, t; };
    short v[2];
} N3DShortVector2;

typedef union _N3DShortVector3 {
    struct { short x, y, z; };
    struct { short r, g, b; };
    struct { short s, t, p; };
    short v[3];
} N3DShortVector3;

typedef GLKVector3 N3DFloatVector3;

typedef struct _N3DMeshRecordSV3 {
    N3DShortVector3 v1, v2, v3;
} N3DMeshRecordSV3;

typedef struct _N3DMeshRecordSV3FN3ST2 {
    N3DShortVector3 v1, v2, v3;
    N3DFloatVector3 n1, n2, n3;
    N3DShortVector2 t1, t2, t3;
} N3DMeshRecordSV3FN3ST2;
share|improve this question
add comment

2 Answers

1 and 2: Sounds like your 3D model is what contains transformation of an object and the mesh data. If you want want hierarchical objects, your 3D models should have child models. Meshes themself don't need hierarchy, a flat list is enough. Each part of a model should allow own material, so each mesh should have a material assigned. However even in that case it's a good idea to allow meshes to share the same vertex data, i.e. vertex buffers inside a single 3D model. Index buffers are unique for each mesh.

You can also add one level of indirection, where the list of meshes can be shared between different 3D models. You could rename the meshes to mesh clusters and the list of meshes as the mesh itself. In that case the 3D models could share meshes.

share|improve this answer
add comment
  1. Ultimately, each mesh is a collection of OpenGL primitives (triangles, triangle strips, etc) that form a 3D model. You'll want a level to include a variety of meshes, so you can address them each separately.
  2. To my knowledge, each mesh can only have one material, although generally one would use texturing to get around this (I.e. set up a texture to color each part of the model as you like). A texture or material can be reused on multiple models.
  3. Sorry, I don't have experience with this.

To answer your original question, this depends slightly on what you are using the models for. If your models will be rigid, meaning you will not change each vertex individually, and you will render many frames with the same model, you will achieve the best performance not by storing the models in your class, but in vertex buffer objects (VBOs). This basically means that the models are stored in GPU memory instead of CPU memory, minimizing GPU to CPU transfers and greatly improving rendering performance. A good tutorial on OpenGL ES vertex buffering is available at http://www.learnopengles.com/android-lesson-seven-an-introduction-to-vertex-buffer-objects-vbos/ (This is for android, but the code will be similar).

Regardless of whether you decide to store your mesh on the CPU or GPU, your performance will be best if you interweave vertex, normal, and UV coordinates, use the smallest data primitives that provide the accuracy needed for your application, and align your data structure to the memory. http://developer.apple.com/library/ios/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.