载入中...
搜索中...
未找到
AnimPlayer.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
8#include "common/Result.h"
9#include "common/Time.h"
10
11#include <cstdint>
12#include <string>
13#include <vector>
14
15namespace eve::animation {
16
18enum class AnimBlendCurve : std::uint8_t {
19 Linear,
20 EaseIn,
21 EaseOut,
24};
25
26class AnimClip;
27class AnimSkeleton;
28
34public:
36 explicit AnimPlayer(AnimSkeleton* skeleton);
38 ~AnimPlayer() override = default;
39
40 AnimPlayer(const AnimPlayer&) = delete;
41 AnimPlayer& operator=(const AnimPlayer&) = delete;
42
47 AnimSkeleton* getSkeleton() const override { return skeleton_; }
48
50 void play(AnimClip* clip);
52 void crossFade(AnimClip* clip, float blendSeconds);
54 void setBlendCurve(AnimBlendCurve curve) noexcept { blendCurve_ = curve; }
55
57 void stop();
59 void pause();
61 void resume();
62
64 void setSpeed(float speed);
66 float getSpeed() const noexcept { return speed_; }
68 void setTime(float seconds);
70 float getTime() const noexcept { return time_; }
72 void setLoop(bool loop) noexcept {
73 loopOverride_ = loop;
74 hasLoopOverride_ = true;
75 }
77 bool getLoop() const;
78
80 bool isPlaying() const noexcept { return playing_ && clip_ != nullptr; }
82 bool isPaused() const noexcept { return paused_; }
83
89 AnimClip* getClip() const { return clip_; }
94 AnimPose* getPose() override;
96 void setRootMotionBone(int boneIndex);
98 int getRootMotionBone() const { return rootMotionBone_; }
99
105 [[nodiscard]] eve::Result<void> setRootMotionPolicy(const RootMotionPolicy& policy);
107 [[nodiscard]] RootMotionPolicy getRootMotionPolicy() const { return rootMotionPolicy_; }
112 [[nodiscard]] eve::Result<void> setRootMotionCharacterYaw(float yawRadians);
113
115 float getRootMotionX() const { return rootMotion_.px; }
117 float getRootMotionY() const { return rootMotion_.py; }
119 float getRootMotionZ() const { return rootMotion_.pz; }
121 float getRootMotionRotationX() const { return rootMotion_.qx; }
123 float getRootMotionRotationY() const { return rootMotion_.qy; }
125 float getRootMotionRotationZ() const { return rootMotion_.qz; }
127 float getRootMotionRotationW() const { return rootMotion_.qw; }
129 std::string consumeEvent();
131 void setUpdateRate(float hz);
133 float getUpdateRate() const { return updateRate_; }
134
136 int getEventCount() const override { return static_cast<int>(events_.size()); }
138 std::string getEventName(int index) const override;
140 std::string getEventPayload(int index) const override;
142 void clearEvents() { events_.clear(); }
143
145 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep& step) override;
146
148 [[nodiscard]] eve::SimulationTick currentTick() const noexcept override { return lastTick_; }
150 [[nodiscard]] bool hasCurrentTick() const noexcept override { return hasLastTick_; }
151
153 void update(float dt);
154
155private:
156 bool effectiveLoop() const;
157 void updateUnchecked(float dt);
158
159 AnimSkeleton* skeleton_ = nullptr;
160 AnimClip* clip_ = nullptr;
161 AnimClip* prevClip_ = nullptr;
162 AnimPose pose_;
163 AnimPose prevPose_;
164 AnimPose sampledPose_;
165 AnimPose rootPreviousPose_;
166 AnimPose rootStartPose_;
167 AnimPose rootEndPose_;
168 float time_ = 0.f;
169 float prevTime_ = 0.f;
170 float speed_ = 1.f;
171 float blendDuration_ = 0.f;
172 float blendElapsed_ = 0.f;
173 bool blending_ = false;
174 AnimBlendCurve blendCurve_ = AnimBlendCurve::Linear;
175 bool playing_ = false;
176 bool paused_ = false;
177 bool hasLoopOverride_ = false;
178 bool loopOverride_ = true;
179 int rootMotionBone_ = 0;
180 RootMotionPolicy rootMotionPolicy_{};
181 TransformTRS rootMotion_;
182 std::vector<std::string> pendingEvents_;
183 float updateRate_ = 0.f;
184 float updateAccumulator_ = 0.f;
185 struct DispatchedEvent {
186 std::string name;
187 std::string payload;
188 };
189 std::vector<DispatchedEvent> events_;
191 bool hasLastTick_ = false;
192
193 void dispatchEvents(float oldTime, float newTime);
194};
195
196} // namespace eve::animation
Value::Object payload
std::string name
Definition ECS.cpp:154
#define EVENGINE_API_WORLD
Definition Export.h:109
glm::vec4 clip
double dt
Move-only, checked operation results for the common layer.
Heightmap curve
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:451
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Keyframed skeletal animation clip (local TRS tracks per bone). Script type: AnimClip.
Definition AnimClip.h:145
Single-clip (or cross-fading) 3D animation player. Script type: AnimPlayer.
Definition AnimPlayer.h:33
AnimSkeleton * getSkeleton() const override
Borrowed pointer accessor. @ownership Borrowed @lifetime Valid while the owning animation object rema...
Definition AnimPlayer.h:47
float getRootMotionRotationW() const
Returns the root motion rotation w.
Definition AnimPlayer.h:127
float getRootMotionRotationY() const
Returns the root motion rotation y.
Definition AnimPlayer.h:123
eve::SimulationTick currentTick() const noexcept override
Last scheduler tick consumed by the checked playback API.
Definition AnimPlayer.h:148
AnimPlayer(const AnimPlayer &)=delete
void clearEvents()
Clear currently dispatched events. update() also clears them at frame start.
Definition AnimPlayer.h:142
float getRootMotionY() const
Returns the root motion y.
Definition AnimPlayer.h:117
float getSpeed() const noexcept
Returns the speed.
Definition AnimPlayer.h:66
bool hasCurrentTick() const noexcept override
Whether the player has consumed at least one checked step.
Definition AnimPlayer.h:150
float getUpdateRate() const
Returns the update rate.
Definition AnimPlayer.h:133
void setBlendCurve(AnimBlendCurve curve) noexcept
Select the curve used by subsequent and active cross-fades.
Definition AnimPlayer.h:54
int getRootMotionBone() const
Returns the root motion bone.
Definition AnimPlayer.h:98
float getTime() const noexcept
Returns the time.
Definition AnimPlayer.h:70
void setLoop(bool loop) noexcept
Sets the loop.
Definition AnimPlayer.h:72
int getEventCount() const override
Number of events crossed by the most recent play/update call.
Definition AnimPlayer.h:136
AnimPlayer & operator=(const AnimPlayer &)=delete
~AnimPlayer() override=default
Anim player.
float getRootMotionX() const
Controller-facing translation X after policy filtering (BoneLocal or CharacterFacing).
Definition AnimPlayer.h:115
float getRootMotionRotationX() const
Returns the root motion rotation x.
Definition AnimPlayer.h:121
bool isPlaying() const noexcept
True when playing.
Definition AnimPlayer.h:80
bool isPaused() const noexcept
True when paused.
Definition AnimPlayer.h:82
float getRootMotionRotationZ() const
Returns the root motion rotation z.
Definition AnimPlayer.h:125
AnimClip * getClip() const
Borrow the selected clip, or null if none is selected. The caller owns the clip and must keep it aliv...
Definition AnimPlayer.h:89
float getRootMotionZ() const
Returns the root motion z.
Definition AnimPlayer.h:119
RootMotionPolicy getRootMotionPolicy() const
Copy of the active root-motion policy.
Definition AnimPlayer.h:107
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
Borrowed pose provider consumed by AnimLayerMixer.
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
AnimBlendCurve
Deterministic built-in curve used by cross-fade pose interpolation.
Definition AnimPlayer.h:18
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Policy applied after raw root-bone delta extraction. @ownership Value type; owned by AnimPlayer or th...