From Cedric Pinson, The following modification are
Update Timeline.cpp to add current layer to the ActionVisitor, use correctly the priority Add accessors in Action.cpp to retrieve protected data Split files and rename them to classname Change de default color of UpdateMaterial to FFOOFF to detect unset value Add accessors in LinkVisitor instead of accessing data directly Update osganimationtimeline example to fit the api callback
This commit is contained in:
@@ -166,7 +166,7 @@ namespace osgAnimation
|
||||
ActionAnimation() {}
|
||||
ActionAnimation(const ActionAnimation& a, const osg::CopyOp& c) : Action(a,c) { _animation = a._animation;}
|
||||
ActionAnimation(Animation* animation);
|
||||
void updateAnimation(unsigned int frame);
|
||||
void updateAnimation(unsigned int frame, int priority);
|
||||
Animation* getAnimation() { return _animation.get(); }
|
||||
|
||||
protected:
|
||||
@@ -192,8 +192,6 @@ namespace osgAnimation
|
||||
|
||||
unsigned int getLoop() const { return _animation->getLoop(); }
|
||||
void setLoop(unsigned int loop);
|
||||
void computeWeightAndUpdateAnimation(unsigned int frame);
|
||||
|
||||
void traverse(ActionVisitor& visitor);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -38,10 +38,8 @@ namespace osgAnimation
|
||||
class OSGANIMATION_EXPORT ActionVisitor : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
std::vector<FrameAction> _stackFrameAction;
|
||||
std::vector<Timeline*> _stackTimeline;
|
||||
|
||||
META_ActionVisitor(osgAnimation, ActionVisitor);
|
||||
ActionVisitor();
|
||||
void traverse(Action& visitor);
|
||||
|
||||
void pushFrameActionOnStack(const FrameAction& fa);
|
||||
@@ -51,6 +49,10 @@ namespace osgAnimation
|
||||
void popTimeline();
|
||||
|
||||
Timeline* getCurrentTimeline();
|
||||
void setCurrentLayer(int layer) { _currentLayer = layer;}
|
||||
int getCurrentLayer() const { return _currentLayer; }
|
||||
|
||||
const std::vector<FrameAction>& getStackedFrameAction() const { return _stackFrameAction; }
|
||||
|
||||
virtual void apply(Action& action);
|
||||
virtual void apply(Timeline& tm);
|
||||
@@ -58,6 +60,11 @@ namespace osgAnimation
|
||||
virtual void apply(BlendOut& action);
|
||||
virtual void apply(ActionAnimation& action);
|
||||
virtual void apply(StripAnimation& action);
|
||||
|
||||
protected:
|
||||
std::vector<FrameAction> _stackFrameAction;
|
||||
std::vector<Timeline*> _stackTimeline;
|
||||
int _currentLayer;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -56,25 +56,6 @@ namespace osgAnimation
|
||||
|
||||
void setDefaultUpdateCallback(const std::string& name = "");
|
||||
|
||||
struct BoneMapVisitor : public osg::NodeVisitor
|
||||
{
|
||||
BoneMap _map;
|
||||
BoneMapVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
||||
|
||||
META_NodeVisitor("osgAnimation","BoneMapVisitor")
|
||||
|
||||
void apply(osg::Node&) { return; }
|
||||
void apply(osg::Transform& node)
|
||||
{
|
||||
Bone* bone = dynamic_cast<Bone*>(&node);
|
||||
if (bone)
|
||||
{
|
||||
_map[bone->getName()] = bone;
|
||||
traverse(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class OSGANIMATION_EXPORT UpdateBone : public AnimationUpdateCallback <osg::NodeCallback>
|
||||
{
|
||||
protected:
|
||||
@@ -131,6 +112,8 @@ namespace osgAnimation
|
||||
|
||||
const osg::Vec3& getTranslation() const { return _position;}
|
||||
const osg::Quat& getRotation() const { return _rotation;}
|
||||
const osg::Vec3& getScale() const { return _scale;}
|
||||
|
||||
osg::Matrix getMatrixInBoneSpace() const { return (osg::Matrix(getRotation())) * osg::Matrix::translate(getTranslation()) * _bindInBoneSpace;}
|
||||
const osg::Matrix& getBindMatrixInBoneSpace() const { return _bindInBoneSpace; }
|
||||
const osg::Matrix& getMatrixInSkeletonSpace() const { return _boneInSkeletonSpace; }
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace osgAnimation
|
||||
|
||||
AnimationList& getAnimationList();
|
||||
void reset();
|
||||
unsigned int getNbLinkedTarget() const { return _nbLinkedTarget; }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace osgAnimation
|
||||
public:
|
||||
|
||||
Target();
|
||||
virtual ~Target();
|
||||
virtual ~Target() {}
|
||||
virtual void normalize() = 0;
|
||||
void reset() { _weight = 0; _priorityWeight = 0; }
|
||||
int getCount() const { return referenceCount(); }
|
||||
|
||||
@@ -103,9 +103,9 @@ osgAnimation::ActionAnimation::ActionAnimation(Animation* animation) : _animatio
|
||||
Action::setDuration(animation->getDuration());
|
||||
setName(animation->getName());
|
||||
}
|
||||
void osgAnimation::ActionAnimation::updateAnimation(unsigned int frame)
|
||||
void osgAnimation::ActionAnimation::updateAnimation(unsigned int frame, int priority)
|
||||
{
|
||||
_animation->update(frame * 1.0/_fps);
|
||||
_animation->update(frame * 1.0/_fps, priority);
|
||||
}
|
||||
|
||||
|
||||
@@ -149,14 +149,14 @@ void osgAnimation::StripAnimation::traverse(ActionVisitor& visitor)
|
||||
{
|
||||
if (_blendIn.valid())
|
||||
{
|
||||
unsigned int f = visitor._stackFrameAction.back().first;
|
||||
unsigned int f = visitor.getStackedFrameAction().back().first;
|
||||
visitor.pushFrameActionOnStack(FrameAction(f,_blendIn.get()));
|
||||
_blendIn->accept(visitor);
|
||||
visitor.popFrameAction();
|
||||
}
|
||||
if (_blendOut.second.valid())
|
||||
{
|
||||
unsigned int f = visitor._stackFrameAction.back().first;
|
||||
unsigned int f = visitor.getStackedFrameAction().back().first;
|
||||
visitor.pushFrameActionOnStack(FrameAction(f + _blendOut.first,_blendOut.second.get()));
|
||||
_blendOut.second.get()->accept(visitor);
|
||||
visitor.popFrameAction();
|
||||
@@ -164,18 +164,9 @@ void osgAnimation::StripAnimation::traverse(ActionVisitor& visitor)
|
||||
|
||||
if (_animation.valid())
|
||||
{
|
||||
unsigned int f = visitor._stackFrameAction.back().first;
|
||||
unsigned int f = visitor.getStackedFrameAction().back().first;
|
||||
visitor.pushFrameActionOnStack(FrameAction(f,_animation.get()));
|
||||
_animation->accept(visitor);
|
||||
visitor.popFrameAction();
|
||||
}
|
||||
}
|
||||
|
||||
void osgAnimation::StripAnimation::computeWeightAndUpdateAnimation(unsigned int frame)
|
||||
{
|
||||
if (frame < _blendIn->getNumFrames())
|
||||
_blendIn->computeWeight(frame);
|
||||
if (frame >= _blendOut.first)
|
||||
_blendOut.second->computeWeight(frame - _blendOut.first);
|
||||
_animation->updateAnimation(frame);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
#include <osgAnimation/ActionVisitor>
|
||||
#include <osgAnimation/Timeline>
|
||||
|
||||
osgAnimation::ActionVisitor::ActionVisitor()
|
||||
{
|
||||
_currentLayer = 0;
|
||||
}
|
||||
void osgAnimation::ActionVisitor::pushFrameActionOnStack(const FrameAction& fa) { _stackFrameAction.push_back(fa); }
|
||||
void osgAnimation::ActionVisitor::popFrameAction() { _stackFrameAction.pop_back(); }
|
||||
void osgAnimation::ActionVisitor::pushTimelineOnStack(Timeline* tm) { _stackTimeline.push_back(tm); }
|
||||
@@ -124,7 +128,7 @@ void osgAnimation::UpdateActionVisitor::apply(ActionAnimation& action)
|
||||
{
|
||||
unsigned int frame = getLocalFrame();
|
||||
apply(static_cast<Action&>(action));
|
||||
action.updateAnimation(frame);
|
||||
action.updateAnimation(frame, getCurrentLayer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,29 +137,7 @@ void osgAnimation::UpdateActionVisitor::apply(StripAnimation& action)
|
||||
if (isActive(action))
|
||||
{
|
||||
apply(static_cast<Action&>(action));
|
||||
|
||||
#if 0
|
||||
unsigned int frame = getLocalFrame();
|
||||
// evaluate callback in blendin/blendout/animation
|
||||
{
|
||||
BlendIn* subAction = action.getBlendIn();
|
||||
if (subAction)
|
||||
apply(static_cast<Action&>(*subAction));
|
||||
}
|
||||
{
|
||||
BlendOut* subAction = action.getBlendOut();
|
||||
if (subAction)
|
||||
apply(static_cast<Action&>(*subAction));
|
||||
}
|
||||
{
|
||||
ActionAnimation* subAction = action.getActionAnimation();
|
||||
if (subAction)
|
||||
apply(static_cast<Action&>(*subAction));
|
||||
}
|
||||
action.computeWeightAndUpdateAnimation(frame);
|
||||
#else
|
||||
action.traverse(*this);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
|
||||
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@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
|
||||
@@ -15,45 +15,9 @@
|
||||
#include <osgAnimation/Skinning>
|
||||
#include <osgAnimation/Bone>
|
||||
#include <osgAnimation/Skeleton>
|
||||
|
||||
|
||||
struct FindNearestParentAnimationManager : public osg::NodeVisitor
|
||||
{
|
||||
osg::ref_ptr<osgAnimation::AnimationManagerBase> _manager;
|
||||
FindNearestParentAnimationManager() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {}
|
||||
void apply(osg::Node& node)
|
||||
{
|
||||
if (_manager.valid())
|
||||
return;
|
||||
osg::NodeCallback* callback = node.getUpdateCallback();
|
||||
while (callback)
|
||||
{
|
||||
_manager = dynamic_cast<osgAnimation::AnimationManagerBase*>(callback);
|
||||
if (_manager.valid())
|
||||
return;
|
||||
callback = callback->getNestedCallback();
|
||||
}
|
||||
traverse(node);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct ComputeBindMatrixVisitor : public osg::NodeVisitor
|
||||
{
|
||||
ComputeBindMatrixVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
||||
void apply(osg::Node& node) { return; }
|
||||
void apply(osg::Transform& node)
|
||||
{
|
||||
osgAnimation::Bone* bone = dynamic_cast<osgAnimation::Bone*>(&node);
|
||||
if (!bone)
|
||||
return;
|
||||
if (bone->needToComputeBindMatrix())
|
||||
bone->computeBindMatrix();
|
||||
|
||||
traverse(node);
|
||||
}
|
||||
};
|
||||
|
||||
#include <osgAnimation/FindParentAnimationManagerVisitor>
|
||||
#include <osgAnimation/BoneMapVisitor>
|
||||
#include <osgAnimation/ComputeBindMatrixVisitor>
|
||||
|
||||
|
||||
osgAnimation::Bone::UpdateBone::UpdateBone(const osgAnimation::Bone::UpdateBone& apc,const osg::CopyOp& copyop) :
|
||||
@@ -107,7 +71,7 @@ void osgAnimation::Bone::UpdateBone::operator()(osg::Node* node, osg::NodeVisito
|
||||
|
||||
if (!_manager.valid())
|
||||
{
|
||||
FindNearestParentAnimationManager finder;
|
||||
FindParentAnimationManagerVisitor finder;
|
||||
|
||||
if (b->getParents().size() > 1)
|
||||
{
|
||||
@@ -120,13 +84,13 @@ void osgAnimation::Bone::UpdateBone::operator()(osg::Node* node, osg::NodeVisito
|
||||
}
|
||||
b->getParents()[0]->accept(finder);
|
||||
|
||||
if (!finder._manager.valid())
|
||||
if (!finder.getAnimationManager())
|
||||
{
|
||||
osg::notify(osg::WARN) << "Warning can't update Bone, path to parent AnimationManagerBase not found" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
_manager = finder._manager.get();
|
||||
_manager = finder.getAnimationManager();
|
||||
}
|
||||
|
||||
updateLink();
|
||||
@@ -153,6 +117,7 @@ osgAnimation::Bone::Bone(const Bone& b, const osg::CopyOp& copyop) :
|
||||
_invBindInSkeletonSpace(b._invBindInSkeletonSpace),
|
||||
_boneInSkeletonSpace(b._boneInSkeletonSpace)
|
||||
{
|
||||
#if 0
|
||||
osg::ref_ptr<osg::NodeCallback> updatecallback = getUpdateCallback();
|
||||
setUpdateCallback(0);
|
||||
while (updatecallback.valid()) {
|
||||
@@ -161,6 +126,7 @@ osgAnimation::Bone::Bone(const Bone& b, const osg::CopyOp& copyop) :
|
||||
addUpdateCallback(ucb);
|
||||
updatecallback = updatecallback->getNestedCallback();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
osgAnimation::Bone::Bone(const std::string& name)
|
||||
@@ -192,7 +158,7 @@ void osgAnimation::Bone::computeBindMatrix()
|
||||
_invBindInSkeletonSpace = parent->getInvBindMatrixInSkeletonSpace() * _invBindInSkeletonSpace;
|
||||
}
|
||||
|
||||
osgAnimation::Bone* osgAnimation::Bone::getBoneParent()
|
||||
osgAnimation::Bone* osgAnimation::Bone::getBoneParent()
|
||||
{
|
||||
if (getParents().empty())
|
||||
return 0;
|
||||
@@ -238,5 +204,5 @@ osgAnimation::Bone::BoneMap osgAnimation::Bone::getBoneMap()
|
||||
{
|
||||
BoneMapVisitor mapVisitor;
|
||||
this->accept(mapVisitor);
|
||||
return mapVisitor._map;
|
||||
return mapVisitor.getBoneMap();
|
||||
}
|
||||
|
||||
@@ -18,10 +18,13 @@ SET(LIB_PUBLIC_HEADERS
|
||||
${HEADER_PATH}/Assert
|
||||
${HEADER_PATH}/BasicAnimationManager
|
||||
${HEADER_PATH}/Bone
|
||||
${HEADER_PATH}/BoneMapVisitor
|
||||
${HEADER_PATH}/Channel
|
||||
${HEADER_PATH}/CubicBezier
|
||||
${HEADER_PATH}/ComputeBindMatrixVisitor
|
||||
${HEADER_PATH}/EaseMotion
|
||||
${HEADER_PATH}/Export
|
||||
${HEADER_PATH}/FindParentAnimationManagerVisitor
|
||||
${HEADER_PATH}/FrameAction
|
||||
${HEADER_PATH}/Interpolator
|
||||
${HEADER_PATH}/Keyframe
|
||||
@@ -53,7 +56,9 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
AnimationManager.cpp
|
||||
BasicAnimationManager.cpp
|
||||
Bone.cpp
|
||||
BoneMapVisitor.cpp
|
||||
Channel.cpp
|
||||
FindParentAnimationManagerVisitor.cpp
|
||||
LinkVisitor.cpp
|
||||
MorphGeometry.cpp
|
||||
RigGeometry.cpp
|
||||
|
||||
@@ -19,4 +19,3 @@
|
||||
using namespace osgAnimation;
|
||||
|
||||
Target::Target() : _weight(0), _priorityWeight(0), _lastPriority(0) {}
|
||||
Target::~Target() {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
|
||||
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@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
|
||||
@@ -55,10 +55,12 @@ osgAnimation::Timeline::Timeline(const Timeline& nc,const osg::CopyOp& op)
|
||||
|
||||
void osgAnimation::Timeline::traverse(ActionVisitor& visitor)
|
||||
{
|
||||
int layer = visitor.getCurrentLayer();
|
||||
visitor.pushTimelineOnStack(this);
|
||||
// update from high priority to low priority
|
||||
for( ActionLayers::reverse_iterator iterAnim = _actions.rbegin(); iterAnim != _actions.rend(); ++iterAnim )
|
||||
{
|
||||
visitor.setCurrentLayer(iterAnim->first);
|
||||
ActionList& list = iterAnim->second;
|
||||
for (unsigned int i = 0; i < list.size(); i++)
|
||||
{
|
||||
@@ -68,6 +70,7 @@ void osgAnimation::Timeline::traverse(ActionVisitor& visitor)
|
||||
}
|
||||
}
|
||||
visitor.popTimeline();
|
||||
visitor.setCurrentLayer(layer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ UpdateMaterial::UpdateMaterial(const UpdateMaterial& apc,const osg::CopyOp& copy
|
||||
UpdateMaterial::UpdateMaterial(const std::string& name):
|
||||
AnimationUpdateCallback<osg::StateAttribute::Callback>(name)
|
||||
{
|
||||
_diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,1,1,1));
|
||||
_diffuse = new osgAnimation::Vec4Target(osg::Vec4(1,0,1,1));
|
||||
}
|
||||
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
|
||||
Reference in New Issue
Block a user