agentscape3d-engine 0.0.0-stage → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/cli.mjs +53 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js +337 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js.map +1 -0
- package/dist/AssetCompiler-BLj09iu1.js +2424 -0
- package/dist/AssetCompiler-BLj09iu1.js.map +1 -0
- package/dist/AssetModule-DME-XaFS.js +2637 -0
- package/dist/AssetModule-DME-XaFS.js.map +1 -0
- package/dist/AssetRecipe-g8dZBhgJ.js +298 -0
- package/dist/AssetRecipe-g8dZBhgJ.js.map +1 -0
- package/dist/BrowserCodeWorker.js +53856 -0
- package/dist/BrowserCodeWorker.js.map +1 -0
- package/dist/CarryCapability-CXwHU5ay.js +104 -0
- package/dist/CarryCapability-CXwHU5ay.js.map +1 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js +241 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js.map +1 -0
- package/dist/ObjectTransform-BlQUNK7c.js +61 -0
- package/dist/ObjectTransform-BlQUNK7c.js.map +1 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js +3259 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js.map +1 -0
- package/dist/RenderingSystem-WIr1ZuGu.js +1042 -0
- package/dist/RenderingSystem-WIr1ZuGu.js.map +1 -0
- package/dist/ScenePresentation-LsYiDxbm.js +152 -0
- package/dist/ScenePresentation-LsYiDxbm.js.map +1 -0
- package/dist/SceneProject-K7HH1s8o.js +2687 -0
- package/dist/SceneProject-K7HH1s8o.js.map +1 -0
- package/dist/SceneSerializer-zOzbX4jZ.js +932 -0
- package/dist/SceneSerializer-zOzbX4jZ.js.map +1 -0
- package/dist/SimulationProfile-DSYZbBLQ.js +165 -0
- package/dist/SimulationProfile-DSYZbBLQ.js.map +1 -0
- package/dist/StylePack-DcRa_kU0.js +88 -0
- package/dist/StylePack-DcRa_kU0.js.map +1 -0
- package/dist/WorldArchive-BiFGLt--.js +451 -0
- package/dist/WorldArchive-BiFGLt--.js.map +1 -0
- package/dist/WorldCommands-Debj7V4L.js +2207 -0
- package/dist/WorldCommands-Debj7V4L.js.map +1 -0
- package/dist/WorldIO-Ch8QBfKY.js +151 -0
- package/dist/WorldIO-Ch8QBfKY.js.map +1 -0
- package/dist/admission-CVEvsrdz.js +121 -0
- package/dist/admission-CVEvsrdz.js.map +1 -0
- package/dist/blankWorld-B0MW6g7q.js +75 -0
- package/dist/blankWorld-B0MW6g7q.js.map +1 -0
- package/dist/core.d.ts +68 -0
- package/dist/core.js +209 -0
- package/dist/core.js.map +1 -0
- package/dist/disposeObject3D-DIMzy0FA.js +128 -0
- package/dist/disposeObject3D-DIMzy0FA.js.map +1 -0
- package/dist/environments-HOe3sJXH.js +567 -0
- package/dist/environments-HOe3sJXH.js.map +1 -0
- package/dist/gltfIO-BzVKLyaL.js +339 -0
- package/dist/gltfIO-BzVKLyaL.js.map +1 -0
- package/dist/grandUrbanBlock-DRndRZjF.js +515 -0
- package/dist/grandUrbanBlock-DRndRZjF.js.map +1 -0
- package/dist/index.d.ts +345 -0
- package/dist/index.js +16952 -0
- package/dist/index.js.map +1 -0
- package/dist/magicCabin-CfBZjx2Q.js +11019 -0
- package/dist/magicCabin-CfBZjx2Q.js.map +1 -0
- package/dist/manifests-D0LwbJ36.js +866 -0
- package/dist/manifests-D0LwbJ36.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +1 -0
- package/dist/monumentHall-awZiGtda.js +403 -0
- package/dist/monumentHall-awZiGtda.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +26 -0
- package/dist/parts-DrEcfJRl.js +37 -0
- package/dist/parts-DrEcfJRl.js.map +1 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js +696 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js.map +1 -0
- package/dist/runtime/application/AgentTools.js +28 -0
- package/dist/runtime/application/README.md +14 -0
- package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
- package/dist/runtime/application/agent/StudioMcpAllowlist.js +10 -0
- package/dist/runtime/application/agent/StudioProjectTools.js +18 -0
- package/dist/runtime/application/agent/TaskEvidence.js +199 -0
- package/dist/runtime/application/buildTaskObservation.js +117 -0
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +50 -0
- package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
- package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
- package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +82 -0
- package/dist/runtime/application/createSession.js +66 -0
- package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
- package/dist/runtime/application/generation/GenerationOrchestrator.js +630 -0
- package/dist/runtime/application/generation/GenerationRuntime.js +215 -0
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +289 -0
- package/dist/runtime/application/native-scene/CodeProject.js +215 -0
- package/dist/runtime/application/native-scene/CodeProjectModules.js +143 -0
- package/dist/runtime/application/native-scene/ExampleWorldCatalog.js +35 -0
- package/dist/runtime/application/native-scene/NativeArticulation.js +53 -0
- package/dist/runtime/application/native-scene/NativeEditableRegistry.js +150 -0
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +85 -0
- package/dist/runtime/application/native-scene/NativeLightingInspection.js +33 -0
- package/dist/runtime/application/native-scene/NativeMaterialInspection.js +52 -0
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
- package/dist/runtime/application/native-scene/NativePhysicsGeometry.js +64 -0
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
- package/dist/runtime/application/native-scene/NativeSceneHost.js +406 -0
- package/dist/runtime/application/native-scene/NativeSceneInspection.js +203 -0
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
- package/dist/runtime/application/native-scene/NativeSceneQuery.js +123 -0
- package/dist/runtime/application/native-scene/NativeSceneReview.js +132 -0
- package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
- package/dist/runtime/application/native-scene/SceneObserver.js +97 -0
- package/dist/runtime/application/native-scene/VisualCapturePolicy.js +4 -0
- package/dist/runtime/application/object-forge/SceneObjectForge.js +263 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
- package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
- package/dist/runtime/application/scene/CapabilityResolver.js +90 -0
- package/dist/runtime/application/scene/NativeEditableContracts.js +18 -0
- package/dist/runtime/application/scene/RequestWindow.js +54 -0
- package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
- package/dist/runtime/application/scene/SceneContracts.js +49 -0
- package/dist/runtime/application/scene/SceneEditService.js +154 -0
- package/dist/runtime/application/scene/SceneFacade.js +356 -0
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +41 -0
- package/dist/runtime/application/scene/SceneJobController.js +320 -0
- package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
- package/dist/runtime/application/scene/ScenePackage.js +173 -0
- package/dist/runtime/application/scene/ScenePersistence.js +50 -0
- package/dist/runtime/application/scene/SceneProject.js +95 -0
- package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
- package/dist/runtime/application/scene/StarterScene.js +56 -0
- package/dist/runtime/application/scene/WorldArchive.js +89 -0
- package/dist/runtime/application/scene/WorldDirectory.js +20 -0
- package/dist/runtime/application/scene/WorldDocument.js +76 -0
- package/dist/runtime/application/scene/WorldIO.js +103 -0
- package/dist/runtime/application/scene/WorldStorage.js +155 -0
- package/dist/runtime/application/skills/SkillRegistry.js +193 -0
- package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
- package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
- package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
- package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
- package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
- package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
- package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
- package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
- package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
- package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
- package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
- package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
- package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
- package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
- package/dist/runtime/application/skills/skillPrimitives.js +4 -0
- package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
- package/dist/runtime/application/tasks.jsonl +67 -0
- package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
- package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
- package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
- package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
- package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
- package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
- package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
- package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
- package/dist/runtime/application/world-authoring/HeadlessImageExport.js +92 -0
- package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
- package/dist/runtime/application/world-authoring/SceneGLBExport.js +88 -0
- package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
- package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +68 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
- package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
- package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
- package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
- package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
- package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
- package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
- package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
- package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +157 -0
- package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
- package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
- package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
- package/dist/runtime/apps/mcp-server/README.md +269 -0
- package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
- package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
- package/dist/runtime/apps/mcp-server/SessionManager.js +148 -0
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +75 -0
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +246 -0
- package/dist/runtime/apps/mcp-server/StudioProjectToolContracts.js +58 -0
- package/dist/runtime/apps/mcp-server/TransferHttp.js +47 -0
- package/dist/runtime/apps/mcp-server/TransferLimits.js +6 -0
- package/dist/runtime/apps/mcp-server/TransferStore.js +134 -0
- package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
- package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
- package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
- package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
- package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
- package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
- package/dist/runtime/apps/mcp-server/main.mjs +82 -0
- package/dist/runtime/apps/mcp-server/registerTools.js +274 -0
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
- package/dist/runtime/apps/mcp-server/security.js +23 -0
- package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
- package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
- package/dist/runtime/apps/server/README.md +7 -0
- package/dist/runtime/apps/server/WorldRepository.js +338 -0
- package/dist/runtime/apps/server/WorldRepositoryHttp.js +96 -0
- package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
- package/dist/runtime/apps/server/tasks.jsonl +10 -0
- package/dist/runtime/apps/shared/node/WorldDiskStorage.js +62 -0
- package/dist/runtime/foundation/EventBus.js +26 -0
- package/dist/runtime/foundation/JsonGateway.js +47 -0
- package/dist/runtime/foundation/PngRgba.js +99 -0
- package/dist/runtime/foundation/PolicyEngine.js +21 -0
- package/dist/runtime/foundation/README.md +7 -0
- package/dist/runtime/foundation/TraceRecorder.js +76 -0
- package/dist/runtime/foundation/errors.js +8 -0
- package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
- package/dist/runtime/foundation/version.js +2 -0
- package/dist/runtime/modules/agent/README.md +11 -0
- package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
- package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
- package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
- package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
- package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
- package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
- package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
- package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
- package/dist/runtime/modules/agent/prompt/index.js +52 -0
- package/dist/runtime/modules/agent/tasks.jsonl +94 -0
- package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
- package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
- package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
- package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
- package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
- package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
- package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
- package/dist/runtime/modules/artifact/README.md +7 -0
- package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
- package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
- package/dist/runtime/modules/asset/AssetModule.js +416 -0
- package/dist/runtime/modules/asset/README.md +67 -0
- package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
- package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
- package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
- package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
- package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
- package/dist/runtime/modules/asset/model/AssetInputContracts.js +139 -0
- package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
- package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
- package/dist/runtime/modules/asset/model/ProceduralTextureContract.js +24 -0
- package/dist/runtime/modules/asset/model/admission.js +117 -0
- package/dist/runtime/modules/asset/model/errors.js +6 -0
- package/dist/runtime/modules/asset/model/parts.js +27 -0
- package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
- package/dist/runtime/modules/asset/model/schema.js +150 -0
- package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
- package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
- package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
- package/dist/runtime/modules/asset/production/AssetRecipe.js +91 -0
- package/dist/runtime/modules/asset/production/ProceduralTexture.js +85 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
- package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
- package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
- package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
- package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
- package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
- package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
- package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
- package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
- package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
- package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
- package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
- package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
- package/dist/runtime/modules/asset/tasks.jsonl +87 -0
- package/dist/runtime/modules/generation/README.md +9 -0
- package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
- package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
- package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
- package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
- package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
- package/dist/runtime/modules/generation/tasks.jsonl +35 -0
- package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
- package/dist/runtime/modules/navigation/RecastNavigationBackend.js +263 -0
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +660 -0
- package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +414 -0
- package/dist/runtime/modules/rendering/README.md +7 -0
- package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
- package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
- package/dist/runtime/modules/rendering/captureStill.js +54 -0
- package/dist/runtime/modules/rendering/createRenderer.js +76 -0
- package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
- package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
- package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
- package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
- package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
- package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
- package/dist/runtime/modules/world/README.md +13 -0
- package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
- package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
- package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
- package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
- package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
- package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
- package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
- package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
- package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
- package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
- package/dist/runtime/modules/world/content/blankWorld.js +35 -0
- package/dist/runtime/modules/world/content/environments.js +84 -0
- package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
- package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
- package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
- package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
- package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
- package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
- package/dist/runtime/modules/world/content/magicCabin.js +190 -0
- package/dist/runtime/modules/world/content/monumentHall.js +154 -0
- package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
- package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
- package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
- package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
- package/dist/runtime/modules/world/errors.js +9 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
- package/dist/runtime/modules/world/runtime/CommandHistory.js +111 -0
- package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +165 -0
- package/dist/runtime/modules/world/runtime/NativeNavigationGeometry.js +84 -0
- package/dist/runtime/modules/world/runtime/NativePhysicsSnapshot.js +245 -0
- package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
- package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
- package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
- package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +240 -0
- package/dist/runtime/modules/world/runtime/SceneExtensions.js +36 -0
- package/dist/runtime/modules/world/runtime/ScenePresentation.js +101 -0
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +281 -0
- package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
- package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
- package/dist/runtime/modules/world/runtime/WorldCommands.js +503 -0
- package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
- package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
- package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
- package/dist/runtime/modules/world/runtime/WorldRuntime.js +806 -0
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +110 -0
- package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
- package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
- package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
- package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +390 -0
- package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +244 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +147 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
- package/dist/runtime/modules/world/runtime/interaction/ManipulationActions.js +7 -0
- package/dist/runtime/modules/world/runtime/interaction/NativePhysicalTarget.js +31 -0
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +134 -0
- package/dist/runtime/modules/world/runtime/semantic/NativePhysicsState.js +89 -0
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +129 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +104 -0
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/simulation/WorldTimeline.js +110 -0
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
- package/dist/runtime/modules/world/runtime/spatial/VisualMeshBounds.js +41 -0
- package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +306 -0
- package/dist/runtime/modules/world/runtime/systems/Instrument.js +39 -0
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +806 -0
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +281 -0
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +561 -0
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1752 -0
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +527 -0
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +402 -0
- package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
- package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
- package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
- package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
- package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
- package/dist/runtime/modules/world/tasks.jsonl +530 -0
- package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
- package/dist/runtime/modules/world/verification/Finding.js +105 -0
- package/dist/runtime/modules/world/verification/InteractionEvidence.js +73 -0
- package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
- package/dist/runtime/modules/world/verification/VisualLayoutAcceptance.js +58 -0
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +176 -0
- package/dist/runtime/modules/world/verification/WorldValidator.js +67 -0
- package/dist/runtime/package-lock.json +16071 -0
- package/dist/runtime/package.json +106 -0
- package/dist/runtime/public/assets/cabinet.glb +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
- package/dist/schema-DT7K9NjP.js +165 -0
- package/dist/schema-DT7K9NjP.js.map +1 -0
- package/dist/suzhouGarden-Y3hny8j6.js +6150 -0
- package/dist/suzhouGarden-Y3hny8j6.js.map +1 -0
- package/dist/version-CHc-i8ch.js +5 -0
- package/dist/version-CHc-i8ch.js.map +1 -0
- package/dist/woodlandWorkshop-DsScU-cx.js +483 -0
- package/dist/woodlandWorkshop-DsScU-cx.js.map +1 -0
- package/dist/yuanmingyuan-DsFnPzzR.js +4955 -0
- package/dist/yuanmingyuan-DsFnPzzR.js.map +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,932 @@
|
|
|
1
|
+
import { r as parseScenePresentation } from "./ScenePresentation-LsYiDxbm.js";
|
|
2
|
+
import { r as uniformScaleValue } from "./ObjectTransform-BlQUNK7c.js";
|
|
3
|
+
import { i as thermalStateSchema, o as validateThermalStateForProfile } from "./SimulationProfile-DSYZbBLQ.js";
|
|
4
|
+
import { t as inferCarryCapability } from "./CarryCapability-CXwHU5ay.js";
|
|
5
|
+
import * as z from "zod/v4";
|
|
6
|
+
import * as THREE from "three";
|
|
7
|
+
import { Quaternion, Vector3 } from "three";
|
|
8
|
+
import { z as z$1 } from "zod";
|
|
9
|
+
// modules/world/runtime/SceneExtensions.js
|
|
10
|
+
const volume = z$1.number().min(0).max(1);
|
|
11
|
+
const mix = z$1.object({
|
|
12
|
+
music: volume.optional(),
|
|
13
|
+
ambience: volume.optional(),
|
|
14
|
+
sfx: volume.optional(),
|
|
15
|
+
voice: volume.optional()
|
|
16
|
+
}).strict();
|
|
17
|
+
const envelope = z$1.object({
|
|
18
|
+
version: z$1.number().int().positive(),
|
|
19
|
+
required: z$1.boolean(),
|
|
20
|
+
state: z$1.json()
|
|
21
|
+
}).passthrough();
|
|
22
|
+
const extensionMap = z$1.record(z$1.string().min(1), envelope);
|
|
23
|
+
function validateSceneExtensions(input, runtime) {
|
|
24
|
+
if (input === void 0) return;
|
|
25
|
+
const extensions = extensionMap.parse(input);
|
|
26
|
+
for (const [id, entry] of Object.entries(extensions)) if (id === "agentscape.audio" && entry.version === 1) {
|
|
27
|
+
mix.parse(entry.state);
|
|
28
|
+
if (runtime && entry.required && !runtime.audio) throw new Error("Required audio output unavailable");
|
|
29
|
+
} else if (entry.required || id === "agentscape.audio") throw new Error("Unsupported scene extension: " + id + " v" + entry.version);
|
|
30
|
+
}
|
|
31
|
+
function captureSceneExtensions(runtime) {
|
|
32
|
+
const extensions = structuredClone(runtime.preservedSceneExtensions ?? {});
|
|
33
|
+
if (runtime.audio) {
|
|
34
|
+
const state = runtime.audio.snapshotMix();
|
|
35
|
+
if (Object.keys(state).length || extensions["agentscape.audio"]) extensions["agentscape.audio"] = {
|
|
36
|
+
...extensions["agentscape.audio"],
|
|
37
|
+
version: 1,
|
|
38
|
+
required: extensions["agentscape.audio"]?.required ?? false,
|
|
39
|
+
state
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return Object.keys(extensions).length ? { extensions } : {};
|
|
43
|
+
}
|
|
44
|
+
function restoreSceneExtensions(runtime, extensions) {
|
|
45
|
+
const audio = extensions?.["agentscape.audio"];
|
|
46
|
+
if (audio?.required && !runtime.audio) throw new Error("Required audio output unavailable");
|
|
47
|
+
runtime.audio?.restoreMix(audio?.state ?? {});
|
|
48
|
+
runtime.preservedSceneExtensions = structuredClone(extensions ?? {});
|
|
49
|
+
}
|
|
50
|
+
// modules/world/runtime/simulation/WorldTimeline.js
|
|
51
|
+
const positiveTicks = z$1.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
52
|
+
const environment = z$1.object({
|
|
53
|
+
weather: z$1.enum([
|
|
54
|
+
"clear",
|
|
55
|
+
"rain",
|
|
56
|
+
"snow"
|
|
57
|
+
]),
|
|
58
|
+
daylight: z$1.number().min(0).max(1)
|
|
59
|
+
});
|
|
60
|
+
const sound = z$1.object({
|
|
61
|
+
kind: z$1.literal("sound"),
|
|
62
|
+
source: z$1.string().min(1).max(256),
|
|
63
|
+
category: z$1.string().min(1).max(256),
|
|
64
|
+
radius: z$1.number().positive(),
|
|
65
|
+
ticks: positiveTicks
|
|
66
|
+
});
|
|
67
|
+
const cueSchema = z$1.discriminatedUnion("kind", [sound, environment.extend({ kind: z$1.literal("environment") })]);
|
|
68
|
+
const timelineSnapshotSchema = z$1.object({
|
|
69
|
+
version: z$1.literal(1),
|
|
70
|
+
environment,
|
|
71
|
+
cues: z$1.array(z$1.object({
|
|
72
|
+
after: positiveTicks,
|
|
73
|
+
cue: cueSchema
|
|
74
|
+
})).max(4096),
|
|
75
|
+
sounds: z$1.array(z$1.object({
|
|
76
|
+
remaining: positiveTicks,
|
|
77
|
+
cue: sound
|
|
78
|
+
})).max(256)
|
|
79
|
+
});
|
|
80
|
+
/** Simulation cues and sensory observations scoped to one simulation session. */
|
|
81
|
+
var WorldTimeline = class {
|
|
82
|
+
constructor(world) {
|
|
83
|
+
this.world = world;
|
|
84
|
+
this.reset();
|
|
85
|
+
}
|
|
86
|
+
reset() {
|
|
87
|
+
this.cues = [];
|
|
88
|
+
this.sounds = [];
|
|
89
|
+
this.environment = {
|
|
90
|
+
weather: "clear",
|
|
91
|
+
daylight: 1
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
schedule(tick, cue) {
|
|
95
|
+
if (!Number.isSafeInteger(tick) || tick <= this.world.simulation.tick) throw new RangeError("Expected a future simulation tick");
|
|
96
|
+
if (this.cues.length >= 4096) throw new RangeError("Timeline cue limit exceeded");
|
|
97
|
+
const entry = {
|
|
98
|
+
tick,
|
|
99
|
+
cue: cueSchema.parse(cue)
|
|
100
|
+
};
|
|
101
|
+
this.cues.push(entry);
|
|
102
|
+
this.cues.sort((a, b) => a.tick - b.tick);
|
|
103
|
+
return () => {
|
|
104
|
+
const index = this.cues.indexOf(entry);
|
|
105
|
+
if (index >= 0) this.cues.splice(index, 1);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
snapshot() {
|
|
109
|
+
const now = this.world.simulation.tick;
|
|
110
|
+
return {
|
|
111
|
+
version: 1,
|
|
112
|
+
environment: { ...this.environment },
|
|
113
|
+
cues: this.cues.map(({ tick, cue }) => ({
|
|
114
|
+
after: tick - now,
|
|
115
|
+
cue: { ...cue }
|
|
116
|
+
})),
|
|
117
|
+
sounds: this.sounds.filter((s) => s.until > now && this.object(s.source) === s.object).map(({ object, until, ...cue }) => ({
|
|
118
|
+
remaining: until - now,
|
|
119
|
+
cue
|
|
120
|
+
}))
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
rebase(delta) {
|
|
124
|
+
for (const entry of this.cues) entry.tick += delta;
|
|
125
|
+
for (const sound of this.sounds) sound.until += delta;
|
|
126
|
+
}
|
|
127
|
+
restore(saved) {
|
|
128
|
+
const state = saved && timelineSnapshotSchema.parse(saved);
|
|
129
|
+
this.reset();
|
|
130
|
+
if (!state) return;
|
|
131
|
+
const now = this.world.simulation.tick;
|
|
132
|
+
this.environment = state.environment;
|
|
133
|
+
for (const { after, cue } of state.cues) this.schedule(now + after, cue);
|
|
134
|
+
for (const { remaining, cue } of state.sounds) {
|
|
135
|
+
const object = this.object(cue.source);
|
|
136
|
+
if (object) this.sounds.push({
|
|
137
|
+
...cue,
|
|
138
|
+
object,
|
|
139
|
+
until: now + remaining
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
object(id) {
|
|
144
|
+
if (this.world.store.has(id)) {
|
|
145
|
+
if (this.world.store.get(id).active === false) return null;
|
|
146
|
+
}
|
|
147
|
+
return this.world.entities.get(id)?.object;
|
|
148
|
+
}
|
|
149
|
+
advance(tick) {
|
|
150
|
+
if (this.sounds.length) this.sounds = this.sounds.filter((sound) => sound.until > tick);
|
|
151
|
+
if (!this.cues.length || this.cues[0].tick > tick) return;
|
|
152
|
+
const due = [];
|
|
153
|
+
while (this.cues.length && this.cues[0].tick <= tick) due.push(this.cues.shift());
|
|
154
|
+
for (const { cue } of due) {
|
|
155
|
+
if (cue.kind === "environment") this.environment = {
|
|
156
|
+
weather: cue.weather,
|
|
157
|
+
daylight: cue.daylight
|
|
158
|
+
};
|
|
159
|
+
else {
|
|
160
|
+
const object = this.object(cue.source);
|
|
161
|
+
if (!object) continue;
|
|
162
|
+
if (this.sounds.length === 256) this.sounds.shift();
|
|
163
|
+
this.sounds.push({
|
|
164
|
+
...cue,
|
|
165
|
+
object,
|
|
166
|
+
until: tick + cue.ticks
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
this.world.events.emit("timeline." + cue.kind, {
|
|
170
|
+
...cue,
|
|
171
|
+
tick
|
|
172
|
+
}, { isolateListeners: true });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
observeSounds(observerId) {
|
|
176
|
+
const observer = this.object(observerId);
|
|
177
|
+
if (!observer) throw new Error("Missing sound observer");
|
|
178
|
+
const origin = observer.getWorldPosition(new Vector3());
|
|
179
|
+
const inverse = observer.getWorldQuaternion(new Quaternion()).invert();
|
|
180
|
+
const result = [];
|
|
181
|
+
for (const sound of this.sounds) {
|
|
182
|
+
if (this.object(sound.source) !== sound.object) continue;
|
|
183
|
+
const delta = sound.object.getWorldPosition(new Vector3()).sub(origin);
|
|
184
|
+
const distance = delta.length();
|
|
185
|
+
if (distance >= sound.radius) continue;
|
|
186
|
+
const target = sound.object.getWorldPosition(new Vector3());
|
|
187
|
+
const hit = this.world.physics?.raycast?.(origin.toArray(), target.toArray(), { excludeIds: [observerId, sound.source] });
|
|
188
|
+
const occluded = Boolean(hit && hit.distance < distance - 1e-5);
|
|
189
|
+
result.push({
|
|
190
|
+
occluded,
|
|
191
|
+
source: sound.source,
|
|
192
|
+
category: sound.category,
|
|
193
|
+
distance,
|
|
194
|
+
direction: delta.normalize().applyQuaternion(inverse).toArray(),
|
|
195
|
+
audibility: (1 - distance / sound.radius) * (occluded ? .35 : 1)
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
// modules/world/runtime/behavior/RuleGraph.js
|
|
202
|
+
const SCHEMA = "agentscape.rule-graph";
|
|
203
|
+
const allowedEffectKinds = /* @__PURE__ */ new Set(["set-state"]);
|
|
204
|
+
const clean = (v) => typeof v === "string" ? v.trim() : "";
|
|
205
|
+
const scalar = (v) => v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean";
|
|
206
|
+
function compileRuleGraph(rules = []) {
|
|
207
|
+
if (!Array.isArray(rules)) throw new TypeError("Rules must be an array");
|
|
208
|
+
const ids = /* @__PURE__ */ new Set();
|
|
209
|
+
const compiled = rules.map((rule, index) => {
|
|
210
|
+
if (!rule || typeof rule !== "object" || Array.isArray(rule)) throw new TypeError(`Rule[${index}] must be an object`);
|
|
211
|
+
const id = clean(rule.id), event = clean(rule.event), effect = rule.effect;
|
|
212
|
+
if (!id || ids.has(id)) throw new TypeError(`Rule[${index}] requires unique id`);
|
|
213
|
+
ids.add(id);
|
|
214
|
+
if (!event) throw new TypeError(`Rule[${index}] requires event`);
|
|
215
|
+
if (!effect || typeof effect !== "object" || allowedEffectKinds.has(effect.kind) === false) throw new TypeError(`Rule[${index}] unsupported effect`);
|
|
216
|
+
const targetId = clean(effect.targetId), stateKey = clean(effect.stateKey);
|
|
217
|
+
if (!targetId || !stateKey || !Object.prototype.hasOwnProperty.call(effect, "value") || !scalar(effect.value)) throw new TypeError(`Rule[${index}] set-state effect requires targetId/stateKey/scalar value`);
|
|
218
|
+
return {
|
|
219
|
+
id,
|
|
220
|
+
event,
|
|
221
|
+
condition: rule.condition ? compileCondition(rule.condition, `Rule[${index}] condition`) : null,
|
|
222
|
+
effect: {
|
|
223
|
+
kind: "set-state",
|
|
224
|
+
targetId,
|
|
225
|
+
stateKey,
|
|
226
|
+
value: effect.value
|
|
227
|
+
},
|
|
228
|
+
description: clean(rule.description) || void 0
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
return {
|
|
232
|
+
schema: SCHEMA,
|
|
233
|
+
schemaVersion: 1,
|
|
234
|
+
rules: compiled
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function compileCondition(condition, label) {
|
|
238
|
+
if (!condition || typeof condition !== "object" || Array.isArray(condition)) throw new TypeError(`${label} must be an object`);
|
|
239
|
+
const kind = clean(condition.kind);
|
|
240
|
+
if (kind === "equals") {
|
|
241
|
+
if (!clean(condition.targetId) || !clean(condition.stateKey) || !Object.prototype.hasOwnProperty.call(condition, "value") || !scalar(condition.value)) throw new TypeError(`${label} equals requires targetId/stateKey/value`);
|
|
242
|
+
return {
|
|
243
|
+
kind: "equals",
|
|
244
|
+
targetId: clean(condition.targetId),
|
|
245
|
+
stateKey: clean(condition.stateKey),
|
|
246
|
+
value: condition.value
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (kind === "not-equals") {
|
|
250
|
+
if (!clean(condition.targetId) || !clean(condition.stateKey) || !Object.prototype.hasOwnProperty.call(condition, "value") || !scalar(condition.value)) throw new TypeError(`${label} not-equals requires targetId/stateKey/value`);
|
|
251
|
+
return {
|
|
252
|
+
kind: "not-equals",
|
|
253
|
+
targetId: clean(condition.targetId),
|
|
254
|
+
stateKey: clean(condition.stateKey),
|
|
255
|
+
value: condition.value
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
throw new TypeError(`${label} unsupported kind: ${kind}`);
|
|
259
|
+
}
|
|
260
|
+
function evaluateRuleGraph(graph, event, stateReader) {
|
|
261
|
+
if (graph?.schema !== "agentscape.rule-graph" || graph.schemaVersion !== 1) throw new TypeError("Unsupported rule graph");
|
|
262
|
+
if (typeof stateReader !== "function") throw new TypeError("stateReader must be a function");
|
|
263
|
+
const matches = [];
|
|
264
|
+
for (const rule of graph.rules) {
|
|
265
|
+
if (rule.event !== event) continue;
|
|
266
|
+
if (rule.condition && !evaluateCondition(rule.condition, stateReader)) continue;
|
|
267
|
+
matches.push(structuredClone(rule.effect));
|
|
268
|
+
}
|
|
269
|
+
return matches;
|
|
270
|
+
}
|
|
271
|
+
function evaluateCondition(condition, stateReader) {
|
|
272
|
+
const value = stateReader(condition.targetId, condition.stateKey);
|
|
273
|
+
return condition.kind === "equals" ? Object.is(value, condition.value) : !Object.is(value, condition.value);
|
|
274
|
+
}
|
|
275
|
+
function executeRuleEffects(runtime, effects, { source = "rule-graph", eventId = null, ruleCascadeDepth = null } = {}) {
|
|
276
|
+
if (!Array.isArray(effects)) throw new TypeError("Rule effects must be an array");
|
|
277
|
+
if (!effects.length) return Promise.resolve({
|
|
278
|
+
status: "no-rule-match",
|
|
279
|
+
effects: []
|
|
280
|
+
});
|
|
281
|
+
return runtime.mutate(`rule:${eventId || source}`, async () => {
|
|
282
|
+
const applied = [];
|
|
283
|
+
for (const effect of effects) {
|
|
284
|
+
if (effect.kind !== "set-state") {
|
|
285
|
+
const error = /* @__PURE__ */ new TypeError(`Unsupported rule effect: ${effect.kind}`);
|
|
286
|
+
error.code = "RULE_EFFECT_UNSUPPORTED";
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
const result = runtime.applyStateTransition(effect.targetId, effect.stateKey, effect.value, {
|
|
290
|
+
source: "rule-graph",
|
|
291
|
+
event: eventId,
|
|
292
|
+
...ruleCascadeDepth == null ? {} : { ruleCascadeDepth }
|
|
293
|
+
});
|
|
294
|
+
if (result?.status !== "state-transition-applied") throw new Error(`Rule state transition rejected: ${effect.targetId}.${effect.stateKey}`);
|
|
295
|
+
applied.push(result);
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
status: "rule-effects-applied",
|
|
299
|
+
effects: applied
|
|
300
|
+
};
|
|
301
|
+
}, ruleCascadeDepth == null ? {} : { ruleCascadeDepth });
|
|
302
|
+
}
|
|
303
|
+
// modules/world/runtime/WorldAuthority.js
|
|
304
|
+
const clone$1 = (value) => value == null ? value : structuredClone(value);
|
|
305
|
+
function captureWorldAuthority(runtime) {
|
|
306
|
+
return {
|
|
307
|
+
currentWorldRevision: clone$1(runtime.currentWorldRevision) || null,
|
|
308
|
+
currentBehaviorBundle: clone$1(runtime.currentBehaviorBundle) || null,
|
|
309
|
+
currentPhysicsRequirements: clone$1(runtime.currentPhysicsRequirements) || null,
|
|
310
|
+
lastAcceptanceBundle: clone$1(runtime.lastAcceptanceBundle) || null,
|
|
311
|
+
restoredAcceptanceEvidence: clone$1(runtime.restoredAcceptanceEvidence) || null,
|
|
312
|
+
interactionEvidence: runtime.interactionEvidence instanceof Map ? [...runtime.interactionEvidence.entries()].map(([key, value]) => [key, clone$1(value)]) : null
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function restoreWorldAuthority(runtime, authority = {}) {
|
|
316
|
+
runtime.currentWorldRevision = clone$1(authority.currentWorldRevision) || null;
|
|
317
|
+
runtime.currentBehaviorBundle = clone$1(authority.currentBehaviorBundle) || null;
|
|
318
|
+
runtime.currentPhysicsRequirements = clone$1(authority.currentPhysicsRequirements) || null;
|
|
319
|
+
runtime.lastAcceptanceBundle = clone$1(authority.lastAcceptanceBundle) || null;
|
|
320
|
+
runtime.restoredAcceptanceEvidence = clone$1(authority.restoredAcceptanceEvidence) || null;
|
|
321
|
+
if (authority.interactionEvidence === null) delete runtime.interactionEvidence;
|
|
322
|
+
else runtime.interactionEvidence = new Map((authority.interactionEvidence || []).map(([key, value]) => [key, clone$1(value)]));
|
|
323
|
+
runtime.loadRuleGraph?.(authority.currentBehaviorBundle?.ruleGraph || []);
|
|
324
|
+
}
|
|
325
|
+
// modules/world/runtime/NativePhysicsSnapshot.js
|
|
326
|
+
const fail = (code) => Object.assign(new Error(code), { code });
|
|
327
|
+
const id = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/);
|
|
328
|
+
const number = z.number().finite().min(-1e6).max(1e6);
|
|
329
|
+
const vec3 = z.tuple([
|
|
330
|
+
number,
|
|
331
|
+
number,
|
|
332
|
+
number
|
|
333
|
+
]);
|
|
334
|
+
const quaternion = z.tuple([
|
|
335
|
+
number,
|
|
336
|
+
number,
|
|
337
|
+
number,
|
|
338
|
+
number
|
|
339
|
+
]).refine((q) => Math.abs(Math.hypot(...q) - 1) < .001);
|
|
340
|
+
const pose = z.object({
|
|
341
|
+
position: vec3,
|
|
342
|
+
rotation: quaternion
|
|
343
|
+
}).strict();
|
|
344
|
+
const motion = z.object({
|
|
345
|
+
linearVelocity: vec3,
|
|
346
|
+
angularVelocity: vec3,
|
|
347
|
+
sleeping: z.boolean()
|
|
348
|
+
}).strict();
|
|
349
|
+
const held = z.object({
|
|
350
|
+
kind: z.literal("agent"),
|
|
351
|
+
id,
|
|
352
|
+
anchor: z.literal("hold")
|
|
353
|
+
}).strict();
|
|
354
|
+
const partSnapshot = z.object({
|
|
355
|
+
name: id,
|
|
356
|
+
pose,
|
|
357
|
+
motion,
|
|
358
|
+
motorTarget: number.nullable()
|
|
359
|
+
}).strict();
|
|
360
|
+
const base = {
|
|
361
|
+
id,
|
|
362
|
+
signature: z.string().regex(/^[a-f0-9]{64}$/),
|
|
363
|
+
bindingId: z.string().uuid().optional()
|
|
364
|
+
};
|
|
365
|
+
const record = z.discriminatedUnion("body", [
|
|
366
|
+
z.object({
|
|
367
|
+
...base,
|
|
368
|
+
body: z.literal("kinematic")
|
|
369
|
+
}).strict(),
|
|
370
|
+
z.object({
|
|
371
|
+
...base,
|
|
372
|
+
body: z.literal("fixed"),
|
|
373
|
+
pose,
|
|
374
|
+
parts: z.array(partSnapshot).min(1).max(16).optional()
|
|
375
|
+
}).strict(),
|
|
376
|
+
z.object({
|
|
377
|
+
...base,
|
|
378
|
+
body: z.literal("dynamic"),
|
|
379
|
+
pose,
|
|
380
|
+
motion,
|
|
381
|
+
heldBy: held.nullable()
|
|
382
|
+
}).strict()
|
|
383
|
+
]);
|
|
384
|
+
const schema = z.object({
|
|
385
|
+
schema: z.literal("agentscape.native-physics-state"),
|
|
386
|
+
schemaVersion: z.literal(1),
|
|
387
|
+
bodies: z.array(record).max(1024)
|
|
388
|
+
}).strict();
|
|
389
|
+
function nativePhysicsBindings(runtime) {
|
|
390
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
391
|
+
for (const item of runtime.entities?.list?.({
|
|
392
|
+
source: "native",
|
|
393
|
+
capability: "physics"
|
|
394
|
+
}) || []) {
|
|
395
|
+
const entity = runtime.entities.get(item.id);
|
|
396
|
+
const spec = entity.manifest?.physics;
|
|
397
|
+
let mounted = false;
|
|
398
|
+
for (let node = entity.object; node; node = node.parent) if (node.uuid === entity.metadata.hostSceneUuid) {
|
|
399
|
+
mounted = true;
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
if (!mounted || !spec || !entity.metadata.physicsSignature || !entity.metadata.bindingId) throw fail("NATIVE_PHYSICS_BINDING_INVALID");
|
|
403
|
+
bindings.set(entity.id, entity);
|
|
404
|
+
}
|
|
405
|
+
return bindings;
|
|
406
|
+
}
|
|
407
|
+
/** Portable snapshots identify the source-declared body; history additionally pins the live registration. */
|
|
408
|
+
function captureNativePhysics(runtime, { identity = false } = {}) {
|
|
409
|
+
const bindings = nativePhysicsBindings(runtime);
|
|
410
|
+
if (!bindings.size) return void 0;
|
|
411
|
+
const bodies = [];
|
|
412
|
+
for (const [id, entity] of [...bindings].sort(([a], [b]) => a.localeCompare(b, "en"))) {
|
|
413
|
+
const spec = entity.manifest.physics, entry = runtime.physics.entries.get(id);
|
|
414
|
+
if (entity.manifest.nativeArticulation) linkNodes(entity);
|
|
415
|
+
if (!entry?.body || entry.root !== entity.object || entry.parts.size !== Object.keys(entity.manifest.parts || {}).length) throw fail("NATIVE_PHYSICS_BODY_UNAVAILABLE");
|
|
416
|
+
const body = spec.body;
|
|
417
|
+
const row = {
|
|
418
|
+
id,
|
|
419
|
+
signature: entity.metadata.physicsSignature,
|
|
420
|
+
body,
|
|
421
|
+
...identity ? { bindingId: entity.metadata.bindingId } : {}
|
|
422
|
+
};
|
|
423
|
+
const heldBy = entity.state?.heldBy || null;
|
|
424
|
+
if (runtime.physics.backend.bodyType(entry.body) !== (heldBy ? "kinematic" : body) || Boolean(entry.held) !== Boolean(heldBy)) throw fail("NATIVE_PHYSICS_OWNERSHIP_MISMATCH");
|
|
425
|
+
if (body !== "kinematic") row.pose = runtime.physics.backend.bodyPose(entry.body);
|
|
426
|
+
if (body === "dynamic") {
|
|
427
|
+
const { linearVelocity, angularVelocity, sleeping } = runtime.physics.getMotion(id);
|
|
428
|
+
row.motion = {
|
|
429
|
+
linearVelocity: heldBy ? [
|
|
430
|
+
0,
|
|
431
|
+
0,
|
|
432
|
+
0
|
|
433
|
+
] : linearVelocity,
|
|
434
|
+
angularVelocity: heldBy ? [
|
|
435
|
+
0,
|
|
436
|
+
0,
|
|
437
|
+
0
|
|
438
|
+
] : angularVelocity,
|
|
439
|
+
sleeping: heldBy ? false : sleeping
|
|
440
|
+
};
|
|
441
|
+
row.heldBy = heldBy ? structuredClone(heldBy) : null;
|
|
442
|
+
}
|
|
443
|
+
if (entry.parts.size) row.parts = [...entry.parts].map(([name, part]) => {
|
|
444
|
+
if (runtime.physics.backend.bodyType(part.body) !== "dynamic") throw fail("NATIVE_ARTICULATION_BODY_INVALID");
|
|
445
|
+
const { linearVelocity, angularVelocity, sleeping } = runtime.physics.backend.bodyMotion(part.body);
|
|
446
|
+
return {
|
|
447
|
+
name,
|
|
448
|
+
pose: runtime.physics.backend.bodyPose(part.body),
|
|
449
|
+
motion: {
|
|
450
|
+
linearVelocity,
|
|
451
|
+
angularVelocity,
|
|
452
|
+
sleeping
|
|
453
|
+
},
|
|
454
|
+
motorTarget: part.motorTarget ?? null
|
|
455
|
+
};
|
|
456
|
+
});
|
|
457
|
+
bodies.push(row);
|
|
458
|
+
}
|
|
459
|
+
return validateNativePhysics({
|
|
460
|
+
schema: "agentscape.native-physics-state",
|
|
461
|
+
schemaVersion: 1,
|
|
462
|
+
bodies
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
function validateNativePhysics(input, objects = null) {
|
|
466
|
+
const result = schema.safeParse(input);
|
|
467
|
+
if (!result.success) throw fail("NATIVE_PHYSICS_SNAPSHOT_INVALID");
|
|
468
|
+
const snapshot = result.data, ids = /* @__PURE__ */ new Set(), owners = /* @__PURE__ */ new Set();
|
|
469
|
+
const managed = objects && new Map(objects.map((object) => [object.id, object]));
|
|
470
|
+
if (objects) {
|
|
471
|
+
for (const object of objects) if (object.state?.heldBy?.kind === "agent") owners.add(object.state.heldBy.id);
|
|
472
|
+
}
|
|
473
|
+
if (snapshot.bodies.reduce((n, row) => n + 1 + (row.parts?.length || 0), 0) > 1024) throw fail("NATIVE_PHYSICS_SNAPSHOT_LIMIT");
|
|
474
|
+
for (const row of snapshot.bodies) {
|
|
475
|
+
if (row.parts && new Set(row.parts.map((p) => p.name)).size !== row.parts.length) throw fail("NATIVE_ARTICULATION_SNAPSHOT_INVALID");
|
|
476
|
+
if (ids.has(row.id) || managed?.has(row.id)) throw fail("NATIVE_PHYSICS_ID_CONFLICT");
|
|
477
|
+
ids.add(row.id);
|
|
478
|
+
if (row.heldBy) {
|
|
479
|
+
const owner = row.heldBy.id;
|
|
480
|
+
if (owners.has(owner) || managed && (!managed.has(owner) || managed.get(owner).active === false)) throw fail("NATIVE_PHYSICS_HELD_OWNER_INVALID");
|
|
481
|
+
if (row.motion.sleeping || [...row.motion.linearVelocity, ...row.motion.angularVelocity].some((n) => n !== 0)) throw fail("NATIVE_PHYSICS_HELD_MOTION_INVALID");
|
|
482
|
+
owners.add(owner);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return snapshot;
|
|
486
|
+
}
|
|
487
|
+
/** Preflight before resetting a solver or replacing any managed entity. No body definitions are trusted from a save. */
|
|
488
|
+
function prepareNativePhysics(runtime, input, objects = null, { compatible = false } = {}) {
|
|
489
|
+
const snapshot = validateNativePhysics(input, objects), bindings = nativePhysicsBindings(runtime), selected = [], skipped = [];
|
|
490
|
+
const matches = (row) => {
|
|
491
|
+
const entity = bindings.get(row.id);
|
|
492
|
+
return entity && entity.metadata.physicsSignature === row.signature && entity.manifest.physics.body === row.body && (!row.bindingId || entity.metadata.bindingId === row.bindingId);
|
|
493
|
+
};
|
|
494
|
+
for (const row of snapshot.bodies) {
|
|
495
|
+
if (!matches(row)) {
|
|
496
|
+
if (!compatible || row.heldBy) throw fail("NATIVE_PHYSICS_BINDING_MISMATCH");
|
|
497
|
+
skipped.push({
|
|
498
|
+
id: row.id,
|
|
499
|
+
reason: "BINDING_CHANGED_OR_MISSING"
|
|
500
|
+
});
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (row.heldBy && (bindings.get(row.id).manifest.physics.carryable !== true || !inferCarryCapability(bindings.get(row.id).manifest).eligible)) throw fail("NATIVE_PHYSICS_HELD_BODY_INVALID");
|
|
504
|
+
validateArticulationSnapshot(bindings.get(row.id), row);
|
|
505
|
+
selected.push(row);
|
|
506
|
+
}
|
|
507
|
+
const selectedIds = new Set(selected.map((row) => row.id));
|
|
508
|
+
for (const id of bindings.keys()) if (!selectedIds.has(id)) {
|
|
509
|
+
if (!compatible) throw fail("NATIVE_PHYSICS_BINDING_MISMATCH");
|
|
510
|
+
if (!skipped.some((row) => row.id === id)) skipped.push({
|
|
511
|
+
id,
|
|
512
|
+
reason: "NEW_BINDING"
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
snapshot: {
|
|
517
|
+
...snapshot,
|
|
518
|
+
bodies: selected
|
|
519
|
+
},
|
|
520
|
+
bindings,
|
|
521
|
+
skipped
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function linkNodes(entity) {
|
|
525
|
+
const definitions = entity.manifest.parts || {}, nodes = /* @__PURE__ */ new Map();
|
|
526
|
+
if (!Object.keys(definitions).length) return nodes;
|
|
527
|
+
const names = new Set(Object.values(definitions).map((part) => part.node)), byName = /* @__PURE__ */ new Map();
|
|
528
|
+
let count = 0;
|
|
529
|
+
entity.object.traverse((node) => {
|
|
530
|
+
if (++count > 8192) throw fail("NATIVE_ARTICULATION_NODE_LIMIT");
|
|
531
|
+
if (!names.has(node.name)) return;
|
|
532
|
+
if (node === entity.object || byName.has(node.name)) throw fail("NATIVE_ARTICULATION_LINK_HIERARCHY_INVALID");
|
|
533
|
+
byName.set(node.name, node);
|
|
534
|
+
});
|
|
535
|
+
for (const [id, part] of Object.entries(definitions)) {
|
|
536
|
+
const node = byName.get(part.node);
|
|
537
|
+
const parent = part.parent === "$root" ? entity.object : byName.get(definitions[part.parent]?.node);
|
|
538
|
+
if (!node || !parent || node.uuid !== entity.metadata.articulationNodeUuids?.[id] || node.parent !== parent || !node.matrixAutoUpdate || node.scale.toArray().some((n) => !Number.isFinite(n) || Math.abs(n - 1) > 1e-6)) throw fail("NATIVE_ARTICULATION_LINK_HIERARCHY_INVALID");
|
|
539
|
+
nodes.set(id, node);
|
|
540
|
+
}
|
|
541
|
+
return nodes;
|
|
542
|
+
}
|
|
543
|
+
function relativePose(parent, child) {
|
|
544
|
+
const inverse = new THREE.Quaternion(...parent.rotation).invert();
|
|
545
|
+
return {
|
|
546
|
+
position: new THREE.Vector3(...child.position).sub(new THREE.Vector3(...parent.position)).applyQuaternion(inverse).toArray(),
|
|
547
|
+
rotation: inverse.multiply(new THREE.Quaternion(...child.rotation)).normalize().toArray()
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
function validateArticulationSnapshot(entity, row) {
|
|
551
|
+
const definitions = entity.manifest.parts || {}, expected = Object.keys(definitions), parts = row.parts || [];
|
|
552
|
+
if (parts.length !== expected.length || parts.some((p) => !Object.hasOwn(definitions, p.name))) throw fail("NATIVE_ARTICULATION_SNAPSHOT_MISMATCH");
|
|
553
|
+
if (!parts.length) return;
|
|
554
|
+
linkNodes(entity);
|
|
555
|
+
const poses = new Map(parts.map((p) => [p.name, p.pose]));
|
|
556
|
+
poses.set("$root", row.pose);
|
|
557
|
+
for (const part of parts) {
|
|
558
|
+
const definition = definitions[part.name], joint = definition.joint, rest = entity.metadata.articulationRest[part.name];
|
|
559
|
+
const local = relativePose(poses.get(definition.parent), part.pose);
|
|
560
|
+
const axis = new THREE.Vector3(...joint.axis), rotation = new THREE.Quaternion(...local.rotation);
|
|
561
|
+
const delta = rotation.clone().multiply(new THREE.Quaternion(...rest.rotation).invert()).normalize();
|
|
562
|
+
const displacement = new THREE.Vector3(...local.position).sub(new THREE.Vector3(...rest.position));
|
|
563
|
+
const coordinate = joint.type === "prismatic" ? displacement.dot(axis) : Math.atan2(Math.sin(2 * Math.atan2(delta.x * axis.x + delta.y * axis.y + delta.z * axis.z, delta.w)), Math.cos(2 * Math.atan2(delta.x * axis.x + delta.y * axis.y + delta.z * axis.z, delta.w)));
|
|
564
|
+
const expectedRotation = joint.type === "prismatic" ? new THREE.Quaternion(...rest.rotation) : new THREE.Quaternion().setFromAxisAngle(axis, coordinate).multiply(new THREE.Quaternion(...rest.rotation));
|
|
565
|
+
const anchorError = new THREE.Vector3(...local.position).add(new THREE.Vector3(...joint.childAnchor).applyQuaternion(rotation)).sub(new THREE.Vector3(...joint.parentAnchor));
|
|
566
|
+
if (joint.type === "prismatic") anchorError.addScaledVector(axis, -coordinate);
|
|
567
|
+
const tolerance = joint.type === "prismatic" ? .03 : .08;
|
|
568
|
+
if (!Number.isFinite(coordinate) || coordinate < joint.limits[0] - tolerance || coordinate > joint.limits[1] + tolerance || anchorError.length() > .06 || rotation.angleTo(expectedRotation) > .1 || part.motorTarget !== null && (part.motorTarget < joint.limits[0] || part.motorTarget > joint.limits[1])) throw fail("NATIVE_ARTICULATION_SNAPSHOT_POSE_INVALID");
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function localPose(entity, worldPose) {
|
|
572
|
+
const parent = entity.object.parent;
|
|
573
|
+
const position = new THREE.Vector3(...worldPose.position), rotation = new THREE.Quaternion(...worldPose.rotation);
|
|
574
|
+
if (parent) {
|
|
575
|
+
parent.updateWorldMatrix(true, false);
|
|
576
|
+
const p = new THREE.Vector3(), q = new THREE.Quaternion(), s = new THREE.Vector3();
|
|
577
|
+
parent.matrixWorld.decompose(p, q, s);
|
|
578
|
+
if (s.toArray().some((value) => Math.abs(value - 1) > 1e-6) || parent.matrixWorld.elements.some((value, index) => Math.abs(value - new THREE.Matrix4().compose(p, q, s).elements[index]) > 1e-6)) throw fail("NATIVE_PHYSICS_PARENT_TRANSFORM_INVALID");
|
|
579
|
+
parent.worldToLocal(position);
|
|
580
|
+
rotation.premultiply(q.invert()).normalize();
|
|
581
|
+
}
|
|
582
|
+
return {
|
|
583
|
+
position: position.toArray(),
|
|
584
|
+
rotation: rotation.toArray()
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
/** Called after managed agents and their held ownership have been restored. Native objects are never recreated. */
|
|
588
|
+
function applyNativePhysics(runtime, prepared) {
|
|
589
|
+
const { snapshot, bindings } = prepared;
|
|
590
|
+
const carry = runtime.interactions?.carry;
|
|
591
|
+
for (const entity of bindings.values()) {
|
|
592
|
+
if (entity.state?.heldBy) carry.releaseHeld(entity.id, "NATIVE_PHYSICS_RESTORE", { silent: true });
|
|
593
|
+
const entry = runtime.physics.entries.get(entity.id);
|
|
594
|
+
if (!entry) {
|
|
595
|
+
for (const [name, node] of linkNodes(entity)) {
|
|
596
|
+
const rest = entity.metadata.articulationRest[name];
|
|
597
|
+
node.position.fromArray(rest.position);
|
|
598
|
+
node.quaternion.fromArray(rest.rotation);
|
|
599
|
+
}
|
|
600
|
+
entity.object.updateMatrixWorld(true);
|
|
601
|
+
runtime.physics.addObject(entity.id, entity.manifest, entity.object);
|
|
602
|
+
} else if (entry.root !== entity.object) throw fail("NATIVE_PHYSICS_BODY_CONFLICT");
|
|
603
|
+
if (entity.manifest.physics.body === "kinematic") {
|
|
604
|
+
const body = runtime.physics.entries.get(entity.id).body;
|
|
605
|
+
const pose = {
|
|
606
|
+
position: entity.object.getWorldPosition(new THREE.Vector3()).toArray(),
|
|
607
|
+
rotation: entity.object.getWorldQuaternion(new THREE.Quaternion()).toArray()
|
|
608
|
+
};
|
|
609
|
+
runtime.physics.backend.setBodyPose(body, {
|
|
610
|
+
...pose,
|
|
611
|
+
wake: false
|
|
612
|
+
});
|
|
613
|
+
runtime.physics.backend.setBodyPose(body, {
|
|
614
|
+
...pose,
|
|
615
|
+
next: true,
|
|
616
|
+
wake: false
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
const checkpoints = [];
|
|
621
|
+
for (const row of snapshot.bodies) {
|
|
622
|
+
if (row.body === "kinematic") continue;
|
|
623
|
+
const entity = bindings.get(row.id), heldBy = row.heldBy || null;
|
|
624
|
+
const root = {
|
|
625
|
+
...localPose(entity, row.pose),
|
|
626
|
+
type: heldBy ? "kinematic" : row.body,
|
|
627
|
+
pose: row.pose,
|
|
628
|
+
...row.motion ? { motion: row.motion } : {},
|
|
629
|
+
...heldBy ? { nextPose: row.pose } : {}
|
|
630
|
+
};
|
|
631
|
+
const savedParts = new Map((row.parts || []).map((part) => [part.name, part]));
|
|
632
|
+
const poses = new Map((row.parts || []).map((part) => [part.name, part.pose]));
|
|
633
|
+
poses.set("$root", row.pose);
|
|
634
|
+
const parts = [...runtime.physics.entries.get(row.id).parts].map(([name, part]) => {
|
|
635
|
+
const saved = savedParts.get(name);
|
|
636
|
+
if (!saved) throw fail("NATIVE_ARTICULATION_SNAPSHOT_MISMATCH");
|
|
637
|
+
return {
|
|
638
|
+
name,
|
|
639
|
+
...relativePose(poses.get(part.parentName), saved.pose),
|
|
640
|
+
type: "dynamic",
|
|
641
|
+
pose: saved.pose,
|
|
642
|
+
motion: saved.motion,
|
|
643
|
+
motorTarget: saved.motorTarget
|
|
644
|
+
};
|
|
645
|
+
});
|
|
646
|
+
checkpoints.push({
|
|
647
|
+
id: row.id,
|
|
648
|
+
root,
|
|
649
|
+
parts,
|
|
650
|
+
held: Boolean(heldBy),
|
|
651
|
+
heldOriginalType: heldBy ? "dynamic" : null
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
runtime.physics.restoreState(checkpoints);
|
|
655
|
+
runtime.physics.backend.syncSceneQueries(runtime.physics.world);
|
|
656
|
+
for (const row of snapshot.bodies) {
|
|
657
|
+
if (!row.heldBy) continue;
|
|
658
|
+
const { id: actor } = row.heldBy, entity = bindings.get(row.id);
|
|
659
|
+
const owner = runtime.store.has(actor) ? runtime.store.get(actor) : null;
|
|
660
|
+
if (!carry || !owner || owner.active === false || owner.manifest.type !== "agent" || carry.heldByAgent(actor)) throw fail("NATIVE_PHYSICS_HELD_OWNER_INVALID");
|
|
661
|
+
const anchor = runtime.physics.anchorPose(actor, carry.holdAnchor(actor));
|
|
662
|
+
const positionError = anchor ? Math.hypot(...row.pose.position.map((n, i) => n - anchor.position[i])) : 1e400;
|
|
663
|
+
const angleError = anchor ? new THREE.Quaternion(...row.pose.rotation).angleTo(new THREE.Quaternion(...anchor.rotation)) : 1e400;
|
|
664
|
+
if (positionError > .15 || angleError > .2 || !runtime.physics.checkBodyPose(row.id, row.pose.position, row.pose.rotation, { excludeIds: [actor] }).clear) throw fail("NATIVE_PHYSICS_HELD_POSE_INVALID");
|
|
665
|
+
entity.state.heldBy = structuredClone(row.heldBy);
|
|
666
|
+
carry.agentHeld.set(actor, row.id);
|
|
667
|
+
runtime.physics.setHeldTarget(row.id, anchor.position, anchor.rotation);
|
|
668
|
+
}
|
|
669
|
+
runtime.navigation?.invalidate?.("native-physics-restored");
|
|
670
|
+
return {
|
|
671
|
+
restored: snapshot.bodies.length,
|
|
672
|
+
skipped: prepared.skipped
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
// modules/world/runtime/SceneSerializer.js
|
|
676
|
+
const SCENE_SCHEMA = "agentscape.scene";
|
|
677
|
+
const clone = (value) => JSON.parse(JSON.stringify(value));
|
|
678
|
+
const isFiniteVec = (value, length) => Array.isArray(value) && value.length === length && value.every(Number.isFinite);
|
|
679
|
+
var SceneSerializer = class {
|
|
680
|
+
*objects(runtime) {
|
|
681
|
+
for (const [id, record] of runtime.store.entries()) {
|
|
682
|
+
const object = record.object;
|
|
683
|
+
const articulation = runtime.physics?.captureArticulationPose?.(id) || [];
|
|
684
|
+
yield {
|
|
685
|
+
id,
|
|
686
|
+
assetId: record.assetId,
|
|
687
|
+
transform: {
|
|
688
|
+
position: object.position.toArray(),
|
|
689
|
+
quaternion: object.quaternion.toArray(),
|
|
690
|
+
scale: object.scale.toArray()
|
|
691
|
+
},
|
|
692
|
+
state: clone(record.state || {}),
|
|
693
|
+
...runtime.thermal?.capture?.(id) ? { simulation: runtime.thermal.capture(id) } : {},
|
|
694
|
+
...record.active === false ? { active: false } : {},
|
|
695
|
+
...articulation.length ? { articulation } : record.dormantArticulation?.length ? { articulation: clone(record.dormantArticulation) } : {}
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
serialize(runtime, { name = "Untitled World", includeRelations = true, includeObjects = true, nativeIdentity = false } = {}) {
|
|
700
|
+
if (includeRelations) runtime.sceneGraph?.update?.();
|
|
701
|
+
const objects = includeObjects ? Array.from(this.objects(runtime)) : [];
|
|
702
|
+
const assets = [...new Set(objects.map((object) => object.assetId))].map((assetId) => runtime.assetModule.getManifest(assetId)).filter((manifest) => ["glb", "compiled"].includes(manifest.source?.kind)).map(clone);
|
|
703
|
+
const worldRevision = runtime.currentWorldRevision ? clone(runtime.currentWorldRevision) : null;
|
|
704
|
+
const acceptanceEvidence = runtime.lastAcceptanceBundle ? clone(runtime.lastAcceptanceBundle) : null;
|
|
705
|
+
const nativePhysics = captureNativePhysics(runtime, { identity: nativeIdentity });
|
|
706
|
+
const cameraState = runtime.rendering?.cameraState?.() || null;
|
|
707
|
+
const presentation = runtime.presentation?.snapshot() || null;
|
|
708
|
+
const stylePack = runtime.rendering?.serializeStyle?.() ?? runtime.styleSystem?.export() ?? null;
|
|
709
|
+
return {
|
|
710
|
+
schema: SCENE_SCHEMA,
|
|
711
|
+
schemaVersion: 1,
|
|
712
|
+
metadata: {
|
|
713
|
+
name,
|
|
714
|
+
savedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
715
|
+
generator: `AgentScape/${runtime.version || "unknown"}`,
|
|
716
|
+
environment: runtime.environment?.id || null,
|
|
717
|
+
...stylePack ? { stylePack } : {},
|
|
718
|
+
...runtime.environment?.snapshot ? { environmentState: clone(runtime.environment.snapshot()) } : {},
|
|
719
|
+
...worldRevision ? { worldRevision } : {}
|
|
720
|
+
},
|
|
721
|
+
...captureSceneExtensions(runtime),
|
|
722
|
+
assets,
|
|
723
|
+
objects,
|
|
724
|
+
...nativePhysics ? { nativePhysics } : {},
|
|
725
|
+
configuration: {
|
|
726
|
+
...runtime.timeline ? { timeline: runtime.timeline.snapshot() } : {},
|
|
727
|
+
behaviorBundle: runtime.currentBehaviorBundle ? clone(runtime.currentBehaviorBundle) : null,
|
|
728
|
+
physicsRequirements: runtime.currentPhysicsRequirements ? clone(runtime.currentPhysicsRequirements) : null
|
|
729
|
+
},
|
|
730
|
+
...includeRelations ? { relations: runtime.sceneGraph?.list?.() || [] } : {},
|
|
731
|
+
...acceptanceEvidence ? { verification: { acceptanceEvidence } } : {},
|
|
732
|
+
...cameraState ? { camera: cameraState } : {},
|
|
733
|
+
...presentation ? { presentation } : {}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
validate(scene, runtime) {
|
|
737
|
+
if (!scene || typeof scene !== "object") throw new Error("Scene must be an object");
|
|
738
|
+
if (scene.schema !== "agentscape.scene") throw new Error(`Unsupported scene schema: ${scene.schema || "missing"}`);
|
|
739
|
+
if (scene.schemaVersion !== 1) throw new Error(`Unsupported scene version: ${scene.schemaVersion}`);
|
|
740
|
+
if (!Array.isArray(scene.objects)) throw new Error("Scene objects must be an array");
|
|
741
|
+
if (!Array.isArray(scene.assets)) throw new Error("Scene assets must be an array");
|
|
742
|
+
validateSceneExtensions(scene.extensions, runtime);
|
|
743
|
+
if (scene.camera != null && (!isFiniteVec(scene.camera.position, 3) || !isFiniteVec(scene.camera.target, 3))) throw new Error("Scene camera requires finite position and target");
|
|
744
|
+
if (scene.configuration?.timeline != null) timelineSnapshotSchema.parse(scene.configuration.timeline);
|
|
745
|
+
if (scene.presentation != null) parseScenePresentation(scene.presentation);
|
|
746
|
+
if (scene.relations != null && !Array.isArray(scene.relations)) throw new Error("Scene relations must be an array");
|
|
747
|
+
const worldRevision = scene.metadata?.worldRevision;
|
|
748
|
+
if (worldRevision != null) {
|
|
749
|
+
if (!worldRevision || typeof worldRevision !== "object" || Array.isArray(worldRevision)) throw new Error("Scene worldRevision must be an object");
|
|
750
|
+
if (!worldRevision.revision?.id) throw new Error("Scene worldRevision requires revision.id");
|
|
751
|
+
if (!worldRevision.provenance?.source) throw new Error("Scene worldRevision requires provenance.source");
|
|
752
|
+
}
|
|
753
|
+
const configuration = scene.configuration;
|
|
754
|
+
if (configuration != null) {
|
|
755
|
+
if (typeof configuration !== "object" || Array.isArray(configuration)) throw new Error("Invalid scene configuration");
|
|
756
|
+
for (const key of ["behaviorBundle", "physicsRequirements"]) {
|
|
757
|
+
const value = configuration[key];
|
|
758
|
+
if (value != null && (typeof value !== "object" || Array.isArray(value))) throw new Error(`Invalid scene ${key}`);
|
|
759
|
+
if (value?.worldRevisionId && value.worldRevisionId !== worldRevision?.revision?.id) throw new Error(`Scene ${key} revision mismatch`);
|
|
760
|
+
}
|
|
761
|
+
const graph = configuration.behaviorBundle?.ruleGraph || [];
|
|
762
|
+
if (!Array.isArray(graph) && (graph.schema !== "agentscape.rule-graph" || graph.schemaVersion !== 1)) throw new Error("Invalid scene rule graph");
|
|
763
|
+
compileRuleGraph(Array.isArray(graph) ? graph : graph.rules);
|
|
764
|
+
}
|
|
765
|
+
const acceptanceEvidence = scene.verification?.acceptanceEvidence;
|
|
766
|
+
if (acceptanceEvidence != null) {
|
|
767
|
+
if (acceptanceEvidence.schema !== "agentscape.acceptance-evidence" || acceptanceEvidence.schemaVersion !== 1) throw new Error("Unsupported acceptance evidence");
|
|
768
|
+
if (!Array.isArray(acceptanceEvidence.criteria) || !acceptanceEvidence.result || typeof acceptanceEvidence.result !== "object") throw new Error("Invalid acceptance evidence payload");
|
|
769
|
+
const revisionId = worldRevision?.revision?.id || null;
|
|
770
|
+
if (revisionId && acceptanceEvidence.worldRevisionId && acceptanceEvidence.worldRevisionId !== revisionId) throw new Error(`Acceptance evidence revision mismatch: ${acceptanceEvidence.worldRevisionId} != ${revisionId}`);
|
|
771
|
+
}
|
|
772
|
+
const objectIds = /* @__PURE__ */ new Set();
|
|
773
|
+
for (const object of scene.objects) {
|
|
774
|
+
if (!object.id || !object.assetId) throw new Error("Scene object requires id and assetId");
|
|
775
|
+
if (object.active != null && typeof object.active !== "boolean") throw new Error("Invalid entity activation");
|
|
776
|
+
if (object.simulation != null) {
|
|
777
|
+
if (!thermalStateSchema.safeParse(object.simulation).success) throw new Error("Invalid entity thermal state");
|
|
778
|
+
}
|
|
779
|
+
if (object.articulation != null) {
|
|
780
|
+
if (!Array.isArray(object.articulation) || object.articulation.length > 128) throw new Error("Invalid articulation poses");
|
|
781
|
+
const names = /* @__PURE__ */ new Set();
|
|
782
|
+
for (const part of object.articulation) {
|
|
783
|
+
if (!part || typeof part.partName !== "string" || names.has(part.partName) || !isFiniteVec(part.position, 3) || !isFiniteVec(part.quaternion, 4) || Math.abs(Math.hypot(...part.quaternion) - 1) > .001 || part.motorTarget != null && !Number.isFinite(part.motorTarget)) throw new Error("Invalid articulation pose");
|
|
784
|
+
names.add(part.partName);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
if (objectIds.has(object.id)) throw new Error(`Duplicate scene object id: ${object.id}`);
|
|
788
|
+
objectIds.add(object.id);
|
|
789
|
+
}
|
|
790
|
+
const heldOwners = /* @__PURE__ */ new Set();
|
|
791
|
+
for (const object of scene.objects) {
|
|
792
|
+
if (!isFiniteVec(object.transform?.position, 3)) throw new Error(`${object.id}: invalid position`);
|
|
793
|
+
if (!isFiniteVec(object.transform?.quaternion, 4)) throw new Error(`${object.id}: invalid quaternion`);
|
|
794
|
+
if (!isFiniteVec(object.transform?.scale, 3)) throw new Error(`${object.id}: invalid scale`);
|
|
795
|
+
uniformScaleValue(object.transform.scale);
|
|
796
|
+
const heldBy = object.state?.heldBy;
|
|
797
|
+
if (heldBy) {
|
|
798
|
+
if (!["human", "agent"].includes(heldBy.kind)) throw new Error(`${object.id}: invalid heldBy.kind`);
|
|
799
|
+
const ownerKey = heldBy.kind === "human" ? "human" : `agent:${heldBy.id}`;
|
|
800
|
+
if (heldBy.kind === "agent" && (!heldBy.id || !objectIds.has(heldBy.id))) throw new Error(`${object.id}: heldBy agent is missing`);
|
|
801
|
+
if (heldOwners.has(ownerKey)) throw new Error(`${ownerKey}: multiple held objects are not supported`);
|
|
802
|
+
heldOwners.add(ownerKey);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (scene.nativePhysics != null) validateNativePhysics(scene.nativePhysics, scene.objects);
|
|
806
|
+
return scene;
|
|
807
|
+
}
|
|
808
|
+
async restore(runtime, input, physics) {
|
|
809
|
+
const scene = this.validate(clone(input), runtime);
|
|
810
|
+
runtime.rendering?.validateStyle?.(scene.metadata?.stylePack || null);
|
|
811
|
+
const sceneEnvironment = scene.metadata?.environment;
|
|
812
|
+
const runtimeEnvironment = runtime.environment?.id;
|
|
813
|
+
if (sceneEnvironment && runtimeEnvironment && sceneEnvironment !== runtimeEnvironment) throw new Error(`Scene environment mismatch: ${sceneEnvironment} != ${runtimeEnvironment}`);
|
|
814
|
+
const incoming = /* @__PURE__ */ new Map();
|
|
815
|
+
for (const manifest of scene.assets) {
|
|
816
|
+
if (incoming.has(manifest.id)) throw new Error("Duplicate scene asset: " + manifest.id);
|
|
817
|
+
runtime.assetModule.assertCompatibleManifest(manifest);
|
|
818
|
+
incoming.set(manifest.id, manifest);
|
|
819
|
+
}
|
|
820
|
+
for (const item of scene.objects) {
|
|
821
|
+
if (!incoming.has(item.assetId) && !runtime.assetModule.hasAsset(item.assetId)) throw new Error(`Scene references unknown asset: ${item.assetId}`);
|
|
822
|
+
if (item.simulation) {
|
|
823
|
+
const profile = (incoming.get(item.assetId) ?? runtime.assetModule.getManifest(item.assetId)).simulation;
|
|
824
|
+
if (!profile) throw new Error(`Scene has thermal state without a thermal asset: ${item.id}`);
|
|
825
|
+
validateThermalStateForProfile(profile, item.simulation);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
if (scene.metadata?.environmentState) runtime.environment?.validateSnapshot?.(scene.metadata.environmentState);
|
|
829
|
+
const nativePhysics = scene.nativePhysics ?? captureNativePhysics(runtime, { identity: true });
|
|
830
|
+
if (nativePhysics) {
|
|
831
|
+
prepareNativePhysics(runtime, nativePhysics, scene.objects);
|
|
832
|
+
scene.nativePhysics = nativePhysics;
|
|
833
|
+
}
|
|
834
|
+
const previous = typeof runtime.snapshot === "function" ? runtime.snapshot() : null;
|
|
835
|
+
const previousAuthority = captureWorldAuthority(runtime);
|
|
836
|
+
const previousPhysics = runtime.physics?.captureState?.();
|
|
837
|
+
const attachments = runtime.projectCapabilities?.captureAttachments?.() || [];
|
|
838
|
+
const added = [];
|
|
839
|
+
try {
|
|
840
|
+
for (const manifest of scene.assets) if (!runtime.assetModule.hasAsset(manifest.id) && runtime.assetModule.registry.registerManifest(manifest)) added.push(manifest.id);
|
|
841
|
+
const applied = await this.applyScene(runtime, scene);
|
|
842
|
+
if (physics) {
|
|
843
|
+
runtime.physics.restoreState(physics);
|
|
844
|
+
runtime.sceneGraph?.invalidate();
|
|
845
|
+
}
|
|
846
|
+
runtime.projectCapabilities?.rebindAttachments?.(attachments);
|
|
847
|
+
return applied;
|
|
848
|
+
} catch (error) {
|
|
849
|
+
for (const id of added) runtime.assetModule.registry.removeManifest(id);
|
|
850
|
+
if (!previous) throw error;
|
|
851
|
+
try {
|
|
852
|
+
await this.applyScene(runtime, previous);
|
|
853
|
+
if (previousPhysics) {
|
|
854
|
+
runtime.physics.restoreState(previousPhysics);
|
|
855
|
+
runtime.sceneGraph?.invalidate?.();
|
|
856
|
+
}
|
|
857
|
+
restoreWorldAuthority(runtime, previousAuthority);
|
|
858
|
+
runtime.projectCapabilities?.rebindAttachments?.(attachments);
|
|
859
|
+
} catch (rollbackError) {
|
|
860
|
+
const failure = new AggregateError([error, rollbackError], "Scene restore rollback failed", { cause: error });
|
|
861
|
+
failure.code = "SCENE_RESTORE_ROLLBACK_FAILED";
|
|
862
|
+
runtime.quarantine?.(failure.code);
|
|
863
|
+
failure.rollbackError = rollbackError;
|
|
864
|
+
throw failure;
|
|
865
|
+
}
|
|
866
|
+
throw error;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
async applyScene(runtime, scene) {
|
|
870
|
+
const nativePhysics = scene.nativePhysics ?? captureNativePhysics(runtime, { identity: true });
|
|
871
|
+
const preparedNative = nativePhysics ? prepareNativePhysics(runtime, nativePhysics, scene.objects) : null;
|
|
872
|
+
runtime.affordances?.cancel("SCENE_RESTORE");
|
|
873
|
+
if (typeof runtime.physics?.resetWorld === "function") {
|
|
874
|
+
runtime.locomotion?.cancelAll?.();
|
|
875
|
+
runtime.interactions?.cancelPending?.("SCENE_RESTORE");
|
|
876
|
+
runtime.physics.resetWorld();
|
|
877
|
+
if (runtime.environment?.colliders?.length) runtime.physics.addEnvironment(runtime.environment.colliders, { id: runtime.environment.id });
|
|
878
|
+
const characterOptions = runtime.environment?.physics?.characterController || runtime.environment?.characterController || null;
|
|
879
|
+
if (characterOptions && typeof runtime.physics.setCharacterControllerOptions === "function") runtime.physics.setCharacterControllerOptions(characterOptions);
|
|
880
|
+
}
|
|
881
|
+
await runtime.sceneGraph.batch(async () => {
|
|
882
|
+
await runtime.clearObjects({ silent: true });
|
|
883
|
+
for (const item of scene.objects) {
|
|
884
|
+
await runtime.spawn(item.assetId, {
|
|
885
|
+
id: item.id,
|
|
886
|
+
position: item.transform.position,
|
|
887
|
+
quaternion: item.transform.quaternion,
|
|
888
|
+
scale: item.transform.scale,
|
|
889
|
+
active: item.active !== false
|
|
890
|
+
});
|
|
891
|
+
const record = runtime.store.get(item.id);
|
|
892
|
+
if (item.simulation) runtime.thermal.restore(item.id, item.simulation);
|
|
893
|
+
runtime.restoreObjectState(item.id, clone(item.state || {}));
|
|
894
|
+
if (item.articulation?.length) {
|
|
895
|
+
if (record.active === false) record.dormantArticulation = clone(item.articulation);
|
|
896
|
+
else runtime.physics.restoreArticulationPose(item.id, item.articulation);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
runtime.interactions?.rebuildHeldOwnership?.();
|
|
900
|
+
if (preparedNative) applyNativePhysics(runtime, preparedNative);
|
|
901
|
+
runtime.sceneGraph.changed();
|
|
902
|
+
});
|
|
903
|
+
if (scene.metadata?.environmentState) runtime.environment?.restore?.(scene.metadata.environmentState);
|
|
904
|
+
runtime.navigation?.invalidate?.("scene-restored");
|
|
905
|
+
if (scene.camera) runtime.rendering?.applyCameraState?.(scene.camera);
|
|
906
|
+
runtime.presentation?.replace(scene.presentation ?? {});
|
|
907
|
+
const style = scene.metadata?.stylePack ?? null;
|
|
908
|
+
if (runtime.rendering?.restoreStyle) await runtime.rendering.restoreStyle(style);
|
|
909
|
+
else if (runtime.styleSystem) {
|
|
910
|
+
if (style) await runtime.styleSystem.set(style);
|
|
911
|
+
else runtime.styleSystem.clear();
|
|
912
|
+
}
|
|
913
|
+
runtime.currentWorldRevision = scene.metadata?.worldRevision ? clone(scene.metadata.worldRevision) : null;
|
|
914
|
+
runtime.restoredAcceptanceEvidence = scene.verification?.acceptanceEvidence ? clone(scene.verification.acceptanceEvidence) : null;
|
|
915
|
+
runtime.lastAcceptanceBundle = null;
|
|
916
|
+
runtime.currentBehaviorBundle = scene.configuration?.behaviorBundle ? clone(scene.configuration.behaviorBundle) : null;
|
|
917
|
+
runtime.currentPhysicsRequirements = scene.configuration?.physicsRequirements ? clone(scene.configuration.physicsRequirements) : null;
|
|
918
|
+
runtime.interactionEvidence?.clear?.();
|
|
919
|
+
runtime.loadRuleGraph?.(runtime.currentBehaviorBundle?.ruleGraph || []);
|
|
920
|
+
restoreSceneExtensions(runtime, scene.extensions);
|
|
921
|
+
runtime.timeline?.restore(scene.configuration?.timeline);
|
|
922
|
+
runtime.events.emit("scene.restored", {
|
|
923
|
+
objects: scene.objects.length,
|
|
924
|
+
worldRevisionId: runtime.currentWorldRevision?.revision?.id || null,
|
|
925
|
+
hasAcceptanceEvidence: Boolean(runtime.restoredAcceptanceEvidence)
|
|
926
|
+
});
|
|
927
|
+
return scene;
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
export { captureWorldAuthority as a, evaluateRuleGraph as c, prepareNativePhysics as i, executeRuleEffects as l, applyNativePhysics as n, restoreWorldAuthority as o, nativePhysicsBindings as r, compileRuleGraph as s, SceneSerializer as t, WorldTimeline as u };
|
|
931
|
+
|
|
932
|
+
//# sourceMappingURL=SceneSerializer-zOzbX4jZ.js.map
|