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,110 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Vector3, Quaternion } from 'three';
|
|
3
|
+
|
|
4
|
+
const positiveTicks=z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
5
|
+
const environment=z.object({weather:z.enum(['clear','rain','snow']),daylight:z.number().min(0).max(1)});
|
|
6
|
+
const sound=z.object({kind:z.literal('sound'),source:z.string().min(1).max(256),category:z.string().min(1).max(256),
|
|
7
|
+
radius:z.number().positive(),ticks:positiveTicks});
|
|
8
|
+
const cueSchema=z.discriminatedUnion('kind',[sound,environment.extend({kind:z.literal('environment')})]);
|
|
9
|
+
export const timelineSnapshotSchema=z.object({
|
|
10
|
+
version:z.literal(1),environment,cues:z.array(z.object({after:positiveTicks,cue:cueSchema})).max(4096),
|
|
11
|
+
sounds:z.array(z.object({remaining:positiveTicks,cue:sound})).max(256)
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/** Simulation cues and sensory observations scoped to one simulation session. */
|
|
15
|
+
export class WorldTimeline {
|
|
16
|
+
constructor(world) {
|
|
17
|
+
this.world = world;
|
|
18
|
+
this.reset();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
reset() {
|
|
22
|
+
this.cues = [];
|
|
23
|
+
this.sounds = [];
|
|
24
|
+
this.environment = {weather:'clear', daylight:1};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
schedule(tick, cue) {
|
|
28
|
+
if (!Number.isSafeInteger(tick) || tick <= this.world.simulation.tick) throw new RangeError('Expected a future simulation tick');
|
|
29
|
+
if (this.cues.length >= 4096) throw new RangeError('Timeline cue limit exceeded');
|
|
30
|
+
const entry = {tick,cue:cueSchema.parse(cue)};
|
|
31
|
+
this.cues.push(entry);
|
|
32
|
+
this.cues.sort((a,b)=>a.tick-b.tick);
|
|
33
|
+
return () => {
|
|
34
|
+
const index = this.cues.indexOf(entry);
|
|
35
|
+
if (index >= 0) this.cues.splice(index,1);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
snapshot() {
|
|
40
|
+
const now=this.world.simulation.tick;
|
|
41
|
+
return {version:1,environment:{...this.environment},
|
|
42
|
+
cues:this.cues.map(({tick,cue})=>({after:tick-now,cue:{...cue}})),
|
|
43
|
+
sounds:this.sounds.filter(s=>s.until>now && this.object(s.source)===s.object)
|
|
44
|
+
.map(({object,until,...cue})=>({remaining:until-now,cue}))};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
rebase(delta) {
|
|
48
|
+
for (const entry of this.cues) entry.tick+=delta;
|
|
49
|
+
for (const sound of this.sounds) sound.until+=delta;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
restore(saved) {
|
|
53
|
+
const state=saved && timelineSnapshotSchema.parse(saved);
|
|
54
|
+
this.reset();
|
|
55
|
+
if (!state) return;
|
|
56
|
+
const now=this.world.simulation.tick;
|
|
57
|
+
this.environment=state.environment;
|
|
58
|
+
for (const {after,cue} of state.cues) this.schedule(now+after,cue);
|
|
59
|
+
for (const {remaining,cue} of state.sounds) {
|
|
60
|
+
const object=this.object(cue.source);
|
|
61
|
+
if (object) this.sounds.push({...cue,object,until:now+remaining});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
object(id) {
|
|
66
|
+
if (this.world.store.has(id)) {
|
|
67
|
+
const record = this.world.store.get(id);
|
|
68
|
+
if (record.active === false) return null;
|
|
69
|
+
}
|
|
70
|
+
return this.world.entities.get(id)?.object;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
advance(tick) {
|
|
74
|
+
if (this.sounds.length) this.sounds = this.sounds.filter(sound=>sound.until>tick);
|
|
75
|
+
if (!this.cues.length || this.cues[0].tick>tick) return;
|
|
76
|
+
const due=[];
|
|
77
|
+
while (this.cues.length && this.cues[0].tick<=tick) due.push(this.cues.shift());
|
|
78
|
+
for (const {cue} of due) {
|
|
79
|
+
if (cue.kind==='environment') {
|
|
80
|
+
this.environment={weather:cue.weather,daylight:cue.daylight};
|
|
81
|
+
} else {
|
|
82
|
+
const object=this.object(cue.source);
|
|
83
|
+
if (!object) continue;
|
|
84
|
+
if (this.sounds.length===256) this.sounds.shift();
|
|
85
|
+
this.sounds.push({...cue,object,until:tick+cue.ticks});
|
|
86
|
+
}
|
|
87
|
+
this.world.events.emit('timeline.'+cue.kind,{...cue,tick},{isolateListeners:true});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
observeSounds(observerId) {
|
|
92
|
+
const observer=this.object(observerId);
|
|
93
|
+
if (!observer) throw new Error('Missing sound observer');
|
|
94
|
+
const origin=observer.getWorldPosition(new Vector3());
|
|
95
|
+
const inverse=observer.getWorldQuaternion(new Quaternion()).invert();
|
|
96
|
+
const result=[];
|
|
97
|
+
for (const sound of this.sounds) {
|
|
98
|
+
if (this.object(sound.source)!==sound.object) continue;
|
|
99
|
+
const delta=sound.object.getWorldPosition(new Vector3()).sub(origin);
|
|
100
|
+
const distance=delta.length();
|
|
101
|
+
if (distance>=sound.radius) continue;
|
|
102
|
+
const target=sound.object.getWorldPosition(new Vector3());
|
|
103
|
+
const hit=this.world.physics?.raycast?.(origin.toArray(),target.toArray(),{excludeIds:[observerId,sound.source]});
|
|
104
|
+
const occluded=Boolean(hit && hit.distance < distance-1e-5);
|
|
105
|
+
result.push({occluded,source:sound.source,category:sound.category,distance,
|
|
106
|
+
direction:delta.normalize().applyQuaternion(inverse).toArray(),audibility:(1-distance/sound.radius)*(occluded ? 0.35 : 1)});
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
const rounded = (vector) => vector.toArray().map((value) => Number(value.toFixed(3)));
|
|
4
|
+
|
|
5
|
+
export function spatialSnapshotEntry(id, object) {
|
|
6
|
+
const box = new THREE.Box3().setFromObject(object);
|
|
7
|
+
const size = box.getSize(new THREE.Vector3());
|
|
8
|
+
const center = box.getCenter(new THREE.Vector3());
|
|
9
|
+
return {
|
|
10
|
+
id,
|
|
11
|
+
box,
|
|
12
|
+
center,
|
|
13
|
+
size,
|
|
14
|
+
bounds: { id, min: rounded(box.min), max: rounded(box.max), center: rounded(center), size: rounded(size) }
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function objectWorldPosition(object) {
|
|
19
|
+
return object.getWorldPosition(new THREE.Vector3());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function translateSpatialEntry(entry, delta) {
|
|
23
|
+
const offset = delta?.isVector3 ? delta : new THREE.Vector3(...delta);
|
|
24
|
+
const box = entry.box.clone().translate(offset);
|
|
25
|
+
const center = entry.center.clone().add(offset);
|
|
26
|
+
const size = entry.size.clone();
|
|
27
|
+
return {
|
|
28
|
+
id: entry.id,
|
|
29
|
+
box,
|
|
30
|
+
center,
|
|
31
|
+
size,
|
|
32
|
+
bounds: {
|
|
33
|
+
id: entry.id,
|
|
34
|
+
min: rounded(box.min),
|
|
35
|
+
max: rounded(box.max),
|
|
36
|
+
center: rounded(center),
|
|
37
|
+
size: rounded(size)
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function spatialEntryAtRootPosition(entry, currentRootPosition, candidateRootPosition) {
|
|
43
|
+
const current = currentRootPosition?.isVector3 ? currentRootPosition : new THREE.Vector3(...currentRootPosition);
|
|
44
|
+
const candidate = candidateRootPosition?.isVector3 ? candidateRootPosition : new THREE.Vector3(...candidateRootPosition);
|
|
45
|
+
return translateSpatialEntry(entry, candidate.clone().sub(current));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function boxesOverlap(left, right, margin = 0) {
|
|
49
|
+
const inset = Math.max(0, Number.isFinite(margin) ? margin : 0);
|
|
50
|
+
const aminX = left.min.x + inset, aminY = left.min.y + inset, aminZ = left.min.z + inset;
|
|
51
|
+
const amaxX = left.max.x - inset, amaxY = left.max.y - inset, amaxZ = left.max.z - inset;
|
|
52
|
+
const bminX = right.min.x + inset, bminY = right.min.y + inset, bminZ = right.min.z + inset;
|
|
53
|
+
const bmaxX = right.max.x - inset, bmaxY = right.max.y - inset, bmaxZ = right.max.z - inset;
|
|
54
|
+
if (aminX > amaxX || aminY > amaxY || aminZ > amaxZ || bminX > bmaxX || bminY > bmaxY || bminZ > bmaxZ) return false;
|
|
55
|
+
return aminX <= bmaxX && amaxX >= bminX && aminY <= bmaxY && amaxY >= bminY && aminZ <= bmaxZ && amaxZ >= bminZ;
|
|
56
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
// Material batching can put distant, disconnected solids in a single mesh.
|
|
4
|
+
// Refine the conservative AABB only for bounded indexed triangle geometry.
|
|
5
|
+
// Weld coincident positions for connectivity so UV/normal seams cannot split
|
|
6
|
+
// a closed solid into unrelated faces. No geometry or physics is mutated.
|
|
7
|
+
export function visualComponentBounds(geometry, matrixWorld, limit) {
|
|
8
|
+
const position=geometry.getAttribute('position'), index=geometry.getIndex();
|
|
9
|
+
if(!index || !position || position.itemSize!==3 || position.count>100000 || index.count>300000 || index.count%3!==0 || limit<2) return null;
|
|
10
|
+
const parent=new Int32Array(position.count);
|
|
11
|
+
const points=new Map();
|
|
12
|
+
for(let i=0;i<position.count;i++){
|
|
13
|
+
parent[i]=i;
|
|
14
|
+
const x=position.getX(i),y=position.getY(i),z=position.getZ(i);
|
|
15
|
+
if(![x,y,z].every(Number.isFinite))return null;
|
|
16
|
+
const key=`${x},${y},${z}`;
|
|
17
|
+
if(points.has(key))parent[i]=points.get(key);
|
|
18
|
+
else points.set(key,i);
|
|
19
|
+
}
|
|
20
|
+
const root=i=>{while(parent[i]!==i){parent[i]=parent[parent[i]];i=parent[i];}return i;};
|
|
21
|
+
const join=(a,b)=>{a=root(a);b=root(b);if(a!==b)parent[Math.max(a,b)]=Math.min(a,b);};
|
|
22
|
+
for(let i=0;i<index.count;i+=3){
|
|
23
|
+
const a=index.getX(i),b=index.getX(i+1),c=index.getX(i+2);
|
|
24
|
+
if(![a,b,c].every(v=>Number.isInteger(v)&&v>=0&&v<position.count))return null;
|
|
25
|
+
join(a,b);join(a,c);
|
|
26
|
+
}
|
|
27
|
+
const boxes=new Map(),point=new THREE.Vector3();
|
|
28
|
+
// Include even unreferenced vertices to preserve the full mesh bound.
|
|
29
|
+
for(let i=0;i<position.count;i++){
|
|
30
|
+
const key=root(i);
|
|
31
|
+
if(!boxes.has(key)){
|
|
32
|
+
if(boxes.size>=limit)return null;
|
|
33
|
+
boxes.set(key,new THREE.Box3());
|
|
34
|
+
}
|
|
35
|
+
point.fromBufferAttribute(position,i);
|
|
36
|
+
boxes.get(key).expandByPoint(point);
|
|
37
|
+
}
|
|
38
|
+
if(boxes.size<2)return null;
|
|
39
|
+
const result=[...boxes.values()].map(box=>box.applyMatrix4(matrixWorld));
|
|
40
|
+
return result.every(box=>!box.isEmpty()&&[...box.min.toArray(),...box.max.toArray()].every(Number.isFinite))?result:null;
|
|
41
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { Instrument } from './Instrument.js';
|
|
3
|
+
|
|
4
|
+
const fail = (code, message) => Object.assign(new Error(message), { code });
|
|
5
|
+
|
|
6
|
+
/** Spatial one-shot tones attached to host-owned Three.js entities. */
|
|
7
|
+
export class AudioSystem {
|
|
8
|
+
constructor({ entities, listener, three = THREE, maxVoices = 128 } = {}) {
|
|
9
|
+
if (!entities || typeof entities.get !== 'function') throw new TypeError('AudioSystem requires an entity registry');
|
|
10
|
+
if (!listener?.context || typeof listener.context.createOscillator !== 'function' || typeof listener.getInput !== 'function') {
|
|
11
|
+
throw new TypeError('AudioSystem requires a host-owned Three.js AudioListener');
|
|
12
|
+
}
|
|
13
|
+
if (typeof three.PositionalAudio !== 'function') throw new TypeError('AudioSystem requires Three.js PositionalAudio');
|
|
14
|
+
this.entities = entities;
|
|
15
|
+
this.listener = listener;
|
|
16
|
+
this.context = listener.context;
|
|
17
|
+
this.three = three;
|
|
18
|
+
this.buses = new Map();
|
|
19
|
+
this.volumes = new Map();
|
|
20
|
+
if (!Number.isSafeInteger(maxVoices) || maxVoices<1) throw new RangeError('Invalid audio voice limit');
|
|
21
|
+
this.maxVoices=maxVoices;
|
|
22
|
+
this.voices=new Set();
|
|
23
|
+
this.emitters = new Map();
|
|
24
|
+
this.notes = new Set();
|
|
25
|
+
this.instruments = new Set();
|
|
26
|
+
this.disposed = false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
registerEmitter(id, object = this.entities.get(id)?.object, options = {}) {
|
|
30
|
+
this.assertAvailable();
|
|
31
|
+
const entity = this.entities.get(id);
|
|
32
|
+
if (!entity) throw fail('AUDIO_ENTITY_NOT_FOUND', `Audio entity not found: ${id}`);
|
|
33
|
+
if (entity.phase==='inactive') throw fail('AUDIO_ENTITY_INACTIVE','Activate the entity before attaching audio');
|
|
34
|
+
if (!object?.isObject3D || object !== entity.object) throw fail('AUDIO_OBJECT_MISMATCH', 'Audio emitter must use its registered entity object');
|
|
35
|
+
if (this.emitters.has(id)) throw fail('AUDIO_EMITTER_CONFLICT', `Audio emitter already registered: ${id}`);
|
|
36
|
+
const refDistance=options.refDistance ?? 1;
|
|
37
|
+
const rolloffFactor=options.rolloffFactor ?? 1;
|
|
38
|
+
if (!Number.isFinite(refDistance) || refDistance<=0 || !Number.isFinite(rolloffFactor) || rolloffFactor<0) {
|
|
39
|
+
throw new RangeError('Invalid spatial attenuation');
|
|
40
|
+
}
|
|
41
|
+
const bus = this.bus(options.bus ?? 'sfx');
|
|
42
|
+
const sound = new this.three.PositionalAudio(this.listener);
|
|
43
|
+
let input;
|
|
44
|
+
try {
|
|
45
|
+
sound.gain.disconnect();
|
|
46
|
+
sound.gain.connect(bus);
|
|
47
|
+
sound.setRefDistance(refDistance);
|
|
48
|
+
sound.setRolloffFactor(rolloffFactor);
|
|
49
|
+
input=this.context.createGain();
|
|
50
|
+
sound.setNodeSource(input);
|
|
51
|
+
object.add(sound);
|
|
52
|
+
} catch(error) {
|
|
53
|
+
input?.disconnect();
|
|
54
|
+
sound.panner.disconnect();
|
|
55
|
+
sound.gain.disconnect();
|
|
56
|
+
sound.removeFromParent();
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
this.emitters.set(id, { object, sound, input, slots:new Map(), previousPhase: entity.phase });
|
|
60
|
+
this.entities.addCapabilities(id, ['audio-emitter']);
|
|
61
|
+
this.entities.setPhase(id, 'audio-registered');
|
|
62
|
+
return sound;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
unregisterEmitter(id) {
|
|
66
|
+
const emitter = this.emitters.get(id);
|
|
67
|
+
if (!emitter) return false;
|
|
68
|
+
for (const slot of emitter.slots.values()) slot.stop();
|
|
69
|
+
emitter.slots.clear();
|
|
70
|
+
this.stopEntityNotes(id);
|
|
71
|
+
for (const instrument of [...this.instruments]) {
|
|
72
|
+
if (instrument.entityId === id) instrument.dispose();
|
|
73
|
+
}
|
|
74
|
+
this.emitters.delete(id);
|
|
75
|
+
emitter.sound.disconnect();
|
|
76
|
+
emitter.sound.gain.disconnect();
|
|
77
|
+
emitter.sound.removeFromParent();
|
|
78
|
+
if (this.entities.has(id)) {
|
|
79
|
+
this.entities.removeCapabilities(id, ['audio-emitter']);
|
|
80
|
+
this.entities.setPhase(id, emitter.previousPhase);
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
bus(name) {
|
|
86
|
+
this.assertAvailable();
|
|
87
|
+
if (!['music','ambience','sfx','voice'].includes(name)) throw fail('AUDIO_BUS_INVALID','Unknown audio bus');
|
|
88
|
+
if (!this.buses.has(name)) {
|
|
89
|
+
const bus = this.context.createGain();
|
|
90
|
+
bus.connect(this.listener.getInput());
|
|
91
|
+
this.buses.set(name,bus);
|
|
92
|
+
}
|
|
93
|
+
return this.buses.get(name);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setBusVolume(name, volume) {
|
|
97
|
+
if (!Number.isFinite(volume) || volume < 0 || volume > 1) throw new RangeError('Volume must be within [0,1]');
|
|
98
|
+
this.bus(name).gain.setValueAtTime(volume,this.context.currentTime);
|
|
99
|
+
this.volumes.set(name,volume);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
reserveVoice(stop) {
|
|
103
|
+
if (this.voices.size>=this.maxVoices) this.voices.values().next().value();
|
|
104
|
+
this.voices.add(stop);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
snapshotMix() { return Object.fromEntries(this.volumes); }
|
|
108
|
+
|
|
109
|
+
restoreMix(state) {
|
|
110
|
+
for (const name of this.volumes.keys()) {
|
|
111
|
+
if (!Object.hasOwn(state,name)) this.bus(name).gain.setValueAtTime(1,this.context.currentTime);
|
|
112
|
+
}
|
|
113
|
+
this.volumes.clear();
|
|
114
|
+
for (const [name,value] of Object.entries(state)) this.setBusVolume(name,value);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async loadSlot(id, name, bytes, {loop=false}={}) {
|
|
118
|
+
this.assertAvailable();
|
|
119
|
+
const emitter = this.emitters.get(id);
|
|
120
|
+
if (!emitter) throw fail('AUDIO_EMITTER_NOT_FOUND','Missing audio emitter');
|
|
121
|
+
if (!name || emitter.slots.has(name)) throw fail('AUDIO_SLOT_CONFLICT','Slot requires a unique name');
|
|
122
|
+
let level;
|
|
123
|
+
let source = null, offset = 0, started = 0, buffer;
|
|
124
|
+
const context = this.context;
|
|
125
|
+
const runtime = this;
|
|
126
|
+
const stop = () => {
|
|
127
|
+
if (source) {
|
|
128
|
+
source.onended = null;
|
|
129
|
+
source.stop();
|
|
130
|
+
source.disconnect();
|
|
131
|
+
level.disconnect();
|
|
132
|
+
source = null;
|
|
133
|
+
}
|
|
134
|
+
runtime.voices.delete(stop);
|
|
135
|
+
offset = 0;
|
|
136
|
+
};
|
|
137
|
+
const slot = {
|
|
138
|
+
play({at=context.currentTime,fade=0}={}) {
|
|
139
|
+
if (!Number.isFinite(at) || at<0 || !Number.isFinite(fade) || fade<0) throw new RangeError('Invalid audio timing');
|
|
140
|
+
if (emitter.slots.get(name) !== slot) throw fail('AUDIO_SLOT_RELEASED','Sound slot was released');
|
|
141
|
+
if (source) return;
|
|
142
|
+
source = context.createBufferSource();
|
|
143
|
+
source.buffer = buffer;
|
|
144
|
+
source.loop = loop;
|
|
145
|
+
level = context.createGain();
|
|
146
|
+
source.connect(level);
|
|
147
|
+
level.connect(emitter.input);
|
|
148
|
+
level.gain.setValueAtTime(fade ? 0 : 1,at);
|
|
149
|
+
if (fade) level.gain.linearRampToValueAtTime(1,at+fade);
|
|
150
|
+
source.onended = () => { runtime.voices.delete(stop); level.disconnect(); source.disconnect(); source = null; offset = 0; };
|
|
151
|
+
started = Math.max(at,context.currentTime);
|
|
152
|
+
runtime.reserveVoice(stop);
|
|
153
|
+
try { source.start(started,offset); }
|
|
154
|
+
catch(error) { source.onended=null; level.disconnect(); source.disconnect(); source=null; runtime.voices.delete(stop); throw error; }
|
|
155
|
+
},
|
|
156
|
+
fadeOut(at,duration) {
|
|
157
|
+
if (!source) return;
|
|
158
|
+
if (!Number.isFinite(at) || at<0 || !Number.isFinite(duration) || duration<0) throw new RangeError('Invalid audio timing');
|
|
159
|
+
level.gain.cancelAndHoldAtTime(at);
|
|
160
|
+
level.gain.linearRampToValueAtTime(0,at+duration);
|
|
161
|
+
source.stop(at+duration);
|
|
162
|
+
},
|
|
163
|
+
pause() {
|
|
164
|
+
if (!source) return;
|
|
165
|
+
const elapsed = offset + Math.max(0,context.currentTime - started);
|
|
166
|
+
stop();
|
|
167
|
+
offset = loop ? elapsed % buffer.duration : Math.min(elapsed,buffer.duration);
|
|
168
|
+
},
|
|
169
|
+
stop
|
|
170
|
+
};
|
|
171
|
+
emitter.slots.set(name,slot);
|
|
172
|
+
try {
|
|
173
|
+
buffer = await context.decodeAudioData(bytes.slice(0));
|
|
174
|
+
if (emitter.slots.get(name) !== slot) throw fail('AUDIO_SLOT_RELEASED','Emitter removed during decode');
|
|
175
|
+
return slot;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
emitter.slots.delete(name);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
createMusicDirector(states, {bpm=120,fade=0.25}={}) {
|
|
183
|
+
this.assertAvailable();
|
|
184
|
+
if (!Number.isFinite(bpm) || bpm<=0 || !Number.isFinite(fade) || fade<0) throw new RangeError('Invalid music timing');
|
|
185
|
+
const origin = this.context.currentTime;
|
|
186
|
+
const tracks = new Map(Object.entries(states));
|
|
187
|
+
let current;
|
|
188
|
+
return {
|
|
189
|
+
transition: name => {
|
|
190
|
+
this.assertAvailable();
|
|
191
|
+
const next = tracks.get(name);
|
|
192
|
+
if (!next) throw fail('AUDIO_STATE_UNKNOWN','Unknown music state');
|
|
193
|
+
if (current === next) return;
|
|
194
|
+
const now = this.context.currentTime;
|
|
195
|
+
const beat = 60/bpm;
|
|
196
|
+
const at = origin + Math.ceil((now-origin)/beat)*beat;
|
|
197
|
+
next.stop();
|
|
198
|
+
next.play({at,fade});
|
|
199
|
+
current?.fadeOut(at,fade);
|
|
200
|
+
current = next;
|
|
201
|
+
},
|
|
202
|
+
stop: () => {
|
|
203
|
+
for (const slot of tracks.values()) slot.stop();
|
|
204
|
+
current = null;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
createInstrument(id, options = {}) {
|
|
210
|
+
this.assertAvailable();
|
|
211
|
+
if (!this.emitters.has(id)) throw fail('AUDIO_EMITTER_NOT_FOUND', `Audio emitter not registered: ${id}`);
|
|
212
|
+
const instrument = new Instrument({ ...options, audio: this, entityId: id });
|
|
213
|
+
this.instruments.add(instrument);
|
|
214
|
+
return instrument;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async createSampleInstrument(id, bytes, {rootMidi=60}={}) {
|
|
218
|
+
this.assertAvailable();
|
|
219
|
+
if (!Number.isInteger(rootMidi) || rootMidi<0 || rootMidi>127) throw new RangeError('Invalid sample root note');
|
|
220
|
+
const emitter = this.emitters.get(id);
|
|
221
|
+
if (!emitter) throw fail('AUDIO_EMITTER_NOT_FOUND','Missing sample emitter');
|
|
222
|
+
const buffer = await this.context.decodeAudioData(bytes.slice(0));
|
|
223
|
+
if (this.emitters.get(id)!==emitter) throw fail('AUDIO_SLOT_RELEASED','Emitter removed during decode');
|
|
224
|
+
const instrument = this.createInstrument(id);
|
|
225
|
+
instrument.sample = {buffer, rootFrequency:440 * 2 ** ((rootMidi-69)/12)};
|
|
226
|
+
return instrument;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
releaseInstrument(instrument) {
|
|
230
|
+
for (const note of this.notes) if (note.instrument===instrument) this.stopNote(note);
|
|
231
|
+
this.instruments.delete(instrument);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
scheduleNote(id, { frequency, duration = 0.25, gain = 0.2, startAt = this.context.currentTime, waveform = 'sine' } = {}, instrument) {
|
|
235
|
+
this.assertAvailable();
|
|
236
|
+
const emitter = this.emitters.get(id);
|
|
237
|
+
if (!emitter) throw fail('AUDIO_EMITTER_NOT_FOUND', `Audio emitter not registered: ${id}`);
|
|
238
|
+
if (!Number.isFinite(frequency) || frequency <= 0 || !Number.isFinite(duration) || duration <= 0 ||
|
|
239
|
+
!Number.isFinite(gain) || gain < 0 || gain > 1 || !Number.isFinite(startAt) || startAt < 0 ||
|
|
240
|
+
!['sine', 'square', 'sawtooth', 'triangle'].includes(waveform)) {
|
|
241
|
+
throw fail('AUDIO_NOTE_INVALID', 'Note requires a positive frequency and duration, gain from 0 to 1, valid start time, and supported waveform');
|
|
242
|
+
}
|
|
243
|
+
const sample = instrument?.sample;
|
|
244
|
+
const source = sample ? this.context.createBufferSource() : this.context.createOscillator();
|
|
245
|
+
const envelope = this.context.createGain();
|
|
246
|
+
const note = { id, source, envelope, instrument };
|
|
247
|
+
if (sample) {
|
|
248
|
+
source.buffer = sample.buffer;
|
|
249
|
+
source.playbackRate.setValueAtTime(frequency/sample.rootFrequency,startAt);
|
|
250
|
+
} else {
|
|
251
|
+
source.type = waveform;
|
|
252
|
+
source.frequency.setValueAtTime(frequency,startAt);
|
|
253
|
+
}
|
|
254
|
+
envelope.gain.setValueAtTime(0, startAt);
|
|
255
|
+
envelope.gain.linearRampToValueAtTime(gain, startAt + Math.min(0.01,duration/2));
|
|
256
|
+
envelope.gain.setValueAtTime(gain, Math.max(startAt + Math.min(0.01,duration/2), startAt + duration - 0.02));
|
|
257
|
+
envelope.gain.linearRampToValueAtTime(0, startAt + duration);
|
|
258
|
+
source.connect(envelope);
|
|
259
|
+
envelope.connect(emitter.input);
|
|
260
|
+
source.onended = () => this.releaseNote(note);
|
|
261
|
+
note.stop=()=>this.stopNote(note);
|
|
262
|
+
this.notes.add(note);
|
|
263
|
+
this.reserveVoice(note.stop);
|
|
264
|
+
try {
|
|
265
|
+
source.start(startAt);
|
|
266
|
+
source.stop(startAt + duration);
|
|
267
|
+
} catch(error) {
|
|
268
|
+
this.stopNote(note);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
return Object.freeze({ entityId:id, stop:note.stop });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
stopNote(note) {
|
|
275
|
+
if (!this.notes.has(note)) return false;
|
|
276
|
+
try { note.source.stop(); } catch { /* It may already have ended. */ }
|
|
277
|
+
this.releaseNote(note);
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
stopEntityNotes(id) {
|
|
282
|
+
for (const note of [...this.notes]) if (note.id === id) this.stopNote(note);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
releaseNote(note) {
|
|
286
|
+
if (!this.notes.delete(note)) return;
|
|
287
|
+
this.voices.delete(note.stop);
|
|
288
|
+
note.source.onended = null;
|
|
289
|
+
note.source.disconnect();
|
|
290
|
+
note.envelope.disconnect();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
assertAvailable() {
|
|
294
|
+
if (this.disposed) throw fail('AUDIO_RUNTIME_DISPOSED', 'AudioSystem has been disposed');
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
dispose() {
|
|
298
|
+
if (this.disposed) return;
|
|
299
|
+
for (const instrument of [...this.instruments]) instrument.dispose();
|
|
300
|
+
for (const id of [...this.emitters.keys()]) this.unregisterEmitter(id);
|
|
301
|
+
for (const note of [...this.notes]) this.stopNote(note);
|
|
302
|
+
for (const bus of this.buses.values()) bus.disconnect();
|
|
303
|
+
this.buses.clear();
|
|
304
|
+
this.disposed = true;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const fail = (code, message) => Object.assign(new Error(message), { code });
|
|
2
|
+
|
|
3
|
+
/** Maps named instrument notes to the host-owned spatial audio runtime. */
|
|
4
|
+
export class Instrument {
|
|
5
|
+
constructor({ audio, entityId, notes = {}, duration = 0.25, gain = 0.2, waveform = 'sine' } = {}) {
|
|
6
|
+
if (!audio || typeof audio.scheduleNote !== 'function' || typeof audio.releaseInstrument !== 'function') {
|
|
7
|
+
throw new TypeError('Instrument requires an AudioSystem');
|
|
8
|
+
}
|
|
9
|
+
if (typeof entityId !== 'string' || !entityId) throw new TypeError('Instrument requires an entity ID');
|
|
10
|
+
if (!notes || typeof notes !== 'object' || Array.isArray(notes)) throw new TypeError('Instrument notes must be an object');
|
|
11
|
+
this.audio = audio;
|
|
12
|
+
this.entityId = entityId;
|
|
13
|
+
this.notes = Object.freeze({ ...notes });
|
|
14
|
+
this.defaults = Object.freeze({ duration, gain, waveform });
|
|
15
|
+
this.disposed = false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
play(note, options = {}) {
|
|
19
|
+
if (this.disposed) throw fail('AUDIO_INSTRUMENT_DISPOSED', 'Instrument has been disposed');
|
|
20
|
+
const noteOptions = typeof note === 'string' ? this.notes[note] : note;
|
|
21
|
+
if (noteOptions === undefined) throw fail('AUDIO_NOTE_UNKNOWN', `Instrument note not found: ${note}`);
|
|
22
|
+
const resolved = typeof noteOptions === 'number' ? { frequency: noteOptions } : noteOptions;
|
|
23
|
+
if (!resolved || typeof resolved !== 'object' || Array.isArray(resolved)) {
|
|
24
|
+
throw fail('AUDIO_NOTE_UNKNOWN', `Instrument note is invalid: ${note}`);
|
|
25
|
+
}
|
|
26
|
+
return this.audio.scheduleNote(this.entityId, { ...this.defaults, ...resolved, ...options }, this);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
trigger(note, options = {}) {
|
|
30
|
+
return this.play(note, options);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dispose() {
|
|
34
|
+
if (this.disposed) return;
|
|
35
|
+
this.disposed = true;
|
|
36
|
+
this.audio.releaseInstrument(this);
|
|
37
|
+
this.sample = null;
|
|
38
|
+
}
|
|
39
|
+
}
|