Submitted with fixes by Julian Valentin

This commit is contained in:
Cedric Pinson
2016-06-25 07:49:56 +01:00
committed by Robert Osfield
parent 295da33cdf
commit 0ecb52ff82
26 changed files with 298 additions and 189 deletions

View File

@@ -47,6 +47,9 @@ namespace osgAnimation
// addChannel insert the channel and call the computeDuration function
void addChannel (Channel* pChannel);
// removeChannel remove the channel from channels list and call the computeDuration function
void removeChannel (Channel* pChannel);
/** Those accessors let you add and remove channels
* if you modify something that can change the duration
* you are supposed to call computeDuration or setDuration
@@ -61,16 +64,13 @@ namespace osgAnimation
*/
void setDuration(double duration);
/** Compute duration from channel and keyframes
* if the duration is not specified you should
* call this method before using it
*/
void computeDuration();
double getDuration() const;
void setWeight (float weight);
float getWeight() const;
@@ -85,10 +85,10 @@ namespace osgAnimation
protected:
double computeDurationFromChannels() const;
~Animation() {}
double computeDurationFromChannels() const;
double _duration;
double _originalDuration;
float _weight;

View File

@@ -40,6 +40,7 @@ namespace osgAnimation
virtual void update(double t) = 0;
virtual bool needToLink() const;
const AnimationList& getAnimationList() const { return _animations;}
AnimationList& getAnimationList() { return _animations;}
/** Callback method called by the NodeVisitor when visiting a node.*/
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);

View File

