root/OpenSceneGraph/trunk/src/osgPlugins/Inventor/ConvertToInventor.h @ 13041

Revision 13041, 5.1 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#ifndef OSG_CONVERT_TO_INVENTOR_H
2#define OSG_CONVERT_TO_INVENTOR_H
3//
4//  ConvertToInventor converts OSG scene graph to Inventor or VRML 1 scene graph
5//
6//  It requires OSG and Inventor compatible library, such as Coin,
7//  SGI Inventor , or TGS Inventor.
8//
9//
10//  Autor: PCJohn (peciva _at fit.vutbr.cz)
11//
12//  License: public domain
13//
14//
15//  THIS SOFTWARE IS NOT COPYRIGHTED
16//
17//  This source code is offered for use in the public domain.
18//  You may use, modify or distribute it freely.
19//
20//  This source code is distributed in the hope that it will be useful but
21//  WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
22//  DISCLAIMED.  This includes but is not limited to warranties of
23//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24//
25//  If you find the source code useful, authors will kindly welcome
26//  if you give them credit and keep their names with their source code,
27//  but you are not forced to do so.
28//
29
30#include <stack>
31#include <osg/CullFace>
32#include <osg/FrontFace>
33
34class SoSeparator;
35
36namespace osg {
37  class BlendFunc;
38  class CullFace;
39  class FrontFace;
40  class Material;
41  class ShapeDrawable;
42  class TexEnv;
43  class TexGen;
44}
45
46
47
48class ConvertToInventor : public osg::NodeVisitor
49{
50public:
51  ConvertToInventor();
52  virtual ~ConvertToInventor();
53
54  SoNode* getIvSceneGraph() const;
55  void setVRML1Conversion(bool useVRML1)  { vrml1Conversion = useVRML1; };
56
57  virtual void apply(osg::Node &node);
58  virtual void apply(osg::Geode &node);
59  virtual void apply(osg::Group &node);
60
61  virtual void apply(osg::Billboard& node);
62  //virtual void apply(ProxyNode& node)                 { apply((Group&)node); }
63  //virtual void apply(Projection& node)                { apply((Group&)node); }
64  //virtual void apply(CoordinateSystemNode& node)      { apply((Group&)node); }
65
66  //virtual void apply(ClipNode& node)                  { apply((Group&)node); }
67  //virtual void apply(TexGenNode& node)                { apply((Group&)node); }
68  //virtual void apply(LightSource& node)               { apply((Group&)node); }
69
70  //virtual void apply(Transform& node);
71  //virtual void apply(Camera& node)                    { apply((Transform&)node); }
72  //virtual void apply(CameraView& node)                { apply((Transform&)node); }
73  virtual void apply(osg::MatrixTransform& node);
74  virtual void apply(osg::PositionAttitudeTransform& node);
75
76  //virtual void apply(Switch& node)                    { apply((Group&)node); }
77  //virtual void apply(Sequence& node)                  { apply((Group&)node); }
78  virtual void apply(osg::LOD& node);
79  //virtual void apply(PagedLOD& node)                  { apply((LOD&)node); }
80  //virtual void apply(ClearNode& node)                 { apply((Group&)node); }
81  //virtual void apply(OccluderNode& node)              { apply((Group&)node); }
82
83protected:
84  bool vrml1Conversion;
85  bool useIvExtensions;
86  SoSeparator *ivRoot;
87
88  struct InventorState {
89    class SoGroup      *ivHead;
90    class SoTexture2   *ivTexture;
91    class SoMaterial   *ivMaterial;
92    const osg::Material *osgMaterial;
93    bool osgTexture2Enabled;
94    const osg::Texture  *osgTexture;
95    const osg::TexEnv   *osgTexEnv;
96    bool osgTexGenS, osgTexGenT;
97    const osg::TexGen   *osgTexGen;
98    bool osgLighting;
99    bool osgTwoSided;
100    osg::FrontFace::Mode osgFrontFace;
101    bool osgCullFaceEnabled;
102    osg::CullFace::Mode osgCullFace;
103    bool osgBlendEnabled;
104    const osg::BlendFunc *osgBlendFunc;
105
106    InventorState()  {}
107    InventorState(SoGroup *root) : ivHead(root), ivTexture(NULL),
108        ivMaterial(NULL), osgMaterial(NULL),
109        osgTexture2Enabled(false), osgTexture(NULL), osgTexEnv(NULL),
110        osgTexGenS(false), osgTexGenT(false), osgTexGen(NULL),
111        osgLighting(true), osgTwoSided(false), osgFrontFace(osg::FrontFace::COUNTER_CLOCKWISE),
112        osgCullFaceEnabled(false), osgCullFace(osg::CullFace::BACK),
113        osgBlendEnabled(false), osgBlendFunc(NULL)  {}
114    InventorState(const InventorState &s) : ivHead(s.ivHead), ivTexture(s.ivTexture),
115        ivMaterial(s.ivMaterial), osgMaterial(s.osgMaterial),
116        osgTexture2Enabled(s.osgTexture2Enabled), osgTexture(s.osgTexture), osgTexEnv(s.osgTexEnv),
117        osgTexGenS(s.osgTexGenS), osgTexGenT(s.osgTexGenT), osgTexGen(s.osgTexGen),
118        osgLighting(s.osgLighting), osgTwoSided(s.osgTwoSided), osgFrontFace(s.osgFrontFace),
119        osgCullFaceEnabled(s.osgCullFaceEnabled), osgCullFace(s.osgCullFace),
120        osgBlendEnabled(s.osgBlendEnabled), osgBlendFunc(s.osgBlendFunc)  {}
121    static InventorState createTopLevelState(SoSeparator *ivRoot) { return InventorState(ivRoot); }
122  };
123
124  std::stack<InventorState> ivStack;
125
126  typedef std::map<const class osg::TexEnv*, class SoTexture2*> Env2ivTexMap;
127  std::map<const osg::Texture*, Env2ivTexMap> ivTexturesMap;
128  int uniqueIdGenerator;
129
130  void processDrawable(osg::Drawable *d);
131  void processGeometry(const osg::Geometry *g, InventorState *ivState);
132  void processShapeDrawable(const osg::ShapeDrawable *d, InventorState *ivState);
133
134  virtual InventorState* createInventorState(const osg::StateSet *ss);
135  virtual void popInventorState();
136};
137
138
139#endif /* OSG_CONVERT_TO_INVENTOR_H */
Note: See TracBrowser for help on using the browser.