载入中...
搜索中...
未找到
AnimInspection.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4#include <utility>
9
10namespace eve::animation {
11AnimInspectionBuilder::AnimInspectionBuilder(std::vector<AnimInspectionTime> times) : times_(std::move(times)) {}
12
14 const AnimSkeleton& skeleton,
15 const AnimSkin& skin) const {
16 using Output = std::vector<AnimInspectionFrame>;
17 auto fail = [](const char* message) {
20 };
21 const int bones = skeleton.getBoneCount(), joints = skin.getBoneCount();
22 if (times_.empty() || times_.size() > 16 || bones <= 0 || bones > 4096 || joints <= 0 || joints > 4096 ||
23 clip.getTrackCount() > bones)
24 return fail("Inspection requires 1..16 samples, 1..4096 bones/joints and compatible clip tracks");
25 if (!std::isfinite(clip.getDuration()) || clip.getDuration() <= 0.f)
26 return fail("Clip duration must be finite and positive");
27 double previous = -1.;
28 for (const auto& time : times_) {
29 if (!std::isfinite(time.timelineTime) || !std::isfinite(time.clipTime) || time.timelineTime < 0. ||
30 time.timelineTime > 1e6 || time.timelineTime <= previous || time.clipTime < 0. ||
31 time.clipTime > double(clip.getDuration()))
32 return fail("Sample times must be finite, strictly ordered on the timeline and inside the clip");
33 previous = time.timelineTime;
34 }
35 std::vector<Mat4> inverseBinds(size_t(joints), Mat4::identity());
36 for (int joint = 0; joint < joints; ++joint) {
37 const int bone = skin.getSkeletonBone(joint);
38 if (bone < 0 || bone >= bones || skin.getSkinBoneName(joint) != skeleton.getBoneName(bone))
39 return fail("Skin joint identity does not match the supplied skeleton");
40 for (int element = 0; element < 16; ++element) {
41 const float value = skin.getInverseBindElement(joint, element);
42 if (!std::isfinite(value)) return fail("Inverse bind matrix is non-finite");
43 inverseBinds[size_t(joint)].m[element] = value;
44 }
45 }
46 Output frames;
47 frames.reserve(times_.size());
49 for (const auto& time : times_) {
50 // Use the canonical sampler with already-resolved time: do not change clip.loop
51 // or call AnimPlayer::setTime/advance, which would affect live playback.
52 clip.sampleClamped(float(time.clipTime), &pose, &skeleton);
53 pose.computeWorld(&skeleton);
54 AnimInspectionFrame frame{time, std::vector<float>(size_t(joints) * 16)};
55 for (int joint = 0; joint < joints; ++joint) {
56 const auto matrix =
57 Mat4::mul(Mat4::fromTRS(pose.world(skin.getSkeletonBone(joint))), inverseBinds[size_t(joint)]);
58 for (float value : matrix.m)
59 if (!std::isfinite(value)) return fail("Sampled palette contains non-finite values");
60 if (matrix.m[3] != 0.f || matrix.m[7] != 0.f || matrix.m[11] != 0.f || matrix.m[15] != 1.f)
61 return fail("Sampled skin matrix must be affine");
62 std::copy_n(matrix.m, 16, frame.palette.begin() + size_t(joint) * 16);
63 }
64 frames.push_back(std::move(frame));
65 }
66 return Result<Output>::success(std::move(frames));
67}
68} // namespace eve::animation
eve::EntitySpatialPose pose
std::string message
glm::vec4 clip
std::vector< Bone > bones
std::uint32_t bone
ssq::Object frame
std::shared_ptr< const OceanSprayFrame > previous
Object::Ptr value
glm::dmat4 matrix
std::string element
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Keyframed skeletal animation clip (local TRS tracks per bone). Script type: AnimClip.
Definition AnimClip.h:145
Result< std::vector< AnimInspectionFrame > > build(const AnimClip &clip, const AnimSkeleton &skeleton, const AnimSkin &skin) const
Evaluate all requested poses into independent palettes or return a diagnostic.
AnimInspectionBuilder(std::vector< AnimInspectionTime > times)
Own an explicit schedule; validation happens atomically in build().
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.
std::string getBoneName(int boneIndex) const
Returns the bone name.
CPU linear-blend skinning binding for one mesh against an AnimSkeleton.
Definition AnimSkin.h:47
int getSkeletonBone(int skinBoneIndex) const
Skeleton bone index used by skin joint i (-1 if unused).
Definition AnimSkin.cpp:104
float getInverseBindElement(int skinBoneIndex, int elementIndex) const
Inverse-bind matrix element (column-major, 0..15) for skin joint i.
Definition AnimSkin.cpp:114
int getBoneCount() const
Returns the bone count.
Definition AnimSkin.h:76
std::string getSkinBoneName(int skinBoneIndex) const
Returns the skin bone name.
Definition AnimSkin.cpp:109
Owning column-major skin palette; joint order is exactly that of the supplied AnimSkin.
static constexpr Mat4 identity() noexcept
Identity.
Definition AnimMath.h:160
static constexpr Mat4 fromTRS(const TransformTRS &t) noexcept
From trs.
Definition AnimMath.h:163
static constexpr Mat4 mul(const Mat4 &a, const Mat4 &b) noexcept
Mul.
Definition AnimMath.h:191