载入中...
搜索中...
未找到
AnimationEditingCommands.cpp
浏览该文件的文档.
3
5
6#include <cstdint>
7
9namespace {
10
11const editing::Value* field(const editing::Value& value, const char* key) {
12 const auto* object = value.getIf<editing::Value::Object>();
13 if (!object) return nullptr;
14 const auto found = object->find(key);
15 return found == object->end() ? nullptr : &found->second;
16}
17
18bool readNumber(const editing::Value& value, const char* key, double& out) {
19 const auto* entry = field(value, key);
20 if (!entry) return false;
21 auto number = editing::numericValue(*entry);
22 if (!number) return false;
23 out = number.value();
24 return true;
25}
26
27IAnimationClipEditTarget* clipTarget(editing::IEditableTarget& target) {
28 return static_cast<IAnimationClipEditTarget*>(
30}
31
32editing::Result<void> registerOne(editing::IEditingCommandRegistry& registry, const char* id,
33 const char* displayName, editing::EditingCommandPlanner planner) {
34 editing::EditingCommandDescriptor descriptor;
36 descriptor.ownerModule = "animation_editing";
37 descriptor.displayName = displayName;
38 descriptor.category = "Animation";
39 descriptor.automationAllowed = true;
40 return registry.registerPlannedCommand(std::move(descriptor), std::move(planner));
41}
42
43} // namespace
44
46 auto settings = registerOne(
47 registry, "animation.clip.settings.set.v1", "Set animation clip settings",
49 auto* capability = clipTarget(target);
50 double duration = 0, sampleRate = 0;
51 const editing::Value* loopEntry = field(request.payload, "loop");
52 const auto* loop = loopEntry ? loopEntry->getIf<bool>() : nullptr;
53 if (!capability || !readNumber(request.payload, "duration", duration) ||
54 !readNumber(request.payload, "sampleRate", sampleRate) || !loop)
55 return eve::editing::failed<editing::CommandPlan>(
56 editing::Status::Rejected, editing::RuleId("animation.editing.settings-payload"),
57 "Clip settings require duration, sampleRate and loop");
58 auto operation = capability->makeSetSettings(duration, sampleRate, *loop);
59 if (!operation.ok())
60 return eve::editing::failed<editing::CommandPlan>(
61 operation.code(), editing::RuleId("animation.editing.settings-operation"),
62 "Animation clip rejected the settings");
64 plan.operations.push_back(std::move(operation).takeValue());
65 plan.summary = editing::Value::Object{{"duration", duration}, {"sampleRate", sampleRate}, {"loop", *loop}};
66 return eve::editing::applied<editing::CommandPlan>(std::move(plan));
67 });
68 if (!settings.ok()) return settings;
69
70 auto setTrack = registerOne(
71 registry, "animation.clip.track.set.v1", "Set animation clip bone track",
73 auto* capability = clipTarget(target);
74 if (!capability)
75 return eve::editing::failed<editing::CommandPlan>(editing::Status::Rejected,
76 editing::RuleId("animation.editing.track-target"),
77 "Animation clip track requires a clip target");
78 auto parsed = parseAnimationBoneTrack(request.payload);
79 if (!parsed.ok())
80 return eve::editing::failed<editing::CommandPlan>(parsed.code(),
81 editing::RuleId("animation.editing.track-payload"),
82 "Bone track requires stable id, bone name and keys");
83 auto operation = capability->makeSetTrack(parsed.value());
84 if (!operation.ok())
85 return eve::editing::failed<editing::CommandPlan>(operation.code(),
86 editing::RuleId("animation.editing.track-operation"),
87 "Animation clip rejected the bone track");
89 plan.operations.push_back(std::move(operation).takeValue());
90 plan.summary = editing::Value::Object{{"id", parsed.value().id.value()}, {"bone", parsed.value().bone}};
91 return eve::editing::applied<editing::CommandPlan>(std::move(plan));
92 });
93 if (!setTrack.ok()) return setTrack;
94
95 auto deleteTrack = registerOne(
96 registry, "animation.clip.track.delete.v1", "Delete animation clip bone track",
98 auto* capability = clipTarget(target);
99 const editing::Value* idValue = field(request.payload, "id");
100 const auto* id = idValue ? idValue->getIf<std::string>() : nullptr;
101 if (!capability || !id || id->empty())
102 return eve::editing::failed<editing::CommandPlan>(
103 editing::Status::Rejected, editing::RuleId("animation.editing.track-id"),
104 "Track deletion requires a clip target and stable id");
105 auto operation = capability->makeDeleteTrack(editing::StableId(*id));
106 if (!operation.ok())
107 return eve::editing::failed<editing::CommandPlan>(operation.code(),
108 editing::RuleId("animation.editing.track-delete"),
109 "Animation clip could not delete the bone track");
111 plan.operations.push_back(std::move(operation).takeValue());
112 plan.summary = editing::Value::Object{{"id", *id}};
113 return eve::editing::applied<editing::CommandPlan>(std::move(plan));
114 });
115 if (!deleteTrack.ok()) return deleteTrack;
116
117 auto setEvent = registerOne(
118 registry, "animation.clip.event.set.v1", "Set animation clip event",
120 auto* capability = clipTarget(target);
121 if (!capability)
122 return eve::editing::failed<editing::CommandPlan>(editing::Status::Rejected,
123 editing::RuleId("animation.editing.event-target"),
124 "Animation clip event requires a clip target");
125 auto parsed = parseAnimationEventRecord(request.payload);
126 if (!parsed.ok())
127 return eve::editing::failed<editing::CommandPlan>(parsed.code(),
128 editing::RuleId("animation.editing.event-payload"),
129 "Event requires stable id, time, name and payload");
130 auto operation = capability->makeSetEvent(parsed.value());
131 if (!operation.ok())
132 return eve::editing::failed<editing::CommandPlan>(operation.code(),
133 editing::RuleId("animation.editing.event-operation"),
134 "Animation clip rejected the event");
136 plan.operations.push_back(std::move(operation).takeValue());
137 plan.summary = editing::Value::Object{{"id", parsed.value().id.value()}};
138 return eve::editing::applied<editing::CommandPlan>(std::move(plan));
139 });
140 if (!setEvent.ok()) return setEvent;
141
142 auto deleteEvent = registerOne(
143 registry, "animation.clip.event.delete.v1", "Delete animation clip event",
145 auto* capability = clipTarget(target);
146 const editing::Value* idValue = field(request.payload, "id");
147 const auto* id = idValue ? idValue->getIf<std::string>() : nullptr;
148 if (!capability || !id || id->empty())
149 return eve::editing::failed<editing::CommandPlan>(
150 editing::Status::Rejected, editing::RuleId("animation.editing.event-id"),
151 "Event deletion requires a clip target and stable id");
152 auto operation = capability->makeDeleteEvent(editing::StableId(*id));
153 if (!operation.ok())
154 return eve::editing::failed<editing::CommandPlan>(operation.code(),
155 editing::RuleId("animation.editing.event-delete"),
156 "Animation clip could not delete the event");
158 plan.operations.push_back(std::move(operation).takeValue());
159 plan.summary = editing::Value::Object{{"id", *id}};
160 return eve::editing::applied<editing::CommandPlan>(std::move(plan));
161 });
162 if (!deleteEvent.ok()) return deleteEvent;
163
164 return registerOne(registry, "animation.clip.mask.set.v1", "Set animation clip bone mask",
166 auto* capability = clipTarget(target);
167 const editing::Value* boneValue = field(request.payload, "bone");
168 const auto* bone = boneValue ? boneValue->getIf<std::string>() : nullptr;
169 double weight = 0;
170 if (!capability || !bone || bone->empty() || !readNumber(request.payload, "weight", weight))
171 return eve::editing::failed<editing::CommandPlan>(
172 editing::Status::Rejected, editing::RuleId("animation.editing.mask-payload"),
173 "Mask requires a clip target, bone and weight");
174 auto operation = capability->makeSetMask({*bone, weight});
175 if (!operation.ok())
176 return eve::editing::failed<editing::CommandPlan>(
177 operation.code(), editing::RuleId("animation.editing.mask-operation"),
178 "Animation clip rejected the mask");
180 plan.operations.push_back(std::move(operation).takeValue());
181 plan.summary = editing::Value::Object{{"bone", *bone}, {"weight", weight}};
182 return eve::editing::applied<editing::CommandPlan>(std::move(plan));
183 });
184}
185
186} // namespace eve::animation_editing
LogicalId target
ActionParameterOperation operation
float duration
std::string descriptor
SQObjectPtr key
Definition ECS.cpp:155
const GltfImportRequest & request
std::uint32_t bone
std::string id
OceanWakeSettings settings
const eve::script::BindingContractRegistry & registry
Object::Ptr value
double number
bool found
ScriptStructure out
double weight
Move-only operation result carrying either a value or Status.
Definition Result.h:176
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:313
static CapabilityId editingCapabilityId()
Stable capability id for clip timeline operations.
IEditableTarget public API.
Lower-layer registration boundary implemented by an editor or runtime editing host.
Deterministic owning value tree shared by authoring hosts.
std::map< std::string, Value > Object
const T * getIf() const
Return an immediately borrowed typed value.
Result< AnimationEventRecord > parseAnimationEventRecord(const EditorValue &value)
Parse one authored event marker from an owning Value payload.
editing::Result< void > registerEditingCommands(editing::IEditingCommandRegistry &registry)
Register animation-clip commands with a generic editing host.
Result< AnimationBoneTrack > parseAnimationBoneTrack(const EditorValue &value)
Parse one authored bone track from an owning Value payload.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
std::function< Result< CommandPlan >(IEditableTarget &, const CommandRequest &)> EditingCommandPlanner
Side-effect-free planner invoked with the resolved target.
StrongId< CommandIdTag > CommandId
Definition EditingIds.h:58
Result< double > numericValue(const Value &value)
Read an Integer or Number as an owning double without applying domain validation.
animation_editing::IAnimationClipEditTarget IAnimationClipEditTarget
eve::Result< double > readNumber(const eve::Value::Object &object, std::string_view name)
Reads a required finite number.
CommandPlan public API.
CommandRequest public API.