2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*-
|
2009-08-06 20:40:06 +08:00
|
|
|
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
|
2008-11-22 20:14:19 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2008-11-22 20:14:19 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2008-11-22 20:14:19 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2008-11-22 20:14:19 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
2009-08-06 20:40:06 +08:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Cedric Pinson <cedric.pinson@plopbyte.net>
|
|
|
|
* Michael Platings <mplatings@pixelpower.com>
|
|
|
|
*/
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2010-03-26 01:50:29 +08:00
|
|
|
#ifndef OSGANIMATION_CHANNEL
|
|
|
|
#define OSGANIMATION_CHANNEL 1
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
#include <osgAnimation/Export>
|
|
|
|
#include <osgAnimation/Sampler>
|
|
|
|
#include <osgAnimation/Target>
|
|
|
|
#include <osg/Referenced>
|
|
|
|
#include <string>
|
|
|
|
|
2016-06-25 14:49:56 +08:00
|
|
|
|
2008-11-22 20:14:19 +08:00
|
|
|
namespace osgAnimation
|
|
|
|
{
|
|
|
|
|
2016-06-25 14:49:56 +08:00
|
|
|
class OSGANIMATION_EXPORT Channel : public osg::Object
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Channel();
|
2009-06-22 22:24:59 +08:00
|
|
|
Channel(const Channel& channel);
|
2008-11-22 20:14:19 +08:00
|
|
|
virtual ~Channel();
|
2009-06-22 22:24:59 +08:00
|
|
|
virtual Channel* clone() const = 0;
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2016-06-25 14:49:56 +08:00
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Channel*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osgAnimation"; }
|
|
|
|
virtual const char* className() const { return "Channel"; }
|
|
|
|
|
2010-03-26 01:50:29 +08:00
|
|
|
virtual void update(double time, float weight, int priority) = 0;
|
2008-11-22 20:14:19 +08:00
|
|
|
virtual void reset() = 0;
|
|
|
|
virtual Target* getTarget() = 0;
|
2009-08-06 20:40:06 +08:00
|
|
|
virtual bool setTarget(Target*) = 0;
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
const std::string& getName() const;
|
|
|
|
void setName(const std::string& name);
|
|
|
|
|
2010-03-26 01:50:29 +08:00
|
|
|
virtual double getStartTime() const = 0;
|
|
|
|
virtual double getEndTime() const = 0;
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
const std::string& getTargetName() const;
|
|
|
|
void setTargetName(const std::string& name);
|
|
|
|
|
|
|
|
virtual Sampler* getSampler() = 0;
|
|
|
|
virtual const Sampler* getSampler() const = 0;
|
|
|
|
|
2009-09-09 17:52:54 +08:00
|
|
|
// 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;
|
|
|
|
|
2008-11-22 20:14:19 +08:00
|
|
|
protected:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-11-22 20:14:19 +08:00
|
|
|
std::string _targetName;
|
|
|
|
std::string _name;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename SamplerType>
|
|
|
|
class TemplateChannel : public Channel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef typename SamplerType::UsingType UsingType;
|
|
|
|
typedef TemplateTarget<UsingType> TargetType;
|
|
|
|
typedef TemplateKeyframeContainer<typename SamplerType::KeyframeType> KeyframeContainerType;
|
2016-06-25 14:49:56 +08:00
|
|
|
|
|
|
|
Object* cloneType() const { return new TemplateChannel(); }
|
2016-06-26 00:19:00 +08:00
|
|
|
Object* clone(const osg::CopyOp&) const { return new TemplateChannel<SamplerType>(*this); }
|
2009-06-22 22:24:59 +08:00
|
|
|
Channel* clone() const { return new TemplateChannel<SamplerType>(*this); }
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-09-09 17:52:54 +08:00
|
|
|
TemplateChannel (const TemplateChannel& channel) :
|
2009-10-21 23:45:13 +08:00
|
|
|
Channel(channel)
|
2009-06-22 22:24:59 +08:00
|
|
|
{
|
2009-10-21 23:45:13 +08:00
|
|
|
if (channel.getTargetTyped())
|
|
|
|
_target = new TargetType(*channel.getTargetTyped());
|
|
|
|
|
|
|
|
if (channel.getSamplerTyped())
|
|
|
|
_sampler = new SamplerType(*channel.getSamplerTyped());
|
2009-06-22 22:24:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TemplateChannel (SamplerType* s = 0,TargetType* target = 0)
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
if (target)
|
|
|
|
_target = target;
|
|
|
|
else
|
|
|
|
_target = new TargetType;
|
|
|
|
_sampler = s;
|
|
|
|
}
|
|
|
|
|
2009-09-09 17:52:54 +08:00
|
|
|
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
|
2009-10-21 23:45:13 +08:00
|
|
|
getOrCreateSampler()->setKeyframeContainer(0);
|
2009-09-09 17:52:54 +08:00
|
|
|
getOrCreateSampler()->getOrCreateKeyframeContainer();
|
|
|
|
// add the key
|
|
|
|
_sampler->getKeyframeContainerTyped()->push_back(key);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-22 20:14:19 +08:00
|
|
|
virtual ~TemplateChannel() {}
|
2012-03-22 01:36:20 +08:00
|
|
|
virtual void update(double time, float weight, int priority)
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
// skip if weight == 0
|
2009-08-26 17:24:02 +08:00
|
|
|
if (weight < 1e-4)
|
2008-11-22 20:14:19 +08:00
|
|
|
return;
|
|
|
|
typename SamplerType::UsingType value;
|
|
|
|
_sampler->getValueAt(time, value);
|
2009-08-26 17:24:02 +08:00
|
|
|
_target->update(weight, value, priority);
|
2008-11-22 20:14:19 +08:00
|
|
|
}
|
|
|
|
virtual void reset() { _target->reset(); }
|
|
|
|
virtual Target* getTarget() { return _target.get();}
|
2009-08-06 20:40:06 +08:00
|
|
|
virtual bool setTarget(Target* target)
|
|
|
|
{
|
|
|
|
_target = dynamic_cast<TargetType*>(target);
|
|
|
|
return _target.get() == target;
|
|
|
|
}
|
2008-11-22 20:14:19 +08:00
|
|
|
|
2009-08-06 20:40:06 +08:00
|
|
|
SamplerType* getOrCreateSampler()
|
2008-11-22 20:14:19 +08:00
|
|
|
{
|
|
|
|
if (!_sampler.valid())
|
|
|
|
_sampler = new SamplerType;
|
|
|
|
return _sampler.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Sampler* getSampler() { return _sampler.get(); }
|
|
|
|
const Sampler* getSampler() const { return _sampler.get(); }
|
|
|
|
|
|
|
|
SamplerType* getSamplerTyped() { return _sampler.get();}
|
|
|
|
const SamplerType* getSamplerTyped() const { return _sampler.get();}
|
|
|
|
void setSampler(SamplerType* sampler) { _sampler = sampler; }
|
|
|
|
|
|
|
|
TargetType* getTargetTyped() { return _target.get(); }
|
2009-09-09 17:52:54 +08:00
|
|
|
const TargetType* getTargetTyped() const { return _target.get(); }
|
2008-11-22 20:14:19 +08:00
|
|
|
void setTarget(TargetType* target) { _target = target; }
|
|
|
|
|
2010-03-26 01:50:29 +08:00
|
|
|
virtual double getStartTime() const { return _sampler->getStartTime(); }
|
|
|
|
virtual double getEndTime() const { return _sampler->getEndTime(); }
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
osg::ref_ptr<TargetType> _target;
|
|
|
|
osg::ref_ptr<SamplerType> _sampler;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector<osg::ref_ptr<osgAnimation::Channel> > ChannelList;
|
2009-08-06 20:40:06 +08:00
|
|
|
|
|
|
|
typedef TemplateChannel<DoubleStepSampler> DoubleStepChannel;
|
|
|
|
typedef TemplateChannel<FloatStepSampler> FloatStepChannel;
|
|
|
|
typedef TemplateChannel<Vec2StepSampler> Vec2StepChannel;
|
|
|
|
typedef TemplateChannel<Vec3StepSampler> Vec3StepChannel;
|
|
|
|
typedef TemplateChannel<Vec4StepSampler> Vec4StepChannel;
|
|
|
|
typedef TemplateChannel<QuatStepSampler> QuatStepChannel;
|
|
|
|
|
2008-11-22 20:14:19 +08:00
|
|
|
typedef TemplateChannel<DoubleLinearSampler> DoubleLinearChannel;
|
|
|
|
typedef TemplateChannel<FloatLinearSampler> FloatLinearChannel;
|
|
|
|
typedef TemplateChannel<Vec2LinearSampler> Vec2LinearChannel;
|
|
|
|
typedef TemplateChannel<Vec3LinearSampler> Vec3LinearChannel;
|
2016-06-25 14:49:56 +08:00
|
|
|
typedef TemplateChannel<Vec3usLinearSampler> Vec3usLinearChannel; // quantized Vec3LinearChannel
|
2008-11-22 20:14:19 +08:00
|
|
|
typedef TemplateChannel<Vec4LinearSampler> Vec4LinearChannel;
|
|
|
|
typedef TemplateChannel<QuatSphericalLinearSampler> QuatSphericalLinearChannel;
|
2016-06-25 14:49:56 +08:00
|
|
|
typedef TemplateChannel<Vec3usSphericalLinearSampler> Vec3usSphericalLinearChannel; // quantized QuatSphericalLinearChannel
|
2010-01-27 20:24:55 +08:00
|
|
|
typedef TemplateChannel<MatrixLinearSampler> MatrixLinearChannel;
|
2008-11-22 20:14:19 +08:00
|
|
|
|
|
|
|
typedef TemplateChannel<FloatCubicBezierSampler> FloatCubicBezierChannel;
|
|
|
|
typedef TemplateChannel<DoubleCubicBezierSampler> DoubleCubicBezierChannel;
|
|
|
|
typedef TemplateChannel<Vec2CubicBezierSampler> Vec2CubicBezierChannel;
|
|
|
|
typedef TemplateChannel<Vec3CubicBezierSampler> Vec3CubicBezierChannel;
|
|
|
|
typedef TemplateChannel<Vec4CubicBezierSampler> Vec4CubicBezierChannel;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|