I have a question about Switch.

classic Classic list List threaded Threaded
3 messages Options
newlife958 newlife958
Reply | Threaded
Open this post in threaded view
|

I have a question about Switch.

There are two models with four levels of switches.
Changing the steps of the switch causes a phenomenon that applies to all models.

I want to have a separate switch step for each model, what should I do?

Attach the code implemented below.

========================================================
class SwitchDOFVisitor : public osg::NodeVisitor
{
public:
        SwitchDOFVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { }

        SwitchDOFVisitor(const SwitchDOFVisitor& sdfv, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) {}
        META_Object(osg, SwitchDOFVisitor)

        virtual void apply(osg::Group& node)
        {
                osgSim::MultiSwitch* pMSwitch = dynamic_cast<osgSim::MultiSwitch*>(&node);
                if (pMSwitch)
                {
                        mSwitches.push_back(pMSwitch);
                }

                osg::NodeVisitor::apply(node);
        }

        void nextSwitch(int switchStep)
        {
                for (size_t i = 0; i < mSwitches.size(); i++)
                {
                        mSwitches[i]->setActiveSwitchSet(switchStep);
                }
        }

private:
        std::vector<osgSim::MultiSwitch*> mSwitches;
};

------------------------------
//create model 1
osg::Node* model = ModelLoader::GetInstance()->getModel(layer);
osg::ref_ptr<SwitchDOFVisitor> _visit = new SwitchDOFVisitor;
model->accept(*_visit);

//create model 2
osg::Node* model2 = ModelLoader::GetInstance()->getModel(layer2);
osg::ref_ptr<SwitchDOFVisitor> _visit2 = new SwitchDOFVisitor;
model2->accept(*_visit2);
...
...
-----------------------------------
//changing switch step
GetLayer(index)->GetVisitor()->nextSwitch(switchStep);

===========================================================
stevenj279 stevenj279
Reply | Threaded
Open this post in threaded view
|

Re: I have a question about Switch.

This is also of great help to me! Out of curiosity, are you changing the appearance states of 3D models, such as for aircraft gear down, up, props on or off, etc? If so, where or how are you specifying the state number in the code?

On Wed, Jul 8, 2020, 3:17 AM newlife958 [via osgEarth] <[hidden email]> wrote:
There are two models with four levels of switches.
Changing the steps of the switch causes a phenomenon that applies to all models.

I want to have a separate switch step for each model, what should I do?

Provide the code applied below.

========================================================
class SwitchDOFVisitor : public osg::NodeVisitor
{
public:
        SwitchDOFVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { }

        SwitchDOFVisitor(const SwitchDOFVisitor& sdfv, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) {}
        META_Object(osg, SwitchDOFVisitor)

        virtual void apply(osg::Group& node)
        {
                osgSim::MultiSwitch* pMSwitch = dynamic_cast<osgSim::MultiSwitch*>(&node);
                if (pMSwitch)
                {
                        mSwitches.push_back(pMSwitch);
                }

                osg::NodeVisitor::apply(node);
        }

        void nextSwitch(int switchStep)
        {
                for (size_t i = 0; i < mSwitches.size(); i++)
                {
                        mSwitches[i]->setActiveSwitchSet(switchStep);
                }
        }

private:
        std::vector<osgSim::MultiSwitch*> mSwitches;
};

------------------------------
//create model 1
osg::Node* model = ModelLoader::GetInstance()->getModel(layer);
osg::ref_ptr<SwitchDOFVisitor> _visit = new SwitchDOFVisitor;
model->accept(*_visit);

//create model 2
osg::Node* model2 = ModelLoader::GetInstance()->getModel(layer2);
osg::ref_ptr<SwitchDOFVisitor> _visit2 = new SwitchDOFVisitor;
model2->accept(*_visit2);
...
...
-----------------------------------
//changing switch step
GetLayer(index)->GetVisitor()->nextSwitch(switchStep);

===========================================================


If you reply to this email, your message will be added to the discussion below:
http://forum.osgearth.org/I-have-a-question-about-Switch-tp7593256.html
To unsubscribe from osgEarth, click here.
NAML
S. Jones
Sr Aviation Analyst
Modeling & Simulation Engineer using OSG, OSG Earth and other open source GIS-related apps.
newlife958 newlife958
Reply | Threaded
Open this post in threaded view
|

Re: I have a question about Switch.

hi, S. Jones.

The state number is used by designating the switch step as an own property when creating the FLT model.