diff --git a/CHANGELOG.md b/CHANGELOG.md index 9185e2d49e..f59c8ef26d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Bug #5977: Fatigueless NPCs' corpse underwater changes animation on game load Bug #6313: Followers with high Fight can turn hostile Bug #6427: Enemy health bar disappears before damaging effect ends + Bug #6550: Cloned body parts don't inherit texture effects Bug #6645: Enemy block sounds align with animation instead of blocked hits Bug #6661: Saved games that have no preview screenshot cause issues or crashes Bug #6807: Ultimate Galleon is not working properly diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index eaf49bb61d..0c0bd4295c 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -502,12 +502,12 @@ namespace NifOsg return image; } - void handleEffect(const Nif::Node* nifNode, osg::Node* node, Resource::ImageManager* imageManager) + bool handleEffect(const Nif::Node* nifNode, osg::StateSet* stateset, Resource::ImageManager* imageManager) { if (nifNode->recType != Nif::RC_NiTextureEffect) { Log(Debug::Info) << "Unhandled effect " << nifNode->recName << " in " << mFilename; - return; + return false; } const Nif::NiTextureEffect* textureEffect = static_cast(nifNode); @@ -515,13 +515,13 @@ namespace NifOsg { Log(Debug::Info) << "Unhandled NiTextureEffect type " << textureEffect->textureType << " in " << mFilename; - return; + return false; } if (textureEffect->texture.empty()) { Log(Debug::Info) << "NiTextureEffect missing source texture in " << mFilename; - return; + return false; } osg::ref_ptr texGen(new osg::TexGen); @@ -539,7 +539,7 @@ namespace NifOsg default: Log(Debug::Info) << "Unhandled NiTextureEffect coordGenType " << textureEffect->coordGenType << " in " << mFilename; - return; + return false; } osg::ref_ptr image(handleSourceTexture(textureEffect->texture.getPtr(), imageManager)); @@ -554,12 +554,12 @@ namespace NifOsg int texUnit = 3; // FIXME - osg::StateSet* stateset = node->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(texUnit, texGen, osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(texUnit, createEmissiveTexEnv(), osg::StateAttribute::ON); stateset->addUniform(new osg::Uniform("envMapColor", osg::Vec4f(1, 1, 1, 1))); + return true; } // Get a default dataVariance for this node to be used as a hint by optimization (post)routines @@ -798,17 +798,24 @@ namespace NifOsg const Nif::NiNode* ninode = dynamic_cast(nifNode); if (ninode) { - const Nif::NodeList& effects = ninode->effects; - for (const auto& effect : effects) - if (!effect.empty()) - handleEffect(effect.getPtr(), currentNode, imageManager); - const Nif::NodeList& children = ninode->children; const Nif::Parent currentParent{ *ninode, parent }; for (const auto& child : children) if (!child.empty()) handleNode(child.getPtr(), ¤tParent, currentNode, imageManager, boundTextures, animflags, skipMeshes, hasMarkers, hasAnimatedParents, textKeys, rootNode); + + // Propagate effects to the the direct subgraph instead of the node itself + // This simulates their "affected node list" which Morrowind appears to replace with the subgraph (?) + // Note that the serialized affected node list is actually unused + for (const auto& effect : ninode->effects) + if (!effect.empty()) + { + osg::ref_ptr effectStateSet = new osg::StateSet; + if (handleEffect(effect.getPtr(), effectStateSet, imageManager)) + for (unsigned int i = 0; i < currentNode->getNumChildren(); ++i) + currentNode->getChild(i)->getOrCreateStateSet()->merge(*effectStateSet); + } } if (nifNode->recType == Nif::RC_NiFltAnimationNode)