Toast Engine
Loading...
Searching...
No Matches
animation_player.hpp
Go to the documentation of this file.
1
7
8#pragma once
9#include "node_3d.hpp"
10
11#include <string>
14#include <unordered_map>
15
16namespace toast {
17
29class [[ToastNode, Icon("Film")]] TOAST_API AnimationPlayer : public Node3D {
30public:
31 AnimationPlayer() = default;
32
35 [[Reflect]]
36 auto play(std::string_view clip_name) -> bool;
37
38 [[Reflect]]
39 void stop();
40
41 [[Reflect]]
42 void pause(bool value) {
43 m_paused = value;
44 }
45
46 [[nodiscard]]
47 auto isPlaying() const noexcept -> bool {
48 return m_playing;
49 }
50
52 [[nodiscard]]
53 auto time() const noexcept -> float {
54 return m_time;
55 }
56
57 void time(float seconds) noexcept { m_time = seconds; }
58
64 [[nodiscard]]
65 auto jointWorldTransforms(const assets::Skin& skin) -> std::vector<glm::mat4>;
66
73 void tick();
74
75private:
76 void begin();
77
79 auto resolveNode(const std::string& name) -> Node3D*;
80
81 [[Reflect, Name("Animation")]]
83
84 [[Reflect, Name("Clip")]]
85 std::string m_clip_name;
86
87 [[Reflect, Name("Play On Begin")]]
88 bool m_play_on_begin = true;
89
90 [[Reflect, Name("Loop")]]
91 bool m_loop = true;
92
93 [[Reflect, Unit("x"), Range(0.0, 10.0)]]
94 float m_speed = 1.0f;
95
96 bool m_playing = false;
97 bool m_paused = false;
98 float m_time = 0.0f;
99
100 const assets::AnimationClip* m_active_clip = nullptr;
101
102 // Name lookups walk the subtree, which is far too expensive to redo per track per frame. Cleared
103 // whenever the clip changes, since a different clip may target an entirely different set of nodes
104 std::unordered_map<std::string, Box<Node3D>> m_node_cache;
105};
106
107}
Keyframe animation asset (.tanim), imported from glTF.
Type-safe smart pointer for assets.
Definition core_types.hpp:149
auto play(std::string_view clip_name) -> bool
Starts the named clip from the beginning.
Definition animation_player.cpp:11
auto time() const noexcept -> float
Definition animation_player.hpp:53
Definition node_3d.hpp:25
Definition reflect.hpp:244
Node with 3D spatial transforms.
A named set of tracks that play together.
Definition animation.hpp:97
A skeleton: the joint nodes a skinned mesh binds to.
Definition animation.hpp:127
Concrete asset types for the Toast engine.