载入中...
搜索中...
未找到
AnimLayerMixer.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
7#include "common/Time.h"
8
9#include <string>
10#include <vector>
11
12namespace eve::animation {
13
14class AnimGraph;
15class AnimPlayer;
16class AnimSkeleton;
17class AnimStateMachine;
18
21public:
23 explicit AnimBoneMask(AnimSkeleton* skeleton);
24
26 void setAll(float weight);
28 bool setBoneWeight(int boneIndex, float weight);
30 bool setBoneWeightByName(const std::string& boneName, float weight);
32 bool setBoneAndChildren(const std::string& boneName, float weight);
34 float getBoneWeight(int boneIndex) const;
36 int getBoneCount() const { return static_cast<int>(weights_.size()); }
38 AnimSkeleton* getSkeleton() const { return skeleton_; }
39
40private:
41 AnimSkeleton* skeleton_ = nullptr;
42 std::vector<float> weights_;
43};
44
54public:
56 explicit AnimLayerMixer(AnimSkeleton* skeleton);
57
62 [[nodiscard]] eve::Result<void> setBaseSource(IAnimPoseSource* source);
64 bool setBasePlayer(AnimPlayer* player);
66 bool setBaseGraph(AnimGraph* graph);
68 bool setBaseStateMachine(AnimStateMachine* stateMachine);
74 IAnimPoseSource* getBaseSource() const { return baseSource_; }
80 AnimPlayer* getBasePlayer() const;
81
86 [[nodiscard]] eve::Result<int> addPoseLayer(const std::string& name, IAnimPoseSource* source, AnimBoneMask* mask,
87 const std::string& mode);
89 int addLayer(const std::string& name, AnimPlayer* player, AnimBoneMask* mask, const std::string& mode);
91 int addGraphLayer(const std::string& name, AnimGraph* graph, AnimBoneMask* mask, const std::string& mode);
93 int addStateMachineLayer(const std::string& name, AnimStateMachine* stateMachine, AnimBoneMask* mask,
94 const std::string& mode);
95
97 bool removeLayer(const std::string& name);
99 bool setLayerWeight(const std::string& name, float weight);
101 bool setLayerEnabled(const std::string& name, bool enabled);
106 [[nodiscard]] eve::Result<void> setLayerAdditiveReference(const std::string& name, const std::string& reference);
108 bool setLayerAdditiveReferenceCompat(const std::string& name, const std::string& reference);
109
111 int getLayerCount() const { return static_cast<int>(layers_.size()); }
113 std::string getLayerName(int index) const;
115 float getLayerWeight(const std::string& name) const;
117 bool getLayerEnabled(const std::string& name) const;
119 std::string getLayerMode(const std::string& name) const;
121 std::string getLayerAdditiveReference(const std::string& name) const;
122
124 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep& step) override;
126 void update(float dt);
132 AnimPose* getPose() override { return &pose_; }
138 AnimSkeleton* getSkeleton() const override { return skeleton_; }
140 [[nodiscard]] bool hasCurrentTick() const noexcept override { return hasLastTick_; }
142 [[nodiscard]] eve::SimulationTick currentTick() const noexcept override { return lastTick_; }
144 [[nodiscard]] int getEventCount() const override { return static_cast<int>(events_.size()); }
146 [[nodiscard]] std::string getEventName(int index) const override;
148 [[nodiscard]] std::string getEventPayload(int index) const override;
149
151 std::string getEventLayer(int index) const;
153 void clearEvents() { events_.clear(); }
154
155private:
156 struct Layer {
157 std::string name;
158 IAnimPoseSource* source = nullptr;
159 AnimBoneMask* mask = nullptr;
160 float weight = 1.f;
161 bool additive = false;
162 bool enabled = true;
163 AnimAdditiveReference additiveReference = AnimAdditiveReference::BindPose;
164 };
165 struct Event {
166 std::string layer;
167 std::string name;
168 std::string payload;
169 };
170
172 Layer* findLayer(const std::string& name);
174 const Layer* findLayer(const std::string& name) const;
175 void collectEvents(const std::string& layerName, IAnimPoseSource* source);
176 void applyOverride(const Layer& layer);
177 void applyAdditive(const Layer& layer);
178 [[nodiscard]] eve::Result<void> attachSource(IAnimPoseSource* source, const char* role);
179 bool sourceAlreadyAttached(const IAnimPoseSource* source) const;
180
181 AnimSkeleton* skeleton_ = nullptr;
182 IAnimPoseSource* baseSource_ = nullptr;
183 AnimPose pose_;
184 std::vector<Layer> layers_;
185 std::vector<Event> events_;
187 bool hasLastTick_ = false;
188
189 void compose();
190};
191
192} // namespace eve::animation
Value::Object payload
AuthorityStoreHandleRef reference
Definition Authority.cpp:24
int mask
#define EVENGINE_API_WORLD
Definition Export.h:109
std::string name
std::map< std::string, std::vector< std::string > > graph
Definition Package.cpp:59
TileLayer * layer
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
uint32_t index
const UnitySourceAsset & source
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Per-bone weights used by override and additive animation layers.
AnimSkeleton * getSkeleton() const
Return the non-owned skeleton used by this mask.
int getBoneCount() const
Return the number of bones represented by this mask.
Composable runtime pose graph supporting clips, blends, additive layers, per-bone masks,...
Definition AnimGraph.h:26
Combines a borrowed base pose source with ordered override/additive layers.
AnimSkeleton * getSkeleton() const override
Return the mixer skeleton. @ownership Borrowed @lifetime Valid while the owning animation object rema...
bool hasCurrentTick() const noexcept override
True when current tick.
IAnimPoseSource * getBaseSource() const
Return the borrowed base source, or null. @ownership Borrowed @lifetime Valid while the owning animat...
int getLayerCount() const
Return the number of configured layers.
AnimPose * getPose() override
Return the most recently combined pose. @ownership Borrowed @lifetime Valid while the owning animatio...
eve::SimulationTick currentTick() const noexcept override
Current tick.
void clearEvents()
Clear events collected by the most recent update.
int getEventCount() const override
Returns the event count.
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...
Clip-driven animation state machine with float/bool/trigger parameters and cross-fade transitions....
Borrowed pose provider consumed by AnimLayerMixer.
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
AnimAdditiveReference
Reference pose used when converting an additive sample into a delta.
bool enabled
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158