载入中...
搜索中...
未找到
AnimationClipRuntime.cpp
浏览该文件的文档.
2
5
7
9 const AnimationClipDocumentTarget& document, const animation::AnimSkeleton* skeleton) const {
10 if (!skeleton)
11 return eve::editing::failed<animation::AnimClip*>(EditorStatus::Rejected,
12 RuleId("editor.animation.skeleton-required"), "Runtime clip building requires a target skeleton");
13 std::vector<std::string> bones;
14 bones.reserve(skeleton->getBoneCount() > 0 ? static_cast<std::size_t>(skeleton->getBoneCount()) : 0);
15 for (int index = 0; index < skeleton->getBoneCount(); ++index) bones.push_back(skeleton->getBoneName(index));
16 const auto diagnostics = document.validate(bones);
17 for (const auto& diagnostic : diagnostics)
18 if (diagnostic.severity() == DiagnosticSeverity::Error)
19 return eve::editing::failed<animation::AnimClip*>(EditorStatus::Rejected,
20 eve::editing::diagnosticRule(diagnostic), diagnostic.message());
21
22 const auto snapshot = document.snapshotValue();
23 const auto* root = snapshot.getIf<EditorValue::Object>();
24 const auto* settings = root ? root->at("settings").getIf<EditorValue::Object>() : nullptr;
25 if (!settings)
26 return eve::editing::failed<animation::AnimClip*>(EditorStatus::Failed,
27 RuleId("editor.animation.runtime-snapshot"), "Clip settings are unavailable");
28 auto* clip = new animation::AnimClip(document.targetId().value());
29 clip->setDuration(static_cast<float>(*settings->at("duration").getIf<double>()));
30 clip->setSampleRate(static_cast<float>(*settings->at("sampleRate").getIf<double>()));
31 clip->setLoop(*settings->at("loop").getIf<bool>());
32 for (const auto& track : document.tracks()) {
33 const int bone = skeleton->findBone(track.bone);
34 for (const auto& key : track.keys) {
35 clip->addPositionKey(bone, static_cast<float>(key.time), static_cast<float>(key.positionX),
36 static_cast<float>(key.positionY), static_cast<float>(key.positionZ));
37 clip->addRotationKey(bone, static_cast<float>(key.time), static_cast<float>(key.rotationX),
38 static_cast<float>(key.rotationY), static_cast<float>(key.rotationZ),
39 static_cast<float>(key.rotationW));
40 clip->addScaleKey(bone, static_cast<float>(key.time), static_cast<float>(key.scaleX),
41 static_cast<float>(key.scaleY), static_cast<float>(key.scaleZ));
42 }
43 }
44 for (const auto& event : document.events())
45 clip->addEvent(static_cast<float>(event.time), event.name, event.payload);
46 return eve::editing::applied<animation::AnimClip*>(clip);
47}
48
49} // namespace eve::animation_editing
int root
Definition AnimSmr.cpp:119
SQObjectPtr key
Definition ECS.cpp:155
glm::vec4 clip
std::vector< Bone > bones
std::uint32_t bone
Snapshot snapshot
OceanWakeSettings settings
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Keyframed skeletal animation clip (local TRS tracks per bone). Script type: AnimClip.
Definition AnimClip.h:145
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.
int findBone(const std::string &name) const
Finds bone.
UI-neutral animation clip document with reversible stable-id timeline edits.
std::vector< EditorDiagnostic > validate(const std::vector< std::string > &skeletonBones={}) const
Validate timeline, references and mask against optional target bone names.
TargetId targetId() const override
Target id.
EditorValue snapshotValue() const override
Capture deterministic schema-version-one clip data.
std::vector< AnimationEventRecord > events() const
Return event markers ordered by time then stable id.
std::vector< AnimationBoneTrack > tracks() const
Return tracks ordered by stable id.
Result< animation::AnimClip * > build(const AnimationClipDocumentTarget &document, const animation::AnimSkeleton *skeleton) const
Build a new runtime clip; caller owns the result.
std::map< std::string, Value > Object
RuleId diagnosticRule(const Diagnostic &diagnostic)
Return the projected editing rule, or an empty RuleId when absent.