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

Revision 11290, 2.7 kB (checked in by robert, 4 years ago)

From Mathias Froehlich, "I added some features to the vrml plugin.

The plugin can now handle embeded PixelTexture? fields in addition to the
already implemented ImageTexture? fields.

Fixed a bug with texture repeat being applied to the wrong texture dimension.

Added handling for IndexedLineSet? geometries."

Line 
1// -*-c++-*-
2
3/*
4 *
5 * VRML2 file converter for OpenSceneGraph.
6 *
7 * authors : Jan Ciger (jan.ciger@gmail.com),
8 *           Tolga Abaci (tolga.abaci@gmail.com),
9 *           Bruno Herbelin (bruno.herbelin@gmail.com)
10 *
11 *           (c) VRlab EPFL, Switzerland, 2004-2006
12 *
13 *           Gino van den Bergen, DTECTA (gino@dtecta.com)
14 *           Xiangxian Wang (xiangxianwang@yahoo.com.cn)
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
30namespace openvrml
31{
32    class node;
33}
34
35class QuadricKey
36{
37public:
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
51private:
52    float m_height;
53    float m_radius;
54    unsigned m_flags;
55};
56
57
58
59
60/**
61 * OpenSceneGraph plugin wrapper/converter.
62 */
63class ReaderWriterVRML2
64    : public osgDB::ReaderWriter
65{
66public:
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    // virtual ReadResult readNode(std::istream& fin, const osgDB::Options* options) const;
77
78private:
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};
Note: See TracBrowser for help on using the browser.