Show
Ignore:
Timestamp:
01/31/10 13:55:29 (3 years ago)
Author:
robert
Message:

From Jan Peciva, "I am sending improved version of Inventor plugin. Attaching just
modified files, while GroupSoLOD.h and .cpp was deleted. Please, delete
it from repository, it is not used any longer and I doubt if it is
probably not used for anything meaningful for a while. In the new code,
there is no GroupSoLOD. Please, delete it.

I am using new plugin version for about 1.5 month so I consider it
stable by myself.

List of changes:
- rewritten Inventor state stack
- shaders support
- light attenuation support
- support for reading from stream (readNode(std::istream& fin, options))
- improved grouping node handling (SoSeparator?, SoGroup?,...)
- fixed transformation bug when two SoShapes/Drawables? with different transformations are placed bellow one grouping node
- introduced preprocessing to handle more advanced usage schemes of SoLOD and SoSwitch? nodes
- unused code clean up
- improved notify messages
- animation callbacks fixes
- FindInventor?.cmake improved finding routines, support for Coin3 and Coin4"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/Inventor/ConvertFromInventor.h

    r9053 r11032  
    1111#include <vector> 
    1212#include <stack> 
     13#include <assert.h> 
    1314 
    1415class ConvertFromInventor 
     
    1819        ~ConvertFromInventor(); 
    1920 
     21        /// Conversts from IV to OSG scene graph 
    2022        osg::Node* convert(SoNode* rootIVNode); 
    2123 
     24        /** 
     25         * Preprocessing restructure the scene for the convertor 
     26         * to be able to convert some peculiar scene constructions. 
     27         * Resulting scene is geometrically equivalent to the source 
     28         * scene. The preprocessing is related to grouping nodes only 
     29         * (SoSeparator, SoGroup, SoLOD, SoSwitch,...) and their 
     30         * treatment with traversal state. 
     31         */ 
     32        void preprocess(SoNode *root); 
     33 
    2234    private: 
    2335 
    24         // Callback functions for converting inventor scene graph to osg  
     36        // Callback functions for converting inventor scene graph to osg 
    2537        // scene graph 
    2638 
     39        static SoCallbackAction::Response preNode(void* data, 
     40                                 SoCallbackAction* action, const SoNode* node); 
     41        static SoCallbackAction::Response postNode(void* data, 
     42                                 SoCallbackAction* action, const SoNode* node); 
     43        static SoCallbackAction::Response preTransformSeparator(void* data, 
     44                                 SoCallbackAction* action, const SoNode* node); 
     45        static SoCallbackAction::Response postTransformSeparator(void* data, 
     46                                 SoCallbackAction* action, const SoNode* node); 
     47        static SoCallbackAction::Response preLOD(void* data, 
     48                                 SoCallbackAction* action, const SoNode* node); 
     49        static SoCallbackAction::Response postLOD(void* data, 
     50                                 SoCallbackAction* action, const SoNode* node); 
    2751        static SoCallbackAction::Response preShape(void* data, 
    2852                                 SoCallbackAction* action, const SoNode* node); 
    2953        static SoCallbackAction::Response postShape(void* data, 
    3054                                 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); 
    45         static SoCallbackAction::Response postLOD(void* data, 
    46                                  SoCallbackAction* action, const SoNode* node); 
    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); 
    53         static SoCallbackAction::Response preVRMLAppearance(void* data, 
    54                                  SoCallbackAction* action, const SoNode* node); 
    55         static SoCallbackAction::Response postVRMLAppearance(void* data, 
     55        static SoCallbackAction::Response postTexture(void* data, 
     56                                 SoCallbackAction* action, const SoNode* node); 
     57        static SoCallbackAction::Response preLight(void* data, 
     58                                 SoCallbackAction* action, const SoNode* node); 
     59        static SoCallbackAction::Response preEnvironment(void* data, 
     60                                 SoCallbackAction* action, const SoNode* node); 
     61        static SoCallbackAction::Response preShaderProgram(void* data, 
     62                                 SoCallbackAction* action, const SoNode* node); 
     63        static SoCallbackAction::Response preRotor(void* data, 
     64                                 SoCallbackAction* action, const SoNode* node); 
     65        static SoCallbackAction::Response prePendulum(void* data, 
     66                                 SoCallbackAction* action, const SoNode* node); 
     67        static SoCallbackAction::Response preShuttle(void* data, 
    5668                                 SoCallbackAction* action, const SoNode* node); 
    5769        static SoCallbackAction::Response preInfo(void* data, 
     
    6880                               const SoPrimitiveVertex *v0); 
    6981 
     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 
    7089    private: 
    7190        SbString transformInfoName; 
    7291        SbName appearanceName; 
    73         bool inAppearanceWithNoTexture; 
    74  
    75         void addMatrixTransform(const std::string& name, SbVec3f axis, float angle, SbVec3f center, SbVec3f trans, SbVec3f scale); 
    76         void addVertex(SoCallbackAction* action, const SoPrimitiveVertex* v,  
     92 
     93        void addVertex(SoCallbackAction* action, const SoPrimitiveVertex* v, 
    7794                       int index); 
    7895 
    7996        osg::ref_ptr<osg::StateSet> getStateSet(SoCallbackAction* action); 
    8097 
    81         osg::Texture2D* convertIVTexToOSGTex(const SoNode* soNode,  
     98        osg::Texture2D* convertIVTexToOSGTex(const SoNode* soNode, 
    8299                                             SoCallbackAction* action); 
    83100 
     
    100117        std::vector<osg::Vec2> textureCoords; 
    101118 
    102         // Num of primitive and primitive type  
     119        // Num of primitive and primitive type 
    103120        int numPrimitives; 
    104121        osg::PrimitiveSet::Mode primitiveType; 
     
    108125        VertexOrder vertexOrder; 
    109126 
    110         // Stack of group nodes (used to build the scene graph) 
    111         std::stack<osg::Group* > groupStack; 
    112         // Stack of texture nodes (used for attaching the right texture to the 
    113         // geosets). Supported types are SoTexture2 and SoVRMLImageTexture for now. 
    114         std::stack<const SoNode*> soTexStack; 
    115  
    116127        // Mapping from SoTexture2 and SoVRMLImageTexture to already converted 
    117128        // osg::Texture2D - avoids duplication of same texture objects 
    118129        std::map<const SoNode*, osg::Texture2D*> ivToOsgTexMap; 
    119130 
    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; 
    124  
    125131        osg::ref_ptr<osg::MatrixTransform> _root;///<The root node; 
    126132 
    127         osg::ref_ptr<osg::Group> lightGroup; 
     133        /** 
     134         * IvStateItem aids lack of some state retrieval methods 
     135         * of SoCallbackAction. State is maintained in stack 
     136         * manner separately from Open Inventor. 
     137         */ 
     138        class IvStateItem { 
     139        public: 
     140 
     141            // Pop flags and node caused the push 
     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 // this has the same 
     149                          // effect as UPDATE_STATE at the present time 
     150            }; 
     151            int flags; 
     152            const SoNode *pushInitiator; 
     153 
     154            // Tracking of model transformation 
     155            SbMatrix inheritedTransformation; 
     156            SbMatrix lastUsedTransformation; 
     157 
     158            // Active texture node (used for attaching the right texture to the 
     159            // geosets). Supported types are SoTexture2 and SoVRMLImageTexture for now. 
     160            // No multitexturing yet. 
     161            const SoNode* inheritedTexture; 
     162            const SoNode* currentTexture; 
     163 
     164            // List of active lights 
     165            std::vector<osg::ref_ptr<osg::Light> > inheritedLights; 
     166            std::vector<osg::ref_ptr<osg::Light> > currentLights; 
     167 
     168            // Active OpenGL glProgram and associated shaders 
     169            osg::ref_ptr<osg::Program> inheritedGLProgram; 
     170            osg::ref_ptr<osg::Program> currentGLProgram; 
     171 
     172            // Ambient light (of SoEnvironment) 
     173            SbColor inheritedAmbientLight; 
     174            SbColor currentAmbientLight; 
     175 
     176            // Generated OSG graph 
     177            osg::ref_ptr<osg::Group> osgStateRoot; 
     178 
     179            // Extra variables 
     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        /// State stack for Inventor scene traversal 
     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 
    128225}; 
    129226