载入中...
搜索中...
未找到
SceneEditorSession.cpp
浏览该文件的文档.
40 return editing::failed<SceneGraph>(editing::Status::Failed, editing::RuleId("scene.physics-placement.snapshot"),
43 const auto* objects = found != root->end() ? found->second.getIf<editing::Value::Array>() : nullptr;
45 return editing::failed<SceneGraph>(editing::Status::Failed, editing::RuleId("scene.physics-placement.snapshot"),
54 const auto* transform = transformValue ? transformValue->getIf<editing::Value::Object>() : nullptr;
82 return glm::translate(glm::dmat4(1.0), glm::dvec3(value.x, value.y, value.z)) * glm::mat4_cast(rotation) *
89 if (const auto cached = cache.find(id); cached != cache.end()) return editing::applied<glm::dmat4>(cached->second);
116 if (!glm::decompose(matrix, scale, rotation, translation, skew, perspective) || glm::length(skew) > 1.0e-7 ||
117 std::abs(perspective.x) > 1.0e-9 || std::abs(perspective.y) > 1.0e-9 || std::abs(perspective.z) > 1.0e-9 ||
146 return std::array<double, 3>{left[1] * right[2] - left[2] * right[1], left[2] * right[0] - left[0] * right[2],
191 for (const float value : collider.convexVertices) vertices.emplace_back(static_cast<double>(value));
194 {"source", collider.source == PhysicsPlacementColliderSource::Existing ? "existing" : "generated"},
195 {"halfExtents", editing::Value::Array{collider.halfExtentX, collider.halfExtentY, collider.halfExtentZ}},
198 editing::Value::Array{collider.localRotationX, collider.localRotationY, collider.localRotationZ}},
230 if (!shape || !source || !half || half->size() != 3 || !local || local->size() != 3 || !rotation ||
231 rotation->size() != 3 || !vertices || !maximum || !valueNumber((*half)[0], collider.halfExtentX) ||
232 !valueNumber((*half)[1], collider.halfExtentY) || !valueNumber((*half)[2], collider.halfExtentZ) ||
234 !valueNumber((*local)[2], collider.localZ) || !valueNumber((*rotation)[0], collider.localRotationX) ||
235 !valueNumber((*rotation)[1], collider.localRotationY) || !valueNumber((*rotation)[2], collider.localRotationZ))
276 if (!target || target->targetId().empty()) throw std::invalid_argument("Scene target must have an identity");
277 if (!scene_editing::registerEditingCommands(coordinator).ok() || !coordinator.registerTarget(*target).ok())
296editing::Result<editing::TransactionReceipt> SceneEditorSession::execute(std::string command, editing::Value payload) {
309editing::Result<void> SceneEditorSession::restrictCommands(const std::vector<std::string>& commands) {
313 return editing::failed<void>(editing::Status::Rejected, editing::RuleId("scene.session.empty-command"),
327std::string SceneEditorSession::saveJson() const { return editing::editorValueToJson(snapshot()); }
330editing::Result<void> SceneEditorSession::cachePhysicsPlacementHull(const editing::ObjectId& object,
332 if (object.empty() || vertices.size() < 12 || vertices.size() % 3 != 0 || vertices.size() / 3 > 100000 ||
347 const editing::ObjectId& object, std::string resourceKey, std::vector<PhysicsPlacementCollider> colliders) {
355 !std::isfinite(collider.halfExtentZ) || collider.halfExtentX <= 0.0 || collider.halfExtentY <= 0.0 ||
411editing::Result<void> SceneEditorSession::restorePhysicsPlacementColliderCacheJson(const std::string& json) {
420 if (!schema || *schema != "eve.scene.physics-placement-collider-cache" || !version || *version != 2 || !entries)
421 return editing::failed<void>(editing::Status::Rejected, editing::RuleId("scene.physics-placement.cache-schema"),
430 const auto* colliders = collidersValue ? collidersValue->getIf<editing::Value::Array>() : nullptr;
449editing::Result<void> SceneEditorSession::beginPhysicsPlacement(PhysicsPlacementRequest request) {
451 return editing::failed<void>(editing::Status::Conflict, editing::RuleId("scene.physics-placement.active"),
464 if (!object.colliderResourceKey.empty() && object.colliderResourceKey != found->second.resourceKey)
487editing::Result<PhysicsPlacementFrame> SceneEditorSession::updatePhysicsPlacement(double x, double y, double z,
540 double fromX, double fromY, double fromZ, double toX, double toY, double toZ, double offset, double fixedDelta) {
545 auto aligned = impl_->placement->alignHandleToSurface(fromX, fromY, fromZ, toX, toY, toZ, offset);
564 if (!captured.ok()) return editing::Result<editing::TransactionReceipt>::failure(captured.status());
567 if (object.selected) desiredWorld.insert_or_assign(object.object.value(), matrixOf(object.transform));
601 execute("scene.transform.batch.set.v1", editing::Value::Object{{"transforms", std::move(transforms)}});
612 return editing::failed<void>(editing::Status::NoOp, editing::RuleId("scene.physics-placement.inactive"),
621bool SceneEditorSession::physicsPlacementActive() const noexcept { return impl_->placement != nullptr; }
622editing::Result<editing::TransactionReceipt> SceneEditorSession::restoreJson(const std::string& json) {
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Definition Result.h:480
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:314
Deterministic owning value tree shared by authoring hosts.
Definition EditingValue.h:19
Registry and execution gate for UI-, script- and automation-neutral commands.
Definition EditorCommandService.h:51
Coordinates editable targets, per-target histories and domain commands.
Definition EditorTargetCoordinator.h:25
Result< void > registerTarget(IEditableTarget &target)
Registers target.
Definition EditorTargetCoordinator.cpp:156
Upper capability boundary for one editor host.
Definition EditorHostProfile.h:51
static HostProfile runtimeBuilder()
Safe runtime profile that denies commands unless allow-listed.
Definition EditorHostProfile.cpp:15
static HostProfile developer()
Unrestricted developer profile used by legacy sessions.
Definition EditorHostProfile.cpp:5
Composable scene command/history host with no UI or renderer dependency. Owns its target,...
Definition SceneEditorSession.h:24
editing::Result< editing::TransactionReceipt > redo()
Reapply the last undone scene transaction.
Definition SceneEditorSession.cpp:323
editing::Result< void > cachePhysicsPlacementCompound(const editing::ObjectId &object, std::string resourceKey, std::vector< PhysicsPlacementCollider > colliders)
Replace one object's generated compound collider cache entry.
Definition SceneEditorSession.cpp:346
editing::Result< PhysicsPlacementFrame > alignPhysicsPlacementToSurface(double fromX, double fromY, double fromZ, double toX, double toY, double toZ, double offset=0.0, double fixedDelta=1.0/60.0)
Align the active selection to a non-selected preview surface and advance one step.
Definition SceneEditorSession.cpp:539
editing::Result< void > removePhysicsPlacementHull(const editing::ObjectId &object)
Remove one cached automatic placement hull; missing entries return NoOp.
Definition SceneEditorSession.cpp:375
editing::Result< PhysicsPlacementFrame > updatePhysicsPlacementPose(double x, double y, double z, double rotationX, double rotationY, double rotationZ, double fixedDelta=1.0/60.0)
Move and rotate the preview handle, then advance one fixed simulation step.
Definition SceneEditorSession.cpp:502
editing::Result< void > restrictCommands(const std::vector< std::string > &commands)
Restrict future commands to a host allow-list; empty denies all. Existing history remains undoable.
Definition SceneEditorSession.cpp:309
editing::Result< editing::TransactionReceipt > undo()
Undo the last scene transaction; failures preserve history.
Definition SceneEditorSession.cpp:320
std::string savePhysicsPlacementColliderCacheJson() const
Encode schema-2 generated collider cache; host owns file I/O and the returned string.
Definition SceneEditorSession.cpp:387
editing::Result< editing::TransactionReceipt > commitPhysicsPlacement()
Atomically publish selected preview transforms as one undoable transaction.
Definition SceneEditorSession.cpp:554
SceneEditorSession(std::string targetId)
Own a document target with a nonempty host-local identity.
Definition SceneEditorSession.cpp:290
editing::Result< editing::TransactionReceipt > execute(std::string command, editing::Value payload)
Execute a registered scene command through revision checks and one reversible transaction.
Definition SceneEditorSession.cpp:296
editing::Result< editing::TransactionReceipt > restoreJson(const std::string &json)
Parse and restore schema-1 JSON as an undoable transaction; invalid input changes nothing.
Definition SceneEditorSession.cpp:622
editing::Value snapshot() const
Copy the versioned hierarchy/TRS snapshot; caller owns the returned tree.
Definition SceneEditorSession.cpp:326
editing::Result< PhysicsPlacementFrame > updatePhysicsPlacement(double x, double y, double z, double fixedDelta=1.0/60.0)
Move the preview handle and advance one fixed simulation step.
Definition SceneEditorSession.cpp:487
editing::Revision revision() const
Return the current monotonic target revision.
Definition SceneEditorSession.cpp:328
std::string saveJson() const
Encode snapshot deterministically; file I/O and paths belong to the host.
Definition SceneEditorSession.cpp:327
editing::Result< void > beginPhysicsPlacement(PhysicsPlacementRequest request)
Begin an isolated Box3D placement preview using current scene transforms.
Definition SceneEditorSession.cpp:449
editing::Result< void > restorePhysicsPlacementColliderCacheJson(const std::string &json)
Atomically replace generated collider cache from schema-2 JSON.
Definition SceneEditorSession.cpp:411
bool physicsPlacementActive() const noexcept
Report whether this session owns an active placement preview.
Definition SceneEditorSession.cpp:621
editing::Result< void > cancelPhysicsPlacement()
Discard the isolated preview without changing scene state.
Definition SceneEditorSession.cpp:610
~SceneEditorSession()
Scene editor session.
editing::Result< PhysicsPlacementFrame > updatePhysicsPlacementTransform(double x, double y, double z, double rotationX, double rotationY, double rotationZ, double scaleX, double scaleY, double scaleZ, double fixedDelta=1.0/60.0)
Move, rotate and scale the preview handle, then advance one fixed simulation step.
Definition SceneEditorSession.cpp:519
editing::Result< void > cachePhysicsPlacementHull(const editing::ObjectId &object, std::vector< float > vertices, int maxVertices=64)
Cache backend-neutral local-space mesh points for later automatic convex placement.
Definition SceneEditorSession.cpp:330
static editing::Result< std::unique_ptr< ScenePhysicsPlacementBackend > > create(PhysicsPlacementRequest request)
Validate and build an isolated placement world.
Definition ScenePhysicsPlacement.cpp:211
std::string editorValueToJson(const EditorValue &value)
Serialize an EditorValue to deterministic compact JSON.
Definition EditingValueJson.cpp:346
Result< EditorValue > editorValueFromJson(const std::string &json)
Parse JSON into the pointer-free EditorValue protocol tree.
Definition EditingValueJson.cpp:352
editing::Result< void > registerEditingCommands(editing::IEditingCommandRegistry ®istry)
Register Scene-owned commands with a generic editing host.
Definition SceneEditingCommands.cpp:38
Definition SceneEditorModule.cpp:18
PhysicsPlacementShape
Collision approximation admitted into the private preview world.
Definition ScenePhysicsPlacement.h:20
Definition Container.h:602
One local-space shape in a possibly compound placement collider.
Definition ScenePhysicsPlacement.h:29
int convexMaxVertices
Definition ScenePhysicsPlacement.h:42
std::vector< float > convexVertices
Definition ScenePhysicsPlacement.h:41
PhysicsPlacementShape shape
Definition ScenePhysicsPlacement.h:30
Owning request used to construct one isolated placement candidate.
Definition ScenePhysicsPlacement.h:110
std::vector< PhysicsPlacementCollider > colliders
Definition SceneEditorSession.cpp:272
std::string resourceKey
Definition SceneEditorSession.cpp:271
editor::EditorTargetCoordinator coordinator
Definition SceneEditorSession.cpp:282
std::unique_ptr< ScenePhysicsPlacementBackend > placement
Definition SceneEditorSession.cpp:284
std::unordered_map< std::string, CachedHull > placementHulls
Definition SceneEditorSession.cpp:285
std::unique_ptr< scene_editing::SceneTargetBase > target
Definition SceneEditorSession.cpp:280
Impl(std::unique_ptr< scene_editing::SceneTargetBase > value)
Definition SceneEditorSession.cpp:274
editor::EditorCommandService commands
Definition SceneEditorSession.cpp:281
editor::HostProfile profile
Definition SceneEditorSession.cpp:283
SceneGraph placementGraph
Definition SceneEditorSession.cpp:286
std::unordered_map< std::string, glm::dmat4 > placementInitialWorld
Definition SceneEditorSession.cpp:287
std::uint64_t placementTick
Definition SceneEditorSession.cpp:288