From Cedric Pinson and Jeremey Moles, Changes to OpenSceneGraph-osgWidget-dev branch.
Notes from Robert Osfield, Merged changes to OpenSceneGraph-osgWidget-dev r9367 (prior to my botched attempt at merged svn/trunk into the branch).
This commit is contained in:
@@ -18,15 +18,53 @@
|
||||
|
||||
using namespace osgAnimation;
|
||||
|
||||
|
||||
AnimationManagerBase::~AnimationManagerBase() {}
|
||||
|
||||
AnimationManagerBase::AnimationManagerBase()
|
||||
{
|
||||
setUpdateCallback(new UpdateCallback);
|
||||
_needToLink = false;
|
||||
}
|
||||
|
||||
void AnimationManagerBase::clearTargets()
|
||||
{
|
||||
for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++)
|
||||
(*it).get()->reset();
|
||||
}
|
||||
void AnimationManagerBase::normalizeTargets()
|
||||
{
|
||||
for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++)
|
||||
(*it).get()->normalize();
|
||||
}
|
||||
|
||||
void AnimationManagerBase::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
||||
{
|
||||
if (needToLink())
|
||||
{
|
||||
/** manager need to link, it means that an animation has been added
|
||||
so we need to relink all item animated with all animations.
|
||||
We apply the linker visitor on the manager node to affect
|
||||
all its children.
|
||||
But it should not be done here, it should be done in the
|
||||
update of AnimationManager
|
||||
*/
|
||||
link(node);
|
||||
}
|
||||
const osg::FrameStamp* fs = nv->getFrameStamp();
|
||||
update(fs->getSimulationTime());
|
||||
}
|
||||
traverse(node,nv);
|
||||
}
|
||||
|
||||
|
||||
AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::NodeCallback(b,copyop)
|
||||
{
|
||||
_animations = b._animations;
|
||||
_targets = b._targets;
|
||||
_needToLink = b._needToLink;
|
||||
}
|
||||
|
||||
void AnimationManagerBase::buildTargetReference()
|
||||
{
|
||||
_targets.clear();
|
||||
@@ -52,20 +90,10 @@ bool AnimationManagerBase::needToLink() const { return _needToLink; }
|
||||
|
||||
|
||||
|
||||
void AnimationManagerBase::link()
|
||||
void AnimationManagerBase::link(osg::Node* subgraph)
|
||||
{
|
||||
LinkVisitor linker(_animations);
|
||||
accept(linker);
|
||||
subgraph->accept(linker);
|
||||
_needToLink = false;
|
||||
buildTargetReference();
|
||||
}
|
||||
|
||||
|
||||
osgAnimation::AnimationMap AnimationManagerBase::getAnimationMap() const
|
||||
{
|
||||
osgAnimation::AnimationMap map;
|
||||
for (AnimationList::const_iterator it = _animations.begin(); it != _animations.end(); it++)
|
||||
map[(*it)->getName()] = *it;
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
138
src/osgAnimation/BasicAnimationManager.cpp
Normal file
138
src/osgAnimation/BasicAnimationManager.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
#include <osgAnimation/LinkVisitor>
|
||||
#include <osgAnimation/Assert>
|
||||
|
||||
using namespace osgAnimation;
|
||||
|
||||
BasicAnimationManager::~BasicAnimationManager() {}
|
||||
|
||||
void BasicAnimationManager::stopAll()
|
||||
{
|
||||
// loop over all playing animation
|
||||
for( AnimationLayers::iterator iterAnim = _animationsPlaying.begin(); iterAnim != _animationsPlaying.end(); ++iterAnim )
|
||||
{
|
||||
AnimationList& list = iterAnim->second;
|
||||
for (AnimationList::iterator it = list.begin(); it != list.end(); it++)
|
||||
(*it)->resetTargets();
|
||||
}
|
||||
_animationsPlaying.clear();
|
||||
}
|
||||
|
||||
BasicAnimationManager::BasicAnimationManager()
|
||||
{
|
||||
_lastUpdate = 0;
|
||||
}
|
||||
void BasicAnimationManager::playAnimation(Animation* pAnimation, int priority, float weight)
|
||||
{
|
||||
bool r = findAnimation(pAnimation);
|
||||
OSGANIMATION_ASSERT(r && "This animation is not registered");
|
||||
|
||||
if ( isPlaying(pAnimation) )
|
||||
stopAnimation(pAnimation);
|
||||
|
||||
_animationsPlaying[priority].push_back(pAnimation);
|
||||
pAnimation->setStartTime(_lastUpdate);
|
||||
pAnimation->setWeight(weight);
|
||||
}
|
||||
|
||||
bool BasicAnimationManager::stopAnimation(Animation* pAnimation)
|
||||
{
|
||||
// search though the layer and remove animation
|
||||
for( AnimationLayers::iterator iterAnim = _animationsPlaying.begin(); iterAnim != _animationsPlaying.end(); ++iterAnim )
|
||||
{
|
||||
AnimationList& list = iterAnim->second;
|
||||
for (AnimationList::iterator it = list.begin(); it != list.end(); it++)
|
||||
if( (*it) == pAnimation )
|
||||
{
|
||||
(*it)->resetTargets();
|
||||
list.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void BasicAnimationManager::update (double time)
|
||||
{
|
||||
if (!_lastUpdate)
|
||||
_lastUpdate = time;
|
||||
|
||||
// could filtered with an active flag
|
||||
for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++)
|
||||
(*it).get()->reset();
|
||||
|
||||
// update from high priority to low priority
|
||||
for( AnimationLayers::reverse_iterator iterAnim = _animationsPlaying.rbegin(); iterAnim != _animationsPlaying.rend(); ++iterAnim )
|
||||
{
|
||||
// update all animation
|
||||
std::vector<int> toremove;
|
||||
AnimationList& list = iterAnim->second;
|
||||
for (unsigned int i = 0; i < list.size(); i++)
|
||||
{
|
||||
if (! list[i]->update(time))
|
||||
toremove.push_back(i);
|
||||
}
|
||||
|
||||
// remove finished animation
|
||||
while (!toremove.empty())
|
||||
{
|
||||
list.erase(list.begin() + toremove.back());
|
||||
toremove.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
for (TargetSet::iterator it = _targets.begin(); it != _targets.end(); it++)
|
||||
(*it).get()->normalize();
|
||||
}
|
||||
|
||||
|
||||
bool BasicAnimationManager::findAnimation(Animation* pAnimation)
|
||||
{
|
||||
for( AnimationList::const_iterator iterAnim = _animations.begin(); iterAnim != _animations.end(); ++iterAnim )
|
||||
{
|
||||
if ( (*iterAnim) == pAnimation )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool BasicAnimationManager::isPlaying(Animation* pAnimation)
|
||||
{
|
||||
for( AnimationLayers::iterator iterAnim = _animationsPlaying.begin(); iterAnim != _animationsPlaying.end(); ++iterAnim )
|
||||
{
|
||||
AnimationList& list = iterAnim->second;
|
||||
for (AnimationList::iterator it = list.begin(); it != list.end(); it++)
|
||||
if ( (*it) == pAnimation )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BasicAnimationManager::isPlaying(const std::string& name)
|
||||
{
|
||||
// loop over all playing animation
|
||||
for( AnimationLayers::iterator iterAnim = _animationsPlaying.begin(); iterAnim != _animationsPlaying.end(); ++iterAnim )
|
||||
{
|
||||
AnimationList& list = iterAnim->second;
|
||||
for (AnimationList::iterator it = list.begin(); it != list.end(); it++)
|
||||
if ( (*it)->getName() == name )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -24,6 +24,31 @@ osgAnimation::Bone::UpdateBone::UpdateBone(const osgAnimation::Bone::UpdateBone&
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
osgAnimation::Bone::Bone(const Bone& b, const osg::CopyOp& copyop)
|
||||
: osg::Transform(b,copyop),
|
||||
_position(b._position),
|
||||
_rotation(b._rotation),
|
||||
_scale(b._scale)
|
||||
{
|
||||
}
|
||||
|
||||
osgAnimation::Bone::Bone(const std::string& name)
|
||||
{
|
||||
if (!name.empty())
|
||||
setName(name);
|
||||
_needToRecomputeBindMatrix = false;
|
||||
}
|
||||
|
||||
|
||||
void osgAnimation::Bone::setDefaultUpdateCallback(const std::string& name)
|
||||
{
|
||||
std::string cbName = name;
|
||||
if (cbName.empty())
|
||||
cbName = getName();
|
||||
setUpdateCallback(new UpdateBone(cbName));
|
||||
}
|
||||
|
||||
void osgAnimation::Bone::computeBindMatrix()
|
||||
{
|
||||
_invBindInSkeletonSpace = osg::Matrix::inverse(_bindInBoneSpace);
|
||||
|
||||
@@ -10,26 +10,27 @@ SET(LIB_NAME osgAnimation)
|
||||
|
||||
SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME})
|
||||
SET(LIB_PUBLIC_HEADERS
|
||||
${HEADER_PATH}/Export
|
||||
${HEADER_PATH}/Bone
|
||||
${HEADER_PATH}/Skeleton
|
||||
${HEADER_PATH}/Channel
|
||||
${HEADER_PATH}/Sampler
|
||||
${HEADER_PATH}/Interpolator
|
||||
${HEADER_PATH}/Target
|
||||
${HEADER_PATH}/Animation
|
||||
${HEADER_PATH}/Keyframe
|
||||
${HEADER_PATH}/Skinning
|
||||
${HEADER_PATH}/CubicBezier
|
||||
${HEADER_PATH}/Vec3Packed
|
||||
${HEADER_PATH}/AnimationManager
|
||||
${HEADER_PATH}/AnimationManagerBase
|
||||
${HEADER_PATH}/UpdateCallback
|
||||
${HEADER_PATH}/LinkVisitor
|
||||
${HEADER_PATH}/VertexInfluence
|
||||
${HEADER_PATH}/EaseMotion
|
||||
${HEADER_PATH}/Assert
|
||||
${HEADER_PATH}/Timeline
|
||||
${HEADER_PATH}/Export
|
||||
${HEADER_PATH}/Bone
|
||||
${HEADER_PATH}/Skeleton
|
||||
${HEADER_PATH}/Channel
|
||||
${HEADER_PATH}/Sampler
|
||||
${HEADER_PATH}/Interpolator
|
||||
${HEADER_PATH}/Target
|
||||
${HEADER_PATH}/Animation
|
||||
${HEADER_PATH}/Keyframe
|
||||
${HEADER_PATH}/Skinning
|
||||
${HEADER_PATH}/CubicBezier
|
||||
${HEADER_PATH}/Vec3Packed
|
||||
${HEADER_PATH}/BasicAnimationManager
|
||||
${HEADER_PATH}/TimelineAnimationManager
|
||||
${HEADER_PATH}/AnimationManagerBase
|
||||
${HEADER_PATH}/UpdateCallback
|
||||
${HEADER_PATH}/LinkVisitor
|
||||
${HEADER_PATH}/VertexInfluence
|
||||
${HEADER_PATH}/EaseMotion
|
||||
${HEADER_PATH}/Assert
|
||||
${HEADER_PATH}/Timeline
|
||||
)
|
||||
|
||||
|
||||
@@ -41,7 +42,8 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
Animation.cpp
|
||||
Bone.cpp
|
||||
RigGeometry.cpp
|
||||
AnimationManager.cpp
|
||||
BasicAnimationManager.cpp
|
||||
TimelineAnimationManager.cpp
|
||||
AnimationManagerBase.cpp
|
||||
Skeleton.cpp
|
||||
VertexInfluence.cpp
|
||||
|
||||
@@ -22,14 +22,45 @@
|
||||
*/
|
||||
#include <osgAnimation/RigGeometry>
|
||||
|
||||
void osgAnimation::RigGeometry::buildTransformer(Skeleton* root)
|
||||
using namespace osgAnimation;
|
||||
|
||||
RigGeometry::RigGeometry()
|
||||
{
|
||||
setUseDisplayList(false);
|
||||
setUpdateCallback(new UpdateVertex);
|
||||
setDataVariance(osg::Object::DYNAMIC);
|
||||
_needToComputeMatrix = true;
|
||||
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();
|
||||
}
|
||||
|
||||
RigGeometry::RigGeometry(const osg::Geometry& b) : osg::Geometry(b, osg::CopyOp::SHALLOW_COPY)
|
||||
{
|
||||
setUseDisplayList(false);
|
||||
setUpdateCallback(new UpdateVertex);
|
||||
setDataVariance(osg::Object::DYNAMIC);
|
||||
_needToComputeMatrix = true;
|
||||
_matrixFromSkeletonToGeometry = _invMatrixFromSkeletonToGeometry = osg::Matrix::identity();
|
||||
}
|
||||
|
||||
RigGeometry::RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop) :
|
||||
osg::Geometry(b,copyop),
|
||||
_positionSource(b._positionSource),
|
||||
_normalSource(b._normalSource),
|
||||
_vertexInfluenceSet(b._vertexInfluenceSet),
|
||||
_vertexInfluenceMap(b._vertexInfluenceMap),
|
||||
_transformVertexes(b._transformVertexes),
|
||||
_needToComputeMatrix(b._needToComputeMatrix)
|
||||
{
|
||||
}
|
||||
|
||||
void RigGeometry::buildTransformer(Skeleton* root)
|
||||
{
|
||||
Bone::BoneMap bm = root->getBoneMap();
|
||||
_transformVertexes.init(bm, _vertexInfluenceSet.getUniqVertexSetToBoneSetList());
|
||||
_root = root;
|
||||
}
|
||||
|
||||
void osgAnimation::RigGeometry::buildVertexSet()
|
||||
void RigGeometry::buildVertexSet()
|
||||
{
|
||||
if (!_vertexInfluenceMap.valid())
|
||||
{
|
||||
@@ -47,7 +78,7 @@ void osgAnimation::RigGeometry::buildVertexSet()
|
||||
std::cout << "uniq groups " << _vertexInfluenceSet.getUniqVertexSetToBoneSetList().size() << " for " << getName() << std::endl;
|
||||
}
|
||||
|
||||
void osgAnimation::RigGeometry::computeMatrixFromRootSkeleton()
|
||||
void RigGeometry::computeMatrixFromRootSkeleton()
|
||||
{
|
||||
if (!_root.valid())
|
||||
{
|
||||
@@ -60,8 +91,11 @@ void osgAnimation::RigGeometry::computeMatrixFromRootSkeleton()
|
||||
_needToComputeMatrix = false;
|
||||
}
|
||||
|
||||
void osgAnimation::RigGeometry::transformSoftwareMethod()
|
||||
void RigGeometry::transformSoftwareMethod()
|
||||
{
|
||||
setUseDisplayList(false);
|
||||
setUseVertexBufferObjects(true);
|
||||
|
||||
// std::cout << getName() << " _matrixFromSkeletonToGeometry" << _matrixFromSkeletonToGeometry << std::endl;
|
||||
osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(getVertexArray());
|
||||
if (pos && _positionSource.size() != pos->size())
|
||||
@@ -86,8 +120,10 @@ void osgAnimation::RigGeometry::transformSoftwareMethod()
|
||||
_transformVertexes.compute<osg::Vec3>(_matrixFromSkeletonToGeometry, _invMatrixFromSkeletonToGeometry, &_normalSource.front(), &normal->front());
|
||||
normal->dirty();
|
||||
}
|
||||
if (getUseDisplayList())
|
||||
dirtyDisplayList();
|
||||
dirtyBound();
|
||||
}
|
||||
|
||||
const osgAnimation::Skeleton* osgAnimation::RigGeometry::getSkeleton() const { return _root.get(); }
|
||||
osgAnimation::Skeleton* osgAnimation::RigGeometry::getSkeleton() { return _root.get(); }
|
||||
const osgAnimation::Skeleton* RigGeometry::getSkeleton() const { return _root.get(); }
|
||||
osgAnimation::Skeleton* RigGeometry::getSkeleton() { return _root.get(); }
|
||||
|
||||
@@ -52,15 +52,15 @@ struct updateMatrixVisitor : public osg::NodeVisitor
|
||||
}
|
||||
|
||||
if (parent)
|
||||
bone->_boneInSkeletonSpace = bone->getMatrixInBoneSpace() * bone->getBoneParent()->getMatrixInSkeletonSpace();
|
||||
bone->setBoneInSkeletonSpace(bone->getMatrixInBoneSpace() * bone->getBoneParent()->getMatrixInSkeletonSpace());
|
||||
else
|
||||
bone->_boneInSkeletonSpace = bone->getMatrixInBoneSpace();// * _skeleton;
|
||||
bone->setBoneInSkeletonSpace(bone->getMatrixInBoneSpace());
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
};
|
||||
|
||||
void Skeleton::UpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
void Skeleton::UpdateSkeleton::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
||||
{
|
||||
@@ -72,23 +72,18 @@ void Skeleton::UpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
// process. It's important to update Bone before other things because the update
|
||||
// of RigGeometry need it
|
||||
updateMatrixVisitor visitor;
|
||||
#if 0
|
||||
visitor._skeleton = b->getMatrix();
|
||||
int numChildren = b->getNumChildren();
|
||||
for (int i = 0; i < numChildren; i++)
|
||||
{
|
||||
b->getChild(i)->accept(visitor);
|
||||
}
|
||||
#else
|
||||
b->accept(visitor);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
traverse(node,nv);
|
||||
}
|
||||
|
||||
|
||||
Skeleton::Skeleton()
|
||||
Skeleton::Skeleton()
|
||||
{
|
||||
setUpdateCallback(new UpdateCallback());
|
||||
}
|
||||
|
||||
void Skeleton::setDefaultUpdateCallback()
|
||||
{
|
||||
setUpdateCallback(new Skeleton::UpdateSkeleton );
|
||||
}
|
||||
|
||||
@@ -16,34 +16,32 @@
|
||||
|
||||
using namespace osgAnimation;
|
||||
|
||||
// temporary
|
||||
// the problem comes that the AnimationManagerBase should only a group
|
||||
// and it's data should be in an update callback
|
||||
struct TimelineAdaptator : public Timeline
|
||||
{
|
||||
osg::ref_ptr<AnimationManagerTimeline> _manager;
|
||||
|
||||
TimelineAdaptator(AnimationManagerTimeline* manager) : _manager(manager) {}
|
||||
void evaluate(unsigned int frame)
|
||||
{
|
||||
_manager->clearTargets();
|
||||
Timeline::evaluate(frame);
|
||||
_manager->normalizeTargets();
|
||||
}
|
||||
};
|
||||
|
||||
AnimationManagerTimeline::AnimationManagerTimeline()
|
||||
Timeline::Timeline()
|
||||
{
|
||||
_timeline = new TimelineAdaptator(this);
|
||||
_lastUpdate = 0;
|
||||
_currentFrame = 0;
|
||||
_fps = 25;
|
||||
_speed = 1.0;
|
||||
_state = Stop;
|
||||
_initFirstFrame = false;
|
||||
_previousFrameEvaluated = 0;
|
||||
_evaluating = 0;
|
||||
_numberFrame = -1; // something like infinity
|
||||
setName("Timeline");
|
||||
}
|
||||
|
||||
AnimationManagerTimeline::AnimationManagerTimeline(const AnimationManagerBase& manager) : AnimationManagerBase(manager)
|
||||
Timeline::Timeline(const Timeline& nc,const osg::CopyOp& op) : osg::Object(nc, op),
|
||||
_actions(nc._actions)
|
||||
{
|
||||
_timeline = new TimelineAdaptator(this);
|
||||
_lastUpdate = 0;
|
||||
_currentFrame = 0;
|
||||
_fps = 25;
|
||||
_speed = 1.0;
|
||||
_state = Stop;
|
||||
_initFirstFrame = false;
|
||||
_previousFrameEvaluated = 0;
|
||||
_evaluating = 0;
|
||||
_numberFrame = -1; // something like infinity
|
||||
setName("Timeline");
|
||||
}
|
||||
|
||||
void AnimationManagerTimeline::update(double time)
|
||||
{
|
||||
_timeline->update(time);
|
||||
}
|
||||
|
||||
|
||||
40
src/osgAnimation/TimelineAnimationManager.cpp
Normal file
40
src/osgAnimation/TimelineAnimationManager.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osgAnimation/Timeline>
|
||||
#include <osgAnimation/TimelineAnimationManager>
|
||||
|
||||
using namespace osgAnimation;
|
||||
|
||||
TimelineAnimationManager::TimelineAnimationManager()
|
||||
{
|
||||
_timeline = new Timeline;
|
||||
}
|
||||
|
||||
TimelineAnimationManager::TimelineAnimationManager(const AnimationManagerBase& manager) : AnimationManagerBase(manager)
|
||||
{
|
||||
_timeline = new Timeline;
|
||||
}
|
||||
|
||||
TimelineAnimationManager::TimelineAnimationManager(const TimelineAnimationManager& nc,const osg::CopyOp& co) : AnimationManagerBase(nc, co)
|
||||
{
|
||||
_timeline = new Timeline(*nc.getTimeline());
|
||||
}
|
||||
|
||||
void TimelineAnimationManager::update(double time)
|
||||
{
|
||||
clearTargets();
|
||||
_timeline->update(time);
|
||||
normalizeTargets();
|
||||
}
|
||||
@@ -54,9 +54,9 @@ void AnimationUpdateCallback::updateLink()
|
||||
Maybe this function should be on the manager side like
|
||||
_manager->linkItem(Bone);
|
||||
*/
|
||||
AnimationMap map = _manager->getAnimationMap();
|
||||
for (AnimationMap::iterator it = map.begin(); it != map.end(); it++)
|
||||
link(it->second.get());
|
||||
const AnimationList& animationList = _manager->getAnimationList();
|
||||
for (AnimationList::const_iterator it = animationList.begin(); it != animationList.end(); it++)
|
||||
link(it->get());
|
||||
_manager->buildTargetReference();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <osgAnimation/Bone>
|
||||
#include <osgAnimation/Skeleton>
|
||||
#include <osgAnimation/AnimationManager>
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
|
||||
class BvhMotionBuilder : public osg::Referenced
|
||||
{
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone( parent->getName()+"End" );
|
||||
bone->setBindMatrixInBoneSpace( osg::Matrix::translate(offsetEndSite) );
|
||||
bone->setDataVariance( osg::Object::DYNAMIC );
|
||||
parent->addChild( bone.get() );
|
||||
parent->addChild( bone );
|
||||
|
||||
if ( _drawingFlag )
|
||||
parent->addChild( createRefGeometry(offsetEndSite, 0.5).get() );
|
||||
@@ -94,11 +94,9 @@ public:
|
||||
|
||||
// Process JOINT section
|
||||
osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone( fr[1].getStr() );
|
||||
bone->setDefaultUpdateCallback();
|
||||
bone->setDataVariance( osg::Object::DYNAMIC );
|
||||
osgAnimation::AnimationUpdateCallback* cb =
|
||||
dynamic_cast<osgAnimation::AnimationUpdateCallback*>( bone->getUpdateCallback() );
|
||||
if ( cb ) cb->setName( bone->getName() );
|
||||
parent->addChild( bone.get() );
|
||||
parent->addChild( bone );
|
||||
_joints.push_back( JointNode(bone, 0) );
|
||||
|
||||
int entry = fr[1].getNoNestedBrackets();
|
||||
@@ -185,7 +183,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
osgAnimation::AnimationManager* buildBVH( std::istream& stream, const osgDB::ReaderWriter::Options* options )
|
||||
osg::Group* buildBVH( std::istream& stream, const osgDB::ReaderWriter::Options* options )
|
||||
{
|
||||
if ( options )
|
||||
{
|
||||
@@ -197,6 +195,7 @@ public:
|
||||
fr.attach( &stream );
|
||||
|
||||
osg::ref_ptr<osgAnimation::Skeleton> skelroot = new osgAnimation::Skeleton;
|
||||
skelroot->setDefaultUpdateCallback();
|
||||
osg::ref_ptr<osgAnimation::Animation> anim = new osgAnimation::Animation;
|
||||
|
||||
while( !fr.eof() )
|
||||
@@ -234,14 +233,16 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
osgAnimation::AnimationManager* manager = new osgAnimation::AnimationManager;
|
||||
manager->addChild( skelroot.get() );
|
||||
osg::Group* root = new osg::Group;
|
||||
osgAnimation::BasicAnimationManager* manager = new osgAnimation::BasicAnimationManager;
|
||||
root->addChild( skelroot.get() );
|
||||
root->setUpdateCallback(manager);
|
||||
manager->registerAnimation( anim.get() );
|
||||
manager->buildTargetReference();
|
||||
manager->playAnimation( anim.get() );
|
||||
|
||||
_joints.clear();
|
||||
return manager;
|
||||
return root;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
#include <osgAnimation/AnimationManager>
|
||||
#include <osgAnimation/AnimationManagerBase>
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
#include <osgAnimation/TimelineAnimationManager>
|
||||
#include <osgAnimation/VertexInfluence>
|
||||
#include <osgAnimation/Animation>
|
||||
#include <osgAnimation/Bone>
|
||||
@@ -73,8 +75,8 @@ bool Bone_readLocalData(Object& obj, Input& fr)
|
||||
}
|
||||
|
||||
bone.setBindMatrixInBoneSpace( osg::Matrix(att) * osg::Matrix::translate(pos));
|
||||
if (bone.getUpdateCallback() && bone.getUpdateCallback()->getName().empty() && bone.getUpdateCallback()->getNestedCallback())
|
||||
bone.setUpdateCallback(bone.getUpdateCallback()->getNestedCallback()); // skip the default callback build in constructor of Bone
|
||||
// if (bone.getUpdateCallback() && bone.getUpdateCallback()->getName().empty() && bone.getUpdateCallback()->getNestedCallback())
|
||||
// bone.setUpdateCallback(bone.getUpdateCallback()->getNestedCallback()); // skip the default callback build in constructor of Bone
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
@@ -297,9 +299,8 @@ RegisterDotOsgWrapperProxy g_atkAnimationProxy
|
||||
|
||||
|
||||
|
||||
bool AnimationManager_readLocalData(Object& obj, Input& fr)
|
||||
bool AnimationManagerBase_readLocalData(osgAnimation::AnimationManagerBase& manager, Input& fr)
|
||||
{
|
||||
osgAnimation::AnimationManager& manager = dynamic_cast<osgAnimation::AnimationManager&>(obj);
|
||||
int nbAnims = 0;
|
||||
bool iteratorAdvanced = false;
|
||||
|
||||
@@ -310,7 +311,7 @@ bool AnimationManager_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nbAnims; i++)
|
||||
for (int i = 0; i < nbAnims; i++)
|
||||
{
|
||||
Object* o = fr.readObject();
|
||||
osgAnimation::Animation* a = dynamic_cast<osgAnimation::Animation*>(o);
|
||||
@@ -326,30 +327,65 @@ bool AnimationManager_readLocalData(Object& obj, Input& fr)
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
bool AnimationManager_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
const osgAnimation::AnimationManager& manager = dynamic_cast<const osgAnimation::AnimationManager&>(obj);
|
||||
|
||||
osgAnimation::AnimationMap map = manager.getAnimationMap();
|
||||
int nbanims = map.size();
|
||||
fw.indent() << "num_animations " << nbanims << std::endl;
|
||||
for (osgAnimation::AnimationMap::iterator it = map.begin(); it != map.end(); it++)
|
||||
bool BasicAnimationManager_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
osgAnimation::BasicAnimationManager& manager = dynamic_cast<osgAnimation::BasicAnimationManager&>(obj);
|
||||
return AnimationManagerBase_readLocalData(manager, fr);
|
||||
}
|
||||
|
||||
bool TimelineAnimationManager_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
osgAnimation::TimelineAnimationManager& manager = dynamic_cast<osgAnimation::TimelineAnimationManager&>(obj);
|
||||
return AnimationManagerBase_readLocalData(manager, fr);
|
||||
}
|
||||
|
||||
|
||||
bool AnimationManagerBase_writeLocalData(const osgAnimation::AnimationManagerBase& manager, Output& fw)
|
||||
{
|
||||
const osgAnimation::AnimationList& animList = manager.getAnimationList();
|
||||
|
||||
fw.indent() << "num_animations " << animList.size() << std::endl;
|
||||
for (osgAnimation::AnimationList::const_iterator it = animList.begin(); it != animList.end(); it++)
|
||||
{
|
||||
if (!fw.writeObject(*it->second))
|
||||
if (!fw.writeObject(**it))
|
||||
osg::notify(osg::WARN)<<"Warning: can't write an animation object"<< std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RegisterDotOsgWrapperProxy g_atkAnimationManagerProxy
|
||||
bool BasicAnimationManager_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
const osgAnimation::BasicAnimationManager& manager = dynamic_cast<const osgAnimation::BasicAnimationManager&>(obj);
|
||||
return AnimationManagerBase_writeLocalData(manager, fw);
|
||||
}
|
||||
|
||||
bool TimelineAnimationManager_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
const osgAnimation::TimelineAnimationManager& manager = dynamic_cast<const osgAnimation::TimelineAnimationManager&>(obj);
|
||||
return AnimationManagerBase_writeLocalData(manager, fw);
|
||||
}
|
||||
|
||||
|
||||
RegisterDotOsgWrapperProxy g_BasicAnimationManagerProxy
|
||||
(
|
||||
new osgAnimation::AnimationManager,
|
||||
"osgAnimation::AnimationManager",
|
||||
"Object Node Group osgAnimation::AnimationManager",
|
||||
&AnimationManager_readLocalData,
|
||||
&AnimationManager_writeLocalData,
|
||||
new osgAnimation::BasicAnimationManager,
|
||||
"osgAnimation::BasicAnimationManager",
|
||||
"Object NodeCallback osgAnimation::BasicAnimationManager",
|
||||
&BasicAnimationManager_readLocalData,
|
||||
&BasicAnimationManager_writeLocalData,
|
||||
DotOsgWrapper::READ_AND_WRITE
|
||||
);
|
||||
);
|
||||
|
||||
RegisterDotOsgWrapperProxy g_TimelineAnimationManagerProxy
|
||||
(
|
||||
new osgAnimation::TimelineAnimationManager,
|
||||
"osgAnimation::TimelineAnimationManager",
|
||||
"Object NodeCallback osgAnimation::TimelineAnimationManager",
|
||||
&TimelineAnimationManager_readLocalData,
|
||||
&TimelineAnimationManager_writeLocalData,
|
||||
DotOsgWrapper::READ_AND_WRITE
|
||||
);
|
||||
|
||||
|
||||
bool RigGeometry_readLocalData(Object& obj, Input& fr)
|
||||
@@ -468,6 +504,29 @@ RegisterDotOsgWrapperProxy g_atkUpdateBoneProxy
|
||||
|
||||
|
||||
|
||||
bool UpdateSkeleton_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
bool iteratorAdvanced = false;
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
bool UpdateSkeleton_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
RegisterDotOsgWrapperProxy g_atkUpdateSkeletonProxy
|
||||
(
|
||||
new osgAnimation::Skeleton::UpdateSkeleton,
|
||||
"osgAnimation::UpdateSkeleton",
|
||||
"Object osgAnimation::UpdateSkeleton",
|
||||
&UpdateSkeleton_readLocalData,
|
||||
&UpdateSkeleton_writeLocalData,
|
||||
DotOsgWrapper::READ_AND_WRITE
|
||||
);
|
||||
|
||||
|
||||
|
||||
bool UpdateTransform_readLocalData(Object& obj, Input& fr)
|
||||
{
|
||||
bool iteratorAdvanced = false;
|
||||
@@ -487,5 +546,5 @@ RegisterDotOsgWrapperProxy g_atkUpdateTransformProxy
|
||||
&UpdateTransform_readLocalData,
|
||||
&UpdateTransform_writeLocalData,
|
||||
DotOsgWrapper::READ_AND_WRITE
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user