WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Plug-in development (https://forum.worldviz.com/forumdisplay.php?f=8)
-   -   How to access scene information in a C++ modifier (https://forum.worldviz.com/showthread.php?t=1031)

m7ossny 03-22-2007 10:40 PM

How to access scene information in a C++ modifier
 
Hi,

I am building a new C++ modifier for Vizard. I am intending to handle the whole scen at once.

modifier=viz.add('modifier.dlm')
logo1=viz.add('logo1.wrl')
logo2=viz.add('logo2.wrl')

viz.modify(modifier)

Well, the last command calls a native code in the dlm file in the function named "void SceneModifier(void *modifier)"

In this function i can get the whole scene through the modifier parameter.
VizModifierObj* pscenemodifier=(VizModifierObj*)modifier;
osg::Node* pnode=pscenemodifier->node.get();

The question is how to get seperate nodes declared in this scene?


Thanks alot for time, Bye.

farshizzo 03-23-2007 11:02 AM

Hi,

To get the root of each individual vizard node, you will need to create an osg::NodeVisitor that traverses the scenegraph and checks the user data of each node. Here is some sample code that will do this:
Code:

class VizNodeData : public osg::Referenced
{
public:
        VizNodeData(int id) : m_id(id) {}
        int getID() const { return m_id; }
private:
        int m_id;
};

class VizardNodeVisitor : public osg::NodeVisitor
{
public :
        VizardNodeVisitor() : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN ) {}

        virtual void apply( osg::Node &node )
        {
                VizNodeData *data = dynamic_cast(node.getUserData());
                if(data) {
                        //This is the root of a Vizard node with ID: data->getID()
                }
                traverse(node);
        }
};

Then in your SceneModifier function you will need to apply this node visitor to the scene root:
Code:

VizardNodeVisitor vnv;
((VizModifierObj*)modifier)->node->accept(vnv);

Let me know if you need anymore help.


All times are GMT -7. The time now is 09:34 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC