198 {
199 auto allocator =
GetContext()->GetResourceAllocator();
200
202 if (!mapping) {
203
204
205
206
207 return;
208 }
209 ASSERT_NE(mapping, nullptr);
210
211 std::shared_ptr<Node> gltf_scene =
212 Node::MakeFromFlatbuffer(*mapping, *allocator);
213 ASSERT_NE(gltf_scene, nullptr);
214
215 auto walk_anim = gltf_scene->FindAnimationByName("Walk");
216 ASSERT_NE(walk_anim, nullptr);
217
218 AnimationClip* walk_clip = gltf_scene->AddAnimation(walk_anim);
219 ASSERT_NE(walk_clip, nullptr);
222
223 auto run_anim = gltf_scene->FindAnimationByName("Run");
224 ASSERT_NE(walk_anim, nullptr);
225
226 AnimationClip* run_clip = gltf_scene->AddAnimation(run_anim);
227 ASSERT_NE(run_clip, nullptr);
230
231 auto scene_context = std::make_shared<SceneContext>(
GetContext());
232 auto scene =
Scene(scene_context);
233 scene.GetRoot().AddChild(std::move(gltf_scene));
234
236 ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
237 {
238 static Scalar playback_time_scale = 1;
241 static bool loop = true;
242
243 ImGui::SliderFloat("Playback time scale", &playback_time_scale, -5, 5);
244 ImGui::SliderFloat("Walk weight", &walk, 0, 1);
245 ImGui::SliderFloat(
"Run weight", &
run, 0, 1);
246 ImGui::Checkbox("Loop", &loop);
247 if (ImGui::Button("Play")) {
250 }
251 if (ImGui::Button("Pause")) {
254 }
255 if (ImGui::Button("Stop")) {
258 }
259
263
267 }
268
269 ImGui::End();
270 Node& node = *scene.GetRoot().GetChildren()[0];
271 node.SetLocalTransform(node.GetLocalTransform() *
272 Matrix::MakeRotation(Radians(0.02), {0, 1, 0, 0}));
273
274 static ImVec2 mouse_pos_prev = ImGui::GetMousePos();
275 ImVec2 mouse_pos = ImGui::GetMousePos();
277 Vector2(mouse_pos.x - mouse_pos_prev.x, mouse_pos.y - mouse_pos_prev.y);
278
279 static Vector3 position(0, 1, -5);
280 static Vector3 cam_position = position;
281 auto strafe =
282 Vector3(ImGui::IsKeyDown(ImGuiKey_D) - ImGui::IsKeyDown(ImGuiKey_A),
283 ImGui::IsKeyDown(ImGuiKey_E) - ImGui::IsKeyDown(ImGuiKey_Q),
284 ImGui::IsKeyDown(ImGuiKey_W) - ImGui::IsKeyDown(ImGuiKey_S));
285 position += strafe * 0.5;
286 cam_position = cam_position.Lerp(position, 0.02);
287
288
289 auto camera = Camera::MakePerspective(
290 Degrees(60),
291 cam_position)
292 .LookAt(
293 cam_position + Vector3(0, 0, 1),
294 {0, 1, 0});
295
296 scene.Render(render_target, camera);
297 return true;
298 };
299
301}
void SetPlaybackTimeScale(Scalar playback_speed)
Sets the animation playback speed. Negative values make the clip play in reverse.
void SetWeight(Scalar weight)
void SetLoop(bool looping)
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.