mirror of
https://github.com/OpenMW/openmw.git
synced 2025-07-08 20:41:35 +00:00
refactor for NiFltAnimationNode
This commit is contained in:
parent
c376f3793e
commit
373776170d
2 changed files with 28 additions and 12 deletions
|
@ -433,17 +433,17 @@ struct NiLODNode : public NiSwitchNode
|
||||||
|
|
||||||
struct NiFltAnimationNode : public NiSwitchNode
|
struct NiFltAnimationNode : public NiSwitchNode
|
||||||
{
|
{
|
||||||
float mInterval;
|
float mDuration;
|
||||||
enum Flags
|
enum Flags
|
||||||
{
|
{
|
||||||
Flag_Reverse = 0x40
|
Flag_Swing = 0x40
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void read(NIFStream *nif) override
|
void read(NIFStream *nif) override
|
||||||
{
|
{
|
||||||
NiSwitchNode::read(nif);
|
NiSwitchNode::read(nif);
|
||||||
mInterval = nif->getFloat();
|
mDuration = nif->getFloat();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -417,19 +417,33 @@ namespace NifOsg
|
||||||
return switchNode;
|
return switchNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static osg::ref_ptr<osg::Sequence> handleSequenceNode(const Nif::NiFltAnimationNode* niFltAnimationNode)
|
static osg::ref_ptr<osg::Sequence> prepareSequenceNode(const Nif::Node* nifNode)
|
||||||
{
|
{
|
||||||
|
const Nif::NiFltAnimationNode* niFltAnimationNode = static_cast<const Nif::NiFltAnimationNode*>(nifNode);
|
||||||
osg::ref_ptr<osg::Sequence> sequenceNode (new osg::Sequence);
|
osg::ref_ptr<osg::Sequence> sequenceNode (new osg::Sequence);
|
||||||
sequenceNode->setName(niFltAnimationNode->name);
|
sequenceNode->setName(niFltAnimationNode->name);
|
||||||
sequenceNode->setDefaultTime(niFltAnimationNode->mInterval);
|
if (niFltAnimationNode->children.length()!=0)
|
||||||
sequenceNode->setMode(osg::Sequence::START);
|
{
|
||||||
if (niFltAnimationNode->flags & Nif::NiFltAnimationNode::Flag_Reverse)
|
if (niFltAnimationNode->flags & Nif::NiFltAnimationNode::Flag_Swing)
|
||||||
sequenceNode->setDuration(0.2f, -1);
|
sequenceNode->setDefaultTime(niFltAnimationNode->mDuration/(niFltAnimationNode->children.length()*2));
|
||||||
else
|
else
|
||||||
sequenceNode->setDuration(-0.2f, -1);
|
sequenceNode->setDefaultTime(niFltAnimationNode->mDuration/niFltAnimationNode->children.length());
|
||||||
|
}
|
||||||
return sequenceNode;
|
return sequenceNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void activateSequenceNode(osg::Group* osgNode, const Nif::Node* nifNode)
|
||||||
|
{
|
||||||
|
const Nif::NiFltAnimationNode* niFltAnimationNode = static_cast<const Nif::NiFltAnimationNode*>(nifNode);
|
||||||
|
osg::Sequence* sequenceNode = static_cast<osg::Sequence*>(osgNode);
|
||||||
|
if (niFltAnimationNode->flags & Nif::NiFltAnimationNode::Flag_Swing)
|
||||||
|
sequenceNode->setInterval(osg::Sequence::SWING, 0,-1);
|
||||||
|
else
|
||||||
|
sequenceNode->setInterval(osg::Sequence::LOOP, 0,-1);
|
||||||
|
sequenceNode->setDuration(1.0f, -1);
|
||||||
|
sequenceNode->setMode(osg::Sequence::START);
|
||||||
|
}
|
||||||
|
|
||||||
osg::ref_ptr<osg::Image> handleSourceTexture(const Nif::NiSourceTexture* st, Resource::ImageManager* imageManager)
|
osg::ref_ptr<osg::Image> handleSourceTexture(const Nif::NiSourceTexture* st, Resource::ImageManager* imageManager)
|
||||||
{
|
{
|
||||||
if (!st)
|
if (!st)
|
||||||
|
@ -727,8 +741,7 @@ namespace NifOsg
|
||||||
}
|
}
|
||||||
else if (nifNode->recType == Nif::RC_NiFltAnimationNode)
|
else if (nifNode->recType == Nif::RC_NiFltAnimationNode)
|
||||||
{
|
{
|
||||||
const Nif::NiFltAnimationNode* niFltAnimationNode = static_cast<const Nif::NiFltAnimationNode*>(nifNode);
|
osg::ref_ptr<osg::Sequence> sequenceNode = prepareSequenceNode(nifNode);
|
||||||
osg::ref_ptr<osg::Sequence> sequenceNode = handleSequenceNode(niFltAnimationNode);
|
|
||||||
node->addChild(sequenceNode);
|
node->addChild(sequenceNode);
|
||||||
currentNode = sequenceNode;
|
currentNode = sequenceNode;
|
||||||
}
|
}
|
||||||
|
@ -752,6 +765,9 @@ namespace NifOsg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nifNode->recType == Nif::RC_NiFltAnimationNode)
|
||||||
|
activateSequenceNode(currentNode,nifNode);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue