18 : skeleton_(skeleton), database_(database) {
19 if (!skeleton_)
throw Exception(
"MotionMatcher: skeleton is null");
20 if (!database_)
throw Exception(
"MotionMatcher: database is null");
22 throw Exception(
"MotionMatcher: database skeleton mismatch");
25 inertia_ = std::make_unique<detail::PoseInertia>();
40 if (seconds < 0.f)
throw Exception(
"MotionMatcher.setSearchInterval: must be >= 0");
41 searchInterval_ = seconds;
45 if (seconds < 0.f)
throw Exception(
"MotionMatcher.setBlendTime: must be >= 0");
50 if (
w < 0.f)
throw Exception(
"MotionMatcher.setTrajectoryWeight: must be >= 0");
55 if (
w < 0.f)
throw Exception(
"MotionMatcher.setPoseWeight: must be >= 0");
60 if (
w < 0.f)
throw Exception(
"MotionMatcher.setVelocityWeight: must be >= 0");
65 if (frames < 0)
throw Exception(
"MotionMatcher.setIgnoreRadius: must be >= 0");
66 ignoreRadius_ = frames;
70 if (!std::isfinite(
minimum) || !std::isfinite(
maximum) ||
minimum <= 0.f || maximum < minimum || maximum > 10.f)
73 "playRateRange", {},
"animation"));
80void MotionMatcher::updatePlayRate(
int frame) {
81 float estimated = 1.f;
82 if (database_->schema_ &&
frame >= 0) {
84 if (poseSpeed > 1e-4f) estimated = queryTrajectorySpeed_ / poseSpeed;
86 playRate_ = std::clamp(estimated, playRateMin_, playRateMax_);
90 if (!std::isfinite(seconds) || seconds < 0.f || seconds > 10.f)
93 "pose reselect history must be finite and between zero and ten seconds",
94 "poseReselectHistory", {},
"animation"));
95 poseReselectHistory_ = seconds;
96 if (seconds == 0.f) poseHistory_.clear();
101 if (matchedFrame_ < 0 || !database_->isBaked())
return -1;
107void MotionMatcher::buildQuery(std::vector<float>& query)
const {
109 buildSchemaQuery(query);
112 if (!database_->
isBaked())
throw Exception(
"MotionMatcher: database not baked");
114 buildLocomotionQuery(query);
118 query.assign(
static_cast<size_t>(
n), 0.f);
121 const float cs = std::cos(desiredYaw_);
122 const float sn = std::sin(desiredYaw_);
123 query[0] = desiredVelX_ * cs - desiredVelZ_ * sn;
124 query[1] = desiredVelX_ * sn + desiredVelZ_ * cs;
127 const float horizons[3] = {0.33f, 0.66f, 1.0f};
128 for (
int h = 0;
h < 3; ++
h) {
129 query[
static_cast<size_t>(2 +
h * 2)] = query[0] * horizons[
h];
130 query[
static_cast<size_t>(2 +
h * 2 + 1)] = query[1] * horizons[
h];
131 if (hasTrajectory_) {
132 query[
static_cast<size_t>(2 +
h * 2)] = trajectory_[
h].
x * cs - trajectory_[
h].
z * sn;
133 query[
static_cast<size_t>(3 +
h * 2)] = trajectory_[
h].
x * sn + trajectory_[
h].
z * cs;
138 yawToForward(hasTrajectory_ ? trajectory_[2].
yaw - desiredYaw_ : 0.f, fx, fz);
144 cur.copyFrom(hasQueryPose_ ? &queryPose_ : (playing_ ? &matchedPose_ : &pose_));
145 cur.computeWorld(skeleton_);
147 const float rootX = cur.getWorldPositionX(
root);
148 const float rootZ = cur.getWorldPositionZ(
root);
150 const float qy = cur.getWorldRotationY(
root);
151 const float qw = cur.getWorldRotationW(
root);
152 const float yaw = std::atan2(2.f * (
qw *
qy), 1.f - 2.f * (
qy *
qy));
153 const float c2 = std::cos(
yaw);
154 const float s2 = std::sin(
yaw);
159 const float dx = cur.getWorldPositionX(
b) - rootX;
160 const float dz = cur.getWorldPositionZ(
b) - rootZ;
161 const float lx =
dx * c2 -
dz * s2;
162 const float lz =
dx * s2 +
dz * c2;
163 query[
static_cast<size_t>(base)] = lx;
164 query[
static_cast<size_t>(base + 1)] = cur.getWorldPositionY(
b);
165 query[
static_cast<size_t>(base + 2)] = lz;
171float MotionMatcher::cost(
const std::vector<float>& query,
const std::vector<float>& cand,
float upperBound)
const {
172 const int n =
static_cast<int>(
query.size());
174 const auto* schema = database_->schema_.get();
175 const float schemaWeight = schema ? schema->weightSums[0] * poseWeight_ + schema->weightSums[1] * velWeight_ +
176 schema->weightSums[2] * trajWeight_
178 for (
int i = 0; i <
n; ++i) {
179 const float d =
query[
static_cast<size_t>(i)] - cand[
static_cast<size_t>(i)];
180 float w = poseWeight_;
185 w *= schema->weights[i] / std::max(1e-8f, schemaWeight);
188 if (i < 2 || (i >= 12 && i < 14) || (i >= 16 && i < 19))
w = velWeight_;
190 w /= std::max(1e-8f, 8.5f * velWeight_ + 10.6f * trajWeight_ + 5.f * poseWeight_);
196 if (sum >= upperBound)
return sum;
201void MotionMatcher::sampleMatched(AnimPose*
out)
const {
202 if (matchedFrame_ < 0) {
212 if (!database_->
isBaked())
throw Exception(
"MotionMatcher.search: database not baked");
214 throw Exception(
"MotionMatcher.search: empty database");
217 std::vector<float> query;
222 int continuation = -1;
223 float nearest = std::numeric_limits<float>::infinity();
225 const auto* currentAsset = currentClip >= 0 ? database_->
getClip(currentClip) :
nullptr;
226 const bool ended = currentAsset && !currentAsset->
getLoop() && matchedTime_ >= currentAsset->getDuration();
227 if (playing_ && currentClip >= 0 && !
ended) {
228 const auto*
clip = database_->
getClip(currentClip);
230 const int count = filtered_ ?
static_cast<int>(candidateFrames_.size()) : database_->
getFrameCount();
231 for (
int candidate = 0; candidate <
count; ++candidate) {
232 const int i = filtered_ ? candidateFrames_[candidate] : candidate;
246 if (filtered_ && continuation >= 0) {
247 const float rate = currentAsset->getSampleRate() > 0.f ? currentAsset->getSampleRate() : 30.f;
248 if (nearest > .5f /
rate + 1e-5f) continuation = -1;
251 float bestCost = std::numeric_limits<float>::infinity();
252 if (continuation >= 0) {
256 if (database_->schema_) {
257 for (std::size_t i = 0; i < query.size(); ++i)
265 std::copy(query.begin() + 10, query.end(), feature.begin() + 10);
266 bestCost =
cost(query, feature, bestCost);
267 if (filtered_) bestCost += candidateBias_[continuation] + candidateContinuingBias_[continuation];
269 int best = continuation;
270 float switchCost = bestCost;
271 const int searchCount = filtered_ ?
static_cast<int>(candidateFrames_.size()) : database_->
getFrameCount();
272 for (
int candidate = 0; candidate < searchCount; ++candidate) {
273 const int i = filtered_ ? candidateFrames_[candidate] : candidate;
275 if (filtered_ && transitionBlocked_[i])
continue;
276 if (std::any_of(poseHistory_.begin(), poseHistory_.end(), [i](
const auto& item) { return item.first == i; }))
280 if (playing_ && filtered_ && disableReselection_[currentClip] && database_->
getFrameClipIndex(i) == currentClip)
283 if (filtered_ && disableReselection_[currentClip])
continue;
284 const auto*
clip = database_->
getClip(currentClip);
287 const float rate =
clip->getSampleRate() > 0.f ?
clip->getSampleRate() : 30.f;
288 if (
distance <=
static_cast<float>(ignoreRadius_) /
rate + 1e-5f)
continue;
290 const float bias = filtered_ ? candidateBias_[i] : 0.f;
292 if (
c + 1e-5f < switchCost) {
298 if (
best == continuation && continuation >= 0) {
299 matchedFrame_ = continuation;
300 lastCost_ = bestCost;
301 updatePlayRate(continuation);
307 if (
best < 0)
return;
308 lastCost_ = bestCost;
309 updatePlayRate(
best);
311 matchedFrame_ =
best;
313 sampleMatched(&matchedPose_);
314 if (blendTime_ > 1e-6f && playing_) {
317 ->
sample(matchedTime_ - inertia_->historyInterval * playRate_, &previousTarget, skeleton_);
318 inertia_->begin(pose_, matchedPose_, previousTarget, blendTime_);
329void MotionMatcher::updateUnchecked(
float dt) {
330 if (
dt < 0.f)
throw Exception(
"MotionMatcher.update: dt must be >= 0");
331 if (!database_->
isBaked())
return;
340 if (searchTimer_ >= searchInterval_ ||
ended) {
346 inertia_->remember(pose_,
dt);
347 if (matchedFrame_ >= 0) {
348 matchedTime_ +=
dt * playRate_;
350 if (!
clip->getLoop()) matchedTime_ = std::min(matchedTime_,
clip->getDuration());
351 sampleMatched(&matchedPose_);
356 if (blendElapsed_ >= inertia_->duration) {
360 inertia_->apply(matchedPose_, blendElapsed_, pose_);
362 }
else if (matchedFrame_ >= 0) {
365 updatePoseHistory(
dt);
368void MotionMatcher::updatePoseHistory(
float dt) {
369 if (poseReselectHistory_ <= 0.f ||
dt <= 0.f || matchedFrame_ < 0)
return;
370 for (
auto& item : poseHistory_) item.
second +=
dt;
371 std::erase_if(poseHistory_, [&](
const auto& item) {
return item.second > poseReselectHistory_; });
375 int nearestFrame = -1;
376 float nearest = std::numeric_limits<float>::infinity();
377 const int count = filtered_ ?
static_cast<int>(candidateFrames_.size()) : database_->getFrameCount();
378 for (
int candidate = 0; candidate <
count; ++candidate) {
379 const int i = filtered_ ? candidateFrames_[candidate] : candidate;
388 if (nearestFrame < 0)
return;
389 auto found = std::find_if(poseHistory_.begin(), poseHistory_.end(),
390 [nearestFrame](
const auto& item) { return item.first == nearestFrame; });
391 if (
found == poseHistory_.end())
392 poseHistory_.push_back({nearestFrame, 0.f});
400 updateUnchecked(std::move(seconds).takeValue());
401 lastTick_ =
step.tick;
409 step.ignore(
"legacy MotionMatcher update");
420 float elapsedSeconds,
421 std::span<const MotionLocomotionSample> samples) {
423 for (
int i = 0; i <
pose.getBoneCount(); ++i) {
424 const auto&
t =
pose.local(i);
425 for (
float v : {
t.px,
t.py,
t.pz,
t.qx,
t.qy,
t.qz,
t.qw,
t.sx,
t.sy,
t.sz})
426 if (!std::isfinite(
v))
return false;
431 previous.getBoneCount() != pose_.
getBoneCount() || !std::isfinite(elapsedSeconds) || elapsedSeconds <= 0.f ||
432 elapsedSeconds > 1.f || samples.size() != 5 || !finitePose(
current) || !finitePose(
previous) ||
433 std::any_of(samples.begin(), samples.end(), [](
const auto&
s) {
434 for (float v : {s.x, s.y, s.z, s.vx, s.vy, s.vz, s.yaw})
435 if (!std::isfinite(
v))
return true;
440 "locomotion query requires the locomotion layout, finite matching poses, five samples, and dt in (0,1]",
441 "locomotionQuery", {},
"animation"));
442 AnimPose nextCurrent, nextPrevious;
443 nextCurrent.copyFrom(&
current);
445 queryPose_ = std::move(nextCurrent);
446 previousQueryPose_ = std::move(nextPrevious);
447 std::copy(samples.begin(), samples.end(), locomotionTrajectory_.begin());
448 queryPoseInterval_ = elapsedSeconds;
449 hasLocomotionQuery_ =
true;
450 hasQueryPose_ =
true;
454void MotionMatcher::buildLocomotionQuery(std::vector<float>& query)
const {
455 if (!hasLocomotionQuery_)
throw Exception(
"MotionMatcher: configure a locomotion query before searching");
456 query.assign(detail::locomotionFeatureCount, 0.f);
457 detail::encodeLocomotionTrajectory(std::span(query), locomotionTrajectory_, desiredYaw_);
460 previous.copyFrom(&previousQueryPose_);
461 current.computeWorld(skeleton_);
463 std::array<TransformTRS, 4> now{}, past{};
464 now[0] =
current.world(database_->getRootBone());
465 past[0] =
previous.world(database_->getRootBone());
466 for (
int i = 0; i < 3; ++i) {
467 const int bone = database_->getFeatureBone(i);
471 detail::encodeLocomotionPose(query, now, past, queryPoseInterval_);
472 database_->normalizeFeature(query);
479 std::span<const MotionFeatureTrajectorySample> samples,
480 std::span<const MotionFeatureCurveSample> curves) {
481 auto fail = [](
const char*
message) {
485 if (!database_->schema_ || !database_->
isBaked() || !std::isfinite(
dt) || dt <= 0.f || dt > 1.f ||
487 samples.size() > 256 || curves.size() > 256)
488 return fail(
"feature query requires a baked variable layout, matching poses and finite dt in (0,1]");
490 for (
int i = 0; i <
pose->getBoneCount(); ++i) {
491 const auto&
t =
pose->local(i);
492 for (
float v : {
t.px,
t.py,
t.pz,
t.qx,
t.qy,
t.qz,
t.qw,
t.sx,
t.sy,
t.sz})
493 if (!std::isfinite(
v))
return fail(
"feature query poses must be finite");
495 for (std::size_t i = 0; i < samples.size(); ++i) {
496 const auto&
s = samples[i];
497 for (
float v : {
s.seconds,
s.x,
s.y,
s.z,
s.vx,
s.vy,
s.vz,
s.yaw})
498 if (!std::isfinite(
v))
return fail(
"trajectory samples must be finite");
499 for (std::size_t j = 0; j < i; ++j)
500 if (std::abs(
s.seconds - samples[j].seconds) < 1e-6f)
return fail(
"trajectory sample times must be unique");
502 const auto& schema = *database_->schema_;
503 for (std::size_t i = 0; i < curves.size(); ++i) {
504 const auto&
c = curves[i];
505 if (
c.curve.empty() ||
c.curve.size() > 4096 || !std::isfinite(
c.seconds) || !std::isfinite(
c.value))
506 return fail(
"curve queries require bounded names and finite times/values");
507 for (std::size_t j = 0; j < i; ++j)
508 if (
c.curve == curves[j].curve && std::abs(
c.seconds - curves[j].seconds) < 1e-6f)
509 return fail(
"curve query names and times must be unique");
511 std::vector<float> scalarValues(schema.layout.channels.size(), 0.f);
512 for (std::size_t i = 0; i < schema.layout.channels.size(); ++i) {
513 const auto&
c = schema.layout.channels[i];
515 auto sample = std::find_if(curves.begin(), curves.end(), [&](
const auto&
s) {
516 return s.curve == c.curve && std::abs(s.seconds - c.sampleTime) < 1e-6f;
518 if (sample == curves.end())
return fail(
"curve query does not cover a configured channel/time");
519 scalarValues[i] = sample->value;
521 std::vector<const MotionFeatureTrajectorySample*>
selected;
522 for (
const auto&
c : schema.layout.channels) {
525 for (
const auto&
s : samples)
526 if (std::abs(
s.seconds -
c.sampleTime) < 1e-6f) {
530 if (!sample)
return fail(
"trajectory query does not cover a configured sample time");
542 character.
qy = std::sin(desiredYaw_ * .5f);
543 character.
qw = std::cos(desiredYaw_ * .5f);
544 std::vector<float> query(schema.dimension, 0.f);
545 for (std::size_t i = 0; i < schema.layout.channels.size(); ++i) {
546 const auto&
c = schema.layout.channels[i];
547 std::array<float, 3>
value{};
549 value[0] = scalarValues[i];
550 else if (
const auto* sample =
selected[i]) {
558 rotation.qw = std::cos(sample->yaw * .5f);
567 else if (
c.characterSpaceVelocity) {
577 schema.layout.normalizationLengthScale);
579 for (
float v : query)
580 if (!std::isfinite(
v))
return fail(
"encoded feature query exceeds finite range");
581 const float queryTrajectorySpeed = database_->schemaTrajectorySpeed(query);
583 for (
float v : query)
584 if (!std::isfinite(
v))
return fail(
"normalized feature query exceeds finite range");
585 schemaQuery_.swap(query);
586 queryTrajectorySpeed_ = queryTrajectorySpeed;
590void MotionMatcher::buildSchemaQuery(std::vector<float>& query)
const {
591 if (schemaQuery_.empty())
throw Exception(
"MotionMatcher: configure a feature query before searching");
592 query = schemaQuery_;
599 auto fail = [](
const char*
message) {
603 if (!database_->
isBaked() || ranges.empty() || ranges.size() > 100000)
604 return fail(
"candidate selection requires a baked database and bounded nonempty ranges");
605 std::vector<std::vector<MotionSearchRange>> perClip(database_->
getClipCount());
606 std::size_t intervalCount = 0;
607 for (
const auto&
r : ranges) {
608 if (
r.clipIndex < 0 ||
r.clipIndex >= database_->
getClipCount() || !std::isfinite(
r.start) ||
609 !std::isfinite(
r.end) || !std::isfinite(
r.costBias) ||
r.start < 0.f ||
r.end <
r.start ||
611 return fail(
"invalid candidate clip, time interval, or cost bias");
612 intervalCount +=
r.transitionBlocks.size() +
r.costOverrides.size() +
r.continuingCostOverrides.size();
613 if (intervalCount > 100000)
return fail(
"too many candidate metadata intervals");
614 for (
const auto& block :
r.transitionBlocks)
615 if (!std::isfinite(block.start) || !std::isfinite(block.end) || block.start < 0.f ||
616 block.end <= block.start)
617 return fail(
"invalid transition block interval");
618 if (!std::isfinite(
r.continuingCostBias))
return fail(
"invalid continuing cost bias");
619 for (
const auto* overrides : {&
r.costOverrides, &
r.continuingCostOverrides})
620 for (
const auto&
cost : *overrides)
621 if (!std::isfinite(
cost.start) || !std::isfinite(
cost.end) || !std::isfinite(
cost.costBias) ||
623 return fail(
"invalid cost override interval");
624 perClip[
r.clipIndex].push_back(
r);
629 std::vector<float> continuingBias(
count, 0.f);
631 std::vector<unsigned char> blocked(
count, 0);
632 for (
int clipIndex = 0; clipIndex < database_->
getClipCount(); ++clipIndex) {
633 const auto& clipRanges = perClip[clipIndex];
634 if (clipRanges.empty())
continue;
635 const int begin = database_->clipFrameOffsets_[
static_cast<std::size_t
>(clipIndex)];
636 const int end = database_->clipFrameOffsets_[
static_cast<std::size_t
>(clipIndex + 1)];
639 float best = std::numeric_limits<float>::infinity();
640 for (
const auto&
r : clipRanges) {
641 for (
const auto& block :
r.transitionBlocks)
642 if (
frame.time >= block.start &&
frame.time < block.end) blocked[i] = 1;
643 if (
frame.time + 1e-5f <
r.start ||
frame.time - 1e-5f >
r.end)
continue;
644 float rangeBias =
r.costBias;
645 for (
const auto&
cost :
r.costOverrides)
647 float rangeContinuingBias =
r.continuingCostBias;
648 for (
const auto&
cost :
r.continuingCostOverrides)
650 if (rangeBias <
best) {
652 continuingBias[i] = rangeContinuingBias;
654 if (
r.disableReselection) noReselect[
frame.clipIndex] = 1;
656 if (!std::isfinite(
best))
continue;
662 if (
selected.empty())
return fail(
"candidate selection contains no sampled frames");
664 candidateBias_.swap(
bias);
665 candidateContinuingBias_.swap(continuingBias);
666 candidateMask_.swap(
mask);
667 transitionBlocked_.swap(blocked);
668 disableReselection_.swap(noReselect);
679 "queryPose", {},
"animation"));
681 hasQueryPose_ =
true;
687 std::any_of(samples.begin(), samples.end(),
688 [](
const auto&
s) { return !std::isfinite(s.x) || !std::isfinite(s.z) || !std::isfinite(s.yaw); }))
690 "trajectory requires three finite samples",
691 "trajectory", {},
"animation"));
692 std::copy(samples.begin(), samples.end(), trajectory_.begin());
693 hasTrajectory_ =
true;
eve::EntitySpatialPose pose
eve::resource::CostSpec cost
std::array< float, 4 > rotation
std::shared_ptr< const OceanSprayFrame > previous
std::map< Cell, int > best
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
EVENGINE_API_FOUNDATION public API.
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
float getDuration() const
Returns the duration.
bool getLoop() const
Returns the loop.
void sample(float time, AnimPose *out, const AnimSkeleton *skeleton=nullptr) const
Sample local pose at time (seconds). If skeleton non-null, missing tracks fall back to bind pose; oth...
float wrapTime(float time) const
Wrap or clamp time according to loop flag.
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
int getBoneCount() const noexcept
Returns the bone count.
const TransformTRS & world(int boneIndex) const
World.
void copyFrom(const AnimPose *other)
Copies from.
void computeWorld(const AnimSkeleton *skeleton)
Compute world transforms from local pose + skeleton hierarchy. World values readable via getWorld* af...
void resize(int boneCount)
Resize.
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
int getBoneCount() const
Returns the bone count.
void applyBindPose(class AnimPose *pose) const
Fill pose locals with bind pose.
Baked motion-matching feature database from one or more AnimClips. Feature layout per frame: [0....
void normalizeFeature(std::vector< float > &feature) const
Normalize a query with statistics computed by bake().
AnimSkeleton * getSkeleton() const
Returns the skeleton.
bool hasFeatureLayout() const
Whether this database uses an explicitly configured variable layout.
float getFrameTime(int frameIndex) const
Returns the frame time.
bool isBaked() const
True when baked.
int getFeatureBoneCount() const
Returns the feature bone count.
AnimClip * getClip(int clipIndex) const
Returns the clip.
const Frame & frameAt(int index) const
int getFeatureSize() const
Returns the feature size.
int getRootBone() const
Returns the root bone.
bool hasLocomotionFeatures() const
Whether this database uses the 30-dimensional locomotion layout.
int getFeatureBone(int index) const
Returns the feature bone.
int getFrameCount() const
Returns the frame count.
int getFrameClipIndex(int frameIndex) const
Returns the frame clip index.
int getClipCount() const
Returns the clip count.
void search()
Force an immediate search (also called periodically from update).
void update(float dt)
Legacy seconds facade; explicitly forwards to advance().
void setBlendTime(float seconds)
Sets the blend time.
MotionMatcher(AnimSkeleton *skeleton, MotionDatabase *database)
Motion matcher.
eve::Result< void > setFeatureQuery(const AnimPose ¤t, const AnimPose &previous, float elapsedSeconds, std::span< const MotionFeatureTrajectorySample > samples, std::span< const MotionFeatureCurveSample > curves={})
Atomically copy a query for the database's variable feature layout.
void setDesiredYaw(float yaw)
Desired facing yaw (radians, Y-up).
eve::Result< void > setPoseReselectHistory(float seconds)
Set how long an already selected baked pose is excluded from new candidates.
eve::Result< void > setQueryPose(const AnimPose &pose)
Copy the character's current local pose for the next search, including action handoffs.
void setDesiredVelocity(float x, float z)
Desired planar velocity in character/world XZ (units/sec).
eve::Result< int > setCandidateRanges(std::span< const MotionSearchRange > ranges)
Atomically replace searchable intervals, retaining original database frame IDs.
void setVelocityWeight(float w)
Sets the velocity weight.
eve::Result< void > setLocomotionQuery(const AnimPose ¤t, const AnimPose &previous, float elapsedSeconds, std::span< const MotionLocomotionSample > samples)
Atomically copy pose history and trajectory for a locomotion database.
void setPoseWeight(float w)
Sets the pose weight.
void setTrajectoryWeight(float w)
Sets the trajectory weight.
AnimPose * getPose()
Returns the pose.
void setIgnoreRadius(int frames)
Keep continuous playback within this frame radius of the live playhead, including loop seams.
eve::Result< void > setTrajectory(std::span< const MotionTrajectorySample > samples)
Set predictions at 0.33, 0.66, and 1.0 seconds instead of constant-velocity prediction.
~MotionMatcher()
Motion matcher.
int getMatchedClipIndex() const
Returns the matched clip index.
eve::Result< void > setPlayRateRange(float minimum, float maximum)
Configure the inclusive playback-rate interval used to reconcile query and selected trajectory speed.
void setSearchInterval(float seconds)
Sets the search interval.
eve::Result< void > advance(const eve::SimulationStep &step)
Advance matching and pose blending by one scheduler step.
float locomotionWeight(int index)
Locomotion weight.
eve::Result< eve::SimulationStep > legacyStep(float seconds, bool hasLastTick, eve::SimulationTick lastTick, const char *owner)
Convert a legacy seconds call to the next local scheduler step.
std::array< float, 3 > schemaDifference(const TransformTRS &a, const TransformTRS &b, const TransformTRS &root)
eve::Result< float > secondsForStep(const eve::SimulationStep &step, bool hasLastTick, eve::SimulationTick lastTick, const char *owner)
Validate a scheduler step before an animation object mutates state.
std::array< float, 3 > schemaHeading(const TransformTRS &bone, const TransformTRS &root, int axis)
std::array< float, 3 > schemaRotate(const std::array< float, 3 > &p, const TransformTRS &q, bool inverse=false)
void schemaEncode(std::span< float > output, const MotionFeatureChannel &channel, std::array< float, 3 > value, float lengthScale)
Schema encode.
constexpr int locomotionPoseOffset
void yawToForward(float yaw, float &fx, float &fz)
Rotate unit +Z by yaw (radians) around Y — used for planar facing.
One deterministic fixed-step emitted by SimulationClock.
std::vector< float > feature
Copied trajectory sample at an explicit offset from the current frame.