mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 15:09:39 +00:00
initial NiFltAnimationNode support
This commit is contained in:
parent
8b2c5e4801
commit
ead73fce31
7 changed files with 62 additions and 1 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <osg/Version>
|
||||
#include <osg/LOD>
|
||||
#include <osg/Switch>
|
||||
#include <osg/Sequence>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/Material>
|
||||
#include <osgUtil/IncrementalCompileOperation>
|
||||
|
@ -152,6 +153,13 @@ namespace MWRender
|
|||
n->setDataVariance(osg::Object::STATIC);
|
||||
return n;
|
||||
}
|
||||
if (const osg::Sequence* sq = dynamic_cast<const osg::Sequence*>(node))
|
||||
{
|
||||
osg::Group* n = new osg::Group;
|
||||
n->addChild(operator()(sq->getChild(sq->getValue())));
|
||||
n->setDataVariance(osg::Object::STATIC);
|
||||
return n;
|
||||
}
|
||||
|
||||
mNodePath.push_back(node);
|
||||
|
||||
|
@ -301,6 +309,11 @@ namespace MWRender
|
|||
traverse(*lod->getChild(i));
|
||||
return;
|
||||
}
|
||||
if (osg::Sequence* sq = dynamic_cast<osg::Sequence*>(&node))
|
||||
{
|
||||
traverse(*sq->getChild(sq->getValue()));
|
||||
return;
|
||||
}
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ static std::map<std::string, CreateRecord> makeFactory()
|
|||
{"NiNode" , &construct <NiNode , RC_NiNode >},
|
||||
{"NiSwitchNode" , &construct <NiSwitchNode , RC_NiSwitchNode >},
|
||||
{"NiLODNode" , &construct <NiLODNode , RC_NiLODNode >},
|
||||
{"NiFltAnimationNode" , &construct <NiFltAnimationNode , RC_NiFltAnimationNode >},
|
||||
{"AvoidNode" , &construct <NiNode , RC_AvoidNode >},
|
||||
{"NiCollisionSwitch" , &construct <NiNode , RC_NiCollisionSwitch >},
|
||||
{"NiBSParticleNode" , &construct <NiNode , RC_NiBSParticleNode >},
|
||||
|
|
|
@ -431,6 +431,17 @@ struct NiLODNode : public NiSwitchNode
|
|||
}
|
||||
};
|
||||
|
||||
struct NiFltAnimationNode : public NiSwitchNode
|
||||
{
|
||||
float Interval;
|
||||
|
||||
void read(NIFStream *nif) override
|
||||
{
|
||||
NiSwitchNode::read(nif);
|
||||
Interval = nif->getFloat();
|
||||
}
|
||||
};
|
||||
|
||||
// Abstract
|
||||
struct NiAccumulator : Record
|
||||
{
|
||||
|
|
|
@ -38,6 +38,7 @@ enum RecordType
|
|||
RC_NiNode,
|
||||
RC_NiSwitchNode,
|
||||
RC_NiLODNode,
|
||||
RC_NiFltAnimationNode,
|
||||
RC_NiBillboardNode,
|
||||
RC_AvoidNode,
|
||||
RC_NiCollisionSwitch,
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <osg/Array>
|
||||
#include <osg/LOD>
|
||||
#include <osg/Switch>
|
||||
#include <osg/Sequence>
|
||||
#include <osg/TexGen>
|
||||
#include <osg/ValueObject>
|
||||
|
||||
|
@ -416,6 +417,17 @@ namespace NifOsg
|
|||
return switchNode;
|
||||
}
|
||||
|
||||
static osg::ref_ptr<osg::Sequence> handleSequenceNode(const Nif::NiFltAnimationNode* niFltAnimationNode)
|
||||
{
|
||||
osg::ref_ptr<osg::Sequence> sequenceNode (new osg::Sequence);
|
||||
sequenceNode->setName(niFltAnimationNode->name);
|
||||
sequenceNode->setDefaultTime(niFltAnimationNode->Interval);
|
||||
sequenceNode->setInterval(osg::Sequence::LOOP, 0,-1);
|
||||
sequenceNode->setDuration( -1.0f, -1);
|
||||
sequenceNode->setMode(osg::Sequence::START);
|
||||
return sequenceNode;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Image> handleSourceTexture(const Nif::NiSourceTexture* st, Resource::ImageManager* imageManager)
|
||||
{
|
||||
if (!st)
|
||||
|
@ -711,6 +723,13 @@ namespace NifOsg
|
|||
node->addChild(lodNode);
|
||||
currentNode = lodNode;
|
||||
}
|
||||
else if (nifNode->recType == Nif::RC_NiFltAnimationNode)
|
||||
{
|
||||
const Nif::NiFltAnimationNode* niFltAnimationNode = static_cast<const Nif::NiFltAnimationNode*>(nifNode);
|
||||
osg::ref_ptr<osg::Sequence> sequenceNode = handleSequenceNode(niFltAnimationNode);
|
||||
node->addChild(sequenceNode);
|
||||
currentNode = sequenceNode;
|
||||
}
|
||||
|
||||
const Nif::NiNode *ninode = dynamic_cast<const Nif::NiNode*>(nifNode);
|
||||
if(ninode)
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <osg/MatrixTransform>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/LOD>
|
||||
#include <osg/Sequence>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Notify>
|
||||
|
@ -845,7 +846,7 @@ void Optimizer::RemoveEmptyNodesVisitor::removeEmptyNodes()
|
|||
++pitr)
|
||||
{
|
||||
osg::Group* parent = *pitr;
|
||||
if (!parent->asSwitch() && !dynamic_cast<osg::LOD*>(parent))
|
||||
if (!parent->asSwitch() && !dynamic_cast<osg::LOD*>(parent) && !dynamic_cast<osg::Sequence*>(parent))
|
||||
{
|
||||
parent->removeChild(nodeToRemove.get());
|
||||
if (parent->getNumChildren()==0 && isOperationPermissibleForObject(parent)) newEmptyGroups.insert(parent);
|
||||
|
@ -887,6 +888,13 @@ void Optimizer::RemoveRedundantNodesVisitor::apply(osg::Switch& switchNode)
|
|||
traverse(*switchNode.getChild(i));
|
||||
}
|
||||
|
||||
void Optimizer::RemoveRedundantNodesVisitor::apply(osg::Sequence& sequenceNode)
|
||||
{
|
||||
// We should keep all sequence child nodes since they reflect different sequence states.
|
||||
for (unsigned int i=0; i<sequenceNode.getNumChildren(); ++i)
|
||||
traverse(*sequenceNode.getChild(i));
|
||||
}
|
||||
|
||||
void Optimizer::RemoveRedundantNodesVisitor::apply(osg::Group& group)
|
||||
{
|
||||
if (typeid(group)==typeid(osg::Group) &&
|
||||
|
@ -1951,6 +1959,12 @@ void Optimizer::MergeGroupsVisitor::apply(osg::Switch &switchNode)
|
|||
traverse(switchNode);
|
||||
}
|
||||
|
||||
void Optimizer::MergeGroupsVisitor::apply(osg::Sequence &sequenceNode)
|
||||
{
|
||||
// We should keep all sequence child nodes since they reflect different sequence states.
|
||||
traverse(sequenceNode);
|
||||
}
|
||||
|
||||
void Optimizer::MergeGroupsVisitor::apply(osg::Group &group)
|
||||
{
|
||||
if (group.getNumChildren() <= 1)
|
||||
|
|
|
@ -362,6 +362,7 @@ class Optimizer
|
|||
void apply(osg::Transform& transform) override;
|
||||
void apply(osg::LOD& lod) override;
|
||||
void apply(osg::Switch& switchNode) override;
|
||||
void apply(osg::Sequence& sequenceNode) override;
|
||||
void apply(osg::Geometry&) override { }
|
||||
|
||||
bool isOperationPermissible(osg::Node& node);
|
||||
|
@ -385,6 +386,7 @@ class Optimizer
|
|||
void apply(osg::Group& group) override;
|
||||
void apply(osg::LOD& lod) override;
|
||||
void apply(osg::Switch& switchNode) override;
|
||||
void apply(osg::Sequence& sequenceNode) override;
|
||||
};
|
||||
|
||||
class MergeGeometryVisitor : public BaseOptimizerVisitor
|
||||
|
|
Loading…
Reference in a new issue