diff --git a/components/nifosg/riggeometry.cpp b/components/nifosg/riggeometry.cpp index 37fee1f515..0217a7ac00 100644 --- a/components/nifosg/riggeometry.cpp +++ b/components/nifosg/riggeometry.cpp @@ -135,7 +135,7 @@ void RigGeometry::update(osg::NodeVisitor* nv) return; } - mSkeleton->updateBoneMatrices(); + mSkeleton->updateBoneMatrices(nv); osg::NodePath path; bool foundSkel = false; diff --git a/components/nifosg/skeleton.cpp b/components/nifosg/skeleton.cpp index 2e00eb76e3..b9d113d341 100644 --- a/components/nifosg/skeleton.cpp +++ b/components/nifosg/skeleton.cpp @@ -34,6 +34,7 @@ private: Skeleton::Skeleton() : mBoneCacheInit(false) , mNeedToUpdateBoneMatrices(true) + , mLastFrameNumber(0) { } @@ -42,6 +43,7 @@ Skeleton::Skeleton(const Skeleton ©, const osg::CopyOp ©op) : osg::Group(copy, copyop) , mBoneCacheInit(false) , mNeedToUpdateBoneMatrices(true) + , mLastFrameNumber(0) { } @@ -100,11 +102,15 @@ Bone* Skeleton::getBone(const std::string &name) return bone; } -void Skeleton::updateBoneMatrices() +void Skeleton::updateBoneMatrices(osg::NodeVisitor* nv) { - //if (mNeedToUpdateBoneMatrices) - { + if (nv->getFrameStamp()->getFrameNumber() != mLastFrameNumber) + mNeedToUpdateBoneMatrices = true; + + mLastFrameNumber = nv->getFrameStamp()->getFrameNumber(); + if (mNeedToUpdateBoneMatrices) + { if (mRootBone.get()) { for (unsigned int i=0; imChildren.size(); ++i) diff --git a/components/nifosg/skeleton.hpp b/components/nifosg/skeleton.hpp index f006ca84b2..5344f9f5df 100644 --- a/components/nifosg/skeleton.hpp +++ b/components/nifosg/skeleton.hpp @@ -39,7 +39,7 @@ namespace NifOsg META_Node(NifOsg, Skeleton) - void updateBoneMatrices(); + void updateBoneMatrices(osg::NodeVisitor* nv); private: // The root bone is not a "real" bone, it has no corresponding node in the scene graph. @@ -51,6 +51,8 @@ namespace NifOsg bool mBoneCacheInit; bool mNeedToUpdateBoneMatrices; + + unsigned int mLastFrameNumber; }; }