osgAnimation.Sampler是OpenSceneGraph中的动画抽样器,用于处理和管理动画数据。它是osgAnimation::AnimationManagerBase类的基类,可以用来创建和管理各种类型的动画数据。
osg::Referenced => osg::Object => osgAnimation::Sampler
创建osgAnimation.Sampler的方法如下:
osg::ref_ptr<osgAnimation::Sampler> sampler = new osgAnimation::Sampler();
通过setTime()函数设置抽样器的时间。
void setTime(double time);
time:时间,类型为double。通过getTime()函数获取抽样器当前的时间。
double getTime() const;
通过insert()函数添加控制点。
void insert(double time, const Keyframe& keyframe);
time:控制点对应的时间,类型为double。keyframe:Keyframe结构体,包含关键帧相关的数据。struct Keyframe
{
Keyframe();
Keyframe(float value);
Keyframe(const osg::Vec2f& value);
Keyframe(const osg::Vec3f& value);
Keyframe(const osg::Vec4f& value);
Keyframe(const osg::Quat& rotation);
float getFloatValue() const;
void setFloatValue(float v);
osg::Vec2f getVec2Value() const;
void setVec2Value(const osg::Vec2f& v);
osg::Vec3f getVec3Value() const;
void setVec3Value(const osg::Vec3f& v);
osg::Vec4f getVec4Value() const;
void setVec4Value(const osg::Vec4f& v);
osg::Quat getQuatValue() const;
void setQuatValue(const osg::Quat& quat);
osg::ref_ptr<osg::Object> _value;
};
通过remove()函数移除控制点。
void remove(double time);
time:要移除的控制点的时间,类型为double。通过get()函数获取对应时间的关键帧。
const Keyframe& get(double time) const;
time:关键帧对应的时间,类型为double。通过getKeyframe()函数获取一组控制点。
bool getKeyframe(double time, Keyframe& keyframe) const;
time:控制点对应的时间,类型为double。keyframe:要获取的控制点。通过getFirstTime()函数获取第一个控制点的时间。
double getFirstTime() const;
通过getLastTime()函数获取最后一个控制点的时间。
double getLastTime() const;
通过size()函数获取控制点的数量。
unsigned int size() const;
通过clear()函数清空所有控制点。
void clear();
通过getKeyframeCount()函数获取关键帧的数量。
unsigned int getKeyframeCount() const;
osgAnimation.Sampler提供了管理动画数据的基本操作,可以通过它创建并管理各种类型的动画数据。本文档参考了官方文档和源代码,欢迎指出错误和不足之处。