|
From: Mike D. <o3d...@us...> - 2004-07-21 07:41:13
|
Update of /cvsroot/grappelmann/spaceplane In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3987 Added Files: mesh.cpp mesh.cpp~ mesh.h mesh.h~ model.cpp polygon.cpp polygon.cpp~ polygon.h polygon.h~ scene_object.cpp scene_object.cpp~ scene_object.h scene_object.h~ Log Message: -now using x3d for models --- NEW FILE: mesh.cpp~ --- /* $Id: mesh.cpp~,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "mesh.h" Mesh::Mesh(SceneObject* parent) : SceneObject(parent) { } bool Mesh::addPolygon(Polygon& polygon) { m_polygons.push_back(polygon); return true; } /* $Log: mesh.cpp~,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ --- NEW FILE: mesh.h~ --- #ifndef MESH_H #define MESH_H /* $Id: mesh.h~,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "scene_object.h" class Mesh : public SceneObject { public: Mesh(SceneObject* parent = NULL); virtual ~Mesh; bool addPolygon(Polygon& polygon); private: vector<Polygon> m_polygons; /* coordIndex normalIndex coord - point (3d coord?) normal - vector */ }; /* $Log: mesh.h~,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ #endif --- NEW FILE: model.cpp --- #include "model.h" Model::Model(const string& vrmlFilename) { /* m_x3dLoader = new X3D::XercesLoader(new X3D::Creator()); if((m_x3dScene = m_x3dLoader->load(vrmlFilename.c_str(), false)) == NULL) { cout << "<Model::Model>\tcouldn't parse file [" << vrmlFilename << "]" << endl; throw("could not parse file"); } cout << "<Model::Model>\tmodel loaded" << endl; _dumpX3DScene(m_x3dScene); */ if(!_parseX3DFile(vrmlFilename.c_str())) { cout << "error parsing x3d file" << endl; abort(); } cout << "stopping now" << endl; abort(); /* if(!_parseVrmlFile(vrmlFilename.c_str())) { cout << "<Model::Model>\tcouldn't parse file [" << vrmlFilename << "]" << endl; throw("could not parse file"); } */ // should get normals here } bool Model::_parseVrmlFile(const char* filename) { string vrmlText = ""; cout << "<main>\topening vrmlFile [" << filename << "]" << endl; ifstream vrmlFile; vrmlFile.open(filename); if(!vrmlFile.is_open()) { cout << "<main>\tcouldn't open file" << endl; return false; } // get length of file: vrmlFile.seekg (0, ios::end); int fileLength = vrmlFile.tellg(); vrmlFile.seekg (0, ios::beg); cout << "<main>\tfile length [" << fileLength << "]" << endl; string buffer; while(vrmlFile.good()) { getline(vrmlFile, buffer); vrmlText += buffer; vrmlText += '\n'; //cout << "<main>\tgot buffer [" << buffer << "]" << endl; } cout << "<main>\tfinished reading" << endl; //Vrml::Object m_rootObject; cout << "<main>\tparsing" << endl; string::size_type parseStart = 0; m_rootObject.parse(vrmlText, parseStart); cout << "<main>\tdumping m_rootObject:" << endl; m_rootObject.Dump(0); cout << "<main>\tfinding suzanne" << endl; /* Vrml::Object* obj_separator = m_rootObject.findChildByType("Separator"); if(obj_separator == NULL) { cout << "<main>\tdidn't find seperator" << endl; return false; } */ Vrml::Object* obj_switch = m_rootObject.findChildByType("Switch"); if(obj_switch == NULL) { cout << "<main>\tdidn't find switch" << endl; return false; } Vrml::Object* obj_separator = obj_switch->findChildByType("Separator"); if(obj_separator == NULL) { cout << "<main>\tdidn't find separator" << endl; return false; } Vrml::Object* obj_coords = obj_separator->findChildByType("Coordinate3"); if(obj_coords == NULL) { cout << "<main>\tdidn't find coords" << endl; return false; } Vrml::Object* obj_point = obj_coords->findChildByType("point"); if(obj_point == NULL) { cout << "<main>\tdidn't find point" << endl; return false; } Vrml::Object* obj_faceset = obj_separator->findChildByType("IndexedFaceSet"); if(obj_faceset == NULL) { cout << "<main>\tdidn't find face set" << endl; return false; } Vrml::Object* obj_indices = obj_faceset->findChildByType("coordIndex"); if(obj_indices == NULL) { cout << "<main>\tdidn't find indices" << endl; return false; } cout << "<main>\tdumping points" << endl; obj_point->Dump(0); m_pointsArray = (Vrml::DoubleArray*)obj_point->getChildByIndex(0); /* for(long index = 0; index < m_pointsArray->size(); index++) { cout << "index [" << index << "] value [" << (*m_pointsArray)[index] << "]" << endl; } */ cout << "<main>\tdumping coord indices" << endl; obj_indices->Dump(0); m_indicesArray = (Vrml::DoubleArray*)obj_indices->getChildByIndex(0); return true; } bool Model::_parseX3DFile(const char* filename) { try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { char* message = XMLString::transcode(toCatch.getMessage()); cout << "Error during initialization [" << message << "]" << endl; XMLString::release(&message); return false; } XercesDOMParser* parser = new XercesDOMParser(); parser->setValidationScheme(XercesDOMParser::Val_Always); // optional. parser->setDoNamespaces(true); // optional ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase(); parser->setErrorHandler(errHandler); try { parser->parse(filename); DOMDocument* domDocument = parser->getDocument(); if(!_dumpDOMNode(domDocument->getDocumentElement())) { cout << "couldn't dump dom document" << endl; return false; } } catch (const XMLException& toCatch) { char* message = XMLString::transcode(toCatch.getMessage()); cout << "Exception message is [" << message << "]" << endl; XMLString::release(&message); return false; } catch (const DOMException& toCatch) { char* message = XMLString::transcode(toCatch.msg); cout << "Exception message is [" << message << "]" << endl; XMLString::release(&message); return false; } catch (...) { cout << "Unexpected Exception \n" ; return false; } delete parser; delete errHandler; return true; } bool Model::_dumpDOMNode(DOMNode* domNode, long curLevel) { if(domNode == NULL) { return false; } try { if((domNode->getNodeType() == DOMNode::ELEMENT_NODE) || (domNode->getNodeType() == DOMNode::ATTRIBUTE_NODE)) { cout << "[" << curLevel << "] node type [" << domNode->getNodeType() << "] node name [" << XMLString::transcode(domNode->getNodeName()) << "]" << endl; // value [" << XMLString::transcode(domNode->getNodeValue()) << "]" << endl; if(domNode->getNodeValue() != NULL) { cout << "[" << curLevel << "] value [" << XMLString::transcode(domNode->getNodeValue()) << "]" << endl; } DOMNamedNodeMap* attributes = domNode->getAttributes(); if(attributes != NULL) { cout << "[" << curLevel << "] dumping attributes" << endl; for(XMLSize_t index = 0; index < attributes->getLength(); index++) { _dumpDOMNode(attributes->item(index), curLevel + 1); } cout << "[" << curLevel << "] dumping attributes complete" << endl; } } else if(domNode->getNodeType() == DOMNode::TEXT_NODE) { return false; } // dump this element's children first DOMNode* curChild = domNode->getFirstChild(); while(curChild != NULL) { // dump the child _dumpDOMNode(curChild, curLevel + 1); // now get the child's sibling DOMNode* nextChild = curChild->getNextSibling(); curChild = nextChild; } } catch (const XMLException& toCatch) { char* message = XMLString::transcode(toCatch.getMessage()); cout << "Exception message is [" << message << "]" << endl; XMLString::release(&message); return false; } catch (const DOMException& toCatch) { char* message = XMLString::transcode(toCatch.msg); cout << "Exception message is [" << message << "]" << endl; XMLString::release(&message); return false; } catch (...) { cout << "Unexpected Exception \n" ; return false; } return true; } bool Model::_dumpX3DScene(X3D::X3DNode* curNode, long curLevel) { MFAbstractNode childList = curNode->getChildList(); /* if(childList == NULL) { cout << "got an empty child list at level [" << curLevel << "]" << endl; return false; } */ //cout << "start loop at level [" << curLevel << "]" << endl; for(MFAbstractNode::iterator i = childList.begin(); i != childList.end(); i++) { try { cout << "got child of type [" << typeid(*(*i)).name() << "] at level [" << curLevel << "]" << endl; } catch(exception& e) { cout << "got an exception at level [" << curLevel << "] what [" << e.what() << "]" << endl; continue; } _dumpX3DScene((X3D::X3DNode*)*i, curLevel + 1); //cout << "finished with node at level [" << curLevel << "]" << endl; } //cout << "end loop at level [" << curLevel << "]" << endl; return true; } --- NEW FILE: polygon.h~ --- #ifndef POLYGON_H #define POLYGON_H /* $Id: polygon.h~,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "scene_object.h" #include "coord3d.h" class PolyGon : public SceneObject { public: PolyGon(SceneObject* parent = NULL); virtual ~PolyGon; bool setNormal(double normal); bool setCoord(Coord3D& coord); private: double m_normal; Coord3D m_coord; }; /* $Log: polygon.h~,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ #endif --- NEW FILE: scene_object.cpp --- /* $Id: scene_object.cpp,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "scene_object.h" SceneObject::SceneObject(SceneObject* parent) : m_parent(parent) { } bool SceneObject::addChild(SceneObject* child) { m_children.push_back(child); return true; } bool SceneObject::draw(bool drawChildren) { } /* $Log: scene_object.cpp,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ --- NEW FILE: scene_object.cpp~ --- /* $Id: scene_object.cpp~,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "scene_object.h" SceneObject::SceneObject(SceneObject* parent) : m_parent(parent) { } bool SceneObject::addChild(SceneObject* child) { m_children.push_back(child); return true; } bool SceneObject::draw(bool drawChildren) { } /* $Log: scene_object.cpp~,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ --- NEW FILE: polygon.cpp~ --- /* $Id: polygon.cpp~,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "polygon.h" PolyGon::PolyGon(SceneObject* parent) : SceneObject(parent) { cout << "<Mesh::Mesh>\tcalled" << endl; } Polygon::Polygon(const Polygon& rhs) { cout << "<Polygon::Polygon(copy)>\tcalled" << endl; } bool PolyGon::setNormal(double normal) { m_normal = normal; return true; } bool setCoord(Coord3D& coord) { m_coord = coord; return true; } /* $Log: polygon.cpp~,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ --- NEW FILE: scene_object.h~ --- /* $Id: scene_object.h~,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #ifndef SCENE_OBJECT #define SCENE_OBJECT #include <vector> #include <string> using namespace std; class SceneObject { public: SceneObject(SceneObject* parent = NULL); virtual ~SceneObject(); bool addChild(SceneObject* child); bool draw(bool drawChildren = true); private: SceneObject* m_parent; vector<SceneObject*> m_children; }; /* $Log: scene_object.h~,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ #endif --- NEW FILE: mesh.h --- #ifndef MESH_H #define MESH_H /* $Id: mesh.h,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "scene_object.h" #include <vector> using namespace std; class Mesh : public SceneObject { public: Mesh(SceneObject* parent = NULL); virtual ~Mesh; bool addPolygon(Polygon& polygon); private: vector<Polygon> m_polygons; /* coordIndex normalIndex coord - point (3d coord?) normal - vector */ }; /* $Log: mesh.h,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ #endif --- NEW FILE: polygon.cpp --- /* $Id: polygon.cpp,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "polygon.h" PolyGon::PolyGon(SceneObject* parent) : SceneObject(parent) { cout << "<Mesh::Mesh>\tcalled" << endl; } Polygon::Polygon(const Polygon& rhs) { cout << "<Polygon::Polygon(copy)>\tcalled" << endl; } bool PolyGon::setNormal(double normal) { m_normal = normal; return true; } bool setCoord(Coord3D& coord) { m_coord = coord; return true; } /* $Log: polygon.cpp,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ --- NEW FILE: polygon.h --- #ifndef POLYGON_H #define POLYGON_H /* $Id: polygon.h,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "scene_object.h" #include "coord3d.h" class PolyGon : public SceneObject { public: PolyGon(SceneObject* parent = NULL); Polygon(const Polygon& rhs); virtual ~PolyGon; bool setNormal(double normal); bool setCoord(Coord3D& coord); private: double m_normal; Coord3D m_coord; }; /* $Log: polygon.h,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ #endif --- NEW FILE: scene_object.h --- /* $Id: scene_object.h,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #ifndef SCENE_OBJECT_H #define SCENE_OBJECT_H #include <vector> #include <string> using namespace std; class SceneObject { public: SceneObject(SceneObject* parent = NULL); virtual ~SceneObject(); bool addChild(SceneObject* child); bool draw(bool drawChildren = true); private: SceneObject* m_parent; vector<SceneObject*> m_children; }; /* $Log: scene_object.h,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ #endif --- NEW FILE: mesh.cpp --- /* $Id: mesh.cpp,v 1.1 2004/07/21 07:41:03 o3dozone Exp $ */ #include "mesh.h" Mesh::Mesh(SceneObject* parent) : SceneObject(parent) { cout << "<Mesh::Mesh>\tcalled" << endl; } bool Mesh::addPolygon(Polygon& polygon) { m_polygons.push_back(polygon); return true; } /* $Log: mesh.cpp,v $ Revision 1.1 2004/07/21 07:41:03 o3dozone -now using x3d for models */ |