载入中...
搜索中...
未找到
MotionMatcher.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6#include "common/Time.h"
7
8#include <array>
9#include <memory>
10#include <span>
11#include <vector>
12
13namespace eve::animation {
14
15namespace detail {
16struct PoseInertia;
17}
18class AnimSkeleton;
19class MotionDatabase;
20struct MotionFeatureTrajectorySample;
21struct MotionFeatureCurveSample;
22
25 float start = 0.f;
26 float end = 0.f;
27};
30 float start = 0.f;
31 float end = 0.f;
32 float costBias = 0.f;
33};
36 int clipIndex = 0;
37 float start = 0.f;
38 float end = 0.f;
39 float costBias = 0.f;
40 bool disableReselection = false;
42 std::vector<MotionTransitionBlock> transitionBlocks;
44 float continuingCostBias = 0.f;
46 std::vector<MotionCostOverride> costOverrides;
48 std::vector<MotionCostOverride> continuingCostOverrides;
49};
52 float x = 0.f, z = 0.f, yaw = 0.f;
53};
56 float x = 0.f, y = 0.f, z = 0.f;
57 float vx = 0.f, vy = 0.f, vz = 0.f;
58 float yaw = 0.f;
59};
60
67public:
69 MotionMatcher(AnimSkeleton* skeleton, MotionDatabase* database);
72
73 MotionMatcher(const MotionMatcher&) = delete;
75
77 AnimSkeleton* getSkeleton() const { return skeleton_; }
79 MotionDatabase* getDatabase() const { return database_; }
80
82 void setDesiredVelocity(float x, float z);
84 float getDesiredVelocityX() const { return desiredVelX_; }
86 float getDesiredVelocityZ() const { return desiredVelZ_; }
87
89 void setDesiredYaw(float yaw);
91 float getDesiredYaw() const { return desiredYaw_; }
92
94 void setSearchInterval(float seconds);
96 float getSearchInterval() const { return searchInterval_; }
98 void setBlendTime(float seconds);
100 float getBlendTime() const { return blendTime_; }
111 [[nodiscard]] eve::Result<void> setPlayRateRange(float minimum, float maximum);
112 float getPlayRateMinimum() const { return playRateMin_; }
114 float getPlayRateMaximum() const { return playRateMax_; }
116 float getPlayRate() const { return playRate_; }
118 void setTrajectoryWeight(float w);
120 float getTrajectoryWeight() const { return trajWeight_; }
122 void setPoseWeight(float w);
124 float getPoseWeight() const { return poseWeight_; }
126 void setVelocityWeight(float w);
128 float getVelocityWeight() const { return velWeight_; }
129
131 void setIgnoreRadius(int frames);
133 int getIgnoreRadius() const { return ignoreRadius_; }
141 [[nodiscard]] eve::Result<void> setPoseReselectHistory(float seconds);
142 float getPoseReselectHistory() const { return poseReselectHistory_; }
143
145 int getMatchedFrame() const { return matchedFrame_; }
147 int getMatchedClipIndex() const;
149 float getMatchedTime() const { return matchedTime_; }
151 float getLastSearchCost() const { return lastCost_; }
152
154 AnimPose* getPose();
155
179 [[nodiscard]] eve::Result<int> setCandidateRanges(std::span<const MotionSearchRange> ranges);
188 [[nodiscard]] eve::Result<void> setQueryPose(const AnimPose& pose);
197 [[nodiscard]] eve::Result<void> setTrajectory(std::span<const MotionTrajectorySample> samples);
198
219 [[nodiscard]] eve::Result<void> setLocomotionQuery(const AnimPose& current, const AnimPose& previous,
220 float elapsedSeconds,
221 std::span<const MotionLocomotionSample> samples);
222
240 [[nodiscard]] eve::Result<void> setFeatureQuery(const AnimPose& current, const AnimPose& previous,
241 float elapsedSeconds,
242 std::span<const MotionFeatureTrajectorySample> samples,
243 std::span<const MotionFeatureCurveSample> curves = {});
244
246 void search();
247
249 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep& step);
251 void update(float dt);
252
253private:
254 void buildSchemaQuery(std::vector<float>& query) const;
255 void buildLocomotionQuery(std::vector<float>& query) const;
256 void buildQuery(std::vector<float>& query) const;
257 float cost(const std::vector<float>& query, const std::vector<float>& cand, float upperBound) const;
258 void sampleMatched(AnimPose* out) const;
259
260 AnimSkeleton* skeleton_ = nullptr;
261 MotionDatabase* database_ = nullptr;
262 AnimPose pose_;
263 std::unique_ptr<detail::PoseInertia> inertia_;
264 AnimPose matchedPose_;
265
266 float desiredVelX_ = 0.f;
267 float desiredVelZ_ = 0.f;
268 float desiredYaw_ = 0.f;
269
270 float searchInterval_ = 0.1f;
271 float searchTimer_ = 0.f;
272 float blendTime_ = 0.15f;
273 float blendElapsed_ = 0.f;
274 bool blending_ = false;
275 float playRateMin_ = 1.f;
276 float playRateMax_ = 1.f;
277 float playRate_ = 1.f;
278 float queryTrajectorySpeed_ = 0.f;
279
280 float trajWeight_ = 1.f;
281 float poseWeight_ = 1.f;
282 float velWeight_ = 1.f;
283 int ignoreRadius_ = 2;
284 float poseReselectHistory_ = 0.f;
285 std::vector<std::pair<int, float>> poseHistory_;
286
287 int matchedFrame_ = -1;
288 float matchedTime_ = 0.f;
289 float lastCost_ = 0.f;
290 bool playing_ = false;
292 bool hasLastTick_ = false;
293
294 std::vector<int> candidateFrames_;
295 std::vector<float> candidateBias_;
296 std::vector<float> candidateContinuingBias_;
297 std::vector<unsigned char> candidateMask_;
298 std::vector<unsigned char> transitionBlocked_;
299 std::vector<unsigned char> disableReselection_;
300 bool filtered_ = false;
301 AnimPose queryPose_;
302 bool hasQueryPose_ = false;
303 std::array<MotionTrajectorySample, 3> trajectory_{};
304 bool hasTrajectory_ = false;
305 AnimPose previousQueryPose_;
306 float queryPoseInterval_ = 0.f;
307 std::array<MotionLocomotionSample, 5> locomotionTrajectory_{};
308 bool hasLocomotionQuery_ = false;
309 std::vector<float> schemaQuery_;
310
311 void updateUnchecked(float dt);
312 void updatePoseHistory(float dt);
313 void updatePlayRate(int frame);
314};
315
316} // namespace eve::animation
float w
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
eve::EntitySpatialPose pose
eve::resource::CostSpec cost
#define EVENGINE_API_WORLD
Definition Export.h:109
float maximum[3]
float minimum[3]
HexSearchContext search
Frontier reused by the land-growth and erosion searches.
graphics::Canvas * previous
int detail
double current
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
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...
Baked motion-matching feature database from one or more AnimClips. Feature layout per frame: [0....
Runtime motion matching player: builds a query feature from current pose + desired trajectory,...
AnimSkeleton * getSkeleton() const
Returns the skeleton.
float getMatchedTime() const
Returns the matched time.
int getMatchedFrame() const
Returns the matched frame.
float getDesiredVelocityX() const
Returns the desired velocity x.
MotionDatabase * getDatabase() const
Returns the database.
float getSearchInterval() const
Returns the search interval.
MotionMatcher & operator=(const MotionMatcher &)=delete
float getDesiredYaw() const
Returns the desired yaw.
float getVelocityWeight() const
Returns the velocity weight.
int getIgnoreRadius() const
Returns the ignore radius.
~MotionMatcher()
Motion matcher.
float getBlendTime() const
Returns the blend time.
float getPlayRateMaximum() const
Returns the play rate maximum.
float getLastSearchCost() const
Returns the last search cost.
float getPoseWeight() const
Returns the pose weight.
float getTrajectoryWeight() const
Returns the trajectory weight.
float getDesiredVelocityZ() const
Returns the desired velocity z.
float getPlayRate() const
Returns the play rate.
MotionMatcher(const MotionMatcher &)=delete
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Copied clip-time interval overriding a matching cost, with inclusive start and exclusive end.
Copied world displacement, velocity (metres/second), and yaw for a locomotion horizon.
Owning candidate interval in seconds in a database clip; endpoints inclusive.
std::vector< MotionCostOverride > continuingCostOverrides
Owned continuing-cost overrides, evaluated in order so the last active interval wins.
std::vector< MotionTransitionBlock > transitionBlocks
Owned transition blocks, unioned across all ranges of this clip; continuation remains eligible.
float continuingCostBias
Default extra cost for continuing a pose selected through this range.
std::vector< MotionCostOverride > costOverrides
Owned absolute candidate-cost overrides, evaluated in order so the last active interval wins.
Predicted world-space displacement and facing at a fixed future horizon.
Copied clip-time interval forbidding new matches, with inclusive start and exclusive end.