| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #include <string> |
|---|
| 22 | #include <map> |
|---|
| 23 | |
|---|
| 24 | #include <osg/Node> |
|---|
| 25 | #include <osg/Geometry> |
|---|
| 26 | |
|---|
| 27 | #include <osgDB/Registry> |
|---|
| 28 | #include <osgDB/ReadFile> |
|---|
| 29 | #include <osgDB/FileNameUtils> |
|---|
| 30 | #include <osgDB/FileUtils> |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | namespace openvrml |
|---|
| 34 | { |
|---|
| 35 | class node; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | class QuadricKey |
|---|
| 39 | { |
|---|
| 40 | public: |
|---|
| 41 | QuadricKey(float height, float radius, unsigned bottom, unsigned side, unsigned top) |
|---|
| 42 | : m_height(height) |
|---|
| 43 | , m_radius(radius) |
|---|
| 44 | , m_flags(bottom | (side << 1) | (top << 2)) |
|---|
| 45 | {} |
|---|
| 46 | |
|---|
| 47 | bool operator<(const QuadricKey& rhs) const |
|---|
| 48 | { |
|---|
| 49 | return m_height < rhs.m_height || |
|---|
| 50 | (m_height == rhs.m_height && (m_radius < rhs.m_radius || |
|---|
| 51 | (m_radius == rhs.m_radius && m_flags < rhs.m_flags))); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | private: |
|---|
| 55 | float m_height; |
|---|
| 56 | float m_radius; |
|---|
| 57 | unsigned m_flags; |
|---|
| 58 | }; |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | class ReaderWriterVRML2 |
|---|
| 67 | : public osgDB::ReaderWriter |
|---|
| 68 | { |
|---|
| 69 | public: |
|---|
| 70 | ReaderWriterVRML2() |
|---|
| 71 | { |
|---|
| 72 | supportsExtension("wrl","VRML format"); |
|---|
| 73 | supportsOption("directoryTexture=<aDirectory>","Export option. If a texture needs to be copied, it will be into directory <aDirectory> instead of the working one"); |
|---|
| 74 | supportsOption("convertTextures=0","Export option. Keep textures in their original format but copy them into <directoryTexture> directory"); |
|---|
| 75 | supportsOption("convertTextures=-1","Export option. Use textures but do not convert them, keep them in their original format and location."); |
|---|
| 76 | supportsOption("convertTextures=-2","Export option. Do not use textures, export only geometry"); |
|---|
| 77 | supportsOption("convertTextures=-3","Export option. Default value.Convert textures to jpeg or png format, according to alpha values, and copy them into <directoryTexture> directory "); |
|---|
| 78 | supportsOption("textureUnit=<X>","Export option. Use parameters of texture unit X instead of unit 0 in case of multitexture input file"); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | virtual const char* className() const { return "VRML2 Reader/Writer"; } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | virtual ReadResult readNode(const std::string&, const osgDB::Options *options) const; |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | virtual WriteResult writeNode(const osg::Node&,const std::string& filename,const osgDB::ReaderWriter::Options *options) const; |
|---|
| 88 | |
|---|
| 89 | private: |
|---|
| 90 | typedef std::map<float, osg::ref_ptr<osg::Geometry> > SphereLibrary; |
|---|
| 91 | typedef std::map<osg::Vec3, osg::ref_ptr<osg::Geometry> > BoxLibrary; |
|---|
| 92 | typedef std::map<QuadricKey, osg::ref_ptr<osg::Geometry> > ConeLibrary; |
|---|
| 93 | typedef std::map<QuadricKey, osg::ref_ptr<osg::Geometry> > CylinderLibrary; |
|---|
| 94 | |
|---|
| 95 | osg::Node* convertFromVRML(openvrml::node *obj) const; |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | osg::ref_ptr<osg::Geometry> convertVRML97IndexedFaceSet(openvrml::node *vrml_ifs) const; |
|---|
| 99 | osg::ref_ptr<osg::Geometry> convertVRML97IndexedLineSet(openvrml::node *vrml_ifs) const; |
|---|
| 100 | osg::ref_ptr<osg::Geometry> convertVRML97Box(openvrml::node* vrml_box) const; |
|---|
| 101 | osg::ref_ptr<osg::Geometry> convertVRML97Sphere(openvrml::node* vrml_sphere) const; |
|---|
| 102 | osg::ref_ptr<osg::Geometry> convertVRML97Cone(openvrml::node* vrml_cone) const; |
|---|
| 103 | osg::ref_ptr<osg::Geometry> convertVRML97Cylinder(openvrml::node* vrml_cylinder) const; |
|---|
| 104 | |
|---|
| 105 | mutable BoxLibrary m_boxLibrary; |
|---|
| 106 | mutable SphereLibrary m_sphereLibrary; |
|---|
| 107 | mutable ConeLibrary m_coneLibrary; |
|---|
| 108 | mutable CylinderLibrary m_cylinderLibrary; |
|---|
| 109 | }; |
|---|