Mesh/Meshbuffer format in Irrlicht?
Mesh/Meshbuffer format in Irrlicht?
I need to generate a mesh according to some parameters from an algorithm (cave number, size and position). Looking at the source I see vertex and indices arrays, but no clue on what is what. Are they all VV mesh? How do I set edges and faces?
Re: Mesh/Meshbuffer format in Irrlicht?
Generally you create meshes out of triangles (other mesh-types are possible with some drivers but rather uncommon so I'm going to ignore those). Each corner of a triangle is called a vertex. Which means you need at least as many vertices as you have corners in your mesh. The indices then refer to that vertex array. So when using triangles you always need to create 3 indices for each triangle (each index telling the position of the corresponding vertex in the vertices array).
If you also need textures on your model there are a few more things you have to care about. If you have more than one texture in your mesh then you need different materials. For each material you will need one meshbuffer (each meshbuffer can be thought of as a vertex array, an index array and a material).
Also with textures you have to care about the uv-coordinates at each vertex. This also usually means you will have a few places where you need more than one vertex at corners which are shared between different triangles. Because they might have the same position, but not the same uv-coordinates (take a look at the way a cube is created in CGeometryCreator::createCubeMesh for example to see how it has more than just 8 vertices to allow top and bottom have different uv-coordinates for textures).
In theory you can also just make 3 vertices for each triangle and then have 3 indices point to those 3 vertices. That way you wouldn't share any vertex between different triangles. But it will cost more memory and be somewhat slower. Also calculating normals (which you need for good light) might be a little more tricky then (as usually you use the average direction of connected triangles - you have to find those then yourself).
If you also need textures on your model there are a few more things you have to care about. If you have more than one texture in your mesh then you need different materials. For each material you will need one meshbuffer (each meshbuffer can be thought of as a vertex array, an index array and a material).
Also with textures you have to care about the uv-coordinates at each vertex. This also usually means you will have a few places where you need more than one vertex at corners which are shared between different triangles. Because they might have the same position, but not the same uv-coordinates (take a look at the way a cube is created in CGeometryCreator::createCubeMesh for example to see how it has more than just 8 vertices to allow top and bottom have different uv-coordinates for textures).
In theory you can also just make 3 vertices for each triangle and then have 3 indices point to those 3 vertices. That way you wouldn't share any vertex between different triangles. But it will cost more memory and be somewhat slower. Also calculating normals (which you need for good light) might be a little more tricky then (as usually you use the average direction of connected triangles - you have to find those then yourself).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Mesh/Meshbuffer format in Irrlicht?
You mean the index arrays are faces (triangles), and Irrlicht uses face-vertex mesh format? good.CuteAlien wrote:Generally you create meshes out of triangles (other mesh-types are possible with some drivers but rather uncommon so I'm going to ignore those). Each corner of a triangle is called a vertex. Which means you need at least as many vertices as you have corners in your mesh. The indices then refer to that vertex array. So when using triangles you always need to create 3 indices for each triangle
Next question, does Irrlicht use the vertex order of a triangle for choosing normal direction like openGL does (clockwise/counterclockwise)?
OK... This calls for another question: how meshbuffers are sewn together? Do they share boundary vertexes?If you also need textures on your model there are a few more things you have to care about. If you have more than one texture in your mesh then you need different materials. For each material you will need one meshbuffer (each meshbuffer can be thought of as a vertex array, an index array and a material).
I'm going to show scientific/engineering data and probably will need to animate objects and surfaces in a complex way, either generating many meshes on the fly or heavily editing the same mesh many times a second. Does Irrlicht store meshes in GPU memory? What's the best way to implement this kind of feature?
Thanks in advance
Re: Mesh/Meshbuffer format in Irrlicht?
Yeah, index arrays contains the indices to the vertices needed for faces. And yes the normal direction for defining the front/back of a face is set by the vertex order (clockwise front-facing).
I'm not certain about meshbuffer borders. I assume they are not sewn together as they don't share vertices.
For moving meshes to the gpu you can set IMeshBuffer::setHardwareMappingHint to EHM_STATIC. Then they are only updated when the meshbuffer is marked as dirty. For animated meshes we currently only support CPU animation.
I'm not certain about meshbuffer borders. I assume they are not sewn together as they don't share vertices.
For moving meshes to the gpu you can set IMeshBuffer::setHardwareMappingHint to EHM_STATIC. Then they are only updated when the meshbuffer is marked as dirty. For animated meshes we currently only support CPU animation.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm