载入中...
搜索中...
未找到
OrientationWarpingBindings.cpp
浏览该文件的文档.
1#include <functional>
2#include <simplesquirrel/simplesquirrel.hpp>
3#include <stdexcept>
4#include <string>
5#include <vector>
6
13
14namespace eve::animation {
15namespace {
16
17constexpr const char* kSource = "animation.bindings";
18
19std::vector<int> copyBoneArray(ssq::Array values, const char* label, int maximum) {
20 if (values.size() > static_cast<std::size_t>(maximum))
21 throw std::runtime_error(std::string(label) + " exceeds the supported bone count");
22 std::vector<int> bones;
23 bones.reserve(values.size());
24 for (std::size_t i = 0; i < values.size(); ++i) bones.push_back(values.get<int>(i));
25 return bones;
26}
27
28} // namespace
29
30void exposeOrientationWarpingBindings(ssq::Table& table) {
31 const script::BindContext bind{table.getHandle(), kSource};
32 auto cls = table.addClass<OrientationWarping>(
33 "OrientationWarping", std::function<OrientationWarping*()>([] { return new OrientationWarping(); }), true);
35 cls, "configure",
36 [bind](OrientationWarping* self, AnimSkeleton* skeleton, int root, ssq::Array spine, ssq::Array ik) {
37 if (!skeleton) return bind.failInvalid("configure requires a skeleton");
38 try {
39 auto spineBones = copyBoneArray(spine, "spine bones", 32);
40 auto ikBones = copyBoneArray(ik, "ik bones", 16);
41 return script::projectResult(bind.vm(), self->configure(*skeleton, root, spineBones, ikBones));
42 } catch (const std::exception& error) {
43 return bind.failInvalid(error.what());
44 }
45 });
46 script::bindMethod(cls, "setDistributedAlpha", [bind](OrientationWarping* self, float alpha) {
47 return script::projectResult(bind.vm(), self->setDistributedAlpha(alpha));
48 });
50 script::bindMethod(cls, "setAngleThreshold", [bind](OrientationWarping* self, float radians) {
51 return script::projectResult(bind.vm(), self->setAngleThreshold(radians));
52 });
54 script::bindMethod(cls, "setRotationInterpSpeed", [bind](OrientationWarping* self, float speed) {
55 return script::projectResult(bind.vm(), self->setRotationInterpSpeed(speed));
56 });
58 script::bindMethod(cls, "setMinRootMotionSpeed", [bind](OrientationWarping* self, float speed) {
59 return script::projectResult(bind.vm(), self->setMinRootMotionSpeed(speed));
60 });
65 script::bindMethod(cls, "apply",
66 [bind](OrientationWarping* self, AnimPose* pose, float locomotionX, float locomotionZ,
67 float animatedX, float animatedZ, float dt) {
68 if (!pose) return bind.failInvalid("apply requires a pose");
70 bind.vm(), self->apply(*pose, locomotionX, locomotionZ, animatedX, animatedZ, dt));
71 });
78}
79} // namespace eve::animation
int root
Definition AnimSmr.cpp:119
eve::EntitySpatialPose pose
std::string label
HSQOBJECT cls
Definition ECS.cpp:21
std::map< std::string, Var > values
float maximum[3]
std::vector< Bone > bones
std::string error
Definition Package.cpp:60
Per-translation-unit VM + diagnostic-source helper for Squirrel bindings.
The single Squirrel projection for common Result, Status and Value.
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...
Planar orientation warp applied after motion matching, never fed back into search.
int getSpineBoneCount() const
Returns the spine bone count.
eve::Result< void > setDistributedAlpha(float alpha)
Set how much of the warp is distributed onto the spine chain.
AnimSkeleton * getSkeleton() const
Borrowed skeleton from the last successful configure, or null. @ownership Borrowed; ownership remains...
void reset()
Clear smoothed yaw so the next apply starts from zero.
eve::Result< void > apply(AnimPose &pose, float locomotionX, float locomotionZ, float animatedX, float animatedZ, float dt)
Warp a local pose so animated planar velocity aligns with locomotion velocity.
float getAppliedAngle() const
Smoothed yaw last applied to a pose, radians, positive from +Z toward +X.
eve::Result< void > setAngleThreshold(float radians)
Set the inclusive planar-angle magnitude that disables warping.
eve::Result< void > setMinRootMotionSpeed(float metresPerSecond)
Set the planar speed below which either direction is treated as stationary.
eve::Result< void > setRotationInterpSpeed(float speed)
Set how quickly the applied yaw approaches the target, matching Unreal FInterpTo.
int getIkBoneCount() const
Returns the ik bone count.
void setEnabled(bool enabled)
Enable or disable pose mutation. Disabled apply calls still recompute the target.
bool isEnabled() const
True when enabled.
eve::Result< void > configure(AnimSkeleton &skeleton, int rootBone, std::span< const int > spineBones={}, std::span< const int > ikBones={})
Atomically bind a skeleton and bone lists used by later apply calls.
float getTargetAngle() const
Unsmoothed target yaw from the last successful apply, radians.
int getRootBone() const
Returns the root bone.
Pins the active VM and a stable diagnostic source for one expose() TU.
void exposeOrientationWarpingBindings(ssq::Table &table)
Register the owning OrientationWarping Squirrel surface.
void bindMethod(ssq::Class &cls, const char *name, F &&fn)
Register one script method while keeping a literal name for Binding Contracts.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.