1 #include <msp/datafile/collection.h>
2 #include <msp/fs/utils.h>
11 // Avoid synthesizing RefPtr c'tor and d'tor in files including keyframe.h
18 void KeyFrame::set_transform(const Transform &t)
23 void KeyFrame::set_matrix(const Matrix &m)
25 transform = Transform::from_matrix(m);
28 void KeyFrame::set_uniform(const string &n, const AnimatedUniform &u)
31 uniforms.insert(UniformMap::value_type(n, u));
34 void KeyFrame::set_pose(const Pose &p)
40 KeyFrame::AnimatedUniform::AnimatedUniform(unsigned s, float v0, float v1, float v2, float v3):
50 KeyFrame::Loader::Loader(KeyFrame &k, Collection *c):
51 DataFile::CollectionObjectLoader<KeyFrame>(k, c)
53 add("pose", &Loader::pose);
54 add("pose", &Loader::pose_inline);
55 add("transform", &Loader::transform);
56 add("uniforms", &Loader::uniforms);
58 // Deprecated; use the transform statement instead
59 add("position", &Loader::position);
60 add("rotation", &Loader::rotation);
61 add("scaling", &Loader::scaling_uniform);
62 add("scaling", &Loader::scaling);
65 void KeyFrame::Loader::set_inline_base_name(const string &n)
70 void KeyFrame::Loader::pose(const string &n)
72 obj.pose = &get_collection().get<Pose>(n);
75 void KeyFrame::Loader::pose_inline()
77 RefPtr<Pose> p = new Pose;
78 load_sub(*p, get_collection());
79 get_collection().add((inline_base_name.empty() ? FS::basename(get_source()) : inline_base_name)+".pose", p.get());
80 obj.pose = p.release();
83 void KeyFrame::Loader::position(float x, float y, float z)
85 obj.transform.set_position(Vector3(x, y, z));
88 void KeyFrame::Loader::rotation(float a, float x, float y, float z)
90 obj.transform.set_rotation(Transform::Angle::from_degrees(a), Vector3(x, y, z));
93 void KeyFrame::Loader::scaling_uniform(float s)
95 obj.transform.set_scale(s);
98 void KeyFrame::Loader::scaling(float x, float y, float z)
100 obj.transform.set_scale(Vector3(x, y, z));
103 void KeyFrame::Loader::transform()
105 load_sub(obj.transform);
108 void KeyFrame::Loader::uniforms()
110 UniformsLoader ldr(obj);
115 KeyFrame::UniformsLoader::UniformsLoader(KeyFrame &k):
116 DataFile::ObjectLoader<KeyFrame>(k)
118 add("uniform", &UniformsLoader::uniform1f);
119 add("uniform", &UniformsLoader::uniform2f);
120 add("uniform", &UniformsLoader::uniform3f);
121 add("uniform", &UniformsLoader::uniform4f);
124 add("uniform1f", &UniformsLoader::uniform1f);
125 add("uniform2f", &UniformsLoader::uniform2f);
126 add("uniform3f", &UniformsLoader::uniform3f);
127 add("uniform4f", &UniformsLoader::uniform4f);
130 void KeyFrame::UniformsLoader::uniform1f(const string &n, float v)
132 obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(1, v)));
135 void KeyFrame::UniformsLoader::uniform2f(const string &n, float v0, float v1)
137 obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(2, v0, v1)));
140 void KeyFrame::UniformsLoader::uniform3f(const string &n, float v0, float v1, float v2)
142 obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(3, v0, v1, v2)));
145 void KeyFrame::UniformsLoader::uniform4f(const string &n, float v0, float v1, float v2, float v3)
147 obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(4, v0, v1, v2, v3)));