Support NiSwitchNode (feature #4812)

pull/2141/head
Andrei Kortunov 5 years ago
parent 6fd4d016eb
commit 2c38e337ae

@ -26,6 +26,7 @@
Feature #3610: Option to invert X axis
Feature #4673: Weapon sheathing
Feature #4730: Native animated containers support
Feature #4812: Support NiSwitchNode
Task #4686: Upgrade media decoder to a more current FFmpeg API
0.45.0

@ -5,6 +5,7 @@
#include <osg/Geometry>
#include <osg/Array>
#include <osg/LOD>
#include <osg/Switch>
#include <osg/TexGen>
#include <osg/ValueObject>
@ -335,6 +336,13 @@ namespace NifOsg
return lod;
}
osg::ref_ptr<osg::Switch> handleSwitchNode(const Nif::NiSwitchNode* niSwitchNode)
{
osg::ref_ptr<osg::Switch> switchNode (new osg::Switch);
switchNode->setNewChildDefaultValue(false);
return switchNode;
}
osg::ref_ptr<osg::Image> handleSourceTexture(const Nif::NiSourceTexture* st, Resource::ImageManager* imageManager)
{
if (!st)
@ -593,6 +601,23 @@ namespace NifOsg
node = lod;
}
if (nifNode->recType == Nif::RC_NiSwitchNode)
{
const Nif::NiSwitchNode* niSwitchNode = static_cast<const Nif::NiSwitchNode*>(nifNode);
osg::ref_ptr<osg::Switch> switchNode = handleSwitchNode(niSwitchNode);
node->addChild(switchNode);
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<const Nif::NiNode*>(nifNode);
if(ninode)
{

@ -807,6 +807,13 @@ void Optimizer::RemoveRedundantNodesVisitor::apply(osg::LOD& lod)
traverse(*lod.getChild(i));
}
void Optimizer::RemoveRedundantNodesVisitor::apply(osg::Switch& switchNode)
{
// We should keep all switch child nodes since they reflect different switch states.
for (unsigned int i=0; i<switchNode.getNumChildren(); ++i)
traverse(*switchNode.getChild(i));
}
void Optimizer::RemoveRedundantNodesVisitor::apply(osg::Group& group)
{
if (typeid(group)==typeid(osg::Group) &&
@ -1862,6 +1869,12 @@ void Optimizer::MergeGroupsVisitor::apply(osg::LOD &lod)
traverse(lod);
}
void Optimizer::MergeGroupsVisitor::apply(osg::Switch &switchNode)
{
// We should keep all switch child nodes since they reflect different switch states.
traverse(switchNode);
}
void Optimizer::MergeGroupsVisitor::apply(osg::Group &group)
{
if (group.getNumChildren() <= 1)

@ -340,6 +340,7 @@ class Optimizer
virtual void apply(osg::Group& group);
virtual void apply(osg::Transform& transform);
virtual void apply(osg::LOD& lod);
virtual void apply(osg::Switch& switchNode);
bool isOperationPermissible(osg::Node& node);
@ -360,6 +361,7 @@ class Optimizer
virtual void apply(osg::Group& group);
virtual void apply(osg::LOD& lod);
virtual void apply(osg::Switch& switchNode);
};
class MergeGeometryVisitor : public BaseOptimizerVisitor

Loading…
Cancel
Save