root/OpenSceneGraph/trunk/src/osgPlugins/Inventor/ConvertFromInventor.h @ 9053

Revision 9053, 5.6 kB (checked in by robert, 6 years ago)

From Jim Vaughan,

- Matrix transform nodes were stripped out, and the
vertices and normals of each node were
transposed by the modelling matrix. My change preserves
the matrix transform nodes, so that
models can still be articulated by changing the matrices.

- Lights were copied from the COIN scenegraph to the OSG
scenegraph, but they were not associated
with a LightSource? node. My change for this creates a
Group and adds a LightSource? for each Light.

- If VRML textures have names, the name is now copied to

--

Form Robert Osfild, changed SbString? to std::string usage

M Inventor/ConvertFromInventor.h
M Inventor/ConvertFromInventor.cpp

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[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>
13
[6543]14class ConvertFromInventor
[2225]15{
16    public:
17        ConvertFromInventor();
18        ~ConvertFromInventor();
[6543]19
20        osg::Node* convert(SoNode* rootIVNode);
21
[2225]22    private:
23
24        // Callback functions for converting inventor scene graph to osg
25        // scene graph
26
27        static SoCallbackAction::Response preShape(void* data,
28                                 SoCallbackAction* action, const SoNode* node);
29        static SoCallbackAction::Response postShape(void* data,
30                                 SoCallbackAction* action, const SoNode* node);
31        static SoCallbackAction::Response preGroup(void* data,
32                                 SoCallbackAction* action, const SoNode* node);
33        static SoCallbackAction::Response postGroup(void* data,
34                                 SoCallbackAction* action, const SoNode* node);
35        static SoCallbackAction::Response preTexture(void* data,
36                                 SoCallbackAction* action, const SoNode* node);
37        static SoCallbackAction::Response preLight(void* data,
38                                 SoCallbackAction* action, const SoNode* node);
39        static SoCallbackAction::Response preRotor(void* data,
40                                 SoCallbackAction* action, const SoNode* node);
41        static SoCallbackAction::Response prePendulum(void* data,
42                                 SoCallbackAction* action, const SoNode* node);
43        static SoCallbackAction::Response preShuttle(void* data,
44                                 SoCallbackAction* action, const SoNode* node);
[6543]45        static SoCallbackAction::Response postLOD(void* data,
[2225]46                                 SoCallbackAction* action, const SoNode* node);
[6543]47        ///Callback for VRMLImageTexture
48        ///\param data The pointer to ConvertFromInventor object
49        ///\param action The action handling class
50        ///\param node The current VRMLImageTexture node
51        static SoCallbackAction::Response preVRMLImageTexture(void* data,
52                                 SoCallbackAction* action, const SoNode* node);
[9053]53        static SoCallbackAction::Response preVRMLAppearance(void* data,
54                                 SoCallbackAction* action, const SoNode* node);
55        static SoCallbackAction::Response postVRMLAppearance(void* data,
56                                 SoCallbackAction* action, const SoNode* node);
57        static SoCallbackAction::Response preInfo(void* data,
58                                 SoCallbackAction* action, const SoNode* node);
[2225]59
60        static void addTriangleCB(void* data, SoCallbackAction* action,
[5802]61                              const SoPrimitiveVertex *v0,
[2225]62                                  const SoPrimitiveVertex *v1,
63                                  const SoPrimitiveVertex *v2);
64        static void addLineSegmentCB(void* data, SoCallbackAction* action,
65                                     const SoPrimitiveVertex *v0,
66                                     const SoPrimitiveVertex *v1);
67        static void addPointCB(void* data, SoCallbackAction* action,
68                               const SoPrimitiveVertex *v0);
[6543]69
[2225]70    private:
[9053]71        SbString transformInfoName;
72        SbName appearanceName;
73        bool inAppearanceWithNoTexture;
[2225]74
[9053]75        void addMatrixTransform(const std::string& name, SbVec3f axis, float angle, SbVec3f center, SbVec3f trans, SbVec3f scale);
[2225]76        void addVertex(SoCallbackAction* action, const SoPrimitiveVertex* v,
77                       int index);
78
[6543]79        osg::ref_ptr<osg::StateSet> getStateSet(SoCallbackAction* action);
[2225]80
[6543]81        osg::Texture2D* convertIVTexToOSGTex(const SoNode* soNode,
82                                             SoCallbackAction* action);
[2225]83
84        void transformLight(SoCallbackAction* action, const SbVec3f& vec,
85                            osg::Vec3& transVec);
86
87        // OSG doesn't seem to have a transpose function for matrices
88        void transposeMatrix(osg::Matrix& mat);
[6543]89
[2225]90    private:
91
92        // Normal and color binding
93        osg::Geometry::AttributeBinding normalBinding;
94        osg::Geometry::AttributeBinding colorBinding;
95
96        // List of vertices, normals, colors and texture coordinates
97        std::vector<osg::Vec3> vertices;
98        std::vector<osg::Vec3> normals;
99        std::vector<osg::Vec4> colors;
100        std::vector<osg::Vec2> textureCoords;
101
102        // Num of primitive and primitive type
103        int numPrimitives;
104        osg::PrimitiveSet::Mode primitiveType;
105
106        // Vertex ordering
107        enum VertexOrder { CLOCKWISE, COUNTER_CLOCKWISE };
108        VertexOrder vertexOrder;
109
110        // Stack of group nodes (used to build the scene graph)
[5802]111        std::stack<osg::Group* > groupStack;
[2225]112        // Stack of texture nodes (used for attaching the right texture to the
[6543]113        // geosets). Supported types are SoTexture2 and SoVRMLImageTexture for now.
114        std::stack<const SoNode*> soTexStack;
[2225]115
[6543]116        // Mapping from SoTexture2 and SoVRMLImageTexture to already converted
117        // osg::Texture2D - avoids duplication of same texture objects
118        std::map<const SoNode*, osg::Texture2D*> ivToOsgTexMap;
[2225]119
120        // Stack to maintain the list of lights at each level of the
121        // scenegraph
122        typedef std::vector<osg::Light *> LightList;
123        std::stack<LightList> lightStack;
[5802]124
125        osg::ref_ptr<osg::MatrixTransform> _root;///<The root node;
[9053]126
127        osg::ref_ptr<osg::Group> lightGroup;
[2225]128};
129
130#endif
Note: See TracBrowser for help on using the browser.