| [2225] | 1 | #ifndef _CONVERTFROMINVENTOR_H_ |
|---|
| 2 | #define _CONVERTFROMINVENTOR_H_ |
|---|
| 3 | |
|---|
| 4 | #include <osg/Group> |
|---|
| 5 | #include <osg/Geometry> |
|---|
| 6 | #include <osg/PrimitiveSet> |
|---|
| 7 | #include <osg/Texture2D> |
|---|
| 8 | #include <osg/Light> |
|---|
| 9 | #include <Inventor/actions/SoCallbackAction.h> |
|---|
| [9053] | 10 | #include <Inventor/SbLinear.h> |
|---|
| [2225] | 11 | #include <vector> |
|---|
| 12 | #include <stack> |
|---|
| [11032] | 13 | #include <assert.h> |
|---|
| [2225] | 14 | |
|---|
| [6543] | 15 | class ConvertFromInventor |
|---|
| [2225] | 16 | { |
|---|
| 17 | public: |
|---|
| 18 | ConvertFromInventor(); |
|---|
| 19 | ~ConvertFromInventor(); |
|---|
| [6543] | 20 | |
|---|
| [11032] | 21 | |
|---|
| [6543] | 22 | osg::Node* convert(SoNode* rootIVNode); |
|---|
| 23 | |
|---|
| [11032] | 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | void preprocess(SoNode *root); |
|---|
| 33 | |
|---|
| [2225] | 34 | private: |
|---|
| 35 | |
|---|
| [11032] | 36 | |
|---|
| [2225] | 37 | |
|---|
| 38 | |
|---|
| [11032] | 39 | static SoCallbackAction::Response preNode(void* data, |
|---|
| [2225] | 40 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 41 | static SoCallbackAction::Response postNode(void* data, |
|---|
| [2225] | 42 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 43 | static SoCallbackAction::Response preTransformSeparator(void* data, |
|---|
| [2225] | 44 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 45 | static SoCallbackAction::Response postTransformSeparator(void* data, |
|---|
| [2225] | 46 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 47 | static SoCallbackAction::Response preLOD(void* data, |
|---|
| [2225] | 48 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 49 | static SoCallbackAction::Response postLOD(void* data, |
|---|
| [2225] | 50 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 51 | static SoCallbackAction::Response preShape(void* data, |
|---|
| [2225] | 52 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 53 | static SoCallbackAction::Response postShape(void* data, |
|---|
| [2225] | 54 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 55 | static SoCallbackAction::Response postTexture(void* data, |
|---|
| [2225] | 56 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 57 | static SoCallbackAction::Response preLight(void* data, |
|---|
| [2225] | 58 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 59 | static SoCallbackAction::Response preEnvironment(void* data, |
|---|
| [6543] | 60 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 61 | static SoCallbackAction::Response preShaderProgram(void* data, |
|---|
| [9053] | 62 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 63 | static SoCallbackAction::Response preRotor(void* data, |
|---|
| [9053] | 64 | SoCallbackAction* action, const SoNode* node); |
|---|
| [11032] | 65 | static SoCallbackAction::Response prePendulum(void* data, |
|---|
| 66 | SoCallbackAction* action, const SoNode* node); |
|---|
| 67 | static SoCallbackAction::Response preShuttle(void* data, |
|---|
| 68 | SoCallbackAction* action, const SoNode* node); |
|---|
| [9053] | 69 | static SoCallbackAction::Response preInfo(void* data, |
|---|
| 70 | SoCallbackAction* action, const SoNode* node); |
|---|
| [2225] | 71 | |
|---|
| 72 | static void addTriangleCB(void* data, SoCallbackAction* action, |
|---|
| [5802] | 73 | const SoPrimitiveVertex *v0, |
|---|
| [2225] | 74 | const SoPrimitiveVertex *v1, |
|---|
| 75 | const SoPrimitiveVertex *v2); |
|---|
| 76 | static void addLineSegmentCB(void* data, SoCallbackAction* action, |
|---|
| 77 | const SoPrimitiveVertex *v0, |
|---|
| 78 | const SoPrimitiveVertex *v1); |
|---|
| 79 | static void addPointCB(void* data, SoCallbackAction* action, |
|---|
| 80 | const SoPrimitiveVertex *v0); |
|---|
| [6543] | 81 | |
|---|
| [11032] | 82 | static SoCallbackAction::Response restructure(void* data, |
|---|
| 83 | SoCallbackAction* action, const SoNode* node); |
|---|
| 84 | static SoCallbackAction::Response restructurePreNode(void* data, |
|---|
| 85 | SoCallbackAction* action, const SoNode* node); |
|---|
| 86 | static SoCallbackAction::Response restructurePostNode(void* data, |
|---|
| 87 | SoCallbackAction* action, const SoNode* node); |
|---|
| 88 | |
|---|
| [2225] | 89 | private: |
|---|
| [9053] | 90 | SbString transformInfoName; |
|---|
| 91 | SbName appearanceName; |
|---|
| [2225] | 92 | |
|---|
| [11032] | 93 | void addVertex(SoCallbackAction* action, const SoPrimitiveVertex* v, |
|---|
| [2225] | 94 | int index); |
|---|
| 95 | |
|---|
| [6543] | 96 | osg::ref_ptr<osg::StateSet> getStateSet(SoCallbackAction* action); |
|---|
| [2225] | 97 | |
|---|
| [11032] | 98 | osg::Texture2D* convertIVTexToOSGTex(const SoNode* soNode, |
|---|
| [6543] | 99 | SoCallbackAction* action); |
|---|
| [2225] | 100 | |
|---|
| 101 | void transformLight(SoCallbackAction* action, const SbVec3f& vec, |
|---|
| 102 | osg::Vec3& transVec); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | void transposeMatrix(osg::Matrix& mat); |
|---|
| [6543] | 106 | |
|---|
| [2225] | 107 | private: |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | osg::Geometry::AttributeBinding normalBinding; |
|---|
| 111 | osg::Geometry::AttributeBinding colorBinding; |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | std::vector<osg::Vec3> vertices; |
|---|
| 115 | std::vector<osg::Vec3> normals; |
|---|
| 116 | std::vector<osg::Vec4> colors; |
|---|
| 117 | std::vector<osg::Vec2> textureCoords; |
|---|
| 118 | |
|---|
| [11032] | 119 | |
|---|
| [2225] | 120 | int numPrimitives; |
|---|
| 121 | osg::PrimitiveSet::Mode primitiveType; |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | enum VertexOrder { CLOCKWISE, COUNTER_CLOCKWISE }; |
|---|
| 125 | VertexOrder vertexOrder; |
|---|
| 126 | |
|---|
| [6543] | 127 | |
|---|
| 128 | |
|---|
| 129 | std::map<const SoNode*, osg::Texture2D*> ivToOsgTexMap; |
|---|
| [2225] | 130 | |
|---|
| [5802] | 131 | osg::ref_ptr<osg::MatrixTransform> _root; |
|---|
| [9053] | 132 | |
|---|
| [11032] | 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | class IvStateItem { |
|---|
| 139 | public: |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | enum Flags { |
|---|
| 143 | DEFAULT_FLAGS = 0, |
|---|
| 144 | MULTI_POP = 1, |
|---|
| 145 | KEEP_CHILDREN_ORDER = 2, |
|---|
| 146 | APPEND_AT_PUSH = 4, |
|---|
| 147 | UPDATE_STATE = 8, |
|---|
| 148 | UPDATE_STATE_EXCEPT_TRANSFORM = 0x10 |
|---|
| 149 | |
|---|
| 150 | }; |
|---|
| 151 | int flags; |
|---|
| 152 | const SoNode *pushInitiator; |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | SbMatrix inheritedTransformation; |
|---|
| 156 | SbMatrix lastUsedTransformation; |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | const SoNode* inheritedTexture; |
|---|
| 162 | const SoNode* currentTexture; |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | std::vector<osg::ref_ptr<osg::Light> > inheritedLights; |
|---|
| 166 | std::vector<osg::ref_ptr<osg::Light> > currentLights; |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | osg::ref_ptr<osg::Program> inheritedGLProgram; |
|---|
| 170 | osg::ref_ptr<osg::Program> currentGLProgram; |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | SbColor inheritedAmbientLight; |
|---|
| 174 | SbColor currentAmbientLight; |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | osg::ref_ptr<osg::Group> osgStateRoot; |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | const SoNode *keepChildrenOrderParent; |
|---|
| 181 | |
|---|
| 182 | IvStateItem(const SoNode *initiator, osg::Group *root = NULL) : |
|---|
| 183 | flags(IvStateItem::DEFAULT_FLAGS), |
|---|
| 184 | pushInitiator(initiator), |
|---|
| 185 | inheritedTransformation(SbMatrix::identity()), |
|---|
| 186 | lastUsedTransformation(SbMatrix::identity()), |
|---|
| 187 | inheritedTexture(NULL), |
|---|
| 188 | currentTexture(NULL), |
|---|
| 189 | inheritedLights(), |
|---|
| 190 | currentLights(), |
|---|
| 191 | inheritedGLProgram(NULL), |
|---|
| 192 | currentGLProgram(NULL), |
|---|
| 193 | inheritedAmbientLight(SbColor(0.2f,0.2f,0.2f)), |
|---|
| 194 | currentAmbientLight(SbColor(0.2f,0.2f,0.2f)), |
|---|
| 195 | osgStateRoot(root ? root : new osg::Group) {} |
|---|
| 196 | |
|---|
| 197 | IvStateItem(const IvStateItem& i, const SoCallbackAction *action, |
|---|
| 198 | const SoNode *initiator, const int f, |
|---|
| 199 | osg::Group *root) : |
|---|
| 200 | flags(f), |
|---|
| 201 | pushInitiator(initiator), |
|---|
| 202 | inheritedTransformation(action->getModelMatrix()), |
|---|
| 203 | lastUsedTransformation(action->getModelMatrix()), |
|---|
| 204 | inheritedTexture(i.currentTexture), |
|---|
| 205 | currentTexture(i.currentTexture), |
|---|
| 206 | inheritedLights(i.currentLights), |
|---|
| 207 | currentLights(i.currentLights), |
|---|
| 208 | inheritedGLProgram(i.currentGLProgram), |
|---|
| 209 | currentGLProgram(i.currentGLProgram), |
|---|
| 210 | inheritedAmbientLight(i.inheritedAmbientLight), |
|---|
| 211 | currentAmbientLight(i.currentAmbientLight), |
|---|
| 212 | osgStateRoot(root) {} |
|---|
| 213 | }; |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | std::stack<IvStateItem> ivStateStack; |
|---|
| 217 | |
|---|
| 218 | void ivPushState(const SoCallbackAction *action, |
|---|
| 219 | const SoNode *initiator, const int flags = IvStateItem::DEFAULT_FLAGS, |
|---|
| 220 | osg::Group *root = new osg::Group); |
|---|
| 221 | void ivPopState(const SoCallbackAction *action, const SoNode *initator); |
|---|
| 222 | |
|---|
| 223 | void appendNode(osg::Node *n, const SoCallbackAction *action); |
|---|
| 224 | |
|---|
| [2225] | 225 | }; |
|---|
| 226 | |
|---|
| 227 | #endif |
|---|