agentscape3d-engine 0.0.0-stage → 1.0.0-beta.2
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/AssetCompiler-A99wKf7H.js +2424 -0
- package/dist/AssetCompiler-A99wKf7H.js.map +1 -0
- package/dist/AssetInputContracts-uKYeQu-X.js +245 -0
- package/dist/AssetInputContracts-uKYeQu-X.js.map +1 -0
- package/dist/AssetRecipe-DCaLLXvG.js +67 -0
- package/dist/AssetRecipe-DCaLLXvG.js.map +1 -0
- package/dist/BrowserCodeWorker.js +53850 -0
- package/dist/BrowserCodeWorker.js.map +1 -0
- package/dist/KinematicHypothesisScreen-4v7GBwdv.js +241 -0
- package/dist/KinematicHypothesisScreen-4v7GBwdv.js.map +1 -0
- package/dist/SceneSerializer-CLCzQjL_.js +350 -0
- package/dist/SceneSerializer-CLCzQjL_.js.map +1 -0
- package/dist/StylePack-CD_BC-Mv.js +6317 -0
- package/dist/StylePack-CD_BC-Mv.js.map +1 -0
- package/dist/WorldArchive-dYf1OpSe.js +417 -0
- package/dist/WorldArchive-dYf1OpSe.js.map +1 -0
- package/dist/WorldIO-Dqz4MqTQ.js +149 -0
- package/dist/WorldIO-Dqz4MqTQ.js.map +1 -0
- package/dist/blankWorld-OoOvN_IK.js +75 -0
- package/dist/blankWorld-OoOvN_IK.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-B3HCflvO.js +128 -0
- package/dist/disposeObject3D-B3HCflvO.js.map +1 -0
- package/dist/environments-B1WaICAN.js +4197 -0
- package/dist/environments-B1WaICAN.js.map +1 -0
- package/dist/gltfIO-BMK1hc2D.js +9 -0
- package/dist/gltfIO-BMK1hc2D.js.map +1 -0
- package/dist/grandUrbanBlock-Bdjgc6ZT.js +515 -0
- package/dist/grandUrbanBlock-Bdjgc6ZT.js.map +1 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +16239 -0
- package/dist/index.js.map +1 -0
- package/dist/magicCabin-DPQi_jh-.js +11019 -0
- package/dist/magicCabin-DPQi_jh-.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +1 -0
- package/dist/monumentHall-IOLbRZQC.js +403 -0
- package/dist/monumentHall-IOLbRZQC.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +26 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/ruinedCourtyard-BtaF_aOi.js +696 -0
- package/dist/ruinedCourtyard-BtaF_aOi.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 +8 -0
- package/dist/runtime/application/buildTaskObservation.js +117 -0
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +46 -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 +72 -0
- package/dist/runtime/application/createSession.js +66 -0
- package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
- package/dist/runtime/application/generation/GenerationOrchestrator.js +629 -0
- package/dist/runtime/application/generation/GenerationRuntime.js +214 -0
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +285 -0
- package/dist/runtime/application/native-scene/CodeProject.js +119 -0
- package/dist/runtime/application/native-scene/CodeProjectModules.js +128 -0
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +62 -0
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
- package/dist/runtime/application/native-scene/NativeSceneHost.js +319 -0
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
- package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
- package/dist/runtime/application/object-forge/SceneObjectForge.js +232 -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 +79 -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 +45 -0
- package/dist/runtime/application/scene/SceneEditService.js +144 -0
- package/dist/runtime/application/scene/SceneFacade.js +261 -0
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +40 -0
- package/dist/runtime/application/scene/SceneJobController.js +229 -0
- package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
- package/dist/runtime/application/scene/ScenePackage.js +162 -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 +87 -0
- package/dist/runtime/application/scene/WorldDirectory.js +20 -0
- package/dist/runtime/application/scene/WorldDocument.js +74 -0
- package/dist/runtime/application/scene/WorldIO.js +103 -0
- package/dist/runtime/application/scene/WorldStorage.js +137 -0
- package/dist/runtime/application/skills/SkillRegistry.js +189 -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 +174 -0
- package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
- package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
- package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +77 -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 +132 -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 +150 -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 +80 -0
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +58 -0
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +190 -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 +65 -0
- package/dist/runtime/apps/mcp-server/registerTools.js +225 -0
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
- package/dist/runtime/apps/mcp-server/security.js +21 -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/WorldDiskStorage.js +51 -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/foundation/EventBus.js +18 -0
- package/dist/runtime/foundation/JsonGateway.js +47 -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 +399 -0
- package/dist/runtime/modules/asset/README.md +54 -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 +100 -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/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 +47 -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 +245 -0
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +651 -0
- package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +410 -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/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 +80 -0
- package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +150 -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 +207 -0
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +246 -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 +502 -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 +665 -0
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +107 -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 +305 -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 +222 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +130 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +120 -0
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +102 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +99 -0
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
- package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +125 -0
- package/dist/runtime/modules/world/runtime/systems/Instrument.js +38 -0
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +728 -0
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +469 -0
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1673 -0
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +457 -0
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +284 -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 +69 -0
- package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +158 -0
- package/dist/runtime/modules/world/verification/WorldValidator.js +65 -0
- package/dist/runtime/package-lock.json +16048 -0
- package/dist/runtime/package.json +105 -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-BWpTl0Wj.js +359 -0
- package/dist/schema-BWpTl0Wj.js.map +1 -0
- package/dist/suzhouGarden-H9tiPgxq.js +6150 -0
- package/dist/suzhouGarden-H9tiPgxq.js.map +1 -0
- package/dist/woodlandWorkshop-D6zzSbHr.js +483 -0
- package/dist/woodlandWorkshop-D6zzSbHr.js.map +1 -0
- package/dist/yuanmingyuan-D6IHqjZ-.js +4955 -0
- package/dist/yuanmingyuan-D6IHqjZ-.js.map +1 -0
- package/package.json +70 -4
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { AssetCatalog } from './registry/AssetCatalog.js';
|
|
2
|
+
import { AssetRegistry } from './registry/AssetRegistry.js';
|
|
3
|
+
import { AssetLoader } from './loading/AssetLoader.js';
|
|
4
|
+
import { AssetProductionError, createAssetProducer } from './production/AssetProductionPipeline.js';
|
|
5
|
+
import { HttpCompilerProvider } from './production/compiler/providers/HttpCompilerProvider.js';
|
|
6
|
+
import { CompiledAssetStore } from './persistence/CompiledAssetStore.js';
|
|
7
|
+
import { AssetManifestStore } from './persistence/AssetManifestStore.js';
|
|
8
|
+
import { LocalAssetLibrary } from './persistence/LocalAssetLibrary.js';
|
|
9
|
+
import { LocalAssetLibraryStore } from './persistence/LocalAssetLibraryStore.js';
|
|
10
|
+
import { assetAdmission } from './model/admission.js';
|
|
11
|
+
import { mechanicalDraftSchema, mechanicalDraftToAssetRecipe, mechanicalDraftToManifest } from './model/MechanicalAssetDraft.js';
|
|
12
|
+
import { recipeSchema, canonicalAssetJson, assetDigest, assertEmbeddedGLB, interactionReviewSchema } from './model/AssetInputContracts.js';
|
|
13
|
+
|
|
14
|
+
export async function verifyAndUpdateAssetArticulation(assets,assetId,options) {
|
|
15
|
+
const report=await assets.verifyArticulation(assetId,options);
|
|
16
|
+
const manifest=assets.getManifest(assetId);
|
|
17
|
+
manifest.verification={...(manifest.verification||{}),articulation:report};
|
|
18
|
+
const quality=manifest.compiler?.quality;
|
|
19
|
+
if(quality){
|
|
20
|
+
quality.advisory=(quality.advisory||[]).filter(item=>!['ARTICULATION_UNVERIFIED','ARTICULATION_VERIFICATION_FAILED'].includes(item.code));
|
|
21
|
+
if(!report.ok)quality.advisory.push({code:'ARTICULATION_VERIFICATION_FAILED',message:'运行时运动验证失败'});
|
|
22
|
+
quality.status=quality.hard?.length?'rejected':quality.advisory.length?'provisional':'ready';
|
|
23
|
+
}
|
|
24
|
+
await assets.registerManifest(manifest,{replace:true});
|
|
25
|
+
const admission=assetAdmission(manifest);
|
|
26
|
+
return {...report,readiness:admission.status,admission};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createAssetModule({
|
|
30
|
+
manifests,
|
|
31
|
+
volatile = false,
|
|
32
|
+
compiledStore = null,
|
|
33
|
+
manifestStore = undefined,
|
|
34
|
+
libraryStore = undefined,
|
|
35
|
+
gltfLoader = undefined,
|
|
36
|
+
now = () => Date.now()
|
|
37
|
+
} = {}) {
|
|
38
|
+
const store = compiledStore || new CompiledAssetStore({ indexedDBImpl: volatile ? null : globalThis.indexedDB });
|
|
39
|
+
const durableManifests = manifestStore === undefined
|
|
40
|
+
? (globalThis.indexedDB ? new AssetManifestStore() : null)
|
|
41
|
+
: manifestStore;
|
|
42
|
+
|
|
43
|
+
const registry = new AssetRegistry({ manifests });
|
|
44
|
+
const loader = new AssetLoader({ registry, compiledStore:store, ...(gltfLoader ? {gltfLoader} : {}) });
|
|
45
|
+
const catalog = new AssetCatalog({ registry });
|
|
46
|
+
|
|
47
|
+
const durableLibrary = libraryStore === undefined
|
|
48
|
+
? new LocalAssetLibraryStore()
|
|
49
|
+
: (libraryStore || new LocalAssetLibraryStore({ indexedDBImpl:null }));
|
|
50
|
+
const library = new LocalAssetLibrary({
|
|
51
|
+
assetRegistry:registry,
|
|
52
|
+
compiledStore:store,
|
|
53
|
+
store:durableLibrary,
|
|
54
|
+
now:()=>new Date(now()).toISOString()
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
let producer = null;
|
|
58
|
+
let hydrated = false;
|
|
59
|
+
let configuredCompilerProvider = null;
|
|
60
|
+
let configuredCompiler = null;
|
|
61
|
+
let configuredCompilerGetter = null;
|
|
62
|
+
let articulationVerifier = null;
|
|
63
|
+
|
|
64
|
+
const persistManifest = async (manifest) => {
|
|
65
|
+
if (manifest?.source?.kind !== 'compiled' || !durableManifests?.put) return false;
|
|
66
|
+
await durableManifests.put(manifest);
|
|
67
|
+
return true;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const configureCompiler = ({ provider = null, endpoint = '', events = null, version = 'dev' } = {}) => {
|
|
71
|
+
configuredCompilerProvider = provider || new HttpCompilerProvider({ endpoint:String(endpoint || '').trim() });
|
|
72
|
+
configuredCompiler = null;
|
|
73
|
+
configuredCompilerGetter = async () => {
|
|
74
|
+
if (!configuredCompiler) {
|
|
75
|
+
const { AssetCompiler } = await import('./production/compiler/AssetCompiler.js');
|
|
76
|
+
configuredCompiler = new AssetCompiler({ store, provider:configuredCompilerProvider, events, version });
|
|
77
|
+
}
|
|
78
|
+
return configuredCompiler;
|
|
79
|
+
};
|
|
80
|
+
return configuredCompilerGetter;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const module = {
|
|
84
|
+
async readAssetBytes(id) {
|
|
85
|
+
const manifest = registry.getManifest(id);
|
|
86
|
+
if (manifest.source.kind === 'compiled') {
|
|
87
|
+
const entry = await store.get(manifest.source.key);
|
|
88
|
+
if (!entry?.bytes) throw new Error('RESOURCE_UNAVAILABLE');
|
|
89
|
+
return entry.bytes.slice();
|
|
90
|
+
}
|
|
91
|
+
if (manifest.source.kind !== 'glb') throw new Error('RESOURCE_UNAVAILABLE');
|
|
92
|
+
const { AssetCompiler } = await import('./production/compiler/AssetCompiler.js');
|
|
93
|
+
return new AssetCompiler({ store }).fetchBytes(manifest.source.url);
|
|
94
|
+
},
|
|
95
|
+
async installPreparedAssets(entries, operation) {
|
|
96
|
+
const added = [];
|
|
97
|
+
try {
|
|
98
|
+
const durableIds = new Set((await durableManifests?.list?.() || []).map(manifest => manifest.id));
|
|
99
|
+
for (const entry of entries) if (!registry.has(entry.manifest.id) && durableIds.has(entry.manifest.id)) throw new Error('ASSET_ID_CONFLICT');
|
|
100
|
+
// Check every identity before touching durable storage.
|
|
101
|
+
for (const entry of entries) if (registry.has(entry.manifest.id)) {
|
|
102
|
+
const existing = registry.getManifest(entry.manifest.id);
|
|
103
|
+
const definition = Object.fromEntries(Object.keys(entry.expectedDefinition).map(key => [key, existing[key]]));
|
|
104
|
+
if (canonicalAssetJson(definition) !== canonicalAssetJson(entry.expectedDefinition) || await assetDigest(await module.readAssetBytes(existing.id)) !== entry.expectedSourceHash) throw new Error('ASSET_ID_CONFLICT');
|
|
105
|
+
}
|
|
106
|
+
for (const entry of entries) {
|
|
107
|
+
if (registry.has(entry.manifest.id)) continue;
|
|
108
|
+
const key = entry.manifest.source.key, previous = await store.get(key);
|
|
109
|
+
if (previous && await assetDigest(previous.bytes) !== await assetDigest(entry.bytes)) throw new Error('ASSET_ID_CONFLICT');
|
|
110
|
+
added.push({ id: entry.manifest.id, key, bytesAdded: !previous });
|
|
111
|
+
await store.put(key, entry.bytes, { manifestId: entry.manifest.id });
|
|
112
|
+
await module.registerManifest(entry.manifest);
|
|
113
|
+
}
|
|
114
|
+
return await operation();
|
|
115
|
+
} catch (error) {
|
|
116
|
+
const failures = [];
|
|
117
|
+
for (const entry of added.reverse()) try {
|
|
118
|
+
registry.removeManifest(entry.id);
|
|
119
|
+
await durableManifests?.delete?.(entry.id);
|
|
120
|
+
if (entry.bytesAdded) await store.delete(entry.key);
|
|
121
|
+
} catch (failure) { failures.push(failure); }
|
|
122
|
+
if (failures.length) throw Object.assign(new AggregateError([error, ...failures], 'Project resource rollback failed'), { code: 'PROJECT_ROLLBACK_FAILED' });
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
async importMechanicalDraft(input) {
|
|
127
|
+
const draft=mechanicalDraftSchema.parse(input);
|
|
128
|
+
const hash=await assetDigest(new TextEncoder().encode(canonicalAssetJson({draft,compiler:'mechanical-draft-v1'})));
|
|
129
|
+
const id='asset_'+hash;
|
|
130
|
+
if(registry.has(id)) {
|
|
131
|
+
const manifest=registry.getManifest(id);
|
|
132
|
+
return {manifest,admission:assetAdmission(manifest)};
|
|
133
|
+
}
|
|
134
|
+
const { compileRecipeGeometry } = await import('./production/AssetRecipe.js');
|
|
135
|
+
const {bytes}=await compileRecipeGeometry(mechanicalDraftToAssetRecipe(draft));
|
|
136
|
+
return module.importPackageAsset({id,bytes,definition:mechanicalDraftToManifest(draft)});
|
|
137
|
+
},
|
|
138
|
+
async importPackageAsset({ id, bytes, definition }) {
|
|
139
|
+
assertEmbeddedGLB(bytes);
|
|
140
|
+
if (registry.has(id)) throw Object.assign(new Error('Asset id already exists'), {code:'ASSET_ID_CONFLICT'});
|
|
141
|
+
const { AssetCompiler } = await import('./production/compiler/AssetCompiler.js');
|
|
142
|
+
const compiler = new AssetCompiler({ store, version: 'v2-input-1' });
|
|
143
|
+
// Prepare bytes without publishing them. Failed physical checks must leave no binary.
|
|
144
|
+
const output = definition.capabilityLevel === 'visual'
|
|
145
|
+
? await compiler.compileVisual({ bytes, assetId:id, label:definition.label, persist:false })
|
|
146
|
+
: await compiler.compile({ bytes, assetId:id, sourceName:'package.glb', definition,
|
|
147
|
+
authoringIntent:{usage:'interactive'}, persist:false });
|
|
148
|
+
output.manifest.capabilityLevel = definition.capabilityLevel;
|
|
149
|
+
if (Object.values(output.manifest.parts || {}).some(part=>part.joint && part.joint.type!=='fixed')) {
|
|
150
|
+
if (!articulationVerifier) throw Object.assign(new Error('Runtime verification unavailable'), {code:'RUNTIME_VERIFICATION_UNAVAILABLE'});
|
|
151
|
+
const report=await articulationVerifier.verify(id,{manifest:output.manifest,requireRegistration:true,requireSettled:true,
|
|
152
|
+
instantiate:async()=>({object:await loader.gltfLoader.loadBytes(output.optimizedBytes)})});
|
|
153
|
+
if (!report.ok) throw Object.assign(new Error('Package articulation failed validation'),
|
|
154
|
+
{code:'ASSET_PHYSICS_VERIFICATION_FAILED',details:report});
|
|
155
|
+
output.manifest.verification={articulation:report};
|
|
156
|
+
output.manifest.compiler.quality.advisory=output.manifest.compiler.quality.advisory.filter(item=>item.code!=='ARTICULATION_UNVERIFIED');
|
|
157
|
+
output.manifest.compiler.quality.status=output.manifest.compiler.quality.advisory.length?'provisional':'ready';
|
|
158
|
+
}
|
|
159
|
+
const previous=await store.get(id);
|
|
160
|
+
if (previous) throw Object.assign(new Error('Compiled asset id already exists'), {code:'ASSET_ID_CONFLICT'});
|
|
161
|
+
try {
|
|
162
|
+
await store.put(id,output.optimizedBytes,{manifestId:id,quality:output.manifest.compiler.quality.status});
|
|
163
|
+
await module.registerManifest(output.manifest);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
registry.removeManifest(id);
|
|
166
|
+
try {
|
|
167
|
+
await durableManifests?.delete?.(id);
|
|
168
|
+
await store.delete(id);
|
|
169
|
+
} catch (rollbackError) {
|
|
170
|
+
throw Object.assign(new AggregateError([error,rollbackError],'Package publish rollback failed'),
|
|
171
|
+
{code:'ASSET_PUBLISH_ROLLBACK_FAILED'});
|
|
172
|
+
}
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
return {manifest:output.manifest,admission:assetAdmission(output.manifest)};
|
|
176
|
+
},
|
|
177
|
+
async prepareInteraction({bytes,urdfBytes,name='import.glb'}) {
|
|
178
|
+
if(!(bytes instanceof Uint8Array) || bytes.byteLength>32*1024*1024) throw Object.assign(new Error('Invalid GLB input'),{code:'ASSET_INPUT_INVALID'});
|
|
179
|
+
bytes=bytes.slice();assertEmbeddedGLB(bytes);
|
|
180
|
+
let partProposal=null,urdfHash=null;
|
|
181
|
+
if(urdfBytes) {
|
|
182
|
+
if(!(urdfBytes instanceof Uint8Array) || !urdfBytes.length || urdfBytes.length>1024*1024) throw Object.assign(new Error('Invalid URDF input'),{code:'ASSET_INPUT_INVALID'});
|
|
183
|
+
urdfBytes=urdfBytes.slice();urdfHash=await assetDigest(urdfBytes);
|
|
184
|
+
if(!configuredCompilerProvider?.runUrdfProposal || configuredCompilerProvider.isConfigured?.()===false) throw Object.assign(new Error('URDF requires the configured compiler provider'),{code:'URDF_PROVIDER_UNAVAILABLE'});
|
|
185
|
+
const response=await configuredCompilerProvider.runUrdfProposal(urdfBytes);
|
|
186
|
+
partProposal=response.partProposal;
|
|
187
|
+
if(partProposal?.version!==1 || !Array.isArray(partProposal.parts) || partProposal.parts.length>32) throw Object.assign(new Error('Invalid URDF proposal'),{code:'CAPABILITY_PROPOSAL_INVALID'});
|
|
188
|
+
}
|
|
189
|
+
const {AssetCompiler}=await import('./production/compiler/AssetCompiler.js');
|
|
190
|
+
return new AssetCompiler({store,version:'interaction-v1'}).proposeInteraction({bytes,sourceName:name,partProposal,urdfHash});
|
|
191
|
+
},
|
|
192
|
+
async screenInteraction({bytes,urdfBytes,name='import.glb',proposalId,hypothesisIds}={}) {
|
|
193
|
+
assertEmbeddedGLB(bytes);
|
|
194
|
+
if (!/^[a-f0-9]{64}$/.test(String(proposalId || ''))) throw Object.assign(new Error('Invalid proposal ID'),{code:'PROPOSAL_MISMATCH'});
|
|
195
|
+
if (!articulationVerifier) throw Object.assign(new Error('Runtime verification unavailable'),{code:'RUNTIME_VERIFICATION_UNAVAILABLE'});
|
|
196
|
+
// Recompute from *these bytes*, with the same name and optional URDF:
|
|
197
|
+
// the client never provides joint frames, evidence or verification flags.
|
|
198
|
+
const proposal=await module.prepareInteraction({bytes,urdfBytes,name});
|
|
199
|
+
if (proposal.proposalId !== proposalId) throw Object.assign(new Error('Review does not match the imported source'),{code:'PROPOSAL_MISMATCH'});
|
|
200
|
+
const hypotheses=proposal.kinematics?.hypotheses || [];
|
|
201
|
+
const ids=hypothesisIds || hypotheses.slice(0,4).map(item=>item.id);
|
|
202
|
+
if (!Array.isArray(ids) || ids.length > 4 || ids.some(id=>typeof id!=='string'))
|
|
203
|
+
throw Object.assign(new Error('Invalid hypothesis selection'),{code:'HYPOTHESIS_SELECTION_INVALID'});
|
|
204
|
+
if (!ids.length) return {schema:'agentscape.kinematic-screen',schemaVersion:1,
|
|
205
|
+
proposalId,sourceHash:proposal.sourceHash,results:[],admission:'not-granted',
|
|
206
|
+
interpretation:'simulation-only; no semantic authorization or real-world mechanism proof'};
|
|
207
|
+
const {screenKinematicHypotheses}=await import('./production/verification/KinematicHypothesisScreen.js');
|
|
208
|
+
return screenKinematicHypotheses({bytes,proposal,ids,loader:loader.gltfLoader,verifier:articulationVerifier});
|
|
209
|
+
},
|
|
210
|
+
async importReviewedGLB({bytes,urdfBytes,name='import.glb',review,level='physical'}) {
|
|
211
|
+
review=interactionReviewSchema.parse(review);
|
|
212
|
+
bytes=bytes.slice();urdfBytes=urdfBytes?.slice();
|
|
213
|
+
const proposal=await module.prepareInteraction({bytes,urdfBytes,name});
|
|
214
|
+
if(review.proposalId!==proposal.proposalId) throw Object.assign(new Error('Review does not match the imported source'),{code:'PROPOSAL_MISMATCH'});
|
|
215
|
+
const hash=await assetDigest(new TextEncoder().encode(canonicalAssetJson({source:proposal.sourceHash,review,compiler:'interaction-v1'}))),assetId=`asset_${hash}`;
|
|
216
|
+
if(registry.has(assetId)) return {asset:`asset://sha256/${hash}`,manifest:registry.getManifest(assetId),admission:assetAdmission(registry.getManifest(assetId))};
|
|
217
|
+
if(!articulationVerifier) throw Object.assign(new Error('Runtime verification unavailable'),{code:'RUNTIME_VERIFICATION_UNAVAILABLE'});
|
|
218
|
+
const {AssetCompiler}=await import('./production/compiler/AssetCompiler.js');
|
|
219
|
+
const output=await new AssetCompiler({store,version:'interaction-v1'}).compile({bytes,assetId,sourceName:name,
|
|
220
|
+
authoringIntent:{usage:'interactive'},interactionReview:review,
|
|
221
|
+
partProposal:review.parts.length ? {version:1,source:'reviewed-capability-proposal',parts:review.parts.map(part=>({...part,actions:[],targets:{}}))} : null});
|
|
222
|
+
try {
|
|
223
|
+
if(Object.keys(output.manifest.parts || {}).length!==review.parts.length) throw Object.assign(new Error('Part review did not compile'),{code:'CAPABILITY_REVIEW_INVALID'});
|
|
224
|
+
const report=await articulationVerifier.verify(assetId,{manifest:output.manifest,requireRegistration:true,verifyRigidBody:true,requireSettled:true,
|
|
225
|
+
instantiate:async()=>({object:await loader.loadCompiled(output.manifest.source)})});
|
|
226
|
+
if(!report.ok || !report.physicsRegistered || report.tested!==review.parts.length || report.parts.some(part=>!part.actions?.some(action=>action.moved))) throw Object.assign(new Error('Imported physics failed validation'),{code:'ASSET_PHYSICS_VERIFICATION_FAILED',details:report});
|
|
227
|
+
output.manifest.verification={articulation:report};
|
|
228
|
+
output.manifest.capabilityLevel=level;output.manifest.contentHash=hash;
|
|
229
|
+
output.manifest.compiler.quality.advisory=output.manifest.compiler.quality.advisory.filter(item=>item.code!=='ARTICULATION_UNVERIFIED');
|
|
230
|
+
output.manifest.compiler.quality.status=output.manifest.compiler.quality.advisory.length?'provisional':'ready';
|
|
231
|
+
output.manifest.provenance.interactionSource={sourceHash:proposal.sourceHash,urdfHash:proposal.urdfHash,proposalId:proposal.proposalId};
|
|
232
|
+
await module.registerManifest(output.manifest);
|
|
233
|
+
return {asset:`asset://sha256/${hash}`,manifest:output.manifest,admission:assetAdmission(output.manifest)};
|
|
234
|
+
} catch(error) { await store.delete?.(assetId);throw error; }
|
|
235
|
+
},
|
|
236
|
+
async importGLB({ bytes, level = 'visual', label = 'Imported model', review = null, urdfBytes, name }) {
|
|
237
|
+
if(review) return module.importReviewedGLB({bytes,level,review,urdfBytes,name});
|
|
238
|
+
if (level !== 'visual') throw Object.assign(new Error('GLB physical import requires an explicit compiled definition'), { code: 'CAPABILITY_UNAVAILABLE' });
|
|
239
|
+
if (!(bytes instanceof Uint8Array) || bytes.byteLength > 32 * 1024 * 1024) throw Object.assign(new Error('Invalid GLB input'), { code: 'ASSET_INPUT_INVALID' });
|
|
240
|
+
// Own the input before asynchronous hashing; callers may reuse their buffer.
|
|
241
|
+
bytes = bytes.slice();
|
|
242
|
+
assertEmbeddedGLB(bytes);
|
|
243
|
+
const hash = await assetDigest(bytes), assetId = `asset_${hash}`;
|
|
244
|
+
if (registry.has(assetId)) return { asset: `asset://sha256/${hash}`, manifest: registry.getManifest(assetId), admission: assetAdmission(registry.getManifest(assetId)) };
|
|
245
|
+
const { AssetCompiler } = await import('./production/compiler/AssetCompiler.js');
|
|
246
|
+
const output = await new AssetCompiler({ store, version: 'v2-input-1' }).compileVisual({ bytes, assetId, label });
|
|
247
|
+
output.manifest.contentHash = hash;
|
|
248
|
+
await module.registerManifest(output.manifest);
|
|
249
|
+
return { asset: `asset://sha256/${hash}`, manifest: output.manifest, admission: assetAdmission(output.manifest) };
|
|
250
|
+
},
|
|
251
|
+
async importRecipe(input) {
|
|
252
|
+
const recipe = recipeSchema.parse(input);
|
|
253
|
+
const hash = await assetDigest(new TextEncoder().encode(canonicalAssetJson({ recipe, compiler: 'v2-input-1' }))), assetId = `asset_${hash}`;
|
|
254
|
+
if (registry.has(assetId)) return { asset: `asset://sha256/${hash}`, manifest: registry.getManifest(assetId), admission: assetAdmission(registry.getManifest(assetId)) };
|
|
255
|
+
const { compileRecipeGeometry } = await import('./production/AssetRecipe.js');
|
|
256
|
+
const { AssetCompiler } = await import('./production/compiler/AssetCompiler.js');
|
|
257
|
+
const { bytes } = await compileRecipeGeometry(recipe);
|
|
258
|
+
const compiler = new AssetCompiler({ store, version: 'v2-input-1' });
|
|
259
|
+
const output = recipe.capabilities.level === 'visual' ? await compiler.compileVisual({ bytes, assetId, label: recipe.id })
|
|
260
|
+
: await compiler.compile({ bytes, assetId, sourceName: 'recipe.glb', label: recipe.id,
|
|
261
|
+
authoringIntent: { usage: recipe.capabilities.physics.body === 'dynamic' ? 'movable' : 'static' },
|
|
262
|
+
definition: { type: 'prop', label: recipe.id, actions: recipe.capabilities.actions, physics: recipe.capabilities.physics, surfaces: recipe.capabilities.surfaces } });
|
|
263
|
+
output.manifest.capabilityLevel = recipe.capabilities.level;
|
|
264
|
+
output.manifest.contentHash = hash;
|
|
265
|
+
output.manifest.provenance = { ...output.manifest.provenance, recipe };
|
|
266
|
+
const admission = assetAdmission(output.manifest);
|
|
267
|
+
if (admission.status === 'rejected') throw Object.assign(new Error('Recipe rejected'), { code: 'ASSET_REJECTED' });
|
|
268
|
+
await module.registerManifest(output.manifest);
|
|
269
|
+
return { asset: `asset://sha256/${hash}`, manifest: output.manifest, admission };
|
|
270
|
+
},
|
|
271
|
+
registry,
|
|
272
|
+
loader,
|
|
273
|
+
catalog,
|
|
274
|
+
compiledStore:store,
|
|
275
|
+
manifestStore:durableManifests,
|
|
276
|
+
library,
|
|
277
|
+
|
|
278
|
+
getManifest(assetId) {
|
|
279
|
+
return registry.getManifest(assetId);
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
hasAsset(assetId) {
|
|
283
|
+
return registry.has(assetId);
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
assertCompatibleManifest(manifest) {
|
|
287
|
+
return registry.assertCompatibleManifest(manifest);
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
configureRenderer(renderer) {
|
|
291
|
+
return loader.configureRenderer?.(renderer);
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
instantiate(assetId, options) {
|
|
295
|
+
return loader.instantiate(assetId, options);
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
configureVerification({ articulationVerifier: verifier = null } = {}) {
|
|
299
|
+
if (verifier != null && typeof verifier.verify !== 'function') {
|
|
300
|
+
throw new TypeError('Asset articulation verifier must provide verify(assetId)');
|
|
301
|
+
}
|
|
302
|
+
articulationVerifier = verifier;
|
|
303
|
+
return module;
|
|
304
|
+
},
|
|
305
|
+
|
|
306
|
+
async verifyArticulation(assetId, options) {
|
|
307
|
+
if (!articulationVerifier) {
|
|
308
|
+
const error = new Error('Asset articulation verification is not configured');
|
|
309
|
+
error.code = 'ASSET_ARTICULATION_VERIFIER_UNAVAILABLE';
|
|
310
|
+
throw error;
|
|
311
|
+
}
|
|
312
|
+
return options==null ? articulationVerifier.verify(assetId) : articulationVerifier.verify(assetId, options);
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
async verifyAndUpdateArticulation(assetId, options) {
|
|
316
|
+
return verifyAndUpdateAssetArticulation(module,assetId,options);
|
|
317
|
+
},
|
|
318
|
+
|
|
319
|
+
async hydrate() {
|
|
320
|
+
if (hydrated) return { manifests:registry.size, restored:false };
|
|
321
|
+
if (!durableManifests?.list) {
|
|
322
|
+
await library.hydrate();
|
|
323
|
+
hydrated = true;
|
|
324
|
+
return { manifests:registry.size, restored:false };
|
|
325
|
+
}
|
|
326
|
+
const persisted = await durableManifests.list();
|
|
327
|
+
let restored = 0;
|
|
328
|
+
for (const manifest of persisted) {
|
|
329
|
+
const changed = registry.registerManifest(manifest);
|
|
330
|
+
if (changed) restored += 1;
|
|
331
|
+
}
|
|
332
|
+
await library.hydrate();
|
|
333
|
+
hydrated = true;
|
|
334
|
+
return { manifests:persisted.length, restored };
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
async registerManifest(manifest, options = {}) {
|
|
338
|
+
const changed = registry.registerManifest(manifest, options);
|
|
339
|
+
await persistManifest(registry.getManifest(manifest.id));
|
|
340
|
+
return changed;
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
async approveAsset(assetId, metadata = {}) {
|
|
344
|
+
return library.approve(assetId, metadata);
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
async listApprovedAssets() {
|
|
348
|
+
return library.list();
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
configureProduction({
|
|
352
|
+
artifacts,
|
|
353
|
+
getAssetCompiler = null,
|
|
354
|
+
compilerProvider = null,
|
|
355
|
+
compilerEndpoint = '',
|
|
356
|
+
events = null,
|
|
357
|
+
version = 'dev',
|
|
358
|
+
idFactory = undefined
|
|
359
|
+
} = {}) {
|
|
360
|
+
if (!artifacts?.registry || !artifacts?.byteStore) {
|
|
361
|
+
throw new AssetProductionError('ASSET_PRODUCTION_INVALID', 'Asset production requires an ArtifactModule boundary');
|
|
362
|
+
}
|
|
363
|
+
const compilerGetter = getAssetCompiler || configureCompiler({
|
|
364
|
+
provider:compilerProvider,
|
|
365
|
+
endpoint:compilerEndpoint,
|
|
366
|
+
events,
|
|
367
|
+
version
|
|
368
|
+
});
|
|
369
|
+
producer = createAssetProducer({
|
|
370
|
+
artifactRegistry:artifacts.registry,
|
|
371
|
+
byteStore:artifacts.byteStore,
|
|
372
|
+
getAssetCompiler:compilerGetter,
|
|
373
|
+
assetRegistry:registry,
|
|
374
|
+
onManifestRegistered:persistManifest,
|
|
375
|
+
events,
|
|
376
|
+
now,
|
|
377
|
+
...(idFactory ? { idFactory } : {})
|
|
378
|
+
});
|
|
379
|
+
return module;
|
|
380
|
+
},
|
|
381
|
+
|
|
382
|
+
setCompilerEndpoint(endpoint = '') {
|
|
383
|
+
configuredCompilerProvider?.setEndpoint?.(String(endpoint || '').trim());
|
|
384
|
+
return module;
|
|
385
|
+
},
|
|
386
|
+
|
|
387
|
+
async produceAsset(request = {}) {
|
|
388
|
+
if (!producer) {
|
|
389
|
+
throw new AssetProductionError(
|
|
390
|
+
'ASSET_PRODUCTION_NOT_CONFIGURED',
|
|
391
|
+
'Asset production requires composition-time compiler configuration'
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
return producer(request);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
return module;
|
|
399
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# 资产(Asset)
|
|
2
|
+
|
|
3
|
+
## v2 声明式输入
|
|
4
|
+
|
|
5
|
+
`importRecipe(json)` 接收严格的 Asset Recipe v1:最多 64 个节点、4 层分组、box/sphere/cylinder、有限变换和标准材质。默认只请求 Visual;Physical/Interactive 必须显式声明物理与行为,声明经过现有 AssetCompiler 和 admission,不替代真实动作验证。复杂关节和高级源码继续走既有隔离构建入口。
|
|
6
|
+
|
|
7
|
+
`importGLB({bytes, level:'visual'})` 在加载前检查自包含 GLB,拒绝外部资源 URI、过多节点和非法层级,再执行现有编译器的几何与资源预算检查。该路径不依赖 Docker。请求 Physical 时明确拒绝,不推断碰撞或降级。Visual Manifest 无 physics/actions,WorldRuntime 不为其创建物理实体。
|
|
8
|
+
|
|
9
|
+
返回 `asset://sha256/<摘要>`、Manifest 和 admission。Recipe 摘要包含规范化定义与编译版本;修改定义产生新资产,已有实例不自动升级。`AssetInputContracts.js` 同时定义严格 Asset Package v1 数据结构,完整包依赖与跨设备迁移由保存阶段验收。
|
|
10
|
+
|
|
11
|
+
`modules/asset` 负责把"已验证的 Artifact"变成 AgentScape Asset,并在之后把 Asset 实例化为 World 运行时对象。入口:`AssetModule.js`。
|
|
12
|
+
|
|
13
|
+
它不调度生成任务,也不拥有 World 实例状态。
|
|
14
|
+
|
|
15
|
+
## 结构
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
asset/
|
|
19
|
+
├─ AssetModule.js composition root
|
|
20
|
+
├─ model/ Asset 定义与有效性
|
|
21
|
+
├─ production/ Artifact → Asset 生产
|
|
22
|
+
├─ registry/ 已知 Asset 元数据与查询
|
|
23
|
+
├─ loading/ Asset → 运行时对象
|
|
24
|
+
└─ persistence/ 持久化本地 Asset 状态
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 边界
|
|
28
|
+
|
|
29
|
+
- `model/`:`AssetRef`、schema、parts、admission、资源预算、Asset 错误。无外部 I/O。
|
|
30
|
+
- `production/`:`AssetProductionPipeline`、compiler、compiler passes/providers、外部 payload adapters。这是唯一的 Artifact → Asset 路径。
|
|
31
|
+
- `registry/`:`AssetRegistry` 是 manifest 身份/注册真相;`AssetCatalog` 是其搜索/读取视图;内置 manifests 在此。
|
|
32
|
+
- `loading/`:`AssetLoader` 把已注册 Asset 解析为 Three.js 运行时对象;`GltfAssetLoader` 与内置 factories 是加载细节。
|
|
33
|
+
- `persistence/`:编译后的字节、持久化 manifests、以及用户批准的 `LocalAssetLibrary`。
|
|
34
|
+
|
|
35
|
+
## 生命周期
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
Artifact
|
|
39
|
+
↓
|
|
40
|
+
production
|
|
41
|
+
↓
|
|
42
|
+
model validation / admission
|
|
43
|
+
↓
|
|
44
|
+
registry
|
|
45
|
+
├─→ persistence
|
|
46
|
+
↓
|
|
47
|
+
loading
|
|
48
|
+
↓
|
|
49
|
+
World Object
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`AssetModule` 是 composition root,拥有 `AssetRegistry`、`AssetLoader`、persistence stores 与 Asset 生产配置。重型几何服务仍在 `services/asset-compiler`。
|
|
53
|
+
|
|
54
|
+
验证:`npm run test:asset`、`npm run assets:validate`、`npm run architecture:validate`。
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { GltfAssetLoader } from './GltfAssetLoader.js';
|
|
2
|
+
import { Errors } from '../model/errors.js';
|
|
3
|
+
import { disposeObject3D, RELEASE_RESOURCE } from '../../rendering/disposeObject3D.js';
|
|
4
|
+
import { clone as cloneSkeleton } from 'three/examples/jsm/utils/SkeletonUtils.js';
|
|
5
|
+
import { builtinAssetFactories } from './builtins/BuiltinAssets.js';
|
|
6
|
+
|
|
7
|
+
export class AssetLoader {
|
|
8
|
+
constructor({ registry, compiledStore = null, gltfLoader = new GltfAssetLoader(), factories = builtinAssetFactories, maxResidentBytes = 256 * 1024 * 1024 } = {}) {
|
|
9
|
+
if (!registry?.getManifest || !registry?.has) throw new TypeError('AssetLoader requires an AssetRegistry');
|
|
10
|
+
if (!gltfLoader || typeof gltfLoader.loadScene !== 'function') throw new TypeError('AssetLoader requires a glTF asset loader');
|
|
11
|
+
this.registry = registry;
|
|
12
|
+
this.compiledStore = compiledStore;
|
|
13
|
+
this.gltfLoader = gltfLoader;
|
|
14
|
+
this.factories = new Map(Object.entries(factories || {}));
|
|
15
|
+
this.shared = new Map();
|
|
16
|
+
this.residentBytes = 0;
|
|
17
|
+
this.maxResidentBytes = maxResidentBytes;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
registerFactory(assetId, factory) {
|
|
21
|
+
if (typeof factory !== 'function') throw new TypeError(`Asset factory for ${assetId} must be a function`);
|
|
22
|
+
this.factories.set(assetId, factory);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
configureRenderer(renderer) {
|
|
26
|
+
return this.gltfLoader.configureRenderer?.(renderer) ?? false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async instantiate(assetId, { signal } = {}) {
|
|
30
|
+
const manifest = this.registry.getManifest(assetId);
|
|
31
|
+
let object;
|
|
32
|
+
if (['glb', 'compiled'].includes(manifest.source?.kind)) object = await this.instantiateShared(manifest, signal);
|
|
33
|
+
else {
|
|
34
|
+
const factory = this.factories.get(assetId);
|
|
35
|
+
if (!factory) throw Errors.assetNotFound(assetId);
|
|
36
|
+
object = await factory();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
this.validateNodes(object, manifest);
|
|
41
|
+
object.name ||= assetId;
|
|
42
|
+
object.userData.assetId = assetId;
|
|
43
|
+
object.userData.manifest = manifest;
|
|
44
|
+
return { object, manifest };
|
|
45
|
+
} catch (error) {
|
|
46
|
+
disposeObject3D(object);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
stats() {
|
|
52
|
+
return { resources: this.shared.size, references: [...this.shared.values()].reduce((sum, entry) => sum + entry.users, 0),
|
|
53
|
+
estimatedResidentBytes: this.residentBytes, maxResidentBytes: this.maxResidentBytes };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async instantiateShared(manifest, signal) {
|
|
57
|
+
if (signal?.aborted) throw Object.assign(new Error('ASSET_CANCELLED'), { code: 'ASSET_CANCELLED' });
|
|
58
|
+
const source = manifest.source;
|
|
59
|
+
const key = source.kind === 'compiled' ? `compiled:${source.key}` : `glb:${source.url}`;
|
|
60
|
+
let entry = this.shared.get(key);
|
|
61
|
+
if (!entry) {
|
|
62
|
+
entry = { users: 0, bytes: 0, root: null, promise: null };
|
|
63
|
+
this.shared.set(key, entry);
|
|
64
|
+
entry.promise = (async () => {
|
|
65
|
+
const root = source.kind === 'compiled' ? await this.loadCompiled(source) : await this.loadGLB(source.url);
|
|
66
|
+
const bytes = estimateResourceBytes(root);
|
|
67
|
+
if (this.residentBytes + bytes > this.maxResidentBytes) {
|
|
68
|
+
disposeObject3D(root); throw Object.assign(new Error('ASSET_RESIDENT_BUDGET'), { code: 'ASSET_RESIDENT_BUDGET' });
|
|
69
|
+
}
|
|
70
|
+
entry.root = root; entry.bytes = bytes; this.residentBytes += bytes;
|
|
71
|
+
return root;
|
|
72
|
+
})();
|
|
73
|
+
}
|
|
74
|
+
entry.users++;
|
|
75
|
+
const release = () => {
|
|
76
|
+
entry.users--;
|
|
77
|
+
if (!entry.users) {
|
|
78
|
+
this.shared.delete(key);
|
|
79
|
+
this.residentBytes -= entry.bytes;
|
|
80
|
+
if (entry.root) disposeObject3D(entry.root);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
const root = await entry.promise;
|
|
85
|
+
if (signal?.aborted) throw Object.assign(new Error('ASSET_CANCELLED'), { code: 'ASSET_CANCELLED' });
|
|
86
|
+
this.validateNodes(root, manifest);
|
|
87
|
+
const object = cloneSkeleton(root), materials = new Map();
|
|
88
|
+
object.traverse(node => {
|
|
89
|
+
if (!node.material) return;
|
|
90
|
+
const copy = material => { if (!materials.has(material)) materials.set(material, material.clone()); return materials.get(material); };
|
|
91
|
+
node.material = Array.isArray(node.material) ? node.material.map(copy) : copy(node.material);
|
|
92
|
+
});
|
|
93
|
+
let released = false;
|
|
94
|
+
object[RELEASE_RESOURCE] = () => {
|
|
95
|
+
if (!released) { released = true; for (const material of materials.values()) material.dispose(); release(); }
|
|
96
|
+
return { geometries: 0, materials: materials.size, textures: 0 };
|
|
97
|
+
};
|
|
98
|
+
return object;
|
|
99
|
+
} catch (error) { release(); throw error; }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
validateNodes(object, manifest) {
|
|
103
|
+
const missing = (manifest.requiredNodes || []).filter((name) => !object.getObjectByName(name));
|
|
104
|
+
if (missing.length) {
|
|
105
|
+
throw Errors.invalidManifest(
|
|
106
|
+
`Asset ${manifest.id} is missing required GLB nodes: ${missing.join(', ')}`,
|
|
107
|
+
{ id:manifest.id, missing }
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async loadCompiled(source) {
|
|
113
|
+
const stored = await this.compiledStore?.get(source.key);
|
|
114
|
+
if (!stored?.bytes) {
|
|
115
|
+
if (source.fallbackUrl) return this.loadGLB(source.fallbackUrl);
|
|
116
|
+
throw new Error(`Compiled asset binary missing: ${source.key}`);
|
|
117
|
+
}
|
|
118
|
+
if (this.gltfLoader.loadBytes) {
|
|
119
|
+
const object = await this.gltfLoader.loadBytes(stored.bytes);
|
|
120
|
+
object.traverse(node => { if (node.isMesh) { node.castShadow = true; node.receiveShadow = true; } });
|
|
121
|
+
return object;
|
|
122
|
+
}
|
|
123
|
+
const blob = new Blob([stored.bytes], { type:'model/gltf-binary' });
|
|
124
|
+
const url = URL.createObjectURL(blob);
|
|
125
|
+
try {
|
|
126
|
+
return await this.loadGLB(url);
|
|
127
|
+
} finally {
|
|
128
|
+
URL.revokeObjectURL(url);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async loadGLB(url) {
|
|
133
|
+
const scene = await this.gltfLoader.loadScene(url);
|
|
134
|
+
scene.traverse((node) => {
|
|
135
|
+
if (!node.isMesh) return;
|
|
136
|
+
node.castShadow = true;
|
|
137
|
+
node.receiveShadow = true;
|
|
138
|
+
});
|
|
139
|
+
return scene;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function estimateResourceBytes(root) {
|
|
144
|
+
const buffers = new Set(), textures = new Set(); let total = 0;
|
|
145
|
+
root.traverse(node => {
|
|
146
|
+
for (const attribute of [...Object.values(node.geometry?.attributes || {}), node.geometry?.index].filter(Boolean)) {
|
|
147
|
+
const buffer = attribute.array?.buffer || attribute.data?.array?.buffer;
|
|
148
|
+
if (buffer && !buffers.has(buffer)) { buffers.add(buffer); total += buffer.byteLength; }
|
|
149
|
+
}
|
|
150
|
+
for (const material of (Array.isArray(node.material) ? node.material : [node.material]).filter(Boolean)) {
|
|
151
|
+
for (const value of Object.values(material)) if (value?.isTexture && !textures.has(value)) {
|
|
152
|
+
textures.add(value); total += (value.image?.width || 0) * (value.image?.height || 0) * 4;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return total;
|
|
157
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
2
|
+
import { KTX2Loader } from 'three/examples/jsm/loaders/KTX2Loader.js';
|
|
3
|
+
import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js';
|
|
4
|
+
import { assertEmbeddedGLB } from '../model/AssetInputContracts.js';
|
|
5
|
+
|
|
6
|
+
export class GltfAssetLoader {
|
|
7
|
+
constructor({
|
|
8
|
+
loader = new GLTFLoader(),
|
|
9
|
+
meshoptDecoder = MeshoptDecoder,
|
|
10
|
+
ktx2TranscoderPath = '/basis/',
|
|
11
|
+
ktx2LoaderFactory = () => new KTX2Loader()
|
|
12
|
+
} = {}) {
|
|
13
|
+
if (!loader || typeof loader.loadAsync !== 'function') {
|
|
14
|
+
throw new TypeError('GltfAssetLoader requires a GLTF-compatible loader');
|
|
15
|
+
}
|
|
16
|
+
if (typeof ktx2LoaderFactory !== 'function') throw new TypeError('GltfAssetLoader ktx2LoaderFactory must be a function');
|
|
17
|
+
this.loader = loader;
|
|
18
|
+
this.ktx2TranscoderPath = ktx2TranscoderPath;
|
|
19
|
+
this.ktx2LoaderFactory = ktx2LoaderFactory;
|
|
20
|
+
this.ktx2Loader = null;
|
|
21
|
+
this.loader.setMeshoptDecoder?.(meshoptDecoder);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
configureRenderer(renderer) {
|
|
26
|
+
if (!renderer) throw new TypeError('GltfAssetLoader.configureRenderer requires a renderer');
|
|
27
|
+
if (typeof this.loader.setKTX2Loader !== 'function' || !this.ktx2TranscoderPath) return false;
|
|
28
|
+
this.ktx2Loader?.dispose?.();
|
|
29
|
+
this.ktx2Loader = this.ktx2LoaderFactory()
|
|
30
|
+
.setTranscoderPath(this.ktx2TranscoderPath)
|
|
31
|
+
.detectSupport(renderer);
|
|
32
|
+
this.loader.setKTX2Loader(this.ktx2Loader);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async load(url) {
|
|
37
|
+
const gltf = await this.loader.loadAsync(url);
|
|
38
|
+
if (!gltf?.scene) throw new Error(`GLTF has no default scene: ${url}`);
|
|
39
|
+
return gltf;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async loadScene(url) {
|
|
43
|
+
const gltf = await this.load(url);
|
|
44
|
+
gltf.scene.animations = [...(gltf.animations || [])];
|
|
45
|
+
return gltf.scene;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async loadBytes(bytes) {
|
|
49
|
+
if (!globalThis.document && !globalThis.createImageBitmap && assertEmbeddedGLB(bytes).images?.length) throw Object.assign(new Error('Headless texture decoder unavailable'), { code: 'HEADLESS_TEXTURE_DECODER_UNAVAILABLE' });
|
|
50
|
+
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
51
|
+
const gltf = await this.loader.parseAsync(buffer, '');
|
|
52
|
+
if (!gltf?.scene) throw new Error('GLTF has no default scene');
|
|
53
|
+
gltf.scene.animations = [...(gltf.animations || [])];
|
|
54
|
+
return gltf.scene;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
dispose() {
|
|
58
|
+
this.ktx2Loader?.dispose?.();
|
|
59
|
+
this.ktx2Loader = null;
|
|
60
|
+
}
|
|
61
|
+
}
|