载入中...
搜索中...
未找到
AnimGraph.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
7#include "common/Time.h"
8
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13namespace eve::animation {
14
15class AnimClip;
16class AnimSkeleton;
17
27public:
29 explicit AnimGraph(AnimSkeleton* skeleton);
31 ~AnimGraph() override = default;
32
33 AnimGraph(const AnimGraph&) = delete;
34 AnimGraph& operator=(const AnimGraph&) = delete;
35
37 int addClip(AnimClip* clip);
39 int addBlend(int a, int b, float weight = 0.5f);
41 int addAdditive(int base, int additive, float weight = 1.f);
43 int addLayer(int base, int overlay, float weight = 1.f);
45 int addOneShot(int base, int shot, float fadeIn = 0.1f, float fadeOut = 0.1f);
47 int addBlendSpace1D();
49 int addBlendSpace2D();
50
52 void addBlendSpace1DPoint(int node, float x, int child);
54 void addBlendSpace2DPoint(int node, float x, float y, int child);
56 void setBoneMask(int node, int boneIndex, float weight, bool includeChildren = false);
58 void clearBoneMask(int node);
59
61 void setRoot(int node);
63 int getRoot() const { return root_; }
65 int getNodeCount() const { return static_cast<int>(nodes_.size()); }
67 void setWeight(int node, float weight);
69 void setPosition1D(int node, float x);
71 void setPosition2D(int node, float x, float y);
73 void setSpeed(int node, float speed);
75 void trigger(int node);
77 bool isOneShotActive(int node) const;
78
83 [[nodiscard]] eve::Result<void> setAdditiveReference(int node, const std::string& reference);
85 bool setAdditiveReferenceCompat(int node, const std::string& reference);
87 std::string getAdditiveReference(int node) const;
88
90 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep& step) override;
92 void update(float dt);
97 AnimPose* getPose() override { return &output_; }
103 AnimSkeleton* getSkeleton() const override { return skeleton_; }
105 [[nodiscard]] bool hasCurrentTick() const noexcept override { return hasLastTick_; }
107 [[nodiscard]] eve::SimulationTick currentTick() const noexcept override { return lastTick_; }
108
109private:
110 enum class Kind { Clip, Blend, Additive, Layer, OneShot, BlendSpace1D, BlendSpace2D };
111 struct Point {
112 float x = 0.f, y = 0.f;
113 int child = -1;
114 };
115 struct Node {
116 Kind kind = Kind::Clip;
117 AnimClip* clip = nullptr;
118 int a = -1, b = -1;
119 float weight = 1.f;
120 float time = 0.f;
121 float speed = 1.f;
122 float x = 0.f, y = 0.f;
123 float fadeIn = 0.1f, fadeOut = 0.1f;
124 bool active = false;
125 AnimAdditiveReference additiveReference = AnimAdditiveReference::Identity;
126 std::vector<Point> points;
127 std::vector<float> mask;
128 AnimPose cache;
129 AnimPose scratch;
130 unsigned cacheGeneration = 0;
131 };
132
133 int addNode(Kind kind);
134 Node& requireNode(int node);
135 const Node& requireNode(int node) const;
136 void requireChild(int child) const;
137 const AnimPose& evaluate(int node);
138 const AnimPose& evaluateBlendSpace(Node& node, bool twoDimensional);
139 void blendMasked(AnimPose& out, const AnimPose& base, const AnimPose& overlay, float weight,
140 const std::vector<float>* mask) const;
141 void applyAdditive(AnimPose& out, const AnimPose& base, const AnimPose& delta, float weight,
142 const std::vector<float>* mask, AnimAdditiveReference reference) const;
143
144 AnimSkeleton* skeleton_ = nullptr;
145 std::vector<Node> nodes_;
146 AnimPose output_;
147 int root_ = -1;
148 unsigned generation_ = 0;
150 bool hasLastTick_ = false;
151
152 void updateUnchecked(float dt);
153};
154
155} // namespace eve::animation
bool & active
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
AuthorityStoreHandleRef reference
Definition Authority.cpp:24
int mask
#define EVENGINE_API_WORLD
Definition Export.h:109
glm::vec4 clip
TokenKind kind
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::shared_ptr< const std::vector< glm::vec2 > > points
const RoadNode * node
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
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
Composable runtime pose graph supporting clips, blends, additive layers, per-bone masks,...
Definition AnimGraph.h:26
eve::SimulationTick currentTick() const noexcept override
Current tick.
Definition AnimGraph.h:107
int getRoot() const
Returns the root.
Definition AnimGraph.h:63
bool hasCurrentTick() const noexcept override
True when current tick.
Definition AnimGraph.h:105
AnimPose * getPose() override
Borrowed pointer accessor. @ownership Borrowed @lifetime Valid while the owning animation object rema...
Definition AnimGraph.h:97
~AnimGraph() override=default
Anim graph.
AnimGraph & operator=(const AnimGraph &)=delete
AnimGraph(const AnimGraph &)=delete
AnimSkeleton * getSkeleton() const override
Return the graph skeleton. @ownership Borrowed @lifetime Valid while the owning animation object rema...
Definition AnimGraph.h:103
int getNodeCount() const
Returns the node count.
Definition AnimGraph.h:65
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.
std::vector< OnnxNamedTensor > evaluate(const ModelData &, std::span< const OnnxNamedTensor >, const std::vector< std::string > &, OnnxCompute *, OnnxRunOptions options)
Evaluate.
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158