@@ -25,10 +25,11 @@
#include <osg/Referenced>
#include <string>
namespace osgAnimation
{
class OSGANIMATION_EXPORT Channel : public osg::Referenced
class OSGANIMATION_EXPORT Channel : public osg::Object
{
public:
@@ -37,6 +38,10 @@ namespace osgAnimation
virtual ~Channel();
virtual Channel* clone() const = 0;
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"; }
virtual void update(double time, float weight, int priority) = 0;
virtual void reset() = 0;
virtual Target* getTarget() = 0;
@@ -74,6 +79,9 @@ namespace osgAnimation
typedef typename SamplerType::UsingType UsingType;
typedef TemplateTarget<UsingType> TargetType;
typedef TemplateKeyframeContainer<typename SamplerType::KeyframeType> KeyframeContainerType;
Object* cloneType() const { return new TemplateChannel(); }
Object* clone(const osg::CopyOp& copyop) const { return new TemplateChannel<SamplerType>(*this); }
Channel* clone() const { return new TemplateChannel<SamplerType>(*this); }
TemplateChannel (const TemplateChannel& channel) :
@@ -170,8 +178,10 @@ namespace osgAnimation
typedef TemplateChannel<FloatLinearSampler> FloatLinearChannel;
typedef TemplateChannel<Vec2LinearSampler> Vec2LinearChannel;
typedef TemplateChannel<Vec3LinearSampler> Vec3LinearChannel;
typedef TemplateChannel<Vec3usLinearSampler> Vec3usLinearChannel; // quantized Vec3LinearChannel
typedef TemplateChannel<Vec4LinearSampler> Vec4LinearChannel;
typedef TemplateChannel<QuatSphericalLinearSampler> QuatSphericalLinearChannel;
typedef TemplateChannel<Vec3usSphericalLinearSampler> Vec3usSphericalLinearChannel; // quantized QuatSphericalLinearChannel
typedef TemplateChannel<MatrixLinearSampler> MatrixLinearChannel;
typedef TemplateChannel<FloatCubicBezierSampler> FloatCubicBezierChannel;

View File

@@ -21,11 +21,11 @@
namespace osgAnimation
{
template <class T>
class TemplateCubicBezier
{
public:
TemplateCubicBezier() : _position(osg::default_value<T>()), _controlPointIn(osg::default_value<T>()), _controlPointOut(osg::default_value<T>()) {}
TemplateCubicBezier(const T& p, const T& i, const T& o) : _position(p), _controlPointIn(i), _controlPointOut(o)
@@ -49,6 +49,9 @@ namespace osgAnimation
void setControlPointIn(const T& v) {_controlPointIn = v;}
void setControlPointOut(const T& v) {_controlPointOut = v;}
bool operator==(const TemplateCubicBezier<T>& other) const
{ return _position == other._position && _controlPointIn == other._controlPointIn && _controlPointOut == other._controlPointOut; }
// steaming operators.
friend std::ostream& operator << (std::ostream& output, const TemplateCubicBezier<T>& tcb)
{

View File

@@ -221,9 +221,11 @@ namespace osgAnimation
typedef TemplateLinearInterpolator<float, float> FloatLinearInterpolator;
typedef TemplateLinearInterpolator<osg::Vec2, osg::Vec2> Vec2LinearInterpolator;
typedef TemplateLinearInterpolator<osg::Vec3, osg::Vec3> Vec3LinearInterpolator;
typedef TemplateLinearInterpolator<osg::Vec3us, osg::Vec3us> Vec3usLinearInterpolator;
typedef TemplateLinearInterpolator<osg::Vec3, Vec3Packed> Vec3PackedLinearInterpolator;
typedef TemplateLinearInterpolator<osg::Vec4, osg::Vec4> Vec4LinearInterpolator;
typedef TemplateSphericalLinearInterpolator<osg::Quat, osg::Quat> QuatSphericalLinearInterpolator;
typedef TemplateSphericalLinearInterpolator<osg::Vec3us, osg::Vec3us> Vec3usSphericalLinearInterpolator;
typedef TemplateLinearInterpolator<osg::Matrixf, osg::Matrixf> MatrixLinearInterpolator;
typedef TemplateCubicBezierInterpolator<float, FloatCubicBezier > FloatCubicBezierInterpolator;

View File

@@ -17,12 +17,14 @@
#include <string>
#include <osg/Referenced>
#include <osg/MixinVector>
#include <osgAnimation/Vec3Packed>
#include <osgAnimation/CubicBezier>
#include <osg/Quat>
#include <osg/Vec4>
#include <osg/Vec3>
#include <osg/Vec2>
#include <osg/Vec3us>
#include <osg/Matrixf>
namespace osgAnimation
@@ -45,6 +47,8 @@ namespace osgAnimation
protected:
T _value;
public:
typedef T value_type;
TemplateKeyframe () {}
~TemplateKeyframe () {}
@@ -71,19 +75,19 @@ namespace osgAnimation
template <class T>
class TemplateKeyframeContainer : public std::vector<TemplateKeyframe<T> >, public KeyframeContainer
class TemplateKeyframeContainer : public osg::MixinVector<TemplateKeyframe<T> >, public KeyframeContainer
{
public:
// const char* getKeyframeType() { return #T ;}
TemplateKeyframeContainer() {}
typedef TemplateKeyframe<T> KeyType;
virtual unsigned int size() const { return (unsigned int)std::vector<TemplateKeyframe<T> >::size(); }
typedef typename osg::MixinVector< TemplateKeyframe<T> > VectorType;
virtual unsigned int size() const { return (unsigned int)osg::MixinVector<TemplateKeyframe<T> >::size(); }
};
template <>
class TemplateKeyframeContainer<Vec3Packed> : public std::vector<TemplateKeyframe<Vec3Packed> >, public KeyframeContainer
class TemplateKeyframeContainer<Vec3Packed> : public osg::MixinVector<TemplateKeyframe<Vec3Packed> >, public KeyframeContainer
{
public:
typedef TemplateKeyframe<Vec3Packed> KeyType;
@@ -109,12 +113,18 @@ namespace osgAnimation
typedef TemplateKeyframe<osg::Vec3> Vec3Keyframe;
typedef TemplateKeyframeContainer<osg::Vec3> Vec3KeyframeContainer;
typedef TemplateKeyframe<osg::Vec3us> Vec3usKeyframe;
typedef TemplateKeyframeContainer<osg::Vec3us> Vec3usKeyframeContainer;
typedef TemplateKeyframe<osg::Vec4> Vec4Keyframe;
typedef TemplateKeyframeContainer<osg::Vec4> Vec4KeyframeContainer;
typedef TemplateKeyframe<osg::Quat> QuatKeyframe;
typedef TemplateKeyframeContainer<osg::Quat> QuatKeyframeContainer;
typedef TemplateKeyframe<osg::Vec3us> Vec3usKeyframe;
typedef TemplateKeyframeContainer<osg::Vec3us> Vec3usKeyframeContainer;
typedef TemplateKeyframe<osg::Matrixf> MatrixKeyframe;
typedef TemplateKeyframeContainer<osg::Matrixf> MatrixKeyframeContainer;

View File

@@ -52,7 +52,7 @@ namespace osgAnimation
public:
RigGeometry();
// RigGeometry(const osg::Geometry& b);
RigGeometry(const RigGeometry& b, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
META_Object(osgAnimation, RigGeometry);
@@ -123,7 +123,7 @@ namespace osgAnimation
};
struct UpdateRigGeometry : public osg::DrawableUpdateCallback
struct UpdateRigGeometry : public osg::Drawable::UpdateCallback
{
UpdateRigGeometry() {}
@@ -131,7 +131,7 @@ namespace osgAnimation
META_Object(osgAnimation, UpdateRigGeometry);
virtual void update(osg::NodeVisitor*, osg::Drawable* drw) {
virtual void update(osg::NodeVisitor* nv, osg::Drawable* drw) {
RigGeometry* geom = dynamic_cast<RigGeometry*>(drw);
if(!geom)
return;
@@ -157,6 +157,12 @@ namespace osgAnimation
if(geom->getNeedToComputeMatrix())
geom->computeMatrixFromRootSkeleton();
if(geom->getSourceGeometry()) {
osg::Drawable::UpdateCallback * up = dynamic_cast<osg::Drawable::UpdateCallback*>(geom->getSourceGeometry()->getUpdateCallback());
if(up)
up->update(nv, geom->getSourceGeometry());
}
geom->update();
}
};

View File

@@ -34,6 +34,7 @@ namespace osgAnimation
typedef osgAnimation::Bone BoneType;
typedef std::vector<osg::ref_ptr<osg::Vec4Array> > BoneWeightAttribList;
typedef std::vector<osg::ref_ptr<BoneType> > BonePalette;
typedef std::map<std::string, int> BoneNamePaletteIndex;
typedef std::vector<osg::Matrix> MatrixPalette;
struct IndexWeightEntry
@@ -63,6 +64,10 @@ namespace osgAnimation
virtual void operator()(RigGeometry&);
void setShader(osg::Shader*);
const BoneNamePaletteIndex& getBoneNameToPalette() {
return _boneNameToPalette;
}
protected:
bool init(RigGeometry&);
@@ -74,6 +79,7 @@ namespace osgAnimation
int _nbVertexes;
VertexIndexWeightList _vertexIndexMatrixWeightList;
BonePalette _bonePalette;
BoneNamePaletteIndex _boneNameToPalette;
BoneWeightAttribList _boneWeightAttribArrays;
osg::ref_ptr<osg::Uniform> _uniformMatrixPalette;
osg::ref_ptr<osg::Shader> _shader;

View File

@@ -166,6 +166,7 @@ namespace osgAnimation
bool _needInit;
std::map<std::string,bool> _invalidInfluence;
};
}

View File

@@ -123,8 +123,10 @@ namespace osgAnimation
typedef TemplateSampler<FloatLinearInterpolator> FloatLinearSampler;
typedef TemplateSampler<Vec2LinearInterpolator> Vec2LinearSampler;
typedef TemplateSampler<Vec3LinearInterpolator> Vec3LinearSampler;
typedef TemplateSampler<Vec3usLinearInterpolator> Vec3usLinearSampler;
typedef TemplateSampler<Vec4LinearInterpolator> Vec4LinearSampler;
typedef TemplateSampler<QuatSphericalLinearInterpolator> QuatSphericalLinearSampler;
typedef TemplateSampler<Vec3usSphericalLinearInterpolator> Vec3usSphericalLinearSampler;
typedef TemplateSampler<MatrixLinearInterpolator> MatrixLinearSampler;
typedef TemplateSampler<FloatCubicBezierInterpolator> FloatCubicBezierSampler;

View File

@@ -32,9 +32,6 @@ namespace osgAnimation
const osg::Matrix& getMatrix() const;
protected:
typedef osg::MixinVector<osg::ref_ptr<StackedTransformElement> > inherited;
osg::Matrix _matrix;
};

View File

@@ -90,7 +90,7 @@ public:
void setSupportBinaryBrackets( bool b ) { _supportBinaryBrackets = b; }
bool getSupportBinaryBrackets() const { return _supportBinaryBrackets; }
void checkStream() const { if (_in->rdstate()&_in->failbit) _failed = true; }
void checkStream() const;
bool isFailed() const { return _failed; }
virtual bool isBinary() const = 0;