delete *i;
curves.clear();
- typedef ValueCurve<3>::Knot Knot;
- vector<Knot> positions;
- vector<Knot> eulers;
- vector<Knot> scales;
- for(vector<TimedKeyFrame>::const_iterator i=keyframes.begin(); i!=keyframes.end(); ++i)
- {
- positions.push_back(Knot(i->time/Time::sec, i->keyframe->get_transform().get_position()));
- const Transform::AngleVector3 &euler = i->keyframe->get_transform().get_euler();
- eulers.push_back(Knot(i->time/Time::sec, Vector3(euler.x.radians(), euler.y.radians(), euler.z.radians())));
- scales.push_back(Knot(i->time/Time::sec, i->keyframe->get_transform().get_scale()));
- }
-
curves.reserve(3+uniforms.size());
- curves.push_back(new ValueCurve<3>(POSITION, positions));
- curves.push_back(new ValueCurve<3>(EULER, eulers));
- curves.push_back(new ValueCurve<3>(SCALE, scales));
+ create_curve<3>(POSITION, &extract_position);
+ create_curve<3>(EULER, &extract_euler);
+ create_curve<3>(SCALE, &extract_scale);
for(vector<UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
{
if(i->size==1)
- create_uniform_curve<1>(i->name);
+ create_curve<1>(UNIFORM, ExtractUniform<1>(i->name));
else if(i->size==2)
- create_uniform_curve<2>(i->name);
+ create_curve<2>(UNIFORM, ExtractUniform<2>(i->name));
else if(i->size==3)
- create_uniform_curve<3>(i->name);
+ create_curve<3>(UNIFORM, ExtractUniform<3>(i->name));
else if(i->size==4)
- create_uniform_curve<4>(i->name);
+ create_curve<4>(UNIFORM, ExtractUniform<4>(i->name));
}
}
-template<unsigned N>
-void Animation::create_uniform_curve(const string &name)
+template<unsigned N, typename T>
+void Animation::create_curve(CurveTarget target, const T &extract)
{
typedef typename ValueCurve<N>::Knot Knot;
vector<Knot> knots;
for(vector<TimedKeyFrame>::const_iterator i=keyframes.begin(); i!=keyframes.end(); ++i)
{
- const KeyFrame::UniformMap &kf_uniforms = i->keyframe->get_uniforms();
- const KeyFrame::UniformMap::const_iterator j = kf_uniforms.find(name);
- if(j!=kf_uniforms.end())
- knots.push_back(Knot(i->time/Time::sec, Interpolate::SplineValue<float, N>::make(j->second.values)));
+ typename Interpolate::SplineValue<float, N>::Type value;
+ if(extract(*i->keyframe, value))
+ knots.push_back(Knot(i->time/Time::sec, value));
}
- curves.push_back(new ValueCurve<N>(UNIFORM, knots));
+ curves.push_back(new ValueCurve<N>(target, knots));
+}
+
+bool Animation::extract_position(const KeyFrame &kf, Vector3 &value)
+{
+ value = kf.get_transform().get_position();
+ return true;
+}
+
+bool Animation::extract_euler(const KeyFrame &kf, Vector3 &value)
+{
+ const Transform::AngleVector3 &euler = kf.get_transform().get_euler();
+ value = Vector3(euler.x.radians(), euler.y.radians(), euler.z.radians());
+ return true;
+}
+
+bool Animation::extract_scale(const KeyFrame &kf, Vector3 &value)
+{
+ value = kf.get_transform().get_scale();
+ return true;
}
void Animation::add_event(const Time::TimeDelta &t, const string &n, const Variant &v)
}
+template<unsigned N>
+bool Animation::ExtractUniform<N>::operator()(const KeyFrame &kf, typename Interpolate::SplineValue<float, N>::Type &value) const
+{
+ const KeyFrame::UniformMap &kf_uniforms = kf.get_uniforms();
+ const KeyFrame::UniformMap::const_iterator i = kf_uniforms.find(name);
+ if(i==kf_uniforms.end())
+ return false;
+
+ value = Interpolate::SplineValue<float, N>::make(i->second.values);
+ return true;
+}
+
+
Animation::UniformInfo::UniformInfo(const string &n, unsigned s):
name(n),
size(s)
virtual void apply(float, KeyFrame::AnimatedUniform &) const;
};
+ template<unsigned N>
+ struct ExtractUniform
+ {
+ const std::string &name;
+
+ ExtractUniform(const std::string &n): name(n) { }
+
+ bool operator()(const KeyFrame &, typename Interpolate::SplineValue<float, N>::Type &) const;
+ };
+
struct TimedKeyFrame
{
Time::TimeDelta time;
void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &, float, float);
void prepare_keyframe(TimedKeyFrame &);
void create_curves();
- template<unsigned N>
- void create_uniform_curve(const std::string &);
+ template<unsigned N, typename T>
+ void create_curve(CurveTarget target, const T &);
+ static bool extract_position(const KeyFrame &, Vector3 &);
+ static bool extract_euler(const KeyFrame &, Vector3 &);
+ static bool extract_scale(const KeyFrame &, Vector3 &);
public:
void add_event(const Time::TimeDelta &, const std::string &, const Variant & = Variant());