@woosh/meep-engine 2.138.19 → 2.139.0

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 (496) hide show
  1. package/package.json +2 -1
  2. package/src/core/collection/PairUint32Map.d.ts +100 -0
  3. package/src/core/collection/PairUint32Map.d.ts.map +1 -0
  4. package/src/core/collection/PairUint32Map.js +321 -0
  5. package/src/core/collection/Uint32Map.d.ts +119 -0
  6. package/src/core/collection/Uint32Map.d.ts.map +1 -0
  7. package/src/core/collection/Uint32Map.js +345 -0
  8. package/src/core/collection/array/array_shuffle.d.ts +10 -3
  9. package/src/core/collection/array/array_shuffle.d.ts.map +1 -1
  10. package/src/core/collection/array/array_shuffle.js +27 -22
  11. package/src/core/collection/heap/FibonacciHeap.d.ts +195 -0
  12. package/src/core/collection/heap/FibonacciHeap.d.ts.map +1 -0
  13. package/src/core/collection/heap/FibonacciHeap.js +586 -0
  14. package/src/core/collection/heap/Uint32Heap.js +1 -1
  15. package/src/core/collection/heap/Uint32Heap4.d.ts +169 -0
  16. package/src/core/collection/heap/Uint32Heap4.d.ts.map +1 -0
  17. package/src/core/collection/heap/Uint32Heap4.js +490 -0
  18. package/src/core/geom/3d/line/line3_closest_points_segment_segment.d.ts +27 -0
  19. package/src/core/geom/3d/line/line3_closest_points_segment_segment.d.ts.map +1 -0
  20. package/src/core/geom/3d/line/line3_closest_points_segment_segment.js +88 -0
  21. package/src/core/geom/3d/shape/BoxShape3D.d.ts +61 -0
  22. package/src/core/geom/3d/shape/BoxShape3D.d.ts.map +1 -0
  23. package/src/core/geom/3d/shape/BoxShape3D.js +158 -0
  24. package/src/core/geom/3d/shape/CapsuleShape3D.d.ts +11 -0
  25. package/src/core/geom/3d/shape/CapsuleShape3D.d.ts.map +1 -1
  26. package/src/core/geom/3d/shape/CapsuleShape3D.js +12 -0
  27. package/src/core/geom/3d/shape/UnitCubeShape3D.d.ts +37 -9
  28. package/src/core/geom/3d/shape/UnitCubeShape3D.d.ts.map +1 -1
  29. package/src/core/geom/3d/shape/UnitCubeShape3D.js +45 -98
  30. package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts +10 -0
  31. package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts.map +1 -1
  32. package/src/core/geom/3d/shape/UnitSphereShape3D.js +11 -0
  33. package/src/core/geom/3d/shape/util/shape3d_voxelize_to_grid.d.ts +61 -0
  34. package/src/core/geom/3d/shape/util/shape3d_voxelize_to_grid.d.ts.map +1 -0
  35. package/src/core/geom/3d/shape/util/shape3d_voxelize_to_grid.js +148 -0
  36. package/src/core/geom/3d/tetrahedra/compute_tetrahedral_mesh_from_surface.d.ts +39 -0
  37. package/src/core/geom/3d/tetrahedra/compute_tetrahedral_mesh_from_surface.d.ts.map +1 -0
  38. package/src/core/geom/3d/tetrahedra/compute_tetrahedral_mesh_from_surface.js +147 -0
  39. package/src/core/geom/3d/tetrahedra/compute_tetrahedron_quality.d.ts +15 -0
  40. package/src/core/geom/3d/tetrahedra/compute_tetrahedron_quality.d.ts.map +1 -0
  41. package/src/core/geom/3d/tetrahedra/compute_tetrahedron_quality.js +22 -0
  42. package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.d.ts +2 -0
  43. package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.d.ts.map +1 -0
  44. package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.js +673 -0
  45. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.d.ts +26 -0
  46. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.d.ts.map +1 -0
  47. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.js +222 -0
  48. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_around_edge.d.ts +34 -0
  49. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_around_edge.d.ts.map +1 -0
  50. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_around_edge.js +146 -0
  51. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_23.d.ts +36 -0
  52. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_23.d.ts.map +1 -0
  53. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_23.js +232 -0
  54. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_32.d.ts +33 -0
  55. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_32.d.ts.map +1 -0
  56. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_32.js +255 -0
  57. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.d.ts +68 -0
  58. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.d.ts.map +1 -0
  59. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.js +365 -0
  60. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.d.ts +31 -0
  61. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.d.ts.map +1 -0
  62. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.js +112 -0
  63. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.d.ts +22 -0
  64. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.d.ts.map +1 -0
  65. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.js +55 -0
  66. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_quality.d.ts +32 -0
  67. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_quality.d.ts.map +1 -0
  68. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_quality.js +66 -0
  69. package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.d.ts +22 -0
  70. package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.d.ts.map +1 -1
  71. package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.js +49 -0
  72. package/src/core/geom/3d/topology/struct/binary/BinaryTopology.d.ts +134 -0
  73. package/src/core/geom/3d/topology/struct/binary/BinaryTopology.d.ts.map +1 -1
  74. package/src/core/geom/3d/topology/struct/binary/BinaryTopology.js +276 -3
  75. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts +17 -0
  76. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts.map +1 -0
  77. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.js +135 -0
  78. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compact.d.ts +14 -0
  79. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compact.d.ts.map +1 -0
  80. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compact.js +177 -0
  81. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_face_decouple.d.ts.map +1 -1
  82. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_face_decouple.js +20 -4
  83. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.d.ts.map +1 -1
  84. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.js +5 -3
  85. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_create.d.ts.map +1 -1
  86. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_create.js +9 -0
  87. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_get_or_create.d.ts.map +1 -1
  88. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_get_or_create.js +21 -45
  89. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill.d.ts.map +1 -1
  90. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill.js +7 -1
  91. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.d.ts +8 -6
  92. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.d.ts.map +1 -1
  93. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.js +8 -6
  94. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_kill_short_edges.d.ts +22 -0
  95. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_kill_short_edges.d.ts.map +1 -0
  96. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_kill_short_edges.js +73 -0
  97. package/src/core/geom/3d/topology/struct/binary/io/vertex/bt_vertex_replace.d.ts.map +1 -1
  98. package/src/core/geom/3d/topology/struct/binary/io/vertex/bt_vertex_replace.js +51 -1
  99. package/src/core/geom/3d/topology/struct/binary/query/bt_edge_get.d.ts +10 -0
  100. package/src/core/geom/3d/topology/struct/binary/query/bt_edge_get.d.ts.map +1 -0
  101. package/src/core/geom/3d/topology/struct/binary/query/bt_edge_get.js +42 -0
  102. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.d.ts +28 -0
  103. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.d.ts.map +1 -0
  104. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.js +227 -0
  105. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_walk_boundary_loops.d.ts +13 -0
  106. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_walk_boundary_loops.d.ts.map +1 -0
  107. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_walk_boundary_loops.js +108 -0
  108. package/src/core/geom/3d/topology/struct/binary/query/bt_query_edge_is_boundary.d.ts +11 -0
  109. package/src/core/geom/3d/topology/struct/binary/query/bt_query_edge_is_boundary.d.ts.map +1 -0
  110. package/src/core/geom/3d/topology/struct/binary/query/bt_query_edge_is_boundary.js +20 -0
  111. package/src/core/geom/3d/triangle/triangle_mesh_compute_signed_volume.d.ts +20 -0
  112. package/src/core/geom/3d/triangle/triangle_mesh_compute_signed_volume.d.ts.map +1 -0
  113. package/src/core/geom/3d/triangle/triangle_mesh_compute_signed_volume.js +38 -0
  114. package/src/core/graph/csr/CSRGraph.d.ts +168 -0
  115. package/src/core/graph/csr/CSRGraph.d.ts.map +1 -0
  116. package/src/core/graph/csr/CSRGraph.js +319 -0
  117. package/src/core/graph/metis/cluster_mesh_metis.d.ts +12 -0
  118. package/src/core/graph/metis/cluster_mesh_metis.d.ts.map +1 -1
  119. package/src/core/graph/metis/cluster_mesh_metis.js +12 -0
  120. package/src/core/graph/metis/metis.d.ts +19 -0
  121. package/src/core/graph/metis/metis.d.ts.map +1 -1
  122. package/src/core/graph/metis/metis.js +20 -0
  123. package/src/core/graph/metis/metis_cluster_bs.d.ts +11 -0
  124. package/src/core/graph/metis/metis_cluster_bs.d.ts.map +1 -1
  125. package/src/core/graph/metis/metis_cluster_bs.js +11 -0
  126. package/src/core/graph/metis/metis_options.d.ts +17 -2
  127. package/src/core/graph/metis/metis_options.d.ts.map +1 -1
  128. package/src/core/graph/metis/metis_options.js +17 -2
  129. package/src/core/graph/metis/native/MetisGraph.d.ts +144 -0
  130. package/src/core/graph/metis/native/MetisGraph.d.ts.map +1 -0
  131. package/src/core/graph/metis/native/MetisGraph.js +212 -0
  132. package/src/core/graph/metis/native/bisection/BisectionScratch.d.ts +72 -0
  133. package/src/core/graph/metis/native/bisection/BisectionScratch.d.ts.map +1 -0
  134. package/src/core/graph/metis/native/bisection/BisectionScratch.js +101 -0
  135. package/src/core/graph/metis/native/bisection/bisect_graph.d.ts +37 -0
  136. package/src/core/graph/metis/native/bisection/bisect_graph.d.ts.map +1 -0
  137. package/src/core/graph/metis/native/bisection/bisect_graph.js +100 -0
  138. package/src/core/graph/metis/native/bisection/compute_2way_params.d.ts +15 -0
  139. package/src/core/graph/metis/native/bisection/compute_2way_params.d.ts.map +1 -0
  140. package/src/core/graph/metis/native/bisection/compute_2way_params.js +84 -0
  141. package/src/core/graph/metis/native/bisection/fm_2way.d.ts +30 -0
  142. package/src/core/graph/metis/native/bisection/fm_2way.d.ts.map +1 -0
  143. package/src/core/graph/metis/native/bisection/fm_2way.js +290 -0
  144. package/src/core/graph/metis/native/bisection/grow_bisection.d.ts +23 -0
  145. package/src/core/graph/metis/native/bisection/grow_bisection.d.ts.map +1 -0
  146. package/src/core/graph/metis/native/bisection/grow_bisection.js +137 -0
  147. package/src/core/graph/metis/native/bisection/split_graph_two_way.d.ts +28 -0
  148. package/src/core/graph/metis/native/bisection/split_graph_two_way.d.ts.map +1 -0
  149. package/src/core/graph/metis/native/bisection/split_graph_two_way.js +119 -0
  150. package/src/core/graph/metis/native/coarsen/coarsen_graph.d.ts +20 -0
  151. package/src/core/graph/metis/native/coarsen/coarsen_graph.d.ts.map +1 -0
  152. package/src/core/graph/metis/native/coarsen/coarsen_graph.js +94 -0
  153. package/src/core/graph/metis/native/coarsen/create_coarse_graph.d.ts +24 -0
  154. package/src/core/graph/metis/native/coarsen/create_coarse_graph.d.ts.map +1 -0
  155. package/src/core/graph/metis/native/coarsen/create_coarse_graph.js +158 -0
  156. package/src/core/graph/metis/native/coarsen/match_shem.d.ts +41 -0
  157. package/src/core/graph/metis/native/coarsen/match_shem.d.ts.map +1 -0
  158. package/src/core/graph/metis/native/coarsen/match_shem.js +175 -0
  159. package/src/core/graph/metis/native/initial/initial_kway_bfs.d.ts +24 -0
  160. package/src/core/graph/metis/native/initial/initial_kway_bfs.d.ts.map +1 -0
  161. package/src/core/graph/metis/native/initial/initial_kway_bfs.js +122 -0
  162. package/src/core/graph/metis/native/initial/initial_kway_recursive_bisection.d.ts +29 -0
  163. package/src/core/graph/metis/native/initial/initial_kway_recursive_bisection.d.ts.map +1 -0
  164. package/src/core/graph/metis/native/initial/initial_kway_recursive_bisection.js +170 -0
  165. package/src/core/graph/metis/native/metis_partition_kway.d.ts +41 -0
  166. package/src/core/graph/metis/native/metis_partition_kway.d.ts.map +1 -0
  167. package/src/core/graph/metis/native/metis_partition_kway.js +126 -0
  168. package/src/core/graph/metis/native/refine/IndexedFloatMaxHeap.d.ts +62 -0
  169. package/src/core/graph/metis/native/refine/IndexedFloatMaxHeap.d.ts.map +1 -0
  170. package/src/core/graph/metis/native/refine/IndexedFloatMaxHeap.js +261 -0
  171. package/src/core/graph/metis/native/refine/RefinementScratch.d.ts +45 -0
  172. package/src/core/graph/metis/native/refine/RefinementScratch.d.ts.map +1 -0
  173. package/src/core/graph/metis/native/refine/RefinementScratch.js +53 -0
  174. package/src/core/graph/metis/native/refine/compute_kway_params.d.ts +18 -0
  175. package/src/core/graph/metis/native/refine/compute_kway_params.d.ts.map +1 -0
  176. package/src/core/graph/metis/native/refine/compute_kway_params.js +138 -0
  177. package/src/core/graph/metis/native/refine/fm_kway.d.ts +63 -0
  178. package/src/core/graph/metis/native/refine/fm_kway.d.ts.map +1 -0
  179. package/src/core/graph/metis/native/refine/fm_kway.js +462 -0
  180. package/src/core/graph/metis/native/refine/project_kway.d.ts +22 -0
  181. package/src/core/graph/metis/native/refine/project_kway.d.ts.map +1 -0
  182. package/src/core/graph/metis/native/refine/project_kway.js +43 -0
  183. package/src/core/graph/metis/native/refine/refine_kway.d.ts +34 -0
  184. package/src/core/graph/metis/native/refine/refine_kway.d.ts.map +1 -0
  185. package/src/core/graph/metis/native/refine/refine_kway.js +43 -0
  186. package/src/core/math/linalg/eigen/matrix_householder_in_place.d.ts +2 -2
  187. package/src/core/math/linalg/eigen/matrix_householder_in_place.js +2 -2
  188. package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts +6 -4
  189. package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts.map +1 -1
  190. package/src/core/math/linalg/eigen/matrix_qr_in_place.js +69 -23
  191. package/src/engine/EngineHarness.d.ts +3 -1
  192. package/src/engine/EngineHarness.d.ts.map +1 -1
  193. package/src/engine/EngineHarness.js +6 -4
  194. package/src/engine/control/first-person/DESIGN.md +30 -6
  195. package/src/engine/control/first-person/DESIGN_EXTENSIONS.md +563 -0
  196. package/src/engine/control/first-person/FirstPersonPlayerController.d.ts +102 -9
  197. package/src/engine/control/first-person/FirstPersonPlayerController.d.ts.map +1 -1
  198. package/src/engine/control/first-person/FirstPersonPlayerController.js +38 -3
  199. package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts +533 -4
  200. package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts.map +1 -1
  201. package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.js +315 -6
  202. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts +220 -22
  203. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
  204. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +858 -241
  205. package/src/engine/control/first-person/TODO.md +127 -0
  206. package/src/engine/control/first-person/abilities/Ability.d.ts +101 -0
  207. package/src/engine/control/first-person/abilities/Ability.d.ts.map +1 -0
  208. package/src/engine/control/first-person/abilities/Ability.js +119 -0
  209. package/src/engine/control/first-person/abilities/AbilitySet.d.ts +86 -0
  210. package/src/engine/control/first-person/abilities/AbilitySet.d.ts.map +1 -0
  211. package/src/engine/control/first-person/abilities/AbilitySet.js +185 -0
  212. package/src/engine/control/first-person/abilities/LedgeGrab.d.ts +62 -0
  213. package/src/engine/control/first-person/abilities/LedgeGrab.d.ts.map +1 -0
  214. package/src/engine/control/first-person/abilities/LedgeGrab.js +199 -0
  215. package/src/engine/control/first-person/abilities/Mantle.d.ts +45 -0
  216. package/src/engine/control/first-person/abilities/Mantle.d.ts.map +1 -0
  217. package/src/engine/control/first-person/abilities/Mantle.js +188 -0
  218. package/src/engine/control/first-person/abilities/Slide.d.ts +33 -0
  219. package/src/engine/control/first-person/abilities/Slide.d.ts.map +1 -0
  220. package/src/engine/control/first-person/abilities/Slide.js +158 -0
  221. package/src/engine/control/first-person/abilities/WallJump.d.ts +45 -0
  222. package/src/engine/control/first-person/abilities/WallJump.d.ts.map +1 -0
  223. package/src/engine/control/first-person/abilities/WallJump.js +131 -0
  224. package/src/engine/control/first-person/abilities/WallRun.d.ts +44 -0
  225. package/src/engine/control/first-person/abilities/WallRun.d.ts.map +1 -0
  226. package/src/engine/control/first-person/abilities/WallRun.js +180 -0
  227. package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts +49 -0
  228. package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts.map +1 -0
  229. package/src/engine/control/first-person/composer/EyeOffsetStack.js +60 -0
  230. package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.d.ts +100 -0
  231. package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.d.ts.map +1 -0
  232. package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.js +133 -0
  233. package/src/engine/control/first-person/mastery/DecisionPoint.d.ts +10 -0
  234. package/src/engine/control/first-person/mastery/DecisionPoint.d.ts.map +1 -0
  235. package/src/engine/control/first-person/mastery/DecisionPoint.js +30 -0
  236. package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.d.ts +61 -0
  237. package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.d.ts.map +1 -0
  238. package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.js +109 -0
  239. package/src/engine/control/first-person/mastery/MasteryEvaluator.d.ts +40 -0
  240. package/src/engine/control/first-person/mastery/MasteryEvaluator.d.ts.map +1 -0
  241. package/src/engine/control/first-person/mastery/MasteryEvaluator.js +45 -0
  242. package/src/engine/control/first-person/mastery/MasteryScore.d.ts +68 -0
  243. package/src/engine/control/first-person/mastery/MasteryScore.d.ts.map +1 -0
  244. package/src/engine/control/first-person/mastery/MasteryScore.js +100 -0
  245. package/src/engine/control/first-person/mastery/MasterySet.d.ts +60 -0
  246. package/src/engine/control/first-person/mastery/MasterySet.d.ts.map +1 -0
  247. package/src/engine/control/first-person/mastery/MasterySet.js +86 -0
  248. package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.d.ts +58 -0
  249. package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.d.ts.map +1 -0
  250. package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.js +83 -0
  251. package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.d.ts +69 -0
  252. package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.d.ts.map +1 -0
  253. package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.js +109 -0
  254. package/src/engine/control/first-person/math/Spring.d.ts +56 -0
  255. package/src/engine/control/first-person/math/Spring.d.ts.map +1 -0
  256. package/src/engine/control/first-person/math/Spring.js +71 -0
  257. package/src/engine/control/first-person/math/computeLRCBreathRate.d.ts +26 -0
  258. package/src/engine/control/first-person/math/computeLRCBreathRate.d.ts.map +1 -0
  259. package/src/engine/control/first-person/math/computeLRCBreathRate.js +41 -0
  260. package/src/engine/control/first-person/math/computeMassRatios.d.ts +35 -0
  261. package/src/engine/control/first-person/math/computeMassRatios.d.ts.map +1 -0
  262. package/src/engine/control/first-person/math/computeMassRatios.js +44 -0
  263. package/src/engine/control/first-person/pose/FirstPersonPose.d.ts +31 -1
  264. package/src/engine/control/first-person/pose/FirstPersonPose.d.ts.map +1 -1
  265. package/src/engine/control/first-person/pose/FirstPersonPose.js +49 -3
  266. package/src/engine/control/first-person/pose/FirstPersonPosture.d.ts +7 -0
  267. package/src/engine/control/first-person/pose/FirstPersonPosture.d.ts.map +1 -0
  268. package/src/engine/control/first-person/pose/FirstPersonPosture.js +27 -0
  269. package/src/engine/control/first-person/prototype_first_person_controller.js +550 -119
  270. package/src/engine/control/first-person/sensors/FirstPersonSensors.d.ts +58 -0
  271. package/src/engine/control/first-person/sensors/FirstPersonSensors.d.ts.map +1 -0
  272. package/src/engine/control/first-person/sensors/FirstPersonSensors.js +77 -0
  273. package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts +80 -0
  274. package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts.map +1 -0
  275. package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.js +196 -0
  276. package/src/engine/control/first-person/test/buildTestPlayer.d.ts +20 -0
  277. package/src/engine/control/first-person/test/buildTestPlayer.d.ts.map +1 -0
  278. package/src/engine/control/first-person/test/buildTestPlayer.js +28 -0
  279. package/src/engine/ecs/EntityManager.d.ts +2 -2
  280. package/src/engine/ecs/EntityManager.d.ts.map +1 -1
  281. package/src/engine/ecs/EntityManager.js +13 -8
  282. package/src/engine/ecs/System.d.ts.map +1 -1
  283. package/src/engine/ecs/System.js +2 -2
  284. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -2
  285. package/src/engine/graphics/ecs/light/Light.d.ts.map +1 -1
  286. package/src/engine/graphics/ecs/light/Light.js +27 -0
  287. package/src/engine/graphics/ecs/light/LightSystem.js +1 -1
  288. package/src/engine/graphics/ecs/path/PathDisplaySystem.d.ts.map +1 -1
  289. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
  290. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +0 -2
  291. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -2
  292. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -2
  293. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -2
  294. package/src/engine/navigation/grid/find_path_on_grid_astar.d.ts.map +1 -1
  295. package/src/engine/navigation/grid/find_path_on_grid_astar.js +11 -2
  296. package/src/engine/navigation/mesh/bt_mesh_face_find_path.d.ts.map +1 -1
  297. package/src/engine/navigation/mesh/bt_mesh_face_find_path.js +11 -1
  298. package/src/engine/physics/PLAN.md +236 -0
  299. package/src/engine/physics/body/BodyStorage.d.ts +187 -0
  300. package/src/engine/physics/body/BodyStorage.d.ts.map +1 -0
  301. package/src/engine/physics/body/BodyStorage.js +427 -0
  302. package/src/engine/physics/broadphase/PairList.d.ts +62 -0
  303. package/src/engine/physics/broadphase/PairList.d.ts.map +1 -0
  304. package/src/engine/physics/broadphase/PairList.js +97 -0
  305. package/src/engine/physics/broadphase/aabb_transform_oriented.d.ts +30 -0
  306. package/src/engine/physics/broadphase/aabb_transform_oriented.d.ts.map +1 -0
  307. package/src/engine/physics/broadphase/aabb_transform_oriented.js +93 -0
  308. package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts +16 -0
  309. package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts.map +1 -0
  310. package/src/engine/physics/broadphase/compute_fat_world_aabb.js +61 -0
  311. package/src/engine/physics/broadphase/generate_pairs.d.ts +38 -0
  312. package/src/engine/physics/broadphase/generate_pairs.d.ts.map +1 -0
  313. package/src/engine/physics/broadphase/generate_pairs.js +101 -0
  314. package/src/engine/physics/contact/ManifoldStore.d.ts +226 -0
  315. package/src/engine/physics/contact/ManifoldStore.d.ts.map +1 -0
  316. package/src/engine/physics/contact/ManifoldStore.js +499 -0
  317. package/src/engine/physics/ecs/BodyKind.d.ts +23 -0
  318. package/src/engine/physics/ecs/BodyKind.d.ts.map +1 -0
  319. package/src/engine/physics/ecs/BodyKind.js +24 -0
  320. package/src/engine/physics/ecs/Collider.d.ts +98 -0
  321. package/src/engine/physics/ecs/Collider.d.ts.map +1 -0
  322. package/src/engine/physics/ecs/Collider.js +136 -0
  323. package/src/engine/physics/ecs/ColliderFlags.d.ts +14 -0
  324. package/src/engine/physics/ecs/ColliderFlags.d.ts.map +1 -0
  325. package/src/engine/physics/ecs/ColliderFlags.js +15 -0
  326. package/src/engine/physics/ecs/ColliderObserverSystem.d.ts +58 -0
  327. package/src/engine/physics/ecs/ColliderObserverSystem.d.ts.map +1 -0
  328. package/src/engine/physics/ecs/ColliderObserverSystem.js +103 -0
  329. package/src/engine/physics/ecs/ColliderSerializationAdapter.d.ts +25 -0
  330. package/src/engine/physics/ecs/ColliderSerializationAdapter.d.ts.map +1 -0
  331. package/src/engine/physics/ecs/ColliderSerializationAdapter.js +37 -0
  332. package/src/engine/physics/ecs/PhysicsEvents.d.ts +15 -0
  333. package/src/engine/physics/ecs/PhysicsEvents.d.ts.map +1 -0
  334. package/src/engine/physics/ecs/PhysicsEvents.js +16 -0
  335. package/src/engine/physics/ecs/PhysicsSystem.d.ts +520 -0
  336. package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -0
  337. package/src/engine/physics/ecs/PhysicsSystem.js +1159 -0
  338. package/src/engine/physics/ecs/RigidBody.d.ts +197 -0
  339. package/src/engine/physics/ecs/RigidBody.d.ts.map +1 -0
  340. package/src/engine/physics/ecs/RigidBody.js +240 -0
  341. package/src/engine/physics/ecs/RigidBodyFlags.d.ts +21 -0
  342. package/src/engine/physics/ecs/RigidBodyFlags.d.ts.map +1 -0
  343. package/src/engine/physics/ecs/RigidBodyFlags.js +22 -0
  344. package/src/engine/physics/ecs/RigidBodySerializationAdapter.d.ts +28 -0
  345. package/src/engine/physics/ecs/RigidBodySerializationAdapter.d.ts.map +1 -0
  346. package/src/engine/physics/ecs/RigidBodySerializationAdapter.js +81 -0
  347. package/src/engine/physics/ecs/SleepState.d.ts +11 -0
  348. package/src/engine/physics/ecs/SleepState.d.ts.map +1 -0
  349. package/src/engine/physics/ecs/SleepState.js +12 -0
  350. package/src/engine/physics/events/ContactEventBuffer.d.ts +46 -0
  351. package/src/engine/physics/events/ContactEventBuffer.d.ts.map +1 -0
  352. package/src/engine/physics/events/ContactEventBuffer.js +83 -0
  353. package/src/engine/physics/events/diff_manifolds.d.ts +25 -0
  354. package/src/engine/physics/events/diff_manifolds.d.ts.map +1 -0
  355. package/src/engine/physics/events/diff_manifolds.js +50 -0
  356. package/src/engine/physics/fluid/FluidField.d.ts +294 -16
  357. package/src/engine/physics/fluid/FluidField.d.ts.map +1 -1
  358. package/src/engine/physics/fluid/FluidField.js +510 -66
  359. package/src/engine/physics/fluid/FluidSimulator.d.ts +188 -5
  360. package/src/engine/physics/fluid/FluidSimulator.d.ts.map +1 -1
  361. package/src/engine/physics/fluid/FluidSimulator.js +455 -95
  362. package/src/engine/physics/fluid/SliceVisualiser.d.ts +29 -6
  363. package/src/engine/physics/fluid/SliceVisualiser.d.ts.map +1 -1
  364. package/src/engine/physics/fluid/SliceVisualiser.js +190 -165
  365. package/src/engine/physics/fluid/ecs/FluidComponent.d.ts +154 -0
  366. package/src/engine/physics/fluid/ecs/FluidComponent.d.ts.map +1 -0
  367. package/src/engine/physics/fluid/ecs/FluidComponent.js +238 -0
  368. package/src/engine/physics/fluid/ecs/FluidEffectorsComponent.d.ts +45 -0
  369. package/src/engine/physics/fluid/ecs/FluidEffectorsComponent.d.ts.map +1 -0
  370. package/src/engine/physics/fluid/ecs/FluidEffectorsComponent.js +89 -0
  371. package/src/engine/physics/fluid/ecs/FluidSystem.d.ts +107 -0
  372. package/src/engine/physics/fluid/ecs/FluidSystem.d.ts.map +1 -0
  373. package/src/engine/physics/fluid/ecs/FluidSystem.js +278 -0
  374. package/src/engine/physics/fluid/effector/AbstractFluidEffector.d.ts +62 -1
  375. package/src/engine/physics/fluid/effector/AbstractFluidEffector.d.ts.map +1 -1
  376. package/src/engine/physics/fluid/effector/AbstractFluidEffector.js +81 -6
  377. package/src/engine/physics/fluid/effector/GlobalFluidEffector.d.ts +17 -4
  378. package/src/engine/physics/fluid/effector/GlobalFluidEffector.d.ts.map +1 -1
  379. package/src/engine/physics/fluid/effector/GlobalFluidEffector.js +105 -12
  380. package/src/engine/physics/fluid/effector/ImpulseFluidEffector.d.ts +43 -0
  381. package/src/engine/physics/fluid/effector/ImpulseFluidEffector.d.ts.map +1 -0
  382. package/src/engine/physics/fluid/effector/ImpulseFluidEffector.js +210 -0
  383. package/src/engine/physics/fluid/effector/WakeFluidEffector.d.ts +62 -1
  384. package/src/engine/physics/fluid/effector/WakeFluidEffector.d.ts.map +1 -1
  385. package/src/engine/physics/fluid/effector/WakeFluidEffector.js +302 -8
  386. package/src/engine/physics/fluid/prototype.js +102 -91
  387. package/src/engine/physics/fluid/solver/optimal_sor_omega.d.ts +33 -0
  388. package/src/engine/physics/fluid/solver/optimal_sor_omega.d.ts.map +1 -0
  389. package/src/engine/physics/fluid/solver/optimal_sor_omega.js +41 -0
  390. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.d.ts +20 -5
  391. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.d.ts.map +1 -1
  392. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.js +60 -38
  393. package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.d.ts +25 -4
  394. package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.d.ts.map +1 -1
  395. package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.js +93 -73
  396. package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.d.ts +23 -0
  397. package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.d.ts.map +1 -0
  398. package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.js +60 -0
  399. package/src/engine/physics/fluid/solver/v3_grid_compute_divergence.d.ts +23 -0
  400. package/src/engine/physics/fluid/solver/v3_grid_compute_divergence.d.ts.map +1 -0
  401. package/src/engine/physics/fluid/solver/v3_grid_compute_divergence.js +68 -0
  402. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts +30 -0
  403. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts.map +1 -0
  404. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.js +66 -0
  405. package/src/engine/physics/fluid/solver/v3_grid_patch_edges_uniform.d.ts +26 -0
  406. package/src/engine/physics/fluid/solver/v3_grid_patch_edges_uniform.d.ts.map +1 -0
  407. package/src/engine/physics/fluid/solver/v3_grid_patch_edges_uniform.js +113 -0
  408. package/src/engine/physics/fluid/solver/v3_grid_shift_in_place.d.ts +30 -0
  409. package/src/engine/physics/fluid/solver/v3_grid_shift_in_place.d.ts.map +1 -0
  410. package/src/engine/physics/fluid/solver/v3_grid_shift_in_place.js +107 -0
  411. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts +49 -0
  412. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts.map +1 -0
  413. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.js +126 -0
  414. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts +93 -0
  415. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts.map +1 -0
  416. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.js +424 -0
  417. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.d.ts +20 -0
  418. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.d.ts.map +1 -0
  419. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.js +83 -0
  420. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts +26 -0
  421. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts.map +1 -0
  422. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.js +70 -0
  423. package/src/engine/physics/gjk/expanding_polytope_algorithm.d.ts.map +1 -1
  424. package/src/engine/physics/gjk/expanding_polytope_algorithm.js +8 -10
  425. package/src/engine/physics/inertia/world_inverse_inertia.d.ts +29 -0
  426. package/src/engine/physics/inertia/world_inverse_inertia.d.ts.map +1 -0
  427. package/src/engine/physics/inertia/world_inverse_inertia.js +79 -0
  428. package/src/engine/physics/integration/integrate_position.d.ts +16 -0
  429. package/src/engine/physics/integration/integrate_position.d.ts.map +1 -0
  430. package/src/engine/physics/integration/integrate_position.js +48 -0
  431. package/src/engine/physics/integration/integrate_velocity.d.ts +25 -0
  432. package/src/engine/physics/integration/integrate_velocity.d.ts.map +1 -0
  433. package/src/engine/physics/integration/integrate_velocity.js +79 -0
  434. package/src/engine/physics/integration/quat_integrate.d.ts +27 -0
  435. package/src/engine/physics/integration/quat_integrate.d.ts.map +1 -0
  436. package/src/engine/physics/integration/quat_integrate.js +62 -0
  437. package/src/engine/physics/island/IslandBuilder.d.ts +167 -0
  438. package/src/engine/physics/island/IslandBuilder.d.ts.map +1 -0
  439. package/src/engine/physics/island/IslandBuilder.js +411 -0
  440. package/src/engine/physics/island/union_find.d.ts +51 -0
  441. package/src/engine/physics/island/union_find.d.ts.map +1 -0
  442. package/src/engine/physics/island/union_find.js +76 -0
  443. package/src/engine/physics/narrowphase/PosedShape.d.ts +59 -0
  444. package/src/engine/physics/narrowphase/PosedShape.d.ts.map +1 -0
  445. package/src/engine/physics/narrowphase/PosedShape.js +110 -0
  446. package/src/engine/physics/narrowphase/box_box_manifold.d.ts +32 -0
  447. package/src/engine/physics/narrowphase/box_box_manifold.d.ts.map +1 -0
  448. package/src/engine/physics/narrowphase/box_box_manifold.js +543 -0
  449. package/src/engine/physics/narrowphase/capsule_contacts.d.ts +122 -0
  450. package/src/engine/physics/narrowphase/capsule_contacts.d.ts.map +1 -0
  451. package/src/engine/physics/narrowphase/capsule_contacts.js +508 -0
  452. package/src/engine/physics/narrowphase/narrowphase_step.d.ts +11 -0
  453. package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -0
  454. package/src/engine/physics/narrowphase/narrowphase_step.js +382 -0
  455. package/src/engine/physics/narrowphase/sphere_box_contact.d.ts +38 -0
  456. package/src/engine/physics/narrowphase/sphere_box_contact.d.ts.map +1 -0
  457. package/src/engine/physics/narrowphase/sphere_box_contact.js +130 -0
  458. package/src/engine/physics/narrowphase/sphere_sphere_contact.d.ts +26 -0
  459. package/src/engine/physics/narrowphase/sphere_sphere_contact.d.ts.map +1 -0
  460. package/src/engine/physics/narrowphase/sphere_sphere_contact.js +51 -0
  461. package/src/engine/physics/queries/PhysicsSurfacePoint.d.ts +83 -0
  462. package/src/engine/physics/queries/PhysicsSurfacePoint.d.ts.map +1 -0
  463. package/src/engine/physics/queries/PhysicsSurfacePoint.js +100 -0
  464. package/src/engine/physics/queries/raycast.d.ts +20 -0
  465. package/src/engine/physics/queries/raycast.d.ts.map +1 -0
  466. package/src/engine/physics/queries/raycast.js +249 -0
  467. package/src/engine/physics/solver/friction_cone.d.ts +16 -0
  468. package/src/engine/physics/solver/friction_cone.d.ts.map +1 -0
  469. package/src/engine/physics/solver/friction_cone.js +37 -0
  470. package/src/engine/physics/solver/solve_contacts.d.ts +36 -0
  471. package/src/engine/physics/solver/solve_contacts.d.ts.map +1 -0
  472. package/src/engine/physics/solver/solve_contacts.js +598 -0
  473. package/src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.d.ts +0 -34
  474. package/src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.d.ts.map +0 -1
  475. package/src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.js +0 -66
  476. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_calc_edges.d.ts +0 -2
  477. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_calc_edges.d.ts.map +0 -1
  478. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_calc_edges.js +0 -54
  479. package/src/core/geom/3d/topology/struct/binary/io/edge/get_or_create_edge_map.d.ts +0 -2
  480. package/src/core/geom/3d/topology/struct/binary/io/edge/get_or_create_edge_map.d.ts.map +0 -1
  481. package/src/core/geom/3d/topology/struct/binary/io/edge/get_or_create_edge_map.js +0 -26
  482. package/src/engine/ecs/components/Motion.d.ts +0 -21
  483. package/src/engine/ecs/components/Motion.d.ts.map +0 -1
  484. package/src/engine/ecs/components/Motion.js +0 -27
  485. package/src/engine/ecs/components/MotionSerializationAdapter.d.ts +0 -20
  486. package/src/engine/ecs/components/MotionSerializationAdapter.d.ts.map +0 -1
  487. package/src/engine/ecs/components/MotionSerializationAdapter.js +0 -26
  488. package/src/engine/ecs/systems/MotionSystem.d.ts +0 -9
  489. package/src/engine/ecs/systems/MotionSystem.d.ts.map +0 -1
  490. package/src/engine/ecs/systems/MotionSystem.js +0 -29
  491. package/src/engine/physics/fluid/Fluid.d.ts +0 -26
  492. package/src/engine/physics/fluid/Fluid.d.ts.map +0 -1
  493. package/src/engine/physics/fluid/Fluid.js +0 -221
  494. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_reverse.d.ts +0 -7
  495. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_reverse.d.ts.map +0 -1
  496. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_reverse.js +0 -8
