agentscape3d 1.0.0-beta.1 → 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 (386) hide show
  1. package/README.md +23 -48
  2. package/dist/core.d.ts +68 -0
  3. package/dist/core.js +209 -0
  4. package/dist/core.js.map +1 -0
  5. package/dist/index.d.ts +10 -229
  6. package/dist/index.js +192 -15462
  7. package/dist/index.js.map +1 -1
  8. package/package.json +11 -40
  9. package/cli.mjs +0 -27
  10. package/dist/AssetCompiler-CDFiElji.js +0 -2451
  11. package/dist/AssetCompiler-CDFiElji.js.map +0 -1
  12. package/dist/AssetInputContracts-Dy8iU4eT.js +0 -228
  13. package/dist/AssetInputContracts-Dy8iU4eT.js.map +0 -1
  14. package/dist/AssetRecipe-DmFpzxr-.js +0 -55
  15. package/dist/AssetRecipe-DmFpzxr-.js.map +0 -1
  16. package/dist/BrowserCodeWorker.js +0 -53615
  17. package/dist/KinematicHypothesisScreen-D-z6qgMB.js +0 -242
  18. package/dist/KinematicHypothesisScreen-D-z6qgMB.js.map +0 -1
  19. package/dist/SceneSerializer-DPVOyeRk.js +0 -353
  20. package/dist/SceneSerializer-DPVOyeRk.js.map +0 -1
  21. package/dist/StylePack-DNrdLeGI.js +0 -6314
  22. package/dist/StylePack-DNrdLeGI.js.map +0 -1
  23. package/dist/WorldArchive-pSBIGxLa.js +0 -420
  24. package/dist/WorldArchive-pSBIGxLa.js.map +0 -1
  25. package/dist/WorldIO-wsDfZGM4.js +0 -150
  26. package/dist/WorldIO-wsDfZGM4.js.map +0 -1
  27. package/dist/blankWorld-CBWbwJGj.js +0 -76
  28. package/dist/blankWorld-CBWbwJGj.js.map +0 -1
  29. package/dist/disposeObject3D-BQ9TyVC_.js +0 -54
  30. package/dist/disposeObject3D-BQ9TyVC_.js.map +0 -1
  31. package/dist/environments-DgH66NqV.js +0 -4220
  32. package/dist/environments-DgH66NqV.js.map +0 -1
  33. package/dist/gltfIO-B87nJaat.js +0 -10
  34. package/dist/gltfIO-B87nJaat.js.map +0 -1
  35. package/dist/grandUrbanBlock-Ob9pN-CB.js +0 -516
  36. package/dist/grandUrbanBlock-Ob9pN-CB.js.map +0 -1
  37. package/dist/magicCabin-D64fD1E2.js +0 -11024
  38. package/dist/magicCabin-D64fD1E2.js.map +0 -1
  39. package/dist/mcp.d.ts +0 -2
  40. package/dist/mcp.js +0 -1
  41. package/dist/monumentHall-BKbs0UOQ.js +0 -404
  42. package/dist/monumentHall-BKbs0UOQ.js.map +0 -1
  43. package/dist/node.d.ts +0 -16
  44. package/dist/node.js +0 -25
  45. package/dist/ruinedCourtyard-BoZxHldu.js +0 -697
  46. package/dist/ruinedCourtyard-BoZxHldu.js.map +0 -1
  47. package/dist/runtime/application/AgentTools.js +0 -25
  48. package/dist/runtime/application/README.md +0 -14
  49. package/dist/runtime/application/buildTaskObservation.js +0 -117
  50. package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +0 -46
  51. package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +0 -35
  52. package/dist/runtime/application/code-execution/BrowserCodeWorker.js +0 -17
  53. package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +0 -72
  54. package/dist/runtime/application/createSession.js +0 -66
  55. package/dist/runtime/application/createWorldAuthoringContext.js +0 -400
  56. package/dist/runtime/application/generation/GenerationOrchestrator.js +0 -629
  57. package/dist/runtime/application/generation/GenerationRuntime.js +0 -214
  58. package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +0 -285
  59. package/dist/runtime/application/native-scene/CodeProject.js +0 -119
  60. package/dist/runtime/application/native-scene/CodeProjectModules.js +0 -128
  61. package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +0 -62
  62. package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +0 -127
  63. package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +0 -51
  64. package/dist/runtime/application/native-scene/NativeSceneHost.js +0 -164
  65. package/dist/runtime/application/native-scene/NativeSceneOverlay.js +0 -116
  66. package/dist/runtime/application/native-scene/NativeThreeModule.js +0 -16
  67. package/dist/runtime/application/object-forge/SceneObjectForge.js +0 -232
  68. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +0 -54
  69. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +0 -22
  70. package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +0 -40
  71. package/dist/runtime/application/scene/CapabilityResolver.js +0 -79
  72. package/dist/runtime/application/scene/RequestWindow.js +0 -54
  73. package/dist/runtime/application/scene/SceneAgentTools.js +0 -21
  74. package/dist/runtime/application/scene/SceneContracts.js +0 -45
  75. package/dist/runtime/application/scene/SceneEditService.js +0 -144
  76. package/dist/runtime/application/scene/SceneFacade.js +0 -267
  77. package/dist/runtime/application/scene/SceneInteractionAdapters.js +0 -40
  78. package/dist/runtime/application/scene/SceneJobController.js +0 -229
  79. package/dist/runtime/application/scene/ScenePackage.js +0 -162
  80. package/dist/runtime/application/scene/ScenePersistence.js +0 -50
  81. package/dist/runtime/application/scene/SceneProject.js +0 -95
  82. package/dist/runtime/application/scene/SceneSkillNames.js +0 -5
  83. package/dist/runtime/application/scene/StarterScene.js +0 -56
  84. package/dist/runtime/application/scene/WorldArchive.js +0 -87
  85. package/dist/runtime/application/scene/WorldDirectory.js +0 -20
  86. package/dist/runtime/application/scene/WorldDocument.js +0 -74
  87. package/dist/runtime/application/scene/WorldIO.js +0 -103
  88. package/dist/runtime/application/scene/WorldStorage.js +0 -137
  89. package/dist/runtime/application/skills/SkillRegistry.js +0 -163
  90. package/dist/runtime/application/skills/packs/acceptanceSkills.js +0 -32
  91. package/dist/runtime/application/skills/packs/affordanceSkills.js +0 -36
  92. package/dist/runtime/application/skills/packs/assetSkills.js +0 -46
  93. package/dist/runtime/application/skills/packs/authoringSkills.js +0 -16
  94. package/dist/runtime/application/skills/packs/batchSkills.js +0 -22
  95. package/dist/runtime/application/skills/packs/codeSkills.js +0 -106
  96. package/dist/runtime/application/skills/packs/generationSkills.js +0 -45
  97. package/dist/runtime/application/skills/packs/interactionSkills.js +0 -46
  98. package/dist/runtime/application/skills/packs/recoverySkills.js +0 -80
  99. package/dist/runtime/application/skills/packs/sceneSkills.js +0 -24
  100. package/dist/runtime/application/skills/packs/spatialSkills.js +0 -35
  101. package/dist/runtime/application/skills/packs/verificationSkills.js +0 -14
  102. package/dist/runtime/application/skills/packs/worldSkills.js +0 -45
  103. package/dist/runtime/application/skills/registerCoreSkills.js +0 -31
  104. package/dist/runtime/application/skills/skillPrimitives.js +0 -4
  105. package/dist/runtime/application/tasks/CabinetCupTask.js +0 -76
  106. package/dist/runtime/application/tasks.jsonl +0 -67
  107. package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +0 -42
  108. package/dist/runtime/application/world-authoring/AuthoringDiff.js +0 -149
  109. package/dist/runtime/application/world-authoring/AuthoringDocument.js +0 -825
  110. package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +0 -109
  111. package/dist/runtime/application/world-authoring/AuthoringIdentity.js +0 -17
  112. package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +0 -29
  113. package/dist/runtime/application/world-authoring/AuthoringPatch.js +0 -118
  114. package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +0 -334
  115. package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +0 -126
  116. package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +0 -144
  117. package/dist/runtime/application/world-authoring/HeadlessImageExport.js +0 -174
  118. package/dist/runtime/application/world-authoring/ModelRef.js +0 -62
  119. package/dist/runtime/apps/mcp-server/AUTHORING.md +0 -71
  120. package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +0 -1
  121. package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +0 -30
  122. package/dist/runtime/apps/mcp-server/BuildEnvironment.js +0 -17
  123. package/dist/runtime/apps/mcp-server/CodeExecutor.js +0 -71
  124. package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +0 -42
  125. package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +0 -66
  126. package/dist/runtime/apps/mcp-server/FileAssetRepository.js +0 -159
  127. package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +0 -8
  128. package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +0 -47
  129. package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +0 -132
  130. package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +0 -6
  131. package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +0 -116
  132. package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +0 -60
  133. package/dist/runtime/apps/mcp-server/README.md +0 -150
  134. package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +0 -1
  135. package/dist/runtime/apps/mcp-server/SandboxBundle.js +0 -13
  136. package/dist/runtime/apps/mcp-server/SessionManager.js +0 -80
  137. package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +0 -58
  138. package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +0 -190
  139. package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +0 -16
  140. package/dist/runtime/apps/mcp-server/VALIDATION.md +0 -45
  141. package/dist/runtime/apps/mcp-server/acceptance-evidence.json +0 -332
  142. package/dist/runtime/apps/mcp-server/errorDiagnostics.js +0 -32
  143. package/dist/runtime/apps/mcp-server/examples/code-house.js +0 -24
  144. package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +0 -37
  145. package/dist/runtime/apps/mcp-server/main.mjs +0 -56
  146. package/dist/runtime/apps/mcp-server/registerTools.js +0 -215
  147. package/dist/runtime/apps/mcp-server/sandbox/run.mjs +0 -23
  148. package/dist/runtime/apps/mcp-server/security.js +0 -21
  149. package/dist/runtime/apps/mcp-server/tasks.jsonl +0 -9
  150. package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +0 -157
  151. package/dist/runtime/apps/server/README.md +0 -7
  152. package/dist/runtime/apps/server/WorldDiskStorage.js +0 -51
  153. package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +0 -278
  154. package/dist/runtime/apps/server/tasks.jsonl +0 -10
  155. package/dist/runtime/foundation/EventBus.js +0 -18
  156. package/dist/runtime/foundation/JsonGateway.js +0 -47
  157. package/dist/runtime/foundation/PolicyEngine.js +0 -21
  158. package/dist/runtime/foundation/README.md +0 -7
  159. package/dist/runtime/foundation/TraceRecorder.js +0 -76
  160. package/dist/runtime/foundation/errors.js +0 -8
  161. package/dist/runtime/foundation/simulation/SimulationProfile.js +0 -143
  162. package/dist/runtime/foundation/version.js +0 -2
  163. package/dist/runtime/modules/agent/README.md +0 -11
  164. package/dist/runtime/modules/agent/ToolCallingAgent.js +0 -19
  165. package/dist/runtime/modules/agent/bootstrapWorld.js +0 -10
  166. package/dist/runtime/modules/agent/buildRecoveryProposals.js +0 -533
  167. package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +0 -127
  168. package/dist/runtime/modules/agent/execution/AgentRunResults.js +0 -55
  169. package/dist/runtime/modules/agent/execution/AgentRunSession.js +0 -390
  170. package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +0 -39
  171. package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +0 -19
  172. package/dist/runtime/modules/agent/prompt/index.js +0 -46
  173. package/dist/runtime/modules/agent/tasks.jsonl +0 -94
  174. package/dist/runtime/modules/artifact/ArtifactContentGate.js +0 -144
  175. package/dist/runtime/modules/artifact/ArtifactDescriptor.js +0 -280
  176. package/dist/runtime/modules/artifact/ArtifactImporter.js +0 -185
  177. package/dist/runtime/modules/artifact/ArtifactModule.js +0 -111
  178. package/dist/runtime/modules/artifact/ArtifactRegistry.js +0 -197
  179. package/dist/runtime/modules/artifact/IncrementalSha256.js +0 -129
  180. package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +0 -115
  181. package/dist/runtime/modules/artifact/README.md +0 -7
  182. package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +0 -67
  183. package/dist/runtime/modules/artifact/tasks.jsonl +0 -31
  184. package/dist/runtime/modules/asset/AssetModule.js +0 -399
  185. package/dist/runtime/modules/asset/README.md +0 -54
  186. package/dist/runtime/modules/asset/loading/AssetLoader.js +0 -157
  187. package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +0 -61
  188. package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +0 -95
  189. package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +0 -33
  190. package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +0 -103
  191. package/dist/runtime/modules/asset/model/AssetInputContracts.js +0 -95
  192. package/dist/runtime/modules/asset/model/AssetRef.js +0 -12
  193. package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +0 -172
  194. package/dist/runtime/modules/asset/model/admission.js +0 -117
  195. package/dist/runtime/modules/asset/model/errors.js +0 -6
  196. package/dist/runtime/modules/asset/model/parts.js +0 -27
  197. package/dist/runtime/modules/asset/model/resourceBudget.js +0 -10
  198. package/dist/runtime/modules/asset/model/schema.js +0 -150
  199. package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +0 -78
  200. package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +0 -84
  201. package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +0 -86
  202. package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +0 -81
  203. package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +0 -272
  204. package/dist/runtime/modules/asset/production/AssetRecipe.js +0 -32
  205. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +0 -45
  206. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +0 -590
  207. package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +0 -173
  208. package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +0 -124
  209. package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +0 -56
  210. package/dist/runtime/modules/asset/production/compiler/gltfIO.js +0 -6
  211. package/dist/runtime/modules/asset/production/compiler/partGeometry.js +0 -74
  212. package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +0 -63
  213. package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +0 -48
  214. package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +0 -16
  215. package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +0 -30
  216. package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +0 -75
  217. package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +0 -20
  218. package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +0 -34
  219. package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +0 -32
  220. package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +0 -116
  221. package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +0 -84
  222. package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +0 -63
  223. package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +0 -16
  224. package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +0 -23
  225. package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +0 -50
  226. package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +0 -60
  227. package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +0 -93
  228. package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +0 -32
  229. package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +0 -55
  230. package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +0 -203
  231. package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +0 -43
  232. package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +0 -33
  233. package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +0 -60
  234. package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +0 -23
  235. package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +0 -198
  236. package/dist/runtime/modules/asset/registry/AssetCatalog.js +0 -72
  237. package/dist/runtime/modules/asset/registry/AssetRegistry.js +0 -51
  238. package/dist/runtime/modules/asset/registry/manifests/index.js +0 -173
  239. package/dist/runtime/modules/asset/tasks.jsonl +0 -87
  240. package/dist/runtime/modules/generation/README.md +0 -9
  241. package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +0 -45
  242. package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +0 -169
  243. package/dist/runtime/modules/generation/connector/ConnectorClient.js +0 -192
  244. package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +0 -167
  245. package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +0 -179
  246. package/dist/runtime/modules/generation/connector/ConnectorSession.js +0 -202
  247. package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +0 -239
  248. package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +0 -99
  249. package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +0 -91
  250. package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +0 -50
  251. package/dist/runtime/modules/generation/providers/ProviderRegistry.js +0 -304
  252. package/dist/runtime/modules/generation/tasks.jsonl +0 -35
  253. package/dist/runtime/modules/navigation/NavigationBackend.js +0 -17
  254. package/dist/runtime/modules/navigation/RecastNavigationBackend.js +0 -245
  255. package/dist/runtime/modules/physics/JoltPhysicsBackend.js +0 -850
  256. package/dist/runtime/modules/physics/PhysicsApiSurface.js +0 -651
  257. package/dist/runtime/modules/physics/PhysicsBackend.js +0 -88
  258. package/dist/runtime/modules/physics/RapierPhysicsBackend.js +0 -410
  259. package/dist/runtime/modules/rendering/README.md +0 -7
  260. package/dist/runtime/modules/rendering/RendererProbe.js +0 -153
  261. package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +0 -140
  262. package/dist/runtime/modules/rendering/createRenderer.js +0 -76
  263. package/dist/runtime/modules/rendering/disposeObject3D.js +0 -34
  264. package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +0 -74
  265. package/dist/runtime/modules/rendering/style/StylePack.js +0 -34
  266. package/dist/runtime/modules/rendering/style/StyleSystem.js +0 -173
  267. package/dist/runtime/modules/rendering/tasks.jsonl +0 -7
  268. package/dist/runtime/modules/world/README.md +0 -13
  269. package/dist/runtime/modules/world/build/WorldBuilder.js +0 -170
  270. package/dist/runtime/modules/world/compiler/PipelineEngine.js +0 -32
  271. package/dist/runtime/modules/world/compiler/WorldAdmission.js +0 -43
  272. package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +0 -68
  273. package/dist/runtime/modules/world/compiler/WorldCompilation.js +0 -157
  274. package/dist/runtime/modules/world/compiler/WorldComposer.js +0 -201
  275. package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +0 -76
  276. package/dist/runtime/modules/world/compiler/WorldRecompiler.js +0 -356
  277. package/dist/runtime/modules/world/compiler/WorldRetry.js +0 -75
  278. package/dist/runtime/modules/world/compiler/createWorldPipeline.js +0 -379
  279. package/dist/runtime/modules/world/content/blankWorld.js +0 -35
  280. package/dist/runtime/modules/world/content/environments.js +0 -84
  281. package/dist/runtime/modules/world/content/grandUrbanBlock.js +0 -189
  282. package/dist/runtime/modules/world/content/magic-cabin/README.md +0 -28
  283. package/dist/runtime/modules/world/content/magic-cabin/affordances.js +0 -64
  284. package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +0 -7078
  285. package/dist/runtime/modules/world/content/magic-cabin/lighting.js +0 -26
  286. package/dist/runtime/modules/world/content/magic-cabin/materials.js +0 -20
  287. package/dist/runtime/modules/world/content/magicCabin.js +0 -190
  288. package/dist/runtime/modules/world/content/monumentHall.js +0 -154
  289. package/dist/runtime/modules/world/content/ruinedCourtyard.js +0 -196
  290. package/dist/runtime/modules/world/content/suzhouGarden/README.md +0 -141
  291. package/dist/runtime/modules/world/content/suzhouGarden/index.js +0 -137
  292. package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +0 -491
  293. package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +0 -670
  294. package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +0 -578
  295. package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +0 -127
  296. package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +0 -642
  297. package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +0 -650
  298. package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +0 -280
  299. package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +0 -242
  300. package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +0 -215
  301. package/dist/runtime/modules/world/content/woodlandWorkshop.js +0 -192
  302. package/dist/runtime/modules/world/content/yuanmingyuan/README.md +0 -36
  303. package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +0 -351
  304. package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +0 -490
  305. package/dist/runtime/modules/world/content/yuanmingyuan/core.js +0 -505
  306. package/dist/runtime/modules/world/content/yuanmingyuan/index.js +0 -101
  307. package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +0 -435
  308. package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +0 -169
  309. package/dist/runtime/modules/world/content/yuanmingyuan/water.js +0 -245
  310. package/dist/runtime/modules/world/errors.js +0 -9
  311. package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +0 -50
  312. package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +0 -297
  313. package/dist/runtime/modules/world/runtime/CommandHistory.js +0 -80
  314. package/dist/runtime/modules/world/runtime/ObjectStore.js +0 -31
  315. package/dist/runtime/modules/world/runtime/ObjectTransform.js +0 -62
  316. package/dist/runtime/modules/world/runtime/ObservedEntity.js +0 -37
  317. package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +0 -207
  318. package/dist/runtime/modules/world/runtime/SceneSerializer.js +0 -246
  319. package/dist/runtime/modules/world/runtime/WorldAuthority.js +0 -41
  320. package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +0 -14
  321. package/dist/runtime/modules/world/runtime/WorldCommands.js +0 -502
  322. package/dist/runtime/modules/world/runtime/WorldObservation.js +0 -71
  323. package/dist/runtime/modules/world/runtime/WorldQueries.js +0 -340
  324. package/dist/runtime/modules/world/runtime/WorldRecovery.js +0 -78
  325. package/dist/runtime/modules/world/runtime/WorldRuntime.js +0 -649
  326. package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +0 -107
  327. package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +0 -130
  328. package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +0 -79
  329. package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +0 -195
  330. package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +0 -70
  331. package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +0 -115
  332. package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +0 -216
  333. package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +0 -214
  334. package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +0 -65
  335. package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +0 -222
  336. package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +0 -130
  337. package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +0 -57
  338. package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +0 -123
  339. package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +0 -120
  340. package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +0 -102
  341. package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +0 -89
  342. package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +0 -99
  343. package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +0 -269
  344. package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +0 -56
  345. package/dist/runtime/modules/world/runtime/spatial/ThreeBvhRuntime.js +0 -36
  346. package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +0 -728
  347. package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +0 -269
  348. package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +0 -469
  349. package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +0 -1657
  350. package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +0 -457
  351. package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +0 -284
  352. package/dist/runtime/modules/world/spec/WorldIR.js +0 -165
  353. package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +0 -86
  354. package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +0 -51
  355. package/dist/runtime/modules/world/spec/WorldRevision.js +0 -231
  356. package/dist/runtime/modules/world/spec/WorldSpec.js +0 -86
  357. package/dist/runtime/modules/world/tasks.jsonl +0 -530
  358. package/dist/runtime/modules/world/verification/ArticulationVerifier.js +0 -254
  359. package/dist/runtime/modules/world/verification/Finding.js +0 -105
  360. package/dist/runtime/modules/world/verification/InteractionEvidence.js +0 -69
  361. package/dist/runtime/modules/world/verification/RepairEngine.js +0 -49
  362. package/dist/runtime/modules/world/verification/WorldAcceptance.js +0 -158
  363. package/dist/runtime/modules/world/verification/WorldValidator.js +0 -65
  364. package/dist/runtime/package-lock.json +0 -6245
  365. package/dist/runtime/package.json +0 -91
  366. package/dist/runtime/public/assets/cabinet.glb +0 -0
  367. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
  368. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
  369. package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
  370. package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
  371. package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
  372. package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
  373. package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
  374. package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
  375. package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
  376. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
  377. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
  378. package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
  379. package/dist/schema-Dudvovhu.js +0 -364
  380. package/dist/schema-Dudvovhu.js.map +0 -1
  381. package/dist/suzhouGarden-BCx_JeV5.js +0 -6159
  382. package/dist/suzhouGarden-BCx_JeV5.js.map +0 -1
  383. package/dist/woodlandWorkshop-BGNWPNdK.js +0 -484
  384. package/dist/woodlandWorkshop-BGNWPNdK.js.map +0 -1
  385. package/dist/yuanmingyuan-DAIb1msO.js +0 -4962
  386. package/dist/yuanmingyuan-DAIb1msO.js.map +0 -1
@@ -1,850 +0,0 @@
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
- }