agentscape3d-engine 0.0.0-stage → 1.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (457) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/cli.mjs +53 -0
  4. package/dist/ArticulationVerifier-BfGxXY8V.js +337 -0
  5. package/dist/ArticulationVerifier-BfGxXY8V.js.map +1 -0
  6. package/dist/AssetCompiler-BLj09iu1.js +2424 -0
  7. package/dist/AssetCompiler-BLj09iu1.js.map +1 -0
  8. package/dist/AssetModule-DME-XaFS.js +2637 -0
  9. package/dist/AssetModule-DME-XaFS.js.map +1 -0
  10. package/dist/AssetRecipe-g8dZBhgJ.js +298 -0
  11. package/dist/AssetRecipe-g8dZBhgJ.js.map +1 -0
  12. package/dist/BrowserCodeWorker.js +53856 -0
  13. package/dist/BrowserCodeWorker.js.map +1 -0
  14. package/dist/CarryCapability-CXwHU5ay.js +104 -0
  15. package/dist/CarryCapability-CXwHU5ay.js.map +1 -0
  16. package/dist/KinematicHypothesisScreen-C3TKiuYR.js +241 -0
  17. package/dist/KinematicHypothesisScreen-C3TKiuYR.js.map +1 -0
  18. package/dist/ObjectTransform-BlQUNK7c.js +61 -0
  19. package/dist/ObjectTransform-BlQUNK7c.js.map +1 -0
  20. package/dist/RapierPhysicsBackend-B2wQe_Vl.js +3259 -0
  21. package/dist/RapierPhysicsBackend-B2wQe_Vl.js.map +1 -0
  22. package/dist/RenderingSystem-WIr1ZuGu.js +1042 -0
  23. package/dist/RenderingSystem-WIr1ZuGu.js.map +1 -0
  24. package/dist/ScenePresentation-LsYiDxbm.js +152 -0
  25. package/dist/ScenePresentation-LsYiDxbm.js.map +1 -0
  26. package/dist/SceneProject-K7HH1s8o.js +2687 -0
  27. package/dist/SceneProject-K7HH1s8o.js.map +1 -0
  28. package/dist/SceneSerializer-zOzbX4jZ.js +932 -0
  29. package/dist/SceneSerializer-zOzbX4jZ.js.map +1 -0
  30. package/dist/SimulationProfile-DSYZbBLQ.js +165 -0
  31. package/dist/SimulationProfile-DSYZbBLQ.js.map +1 -0
  32. package/dist/StylePack-DcRa_kU0.js +88 -0
  33. package/dist/StylePack-DcRa_kU0.js.map +1 -0
  34. package/dist/WorldArchive-BiFGLt--.js +451 -0
  35. package/dist/WorldArchive-BiFGLt--.js.map +1 -0
  36. package/dist/WorldCommands-Debj7V4L.js +2207 -0
  37. package/dist/WorldCommands-Debj7V4L.js.map +1 -0
  38. package/dist/WorldIO-Ch8QBfKY.js +151 -0
  39. package/dist/WorldIO-Ch8QBfKY.js.map +1 -0
  40. package/dist/admission-CVEvsrdz.js +121 -0
  41. package/dist/admission-CVEvsrdz.js.map +1 -0
  42. package/dist/blankWorld-B0MW6g7q.js +75 -0
  43. package/dist/blankWorld-B0MW6g7q.js.map +1 -0
  44. package/dist/core.d.ts +68 -0
  45. package/dist/core.js +209 -0
  46. package/dist/core.js.map +1 -0
  47. package/dist/disposeObject3D-DIMzy0FA.js +128 -0
  48. package/dist/disposeObject3D-DIMzy0FA.js.map +1 -0
  49. package/dist/environments-HOe3sJXH.js +567 -0
  50. package/dist/environments-HOe3sJXH.js.map +1 -0
  51. package/dist/gltfIO-BzVKLyaL.js +339 -0
  52. package/dist/gltfIO-BzVKLyaL.js.map +1 -0
  53. package/dist/grandUrbanBlock-DRndRZjF.js +515 -0
  54. package/dist/grandUrbanBlock-DRndRZjF.js.map +1 -0
  55. package/dist/index.d.ts +345 -0
  56. package/dist/index.js +16952 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/magicCabin-CfBZjx2Q.js +11019 -0
  59. package/dist/magicCabin-CfBZjx2Q.js.map +1 -0
  60. package/dist/manifests-D0LwbJ36.js +866 -0
  61. package/dist/manifests-D0LwbJ36.js.map +1 -0
  62. package/dist/mcp.d.ts +2 -0
  63. package/dist/mcp.js +1 -0
  64. package/dist/monumentHall-awZiGtda.js +403 -0
  65. package/dist/monumentHall-awZiGtda.js.map +1 -0
  66. package/dist/node.d.ts +16 -0
  67. package/dist/node.js +26 -0
  68. package/dist/parts-DrEcfJRl.js +37 -0
  69. package/dist/parts-DrEcfJRl.js.map +1 -0
  70. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  71. package/dist/ruinedCourtyard-DuF7NmUU.js +696 -0
  72. package/dist/ruinedCourtyard-DuF7NmUU.js.map +1 -0
  73. package/dist/runtime/application/AgentTools.js +28 -0
  74. package/dist/runtime/application/README.md +14 -0
  75. package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
  76. package/dist/runtime/application/agent/StudioMcpAllowlist.js +10 -0
  77. package/dist/runtime/application/agent/StudioProjectTools.js +18 -0
  78. package/dist/runtime/application/agent/TaskEvidence.js +199 -0
  79. package/dist/runtime/application/buildTaskObservation.js +117 -0
  80. package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +50 -0
  81. package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
  82. package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
  83. package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +82 -0
  84. package/dist/runtime/application/createSession.js +66 -0
  85. package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
  86. package/dist/runtime/application/generation/GenerationOrchestrator.js +630 -0
  87. package/dist/runtime/application/generation/GenerationRuntime.js +215 -0
  88. package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +289 -0
  89. package/dist/runtime/application/native-scene/CodeProject.js +215 -0
  90. package/dist/runtime/application/native-scene/CodeProjectModules.js +143 -0
  91. package/dist/runtime/application/native-scene/ExampleWorldCatalog.js +35 -0
  92. package/dist/runtime/application/native-scene/NativeArticulation.js +53 -0
  93. package/dist/runtime/application/native-scene/NativeEditableRegistry.js +150 -0
  94. package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +85 -0
  95. package/dist/runtime/application/native-scene/NativeLightingInspection.js +33 -0
  96. package/dist/runtime/application/native-scene/NativeMaterialInspection.js +52 -0
  97. package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
  98. package/dist/runtime/application/native-scene/NativePhysicsGeometry.js +64 -0
  99. package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
  100. package/dist/runtime/application/native-scene/NativeSceneHost.js +406 -0
  101. package/dist/runtime/application/native-scene/NativeSceneInspection.js +203 -0
  102. package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
  103. package/dist/runtime/application/native-scene/NativeSceneQuery.js +123 -0
  104. package/dist/runtime/application/native-scene/NativeSceneReview.js +132 -0
  105. package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
  106. package/dist/runtime/application/native-scene/SceneObserver.js +97 -0
  107. package/dist/runtime/application/native-scene/VisualCapturePolicy.js +4 -0
  108. package/dist/runtime/application/object-forge/SceneObjectForge.js +263 -0
  109. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
  110. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
  111. package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
  112. package/dist/runtime/application/scene/CapabilityResolver.js +90 -0
  113. package/dist/runtime/application/scene/NativeEditableContracts.js +18 -0
  114. package/dist/runtime/application/scene/RequestWindow.js +54 -0
  115. package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
  116. package/dist/runtime/application/scene/SceneContracts.js +49 -0
  117. package/dist/runtime/application/scene/SceneEditService.js +154 -0
  118. package/dist/runtime/application/scene/SceneFacade.js +356 -0
  119. package/dist/runtime/application/scene/SceneInteractionAdapters.js +41 -0
  120. package/dist/runtime/application/scene/SceneJobController.js +320 -0
  121. package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
  122. package/dist/runtime/application/scene/ScenePackage.js +173 -0
  123. package/dist/runtime/application/scene/ScenePersistence.js +50 -0
  124. package/dist/runtime/application/scene/SceneProject.js +95 -0
  125. package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
  126. package/dist/runtime/application/scene/StarterScene.js +56 -0
  127. package/dist/runtime/application/scene/WorldArchive.js +89 -0
  128. package/dist/runtime/application/scene/WorldDirectory.js +20 -0
  129. package/dist/runtime/application/scene/WorldDocument.js +76 -0
  130. package/dist/runtime/application/scene/WorldIO.js +103 -0
  131. package/dist/runtime/application/scene/WorldStorage.js +155 -0
  132. package/dist/runtime/application/skills/SkillRegistry.js +193 -0
  133. package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
  134. package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
  135. package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
  136. package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
  137. package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
  138. package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
  139. package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
  140. package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
  141. package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
  142. package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
  143. package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
  144. package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
  145. package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
  146. package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
  147. package/dist/runtime/application/skills/skillPrimitives.js +4 -0
  148. package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
  149. package/dist/runtime/application/tasks.jsonl +67 -0
  150. package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
  151. package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
  152. package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
  153. package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
  154. package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
  155. package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
  156. package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
  157. package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
  158. package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
  159. package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
  160. package/dist/runtime/application/world-authoring/HeadlessImageExport.js +92 -0
  161. package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
  162. package/dist/runtime/application/world-authoring/SceneGLBExport.js +88 -0
  163. package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
  164. package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +68 -0
  165. package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
  166. package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
  167. package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
  168. package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
  169. package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
  170. package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
  171. package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
  172. package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
  173. package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
  174. package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +157 -0
  175. package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
  176. package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
  177. package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
  178. package/dist/runtime/apps/mcp-server/README.md +269 -0
  179. package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
  180. package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
  181. package/dist/runtime/apps/mcp-server/SessionManager.js +148 -0
  182. package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +75 -0
  183. package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +246 -0
  184. package/dist/runtime/apps/mcp-server/StudioProjectToolContracts.js +58 -0
  185. package/dist/runtime/apps/mcp-server/TransferHttp.js +47 -0
  186. package/dist/runtime/apps/mcp-server/TransferLimits.js +6 -0
  187. package/dist/runtime/apps/mcp-server/TransferStore.js +134 -0
  188. package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
  189. package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
  190. package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
  191. package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
  192. package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
  193. package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
  194. package/dist/runtime/apps/mcp-server/main.mjs +82 -0
  195. package/dist/runtime/apps/mcp-server/registerTools.js +274 -0
  196. package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
  197. package/dist/runtime/apps/mcp-server/security.js +23 -0
  198. package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
  199. package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
  200. package/dist/runtime/apps/server/README.md +7 -0
  201. package/dist/runtime/apps/server/WorldRepository.js +338 -0
  202. package/dist/runtime/apps/server/WorldRepositoryHttp.js +96 -0
  203. package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
  204. package/dist/runtime/apps/server/tasks.jsonl +10 -0
  205. package/dist/runtime/apps/shared/node/WorldDiskStorage.js +62 -0
  206. package/dist/runtime/foundation/EventBus.js +26 -0
  207. package/dist/runtime/foundation/JsonGateway.js +47 -0
  208. package/dist/runtime/foundation/PngRgba.js +99 -0
  209. package/dist/runtime/foundation/PolicyEngine.js +21 -0
  210. package/dist/runtime/foundation/README.md +7 -0
  211. package/dist/runtime/foundation/TraceRecorder.js +76 -0
  212. package/dist/runtime/foundation/errors.js +8 -0
  213. package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
  214. package/dist/runtime/foundation/version.js +2 -0
  215. package/dist/runtime/modules/agent/README.md +11 -0
  216. package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
  217. package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
  218. package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
  219. package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
  220. package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
  221. package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
  222. package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
  223. package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
  224. package/dist/runtime/modules/agent/prompt/index.js +52 -0
  225. package/dist/runtime/modules/agent/tasks.jsonl +94 -0
  226. package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
  227. package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
  228. package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
  229. package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
  230. package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
  231. package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
  232. package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
  233. package/dist/runtime/modules/artifact/README.md +7 -0
  234. package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
  235. package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
  236. package/dist/runtime/modules/asset/AssetModule.js +416 -0
  237. package/dist/runtime/modules/asset/README.md +67 -0
  238. package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
  239. package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
  240. package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
  241. package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
  242. package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
  243. package/dist/runtime/modules/asset/model/AssetInputContracts.js +139 -0
  244. package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
  245. package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
  246. package/dist/runtime/modules/asset/model/ProceduralTextureContract.js +24 -0
  247. package/dist/runtime/modules/asset/model/admission.js +117 -0
  248. package/dist/runtime/modules/asset/model/errors.js +6 -0
  249. package/dist/runtime/modules/asset/model/parts.js +27 -0
  250. package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
  251. package/dist/runtime/modules/asset/model/schema.js +150 -0
  252. package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
  253. package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
  254. package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
  255. package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
  256. package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
  257. package/dist/runtime/modules/asset/production/AssetRecipe.js +91 -0
  258. package/dist/runtime/modules/asset/production/ProceduralTexture.js +85 -0
  259. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
  260. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
  261. package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
  262. package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
  263. package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
  264. package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
  265. package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
  266. package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
  267. package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
  268. package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
  269. package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
  270. package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
  271. package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
  272. package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
  273. package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
  274. package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
  275. package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
  276. package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
  277. package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
  278. package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
  279. package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
  280. package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
  281. package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
  282. package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
  283. package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
  284. package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
  285. package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
  286. package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
  287. package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
  288. package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
  289. package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
  290. package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
  291. package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
  292. package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
  293. package/dist/runtime/modules/asset/tasks.jsonl +87 -0
  294. package/dist/runtime/modules/generation/README.md +9 -0
  295. package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
  296. package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
  297. package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
  298. package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
  299. package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
  300. package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
  301. package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
  302. package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
  303. package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
  304. package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
  305. package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
  306. package/dist/runtime/modules/generation/tasks.jsonl +35 -0
  307. package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
  308. package/dist/runtime/modules/navigation/RecastNavigationBackend.js +263 -0
  309. package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
  310. package/dist/runtime/modules/physics/PhysicsApiSurface.js +660 -0
  311. package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
  312. package/dist/runtime/modules/physics/RapierPhysicsBackend.js +414 -0
  313. package/dist/runtime/modules/rendering/README.md +7 -0
  314. package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
  315. package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
  316. package/dist/runtime/modules/rendering/captureStill.js +54 -0
  317. package/dist/runtime/modules/rendering/createRenderer.js +76 -0
  318. package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
  319. package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
  320. package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
  321. package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
  322. package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
  323. package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
  324. package/dist/runtime/modules/world/README.md +13 -0
  325. package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
  326. package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
  327. package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
  328. package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
  329. package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
  330. package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
  331. package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
  332. package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
  333. package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
  334. package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
  335. package/dist/runtime/modules/world/content/blankWorld.js +35 -0
  336. package/dist/runtime/modules/world/content/environments.js +84 -0
  337. package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
  338. package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
  339. package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
  340. package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
  341. package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
  342. package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
  343. package/dist/runtime/modules/world/content/magicCabin.js +190 -0
  344. package/dist/runtime/modules/world/content/monumentHall.js +154 -0
  345. package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
  346. package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
  347. package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
  348. package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
  349. package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
  350. package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
  351. package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
  352. package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
  353. package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
  354. package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
  355. package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
  356. package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
  357. package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
  358. package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
  359. package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
  360. package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
  361. package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
  362. package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
  363. package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
  364. package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
  365. package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
  366. package/dist/runtime/modules/world/errors.js +9 -0
  367. package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
  368. package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
  369. package/dist/runtime/modules/world/runtime/CommandHistory.js +111 -0
  370. package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +165 -0
  371. package/dist/runtime/modules/world/runtime/NativeNavigationGeometry.js +84 -0
  372. package/dist/runtime/modules/world/runtime/NativePhysicsSnapshot.js +245 -0
  373. package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
  374. package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
  375. package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
  376. package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +240 -0
  377. package/dist/runtime/modules/world/runtime/SceneExtensions.js +36 -0
  378. package/dist/runtime/modules/world/runtime/ScenePresentation.js +101 -0
  379. package/dist/runtime/modules/world/runtime/SceneSerializer.js +281 -0
  380. package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
  381. package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
  382. package/dist/runtime/modules/world/runtime/WorldCommands.js +503 -0
  383. package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
  384. package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
  385. package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
  386. package/dist/runtime/modules/world/runtime/WorldRuntime.js +806 -0
  387. package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +110 -0
  388. package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
  389. package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
  390. package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
  391. package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
  392. package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
  393. package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +390 -0
  394. package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
  395. package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
  396. package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +244 -0
  397. package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +147 -0
  398. package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
  399. package/dist/runtime/modules/world/runtime/interaction/ManipulationActions.js +7 -0
  400. package/dist/runtime/modules/world/runtime/interaction/NativePhysicalTarget.js +31 -0
  401. package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
  402. package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +134 -0
  403. package/dist/runtime/modules/world/runtime/semantic/NativePhysicsState.js +89 -0
  404. package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +129 -0
  405. package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
  406. package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +104 -0
  407. package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
  408. package/dist/runtime/modules/world/runtime/simulation/WorldTimeline.js +110 -0
  409. package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
  410. package/dist/runtime/modules/world/runtime/spatial/VisualMeshBounds.js +41 -0
  411. package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +306 -0
  412. package/dist/runtime/modules/world/runtime/systems/Instrument.js +39 -0
  413. package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +806 -0
  414. package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +281 -0
  415. package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +561 -0
  416. package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1752 -0
  417. package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +527 -0
  418. package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +402 -0
  419. package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
  420. package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
  421. package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
  422. package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
  423. package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
  424. package/dist/runtime/modules/world/tasks.jsonl +530 -0
  425. package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
  426. package/dist/runtime/modules/world/verification/Finding.js +105 -0
  427. package/dist/runtime/modules/world/verification/InteractionEvidence.js +73 -0
  428. package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
  429. package/dist/runtime/modules/world/verification/VisualLayoutAcceptance.js +58 -0
  430. package/dist/runtime/modules/world/verification/WorldAcceptance.js +176 -0
  431. package/dist/runtime/modules/world/verification/WorldValidator.js +67 -0
  432. package/dist/runtime/package-lock.json +16071 -0
  433. package/dist/runtime/package.json +106 -0
  434. package/dist/runtime/public/assets/cabinet.glb +0 -0
  435. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
  436. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
  437. package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
  438. package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
  439. package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
  440. package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
  441. package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
  442. package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
  443. package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
  444. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
  445. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
  446. package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
  447. package/dist/schema-DT7K9NjP.js +165 -0
  448. package/dist/schema-DT7K9NjP.js.map +1 -0
  449. package/dist/suzhouGarden-Y3hny8j6.js +6150 -0
  450. package/dist/suzhouGarden-Y3hny8j6.js.map +1 -0
  451. package/dist/version-CHc-i8ch.js +5 -0
  452. package/dist/version-CHc-i8ch.js.map +1 -0
  453. package/dist/woodlandWorkshop-DsScU-cx.js +483 -0
  454. package/dist/woodlandWorkshop-DsScU-cx.js.map +1 -0
  455. package/dist/yuanmingyuan-DsFnPzzR.js +4955 -0
  456. package/dist/yuanmingyuan-DsFnPzzR.js.map +1 -0
  457. package/package.json +75 -4
