@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,598 @@
1
+ import { BodyKind } from "../ecs/BodyKind.js";
2
+ import { ColliderFlags } from "../ecs/ColliderFlags.js";
3
+ import { CONTACT_STRIDE } from "../contact/ManifoldStore.js";
4
+ import { RigidBodyFlags } from "../ecs/RigidBodyFlags.js";
5
+ import { world_inverse_inertia_apply } from "../inertia/world_inverse_inertia.js";
6
+ import { friction_cone_clamp } from "./friction_cone.js";
7
+
8
+ /**
9
+ * A pair is "sensor-only" when either body OR either body's primary
10
+ * collider carries the IsSensor flag. The manifold still exists (so
11
+ * Begin/Stay/End events fire from the manifold-diff pass) but no impulse
12
+ * is applied.
13
+ *
14
+ * @param {RigidBody} rbA
15
+ * @param {Collider} colA
16
+ * @param {RigidBody} rbB
17
+ * @param {Collider} colB
18
+ * @returns {boolean}
19
+ */
20
+ function pair_is_sensor(rbA, colA, rbB, colB) {
21
+ return (rbA.flags & RigidBodyFlags.IsSensor) !== 0
22
+ || (rbB.flags & RigidBodyFlags.IsSensor) !== 0
23
+ || (colA.flags & ColliderFlags.IsSensor) !== 0
24
+ || (colB.flags & ColliderFlags.IsSensor) !== 0;
25
+ }
26
+
27
+ /**
28
+ * Default velocity-iteration count per `solve_contacts` call. With TGS
29
+ * substepping driven by the PhysicsSystem, each tick now produces multiple
30
+ * solver calls (one per substep), so the per-call iter count is set lower
31
+ * than the classic PGS default of 10. Total iterations per tick =
32
+ * substeps × iters_per_substep; the recommended pairing is 4 × 2 = 8,
33
+ * which matches Box2D's TGS defaults and outperforms 1 × 10 on tall
34
+ * stacks (impulses get position-integrated between substeps, so info
35
+ * propagation through a contact chain compounds across substeps rather
36
+ * than fighting against accumulating position drift inside one solve).
37
+ *
38
+ * Direct callers that want classic PGS can still pass `iters = 10` and
39
+ * skip substepping by calling once with the full tick `dt`.
40
+ * @type {number}
41
+ */
42
+ const DEFAULT_VELOCITY_ITERATIONS = 2;
43
+
44
+ /**
45
+ * Baumgarte position-correction gain. Smaller values are "softer" (slower to
46
+ * push bodies apart but more stable); larger values can introduce jitter.
47
+ * 0.2 is the Catto / Box2D default.
48
+ * @type {number}
49
+ */
50
+ const BAUMGARTE_BETA = 0.2;
51
+
52
+ /**
53
+ * Penetration allowed without applying position correction. Eliminates
54
+ * micro-jitter at near-zero overlap.
55
+ * @type {number}
56
+ */
57
+ const PENETRATION_SLOP = 0.005;
58
+
59
+ /**
60
+ * Velocity below which restitution is suppressed (no "buzz" of micro-bounces
61
+ * when bodies are nearly resting on each other).
62
+ * @type {number}
63
+ */
64
+ const RESTITUTION_VELOCITY_THRESHOLD = 1.0;
65
+
66
+ /**
67
+ * Pre-step scratch stride per contact: 16 doubles
68
+ * 0..2 : rA (contact point − bodyA position)
69
+ * 3..5 : rB (contact point − bodyB position)
70
+ * 6..8 : t1 (tangent 1, unit, world)
71
+ * 9..11: t2 (tangent 2, unit, world)
72
+ * 12 : m_eff_n
73
+ * 13 : m_eff_t1
74
+ * 14 : m_eff_t2
75
+ * 15 : bias_n (combined Baumgarte + restitution target velocity)
76
+ * @type {number}
77
+ */
78
+ const PRE_STRIDE = 16;
79
+
80
+ /** Per-contact index list — 4 uint32 per contact: slot, idx, idxA, idxB. */
81
+ const INDEX_STRIDE = 4;
82
+
83
+ let scratch_pre = new Float64Array(64 * PRE_STRIDE);
84
+ let scratch_idx = new Uint32Array(64 * INDEX_STRIDE);
85
+ let scratch_mu = new Float64Array(64);
86
+
87
+ function ensure_capacity(n) {
88
+ if (scratch_pre.length < n * PRE_STRIDE) {
89
+ scratch_pre = new Float64Array(n * PRE_STRIDE * 2);
90
+ }
91
+ if (scratch_idx.length < n * INDEX_STRIDE) {
92
+ scratch_idx = new Uint32Array(n * INDEX_STRIDE * 2);
93
+ }
94
+ if (scratch_mu.length < n) {
95
+ scratch_mu = new Float64Array(n * 2);
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Build an orthonormal tangent basis perpendicular to a unit normal. Standard
101
+ * "least-aligned axis" trick: pick the world axis least aligned with `n`,
102
+ * cross with `n`, then cross again for the second tangent.
103
+ *
104
+ * @param {Float64Array} out 6 floats: t1.xyz then t2.xyz
105
+ * @param {number} off
106
+ * @param {number} nx
107
+ * @param {number} ny
108
+ * @param {number} nz
109
+ */
110
+ function build_tangents(out, off, nx, ny, nz) {
111
+ // Pick the world axis least aligned with n.
112
+ const ax = nx < 0 ? -nx : nx;
113
+ const ay = ny < 0 ? -ny : ny;
114
+ const az = nz < 0 ? -nz : nz;
115
+
116
+ let rx, ry, rz;
117
+ if (ax <= ay && ax <= az) {
118
+ rx = 1; ry = 0; rz = 0;
119
+ } else if (ay <= az) {
120
+ rx = 0; ry = 1; rz = 0;
121
+ } else {
122
+ rx = 0; ry = 0; rz = 1;
123
+ }
124
+ // t1 = normalize(n × r)
125
+ let t1x = ny * rz - nz * ry;
126
+ let t1y = nz * rx - nx * rz;
127
+ let t1z = nx * ry - ny * rx;
128
+ const inv = 1 / Math.sqrt(t1x * t1x + t1y * t1y + t1z * t1z);
129
+ t1x *= inv; t1y *= inv; t1z *= inv;
130
+
131
+ // t2 = n × t1 (already unit since n and t1 are orthogonal unit vectors)
132
+ const t2x = ny * t1z - nz * t1y;
133
+ const t2y = nz * t1x - nx * t1z;
134
+ const t2z = nx * t1y - ny * t1x;
135
+
136
+ out[off] = t1x; out[off + 1] = t1y; out[off + 2] = t1z;
137
+ out[off + 3] = t2x; out[off + 4] = t2y; out[off + 5] = t2z;
138
+ }
139
+
140
+ /**
141
+ * @param {RigidBody} rb
142
+ * @returns {number}
143
+ */
144
+ function inv_mass_of(rb) {
145
+ if (rb.kind !== BodyKind.Dynamic) return 0;
146
+ return rb.mass > 0 ? 1 / rb.mass : 0;
147
+ }
148
+
149
+ /**
150
+ * Combine two friction coefficients. Geometric mean — matches the Bullet /
151
+ * PhysX default and never goes beyond the smaller of the two.
152
+ * @param {number} a
153
+ * @param {number} b
154
+ * @returns {number}
155
+ */
156
+ function combine_friction(a, b) {
157
+ return Math.sqrt(a * b);
158
+ }
159
+
160
+ /**
161
+ * Combine two restitution coefficients. Maximum — visually bounciest pair
162
+ * wins; matches Unity / common game-engine default.
163
+ * @param {number} a
164
+ * @param {number} b
165
+ * @returns {number}
166
+ */
167
+ function combine_restitution(a, b) {
168
+ return a > b ? a : b;
169
+ }
170
+
171
+ const scratch_clamp = new Float64Array(2);
172
+ const scratch_inertia_a = new Float64Array(3);
173
+ const scratch_inertia_b = new Float64Array(3);
174
+
175
+ /**
176
+ * Apply an impulse `P` at body-relative offset `r`, advancing both the linear
177
+ * velocity (Δv = P/m) and angular velocity (Δω = I⁻¹·(r × P)).
178
+ *
179
+ * Writes go directly to the typed-array backing of `linearVelocity` and
180
+ * `angularVelocity` — bypassing {@link Vector3#set} on purpose. Each `set()`
181
+ * runs a hasHandlers / sendN dispatch path which is dead weight in the
182
+ * solver inner loop (no observer is subscribed to a body's velocity in
183
+ * normal use, and even when one is, fanning out per-iteration writes is
184
+ * useless — callers want the post-step value).
185
+ *
186
+ * @param {RigidBody} rb
187
+ * @param {Transform} transform
188
+ * @param {number} invM
189
+ * @param {number} rx
190
+ * @param {number} ry
191
+ * @param {number} rz
192
+ * @param {number} Px
193
+ * @param {number} Py
194
+ * @param {number} Pz
195
+ * @param {number} sign +1 for body A, -1 for body B (the contact normal points
196
+ * from B → A, so A receives +P and B receives −P).
197
+ * @param {Float64Array} scratch_inertia 3-vector scratch for the angular term
198
+ */
199
+ function apply_impulse_to_body(
200
+ rb, transform, invM,
201
+ rx, ry, rz,
202
+ Px, Py, Pz,
203
+ sign,
204
+ scratch_inertia
205
+ ) {
206
+ if (invM === 0) return;
207
+
208
+ const sPx = sign * Px;
209
+ const sPy = sign * Py;
210
+ const sPz = sign * Pz;
211
+
212
+ const lv = rb.linearVelocity;
213
+ lv[0] += sPx * invM;
214
+ lv[1] += sPy * invM;
215
+ lv[2] += sPz * invM;
216
+
217
+ // r × P (already-signed)
218
+ const tx = ry * sPz - rz * sPy;
219
+ const ty = rz * sPx - rx * sPz;
220
+ const tz = rx * sPy - ry * sPx;
221
+
222
+ world_inverse_inertia_apply(scratch_inertia, 0, rb, transform, tx, ty, tz);
223
+
224
+ const av = rb.angularVelocity;
225
+ av[0] += scratch_inertia[0];
226
+ av[1] += scratch_inertia[1];
227
+ av[2] += scratch_inertia[2];
228
+ }
229
+
230
+ /**
231
+ * Quadratic-form contribution of one body to the constraint effective mass
232
+ * along a unit axis. Computes `(r × axis)^T · I⁻¹_world · (r × axis)`.
233
+ *
234
+ * @param {RigidBody} rb
235
+ * @param {Transform} transform
236
+ * @param {number} rx
237
+ * @param {number} ry
238
+ * @param {number} rz
239
+ * @param {number} ax axis x
240
+ * @param {number} ay
241
+ * @param {number} az
242
+ * @param {Float64Array} scratch_inertia
243
+ * @returns {number}
244
+ */
245
+ function angular_jacobian_contribution(
246
+ rb, transform,
247
+ rx, ry, rz,
248
+ ax, ay, az,
249
+ scratch_inertia
250
+ ) {
251
+ if (rb.kind !== BodyKind.Dynamic) return 0;
252
+ const ii = rb.inverseInertiaLocal;
253
+ if (ii.x === 0 && ii.y === 0 && ii.z === 0) return 0;
254
+
255
+ const rxax = ry * az - rz * ay;
256
+ const rxay = rz * ax - rx * az;
257
+ const rxaz = rx * ay - ry * ax;
258
+
259
+ world_inverse_inertia_apply(scratch_inertia, 0, rb, transform, rxax, rxay, rxaz);
260
+
261
+ return rxax * scratch_inertia[0]
262
+ + rxay * scratch_inertia[1]
263
+ + rxaz * scratch_inertia[2];
264
+ }
265
+
266
+ /**
267
+ * Sequential-impulse contact solver. Partitions the touched contact set into
268
+ * islands (via {@link IslandBuilder}, owned by the PhysicsSystem and rebuilt
269
+ * upstream in the pipeline), then iterates each island independently.
270
+ *
271
+ * Per-island iteration matters for two reasons:
272
+ * 1. Impulse propagation converges inside an island without waiting for
273
+ * unrelated bodies' Gauss-Seidel updates from previous outer loops.
274
+ * 2. Disconnected awake bodies don't pay each other's solver cost — adding
275
+ * an unrelated active body to the scene scales O(island_size) rather than
276
+ * O(global_active).
277
+ *
278
+ * Coulomb friction is applied as a disk clamp in the contact tangent plane.
279
+ * Position correction is folded into the velocity solve via Baumgarte bias.
280
+ *
281
+ * The `apply_warm_start` flag gates the warm-start impulse application.
282
+ * In a classic PGS call (one solve per tick), pass `true` (default) — the
283
+ * cached impulses from the previous tick get replayed onto the velocity,
284
+ * seeding the iterations near the converged answer. In TGS substepping,
285
+ * the PhysicsSystem calls this once per substep; only substep 0 should
286
+ * apply warm-start, because subsequent substeps continue from the solver
287
+ * state left by the previous substep (the impulses in `data` already
288
+ * reflect the current velocity, so re-applying them would double-count).
289
+ *
290
+ * Inertial: angular response uses the full world-frame inverse inertia
291
+ * `R · diag(I⁻¹_local) · R^T` via {@link world_inverse_inertia_apply},
292
+ * correct for arbitrary rotations + diagonal local inertia.
293
+ *
294
+ * @param {ManifoldStore} manifolds
295
+ * @param {PhysicsSystem} system PhysicsSystem; reads `system.islands`.
296
+ * @param {number} dt step duration (full tick `dt` for PGS, sub-tick for TGS)
297
+ * @param {number} [iters]
298
+ * @param {boolean} [apply_warm_start]
299
+ */
300
+ export function solve_contacts(manifolds, system, dt, iters = DEFAULT_VELOCITY_ITERATIONS, apply_warm_start = true) {
301
+ if (dt <= 0) return;
302
+
303
+ const islands = system.islands;
304
+ if (islands === undefined || islands === null) return;
305
+
306
+ const island_count = islands.island_count;
307
+ if (island_count === 0) return;
308
+
309
+ const slot_list = islands.contact_data;
310
+ const slot_offsets = islands.contact_offsets;
311
+
312
+ for (let i = 0; i < island_count; i++) {
313
+ const start = slot_offsets[i];
314
+ const end = slot_offsets[i + 1];
315
+ if (end === start) continue;
316
+ solve_island(manifolds, system, dt, iters, slot_list, start, end, apply_warm_start);
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Solve a single island's contact constraints. Operates on the slice
322
+ * `slot_list[slot_start..slot_end)` of manifold slot ids. Module-scoped
323
+ * scratch buffers are reused across islands (resized by doubling when an
324
+ * island has more contacts than seen before in the same step).
325
+ *
326
+ * @param {ManifoldStore} manifolds
327
+ * @param {PhysicsSystem} system
328
+ * @param {number} dt
329
+ * @param {number} iters
330
+ * @param {Uint32Array} slot_list
331
+ * @param {number} slot_start
332
+ * @param {number} slot_end
333
+ * @param {boolean} apply_warm_start whether to replay cached impulses (see
334
+ * {@link solve_contacts})
335
+ */
336
+ function solve_island(manifolds, system, dt, iters, slot_list, slot_start, slot_end, apply_warm_start) {
337
+ // 1. Count contacts in this island so we can size scratch.
338
+ // Stale-but-cached slots (the island builder skips them upstream) and
339
+ // sensor-only slots contribute zero impulse but we still want exact
340
+ // sizing — sensor slots are filtered at the per-pair check below and
341
+ // contribute zero to `contact_total`.
342
+ let contact_total = 0;
343
+ for (let i = slot_start; i < slot_end; i++) {
344
+ const slot = slot_list[i];
345
+ contact_total += manifolds.contact_count(slot);
346
+ }
347
+ if (contact_total === 0) return;
348
+ ensure_capacity(contact_total);
349
+
350
+ const data = manifolds.data_buffer;
351
+ const pre = scratch_pre;
352
+ const idx = scratch_idx;
353
+ const mus = scratch_mu;
354
+
355
+ // 2. Pre-step + warm-start.
356
+ let c = 0;
357
+ for (let i = slot_start; i < slot_end; i++) {
358
+ const slot = slot_list[i];
359
+ const idxA = system.__index_of(manifolds.bodyA(slot));
360
+ const idxB = system.__index_of(manifolds.bodyB(slot));
361
+ const rbA = system.__bodies[idxA];
362
+ const rbB = system.__bodies[idxB];
363
+ const trA = system.__transforms[idxA];
364
+ const trB = system.__transforms[idxB];
365
+ // Material parameters come from the "primary" collider of each body
366
+ // — for single-collider bodies this is the only one; for compound
367
+ // bodies it's a v1 approximation (per-contact source-collider
368
+ // tracking is a follow-up). Fall back to defaults if a body has no
369
+ // attached colliders.
370
+ const colA = system.__primary_collider(idxA);
371
+ const colB = system.__primary_collider(idxB);
372
+ if (colA === null || colB === null) continue;
373
+ // Sensor pairs: contacts persist in the manifold (for events) but
374
+ // produce no impulse. Skip the solver work for this pair entirely.
375
+ if (pair_is_sensor(rbA, colA, rbB, colB)) continue;
376
+
377
+ const invMA = inv_mass_of(rbA);
378
+ const invMB = inv_mass_of(rbB);
379
+
380
+ const cc = manifolds.contact_count(slot);
381
+ const slot_off = manifolds.slot_data_offset(slot);
382
+ const restitution_combined = combine_restitution(colA.restitution, colB.restitution);
383
+ const friction_combined = combine_friction(colA.friction, colB.friction);
384
+
385
+ for (let k = 0; k < cc; k++) {
386
+ const off = slot_off + k * CONTACT_STRIDE;
387
+
388
+ const wax = data[off], way = data[off + 1], waz = data[off + 2];
389
+ const wbx = data[off + 3], wby = data[off + 4], wbz = data[off + 5];
390
+ const nx = data[off + 6], ny = data[off + 7], nz = data[off + 8];
391
+ const depth = data[off + 9];
392
+
393
+ // Application point: midpoint of the two surface witnesses.
394
+ const px = (wax + wbx) * 0.5;
395
+ const py = (way + wby) * 0.5;
396
+ const pz = (waz + wbz) * 0.5;
397
+
398
+ const rax = px - trA.position.x;
399
+ const ray = py - trA.position.y;
400
+ const raz = pz - trA.position.z;
401
+ const rbx = px - trB.position.x;
402
+ const rby = py - trB.position.y;
403
+ const rbz = pz - trB.position.z;
404
+
405
+ const pre_off = c * PRE_STRIDE;
406
+ pre[pre_off] = rax; pre[pre_off + 1] = ray; pre[pre_off + 2] = raz;
407
+ pre[pre_off + 3] = rbx; pre[pre_off + 4] = rby; pre[pre_off + 5] = rbz;
408
+ build_tangents(pre, pre_off + 6, nx, ny, nz);
409
+
410
+ const t1x = pre[pre_off + 6], t1y = pre[pre_off + 7], t1z = pre[pre_off + 8];
411
+ const t2x = pre[pre_off + 9], t2y = pre[pre_off + 10], t2z = pre[pre_off + 11];
412
+
413
+ // K = invMA + invMB + (rA×axis)^T·I_w⁻¹_A·(rA×axis) + (rB×axis)^T·I_w⁻¹_B·(rB×axis)
414
+ const k_n = invMA + invMB
415
+ + angular_jacobian_contribution(rbA, trA, rax, ray, raz, nx, ny, nz, scratch_inertia_a)
416
+ + angular_jacobian_contribution(rbB, trB, rbx, rby, rbz, nx, ny, nz, scratch_inertia_b);
417
+ const k_t1 = invMA + invMB
418
+ + angular_jacobian_contribution(rbA, trA, rax, ray, raz, t1x, t1y, t1z, scratch_inertia_a)
419
+ + angular_jacobian_contribution(rbB, trB, rbx, rby, rbz, t1x, t1y, t1z, scratch_inertia_b);
420
+ const k_t2 = invMA + invMB
421
+ + angular_jacobian_contribution(rbA, trA, rax, ray, raz, t2x, t2y, t2z, scratch_inertia_a)
422
+ + angular_jacobian_contribution(rbB, trB, rbx, rby, rbz, t2x, t2y, t2z, scratch_inertia_b);
423
+
424
+ pre[pre_off + 12] = k_n > 0 ? 1 / k_n : 0;
425
+ pre[pre_off + 13] = k_t1 > 0 ? 1 / k_t1 : 0;
426
+ pre[pre_off + 14] = k_t2 > 0 ? 1 / k_t2 : 0;
427
+
428
+ // Pre-impulse relative velocity at the contact point, including
429
+ // angular contribution. Convention: n is from B toward A;
430
+ // dv = vA_at_contact − vB_at_contact; vn = dv · n.
431
+ // Cache the typed-array views once — Vector3 extends Float64Array,
432
+ // so `lv[0]` is a direct memory read, no signal observer chain.
433
+ const lvA = rbA.linearVelocity, avA = rbA.angularVelocity;
434
+ const lvB = rbB.linearVelocity, avB = rbB.angularVelocity;
435
+ const vAx_at = lvA[0] + avA[1] * raz - avA[2] * ray;
436
+ const vAy_at = lvA[1] + avA[2] * rax - avA[0] * raz;
437
+ const vAz_at = lvA[2] + avA[0] * ray - avA[1] * rax;
438
+ const vBx_at = lvB[0] + avB[1] * rbz - avB[2] * rby;
439
+ const vBy_at = lvB[1] + avB[2] * rbx - avB[0] * rbz;
440
+ const vBz_at = lvB[2] + avB[0] * rby - avB[1] * rbx;
441
+ const dvx = vAx_at - vBx_at;
442
+ const dvy = vAy_at - vBy_at;
443
+ const dvz = vAz_at - vBz_at;
444
+ const vn_pre = dvx * nx + dvy * ny + dvz * nz;
445
+
446
+ // Baumgarte position correction: gentle separation push when depth
447
+ // exceeds the slop tolerance.
448
+ let bias = 0;
449
+ if (depth > PENETRATION_SLOP) {
450
+ bias = -BAUMGARTE_BETA / dt * (depth - PENETRATION_SLOP);
451
+ // negative because the solver formula is `lambda = m_eff * (-vn + bias_pos)`
452
+ // → bias_pos = beta/dt * pen → we'll flip below by using `lambda = -m_eff * (vn + bias)`
453
+ // For clarity: target vn_new = -bias_pos (i.e. positive separation velocity).
454
+ // Stored sign convention: lambda = -m_eff * (vn + bias) with bias < 0 to push apart.
455
+ }
456
+ // Restitution: if closing fast, push the post-impulse vn to -e * vn_pre.
457
+ if (vn_pre < -RESTITUTION_VELOCITY_THRESHOLD) {
458
+ bias += restitution_combined * vn_pre;
459
+ // restitution_combined > 0, vn_pre < 0 → contribution is negative,
460
+ // reinforcing separation.
461
+ }
462
+ pre[pre_off + 15] = bias;
463
+
464
+ mus[c] = friction_combined;
465
+
466
+ idx[c * INDEX_STRIDE] = slot;
467
+ idx[c * INDEX_STRIDE + 1] = k;
468
+ idx[c * INDEX_STRIDE + 2] = idxA;
469
+ idx[c * INDEX_STRIDE + 3] = idxB;
470
+
471
+ if (apply_warm_start) {
472
+ // Warm-start: replay cached impulses immediately so the
473
+ // iteration loop starts close to the answer. With TGS
474
+ // substepping, this only fires on substep 0 — later
475
+ // substeps continue from the impulses left by the
476
+ // previous substep's iterations (those are already
477
+ // reflected in the current velocity, re-applying would
478
+ // double-count).
479
+ const j_n = data[off + 10];
480
+ const j_t1 = data[off + 11];
481
+ const j_t2 = data[off + 12];
482
+ const Px = nx * j_n + t1x * j_t1 + t2x * j_t2;
483
+ const Py = ny * j_n + t1y * j_t1 + t2y * j_t2;
484
+ const Pz = nz * j_n + t1z * j_t1 + t2z * j_t2;
485
+
486
+ apply_impulse_to_body(rbA, trA, invMA, rax, ray, raz, Px, Py, Pz, +1, scratch_inertia_a);
487
+ apply_impulse_to_body(rbB, trB, invMB, rbx, rby, rbz, Px, Py, Pz, -1, scratch_inertia_b);
488
+ }
489
+
490
+ c++;
491
+ }
492
+ }
493
+
494
+ const contact_count = c;
495
+
496
+ // 3. Velocity iterations.
497
+ for (let iter = 0; iter < iters; iter++) {
498
+ for (let ci = 0; ci < contact_count; ci++) {
499
+ const slot = idx[ci * INDEX_STRIDE];
500
+ const cidx = idx[ci * INDEX_STRIDE + 1];
501
+ const idxA = idx[ci * INDEX_STRIDE + 2];
502
+ const idxB = idx[ci * INDEX_STRIDE + 3];
503
+ const rbA = system.__bodies[idxA];
504
+ const rbB = system.__bodies[idxB];
505
+ const trA = system.__transforms[idxA];
506
+ const trB = system.__transforms[idxB];
507
+ const invMA = inv_mass_of(rbA);
508
+ const invMB = inv_mass_of(rbB);
509
+
510
+ const pre_off = ci * PRE_STRIDE;
511
+ const rax = pre[pre_off], ray = pre[pre_off + 1], raz = pre[pre_off + 2];
512
+ const rbx = pre[pre_off + 3], rby = pre[pre_off + 4], rbz = pre[pre_off + 5];
513
+ const t1x = pre[pre_off + 6], t1y = pre[pre_off + 7], t1z = pre[pre_off + 8];
514
+ const t2x = pre[pre_off + 9], t2y = pre[pre_off + 10], t2z = pre[pre_off + 11];
515
+ const m_eff_n = pre[pre_off + 12];
516
+ const m_eff_t1 = pre[pre_off + 13];
517
+ const m_eff_t2 = pre[pre_off + 14];
518
+ const bias_n = pre[pre_off + 15];
519
+
520
+ const slot_off = manifolds.slot_data_offset(slot);
521
+ const off = slot_off + cidx * CONTACT_STRIDE;
522
+ const nx = data[off + 6], ny = data[off + 7], nz = data[off + 8];
523
+
524
+ // --- Current relative velocity at contact (linear + angular) ---
525
+ // Cache typed-array views once; direct indexing avoids the
526
+ // accessor chain on Vector3.x/y/z.
527
+ const lvA = rbA.linearVelocity, avA = rbA.angularVelocity;
528
+ const lvB = rbB.linearVelocity, avB = rbB.angularVelocity;
529
+
530
+ const vAx_at = lvA[0] + avA[1] * raz - avA[2] * ray;
531
+ const vAy_at = lvA[1] + avA[2] * rax - avA[0] * raz;
532
+ const vAz_at = lvA[2] + avA[0] * ray - avA[1] * rax;
533
+ const vBx_at = lvB[0] + avB[1] * rbz - avB[2] * rby;
534
+ const vBy_at = lvB[1] + avB[2] * rbx - avB[0] * rbz;
535
+ const vBz_at = lvB[2] + avB[0] * rby - avB[1] * rbx;
536
+ const dvx = vAx_at - vBx_at;
537
+ const dvy = vAy_at - vBy_at;
538
+ const dvz = vAz_at - vBz_at;
539
+
540
+ // --- Normal impulse ---
541
+ const vn = dvx * nx + dvy * ny + dvz * nz;
542
+ const j_n_accum = data[off + 10];
543
+ const lambda_n = -m_eff_n * (vn + bias_n);
544
+ const sum_n = j_n_accum + lambda_n;
545
+ const new_j_n = sum_n > 0 ? sum_n : 0;
546
+ const delta_j_n = new_j_n - j_n_accum;
547
+ data[off + 10] = new_j_n;
548
+
549
+ if (delta_j_n !== 0) {
550
+ const Pnx = nx * delta_j_n;
551
+ const Pny = ny * delta_j_n;
552
+ const Pnz = nz * delta_j_n;
553
+ apply_impulse_to_body(rbA, trA, invMA, rax, ray, raz, Pnx, Pny, Pnz, +1, scratch_inertia_a);
554
+ apply_impulse_to_body(rbB, trB, invMB, rbx, rby, rbz, Pnx, Pny, Pnz, -1, scratch_inertia_b);
555
+ }
556
+
557
+ // --- Friction impulse (Coulomb disk in tangent plane) ---
558
+ // Recompute relative velocity at contact after the normal impulse.
559
+ // lvA/avA/lvB/avB still alias the same arrays, so we just re-read.
560
+ const vAx2 = lvA[0] + avA[1] * raz - avA[2] * ray;
561
+ const vAy2 = lvA[1] + avA[2] * rax - avA[0] * raz;
562
+ const vAz2 = lvA[2] + avA[0] * ray - avA[1] * rax;
563
+ const vBx2 = lvB[0] + avB[1] * rbz - avB[2] * rby;
564
+ const vBy2 = lvB[1] + avB[2] * rbx - avB[0] * rbz;
565
+ const vBz2 = lvB[2] + avB[0] * rby - avB[1] * rbx;
566
+ const dvx2 = vAx2 - vBx2;
567
+ const dvy2 = vAy2 - vBy2;
568
+ const dvz2 = vAz2 - vBz2;
569
+
570
+ const vt1 = dvx2 * t1x + dvy2 * t1y + dvz2 * t1z;
571
+ const vt2 = dvx2 * t2x + dvy2 * t2y + dvz2 * t2z;
572
+
573
+ const j_t1_accum = data[off + 11];
574
+ const j_t2_accum = data[off + 12];
575
+ const lambda_t1 = -m_eff_t1 * vt1;
576
+ const lambda_t2 = -m_eff_t2 * vt2;
577
+
578
+ const want_t1 = j_t1_accum + lambda_t1;
579
+ const want_t2 = j_t2_accum + lambda_t2;
580
+ const max_friction = mus[ci] * new_j_n;
581
+ friction_cone_clamp(scratch_clamp, 0, want_t1, want_t2, max_friction);
582
+ const new_j_t1 = scratch_clamp[0];
583
+ const new_j_t2 = scratch_clamp[1];
584
+ const delta_t1 = new_j_t1 - j_t1_accum;
585
+ const delta_t2 = new_j_t2 - j_t2_accum;
586
+ data[off + 11] = new_j_t1;
587
+ data[off + 12] = new_j_t2;
588
+
589
+ if (delta_t1 !== 0 || delta_t2 !== 0) {
590
+ const Ptx = t1x * delta_t1 + t2x * delta_t2;
591
+ const Pty = t1y * delta_t1 + t2y * delta_t2;
592
+ const Ptz = t1z * delta_t1 + t2z * delta_t2;
593
+ apply_impulse_to_body(rbA, trA, invMA, rax, ray, raz, Ptx, Pty, Ptz, +1, scratch_inertia_a);
594
+ apply_impulse_to_body(rbB, trB, invMB, rbx, rby, rbz, Ptx, Pty, Ptz, -1, scratch_inertia_b);
595
+ }
596
+ }
597
+ }
598
+ }
@@ -1,34 +0,0 @@
1
- export class OrderedEdge {
2
- /**
3
- *
4
- * @param {number} v1
5
- * @param {number} v2
6
- */
7
- constructor(v1: number, v2: number);
8
- v_low: number;
9
- v_high: number;
10
- /**
11
- *
12
- * @param {number} v1
13
- * @param {number} v2
14
- */
15
- set(v1: number, v2: number): void;
16
- /**
17
- *
18
- * @param {OrderedEdge} other
19
- */
20
- copy(other: OrderedEdge): void;
21
- clone(): OrderedEdge;
22
- /**
23
- *
24
- * @return {number}
25
- */
26
- hash(): number;
27
- /**
28
- *
29
- * @param {OrderedEdge} other
30
- * @returns {boolean}
31
- */
32
- equals(other: OrderedEdge): boolean;
33
- }
34
- //# sourceMappingURL=OrderedEdge.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OrderedEdge.d.ts","sourceRoot":"","sources":["../../../../../../../../../../src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.js"],"names":[],"mappings":"AAEA;IACI;;;;OAIG;IACH,gBAHW,MAAM,MACN,MAAM,EAUhB;IANO,cAAe;IACf,eAAgB;IAOxB;;;;OAIG;IACH,QAHW,MAAM,MACN,MAAM,QAUhB;IAED;;;OAGG;IACH,YAFW,WAAW,QAKrB;IAED,qBAEC;IAED;;;OAGG;IACH,QAFY,MAAM,CAKjB;IAED;;;;OAIG;IACH,cAHW,WAAW,GACT,OAAO,CAMnB;CACJ"}
@@ -1,66 +0,0 @@
1
- import { split_by_2 } from "../../../../../../../binary/split_by_2.js";
2
-
3
- export class OrderedEdge {
4
- /**
5
- *
6
- * @param {number} v1
7
- * @param {number} v2
8
- */
9
- constructor(v1, v2) {
10
- if (v1 < v2) {
11
- this.v_low = v1;
12
- this.v_high = v2;
13
- } else {
14
- this.v_low = v2;
15
- this.v_high = v1;
16
- }
17
- }
18
-
19
- /**
20
- *
21
- * @param {number} v1
22
- * @param {number} v2
23
- */
24
- set(v1, v2) {
25
- if (v1 < v2) {
26
- this.v_low = v1;
27
- this.v_high = v2;
28
- } else {
29
- this.v_low = v2;
30
- this.v_high = v1;
31
- }
32
- }
33
-
34
- /**
35
- *
36
- * @param {OrderedEdge} other
37
- */
38
- copy(other) {
39
- this.v_low = other.v_low;
40
- this.v_high = other.v_high;
41
- }
42
-
43
- clone() {
44
- return new OrderedEdge(this.v_low, this.v_high);
45
- }
46
-
47
- /**
48
- *
49
- * @return {number}
50
- */
51
- hash() {
52
- // resulting hashes are close by
53
- return split_by_2(this.v_low) | (split_by_2(this.v_high) << 1);
54
- }
55
-
56
- /**
57
- *
58
- * @param {OrderedEdge} other
59
- * @returns {boolean}
60
- */
61
- equals(other) {
62
- return this.v_low === other.v_low
63
- && this.v_high === other.v_high
64
- ;
65
- }
66
- }