2.8 branch: backport of osgAnimation from svn head 11026.
This commit is contained in:
147
include/osgAnimation/Action
Normal file
147
include/osgAnimation/Action
Normal file
@@ -0,0 +1,147 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ACTION_H
|
||||
#define OSGANIMATION_ACTION_H
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/Animation>
|
||||
#include <osgAnimation/ActionVisitor>
|
||||
#include <osgAnimation/FrameAction>
|
||||
#include <iostream>
|
||||
|
||||
#define META_Action(library,name) \
|
||||
virtual osg::Object* cloneType() const { return new name (); } \
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
|
||||
virtual const char* className() const { return #name; } \
|
||||
virtual const char* libraryName() const { return #library; } \
|
||||
virtual void accept(osgAnimation::ActionVisitor& nv) { nv.apply(*this); } \
|
||||
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT Action : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
class Callback : public osg::Object
|
||||
{
|
||||
public:
|
||||
Callback(){}
|
||||
Callback(const Callback& nc,const osg::CopyOp&) :
|
||||
_nestedCallback(nc._nestedCallback) {}
|
||||
|
||||
META_Object(osgAnimation,Callback);
|
||||
|
||||
virtual void operator()(Action* action, osgAnimation::ActionVisitor* nv) {}
|
||||
|
||||
Callback* getNestedCallback() { return _nestedCallback.get(); }
|
||||
void addNestedCallback(Callback* callback)
|
||||
{
|
||||
if (callback) {
|
||||
if (_nestedCallback.valid())
|
||||
_nestedCallback->addNestedCallback(callback);
|
||||
else
|
||||
_nestedCallback = callback;
|
||||
}
|
||||
}
|
||||
|
||||
void removeCallback(Callback* cb)
|
||||
{
|
||||
if (!cb)
|
||||
return;
|
||||
|
||||
if (_nestedCallback.get() == cb)
|
||||
_nestedCallback = _nestedCallback->getNestedCallback();
|
||||
else if (_nestedCallback.valid())
|
||||
_nestedCallback->removeCallback(cb);
|
||||
}
|
||||
|
||||
protected:
|
||||
osg::ref_ptr<Callback> _nestedCallback;
|
||||
};
|
||||
|
||||
|
||||
typedef std::map<unsigned int, osg::ref_ptr<Callback> > FrameCallback;
|
||||
|
||||
META_Action(osgAnimation, Action);
|
||||
|
||||
Action();
|
||||
Action(const Action&,const osg::CopyOp&);
|
||||
|
||||
void setCallback(double when, Callback* callback)
|
||||
{
|
||||
setCallback(static_cast<unsigned int>(floor(when*_fps)), callback);
|
||||
}
|
||||
|
||||
void setCallback(unsigned int frame, Callback* callback)
|
||||
{
|
||||
if (_framesCallback[frame].valid())
|
||||
_framesCallback[frame]->addNestedCallback(callback);
|
||||
else
|
||||
_framesCallback[frame] = callback;
|
||||
}
|
||||
Callback* getCallback(unsigned int frame)
|
||||
{
|
||||
if (_framesCallback.find(frame) == _framesCallback.end())
|
||||
return 0;
|
||||
return _framesCallback[frame].get();
|
||||
}
|
||||
|
||||
void removeCallback(Callback*);
|
||||
|
||||
Callback* getFrameCallback(unsigned int frame);
|
||||
Callback* getFrameCallback(double time);
|
||||
unsigned int getFramesPerSecond() const { return _fps; }
|
||||
|
||||
void setNumFrames(unsigned int numFrames) { _numberFrame = numFrames;}
|
||||
void setDuration(double duration) { _numberFrame = static_cast<unsigned int>(floor(duration * _fps)); }
|
||||
unsigned int getNumFrames() const { return _numberFrame;}
|
||||
double getDuration() const { return _numberFrame * 1.0 / _fps; }
|
||||
|
||||
// 0 means infini else it's the number of loop
|
||||
virtual void setLoop(int nb) { _loop = nb; }
|
||||
virtual unsigned int getLoop() const { return _loop;}
|
||||
|
||||
// get the number of loop, the frame relative to loop.
|
||||
// return true if in range, and false if out of range.
|
||||
bool evaluateFrame(unsigned int frame, unsigned int& resultframe, unsigned int& nbloop );
|
||||
virtual void traverse(ActionVisitor& visitor) {}
|
||||
//virtual void evaluate(unsigned int frame);
|
||||
|
||||
protected:
|
||||
FrameCallback _framesCallback;
|
||||
|
||||
double _speed;
|
||||
unsigned int _fps;
|
||||
unsigned int _numberFrame;
|
||||
unsigned int _loop;
|
||||
|
||||
enum Status
|
||||
{
|
||||
Play,
|
||||
Stop
|
||||
};
|
||||
|
||||
Status _state;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
41
include/osgAnimation/ActionAnimation
Normal file
41
include/osgAnimation/ActionAnimation
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ACTION_ANIMATION_H
|
||||
#define OSGANIMATION_ACTION_ANIMATION_H
|
||||
|
||||
#include <osgAnimation/Action>
|
||||
#include <osgAnimation/Export>
|
||||
|
||||
|
||||
namespace osgAnimation {
|
||||
|
||||
|
||||
class OSGANIMATION_EXPORT ActionAnimation : public Action
|
||||
{
|
||||
public:
|
||||
META_Action(osgAnimation, ActionAnimation);
|
||||
ActionAnimation();
|
||||
ActionAnimation(const ActionAnimation& a, const osg::CopyOp& c);
|
||||
ActionAnimation(Animation* animation);
|
||||
void updateAnimation(unsigned int frame, int priority);
|
||||
Animation* getAnimation() { return _animation.get(); }
|
||||
|
||||
protected:
|
||||
osg::ref_ptr<Animation> _animation;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
44
include/osgAnimation/ActionBlendIn
Normal file
44
include/osgAnimation/ActionBlendIn
Normal file
@@ -0,0 +1,44 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ACTION_BLENDIN_H
|
||||
#define OSGANIMATION_ACTION_BLENDIN_H
|
||||
|
||||
#include <osgAnimation/Action>
|
||||
#include <osgAnimation/Export>
|
||||
|
||||
|
||||
namespace osgAnimation {
|
||||
|
||||
|
||||
/// blend in from 0 to weight in duration
|
||||
class OSGANIMATION_EXPORT ActionBlendIn : public Action
|
||||
{
|
||||
public:
|
||||
META_Action(osgAnimation, ActionBlendIn);
|
||||
ActionBlendIn();
|
||||
ActionBlendIn(const ActionBlendIn& a, const osg::CopyOp& c);
|
||||
ActionBlendIn(Animation* animation, double duration, double weight);
|
||||
double getWeight() const { return _weight;}
|
||||
Animation* getAnimation() { return _animation.get(); }
|
||||
void computeWeight(unsigned int frame);
|
||||
|
||||
protected:
|
||||
double _weight;
|
||||
osg::ref_ptr<Animation> _animation;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
45
include/osgAnimation/ActionBlendOut
Normal file
45
include/osgAnimation/ActionBlendOut
Normal file
@@ -0,0 +1,45 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ACTION_BLENDOUT_H
|
||||
#define OSGANIMATION_ACTION_BLENDOUT_H
|
||||
|
||||
#include <osgAnimation/Action>
|
||||
#include <osgAnimation/Export>
|
||||
|
||||
|
||||
namespace osgAnimation {
|
||||
|
||||
|
||||
/// blend out from weight to 0 in duration
|
||||
class OSGANIMATION_EXPORT ActionBlendOut : public Action
|
||||
{
|
||||
public:
|
||||
META_Action(osgAnimation, ActionBlendOut);
|
||||
ActionBlendOut();
|
||||
ActionBlendOut(const ActionBlendOut& a, const osg::CopyOp& c);
|
||||
ActionBlendOut(Animation* animation, double duration);
|
||||
Animation* getAnimation() { return _animation.get(); }
|
||||
double getWeight() const { return _weight;}
|
||||
void computeWeight(unsigned int frame);
|
||||
|
||||
protected:
|
||||
double _weight;
|
||||
osg::ref_ptr<Animation> _animation;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
41
include/osgAnimation/ActionCallback
Normal file
41
include/osgAnimation/ActionCallback
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ACTION_CALLBACK_H
|
||||
#define OSGANIMATION_ACTION_CALLBACK_H
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/Action>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
/** Callback used to run new action on the timeline.*/
|
||||
class OSGANIMATION_EXPORT RunAction : public Action::Callback
|
||||
{
|
||||
public:
|
||||
RunAction(Action* a, int priority = 0) : _action(a), _priority(priority) {}
|
||||
virtual void operator()(Action* action, ActionVisitor* visitor);
|
||||
|
||||
Action* getAction() const { return _action.get(); }
|
||||
int getPriority() const { return _priority; }
|
||||
protected:
|
||||
osg::ref_ptr<Action> _action;
|
||||
int _priority;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
57
include/osgAnimation/ActionStripAnimation
Normal file
57
include/osgAnimation/ActionStripAnimation
Normal file
@@ -0,0 +1,57 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ACTION_STRIPANIMATION_H
|
||||
#define OSGANIMATION_ACTION_STRIPANIMATION_H
|
||||
|
||||
#include <osgAnimation/Action>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/FrameAction>
|
||||
#include <osgAnimation/ActionBlendIn>
|
||||
#include <osgAnimation/ActionBlendOut>
|
||||
#include <osgAnimation/ActionAnimation>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
// encapsulate animation with blend in blend out for classic usage
|
||||
class OSGANIMATION_EXPORT ActionStripAnimation : public Action
|
||||
{
|
||||
public:
|
||||
META_Action(osgAnimation, ActionStripAnimation);
|
||||
ActionStripAnimation() {}
|
||||
ActionStripAnimation(const ActionStripAnimation& a, const osg::CopyOp& c);
|
||||
ActionStripAnimation(Animation* animation, double blendInDuration = 0.0, double blendOutDuration = 0.0, double blendInWeightTarget = 1.0 );
|
||||
ActionAnimation* getAnimation();
|
||||
ActionBlendIn* getBlendIn();
|
||||
ActionBlendOut* getBlendOut();
|
||||
const ActionAnimation* getAnimation() const;
|
||||
const ActionBlendIn* getBlendIn() const;
|
||||
const ActionBlendOut* getBlendOut() const;
|
||||
unsigned int getBlendOutStartFrame() const;
|
||||
|
||||
unsigned int getLoop() const;
|
||||
void setLoop(unsigned int loop);
|
||||
void traverse(ActionVisitor& visitor);
|
||||
|
||||
protected:
|
||||
typedef std::pair<unsigned int, osg::ref_ptr<ActionBlendOut> > FrameBlendOut;
|
||||
osg::ref_ptr<ActionBlendIn> _blendIn;
|
||||
FrameBlendOut _blendOut;
|
||||
osg::ref_ptr<ActionAnimation> _animation;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
117
include/osgAnimation/ActionVisitor
Normal file
117
include/osgAnimation/ActionVisitor
Normal file
@@ -0,0 +1,117 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ACTIONVISITOR_H
|
||||
#define OSGANIMATION_ACTIONVISITOR_H
|
||||
|
||||
#include <vector>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osg/Referenced>
|
||||
#include <osgAnimation/FrameAction>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class Timeline;
|
||||
class Action;
|
||||
class ActionBlendIn;
|
||||
class ActionBlendOut;
|
||||
class ActionAnimation;
|
||||
class ActionStripAnimation;
|
||||
|
||||
#define META_ActionVisitor(library,name) \
|
||||
virtual const char* libraryName() const { return #library; }\
|
||||
virtual const char* className() const { return #name; }
|
||||
|
||||
|
||||
class OSGANIMATION_EXPORT ActionVisitor : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
META_ActionVisitor(osgAnimation, ActionVisitor);
|
||||
ActionVisitor();
|
||||
void traverse(Action& visitor);
|
||||
|
||||
void pushFrameActionOnStack(const FrameAction& fa);
|
||||
void popFrameAction();
|
||||
|
||||
void pushTimelineOnStack(Timeline* tm);
|
||||
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);
|
||||
virtual void apply(ActionBlendIn& action);
|
||||
virtual void apply(ActionBlendOut& action);
|
||||
virtual void apply(ActionAnimation& action);
|
||||
virtual void apply(ActionStripAnimation& action);
|
||||
|
||||
protected:
|
||||
std::vector<FrameAction> _stackFrameAction;
|
||||
std::vector<Timeline*> _stackTimeline;
|
||||
int _currentLayer;
|
||||
};
|
||||
|
||||
|
||||
class OSGANIMATION_EXPORT UpdateActionVisitor : public osgAnimation::ActionVisitor
|
||||
{
|
||||
protected:
|
||||
unsigned int _frame;
|
||||
unsigned int _currentAnimationPriority;
|
||||
public:
|
||||
META_ActionVisitor(osgAnimation, UpdateActionVisitor);
|
||||
UpdateActionVisitor();
|
||||
void setFrame(unsigned int frame) { _frame = frame;}
|
||||
|
||||
bool isActive(Action& action) const;
|
||||
unsigned int getLocalFrame() const;
|
||||
|
||||
void apply(Timeline& action);
|
||||
void apply(Action& action);
|
||||
void apply(ActionBlendIn& action);
|
||||
void apply(ActionBlendOut& action);
|
||||
void apply(ActionAnimation& action);
|
||||
void apply(ActionStripAnimation& action);
|
||||
|
||||
};
|
||||
|
||||
|
||||
class OSGANIMATION_EXPORT ClearActionVisitor : public osgAnimation::ActionVisitor
|
||||
{
|
||||
public:
|
||||
enum ClearType {
|
||||
BEFORE_FRAME,
|
||||
AFTER_FRAME
|
||||
};
|
||||
|
||||
META_ActionVisitor(osgAnimation, ClearActionVisitor);
|
||||
ClearActionVisitor(ClearType type = BEFORE_FRAME);
|
||||
void setFrame(unsigned int frame) { _frame = frame;}
|
||||
|
||||
void apply(Timeline& action);
|
||||
void apply(Action& action);
|
||||
|
||||
protected:
|
||||
unsigned int _frame;
|
||||
std::vector<osg::ref_ptr<Action> > _remove;
|
||||
ClearType _clearType;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -31,7 +31,7 @@ namespace osgAnimation
|
||||
META_Object(osgAnimation, Animation)
|
||||
|
||||
Animation() : _duration(0), _weight(0), _startTime(0), _playmode(LOOP) {}
|
||||
Animation(const osgAnimation::Animation& anim, const osg::CopyOp&);
|
||||
Animation(const osgAnimation::Animation&, const osg::CopyOp&);
|
||||
|
||||
enum PlayMode
|
||||
{
|
||||
@@ -71,10 +71,12 @@ namespace osgAnimation
|
||||
void setWeight (float weight);
|
||||
float getWeight() const;
|
||||
|
||||
bool update (float time);
|
||||
bool update (float time, int priority = 0);
|
||||
void resetTargets();
|
||||
|
||||
void setPlaymode (PlayMode mode) { _playmode = mode; }
|
||||
PlayMode getPlayMode() const { return _playmode; }
|
||||
|
||||
void setStartTime(float time) { _startTime = time;}
|
||||
float getStartTime() const { return _startTime;}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -12,9 +12,10 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ANIMATION_MANAGER_BASE_H
|
||||
#define OSGANIMATION_ANIMATION_MANAGER_BASE_H
|
||||
#ifndef OSGANIMATION_ANIMATION_MANAGER_BASE
|
||||
#define OSGANIMATION_ANIMATION_MANAGER_BASE 1
|
||||
|
||||
#include <osgAnimation/LinkVisitor>
|
||||
#include <osgAnimation/Animation>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osg/FrameStamp>
|
||||
@@ -33,7 +34,8 @@ namespace osgAnimation
|
||||
AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY);
|
||||
virtual ~AnimationManagerBase();
|
||||
virtual void buildTargetReference();
|
||||
virtual void registerAnimation (Animation* animation);
|
||||
virtual void registerAnimation (Animation*);
|
||||
virtual void unregisterAnimation (Animation*);
|
||||
virtual void link(osg::Node* subgraph);
|
||||
virtual void update(double t) = 0;
|
||||
virtual bool needToLink() const;
|
||||
@@ -42,16 +44,26 @@ namespace osgAnimation
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
|
||||
/// Operation that must be done each frame
|
||||
/** Reset the value of targets
|
||||
this Operation must be done each frame */
|
||||
void clearTargets();
|
||||
void normalizeTargets();
|
||||
|
||||
|
||||
LinkVisitor* getOrCreateLinkVisitor();
|
||||
void setLinkVisitor(LinkVisitor*);
|
||||
|
||||
/// set a flag to define the behaviour
|
||||
void setAutomaticLink(bool);
|
||||
bool isAutomaticLink() const;
|
||||
void dirty();
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<LinkVisitor> _linker;
|
||||
AnimationList _animations;
|
||||
TargetSet _targets;
|
||||
bool _needToLink;
|
||||
bool _automaticLink;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
72
include/osgAnimation/AnimationUpdateCallback
Normal file
72
include/osgAnimation/AnimationUpdateCallback
Normal file
@@ -0,0 +1,72 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_ANIMATION_UPDATE_CALLBACK
|
||||
#define OSGANIMATION_ANIMATION_UPDATE_CALLBACK 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osgAnimation/Channel>
|
||||
#include <osgAnimation/Animation>
|
||||
#include <string>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class AnimationUpdateCallbackBase : public virtual osg::Object
|
||||
{
|
||||
public:
|
||||
virtual bool link(Channel* channel) = 0;
|
||||
virtual int link(Animation* animation) = 0;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class AnimationUpdateCallback : public AnimationUpdateCallbackBase, public T
|
||||
{
|
||||
public:
|
||||
AnimationUpdateCallback() {}
|
||||
AnimationUpdateCallback(const std::string& name) { T::setName(name);}
|
||||
AnimationUpdateCallback(const AnimationUpdateCallback& apc,const osg::CopyOp& copyop): T(apc, copyop) {}
|
||||
|
||||
META_Object(osgAnimation, AnimationUpdateCallback<T>);
|
||||
|
||||
const std::string& getName() const { return T::getName(); }
|
||||
bool link(Channel* channel) { return 0; }
|
||||
int link(Animation* animation)
|
||||
{
|
||||
if (T::getName().empty())
|
||||
{
|
||||
osg::notify(osg::WARN) << "An update callback has no name, it means it could link only with \"\" named Target, often an error, discard" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
int nbLinks = 0;
|
||||
for (ChannelList::iterator it = animation->getChannels().begin();
|
||||
it != animation->getChannels().end();
|
||||
++it)
|
||||
{
|
||||
std::string targetName = (*it)->getTargetName();
|
||||
if (targetName == T::getName())
|
||||
{
|
||||
AnimationUpdateCallbackBase* a = this;
|
||||
a->link((*it).get());
|
||||
nbLinks++;
|
||||
}
|
||||
}
|
||||
return nbLinks;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -10,39 +10,26 @@
|
||||
* 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.
|
||||
*/
|
||||
*
|
||||
* Authors:
|
||||
* Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
* Michael Platings <mplatings@pixelpower.com>
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_BONE_H
|
||||
#define OSGANIMATION_BONE_H
|
||||
#ifndef OSGANIMATION_BONE
|
||||
#define OSGANIMATION_BONE 1
|
||||
|
||||
#include <osg/Transform>
|
||||
#include <osg/Quat>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Node>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Notify>
|
||||
#include <osg/io_utils>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/Target>
|
||||
#include <osgAnimation/Sampler>
|
||||
#include <osgAnimation/Channel>
|
||||
#include <osgAnimation/Keyframe>
|
||||
#include <osgAnimation/UpdateCallback>
|
||||
#include <osgAnimation/Animation>
|
||||
#include <osgAnimation/AnimationManagerBase>
|
||||
#include <osgAnimation/VertexInfluence>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
// A bone can't have more than one parent Bone, so sharing a part of Bone's hierarchy
|
||||
// has not sense. You can share the entire hierarchie but not only a part of
|
||||
class OSGANIMATION_EXPORT Bone : public osg::Transform
|
||||
// makes no sense. You can share the entire hierarchy but not only a part of it.
|
||||
class OSGANIMATION_EXPORT Bone : public osg::MatrixTransform
|
||||
{
|
||||
public:
|
||||
typedef osg::ref_ptr<Bone> PointerType;
|
||||
typedef std::map<std::string, PointerType > BoneMap;
|
||||
typedef osg::Matrix MatrixType;
|
||||
|
||||
META_Node(osgAnimation, Bone);
|
||||
@@ -51,230 +38,24 @@ 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class OSGANIMATION_EXPORT UpdateBone : public AnimationUpdateCallback
|
||||
{
|
||||
public:
|
||||
osg::ref_ptr<osgAnimation::Vec3Target> _position;
|
||||
osg::ref_ptr<osgAnimation::QuatTarget> _quaternion;
|
||||
osg::ref_ptr<osgAnimation::Vec3Target> _scale;
|
||||
|
||||
public:
|
||||
META_Object(osgAnimation, UpdateBone);
|
||||
UpdateBone(const UpdateBone& apc,const osg::CopyOp& copyop);
|
||||
|
||||
UpdateBone(const std::string& name = "")
|
||||
{
|
||||
setName(name);
|
||||
_quaternion = new osgAnimation::QuatTarget;
|
||||
_position = new osgAnimation::Vec3Target;
|
||||
_scale = new osgAnimation::Vec3Target;
|
||||
}
|
||||
|
||||
void update(osgAnimation::Bone& bone)
|
||||
{
|
||||
bone.setTranslation(_position->getValue());
|
||||
bone.setRotation(_quaternion->getValue());
|
||||
bone.setScale(_scale->getValue());
|
||||
bone.dirtyBound();
|
||||
}
|
||||
|
||||
bool needLink() const
|
||||
{
|
||||
// the idea is to return true if nothing is linked
|
||||
return !((_position->getCount() + _quaternion->getCount() + _scale->getCount()) > 3);
|
||||
}
|
||||
|
||||
bool link(osgAnimation::Channel* channel)
|
||||
{
|
||||
if (channel->getName().find("quaternion") != std::string::npos)
|
||||
{
|
||||
osgAnimation::QuatSphericalLinearChannel* qc = dynamic_cast<osgAnimation::QuatSphericalLinearChannel*>(channel);
|
||||
if (qc)
|
||||
{
|
||||
qc->setTarget(_quaternion.get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (channel->getName().find("position") != std::string::npos)
|
||||
{
|
||||
osgAnimation::Vec3LinearChannel* vc = dynamic_cast<osgAnimation::Vec3LinearChannel*>(channel);
|
||||
if (vc)
|
||||
{
|
||||
vc->setTarget(_position.get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (channel->getName().find("scale") != std::string::npos)
|
||||
{
|
||||
osgAnimation::Vec3LinearChannel* vc = dynamic_cast<osgAnimation::Vec3LinearChannel*>(channel);
|
||||
if (vc)
|
||||
{
|
||||
vc->setTarget(_scale.get());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Channel " << channel->getName() << " does not contain a valid symbolic name for this class" << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
|
||||
{
|
||||
Bone* b = dynamic_cast<Bone*>(node);
|
||||
if (b && !_manager.valid())
|
||||
{
|
||||
FindNearestParentAnimationManager finder;
|
||||
|
||||
if (b->getParents().size() > 1)
|
||||
{
|
||||
osg::notify(osg::WARN) << "A Bone should not have multi parent ( " << b->getName() << " ) has parents ";
|
||||
osg::notify(osg::WARN) << "( " << b->getParents()[0]->getName();
|
||||
for (int i = 1; i < (int)b->getParents().size(); i++)
|
||||
osg::notify(osg::WARN) << ", " << b->getParents()[i]->getName();
|
||||
osg::notify(osg::WARN) << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
b->getParents()[0]->accept(finder);
|
||||
|
||||
if (!finder._manager.valid())
|
||||
{
|
||||
osg::notify(osg::WARN) << "Warning can't update Bone, path to parent AnimationManagerBase not found" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
_manager = finder._manager.get();
|
||||
}
|
||||
|
||||
updateLink();
|
||||
update(*b);
|
||||
}
|
||||
traverse(node,nv);
|
||||
}
|
||||
};
|
||||
|
||||
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
|
||||
virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
|
||||
|
||||
Bone* getBoneParent();
|
||||
const Bone* getBoneParent() const;
|
||||
|
||||
void setTranslation(const osg::Vec3& trans) { _position = trans;}
|
||||
void setRotation(const osg::Quat& quat) { _rotation = quat;}
|
||||
void setScale(const osg::Vec3& scale) { _scale = scale;}
|
||||
|
||||
const osg::Vec3& getTranslation() const { return _position;}
|
||||
const osg::Quat& getRotation() const { return _rotation;}
|
||||
osg::Matrix getMatrixInBoneSpace() const { return (osg::Matrix(getRotation())) * osg::Matrix::translate(getTranslation()) * _bindInBoneSpace;}
|
||||
const osg::Matrix& getBindMatrixInBoneSpace() const { return _bindInBoneSpace; }
|
||||
const osg::Matrix& getMatrixInBoneSpace() const { return getMatrix();}
|
||||
const osg::Matrix& getMatrixInSkeletonSpace() const { return _boneInSkeletonSpace; }
|
||||
const osg::Matrix& getInvBindMatrixInSkeletonSpace() const { return _invBindInSkeletonSpace;}
|
||||
void setMatrixInSkeletonSpace(const osg::Matrix& matrix) { _boneInSkeletonSpace = matrix; }
|
||||
void setBindMatrixInBoneSpace(const osg::Matrix& matrix)
|
||||
{
|
||||
_bindInBoneSpace = matrix;
|
||||
_needToRecomputeBindMatrix = true;
|
||||
}
|
||||
|
||||
inline bool needToComputeBindMatrix() { return _needToRecomputeBindMatrix;}
|
||||
virtual void computeBindMatrix();
|
||||
|
||||
bool needLink() const;
|
||||
|
||||
void setNeedToComputeBindMatrix(bool state) { _needToRecomputeBindMatrix = state; }
|
||||
|
||||
/** Add Node to Group.
|
||||
* If node is not NULL and is not contained in Group then increment its
|
||||
* reference count, add it to the child list and dirty the bounding
|
||||
* sphere to force it to recompute on next getBound() and return true for success.
|
||||
* Otherwise return false. Scene nodes can't be added as child nodes.
|
||||
*/
|
||||
virtual bool addChild( Node *child );
|
||||
BoneMap getBoneMap();
|
||||
|
||||
void setInvBindMatrixInSkeletonSpace(const osg::Matrix& matrix) { _invBindInSkeletonSpace = matrix; }
|
||||
|
||||
protected:
|
||||
|
||||
osg::Vec3 _position;
|
||||
osg::Quat _rotation;
|
||||
osg::Vec3 _scale;
|
||||
|
||||
|
||||
// flag to recompute bind pose
|
||||
bool _needToRecomputeBindMatrix;
|
||||
|
||||
// bind data
|
||||
osg::Matrix _bindInBoneSpace;
|
||||
osg::Matrix _invBindInSkeletonSpace;
|
||||
|
||||
// bone updated
|
||||
osg::Matrix _boneInSkeletonSpace;
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline bool Bone::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const
|
||||
{
|
||||
if (_referenceFrame==RELATIVE_RF)
|
||||
matrix.preMult(getMatrixInBoneSpace());
|
||||
else
|
||||
matrix = getMatrixInBoneSpace();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline bool Bone::computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const
|
||||
{
|
||||
if (_referenceFrame==RELATIVE_RF)
|
||||
matrix.postMult(osg::Matrix::inverse(getMatrixInBoneSpace()));
|
||||
else
|
||||
matrix = osg::Matrix::inverse(getMatrixInBoneSpace());
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef std::map<std::string, osg::ref_ptr<Bone> > BoneMap;
|
||||
}
|
||||
#endif
|
||||
|
||||
42
include/osgAnimation/BoneMapVisitor
Normal file
42
include/osgAnimation/BoneMapVisitor
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*
|
||||
* Authors:
|
||||
* Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_BONEMAP_VISITOR
|
||||
#define OSGANIMATION_BONEMAP_VISITOR 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/Bone>
|
||||
#include <osg/NodeVisitor>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
class OSGANIMATION_EXPORT BoneMapVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
META_NodeVisitor("osgAnimation","BoneMapVisitor")
|
||||
BoneMapVisitor();
|
||||
|
||||
void apply(osg::Node&);
|
||||
void apply(osg::Transform& node);
|
||||
const BoneMap& getBoneMap() const;
|
||||
|
||||
protected:
|
||||
BoneMap _map;
|
||||
};
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -10,7 +10,11 @@
|
||||
* 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.
|
||||
*/
|
||||
*
|
||||
* Authors:
|
||||
* Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
* Michael Platings <mplatings@pixelpower.com>
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_CHANNEL_H
|
||||
#define OSGANIMATION_CHANNEL_H
|
||||
@@ -29,11 +33,14 @@ namespace osgAnimation
|
||||
public:
|
||||
|
||||
Channel();
|
||||
Channel(const Channel& channel);
|
||||
virtual ~Channel();
|
||||
virtual Channel* clone() const = 0;
|
||||
|
||||
virtual void update(float time) = 0;
|
||||
virtual void update(float time, float weight, int priority) = 0;
|
||||
virtual void reset() = 0;
|
||||
virtual Target* getTarget() = 0;
|
||||
virtual bool setTarget(Target*) = 0;
|
||||
|
||||
const std::string& getName() const;
|
||||
void setName(const std::string& name);
|
||||
@@ -44,17 +51,18 @@ namespace osgAnimation
|
||||
const std::string& getTargetName() const;
|
||||
void setTargetName(const std::string& name);
|
||||
|
||||
float getWeight() const;
|
||||
void setWeight(float w);
|
||||
|
||||
virtual Sampler* getSampler() = 0;
|
||||
virtual const Sampler* getSampler() const = 0;
|
||||
|
||||
// create a keyframe container from current target value
|
||||
// with one key only, can be used for debug or to create
|
||||
// easily a default channel from an existing one
|
||||
virtual bool createKeyframeContainerFromTargetValue() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
std::string _targetName;
|
||||
std::string _name;
|
||||
float _weight;
|
||||
};
|
||||
|
||||
|
||||
@@ -66,8 +74,19 @@ namespace osgAnimation
|
||||
typedef typename SamplerType::UsingType UsingType;
|
||||
typedef TemplateTarget<UsingType> TargetType;
|
||||
typedef TemplateKeyframeContainer<typename SamplerType::KeyframeType> KeyframeContainerType;
|
||||
Channel* clone() const { return new TemplateChannel<SamplerType>(*this); }
|
||||
|
||||
TemplateChannel (SamplerType* s = 0,TargetType* target = 0)
|
||||
TemplateChannel (const TemplateChannel& channel) :
|
||||
Channel(channel)
|
||||
{
|
||||
if (channel.getTargetTyped())
|
||||
_target = new TargetType(*channel.getTargetTyped());
|
||||
|
||||
if (channel.getSamplerTyped())
|
||||
_sampler = new SamplerType(*channel.getSamplerTyped());
|
||||
}
|
||||
|
||||
TemplateChannel (SamplerType* s = 0,TargetType* target = 0)
|
||||
{
|
||||
if (target)
|
||||
_target = target;
|
||||
@@ -76,20 +95,42 @@ namespace osgAnimation
|
||||
_sampler = s;
|
||||
}
|
||||
|
||||
virtual bool createKeyframeContainerFromTargetValue()
|
||||
{
|
||||
if (!_target.valid()) // no target it does not make sense to do it
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// create a key from current target value
|
||||
typename KeyframeContainerType::KeyType key(0, _target->getValue());
|
||||
// recreate the keyframe container
|
||||
getOrCreateSampler()->setKeyframeContainer(0);
|
||||
getOrCreateSampler()->getOrCreateKeyframeContainer();
|
||||
// add the key
|
||||
_sampler->getKeyframeContainerTyped()->push_back(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual ~TemplateChannel() {}
|
||||
virtual void update(float time)
|
||||
virtual void update(float time, float weight, int priority)
|
||||
{
|
||||
// skip if weight == 0
|
||||
if (_weight < 1e-4)
|
||||
if (weight < 1e-4)
|
||||
return;
|
||||
typename SamplerType::UsingType value;
|
||||
_sampler->getValueAt(time, value);
|
||||
_target->update(_weight, value);
|
||||
_target->update(weight, value, priority);
|
||||
}
|
||||
virtual void reset() { _target->reset(); }
|
||||
virtual Target* getTarget() { return _target.get();}
|
||||
virtual bool setTarget(Target* target)
|
||||
{
|
||||
_target = dynamic_cast<TargetType*>(target);
|
||||
return _target.get() == target;
|
||||
}
|
||||
|
||||
SamplerType* getOrCreateSampler()
|
||||
SamplerType* getOrCreateSampler()
|
||||
{
|
||||
if (!_sampler.valid())
|
||||
_sampler = new SamplerType;
|
||||
@@ -104,6 +145,7 @@ namespace osgAnimation
|
||||
void setSampler(SamplerType* sampler) { _sampler = sampler; }
|
||||
|
||||
TargetType* getTargetTyped() { return _target.get(); }
|
||||
const TargetType* getTargetTyped() const { return _target.get(); }
|
||||
void setTarget(TargetType* target) { _target = target; }
|
||||
|
||||
virtual float getStartTime() const { return _sampler->getStartTime(); }
|
||||
@@ -116,13 +158,21 @@ namespace osgAnimation
|
||||
|
||||
|
||||
typedef std::vector<osg::ref_ptr<osgAnimation::Channel> > ChannelList;
|
||||
|
||||
typedef TemplateChannel<DoubleStepSampler> DoubleStepChannel;
|
||||
typedef TemplateChannel<FloatStepSampler> FloatStepChannel;
|
||||
typedef TemplateChannel<Vec2StepSampler> Vec2StepChannel;
|
||||
typedef TemplateChannel<Vec3StepSampler> Vec3StepChannel;
|
||||
typedef TemplateChannel<Vec4StepSampler> Vec4StepChannel;
|
||||
typedef TemplateChannel<QuatStepSampler> QuatStepChannel;
|
||||
|
||||
typedef TemplateChannel<DoubleLinearSampler> DoubleLinearChannel;
|
||||
typedef TemplateChannel<FloatLinearSampler> FloatLinearChannel;
|
||||
|
||||
typedef TemplateChannel<Vec2LinearSampler> Vec2LinearChannel;
|
||||
typedef TemplateChannel<Vec3LinearSampler> Vec3LinearChannel;
|
||||
typedef TemplateChannel<Vec4LinearSampler> Vec4LinearChannel;
|
||||
typedef TemplateChannel<QuatSphericalLinearSampler> QuatSphericalLinearChannel;
|
||||
typedef TemplateChannel<MatrixLinearSampler> MatrixLinearChannel;
|
||||
|
||||
typedef TemplateChannel<FloatCubicBezierSampler> FloatCubicBezierChannel;
|
||||
typedef TemplateChannel<DoubleCubicBezierSampler> DoubleCubicBezierChannel;
|
||||
|
||||
@@ -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
|
||||
@@ -12,38 +12,61 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_CUBIC_BEZIER_H
|
||||
#define OSGANIMATION_CUBIC_BEZIER_H
|
||||
#ifndef OSGANIMATION_CUBIC_BEZIER
|
||||
#define OSGANIMATION_CUBIC_BEZIER 1
|
||||
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Quat>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
template <class T>
|
||||
struct TemplateCubicBezier
|
||||
class TemplateCubicBezier
|
||||
{
|
||||
T mPoint[3];
|
||||
const T& getP0() const { return mPoint[0];}
|
||||
const T& getP1() const { return mPoint[1];}
|
||||
const T& getP2() const { return mPoint[2];}
|
||||
TemplateCubicBezier(const T& v0, const T& v1, const T& v2)
|
||||
{
|
||||
mPoint[0] = v0;
|
||||
mPoint[1] = v1;
|
||||
mPoint[2] = v2;
|
||||
}
|
||||
|
||||
public:
|
||||
TemplateCubicBezier() {}
|
||||
|
||||
const T& getPosition() const { return mPoint[0];}
|
||||
const T& getTangentPoint1() const { return mPoint[1];}
|
||||
const T& getTangentPoint2() const { return mPoint[2];}
|
||||
};
|
||||
TemplateCubicBezier(const T& p, const T& i, const T& o) : _position(p), _controlPointIn(i), _controlPointOut(o)
|
||||
{
|
||||
}
|
||||
|
||||
// Constructor with value only
|
||||
TemplateCubicBezier(const T& p) : _position(p), _controlPointIn(p), _controlPointOut(p)
|
||||
{
|
||||
}
|
||||
|
||||
const T& getPosition() const { return _position;}
|
||||
const T& getControlPointIn() const { return _controlPointIn;}
|
||||
const T& getControlPointOut() const { return _controlPointOut;}
|
||||
|
||||
T& getPosition() { return _position;}
|
||||
T& getControlPointIn() { return _controlPointIn;}
|
||||
T& getControlPointOut() { return _controlPointOut;}
|
||||
|
||||
void setPosition(const T& v) {_position = v;}
|
||||
void setControlPointIn(const T& v) {_controlPointIn = v;}
|
||||
void setControlPointOut(const T& v) {_controlPointOut = v;}
|
||||
|
||||
// steaming operators.
|
||||
friend std::ostream& operator << (std::ostream& output, const TemplateCubicBezier<T>& tcb)
|
||||
{
|
||||
output << tcb._position << " "
|
||||
<< tcb._controlPointIn << " "
|
||||
<< tcb._controlPointOut;
|
||||
return output; // to enable cascading
|
||||
}
|
||||
|
||||
friend std::istream& operator >> (std::istream& input, TemplateCubicBezier<T>& tcb)
|
||||
{
|
||||
input >> tcb._position >> tcb._controlPointIn >> tcb._controlPointOut;
|
||||
return input;
|
||||
}
|
||||
|
||||
protected:
|
||||
T _position, _controlPointIn, _controlPointOut;
|
||||
};
|
||||
|
||||
typedef TemplateCubicBezier<float> FloatCubicBezier;
|
||||
typedef TemplateCubicBezier<double> DoubleCubicBezier;
|
||||
|
||||
@@ -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
|
||||
@@ -10,10 +10,10 @@
|
||||
* 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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_EASE_MOTION_H
|
||||
#define OSGANIMATION_EASE_MOTION_H
|
||||
#ifndef OSGANIMATION_EASE_MOTION
|
||||
#define OSGANIMATION_EASE_MOTION 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
#include <osg/ref_ptr>
|
||||
@@ -21,9 +21,8 @@
|
||||
#include <osg/Math>
|
||||
#include <vector>
|
||||
|
||||
namespace osgAnimation {
|
||||
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
struct OutBounceFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
@@ -76,14 +75,12 @@ namespace osgAnimation {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// Linear function
|
||||
struct LinearFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result) { result = t;}
|
||||
};
|
||||
|
||||
|
||||
/// Quad function
|
||||
struct OutQuadFunction
|
||||
{
|
||||
@@ -94,46 +91,47 @@ namespace osgAnimation {
|
||||
{
|
||||
inline static void getValueAt(float t, float& result) { result = t*t;}
|
||||
};
|
||||
|
||||
struct InOutQuadFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
t = t * 2.0;
|
||||
if (t < 1.0)
|
||||
{
|
||||
t *= 2.0;
|
||||
if (t < 1.0)
|
||||
result = 0.5 * t * t;
|
||||
else
|
||||
{
|
||||
t = t - 1.0;
|
||||
result = - 0.5 * t * ( t - 2) - 1;
|
||||
t -= 1.0;
|
||||
result = - 0.5 * (t * ( t - 2) - 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// Cubic function
|
||||
struct OutCubicFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result) { t = t-1.0; result = t*t*t + 1;}
|
||||
};
|
||||
|
||||
struct InCubicFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result) { result = t*t*t;}
|
||||
};
|
||||
|
||||
struct InOutCubicFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
t = t * 2;
|
||||
if (t < 1.0)
|
||||
result = 0.5 * t * t * t;
|
||||
t *= 2.0f;
|
||||
if (t < 1.0f)
|
||||
result = 0.5f * t * t * t;
|
||||
else {
|
||||
t = t - 2;
|
||||
result = 0.5 * t * t * t + 2;
|
||||
t -= 2.0f;
|
||||
result = 0.5 * (t * t * t + 2.0f);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// Quart function
|
||||
struct InQuartFunction
|
||||
{
|
||||
@@ -160,7 +158,191 @@ namespace osgAnimation {
|
||||
}
|
||||
};
|
||||
|
||||
/// Elastic function
|
||||
struct OutElasticFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
result = pow(2.0f, -10.0f * t) * sinf((t - 0.3f / 4.0f) * (2.0f * osg::PI) / 0.3f) + 1.0f;
|
||||
}
|
||||
};
|
||||
|
||||
struct InElasticFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
OutElasticFunction::getValueAt(1.0f - t, result);
|
||||
result = 1.0f - result;
|
||||
}
|
||||
};
|
||||
|
||||
struct InOutElasticFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
t *= 2.0f;
|
||||
if (t < 1.0f)
|
||||
{
|
||||
t -= 1.0f;
|
||||
result = -0.5 * (1.0f * pow(2.0f, 10.0f * t) * sinf((t - 0.45f / 4.0f) * (2.0f * osg::PI) / 0.45f));
|
||||
}
|
||||
else
|
||||
{
|
||||
t -= 1.0f;
|
||||
result = pow(2.0f, -10.0f * t) * sinf((t - 0.45f / 4.0f) * (2.0f * osg::PI) / 0.45f) * 0.5f + 1.0f;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Sine function
|
||||
struct OutSineFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
result = sinf(t * (osg::PI / 2.0f));
|
||||
}
|
||||
};
|
||||
|
||||
struct InSineFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
result = -cosf(t * (osg::PI / 2.0f)) + 1.0f;
|
||||
}
|
||||
};
|
||||
|
||||
struct InOutSineFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
result = -0.5f * (cosf((osg::PI * t)) - 1.0f);
|
||||
}
|
||||
};
|
||||
|
||||
// Back function
|
||||
struct OutBackFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
t -= 1.0f;
|
||||
result = t * t * ((1.70158 + 1.0f) * t + 1.70158) + 1.0f;
|
||||
}
|
||||
};
|
||||
|
||||
struct InBackFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
result = t * t * ((1.70158 + 1.0f) * t - 1.70158);
|
||||
}
|
||||
};
|
||||
|
||||
struct InOutBackFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
float s = 1.70158 * 1.525f;
|
||||
t *= 2.0f;
|
||||
if (t < 1.0f)
|
||||
{
|
||||
result = 0.5f * (t * t * ((s + 1.0f) * t - s));
|
||||
}
|
||||
else
|
||||
{
|
||||
float p = t -= 2.0f;
|
||||
result = 0.5f * ((p) * t * ((s + 1.0f) * t + s) + 2.0f);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Circ function
|
||||
struct OutCircFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
t -= 1.0f;
|
||||
result = sqrt(1.0f - t * t);
|
||||
}
|
||||
};
|
||||
|
||||
struct InCircFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
result = -(sqrt(1.0f - (t * t)) - 1.0f);
|
||||
}
|
||||
};
|
||||
|
||||
struct InOutCircFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
t *= 2.0f;
|
||||
if (t < 1.0f)
|
||||
{
|
||||
result = -0.5f * (sqrt(1.0f - t * t) - 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
t -= 2.0f;
|
||||
result = 0.5f * (sqrt(1 - t * t) + 1.0f);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Expo function
|
||||
struct OutExpoFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
if(t == 1.0f)
|
||||
{
|
||||
result = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = -powf(2.0f, -10.0f * t) + 1.0f;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct InExpoFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
if(t == 0.0f)
|
||||
{
|
||||
result = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = powf(2.0f, 10.0f * (t - 1.0f));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct InOutExpoFunction
|
||||
{
|
||||
inline static void getValueAt(float t, float& result)
|
||||
{
|
||||
if(t == 0.0f || t == 1.0f)
|
||||
{
|
||||
result = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
t *= 2.0f;
|
||||
if(t < 1.0f)
|
||||
{
|
||||
result = 0.5f * powf(2.0f, 10.0f * (t - 1.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0.5f * (-powf(2.0f, -10.0f * (t - 1.0f)) + 2.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Motion : public osg::Referenced
|
||||
{
|
||||
@@ -278,7 +460,7 @@ namespace osgAnimation {
|
||||
osg::notify(osg::WARN) << "CompositeMotion::getValueInNormalizedRange no Motion in the CompositeMotion, add motion to have result" << std::endl;
|
||||
return;
|
||||
}
|
||||
for (MotionList::const_iterator it = _motions.begin(); it != _motions.end(); it++)
|
||||
for (MotionList::const_iterator it = _motions.begin(); it != _motions.end(); ++it)
|
||||
{
|
||||
const Motion* motion = static_cast<const Motion*>(it->get());
|
||||
float durationInRange = motion->getDuration() / getDuration();
|
||||
@@ -314,13 +496,35 @@ namespace osgAnimation {
|
||||
typedef MathMotionTemplate<InQuartFunction> InQuartMotion;
|
||||
typedef MathMotionTemplate<InOutQuartFunction> InOutQuartMotion;
|
||||
|
||||
|
||||
// bounce
|
||||
typedef MathMotionTemplate<OutBounceFunction > OutBounceMotion;
|
||||
typedef MathMotionTemplate<InBounceFunction> InBounceMotion;
|
||||
typedef MathMotionTemplate<InOutBounceFunction> InOutBounceMotion;
|
||||
|
||||
// elastic
|
||||
typedef MathMotionTemplate<OutElasticFunction > OutElasticMotion;
|
||||
typedef MathMotionTemplate<InElasticFunction > InElasticMotion;
|
||||
typedef MathMotionTemplate<InOutElasticFunction > InOutElasticMotion;
|
||||
|
||||
// sine
|
||||
typedef MathMotionTemplate<OutSineFunction > OutSineMotion;
|
||||
typedef MathMotionTemplate<InSineFunction > InSineMotion;
|
||||
typedef MathMotionTemplate<InOutSineFunction > InOutSineMotion;
|
||||
|
||||
// back
|
||||
typedef MathMotionTemplate<OutBackFunction > OutBackMotion;
|
||||
typedef MathMotionTemplate<InBackFunction > InBackMotion;
|
||||
typedef MathMotionTemplate<InOutBackFunction > InOutBackMotion;
|
||||
|
||||
// circ
|
||||
typedef MathMotionTemplate<OutCircFunction > OutCircMotion;
|
||||
typedef MathMotionTemplate<InCircFunction > InCircMotion;
|
||||
typedef MathMotionTemplate<InOutCircFunction > InOutCircMotion;
|
||||
|
||||
// expo
|
||||
typedef MathMotionTemplate<OutExpoFunction > OutExpoMotion;
|
||||
typedef MathMotionTemplate<InExpoFunction > InExpoMotion;
|
||||
typedef MathMotionTemplate<InOutExpoFunction > InOutExpoMotion;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
26
include/osgAnimation/FrameAction
Normal file
26
include/osgAnimation/FrameAction
Normal file
@@ -0,0 +1,26 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_FRAMEACTION_H
|
||||
#define OSGANIMATION_FRAMEACTION_H
|
||||
|
||||
#include <map>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
class Action;
|
||||
typedef std::pair<unsigned int, osg::ref_ptr<Action> > FrameAction;
|
||||
}
|
||||
#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
|
||||
@@ -10,13 +10,16 @@
|
||||
* 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.
|
||||
*/
|
||||
*
|
||||
* Authors:
|
||||
* Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
* Michael Platings <mplatings@pixelpower.com>
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_INTERPOLATOR_H
|
||||
#define OSGANIMATION_INTERPOLATOR_H
|
||||
#ifndef OSGANIMATION_INTERPOLATOR
|
||||
#define OSGANIMATION_INTERPOLATOR 1
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osgAnimation/Interpolator>
|
||||
#include <osgAnimation/Keyframe>
|
||||
|
||||
namespace osgAnimation
|
||||
@@ -61,6 +64,32 @@ namespace osgAnimation
|
||||
};
|
||||
|
||||
|
||||
template <class TYPE, class KEY=TYPE>
|
||||
class TemplateStepInterpolator : public TemplateInterpolatorBase<TYPE,KEY>
|
||||
{
|
||||
public:
|
||||
|
||||
TemplateStepInterpolator() {}
|
||||
void getValue(const TemplateKeyframeContainer<KEY>& keyframes, float time, TYPE& result) const
|
||||
{
|
||||
|
||||
if (time >= keyframes.back().getTime())
|
||||
{
|
||||
result = keyframes.back().getValue();
|
||||
return;
|
||||
}
|
||||
else if (time <= keyframes.front().getTime())
|
||||
{
|
||||
result = keyframes.front().getValue();
|
||||
return;
|
||||
}
|
||||
|
||||
int i = getKeyIndexFromTime(keyframes,time);
|
||||
result = keyframes[i].getValue();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class TYPE, class KEY=TYPE>
|
||||
class TemplateLinearInterpolator : public TemplateInterpolatorBase<TYPE,KEY>
|
||||
{
|
||||
@@ -176,14 +205,22 @@ namespace osgAnimation
|
||||
float t2 = t * t;
|
||||
|
||||
TYPE v0 = keyframes[i].getValue().getPosition() * one_minus_t3;
|
||||
TYPE v1 = keyframes[i].getValue().getTangentPoint1() * (3.0 * t * one_minus_t2);
|
||||
TYPE v2 = keyframes[i].getValue().getTangentPoint2() * (3.0 * t2 * one_minus_t);
|
||||
TYPE v1 = keyframes[i].getValue().getControlPointIn() * (3.0 * t * one_minus_t2);
|
||||
TYPE v2 = keyframes[i].getValue().getControlPointOut() * (3.0 * t2 * one_minus_t);
|
||||
TYPE v3 = keyframes[i+1].getValue().getPosition() * (t2 * t);
|
||||
|
||||
result = v0 + v1 + v2 + v3;
|
||||
}
|
||||
};
|
||||
|
||||
typedef TemplateStepInterpolator<double, double> DoubleStepInterpolator;
|
||||
typedef TemplateStepInterpolator<float, float> FloatStepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Vec2, osg::Vec2> Vec2StepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Vec3, osg::Vec3> Vec3StepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Vec3, Vec3Packed> Vec3PackedStepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Vec4, osg::Vec4> Vec4StepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Quat, osg::Quat> QuatStepInterpolator;
|
||||
|
||||
typedef TemplateLinearInterpolator<double, double> DoubleLinearInterpolator;
|
||||
typedef TemplateLinearInterpolator<float, float> FloatLinearInterpolator;
|
||||
typedef TemplateLinearInterpolator<osg::Vec2, osg::Vec2> Vec2LinearInterpolator;
|
||||
@@ -191,6 +228,7 @@ namespace osgAnimation
|
||||
typedef TemplateLinearInterpolator<osg::Vec3, Vec3Packed> Vec3PackedLinearInterpolator;
|
||||
typedef TemplateLinearInterpolator<osg::Vec4, osg::Vec4> Vec4LinearInterpolator;
|
||||
typedef TemplateSphericalLinearInterpolator<osg::Quat, osg::Quat> QuatSphericalLinearInterpolator;
|
||||
typedef TemplateLinearInterpolator<osg::Matrixf, osg::Matrixf> MatrixLinearInterpolator;
|
||||
|
||||
typedef TemplateCubicBezierInterpolator<float, FloatCubicBezier > FloatCubicBezierInterpolator;
|
||||
typedef TemplateCubicBezierInterpolator<double, DoubleCubicBezier> DoubleCubicBezierInterpolator;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Matrixf>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
@@ -98,6 +99,9 @@ namespace osgAnimation
|
||||
|
||||
typedef TemplateKeyframe<float> FloatKeyframe;
|
||||
typedef TemplateKeyframeContainer<float> FloatKeyframeContainer;
|
||||
|
||||
typedef TemplateKeyframe<double> DoubleKeyframe;
|
||||
typedef TemplateKeyframeContainer<double> DoubleKeyframeContainer;
|
||||
|
||||
typedef TemplateKeyframe<osg::Vec2> Vec2Keyframe;
|
||||
typedef TemplateKeyframeContainer<osg::Vec2> Vec2KeyframeContainer;
|
||||
@@ -111,17 +115,24 @@ namespace osgAnimation
|
||||
typedef TemplateKeyframe<osg::Quat> QuatKeyframe;
|
||||
typedef TemplateKeyframeContainer<osg::Quat> QuatKeyframeContainer;
|
||||
|
||||
typedef TemplateKeyframe<osg::Matrixf> MatrixKeyframe;
|
||||
typedef TemplateKeyframeContainer<osg::Matrixf> MatrixKeyframeContainer;
|
||||
|
||||
typedef TemplateKeyframe<Vec3Packed> Vec3PackedKeyframe;
|
||||
typedef TemplateKeyframeContainer<Vec3Packed> Vec3PackedKeyframeContainer;
|
||||
|
||||
typedef TemplateKeyframe<FloatCubicBezier> FloatCubicBezierKeyframe;
|
||||
typedef TemplateKeyframeContainer<FloatCubicBezier> FloatCubicBezierKeyframeContainer;
|
||||
|
||||
typedef TemplateKeyframe<DoubleCubicBezier> DoubleCubicBezierKeyframe;
|
||||
typedef TemplateKeyframeContainer<DoubleCubicBezier> DoubleCubicBezierKeyframeContainer;
|
||||
|
||||
typedef TemplateKeyframe<Vec2CubicBezier> Vec2CubicBezierKeyframe;
|
||||
typedef TemplateKeyframeContainer<Vec2CubicBezier> Vec2CubicBezierKeyframeContainer;
|
||||
|
||||
typedef TemplateKeyframe<Vec3CubicBezier> Vec3CubicBezierKeyframe;
|
||||
typedef TemplateKeyframeContainer<Vec3CubicBezier> Vec3CubicBezierKeyframeContainer;
|
||||
|
||||
typedef TemplateKeyframe<Vec4CubicBezier> Vec4CubicBezierKeyframe;
|
||||
typedef TemplateKeyframeContainer<Vec4CubicBezier> Vec4CubicBezierKeyframeContainer;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -16,37 +16,39 @@
|
||||
#define OSGANIMATION_NODE_VISITOR_H
|
||||
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/StateSet>
|
||||
#include <osgAnimation/Animation>
|
||||
#include <osgAnimation/UpdateCallback>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
class AnimationUpdateCallbackBase;
|
||||
|
||||
struct LinkVisitor : public osg::NodeVisitor
|
||||
/** This class is instancied by the AnimationManagerBase, it will link animation target to updatecallback that have the same name
|
||||
*/
|
||||
class OSGANIMATION_EXPORT LinkVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
LinkVisitor();
|
||||
|
||||
META_NodeVisitor("osgAnimation","LinkVisitor");
|
||||
|
||||
void apply(osg::Node& node);
|
||||
void apply(osg::Geode& node);
|
||||
|
||||
AnimationList& getAnimationList();
|
||||
void reset();
|
||||
unsigned int getNbLinkedTarget() const { return _nbLinkedTarget; }
|
||||
|
||||
protected:
|
||||
|
||||
void handle_stateset(osg::StateSet* stateset);
|
||||
void link(osgAnimation::AnimationUpdateCallbackBase* cb);
|
||||
|
||||
// animation list to link
|
||||
AnimationList _animations;
|
||||
|
||||
// number of success link done
|
||||
unsigned int _nbLinkedTarget;
|
||||
|
||||
LinkVisitor(Animation* animation) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _animations.push_back(animation); _nbLinkedTarget = 0;}
|
||||
LinkVisitor(const AnimationList& animations) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _animations = animations; _nbLinkedTarget = 0;}
|
||||
|
||||
META_NodeVisitor("osgAnimation","LinkVisitor")
|
||||
|
||||
void apply(osg::Node& node)
|
||||
{
|
||||
osgAnimation::AnimationUpdateCallback* cb = dynamic_cast<osgAnimation::AnimationUpdateCallback*>(node.getUpdateCallback());
|
||||
if (cb)
|
||||
{
|
||||
int result = 0;
|
||||
for (int i = 0; i < (int)_animations.size(); i++)
|
||||
{
|
||||
result += cb->link(_animations[i].get());
|
||||
_nbLinkedTarget += result;
|
||||
}
|
||||
std::cout << "LinkVisitor links " << result << " for \"" << cb->getName() << '"' << std::endl;
|
||||
}
|
||||
traverse(node);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
154
include/osgAnimation/MorphGeometry
Normal file
154
include/osgAnimation/MorphGeometry
Normal file
@@ -0,0 +1,154 @@
|
||||
/* -*-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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_MORPHGEOMETRY_H
|
||||
#define OSGANIMATION_MORPHGEOMETRY_H
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/AnimationUpdateCallback>
|
||||
#include <osg/Geometry>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT MorphGeometry : public osg::Geometry
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
enum Method {
|
||||
NORMALIZED,
|
||||
RELATIVE
|
||||
};
|
||||
|
||||
class MorphTarget
|
||||
{
|
||||
protected:
|
||||
osg::ref_ptr<osg::Geometry> _geom;
|
||||
float _weight;
|
||||
public:
|
||||
MorphTarget(osg::Geometry* geom, float w = 1.0) : _geom(geom), _weight(w) {}
|
||||
void setWeight(float weight) { _weight = weight; }
|
||||
const float getWeight() const { return _weight; }
|
||||
osg::Geometry* getGeometry() { return _geom.get(); }
|
||||
const osg::Geometry* getGeometry() const { return _geom.get(); }
|
||||
void setGeometry(osg::Geometry* geom) { _geom = geom; }
|
||||
};
|
||||
|
||||
typedef std::vector<MorphTarget> MorphTargetList;
|
||||
|
||||
struct UpdateVertex : public osg::Drawable::UpdateCallback
|
||||
{
|
||||
virtual void update(osg::NodeVisitor*, osg::Drawable* drw)
|
||||
{
|
||||
MorphGeometry* geom = dynamic_cast<MorphGeometry*>(drw);
|
||||
if (!geom)
|
||||
return;
|
||||
|
||||
geom->transformSoftwareMethod();
|
||||
}
|
||||
};
|
||||
|
||||
MorphGeometry();
|
||||
MorphGeometry(const osg::Geometry& b);
|
||||
MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual osg::Object* cloneType() const { return new MorphGeometry(); }
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new MorphGeometry(*this,copyop); }
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const MorphGeometry*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osgAnimation"; }
|
||||
virtual const char* className() const { return "MorphGeometry"; }
|
||||
|
||||
virtual void transformSoftwareMethod();
|
||||
|
||||
/** Set the morphing method. */
|
||||
void setMethod(Method method) { _method = method; }
|
||||
/** Get the morphing method. */
|
||||
inline Method getMethod() const { return _method; }
|
||||
|
||||
/** Set flag for morphing normals. */
|
||||
void setMorphNormals(bool morphNormals) { _morphNormals = morphNormals; }
|
||||
/** Get the flag for morphing normals. */
|
||||
inline bool getMorphNormals() const { return _morphNormals; }
|
||||
|
||||
/** Add a \c MorphTarget to the \c MorphGeometry.
|
||||
* If \c MorphTarget is not \c NULL and is not contained in the \c MorphGeometry
|
||||
* then increment its reference count, add it to the MorphTargets list and
|
||||
* dirty the bounding sphere to force it to be recomputed on the next
|
||||
* call to \c getBound().
|
||||
* @param morphTarget The \c MorphTarget to be added to the \c MorphGeometry.
|
||||
* @param weight The weight to be added to the \c MorphGeometry.
|
||||
* @return \c true for success; \c false otherwise.
|
||||
*/
|
||||
virtual void addMorphTarget( osg::Geometry *morphTarget, float weight = 1.0 ) { _morphTargets.push_back(MorphTarget(morphTarget, weight)); _dirty = true; }
|
||||
|
||||
void setWeight(unsigned int index, float morphWeight)
|
||||
{
|
||||
if (index < _morphTargets.size())
|
||||
{
|
||||
_morphTargets[index].setWeight(morphWeight);
|
||||
dirty();
|
||||
}
|
||||
}
|
||||
|
||||
/** Set the MorphGeometry dirty.*/
|
||||
void dirty() { _dirty = true; }
|
||||
|
||||
/** Get the list of MorphTargets.*/
|
||||
const MorphTargetList& getMorphTargetList() const { return _morphTargets; }
|
||||
|
||||
/** Get the list of MorphTargets. Warning if you modify this array you will have to call dirty() */
|
||||
MorphTargetList& getMorphTargetList() { return _morphTargets; }
|
||||
|
||||
/** Return the \c MorphTarget at position \c i.*/
|
||||
inline const MorphTarget& getMorphTarget( unsigned int i ) const { return _morphTargets[i]; }
|
||||
|
||||
/** Return the \c MorphTarget at position \c i.*/
|
||||
inline MorphTarget& getMorphTarget( unsigned int i ) { return _morphTargets[i]; }
|
||||
|
||||
protected:
|
||||
/// Do we need to recalculate the morphed geometry?
|
||||
bool _dirty;
|
||||
|
||||
Method _method;
|
||||
MorphTargetList _morphTargets;
|
||||
|
||||
std::vector<osg::Vec3> _positionSource;
|
||||
std::vector<osg::Vec3> _normalSource;
|
||||
|
||||
/// Do we also morph between normals?
|
||||
bool _morphNormals;
|
||||
};
|
||||
|
||||
class OSGANIMATION_EXPORT UpdateMorph : public AnimationUpdateCallback<osg::NodeCallback>
|
||||
{
|
||||
protected:
|
||||
std::map<int, osg::ref_ptr<osgAnimation::FloatTarget> > _weightTargets;
|
||||
|
||||
public:
|
||||
|
||||
META_Object(osgAnimation, UpdateMorph);
|
||||
|
||||
UpdateMorph(const std::string& name = "");
|
||||
UpdateMorph(const UpdateMorph& apc,const osg::CopyOp& copyop);
|
||||
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
bool needLink() const;
|
||||
bool link(osgAnimation::Channel* channel);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -16,8 +16,9 @@
|
||||
#define OSGANIMATION_RIGGEOMETRY_H
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/Skinning>
|
||||
#include <osgAnimation/Skeleton>
|
||||
#include <osgAnimation/RigTransform>
|
||||
#include <osgAnimation/VertexInfluence>
|
||||
#include <osg/Geometry>
|
||||
|
||||
namespace osgAnimation
|
||||
@@ -28,49 +29,63 @@ namespace osgAnimation
|
||||
public:
|
||||
|
||||
RigGeometry();
|
||||
RigGeometry(const osg::Geometry& b);
|
||||
// RigGeometry(const osg::Geometry& b);
|
||||
RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgAnimation, RigGeometry);
|
||||
|
||||
void setInfluenceMap(osgAnimation::VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; }
|
||||
const osgAnimation::VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get();}
|
||||
osgAnimation::VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get();}
|
||||
void setInfluenceMap(VertexInfluenceMap* vertexInfluenceMap) { _vertexInfluenceMap = vertexInfluenceMap; }
|
||||
const VertexInfluenceMap* getInfluenceMap() const { return _vertexInfluenceMap.get();}
|
||||
VertexInfluenceMap* getInfluenceMap() { return _vertexInfluenceMap.get();}
|
||||
|
||||
const Skeleton* getSkeleton() const;
|
||||
Skeleton* getSkeleton();
|
||||
// will be used by the update callback to init correctly the rig mesh
|
||||
void setSkeleton(Skeleton*);
|
||||
|
||||
void setNeedToComputeMatrix(bool state) { _needToComputeMatrix = state;}
|
||||
bool getNeedToComputeMatrix() const { return _needToComputeMatrix;}
|
||||
|
||||
void buildVertexSet();
|
||||
void buildTransformer(Skeleton* root);
|
||||
|
||||
// this build the internal database about vertex influence and bones
|
||||
void buildVertexInfluenceSet();
|
||||
const VertexInfluenceSet& getVertexInfluenceSet() const;
|
||||
|
||||
void computeMatrixFromRootSkeleton();
|
||||
|
||||
virtual void transformSoftwareMethod();
|
||||
const osgAnimation::VertexInfluenceSet& getVertexInfluenceSet() const { return _vertexInfluenceSet;}
|
||||
|
||||
const std::vector<osg::Vec3>& getPositionSource() const { return _positionSource;}
|
||||
const std::vector<osg::Vec3>& getNormalSource() const { return _normalSource;}
|
||||
// set implementation of rig method
|
||||
void setRigTransformImplementation(RigTransform*);
|
||||
RigTransform* getRigTransformImplementation();
|
||||
|
||||
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
|
||||
void update();
|
||||
|
||||
const osg::Matrix& getMatrixFromSkeletonToGeometry() const;
|
||||
const osg::Matrix& getInvMatrixFromSkeletonToGeometry() const;
|
||||
|
||||
osg::Geometry* getSourceGeometry();
|
||||
const osg::Geometry* getSourceGeometry() const;
|
||||
void setSourceGeometry(osg::Geometry* geometry);
|
||||
|
||||
void copyFrom(osg::Geometry& from);
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<osg::Geometry> _geometry;
|
||||
osg::ref_ptr<RigTransform> _rigTransformImplementation;
|
||||
|
||||
std::vector<osg::Vec3> _positionSource;
|
||||
std::vector<osg::Vec3> _normalSource;
|
||||
|
||||
osgAnimation::VertexInfluenceSet _vertexInfluenceSet;
|
||||
osg::ref_ptr<osgAnimation::VertexInfluenceMap> _vertexInfluenceMap;
|
||||
osgAnimation::TransformVertexFunctor _transformVertexes;
|
||||
VertexInfluenceSet _vertexInfluenceSet;
|
||||
osg::ref_ptr<VertexInfluenceMap> _vertexInfluenceMap;
|
||||
|
||||
osg::Matrix _matrixFromSkeletonToGeometry;
|
||||
osg::Matrix _invMatrixFromSkeletonToGeometry;
|
||||
osg::observer_ptr<Skeleton> _root;
|
||||
bool _needToComputeMatrix;
|
||||
|
||||
|
||||
struct FindNearestParentSkeleton : public osg::NodeVisitor
|
||||
{
|
||||
osg::ref_ptr<osgAnimation::Skeleton> _root;
|
||||
osg::ref_ptr<Skeleton> _root;
|
||||
FindNearestParentSkeleton() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) {}
|
||||
void apply(osg::Transform& node)
|
||||
{
|
||||
@@ -89,7 +104,7 @@ namespace osgAnimation
|
||||
RigGeometry* geom = dynamic_cast<RigGeometry*>(drw);
|
||||
if (!geom)
|
||||
return;
|
||||
if (!geom->getSkeleton() && !geom->getParents().empty())
|
||||
if (!geom->getSkeleton() && !geom->getParents().empty())
|
||||
{
|
||||
FindNearestParentSkeleton finder;
|
||||
if (geom->getParents().size() > 1)
|
||||
@@ -97,9 +112,12 @@ namespace osgAnimation
|
||||
geom->getParents()[0]->accept(finder);
|
||||
|
||||
if (!finder._root.valid())
|
||||
{
|
||||
osg::notify(osg::WARN) << "A RigGeometry did not find a parent skeleton for RigGeomtry ( " << geom->getName() << " )" << std::endl;
|
||||
return;
|
||||
geom->buildVertexSet();
|
||||
geom->buildTransformer(finder._root.get());
|
||||
}
|
||||
geom->buildVertexInfluenceSet();
|
||||
geom->setSkeleton(finder._root.get());
|
||||
}
|
||||
|
||||
if (!geom->getSkeleton())
|
||||
@@ -107,34 +125,10 @@ namespace osgAnimation
|
||||
|
||||
if (geom->getNeedToComputeMatrix())
|
||||
geom->computeMatrixFromRootSkeleton();
|
||||
geom->transformSoftwareMethod();
|
||||
|
||||
geom->update();
|
||||
}
|
||||
};
|
||||
|
||||
/** BuildVertexTransformerVisitor is used to setup RigGeometry drawable
|
||||
* throw a subgraph.
|
||||
*/
|
||||
struct BuildVertexTransformerVisitor : public osg::NodeVisitor
|
||||
{
|
||||
osg::ref_ptr<Skeleton> _root;
|
||||
BuildVertexTransformerVisitor(Skeleton* root): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { _root = root;}
|
||||
|
||||
META_NodeVisitor("osgAnimation","BuildVertexTransformerVisitor")
|
||||
|
||||
void apply(osg::Geode& node)
|
||||
{
|
||||
int num = node.getNumDrawables();
|
||||
for (int i = 0; i < num; i++) {
|
||||
RigGeometry* geom = dynamic_cast<RigGeometry*>(node.getDrawable(i));
|
||||
if (geom)
|
||||
{
|
||||
geom->buildVertexSet();
|
||||
geom->buildTransformer(_root.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
36
include/osgAnimation/RigTransform
Normal file
36
include/osgAnimation/RigTransform
Normal file
@@ -0,0 +1,36 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_RIGTRANSFORM
|
||||
#define OSGANIMATION_RIGTRANSFORM 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class RigGeometry;
|
||||
|
||||
class RigTransform : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
RigTransform() {}
|
||||
virtual ~RigTransform() {}
|
||||
virtual void operator()(RigGeometry& geometry) {}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
85
include/osgAnimation/RigTransformHardware
Normal file
85
include/osgAnimation/RigTransformHardware
Normal file
@@ -0,0 +1,85 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_RIG_TRANSFORM_HARDWARE
|
||||
#define OSGANIMATION_RIG_TRANSFORM_HARDWARE 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/RigTransform>
|
||||
#include <osgAnimation/VertexInfluence>
|
||||
#include <osgAnimation/Bone>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Array>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
class RigGeometry;
|
||||
|
||||
/// This class manage format for hardware skinning
|
||||
class OSGANIMATION_EXPORT RigTransformHardware : public RigTransform
|
||||
{
|
||||
public:
|
||||
typedef osg::Matrix MatrixType;
|
||||
typedef osgAnimation::Bone BoneType;
|
||||
typedef std::vector<osg::ref_ptr<osg::Vec4Array> > BoneWeightAttribList;
|
||||
typedef std::vector<osg::ref_ptr<BoneType> > BonePalette;
|
||||
|
||||
typedef std::vector<osg::Matrix> MatrixPalette;
|
||||
struct IndexWeightEntry
|
||||
{
|
||||
int _boneIndex;
|
||||
float _boneWeight;
|
||||
IndexWeightEntry() { _boneIndex = 0; _boneWeight = 0;}
|
||||
IndexWeightEntry(int index, float weight) { _boneIndex = index; _boneWeight = weight;}
|
||||
int getIndex() const { return _boneIndex; }
|
||||
float getWeight() const { return _boneWeight; }
|
||||
};
|
||||
typedef std::vector<std::vector<IndexWeightEntry> > VertexIndexWeightList;
|
||||
|
||||
RigTransformHardware();
|
||||
|
||||
osg::Vec4Array* getVertexAttrib(int index);
|
||||
int getNumVertexAttrib();
|
||||
|
||||
osg::Uniform* getMatrixPaletteUniform();
|
||||
void computeMatrixPaletteUniform(const osg::Matrix& transformFromSkeletonToGeometry, const osg::Matrix& invTransformFromSkeletonToGeometry);
|
||||
|
||||
int getNumBonesPerVertex() const;
|
||||
int getNumVertexes() const;
|
||||
|
||||
bool createPalette(int nbVertexes, BoneMap boneMap, const VertexInfluenceSet::VertexIndexToBoneWeightMap& vertexIndexToBoneWeightMap);
|
||||
|
||||
virtual void operator()(RigGeometry&);
|
||||
void setShader(osg::Shader*);
|
||||
|
||||
protected:
|
||||
|
||||
bool init(RigGeometry&);
|
||||
|
||||
BoneWeightAttribList createVertexAttribList();
|
||||
osg::Uniform* createVertexUniform();
|
||||
|
||||
int _bonesPerVertex;
|
||||
int _nbVertexes;
|
||||
VertexIndexWeightList _vertexIndexMatrixWeightList;
|
||||
BonePalette _bonePalette;
|
||||
BoneWeightAttribList _boneWeightAttribArrays;
|
||||
osg::ref_ptr<osg::Uniform> _uniformMatrixPalette;
|
||||
osg::ref_ptr<osg::Shader> _shader;
|
||||
|
||||
bool _needInit;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
172
include/osgAnimation/RigTransformSoftware
Normal file
172
include/osgAnimation/RigTransformSoftware
Normal file
@@ -0,0 +1,172 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_RIGTRANSFORM_SOFTWARE
|
||||
#define OSGANIMATION_RIGTRANSFORM_SOFTWARE 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/RigTransform>
|
||||
#include <osgAnimation/Bone>
|
||||
#include <osgAnimation/VertexInfluence>
|
||||
#include <osg/observer_ptr>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class RigGeometry;
|
||||
|
||||
/// This class manage format for hardware skinning
|
||||
class OSGANIMATION_EXPORT RigTransformSoftware : public RigTransform
|
||||
{
|
||||
public:
|
||||
|
||||
RigTransformSoftware();
|
||||
virtual void operator()(RigGeometry&);
|
||||
|
||||
|
||||
class BoneWeight
|
||||
{
|
||||
public:
|
||||
BoneWeight(Bone* bone, float weight) : _bone(bone), _weight(weight) {}
|
||||
const Bone* getBone() const { return _bone.get(); }
|
||||
float getWeight() const { return _weight; }
|
||||
void setWeight(float w) { _weight = w; }
|
||||
protected:
|
||||
osg::observer_ptr<Bone> _bone;
|
||||
float _weight;
|
||||
};
|
||||
|
||||
typedef std::vector<BoneWeight> BoneWeightList;
|
||||
typedef std::vector<int> VertexList;
|
||||
|
||||
class UniqBoneSetVertexSet
|
||||
{
|
||||
public:
|
||||
BoneWeightList& getBones() { return _bones; }
|
||||
VertexList& getVertexes() { return _vertexes; }
|
||||
|
||||
void resetMatrix()
|
||||
{
|
||||
_result.set(0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
void accummulateMatrix(const osg::Matrix& invBindMatrix, const osg::Matrix& matrix, osg::Matrix::value_type weight)
|
||||
{
|
||||
osg::Matrix m = invBindMatrix * matrix;
|
||||
osg::Matrix::value_type* ptr = m.ptr();
|
||||
osg::Matrix::value_type* ptrresult = _result.ptr();
|
||||
ptrresult[0] += ptr[0] * weight;
|
||||
ptrresult[1] += ptr[1] * weight;
|
||||
ptrresult[2] += ptr[2] * weight;
|
||||
|
||||
ptrresult[4] += ptr[4] * weight;
|
||||
ptrresult[5] += ptr[5] * weight;
|
||||
ptrresult[6] += ptr[6] * weight;
|
||||
|
||||
ptrresult[8] += ptr[8] * weight;
|
||||
ptrresult[9] += ptr[9] * weight;
|
||||
ptrresult[10] += ptr[10] * weight;
|
||||
|
||||
ptrresult[12] += ptr[12] * weight;
|
||||
ptrresult[13] += ptr[13] * weight;
|
||||
ptrresult[14] += ptr[14] * weight;
|
||||
}
|
||||
void computeMatrixForVertexSet()
|
||||
{
|
||||
if (_bones.empty())
|
||||
{
|
||||
osg::notify(osg::WARN) << this << " RigTransformSoftware::UniqBoneSetVertexSet no bones found" << std::endl;
|
||||
_result = osg::Matrix::identity();
|
||||
return;
|
||||
}
|
||||
resetMatrix();
|
||||
|
||||
int size = _bones.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
const Bone* bone = _bones[i].getBone();
|
||||
if (!bone)
|
||||
{
|
||||
osg::notify(osg::WARN) << this << " RigTransformSoftware::computeMatrixForVertexSet Warning a bone is null, skip it" << std::endl;
|
||||
continue;
|
||||
}
|
||||
const osg::Matrix& invBindMatrix = bone->getInvBindMatrixInSkeletonSpace();
|
||||
const osg::Matrix& matrix = bone->getMatrixInSkeletonSpace();
|
||||
osg::Matrix::value_type w = _bones[i].getWeight();
|
||||
accummulateMatrix(invBindMatrix, matrix, w);
|
||||
}
|
||||
}
|
||||
const osg::Matrix& getMatrix() const { return _result;}
|
||||
protected:
|
||||
BoneWeightList _bones;
|
||||
VertexList _vertexes;
|
||||
osg::Matrix _result;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class V> void compute(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
||||
{
|
||||
// the result of matrix mult should be cached to be used for vertexes transform and normal transform and maybe other computation
|
||||
int size = _boneSetVertexSet.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
UniqBoneSetVertexSet& uniq = _boneSetVertexSet[i];
|
||||
uniq.computeMatrixForVertexSet();
|
||||
osg::Matrix matrix = transform * uniq.getMatrix() * invTransform;
|
||||
|
||||
const VertexList& vertexes = uniq.getVertexes();
|
||||
int vertexSize = vertexes.size();
|
||||
for (int j = 0; j < vertexSize; j++)
|
||||
{
|
||||
int idx = vertexes[j];
|
||||
dst[idx] = src[idx] * matrix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class V> void computeNormal(const osg::Matrix& transform, const osg::Matrix& invTransform, const V* src, V* dst)
|
||||
{
|
||||
int size = _boneSetVertexSet.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
UniqBoneSetVertexSet& uniq = _boneSetVertexSet[i];
|
||||
uniq.computeMatrixForVertexSet();
|
||||
osg::Matrix matrix = transform * uniq.getMatrix() * invTransform;
|
||||
|
||||
const VertexList& vertexes = uniq.getVertexes();
|
||||
int vertexSize = vertexes.size();
|
||||
for (int j = 0; j < vertexSize; j++)
|
||||
{
|
||||
int idx = vertexes[j];
|
||||
dst[idx] = osg::Matrix::transform3x3(src[idx],matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
bool init(RigGeometry&);
|
||||
void initVertexSetFromBones(const BoneMap& map, const VertexInfluenceSet::UniqVertexSetToBoneSetList& influence);
|
||||
std::vector<UniqBoneSetVertexSet> _boneSetVertexSet;
|
||||
|
||||
bool _needInit;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -10,7 +10,11 @@
|
||||
* 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.
|
||||
*/
|
||||
*
|
||||
* Authors:
|
||||
* Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
* Michael Platings <mplatings@pixelpower.com>
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_SAMPLER_H
|
||||
#define OSGANIMATION_SAMPLER_H
|
||||
@@ -108,12 +112,21 @@ namespace osgAnimation
|
||||
};
|
||||
|
||||
|
||||
typedef TemplateSampler<DoubleStepInterpolator> DoubleStepSampler;
|
||||
typedef TemplateSampler<FloatStepInterpolator> FloatStepSampler;
|
||||
typedef TemplateSampler<Vec2StepInterpolator> Vec2StepSampler;
|
||||
typedef TemplateSampler<Vec3StepInterpolator> Vec3StepSampler;
|
||||
typedef TemplateSampler<Vec4StepInterpolator> Vec4StepSampler;
|
||||
typedef TemplateSampler<QuatStepInterpolator> QuatStepSampler;
|
||||
|
||||
typedef TemplateSampler<DoubleLinearInterpolator> DoubleLinearSampler;
|
||||
typedef TemplateSampler<FloatLinearInterpolator> FloatLinearSampler;
|
||||
typedef TemplateSampler<Vec2LinearInterpolator> Vec2LinearSampler;
|
||||
typedef TemplateSampler<Vec3LinearInterpolator> Vec3LinearSampler;
|
||||
typedef TemplateSampler<Vec4LinearInterpolator> Vec4LinearSampler;
|
||||
typedef TemplateSampler<QuatSphericalLinearInterpolator> QuatSphericalLinearSampler;
|
||||
typedef TemplateSampler<MatrixLinearInterpolator> MatrixLinearSampler;
|
||||
|
||||
typedef TemplateSampler<FloatCubicBezierInterpolator> FloatCubicBezierSampler;
|
||||
typedef TemplateSampler<DoubleCubicBezierInterpolator> DoubleCubicBezierSampler;
|
||||
typedef TemplateSampler<Vec2CubicBezierInterpolator> Vec2CubicBezierSampler;
|
||||
|
||||
@@ -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
|
||||
@@ -12,33 +12,36 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_SKELETON_H
|
||||
#define OSGANIMATION_SKELETON_H
|
||||
#ifndef OSGANIMATION_SKELETON
|
||||
#define OSGANIMATION_SKELETON 1
|
||||
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osgAnimation/Bone>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT Skeleton : public Bone
|
||||
class OSGANIMATION_EXPORT Skeleton : public osg::MatrixTransform
|
||||
{
|
||||
public:
|
||||
META_Node(osgAnimation, Skeleton);
|
||||
|
||||
struct OSGANIMATION_EXPORT UpdateSkeleton : public osg::NodeCallback
|
||||
class OSGANIMATION_EXPORT UpdateSkeleton : public osg::NodeCallback
|
||||
{
|
||||
public:
|
||||
META_Object(osgAnimation, UpdateSkeleton);
|
||||
UpdateSkeleton() {}
|
||||
UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::NodeCallback(us, copyop) {}
|
||||
UpdateSkeleton();
|
||||
UpdateSkeleton(const UpdateSkeleton&, const osg::CopyOp&);
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
bool needToValidate() const;
|
||||
protected:
|
||||
bool _needValidate;
|
||||
};
|
||||
|
||||
Skeleton(const Skeleton& b, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : Bone(b,copyop) {}
|
||||
Skeleton();
|
||||
void setDefaultUpdateCallback(void);
|
||||
void computeBindMatrix() { _invBindInSkeletonSpace = osg::Matrix::inverse(_bindInBoneSpace); }
|
||||
Skeleton(const Skeleton&, const osg::CopyOp&);
|
||||
void setDefaultUpdateCallback();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
54
include/osgAnimation/StackedMatrixElement
Normal file
54
include/osgAnimation/StackedMatrixElement
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSGANIMATION_STACKED_MATRIX_ELEMENT
|
||||
#define OSGANIMATION_STACKED_MATRIX_ELEMENT 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/StackedTransformElement>
|
||||
#include <osgAnimation/Target>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT StackedMatrixElement : public StackedTransformElement
|
||||
{
|
||||
public:
|
||||
META_Object(osgAnimation, StackedMatrixElement);
|
||||
|
||||
StackedMatrixElement();
|
||||
StackedMatrixElement(const StackedMatrixElement&, const osg::CopyOp&);
|
||||
StackedMatrixElement(const std::string& name, const osg::Matrix& matrix);
|
||||
StackedMatrixElement(const osg::Matrix& matrix);
|
||||
|
||||
void applyToMatrix(osg::Matrix& matrix) const { matrix = _matrix * matrix; }
|
||||
osg::Matrix getAsMatrix() const { return _matrix; }
|
||||
const osg::Matrix& getMatrix() const { return _matrix;}
|
||||
void setMatrix(const osg::Matrix& matrix) { _matrix = matrix;}
|
||||
bool isIdentity() const { return _matrix.isIdentity(); }
|
||||
void update();
|
||||
virtual Target* getOrCreateTarget();
|
||||
virtual Target* getTarget() {return _target.get();}
|
||||
virtual const Target* getTarget() const {return _target.get();}
|
||||
|
||||
protected:
|
||||
osg::Matrix _matrix;
|
||||
osg::ref_ptr<MatrixTarget> _target;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
54
include/osgAnimation/StackedQuaternionElement
Normal file
54
include/osgAnimation/StackedQuaternionElement
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSGANIMATION_STACKED_QUATERNION_ELEMENT
|
||||
#define OSGANIMATION_STACKED_QUATERNION_ELEMENT 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/StackedTransformElement>
|
||||
#include <osgAnimation/Target>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT StackedQuaternionElement : public StackedTransformElement
|
||||
{
|
||||
public:
|
||||
META_Object(osgAnimation, StackedQuaternionElement);
|
||||
|
||||
StackedQuaternionElement();
|
||||
StackedQuaternionElement(const StackedQuaternionElement&, const osg::CopyOp&);
|
||||
StackedQuaternionElement(const std::string&, const osg::Quat& q = osg::Quat(0,0,0,1));
|
||||
StackedQuaternionElement(const osg::Quat&);
|
||||
|
||||
void applyToMatrix(osg::Matrix& matrix) const;
|
||||
osg::Matrix getAsMatrix() const;
|
||||
bool isIdentity() const;
|
||||
void update();
|
||||
|
||||
const osg::Quat& getQuaternion() const;
|
||||
void setQuaternion(const osg::Quat&);
|
||||
virtual Target* getOrCreateTarget();
|
||||
virtual Target* getTarget();
|
||||
virtual const Target* getTarget() const;
|
||||
|
||||
protected:
|
||||
osg::Quat _quaternion;
|
||||
osg::ref_ptr<QuatTarget> _target;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
59
include/osgAnimation/StackedRotateAxisElement
Normal file
59
include/osgAnimation/StackedRotateAxisElement
Normal file
@@ -0,0 +1,59 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_STACKED_ROTATE_AXIS_ELEMENT
|
||||
#define OSGANIMATION_STACKED_ROTATE_AXIS_ELEMENT 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/StackedTransformElement>
|
||||
#include <osgAnimation/Target>
|
||||
#include <osg/Vec3>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT StackedRotateAxisElement : public StackedTransformElement
|
||||
{
|
||||
public:
|
||||
META_Object(osgAnimation, StackedRotateAxisElement);
|
||||
|
||||
StackedRotateAxisElement();
|
||||
StackedRotateAxisElement(const StackedRotateAxisElement&, const osg::CopyOp&);
|
||||
StackedRotateAxisElement(const std::string& name, const osg::Vec3& axis, double angle);
|
||||
StackedRotateAxisElement(const osg::Vec3& axis, double angle);
|
||||
|
||||
void applyToMatrix(osg::Matrix& matrix) const;
|
||||
osg::Matrix getAsMatrix() const;
|
||||
bool isIdentity() const { return (_angle == 0); }
|
||||
void update();
|
||||
|
||||
const osg::Vec3& getAxis() const;
|
||||
const double getAngle() const;
|
||||
void setAxis(const osg::Vec3&);
|
||||
void setAngle(const double&);
|
||||
|
||||
virtual Target* getOrCreateTarget();
|
||||
virtual Target* getTarget() {return _target.get();}
|
||||
virtual const Target* getTarget() const {return _target.get();}
|
||||
|
||||
protected:
|
||||
osg::Vec3 _axis;
|
||||
double _angle;
|
||||
osg::ref_ptr<FloatTarget> _target;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
56
include/osgAnimation/StackedScaleElement
Normal file
56
include/osgAnimation/StackedScaleElement
Normal file
@@ -0,0 +1,56 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_STACKED_SCALE_ELEMENT
|
||||
#define OSGANIMATION_STACKED_SCALE_ELEMENT 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/StackedTransformElement>
|
||||
#include <osgAnimation/Target>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT StackedScaleElement : public StackedTransformElement
|
||||
{
|
||||
public:
|
||||
META_Object(osgAnimation, StackedScaleElement)
|
||||
|
||||
StackedScaleElement();
|
||||
StackedScaleElement(const StackedScaleElement&, const osg::CopyOp&);
|
||||
StackedScaleElement(const std::string& name, const osg::Vec3& scale = osg::Vec3(1,1,1));
|
||||
StackedScaleElement(const osg::Vec3& scale);
|
||||
|
||||
void applyToMatrix(osg::Matrix& matrix) const;
|
||||
osg::Matrix getAsMatrix() const;
|
||||
bool isIdentity() const;
|
||||
void update();
|
||||
const osg::Vec3& getScale() const;
|
||||
void setScale(const osg::Vec3& scale);
|
||||
|
||||
virtual Target* getOrCreateTarget();
|
||||
virtual Target* getTarget();
|
||||
virtual const Target* getTarget() const;
|
||||
|
||||
protected:
|
||||
osg::Vec3 _scale;
|
||||
osg::ref_ptr<Vec3Target> _target;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
42
include/osgAnimation/StackedTransform
Normal file
42
include/osgAnimation/StackedTransform
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_STACKED_TRANSFORM
|
||||
#define OSGANIMATION_STACKED_TRANSFORM 1
|
||||
|
||||
#include <osg/MixinVector>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/StackedTransformElement>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT StackedTransform : public osg::MixinVector<osg::ref_ptr<StackedTransformElement> >
|
||||
{
|
||||
public:
|
||||
StackedTransform();
|
||||
StackedTransform(const StackedTransform&, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
void update();
|
||||
const osg::Matrix& getMatrix() const;
|
||||
|
||||
protected:
|
||||
osg::Matrix _matrix;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
42
include/osgAnimation/StackedTransformElement
Normal file
42
include/osgAnimation/StackedTransformElement
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSGANIMATION_STACKED_TRANSFORM_ELEMENT
|
||||
#define OSGANIMATION_STACKED_TRANSFORM_ELEMENT 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osg/Object>
|
||||
#include <osg/Matrix>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
class Target;
|
||||
class OSGANIMATION_EXPORT StackedTransformElement : public osg::Object
|
||||
{
|
||||
public:
|
||||
StackedTransformElement() {}
|
||||
StackedTransformElement(const StackedTransformElement& rhs, const osg::CopyOp& c) : osg::Object(rhs, c) {}
|
||||
virtual void applyToMatrix(osg::Matrix& matrix) const = 0;
|
||||
virtual osg::Matrix getAsMatrix() const = 0;
|
||||
virtual bool isIdentity() const = 0;
|
||||
virtual void update() = 0;
|
||||
virtual Target* getOrCreateTarget() {return 0;}
|
||||
virtual Target* getTarget() {return 0;}
|
||||
virtual const Target* getTarget() const {return 0;}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
54
include/osgAnimation/StackedTranslateElement
Normal file
54
include/osgAnimation/StackedTranslateElement
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSGANIMATION_STACKED_TRANSLATE_ELEMENT
|
||||
#define OSGANIMATION_STACKED_TRANSLATE_ELEMENT 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/StackedTransformElement>
|
||||
#include <osgAnimation/Target>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT StackedTranslateElement : public StackedTransformElement
|
||||
{
|
||||
public:
|
||||
META_Object(osgAnimation, StackedTranslateElement);
|
||||
|
||||
StackedTranslateElement();
|
||||
StackedTranslateElement(const StackedTranslateElement&, const osg::CopyOp&);
|
||||
StackedTranslateElement(const std::string&, const osg::Vec3& translate = osg::Vec3(0,0,0));
|
||||
StackedTranslateElement(const osg::Vec3& translate);
|
||||
|
||||
void applyToMatrix(osg::Matrix& matrix) const;
|
||||
osg::Matrix getAsMatrix() const;
|
||||
bool isIdentity() const;
|
||||
void update();
|
||||
|
||||
const osg::Vec3& getTranslate() const;
|
||||
void setTranslate(const osg::Vec3& );
|
||||
virtual Target* getOrCreateTarget();
|
||||
virtual Target* getTarget();
|
||||
virtual const Target* getTarget() const;
|
||||
|
||||
protected:
|
||||
osg::Vec3 _translate;
|
||||
osg::ref_ptr<Vec3Target> _target;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
113
include/osgAnimation/StatsHandler
Normal file
113
include/osgAnimation/StatsHandler
Normal file
@@ -0,0 +1,113 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_STATSHANDLER_H
|
||||
#define OSGANIMATION_STATSHANDLER_H
|
||||
|
||||
#include <osgAnimation/Timeline>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <osgViewer/ViewerBase>
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgText/Text>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
#if 0
|
||||
struct StatAction
|
||||
{
|
||||
|
||||
std::string _name;
|
||||
osg::ref_ptr<osg::Group> _group;
|
||||
osg::ref_ptr<osg::Geode> _label;
|
||||
osg::ref_ptr<osg::MatrixTransform> _graph;
|
||||
osg::ref_ptr<osgText::Text> _textLabel;
|
||||
|
||||
void init(osg::Stats* stats, const std::string& name, const osg::Vec3& pos, float width, float heigh, const osg::Vec4& color);
|
||||
void setPosition(const osg::Vec3& pos);
|
||||
void setAlpha(float v);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/** Event handler for adding on screen stats reporting to Viewers.*/
|
||||
class OSGANIMATION_EXPORT StatsHandler : public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
|
||||
StatsHandler();
|
||||
|
||||
enum StatsType
|
||||
{
|
||||
NO_STATS = 0,
|
||||
FRAME_RATE = 1,
|
||||
LAST = 2
|
||||
};
|
||||
|
||||
void setKeyEventTogglesOnScreenStats(int key) { _keyEventTogglesOnScreenStats = key; }
|
||||
int getKeyEventTogglesOnScreenStats() const { return _keyEventTogglesOnScreenStats; }
|
||||
|
||||
void setKeyEventPrintsOutStats(int key) { _keyEventPrintsOutStats = key; }
|
||||
int getKeyEventPrintsOutStats() const { return _keyEventPrintsOutStats; }
|
||||
|
||||
double getBlockMultiplier() const { return _blockMultiplier; }
|
||||
|
||||
void reset();
|
||||
|
||||
osg::Camera* getCamera() { return _camera.get(); }
|
||||
const osg::Camera* getCamera() const { return _camera.get(); }
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
|
||||
|
||||
/** Get the keyboard and mouse usage of this manipulator.*/
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
protected:
|
||||
|
||||
void setUpHUDCamera(osgViewer::ViewerBase* viewer);
|
||||
|
||||
osg::Geometry* createBackgroundRectangle(const osg::Vec3& pos, const float width, const float height, osg::Vec4& color);
|
||||
|
||||
osg::Geometry* createGeometry(const osg::Vec3& pos, float height, const osg::Vec4& colour, unsigned int numBlocks);
|
||||
|
||||
osg::Geometry* createFrameMarkers(const osg::Vec3& pos, float height, const osg::Vec4& colour, unsigned int numBlocks);
|
||||
|
||||
osg::Geometry* createTick(const osg::Vec3& pos, float height, const osg::Vec4& colour, unsigned int numTicks);
|
||||
|
||||
osg::Node* createCameraTimeStats(const std::string& font, osg::Vec3& pos, float startBlocks, bool acquireGPUStats, float characterSize, osg::Stats* viewerStats, osg::Camera* camera);
|
||||
|
||||
void setUpScene(osgViewer::Viewer* viewer);
|
||||
|
||||
int _keyEventTogglesOnScreenStats;
|
||||
int _keyEventPrintsOutStats;
|
||||
|
||||
int _statsType;
|
||||
|
||||
bool _initialized;
|
||||
osg::ref_ptr<osg::Camera> _camera;
|
||||
|
||||
osg::ref_ptr<osg::Switch> _switch;
|
||||
osg::ref_ptr<osg::Group> _group;
|
||||
|
||||
unsigned int _frameRateChildNum;
|
||||
unsigned int _numBlocks;
|
||||
double _blockMultiplier;
|
||||
|
||||
float _statsWidth;
|
||||
float _statsHeight;
|
||||
|
||||
// std::map<std::string, StatAction > _actions;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
53
include/osgAnimation/StatsVisitor
Normal file
53
include/osgAnimation/StatsVisitor
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_STATSVISITOR_H
|
||||
#define OSGANIMATION_STATSVISITOR_H
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/ActionVisitor>
|
||||
#include <osg/Stats>
|
||||
#include <vector>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT StatsActionVisitor : public osgAnimation::UpdateActionVisitor
|
||||
{
|
||||
protected:
|
||||
osg::ref_ptr<osg::Stats> _stats;
|
||||
std::vector<std::string> _channels;
|
||||
|
||||
public:
|
||||
META_ActionVisitor(osgAnimation, StatsActionVisitor);
|
||||
|
||||
StatsActionVisitor();
|
||||
StatsActionVisitor(osg::Stats* stats, unsigned int frame);
|
||||
void reset();
|
||||
const std::vector<std::string>& getChannels() const { return _channels; }
|
||||
osg::Stats* getStats() { return _stats.get(); }
|
||||
void setStats(osg::Stats* stats) { _stats = stats; }
|
||||
void setFrame(unsigned int frame) { _frame = frame; }
|
||||
void apply(Timeline& action);
|
||||
void apply(Action& action);
|
||||
void apply(ActionBlendIn& action);
|
||||
void apply(ActionBlendOut& action);
|
||||
void apply(ActionAnimation& action);
|
||||
void apply(ActionStripAnimation& action);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -34,15 +34,14 @@ namespace osgAnimation
|
||||
public:
|
||||
|
||||
Target();
|
||||
virtual ~Target();
|
||||
virtual void normalize() = 0;
|
||||
float getWeight() const { return _weight; }
|
||||
void reset() { _weight = 0;}
|
||||
virtual ~Target() {}
|
||||
void reset() { _weight = 0; _priorityWeight = 0; }
|
||||
int getCount() const { return referenceCount(); }
|
||||
float getWeight() const { return _weight; }
|
||||
protected:
|
||||
|
||||
void addWeight(float w) { _weight += w; }
|
||||
float _weight;
|
||||
float _priorityWeight;
|
||||
int _lastPriority;
|
||||
};
|
||||
|
||||
|
||||
@@ -51,75 +50,78 @@ namespace osgAnimation
|
||||
{
|
||||
public:
|
||||
|
||||
TemplateTarget() {}
|
||||
TemplateTarget() : _target() {}
|
||||
TemplateTarget(const T& v) { setValue(v); }
|
||||
TemplateTarget(const TemplateTarget& v) { setValue(v.getValue()); }
|
||||
|
||||
void update(float weight, const T& val)
|
||||
inline void lerp(float t, const T& a, const T& b);
|
||||
|
||||
/**
|
||||
* The priority is used to detect a change of priority
|
||||
* It's important to update animation target in priority
|
||||
* order. eg:
|
||||
* all animation with priority 1
|
||||
* all animation with priority 0
|
||||
* all animation with priority -1
|
||||
* ...
|
||||
*/
|
||||
void update(float weight, const T& val, int priority)
|
||||
{
|
||||
if (!_weight)
|
||||
_target = val * weight;
|
||||
if (_weight || _priorityWeight)
|
||||
{
|
||||
if (_lastPriority != priority)
|
||||
{
|
||||
// change in priority
|
||||
// add to weight with the same previous priority cumulated weight
|
||||
_weight += _priorityWeight * (1.0 - _weight);
|
||||
_priorityWeight = 0;
|
||||
_lastPriority = priority;
|
||||
}
|
||||
|
||||
_priorityWeight += weight;
|
||||
float t = (1.0 - _weight) * weight / _priorityWeight;
|
||||
lerp(t, _target, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
weight = (1.0 - _weight) * weight;
|
||||
_target += val * weight;
|
||||
_priorityWeight = weight;
|
||||
_lastPriority = priority;
|
||||
_target = val;
|
||||
}
|
||||
addWeight(weight);
|
||||
}
|
||||
const T& getValue() const { return _target;}
|
||||
const T& getValue() const { return _target; }
|
||||
|
||||
void normalize()
|
||||
{
|
||||
float weightSummed = getWeight();
|
||||
if (fabs(weightSummed) < 1e-4 || fabs(weightSummed-1) < 1e-4)
|
||||
return;
|
||||
(_target) /= weightSummed;
|
||||
}
|
||||
|
||||
void setValue(const T& value) { _target = value;}
|
||||
void setValue(const T& value) { _target = value; }
|
||||
|
||||
protected:
|
||||
|
||||
T _target;
|
||||
};
|
||||
|
||||
|
||||
// Target Specialisation for Quaternions
|
||||
template <>
|
||||
class TemplateTarget< osg::Quat > : public Target
|
||||
template <class T>
|
||||
inline void TemplateTarget<T>::lerp(float t, const T& a, const T& b)
|
||||
{
|
||||
public:
|
||||
|
||||
TemplateTarget () {}
|
||||
_target = a * (1.0f - t) + b * t;
|
||||
}
|
||||
|
||||
const osg::Quat& getValue() const { return _target;}
|
||||
void update(float weight, const osg::Quat& val)
|
||||
{
|
||||
if (!_weight)
|
||||
_target = val * weight;
|
||||
else
|
||||
{
|
||||
weight = (1.0 - _weight) * weight;
|
||||
_target += val * weight;
|
||||
}
|
||||
addWeight(weight);
|
||||
}
|
||||
|
||||
// maybe normalize could be non virtual and put on ITarget
|
||||
void normalize()
|
||||
template <>
|
||||
inline void TemplateTarget<osg::Quat>::lerp(float t, const osg::Quat& a, const osg::Quat& b)
|
||||
{
|
||||
if (a.asVec4() * b.asVec4() < 0.0)
|
||||
{
|
||||
float weightSummed = getWeight();
|
||||
if (fabs(weightSummed) < 1e-4 || fabs(weightSummed-1.0) < 1e-4)
|
||||
return;
|
||||
(_target) /= weightSummed;
|
||||
_target = a * (1.0f - t) + b * -t;
|
||||
}
|
||||
else
|
||||
{
|
||||
_target = a * (1.0f - t) + b * t;
|
||||
}
|
||||
|
||||
void setValue(const osg::Quat& value) { _target = value;}
|
||||
|
||||
protected:
|
||||
osg::Quat::value_type len2 = _target.length2();
|
||||
if ( len2 != 1.0 && len2 != 0.0)
|
||||
_target *= 1.0/sqrt(len2);
|
||||
}
|
||||
|
||||
osg::Quat _target;
|
||||
};
|
||||
|
||||
typedef TemplateTarget<osg::Matrixf> MatrixTarget;
|
||||
typedef TemplateTarget<osg::Quat> QuatTarget;
|
||||
typedef TemplateTarget<osg::Vec3> Vec3Target;
|
||||
typedef TemplateTarget<osg::Vec4> Vec4Target;
|
||||
|
||||
@@ -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
|
||||
@@ -12,180 +12,88 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_TIMELINE_H
|
||||
#define OSGANIMATION_TIMELINE_H
|
||||
#ifndef OSGANIMATION_TIMELINE
|
||||
#define OSGANIMATION_TIMELINE 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osg/Object>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <osg/observer_ptr>
|
||||
#include <osg/Notify>
|
||||
#include <osg/Group>
|
||||
#include <osgAnimation/Animation>
|
||||
#include <osg/Stats>
|
||||
#include <osgAnimation/Action>
|
||||
#include <osgAnimation/FrameAction>
|
||||
#include <osgAnimation/AnimationManagerBase>
|
||||
#include <osgAnimation/StatsVisitor>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class Action : public osg::Object
|
||||
class OSGANIMATION_EXPORT Timeline : public Action
|
||||
{
|
||||
public:
|
||||
|
||||
class Callback : public osg::Object
|
||||
{
|
||||
public:
|
||||
Callback(){}
|
||||
Callback(const Callback&,const osg::CopyOp&) {}
|
||||
Timeline();
|
||||
Timeline(const Timeline& nc,const osg::CopyOp& op = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgAnimation,Callback);
|
||||
|
||||
virtual void operator()(Action* /*action*/) {}
|
||||
|
||||
void addNestedCallback(Callback* callback)
|
||||
{
|
||||
if (_nested.valid())
|
||||
_nested->addNestedCallback(callback);
|
||||
else
|
||||
_nested = callback;
|
||||
}
|
||||
META_Action(osgAnimation, Timeline);
|
||||
|
||||
protected:
|
||||
osg::ref_ptr<Callback> _nested;
|
||||
};
|
||||
|
||||
|
||||
typedef std::map<unsigned int, osg::ref_ptr<Callback> > FrameCallback;
|
||||
|
||||
META_Object(osgAnimation, Action);
|
||||
|
||||
Action()
|
||||
{
|
||||
_numberFrame = 25;
|
||||
_fps = 25;
|
||||
_speed = 1.0;
|
||||
_loop = 1;
|
||||
}
|
||||
|
||||
Action(const Action&,const osg::CopyOp&) {}
|
||||
|
||||
void setCallback(double when, Callback* callback)
|
||||
{
|
||||
setCallback(static_cast<unsigned int>(floor(when*_fps)), callback);
|
||||
}
|
||||
|
||||
void setCallback(unsigned int frame, Callback* callback)
|
||||
{
|
||||
if (_framesCallback[frame].valid())
|
||||
_framesCallback[frame]->addNestedCallback(callback);
|
||||
else
|
||||
_framesCallback[frame] = callback;
|
||||
}
|
||||
Callback* getCallback(unsigned int frame)
|
||||
{
|
||||
if (_framesCallback.find(frame) == _framesCallback.end())
|
||||
return 0;
|
||||
return _framesCallback[frame].get();
|
||||
}
|
||||
|
||||
void setNumFrames(unsigned int numFrames) { _numberFrame = numFrames;}
|
||||
void setDuration(double duration) { _numberFrame = static_cast<unsigned int>(floor(duration * _fps)); }
|
||||
|
||||
unsigned int getNumFrames() const { return _numberFrame;}
|
||||
double getDuration() const { return _numberFrame * 1.0 / _fps; }
|
||||
|
||||
// 0 means infini else it's the number of loop
|
||||
virtual void setLoop(int nb) { _loop = nb; }
|
||||
virtual unsigned int getLoop() const { return _loop;}
|
||||
|
||||
// get the number of loop, the frame relative to loop.
|
||||
// return true if in range, and false if out of range.
|
||||
bool evaluateFrame(unsigned int frame, unsigned int& resultframe, unsigned int& nbloop )
|
||||
{
|
||||
nbloop = frame / getNumFrames();
|
||||
resultframe = frame;
|
||||
|
||||
if (frame > getNumFrames()-1)
|
||||
{
|
||||
if (!getLoop())
|
||||
resultframe = frame % getNumFrames();
|
||||
else
|
||||
{
|
||||
if (nbloop >= getLoop())
|
||||
return false;
|
||||
else
|
||||
resultframe = frame % getNumFrames();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void evaluate(unsigned int frame)
|
||||
{
|
||||
unsigned int frameInAction;
|
||||
unsigned int loopDone;
|
||||
if (!evaluateFrame(frame, frameInAction, loopDone))
|
||||
osg::notify(osg::DEBUG_INFO) << getName() << " Action frame " << frameInAction << " finished" << std::endl;
|
||||
else
|
||||
osg::notify(osg::DEBUG_INFO) << getName() << " Action frame " << frame << " relative to loop " << frameInAction << " no loop " << loopDone<< std::endl;
|
||||
}
|
||||
|
||||
virtual void evaluateCallback(unsigned int frame)
|
||||
{
|
||||
unsigned int frameInAction;
|
||||
unsigned int loopDone;
|
||||
if (!evaluateFrame(frame, frameInAction, loopDone))
|
||||
return;
|
||||
|
||||
frame = frameInAction;
|
||||
if (_framesCallback.find(frame) != _framesCallback.end())
|
||||
{
|
||||
std::cout << getName() << " evaluate callback " << _framesCallback[frame]->getName() << " at " << frame << std::endl;
|
||||
(*_framesCallback[frame])(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
FrameCallback _framesCallback;
|
||||
|
||||
double _speed;
|
||||
unsigned int _fps;
|
||||
unsigned int _numberFrame;
|
||||
unsigned int _loop;
|
||||
|
||||
enum State
|
||||
enum TimelineStatus
|
||||
{
|
||||
Play,
|
||||
Stop
|
||||
};
|
||||
|
||||
State _state;
|
||||
};
|
||||
|
||||
TimelineStatus getStatus() const { return _state; }
|
||||
|
||||
class Timeline : public osg::Object
|
||||
{
|
||||
protected:
|
||||
typedef std::pair<unsigned int, osg::ref_ptr<Action> > FrameAction;
|
||||
typedef std::vector<FrameAction> ActionList;
|
||||
typedef std::map<int, ActionList> ActionLayers;
|
||||
enum State
|
||||
{
|
||||
Play,
|
||||
Stop
|
||||
};
|
||||
|
||||
|
||||
const ActionList& getActionLayer(int i) { return _actions[i];}
|
||||
unsigned int getCurrentFrame() const { return _currentFrame;}
|
||||
double getCurrentTime() const { return _currentFrame * 1.0 / _fps;}
|
||||
|
||||
void play() { _state = Play; }
|
||||
void gotoFrame(unsigned int frame) { _currentFrame = frame; }
|
||||
void stop() { _state = Stop; }
|
||||
bool getEvaluating() const { return _evaluating;}
|
||||
|
||||
bool isActive(Action* activeAction);
|
||||
|
||||
void removeAction(Action* action);
|
||||
virtual void addActionAt(unsigned int frame, Action* action, int priority = 0);
|
||||
virtual void addActionAt(double t, Action* action, int priority = 0);
|
||||
void addActionNow(Action* action, int priority = 0);
|
||||
|
||||
void clearActions();
|
||||
|
||||
virtual void update(double simulationTime);
|
||||
void setLastFrameEvaluated(unsigned int frame) { _previousFrameEvaluated = frame; }
|
||||
|
||||
void setEvaluating(bool state) { _evaluating = state;}
|
||||
void traverse(ActionVisitor& visitor);
|
||||
|
||||
void setStats(osg::Stats* stats);
|
||||
osg::Stats* getStats();
|
||||
void collectStats(bool state);
|
||||
osgAnimation::StatsActionVisitor* getStatsVisitor();
|
||||
|
||||
const ActionLayers& getActionLayers() const { return _actions; }
|
||||
|
||||
void processPendingOperation();
|
||||
void setAnimationManager(AnimationManagerBase*);
|
||||
protected:
|
||||
osg::observer_ptr<AnimationManagerBase> _animationManager;
|
||||
ActionLayers _actions;
|
||||
double _lastUpdate;
|
||||
double _speed;
|
||||
unsigned int _currentFrame;
|
||||
unsigned int _fps;
|
||||
unsigned int _numberFrame;
|
||||
unsigned int _previousFrameEvaluated;
|
||||
bool _loop;
|
||||
bool _initFirstFrame;
|
||||
|
||||
State _state;
|
||||
TimelineStatus _state;
|
||||
|
||||
bool _collectStats;
|
||||
osg::ref_ptr<osg::Stats> _stats;
|
||||
osg::ref_ptr<osgAnimation::StatsActionVisitor> _statsVisitor;
|
||||
|
||||
// to manage pending operation
|
||||
bool _evaluating;
|
||||
@@ -202,331 +110,9 @@ namespace osgAnimation
|
||||
CommandList _addActionOperations;
|
||||
ActionList _removeActionOperations;
|
||||
|
||||
void setEvaluating(bool state) { _evaluating = state;}
|
||||
void processPendingOperation()
|
||||
{
|
||||
// process all pending add action operation
|
||||
while( !_addActionOperations.empty())
|
||||
{
|
||||
internalAddAction(_addActionOperations.back()._priority, _addActionOperations.back()._action);
|
||||
_addActionOperations.pop_back();
|
||||
}
|
||||
|
||||
// process all pending remove action operation
|
||||
while( !_removeActionOperations.empty())
|
||||
{
|
||||
internalRemoveAction(_removeActionOperations.back().second.get());
|
||||
_removeActionOperations.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void internalRemoveAction(Action* action)
|
||||
{
|
||||
for (ActionLayers::iterator it = _actions.begin(); it != _actions.end(); it++)
|
||||
{
|
||||
ActionList& fa = it->second;
|
||||
for (unsigned int i = 0; i < fa.size(); i++)
|
||||
if (fa[i].second.get() == action)
|
||||
{
|
||||
fa.erase(fa.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void internalAddAction(int priority, const FrameAction& ftl)
|
||||
{
|
||||
_actions[priority].push_back(ftl);
|
||||
}
|
||||
void internalRemoveAction(Action* action);
|
||||
void internalAddAction(int priority, const FrameAction& ftl);
|
||||
|
||||
public:
|
||||
|
||||
META_Object(osgAnimation, Timeline);
|
||||
|
||||
Timeline();
|
||||
Timeline(const Timeline& nc,const osg::CopyOp& op = osg::CopyOp::SHALLOW_COPY);
|
||||
State getStatus() const { return _state; }
|
||||
const ActionList& getActionLayer(int i)
|
||||
{
|
||||
return _actions[i];
|
||||
}
|
||||
unsigned int getCurrentFrame() const { return _currentFrame;}
|
||||
double getCurrentTime() const { return _currentFrame * 1.0 / _fps;}
|
||||
|
||||
void play() { _state = Play; }
|
||||
void gotoFrame(unsigned int frame) { _currentFrame = frame; }
|
||||
void stop() { _state = Stop; }
|
||||
bool getEvaluating() const { return _evaluating;}
|
||||
|
||||
bool isActive(Action* activeAction)
|
||||
{
|
||||
// update from high priority to low priority
|
||||
for( ActionLayers::iterator iterAnim = _actions.begin(); iterAnim != _actions.end(); ++iterAnim )
|
||||
{
|
||||
// update all animation
|
||||
ActionList& list = iterAnim->second;
|
||||
for (unsigned int i = 0; i < list.size(); i++)
|
||||
{
|
||||
Action* action = list[i].second.get();
|
||||
if (action == activeAction)
|
||||
{
|
||||
unsigned int firstFrame = list[i].first;
|
||||
// check if current frame of timeline hit an action interval
|
||||
if (_currentFrame >= firstFrame &&
|
||||
_currentFrame < (firstFrame + action->getNumFrames()) )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void removeAction(Action* action)
|
||||
{
|
||||
if (getEvaluating())
|
||||
_removeActionOperations.push_back(FrameAction(0, action));
|
||||
else
|
||||
internalRemoveAction(action);
|
||||
}
|
||||
|
||||
virtual void addActionAt(unsigned int frame, Action* action, int priority = 0)
|
||||
{
|
||||
if (getEvaluating())
|
||||
_addActionOperations.push_back(Command(priority,FrameAction(frame, action)));
|
||||
else
|
||||
internalAddAction(priority, FrameAction(frame, action));
|
||||
}
|
||||
virtual void addActionAt(double t, Action* action, int priority = 0)
|
||||
{
|
||||
unsigned int frame = static_cast<unsigned int>(floor(t * _fps));
|
||||
addActionAt(frame, action, priority);
|
||||
}
|
||||
|
||||
virtual void evaluate(unsigned int frame)
|
||||
{
|
||||
setEvaluating(true);
|
||||
osg::notify(osg::DEBUG_INFO) << getName() << " evaluate frame " << _currentFrame << std::endl;
|
||||
|
||||
// update from high priority to low priority
|
||||
for( ActionLayers::reverse_iterator iterAnim = _actions.rbegin(); iterAnim != _actions.rend(); ++iterAnim )
|
||||
{
|
||||
// update all animation
|
||||
ActionList& list = iterAnim->second;
|
||||
for (unsigned int i = 0; i < list.size(); i++)
|
||||
{
|
||||
unsigned int firstFrame = list[i].first;
|
||||
Action* action = list[i].second.get();
|
||||
// check if current frame of timeline hit an action interval
|
||||
if (frame >= firstFrame &&
|
||||
frame < (firstFrame + action->getNumFrames()) )
|
||||
action->evaluate(frame - firstFrame);
|
||||
}
|
||||
}
|
||||
setEvaluating(false);
|
||||
|
||||
// evaluate callback after updating all animation
|
||||
evaluateCallback(frame);
|
||||
_previousFrameEvaluated = frame;
|
||||
}
|
||||
|
||||
virtual void evaluateCallback(unsigned int frame)
|
||||
{
|
||||
// update from high priority to low priority
|
||||
for( ActionLayers::reverse_iterator iterAnim = _actions.rbegin(); iterAnim != _actions.rend(); ++iterAnim )
|
||||
{
|
||||
// update all animation
|
||||
ActionList& list = iterAnim->second;
|
||||
for (unsigned int i = 0; i < list.size(); i++)
|
||||
{
|
||||
unsigned int firstFrame = list[i].first;
|
||||
Action* action = list[i].second.get();
|
||||
// check if current frame of timeline hit an action interval
|
||||
if (frame >= firstFrame &&
|
||||
frame < (firstFrame + action->getNumFrames()) )
|
||||
action->evaluateCallback(frame - firstFrame);
|
||||
}
|
||||
}
|
||||
processPendingOperation();
|
||||
}
|
||||
|
||||
virtual void update(double simulationTime)
|
||||
{
|
||||
// first time we call update we generate one frame
|
||||
if (!_initFirstFrame)
|
||||
{
|
||||
_lastUpdate = simulationTime;
|
||||
_initFirstFrame = true;
|
||||
evaluate(_currentFrame);
|
||||
}
|
||||
|
||||
// find the number of frame pass since the last update
|
||||
double delta = (simulationTime - _lastUpdate);
|
||||
double nbframes = delta * _fps * _speed;
|
||||
unsigned int nb = static_cast<unsigned int>(floor(nbframes));
|
||||
|
||||
for (unsigned int i = 0; i < nb; i++)
|
||||
{
|
||||
if (_state == Play)
|
||||
_currentFrame++;
|
||||
evaluate(_currentFrame);
|
||||
}
|
||||
if (nb)
|
||||
{
|
||||
_lastUpdate += ((double)nb) / _fps;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// blend in from 0 to weight in duration
|
||||
class BlendIn : public Action
|
||||
{
|
||||
double _weight;
|
||||
osg::ref_ptr<Animation> _animation;
|
||||
|
||||
public:
|
||||
BlendIn(Animation* animation, double duration, double weight)
|
||||
{
|
||||
_animation = animation;
|
||||
_weight = weight;
|
||||
float d = duration * _fps;
|
||||
setNumFrames(static_cast<unsigned int>(floor(d)) + 1);
|
||||
setName("BlendIn");
|
||||
}
|
||||
double getWeight() const { return _weight;}
|
||||
virtual void evaluate(unsigned int frame)
|
||||
{
|
||||
Action::evaluate(frame);
|
||||
// frame + 1 because the start is 0 and we want to start the blend in at the first
|
||||
// frame.
|
||||
double ratio = ( (frame+1) * 1.0 / (getNumFrames()) );
|
||||
double w = _weight;
|
||||
if (frame < getNumFrames() -1 ) // the last frame we set the target weight the user asked
|
||||
w = _weight * ratio;
|
||||
_animation->setWeight(w);
|
||||
}
|
||||
};
|
||||
|
||||
// blend in from 0 to weight in duration
|
||||
class BlendOut : public Action
|
||||
{
|
||||
double _weight;
|
||||
osg::ref_ptr<Animation> _animation;
|
||||
public:
|
||||
BlendOut(Animation* animation, double duration)
|
||||
{
|
||||
_animation = animation;
|
||||
float d = duration * _fps;
|
||||
setNumFrames(static_cast<unsigned int>(floor(d) + 1));
|
||||
_weight = 1.0;
|
||||
setName("BlendOut");
|
||||
}
|
||||
double getWeight() const { return _weight;}
|
||||
virtual void evaluate(unsigned int frame)
|
||||
{
|
||||
Action::evaluate(frame);
|
||||
// frame + 1 because the start is 0 and we want to start the blend in at the first
|
||||
// frame.
|
||||
double ratio = ( (frame+1) * 1.0 / (getNumFrames()) );
|
||||
double w = 0.0;
|
||||
if (frame < getNumFrames() -1 ) // the last frame we set the target weight the user asked
|
||||
w = _weight * (1.0-ratio);
|
||||
_animation->setWeight(w);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ActionAnimation : public Action
|
||||
{
|
||||
public:
|
||||
ActionAnimation(Animation* animation) : _animation(animation)
|
||||
{
|
||||
setDuration(animation->getDuration());
|
||||
setName(animation->getName());
|
||||
}
|
||||
virtual void evaluate(unsigned int frame)
|
||||
{
|
||||
Action::evaluate(frame);
|
||||
_animation->update(frame * 1.0/_fps);
|
||||
}
|
||||
Animation* getAnimation() { return _animation.get(); }
|
||||
protected:
|
||||
osg::ref_ptr<Animation> _animation;
|
||||
};
|
||||
|
||||
|
||||
// encapsulate animation with blend in blend out for classic usage
|
||||
class StripAnimation : public Action
|
||||
{
|
||||
protected:
|
||||
typedef std::pair<unsigned int, osg::ref_ptr<Action> > FrameAction;
|
||||
|
||||
public:
|
||||
StripAnimation(Animation* animation, double blendInDuration, double blendOutDuration, double blendInWeightTarget = 1.0 )
|
||||
{
|
||||
_blendIn = new BlendIn(animation, blendInDuration, blendInWeightTarget);
|
||||
_animation = new ActionAnimation(animation);
|
||||
unsigned int start = static_cast<unsigned int>(floor((_animation->getDuration() - blendOutDuration) * _fps));
|
||||
_blendOut = FrameAction(start, new BlendOut(animation, blendOutDuration));
|
||||
setName(animation->getName() + "_Strip");
|
||||
_blendIn->setName(_animation->getName() + "_" + _blendIn->getName());
|
||||
_blendOut.second->setName(_animation->getName() + "_" + _blendOut.second->getName());
|
||||
setDuration(animation->getDuration());
|
||||
}
|
||||
|
||||
ActionAnimation* getActionAnimation() { return _animation.get(); }
|
||||
BlendIn* getBlendIn() { return _blendIn.get(); }
|
||||
BlendOut* getBlendOut() { return dynamic_cast<BlendOut*>(_blendOut.second.get()); }
|
||||
const ActionAnimation* getActionAnimation() const { return _animation.get(); }
|
||||
const BlendIn* getBlendIn() const { return _blendIn.get(); }
|
||||
const BlendOut* getBlendOut() const { return dynamic_cast<BlendOut*>(_blendOut.second.get()); }
|
||||
|
||||
unsigned int getLoop() const { return _animation->getLoop(); }
|
||||
void setLoop(unsigned int loop)
|
||||
{
|
||||
_animation->setLoop(loop);
|
||||
if (!loop)
|
||||
setDuration(-1);
|
||||
else
|
||||
setDuration(loop * _animation->getDuration());
|
||||
|
||||
// duration changed re evaluate the blendout duration
|
||||
unsigned int start = static_cast<unsigned int>(floor((getDuration() - _blendOut.second->getDuration()) * _fps));
|
||||
_blendOut = FrameAction(start, _blendOut.second);
|
||||
}
|
||||
|
||||
virtual void evaluate(unsigned int frame)
|
||||
{
|
||||
if (frame > getNumFrames() - 1)
|
||||
return;
|
||||
|
||||
Action::evaluate(frame);
|
||||
if (frame < _blendIn->getNumFrames())
|
||||
_blendIn->evaluate(frame);
|
||||
if (frame >= _blendOut.first)
|
||||
_blendOut.second->evaluate(frame - _blendOut.first);
|
||||
_animation->evaluate(frame);
|
||||
}
|
||||
|
||||
protected:
|
||||
osg::ref_ptr<BlendIn> _blendIn;
|
||||
FrameAction _blendOut;
|
||||
osg::ref_ptr<ActionAnimation> _animation;
|
||||
};
|
||||
|
||||
|
||||
class RunAction : public Action::Callback
|
||||
{
|
||||
protected:
|
||||
osg::ref_ptr<Timeline> _tm;
|
||||
osg::ref_ptr<Action> _action;
|
||||
|
||||
public:
|
||||
RunAction(Timeline* tm, Action* a) : _tm(tm), _action(a) {}
|
||||
virtual void operator()(Action* /*action*/)
|
||||
{
|
||||
_tm->addActionAt(_tm->getCurrentFrame(), _action.get()); // warning we are trsversing the vector
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -10,10 +10,10 @@
|
||||
* 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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_TIMELINE_ANIMATION_MANAGER_H
|
||||
#define OSGANIMATION_TIMELINE_ANIMATION_MANAGER_H
|
||||
#ifndef OSGANIMATION_TIMELINE_ANIMATION_MANAGER
|
||||
#define OSGANIMATION_TIMELINE_ANIMATION_MANAGER 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/AnimationManagerBase>
|
||||
@@ -23,21 +23,21 @@
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT TimelineAnimationManager : public AnimationManagerBase
|
||||
{
|
||||
protected:
|
||||
osg::ref_ptr<Timeline> _timeline;
|
||||
class OSGANIMATION_EXPORT TimelineAnimationManager : public AnimationManagerBase
|
||||
{
|
||||
protected:
|
||||
osg::ref_ptr<Timeline> _timeline;
|
||||
|
||||
public:
|
||||
META_Object(osgAnimation, TimelineAnimationManager);
|
||||
TimelineAnimationManager();
|
||||
TimelineAnimationManager(const AnimationManagerBase& manager);
|
||||
TimelineAnimationManager(const TimelineAnimationManager& nc,const osg::CopyOp&);
|
||||
public:
|
||||
META_Object(osgAnimation, TimelineAnimationManager);
|
||||
TimelineAnimationManager();
|
||||
TimelineAnimationManager(const AnimationManagerBase& manager);
|
||||
TimelineAnimationManager(const TimelineAnimationManager& nc,const osg::CopyOp&);
|
||||
|
||||
Timeline* getTimeline() { return _timeline.get(); }
|
||||
const Timeline* getTimeline() const { return _timeline.get(); }
|
||||
void update(double time);
|
||||
};
|
||||
Timeline* getTimeline() { return _timeline.get(); }
|
||||
const Timeline* getTimeline() const { return _timeline.get(); }
|
||||
void update(double time);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
36
include/osgAnimation/UpdateBone
Normal file
36
include/osgAnimation/UpdateBone
Normal file
@@ -0,0 +1,36 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_UPDATE_BONE
|
||||
#define OSGANIMATION_UPDATE_BONE 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/UpdateMatrixTransform>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT UpdateBone : public UpdateMatrixTransform
|
||||
{
|
||||
public:
|
||||
META_Object(osgAnimation, UpdateBone);
|
||||
|
||||
UpdateBone(const std::string& name = "");
|
||||
UpdateBone(const UpdateBone&,const osg::CopyOp&);
|
||||
void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
46
include/osgAnimation/UpdateMaterial
Normal file
46
include/osgAnimation/UpdateMaterial
Normal file
@@ -0,0 +1,46 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_UPDATE_MATERIAL
|
||||
#define OSGANIMATION_UPDATE_MATERIAL 1
|
||||
|
||||
#include <osgAnimation/AnimationUpdateCallback>
|
||||
#include <osgAnimation/Export>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/Material>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT UpdateMaterial : public AnimationUpdateCallback<osg::StateAttributeCallback>
|
||||
{
|
||||
protected:
|
||||
osg::ref_ptr<Vec4Target> _diffuse;
|
||||
|
||||
public:
|
||||
|
||||
META_Object(osgAnimation, UpdateMaterial);
|
||||
|
||||
UpdateMaterial(const std::string& name = "");
|
||||
UpdateMaterial(const UpdateMaterial& apc,const osg::CopyOp& copyop);
|
||||
|
||||
/** Callback method called by the NodeVisitor when visiting a node.*/
|
||||
virtual void operator () (osg::StateAttribute*, osg::NodeVisitor*);
|
||||
void update(osg::Material& material);
|
||||
bool link(Channel* channel);
|
||||
Vec4Target* getDiffuse();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
48
include/osgAnimation/UpdateMatrixTransform
Normal file
48
include/osgAnimation/UpdateMatrixTransform
Normal file
@@ -0,0 +1,48 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2009 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
|
||||
* (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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSGANIMATION_UPDATE_MATRIX_TRANSFORM
|
||||
#define OSGANIMATION_UPDATE_MATRIX_TRANSFORM 1
|
||||
|
||||
#include <osgAnimation/Export>
|
||||
#include <osgAnimation/AnimationUpdateCallback>
|
||||
#include <osgAnimation/StackedTransform>
|
||||
#include <osg/NodeCallback>
|
||||
|
||||
namespace osgAnimation
|
||||
{
|
||||
|
||||
class OSGANIMATION_EXPORT UpdateMatrixTransform : public AnimationUpdateCallback<osg::NodeCallback>
|
||||
{
|
||||
public:
|
||||
META_Object(osgAnimation, UpdateMatrixTransform);
|
||||
|
||||
UpdateMatrixTransform(const std::string& name = "");
|
||||
UpdateMatrixTransform(const UpdateMatrixTransform& apc,const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
// Callback method called by the NodeVisitor when visiting a node.
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||
virtual bool link(osgAnimation::Channel* channel);
|
||||
|
||||
StackedTransform& getStackedTransforms() { return _transforms;}
|
||||
const StackedTransform& getStackedTransforms() const { return _transforms;}
|
||||
|
||||
protected:
|
||||
StackedTransform _transforms;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -12,8 +12,8 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_VERTEX_INFLUENCES_H
|
||||
#define OSGANIMATION_VERTEX_INFLUENCES_H
|
||||
#ifndef OSGANIMATION_VERTEX_INFLUENCE
|
||||
#define OSGANIMATION_VERTEX_INFLUENCE 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osgAnimation/Export>
|
||||
@@ -38,8 +38,6 @@ namespace osgAnimation
|
||||
std::string _name;
|
||||
};
|
||||
|
||||
// typedef std::map<std::string, VertexInfluence> VertexInfluenceMap;
|
||||
|
||||
class VertexInfluenceMap : public std::map<std::string, VertexInfluence> , public osg::Object
|
||||
{
|
||||
public:
|
||||
@@ -52,7 +50,7 @@ namespace osgAnimation
|
||||
|
||||
// this class manage VertexInfluence database by mesh
|
||||
// reference bones per vertex ...
|
||||
class VertexInfluenceSet
|
||||
class OSGANIMATION_EXPORT VertexInfluenceSet
|
||||
{
|
||||
public:
|
||||
typedef std::vector<VertexInfluence> BoneToVertexList;
|
||||
@@ -73,7 +71,7 @@ namespace osgAnimation
|
||||
typedef std::vector<BoneWeight> BoneWeightList;
|
||||
typedef std::map<int,BoneWeightList> VertexIndexToBoneWeightMap;
|
||||
|
||||
class UniqVertexSetToBoneSet
|
||||
class UniqVertexSetToBoneSet
|
||||
{
|
||||
public:
|
||||
void setBones(BoneWeightList& bones) { _bones = bones;}
|
||||
@@ -88,14 +86,12 @@ namespace osgAnimation
|
||||
typedef std::vector<UniqVertexSetToBoneSet> UniqVertexSetToBoneSetList;
|
||||
|
||||
const UniqVertexSetToBoneSetList& getUniqVertexSetToBoneSetList() const { return _uniqVertexSetToBoneSet;}
|
||||
void addVertexInfluence(const VertexInfluence& v) { _bone2Vertexes.push_back(v); }
|
||||
void addVertexInfluence(const VertexInfluence& v);
|
||||
void buildVertex2BoneList();
|
||||
void buildUniqVertexSetToBoneSetList();
|
||||
void clear()
|
||||
{
|
||||
_bone2Vertexes.clear();
|
||||
_uniqVertexSetToBoneSet.clear();
|
||||
}
|
||||
void clear();
|
||||
|
||||
const VertexIndexToBoneWeightMap& getVertexToBoneList() const;
|
||||
protected:
|
||||
BoneToVertexList _bone2Vertexes;
|
||||
VertexIndexToBoneWeightMap _vertex2Bones;
|
||||
|
||||
Reference in New Issue
Block a user