载入中...
搜索中...
未找到
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,
21};
22
23class AnimClip;
24class AnimSkeleton;
25
31public:
33 explicit AnimPlayer(AnimSkeleton* skeleton);
35 ~AnimPlayer() override = default;
36
37 AnimPlayer(const AnimPlayer&) = delete;
38 AnimPlayer& operator=(const AnimPlayer&) = delete;
39
44 AnimSkeleton* getSkeleton() const override { return skeleton_; }
45
47 void play(AnimClip* clip);
49 void crossFade(AnimClip* clip, float blendSeconds);
51 void setBlendCurve(AnimBlendCurve curve) noexcept { blendCurve_ = curve; }
52
54 void stop();
56 void pause();
58 void resume();
59
61 void setSpeed(float speed);
63 float getSpeed() const { return speed_; }
65 void setTime(float seconds);
67 float getTime() const { return time_; }
69 void setLoop(bool loop) {
70 loopOverride_ = loop;
71 hasLoopOverride_ = true;
72 }
74 bool getLoop() const;
75
77 bool isPlaying() const { return playing_ && clip_ != nullptr; }
79 bool isPaused() const { return paused_; }
80
86 AnimClip* getClip() const { return clip_; }
91 AnimPose* getPose() override;
93 void setRootMotionBone(int boneIndex);
95 int getRootMotionBone() const { return rootMotionBone_; }
96
102 [[nodiscard]] eve::Result<void> setRootMotionPolicy(const RootMotionPolicy& policy);
104 [[nodiscard]] RootMotionPolicy getRootMotionPolicy() const { return rootMotionPolicy_; }
109 [[nodiscard]] eve::Result<void> setRootMotionCharacterYaw(float yawRadians);
110
112 float getRootMotionX() const { return rootMotion_.px; }
114 float getRootMotionY() const { return rootMotion_.py; }
116 float getRootMotionZ() const { return rootMotion_.pz; }
118 float getRootMotionRotationX() const { return rootMotion_.qx; }
120 float getRootMotionRotationY() const { return rootMotion_.qy; }
122 float getRootMotionRotationZ() const { return rootMotion_.qz; }
124 float getRootMotionRotationW() const { return rootMotion_.qw; }
126 std::string consumeEvent();
128 void setUpdateRate(float hz);
130 float getUpdateRate() const { return updateRate_; }
131
133 int getEventCount() const override { return static_cast<int>(events_.size()); }
135 std::string getEventName(int index) const override;
137 std::string getEventPayload(int index) const override;
139 void clearEvents() { events_.clear(); }
140
142 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep& step) override;
143
145 [[nodiscard]] eve::SimulationTick currentTick() const noexcept override { return lastTick_; }
147 [[nodiscard]] bool hasCurrentTick() const noexcept override { return hasLastTick_; }
148
150 void update(float dt);
151
152private:
153 bool effectiveLoop() const;
154 void updateUnchecked(float dt);
155
156 AnimSkeleton* skeleton_ = nullptr;
157 AnimClip* clip_ = nullptr;
158 AnimClip* prevClip_ = nullptr;
159 AnimPose pose_;
160 AnimPose prevPose_;
161 AnimPose sampledPose_;
162 AnimPose rootPreviousPose_;
163 AnimPose rootStartPose_;
164 AnimPose rootEndPose_;
165 float time_ = 0.f;
166 float prevTime_ = 0.f;
167 float speed_ = 1.f;
168 float blendDuration_ = 0.f;
169 float blendElapsed_ = 0.f;
170 bool blending_ = false;
171 AnimBlendCurve blendCurve_ = AnimBlendCurve::Linear;
172 bool playing_ = false;
173 bool paused_ = false;
174 bool hasLoopOverride_ = false;
175 bool loopOverride_ = true;
176 int rootMotionBone_ = 0;
177 RootMotionPolicy rootMotionPolicy_{};
178 TransformTRS rootMotion_;
179 std::vector<std::string> pendingEvents_;
180 float updateRate_ = 0.f;
181 float updateAccumulator_ = 0.f;
182 struct DispatchedEvent {
183 std::string name;
184 std::string payload;
185 };
186 std::vector<DispatchedEvent> events_;
188 bool hasLastTick_ = false;
189
190 void dispatchEvents(float oldTime, float newTime);
191};
192
193} // namespace eve::animation
Value::Object payload
#define EVENGINE_API_WORLD
Definition Export.h:109
glm::vec4 clip
std::string name
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:314
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
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:30
AnimSkeleton * getSkeleton() const override
Borrowed pointer accessor. @ownership Borrowed @lifetime Valid while the owning animation object rema...
Definition AnimPlayer.h:44
float getRootMotionRotationW() const
Returns the root motion rotation w.
Definition AnimPlayer.h:124
float getRootMotionRotationY() const
Returns the root motion rotation y.
Definition AnimPlayer.h:120
eve::SimulationTick currentTick() const noexcept override
Last scheduler tick consumed by the checked playback API.
Definition AnimPlayer.h:145
float getTime() const
Returns the time.
Definition AnimPlayer.h:67
float getSpeed() const
Returns the speed.
Definition AnimPlayer.h:63
AnimPlayer(const AnimPlayer &)=delete
void clearEvents()
Clear currently dispatched events. update() also clears them at frame start.
Definition AnimPlayer.h:139
float getRootMotionY() const
Returns the root motion y.
Definition AnimPlayer.h:114
bool hasCurrentTick() const noexcept override
Whether the player has consumed at least one checked step.
Definition AnimPlayer.h:147
void setLoop(bool loop)
Sets the loop.
Definition AnimPlayer.h:69
float getUpdateRate() const
Returns the update rate.
Definition AnimPlayer.h:130
void setBlendCurve(AnimBlendCurve curve) noexcept
Select the curve used by subsequent and active cross-fades.
Definition AnimPlayer.h:51
bool isPaused() const
True when paused.
Definition AnimPlayer.h:79
int getRootMotionBone() const
Returns the root motion bone.
Definition AnimPlayer.h:95
int getEventCount() const override
Number of events crossed by the most recent play/update call.
Definition AnimPlayer.h:133
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:112
float getRootMotionRotationX() const
Returns the root motion rotation x.
Definition AnimPlayer.h:118
float getRootMotionRotationZ() const
Returns the root motion rotation z.
Definition AnimPlayer.h:122
bool isPlaying() const
True when playing.
Definition AnimPlayer.h:77
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:86
float getRootMotionZ() const
Returns the root motion z.
Definition AnimPlayer.h:116
RootMotionPolicy getRootMotionPolicy() const
Copy of the active root-motion policy.
Definition AnimPlayer.h:104
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...