1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-07 07:45:35 +00:00

Propagate dynamic effects to node's immediate children (bug #6550)

This commit is contained in:
Alexei Kotov 2023-02-11 17:03:21 +03:00
parent 5f1da29881
commit 9deed5c03e
2 changed files with 19 additions and 11 deletions

View file

@ -15,6 +15,7 @@
Bug #5977: Fatigueless NPCs' corpse underwater changes animation on game load Bug #5977: Fatigueless NPCs' corpse underwater changes animation on game load
Bug #6313: Followers with high Fight can turn hostile Bug #6313: Followers with high Fight can turn hostile
Bug #6427: Enemy health bar disappears before damaging effect ends 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 #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 #6661: Saved games that have no preview screenshot cause issues or crashes
Bug #6807: Ultimate Galleon is not working properly Bug #6807: Ultimate Galleon is not working properly

View file

@ -502,12 +502,12 @@ namespace NifOsg
return image; 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) if (nifNode->recType != Nif::RC_NiTextureEffect)
{ {
Log(Debug::Info) << "Unhandled effect " << nifNode->recName << " in " << mFilename; Log(Debug::Info) << "Unhandled effect " << nifNode->recName << " in " << mFilename;
return; return false;
} }
const Nif::NiTextureEffect* textureEffect = static_cast<const Nif::NiTextureEffect*>(nifNode); const Nif::NiTextureEffect* textureEffect = static_cast<const Nif::NiTextureEffect*>(nifNode);
@ -515,13 +515,13 @@ namespace NifOsg
{ {
Log(Debug::Info) << "Unhandled NiTextureEffect type " << textureEffect->textureType << " in " Log(Debug::Info) << "Unhandled NiTextureEffect type " << textureEffect->textureType << " in "
<< mFilename; << mFilename;
return; return false;
} }
if (textureEffect->texture.empty()) if (textureEffect->texture.empty())
{ {
Log(Debug::Info) << "NiTextureEffect missing source texture in " << mFilename; Log(Debug::Info) << "NiTextureEffect missing source texture in " << mFilename;
return; return false;
} }
osg::ref_ptr<osg::TexGen> texGen(new osg::TexGen); osg::ref_ptr<osg::TexGen> texGen(new osg::TexGen);
@ -539,7 +539,7 @@ namespace NifOsg
default: default:
Log(Debug::Info) << "Unhandled NiTextureEffect coordGenType " << textureEffect->coordGenType Log(Debug::Info) << "Unhandled NiTextureEffect coordGenType " << textureEffect->coordGenType
<< " in " << mFilename; << " in " << mFilename;
return; return false;
} }
osg::ref_ptr<osg::Image> image(handleSourceTexture(textureEffect->texture.getPtr(), imageManager)); osg::ref_ptr<osg::Image> image(handleSourceTexture(textureEffect->texture.getPtr(), imageManager));
@ -554,12 +554,12 @@ namespace NifOsg
int texUnit = 3; // FIXME int texUnit = 3; // FIXME
osg::StateSet* stateset = node->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(texUnit, texture2d, osg::StateAttribute::ON);
stateset->setTextureAttributeAndModes(texUnit, texGen, osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(texUnit, texGen, osg::StateAttribute::ON);
stateset->setTextureAttributeAndModes(texUnit, createEmissiveTexEnv(), osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(texUnit, createEmissiveTexEnv(), osg::StateAttribute::ON);
stateset->addUniform(new osg::Uniform("envMapColor", osg::Vec4f(1, 1, 1, 1))); 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 // 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<const Nif::NiNode*>(nifNode); const Nif::NiNode* ninode = dynamic_cast<const Nif::NiNode*>(nifNode);
if (ninode) 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::NodeList& children = ninode->children;
const Nif::Parent currentParent{ *ninode, parent }; const Nif::Parent currentParent{ *ninode, parent };
for (const auto& child : children) for (const auto& child : children)
if (!child.empty()) if (!child.empty())
handleNode(child.getPtr(), &currentParent, currentNode, imageManager, boundTextures, animflags, handleNode(child.getPtr(), &currentParent, currentNode, imageManager, boundTextures, animflags,
skipMeshes, hasMarkers, hasAnimatedParents, textKeys, rootNode); 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<osg::StateSet> 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) if (nifNode->recType == Nif::RC_NiFltAnimationNode)