| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | #include <string> |
|---|
| 19 | #include <map> |
|---|
| 20 | |
|---|
| 21 | #include <osg/Node> |
|---|
| 22 | #include <osg/Geometry> |
|---|
| 23 | |
|---|
| 24 | #include <osgDB/Registry> |
|---|
| 25 | #include <osgDB/ReadFile> |
|---|
| 26 | #include <osgDB/FileNameUtils> |
|---|
| 27 | #include <osgDB/FileUtils> |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | namespace openvrml |
|---|
| 31 | { |
|---|
| 32 | class node; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | class QuadricKey |
|---|
| 36 | { |
|---|
| 37 | public: |
|---|
| 38 | QuadricKey(float height, float radius, unsigned bottom, unsigned side, unsigned top) |
|---|
| 39 | : m_height(height) |
|---|
| 40 | , m_radius(radius) |
|---|
| 41 | , m_flags(bottom | (side << 1) | (top << 2)) |
|---|
| 42 | {} |
|---|
| 43 | |
|---|
| 44 | bool operator<(const QuadricKey& rhs) const |
|---|
| 45 | { |
|---|
| 46 | return m_height < rhs.m_height || |
|---|
| 47 | (m_height == rhs.m_height && (m_radius < rhs.m_radius || |
|---|
| 48 | (m_radius == rhs.m_radius && m_flags < rhs.m_flags))); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | private: |
|---|
| 52 | float m_height; |
|---|
| 53 | float m_radius; |
|---|
| 54 | unsigned m_flags; |
|---|
| 55 | }; |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | class ReaderWriterVRML2 |
|---|
| 64 | : public osgDB::ReaderWriter |
|---|
| 65 | { |
|---|
| 66 | public: |
|---|
| 67 | ReaderWriterVRML2() |
|---|
| 68 | { |
|---|
| 69 | supportsExtension("wrl","VRML format"); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | virtual const char* className() const { return "VRML2 Reader/Writer"; } |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | virtual ReadResult readNode(const std::string&, const osgDB::Options *options) const; |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | private: |
|---|
| 79 | typedef std::map<float, osg::ref_ptr<osg::Geometry> > SphereLibrary; |
|---|
| 80 | typedef std::map<osg::Vec3, osg::ref_ptr<osg::Geometry> > BoxLibrary; |
|---|
| 81 | typedef std::map<QuadricKey, osg::ref_ptr<osg::Geometry> > ConeLibrary; |
|---|
| 82 | typedef std::map<QuadricKey, osg::ref_ptr<osg::Geometry> > CylinderLibrary; |
|---|
| 83 | |
|---|
| 84 | osg::ref_ptr<osg::Node> convertFromVRML(openvrml::node *obj) const; |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | osg::ref_ptr<osg::Geometry> convertVRML97IndexedFaceSet(openvrml::node *vrml_ifs) const; |
|---|
| 88 | osg::ref_ptr<osg::Geometry> convertVRML97IndexedLineSet(openvrml::node *vrml_ifs) const; |
|---|
| 89 | osg::ref_ptr<osg::Geometry> convertVRML97Box(openvrml::node* vrml_box) const; |
|---|
| 90 | osg::ref_ptr<osg::Geometry> convertVRML97Sphere(openvrml::node* vrml_sphere) const; |
|---|
| 91 | osg::ref_ptr<osg::Geometry> convertVRML97Cone(openvrml::node* vrml_cone) const; |
|---|
| 92 | osg::ref_ptr<osg::Geometry> convertVRML97Cylinder(openvrml::node* vrml_cylinder) const; |
|---|
| 93 | |
|---|
| 94 | mutable BoxLibrary m_boxLibrary; |
|---|
| 95 | mutable SphereLibrary m_sphereLibrary; |
|---|
| 96 | mutable ConeLibrary m_coneLibrary; |
|---|
| 97 | mutable CylinderLibrary m_cylinderLibrary; |
|---|
| 98 | }; |
|---|