载入中...
搜索中...
未找到
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 for (int index = 0; index < skeleton->getBoneCount(); ++index) bones.push_back(skeleton->getBoneName(index));
15 const auto diagnostics = document.validate(bones);
16 for (const auto& diagnostic : diagnostics)
17 if (diagnostic.severity() == DiagnosticSeverity::Error)
18 return eve::editing::failed<animation::AnimClip*>(EditorStatus::Rejected,
19 eve::editing::diagnosticRule(diagnostic), diagnostic.message());
20
21 const auto snapshot = document.snapshotValue();
22 const auto* root = snapshot.getIf<EditorValue::Object>();
23 const auto* settings = root ? root->at("settings").getIf<EditorValue::Object>() : nullptr;
24 if (!settings)
25 return eve::editing::failed<animation::AnimClip*>(EditorStatus::Failed,
26 RuleId("editor.animation.runtime-snapshot"), "Clip settings are unavailable");
27 auto* clip = new animation::AnimClip(document.targetId().value());
28 clip->setDuration(static_cast<float>(*settings->at("duration").getIf<double>()));
29 clip->setSampleRate(static_cast<float>(*settings->at("sampleRate").getIf<double>()));
30 clip->setLoop(*settings->at("loop").getIf<bool>());
31 for (const auto& track : document.tracks()) {
32 const int bone = skeleton->findBone(track.bone);
33 for (const auto& key : track.keys) {
34 clip->addPositionKey(bone, static_cast<float>(key.time), static_cast<float>(key.positionX),
35 static_cast<float>(key.positionY), static_cast<float>(key.positionZ));
36 clip->addRotationKey(bone, static_cast<float>(key.time), static_cast<float>(key.rotationX),
37 static_cast<float>(key.rotationY), static_cast<float>(key.rotationZ),
38 static_cast<float>(key.rotationW));
39 clip->addScaleKey(bone, static_cast<float>(key.time), static_cast<float>(key.scaleX),
40 static_cast<float>(key.scaleY), static_cast<float>(key.scaleZ));
41 }
42 }
43 for (const auto& event : document.events())
44 clip->addEvent(static_cast<float>(event.time), event.name, event.payload);
45 return eve::editing::applied<animation::AnimClip*>(clip);
46}
47
48} // namespace eve::animation_editing
int root
Definition AnimSmr.cpp:119
std::uint32_t key
glm::vec4 clip
std::vector< Bone > bones
std::uint32_t bone
TerrainThermalSettings settings
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
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
const T * getIf() const
Return an immediately borrowed typed value.
RuleId diagnosticRule(const Diagnostic &diagnostic)
Return the projected editing rule, or an empty RuleId when absent.