From 51cfd070c64255b2d8818b42c6b3837d2c7d2d94 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sat, 9 Nov 2019 21:43:08 +0400 Subject: [PATCH] Use transformations of NiSwitchNode --- components/nifosg/nifloader.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index f32224ca84..901dccc51e 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -341,6 +341,7 @@ namespace NifOsg osg::ref_ptr switchNode (new osg::Switch); switchNode->setName(niSwitchNode->name); switchNode->setNewChildDefaultValue(false); + switchNode->setSingleChildOn(niSwitchNode->initialIndex); return switchNode; } @@ -433,7 +434,7 @@ namespace NifOsg osg::ref_ptr node; osg::Object::DataVariance dataVariance = osg::Object::UNSPECIFIED; - // TODO: it is unclear how to handle transformations of LOD and Switch nodes and controllers for them. + // TODO: it is unclear how to handle transformations of LOD nodes and controllers for them. switch (nifNode->recType) { case Nif::RC_NiLODNode: @@ -444,12 +445,6 @@ namespace NifOsg break; } case Nif::RC_NiSwitchNode: - { - const Nif::NiSwitchNode* niSwitchNode = static_cast(nifNode); - node = handleSwitchNode(niSwitchNode); - dataVariance = osg::Object::STATIC; - break; - } case Nif::RC_NiTriShape: case Nif::RC_NiTriStrips: case Nif::RC_NiAutoNormalParticles: @@ -625,6 +620,19 @@ namespace NifOsg && !nifNode->controller.empty() && node->getDataVariance() == osg::Object::DYNAMIC) handleNodeControllers(nifNode, static_cast(node.get()), animflags); + if (nifNode->recType == Nif::RC_NiSwitchNode) + { + const Nif::NiSwitchNode* niSwitchNode = static_cast(nifNode); + osg::ref_ptr switchNode = handleSwitchNode(niSwitchNode); + node->addChild(switchNode); + if (niSwitchNode->name == Constants::NightDayLabel && !SceneUtil::hasUserDescription(rootNode, Constants::NightDayLabel)) + rootNode->getOrCreateUserDataContainer()->addDescription(Constants::NightDayLabel); + else if (niSwitchNode->name == Constants::HerbalismLabel && !SceneUtil::hasUserDescription(rootNode, Constants::HerbalismLabel)) + rootNode->getOrCreateUserDataContainer()->addDescription(Constants::HerbalismLabel); + + node = switchNode; + } + const Nif::NiNode *ninode = dynamic_cast(nifNode); if(ninode) { @@ -643,16 +651,6 @@ namespace NifOsg } } - if (nifNode->recType == Nif::RC_NiSwitchNode) - { - const Nif::NiSwitchNode* niSwitchNode = static_cast(nifNode); - node->asSwitch()->setSingleChildOn(niSwitchNode->initialIndex); - if (niSwitchNode->name == Constants::NightDayLabel && !SceneUtil::hasUserDescription(rootNode, Constants::NightDayLabel)) - rootNode->getOrCreateUserDataContainer()->addDescription(Constants::NightDayLabel); - else if (niSwitchNode->name == Constants::HerbalismLabel && !SceneUtil::hasUserDescription(rootNode, Constants::HerbalismLabel)) - rootNode->getOrCreateUserDataContainer()->addDescription(Constants::HerbalismLabel); - } - return node; }