   Mesh : some designs headaches :(
  Hi everyone,I'm currently thinking about an easy way for handling meshes (with OpenGL), but it gives me some headaches, and the solutions I find don't make me happy, so here I am ^^.From now on, I have a Mesh class that encapsulates a vertex array (which is, in my design, all the vertices data - position, normal, uv... - stored in memory) and a vertex buffer, which creates a VBO and initializes it with the data from the vertex array). A Mesh also contains one or several SubMeshes objects.Each SubMesh has an index array, which is quite similar to vertex array but stores only indices in the memory, as well as an index buffer, which is like vertex buffer but for indices. That way, the data that is in the graphics card memory and main memory is well separated. Each SubMesh also has a material object.The problem with that is that if I have several meshes that are shared, I can't use it easily (for instance, with instanced rendering). So what I have basically is : create a mesh, and then create an instance of the mesh. The instance of the mesh contains a reference to the mesh, so the data is not duplicated. The only thing I add to this instance of the mesh is some math data (for instance matrix transformation, because each instance of the mesh has different matrices) as well as different materials.From now on, do you think it is correct ? Or there is a better way to do that ?But the biggest problem is... that I have to use some raytracing. I mean, all the meshes are inserted into a BVH, and then I shoot rays each frame. So, I have to have all the vertices in world space (I think it's quite easy) so that ray shooting is easy, and each time a mesh moves, I update its vertices (I think that with optimized SSE matrix-vector multiplication it can be quite fast) in the main memory, while I keep object space vertices in the VBO that I update in the vertex shader.But I have several problems with that, and I really don't know a good architecture. I think, at the beginning, of something really simple, that is, duplicate everything. Different VBOs, different vertex array... But I don't think it's quite efficient.Second, I thought about keeping this "mesh and instanced", that is to say :- Create a mesh that loads a mesh from a file. Keep vertex data in object space in memory, send everything to the graphics card.- Then each instance of the mesh keep the VBO as well as IBO (because it will reamin the same), but duplicate the vertex data, transform everything into world-space (and then, only update when it moves).- Insert the instance in the BVH. Use also the instance for rendering.But it doesn't look clean anymore :/... Do you have better ideas ? ^^Thank you very much !   
  I'm assuming you're talking about meshes that can only move and rotate as a whole, i.e., meshes that model rigid bodies.  The standard approach is essentially what you described:  separate constructs for the "model" (the vertex data in object space) and instances of it (a reference to the model with a transform and other per-instance data).For raytracing you just need the bounding volumes in world space, not all the vertex data.  If you get a hit against the bounding volume of an instance of a mesh, you can just transform the ray into the object space of the mesh and do the intersection testing in object space.   ;  yes thats what im doing, try to store as much info in the meshtemplate as possible to cut down on memory, indices,texture coords etc;stuff like bounding boxes (perhaps verts depending onb how youre doing it) etc will be in the meshclass MeshTemplate {};class Mesh{MeshTemplate *meshtemplate_ptr; // if NUKK then not using a meshtemplate};   ;  Thank you guys =).I'm talking about static meshes for the moment, but I don't exclude them to move (I don't need animated meshes for the moment, but I will need them soon). So how handle this ?For raytracing you just need the bounding volumes in world space, not all the vertex data. If you get a hit against the bounding volume of an instance of a mesh, you can just transform the ray into the object space of the mesh and do the intersection testing in object space.Oh yeah, didn't think of that. But I have some questions. I use a QBVH (some kind of BVH, but with 4 child nodes, check the paper on the Internet) and from now I add a triangle soup into the BVH (all the triangles are in world space), therefore it's quite easy to do the ray shooting. So, if I understand it well, it would be something like that :- Load the mesh (object space)- Create an instance, compute the bounding box (in world space)- And... what else ?I will only add the bounding boxes into the three. So when my ray hit a AABB of an object, I convert the ray into object space (that doesn't make too many world-object convertions  ?). I can't test each triangle of the mesh. I really don't get it. Maybe do you mean some kind of 2-levels tree (the first level that would have each bounding boxes of each object and, in each of the bounding box, a smaller BVH that would contain each triangle in object space). Am I true ? It sounds really complicated :/... But I think it's the most efficient and cleanest method.And what about animated meshes ?