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.
Files changed (396) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/cli.mjs +53 -0
  4. package/dist/AssetCompiler-A99wKf7H.js +2424 -0
  5. package/dist/AssetCompiler-A99wKf7H.js.map +1 -0
  6. package/dist/AssetInputContracts-uKYeQu-X.js +245 -0
  7. package/dist/AssetInputContracts-uKYeQu-X.js.map +1 -0
  8. package/dist/AssetRecipe-DCaLLXvG.js +67 -0
  9. package/dist/AssetRecipe-DCaLLXvG.js.map +1 -0
  10. package/dist/BrowserCodeWorker.js +53850 -0
  11. package/dist/BrowserCodeWorker.js.map +1 -0
  12. package/dist/KinematicHypothesisScreen-4v7GBwdv.js +241 -0
  13. package/dist/KinematicHypothesisScreen-4v7GBwdv.js.map +1 -0
  14. package/dist/SceneSerializer-CLCzQjL_.js +350 -0
  15. package/dist/SceneSerializer-CLCzQjL_.js.map +1 -0
  16. package/dist/StylePack-CD_BC-Mv.js +6317 -0
  17. package/dist/StylePack-CD_BC-Mv.js.map +1 -0
  18. package/dist/WorldArchive-dYf1OpSe.js +417 -0
  19. package/dist/WorldArchive-dYf1OpSe.js.map +1 -0
  20. package/dist/WorldIO-Dqz4MqTQ.js +149 -0
  21. package/dist/WorldIO-Dqz4MqTQ.js.map +1 -0
  22. package/dist/blankWorld-OoOvN_IK.js +75 -0
  23. package/dist/blankWorld-OoOvN_IK.js.map +1 -0
  24. package/dist/core.d.ts +68 -0
  25. package/dist/core.js +209 -0
  26. package/dist/core.js.map +1 -0
  27. package/dist/disposeObject3D-B3HCflvO.js +128 -0
  28. package/dist/disposeObject3D-B3HCflvO.js.map +1 -0
  29. package/dist/environments-B1WaICAN.js +4197 -0
  30. package/dist/environments-B1WaICAN.js.map +1 -0
  31. package/dist/gltfIO-BMK1hc2D.js +9 -0
  32. package/dist/gltfIO-BMK1hc2D.js.map +1 -0
  33. package/dist/grandUrbanBlock-Bdjgc6ZT.js +515 -0
  34. package/dist/grandUrbanBlock-Bdjgc6ZT.js.map +1 -0
  35. package/dist/index.d.ts +275 -0
  36. package/dist/index.js +16239 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/magicCabin-DPQi_jh-.js +11019 -0
  39. package/dist/magicCabin-DPQi_jh-.js.map +1 -0
  40. package/dist/mcp.d.ts +2 -0
  41. package/dist/mcp.js +1 -0
  42. package/dist/monumentHall-IOLbRZQC.js +403 -0
  43. package/dist/monumentHall-IOLbRZQC.js.map +1 -0
  44. package/dist/node.d.ts +16 -0
  45. package/dist/node.js +26 -0
  46. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  47. package/dist/ruinedCourtyard-BtaF_aOi.js +696 -0
  48. package/dist/ruinedCourtyard-BtaF_aOi.js.map +1 -0
  49. package/dist/runtime/application/AgentTools.js +28 -0
  50. package/dist/runtime/application/README.md +14 -0
  51. package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
  52. package/dist/runtime/application/agent/StudioMcpAllowlist.js +8 -0
  53. package/dist/runtime/application/buildTaskObservation.js +117 -0
  54. package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +46 -0
  55. package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
  56. package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
  57. package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +72 -0
  58. package/dist/runtime/application/createSession.js +66 -0
  59. package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
  60. package/dist/runtime/application/generation/GenerationOrchestrator.js +629 -0
  61. package/dist/runtime/application/generation/GenerationRuntime.js +214 -0
  62. package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +285 -0
  63. package/dist/runtime/application/native-scene/CodeProject.js +119 -0
  64. package/dist/runtime/application/native-scene/CodeProjectModules.js +128 -0
  65. package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +62 -0
  66. package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
  67. package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
  68. package/dist/runtime/application/native-scene/NativeSceneHost.js +319 -0
  69. package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
  70. package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
  71. package/dist/runtime/application/object-forge/SceneObjectForge.js +232 -0
  72. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
  73. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
  74. package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
  75. package/dist/runtime/application/scene/CapabilityResolver.js +79 -0
  76. package/dist/runtime/application/scene/RequestWindow.js +54 -0
  77. package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
  78. package/dist/runtime/application/scene/SceneContracts.js +45 -0
  79. package/dist/runtime/application/scene/SceneEditService.js +144 -0
  80. package/dist/runtime/application/scene/SceneFacade.js +261 -0
  81. package/dist/runtime/application/scene/SceneInteractionAdapters.js +40 -0
  82. package/dist/runtime/application/scene/SceneJobController.js +229 -0
  83. package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
  84. package/dist/runtime/application/scene/ScenePackage.js +162 -0
  85. package/dist/runtime/application/scene/ScenePersistence.js +50 -0
  86. package/dist/runtime/application/scene/SceneProject.js +95 -0
  87. package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
  88. package/dist/runtime/application/scene/StarterScene.js +56 -0
  89. package/dist/runtime/application/scene/WorldArchive.js +87 -0
  90. package/dist/runtime/application/scene/WorldDirectory.js +20 -0
  91. package/dist/runtime/application/scene/WorldDocument.js +74 -0
  92. package/dist/runtime/application/scene/WorldIO.js +103 -0
  93. package/dist/runtime/application/scene/WorldStorage.js +137 -0
  94. package/dist/runtime/application/skills/SkillRegistry.js +189 -0
  95. package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
  96. package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
  97. package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
  98. package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
  99. package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
  100. package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
  101. package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
  102. package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
  103. package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
  104. package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
  105. package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
  106. package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
  107. package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
  108. package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
  109. package/dist/runtime/application/skills/skillPrimitives.js +4 -0
  110. package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
  111. package/dist/runtime/application/tasks.jsonl +67 -0
  112. package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
  113. package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
  114. package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
  115. package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
  116. package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
  117. package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
  118. package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
  119. package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
  120. package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
  121. package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
  122. package/dist/runtime/application/world-authoring/HeadlessImageExport.js +174 -0
  123. package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
  124. package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
  125. package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +77 -0
  126. package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
  127. package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
  128. package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
  129. package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
  130. package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
  131. package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
  132. package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
  133. package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
  134. package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
  135. package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +132 -0
  136. package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
  137. package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
  138. package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
  139. package/dist/runtime/apps/mcp-server/README.md +150 -0
  140. package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
  141. package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
  142. package/dist/runtime/apps/mcp-server/SessionManager.js +80 -0
  143. package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +58 -0
  144. package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +190 -0
  145. package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
  146. package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
  147. package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
  148. package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
  149. package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
  150. package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
  151. package/dist/runtime/apps/mcp-server/main.mjs +65 -0
  152. package/dist/runtime/apps/mcp-server/registerTools.js +225 -0
  153. package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
  154. package/dist/runtime/apps/mcp-server/security.js +21 -0
  155. package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
  156. package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
  157. package/dist/runtime/apps/server/README.md +7 -0
  158. package/dist/runtime/apps/server/WorldDiskStorage.js +51 -0
  159. package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
  160. package/dist/runtime/apps/server/tasks.jsonl +10 -0
  161. package/dist/runtime/foundation/EventBus.js +18 -0
  162. package/dist/runtime/foundation/JsonGateway.js +47 -0
  163. package/dist/runtime/foundation/PolicyEngine.js +21 -0
  164. package/dist/runtime/foundation/README.md +7 -0
  165. package/dist/runtime/foundation/TraceRecorder.js +76 -0
  166. package/dist/runtime/foundation/errors.js +8 -0
  167. package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
  168. package/dist/runtime/foundation/version.js +2 -0
  169. package/dist/runtime/modules/agent/README.md +11 -0
  170. package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
  171. package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
  172. package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
  173. package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
  174. package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
  175. package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
  176. package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
  177. package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
  178. package/dist/runtime/modules/agent/prompt/index.js +52 -0
  179. package/dist/runtime/modules/agent/tasks.jsonl +94 -0
  180. package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
  181. package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
  182. package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
  183. package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
  184. package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
  185. package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
  186. package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
  187. package/dist/runtime/modules/artifact/README.md +7 -0
  188. package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
  189. package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
  190. package/dist/runtime/modules/asset/AssetModule.js +399 -0
  191. package/dist/runtime/modules/asset/README.md +54 -0
  192. package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
  193. package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
  194. package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
  195. package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
  196. package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
  197. package/dist/runtime/modules/asset/model/AssetInputContracts.js +100 -0
  198. package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
  199. package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
  200. package/dist/runtime/modules/asset/model/admission.js +117 -0
  201. package/dist/runtime/modules/asset/model/errors.js +6 -0
  202. package/dist/runtime/modules/asset/model/parts.js +27 -0
  203. package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
  204. package/dist/runtime/modules/asset/model/schema.js +150 -0
  205. package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
  206. package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
  207. package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
  208. package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
  209. package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
  210. package/dist/runtime/modules/asset/production/AssetRecipe.js +47 -0
  211. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
  212. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
  213. package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
  214. package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
  215. package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
  216. package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
  217. package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
  218. package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
  219. package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
  220. package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
  221. package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
  222. package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
  223. package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
  224. package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
  225. package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
  226. package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
  227. package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
  228. package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
  229. package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
  230. package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
  231. package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
  232. package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
  233. package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
  234. package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
  235. package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
  236. package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
  237. package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
  238. package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
  239. package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
  240. package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
  241. package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
  242. package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
  243. package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
  244. package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
  245. package/dist/runtime/modules/asset/tasks.jsonl +87 -0
  246. package/dist/runtime/modules/generation/README.md +9 -0
  247. package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
  248. package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
  249. package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
  250. package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
  251. package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
  252. package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
  253. package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
  254. package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
  255. package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
  256. package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
  257. package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
  258. package/dist/runtime/modules/generation/tasks.jsonl +35 -0
  259. package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
  260. package/dist/runtime/modules/navigation/RecastNavigationBackend.js +245 -0
  261. package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
  262. package/dist/runtime/modules/physics/PhysicsApiSurface.js +651 -0
  263. package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
  264. package/dist/runtime/modules/physics/RapierPhysicsBackend.js +410 -0
  265. package/dist/runtime/modules/rendering/README.md +7 -0
  266. package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
  267. package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
  268. package/dist/runtime/modules/rendering/createRenderer.js +76 -0
  269. package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
  270. package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
  271. package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
  272. package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
  273. package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
  274. package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
  275. package/dist/runtime/modules/world/README.md +13 -0
  276. package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
  277. package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
  278. package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
  279. package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
  280. package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
  281. package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
  282. package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
  283. package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
  284. package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
  285. package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
  286. package/dist/runtime/modules/world/content/blankWorld.js +35 -0
  287. package/dist/runtime/modules/world/content/environments.js +84 -0
  288. package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
  289. package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
  290. package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
  291. package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
  292. package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
  293. package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
  294. package/dist/runtime/modules/world/content/magicCabin.js +190 -0
  295. package/dist/runtime/modules/world/content/monumentHall.js +154 -0
  296. package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
  297. package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
  298. package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
  299. package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
  300. package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
  301. package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
  302. package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
  303. package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
  304. package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
  305. package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
  306. package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
  307. package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
  308. package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
  309. package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
  310. package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
  311. package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
  312. package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
  313. package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
  314. package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
  315. package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
  316. package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
  317. package/dist/runtime/modules/world/errors.js +9 -0
  318. package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
  319. package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
  320. package/dist/runtime/modules/world/runtime/CommandHistory.js +80 -0
  321. package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +150 -0
  322. package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
  323. package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
  324. package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
  325. package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +207 -0
  326. package/dist/runtime/modules/world/runtime/SceneSerializer.js +246 -0
  327. package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
  328. package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
  329. package/dist/runtime/modules/world/runtime/WorldCommands.js +502 -0
  330. package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
  331. package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
  332. package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
  333. package/dist/runtime/modules/world/runtime/WorldRuntime.js +665 -0
  334. package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +107 -0
  335. package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
  336. package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
  337. package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
  338. package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
  339. package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
  340. package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +305 -0
  341. package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
  342. package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
  343. package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +222 -0
  344. package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +130 -0
  345. package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
  346. package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
  347. package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +120 -0
  348. package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +102 -0
  349. package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
  350. package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +99 -0
  351. package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
  352. package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
  353. package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +125 -0
  354. package/dist/runtime/modules/world/runtime/systems/Instrument.js +38 -0
  355. package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +728 -0
  356. package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +269 -0
  357. package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +469 -0
  358. package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1673 -0
  359. package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +457 -0
  360. package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +284 -0
  361. package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
  362. package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
  363. package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
  364. package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
  365. package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
  366. package/dist/runtime/modules/world/tasks.jsonl +530 -0
  367. package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
  368. package/dist/runtime/modules/world/verification/Finding.js +105 -0
  369. package/dist/runtime/modules/world/verification/InteractionEvidence.js +69 -0
  370. package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
  371. package/dist/runtime/modules/world/verification/WorldAcceptance.js +158 -0
  372. package/dist/runtime/modules/world/verification/WorldValidator.js +65 -0
  373. package/dist/runtime/package-lock.json +16048 -0
  374. package/dist/runtime/package.json +105 -0
  375. package/dist/runtime/public/assets/cabinet.glb +0 -0
  376. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
  377. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
  378. package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
  379. package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
  380. package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
  381. package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
  382. package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
  383. package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
  384. package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
  385. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
  386. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
  387. package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
  388. package/dist/schema-BWpTl0Wj.js +359 -0
  389. package/dist/schema-BWpTl0Wj.js.map +1 -0
  390. package/dist/suzhouGarden-H9tiPgxq.js +6150 -0
  391. package/dist/suzhouGarden-H9tiPgxq.js.map +1 -0
  392. package/dist/woodlandWorkshop-D6zzSbHr.js +483 -0
  393. package/dist/woodlandWorkshop-D6zzSbHr.js.map +1 -0
  394. package/dist/yuanmingyuan-D6IHqjZ-.js +4955 -0
  395. package/dist/yuanmingyuan-D6IHqjZ-.js.map +1 -0
  396. package/package.json +70 -4