@@ -0,0 +1,382 @@
1
+ import { body_id_index } from "../body/BodyStorage.js";
2
+ import { expanding_polytope_algorithm } from "../gjk/expanding_polytope_algorithm.js";
3
+ import { gjk } from "../gjk/gjk.js";
4
+ import { box_box_manifold, BOX_BOX_OUT_LENGTH } from "./box_box_manifold.js";
5
+ import {
6
+ CAPSULE_BOX_CONTACT_STRIDE,
7
+ CAPSULE_BOX_MAX_CONTACTS,
8
+ capsule_box_multi_contacts,
9
+ capsule_capsule_contact,
10
+ capsule_sphere_contact,
11
+ } from "./capsule_contacts.js";
12
+ import { PosedShape } from "./PosedShape.js";
13
+ import { sphere_box_contact } from "./sphere_box_contact.js";
14
+ import { sphere_sphere_contact } from "./sphere_sphere_contact.js";
15
+
16
+ const posed_a = new PosedShape();
17
+ const posed_b = new PosedShape();
18
+
19
+ const simplex_buf = new Float32Array(12);
20
+ const simplex_a = simplex_buf.subarray(0, 3);
21
+ const simplex_b = simplex_buf.subarray(3, 6);
22
+ const simplex_c = simplex_buf.subarray(6, 9);
23
+ const simplex_d = simplex_buf.subarray(9, 12);
24
+
25
+ const epa_result = new Float64Array(3);
26
+ const sphere_result = new Float64Array(4);
27
+ const closed_form_result = new Float64Array(10);
28
+ const box_manifold_result = new Float64Array(BOX_BOX_OUT_LENGTH);
29
+ const capsule_box_multi_result = new Float64Array(CAPSULE_BOX_MAX_CONTACTS * CAPSULE_BOX_CONTACT_STRIDE);
30
+
31
+ /**
32
+ * Candidate-contact stride: wax, way, waz, wbx, wby, wbz, nx, ny, nz, depth.
33
+ * @type {number}
34
+ */
35
+ const CANDIDATE_STRIDE = 10;
36
+
37
+ /**
38
+ * Maximum number of contacts emitted into the per-pair manifold after the
39
+ * reduction step. Mirrors {@link MAX_CONTACTS_PER_MANIFOLD} in ManifoldStore.
40
+ * @type {number}
41
+ */
42
+ const MAX_KEPT = 4;
43
+
44
+ /**
45
+ * Per body-pair scratch buffer for candidate contacts produced by the
46
+ * cross-product of A's colliders × B's colliders. Sized generously for
47
+ * typical compound bodies (each collider-pair contributes 1..4 contacts;
48
+ * 64 covers up to 4 colliders per body × 4 colliders × 4 contacts = 64).
49
+ * @type {Float64Array}
50
+ */
51
+ const candidates = new Float64Array(64 * CANDIDATE_STRIDE);
52
+
53
+ /**
54
+ * Append one contact to the candidate buffer. Returns the new count.
55
+ *
56
+ * @param {number} count
57
+ * @param {number} wax
58
+ * @param {number} way
59
+ * @param {number} waz
60
+ * @param {number} wbx
61
+ * @param {number} wby
62
+ * @param {number} wbz
63
+ * @param {number} nx
64
+ * @param {number} ny
65
+ * @param {number} nz
66
+ * @param {number} depth
67
+ * @returns {number}
68
+ */
69
+ function append_contact(count, wax, way, waz, wbx, wby, wbz, nx, ny, nz, depth) {
70
+ if (count * CANDIDATE_STRIDE >= candidates.length) return count;
71
+ const off = count * CANDIDATE_STRIDE;
72
+ candidates[off] = wax; candidates[off + 1] = way; candidates[off + 2] = waz;
73
+ candidates[off + 3] = wbx; candidates[off + 4] = wby; candidates[off + 5] = wbz;
74
+ candidates[off + 6] = nx; candidates[off + 7] = ny; candidates[off + 8] = nz;
75
+ candidates[off + 9] = depth;
76
+ return count + 1;
77
+ }
78
+
79
+ function swap_candidate(i, j) {
80
+ if (i === j) return;
81
+ const oi = i * CANDIDATE_STRIDE;
82
+ const oj = j * CANDIDATE_STRIDE;
83
+ for (let k = 0; k < CANDIDATE_STRIDE; k++) {
84
+ const t = candidates[oi + k];
85
+ candidates[oi + k] = candidates[oj + k];
86
+ candidates[oj + k] = t;
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Reduce an in-place candidate list to at most {@link MAX_KEPT} entries:
92
+ * 1. Move the deepest to slot 0.
93
+ * 2. For each subsequent slot, pick the remaining candidate whose minimum
94
+ * distance to the already-kept set is largest (approximates max-area).
95
+ *
96
+ * @param {number} n
97
+ * @returns {number} kept count, in [0, min(n, MAX_KEPT)]
98
+ */
99
+ function reduce_candidates(n) {
100
+ if (n <= MAX_KEPT) return n;
101
+
102
+ // Move deepest to slot 0.
103
+ let deepest_idx = 0;
104
+ let deepest_val = candidates[9];
105
+ for (let i = 1; i < n; i++) {
106
+ const d = candidates[i * CANDIDATE_STRIDE + 9];
107
+ if (d > deepest_val) { deepest_val = d; deepest_idx = i; }
108
+ }
109
+ swap_candidate(0, deepest_idx);
110
+
111
+ for (let k = 1; k < MAX_KEPT; k++) {
112
+ let best_score = -1;
113
+ let best_i = -1;
114
+ for (let i = k; i < n; i++) {
115
+ let min_d2 = Infinity;
116
+ for (let j = 0; j < k; j++) {
117
+ const dx = candidates[i * CANDIDATE_STRIDE] - candidates[j * CANDIDATE_STRIDE];
118
+ const dy = candidates[i * CANDIDATE_STRIDE + 1] - candidates[j * CANDIDATE_STRIDE + 1];
119
+ const dz = candidates[i * CANDIDATE_STRIDE + 2] - candidates[j * CANDIDATE_STRIDE + 2];
120
+ const d2 = dx * dx + dy * dy + dz * dz;
121
+ if (d2 < min_d2) min_d2 = d2;
122
+ }
123
+ if (min_d2 > best_score) { best_score = min_d2; best_i = i; }
124
+ }
125
+ swap_candidate(k, best_i);
126
+ }
127
+ return MAX_KEPT;
128
+ }
129
+
130
+ /**
131
+ * Run pairwise narrowphase for one (colliderA, colliderB) tuple — dispatches
132
+ * by shape type and appends 0..K contacts to the candidate buffer. Returns
133
+ * the new candidate count.
134
+ *
135
+ * @param {number} count
136
+ * @param {Collider} colA
137
+ * @param {Transform} trA
138
+ * @param {Collider} colB
139
+ * @param {Transform} trB
140
+ * @returns {number}
141
+ */
142
+ function dispatch_pair(count, colA, trA, colB, trB) {
143
+ const shapeA = colA.shape;
144
+ const shapeB = colB.shape;
145
+ const isSphereA = shapeA.isUnitSphereShape3D === true;
146
+ const isSphereB = shapeB.isUnitSphereShape3D === true;
147
+ // isBoxShape3D covers both UnitCubeShape3D (fixed 0.5) and BoxShape3D
148
+ // (arbitrary half-extents). Both expose `half_extents` as a Vector3.
149
+ const isBoxA = shapeA.isBoxShape3D === true;
150
+ const isBoxB = shapeB.isBoxShape3D === true;
151
+ const isCapsuleA = shapeA.isCapsuleShape3D === true;
152
+ const isCapsuleB = shapeB.isCapsuleShape3D === true;
153
+
154
+ // sphere-sphere
155
+ if (isSphereA && isSphereB) {
156
+ const ok = sphere_sphere_contact(
157
+ sphere_result,
158
+ trA.position.x, trA.position.y, trA.position.z,
159
+ trB.position.x, trB.position.y, trB.position.z,
160
+ 1, 1
161
+ );
162
+ if (!ok) return count;
163
+ const nx = sphere_result[0], ny = sphere_result[1], nz = sphere_result[2];
164
+ return append_contact(count,
165
+ trA.position.x - nx, trA.position.y - ny, trA.position.z - nz,
166
+ trB.position.x + nx, trB.position.y + ny, trB.position.z + nz,
167
+ nx, ny, nz, sphere_result[3]);
168
+ }
169
+
170
+ // sphere ↔ box
171
+ if ((isSphereA && isBoxB) || (isBoxA && isSphereB)) {
172
+ const sphereTr = isSphereA ? trA : trB;
173
+ const boxTr = isSphereA ? trB : trA;
174
+ const boxShape = isSphereA ? shapeB : shapeA;
175
+ const bh = boxShape.half_extents;
176
+ const ok = sphere_box_contact(
177
+ closed_form_result,
178
+ sphereTr.position.x, sphereTr.position.y, sphereTr.position.z, 1,
179
+ boxTr.position.x, boxTr.position.y, boxTr.position.z,
180
+ boxTr.rotation.x, boxTr.rotation.y, boxTr.rotation.z, boxTr.rotation.w,
181
+ bh.x, bh.y, bh.z
182
+ );
183
+ if (!ok) return count;
184
+ let nx = closed_form_result[0], ny = closed_form_result[1], nz = closed_form_result[2];
185
+ const depth = closed_form_result[3];
186
+ const wsx = closed_form_result[4], wsy = closed_form_result[5], wsz = closed_form_result[6];
187
+ const wbx = closed_form_result[7], wby = closed_form_result[8], wbz = closed_form_result[9];
188
+ if (isSphereA) {
189
+ return append_contact(count, wsx, wsy, wsz, wbx, wby, wbz, nx, ny, nz, depth);
190
+ } else {
191
+ return append_contact(count, wbx, wby, wbz, wsx, wsy, wsz, -nx, -ny, -nz, depth);
192
+ }
193
+ }
194
+
195
+ // box-box multi-point
196
+ if (isBoxA && isBoxB) {
197
+ const ah = shapeA.half_extents;
198
+ const bh = shapeB.half_extents;
199
+ const ok = box_box_manifold(
200
+ box_manifold_result,
201
+ trA.position.x, trA.position.y, trA.position.z,
202
+ trA.rotation.x, trA.rotation.y, trA.rotation.z, trA.rotation.w,
203
+ ah.x, ah.y, ah.z,
204
+ trB.position.x, trB.position.y, trB.position.z,
205
+ trB.rotation.x, trB.rotation.y, trB.rotation.z, trB.rotation.w,
206
+ bh.x, bh.y, bh.z
207
+ );
208
+ if (!ok) return count;
209
+ const nx = box_manifold_result[0], ny = box_manifold_result[1], nz = box_manifold_result[2];
210
+ const cc = box_manifold_result[3] | 0;
211
+ for (let k = 0; k < cc; k++) {
212
+ const base = 4 + k * 7;
213
+ count = append_contact(count,
214
+ box_manifold_result[base], box_manifold_result[base + 1], box_manifold_result[base + 2],
215
+ box_manifold_result[base + 3], box_manifold_result[base + 4], box_manifold_result[base + 5],
216
+ nx, ny, nz,
217
+ box_manifold_result[base + 6]);
218
+ }
219
+ return count;
220
+ }
221
+
222
+ // capsule-capsule
223
+ if (isCapsuleA && isCapsuleB) {
224
+ const a_shape = colA.shape, b_shape = colB.shape;
225
+ const ok = capsule_capsule_contact(
226
+ closed_form_result,
227
+ trA.position.x, trA.position.y, trA.position.z,
228
+ trA.rotation.x, trA.rotation.y, trA.rotation.z, trA.rotation.w,
229
+ a_shape.radius, a_shape.height * 0.5,
230
+ trB.position.x, trB.position.y, trB.position.z,
231
+ trB.rotation.x, trB.rotation.y, trB.rotation.z, trB.rotation.w,
232
+ b_shape.radius, b_shape.height * 0.5
233
+ );
234
+ if (!ok) return count;
235
+ return append_contact(count,
236
+ closed_form_result[4], closed_form_result[5], closed_form_result[6],
237
+ closed_form_result[7], closed_form_result[8], closed_form_result[9],
238
+ closed_form_result[0], closed_form_result[1], closed_form_result[2],
239
+ closed_form_result[3]);
240
+ }
241
+
242
+ // capsule ↔ sphere
243
+ if ((isCapsuleA && isSphereB) || (isSphereA && isCapsuleB)) {
244
+ const capsuleTr = isCapsuleA ? trA : trB;
245
+ const capsuleShape = isCapsuleA ? colA.shape : colB.shape;
246
+ const sphereTr = isCapsuleA ? trB : trA;
247
+ const ok = capsule_sphere_contact(
248
+ closed_form_result,
249
+ capsuleTr.position.x, capsuleTr.position.y, capsuleTr.position.z,
250
+ capsuleTr.rotation.x, capsuleTr.rotation.y, capsuleTr.rotation.z, capsuleTr.rotation.w,
251
+ capsuleShape.radius, capsuleShape.height * 0.5,
252
+ sphereTr.position.x, sphereTr.position.y, sphereTr.position.z, 1
253
+ );
254
+ if (!ok) return count;
255
+ let nx = closed_form_result[0], ny = closed_form_result[1], nz = closed_form_result[2];
256
+ const depth = closed_form_result[3];
257
+ const cap_x = closed_form_result[4], cap_y = closed_form_result[5], cap_z = closed_form_result[6];
258
+ const sph_x = closed_form_result[7], sph_y = closed_form_result[8], sph_z = closed_form_result[9];
259
+ if (isCapsuleA) {
260
+ return append_contact(count, cap_x, cap_y, cap_z, sph_x, sph_y, sph_z, nx, ny, nz, depth);
261
+ } else {
262
+ return append_contact(count, sph_x, sph_y, sph_z, cap_x, cap_y, cap_z, -nx, -ny, -nz, depth);
263
+ }
264
+ }
265
+
266
+ // capsule ↔ box (multi-point — 1 closest-segment + up to 2 cap-centres)
267
+ if ((isCapsuleA && isBoxB) || (isBoxA && isCapsuleB)) {
268
+ const capsuleTr = isCapsuleA ? trA : trB;
269
+ const capsuleShape = isCapsuleA ? shapeA : shapeB;
270
+ const boxTr = isCapsuleA ? trB : trA;
271
+ const boxShape = isCapsuleA ? shapeB : shapeA;
272
+ const bh = boxShape.half_extents;
273
+ const cc = capsule_box_multi_contacts(
274
+ capsule_box_multi_result,
275
+ capsuleTr.position.x, capsuleTr.position.y, capsuleTr.position.z,
276
+ capsuleTr.rotation.x, capsuleTr.rotation.y, capsuleTr.rotation.z, capsuleTr.rotation.w,
277
+ capsuleShape.radius, capsuleShape.height * 0.5,
278
+ boxTr.position.x, boxTr.position.y, boxTr.position.z,
279
+ boxTr.rotation.x, boxTr.rotation.y, boxTr.rotation.z, boxTr.rotation.w,
280
+ bh.x, bh.y, bh.z
281
+ );
282
+ if (cc === 0) return count;
283
+ // multi_result layout per contact: cap_x/y/z (A side), box_x/y/z (B side), nx/ny/nz, depth.
284
+ for (let k = 0; k < cc; k++) {
285
+ const o = k * CAPSULE_BOX_CONTACT_STRIDE;
286
+ const cap_x = capsule_box_multi_result[o];
287
+ const cap_y = capsule_box_multi_result[o + 1];
288
+ const cap_z = capsule_box_multi_result[o + 2];
289
+ const box_x = capsule_box_multi_result[o + 3];
290
+ const box_y = capsule_box_multi_result[o + 4];
291
+ const box_z = capsule_box_multi_result[o + 5];
292
+ const nx = capsule_box_multi_result[o + 6];
293
+ const ny = capsule_box_multi_result[o + 7];
294
+ const nz = capsule_box_multi_result[o + 8];
295
+ const depth = capsule_box_multi_result[o + 9];
296
+ if (isCapsuleA) {
297
+ count = append_contact(count, cap_x, cap_y, cap_z, box_x, box_y, box_z, nx, ny, nz, depth);
298
+ } else {
299
+ count = append_contact(count, box_x, box_y, box_z, cap_x, cap_y, cap_z, -nx, -ny, -nz, depth);
300
+ }
301
+ }
302
+ return count;
303
+ }
304
+
305
+ // GJK + EPA fallback for everything else.
306
+ posed_a.setup(colA.shape, trA.position, trA.rotation);
307
+ posed_b.setup(colB.shape, trB.position, trB.rotation);
308
+ if (!gjk(simplex_buf, posed_a, posed_b)) return count;
309
+ expanding_polytope_algorithm(
310
+ epa_result, 0,
311
+ simplex_a, simplex_b, simplex_c, simplex_d,
312
+ posed_a, posed_b
313
+ );
314
+ const ex = epa_result[0], ey = epa_result[1], ez = epa_result[2];
315
+ const depth = Math.sqrt(ex * ex + ey * ey + ez * ez);
316
+ // Reject zero-depth (touching), negative (impossible), and NaN/Inf
317
+ // (degenerate EPA exit) results. `!(depth > 0)` flips for NaN too.
318
+ if (!(depth > 0) || !Number.isFinite(depth)) return count;
319
+ const inv = 1 / depth;
320
+ return append_contact(count,
321
+ trA.position.x, trA.position.y, trA.position.z,
322
+ trB.position.x, trB.position.y, trB.position.z,
323
+ -ex * inv, -ey * inv, -ez * inv,
324
+ depth);
325
+ }
326
+
327
+ /**
328
+ * For every pair in `pair_list`, do a cross-product over A's collider list ×
329
+ * B's collider list, accumulate candidate contacts, reduce to ≤4, and write
330
+ * to the manifold slot.
331
+ *
332
+ * @param {PairList} pair_list
333
+ * @param {ManifoldStore} manifolds
334
+ * @param {PhysicsSystem} system supplies per-body collider lists + transforms
335
+ */
336
+ export function narrowphase_step(pair_list, manifolds, system) {
337
+ const count = pair_list.count;
338
+ const lists = system.__body_collider_lists;
339
+
340
+ for (let i = 0; i < count; i++) {
341
+ const idA = pair_list.get_a(i);
342
+ const idB = pair_list.get_b(i);
343
+ const idxA = body_id_index(idA);
344
+ const idxB = body_id_index(idB);
345
+
346
+ const list_a = lists[idxA];
347
+ const list_b = lists[idxB];
348
+ const slot = manifolds.find(idA, idB);
349
+
350
+ if (list_a === undefined || list_b === undefined
351
+ || list_a.length === 0 || list_b.length === 0) {
352
+ manifolds.clear_contacts(slot);
353
+ continue;
354
+ }
355
+
356
+ let cand_count = 0;
357
+ const la_len = list_a.length;
358
+ const lb_len = list_b.length;
359
+ for (let a = 0; a < la_len; a++) {
360
+ const ea = list_a[a];
361
+ for (let b = 0; b < lb_len; b++) {
362
+ const eb = list_b[b];
363
+ cand_count = dispatch_pair(cand_count, ea.collider, ea.transform, eb.collider, eb.transform);
364
+ }
365
+ }
366
+
367
+ manifolds.clear_contacts(slot);
368
+ if (cand_count === 0) continue;
369
+
370
+ const kept = reduce_candidates(cand_count);
371
+ for (let k = 0; k < kept; k++) {
372
+ const off = k * CANDIDATE_STRIDE;
373
+ manifolds.set_contact(
374
+ slot, k,
375
+ candidates[off], candidates[off + 1], candidates[off + 2],
376
+ candidates[off + 3], candidates[off + 4], candidates[off + 5],
377
+ candidates[off + 6], candidates[off + 7], candidates[off + 8],
378
+ candidates[off + 9]
379
+ );
380
+ }
381
+ }
382
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Closed-form contact generation for a unit sphere vs. an oriented box.
3
+ *
4
+ * Algorithm: transform the sphere centre into the box's body frame, clamp it
5
+ * to the box's half-extents to get the closest surface point in body space,
6
+ * measure the distance, and (when overlapping) rotate the resulting normal
7
+ * and surface point back into world.
8
+ *
9
+ * Singular cases:
10
+ * - If the sphere centre is inside the box (distance == 0 in body frame),
11
+ * the closest-face vector is undefined; we pick the smallest-overlap face
12
+ * direction as a deterministic tie-break.
13
+ *
14
+ * Output convention (mirrors {@link sphere_sphere_contact}): the normal in
15
+ * `out[0..2]` points from the box surface toward the sphere centre; `out[3]`
16
+ * is the (positive) penetration depth; `out[4..6]` is the world-space contact
17
+ * point on the sphere's surface; `out[7..9]` is the world-space contact point
18
+ * on the box's surface.
19
+ *
20
+ * @param {number[]|Float64Array} out length >= 10
21
+ * @param {number} sx sphere centre x
22
+ * @param {number} sy
23
+ * @param {number} sz
24
+ * @param {number} radius
25
+ * @param {number} bx box centre x
26
+ * @param {number} by
27
+ * @param {number} bz
28
+ * @param {number} bqx box rotation quaternion x
29
+ * @param {number} bqy
30
+ * @param {number} bqz
31
+ * @param {number} bqw
32
+ * @param {number} hx box half-extent x (body frame)
33
+ * @param {number} hy
34
+ * @param {number} hz
35
+ * @returns {boolean} true if overlap
36
+ */
37
+ export function sphere_box_contact(out: number[] | Float64Array, sx: number, sy: number, sz: number, radius: number, bx: number, by: number, bz: number, bqx: number, bqy: number, bqz: number, bqw: number, hx: number, hy: number, hz: number): boolean;
38
+ //# sourceMappingURL=sphere_box_contact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sphere_box_contact.d.ts","sourceRoot":"","sources":["../../../../../src/engine/physics/narrowphase/sphere_box_contact.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wCAjBW,MAAM,EAAE,GAAC,YAAY,MACrB,MAAM,MACN,MAAM,MACN,MAAM,UACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,OACN,MAAM,OACN,MAAM,OACN,MAAM,OACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,OAAO,CA+FnB"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Closed-form contact generation for a unit sphere vs. an oriented box.
3
+ *
4
+ * Algorithm: transform the sphere centre into the box's body frame, clamp it
5
+ * to the box's half-extents to get the closest surface point in body space,
6
+ * measure the distance, and (when overlapping) rotate the resulting normal
7
+ * and surface point back into world.
8
+ *
9
+ * Singular cases:
10
+ * - If the sphere centre is inside the box (distance == 0 in body frame),
11
+ * the closest-face vector is undefined; we pick the smallest-overlap face
12
+ * direction as a deterministic tie-break.
13
+ *
14
+ * Output convention (mirrors {@link sphere_sphere_contact}): the normal in
15
+ * `out[0..2]` points from the box surface toward the sphere centre; `out[3]`
16
+ * is the (positive) penetration depth; `out[4..6]` is the world-space contact
17
+ * point on the sphere's surface; `out[7..9]` is the world-space contact point
18
+ * on the box's surface.
19
+ *
20
+ * @param {number[]|Float64Array} out length >= 10
21
+ * @param {number} sx sphere centre x
22
+ * @param {number} sy
23
+ * @param {number} sz
24
+ * @param {number} radius
25
+ * @param {number} bx box centre x
26
+ * @param {number} by
27
+ * @param {number} bz
28
+ * @param {number} bqx box rotation quaternion x
29
+ * @param {number} bqy
30
+ * @param {number} bqz
31
+ * @param {number} bqw
32
+ * @param {number} hx box half-extent x (body frame)
33
+ * @param {number} hy
34
+ * @param {number} hz
35
+ * @returns {boolean} true if overlap
36
+ */
37
+ export function sphere_box_contact(
38
+ out,
39
+ sx, sy, sz, radius,
40
+ bx, by, bz,
41
+ bqx, bqy, bqz, bqw,
42
+ hx, hy, hz
43
+ ) {
44
+ // Step 1: bring the sphere centre into box-local space via the conjugate
45
+ // quaternion. v_local = q* · (s - b) · q
46
+ const dx = sx - bx, dy = sy - by, dz = sz - bz;
47
+
48
+ // Apply conjugate (-qx,-qy,-qz, qw) to (dx,dy,dz,0):
49
+ const cx = -bqx, cy = -bqy, cz = -bqz;
50
+ const tx0 = bqw * dx + cy * dz - cz * dy;
51
+ const ty0 = bqw * dy + cz * dx - cx * dz;
52
+ const tz0 = bqw * dz + cx * dy - cy * dx;
53
+ const tw0 = -cx * dx - cy * dy - cz * dz;
54
+ // Then multiply by c* = (qx,qy,qz,qw) (the original quaternion):
55
+ const lx = tx0 * bqw + tw0 * bqx + ty0 * bqz - tz0 * bqy;
56
+ const ly = ty0 * bqw + tw0 * bqy + tz0 * bqx - tx0 * bqz;
57
+ const lz = tz0 * bqw + tw0 * bqz + tx0 * bqy - ty0 * bqx;
58
+
59
+ // Step 2: closest point on the box to the sphere centre, in body frame.
60
+ const clx = lx < -hx ? -hx : (lx > hx ? hx : lx);
61
+ const cly = ly < -hy ? -hy : (ly > hy ? hy : ly);
62
+ const clz = lz < -hz ? -hz : (lz > hz ? hz : lz);
63
+
64
+ const inside = clx === lx && cly === ly && clz === lz;
65
+
66
+ let nlx, nly, nlz, dist;
67
+ if (!inside) {
68
+ // Centre is outside the box: normal is from clamped point toward centre.
69
+ const ex = lx - clx, ey = ly - cly, ez = lz - clz;
70
+ const dist_sqr = ex * ex + ey * ey + ez * ez;
71
+ if (dist_sqr >= radius * radius) {
72
+ return false;
73
+ }
74
+ dist = Math.sqrt(dist_sqr);
75
+ if (dist > 0) {
76
+ const inv = 1 / dist;
77
+ nlx = ex * inv; nly = ey * inv; nlz = ez * inv;
78
+ } else {
79
+ // Centre lies exactly on a face — pick +X as a tie-break.
80
+ nlx = 1; nly = 0; nlz = 0;
81
+ }
82
+ } else {
83
+ // Centre is inside the box. Closest face is the one we're nearest to.
84
+ // Compute the per-axis "distance to face" (positive); pick min.
85
+ const dx_face = hx - Math.abs(lx);
86
+ const dy_face = hy - Math.abs(ly);
87
+ const dz_face = hz - Math.abs(lz);
88
+
89
+ // Pick smallest depth-to-face; ties broken X > Y > Z (deterministic).
90
+ if (dx_face <= dy_face && dx_face <= dz_face) {
91
+ nlx = lx >= 0 ? 1 : -1; nly = 0; nlz = 0;
92
+ dist = -dx_face;
93
+ } else if (dy_face <= dz_face) {
94
+ nlx = 0; nly = ly >= 0 ? 1 : -1; nlz = 0;
95
+ dist = -dy_face;
96
+ } else {
97
+ nlx = 0; nly = 0; nlz = lz >= 0 ? 1 : -1;
98
+ dist = -dz_face;
99
+ }
100
+ }
101
+
102
+ // Step 3: rotate normal and surface point back to world. v_world = q · v · q*
103
+ function rotate_to_world(out_arr, off, vx, vy, vz) {
104
+ const ix = bqw * vx + bqy * vz - bqz * vy;
105
+ const iy = bqw * vy + bqz * vx - bqx * vz;
106
+ const iz = bqw * vz + bqx * vy - bqy * vx;
107
+ const iw = -bqx * vx - bqy * vy - bqz * vz;
108
+ out_arr[off] = ix * bqw + iw * (-bqx) + iy * (-bqz) - iz * (-bqy);
109
+ out_arr[off + 1] = iy * bqw + iw * (-bqy) + iz * (-bqx) - ix * (-bqz);
110
+ out_arr[off + 2] = iz * bqw + iw * (-bqz) + ix * (-bqy) - iy * (-bqx);
111
+ }
112
+
113
+ // World normal (box → sphere).
114
+ rotate_to_world(out, 0, nlx, nly, nlz);
115
+ const nx = out[0], ny = out[1], nz = out[2];
116
+ out[3] = radius - dist;
117
+
118
+ // World contact on sphere = sphere_center - normal * radius.
119
+ out[4] = sx - nx * radius;
120
+ out[5] = sy - ny * radius;
121
+ out[6] = sz - nz * radius;
122
+
123
+ // World contact on box: rotate the local-space clamped point to world, plus box centre.
124
+ rotate_to_world(out, 7, clx, cly, clz);
125
+ out[7] += bx;
126
+ out[8] += by;
127
+ out[9] += bz;
128
+
129
+ return true;
130
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Closed-form contact generation for two unit spheres positioned in world
3
+ * space. Returns whether the spheres overlap. On overlap, `out` is populated
4
+ * with `[nx, ny, nz, depth]` where the normal points from B toward A and
5
+ * `depth` is the positive penetration distance.
6
+ *
7
+ * Both spheres have radius 1 (the {@link UnitSphereShape3D} convention); any
8
+ * scaling on the body's transform is irrelevant under our "no scale on
9
+ * physics transforms" assumption.
10
+ *
11
+ * Centres-coincident is a singular case for the general normal but is
12
+ * resolved here by picking +X as a deterministic tie-break direction.
13
+ *
14
+ * @param {number[]|Float64Array} out length >= 4
15
+ * @param {number} ax
16
+ * @param {number} ay
17
+ * @param {number} az
18
+ * @param {number} bx
19
+ * @param {number} by
20
+ * @param {number} bz
21
+ * @param {number} radius_a
22
+ * @param {number} radius_b
23
+ * @returns {boolean} true if spheres overlap
24
+ */
25
+ export function sphere_sphere_contact(out: number[] | Float64Array, ax: number, ay: number, az: number, bx: number, by: number, bz: number, radius_a: number, radius_b: number): boolean;
26
+ //# sourceMappingURL=sphere_sphere_contact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sphere_sphere_contact.d.ts","sourceRoot":"","sources":["../../../../../src/engine/physics/narrowphase/sphere_sphere_contact.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,2CAXW,MAAM,EAAE,GAAC,YAAY,MACrB,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,YACN,MAAM,YACN,MAAM,GACJ,OAAO,CA4BnB"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Closed-form contact generation for two unit spheres positioned in world
3
+ * space. Returns whether the spheres overlap. On overlap, `out` is populated
4
+ * with `[nx, ny, nz, depth]` where the normal points from B toward A and
5
+ * `depth` is the positive penetration distance.
6
+ *
7
+ * Both spheres have radius 1 (the {@link UnitSphereShape3D} convention); any
8
+ * scaling on the body's transform is irrelevant under our "no scale on
9
+ * physics transforms" assumption.
10
+ *
11
+ * Centres-coincident is a singular case for the general normal but is
12
+ * resolved here by picking +X as a deterministic tie-break direction.
13
+ *
14
+ * @param {number[]|Float64Array} out length >= 4
15
+ * @param {number} ax
16
+ * @param {number} ay
17
+ * @param {number} az
18
+ * @param {number} bx
19
+ * @param {number} by
20
+ * @param {number} bz
21
+ * @param {number} radius_a
22
+ * @param {number} radius_b
23
+ * @returns {boolean} true if spheres overlap
24
+ */
25
+ export function sphere_sphere_contact(out, ax, ay, az, bx, by, bz, radius_a, radius_b) {
26
+ const dx = ax - bx;
27
+ const dy = ay - by;
28
+ const dz = az - bz;
29
+ const dist_sqr = dx * dx + dy * dy + dz * dz;
30
+
31
+ const sum = radius_a + radius_b;
32
+ if (dist_sqr >= sum * sum) {
33
+ return false;
34
+ }
35
+
36
+ const dist = Math.sqrt(dist_sqr);
37
+ if (dist > 0) {
38
+ const inv = 1 / dist;
39
+ out[0] = dx * inv;
40
+ out[1] = dy * inv;
41
+ out[2] = dz * inv;
42
+ } else {
43
+ // Centres coincide. Pick +X deterministically (no RNG); penetration is
44
+ // the full sum of radii.
45
+ out[0] = 1;
46
+ out[1] = 0;
47
+ out[2] = 0;
48
+ }
49
+ out[3] = sum - dist;
50
+ return true;
51
+ }