载入中...
搜索中...
未找到
ClimbingPose.cpp
浏览该文件的文档.
2
6
7#include <algorithm>
8#include <cmath>
9
10namespace eve::climbing {
11namespace {
12
13eve::Result<ClimbingPoseResult> poseFailure(std::string message, std::string path) {
16}
17
18bool validChain(const ClimbingLimbChain& chain, int boneCount) {
19 return chain.root >= 0 && chain.mid >= 0 && chain.tip >= 0 && chain.root < boneCount && chain.mid < boneCount &&
20 chain.tip < boneCount;
21}
22
23Vec3 toModelSpace(Vec3 world, const ClimbingPoseBinding& binding) {
24 const float x = world.x - binding.modelWorldOrigin.x;
25 const float y = world.y - binding.modelWorldOrigin.y;
26 const float z = world.z - binding.modelWorldOrigin.z;
27 const float cosine = std::cos(binding.modelYawRadians);
28 const float sine = std::sin(binding.modelYawRadians);
29 return {cosine * x - sine * z, y, sine * x + cosine * z};
30}
31
32} // namespace
33
35 const ClimbingAdvance& advance, const ClimbingPoseBinding& binding) {
36 if (!std::isfinite(binding.modelYawRadians))
37 return poseFailure("model yaw must be finite", "binding.modelYawRadians");
38 const int boneCount = skeleton.getBoneCount();
39 if (binding.enableLeftHand && !validChain(binding.leftArm, boneCount))
40 return poseFailure("left arm chain contains an invalid bone", "binding.leftArm");
41 if (binding.enableRightHand && !validChain(binding.rightArm, boneCount))
42 return poseFailure("right arm chain contains an invalid bone", "binding.rightArm");
43
44 ClimbingPoseResult result;
45 const float legacyWeight = std::clamp(advance.contactWeight, 0.f, 1.f);
46 const float authoredLeft = std::clamp(advance.leftHandWeight, 0.f, 1.f);
47 const float authoredRight = std::clamp(advance.rightHandWeight, 0.f, 1.f);
48 const bool hasPerHandWeights = authoredLeft > 0.f || authoredRight > 0.f;
49 const float leftWeight = hasPerHandWeights ? authoredLeft : legacyWeight;
50 const float rightWeight = hasPerHandWeights ? authoredRight : legacyWeight;
51 result.weight = std::max(leftWeight, rightWeight);
52 if (result.weight <= 0.f)
54
55 animation::AnimConstraintStack constraints(&skeleton);
56 if (binding.enableLeftHand && leftWeight > 0.f) {
57 const Vec3 target = toModelSpace(advance.leftHandAnchor, binding);
58 constraints.addTwoBoneIK(binding.leftArm.root, binding.leftArm.mid, binding.leftArm.tip, target.x, target.y,
59 target.z, leftWeight);
60 result.leftHandApplied = true;
61 }
62 if (binding.enableRightHand && rightWeight > 0.f) {
63 const Vec3 target = toModelSpace(advance.rightHandAnchor, binding);
64 constraints.addTwoBoneIK(binding.rightArm.root, binding.rightArm.mid, binding.rightArm.tip, target.x, target.y,
65 target.z, rightWeight);
66 result.rightHandApplied = true;
67 }
68 constraints.apply(&pose);
70}
71
72} // namespace eve::climbing
LogicalId target
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
eve::EntitySpatialPose pose
Synchronous Animation TwoBoneIK adapter for climbing contact anchors.
std::string message
eve::action::ActionVfxBinding binding
World3D * world
std::string path
Definition PlayHost.cpp:110
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
Ordered main-thread post-process stack with aim, limb IK and foot planting.
void apply(AnimPose *pose) const
Apply constraints in insertion order and refresh world transforms. Main-thread only.
void addTwoBoneIK(int root, int mid, int tip, float targetX, float targetY, float targetZ, float weight=1.f)
Append a weighted two-bone IK constraint.
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...
int getBoneCount() const
Returns the bone count.
eve::Result< ClimbingPoseResult > applyClimbingPose(animation::AnimSkeleton &skeleton, animation::AnimPose &pose, const ClimbingAdvance &advance, const ClimbingPoseBinding &binding)
Applies contact anchors to an already evaluated animation pose.
Owning output of one execution tick.
Definition Climbing.h:553
Borrowed-pose adapter inputs; no skeleton or pose pointer is retained.
Observable result of applying built-in hand constraints.
Small owning world-space vector used at climbing module boundaries.