2.8 branch: backport of osgAnimation from svn head 11026.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user