coverity_scan^2
Allofich 8 years ago
parent be96ff1fd1
commit a8e9f2df67

@ -14,9 +14,8 @@ namespace MWRender
class TextureOverrideVisitor : public osg::NodeVisitor class TextureOverrideVisitor : public osg::NodeVisitor
{ {
public: public:
TextureOverrideVisitor(int refID, std::string texture, Resource::ResourceSystem* resourcesystem) TextureOverrideVisitor(std::string texture, Resource::ResourceSystem* resourcesystem)
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
, mRefID(refID)
, mTexture(texture) , mTexture(texture)
, mResourcesystem(resourcesystem) , mResourcesystem(resourcesystem)
{ {
@ -26,26 +25,21 @@ class TextureOverrideVisitor : public osg::NodeVisitor
{ {
int index; int index;
osg::ref_ptr<osg::Node> nodePtr(&node); osg::ref_ptr<osg::Node> nodePtr(&node);
if (node.getUserValue("NiTexturingPropertyIndex", index)) if (node.getUserValue("overrideFx", index))
{ {
if (mRefID == index) if (index == 1)
overrideTexture(mTexture, mResourcesystem, nodePtr); overrideTexture(mTexture, mResourcesystem, nodePtr);
} }
traverse(node); traverse(node);
} }
int mRefID;
std::string mTexture; std::string mTexture;
Resource::ResourceSystem* mResourcesystem; Resource::ResourceSystem* mResourcesystem;
}; };
void overrideFirstRootTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr<osg::Node> node) void overrideFirstRootTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr<osg::Node> node)
{ {
int index; TextureOverrideVisitor overrideVisitor(texture, resourceSystem);
if (node->getUserValue("overrideIndex", index)) node->accept(overrideVisitor);
{
TextureOverrideVisitor overrideVisitor(index, texture, resourceSystem);
node->accept(overrideVisitor);
}
} }
void overrideTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr<osg::Node> node) void overrideTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr<osg::Node> node)

@ -277,11 +277,13 @@ namespace NifOsg
public: public:
/// @param filename used for warning messages. /// @param filename used for warning messages.
LoaderImpl(const std::string& filename) LoaderImpl(const std::string& filename)
: mFilename(filename) : mFilename(filename), mFirstRootTextureIndex(-1), mFoundFirstRootTexturingProperty(false)
{ {
} }
std::string mFilename; std::string mFilename;
size_t mFirstRootTextureIndex;
bool mFoundFirstRootTexturingProperty;
static void loadKf(Nif::NIFFilePtr nif, KeyframeHolder& target) static void loadKf(Nif::NIFFilePtr nif, KeyframeHolder& target)
{ {
@ -372,26 +374,21 @@ namespace NifOsg
void applyNodeProperties(const Nif::Node *nifNode, osg::Node *applyTo, SceneUtil::CompositeStateSetUpdater* composite, Resource::ImageManager* imageManager, std::vector<int>& boundTextures, int animflags) void applyNodeProperties(const Nif::Node *nifNode, osg::Node *applyTo, SceneUtil::CompositeStateSetUpdater* composite, Resource::ImageManager* imageManager, std::vector<int>& boundTextures, int animflags)
{ {
const Nif::PropertyList& props = nifNode->props; const Nif::PropertyList& props = nifNode->props;
bool foundFirstRootTexturingProperty = false;
for (size_t i = 0; i <props.length(); ++i) for (size_t i = 0; i <props.length(); ++i)
{ {
if (!props[i].empty()) if (!props[i].empty())
{ {
// store the recIndex of the NiTexturingProperty. Used for spells when overriding textures. // Get the lowest numbered recIndex of the NiTexturingProperty root node.
// Get the lowest numbered one for the root node. This is what is overridden when a spell // This is what is overridden when a spell effect "particle texture" is used.
// effect "particle texture" is used. For non-root nodes we keep setting until we have the highest if (nifNode->parent == NULL && !mFoundFirstRootTexturingProperty && props[i].getPtr()->recType == Nif::RC_NiTexturingProperty)
// numbered one, which is the one that displays in the game and can be overridden if it matches the
// lowest one on the root.
if (!foundFirstRootTexturingProperty && nifNode->parent == NULL && props[i].getPtr()->recType == Nif::RC_NiTexturingProperty)
{ {
int index = props[i].getPtr()->recIndex; mFirstRootTextureIndex = props[i].getPtr()->recIndex;
applyTo->setUserValue("overrideIndex", index); mFoundFirstRootTexturingProperty = true;
foundFirstRootTexturingProperty = true;
} }
else if (props[i].getPtr()->recType == Nif::RC_NiTexturingProperty) else if (props[i].getPtr()->recType == Nif::RC_NiTexturingProperty)
{ {
int index = props[i].getPtr()->recIndex; if (props[i].getPtr()->recIndex == mFirstRootTextureIndex)
applyTo->setUserValue("NiTexturingPropertyIndex", index); applyTo->setUserValue("overrideFx", 1);
} }
handleProperty(props[i].getPtr(), applyTo, composite, imageManager, boundTextures, animflags); handleProperty(props[i].getPtr(), applyTo, composite, imageManager, boundTextures, animflags);
} }

Loading…
Cancel
Save