1 #ifndef MSP_GL_ANIMATION_H_
2 #define MSP_GL_ANIMATION_H_
4 #include <msp/core/refptr.h>
5 #include <msp/datafile/objectloader.h>
6 #include <msp/interpolate/spline.h>
7 #include <msp/time/timedelta.h>
13 class AnimationEventObserver;
19 An Animation is a sequence of KeyFrames combined with timing information. The
20 state at any point in the animation can be interpolated from the keyframes.
25 class Loader: public DataFile::CollectionObjectLoader<Animation>
28 Time::TimeDelta current_time;
35 Loader(Animation &, Collection &);
38 virtual void finish();
40 void check_slopes_and_control(bool, bool);
41 void add_kf(const KeyFrame *, bool, bool);
42 void load_kf(const std::string &, bool);
43 void load_kf_inline(bool);
45 void control_keyframe(const std::string &);
46 void control_keyframe_inline();
47 void event(const std::string &);
48 void event1i(const std::string &, int);
49 void event1f(const std::string &, float);
50 void event2f(const std::string &, float, float);
51 void event3f(const std::string &, float, float, float);
52 void event4f(const std::string &, float, float, float, float);
54 void keyframe(const std::string &);
55 void keyframe_inline();
56 void slopes(float, float);
77 virtual void apply(float, Matrix &) const = 0;
78 virtual void apply(float, KeyFrame::AnimatedUniform &) const = 0;
82 class ValueCurve: public Curve
85 typedef typename Interpolate::SplineKnot<float, N> Knot;
88 Interpolate::Spline<float, 3, N> spline;
91 ValueCurve(CurveTarget, const std::vector<Knot> &);
93 virtual void apply(float, Matrix &) const;
94 virtual void apply(float, KeyFrame::AnimatedUniform &) const;
100 const std::string &name;
102 ExtractUniform(const std::string &n): name(n) { }
104 bool operator()(const KeyFrame &, typename Interpolate::SplineValue<float, N>::Type &) const;
109 Time::TimeDelta time;
110 RefPtr<const KeyFrame> keyframe;
116 Time::TimeDelta time;
126 UniformInfo(const std::string &, unsigned);
133 const Animation *animation;
134 Time::TimeDelta elapsed;
135 std::vector<Event>::const_iterator event_iter;
139 Iterator(const Animation &);
141 Iterator &operator+=(const Time::TimeDelta &);
142 void dispatch_events(AnimationEventObserver &);
144 bool is_end() const { return end; }
145 Matrix get_matrix() const;
146 KeyFrame::AnimatedUniform get_uniform(unsigned) const;
147 Matrix get_pose_matrix(unsigned) const;
151 const Armature *armature;
152 std::vector<TimedKeyFrame> keyframes;
153 std::vector<Event> events;
155 std::vector<UniformInfo> uniforms;
156 std::vector<Curve *> curves;
162 void set_armature(const Armature &);
163 const Armature *get_armature() const { return armature; }
165 unsigned get_n_uniforms() const { return uniforms.size(); }
166 unsigned get_slot_for_uniform(const std::string &) const;
167 const std::string &get_uniform_name(unsigned) const;
169 void add_keyframe(const Time::TimeDelta &, const KeyFrame &);
170 DEPRECATED void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float);
171 DEPRECATED void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float, float);
172 void add_control_keyframe(const KeyFrame &);
174 void add_keyframe(const Time::TimeDelta &, const KeyFrame *, float, float, bool);
175 void add_keyframe(const Time::TimeDelta &, const KeyFrame *, bool, bool);
176 void prepare_keyframe(TimedKeyFrame &);
177 void create_curves();
178 template<unsigned N, typename T>
179 void create_curve(CurveTarget target, const T &);
180 static bool extract_position(const KeyFrame &, Vector3 &);
181 static bool extract_euler(const KeyFrame &, Vector3 &);
182 static bool extract_scale(const KeyFrame &, Vector3 &);
184 void add_event(const Time::TimeDelta &, const std::string &, const Variant & = Variant());
186 const Msp::Time::TimeDelta &get_duration() const;
188 void set_looping(bool);