Vertex Array and Indexes
Vertex Array and Indexes
Hi,
I need to access the verices and indexes list of a mesh. Please, could you explain me how to do that?
Thank you!
Bye-bye,
Andreasky
I need to access the verices and indexes list of a mesh. Please, could you explain me how to do that?
Thank you!
Bye-bye,
Andreasky
I would like to get vertices list and indexes list of a simple 3D model.
For example, I import a cube mesh based on triangles. Therefore we have 12 triangles (6 faces x 2 triangles each face).
How to get vertices and indexes number? In a cube there are 8 vertices and 36 indexes (3 indexes x 12 triangles), aren't there? Which functions should I call?
And then, how to build the index and vertex list?
Thank you!
For example, I import a cube mesh based on triangles. Therefore we have 12 triangles (6 faces x 2 triangles each face).
How to get vertices and indexes number? In a cube there are 8 vertices and 36 indexes (3 indexes x 12 triangles), aren't there? Which functions should I call?
And then, how to build the index and vertex list?
Thank you!
Just do what I did:
Bookmark http://irrlicht.sourceforge.net/docu/index.html and flip through there.
Bookmark http://irrlicht.sourceforge.net/docu/index.html and flip through there.
Is the somber dream of the Grim Reaper a shade Darker Than Black?
You should also look at http://irrlicht.sourceforge.net/docu/cl ... array.html
The MeshBuffer have to public atributes: Vertices and Indices; They are arrays; You could get the number of Verticies with something like: MeshBuffer.Vertices.size(); and you can add a new vertex with MeshBuffer.Vertices.push_back(...);
The MeshBuffer have to public atributes: Vertices and Indices; They are arrays; You could get the number of Verticies with something like: MeshBuffer.Vertices.size(); and you can add a new vertex with MeshBuffer.Vertices.push_back(...);
-
hybrid
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
direct access to Vertices and Indices is only possible if you have an SMesh or some other public implementation of the IMesh interface. Otherwise you have to go via the getVertexCount() and getIndexCount() methods, and use getVertices() and getIndices(). Both return raw pointers to the array data, which may be mapped into an array of course.
I tried to implement a simple example using getVertexCount() and getIndexCount() methods.
I imported a polygonal plane mesh based on triangles in Irrlicht. Here is the code:
====================================
IMesh* mesh = smgr->getMesh("../../media/plane.x");
IMeshSceneNode* node = smgr->addMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
u32 meshBufferCount=mesh->getMeshBufferCount();
//The maximum vales for getMeshBuffer() is meshBufferCount-1;
IMeshBuffer* meshBuffer=mesh->getMeshBuffer(meshBufferCount-1);
u32 vertexNumber=meshBuffer->getVertexCount();
u32 indexesNumber=meshBuffer->getIndexCount();
ofstream out("vertices.txt");
out<<"The number of vertices is: "<<vertexNumber<<endl<<
"The number of indexes is: "<<indexesNumber<<endl;
out.close();
====================================
When I open "vertices.txt", I got this output:
The number of vertices is: 6
The number of indexes is: 6
I cannot understand why there are 6 vertices instead of 4.
So, I opened "plane.x". Here is its code:
====================================
xof 0303txt 0032
Material lambert1 {
0.400000; 0.400000; 0.400000; 1.000000;;
0.000000;
0.000000; 0.000000; 0.000000;;
0.000000; 0.000000; 0.000000;;
}
Material blinn1 {
0.000000; 0.000000; 0.800000; 1.000000;;
0.000000;
0.250000; 0.250000; 0.250000;;
0.000000; 0.000000; 0.000000;;
}
Frame pPlane1 {
FrameTransformMatrix {
1.000000,0.000000,-0.000000,0.000000,0.000000,1.000000,-0.000000,0.000000,-0.000000,-0.000000,1.000000,0.000000,0.000000,0.000000,-0.000000,1.000000;;
}
Mesh pPlaneShape1 {
6;
-5.000000; -0.000000; -5.000000;,
5.000000; -0.000000; -5.000000;,
-5.000000; 0.000000; 5.000000;,
-5.000000; 0.000000; 5.000000;,
5.000000; -0.000000; -5.000000;,
5.000000; 0.000000; 5.000000;;
2;
3;2,1,0;,
3;5,4,3;;
MeshMaterialList {
1;
2;
0,
0;
{lambert1}
}
VertexDuplicationIndices {
6;
4;
0,
1,
2,
2,
1,
5;
}
}
}
====================================
It seems that there are 2 vertices drawn two times. However in Maya, the 3D software I use, there are only 4 vertices. I use "cvxporter" as ".x" exporter from Maya.
Is it likely to be a cvxporter related issue?
Thank you.
I imported a polygonal plane mesh based on triangles in Irrlicht. Here is the code:
====================================
IMesh* mesh = smgr->getMesh("../../media/plane.x");
IMeshSceneNode* node = smgr->addMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
u32 meshBufferCount=mesh->getMeshBufferCount();
//The maximum vales for getMeshBuffer() is meshBufferCount-1;
IMeshBuffer* meshBuffer=mesh->getMeshBuffer(meshBufferCount-1);
u32 vertexNumber=meshBuffer->getVertexCount();
u32 indexesNumber=meshBuffer->getIndexCount();
ofstream out("vertices.txt");
out<<"The number of vertices is: "<<vertexNumber<<endl<<
"The number of indexes is: "<<indexesNumber<<endl;
out.close();
====================================
When I open "vertices.txt", I got this output:
The number of vertices is: 6
The number of indexes is: 6
I cannot understand why there are 6 vertices instead of 4.
So, I opened "plane.x". Here is its code:
====================================
xof 0303txt 0032
Material lambert1 {
0.400000; 0.400000; 0.400000; 1.000000;;
0.000000;
0.000000; 0.000000; 0.000000;;
0.000000; 0.000000; 0.000000;;
}
Material blinn1 {
0.000000; 0.000000; 0.800000; 1.000000;;
0.000000;
0.250000; 0.250000; 0.250000;;
0.000000; 0.000000; 0.000000;;
}
Frame pPlane1 {
FrameTransformMatrix {
1.000000,0.000000,-0.000000,0.000000,0.000000,1.000000,-0.000000,0.000000,-0.000000,-0.000000,1.000000,0.000000,0.000000,0.000000,-0.000000,1.000000;;
}
Mesh pPlaneShape1 {
6;
-5.000000; -0.000000; -5.000000;,
5.000000; -0.000000; -5.000000;,
-5.000000; 0.000000; 5.000000;,
-5.000000; 0.000000; 5.000000;,
5.000000; -0.000000; -5.000000;,
5.000000; 0.000000; 5.000000;;
2;
3;2,1,0;,
3;5,4,3;;
MeshMaterialList {
1;
2;
0,
0;
{lambert1}
}
VertexDuplicationIndices {
6;
4;
0,
1,
2,
2,
1,
5;
}
}
}
====================================
It seems that there are 2 vertices drawn two times. However in Maya, the 3D software I use, there are only 4 vertices. I use "cvxporter" as ".x" exporter from Maya.
Is it likely to be a cvxporter related issue?
Thank you.
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
If it's just a plane, sometimes either the modeler or Irrlicht will split the polygons to have their own vertices, depending on certain conditions. So since there are 2 triangles and each one is given a unique vertex, that gives you 6. To combine them to only have 4 vertices there is a function in IMeshManipulator:
Code: Select all
mesh = smgr->getMeshManipulator()->createMeshWelded(mesh);-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
I tried to use "mesh = smgr->getMeshManipulator()->createMeshWelded(mesh);"
Here is the code:
=============================
IMesh* mesh = smgr->getMesh("../../media/cube.x");
IMeshSceneNode* node = smgr->addMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
mesh = smgr->getMeshManipulator()->createMeshWelded(mesh);
u32 meshBufferCount=mesh->getMeshBufferCount();
//The maximum vales for getMeshBuffer() is meshBufferCount-1
IMeshBuffer* meshBuffer=mesh->getMeshBuffer(meshBufferCount-1);
u32 vertexNumber=meshBuffer->getVertexCount();
u32 indexesNumber=meshBuffer->getIndexCount();
ofstream out("vertices.txt");
out<<"The number of mesh buffer is: "<<meshBufferCount<<endl<<
"The number of vertices is: "<<vertexNumber<<endl<<
"The number of indexes is: "<<indexesNumber<<endl;
out.close();
=============================
I tried to load a cube. However I found no difference:either using "createMeshWelded" or not I always get 24 vertices and 36 indexes.
Here is the code:
=============================
IMesh* mesh = smgr->getMesh("../../media/cube.x");
IMeshSceneNode* node = smgr->addMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
mesh = smgr->getMeshManipulator()->createMeshWelded(mesh);
u32 meshBufferCount=mesh->getMeshBufferCount();
//The maximum vales for getMeshBuffer() is meshBufferCount-1
IMeshBuffer* meshBuffer=mesh->getMeshBuffer(meshBufferCount-1);
u32 vertexNumber=meshBuffer->getVertexCount();
u32 indexesNumber=meshBuffer->getIndexCount();
ofstream out("vertices.txt");
out<<"The number of mesh buffer is: "<<meshBufferCount<<endl<<
"The number of vertices is: "<<vertexNumber<<endl<<
"The number of indexes is: "<<indexesNumber<<endl;
out.close();
=============================
I tried to load a cube. However I found no difference:either using "createMeshWelded" or not I always get 24 vertices and 36 indexes.
-
hybrid
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
The weld method has a pending bug, so it might not weld anything quite often. The thing is that e.g. the 3ds loader does split nodes unconditionally. So all vertices are duplicated for each face, resulting in 6*4 vertices and 6*6 indices. If you use a different model format, this could be more optimized.
I use Maya as 3D modelling tool and then export the mesh into ".x" format via cvxporter.
I was wondering whether duplicated vertices may cause any memory problem when you store them in a vertex array. Vertex arrays are used to store each vertex only one time, aren't they? So I cannot understand the benefit (in terms of memory) of saving multiple copies of some vertices in an array. In this way you can waste memory.
I was wondering whether duplicated vertices may cause any memory problem when you store them in a vertex array. Vertex arrays are used to store each vertex only one time, aren't they? So I cannot understand the benefit (in terms of memory) of saving multiple copies of some vertices in an array. In this way you can waste memory.
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm