| 1 | #ifndef OSG_CONVERT_TO_INVENTOR_H |
|---|
| 2 | #define OSG_CONVERT_TO_INVENTOR_H |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | #include <stack> |
|---|
| 31 | #include <osg/CullFace> |
|---|
| 32 | #include <osg/FrontFace> |
|---|
| 33 | |
|---|
| 34 | class SoSeparator; |
|---|
| 35 | |
|---|
| 36 | namespace 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 | |
|---|
| 48 | class ConvertToInventor : public osg::NodeVisitor |
|---|
| 49 | { |
|---|
| 50 | public: |
|---|
| 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 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | virtual void apply(osg::MatrixTransform& node); |
|---|
| 74 | virtual void apply(osg::PositionAttitudeTransform& node); |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | virtual void apply(osg::LOD& node); |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | protected: |
|---|
| 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 |
|---|