#include "X3dParser.h" bool X3dParser::ParseFile(const string filename, SceneGraphNode **root) { } namespace X3DTK { namespace MESH { MyStructureComputer::MyStructureComputer() { setGraphTraversal(new DFSGraphTraversal()); setComponentVisitor(new MyStructureComputerCoreVisitor()); } MyStructureComputer::~MyStructureComputer() { Singleton::removeInstance(); } MySimpleMesh *MyStructureComputer::compute(SFNode N) { Singleton::getInstance()->init(); traverse(N); Singleton::getInstance()->finish(); return Singleton::getInstance()->getMesh(); } MyStructureComputerCoreVisitor::MyStructureComputerCoreVisitor() { // Enter functions. define(Recorder::getEnterFunction(&MyStructureComputerCoreVisitor::enterMesh)); define(Recorder::getEnterFunction(&MyStructureComputerCoreVisitor::enterTransform)); // Leave function. define(Recorder::getLeaveFunction(&MyStructureComputerCoreVisitor::leaveX3DGroupingNode)); } void MyStructureComputerCoreVisitor::enterMesh(Mesh *M) { // StateVariables assignation. MyStructureComputerStateVariables *stateVariables = Singleton::getInstance(); SFMatrix34f T = stateVariables->getMatrix(); // Beginning a new Mesh by memorizing the current vertex index. stateVariables->beginNewMesh(); // filling the vertices. for (Mesh::MFVertex::const_iterator v = M->getVertices().begin(); v != M->getVertices().end(); ++v) { SFPoint3f P = T*(*v)->data().getPoint(); stateVariables->addVertex(P.x, P.y, P.z); } // filling the faces. for (Mesh::MFFace::const_iterator f = M->getFaces().begin(); f != M->getFaces().end(); ++f) { const SFFace::MFEdge &edges = (*f)->getEdges(); list indexList; for (SFFace::MFEdge::const_iterator e = edges.begin(); e != edges.end(); ++e) indexList.push_back((*e)->getFromVertex()->getIndex()); stateVariables->addFace(indexList); } } void MyStructureComputerCoreVisitor::enterTransform(Transform *T) { Singleton::getInstance()->pushMatrix(T->getTransform()); } void MyStructureComputerCoreVisitor::leaveX3DGroupingNode(X3DGroupingNode *) { Singleton::getInstance()->popMatrix(); } : StateVariables(), _mesh(0), _decal(0) { } void MyStructureComputerStateVariables::init() { _mesh = new MySimpleMesh(); _matrixStack.push_front(SFMatrix34f::identity); } void MyStructureComputerStateVariables::finish() { _matrixStack.clear(); } void MyStructureComputerStateVariables::beginNewMesh() { _decal = _mesh->getVertexArray().size(); } void MyStructureComputerStateVariables::addFace(const Face &face) { // MyFace decalFace = face; // for (MyFace::iterator it = decalFace.begin(); it != decalFace.end(); ++it) // *it = _decal + *it; // _mesh->addFace(decalFace); }; void MyStructureComputerStateVariables::pushMatrix(const SFMatrix34f &transformation) { _matrixStack.push_front(_matrixStack.front()*transformation); } void MyStructureComputerStateVariables::popMatrix() { _matrixStack.pop_front(); } }