载入中...
搜索中...
未找到
AnimationClipPresentation.cpp
浏览该文件的文档.
2
3#include <bit>
4
5namespace eve::animation_editor {
7 const auto targetId = source_.target().targetId().value();
8 return {source_.revision(),
9 std::to_string(targetId.size()) + ":" + targetId + ":" + source_.selectedBone() + ":" +
10 source_.selectedKeyId().value() + ":" +
11 std::to_string(std::bit_cast<std::uint64_t>(source_.playhead())),
12 source_.canUndo(), source_.canRedo(), source_.isPlaying()};
13}
16 schema.typeId = "animation.clip.presentation";
17 auto number = [&](std::string path, std::string label, double minimum, double maximum) {
19 field.path = editor::PropertyPath(std::move(path));
20 field.displayNameKey = std::move(label);
21 field.type = editor::PropertyType::Float;
22 field.numeric.minimum = minimum;
23 field.numeric.maximum = maximum;
24 schema.properties.push_back(std::move(field));
25 };
26 number("duration", "Duration", 0.25, 8.0);
27 number("sample-rate", "Sample rate", 1.0, 120.0);
30 loop.displayNameKey = "Loop";
31 loop.type = editor::PropertyType::Bool;
32 schema.properties.push_back(std::move(loop));
33 number("mask", "Mask", 0.0, 1.0);
34 number("key-time", "Key time", 0.0, source_.duration());
35 if (!source_.hasSelectedKey()) schema.properties.back().flags = editor::PropertyFlag::ReadOnly;
36 for (const auto& group : {std::string("position"), std::string("rotation"), std::string("scale")})
37 for (const char axis : std::string("xyz")) {
38 const double low = group == "rotation" ? -180.0 : group == "scale" ? 0.05 : -4.0;
39 const double high = group == "rotation" ? 180.0 : group == "scale" ? 3.0 : 4.0;
40 number(group + "-" + axis, group + " " + axis, low, high);
41 }
42 return schema;
43}
45 const auto& p = path.value();
47 if (p == "duration")
48 value = source_.duration();
49 else if (p == "sample-rate")
50 value = source_.sampleRate();
51 else if (p == "loop")
52 value = source_.isLooping();
53 else if (p == "mask")
54 value = source_.selectedMaskWeight();
55 else if (p == "key-time")
56 value = source_.selectedKeyTime();
57 else if (p == "position-x")
58 value = source_.selectedPositionX();
59 else if (p == "position-y")
60 value = source_.selectedPositionY();
61 else if (p == "position-z")
62 value = source_.selectedPositionZ();
63 else if (p == "rotation-x")
64 value = source_.selectedRotationX();
65 else if (p == "rotation-y")
66 value = source_.selectedRotationY();
67 else if (p == "rotation-z")
68 value = source_.selectedRotationZ();
69 else if (p == "scale-x")
70 value = source_.selectedScaleX();
71 else if (p == "scale-y")
72 value = source_.selectedScaleY();
73 else if (p == "scale-z")
74 value = source_.selectedScaleZ();
75 else
76 return {};
77 return {editor::PropertyReadState::Value, std::move(value), {}};
78}
81 const auto descriptor = schema().find(path);
82 if (!descriptor || editor::hasPropertyFlag(descriptor->flags, editor::PropertyFlag::ReadOnly))
83 return editing::failed<void>(editor::EditorStatus::Rejected, editor::RuleId("editor.animation.property"),
84 "Property is unavailable");
85 auto valid = editor::validatePropertyValue(*descriptor, value);
86 if (!valid.ok()) return valid;
87 const auto& p = path.value();
88 if (p == "loop") return source_.setLoop(*value.getIf<bool>());
89 const double v = value.getIf<double>() ? *value.getIf<double>() : static_cast<double>(*value.getIf<std::int64_t>());
90 if (p == "duration") return source_.setDuration(v);
91 if (p == "sample-rate") return source_.setSampleRate(v);
92 if (p == "mask") return source_.setMaskWeight(v);
93 if (p == "key-time") return source_.moveSelectedKey(v);
94 if (p.starts_with("position-"))
95 return source_.setSelectedPosition(p == "position-x" ? v : source_.selectedPositionX(),
96 p == "position-y" ? v : source_.selectedPositionY(),
97 p == "position-z" ? v : source_.selectedPositionZ());
98 if (p.starts_with("rotation-"))
99 return source_.setSelectedRotation(p == "rotation-x" ? v : source_.selectedRotationX(),
100 p == "rotation-y" ? v : source_.selectedRotationY(),
101 p == "rotation-z" ? v : source_.selectedRotationZ());
102 if (p.starts_with("scale-"))
103 return source_.setSelectedScale(p == "scale-x" ? v : source_.selectedScaleX(),
104 p == "scale-y" ? v : source_.selectedScaleY(),
105 p == "scale-z" ? v : source_.selectedScaleZ());
106 return editing::failed<void>(editor::EditorStatus::NotFound, editor::RuleId("editor.animation.property"),
107 "Unknown property");
108}
110 if (id == "undo" || id == "redo") {
111 auto result = id == "undo" ? source_.undo() : source_.redo();
112 if (!result.ok()) return editor::Result<void>::failure(result.status());
113 return editing::applied<void>();
114 }
115 if (id == "set-key") return source_.keySelectedBone();
116 if (id == "delete-key") return source_.deleteSelectedKey();
117 if (id == "play-pause") {
118 if (source_.isPlaying())
119 source_.pause();
120 else
121 source_.play();
122 } else if (id == "stop")
123 source_.stop();
124 else
125 return editing::failed<void>(editor::EditorStatus::NotFound, editor::RuleId("editor.animation.action"),
126 "Unknown animation action");
127 return editing::applied<void>();
128}
129} // namespace eve::animation_editor
std::string descriptor
glm::vec4 p[6]
float maximum[3]
float minimum[3]
float v
JointPoint2D axis
std::string label
Poco::JSON::Object::Ptr result
bool valid
std::string path
Definition PlayHost.cpp:111
std::uint32_t targetId
Object::Ptr value
double number
AbilityActivationGroup group
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:313
const std::string & value() const noexcept
Returns the exact legacy or canonical compatibility spelling.
Definition Identity.h:365
TargetId targetId() const override
Target id.
animation_editing::Result< void > setDuration(double duration)
Commit clip duration through the document transaction path.
animation_editing::Result< void > setMaskWeight(double weight)
double selectedScaleX() const
Selected scale x.
double duration() const noexcept
Duration.
double selectedRotationX() const
Selected rotation x.
double selectedScaleY() const
Selected scale y.
bool isLooping() const noexcept
True when looping.
animation_editing::Result< void > setSelectedScale(double x, double y, double z)
Replace the selected bone scale at the playhead and create a key when needed.
std::string selectedBone() const
Selected bone.
animation_editing::Result< void > setSelectedRotation(double xDegrees, double yDegrees, double zDegrees)
Replace the selected bone Euler rotation in degrees and create a key when needed.
double playhead() const noexcept
Playhead.
std::uint64_t revision() const noexcept
Revision.
double sampleRate() const noexcept
Sample rate.
animation_editing::StableId selectedKeyId() const
Owning stable identity of the selected key, or empty for a bone-only selection.
double selectedPositionY() const
Selected position y.
animation_editing::Result< void > deleteSelectedKey()
Delete the selected transform key.
animation_editing::Result< void > moveSelectedKey(double time)
animation_editing::Result< editor::TransactionReceipt > undo()
animation_editing::Result< void > setLoop(bool loop)
Commit looping through the document transaction path.
double selectedRotationY() const
Selected rotation y.
double selectedPositionX() const
Selected position x.
double selectedRotationZ() const
Selected rotation z.
animation_editing::Result< void > setSampleRate(double sampleRate)
Commit authored sample rate through the document transaction path.
bool hasSelectedKey() const noexcept
True when selected key.
double selectedKeyTime() const
Selected key time.
double selectedScaleZ() const
Selected scale z.
animation_editing::Result< void > keySelectedBone()
Insert or replace a transform key for the selected bone at the playhead.
animation_editing::Result< void > setSelectedPosition(double x, double y, double z)
Replace the selected bone position at the playhead and create a key when needed.
double selectedPositionZ() const
Selected position z.
const animation_editing::AnimationClipDocumentTarget & target() const noexcept
Borrow the authoritative clip document.
bool isPlaying() const noexcept
True when playing.
animation_editing::Result< editor::TransactionReceipt > redo()
editor::PropertySchema schema() const override
Owning schema; field identity is its canonical property path.
editor::Result< void > write(const editor::PropertyPath &path, const editor::EditorValue &value) override
Commit one validated field through the domain's existing transaction path.
editor::WorkspacePresentationState state() const override
Snapshot of document revision, selection/playhead context and history availability.
editor::Result< void > action(std::string_view id) override
Execute a domain action, including undo/redo on its sole history backend.
editor::PropertyReadResult read(const editor::PropertyPath &path) const override
Read a field for the current selection without mutation.
Dotted property path (layout.size) compared and persisted as text.
Definition EditingIds.h:78
Deterministic owning value tree shared by authoring hosts.
eve::editing::PropertyPath PropertyPath
Definition EditorIds.h:37
PropertyDescriptor public API.
PropertyReadResult public API.
EVENGINE_API_PLATFORM public API.
std::vector< PropertyDescriptor > properties
PropertyDescriptorLookup find(const PropertyPath &path) const
Finds find.
Owning state projection; the bound domain remains the only document/history owner.