载入中...
搜索中...
未找到
SceneAuthoringBindings.cpp
浏览该文件的文档.
2#include <simplesquirrel/simplesquirrel.hpp>
10
12void exposeSceneAuthoringQueries(ssq::Table& table, ssq::Class& module) {
13 const auto vm = table.getHandle();
14 module.addFunc("createAuthoringSession", [vm](SceneEditorModule*, const std::string& id) {
15 if (id.empty())
16 return script::projectStatusResult(
17 vm, Status::failure(
18 Diagnostic::error(DiagnosticCode::InvalidArgument, "Authoring target id must be nonempty")));
19 auto owned = script::makeOwnedSquirrelInstance<SceneEditorSession>(
20 vm,
21 std::make_unique<SceneEditorSession>(std::make_unique<scene_editing::SceneAuthoringDocumentTarget>(id)));
22 if (!owned.ok()) return script::projectStatusResult(vm, owned.status());
23 auto result =
25 result.set("ownership", std::string("owned"));
26 return result;
27 });
28 module.addFunc("inspectAuthoringSnapshot", [vm](SceneEditorModule*, ssq::Object snapshot, const std::string& id,
29 ssq::Object bounds) {
30 auto decoded = script::valueFromSquirrel(snapshot);
31 if (!decoded.ok()) return script::projectStatusResult(vm, decoded.status());
33 auto hierarchy = editing::toEditingValue(decoded.value());
34 if (const auto* root = hierarchy.getIf<editing::Value::Object>(); root && root->contains("hierarchy")) {
35 auto copied = root->at("hierarchy");
36 hierarchy = std::move(copied);
37 }
38 auto restore = target.makeRestore(hierarchy);
39 if (!restore.ok()) return script::projectStatusResult(vm, restore.status());
40 auto restored = target.applyDomainOperation(restore.value());
41 if (!restored.ok()) return script::projectStatusResult(vm, restored.status());
43 auto decodedBounds = script::valueFromSquirrel(bounds);
44 if (!decodedBounds.ok()) return script::projectStatusResult(vm, decodedBounds.status());
45 const auto* values = decodedBounds.value().getIf<Value::Array>();
46 if (!values || values->size() != 6)
49 Diagnostic::error(DiagnosticCode::InvalidArgument, "Authoring bounds require six numbers")));
50 for (std::size_t i = 0; i < local.size(); ++i) {
51 if (const auto* real = (*values)[i].getIf<double>())
52 local[i] = *real;
53 else if (const auto* integer = (*values)[i].getIf<std::int64_t>())
54 local[i] = static_cast<double>(*integer);
55 else
58 "Authoring bounds require finite numbers")));
59 }
61 if (!inspected.ok()) return script::projectStatusResult(vm, inspected.status());
62 return script::projectStatusResult(vm, inspected.status(), editing::toPresentationValue(inspected.value()));
63 });
64}
65} // namespace eve::scene_editor
LogicalId target
int root
Definition AnimSmr.cpp:119
ActiveSource owned
HSQUIRRELVM vm
Definition ECS.cpp:38
std::string local
Poco::JSON::Object::Ptr result
std::set< std::string > values
The single Squirrel projection for common Result, Status and Value.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
Definition Status.cpp:28
std::vector< Value > Array
Definition Value.h:33
std::map< std::string, Value > Object
Authoring scene-document backend exposing the standard scene capabilities.
eve::Value toPresentationValue(const Value &value)
To presentation value.
StrongId< ObjectIdTag > ObjectId
Definition EditingIds.h:65
Value toEditingValue(const eve::Value &value)
To editing value.
Result< EditorValue > inspectAuthoringObject(const ISceneHierarchyEditTarget &target, const ObjectId &object, const AuthoringBounds &bounds)
Inspect world geometry derived from the canonical hierarchy and asset bounds.
std::array< double, 6 > AuthoringBounds
Immutable asset-local bounds, ordered minimum XYZ then maximum XYZ.
void exposeSceneAuthoringQueries(ssq::Table &table, ssq::Class &module)
Bind read-only authoring queries; table and module are borrowed synchronously.
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
Result< Value > valueFromSquirrel(HSQUIRRELVM vm, SQInteger index, const SquirrelValueOptions &options)
Convert one Squirrel value into the canonical owning Value tree.
glm::vec4 bounds