载入中...
搜索中...
未找到
MontagePlayer.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
7#include "action/Action.h"
10#include "common/Result.h"
11#include "common/Time.h"
12
13#include <cstddef>
14#include <memory>
15#include <optional>
16#include <string>
17#include <string_view>
18#include <vector>
19
20namespace eve::animation {
21
22class AnimClip;
23class AnimPlayer;
24class AnimPose;
25class AnimSkeleton;
26
29 std::string uri;
30 std::unique_ptr<AnimClip> clip;
31};
32
41public:
43 virtual ~IMontageClipProvider() = default;
45 [[nodiscard]] virtual Result<std::unique_ptr<AnimClip>> load(std::string_view uri,
46 const AnimSkeleton& skeleton) = 0;
47};
48
56 bool translationX = true;
57 bool translationY = true;
58 bool translationZ = true;
59 bool rotation = true;
60};
61
63enum class MontageGapPolicy : std::uint8_t {
68};
69
77public:
79 virtual ~IMontageRootMotionReceiver() = default;
81 virtual void applyMontageRootMotion(const TransformTRS& delta) noexcept = 0;
82};
83
86
91 std::optional<LogicalId> sectionId;
92 std::vector<action::ActionTimelineEvent> events;
93 std::vector<MontageActiveBlock> activeBlocks;
95 double weight = 1.0;
96 bool completed = false;
97};
98
108public:
110 explicit MontagePlayer(AnimSkeleton& skeleton);
113
114 MontagePlayer(const MontagePlayer&) = delete;
116
122 [[nodiscard]] Result<void> prepare(action::ActionTimeline timeline, std::vector<MontageClipAsset>&& clips);
127 [[nodiscard]] Result<void> prepare(action::ActionTimeline timeline, IMontageClipProvider& provider);
132 [[nodiscard]] Result<void> reloadClips(IMontageClipProvider& provider);
138 [[nodiscard]] Result<void> setSettings(action::ActionMontageSettings settings);
144 [[nodiscard]] Result<void> setSectionSplits(std::vector<Duration> splitTimestamps);
146 [[nodiscard]] Result<void> replaceClip(std::string_view uri, std::unique_ptr<AnimClip> clip);
150 [[nodiscard]] Result<void> rebindExecution(action::ActionExecutionId executionId);
156 [[nodiscard]] Result<MontageAdvance> present(const action::ActionAdvance& advance, SimulationTick tick);
164 [[nodiscard]] Result<MontageAdvance> jumpToSection(action::ActionExecutionId executionId, std::size_t sectionIndex,
167 [[nodiscard]] Result<MontageAdvance> evaluateSectionProgress(action::ActionExecutionId executionId,
168 std::size_t sectionIndex, double progress,
171 [[nodiscard]] Result<std::size_t> physicalSectionIndex() const;
173 [[nodiscard]] Result<double> physicalSectionProgress(std::size_t sectionIndex) const;
175 [[nodiscard]] Result<MontageAdvance> interrupt(SimulationTick tick);
177 [[nodiscard]] Result<MontageAdvance> beginBlendOut(Duration duration, SimulationTick tick);
179 [[nodiscard]] Result<MontageAdvance> advanceBlendOut(Duration delta, SimulationTick tick);
181 void stop() noexcept;
182
188 void setRootMotionReceiver(IMontageRootMotionReceiver& receiver) noexcept { receiver_ = &receiver; }
190 void clearRootMotionReceiver() noexcept { receiver_ = nullptr; }
196 void setRootMotionMask(MontageRootMotionMask mask) noexcept;
198 [[nodiscard]] MontageRootMotionMask getRootMotionMask() const noexcept { return rootMotionMask_; }
204 [[nodiscard]] Result<void> setRootMotionPolicy(const RootMotionPolicy& policy);
206 [[nodiscard]] RootMotionPolicy getRootMotionPolicy() const noexcept { return rootMotionPolicy_; }
211 [[nodiscard]] Result<void> setRootMotionCharacterYaw(float yawRadians);
213 void setGapPolicy(MontageGapPolicy policy) noexcept { gapPolicy_ = policy; }
215 [[nodiscard]] AnimPose& pose();
217 [[nodiscard]] Duration time() const noexcept { return time_; }
219 [[nodiscard]] bool isPlaying() const noexcept { return playing_; }
221 [[nodiscard]] bool isBlendingOut() const noexcept { return blendingOut_; }
223 [[nodiscard]] bool isFinished() const noexcept {
224 return timeline_ && !executionId_.isZero() && !playing_ && !blendingOut_ && weight_ > 0.0;
225 }
227 [[nodiscard]] double weight() const noexcept { return weight_; }
229 [[nodiscard]] std::size_t animationLayer() const noexcept {
230 return timeline_ ? timeline_->montage.animationLayer : 0U;
231 }
233 [[nodiscard]] bool footIkEnabled() const noexcept { return timeline_ && timeline_->montage.footIk; }
234
235private:
237 [[nodiscard]] AnimClip* clipFor(std::string_view uri) const noexcept;
239 [[nodiscard]] const action::ActionAnimationSection* sectionAt(Duration time) const noexcept;
240 void activate(const action::ActionAnimationSection& section, Duration localTime);
241 void accumulateRootMotion(TransformTRS& total) const;
243 void applyTimelineRootMotionChannels() noexcept;
245 void pushRootMotionPolicyToPlayer() noexcept;
246 [[nodiscard]] std::vector<action::ActionTimelineEvent> realignStateEvents(Duration target) const;
247 [[nodiscard]] Result<std::vector<MontageActiveBlock>> activeBlocksAt(Duration target) const;
248
249 AnimSkeleton& skeleton_;
250 std::unique_ptr<AnimPlayer> player_;
251 std::optional<action::ActionTimeline> timeline_;
252 std::vector<MontageClipAsset> clips_;
253 const action::ActionAnimationSection* activeSection_ = nullptr;
254 IMontageRootMotionReceiver* receiver_ = nullptr;
255 RootMotionPolicy rootMotionPolicy_{};
256 MontageRootMotionMask rootMotionMask_;
257 MontageGapPolicy gapPolicy_ = MontageGapPolicy::HoldPose;
258 action::ActionExecutionId executionId_{};
259 Duration time_ = Duration::zero();
260 SimulationTick lastTick_ = SimulationTick::zero();
261 bool hasLastTick_ = false;
262 bool started_ = false;
263 bool playing_ = false;
264 bool blendingOut_ = false;
265 Duration blendOutDuration_ = Duration::zero();
266 Duration blendOutElapsed_ = Duration::zero();
267 double blendOutStartWeight_ = 1.0;
268 double weight_ = 1.0;
269};
270
271} // namespace eve::animation
LogicalId target
Renderer- and ruleset-neutral gameplay action pipeline.
float duration
eve::action::ActionExecutionId executionId
eve::EntitySpatialPose pose
int mask
#define EVENGINE_API_WORLD
Definition Export.h:109
glm::vec4 clip
std::string action
Definition PlayHost.cpp:117
std::string uri
Move-only, checked operation results for the common layer.
SimulationTick tick
TerrainThermalSettings settings
Common time values and an injectable deterministic simulation clock.
Signed, fixed-resolution simulation duration in nanoseconds.
Definition Time.h:43
static constexpr Duration zero() noexcept
Return zero duration.
Definition Time.h:60
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
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...
Synchronous ownership-transfer port used to resolve montage clip URIs.
virtual Result< std::unique_ptr< AnimClip > > load(std::string_view uri, const AnimSkeleton &skeleton)=0
Resolve one URI into a clip compatible with the borrowed skeleton.
virtual ~IMontageClipProvider()=default
Releases IMontageClipProvider resources.
Optional receiver for filtered per-step root motion.
virtual void applyMontageRootMotion(const TransformTRS &delta) noexcept=0
Consume one borrowed filtered root-motion delta.
virtual ~IMontageRootMotionReceiver()=default
Releases IMontageRootMotionReceiver resources.
Presentation-only montage player over an ActionTimeline.
RootMotionPolicy getRootMotionPolicy() const noexcept
Copy of the active root-motion policy.
bool footIkEnabled() const noexcept
Whether the host should run its terrain-specific foot-IK provider after this pose.
bool isPlaying() const noexcept
Whether the prepared montage is actively playing.
std::size_t animationLayer() const noexcept
Authored output layer requested by the prepared montage, or zero before preparation.
Duration time() const noexcept
Current derived montage presentation time.
MontagePlayer & operator=(const MontagePlayer &)=delete
~MontagePlayer()
Montage player.
MontageRootMotionMask getRootMotionMask() const noexcept
Compatibility projection of the active policy lock bits.
void clearRootMotionReceiver() noexcept
Clear the borrowed root-motion receiver before its owner is destroyed.
double weight() const noexcept
Current continuous montage slot weight.
void setGapPolicy(MontageGapPolicy policy) noexcept
Select the explicit pose policy used in gaps between animation sections.
bool isFinished() const noexcept
Whether playback completed naturally while retaining its final weighted pose.
bool isBlendingOut() const noexcept
Whether playback is in externally requested blend-out.
MontagePlayer(const MontagePlayer &)=delete
MontageGapPolicy
Pose behavior while the authoritative action cursor is between authored sections.
@ HoldPose
Keep the last evaluated pose until another section starts.
Owning per-step sample of one currently active timeline state.
Result payload for one deterministic advance call.
Definition Action.h:175
Objective animation segment placed on the montage presentation lane.
Montage-wide presentation settings persisted with the action timeline.
Canonical action timeline asset shared by runtime and editor.
Owning observation returned by one montage presentation step.
std::vector< action::ActionTimelineEvent > events
std::optional< LogicalId > sectionId
std::vector< MontageActiveBlock > activeBlocks
Owning clip supplied while transactionally preparing a montage.
std::unique_ptr< AnimClip > clip
Compatibility-only axis enable mask for montage root motion.
Policy applied after raw root-bone delta extraction. @ownership Value type; owned by AnimPlayer or th...
Local TRS used by skeletal animation (quaternion xyzw).
Definition AnimMath.h:9
static TransformTRS identity()
Identity.
Definition AnimMath.h:15