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;

2 Answers 2

  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

  • \$\begingroup\$ You can have multiple materials per mesh, at least in Blender. By default, it supports up to 16 materials per mesh, but even that can be extended with some hacking. \$\endgroup\$
    – Dan
    Jun 19, 2016 at 17:53

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.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .