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,850 @@
1
+ import { PhysicsBackend } from './PhysicsBackend.js';
2
+
3
+ let joltModulePromise=null;
4
+ const loadJolt=()=>joltModulePromise ||= import('jolt-physics').then(({default:initJolt})=>initJolt());
5
+
6
+ const LAYER=0;
7
+ const UNIT=[1,1,1];
8
+ const ZERO=[0,0,0];
9
+ const IDENTITY=[0,0,0,1];
10
+
11
+ const cloneSpec=(spec)=>structuredClone(spec);
12
+ const tuple3=(value=ZERO)=>Array.isArray(value)?value:[value.x,value.y,value.z];
13
+ const tuple4=(value=IDENTITY)=>Array.isArray(value)?value:[value.x,value.y,value.z,value.w];
14
+ const array3=(value)=>[value.GetX(),value.GetY(),value.GetZ()];
15
+ const array4=(value)=>[value.GetX(),value.GetY(),value.GetZ(),value.GetW()];
16
+ const bodyIdNumber=(body)=>body.native.GetID().GetIndexAndSequenceNumber();
17
+ const nativeBodyIdNumber=(id)=>id.GetIndexAndSequenceNumber();
18
+
19
+ const quatMultiply=(a,b)=>[
20
+ a[3]*b[0]+a[0]*b[3]+a[1]*b[2]-a[2]*b[1],
21
+ a[3]*b[1]-a[0]*b[2]+a[1]*b[3]+a[2]*b[0],
22
+ a[3]*b[2]+a[0]*b[1]-a[1]*b[0]+a[2]*b[3],
23
+ a[3]*b[3]-a[0]*b[0]-a[1]*b[1]-a[2]*b[2]
24
+ ];
25
+ const rotateVector=(q,v)=>{
26
+ const [x,y,z,w]=q;
27
+ const tx=2*(y*v[2]-z*v[1]);
28
+ const ty=2*(z*v[0]-x*v[2]);
29
+ const tz=2*(x*v[1]-y*v[0]);
30
+ return [
31
+ v[0]+w*tx+(y*tz-z*ty),
32
+ v[1]+w*ty+(z*tx-x*tz),
33
+ v[2]+w*tz+(x*ty-y*tx)
34
+ ];
35
+ };
36
+ const worldPoseForCollider=(bodyPose,collider)=>{
37
+ const localPosition=collider.spec.translation||ZERO;
38
+ const localRotation=collider.spec.rotation||IDENTITY;
39
+ const offset=rotateVector(bodyPose.rotation,localPosition);
40
+ return {
41
+ position:[bodyPose.position[0]+offset[0],bodyPose.position[1]+offset[1],bodyPose.position[2]+offset[2]],
42
+ rotation:quatMultiply(bodyPose.rotation,localRotation)
43
+ };
44
+ };
45
+
46
+ const shapeDescription=(spec)=>{
47
+ if(spec.shape==='box') return {kind:'box',halfExtents:{x:spec.halfExtents[0],y:spec.halfExtents[1],z:spec.halfExtents[2]},borderRadius:0};
48
+ if(spec.shape==='cylinder') return {kind:'cylinder',halfHeight:spec.halfHeight,radius:spec.radius,borderRadius:0};
49
+ if(spec.shape==='capsule') return {kind:'capsule',halfHeight:spec.halfHeight,radius:spec.radius,borderRadius:0};
50
+ if(spec.shape==='convexHull') return {kind:'convexHull',vertices:[...spec.vertices],borderRadius:0};
51
+ return {kind:'unknown',type:spec.shape};
52
+ };
53
+
54
+ const motionType=(Jolt,type)=>type==='dynamic' ? Jolt.EMotionType_Dynamic
55
+ : type==='kinematic' ? Jolt.EMotionType_Kinematic
56
+ : Jolt.EMotionType_Static;
57
+ const semanticMotionType=(Jolt,type)=>type===Jolt.EMotionType_Dynamic ? 'dynamic'
58
+ : type===Jolt.EMotionType_Kinematic ? 'kinematic'
59
+ : 'fixed';
60
+
61
+ const activation=(Jolt,wake=true)=>wake ? Jolt.EActivation_Activate : Jolt.EActivation_DontActivate;
62
+ const allowedDofs=(Jolt,lockTranslation=null,lockRotation=null)=>{
63
+ let dofs=0;
64
+ if(!lockTranslation?.[0]) dofs|=Jolt.EAllowedDOFs_TranslationX;
65
+ if(!lockTranslation?.[1]) dofs|=Jolt.EAllowedDOFs_TranslationY;
66
+ if(!lockTranslation?.[2]) dofs|=Jolt.EAllowedDOFs_TranslationZ;
67
+ if(!lockRotation?.[0]) dofs|=Jolt.EAllowedDOFs_RotationX;
68
+ if(!lockRotation?.[1]) dofs|=Jolt.EAllowedDOFs_RotationY;
69
+ if(!lockRotation?.[2]) dofs|=Jolt.EAllowedDOFs_RotationZ;
70
+ return dofs;
71
+ };
72
+
73
+ const pairKey=(a,b)=>a<b?`${a}:${b}`:`${b}:${a}`;
74
+ const normalized3=(value)=>{
75
+ const [x,y,z]=tuple3(value); const length=Math.hypot(x,y,z);
76
+ if(length<=1e-12) throw new TypeError('Joint axis must be non-zero');
77
+ return [x/length,y/length,z/length];
78
+ };
79
+ const perpendicular3=(axis)=>{
80
+ const [x,y,z]=normalized3(axis);
81
+ const basis=Math.abs(x)<=Math.abs(y)&&Math.abs(x)<=Math.abs(z)?[1,0,0]:Math.abs(y)<=Math.abs(z)?[0,1,0]:[0,0,1];
82
+ return normalized3([y*basis[2]-z*basis[1],z*basis[0]-x*basis[2],x*basis[1]-y*basis[0]]);
83
+ };
84
+
85
+ const withVec3=(Jolt,value,fn)=>{
86
+ const v=new Jolt.Vec3(value[0],value[1],value[2]);
87
+ try{return fn(v);}finally{Jolt.destroy(v);}
88
+ };
89
+ const withRVec3=(Jolt,value,fn)=>{
90
+ const v=new Jolt.RVec3(value[0],value[1],value[2]);
91
+ try{return fn(v);}finally{Jolt.destroy(v);}
92
+ };
93
+ const withQuat=(Jolt,value,fn)=>{
94
+ const q=new Jolt.Quat(value[0],value[1],value[2],value[3]);
95
+ try{return fn(q);}finally{Jolt.destroy(q);}
96
+ };
97
+
98
+ function createShapeSettings(Jolt,spec,userData=0){
99
+ let settings;
100
+ if(spec.shape==='box') {
101
+ const half=new Jolt.Vec3(...spec.halfExtents);
102
+ settings=new Jolt.BoxShapeSettings(half,0,null);
103
+ Jolt.destroy(half);
104
+ } else if(spec.shape==='cylinder') {
105
+ settings=new Jolt.CylinderShapeSettings(spec.halfHeight,spec.radius,0,null);
106
+ } else if(spec.shape==='capsule') {
107
+ settings=new Jolt.CapsuleShapeSettings(spec.halfHeight,spec.radius,null);
108
+ } else if(spec.shape==='convexHull') {
109
+ settings=new Jolt.ConvexHullShapeSettings();
110
+ const point=new Jolt.Vec3(0,0,0);
111
+ try {
112
+ for(let i=0;i<spec.vertices.length;i+=3){
113
+ point.Set(spec.vertices[i],spec.vertices[i+1],spec.vertices[i+2]);
114
+ settings.mPoints.push_back(point);
115
+ }
116
+ } finally { Jolt.destroy(point); }
117
+ } else {
118
+ throw new TypeError(`JoltPhysicsBackend unsupported collider shape: ${spec.shape}`);
119
+ }
120
+ settings.mUserData=userData;
121
+ return settings;
122
+ }
123
+
124
+ function createOwnedShape(Jolt,spec,userData=0){
125
+ const settings=createShapeSettings(Jolt,spec,userData);
126
+ try {
127
+ const result=settings.Create();
128
+ try {
129
+ if(!result.IsValid()) throw new Error(`Jolt rejected ${spec.shape} shape`);
130
+ const shape=result.Get();
131
+ shape.AddRef();
132
+ result.Clear();
133
+ return shape;
134
+ } finally { Jolt.destroy(result); }
135
+ } finally { Jolt.destroy(settings); }
136
+ }
137
+
138
+ function createBodyShape(Jolt,specs){
139
+ if(!specs.length){ const shape=new Jolt.EmptyShape(); shape.AddRef(); return shape; }
140
+ if(specs.length===1 && !specs[0].translation && !specs[0].rotation) return createOwnedShape(Jolt,specs[0],1);
141
+
142
+ const compound=new Jolt.StaticCompoundShapeSettings();
143
+ try {
144
+ for(const [index,spec] of specs.entries()){
145
+ const settings=createShapeSettings(Jolt,spec,index+1);
146
+ const position=new Jolt.Vec3(...(spec.translation||ZERO));
147
+ const rotation=new Jolt.Quat(...(spec.rotation||IDENTITY));
148
+ try {
149
+ compound.AddShapeShapeSettings(position,rotation,settings,index+1);
150
+ } finally {
151
+ Jolt.destroy(position);
152
+ Jolt.destroy(rotation);
153
+ }
154
+ // Compound owns the child settings after AddShapeShapeSettings.
155
+ }
156
+ const result=compound.Create();
157
+ try {
158
+ if(!result.IsValid()) throw new Error('Jolt rejected compound collider shape');
159
+ const shape=result.Get();
160
+ shape.AddRef();
161
+ result.Clear();
162
+ return shape;
163
+ } finally { Jolt.destroy(result); }
164
+ } finally { Jolt.destroy(compound); }
165
+ }
166
+
167
+ const destroyOwnedShape=(shape)=>shape?.Release?.();
168
+
169
+ function createTransform(Jolt,position,rotation){
170
+ const p=new Jolt.RVec3(...tuple3(position));
171
+ const q=new Jolt.Quat(...tuple4(rotation));
172
+ try { return Jolt.RMat44.prototype.sRotationTranslation(q,p); }
173
+ finally { Jolt.destroy(q); Jolt.destroy(p); }
174
+ }
175
+
176
+ function createQueryFilters(Jolt,world){
177
+ return {
178
+ broadPhase:new Jolt.DefaultBroadPhaseLayerFilter(world.jolt.GetObjectVsBroadPhaseLayerFilter(),LAYER),
179
+ object:new Jolt.DefaultObjectLayerFilter(world.jolt.GetObjectLayerPairFilter(),LAYER),
180
+ body:new Jolt.BodyFilter(),
181
+ shape:new Jolt.ShapeFilter()
182
+ };
183
+ }
184
+ function destroyQueryFilters(Jolt,filters){
185
+ Jolt.destroy(filters.shape); Jolt.destroy(filters.body); Jolt.destroy(filters.object); Jolt.destroy(filters.broadPhase);
186
+ }
187
+
188
+ export class JoltPhysicsBackend extends PhysicsBackend {
189
+ constructor({gravity={x:0,y:-9.81,z:0}}={}){
190
+ super('jolt',['rigid-body','collision','scene-query','articulated-body','joints','character-controller'],{
191
+ executionModes:['realtime','validation-only'],
192
+ qualities:{realtime:true,deterministic:true}
193
+ });
194
+ this.gravity=gravity;
195
+ this.Jolt=null;
196
+ }
197
+
198
+ async init(){ this.Jolt=await loadJolt(); return this; }
199
+
200
+ createWorld(){
201
+ if(!this.Jolt) throw new Error('JoltPhysicsBackend.init() must complete before createWorld()');
202
+ const Jolt=this.Jolt;
203
+ const objectFilter=new Jolt.ObjectLayerPairFilterTable(1);
204
+ objectFilter.EnableCollision(LAYER,LAYER);
205
+ const broadPhaseLayer=new Jolt.BroadPhaseLayer(0);
206
+ const broadPhaseInterface=new Jolt.BroadPhaseLayerInterfaceTable(1,1);
207
+ broadPhaseInterface.MapObjectToBroadPhaseLayer(LAYER,broadPhaseLayer);
208
+ Jolt.destroy(broadPhaseLayer);
209
+ const broadPhaseFilter=new Jolt.ObjectVsBroadPhaseLayerFilterTable(broadPhaseInterface,1,objectFilter,1);
210
+ const settings=new Jolt.JoltSettings();
211
+ settings.mObjectLayerPairFilter=objectFilter;
212
+ settings.mBroadPhaseLayerInterface=broadPhaseInterface;
213
+ settings.mObjectVsBroadPhaseLayerFilter=broadPhaseFilter;
214
+ const jolt=new Jolt.JoltInterface(settings);
215
+ Jolt.destroy(settings);
216
+ const physicsSystem=jolt.GetPhysicsSystem();
217
+ const gravity=new Jolt.Vec3(this.gravity.x,this.gravity.y,this.gravity.z);
218
+ physicsSystem.SetGravity(gravity);
219
+ Jolt.destroy(gravity);
220
+ return {
221
+ jolt,physicsSystem,bodyInterface:physicsSystem.GetBodyInterface(),
222
+ bodies:new Map(),colliders:new Map(),joints:new Map(),
223
+ nextColliderKey:1,nextJointKey:1,nextSubGroupId:1,disabledJointPairs:new Map(),
224
+ groupFilter:null,groupFilterCapacity:0
225
+ };
226
+ }
227
+
228
+ step(world,dt){
229
+ for(const body of world.bodies.values()){
230
+ if(!body.nextPose) continue;
231
+ const pose=body.nextPose;
232
+ body.nextPose=null;
233
+ this.setBodyPose(body,{position:pose.position,rotation:pose.rotation,next:false,wake:true});
234
+ }
235
+ world.jolt.Step(dt,1);
236
+ }
237
+
238
+ debugSnapshot(world,{nativeGeometry=true}={}){
239
+ return {
240
+ backend:this.identity,
241
+ // The production Jolt build does not expose its optional DebugRenderer.
242
+ // Normalized body/collider/joint state is supplied by PhysicsSystem.
243
+ nativeGeometry:null,
244
+ metrics:{ bodyCount:world?.bodies?.size ?? 0, colliderCount:world?.colliders?.size ?? 0, jointCount:world?.joints?.size ?? 0 },
245
+ nativeGeometryAvailable:false,
246
+ nativeGeometryRequested:Boolean(nativeGeometry)
247
+ };
248
+ }
249
+
250
+ dispose(world){
251
+ if(!world) return;
252
+ for(const joint of [...world.joints.values()]) this._removeJoint(world,joint);
253
+ for(const body of [...world.bodies.values()]) this.removeBody(world,body);
254
+ this.Jolt.destroy(world.jolt);
255
+ world.bodies.clear(); world.colliders.clear(); world.joints.clear(); world.disabledJointPairs.clear();
256
+ world.groupFilter=null; world.groupFilterCapacity=0;
257
+ }
258
+
259
+ createBody(world,{type='fixed',position=ZERO,rotation=IDENTITY,canSleep=true,lockTranslation=null,lockRotation=null}={}){
260
+ const Jolt=this.Jolt;
261
+ const empty=new Jolt.EmptyShape();
262
+ const p=new Jolt.RVec3(...position);
263
+ const q=new Jolt.Quat(...rotation);
264
+ const settings=new Jolt.BodyCreationSettings(empty,p,q,motionType(Jolt,type),LAYER);
265
+ if(type==='dynamic') settings.mAllowedDOFs=allowedDofs(Jolt,lockTranslation,lockRotation);
266
+ const subGroupId=world.nextSubGroupId++;
267
+ Jolt.destroy(p); Jolt.destroy(q);
268
+ const native=world.bodyInterface.CreateBody(settings);
269
+ if(type==='dynamic') native.SetAllowSleeping(Boolean(canSleep));
270
+ Jolt.destroy(settings);
271
+ world.bodyInterface.AddBody(native.GetID(),activation(Jolt,type!=='fixed'));
272
+ const body={kind:'jolt-body',world,native,key:native.GetID().GetIndexAndSequenceNumber(),subGroupId,colliders:[],nextPose:null,collisionFilter:null};
273
+ world.bodies.set(body.key,body);
274
+ if(world.groupFilter) this._rebuildGroupFilter(world,subGroupId+1);
275
+ return body;
276
+ }
277
+
278
+ removeBody(world,body){
279
+ if(!body || !world.bodies.has(body.key)) return;
280
+ for(const joint of [...world.joints.values()]) if(joint.parentBody===body||joint.childBody===body) this._removeJoint(world,joint);
281
+ for(const collider of body.colliders) {
282
+ destroyOwnedShape(collider.nativeShape);
283
+ world.colliders.delete(collider.key);
284
+ }
285
+ const id=body.native.GetID();
286
+ if(world.bodyInterface.IsAdded(id)) world.bodyInterface.RemoveBody(id);
287
+ world.bodyInterface.DestroyBody(id);
288
+ body.colliders.length=0;
289
+ world.bodies.delete(body.key);
290
+ }
291
+
292
+ createColliders(world,body,specs=[],{mass,friction,restitution}={}){
293
+ const Jolt=this.Jolt;
294
+ const semantic=specs.map((spec,index)=>{
295
+ const record={
296
+ kind:'jolt-collider',body,index,key:world.nextColliderKey++,spec:cloneSpec(spec),
297
+ nativeShape:createOwnedShape(Jolt,spec,index+1)
298
+ };
299
+ return record;
300
+ });
301
+ let bodyShape;
302
+ try { bodyShape=createBodyShape(Jolt,specs); }
303
+ catch(error){ for(const collider of semantic) destroyOwnedShape(collider.nativeShape); throw error; }
304
+
305
+ try {
306
+ world.bodyInterface.SetShape(body.native.GetID(),bodyShape,true,activation(Jolt,true));
307
+ } finally { destroyOwnedShape(bodyShape); }
308
+
309
+ for(const old of body.colliders){ destroyOwnedShape(old.nativeShape); world.colliders.delete(old.key); }
310
+ body.colliders=semantic;
311
+ for(const collider of semantic) world.colliders.set(collider.key,collider);
312
+
313
+ if(friction!=null) world.bodyInterface.SetFriction(body.native.GetID(),friction);
314
+ if(restitution!=null) world.bodyInterface.SetRestitution(body.native.GetID(),restitution);
315
+ if(mass!=null && mass>0 && this.bodyType(body)==='dynamic') body.native.GetMotionProperties()?.ScaleToMass(mass);
316
+ return [...semantic];
317
+ }
318
+
319
+ colliders(body){ return body ? [...body.colliders] : []; }
320
+ bodyKey(body){ return body?.key ?? null; }
321
+ colliderKey(collider){ return collider?.key ?? null; }
322
+ colliderParent(collider){ return collider?.body ?? null; }
323
+
324
+ colliderSnapshot(collider){
325
+ if(!collider) return null;
326
+ const pose=worldPoseForCollider(this.bodyPose(collider.body),collider);
327
+ return {
328
+ ref:collider,key:collider.key,parent:collider.body,
329
+ position:{x:pose.position[0],y:pose.position[1],z:pose.position[2]},
330
+ rotation:{x:pose.rotation[0],y:pose.rotation[1],z:pose.rotation[2],w:pose.rotation[3]},
331
+ shape:shapeDescription(collider.spec),shapeRef:collider
332
+ };
333
+ }
334
+
335
+ bodyType(body){ return semanticMotionType(this.Jolt,body.world.bodyInterface.GetMotionType(body.native.GetID())); }
336
+ setBodyType(body,type){ body.world.bodyInterface.SetMotionType(body.native.GetID(),motionType(this.Jolt,type),activation(this.Jolt,true)); return true; }
337
+
338
+ bodyPose(body,{next=false}={}){
339
+ if(next && body.nextPose) return {position:[...body.nextPose.position],rotation:[...body.nextPose.rotation]};
340
+ return {position:array3(body.native.GetPosition()),rotation:array4(body.native.GetRotation())};
341
+ }
342
+
343
+ setBodyPose(body,{position=null,rotation=null,next=false,wake=true}={}){
344
+ if(!body) return false;
345
+ const current=next&&body.nextPose ? body.nextPose : this.bodyPose(body);
346
+ const target={position:position ? (Array.isArray(position)?[...position]:[position.x,position.y,position.z]) : [...current.position],
347
+ rotation:rotation ? (Array.isArray(rotation)?[...rotation]:[rotation.x,rotation.y,rotation.z,rotation.w]) : [...current.rotation]};
348
+ if(next){ body.nextPose=target; return true; }
349
+ const Jolt=this.Jolt;
350
+ const p=new Jolt.RVec3(...target.position);
351
+ const q=new Jolt.Quat(...target.rotation);
352
+ try { body.world.bodyInterface.SetPositionAndRotation(body.native.GetID(),p,q,activation(Jolt,wake)); }
353
+ finally { Jolt.destroy(q); Jolt.destroy(p); }
354
+ body.nextPose=null;
355
+ return true;
356
+ }
357
+
358
+ translateBody(body,delta,{clearLinearVelocity=true,wake=true}={}){
359
+ const pose=this.bodyPose(body);
360
+ this.setBodyPose(body,{position:[pose.position[0]+delta[0],pose.position[1]+delta[1],pose.position[2]+delta[2]],wake});
361
+ if(clearLinearVelocity) this.clearBodyMotion(body,{linear:true,angular:false,wake});
362
+ return true;
363
+ }
364
+
365
+ clearBodyMotion(body,{wake=false,linear=true,angular=true}={}){
366
+ const Jolt=this.Jolt;
367
+ if(linear) withVec3(Jolt,ZERO,(v)=>body.world.bodyInterface.SetLinearVelocity(body.native.GetID(),v));
368
+ if(angular) withVec3(Jolt,ZERO,(v)=>body.world.bodyInterface.SetAngularVelocity(body.native.GetID(),v));
369
+ if(wake) this.wakeBody(body);
370
+ return true;
371
+ }
372
+
373
+ bodyMotion(body){
374
+ const linear=body.world.bodyInterface.GetLinearVelocity(body.native.GetID());
375
+ const angular=body.world.bodyInterface.GetAngularVelocity(body.native.GetID());
376
+ const lv=array3(linear),av=array3(angular);
377
+ return {
378
+ sleeping:!body.world.bodyInterface.IsActive(body.native.GetID()),
379
+ linearVelocity:lv,angularVelocity:av,
380
+ linearSpeed:Math.hypot(...lv),angularSpeed:Math.hypot(...av)
381
+ };
382
+ }
383
+ setBodyMotion(body,{linearVelocity=null,angularVelocity=null,wake=true}={}){
384
+ if(!body || this.bodyType(body)!=='dynamic') return false;
385
+ const Jolt=this.Jolt,id=body.native.GetID();
386
+ if(linearVelocity) withVec3(Jolt,linearVelocity,(v)=>body.world.bodyInterface.SetLinearVelocity(id,v));
387
+ if(angularVelocity) withVec3(Jolt,angularVelocity,(v)=>body.world.bodyInterface.SetAngularVelocity(id,v));
388
+ if(wake) this.wakeBody(body);
389
+ return true;
390
+ }
391
+ applyImpulse(body,impulse,{point=null,wake=true}={}){
392
+ if(!body || this.bodyType(body)!=='dynamic') return false;
393
+ const Jolt=this.Jolt,id=body.native.GetID();
394
+ if(point){
395
+ const impulseVec=new Jolt.Vec3(...impulse),position=new Jolt.RVec3(...point);
396
+ try { body.world.bodyInterface.AddImpulse(id,impulseVec,position); }
397
+ finally { Jolt.destroy(position); Jolt.destroy(impulseVec); }
398
+ } else withVec3(Jolt,impulse,(v)=>body.world.bodyInterface.AddImpulse(id,v));
399
+ if(wake) this.wakeBody(body);
400
+ return true;
401
+ }
402
+ applyForce(body,force,{point=null,wake=true}={}){
403
+ if(!body || this.bodyType(body)!=='dynamic') return false;
404
+ const Jolt=this.Jolt,id=body.native.GetID(),mode=activation(Jolt,wake);
405
+ if(point){
406
+ const forceVec=new Jolt.Vec3(...force),position=new Jolt.RVec3(...point);
407
+ try { body.world.bodyInterface.AddForce(id,forceVec,position,mode); }
408
+ finally { Jolt.destroy(position); Jolt.destroy(forceVec); }
409
+ } else withVec3(Jolt,force,(v)=>body.world.bodyInterface.AddForce(id,v,mode));
410
+ return true;
411
+ }
412
+ applyTorque(body,torque,{wake=true}={}){
413
+ if(!body || this.bodyType(body)!=='dynamic') return false;
414
+ const Jolt=this.Jolt,id=body.native.GetID();
415
+ withVec3(Jolt,torque,(v)=>body.world.bodyInterface.AddTorque(id,v,activation(Jolt,wake)));
416
+ return true;
417
+ }
418
+ setBodyMaterial(body,{friction=null,restitution=null}={}){
419
+ if(!body) return false;
420
+ const api=body.world.bodyInterface,id=body.native.GetID();
421
+ if(friction!=null) api.SetFriction(id,friction);
422
+ if(restitution!=null) api.SetRestitution(id,restitution);
423
+ return true;
424
+ }
425
+ setBodyDynamics(body,{linearDamping=null,angularDamping=null,gravityScale=null,wake=true}={}){
426
+ if(!body || this.bodyType(body)!=='dynamic') return false;
427
+ const motion=body.native.GetMotionProperties?.();
428
+ if(linearDamping!=null) motion?.SetLinearDamping(linearDamping);
429
+ if(angularDamping!=null) motion?.SetAngularDamping(angularDamping);
430
+ if(gravityScale!=null) body.world.bodyInterface.SetGravityFactor(body.native.GetID(),gravityScale);
431
+ if(wake) this.wakeBody(body);
432
+ return true;
433
+ }
434
+ setBodyCcd(body,enabled){
435
+ if(!body || this.bodyType(body)!=='dynamic') return false;
436
+ body.world.bodyInterface.SetMotionQuality(body.native.GetID(),enabled ? this.Jolt.EMotionQuality_LinearCast : this.Jolt.EMotionQuality_Discrete);
437
+ return true;
438
+ }
439
+ setBodySensor(body,enabled){
440
+ if(!body) return false;
441
+ body.world.bodyInterface.SetIsSensor(body.native.GetID(),Boolean(enabled));
442
+ return true;
443
+ }
444
+ setBodyCollisionFilter(body,filter=null){
445
+ if(!body) return false;
446
+ body.collisionFilter=filter ? {membership:filter.membership & 0xffff,filter:filter.filter & 0xffff} : null;
447
+ this._rebuildGroupFilter(body.world,body.world.nextSubGroupId+1);
448
+ return true;
449
+ }
450
+ sleepBody(body){ if(!body || this.bodyType(body)!=='dynamic') return false; body.world.bodyInterface.DeactivateBody(body.native.GetID()); return true; }
451
+ wakeBody(body){ body?.world.bodyInterface.ActivateBody(body.native.GetID()); return Boolean(body); }
452
+
453
+ _assignCollisionGroup(world,body){
454
+ if(!world.groupFilter||!body) return;
455
+ const group=new this.Jolt.CollisionGroup(world.groupFilter,1,body.subGroupId);
456
+ try { world.bodyInterface.SetCollisionGroup(body.native.GetID(),group); }
457
+ finally { this.Jolt.destroy(group); }
458
+ }
459
+
460
+ _bodyPairAllowed(world,left,right){
461
+ if(world.disabledJointPairs.has(pairKey(left.subGroupId,right.subGroupId))) return false;
462
+ const a=left.collisionFilter || {membership:0xffff,filter:0xffff};
463
+ const b=right.collisionFilter || {membership:0xffff,filter:0xffff};
464
+ return (a.membership & b.filter)!==0 && (b.membership & a.filter)!==0;
465
+ }
466
+
467
+ _rebuildGroupFilter(world,requiredCapacity=0){
468
+ let capacity=Math.max(16,world.groupFilterCapacity||0);
469
+ while(capacity<Math.max(requiredCapacity,world.nextSubGroupId+1)) capacity*=2;
470
+ const filter=new this.Jolt.GroupFilterTable(capacity);
471
+ const bodies=[...world.bodies.values()];
472
+ for(let i=0;i<bodies.length;i++) for(let j=i+1;j<bodies.length;j++) {
473
+ if(!this._bodyPairAllowed(world,bodies[i],bodies[j])) filter.DisableCollision(bodies[i].subGroupId,bodies[j].subGroupId);
474
+ }
475
+ world.groupFilter=filter;
476
+ world.groupFilterCapacity=capacity;
477
+ for(const body of bodies) this._assignCollisionGroup(world,body);
478
+ }
479
+
480
+ _jointWorldFrame(parentBody,childBody,part){
481
+ const parentPose=this.bodyPose(parentBody);
482
+ const childPose=this.bodyPose(childBody);
483
+ const parentAnchor=tuple3(part.joint.parentAnchor||ZERO);
484
+ const childAnchor=tuple3(part.joint.childAnchor||ZERO);
485
+ const parentOffset=rotateVector(parentPose.rotation,parentAnchor);
486
+ const childOffset=rotateVector(childPose.rotation,childAnchor);
487
+ const axis=normalized3(rotateVector(parentPose.rotation,part.joint.axis||[1,0,0]));
488
+ return {
489
+ parentPoint:[parentPose.position[0]+parentOffset[0],parentPose.position[1]+parentOffset[1],parentPose.position[2]+parentOffset[2]],
490
+ childPoint:[childPose.position[0]+childOffset[0],childPose.position[1]+childOffset[1],childPose.position[2]+childOffset[2]],
491
+ axis,normal:perpendicular3(axis)
492
+ };
493
+ }
494
+
495
+ createJoint(world,part,parentBody,childBody){
496
+ const Jolt=this.Jolt;
497
+ const frame=this._jointWorldFrame(parentBody,childBody,part);
498
+ const childPose=this.bodyPose(childBody);
499
+ let settings,native,type;
500
+ if(part.joint.type==='revolute'){
501
+ settings=new Jolt.HingeConstraintSettings(); type='revolute';
502
+ settings.mSpace=Jolt.EConstraintSpace_WorldSpace;
503
+ settings.mPoint1.Set(...frame.parentPoint); settings.mPoint2.Set(...frame.childPoint);
504
+ settings.mHingeAxis1.Set(...frame.axis); settings.mHingeAxis2.Set(...frame.axis);
505
+ settings.mNormalAxis1.Set(...frame.normal); settings.mNormalAxis2.Set(...frame.normal);
506
+ if(part.joint.limits){ settings.mLimitsMin=part.joint.limits[0]; settings.mLimitsMax=part.joint.limits[1]; }
507
+ native=Jolt.castObject(settings.Create(parentBody.native,childBody.native),Jolt.HingeConstraint);
508
+ } else if(part.joint.type==='prismatic'){
509
+ settings=new Jolt.SliderConstraintSettings(); type='prismatic';
510
+ settings.mSpace=Jolt.EConstraintSpace_WorldSpace;
511
+ settings.mAutoDetectPoint=false;
512
+ settings.mPoint1.Set(...frame.parentPoint); settings.mPoint2.Set(...frame.childPoint);
513
+ settings.mSliderAxis1.Set(...frame.axis); settings.mSliderAxis2.Set(...frame.axis);
514
+ settings.mNormalAxis1.Set(...frame.normal); settings.mNormalAxis2.Set(...frame.normal);
515
+ if(part.joint.limits){ settings.mLimitsMin=part.joint.limits[0]; settings.mLimitsMax=part.joint.limits[1]; }
516
+ native=Jolt.castObject(settings.Create(parentBody.native,childBody.native),Jolt.SliderConstraint);
517
+ } else if(part.joint.type==='fixed'){
518
+ settings=new Jolt.FixedConstraintSettings(); type='fixed';
519
+ settings.mSpace=Jolt.EConstraintSpace_WorldSpace;
520
+ settings.mAutoDetectPoint=false;
521
+ settings.mPoint1.Set(...frame.parentPoint); settings.mPoint2.Set(...frame.childPoint);
522
+ const axisX=normalized3(rotateVector(childPose.rotation,[1,0,0]));
523
+ const axisY=normalized3(rotateVector(childPose.rotation,[0,1,0]));
524
+ settings.mAxisX1.Set(...axisX); settings.mAxisX2.Set(...axisX);
525
+ settings.mAxisY1.Set(...axisY); settings.mAxisY2.Set(...axisY);
526
+ native=settings.Create(parentBody.native,childBody.native);
527
+ } else {
528
+ throw new TypeError(`JoltPhysicsBackend unsupported joint type: ${part.joint.type}`);
529
+ }
530
+ Jolt.destroy(settings);
531
+ world.physicsSystem.AddConstraint(native);
532
+ const joint={kind:'jolt-joint',key:world.nextJointKey++,type,native,parentBody,childBody,pair:pairKey(parentBody.subGroupId,childBody.subGroupId)};
533
+ world.joints.set(joint.key,joint);
534
+ const pairCount=world.disabledJointPairs.get(joint.pair)||0;
535
+ world.disabledJointPairs.set(joint.pair,pairCount+1);
536
+ this._rebuildGroupFilter(world,Math.max(parentBody.subGroupId,childBody.subGroupId)+1);
537
+ return joint;
538
+ }
539
+
540
+ _removeJoint(world,joint){
541
+ if(!joint || !world.joints.has(joint.key)) return;
542
+ // AddConstraint() owns the constraint reference. We never AddRef() here,
543
+ // so RemoveConstraint() must be the only release path. Calling Release()
544
+ // again corrupts Jolt ownership and can crash later during DestroyBody().
545
+ world.physicsSystem.RemoveConstraint(joint.native);
546
+ world.joints.delete(joint.key);
547
+ const count=(world.disabledJointPairs.get(joint.pair)||1)-1;
548
+ if(count<=0) world.disabledJointPairs.delete(joint.pair);
549
+ else world.disabledJointPairs.set(joint.pair,count);
550
+ if(world.groupFilter) this._rebuildGroupFilter(world);
551
+ }
552
+
553
+ setJointTarget(joint,target,{stiffness=40,damping=8}={}){
554
+ if(!joint || joint.type==='fixed') return false;
555
+ const Jolt=this.Jolt;
556
+ if(target == null) { joint.native.SetMotorState(Jolt.EMotorState_Off); return true; }
557
+ const motor=joint.native.GetMotorSettings();
558
+ motor.mSpringSettings.mMode=Jolt.ESpringMode_StiffnessAndDamping;
559
+ motor.mSpringSettings.mStiffness=stiffness;
560
+ motor.mSpringSettings.mDamping=damping;
561
+ joint.native.SetMotorState(Jolt.EMotorState_Position);
562
+ if(joint.type==='revolute') joint.native.SetTargetAngle(target);
563
+ else if(joint.type==='prismatic') joint.native.SetTargetPosition(target);
564
+ else return false;
565
+ this.wakeBody(joint.parentBody); this.wakeBody(joint.childBody);
566
+ return true;
567
+ }
568
+
569
+ createCharacterController(world,{
570
+ offset=.02,autostepHeight=.3,autostepMinWidth=.2,snapToGround=.3,
571
+ maxSlopeClimbAngle=Math.PI/4,minSlopeSlideAngle=Math.PI/6
572
+ }={}){
573
+ return {
574
+ kind:'jolt-character-controller',world,
575
+ offset,autostepHeight,autostepMinWidth,snapToGround,maxSlopeClimbAngle,minSlopeSlideAngle
576
+ };
577
+ }
578
+
579
+ removeCharacterController(){ /* Stateless adapter: CharacterVirtual instances are per-move. */ }
580
+
581
+ cancelCharacterMovement(body){
582
+ const pose=this.bodyPose(body);
583
+ if(!pose) return false;
584
+ return this.setBodyPose(body,{...pose,next:true});
585
+ }
586
+
587
+ _characterSupportRadius(collider){
588
+ const shape=collider?.spec;
589
+ if(!shape) return .1;
590
+ if(shape.shape==='capsule'||shape.shape==='cylinder') return Math.max(.01,shape.radius||.1);
591
+ if(shape.shape==='box') return Math.max(.01,Math.min(shape.halfExtents?.[0]||.1,shape.halfExtents?.[2]||.1));
592
+ if(shape.shape==='convexHull'&&shape.vertices?.length){
593
+ let radius=Infinity;
594
+ for(let i=0;i<shape.vertices.length;i+=3) radius=Math.min(radius,Math.hypot(shape.vertices[i],shape.vertices[i+2]));
595
+ return Number.isFinite(radius)&&radius>1e-3?radius:.1;
596
+ }
597
+ return .1;
598
+ }
599
+
600
+ moveCharacter(controller,body,desiredTranslation,{predicate=null}={}){
601
+ if(!controller||controller.world!==body?.world||this.bodyType(body)!=='kinematic'){
602
+ return {success:false,code:'CHARACTER_BODY_UNAVAILABLE',movement:[0,0,0],grounded:false,collisions:[]};
603
+ }
604
+ const colliders=this.colliders(body);
605
+ if(colliders.length!==1){
606
+ return {success:false,code:'CHARACTER_BODY_UNAVAILABLE',movement:[0,0,0],grounded:false,collisions:[]};
607
+ }
608
+
609
+ const Jolt=this.Jolt,world=body.world,pose=this.bodyPose(body);
610
+ const settings=new Jolt.CharacterVirtualSettings();
611
+ settings.mMass=1000;
612
+ settings.mMaxSlopeAngle=controller.maxSlopeClimbAngle;
613
+ settings.mMaxStrength=100;
614
+ settings.mShape=body.native.GetShape();
615
+ settings.mCharacterPadding=controller.offset;
616
+ settings.mPredictiveContactDistance=Math.max(.05,controller.offset*2);
617
+ const up=new Jolt.Vec3(0,1,0);
618
+ const supportingVolume=new Jolt.Plane(up,-this._characterSupportRadius(colliders[0]));
619
+ settings.mSupportingVolume=supportingVolume;
620
+ const position=new Jolt.RVec3(...pose.position);
621
+ const rotation=new Jolt.Quat(...pose.rotation);
622
+ const character=new Jolt.CharacterVirtual(settings,position,rotation,world.physicsSystem);
623
+ Jolt.destroy(rotation); Jolt.destroy(position); Jolt.destroy(supportingVolume); Jolt.destroy(up); Jolt.destroy(settings);
624
+
625
+ const update=new Jolt.ExtendedUpdateSettings();
626
+ update.mStickToFloorStepDown.Set(0,-controller.snapToGround,0);
627
+ update.mWalkStairsStepUp.Set(0,controller.autostepHeight,0);
628
+ update.mWalkStairsMinStepForward=controller.autostepMinWidth;
629
+ update.mWalkStairsStepForwardTest=Math.max(.05,controller.autostepMinWidth);
630
+ update.mWalkStairsStepDownExtra.Set(0,-Math.min(controller.snapToGround,.1),0);
631
+
632
+ const bpFilter=new Jolt.DefaultBroadPhaseLayerFilter(world.jolt.GetObjectVsBroadPhaseLayerFilter(),LAYER);
633
+ const objectFilter=new Jolt.DefaultObjectLayerFilter(world.jolt.GetObjectLayerPairFilter(),LAYER);
634
+ const bodyFilter=new Jolt.IgnoreMultipleBodiesFilter();
635
+ bodyFilter.IgnoreBody(body.native.GetID());
636
+ if(predicate){
637
+ for(const otherBody of world.bodies.values()){
638
+ if(otherBody===body||!otherBody.colliders.length) continue;
639
+ if(otherBody.colliders.every((collider)=>!predicate(collider))) bodyFilter.IgnoreBody(otherBody.native.GetID());
640
+ }
641
+ }
642
+ const shapeFilter=new Jolt.ShapeFilter();
643
+ const zeroGravity=new Jolt.Vec3(0,0,0);
644
+ const velocity=new Jolt.Vec3(...tuple3(desiredTranslation));
645
+ character.SetLinearVelocity(velocity);
646
+ Jolt.destroy(velocity);
647
+
648
+ try {
649
+ character.ExtendedUpdate(1,zeroGravity,update,bpFilter,objectFilter,bodyFilter,shapeFilter,world.jolt.GetTempAllocator());
650
+ if(controller.snapToGround>0){
651
+ const stepDown=new Jolt.Vec3(0,-controller.snapToGround,0);
652
+ try { character.StickToFloor(stepDown,bpFilter,objectFilter,bodyFilter,shapeFilter,world.jolt.GetTempAllocator()); }
653
+ finally { Jolt.destroy(stepDown); }
654
+ }
655
+ character.RefreshContacts(bpFilter,objectFilter,bodyFilter,shapeFilter,world.jolt.GetTempAllocator());
656
+ const resultPosition=character.GetPosition();
657
+ const next=[resultPosition.GetX(),resultPosition.GetY(),resultPosition.GetZ()];
658
+ const movement=[next[0]-pose.position[0],next[1]-pose.position[1],next[2]-pose.position[2]];
659
+ const collisions=[];
660
+ const contacts=character.GetActiveContacts();
661
+ for(let index=0;index<contacts.size();index++){
662
+ const contact=contacts.at(index);
663
+ const collider=this._colliderFromHit(world,contact.mBodyB,contact.mSubShapeIDB);
664
+ if(!collider||collider.body===body||(predicate&&!predicate(collider))) continue;
665
+ const normal=contact.mContactNormal;
666
+ collisions.push({
667
+ collider,colliderKey:this.colliderKey(collider),
668
+ toi:Number.isFinite(contact.mFraction)?contact.mFraction:0,
669
+ normal:[normal.GetX(),normal.GetY(),normal.GetZ()]
670
+ });
671
+ }
672
+ this.setBodyPose(body,{position:next,rotation:pose.rotation,next:true});
673
+ return {
674
+ success:true,movement,
675
+ grounded:character.GetGroundState()===Jolt.EGroundState_OnGround,
676
+ collisions
677
+ };
678
+ } finally {
679
+ Jolt.destroy(zeroGravity); Jolt.destroy(shapeFilter); Jolt.destroy(bodyFilter); Jolt.destroy(objectFilter); Jolt.destroy(bpFilter); Jolt.destroy(update); character.Release();
680
+ }
681
+ }
682
+
683
+ syncSceneQueries(){ /* Jolt BodyInterface updates broadphase on pose/shape changes. */ }
684
+
685
+ createQueryShape(spec){ return {kind:'jolt-query-shape',spec:cloneSpec(spec),nativeShape:createOwnedShape(this.Jolt,spec)}; }
686
+ disposeQueryShape(shape){ if(shape?.kind==='jolt-query-shape'){ destroyOwnedShape(shape.nativeShape); shape.nativeShape=null; } }
687
+
688
+ _nativeShape(ref){
689
+ if(ref?.kind==='jolt-collider' || ref?.kind==='jolt-query-shape') return ref.nativeShape;
690
+ throw new TypeError('JoltPhysicsBackend requires a Jolt semantic shape handle');
691
+ }
692
+
693
+ _colliderFromHit(world,bodyId,subShapeId){
694
+ const body=world.bodies.get(nativeBodyIdNumber(bodyId));
695
+ if(!body || !body.colliders.length) return null;
696
+ if(body.colliders.length===1) return body.colliders[0];
697
+ const userData=body.native.GetShape().GetSubShapeUserData(subShapeId);
698
+ return body.colliders[userData-1] || null;
699
+ }
700
+
701
+ _allShapeHits(world,shapeRef,position,rotation,{maxSeparationDistance=0}={}){
702
+ const Jolt=this.Jolt;
703
+ const nativeShape=this._nativeShape(shapeRef);
704
+ const scale=new Jolt.Vec3(...UNIT);
705
+ const transform=createTransform(Jolt,position,rotation);
706
+ const settings=new Jolt.CollideShapeSettings();
707
+ settings.mMaxSeparationDistance=maxSeparationDistance;
708
+ const baseOffset=new Jolt.RVec3(...ZERO);
709
+ const collector=new Jolt.CollideShapeAllHitCollisionCollector();
710
+ const filters=createQueryFilters(Jolt,world);
711
+ try {
712
+ world.physicsSystem.GetNarrowPhaseQuery().CollideShape(
713
+ nativeShape,scale,transform,settings,baseOffset,collector,
714
+ filters.broadPhase,filters.object,filters.body,filters.shape
715
+ );
716
+ const hits=[];
717
+ if(collector.HadHit()){
718
+ for(let i=0;i<collector.mHits.size();i++){
719
+ const hit=collector.mHits.at(i);
720
+ hits.push({
721
+ collider:this._colliderFromHit(world,hit.mBodyID2,hit.mSubShapeID2),
722
+ penetrationDepth:hit.mPenetrationDepth,
723
+ normal:array3(hit.mPenetrationAxis)
724
+ });
725
+ }
726
+ }
727
+ return hits;
728
+ } finally {
729
+ destroyQueryFilters(Jolt,filters); Jolt.destroy(collector); Jolt.destroy(baseOffset); Jolt.destroy(settings); Jolt.destroy(transform); Jolt.destroy(scale);
730
+ }
731
+ }
732
+
733
+ intersectionsWithShape(world,position,rotation,shape,callback,{excludeCollider=null,excludeBody=null,predicate=null}={}){
734
+ const seen=new Set();
735
+ for(const hit of this._allShapeHits(world,shape,position,rotation)){
736
+ const collider=hit.collider;
737
+ if(!collider || seen.has(collider.key)) continue;
738
+ seen.add(collider.key);
739
+ if(excludeCollider && collider.key===excludeCollider.key) continue;
740
+ if(excludeBody && collider.body.key===excludeBody.key) continue;
741
+ if(predicate && !predicate(collider)) continue;
742
+ if(callback(collider)===false) break;
743
+ }
744
+ }
745
+
746
+ castCollider(world,source,velocity,{excludeCollider=null,excludeBody=null,predicate=null,maxToi=1}={}){
747
+ const Jolt=this.Jolt;
748
+ const sourcePose=this.colliderSnapshot(source);
749
+ const scale=new Jolt.Vec3(...UNIT);
750
+ const transform=createTransform(Jolt,[sourcePose.position.x,sourcePose.position.y,sourcePose.position.z],sourcePose.rotation);
751
+ const direction=new Jolt.Vec3(velocity[0],velocity[1],velocity[2]);
752
+ const cast=new Jolt.RShapeCast(source.nativeShape,scale,transform,direction);
753
+ const settings=new Jolt.ShapeCastSettings();
754
+ const baseOffset=new Jolt.RVec3(...ZERO);
755
+ const collector=new Jolt.CastShapeAllHitCollisionCollector();
756
+ const filters=createQueryFilters(Jolt,world);
757
+ try {
758
+ world.physicsSystem.GetNarrowPhaseQuery().CastShape(cast,settings,baseOffset,collector,filters.broadPhase,filters.object,filters.body,filters.shape);
759
+ let best=null;
760
+ if(collector.HadHit()){
761
+ for(let i=0;i<collector.mHits.size();i++){
762
+ const hit=collector.mHits.at(i);
763
+ if(hit.mFraction<0 || hit.mFraction>maxToi) continue;
764
+ const collider=this._colliderFromHit(world,hit.mBodyID2,hit.mSubShapeID2);
765
+ if(!collider || collider.key===source.key) continue;
766
+ if(excludeCollider && collider.key===excludeCollider.key) continue;
767
+ if(excludeBody && collider.body.key===excludeBody.key) continue;
768
+ if(predicate && !predicate(collider)) continue;
769
+ if(!best || hit.mFraction<best.timeOfImpact) best={collider,timeOfImpact:hit.mFraction};
770
+ }
771
+ }
772
+ return best;
773
+ } finally {
774
+ destroyQueryFilters(Jolt,filters); Jolt.destroy(collector); Jolt.destroy(baseOffset); Jolt.destroy(settings); Jolt.destroy(cast); Jolt.destroy(direction); Jolt.destroy(transform); Jolt.destroy(scale);
775
+ }
776
+ }
777
+
778
+ raycast(world,origin,direction,maxDistance,{predicate=null}={}){
779
+ const Jolt=this.Jolt;
780
+ const length=Math.hypot(direction[0],direction[1],direction[2]);
781
+ if(length<=1e-12 || maxDistance<=0) return null;
782
+ const ray=new Jolt.RRayCast();
783
+ ray.mOrigin.Set(origin[0],origin[1],origin[2]);
784
+ ray.mDirection.Set(direction[0]/length*maxDistance,direction[1]/length*maxDistance,direction[2]/length*maxDistance);
785
+ const settings=new Jolt.RayCastSettings();
786
+ const collector=new Jolt.CastRayAllHitCollisionCollector();
787
+ const filters=createQueryFilters(Jolt,world);
788
+ try {
789
+ world.physicsSystem.GetNarrowPhaseQuery().CastRay(ray,settings,collector,filters.broadPhase,filters.object,filters.body,filters.shape);
790
+ let best=null;
791
+ if(collector.HadHit()){
792
+ for(let i=0;i<collector.mHits.size();i++){
793
+ const hit=collector.mHits.at(i);
794
+ const collider=this._colliderFromHit(world,hit.mBodyID,hit.mSubShapeID2);
795
+ if(!collider || (predicate && !predicate(collider))) continue;
796
+ const toi=hit.mFraction*maxDistance;
797
+ if(!best || toi<best.timeOfImpact) best={collider,timeOfImpact:toi};
798
+ }
799
+ }
800
+ return best;
801
+ } finally { destroyQueryFilters(Jolt,filters); Jolt.destroy(collector); Jolt.destroy(settings); Jolt.destroy(ray); }
802
+ }
803
+
804
+ contactPairs(world,source){
805
+ const pose=this.colliderSnapshot(source);
806
+ const hits=this._allShapeHits(world,source,[pose.position.x,pose.position.y,pose.position.z],pose.rotation,{maxSeparationDistance:1e-4});
807
+ const byCollider=new Map();
808
+ for(const hit of hits){
809
+ const other=hit.collider;
810
+ if(!other || other.body.key===source.body.key || other.key===source.key) continue;
811
+ if(source.body.world.disabledJointPairs.has(pairKey(source.body.subGroupId,other.body.subGroupId))) continue;
812
+ const previous=byCollider.get(other.key);
813
+ if(!previous || hit.penetrationDepth>previous.penetrationDepth) byCollider.set(other.key,hit);
814
+ }
815
+ return [...byCollider.values()].map((hit)=>({
816
+ other:hit.collider,manifoldCount:1,contactCount:1,activeContactCount:1,
817
+ minDistance:hit.penetrationDepth>0 ? -hit.penetrationDepth : 0,totalImpulse:null,normal:hit.normal,
818
+ evidenceKind:'geometric-contact',impulseAvailable:false
819
+ }));
820
+ }
821
+
822
+ penetrations(world,source){
823
+ const pose=this.colliderSnapshot(source);
824
+ return this._allShapeHits(world,source,[pose.position.x,pose.position.y,pose.position.z],pose.rotation)
825
+ .filter((hit)=>hit.collider && hit.collider.body.key!==source.body.key && hit.penetrationDepth>0)
826
+ .map((hit)=>({other:hit.collider,distance:-hit.penetrationDepth}));
827
+ }
828
+
829
+ shapesIntersect(leftShape,leftPosition,leftRotation,rightShape,rightPosition,rightRotation){
830
+ const Jolt=this.Jolt;
831
+ const transformed=new Jolt.TransformedShape();
832
+ transformed.set_mShape(this._nativeShape(rightShape));
833
+ const rightPositionNative=new Jolt.RVec3(...rightPosition);
834
+ const rightRotationNative=new Jolt.Quat(...(Array.isArray(rightRotation)?rightRotation:[rightRotation.x,rightRotation.y,rightRotation.z,rightRotation.w]));
835
+ const scale=new Jolt.Vec3(...UNIT);
836
+ transformed.SetWorldTransform(rightPositionNative,rightRotationNative,scale);
837
+ const leftRotationArray=Array.isArray(leftRotation)?leftRotation:[leftRotation.x,leftRotation.y,leftRotation.z,leftRotation.w];
838
+ const leftTransform=createTransform(Jolt,leftPosition,leftRotationArray);
839
+ const settings=new Jolt.CollideShapeSettings();
840
+ const baseOffset=new Jolt.RVec3(...ZERO);
841
+ const collector=new Jolt.CollideShapeAnyHitCollisionCollector();
842
+ const shapeFilter=new Jolt.ShapeFilter();
843
+ try {
844
+ transformed.CollideShape(this._nativeShape(leftShape),scale,leftTransform,settings,baseOffset,collector,shapeFilter);
845
+ return collector.HadHit();
846
+ } finally {
847
+ Jolt.destroy(shapeFilter); Jolt.destroy(collector); Jolt.destroy(baseOffset); Jolt.destroy(settings); Jolt.destroy(leftTransform); Jolt.destroy(scale); Jolt.destroy(rightRotationNative); Jolt.destroy(rightPositionNative); Jolt.destroy(transformed);
848
+ }
849
+ }
850
+ }