载入中...
搜索中...
未找到
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;
26class PreparedMontage;
27
30 std::string uri;
31 std::unique_ptr<AnimClip> clip;
32};
33
42public:
44 virtual ~IMontageClipProvider() = default;
46 [[nodiscard]] virtual Result<std::unique_ptr<AnimClip>> load(std::string_view uri,
47 const AnimSkeleton& skeleton) = 0;
48};
49
57 bool translationX = true;
58 bool translationY = true;
59 bool translationZ = true;
60 bool rotation = true;
61};
62
64enum class MontageGapPolicy : std::uint8_t {
69};
70
78public:
80 virtual ~IMontageRootMotionReceiver() = default;
82 virtual void applyMontageRootMotion(const TransformTRS& delta) noexcept = 0;
83};
84
87
92 std::optional<LogicalId> sectionId;
93 std::vector<action::ActionTimelineEvent> events;
94 std::vector<MontageActiveBlock> activeBlocks;
96 double weight = 1.0;
97 bool completed = false;
98};
99
109public:
111 explicit MontagePlayer(AnimSkeleton& skeleton);
114
115 MontagePlayer(const MontagePlayer&) = delete;
117
123 [[nodiscard]] Result<void> prepare(action::ActionTimeline timeline, std::vector<MontageClipAsset>&& clips);
128 [[nodiscard]] Result<void> prepare(action::ActionTimeline timeline, IMontageClipProvider& provider);
133 [[nodiscard]] Result<void> reloadClips(IMontageClipProvider& provider);
139 [[nodiscard]] Result<void> setSettings(action::ActionMontageSettings settings);
145 [[nodiscard]] Result<void> setSectionSplits(std::vector<Duration> splitTimestamps);
147 [[nodiscard]] Result<void> replaceClip(std::string_view uri, std::unique_ptr<AnimClip> clip);
151 [[nodiscard]] Result<void> rebindExecution(action::ActionExecutionId executionId);
173 [[nodiscard]] Result<MontageAdvance> jumpToSection(action::ActionExecutionId executionId, std::size_t sectionIndex,
176 [[nodiscard]] Result<MontageAdvance> evaluateSectionProgress(action::ActionExecutionId executionId,
177 std::size_t sectionIndex, double progress,
180 [[nodiscard]] Result<std::size_t> physicalSectionIndex() const;
182 [[nodiscard]] Result<double> physicalSectionProgress(std::size_t sectionIndex) const;
184 [[nodiscard]] Result<MontageAdvance> interrupt(SimulationTick tick);
186 [[nodiscard]] Result<MontageAdvance> beginBlendOut(Duration duration, SimulationTick tick);
188 [[nodiscard]] Result<MontageAdvance> advanceBlendOut(Duration delta, SimulationTick tick);
190 void stop() noexcept;
191
197 void setRootMotionReceiver(IMontageRootMotionReceiver& receiver) noexcept { receiver_ = &receiver; }
199 void clearRootMotionReceiver() noexcept { receiver_ = nullptr; }
205 void setRootMotionMask(MontageRootMotionMask mask) noexcept;
207 [[nodiscard]] MontageRootMotionMask getRootMotionMask() const noexcept { return rootMotionMask_; }
213 [[nodiscard]] Result<void> setRootMotionPolicy(const RootMotionPolicy& policy);
215 [[nodiscard]] RootMotionPolicy getRootMotionPolicy() const noexcept { return rootMotionPolicy_; }
220 [[nodiscard]] Result<void> setRootMotionCharacterYaw(float yawRadians);
222 void setGapPolicy(MontageGapPolicy policy) noexcept { gapPolicy_ = policy; }
224 [[nodiscard]] AnimPose& pose();
226 [[nodiscard]] Duration time() const noexcept { return time_; }
228 [[nodiscard]] bool isPlaying() const noexcept { return playing_; }
230 [[nodiscard]] bool isBlendingOut() const noexcept { return blendingOut_; }
232 [[nodiscard]] bool isFinished() const noexcept {
233 return timeline_ && !executionId_.isZero() && !playing_ && !blendingOut_ && weight_ > 0.0;
234 }
236 [[nodiscard]] double weight() const noexcept { return weight_; }
238 [[nodiscard]] std::size_t animationLayer() const noexcept {
239 return timeline_ ? timeline_->montage.animationLayer : 0U;
240 }
242 [[nodiscard]] bool footIkEnabled() const noexcept { return timeline_ && timeline_->montage.footIk; }
243
244private:
246 [[nodiscard]] std::optional<std::size_t> sectionIndexAt(Duration time) const noexcept;
248 [[nodiscard]] std::optional<Duration> nextSectionStartAfter(Duration time) const noexcept;
250 [[nodiscard]] const action::ActionAnimationSection* sectionAt(Duration time) const noexcept;
252 [[nodiscard]] double sectionEnvelopeAt(Duration time) const noexcept;
253 void activate(const action::ActionAnimationSection& section, Duration localTime);
254 void accumulateRootMotion(TransformTRS& total) const;
256 void applyTimelineRootMotionChannels() noexcept;
258 void pushRootMotionPolicyToPlayer() noexcept;
259 [[nodiscard]] std::vector<action::ActionTimelineEvent> realignStateEvents(Duration target) const;
260 [[nodiscard]] Result<std::vector<MontageActiveBlock>> activeBlocksAt(Duration target) const;
261 [[nodiscard]] Result<MontageAdvance>
262 presentImpl(const action::ActionAdvance& advance, std::vector<action::ActionTimelineEvent> events,
263 std::vector<MontageActiveBlock> activeBlocks, SimulationTick tick);
264
265 AnimSkeleton& skeleton_;
266 std::unique_ptr<AnimPlayer> player_;
267 std::optional<action::ActionTimeline> timeline_;
268 std::vector<MontageClipAsset> clips_;
269 std::unique_ptr<PreparedMontage> prepared_;
270 const action::ActionAnimationSection* activeSection_ = nullptr;
271 IMontageRootMotionReceiver* receiver_ = nullptr;
272 RootMotionPolicy rootMotionPolicy_{};
273 MontageRootMotionMask rootMotionMask_;
274 MontageGapPolicy gapPolicy_ = MontageGapPolicy::HoldPose;
275 action::ActionExecutionId executionId_{};
276 Duration time_ = Duration::zero();
277 SimulationTick lastTick_ = SimulationTick::zero();
278 bool hasLastTick_ = false;
279 bool started_ = false;
280 bool playing_ = false;
281 bool blendingOut_ = false;
282 Duration blendOutDuration_ = Duration::zero();
283 Duration blendOutElapsed_ = Duration::zero();
284 double blendOutStartWeight_ = 1.0;
285 double weight_ = 1.0;
286};
287
288} // 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
bool present
OceanWakeSettings settings
std::vector< particles::ParticleRecordEvent > events
std::string action
Definition PlayHost.cpp:118
std::string uri
Move-only, checked operation results for the common layer.
SimulationTick tick
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:176
Single-clip (or cross-fading) 3D animation player. Script type: AnimPlayer.
Definition AnimPlayer.h:33
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
Immutable lookup topology built before a montage is published.
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:204
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 constexpr TransformTRS identity() noexcept
Identity.
Definition AnimMath.h:15