diff --git a/CHANGELOG.md b/CHANGELOG.md index a71222989..982184454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Bug #4820: Spell absorption is broken Bug #4827: NiUVController is handled incorrectly Bug #4828: Potion looping effects VFX are not shown for NPCs + Bug #4837: CTD when a mesh with NiLODNode root node with particles is loaded Feature #2229: Improve pathfinding AI Feature #3442: Default values for fallbacks from ini file Feature #3610: Option to invert X axis diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 52e548a69..d45f37b25 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -434,8 +434,23 @@ 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. switch (nifNode->recType) { + case Nif::RC_NiLODNode: + { + const Nif::NiLODNode* niLodNode = static_cast(nifNode); + node = handleLodNode(niLodNode); + dataVariance = osg::Object::STATIC; + 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_NiAutoNormalParticles: case Nif::RC_NiRotatingParticles: @@ -597,35 +612,6 @@ namespace NifOsg if (nifNode->recType != Nif::RC_NiTriShape && !nifNode->controller.empty() && node->getDataVariance() == osg::Object::DYNAMIC) handleNodeControllers(nifNode, static_cast(node.get()), animflags); - if (nifNode->recType == Nif::RC_NiLODNode) - { - const Nif::NiLODNode* niLodNode = static_cast(nifNode); - osg::ref_ptr lod = handleLodNode(niLodNode); - node->addChild(lod); // unsure if LOD should be above or below this node's transform - node = lod; - } - - 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); - - const Nif::NodeList &children = niSwitchNode->children; - for(size_t i = 0;i < children.length();++i) - { - if(!children[i].empty()) - handleNode(children[i].getPtr(), switchNode, imageManager, boundTextures, animflags, skipMeshes, hasMarkers, isAnimated, textKeys, rootNode); - } - - // show only first child by default - switchNode->setSingleChildOn(0); - return switchNode; - } - const Nif::NiNode *ninode = dynamic_cast(nifNode); if(ninode) { @@ -644,6 +630,16 @@ namespace NifOsg } } + if (nifNode->recType == Nif::RC_NiSwitchNode) + { + // show only first child by default + node->asSwitch()->setSingleChildOn(0); + + const Nif::NiSwitchNode* niSwitchNode = static_cast(nifNode); + if (niSwitchNode->name == Constants::NightDayLabel && !SceneUtil::hasUserDescription(rootNode, Constants::NightDayLabel)) + rootNode->getOrCreateUserDataContainer()->addDescription(Constants::NightDayLabel); + } + return node; }