载入中...
搜索中...
未找到
SceneComponentPayload.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4#include <cstdint>
5#include <limits>
6#include <set>
9
10// SceneComponentPayload.cpp
11namespace eve::scene_editing {
12namespace {} // namespace
13
15 : componentType_(std::move(componentType)) {}
16
19 Validator validator) {
20 if (componentType_.empty() || component.target.empty() || component.object.empty() || component.component.empty() ||
21 component.type != componentType_ || !properties || !operations ||
22 moduleSelection.target != TargetId(operations->targetId()))
23 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.scene.component-binding-invalid"),
24 "Component binding requires matching stable ids and module targets");
25 if (find(component.target, component.component))
26 return eve::editing::failed<void>(EditorStatus::Conflict, RuleId("editor.scene.component-binding-duplicate"),
27 "Scene component is already bound: " + component.component.value());
28 component.revision = operations->revision();
29 bindings_.push_back(
30 {std::move(component), std::move(moduleSelection), properties, operations, std::move(validator)});
31 return eve::editing::applied<void>();
32}
33
35 const auto found = std::find_if(bindings_.begin(), bindings_.end(), [&](const Binding& binding) {
36 return binding.component.target == scene && binding.component.component == component;
37 });
38 if (found == bindings_.end()) return SceneComponentChange::Unchanged;
39 bindings_.erase(found);
41}
42
43const SceneComponentPropertyBindings::Binding* SceneComponentPropertyBindings::find(const TargetId& scene,
44 const StableId& component) const {
45 const auto found = std::find_if(bindings_.begin(), bindings_.end(), [&](const Binding& binding) {
46 return binding.component.target == scene && binding.component.component == component;
47 });
48 return found == bindings_.end() ? nullptr : &*found;
49}
50
51std::vector<SceneComponentPayloadRef> SceneComponentPropertyBindings::components(const TargetId& scene,
52 const ObjectId& object) const {
53 std::vector<SceneComponentPayloadRef> result;
54 for (const Binding& binding : bindings_) {
55 if (binding.component.target != scene || binding.component.object != object) continue;
56 SceneComponentPayloadRef component = binding.component;
57 component.revision = binding.operations->revision();
58 result.push_back(std::move(component));
59 }
60 return result;
61}
62
64SceneComponentPropertyBindings::translate(const SelectionSnapshot& selection) const {
65 if (selection.items.empty())
66 return eve::editing::failed<std::pair<const Binding*, SelectionSnapshot>>(
67 EditorStatus::Rejected, RuleId("editor.scene.component-selection-empty"),
68 "Component property selection cannot be empty");
69 const Binding* first = find(selection.items.front().target, selection.items.front().item);
70 if (!first || selection.items.front().type != componentType_)
71 return eve::editing::failed<std::pair<const Binding*, SelectionSnapshot>>(
72 EditorStatus::NotFound, RuleId("editor.scene.component-binding-missing"),
73 "Selected scene component is not bound to this provider");
74 SelectionSnapshot translated;
75 translated.channel = selection.channel;
76 translated.sequence = selection.sequence;
77 for (const SelectionItem& item : selection.items) {
78 const Binding* binding = find(item.target, item.item);
79 if (!binding || item.type != componentType_ || binding->properties != first->properties ||
80 binding->operations != first->operations)
81 return eve::editing::failed<std::pair<const Binding*, SelectionSnapshot>>(
82 EditorStatus::Rejected, RuleId("editor.scene.component-binding-mixed-target"),
83 "Multi-edit requires components owned by one module property target");
84 translated.items.push_back(binding->moduleSelection);
85 }
86 translated.primary = translated.items.front();
87 return eve::editing::applied<std::pair<const Binding*, SelectionSnapshot>>({first, std::move(translated)});
88}
89
91 const SelectionSnapshot& selection) const {
92 auto translated = translate(selection);
93 if (!translated.ok()) return Result<IDomainOperationTarget*>::failure(translated.status());
94 return eve::editing::applied<IDomainOperationTarget*>(translated.value().first->operations);
95}
96
98 const SceneComponentPayloadRef& component) const {
99 const Binding* binding = find(component.target, component.component);
100 if (!binding)
102 RuleId("editor.scene.component-binding-missing"),
103 DiagnosticSeverity::Error, "Scene component binding no longer exists")};
104 return binding->validator ? binding->validator() : std::vector<EditorDiagnostic>{};
105}
106
108 auto translated = translate(selection);
109 if (!translated.ok())
111 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "Scene component selection is not bound",
112 "editor.scene.component-binding", {}, "editor.SceneComponentPropertyBindings"));
113 return translated.value().first->properties->currentRevision(translated.value().second);
114}
115
117 auto translated = translate(selection);
118 if (!translated.ok()) return {};
119 return translated.value().first->properties->schema(translated.value().second);
120}
121
123 const PropertyPath& path) const {
124 auto translated = translate(selection);
125 if (!translated.ok()) return {PropertyReadState::Error, {}, translated.diagnostics()};
126 return translated.value().first->properties->read(translated.value().second, path);
127}
128
130 const PropertyPath& path, const EditorValue& value,
131 PropertySetMode mode) const {
132 auto translated = translate(selection);
133 if (!translated.ok()) return Result<DomainOperation>::failure(translated.status());
134 return translated.value().first->properties->makeSet(translated.value().second, path, value, mode);
135}
136
138 const PropertyPath& path) const {
139 auto translated = translate(selection);
140 if (!translated.ok()) return Result<DomainOperation>::failure(translated.status());
141 return translated.value().first->properties->makeReset(translated.value().second, path);
142}
143
144Result<void> SceneComponentPayloadRegistry::registerProvider(std::shared_ptr<ISceneComponentPayloadProvider> provider) {
145 if (!provider || provider->componentType().empty())
146 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.scene.component-provider-invalid"),
147 "Component payload provider and type are required");
148 const auto type = provider->componentType();
149 auto published = providers_.publish(type, std::move(provider));
150 if (!published.ok())
151 return eve::editing::failed<void>(EditorStatus::Conflict, RuleId("editor.scene.component-provider-duplicate"),
152 "A component payload provider is already registered for type: " + type);
153 return eve::editing::applied<void>();
154}
155
158 auto found = providers_.acquire(provider->componentType());
159 if (!found.ok() || found.value().provider.get() != provider) return SceneComponentChange::Unchanged;
160 return providers_.withdraw(found.value().handle).ok() ? SceneComponentChange::Changed
162}
163
165 const TargetId& scene, const ObjectId& object) const {
166 if (scene.empty() || object.empty())
167 return eve::editing::failed<std::vector<SceneComponentPayloadRef>>(
168 EditorStatus::Rejected, RuleId("editor.scene.component-owner-invalid"),
169 "Scene target and object ids are required for component discovery");
170 std::vector<SceneComponentPayloadRef> result;
171 for (const auto& entry : providers_.snapshot()) {
172 const auto& type = entry.handle.id;
173 const auto& provider = entry.provider;
174 auto components = provider->components(scene, object);
175 for (SceneComponentPayloadRef& component : components) {
176 if (component.target != scene || component.object != object || component.type != type ||
177 component.component.empty())
178 return eve::editing::failed<std::vector<SceneComponentPayloadRef>>(
179 EditorStatus::Failed, RuleId("editor.scene.component-provider-contract"),
180 "Component provider returned an invalid or foreign stable reference: " + type);
181 result.push_back(std::move(component));
182 }
183 }
184 std::sort(result.begin(), result.end(), [](const auto& left, const auto& right) {
185 if (left.type != right.type) return left.type < right.type;
186 return left.component < right.component;
187 });
188 return eve::editing::applied<std::vector<SceneComponentPayloadRef>>(std::move(result));
189}
190
191Result<std::shared_ptr<ISceneComponentPayloadProvider>> SceneComponentPayloadRegistry::resolve(
192 const SelectionSnapshot& selection) const {
193 if (selection.items.empty())
194 return eve::editing::failed<std::shared_ptr<ISceneComponentPayloadProvider>>(
195 EditorStatus::Rejected, RuleId("editor.scene.component-selection-empty"),
196 "Component property selection cannot be empty");
197 const std::string& type = selection.items.front().type;
198 if (type.empty())
199 return eve::editing::failed<std::shared_ptr<ISceneComponentPayloadProvider>>(
200 EditorStatus::Rejected, RuleId("editor.scene.component-selection-type"),
201 "Component property selection requires a stable component type");
202 for (const SelectionItem& item : selection.items) {
203 if (item.domain != SelectionDomain::Scene || item.type != type || item.item.empty())
204 return eve::editing::failed<std::shared_ptr<ISceneComponentPayloadProvider>>(
205 EditorStatus::Rejected, RuleId("editor.scene.component-selection-mixed"),
206 "Component property selections must contain one non-empty component type");
207 }
208 auto found = providers_.acquire(type);
209 if (!found.ok())
210 return eve::editing::failed<std::shared_ptr<ISceneComponentPayloadProvider>>(
211 EditorStatus::Unsupported, RuleId("editor.scene.component-provider-missing"),
212 "No component payload provider is registered for type: " + type);
213 return eve::editing::applied<std::shared_ptr<ISceneComponentPayloadProvider>>(found.value().provider);
214}
215
217 auto provider = resolve(selection);
218 if (!provider.ok()) return Result<IPropertyProvider*>::failure(provider.status());
219 return eve::editing::applied<IPropertyProvider*>(static_cast<IPropertyProvider*>(provider.value().get()));
220}
221
223 const SelectionSnapshot& selection) const {
224 auto provider = resolve(selection);
226 return provider.value()->payloadOperationTarget(selection);
227}
228
230 const SceneComponentPayloadRef& component) const {
231 auto found = providers_.acquire(component.type);
232 if (!found.ok())
233 return eve::editing::failed<std::vector<EditorDiagnostic>>(
234 EditorStatus::Unsupported, RuleId("editor.scene.component-provider-missing"),
235 "No component payload provider is registered for type: " + component.type);
236 const auto current = found.value().provider->components(component.target, component.object);
237 const auto matching = std::find_if(current.begin(), current.end(), [&](const auto& candidate) {
238 return candidate.component == component.component && candidate.type == component.type;
239 });
240 if (matching == current.end())
241 return eve::editing::failed<std::vector<EditorDiagnostic>>(
242 EditorStatus::NotFound, RuleId("editor.scene.component-reference-missing"),
243 "The referenced component no longer exists: " + component.component.value());
244 if (matching->generation != component.generation || matching->revision != component.revision)
245 return eve::editing::failed<std::vector<EditorDiagnostic>>(
246 EditorStatus::Conflict, RuleId("editor.scene.component-reference-stale"),
247 "The component changed since its inspector reference was captured: " + component.component.value());
248 return eve::editing::applied<std::vector<EditorDiagnostic>>(found.value().provider->validateComponent(component));
249}
250
252 const std::vector<SceneComponentPayloadRef>& components,
253 std::uint64_t sequence) {
254 if (components.empty())
255 return eve::editing::failed<SelectionSnapshot>(EditorStatus::Rejected,
256 RuleId("editor.scene.component-selection-empty"),
257 "At least one component is required");
258 const std::string& type = components.front().type;
260 result.channel = std::move(channel);
261 result.sequence = sequence;
262 for (const SceneComponentPayloadRef& component : components) {
263 if (component.component.empty() || component.target.empty() || component.type.empty() || component.type != type)
264 return eve::editing::failed<SelectionSnapshot>(EditorStatus::Rejected,
265 RuleId("editor.scene.component-selection-mixed"),
266 "All selected components must have one non-empty type");
267 result.items.push_back({SelectionDomain::Scene, component.target, component.component, component.type});
268 }
269 result.primary = result.items.front();
270 return eve::editing::applied<SelectionSnapshot>(std::move(result));
271}
272
273} // namespace eve::scene_editing
274
275// SceneEditingCommands.cpp
280
281#include <cstdint>
282#include <set>
283
284namespace eve::scene_editing {
285namespace {
286
287const editing::Value* field(const editing::Value& value, const char* key) {
288 const auto* object = value.getIf<editing::Value::Object>();
289 if (!object) return nullptr;
290 const auto found = object->find(key);
291 return found == object->end() ? nullptr : &found->second;
292}
293
294bool assignVector3(const editing::Value& payload, const char* key, double& x, double& y, double& z) {
295 const editing::Value* entry = field(payload, key);
296 if (!entry) return true;
297 const auto* values = entry->getIf<editing::Value::Array>();
298 if (!values || values->size() != 3) return false;
299 const auto number = [](const editing::Value& value, double& output) {
300 if (const auto* real = value.getIf<double>()) {
301 output = *real;
302 return true;
303 }
304 if (const auto* integer = value.getIf<std::int64_t>()) {
305 output = static_cast<double>(*integer);
306 return true;
307 }
308 return false;
309 };
310 return number((*values)[0], x) && number((*values)[1], y) && number((*values)[2], z);
311}
312
313} // namespace
314
317 descriptor.id = editing::CommandId("scene.transform.set.v1");
318 descriptor.ownerModule = "scene_editing";
319 descriptor.displayName = "Set scene transform";
320 descriptor.category = "Scene";
321 descriptor.automationAllowed = true;
322 auto transformRegistered = registry.registerPlannedCommand(
324 auto* capability =
326 const editing::Value* objectValue = field(request.payload, "object");
327 const auto* object = objectValue ? objectValue->getIf<std::string>() : nullptr;
328 if (!capability || !object)
329 return eve::editing::failed<editing::CommandPlan>(
330 editing::Status::Rejected, editing::RuleId("scene.editing.transform-payload"),
331 "Scene transform requires a transform target and object id");
332 auto current = capability->readTransform(editing::ObjectId(*object));
333 if (!current.ok())
334 return eve::editing::failed<editing::CommandPlan>(current.code(),
335 editing::RuleId("scene.editing.transform-object"),
336 "Scene object transform is unavailable");
337 SceneTransformValue transform = current.value();
338 if (!assignVector3(request.payload, "position", transform.x, transform.y, transform.z) ||
339 !assignVector3(request.payload, "rotation", transform.rotationX, transform.rotationY,
340 transform.rotationZ) ||
341 !assignVector3(request.payload, "scale", transform.scaleX, transform.scaleY, transform.scaleZ))
342 return eve::editing::failed<editing::CommandPlan>(
343 editing::Status::Rejected, editing::RuleId("scene.editing.transform-vector"),
344 "Position, rotation and scale must contain three numbers");
345 auto operation = capability->makeSetTransform(editing::ObjectId(*object), transform);
346 if (!operation.ok())
347 return eve::editing::failed<editing::CommandPlan>(operation.code(),
348 editing::RuleId("scene.editing.transform-operation"),
349 "Scene target rejected the transform");
351 plan.operations.push_back(std::move(operation.value()));
352 plan.summary = editing::Value::Object{{"object", *object}};
353 return eve::editing::applied<editing::CommandPlan>(std::move(plan));
354 });
355 if (!transformRegistered.ok()) return transformRegistered;
357 batchTransform.id = editing::CommandId("scene.transform.batch.set.v1");
358 batchTransform.ownerModule = "scene_editing";
359 batchTransform.displayName = "Set scene transforms";
360 batchTransform.category = "Scene";
361 batchTransform.automationAllowed = true;
362 auto batchRegistered = registry.registerPlannedCommand(
363 std::move(batchTransform), [](editing::IEditableTarget& target, const editing::CommandRequest& request) {
364 auto capability = target.capability<ITransformEditTarget>();
365 const auto* values = field(request.payload, "transforms");
366 const auto* transforms = values ? values->getIf<editing::Value::Array>() : nullptr;
367 if (!capability || !transforms || transforms->empty())
368 return eve::editing::failed<editing::CommandPlan>(
369 editing::Status::Rejected, editing::RuleId("scene.editing.batch-transform-payload"),
370 "Batch transform requires a nonempty transforms array");
372 std::set<editing::ObjectId> ids;
373 for (const auto& value : *transforms) {
374 const auto* objectValue = field(value, "object");
375 const auto* object = objectValue ? objectValue->getIf<std::string>() : nullptr;
376 if (!object || object->empty() || !ids.emplace(*object).second)
377 return eve::editing::failed<editing::CommandPlan>(
378 editing::Status::Rejected, editing::RuleId("scene.editing.batch-transform-object"),
379 "Batch transform object ids must be nonempty and unique");
380 auto current = capability->get().readTransform(editing::ObjectId(*object));
382 auto transform = current.value();
383 if (!assignVector3(value, "position", transform.x, transform.y, transform.z) ||
384 !assignVector3(value, "rotation", transform.rotationX, transform.rotationY, transform.rotationZ) ||
385 !assignVector3(value, "scale", transform.scaleX, transform.scaleY, transform.scaleZ))
386 return eve::editing::failed<editing::CommandPlan>(
387 editing::Status::Rejected, editing::RuleId("scene.editing.batch-transform-vector"),
388 "Batch TRS vectors must contain three numbers");
389 auto operation = capability->get().makeSetTransform(editing::ObjectId(*object), transform);
391 plan.operations.push_back(std::move(operation.value()));
392 }
393 plan.summary = editing::Value::Object{{"count", static_cast<std::int64_t>(transforms->size())}};
394 return editing::applied<editing::CommandPlan>(std::move(plan));
395 });
396 if (!batchRegistered.ok()) return batchRegistered;
397 for (const std::string action : {"create", "delete", "rename", "reparent"}) {
399 entry.id = editing::CommandId("scene.object." + action + ".v1");
400 entry.ownerModule = "scene_editing";
401 entry.displayName = "Scene object " + action;
402 entry.category = "Scene";
403 auto registered = registry.registerPlannedCommand(
405 auto hierarchy = target.capability<ISceneHierarchyEditTarget>();
406 if (!hierarchy)
407 return eve::editing::failed<editing::CommandPlan>(
408 editing::Status::Unsupported, editing::RuleId("scene.editing.hierarchy-unavailable"),
409 "Target does not support scene hierarchy editing");
410 const auto* idValue = field(request.payload, "object");
411 const auto* id = idValue ? idValue->getIf<std::string>() : nullptr;
412 if (!id || id->empty())
413 return eve::editing::failed<editing::CommandPlan>(editing::Status::Rejected,
414 editing::RuleId("scene.editing.object-required"),
415 "A nonempty object id is required");
416 const auto* nameValue = field(request.payload, "name");
417 const auto* name = nameValue ? nameValue->getIf<std::string>() : nullptr;
418 const auto* parentValue = field(request.payload, "parent");
419 const auto* parent = parentValue ? parentValue->getIf<std::string>() : nullptr;
420 if ((nameValue && !name) || (parentValue && !parent) || (action == "rename" && !name) ||
421 (action == "reparent" && !parent))
422 return eve::editing::failed<editing::CommandPlan>(
423 editing::Status::Rejected, editing::RuleId("scene.editing.hierarchy-payload"),
424 "Name and parent must be strings");
426 if (action == "delete") return hierarchy->get().makeDelete(editing::ObjectId(*id));
427 if (action == "rename") return hierarchy->get().makeRename(editing::ObjectId(*id), *name);
428 if (action == "reparent")
429 return hierarchy->get().makeReparent(editing::ObjectId(*id), editing::ObjectId(*parent));
431 create.id = editing::ObjectId(*id);
432 create.name = name ? *name : *id;
434 auto& t = create.transform;
435 if (!assignVector3(request.payload, "position", t.x, t.y, t.z) ||
436 !assignVector3(request.payload, "rotation", t.rotationX, t.rotationY, t.rotationZ) ||
437 !assignVector3(request.payload, "scale", t.scaleX, t.scaleY, t.scaleZ))
438 return eve::editing::failed<editing::DomainOperation>(
439 editing::Status::Rejected, editing::RuleId("scene.editing.create-vector"),
440 "TRS vectors require three numbers");
441 return hierarchy->get().makeCreate(create);
442 }();
445 plan.operations.push_back(std::move(operation.value()));
446 return editing::applied<editing::CommandPlan>(std::move(plan));
447 });
448 if (!registered.ok()) return registered;
449 }
451 update.id = editing::CommandId("scene.object.update.v1");
452 update.ownerModule = "scene_editing";
453 update.displayName = "Edit scene object properties";
454 update.category = "Scene";
455 auto updated = registry.registerPlannedCommand(
456 std::move(update),
459 auto hierarchy = target.capability<ISceneHierarchyEditTarget>();
460 auto transforms = target.capability<ITransformEditTarget>();
461 const auto* idValue = field(request.payload, "object");
462 const auto* id = idValue ? idValue->getIf<std::string>() : nullptr;
463 if (!hierarchy || !transforms || !id)
464 return eve::editing::failed<editing::CommandPlan>(editing::Status::Rejected,
465 editing::RuleId("scene.editing.update-payload"),
466 "Scene object and editing capabilities are required");
467 auto current = transforms->get().readTransform(editing::ObjectId(*id));
469 auto t = current.value();
470 if (!assignVector3(request.payload, "position", t.x, t.y, t.z) ||
471 !assignVector3(request.payload, "rotation", t.rotationX, t.rotationY, t.rotationZ) ||
472 !assignVector3(request.payload, "scale", t.scaleX, t.scaleY, t.scaleZ))
473 return eve::editing::failed<editing::CommandPlan>(
474 editing::Status::Rejected, editing::RuleId("scene.editing.update-vector"), "Invalid TRS vector");
475 auto transform = transforms->get().makeSetTransform(editing::ObjectId(*id), t);
476 if (!transform.ok()) return editing::Result<editing::CommandPlan>::failure(transform.status());
478 plan.operations.push_back(std::move(transform.value()));
479 for (const auto* key : {"name", "parent"}) {
480 const auto* value = field(request.payload, key);
481 if (!value) continue;
482 const auto* text = value->getIf<std::string>();
483 if (!text)
484 return eve::editing::failed<editing::CommandPlan>(editing::Status::Rejected,
485 editing::RuleId("scene.editing.update-text"),
486 "Name and parent must be strings");
487 auto operation = std::string_view(key) == "name"
488 ? hierarchy->get().makeRename(editing::ObjectId(*id), *text)
489 : hierarchy->get().makeReparent(editing::ObjectId(*id), editing::ObjectId(*text));
491 plan.operations.push_back(std::move(operation.value()));
492 }
493 return editing::applied<editing::CommandPlan>(std::move(plan));
494 });
495 if (!updated.ok()) return updated;
497 restore.id = editing::CommandId("scene.snapshot.restore.v1");
498 restore.ownerModule = "scene_editing";
499 restore.displayName = "Restore scene hierarchy and transforms";
500 restore.category = "Scene";
501 auto restored = registry.registerPlannedCommand(
502 std::move(restore),
505 auto* scene = dynamic_cast<SceneTargetBase*>(&value);
506 if (!scene)
507 return eve::editing::failed<editing::CommandPlan>(editing::Status::Unsupported,
508 editing::RuleId("scene.restore.target"),
509 "Target does not support scene snapshots");
510 auto operation = scene->makeRestore(request.payload);
513 plan.operations.push_back(std::move(operation.value()));
514 return editing::applied<editing::CommandPlan>(std::move(plan));
515 });
516 if (!restored.ok()) return restored;
518 if (!placement.ok()) return placement;
520}
521
522} // namespace eve::scene_editing
523
524// SceneSnapshot.cpp
525namespace eve::scene_editing {
526
527Result<std::map<ObjectId, SceneObjectSnapshot>> SceneTargetBase::parseSnapshot(const EditorValue& value) {
528 using Objects = std::map<ObjectId, SceneObjectSnapshot>;
529 const auto reject = [](const char* message) {
530 return editing::failed<Objects>(EditorStatus::Rejected, RuleId("scene.snapshot.invalid"), message);
531 };
532 const auto* root = value.getIf<EditorValue::Object>();
533 if (!root || !root->contains("schemaVersion") || !root->contains("objects") ||
534 root->size() != (root->contains("schemaId") ? 3u : 2u))
535 return reject("Scene snapshot requires schemaId, schemaVersion and objects");
536 if (root->contains("schemaId")) {
537 const auto* schema = root->at("schemaId").getIf<std::string>();
538 if (!schema || *schema != "eve.scene.hierarchy") return reject("Unknown scene schema id");
539 }
540 const auto* version = root->at("schemaVersion").getIf<std::int64_t>();
541 const auto* entries = root->at("objects").getIf<EditorValue::Array>();
542 if (!version || *version != 1 || !entries) return reject("Unsupported scene snapshot schema");
543 Objects objects;
544 for (const auto& entry : *entries) {
545 const auto* fields = entry.getIf<EditorValue::Object>();
546 if (!fields || fields->size() != 4 || !fields->contains("transform"))
547 return reject("Scene object requires id, parent, name and transform");
548 const auto* transform = fields->at("transform").getIf<EditorValue::Object>();
549 if (!transform || transform->size() != 9) return reject("Scene transform requires all nine TRS fields");
550 // JSON parsers may decode integral floating point values as integers.
551 EditorValue normalized = entry;
552 auto& normalizedTransform =
553 *normalized.getIf<EditorValue::Object>()->at("transform").getIf<EditorValue::Object>();
554 for (const auto* key : {"x", "y", "z", "rotationX", "rotationY", "rotationZ", "scaleX", "scaleY", "scaleZ"}) {
555 const auto found = transform->find(key);
556 if (found == transform->end()) return reject("Unknown or missing transform field");
557 double number;
558 if (const auto* real = found->second.getIf<double>())
559 number = *real;
560 else if (const auto* integer = found->second.getIf<std::int64_t>())
561 number = static_cast<double>(*integer);
562 else
563 return reject("Transform fields must be numbers");
564 if (!std::isfinite(number) || std::abs(number) > std::numeric_limits<float>::max())
565 return reject("Transform must be finite and representable by the scene runtime");
566 if (std::string_view(key).starts_with("scale") && static_cast<float>(number) == 0.f)
567 return reject("Scene scale must be nonzero");
568 normalizedTransform[key] = number;
569 }
570 auto parsed = parseObject(normalized);
571 if (!parsed.ok()) return Result<Objects>::failure(parsed.status());
572 auto object = std::move(parsed.value());
573 if (object.id.empty() || object.name.empty() || objects.contains(object.id))
574 return reject("Object ids must be unique and names nonempty");
575 objects.emplace(object.id, std::move(object));
576 }
577 for (const auto& [id, object] : objects) {
578 std::set<ObjectId> visited{id};
579 auto parent = object.parent;
580 while (!parent.empty()) {
581 if (!objects.contains(parent)) return reject("Scene parent does not exist");
582 if (!visited.insert(parent).second) return reject("Scene hierarchy contains a cycle");
583 parent = objects.at(parent).parent;
584 }
585 }
586 return editing::applied<Objects>(std::move(objects));
587}
588
590 auto validated = parseSnapshot(snapshot);
591 if (!validated.ok()) return Result<DomainOperation>::failure(validated.status());
593 operation.type = operation.inverseType = "scene.snapshot.restore.v1";
594 operation.target = targetId();
595 operation.payload = snapshot;
596 operation.inverse = snapshotValue();
597 operation.hasInverse = true;
598 for (const auto& [id, object] : objects_) operation.affectedObjects.push_back({targetId(), id.value(), 0});
599 for (const auto& [id, object] : validated.value())
600 if (!objects_.contains(id)) operation.affectedObjects.push_back({targetId(), id.value(), 0});
601 return editing::applied<DomainOperation>(std::move(operation));
602}
603} // namespace eve::scene_editing
double z
double y
double x
LogicalId target
ActionParameterOperation operation
Value::Object payload
int root
Definition AnimSmr.cpp:119
std::string output
std::string descriptor
std::unordered_map< std::string, QuestRuntime > entries
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
std::vector< std::string > fields
Definition ECS.cpp:42
std::string message
const GltfImportRequest & request
HexVec3 left
HexVec3 right
std::int32_t first
const ColourScope * parent
std::map< std::string, PropertyRule > properties
std::string id
Poco::JSON::Object::Ptr result
Snapshot snapshot
Placement placement
std::unique_ptr< gpgpu::Sequence > sequence
Definition OnnxGpgpu.cpp:43
eve::action::ActionVfxBinding binding
std::array< std::uint64_t, kPixelChunkSize *kPixelChunkSize > updated
std::string action
Definition PlayHost.cpp:118
std::string path
Definition PlayHost.cpp:111
std::uint32_t targetId
std::weak_ptr< PrimitiveScene > scene
std::set< std::string > values
const eve::script::BindingContractRegistry & registry
Object::Ptr value
float t
double number
bool found
std::string text
double current
Json object
std::size_t at
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 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
bool empty() const noexcept
True when no compatibility spelling has been assigned.
Definition Identity.h:377
Editable-target capability that applies owning domain operations.
IEditableTarget public API.
virtual TargetId targetId() const =0
Target id.
virtual std::uint64_t revision() const =0
Revision.
Lower-layer registration boundary implemented by an editor or runtime editing host.
UI-independent property access for an immutable selection snapshot.
Dotted property path (layout.size) compared and persisted as text.
Definition EditingIds.h:78
Deterministic owning value tree shared by authoring hosts.
std::vector< Value > Array
std::map< std::string, Value > Object
const T * getIf() const
Return an immediately borrowed typed value.
Module-owned adapter for one scene component payload type.
Stable hierarchy capability implemented by document and runtime targets.
Definition SceneTarget.h:35
Capability implemented by document and live scene targets.
static editing::CapabilityId editingCapabilityId()
Editing capability id.
Result< std::vector< EditorDiagnostic > > validatePayload(const SceneComponentPayloadRef &component) const override
Validate payload.
Result< IDomainOperationTarget * > operationTarget(const SelectionSnapshot &selection) const override
Operation target.
Result< IPropertyProvider * > propertyProvider(const SelectionSnapshot &selection) const override
Property provider.
SceneComponentChange unregisterProvider(ISceneComponentPayloadProvider *provider)
Remove a provider only when the exact registered instance matches.
Result< void > registerProvider(std::shared_ptr< ISceneComponentPayloadProvider > provider)
Share ownership of one provider; component types must be non-empty and unique. @lifetime Dispatch tak...
Result< std::vector< SceneComponentPayloadRef > > componentPayloads(const TargetId &scene, const ObjectId &object) const override
Component payloads.
Result< DomainOperation > makeSet(const SelectionSnapshot &selection, const PropertyPath &path, const EditorValue &value, PropertySetMode mode) const override
Make set.
Result< void > bind(SceneComponentPayloadRef component, SelectionItem moduleSelection, IPropertyProvider *properties, IDomainOperationTarget *operations, Validator validator={})
Bind one stable scene component to an existing module editor target.
std::vector< EditorDiagnostic > validateComponent(const SceneComponentPayloadRef &component) const override
Validate component.
PropertySchema schema(const SelectionSnapshot &selection) const override
Schema.
SceneComponentChange unbind(const TargetId &scene, const StableId &component)
Remove one exact scene component binding.
std::function< std::vector< EditorDiagnostic >()> Validator
Result< IDomainOperationTarget * > payloadOperationTarget(const SelectionSnapshot &selection) const override
Payload operation target.
PropertyReadResult read(const SelectionSnapshot &selection, const PropertyPath &path) const override
Reads .
std::vector< SceneComponentPayloadRef > components(const TargetId &scene, const ObjectId &object) const override
Components.
eve::Result< eve::Revision > currentRevision(const SelectionSnapshot &selection) const override
Current revision.
SceneComponentPropertyBindings(std::string componentType)
Create bindings for one stable component type.
Result< DomainOperation > makeReset(const SelectionSnapshot &selection, const PropertyPath &path) const override
Make reset.
Shared in-memory scene target implementation for document/runtime adapters.
Definition SceneTarget.h:86
virtual Result< DomainOperation > makeRestore(const EditorValue &snapshot) const
Plan atomic replacement of hierarchy/TRS from a versioned snapshot.
TargetId targetId() const override
Target id.
Definition SceneTarget.h:94
EditorValue snapshotValue() const override
Capture deterministic scene content for document persistence.
StateValue objects
Definition Snapshot.cpp:110
std::unordered_map< const void *, size_t > ids
Definition Snapshot.cpp:109
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
StrongId< ObjectIdTag > ObjectId
Definition EditingIds.h:65
StrongId< RuleIdTag > RuleId
Definition EditingIds.h:60
PropertySetMode
PropertySetMode public API.
StrongId< CommandIdTag > CommandId
Definition EditingIds.h:58
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build an owning common diagnostic carrying an open editing rule identity.
Result< T > failed(Status status, eve::DiagnosticCode code, RuleId rule, std::string message)
Construct a failed editing result with explicit status and diagnostic categories.
Result< SelectionSnapshot > makeSceneComponentSelection(std::string channel, const std::vector< SceneComponentPayloadRef > &components, std::uint64_t sequence)
Build a property selection for one or more homogeneous component references.
editing::Result< void > registerEditingCommands(editing::IEditingCommandRegistry &registry)
Register Scene-owned commands with a generic editing host.
Result< void > registerAuthoringDocumentCommands(editing::IEditingCommandRegistry &registry)
Register authored source creation and camera/lighting payload commands.
Result< void > registerAuthoringCommands(editing::IEditingCommandRegistry &registry)
Register ground, surface-edge alignment and screen-anchor placement planners.
SceneComponentChange
Whether a registry or binding removal changed authoritative state.
CommandPlan public API.
CommandRequest public API.
DomainOperation public API.
Domain-owned metadata for one planned editing command.
PropertyReadResult public API.
EVENGINE_API_PLATFORM public API.
SelectionItem public API.
SelectionSnapshot public API.
std::vector< SelectionItem > items
Request used to create a scene object in either backend.
Definition SceneTarget.h:27
Stable, pointer-free reference to one editable component instance.
Serializable transform exchanged across the scene editing boundary.