root/OpenSceneGraph/trunk/src/osgPlugins/vrml/ReaderWriterVRML2.h @ 13041

Revision 13041, 3.8 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1// -*-c++-*-
2
3/*
4 *
5 * VRML2 file converter for OpenSceneGraph.
6 *
7 * authors :
8 *           Johan Nouvel (johan_nouvel@yahoo.com) for the writeNode function.
9 *
10 *           Jan Ciger (jan.ciger@gmail.com),
11 *           Tolga Abaci (tolga.abaci@gmail.com),
12 *           Bruno Herbelin (bruno.herbelin@gmail.com)
13 *
14 *           (c) VRlab EPFL, Switzerland, 2004-2006
15 *
16 *           Gino van den Bergen, DTECTA (gino@dtecta.com)
17 *           Xiangxian Wang (xiangxianwang@yahoo.com.cn)
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
33namespace openvrml
34{
35    class node;
36}
37
38class QuadricKey
39{
40public:
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
54private:
55    float m_height;
56    float m_radius;
57    unsigned m_flags;
58};
59
60
61
62
63/**
64 * OpenSceneGraph plugin wrapper/converter.
65 */
66class ReaderWriterVRML2
67    : public osgDB::ReaderWriter
68{
69public:
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    // virtual ReadResult readNode(std::istream& fin, const osgDB::Options* options) const;
86
87    virtual WriteResult writeNode(const osg::Node&,const std::string& filename,const osgDB::ReaderWriter::Options *options) const;
88
89private:
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};
Note: See TracBrowser for help on using the browser.