////////////////////////////////////////////////////////////////////////////////
//                            X3D_MeshBuilder.inl                             //
////////////////////////////////////////////////////////////////////////////////

namespace X3DTK {
namespace X3D {

template<class MData, class VData, class EData, class FData, bool RW>
TemplateMeshBuilder<MData, VData, EData, FData, RW>::TemplateMeshBuilder() 
{
  setGraphTraversal(new DFSGraphTraversal());

  getGraphTraversal()->setComponentVisitor(new TemplateMeshBuilderCoreVisitor<MData, VData, EData, FData, RW>());
  getGraphTraversal()->setComponentVisitor(new TemplateMeshBuilderGeometry3DVisitor<MData, VData, EData, FData, RW>());
  getGraphTraversal()->setComponentVisitor(new TemplateMeshBuilderGroupingVisitor<MData, VData, EData, FData, RW>());
  getGraphTraversal()->setComponentVisitor(new TemplateMeshBuilderShapeVisitor<MData, VData, EData, FData, RW>());
  getGraphTraversal()->setComponentVisitor(new TemplateMeshBuilderRenderingVisitor<MData, VData, EData, FData, RW>());
}

template<class MData, class VData, class EData, class FData, bool RW>
TemplateMeshBuilder<MData, VData, EData, FData, RW>::~TemplateMeshBuilder() 
{
  Singleton<TemplateMeshBuilderStateVariables<MData, VData, EData, FData, RW> >::removeInstance();
};

template<class MData, class VData, class EData, class FData, bool RW> 
MESH::X3DNode *TemplateMeshBuilder<MData, VData, EData, FData, RW>::build(X3DNode *N)
{
  Singleton<TemplateMeshBuilderStateVariables<MData, VData, EData, FData, RW> >::getInstance()->init();
  traverse(N);
  Singleton<TemplateMeshBuilderStateVariables<MData, VData, EData, FData, RW> >::getInstance()->finish();
  
  return Singleton<TemplateMeshBuilderStateVariables<MData, VData, EData, FData, RW> >::getInstance()->getRoot();
}

template<class MData, class VData, class EData, class FData, bool RW>
MESH::Scene *TemplateMeshBuilder<MData, VData, EData, FData, RW>::build(Scene *S)
{
  return static_cast<MESH::Scene *>(build(static_cast<X3DNode *>(S)));
};
  
}
}  
