meshCreation

Introduction

This is a small example showing the manual creation and deletion of faces of a MESH scene graph.

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:

Main

First, the two nodes are created and attached:
Vertex *V = new Vertex(); Mesh *M = new Mesh(); M->setChild(V);
These are the default nodes.

Then, 4 vertices are created by the X3DTK::MESH::Vertex node:

SFVertex *v0 = V->createVertex(); SFVertex *v1 = V->createVertex(); SFVertex *v2 = V->createVertex(); SFVertex *v3 = V->createVertex();
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:

SFFace *f0 = M->createFace(index0); SFFace *f1 = M->createFace(index1);

To test the faces and edges, we iterate over them:

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;
The ostream operator has been overloaded for the faces, edges and vertices.

We remove the first face:

M->removeFace(f0);

We check that it has been well deleted, and delete the nodes:

delete M; delete V;
The order is important, and you must not delete the X3DTK::MESH::Vertex node before the X3DTK::MESH::Mesh one.
Generated on Fri Aug 27 13:16:25 2004 for X3DToolKit by doxygen 1.3.6