@@ -0,0 +1,825 @@
1
+ import * as THREE from 'three';
2
+ import { cloneAuthoringModelRef, getAuthoringModelRef, markAuthoringModelRef } from './ModelRef.js';
3
+ import { getAuthoringObjectId, setAuthoringObjectId } from './AuthoringIdentity.js';
4
+
5
+ export const AUTHORING_FORMAT = 'agentscape-world-authoring';
6
+ export const AUTHORING_VERSION = 1;
7
+
8
+ const ROOT_ID = 'root';
9
+ const RESERVED_USER_DATA = new Set([
10
+ 'authoringId',
11
+ 'authoringGeometryId',
12
+ 'authoringMaterialId',
13
+ 'authoringTextureId',
14
+ 'authoringSource',
15
+ 'authoringModelRef',
16
+ 'instanceId',
17
+ 'visualDecoration',
18
+ 'visualDecorationRoot',
19
+ 'worldAuthoringRoot'
20
+ ]);
21
+
22
+ const PRIMITIVE_GEOMETRIES = new Set([
23
+ 'BoxGeometry',
24
+ 'SphereGeometry',
25
+ 'PlaneGeometry',
26
+ 'CylinderGeometry',
27
+ 'ConeGeometry',
28
+ 'TorusGeometry'
29
+ ]);
30
+
31
+ const MATERIAL_TYPES = new Set([
32
+ 'MeshBasicMaterial',
33
+ 'MeshStandardMaterial',
34
+ 'MeshPhysicalMaterial'
35
+ ]);
36
+
37
+ const TEXTURE_SLOTS = [
38
+ 'map',
39
+ 'normalMap',
40
+ 'roughnessMap',
41
+ 'metalnessMap',
42
+ 'emissiveMap',
43
+ 'alphaMap',
44
+ 'aoMap'
45
+ ];
46
+
47
+ const geometryIdsByObject = new WeakMap();
48
+ const materialIdsByObject = new WeakMap();
49
+ const textureIdsByObject = new WeakMap();
50
+ const textureSourcesByObject = new WeakMap();
51
+
52
+ function makeId(prefix) {
53
+ return `${prefix}_${THREE.MathUtils.generateUUID().toLowerCase()}`;
54
+ }
55
+
56
+ function structuredCloneJson(value) {
57
+ return JSON.parse(JSON.stringify(value));
58
+ }
59
+
60
+ function ensureObjectId(object, usedIds, isRoot = false) {
61
+ let id = isRoot ? ROOT_ID : getAuthoringObjectId(object);
62
+ if (
63
+ typeof id !== 'string'
64
+ || !id.trim()
65
+ || (usedIds.has(id) && usedIds.get(id) !== object)
66
+ ) {
67
+ id = isRoot ? ROOT_ID : makeId('node');
68
+ }
69
+ setAuthoringObjectId(object, id);
70
+ usedIds.set(id, object);
71
+ return id;
72
+ }
73
+
74
+ function ensureResourceId(resource, legacyKey, prefix, usedIds, sidecar) {
75
+ let id = sidecar.get(resource) || resource.userData?.[legacyKey];
76
+ if (
77
+ typeof id !== 'string'
78
+ || !id.trim()
79
+ || (usedIds.has(id) && usedIds.get(id) !== resource)
80
+ ) {
81
+ id = makeId(prefix);
82
+ }
83
+ sidecar.set(resource, id);
84
+ usedIds.set(id, resource);
85
+ return id;
86
+ }
87
+
88
+ function toJsonValue(value, seen = new WeakSet()) {
89
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') return value;
90
+ if (typeof value === 'number') return Number.isFinite(value) ? value : undefined;
91
+ if (Array.isArray(value)) {
92
+ if (seen.has(value)) return undefined;
93
+ seen.add(value);
94
+ const result = value.map(item => toJsonValue(item, seen)).filter(item => item !== undefined);
95
+ seen.delete(value);
96
+ return result;
97
+ }
98
+ if (typeof value !== 'object' || value?.isObject3D || value?.isMaterial || value?.isTexture) return undefined;
99
+ if (seen.has(value)) return undefined;
100
+ seen.add(value);
101
+ const result = {};
102
+ for (const [key, entry] of Object.entries(value)) {
103
+ if (RESERVED_USER_DATA.has(key)) continue;
104
+ const converted = toJsonValue(entry, seen);
105
+ if (converted !== undefined) result[key] = converted;
106
+ }
107
+ seen.delete(value);
108
+ return result;
109
+ }
110
+
111
+ function captureMetadata(object) {
112
+ const metadata = toJsonValue(object.userData);
113
+ return metadata && Object.keys(metadata).length > 0 ? metadata : undefined;
114
+ }
115
+
116
+ function transformComponent(object) {
117
+ return {
118
+ type: 'Transform',
119
+ properties: {
120
+ position: object.position.toArray(),
121
+ quaternion: object.quaternion.toArray(),
122
+ scale: object.scale.toArray()
123
+ }
124
+ };
125
+ }
126
+
127
+ function geometryDefinition(geometry) {
128
+ if (PRIMITIVE_GEOMETRIES.has(geometry.type) && geometry.parameters) {
129
+ return {
130
+ type: geometry.type,
131
+ parameters: structuredCloneJson(geometry.parameters)
132
+ };
133
+ }
134
+
135
+ const json = geometry.toJSON();
136
+ delete json.metadata;
137
+ delete json.uuid;
138
+ delete json.userData;
139
+ return {
140
+ type: 'BufferGeometry',
141
+ sourceType: geometry.type,
142
+ json
143
+ };
144
+ }
145
+
146
+ function textureSource(texture) {
147
+ const explicit = textureSourcesByObject.get(texture) || texture.userData?.authoringSource;
148
+ if (explicit && typeof explicit === 'object') {
149
+ const source = toJsonValue(explicit);
150
+ if (source?.type === 'url' && typeof source.uri === 'string' && source.uri) return source;
151
+ }
152
+
153
+ const image = texture.image;
154
+ const uri = image?.currentSrc || image?.src;
155
+ if (typeof uri === 'string' && uri) return { type: 'url', uri };
156
+
157
+ if (image?.data && Number.isFinite(image.width) && Number.isFinite(image.height)) {
158
+ const data = Array.from(image.data);
159
+ return {
160
+ type: 'data',
161
+ width: image.width,
162
+ height: image.height,
163
+ dataType: image.data.constructor?.name || 'Uint8Array',
164
+ data
165
+ };
166
+ }
167
+
168
+ throw new TypeError('World Authoring texture requires a URL or DataTexture source');
169
+ }
170
+
171
+ function textureDefinition(texture) {
172
+ return {
173
+ source: textureSource(texture),
174
+ mapping: texture.mapping,
175
+ wrapS: texture.wrapS,
176
+ wrapT: texture.wrapT,
177
+ magFilter: texture.magFilter,
178
+ minFilter: texture.minFilter,
179
+ anisotropy: texture.anisotropy,
180
+ format: texture.format,
181
+ type: texture.type,
182
+ colorSpace: texture.colorSpace,
183
+ flipY: texture.flipY,
184
+ premultiplyAlpha: texture.premultiplyAlpha,
185
+ generateMipmaps: texture.generateMipmaps,
186
+ offset: texture.offset.toArray(),
187
+ repeat: texture.repeat.toArray(),
188
+ center: texture.center.toArray(),
189
+ rotation: texture.rotation
190
+ };
191
+ }
192
+
193
+ function captureMaterial(
194
+ material,
195
+ textureIds,
196
+ textures
197
+ ) {
198
+ if (!MATERIAL_TYPES.has(material.type)) {
199
+ throw new TypeError(`Unsupported World Authoring material: ${material.type}`);
200
+ }
201
+
202
+ const json = material.toJSON();
203
+ delete json.metadata;
204
+ delete json.uuid;
205
+ delete json.userData;
206
+ delete json.textures;
207
+ delete json.images;
208
+
209
+ for (const slot of TEXTURE_SLOTS) {
210
+ const texture = material[slot];
211
+ if (!texture) {
212
+ delete json[slot];
213
+ continue;
214
+ }
215
+ const textureId = ensureResourceId(texture, 'authoringTextureId', 'tex', textureIds, textureIdsByObject);
216
+ if (!textures[textureId]) textures[textureId] = textureDefinition(texture);
217
+ json[slot] = textureId;
218
+ }
219
+
220
+ return json;
221
+ }
222
+
223
+ function lightComponent(object) {
224
+ if (!(object.isAmbientLight || object.isHemisphereLight || object.isDirectionalLight || object.isPointLight || object.isSpotLight)) return null;
225
+
226
+ const base = {
227
+ color: `#${object.color.getHexString()}`,
228
+ intensity: object.intensity
229
+ };
230
+
231
+ if (object.isAmbientLight) return { type: 'AmbientLight', properties: base };
232
+ if (object.isHemisphereLight) {
233
+ return {
234
+ type: 'HemisphereLight',
235
+ properties: {
236
+ ...base,
237
+ groundColor: `#${object.groundColor.getHexString()}`
238
+ }
239
+ };
240
+ }
241
+ if (object.isDirectionalLight) {
242
+ return {
243
+ type: 'DirectionalLight',
244
+ properties: {
245
+ ...base,
246
+ target: object.target.position.toArray(),
247
+ castShadow: object.castShadow
248
+ }
249
+ };
250
+ }
251
+ if (object.isPointLight) {
252
+ return {
253
+ type: 'PointLight',
254
+ properties: {
255
+ ...base,
256
+ distance: object.distance,
257
+ decay: object.decay,
258
+ castShadow: object.castShadow
259
+ }
260
+ };
261
+ }
262
+ if (object.isSpotLight) {
263
+ return {
264
+ type: 'SpotLight',
265
+ properties: {
266
+ ...base,
267
+ distance: object.distance,
268
+ angle: object.angle,
269
+ penumbra: object.penumbra,
270
+ decay: object.decay,
271
+ target: object.target.position.toArray(),
272
+ castShadow: object.castShadow
273
+ }
274
+ };
275
+ }
276
+ return null;
277
+ }
278
+
279
+ function captureMeshResources(
280
+ object,
281
+ geometryIds,
282
+ materialIds,
283
+ textureIds,
284
+ geometries,
285
+ materials,
286
+ textures
287
+ ) {
288
+ if (Array.isArray(object.material)) {
289
+ throw new TypeError('World Authoring v1 does not persist multi-material Mesh');
290
+ }
291
+
292
+ const geometryId = ensureResourceId(object.geometry, 'authoringGeometryId', 'geo', geometryIds, geometryIdsByObject);
293
+ const materialId = ensureResourceId(object.material, 'authoringMaterialId', 'mat', materialIds, materialIdsByObject);
294
+
295
+ if (!geometries[geometryId]) geometries[geometryId] = geometryDefinition(object.geometry);
296
+ if (!materials[materialId]) {
297
+ materials[materialId] = captureMaterial(object.material, textureIds, textures);
298
+ }
299
+
300
+ return { geometryId, materialId };
301
+ }
302
+
303
+ function captureInstancedMesh(object) {
304
+ const matrices = Array.from(object.instanceMatrix.array);
305
+ const colors = object.instanceColor ? Array.from(object.instanceColor.array) : undefined;
306
+ return {
307
+ type: 'InstancedMesh',
308
+ properties: {
309
+ count: object.count,
310
+ matrices,
311
+ ...(colors ? { colors } : {}),
312
+ castShadow: object.castShadow,
313
+ receiveShadow: object.receiveShadow
314
+ }
315
+ };
316
+ }
317
+
318
+ function sceneComponent(object, textureIds, textures) {
319
+ if (!object.isScene) return null;
320
+ const properties = {};
321
+ if (object.background?.isColor) {
322
+ properties.background = { type:'color', value:`#${object.background.getHexString()}` };
323
+ } else if (object.background?.isTexture) {
324
+ const textureId = ensureResourceId(object.background, 'authoringTextureId', 'tex', textureIds, textureIdsByObject);
325
+ if (!textures[textureId]) textures[textureId] = textureDefinition(object.background);
326
+ properties.background = { type:'texture', textureId };
327
+ }
328
+ if (object.environment?.isTexture) {
329
+ const textureId = ensureResourceId(object.environment, 'authoringTextureId', 'tex', textureIds, textureIdsByObject);
330
+ if (!textures[textureId]) textures[textureId] = textureDefinition(object.environment);
331
+ properties.environment = { textureId };
332
+ }
333
+ if (object.fog?.isFog) {
334
+ properties.fog = { type:'Fog', color:`#${object.fog.color.getHexString()}`, near:object.fog.near, far:object.fog.far };
335
+ } else if (object.fog?.isFogExp2) {
336
+ properties.fog = { type:'FogExp2', color:`#${object.fog.color.getHexString()}`, density:object.fog.density };
337
+ }
338
+ if (Number.isFinite(object.backgroundBlurriness)) properties.backgroundBlurriness = object.backgroundBlurriness;
339
+ if (Number.isFinite(object.backgroundIntensity)) properties.backgroundIntensity = object.backgroundIntensity;
340
+ if (Number.isFinite(object.environmentIntensity)) properties.environmentIntensity = object.environmentIntensity;
341
+ return { type:'Scene', properties };
342
+ }
343
+
344
+ function captureNode(
345
+ object,
346
+ geometryIds,
347
+ materialIds,
348
+ textureIds,
349
+ geometries,
350
+ materials,
351
+ textures
352
+ ) {
353
+ const components = { transform: transformComponent(object) };
354
+
355
+ const modelRef = getAuthoringModelRef(object);
356
+ if (modelRef) {
357
+ components.modelRef = {
358
+ type: 'ModelRef',
359
+ properties: cloneAuthoringModelRef(modelRef)
360
+ };
361
+ } else if (object.isScene) {
362
+ components.scene = sceneComponent(object, textureIds, textures);
363
+ } else if (object.isInstancedMesh) {
364
+ const { geometryId, materialId } = captureMeshResources(
365
+ object,
366
+ geometryIds,
367
+ materialIds,
368
+ textureIds,
369
+ geometries,
370
+ materials,
371
+ textures
372
+ );
373
+ components.instancedMesh = captureInstancedMesh(object);
374
+ components.geometry = { type: 'GeometryRef', properties: { geometryId } };
375
+ components.material = { type: 'MaterialRef', properties: { materialId } };
376
+ } else if (object.isMesh) {
377
+ const { geometryId, materialId } = captureMeshResources(
378
+ object,
379
+ geometryIds,
380
+ materialIds,
381
+ textureIds,
382
+ geometries,
383
+ materials,
384
+ textures
385
+ );
386
+ components.mesh = {
387
+ type: 'Mesh',
388
+ properties: {
389
+ castShadow: object.castShadow,
390
+ receiveShadow: object.receiveShadow
391
+ }
392
+ };
393
+ components.geometry = { type: 'GeometryRef', properties: { geometryId } };
394
+ components.material = { type: 'MaterialRef', properties: { materialId } };
395
+ } else {
396
+ const light = lightComponent(object);
397
+ if (light) {
398
+ components.light = light;
399
+ } else if (!(object.isGroup || object.type === 'Object3D')) {
400
+ throw new TypeError(`Unsupported World Authoring object: ${object.type}`);
401
+ }
402
+ }
403
+
404
+ const node = {
405
+ id: getAuthoringObjectId(object),
406
+ name: object.name || undefined,
407
+ visible: object.visible === false ? false : undefined,
408
+ components
409
+ };
410
+ const metadata = captureMetadata(object);
411
+ if (metadata) node.metadata = metadata;
412
+ return node;
413
+ }
414
+
415
+ export function captureAuthoringState(root) {
416
+ if (!root?.isObject3D) throw new TypeError('World Authoring capture requires an Object3D root');
417
+
418
+ const state = {
419
+ version: AUTHORING_VERSION,
420
+ rootId: ROOT_ID,
421
+ nodesById: {},
422
+ childIdsById: {},
423
+ parentIdById: {},
424
+ geometries: {},
425
+ materials: {},
426
+ textures: {}
427
+ };
428
+
429
+ const objectIds = new Map();
430
+ const geometryIds = new Map();
431
+ const materialIds = new Map();
432
+ const textureIds = new Map();
433
+
434
+ function visit(object, parentId = null, isRoot = false) {
435
+ const id = ensureObjectId(object, objectIds, isRoot);
436
+ const node = captureNode(
437
+ object,
438
+ geometryIds,
439
+ materialIds,
440
+ textureIds,
441
+ state.geometries,
442
+ state.materials,
443
+ state.textures
444
+ );
445
+ node.id = id;
446
+
447
+ state.nodesById[id] = node;
448
+ state.parentIdById[id] = parentId;
449
+ state.childIdsById[id] = [];
450
+
451
+ if (!node.components.modelRef) {
452
+ for (const child of object.children) {
453
+ const childId = visit(child, id, false);
454
+ state.childIdsById[id].push(childId);
455
+ }
456
+ }
457
+ return id;
458
+ }
459
+
460
+ state.rootId = visit(root, null, true);
461
+ return state;
462
+ }
463
+
464
+ function denormalizeNode(id, state) {
465
+ const node = state.nodesById[id];
466
+ if (!node) throw new TypeError(`Missing World Authoring node: ${id}`);
467
+ const childIds = state.childIdsById[id] || [];
468
+ if (node.components?.modelRef && childIds.length > 0) {
469
+ throw new TypeError('World Authoring ModelRef node cannot contain authored children');
470
+ }
471
+ const children = childIds.map(childId => denormalizeNode(childId, state));
472
+ return {
473
+ ...structuredCloneJson(node),
474
+ ...(children.length ? { children } : {})
475
+ };
476
+ }
477
+
478
+ export function exportAuthoringDocument(state) {
479
+ if (!state || state.version !== AUTHORING_VERSION || !state.rootId) {
480
+ throw new TypeError('Invalid World Authoring state');
481
+ }
482
+ return {
483
+ format: AUTHORING_FORMAT,
484
+ version: AUTHORING_VERSION,
485
+ root: denormalizeNode(state.rootId, state),
486
+ ...(Object.keys(state.geometries || {}).length ? { geometries: structuredCloneJson(state.geometries) } : {}),
487
+ ...(Object.keys(state.materials || {}).length ? { materials: structuredCloneJson(state.materials) } : {}),
488
+ ...(Object.keys(state.textures || {}).length ? { textures: structuredCloneJson(state.textures) } : {})
489
+ };
490
+ }
491
+
492
+ export function parseAuthoringDocument(document) {
493
+ if (!document || document.format !== AUTHORING_FORMAT) {
494
+ throw new TypeError(`World Authoring document format must be ${AUTHORING_FORMAT}`);
495
+ }
496
+ if (document.version !== AUTHORING_VERSION) {
497
+ throw new TypeError(`Unsupported World Authoring document version: ${document.version}`);
498
+ }
499
+ if (!document.root || typeof document.root.id !== 'string') {
500
+ throw new TypeError('World Authoring document requires a root node');
501
+ }
502
+
503
+ const state = {
504
+ version: AUTHORING_VERSION,
505
+ rootId: document.root.id,
506
+ nodesById: {},
507
+ childIdsById: {},
508
+ parentIdById: {},
509
+ geometries: structuredCloneJson(document.geometries || {}),
510
+ materials: structuredCloneJson(document.materials || {}),
511
+ textures: structuredCloneJson(document.textures || {})
512
+ };
513
+
514
+ function insert(node, parentId) {
515
+ if (!node || typeof node.id !== 'string' || !node.id) throw new TypeError('World Authoring node id is required');
516
+ if (state.nodesById[node.id]) throw new TypeError(`Duplicate World Authoring node id: ${node.id}`);
517
+ const { children = [], ...record } = node;
518
+ if (record.components?.modelRef && children.length > 0) {
519
+ throw new TypeError('World Authoring ModelRef node cannot contain authored children');
520
+ }
521
+ state.nodesById[node.id] = structuredCloneJson(record);
522
+ state.parentIdById[node.id] = parentId;
523
+ state.childIdsById[node.id] = [];
524
+ for (const child of children) {
525
+ insert(child, node.id);
526
+ state.childIdsById[node.id].push(child.id);
527
+ }
528
+ }
529
+
530
+ insert(document.root, null);
531
+ return state;
532
+ }
533
+
534
+ function createPrimitiveGeometry(definition) {
535
+ const p = definition.parameters || {};
536
+ switch (definition.type) {
537
+ case 'BoxGeometry':
538
+ return new THREE.BoxGeometry(p.width, p.height, p.depth, p.widthSegments, p.heightSegments, p.depthSegments);
539
+ case 'SphereGeometry':
540
+ return new THREE.SphereGeometry(p.radius, p.widthSegments, p.heightSegments, p.phiStart, p.phiLength, p.thetaStart, p.thetaLength);
541
+ case 'PlaneGeometry':
542
+ return new THREE.PlaneGeometry(p.width, p.height, p.widthSegments, p.heightSegments);
543
+ case 'CylinderGeometry':
544
+ return new THREE.CylinderGeometry(p.radiusTop, p.radiusBottom, p.height, p.radialSegments, p.heightSegments, p.openEnded, p.thetaStart, p.thetaLength);
545
+ case 'ConeGeometry':
546
+ return new THREE.ConeGeometry(p.radius, p.height, p.radialSegments, p.heightSegments, p.openEnded, p.thetaStart, p.thetaLength);
547
+ case 'TorusGeometry':
548
+ return new THREE.TorusGeometry(p.radius, p.tube, p.radialSegments, p.tubularSegments, p.arc);
549
+ default:
550
+ return null;
551
+ }
552
+ }
553
+
554
+ function hydrateGeometries(definitions) {
555
+ const geometries = {};
556
+ for (const [id, definition] of Object.entries(definitions || {})) {
557
+ let geometry = createPrimitiveGeometry(definition);
558
+ if (!geometry && definition.type === 'BufferGeometry' && definition.json) {
559
+ geometry = new THREE.BufferGeometryLoader().parse(definition.json);
560
+ }
561
+ if (!geometry) throw new TypeError(`Unsupported World Authoring geometry: ${definition.type}`);
562
+ geometryIdsByObject.set(geometry, id);
563
+
564
+ geometries[id] = geometry;
565
+ }
566
+ return geometries;
567
+ }
568
+
569
+ const TYPED_ARRAYS = {
570
+ Uint8Array,
571
+ Uint8ClampedArray,
572
+ Uint16Array,
573
+ Uint32Array,
574
+ Int8Array,
575
+ Int16Array,
576
+ Int32Array,
577
+ Float32Array,
578
+ Float64Array
579
+ };
580
+
581
+ function hydrateTextureSource(source) {
582
+ if (source?.type === 'data') {
583
+ const ArrayType = TYPED_ARRAYS[source.dataType] || Uint8Array;
584
+ const texture = new THREE.DataTexture(
585
+ new ArrayType(source.data || []),
586
+ source.width,
587
+ source.height
588
+ );
589
+ texture.needsUpdate = true;
590
+ return texture;
591
+ }
592
+
593
+ if (source?.type === 'url' && typeof source.uri === 'string' && source.uri) {
594
+ let texture;
595
+ if (typeof document !== 'undefined') {
596
+ texture = new THREE.TextureLoader().load(source.uri);
597
+ } else {
598
+ texture = new THREE.Texture();
599
+ }
600
+
601
+ textureSourcesByObject.set(texture, structuredCloneJson(source));
602
+ return texture;
603
+ }
604
+
605
+ throw new TypeError('Unsupported World Authoring texture source');
606
+ }
607
+
608
+ function hydrateTextures(definitions) {
609
+ const textures = {};
610
+ for (const [id, definition] of Object.entries(definitions || {})) {
611
+ const texture = hydrateTextureSource(definition.source);
612
+ texture.mapping = definition.mapping ?? texture.mapping;
613
+ texture.wrapS = definition.wrapS ?? texture.wrapS;
614
+ texture.wrapT = definition.wrapT ?? texture.wrapT;
615
+ texture.magFilter = definition.magFilter ?? texture.magFilter;
616
+ texture.minFilter = definition.minFilter ?? texture.minFilter;
617
+ texture.anisotropy = definition.anisotropy ?? texture.anisotropy;
618
+ texture.format = definition.format ?? texture.format;
619
+ texture.type = definition.type ?? texture.type;
620
+ texture.colorSpace = definition.colorSpace ?? texture.colorSpace;
621
+ texture.flipY = definition.flipY ?? texture.flipY;
622
+ texture.premultiplyAlpha = definition.premultiplyAlpha ?? texture.premultiplyAlpha;
623
+ texture.generateMipmaps = definition.generateMipmaps ?? texture.generateMipmaps;
624
+ if (Array.isArray(definition.offset)) texture.offset.fromArray(definition.offset);
625
+ if (Array.isArray(definition.repeat)) texture.repeat.fromArray(definition.repeat);
626
+ if (Array.isArray(definition.center)) texture.center.fromArray(definition.center);
627
+ if (Number.isFinite(definition.rotation)) texture.rotation = definition.rotation;
628
+
629
+ textureIdsByObject.set(texture, id);
630
+ if (definition.source) textureSourcesByObject.set(texture, structuredCloneJson(definition.source));
631
+ textures[id] = texture;
632
+ }
633
+ return textures;
634
+ }
635
+
636
+ function hydrateMaterials(definitions, textures) {
637
+ const materials = {};
638
+ const loader = new THREE.MaterialLoader();
639
+ loader.setTextures(textures);
640
+ for (const [id, definition] of Object.entries(definitions || {})) {
641
+ if (!MATERIAL_TYPES.has(definition.type)) {
642
+ throw new TypeError(`Unsupported World Authoring material: ${definition.type}`);
643
+ }
644
+ const material = loader.parse(definition);
645
+ materialIdsByObject.set(material, id);
646
+
647
+ materials[id] = material;
648
+ }
649
+ return materials;
650
+ }
651
+
652
+ function applyTransform(object, component) {
653
+ const p = component?.properties || {};
654
+ if (Array.isArray(p.position) && p.position.length === 3) object.position.fromArray(p.position);
655
+ if (Array.isArray(p.quaternion) && p.quaternion.length === 4) object.quaternion.fromArray(p.quaternion);
656
+ if (Array.isArray(p.scale) && p.scale.length === 3) object.scale.fromArray(p.scale);
657
+ }
658
+
659
+ function createLight(component) {
660
+ const p = component.properties || {};
661
+ const color = p.color ?? '#ffffff';
662
+ let light;
663
+ switch (component.type) {
664
+ case 'AmbientLight':
665
+ light = new THREE.AmbientLight(color, p.intensity);
666
+ break;
667
+ case 'HemisphereLight':
668
+ light = new THREE.HemisphereLight(color, p.groundColor ?? '#ffffff', p.intensity);
669
+ break;
670
+ case 'DirectionalLight':
671
+ light = new THREE.DirectionalLight(color, p.intensity);
672
+ if (Array.isArray(p.target)) light.target.position.fromArray(p.target);
673
+ light.castShadow = Boolean(p.castShadow);
674
+ break;
675
+ case 'PointLight':
676
+ light = new THREE.PointLight(color, p.intensity, p.distance, p.decay);
677
+ light.castShadow = Boolean(p.castShadow);
678
+ break;
679
+ case 'SpotLight':
680
+ light = new THREE.SpotLight(color, p.intensity, p.distance, p.angle, p.penumbra, p.decay);
681
+ if (Array.isArray(p.target)) light.target.position.fromArray(p.target);
682
+ light.castShadow = Boolean(p.castShadow);
683
+ break;
684
+ default:
685
+ throw new TypeError(`Unsupported World Authoring light: ${component.type}`);
686
+ }
687
+ return light;
688
+ }
689
+
690
+ function requiredMeshResources(components, geometries, materials) {
691
+ const geometryId = components.geometry?.properties?.geometryId;
692
+ const materialId = components.material?.properties?.materialId;
693
+ const geometry = geometries[geometryId];
694
+ const material = materials[materialId];
695
+ if (!geometry) throw new TypeError(`Missing World Authoring geometry: ${geometryId}`);
696
+ if (!material) throw new TypeError(`Missing World Authoring material: ${materialId}`);
697
+ return { geometry, material };
698
+ }
699
+
700
+ function createInstancedMesh(component, geometry, material) {
701
+ const p = component.properties || {};
702
+ const count = Number(p.count);
703
+ if (!Number.isInteger(count) || count < 0) throw new TypeError('Invalid World Authoring InstancedMesh count');
704
+ const object = new THREE.InstancedMesh(geometry, material, count);
705
+ const matrices = p.matrices || [];
706
+ if (matrices.length !== count * 16) {
707
+ throw new TypeError('Invalid World Authoring InstancedMesh matrix data');
708
+ }
709
+ object.instanceMatrix.array.set(matrices);
710
+ object.instanceMatrix.needsUpdate = true;
711
+ if (Array.isArray(p.colors)) {
712
+ if (p.colors.length !== count * 3) throw new TypeError('Invalid World Authoring InstancedMesh color data');
713
+ object.instanceColor = new THREE.InstancedBufferAttribute(new Float32Array(p.colors), 3);
714
+ object.instanceColor.needsUpdate = true;
715
+ }
716
+ object.castShadow = Boolean(p.castShadow);
717
+ object.receiveShadow = Boolean(p.receiveShadow);
718
+ return object;
719
+ }
720
+
721
+ function applySceneComponent(scene, component, textures) {
722
+ const p = component?.properties || {};
723
+ const background = p.background;
724
+ if (background?.type === 'color') scene.background = new THREE.Color(background.value);
725
+ else if (background?.type === 'texture') scene.background = textures[background.textureId] || null;
726
+ if (p.environment?.textureId) scene.environment = textures[p.environment.textureId] || null;
727
+ if (p.fog?.type === 'Fog') scene.fog = new THREE.Fog(p.fog.color, p.fog.near, p.fog.far);
728
+ else if (p.fog?.type === 'FogExp2') scene.fog = new THREE.FogExp2(p.fog.color, p.fog.density);
729
+ if (Number.isFinite(p.backgroundBlurriness)) scene.backgroundBlurriness = p.backgroundBlurriness;
730
+ if (Number.isFinite(p.backgroundIntensity)) scene.backgroundIntensity = p.backgroundIntensity;
731
+ if (Number.isFinite(p.environmentIntensity)) scene.environmentIntensity = p.environmentIntensity;
732
+ }
733
+
734
+ function createObjectForNode(node, geometries, materials, textures) {
735
+ const components = node.components || {};
736
+ let object;
737
+
738
+ if (components.modelRef) {
739
+ throw new TypeError('World Authoring ModelRef requires loadAsync()');
740
+ } else if (components.scene) {
741
+ object = new THREE.Scene();
742
+ applySceneComponent(object, components.scene, textures);
743
+ } else if (components.instancedMesh) {
744
+ const { geometry, material } = requiredMeshResources(components, geometries, materials);
745
+ object = createInstancedMesh(components.instancedMesh, geometry, material);
746
+ } else if (components.mesh) {
747
+ const { geometry, material } = requiredMeshResources(components, geometries, materials);
748
+ object = new THREE.Mesh(geometry, material);
749
+ object.castShadow = Boolean(components.mesh.properties?.castShadow);
750
+ object.receiveShadow = Boolean(components.mesh.properties?.receiveShadow);
751
+ } else if (components.light) {
752
+ object = createLight(components.light);
753
+ } else {
754
+ object = new THREE.Group();
755
+ }
756
+
757
+ object.name = node.name || '';
758
+ object.visible = node.visible !== false;
759
+ object.userData = node.metadata ? structuredCloneJson(node.metadata) : {};
760
+ setAuthoringObjectId(object, node.id);
761
+ applyTransform(object, components.transform);
762
+ return object;
763
+ }
764
+
765
+ export function hydrateAuthoringState(state) {
766
+ if (!state || state.version !== AUTHORING_VERSION) throw new TypeError('Invalid World Authoring state');
767
+
768
+ const geometries = hydrateGeometries(state.geometries);
769
+ const textures = hydrateTextures(state.textures);
770
+ const materials = hydrateMaterials(state.materials, textures);
771
+
772
+ function build(id) {
773
+ const node = state.nodesById[id];
774
+ if (!node) throw new TypeError(`Missing World Authoring node: ${id}`);
775
+ const object = createObjectForNode(node, geometries, materials, textures);
776
+ for (const childId of state.childIdsById[id] || []) object.add(build(childId));
777
+ return object;
778
+ }
779
+
780
+ return build(state.rootId);
781
+ }
782
+
783
+
784
+
785
+ async function createObjectForNodeAsync(node, geometries, materials, textures, resolveModel) {
786
+ const components = node.components || {};
787
+ if (!components.modelRef) return createObjectForNode(node, geometries, materials, textures);
788
+ if (typeof resolveModel !== 'function') {
789
+ throw new TypeError('World Authoring loadAsync requires resolveModel for ModelRef');
790
+ }
791
+
792
+ const reference = cloneAuthoringModelRef(components.modelRef.properties);
793
+ const resolved = await resolveModel(reference, node);
794
+ if (!resolved?.isObject3D) {
795
+ throw new TypeError('World Authoring ModelRef resolver must return an Object3D');
796
+ }
797
+
798
+ const object = new THREE.Group();
799
+ object.name = node.name || '';
800
+ object.visible = node.visible !== false;
801
+ object.userData = node.metadata ? structuredCloneJson(node.metadata) : {};
802
+ setAuthoringObjectId(object, node.id);
803
+ markAuthoringModelRef(object, reference);
804
+ applyTransform(object, components.transform);
805
+ object.add(resolved);
806
+ return object;
807
+ }
808
+
809
+ export async function hydrateAuthoringStateAsync(state, { resolveModel } = {}) {
810
+ if (!state || state.version !== AUTHORING_VERSION) throw new TypeError('Invalid World Authoring state');
811
+
812
+ const geometries = hydrateGeometries(state.geometries);
813
+ const textures = hydrateTextures(state.textures);
814
+ const materials = hydrateMaterials(state.materials, textures);
815
+
816
+ async function build(id) {
817
+ const node = state.nodesById[id];
818
+ if (!node) throw new TypeError('Missing World Authoring node: ' + id);
819
+ const object = await createObjectForNodeAsync(node, geometries, materials, textures, resolveModel);
820
+ for (const childId of state.childIdsById[id] || []) object.add(await build(childId));
821
+ return object;
822
+ }
823
+
824
+ return build(state.rootId);
825
+ }