@@ -0,0 +1,406 @@
1
+ import * as THREE from 'three';
2
+ import * as z from 'zod/v4';
3
+ import { assetPhysicsSchema, canonicalAssetJson } from '../../modules/asset/model/AssetInputContracts.js';
4
+ import { WorldRuntime } from '../../modules/world/runtime/WorldRuntime.js';
5
+ import { createAssetModule } from '../../modules/asset/AssetModule.js';
6
+ import { ArticulationVerifier } from '../../modules/world/verification/ArticulationVerifier.js';
7
+ import { clearInteractionEvidenceForTarget } from '../../modules/world/verification/InteractionEvidence.js';
8
+ import { IncrementalSha256 } from '../../modules/artifact/IncrementalSha256.js';
9
+ import { assetManifests } from '../../modules/asset/registry/manifests/index.js';
10
+ import { createSceneFacade } from '../scene/SceneFacade.js';
11
+ import { createSceneLifecycle } from '../scene/SceneLifecycle.js';
12
+ import { SkillRegistry } from '../skills/SkillRegistry.js';
13
+ import { registerSceneSkills } from '../skills/packs/sceneSkills.js';
14
+ import { registerSpatialSkills } from '../skills/packs/spatialSkills.js';
15
+ import { registerInteractionSkills } from '../skills/packs/interactionSkills.js';
16
+ import { NativeEditableRegistry } from './NativeEditableRegistry.js';
17
+ import { parseNativeArticulation } from './NativeArticulation.js';
18
+ import { extractNativeStaticColliders } from './NativeEnvironmentGeometry.js';
19
+ import { analyzeNativePhysicsGeometry, containsNativeObject, overlapsNativeObject } from './NativePhysicsGeometry.js';
20
+ import { writeNativeSceneOverlay, prepareNativeSceneOverlay, restoreNativeSceneOverlay, exportNativeSceneOverlay, importNativeSceneOverlay } from './NativeSceneOverlay.js';
21
+
22
+ function nativePhysicsSignature(physics,surfaces,colliderSource,articulation=null){
23
+ const definition=JSON.parse(JSON.stringify({physics,surfaces,colliderSource,...(articulation?{articulation}:{})}));
24
+ return new IncrementalSha256().update(new TextEncoder().encode(canonicalAssetJson(definition))).digestHex();
25
+ }
26
+
27
+ const bindings = new WeakMap();
28
+ const fail = code => Object.assign(new Error(code), { code });
29
+ const nativeColliderSize = z.number().finite().positive().max(100);
30
+ const nativeColliderOffset = z.tuple([z.number().finite().min(-100).max(100), z.number().finite().min(-100).max(100), z.number().finite().min(-100).max(100)]).default(() => [0, 0, 0]);
31
+ const nativeColliderRotation = z.tuple([z.number().finite(), z.number().finite(), z.number().finite(), z.number().finite()])
32
+ .refine(rotation => Math.abs(Math.hypot(...rotation) - 1) < 1e-4);
33
+ const nativeBoxCollider = assetPhysicsSchema.shape.colliders.element.extend({ rotation: nativeColliderRotation.optional() });
34
+ const nativeRoundCollider = z.object({
35
+ shape: z.enum(['capsule', 'cylinder']), radius: nativeColliderSize, halfHeight: nativeColliderSize,
36
+ translation: nativeColliderOffset, rotation: nativeColliderRotation.optional(),
37
+ }).strict();
38
+ const nativeSurfaceSchema=z.object({id:z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/),
39
+ localPosition:nativeColliderOffset, size:z.tuple([nativeColliderSize,nativeColliderSize])}).strict();
40
+ const nativePhysicsSchema = assetPhysicsSchema.extend({
41
+ body: z.enum(['fixed', 'dynamic', 'kinematic']),
42
+ manipulable:z.boolean().optional(), lockTranslation:z.tuple([z.boolean(),z.boolean(),z.boolean()]).optional(),
43
+ lockRotation:z.tuple([z.boolean(),z.boolean(),z.boolean()]).optional(),
44
+ colliders: z.array(z.union([nativeBoxCollider, nativeRoundCollider])).min(1).max(64),
45
+ });
46
+
47
+ /** Attach to a trusted, already running native Scene. Never own its renderer or loop.
48
+ * Colliders/navigationRoot are explicit world-space environment registration.
49
+ * Native source and closure state are deliberately outside SceneFacade serialization.
50
+ */
51
+ export async function attachNativeScene({
52
+ scene: nativeScene, camera, renderer, three = THREE, name = 'Native scene',
53
+ environmentId = 'native-scene', colliders = [], navigationRoot = null,
54
+ staticMeshes = [], walkableMesh = null, hostProjectId = null, hostRevision = null,
55
+ assetModule = null, audioListener = null, audioThree = THREE, autoStart = true, codeExecutor = null, codeGLTFLoader,
56
+ assetBaseUrl = globalThis.location?.origin ? globalThis.location.origin + '/' : null,
57
+ onAttach = null,
58
+ } = {}) {
59
+ if (three.Object3D !== THREE.Object3D || three.REVISION !== THREE.REVISION) throw fail('NATIVE_THREE_INSTANCE_MISMATCH');
60
+ if (!nativeScene?.isScene || !camera?.isCamera || typeof renderer?.render !== 'function') throw fail('NATIVE_BINDING_INVALID');
61
+ if (!(nativeScene instanceof THREE.Scene) || !(camera instanceof THREE.Camera)) throw fail('NATIVE_THREE_INSTANCE_MISMATCH');
62
+ if (bindings.has(nativeScene)) throw fail('NATIVE_SCENE_ALREADY_ATTACHED');
63
+ nativeScene.updateWorldMatrix(true, false);
64
+ if (!nativeScene.matrixWorld.equals(new THREE.Matrix4())) throw fail('NATIVE_WORLD_TRANSFORM_UNSUPPORTED');
65
+ if (!Array.isArray(colliders)) throw fail('NATIVE_COLLIDERS_INVALID');
66
+ if (hostProjectId != null && (typeof hostProjectId !== 'string' || !/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(hostProjectId))) throw fail('NATIVE_HOST_IDENTITY_INVALID');
67
+ if (hostRevision != null && (typeof hostRevision !== 'string' || !/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(hostRevision))) throw fail('NATIVE_HOST_IDENTITY_INVALID');
68
+ if (navigationRoot && !navigationRoot.isObject3D) throw fail('NATIVE_NAVIGATION_ROOT_INVALID');
69
+ if (onAttach != null && typeof onAttach !== 'function') throw fail('NATIVE_ATTACH_HOOK_INVALID');
70
+ const extractedColliders = extractNativeStaticColliders(nativeScene, { staticMeshes, walkableMesh });
71
+ const environmentColliders = [...structuredClone(colliders), ...extractedColliders];
72
+ // Explicit navigationRoot is a caller-authored proxy. Otherwise derive
73
+ // navigation from the very same frozen physical environment inputs.
74
+ const environmentNavigation = navigationRoot;
75
+ const navigationColliders=navigationRoot?null:environmentColliders;
76
+ bindings.set(nativeScene, true); // Reserve before asynchronous physics initialization.
77
+ let assets, world, facade, frameId, closed = false;
78
+ const injectedComponents = new Map();
79
+ const componentId = value => typeof value === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(value);
80
+ const unsupported = code => async () => { throw fail(code); };
81
+ const restoreMount = component => {
82
+ component.object.removeFromParent();
83
+ if (!component.originalParent) return;
84
+ component.originalParent.add(component.object);
85
+ const children = component.originalParent.children;
86
+ const currentIndex = children.indexOf(component.object);
87
+ children.splice(currentIndex, 1);
88
+ children.splice(Math.min(component.originalIndex, children.length), 0, component.object);
89
+ };
90
+ try {
91
+ const manifests = structuredClone(assetManifests);
92
+ if (assetBaseUrl) {
93
+ for (const manifest of Object.values(manifests)) {
94
+ if (manifest.source?.kind === 'glb') manifest.source.url = new URL(manifest.source.url, assetBaseUrl).href;
95
+ }
96
+ }
97
+ assets = assetModule || createAssetModule({ manifests, volatile: true, manifestStore: null, libraryStore: null });
98
+ const environmentRoot = new THREE.Group();
99
+ environmentRoot.name = 'AgentScapeEnvironment';
100
+ world = new WorldRuntime({ assetModule: assets, audioListener, audioThree, environmentFactory: () => ({
101
+ id: environmentId, root: environmentRoot, colliders: environmentColliders,
102
+ ...(environmentNavigation ? { navigationRoot: environmentNavigation } : {navigationColliders}), dispose() {},
103
+ }) });
104
+ world.scene.name = 'AgentScapeRoot';
105
+ // The runtime owns only this subtree. Host environment/materials stay untouched.
106
+ // A nested Scene is traversed as Object3D; the outer Scene still owns lighting/fog.
107
+ world.attachRendering({ scene: world.scene, renderer, camera,
108
+ init() {}, render() {}, applyEnvironment() {}, dispose() {},
109
+ });
110
+ assets.configureVerification({ articulationVerifier: new ArticulationVerifier({
111
+ assetRegistry: assets.registry, assetLoader: assets.loader,
112
+ }) });
113
+ world.skills = new SkillRegistry({ policy: world.policy, trace: world.trace, runtime: world });
114
+ const add = (name, options, handler) => world.skills.register({ name, ...options, handler });
115
+ registerSceneSkills(add, world);
116
+ registerSpatialSkills(add, world);
117
+ registerInteractionSkills(add, world);
118
+ await world.init();
119
+ const lifecycle = createSceneLifecycle(world);
120
+ const nativeEditables = new NativeEditableRegistry(nativeScene,world);
121
+ facade = createSceneFacade(world, { name, codeExecutor, codeGLTFLoader, lifecycle, nativeEditables });
122
+ nativeScene.add(world.scene);
123
+ const syncKinematicComponents = () => {
124
+ for (const component of injectedComponents.values()) {
125
+ if (component.bodyType !== 'kinematic') continue;
126
+ const position = component.object.getWorldPosition(new THREE.Vector3());
127
+ const rotation = component.object.getWorldQuaternion(new THREE.Quaternion());
128
+ world.physics.setHeldTarget(component.id, position.toArray(), rotation.toArray());
129
+ }
130
+ };
131
+ const writebackPhysicsComponents = () => world.physics.writeback({
132
+ has: id => Boolean(injectedComponents.get(id)?.physics) && injectedComponents.get(id)?.bodyType !== 'kinematic',
133
+ get: id => injectedComponents.get(id),
134
+ });
135
+ const frame = timestamp => {
136
+ if (closed) throw fail('SCENE_CLOSED');
137
+ // Do not call renderer.render: the original project owns every render pass.
138
+ syncKinematicComponents();
139
+ facade.frame(timestamp);
140
+ writebackPhysicsComponents();
141
+ };
142
+ const step = () => {
143
+ if (closed) throw fail('SCENE_CLOSED');
144
+ syncKinematicComponents();
145
+ const result = facade.step();
146
+ writebackPhysicsComponents();
147
+ return result;
148
+ };
149
+ const tick = timestamp => {
150
+ if (closed) return;
151
+ frame(timestamp);
152
+ frameId = requestAnimationFrame(tick);
153
+ };
154
+ const removeComponent = component => {
155
+ if (!component || injectedComponents.get(component.id) !== component) return false;
156
+ if (!closed) lifecycle.assertIdle();
157
+ world.interactions?.beforeRemove(component.id);
158
+ injectedComponents.delete(component.id);
159
+ clearInteractionEvidenceForTarget(world,component.id);
160
+ world.audio?.unregisterEmitter(component.id);
161
+ if (component.physics) world.physics.removeObject(component.id);
162
+ if(component.bodyType==='fixed')world.navigation?.invalidate('native-fixed-removed');
163
+ component.unregister?.();
164
+ world.entities.unregister(component.id, { reason:'native-component-removed' });
165
+ if (component.mounted) component.object.removeFromParent();
166
+ if(!closed)lifecycle.incrementRevision();
167
+ return true;
168
+ };
169
+ const analyzePhysics = object => {
170
+ if(closed)throw fail('SCENE_CLOSED');
171
+ if(!object?.isObject3D||object===nativeScene||!containsNativeObject(nativeScene,object)||
172
+ overlapsNativeObject(world.scene,object))throw fail('NATIVE_COMPONENT_NOT_IN_HOST_SCENE');
173
+ const existing=[...injectedComponents.values()].find(component=>component.physics&&overlapsNativeObject(component.object,object));
174
+ if(existing)throw fail('NATIVE_PHYSICS_COMPONENT_OVERLAP');
175
+ if([...staticMeshes,walkableMesh].filter(Boolean).some(mesh=>overlapsNativeObject(mesh,object)))
176
+ throw fail('NATIVE_PHYSICS_ENVIRONMENT_OVERLAP');
177
+ return analyzeNativePhysicsGeometry(object);
178
+ };
179
+ const registerComponent = ({ id, object, parent = world.scene, semantic = null, audio = false, audioOptions = {}, physics = null, actions = [], surfaces = [], parts = {} } = {}, mounted = true) => {
180
+ if (closed) throw fail('SCENE_CLOSED');
181
+ lifecycle.assertIdle();
182
+ if (!componentId(id)) throw fail('NATIVE_COMPONENT_ID_INVALID');
183
+ if (!(object instanceof THREE.Object3D) || !object.isObject3D) throw fail('NATIVE_COMPONENT_OBJECT_INVALID');
184
+ if (!(parent instanceof THREE.Object3D) || !parent.isObject3D) throw fail('NATIVE_COMPONENT_PARENT_INVALID');
185
+ if (injectedComponents.has(id) || [...injectedComponents.values()].some(component => component.object === object)) throw fail('NATIVE_COMPONENT_CONFLICT');
186
+ if (mounted) {
187
+ for (let ancestor = parent; ancestor; ancestor = ancestor.parent) {
188
+ if (ancestor === object) throw fail('NATIVE_COMPONENT_PARENT_INVALID');
189
+ }
190
+ }
191
+ if (!mounted) {
192
+ let ancestor = object.parent;
193
+ while (ancestor && ancestor !== nativeScene && ancestor !== world.scene) ancestor = ancestor.parent;
194
+ if (ancestor !== nativeScene) throw fail('NATIVE_COMPONENT_NOT_IN_HOST_SCENE');
195
+ }
196
+ if (semantic != null && (typeof semantic !== 'object' || Array.isArray(semantic))) throw fail('NATIVE_COMPONENT_SEMANTIC_INVALID');
197
+ if (!Array.isArray(actions)) throw fail('NATIVE_COMPONENT_ACTIONS_INVALID');
198
+ if (world.entities.has(id) || world.store.has(id) || world.physics.entries.has(id)) throw fail('NATIVE_COMPONENT_CONFLICT');
199
+ const parsedSurfaces=z.array(nativeSurfaceSchema).max(16).safeParse(surfaces);
200
+ if(!parsedSurfaces.success||new Set(surfaces.map(s=>s.id)).size!==surfaces.length)throw fail('NATIVE_SURFACE_INVALID');
201
+ if(surfaces.length&&physics?.body!=='fixed')throw fail('NATIVE_SURFACE_REQUIRES_FIXED');
202
+ if(!parts||typeof parts!=='object'||Array.isArray(parts))throw fail('NATIVE_ARTICULATION_INVALID');
203
+ const articulated=Object.keys(parts).length>0;
204
+ if(articulated&&(mounted||physics?.body!=='fixed'||physics.colliders==='mesh-bounds'||surfaces.length))
205
+ throw fail('NATIVE_ARTICULATION_REQUIRES_BOUND_FIXED_ROOT');
206
+ let physicsSpec = null,colliderSource=null,articulation=null;
207
+ if (physics != null) {
208
+ colliderSource='declared';
209
+ if([...injectedComponents.values()].some(component=>component.physics&&
210
+ (overlapsNativeObject(component.object,object)||(mounted&&containsNativeObject(component.object,parent)))))
211
+ throw fail('NATIVE_PHYSICS_COMPONENT_OVERLAP');
212
+ if([...staticMeshes,walkableMesh].filter(Boolean).some(mesh=>overlapsNativeObject(mesh,object)||(mounted&&containsNativeObject(mesh,parent))))
213
+ throw fail('NATIVE_PHYSICS_ENVIRONMENT_OVERLAP');
214
+ if(physics.colliders==='mesh-bounds'){
215
+ if(mounted)throw fail('NATIVE_PHYSICS_BOUNDS_BIND_ONLY');
216
+ if(physics.body==='dynamic'&&physics.mass==null)throw fail('NATIVE_PHYSICS_MASS_REQUIRED');
217
+ physics={...physics,colliders:analyzePhysics(object).colliders};
218
+ colliderSource='mesh-bounds';
219
+ }
220
+ if(physics.carryable===true&&physics.body!=='dynamic')throw fail('NATIVE_CARRY_REQUIRES_DYNAMIC');
221
+ if(physics.manipulable===true||physics.carryable===true){
222
+ if(physics.body!=='dynamic')throw fail('NATIVE_MANIPULATION_REQUIRES_DYNAMIC');
223
+ if(physics.mass==null)throw fail('NATIVE_PHYSICS_MASS_REQUIRED');
224
+ if(mounted&&!containsNativeObject(nativeScene,parent))throw fail('NATIVE_COMPONENT_NOT_IN_HOST_SCENE');
225
+ }
226
+ const parsed = nativePhysicsSchema.safeParse(physics);
227
+ if (!parsed.success) throw fail('NATIVE_PHYSICS_INVALID');
228
+ if (!object.matrixAutoUpdate) throw fail('NATIVE_PHYSICS_MATRIX_AUTO_UPDATE_REQUIRED');
229
+ if (object.matrixAutoUpdate) object.updateMatrix();
230
+ const matrix = new THREE.Matrix4();
231
+ if (mounted) {
232
+ parent.updateWorldMatrix(true, false);
233
+ matrix.multiplyMatrices(parent.matrixWorld, object.matrix);
234
+ } else {
235
+ object.updateWorldMatrix(true, false);
236
+ matrix.copy(object.matrixWorld);
237
+ }
238
+ const position = new THREE.Vector3();
239
+ const rotation = new THREE.Quaternion();
240
+ const scale = new THREE.Vector3();
241
+ matrix.decompose(position, rotation, scale);
242
+ const reconstructed = new THREE.Matrix4().compose(position, rotation, scale);
243
+ if (scale.toArray().some(value => Math.abs(value - 1) > 1e-6) ||
244
+ matrix.elements.some((value, index) => Math.abs(value - reconstructed.elements[index]) > 1e-6)) {
245
+ throw fail('NATIVE_PHYSICS_SCALE_UNSUPPORTED');
246
+ }
247
+ if(surfaces.length&&1-Math.abs(rotation.w)>1e-6)throw fail('NATIVE_SURFACE_ROTATION_UNSUPPORTED');
248
+ physicsSpec = parsed.data;
249
+ if(articulated)articulation=parseNativeArticulation(object,parts,nativePhysicsSchema);
250
+ nativeEditables.assertPhysicsCompatible(object,physicsSpec.body);
251
+ }
252
+ const manifest=physicsSpec?{physics:physicsSpec,nativeNavigation:true,...(articulation?{parts:articulation.parts,nativeArticulation:true}:{})}:null;
253
+ const component = { id, object, parent, mounted, originalParent: object.parent,
254
+ originalIndex: object.parent?.children.indexOf(object) ?? -1,
255
+ physics: false, bodyType: physicsSpec?.body ?? null, unregister: null, remove: () => removeComponent(component) };
256
+ try {
257
+ if (mounted) parent.add(object);
258
+ world.entities.register({ id, object, source:'native', manifest, phase:'visual-mounted', transformAuthority:physicsSpec ? physicsSpec.body === 'kinematic' ? 'host' : 'physics' : 'host',
259
+ capabilities:['semantic', ...(physicsSpec ? ['physics'] : []), ...(articulation?['articulation']:[]), ...(actions.length||articulation ? ['interaction'] : []), ...(semantic?.capabilities || [])],
260
+ metadata:{label:semantic?.label??id,...(physicsSpec?{colliderSource,manipulable:physicsSpec.manipulable===true,carryable:physicsSpec.carryable===true,surfaces:parsedSurfaces.data,hostSceneUuid:nativeScene.uuid,bindingId:crypto.randomUUID(),physicsSignature:nativePhysicsSignature(physicsSpec,parsedSurfaces.data,colliderSource,articulation),...(articulation?{articulationRest:articulation.rest,articulationNodeUuids:Object.fromEntries(Object.entries(articulation.parts).map(([name,part])=>[name,object.getObjectByName(part.node).uuid]))}:{})}: {})} });
261
+ if (physicsSpec) {
262
+ world.physics.addObject(id, manifest, object);
263
+ component.physics = true;
264
+ world.entities.setPhase(id, 'physics-registered');
265
+ if(physicsSpec.body==='fixed')world.navigation?.invalidate('native-fixed-registered');
266
+ }
267
+ if (audio) {
268
+ if (!world.audio) throw fail('NATIVE_AUDIO_UNAVAILABLE');
269
+ world.audio.registerEmitter(id, object, audioOptions);
270
+ }
271
+ component.unregister = facade.registerEntity({
272
+ id, label: semantic?.label ?? id, description: semantic?.description ?? '',
273
+ object, read: semantic?.read ?? (() => ({})),
274
+ });
275
+ for (const action of actions) {
276
+ facade.registerAction({ ...action, target: id });
277
+ }
278
+ clearInteractionEvidenceForTarget(world,id);
279
+ injectedComponents.set(id, component);
280
+ lifecycle.incrementRevision();
281
+ return Object.freeze({ id, object, remove: component.remove });
282
+ } catch (error) {
283
+ component.unregister?.();
284
+ world.audio?.unregisterEmitter(id);
285
+ if (component.physics) world.physics.removeObject(id);
286
+ world.entities.unregister(id, { reason:'native-injection-failed' });
287
+ if (mounted) restoreMount(component);
288
+ throw error;
289
+ }
290
+ };
291
+ const addComponent = options => registerComponent(options);
292
+ const bindComponent = options => registerComponent(options, false);
293
+ const timeline = {
294
+ get tick() { return world.simulation.tick; },
295
+ schedule(tick,cue) {
296
+ if (closed) throw fail('SCENE_CLOSED');
297
+ lifecycle.assertIdle();
298
+ return world.timeline.schedule(tick,cue);
299
+ },
300
+ observeSounds:id=>world.timeline.observeSounds(id),
301
+ onCue(kind,handler) {
302
+ if (closed) throw fail('SCENE_CLOSED');
303
+ if (!['sound','environment'].includes(kind)) throw new TypeError('Unknown timeline cue');
304
+ return world.events.on('timeline.'+kind,handler);
305
+ }
306
+ };
307
+ const native = { timeline, scene: nativeScene, renderer, camera, root: world.scene, addComponent, bindComponent, analyzePhysics, audio: world.audio,
308
+ editables:Object.freeze({register:options=>nativeEditables.register(options),list:()=>nativeEditables.list(),
309
+ getObject:id=>nativeEditables.objectFor(id)}) };
310
+ const close = () => {
311
+ if (closed) return;
312
+ facade.close(); // Reject a close during a mutation before detaching anything.
313
+ closed = true;
314
+ if (frameId != null) cancelAnimationFrame(frameId);
315
+ for (const component of [...injectedComponents.values()]) removeComponent(component);
316
+ world.scene.removeFromParent();
317
+ nativeEditables.dispose();
318
+ try { world.dispose(); } finally {
319
+ if (!assetModule) assets.loader.gltfLoader.dispose?.();
320
+ bindings.delete(nativeScene);
321
+ }
322
+ };
323
+ const handle = {
324
+ ...facade,
325
+ frame,
326
+ step,
327
+ close,
328
+ // Never export a native project as a misleading built-in Scene Project.
329
+ save: unsupported('NATIVE_PROJECT_SAVE_UNSUPPORTED'),
330
+ exportWorld: unsupported('NATIVE_PROJECT_SAVE_UNSUPPORTED'),
331
+ saveOverlay: async (storage, options = {}) => {
332
+ if (closed) throw fail('SCENE_CLOSED');
333
+ if (!hostProjectId) throw fail('NATIVE_HOST_IDENTITY_REQUIRED');
334
+ return writeNativeSceneOverlay(world, storage, { projectId: hostProjectId, revision: hostRevision }, options);
335
+ },
336
+ prepareOverlay: async (storage, root, options = {}) => {
337
+ if (closed) throw fail('SCENE_CLOSED');
338
+ if (!hostProjectId) throw fail('NATIVE_HOST_IDENTITY_REQUIRED');
339
+ const prepared = await prepareNativeSceneOverlay(world, storage, root,
340
+ { projectId: hostProjectId, revision: hostRevision }, options);
341
+ return {
342
+ summary: prepared.summary,
343
+ commit: () => { if (closed) throw fail('SCENE_CLOSED');return prepared.commit(); },
344
+ dispose: () => prepared.dispose()
345
+ };
346
+ },
347
+ restoreOverlay: async (storage, root, options = {}) => {
348
+ if (closed) throw fail('SCENE_CLOSED');
349
+ if (!hostProjectId) throw fail('NATIVE_HOST_IDENTITY_REQUIRED');
350
+ return restoreNativeSceneOverlay(world, storage, root,
351
+ { projectId: hostProjectId, revision: hostRevision }, options);
352
+ },
353
+ exportOverlay: async (storage, root, writer, options = {}) => {
354
+ if (closed) throw fail('SCENE_CLOSED');
355
+ if (!hostProjectId) throw fail('NATIVE_HOST_IDENTITY_REQUIRED');
356
+ return exportNativeSceneOverlay(storage, root,
357
+ { projectId: hostProjectId, revision: hostRevision }, writer, options);
358
+ },
359
+ importOverlay: async (storage, source, options = {}) => {
360
+ if (closed) throw fail('SCENE_CLOSED');
361
+ if (!hostProjectId) throw fail('NATIVE_HOST_IDENTITY_REQUIRED');
362
+ return importNativeSceneOverlay(storage, source,
363
+ { projectId: hostProjectId, revision: hostRevision }, options);
364
+ },
365
+ importProject: unsupported('NATIVE_PROJECT_IMPORT_UNSUPPORTED'),
366
+ importWorld: unsupported('NATIVE_PROJECT_IMPORT_UNSUPPORTED'),
367
+ prepareWorld: unsupported('NATIVE_PROJECT_IMPORT_UNSUPPORTED'),
368
+ setStyle: unsupported('NATIVE_RENDERING_OWNED_BY_PROJECT'),
369
+ native,
370
+ registerEditable:options=>nativeEditables.register(options),
371
+ nativeEditables:()=>nativeEditables.list(),
372
+ exportNativeEdits:()=>nativeEditables.export(),
373
+ restoreNativeEdits:snapshot=>nativeEditables.restore(snapshot),
374
+ capabilities: Object.freeze({ mode: 'native-scene', threeRevision: THREE.REVISION,
375
+ sourceConversion: false, ownsRenderer: false, nativeProjectSave: false,
376
+ environmentColliders: environmentColliders.length, navigationRegistered: Boolean(environmentNavigation||navigationColliders?.length),
377
+ navigationSource:environmentNavigation?'explicit-proxy':'physics-colliders',
378
+ nativeOverlayPersistence: Boolean(hostProjectId), audio: Boolean(world.audio) }),
379
+ };
380
+ if (onAttach) await onAttach({ scene: handle, native, three: THREE });
381
+ world.simulation.play();
382
+ if (autoStart) frameId = requestAnimationFrame(tick);
383
+ // Runtime is exposed to the local Studio bridge, never serialized over MCP.
384
+ return { scene: handle, world, close };
385
+ } catch (error) {
386
+ if (frameId != null) cancelAnimationFrame(frameId);
387
+ for (const component of [...injectedComponents.values()].reverse()) {
388
+ component.unregister?.();
389
+ world.audio?.unregisterEmitter(component.id);
390
+ if (component.physics) world.physics.removeObject(component.id);
391
+ world.entities.unregister(component.id, { reason:'native-scene-attach-failed' });
392
+ if (component.mounted) restoreMount(component);
393
+ }
394
+ injectedComponents.clear();
395
+ world?.scene.removeFromParent();
396
+ try {
397
+ facade?.close();
398
+ if (world?.sceneGraph) world.dispose();
399
+ else world?.physics.dispose();
400
+ } finally {
401
+ if (!assetModule) assets?.loader.gltfLoader.dispose?.();
402
+ bindings.delete(nativeScene);
403
+ }
404
+ throw error;
405
+ }
406
+ }
@@ -0,0 +1,203 @@
1
+ import { Box3, Frustum, Matrix4, PerspectiveCamera, Vector3 } from 'three';
2
+ import { createMaterialInventory } from './NativeMaterialInspection.js';
3
+ import { createLightingInventory } from './NativeLightingInspection.js';
4
+
5
+ // Bound CPU work as well as the response. Inspect the relevant child path for
6
+ // large scenes rather than returning every object or allocating geometry copies.
7
+ const MAX_NODES=4096, MAX_VERTICES=2_000_000, MAX_INSTANCES=50_000, MAX_TRIANGLES=100_000_000, MAX_DEPTH=128;
8
+ const fail=code=>Object.assign(new Error(code),{code});
9
+ const finiteBox=box=>!box.isEmpty()&&[...box.min.toArray(),...box.max.toArray()].every(Number.isFinite);
10
+ const vector=v=>v.toArray().map(n=>Number.isFinite(n)?Number(n.toPrecision(10)):null);
11
+ const nameOf=o=>String(o.name||'').slice(0,120);
12
+ const childPath=(path,index)=>path?path+'/'+index:String(index);
13
+
14
+ export function resolveNode(scene,path,objectUuid){
15
+ if(typeof path!=='string'||path.length>256||! /^(?:(?:0|[1-9]\d*)(?:\/(?:0|[1-9]\d*))*)?$/.test(path))
16
+ throw fail('NATIVE_INSPECT_PATH_INVALID');
17
+ let node=scene, visible=scene.visible!==false;
18
+ for(const segment of path?path.split('/'):[]){
19
+ const i=Number(segment);
20
+ if(!Number.isSafeInteger(i)||!node.children[i])throw fail('NATIVE_INSPECT_NODE_NOT_FOUND');
21
+ node=node.children[i];visible=visible&&node.visible!==false;
22
+ }
23
+ // A child-index path is not an identity after native tree edits.
24
+ if(objectUuid!==undefined&&node.uuid!==objectUuid)throw fail('NATIVE_INSPECT_OBJECT_CONFLICT');
25
+ return {node,visible};
26
+ }
27
+
28
+ function cameraCoverage(camera,bounds,complete){
29
+ if(!complete||!camera?.isCamera)return 'unknown';
30
+ if(bounds.isEmpty())return 'empty';
31
+ camera.updateWorldMatrix(true,false);
32
+ const projection=new Matrix4().multiplyMatrices(camera.projectionMatrix,camera.matrixWorldInverse);
33
+ if(!projection.elements.every(Number.isFinite))return 'unknown';
34
+ const frustum=new Frustum().setFromProjectionMatrix(projection,camera.coordinateSystem,camera.reversedDepth);
35
+ if(!frustum.intersectsBox(bounds))return 'outside';
36
+ const point=new Vector3();
37
+ for(const x of [bounds.min.x,bounds.max.x])for(const y of [bounds.min.y,bounds.max.y])
38
+ for(const z of [bounds.min.z,bounds.max.z])if(!frustum.containsPoint(point.set(x,y,z)))return 'intersects';
39
+ return 'inside';
40
+ }
41
+
42
+ /** Detached inspection camera, never changes the project's own camera. */
43
+ export function createInspectionCamera(original,{position,target,fov=45}={},aspect){
44
+ const valid=v=>Array.isArray(v)&&v.length===3&&v.every(n=>Number.isFinite(n)&&Math.abs(n)<=1e6);
45
+ if(!valid(position)||!valid(target)||!Number.isFinite(fov)||fov<10||fov>110||
46
+ !Number.isFinite(aspect)||aspect<=0)throw fail('VISUAL_VIEW_INVALID');
47
+ const eye=new Vector3(...position),focus=new Vector3(...target),delta=focus.clone().sub(eye);
48
+ if(delta.lengthSq()<1e-12)throw fail('VISUAL_VIEW_INVALID');
49
+ const distance=delta.length();
50
+ const near=Math.max(1e-5,Math.min(original.near>0?original.near:0.01,distance/100));
51
+ const far=Math.max(original.far>near&&Number.isFinite(original.far)?original.far:1000,distance*4,near*10);
52
+ const camera=new PerspectiveCamera(fov,aspect,near,far);
53
+ camera.layers.mask=original.layers.mask;
54
+ camera.position.copy(eye);
55
+ if(Math.abs(delta.normalize().y)>.999)camera.up.set(0,0,-1);
56
+ camera.lookAt(focus);camera.updateMatrixWorld(true);
57
+ return camera;
58
+ }
59
+
60
+ /** Fit an independent camera to the measured AABB, including depth of every corner. */
61
+ export function frameNativeView(native,{nodePath,objectUuid,direction=[1,.7,1],fov=45,padding=1.12}={},aspect){
62
+ if(!Array.isArray(direction)||direction.length!==3||!direction.every(Number.isFinite)||
63
+ !Number.isFinite(fov)||fov<10||fov>110||!Number.isFinite(padding)||padding<1.02||padding>2.5||
64
+ !Number.isFinite(aspect)||aspect<=0)throw fail('VISUAL_VIEW_INVALID');
65
+ const back=new Vector3(...direction);
66
+ if(back.lengthSq()<1e-12||!Number.isFinite(back.lengthSq()))throw fail('VISUAL_VIEW_INVALID');
67
+ back.normalize();
68
+ const measured=inspectNativeScene(native,{nodePath,objectUuid,limit:1});
69
+ if(!measured.boundsComplete)throw fail('VISUAL_FRAME_BOUNDS_INCOMPLETE');
70
+ if(!measured.bounds)throw fail('VISUAL_FRAME_BOUNDS_EMPTY');
71
+ const min=new Vector3(...measured.bounds.min),max=new Vector3(...measured.bounds.max);
72
+ const box=new Box3(min,max),center=box.getCenter(new Vector3()),radius=box.getSize(new Vector3()).length()/2;
73
+ const upHint=Math.abs(back.y)>.999?new Vector3(0,0,-1):new Vector3(0,1,0);
74
+ const right=new Vector3().crossVectors(upHint,back).normalize(),up=new Vector3().crossVectors(back,right);
75
+ const tanY=Math.tan(fov*Math.PI/360),tanX=tanY*aspect;
76
+ let distance=1e-4;
77
+ for(const x of [min.x,max.x])for(const y of [min.y,max.y])for(const z of [min.z,max.z]){
78
+ const p=new Vector3(x,y,z).sub(center);
79
+ distance=Math.max(distance,p.dot(back)+padding*Math.max(Math.abs(p.dot(right))/tanX,Math.abs(p.dot(up))/tanY));
80
+ }
81
+ distance+=Math.max(radius*.03,1e-4);
82
+ return {nodePath,objectUuid:measured.node.objectUuid,direction:back.toArray(),padding,fov,position:center.clone().addScaledVector(back,distance).toArray(),target:center.toArray()};
83
+ }
84
+
85
+ /** Read current geometry without requiring semantic registration or advancing the simulation. */
86
+ export function inspectNativeScene({scene,camera,renderer},{nodePath='',objectUuid,offset=0,limit=32,includeMaterials=false,includeLights=false,nodeBudget=MAX_NODES,vertexBudget=MAX_VERTICES,instanceBudget=MAX_INSTANCES,triangleBudget=MAX_TRIANGLES}={}){
87
+ if(!scene?.isScene)throw fail('NATIVE_INSPECT_UNAVAILABLE');
88
+ if(!Number.isSafeInteger(offset)||offset<0||!Number.isSafeInteger(limit)||limit<1||limit>64||
89
+ !Number.isSafeInteger(nodeBudget)||nodeBudget<1||nodeBudget>MAX_NODES||
90
+ !Number.isSafeInteger(vertexBudget)||vertexBudget<1||vertexBudget>MAX_VERTICES||
91
+ !Number.isSafeInteger(instanceBudget)||instanceBudget<1||instanceBudget>MAX_INSTANCES||
92
+ !Number.isSafeInteger(triangleBudget)||triangleBudget<1||triangleBudget>MAX_TRIANGLES)
93
+ throw fail('NATIVE_INSPECT_PAGE_INVALID');
94
+ const {node,visible}=resolveNode(scene,nodePath,objectUuid);
95
+ const reasons=new Set(), cache=new WeakMap(), bounds=new Box3();
96
+ const counts={nodes:0,vertices:0,meshes:0,visibleMeshes:0,instancedMeshes:0,instances:0,visibleInstances:0,
97
+ otherRenderables:0,estimatedTriangles:0,estimatedLineSegments:0,estimatedPoints:0};
98
+ let vertices=0,instances=0;
99
+ const materialInventory=includeMaterials?createMaterialInventory():null;
100
+ const lightingInventory=includeLights?createLightingInventory():null;
101
+ const localBox=new Box3(),matrix=new Matrix4(),instanceMatrix=new Matrix4();
102
+ const describe=(obj,path,shown)=>({nodePath:path,objectUuid:obj.uuid,name:nameOf(obj),type:String(obj.type||'Object3D').slice(0,64),
103
+ visible:shown,childCount:obj.children.length,...(obj.isInstancedMesh?{instances:obj.count}:{})});
104
+ const geometryBounds=geometry=>{
105
+ if(cache.has(geometry))return cache.get(geometry);
106
+ const position=geometry?.attributes?.position;
107
+ let box=null;
108
+ if(!position||typeof position.getX!=='function'||!Number.isSafeInteger(position.count)||position.count<1)
109
+ reasons.add('missing-position');
110
+ else if(vertices+position.count>vertexBudget)reasons.add('vertex-budget');
111
+ else{
112
+ vertices+=position.count;counts.vertices+=position.count;
113
+ const candidate=new Box3().setFromBufferAttribute(position);
114
+ if(finiteBox(candidate))box=candidate;else reasons.add('invalid-geometry');
115
+ }
116
+ if(geometry)cache.set(geometry,box);
117
+ return box;
118
+ };
119
+ const include=(box,transform)=>{
120
+ localBox.copy(box).applyMatrix4(transform);
121
+ if(finiteBox(localBox))bounds.union(localBox);else reasons.add('invalid-transform');
122
+ };
123
+ const visit=(obj,shown)=>{
124
+ counts.nodes++;
125
+ materialInventory?.add(obj,shown&&(!camera||camera.layers.test(obj.layers)));
126
+ lightingInventory?.add(obj,shown&&(!camera||camera.layers.test(obj.layers)));
127
+ if(!obj.isMesh){
128
+ if(!shown||(camera&&!camera.layers.test(obj.layers)))return;
129
+ if(obj.isLine||obj.isPoints){
130
+ counts.otherRenderables++;
131
+ const geometry=obj.geometry;
132
+ const elements=geometry?.index?.count??geometry?.attributes?.position?.count??0;
133
+ if(obj.isPoints)counts.estimatedPoints+=elements;
134
+ else counts.estimatedLineSegments+=obj.isLineSegments?Math.floor(elements/2):
135
+ obj.isLineLoop?elements:Math.max(0,elements-1);
136
+ const materials=Array.isArray(obj.material)?obj.material:[obj.material];
137
+ if(materials.some(m=>m?.isShaderMaterial||m?.displacementMap)||obj.morphTargetInfluences?.some(n=>n!==0))
138
+ reasons.add('shader-deformation-unknown');
139
+ // Bounds cover the geometric centerline/points, not screen-space stroke size.
140
+ const box=geometryBounds(geometry);
141
+ if(box)include(box,obj.matrixWorld);
142
+ }else if(obj.isSprite){
143
+ counts.otherRenderables++;reasons.add('non-mesh-renderable');
144
+ }
145
+ return;
146
+ }
147
+ counts.meshes++;
148
+ const count=obj.isInstancedMesh?obj.count:1;
149
+ if(obj.isInstancedMesh){
150
+ counts.instancedMeshes++;counts.instances+=count;
151
+ if(!Number.isSafeInteger(count)||count<0||instances+count>instanceBudget){reasons.add('instance-budget');return;}
152
+ instances+=count;
153
+ }
154
+ if(!shown||(camera&&!camera.layers.test(obj.layers)))return;
155
+ counts.visibleMeshes++;
156
+ if(obj.isInstancedMesh)counts.visibleInstances+=count;
157
+ const geometry=obj.geometry;
158
+ const elements=geometry?.index?.count??geometry?.attributes?.position?.count??0;
159
+ const estimatedTriangles=Math.floor(elements/3)*count;
160
+ if(counts.estimatedTriangles+estimatedTriangles>triangleBudget){
161
+ counts.estimatedTriangles=triangleBudget+1;reasons.add('triangle-budget');return;
162
+ }
163
+ counts.estimatedTriangles+=estimatedTriangles;
164
+ if(obj.isSkinnedMesh||obj.isBatchedMesh||obj.morphTargetInfluences?.some(n=>n!==0)){
165
+ reasons.add('deformed-mesh');return;
166
+ }
167
+ const materials=Array.isArray(obj.material)?obj.material:[obj.material];
168
+ if(materials.some(m=>m?.isShaderMaterial||m?.displacementMap))reasons.add('shader-deformation-unknown');
169
+ const box=geometryBounds(geometry);
170
+ if(!box)return;
171
+ if(!obj.isInstancedMesh){include(box,obj.matrixWorld);return;}
172
+ for(let i=0;i<count;i++){
173
+ obj.getMatrixAt(i,instanceMatrix);matrix.multiplyMatrices(obj.matrixWorld,instanceMatrix);include(box,matrix);
174
+ }
175
+ };
176
+
177
+ // Update only visited transform caches; do not recurse through unbounded subtrees.
178
+ node.updateWorldMatrix(true,false);
179
+ visit(node,visible);
180
+ const stack=[{node,visible,index:0}];
181
+ while(stack.length){
182
+ const parent=stack.at(-1);
183
+ if(parent.index>=parent.node.children.length){stack.pop();continue;}
184
+ if(counts.nodes>=nodeBudget){reasons.add('node-budget');break;}
185
+ if(stack.length>=MAX_DEPTH){reasons.add('depth-budget');stack.pop();continue;}
186
+ const child=parent.node.children[parent.index++], shown=parent.visible&&child.visible!==false;
187
+ child.updateWorldMatrix(false,false);
188
+ visit(child,shown);stack.push({node:child,visible:shown,index:0});
189
+ }
190
+ const complete=reasons.size===0;
191
+ const children=node.children.slice(offset,offset+limit).map((child,index)=>
192
+ describe(child,childPath(nodePath,offset+index),visible&&child.visible!==false));
193
+ const frame=renderer?.info?.render;
194
+ const renderStats=frame?Object.fromEntries(['calls','triangles','lines','points'].filter(key=>Number.isSafeInteger(frame[key])&&frame[key]>=0).map(key=>[key,frame[key]])):null;
195
+ return {node:describe(node,nodePath,visible),counts,
196
+ bounds:bounds.isEmpty()?null:{min:vector(bounds.min),max:vector(bounds.max),size:vector(bounds.getSize(new Vector3()))},
197
+ boundsComplete:complete,limitations:[...reasons],cameraCoverage:cameraCoverage(camera,bounds,complete),
198
+ camera:camera?.isCamera?{type:camera.type,position:vector(camera.getWorldPosition(new Vector3())),
199
+ direction:vector(camera.getWorldDirection(new Vector3())),...(camera.isPerspectiveCamera?{fov:camera.fov,aspect:camera.aspect}:{})}:null,
200
+ ...(materialInventory?{materials:materialInventory.result(!reasons.has('node-budget')&&!reasons.has('depth-budget'))}:{}),
201
+ ...(lightingInventory?{lights:lightingInventory.result(!reasons.has('node-budget')&&!reasons.has('depth-budget'))}:{}),
202
+ renderStats,children,offset,nextOffset:offset+children.length<node.children.length?offset+children.length:null};
203
+ }