This example can be useful if you write algorithms which modify the MESH scene graph. Here we want to create two faces and remove one of them.
Some important functions and classes:
These are the default nodes.
Then, 4 vertices are created by the X3DTK::MESH::Vertex
node:
They have no point, color, texture coordinate or normal information.
To create the faces, we need to create two index arrays filled with the vertex indexes:
MFInt32 index0, index1; index0.push_back(v0->getIndex()); index0.push_back(v1->getIndex()); index0.push_back(v2->getIndex()); index1.push_back(v1->getIndex()); index1.push_back(v3->getIndex()); index1.push_back(v2->getIndex());
Then, the two faces can be created by the X3DTK::MESH::Mesh
node:
To test the faces and edges, we iterate over them:
The ostream operator has been overloaded for the faces, edges and vertices.const Mesh::MFFace &faces = M->getFaces(); const Vertex::MFEdge &edges = V->getEdges(); cout << "faces:" << endl; for (Mesh::MFFace::const_iterator f = faces.begin(); f != faces.end(); ++f) cout << **f << endl; cout << "edges:" << endl; for (Vertex::MFEdge::const_iterator e = edges.begin(); e != edges.end(); ++e) cout << **e << endl;
We remove the first face:
M->removeFace(f0);
We check that it has been well deleted, and delete the nodes:
The order is important, and you must not delete thedelete M; delete V;
X3DTK::MESH::Vertex
node before the X3DTK::MESH::Mesh
one.