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,402 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { visualComponentBounds } from '../spatial/VisualMeshBounds.js';
|
|
3
|
+
import { nativeCarryRecord } from '../interaction/NativePhysicalTarget.js';
|
|
4
|
+
import {
|
|
5
|
+
boxesOverlap,
|
|
6
|
+
objectWorldPosition,
|
|
7
|
+
spatialEntryAtRootPosition,
|
|
8
|
+
spatialSnapshotEntry
|
|
9
|
+
} from '../spatial/SpatialSnapshot.js';
|
|
10
|
+
|
|
11
|
+
const roundVec = (vector) => vector.toArray().map((value) => Number(value.toFixed(3)));
|
|
12
|
+
|
|
13
|
+
export class SpatialSystem {
|
|
14
|
+
constructor({ store, entities=null, physics=null }) {
|
|
15
|
+
this.store = store;
|
|
16
|
+
this.entities=entities;this.physics=physics;
|
|
17
|
+
this.raycaster = new THREE.Raycaster();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
snapshotObject(id) {
|
|
21
|
+
return spatialSnapshotEntry(id, this.store.get(id).object);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
snapshot() {
|
|
25
|
+
const snapshot = new Map();
|
|
26
|
+
for (const [id, record] of this.store.entries()) if (record.active !== false) snapshot.set(id, spatialSnapshotEntry(id, record.object));
|
|
27
|
+
return snapshot;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
nativeRecord(id){return nativeCarryRecord(this.entities,this.physics,id);}
|
|
31
|
+
interactionRecord(id){return this.store.has(id)?this.store.get(id):this.nativeRecord(id);}
|
|
32
|
+
interactionBounds(id){
|
|
33
|
+
if(this.store.has(id))return this.getBounds(id);
|
|
34
|
+
const bounds=this.nativeRecord(id)?this.physics.manipulationBounds(id):null;
|
|
35
|
+
if(!bounds)throw Object.assign(new Error('TARGET_PHYSICS_UNAVAILABLE'),{code:'TARGET_PHYSICS_UNAVAILABLE'});
|
|
36
|
+
return bounds;
|
|
37
|
+
}
|
|
38
|
+
interactionPosition(id){
|
|
39
|
+
return this.nativeRecord(id)?new THREE.Vector3(...this.physics.getPosition(id)):objectWorldPosition(this.store.get(id).object);
|
|
40
|
+
}
|
|
41
|
+
placementSnapshot(subjectId,targetId){
|
|
42
|
+
const snapshot=this.snapshot();
|
|
43
|
+
if(!this.nativeRecord(subjectId)&&!this.nativeRecord(targetId))return snapshot;
|
|
44
|
+
for(const entity of this.entities?.list({source:'native',capability:'physics'})||[]){
|
|
45
|
+
const bounds=this.nativeRecord(entity.id)?this.physics.manipulationBounds(entity.id):null;
|
|
46
|
+
if(!bounds)continue;
|
|
47
|
+
const box=new THREE.Box3(new THREE.Vector3(...bounds.min),new THREE.Vector3(...bounds.max));
|
|
48
|
+
snapshot.set(entity.id,{id:entity.id,bounds,box,center:box.getCenter(new THREE.Vector3()),size:box.getSize(new THREE.Vector3())});
|
|
49
|
+
}
|
|
50
|
+
return snapshot;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getBounds(id, snapshot = null) {
|
|
54
|
+
return snapshot?.get(id)?.bounds || spatialSnapshotEntry(id, this.store.get(id).object).bounds;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
debugSnapshot({ snapshot = this.snapshot(), overlapMargin = 0.01 } = {}) {
|
|
58
|
+
const bounds = [...snapshot.values()].map((entry) => structuredClone(entry.bounds));
|
|
59
|
+
const overlapPairs = this.overlapPairs({ margin: overlapMargin, snapshot });
|
|
60
|
+
return {
|
|
61
|
+
schemaVersion: 2,
|
|
62
|
+
source: 'spatial',
|
|
63
|
+
bounds,
|
|
64
|
+
overlapPairs,
|
|
65
|
+
metrics: {
|
|
66
|
+
objectCount: bounds.length,
|
|
67
|
+
overlapPairCount: overlapPairs.length,
|
|
68
|
+
overlapMargin
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
findNearby(id, radius = 2, snapshot = null) {
|
|
74
|
+
const localSnapshot = snapshot || this.snapshot();
|
|
75
|
+
const source = localSnapshot.get(id);
|
|
76
|
+
if (!source) return [];
|
|
77
|
+
const results = [];
|
|
78
|
+
for (const [otherId, record] of this.store.entries()) {
|
|
79
|
+
if (otherId === id) continue;
|
|
80
|
+
const other = localSnapshot.get(otherId);
|
|
81
|
+
if (!other) continue;
|
|
82
|
+
const distance = source.center.distanceTo(other.center);
|
|
83
|
+
if (distance <= radius) results.push({ id: otherId, asset: record.assetId, distance: Number(distance.toFixed(3)) });
|
|
84
|
+
}
|
|
85
|
+
return results.sort((left, right) => left.distance - right.distance);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
raycast(origin, direction, maxDistance = 100) {
|
|
89
|
+
const rayOrigin = new THREE.Vector3(...origin);
|
|
90
|
+
const rayDirection = new THREE.Vector3(...direction).normalize();
|
|
91
|
+
this.raycaster.set(rayOrigin, rayDirection);
|
|
92
|
+
this.raycaster.far = maxDistance;
|
|
93
|
+
const roots = this.store.list().map(([, record]) => record.object);
|
|
94
|
+
const hits = this.raycaster.intersectObjects(roots, true);
|
|
95
|
+
const results = [];
|
|
96
|
+
const seen = new Set();
|
|
97
|
+
for (const hit of hits) {
|
|
98
|
+
let current = hit.object;
|
|
99
|
+
while (current && !current.userData.instanceId) current = current.parent;
|
|
100
|
+
const id = current?.userData.instanceId ?? null;
|
|
101
|
+
if (!id || seen.has(id)) continue;
|
|
102
|
+
seen.add(id);
|
|
103
|
+
results.push({ id, distance: Number(hit.distance.toFixed(3)), point: roundVec(hit.point) });
|
|
104
|
+
}
|
|
105
|
+
return results;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
overlappingIds(id, { ignore = [], margin = 0.01, snapshot = null } = {}) {
|
|
109
|
+
const localSnapshot = snapshot || this.snapshot();
|
|
110
|
+
const source = localSnapshot.get(id);
|
|
111
|
+
if (!source) return [];
|
|
112
|
+
const ignored = new Set([id, ...ignore]);
|
|
113
|
+
const overlaps = [];
|
|
114
|
+
for (const [otherId] of this.store.entries()) {
|
|
115
|
+
if (ignored.has(otherId)) continue;
|
|
116
|
+
const other = localSnapshot.get(otherId);
|
|
117
|
+
if (other && boxesOverlap(source.box, other.box, margin)) overlaps.push(otherId);
|
|
118
|
+
}
|
|
119
|
+
return overlaps;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
overlapPairs({ margin = 0.01, snapshot = this.snapshot() } = {}) {
|
|
123
|
+
const entries = [...snapshot].map(([id, { box }], index) => ({ id, box, index }));
|
|
124
|
+
const pairs = [];
|
|
125
|
+
const bruteForce = () => {
|
|
126
|
+
for (let left = 0; left < entries.length; left++) {
|
|
127
|
+
for (let right = left + 1; right < entries.length; right++) {
|
|
128
|
+
if (boxesOverlap(entries[left].box, entries[right].box, margin)) pairs.push([entries[left].id, entries[right].id]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return pairs;
|
|
132
|
+
};
|
|
133
|
+
// Small scenes do not benefit from sorting. Keep the original predicate for
|
|
134
|
+
// all candidates, including touching/degenerate bounds and nonfinite input.
|
|
135
|
+
if (entries.length < 64) return bruteForce();
|
|
136
|
+
const axes = ['x', 'y', 'z'];
|
|
137
|
+
const ranges = axes.map(axis => {
|
|
138
|
+
let min = Infinity, max = -Infinity;
|
|
139
|
+
for (const { box } of entries) {
|
|
140
|
+
if (!Number.isFinite(box.min[axis]) || !Number.isFinite(box.max[axis])) return NaN;
|
|
141
|
+
min = Math.min(min, box.min[axis]);
|
|
142
|
+
max = Math.max(max, box.min[axis]);
|
|
143
|
+
}
|
|
144
|
+
return max - min;
|
|
145
|
+
});
|
|
146
|
+
if (ranges.some(range => !Number.isFinite(range))) return bruteForce();
|
|
147
|
+
const axis = axes[ranges.indexOf(Math.max(...ranges))];
|
|
148
|
+
// A densely overlapping axis cannot prune enough candidates to offset
|
|
149
|
+
// pair ordering and bucket allocation; use the cheap original path.
|
|
150
|
+
const averageExtent = entries.reduce((sum,{box}) => sum + Math.max(0,box.max[axis]-box.min[axis]),0)/entries.length;
|
|
151
|
+
if (averageExtent >= Math.max(...ranges)/2) return bruteForce();
|
|
152
|
+
const ordered = [...entries].sort((a,b) => a.box.min[axis] - b.box.min[axis] || a.index - b.index);
|
|
153
|
+
const buckets = Array.from({length:entries.length}, () => []);
|
|
154
|
+
for (let left = 0; left < ordered.length; left++) {
|
|
155
|
+
const a = ordered[left];
|
|
156
|
+
for (let right = left + 1; right < ordered.length; right++) {
|
|
157
|
+
const b = ordered[right];
|
|
158
|
+
// The un-inset interval is conservative for the exact overlap test.
|
|
159
|
+
if (b.box.min[axis] > a.box.max[axis]) break;
|
|
160
|
+
if (boxesOverlap(a.box,b.box,margin)) buckets[Math.min(a.index,b.index)].push(Math.max(a.index,b.index));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Preserve the snapshot's original pair ordering for deterministic findings.
|
|
164
|
+
for (let left = 0; left < buckets.length; left++) {
|
|
165
|
+
for (const right of buckets[left].sort((a,b) => a-b)) pairs.push([entries[left].id,entries[right].id]);
|
|
166
|
+
}
|
|
167
|
+
return pairs;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// A root AABB is only a broad-phase candidate. For visual-only groups, disjoint
|
|
171
|
+
// conservative mesh AABBs can disprove it; unsupported geometry stays unknown.
|
|
172
|
+
// Do not use this as proof of contact or to bypass physical-body validation.
|
|
173
|
+
visualOverlapDisproved(id, otherId, cache = new Map()) {
|
|
174
|
+
const meshBounds = key => {
|
|
175
|
+
if (cache.has(key)) return cache.get(key);
|
|
176
|
+
const record = this.store.has(key) ? this.store.get(key) : null;
|
|
177
|
+
const boxes = [];
|
|
178
|
+
let vertexBudget=100000,indexBudget=300000;
|
|
179
|
+
let complete = record?.manifest?.capabilityLevel === 'visual';
|
|
180
|
+
if (complete) {
|
|
181
|
+
record.object.updateWorldMatrix(true, true);
|
|
182
|
+
record.object.traverse(node => {
|
|
183
|
+
if (!complete) return;
|
|
184
|
+
if (node.isLine || node.isPoints || node.isSprite) { complete = false; return; }
|
|
185
|
+
if (!node.isMesh) return;
|
|
186
|
+
if (boxes.length >= 256 || node.isInstancedMesh || node.isSkinnedMesh || node.isBatchedMesh || node.geometry?.morphAttributes?.position?.length || !node.geometry?.getAttribute('position')) {
|
|
187
|
+
complete = false; return;
|
|
188
|
+
}
|
|
189
|
+
if (!node.geometry.boundingBox) node.geometry.computeBoundingBox();
|
|
190
|
+
const box = node.geometry.boundingBox?.clone().applyMatrix4(node.matrixWorld);
|
|
191
|
+
if (!box || box.isEmpty() || ![...box.min.toArray(), ...box.max.toArray()].every(Number.isFinite)) { complete = false; return; }
|
|
192
|
+
const vertices=node.geometry.getAttribute('position').count,indices=node.geometry.getIndex()?.count;
|
|
193
|
+
let components=null;
|
|
194
|
+
if(indices!==undefined&&vertices<=vertexBudget&&indices<=indexBudget){
|
|
195
|
+
vertexBudget-=vertices;indexBudget-=indices;
|
|
196
|
+
components=visualComponentBounds(node.geometry,node.matrixWorld,256-boxes.length);
|
|
197
|
+
}
|
|
198
|
+
if(components)boxes.push(...components);
|
|
199
|
+
else boxes.push(box);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
const result = complete && boxes.length ? boxes : null;
|
|
203
|
+
cache.set(key, result);
|
|
204
|
+
return result;
|
|
205
|
+
};
|
|
206
|
+
const left = meshBounds(id), right = meshBounds(otherId);
|
|
207
|
+
if (!left || !right || left.length * right.length > 16384) return false;
|
|
208
|
+
return !left.some(a => right.some(b => boxesOverlap(a,b)));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
getSupportSurface(targetId, surfaceId, snapshot = null) {
|
|
212
|
+
const native=this.nativeRecord(targetId);
|
|
213
|
+
if(native){
|
|
214
|
+
if(this.physics.manipulationBody(targetId).body!=='fixed')return null;
|
|
215
|
+
const rotation=this.physics.getRotation(targetId),position=this.physics.getPosition(targetId);
|
|
216
|
+
if(!rotation||!position||1-Math.abs(rotation[3])>1e-6)return null;
|
|
217
|
+
const surface=surfaceId?native.manifest.surfaces.find(item=>item.id===surfaceId):native.manifest.surfaces[0];
|
|
218
|
+
return surface?{targetId,id:surface.id,center:new THREE.Vector3(...position).add(new THREE.Vector3(...surface.localPosition)),size:[...surface.size]}:null;
|
|
219
|
+
}
|
|
220
|
+
const record = this.store.get(targetId);
|
|
221
|
+
if (!snapshot?.has(targetId)) record.object.updateWorldMatrix(true, true);
|
|
222
|
+
const surface = surfaceId
|
|
223
|
+
? record.manifest.surfaces?.find((item) => item.id === surfaceId)
|
|
224
|
+
: record.manifest.surfaces?.[0];
|
|
225
|
+
if (!surface) return null;
|
|
226
|
+
|
|
227
|
+
const local = new THREE.Vector3(...surface.localPosition);
|
|
228
|
+
const center = local.clone().applyMatrix4(record.object.matrixWorld);
|
|
229
|
+
const size = surface.size || [1, 1];
|
|
230
|
+
const scaleX = Math.abs(record.object.scale.x || 1);
|
|
231
|
+
const scaleZ = Math.abs(record.object.scale.z || 1);
|
|
232
|
+
return { targetId, id: surface.id, center, size: [size[0] * scaleX, size[1] * scaleZ] };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
getReceptacle(targetId, receptacleId = null, snapshot = null) {
|
|
236
|
+
const record = this.store.get(targetId);
|
|
237
|
+
if (!snapshot?.has(targetId)) record.object.updateWorldMatrix(true, true);
|
|
238
|
+
const definition = receptacleId
|
|
239
|
+
? record.manifest.receptacles?.find((item) => item.id === receptacleId)
|
|
240
|
+
: record.manifest.receptacles?.[0];
|
|
241
|
+
if (!definition) return null;
|
|
242
|
+
const half = new THREE.Vector3(...definition.size).multiplyScalar(0.5);
|
|
243
|
+
const center = new THREE.Vector3(...definition.localPosition);
|
|
244
|
+
const box = new THREE.Box3(center.clone().sub(half), center.clone().add(half)).applyMatrix4(record.object.matrixWorld);
|
|
245
|
+
return {
|
|
246
|
+
targetId,
|
|
247
|
+
id: definition.id,
|
|
248
|
+
box,
|
|
249
|
+
center: box.getCenter(new THREE.Vector3()),
|
|
250
|
+
size: box.getSize(new THREE.Vector3())
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
containmentGeometry(subjectId, targetId, { receptacleId = null, tolerance = 0.02, snapshot = null } = {}) {
|
|
255
|
+
const localSnapshot = snapshot || this.snapshot();
|
|
256
|
+
const subject = localSnapshot.get(subjectId);
|
|
257
|
+
const target = localSnapshot.get(targetId);
|
|
258
|
+
if (!subject) return { inside: false, reason: 'SUBJECT_MISSING', evidence: 'spatial-geometry' };
|
|
259
|
+
if (!target) return { inside: false, reason: 'TARGET_MISSING', evidence: 'spatial-geometry' };
|
|
260
|
+
const record = this.store.get(targetId);
|
|
261
|
+
const receptacles = record.manifest.receptacles || [];
|
|
262
|
+
if (receptacles.length) {
|
|
263
|
+
const candidates = receptacleId ? receptacles.filter((item) => item.id === receptacleId) : receptacles;
|
|
264
|
+
if (!candidates.length) return { inside: false, reason: 'RECEPTACLE_MISSING', receptacleId, evidence: 'spatial-geometry' };
|
|
265
|
+
for (const definition of candidates) {
|
|
266
|
+
const receptacle = this.getReceptacle(targetId, definition.id, localSnapshot);
|
|
267
|
+
const box = receptacle.box.clone().expandByScalar(tolerance);
|
|
268
|
+
if (box.containsBox(subject.box)) return {
|
|
269
|
+
inside: true,
|
|
270
|
+
subjectId,
|
|
271
|
+
targetId,
|
|
272
|
+
receptacleId: definition.id,
|
|
273
|
+
mode: 'receptacle',
|
|
274
|
+
tolerance,
|
|
275
|
+
evidence: 'spatial-geometry'
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
return { inside: false, reason: 'OUTSIDE_RECEPTACLE', subjectId, targetId, receptacleId, tolerance, evidence: 'spatial-geometry' };
|
|
279
|
+
}
|
|
280
|
+
const box = target.box.clone().expandByScalar(tolerance);
|
|
281
|
+
const inside = box.containsBox(subject.box);
|
|
282
|
+
return {
|
|
283
|
+
inside,
|
|
284
|
+
subjectId,
|
|
285
|
+
targetId,
|
|
286
|
+
receptacleId: null,
|
|
287
|
+
mode: 'bounds',
|
|
288
|
+
tolerance,
|
|
289
|
+
evidence: 'spatial-geometry',
|
|
290
|
+
...(inside ? {} : { reason: 'OUTSIDE_TARGET_BOUNDS' })
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
findFreeSpaceInside(objectId, targetId, { receptacleId = null, clearance = 0.03, grid = 3, ignore = [], poseClear = null } = {}) {
|
|
295
|
+
const objectRecord = this.store.get(objectId);
|
|
296
|
+
const snapshot = this.snapshot();
|
|
297
|
+
const receptacle = this.getReceptacle(targetId, receptacleId, snapshot);
|
|
298
|
+
if (!receptacle) return null;
|
|
299
|
+
const entry = snapshot.get(objectId);
|
|
300
|
+
const currentRoot = objectWorldPosition(objectRecord.object);
|
|
301
|
+
const { box: bounds, size } = entry;
|
|
302
|
+
if (size.x + clearance * 2 > receptacle.size.x || size.y + clearance * 2 > receptacle.size.y || size.z + clearance * 2 > receptacle.size.z) return null;
|
|
303
|
+
const rootToCenterX = currentRoot.x - entry.center.x;
|
|
304
|
+
const rootToCenterZ = currentRoot.z - entry.center.z;
|
|
305
|
+
const rootToBottomY = currentRoot.y - bounds.min.y;
|
|
306
|
+
const halfX = size.x / 2 + clearance;
|
|
307
|
+
const halfZ = size.z / 2 + clearance;
|
|
308
|
+
const usableX = Math.max(0, receptacle.size.x / 2 - halfX);
|
|
309
|
+
const usableZ = Math.max(0, receptacle.size.z / 2 - halfZ);
|
|
310
|
+
const candidates = [];
|
|
311
|
+
for (let x = 0; x < grid; x++) {
|
|
312
|
+
for (let z = 0; z < grid; z++) {
|
|
313
|
+
const nx = grid === 1 ? 0 : (x / (grid - 1)) * 2 - 1;
|
|
314
|
+
const nz = grid === 1 ? 0 : (z / (grid - 1)) * 2 - 1;
|
|
315
|
+
candidates.push(new THREE.Vector3(
|
|
316
|
+
receptacle.center.x + nx * usableX + rootToCenterX,
|
|
317
|
+
receptacle.box.min.y + clearance + rootToBottomY,
|
|
318
|
+
receptacle.center.z + nz * usableZ + rootToCenterZ
|
|
319
|
+
));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
candidates.sort((left, right) => left.distanceToSquared(receptacle.center) - right.distanceToSquared(receptacle.center));
|
|
323
|
+
for (const candidate of candidates) {
|
|
324
|
+
const candidateSnapshot = new Map(snapshot);
|
|
325
|
+
candidateSnapshot.set(objectId, spatialEntryAtRootPosition(entry, currentRoot, candidate));
|
|
326
|
+
const containment = this.containmentGeometry(objectId, targetId, { receptacleId: receptacle.id, tolerance: 0, snapshot: candidateSnapshot });
|
|
327
|
+
const overlaps = this.overlappingIds(objectId, { ignore: [targetId, ...ignore], margin: clearance / 2, snapshot: candidateSnapshot });
|
|
328
|
+
const physics = poseClear ? poseClear(candidate.toArray()) : { checked: true, clear: true };
|
|
329
|
+
if (containment.inside && !overlaps.length && physics?.checked && physics.clear) return candidate;
|
|
330
|
+
}
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
supportGeometry(subjectId, targetId, { surfaceId = null, tolerance = 0.12, snapshot = null } = {}) {
|
|
335
|
+
const localSnapshot = snapshot || this.placementSnapshot(subjectId,targetId);
|
|
336
|
+
const subject = localSnapshot.get(subjectId);
|
|
337
|
+
if (!subject) return { supported: false, reason: 'SUBJECT_MISSING', evidence: 'spatial-geometry' };
|
|
338
|
+
const surface = this.getSupportSurface(targetId, surfaceId, localSnapshot);
|
|
339
|
+
if (!surface) return { supported: false, reason: 'SURFACE_MISSING', evidence: 'spatial-geometry' };
|
|
340
|
+
const withinX = subject.box.min.x >= surface.center.x - surface.size[0] / 2 - 0.05 && subject.box.max.x <= surface.center.x + surface.size[0] / 2 + 0.05;
|
|
341
|
+
const withinZ = subject.box.min.z >= surface.center.z - surface.size[1] / 2 - 0.05 && subject.box.max.z <= surface.center.z + surface.size[1] / 2 + 0.05;
|
|
342
|
+
const verticalGap = subject.box.min.y - surface.center.y;
|
|
343
|
+
const gap = Math.abs(verticalGap);
|
|
344
|
+
const aboveSurface = verticalGap >= -0.03;
|
|
345
|
+
return {
|
|
346
|
+
supported: withinX && withinZ && aboveSurface && gap <= tolerance,
|
|
347
|
+
subjectId,
|
|
348
|
+
targetId,
|
|
349
|
+
surfaceId: surface.id,
|
|
350
|
+
withinX,
|
|
351
|
+
withinZ,
|
|
352
|
+
aboveSurface,
|
|
353
|
+
verticalGap: Number(verticalGap.toFixed(4)),
|
|
354
|
+
gap: Number(gap.toFixed(4)),
|
|
355
|
+
tolerance,
|
|
356
|
+
evidence: 'spatial-geometry'
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
findFreeSpace(objectId, targetId, { surfaceId, clearance = 0.03, grid = 5, ignore = [] } = {}) {
|
|
361
|
+
const native=Boolean(this.nativeRecord(objectId)||this.nativeRecord(targetId));
|
|
362
|
+
const snapshot = this.placementSnapshot(objectId,targetId);
|
|
363
|
+
const surface = this.getSupportSurface(targetId, surfaceId, snapshot);
|
|
364
|
+
if (!surface) return null;
|
|
365
|
+
|
|
366
|
+
const entry = snapshot.get(objectId);
|
|
367
|
+
if(!entry)return null;
|
|
368
|
+
const currentRoot = this.interactionPosition(objectId);
|
|
369
|
+
const { box: bounds, size } = entry;
|
|
370
|
+
const halfX = size.x / 2 + clearance;
|
|
371
|
+
const halfZ = size.z / 2 + clearance;
|
|
372
|
+
if (surface.size[0] < halfX * 2 || surface.size[1] < halfZ * 2) return null;
|
|
373
|
+
const usableX = Math.max(0, surface.size[0] / 2 - halfX);
|
|
374
|
+
const usableZ = Math.max(0, surface.size[1] / 2 - halfZ);
|
|
375
|
+
const rootToCenterX = currentRoot.x - entry.center.x;
|
|
376
|
+
const rootToCenterZ = currentRoot.z - entry.center.z;
|
|
377
|
+
const rootToBottomY = currentRoot.y - bounds.min.y;
|
|
378
|
+
const candidates = [];
|
|
379
|
+
|
|
380
|
+
for (let x = 0; x < grid; x++) {
|
|
381
|
+
for (let z = 0; z < grid; z++) {
|
|
382
|
+
const nx = grid === 1 ? 0 : (x / (grid - 1)) * 2 - 1;
|
|
383
|
+
const nz = grid === 1 ? 0 : (z / (grid - 1)) * 2 - 1;
|
|
384
|
+
candidates.push(new THREE.Vector3(
|
|
385
|
+
surface.center.x + nx * usableX + rootToCenterX,
|
|
386
|
+
surface.center.y + clearance + rootToBottomY,
|
|
387
|
+
surface.center.z + nz * usableZ + rootToCenterZ
|
|
388
|
+
));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
candidates.sort((left, right) => left.distanceToSquared(surface.center) - right.distanceToSquared(surface.center));
|
|
393
|
+
for (const candidate of candidates) {
|
|
394
|
+
const candidateSnapshot = new Map(snapshot);
|
|
395
|
+
candidateSnapshot.set(objectId, spatialEntryAtRootPosition(entry, currentRoot, candidate));
|
|
396
|
+
const overlaps = this.overlappingIds(objectId, { ignore: [targetId, ...ignore], margin: clearance / 2, snapshot: candidateSnapshot });
|
|
397
|
+
if (native&&!this.physics.checkBodyPose(objectId,candidate.toArray(),this.physics.getRotation(objectId),{excludeIds:ignore}).clear)continue;
|
|
398
|
+
if (!overlaps.length) return candidate;
|
|
399
|
+
}
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { normalizeWorldSpec } from './WorldSpec.js';
|
|
2
|
+
|
|
3
|
+
export const WORLD_IR_SCHEMA = 'agentscape.world-ir';
|
|
4
|
+
export const WORLD_IR_VERSION = 1;
|
|
5
|
+
|
|
6
|
+
const TOP_LEVEL_KEYS=new Set(['schema','schemaVersion','revision','provenance','intent','policy','entities','spatial','interactions','rules','acceptance']);
|
|
7
|
+
const REVISION_KEYS=new Set(['id','parentId','reason']);
|
|
8
|
+
const PROVENANCE_KEYS=new Set(['source','sourceId','createdBy','evidenceRefs']);
|
|
9
|
+
const INTENT_KEYS=new Set(['name','description','task']);
|
|
10
|
+
const POLICY_KEYS=new Set(['generation','physics']);
|
|
11
|
+
const GENERATION_KEYS=new Set(['provider','generate']);
|
|
12
|
+
const PHYSICS_POLICY_KEYS=new Set(['fallbackPolicy']);
|
|
13
|
+
const ENTITY_KEYS=new Set(['id','asset','transform','physicsRequirement','capabilityIntent','initialState']);
|
|
14
|
+
const ASSET_KEYS=new Set(['assetId','query','prompt','type','generate','provider']);
|
|
15
|
+
const TRANSFORM_KEYS=new Set(['position']);
|
|
16
|
+
const PHYSICS_REQUIREMENT_KEYS=new Set(['bodyClass','requiredCapabilities','executionMode','qualityPolicy']);
|
|
17
|
+
const PHYSICS_QUALITY_KEYS=new Set(['deterministicRequired','realtimeRequired','fallbackPolicy']);
|
|
18
|
+
const SPATIAL_KEYS=new Set(['relations','constraints']);
|
|
19
|
+
const RELATION_KEYS=new Set(['subject','predicate','object','anchor','surfaceId','receptacleId','distance']);
|
|
20
|
+
const RELATION_ANCHOR_KEYS=new Set(['kind','id','label']);
|
|
21
|
+
const CONSTRAINT_KEYS=new Set(['id','kind','subject','object','description']);
|
|
22
|
+
const INTERACTION_KEYS=new Set(['id','actorId','targetId','supportId','capability','stateKey','value','description']);
|
|
23
|
+
const RULE_KEYS=new Set(['id','event','condition','effect','description']);
|
|
24
|
+
const ACCEPTANCE_KEYS=new Set(['id','kind','targetId','capability','stateKey','value','subject','predicate','object','surfaceId','description','source','partName']);
|
|
25
|
+
|
|
26
|
+
const clean=(value)=>typeof value==='string'?value.trim():'';
|
|
27
|
+
const STATE_SCALAR=(value)=>value===null||['string','number','boolean'].includes(typeof value);
|
|
28
|
+
const RESERVED_INITIAL_STATE_KEYS=new Set(['heldBy','navigation','parts','partTargets','lastVerifiedAction','door']);
|
|
29
|
+
const plainObject=(value)=>Boolean(value&&typeof value==='object'&&!Array.isArray(value)&&Object.getPrototypeOf(value)===Object.prototype);
|
|
30
|
+
const assertObject=(value,label)=>{if(!plainObject(value)) throw new TypeError(`${label} must be an object`); return value;};
|
|
31
|
+
const assertKnownKeys=(value,allowed,label)=>{for(const key of Object.keys(value||{})) if(!allowed.has(key)) throw new TypeError(`${label} unknown field: ${key}`);};
|
|
32
|
+
const finiteVec3=(value)=>Array.isArray(value)&&value.length===3&&value.every(Number.isFinite)?value.map(Number):null;
|
|
33
|
+
const uniqueStrings=(value,label,{upper=false}={})=>{if(value==null) return []; if(!Array.isArray(value)) throw new TypeError(`${label} must be an array`); const result=[]; for(const item of value){const text=clean(item); if(!text) throw new TypeError(`${label} requires non-empty strings`); const normalized=upper?text.toUpperCase():text; if(!result.includes(normalized)) result.push(normalized);} return result;};
|
|
34
|
+
const assertJsonValue=(value,label)=>{if(value===null||typeof value==='string'||typeof value==='boolean') return; if(typeof value==='number'){if(!Number.isFinite(value)) throw new TypeError(`${label} numbers must be finite`); return;} if(Array.isArray(value)){value.forEach((item,index)=>assertJsonValue(item,`${label}[${index}]`)); return;} if(plainObject(value)){for(const [key,item] of Object.entries(value)) assertJsonValue(item,`${label}.${key}`); return;} throw new TypeError(`${label} must be JSON-serializable`);};
|
|
35
|
+
const normalizeInitialState=(value,label)=>{
|
|
36
|
+
if(value==null) return {};
|
|
37
|
+
assertObject(value,label);
|
|
38
|
+
const result={};
|
|
39
|
+
for(const [rawKey,item] of Object.entries(value)){
|
|
40
|
+
const key=clean(rawKey);
|
|
41
|
+
if(!key||key!==rawKey||key.includes('.')||key.startsWith('__')){const error=new TypeError(`${label} invalid state key: ${rawKey}`);error.code='WORLD_IR_INITIAL_STATE_KEY_INVALID';throw error;}
|
|
42
|
+
if(RESERVED_INITIAL_STATE_KEYS.has(key)){const error=new TypeError(`${label} reserved runtime state key: ${key}`);error.code='WORLD_IR_INITIAL_STATE_RESERVED';error.stateKey=key;throw error;}
|
|
43
|
+
if(!STATE_SCALAR(item)){const error=new TypeError(`${label}.${key} must be a JSON scalar`);error.code='WORLD_IR_INITIAL_STATE_VALUE_INVALID';error.stateKey=key;throw error;}
|
|
44
|
+
result[key]=item;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
const uniqueId=(set,id,label)=>{if(!id) throw new TypeError(`${label} requires id`); if(set.has(id)) throw new TypeError(`${label} duplicate id: ${id}`); set.add(id); return id;};
|
|
49
|
+
|
|
50
|
+
const normalizePhysicsRequirement=(value,label)=>{
|
|
51
|
+
if(value==null) return null;
|
|
52
|
+
assertObject(value,label); assertKnownKeys(value,PHYSICS_REQUIREMENT_KEYS,label);
|
|
53
|
+
const bodyClass=clean(value.bodyClass).toLowerCase();
|
|
54
|
+
if(bodyClass&&!['transform','rigid','articulated','character','soft','cloth'].includes(bodyClass)) throw new TypeError(`${label} unsupported bodyClass: ${bodyClass}`);
|
|
55
|
+
const executionMode=clean(value.executionMode).toLowerCase();
|
|
56
|
+
if(executionMode&&!['render-only','realtime','validation-only'].includes(executionMode)) throw new TypeError(`${label} unsupported executionMode: ${executionMode}`);
|
|
57
|
+
const requiredCapabilities=uniqueStrings(value.requiredCapabilities,`${label} requiredCapabilities`);
|
|
58
|
+
let qualityPolicy={};
|
|
59
|
+
if(value.qualityPolicy!=null){
|
|
60
|
+
assertObject(value.qualityPolicy,`${label} qualityPolicy`); assertKnownKeys(value.qualityPolicy,PHYSICS_QUALITY_KEYS,`${label} qualityPolicy`);
|
|
61
|
+
qualityPolicy={
|
|
62
|
+
...(value.qualityPolicy.deterministicRequired===true?{deterministicRequired:true}:{}),
|
|
63
|
+
...(value.qualityPolicy.realtimeRequired===true?{realtimeRequired:true}:{}),
|
|
64
|
+
...(clean(value.qualityPolicy.fallbackPolicy)?{fallbackPolicy:clean(value.qualityPolicy.fallbackPolicy)}:{})
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {...(bodyClass?{bodyClass}:{}),...(requiredCapabilities.length?{requiredCapabilities}:{}),...(executionMode?{executionMode}:{}),...(Object.keys(qualityPolicy).length?{qualityPolicy}:{})};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const normalizeRelationAnchor=(value,label)=>{
|
|
71
|
+
if(value==null) return null;
|
|
72
|
+
assertObject(value,label); assertKnownKeys(value,RELATION_ANCHOR_KEYS,label);
|
|
73
|
+
const kind=clean(value.kind).toLowerCase(),id=clean(value.id),anchorLabel=clean(value.label);
|
|
74
|
+
if(kind!=='observation') throw new TypeError(`${label} unsupported kind: ${kind || '$empty'}`);
|
|
75
|
+
if(!id&&!anchorLabel) throw new TypeError(`${label} requires id or label`);
|
|
76
|
+
return {kind:'observation',...(id?{id}:{}),...(anchorLabel?{label:anchorLabel}:{})};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const normalizeRelation=(relation,index)=>{
|
|
80
|
+
const label=`WorldIR spatial relation[${index}]`;
|
|
81
|
+
assertObject(relation,label); assertKnownKeys(relation,RELATION_KEYS,label);
|
|
82
|
+
const subject=clean(relation.subject),predicate=clean(relation.predicate).toUpperCase(),object=clean(relation.object);
|
|
83
|
+
const anchor=normalizeRelationAnchor(relation.anchor,`${label} anchor`);
|
|
84
|
+
if(!subject||!predicate) throw new TypeError(`${label} requires subject and predicate`);
|
|
85
|
+
if(!['ON','NEAR','INSIDE'].includes(predicate)) throw new TypeError(`${label} unsupported predicate: ${predicate}`);
|
|
86
|
+
if(Boolean(object)===Boolean(anchor)) throw new TypeError(`${label} requires exactly one of object or anchor`);
|
|
87
|
+
if(anchor&&predicate!=='NEAR') throw new TypeError(`${label} observation anchor is only supported for NEAR`);
|
|
88
|
+
const distance=relation.distance==null?null:Number(relation.distance);
|
|
89
|
+
if(distance!=null&&(!Number.isFinite(distance)||distance<=0)) throw new TypeError(`${label} distance must be positive finite`);
|
|
90
|
+
return {subject,predicate,...(object?{object}:{}),...(anchor?{anchor}:{}),...(clean(relation.surfaceId)?{surfaceId:clean(relation.surfaceId)}:{}),...(clean(relation.receptacleId)?{receptacleId:clean(relation.receptacleId)}:{}),...(distance!=null?{distance}:{})};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const fromWorldSpec=(input)=>{
|
|
94
|
+
const spec=normalizeWorldSpec(input);
|
|
95
|
+
return {
|
|
96
|
+
schema:WORLD_IR_SCHEMA,schemaVersion:WORLD_IR_VERSION,
|
|
97
|
+
revision:{id:'legacy-root'},provenance:{source:'legacy-world-spec',evidenceRefs:[]},
|
|
98
|
+
intent:{name:spec.name,description:spec.description},policy:{generation:structuredClone(spec.generation),physics:{}},
|
|
99
|
+
entities:spec.assets.map((request)=>({
|
|
100
|
+
...(request.id?{id:request.id}:{}),asset:{...(request.assetId?{assetId:request.assetId}:{}),query:request.query,...(request.type?{type:request.type}:{}),...(request.prompt?{prompt:request.prompt}:{}),generate:request.generate===true,...(request.provider?{provider:request.provider}:{})},
|
|
101
|
+
transform:{...(request.position?{position:[...request.position]}:{})},capabilityIntent:[],initialState:{}
|
|
102
|
+
})),
|
|
103
|
+
spatial:{relations:spec.relations.map((item)=>structuredClone(item)),constraints:[]},interactions:[],rules:[],acceptance:[]
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export function upgradeLegacyWorldSpec(input={}){
|
|
108
|
+
if(!input||typeof input!=='object'||Array.isArray(input)) throw new TypeError('Legacy WorldSpec must be an object');
|
|
109
|
+
const legacy=input.schema===1?{...input}:input;
|
|
110
|
+
if(legacy!==input) delete legacy.schema;
|
|
111
|
+
return fromWorldSpec(legacy);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function normalizeWorldIR(input={}){
|
|
115
|
+
if(!input||typeof input!=='object'||Array.isArray(input)) throw new TypeError('WorldIR must be an object');
|
|
116
|
+
if(input.schema!==WORLD_IR_SCHEMA){
|
|
117
|
+
const error=new TypeError(`WorldIR schema must be ${WORLD_IR_SCHEMA}`);
|
|
118
|
+
error.code='WORLD_IR_SCHEMA_REQUIRED';
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
assertKnownKeys(input,TOP_LEVEL_KEYS,'WorldIR');
|
|
122
|
+
if(input.schemaVersion!==WORLD_IR_VERSION) throw new TypeError(`Unsupported WorldIR version: ${input.schemaVersion}`);
|
|
123
|
+
const revision=assertObject(input.revision||{},'WorldIR revision'); assertKnownKeys(revision,REVISION_KEYS,'WorldIR revision');
|
|
124
|
+
const revisionId=clean(revision.id); if(!revisionId) throw new TypeError('WorldIR revision requires id');
|
|
125
|
+
const parentId=clean(revision.parentId)||null; if(parentId===revisionId) throw new TypeError('WorldIR revision parentId must differ from id');
|
|
126
|
+
const provenance=assertObject(input.provenance||{},'WorldIR provenance'); assertKnownKeys(provenance,PROVENANCE_KEYS,'WorldIR provenance');
|
|
127
|
+
const source=clean(provenance.source); if(!source) throw new TypeError('WorldIR provenance requires source');
|
|
128
|
+
const evidenceRefs=uniqueStrings(provenance.evidenceRefs,'WorldIR provenance evidenceRefs');
|
|
129
|
+
const intent=assertObject(input.intent||{},'WorldIR intent'); assertKnownKeys(intent,INTENT_KEYS,'WorldIR intent');
|
|
130
|
+
const name=clean(intent.name)||'Generated World',description=clean(intent.description),task=clean(intent.task)||null;
|
|
131
|
+
const policy=assertObject(input.policy||{},'WorldIR policy'); assertKnownKeys(policy,POLICY_KEYS,'WorldIR policy');
|
|
132
|
+
const generation=assertObject(policy.generation||{},'WorldIR policy generation'); assertKnownKeys(generation,GENERATION_KEYS,'WorldIR policy generation');
|
|
133
|
+
const physicsPolicy=assertObject(policy.physics||{},'WorldIR policy physics'); assertKnownKeys(physicsPolicy,PHYSICS_POLICY_KEYS,'WorldIR policy physics');
|
|
134
|
+
const defaultProvider=clean(generation.provider)||null,defaultGenerate=generation.generate===true;
|
|
135
|
+
if(!Array.isArray(input.entities||[])) throw new TypeError('WorldIR entities must be an array');
|
|
136
|
+
const entityIds=new Set();
|
|
137
|
+
const entities=(input.entities||[]).map((entity,index)=>{
|
|
138
|
+
const label=`WorldIR entity[${index}]`; assertObject(entity,label); assertKnownKeys(entity,ENTITY_KEYS,label);
|
|
139
|
+
const id=clean(entity.id)||null; if(id){if(entityIds.has(id)) throw new TypeError(`WorldIR duplicate entity id: ${id}`); entityIds.add(id);}
|
|
140
|
+
const asset=assertObject(entity.asset||{},`${label} asset`); assertKnownKeys(asset,ASSET_KEYS,`${label} asset`);
|
|
141
|
+
const assetId=clean(asset.assetId)||null,type=clean(asset.type)||null,prompt=clean(asset.prompt)||null,query=clean(asset.query)||prompt||type||assetId;
|
|
142
|
+
if(!query) throw new TypeError(`${label} asset requires assetId, query, prompt, or type`);
|
|
143
|
+
const transform=assertObject(entity.transform||{},`${label} transform`); assertKnownKeys(transform,TRANSFORM_KEYS,`${label} transform`);
|
|
144
|
+
const position=transform.position==null?null:finiteVec3(transform.position); if(transform.position!=null&&!position) throw new TypeError(`${label} transform position requires finite [3]`);
|
|
145
|
+
const physicsRequirement=normalizePhysicsRequirement(entity.physicsRequirement,`${label} physicsRequirement`);
|
|
146
|
+
const capabilityIntent=uniqueStrings(entity.capabilityIntent,`${label} capabilityIntent`,{upper:true});
|
|
147
|
+
const initialState=normalizeInitialState(entity.initialState,`${label} initialState`);
|
|
148
|
+
const provider=clean(asset.provider)||defaultProvider;
|
|
149
|
+
return {...(id?{id}:{}),asset:{...(assetId?{assetId}:{}),query,...(type?{type}:{}),...(prompt?{prompt}:{}),generate:asset.generate==null?defaultGenerate:asset.generate===true,...(provider?{provider}:{})},transform:{...(position?{position}:{})},...(physicsRequirement&&Object.keys(physicsRequirement).length?{physicsRequirement}:{}),capabilityIntent,initialState};
|
|
150
|
+
});
|
|
151
|
+
const spatial=assertObject(input.spatial||{},'WorldIR spatial'); assertKnownKeys(spatial,SPATIAL_KEYS,'WorldIR spatial');
|
|
152
|
+
if(!Array.isArray(spatial.relations||[])) throw new TypeError('WorldIR spatial relations must be an array'); if(!Array.isArray(spatial.constraints||[])) throw new TypeError('WorldIR spatial constraints must be an array');
|
|
153
|
+
const relations=(spatial.relations||[]).map(normalizeRelation); const constraintIds=new Set();
|
|
154
|
+
const constraints=(spatial.constraints||[]).map((constraint,index)=>{const label=`WorldIR spatial constraint[${index}]`; assertObject(constraint,label); assertKnownKeys(constraint,CONSTRAINT_KEYS,label); const id=uniqueId(constraintIds,clean(constraint.id),label),kind=clean(constraint.kind); if(!kind) throw new TypeError(`${label} requires kind`); return {id,kind,...(clean(constraint.subject)?{subject:clean(constraint.subject)}:{}),...(clean(constraint.object)?{object:clean(constraint.object)}:{}),...(clean(constraint.description)?{description:clean(constraint.description)}:{})};});
|
|
155
|
+
const interactionIds=new Set(); if(!Array.isArray(input.interactions||[])) throw new TypeError('WorldIR interactions must be an array');
|
|
156
|
+
const interactions=(input.interactions||[]).map((item,index)=>{const label=`WorldIR interaction[${index}]`; assertObject(item,label); assertKnownKeys(item,INTERACTION_KEYS,label); const id=uniqueId(interactionIds,clean(item.id),label),targetId=clean(item.targetId),supportId=clean(item.supportId),capability=clean(item.capability).toUpperCase(),stateKey=clean(item.stateKey); if(!capability) throw new TypeError(`${label} requires capability`); if(['OPEN','CLOSE','PICKUP','SWITCH'].includes(capability)&&!targetId) throw new TypeError(`${label} ${capability} requires targetId`); if(capability==='PLACE'&&!supportId) throw new TypeError(`${label} PLACE requires supportId`); if(capability==='SWITCH'){if(!stateKey||!Object.prototype.hasOwnProperty.call(item,'value')) throw new TypeError(`${label} SWITCH requires stateKey/value`); const value=item.value; if(value!==null&&!['string','number','boolean'].includes(typeof value)) throw new TypeError(`${label} SWITCH value must be JSON scalar`);} return {id,...(clean(item.actorId)?{actorId:clean(item.actorId)}:{}),...(targetId?{targetId}:{}),...(supportId?{supportId}:{}),capability,...(stateKey?{stateKey}:{}),...(Object.prototype.hasOwnProperty.call(item,'value')?{value:item.value}:{}),...(clean(item.description)?{description:clean(item.description)}:{})};});
|
|
157
|
+
const ruleIds=new Set(); if(!Array.isArray(input.rules||[])) throw new TypeError('WorldIR rules must be an array');
|
|
158
|
+
const rules=(input.rules||[]).map((item,index)=>{const label=`WorldIR rule[${index}]`; assertObject(item,label); assertKnownKeys(item,RULE_KEYS,label); const id=uniqueId(ruleIds,clean(item.id),label),event=clean(item.event); if(!event||item.effect==null) throw new TypeError(`${label} requires event and effect`); assertJsonValue(item.effect,`${label} effect`); if(item.condition!=null) assertJsonValue(item.condition,`${label} condition`); const effect=typeof item.effect==='string'?clean(item.effect):structuredClone(item.effect); if(typeof effect==='string'&&!effect) throw new TypeError(`${label} requires effect`); const condition=item.condition==null?null:(typeof item.condition==='string'?clean(item.condition):structuredClone(item.condition)); return {id,event,...(condition?{condition}:{}),effect,...(clean(item.description)?{description:clean(item.description)}:{})};});
|
|
159
|
+
const acceptanceIds=new Set(); if(!Array.isArray(input.acceptance||[])) throw new TypeError('WorldIR acceptance must be an array');
|
|
160
|
+
const acceptance=(input.acceptance||[]).map((item,index)=>{const label=`WorldIR acceptance[${index}]`; assertObject(item,label); assertKnownKeys(item,ACCEPTANCE_KEYS,label); const id=uniqueId(acceptanceIds,clean(item.id),label),kind=clean(item.kind),descriptionText=clean(item.description); if(!kind) throw new TypeError(`${label} requires kind`); if(!['world-valid','object-exists','state-equals','interaction-verified','relation-exists','no-unresolved'].includes(kind)) throw new TypeError(`${label} unsupported kind: ${kind}`); const targetId=clean(item.targetId),capability=clean(item.capability).toUpperCase(),stateKey=clean(item.stateKey),source=clean(item.source),subject=clean(item.subject),predicate=clean(item.predicate).toUpperCase(),object=clean(item.object),surfaceId=clean(item.surfaceId),partName=clean(item.partName); if(kind==='object-exists'&&!targetId) throw new TypeError(`${label} object-exists requires targetId`); if(kind==='state-equals'&&(!targetId||!stateKey||!Object.prototype.hasOwnProperty.call(item,'value'))) throw new TypeError(`${label} state-equals requires targetId/stateKey/value`); if(kind==='interaction-verified'&&(!targetId||!capability)) throw new TypeError(`${label} interaction-verified requires targetId/capability`); if(kind==='relation-exists'){if(!subject||!predicate||!object) throw new TypeError(`${label} relation-exists requires subject/predicate/object`); if(!['ON','NEAR','INSIDE','CONTAINS','SUPPORTS'].includes(predicate)) throw new TypeError(`${label} unsupported relation predicate: ${predicate}`);} return {id,kind,...(targetId?{targetId}:{}),...(capability?{capability}:{}),...(kind==='interaction-verified'&&partName?{partName}:{}),...(stateKey?{stateKey}:{}),...(source?{source}:{}),...(subject?{subject}:{}),...(predicate?{predicate}:{}),...(object?{object}:{}),...(surfaceId?{surfaceId}:{}),...(Object.prototype.hasOwnProperty.call(item,'value')?{value:item.value}:{}),...(descriptionText?{description:descriptionText}:{})};});
|
|
161
|
+
return {schema:WORLD_IR_SCHEMA,schemaVersion:WORLD_IR_VERSION,revision:{id:revisionId,...(parentId?{parentId}:{}),...(clean(revision.reason)?{reason:clean(revision.reason)}:{})},provenance:{source,...(clean(provenance.sourceId)?{sourceId:clean(provenance.sourceId)}:{}),...(clean(provenance.createdBy)?{createdBy:clean(provenance.createdBy)}:{}),evidenceRefs},intent:{name,description,...(task?{task}: {})},policy:{generation:{...(defaultProvider?{provider:defaultProvider}:{}),generate:defaultGenerate},physics:{...(clean(physicsPolicy.fallbackPolicy)?{fallbackPolicy:clean(physicsPolicy.fallbackPolicy)}:{})}},entities,spatial:{relations,constraints},interactions,rules,acceptance};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function serializeWorldIR(input){return JSON.stringify(normalizeWorldIR(input));}
|
|
165
|
+
export function parseWorldIR(serialized){if(typeof serialized!=='string') throw new TypeError('Serialized WorldIR must be a string'); let value; try{value=JSON.parse(serialized);}catch(cause){const error=new TypeError('Serialized WorldIR must contain valid JSON',{cause});error.code='WORLD_IR_JSON_INVALID';throw error;} return normalizeWorldIR(value);}
|