@woosh/meep-engine 2.156.0 → 2.157.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 (654) hide show
  1. package/README.md +1 -3
  2. package/editor/view/ecs/components/common/AutoCanvasView.js +100 -53
  3. package/editor/view/ecs/components/common/TextController.js +59 -0
  4. package/editor/view/node-graph/NodeGraphCamera.js +90 -0
  5. package/editor/view/node-graph/NodeGraphEditorView.js +121 -22
  6. package/editor/view/node-graph/NodeGraphSelection.js +89 -0
  7. package/editor/view/node-graph/NodeGraphView.js +669 -453
  8. package/editor/view/node-graph/NodeView.js +211 -135
  9. package/editor/view/node-graph/actions/ConnectionCreateAction.js +53 -0
  10. package/editor/view/node-graph/actions/ConnectionDeleteAction.js +36 -0
  11. package/editor/view/node-graph/actions/NodeDeleteAction.js +88 -0
  12. package/editor/view/node-graph/actions/NodeParameterSetAction.js +52 -0
  13. package/editor/view/node-graph/actions/NodesMoveAction.js +41 -0
  14. package/editor/view/node-graph/actions/SelectionSetAction.js +60 -0
  15. package/editor/view/node-graph/connection_wire_geometry.js +107 -0
  16. package/package.json +1 -1
  17. package/samples/generation/SampleGenerator0.js +8 -1
  18. package/src/core/binary/reinterpret_float32_as_uint32.d.ts +7 -0
  19. package/src/core/binary/reinterpret_float32_as_uint32.d.ts.map +1 -0
  20. package/src/core/binary/reinterpret_float32_as_uint32.js +13 -0
  21. package/src/core/binary/reinterpret_uint32_as_float32.d.ts +7 -0
  22. package/src/core/binary/reinterpret_uint32_as_float32.d.ts.map +1 -0
  23. package/src/core/binary/reinterpret_uint32_as_float32.js +14 -0
  24. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_incremental.d.ts.map +1 -1
  25. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_incremental.js +1 -3
  26. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.d.ts +12 -0
  27. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.d.ts.map +1 -0
  28. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.js +92 -0
  29. package/src/core/bvh8/BVH8.d.ts +127 -0
  30. package/src/core/bvh8/BVH8.d.ts.map +1 -0
  31. package/src/core/bvh8/BVH8.js +436 -0
  32. package/src/core/bvh8/NOTES.md +63 -0
  33. package/src/core/bvh8/build/BVH8Converter.d.ts +59 -0
  34. package/src/core/bvh8/build/BVH8Converter.d.ts.map +1 -0
  35. package/src/core/bvh8/build/BVH8Converter.js +588 -0
  36. package/src/core/bvh8/build/NodeProxy.d.ts +66 -0
  37. package/src/core/bvh8/build/NodeProxy.d.ts.map +1 -0
  38. package/src/core/bvh8/build/NodeProxy.js +308 -0
  39. package/src/core/bvh8/build/TriangleCluster.d.ts +29 -0
  40. package/src/core/bvh8/build/TriangleCluster.d.ts.map +1 -0
  41. package/src/core/bvh8/build/TriangleCluster.js +123 -0
  42. package/src/core/bvh8/build/aabb3_compute_merge_cost.d.ts +8 -0
  43. package/src/core/bvh8/build/aabb3_compute_merge_cost.d.ts.map +1 -0
  44. package/src/core/bvh8/build/aabb3_compute_merge_cost.js +29 -0
  45. package/src/core/bvh8/build/aabb3_from_triangle_by_index.d.ts +10 -0
  46. package/src/core/bvh8/build/aabb3_from_triangle_by_index.d.ts.map +1 -0
  47. package/src/core/bvh8/build/aabb3_from_triangle_by_index.js +18 -0
  48. package/src/core/bvh8/build/bvh8_build_for_geometry.d.ts +10 -0
  49. package/src/core/bvh8/build/bvh8_build_for_geometry.d.ts.map +1 -0
  50. package/src/core/bvh8/build/bvh8_build_for_geometry.js +303 -0
  51. package/src/core/bvh8/build/bvh8_from_proxy.d.ts +9 -0
  52. package/src/core/bvh8/build/bvh8_from_proxy.d.ts.map +1 -0
  53. package/src/core/bvh8/build/bvh8_from_proxy.js +256 -0
  54. package/src/core/bvh8/build/byte.d.ts +7 -0
  55. package/src/core/bvh8/build/byte.d.ts.map +1 -0
  56. package/src/core/bvh8/build/byte.js +10 -0
  57. package/src/core/bvh8/build/encode_bounds_e.d.ts +9 -0
  58. package/src/core/bvh8/build/encode_bounds_e.d.ts.map +1 -0
  59. package/src/core/bvh8/build/encode_bounds_e.js +12 -0
  60. package/src/core/bvh8/bvh8_convert_to_dot.d.ts +11 -0
  61. package/src/core/bvh8/bvh8_convert_to_dot.d.ts.map +1 -0
  62. package/src/core/bvh8/bvh8_convert_to_dot.js +133 -0
  63. package/src/core/bvh8/bvh8_count_primitives.d.ts +22 -0
  64. package/src/core/bvh8/bvh8_count_primitives.d.ts.map +1 -0
  65. package/src/core/bvh8/bvh8_count_primitives.js +98 -0
  66. package/src/core/bvh8/bvh8_geometry_validate.d.ts +16 -0
  67. package/src/core/bvh8/bvh8_geometry_validate.d.ts.map +1 -0
  68. package/src/core/bvh8/bvh8_geometry_validate.js +149 -0
  69. package/src/core/bvh8/bvh8_geometry_validate_indirect.d.ts +16 -0
  70. package/src/core/bvh8/bvh8_geometry_validate_indirect.d.ts.map +1 -0
  71. package/src/core/bvh8/bvh8_geometry_validate_indirect.js +177 -0
  72. package/src/core/bvh8/bvh8_get_node_bounds.d.ts +9 -0
  73. package/src/core/bvh8/bvh8_get_node_bounds.d.ts.map +1 -0
  74. package/src/core/bvh8/bvh8_get_node_bounds.js +35 -0
  75. package/src/core/bvh8/bvh8_get_node_child_bounds.d.ts +10 -0
  76. package/src/core/bvh8/bvh8_get_node_child_bounds.d.ts.map +1 -0
  77. package/src/core/bvh8/bvh8_get_node_child_bounds.js +53 -0
  78. package/src/core/bvh8/bvh8_node_child_surface_area.d.ts +9 -0
  79. package/src/core/bvh8/bvh8_node_child_surface_area.d.ts.map +1 -0
  80. package/src/core/bvh8/bvh8_node_child_surface_area.js +18 -0
  81. package/src/core/bvh8/bvh8_node_count_triangles.d.ts +8 -0
  82. package/src/core/bvh8/bvh8_node_count_triangles.d.ts.map +1 -0
  83. package/src/core/bvh8/bvh8_node_count_triangles.js +28 -0
  84. package/src/core/bvh8/bvh8_quality.d.ts +8 -0
  85. package/src/core/bvh8/bvh8_quality.d.ts.map +1 -0
  86. package/src/core/bvh8/bvh8_quality.js +73 -0
  87. package/src/core/bvh8/bvh8_validate_structure.d.ts +15 -0
  88. package/src/core/bvh8/bvh8_validate_structure.d.ts.map +1 -0
  89. package/src/core/bvh8/bvh8_validate_structure.js +87 -0
  90. package/src/core/collection/Uint32MinHeap.d.ts +56 -0
  91. package/src/core/collection/Uint32MinHeap.d.ts.map +1 -0
  92. package/src/core/collection/Uint32MinHeap.js +109 -0
  93. package/src/core/collection/list/FilteredListProjection.js +1 -1
  94. package/src/{engine/physics/island → core/collection/union-find}/union_find.d.ts +8 -5
  95. package/src/core/collection/union-find/union_find.d.ts.map +1 -0
  96. package/src/{engine/physics/island → core/collection/union-find}/union_find.js +8 -5
  97. package/src/core/dom/isImageBitmap.d.ts +7 -0
  98. package/src/core/dom/isImageBitmap.d.ts.map +1 -0
  99. package/src/core/dom/isImageBitmap.js +12 -0
  100. package/src/core/function/frameThrottle.d.ts +8 -0
  101. package/src/core/function/frameThrottle.d.ts.map +1 -0
  102. package/src/core/function/frameThrottle.js +23 -0
  103. package/src/{engine/physics/narrowphase/clip_against_axis_uv.d.ts → core/geom/2d/polygon/polygon2_clip_axis_halfplane.d.ts} +3 -3
  104. package/src/core/geom/2d/polygon/polygon2_clip_axis_halfplane.d.ts.map +1 -0
  105. package/src/{engine/physics/narrowphase/clip_against_axis_uv.js → core/geom/2d/polygon/polygon2_clip_axis_halfplane.js} +51 -51
  106. package/src/{engine/physics/narrowphase/decomposition/aabb_world_to_local.d.ts → core/geom/3d/aabb/aabb3_transform_oriented_inverse.d.ts} +9 -7
  107. package/src/core/geom/3d/aabb/aabb3_transform_oriented_inverse.d.ts.map +1 -0
  108. package/src/{engine/physics/narrowphase/decomposition/aabb_world_to_local.js → core/geom/3d/aabb/aabb3_transform_oriented_inverse.js} +9 -7
  109. package/src/core/geom/3d/aabb/compute_triangle_group_aabb3.d.ts +12 -0
  110. package/src/core/geom/3d/aabb/compute_triangle_group_aabb3.d.ts.map +1 -0
  111. package/src/core/geom/3d/aabb/compute_triangle_group_aabb3.js +46 -0
  112. package/src/core/geom/3d/box/box3_projected_half_extent.d.ts +28 -0
  113. package/src/core/geom/3d/box/box3_projected_half_extent.d.ts.map +1 -0
  114. package/src/core/geom/3d/box/box3_projected_half_extent.js +35 -0
  115. package/src/core/geom/3d/frustum/read_cluster_frustum_corners.js +1 -1
  116. package/src/core/geom/3d/frustum/read_frustum_corner.d.ts +9 -0
  117. package/src/core/geom/3d/frustum/read_frustum_corner.d.ts.map +1 -0
  118. package/src/core/geom/3d/frustum/read_frustum_corner.js +14 -0
  119. package/src/core/geom/3d/gjk/gjk.d.ts.map +1 -0
  120. package/src/{engine/physics → core/geom/3d}/gjk/gjk.js +430 -372
  121. package/src/{engine/physics → core/geom/3d}/gjk/gjk_epa_penetration.d.ts +8 -5
  122. package/src/core/geom/3d/gjk/gjk_epa_penetration.d.ts.map +1 -0
  123. package/src/{engine/physics → core/geom/3d}/gjk/gjk_epa_penetration.js +520 -544
  124. package/src/{engine/physics → core/geom/3d}/gjk/minkowski_support.d.ts +5 -4
  125. package/src/core/geom/3d/gjk/minkowski_support.d.ts.map +1 -0
  126. package/src/{engine/physics → core/geom/3d}/gjk/minkowski_support.js +71 -70
  127. package/src/{engine/physics → core/geom/3d}/gjk/mpr.d.ts +3 -3
  128. package/src/core/geom/3d/gjk/mpr.d.ts.map +1 -0
  129. package/src/{engine/physics → core/geom/3d}/gjk/mpr.js +368 -362
  130. package/src/{engine/physics/integration/quat_integrate.d.ts → core/geom/3d/quaternion/quat3_integrate.d.ts} +2 -2
  131. package/src/core/geom/3d/quaternion/quat3_integrate.d.ts.map +1 -0
  132. package/src/{engine/physics/integration/quat_integrate.js → core/geom/3d/quaternion/quat3_integrate.js} +1 -1
  133. package/src/{engine/physics/narrowphase/PosedShape.d.ts → core/geom/3d/shape/PosedShape3D.d.ts} +9 -8
  134. package/src/{engine/physics/narrowphase/PosedShape.d.ts.map → core/geom/3d/shape/PosedShape3D.d.ts.map} +1 -1
  135. package/src/{engine/physics/narrowphase/PosedShape.js → core/geom/3d/shape/PosedShape3D.js} +10 -9
  136. package/src/core/geom/3d/shape/TransformedShape3D.d.ts.map +1 -1
  137. package/src/core/geom/3d/shape/TransformedShape3D.js +15 -11
  138. package/src/core/geom/vec3/v3_quat3_apply_inverse.d.ts +1 -1
  139. package/src/core/geom/vec3/v3_quat3_apply_inverse.js +1 -1
  140. package/src/core/math/complex/complex_add.d.ts +1 -1
  141. package/src/core/math/complex/complex_add.d.ts.map +1 -1
  142. package/src/core/math/complex/complex_add.js +12 -3
  143. package/src/core/math/complex/complex_div.d.ts +1 -1
  144. package/src/core/math/complex/complex_div.d.ts.map +1 -1
  145. package/src/core/math/complex/complex_div.js +11 -4
  146. package/src/core/math/complex/complex_mul.d.ts +1 -1
  147. package/src/core/math/complex/complex_mul.d.ts.map +1 -1
  148. package/src/core/math/complex/complex_mul.js +10 -3
  149. package/src/core/math/complex/complex_sub.d.ts +1 -1
  150. package/src/core/math/complex/complex_sub.d.ts.map +1 -1
  151. package/src/core/math/complex/complex_sub.js +12 -3
  152. package/src/{engine/physics/fluid/solver/optimal_sor_omega.d.ts → core/math/linalg/sor_optimal_omega.d.ts} +4 -3
  153. package/src/core/math/linalg/sor_optimal_omega.d.ts.map +1 -0
  154. package/src/{engine/physics/fluid/solver/optimal_sor_omega.js → core/math/linalg/sor_optimal_omega.js} +4 -3
  155. package/src/core/math/lookup/ParameterLookupTable.d.ts +123 -0
  156. package/src/core/math/lookup/ParameterLookupTable.d.ts.map +1 -0
  157. package/src/core/math/lookup/ParameterLookupTable.js +495 -0
  158. package/src/core/math/lookup/ParameterLookupTableFlags.d.ts +5 -0
  159. package/src/core/math/lookup/ParameterLookupTableFlags.d.ts.map +1 -0
  160. package/src/core/math/lookup/ParameterLookupTableFlags.js +6 -0
  161. package/src/core/math/physics/kinematics/computeInterceptPoint.d.ts.map +1 -0
  162. package/src/{engine/physics → core/math/physics/kinematics}/computeInterceptPoint.js +79 -79
  163. package/src/core/math/physics/mie/ri_air.d.ts.map +1 -1
  164. package/src/core/math/physics/mie/ri_air.js +1 -3
  165. package/src/core/math/physics/mie/ri_ammonium_sulfate.d.ts.map +1 -1
  166. package/src/core/math/physics/mie/ri_ammonium_sulfate.js +1 -3
  167. package/src/core/math/physics/mie/ri_brine.d.ts.map +1 -1
  168. package/src/core/math/physics/mie/ri_brine.js +1 -3
  169. package/src/core/math/physics/mie/ri_dust.d.ts.map +1 -1
  170. package/src/core/math/physics/mie/ri_dust.js +1 -3
  171. package/src/core/math/physics/mie/ri_pollen.d.ts.map +1 -1
  172. package/src/core/math/physics/mie/ri_pollen.js +1 -3
  173. package/src/core/math/physics/mie/ri_smoke.d.ts.map +1 -1
  174. package/src/core/math/physics/mie/ri_smoke.js +1 -3
  175. package/src/core/math/physics/mie/ri_soot.d.ts.map +1 -1
  176. package/src/core/math/physics/mie/ri_soot.js +1 -3
  177. package/src/core/math/physics/mie/ri_water.d.ts.map +1 -1
  178. package/src/core/math/physics/mie/ri_water.js +1 -3
  179. package/src/core/math/random/random_pick_weighted_index.d.ts +10 -0
  180. package/src/core/math/random/random_pick_weighted_index.d.ts.map +1 -0
  181. package/src/core/math/random/random_pick_weighted_index.js +26 -0
  182. package/src/core/model/node-graph/NodeGraph.d.ts +9 -0
  183. package/src/core/model/node-graph/NodeGraph.d.ts.map +1 -1
  184. package/src/core/model/node-graph/NodeGraph.js +38 -0
  185. package/src/core/model/node-graph/visual/NodeGraphVisualData.d.ts +23 -0
  186. package/src/core/model/node-graph/visual/NodeGraphVisualData.d.ts.map +1 -1
  187. package/src/core/model/node-graph/visual/NodeGraphVisualData.js +54 -0
  188. package/src/core/path/convertPathToURL.d.ts +9 -0
  189. package/src/core/path/convertPathToURL.d.ts.map +1 -0
  190. package/src/core/path/convertPathToURL.js +107 -0
  191. package/src/core/process/worker/WorkerBuilder.js +1 -1
  192. package/src/core/process/worker/extractTransferables.js +1 -1
  193. package/src/engine/animation/curve/draw/build_tangent_editor.d.ts.map +1 -1
  194. package/src/engine/animation/curve/draw/build_tangent_editor.js +8 -1
  195. package/src/engine/animation/curve/editor/createKeyframeDraggableAspect.d.ts.map +1 -1
  196. package/src/engine/animation/curve/editor/createKeyframeDraggableAspect.js +11 -5
  197. package/src/engine/asset/Asset.d.ts.map +1 -1
  198. package/src/engine/asset/Asset.js +16 -6
  199. package/src/engine/asset/AssetManager.d.ts +61 -52
  200. package/src/engine/asset/AssetManager.d.ts.map +1 -1
  201. package/src/engine/asset/AssetManager.js +1411 -1045
  202. package/src/engine/asset/AssetRequest.d.ts +1 -1
  203. package/src/engine/asset/AssetRequest.d.ts.map +1 -1
  204. package/src/engine/asset/AssetRequest.js +1 -1
  205. package/src/engine/asset/AssetRequestScope.d.ts.map +1 -1
  206. package/src/engine/asset/AssetRequestScope.js +7 -0
  207. package/src/engine/asset/PendingAsset.d.ts +32 -1
  208. package/src/engine/asset/PendingAsset.d.ts.map +1 -1
  209. package/src/engine/asset/PendingAsset.js +108 -61
  210. package/src/engine/asset/loaders/ArrayBufferLoader.js +2 -2
  211. package/src/engine/asset/loaders/AssetLoader.d.ts.map +1 -1
  212. package/src/engine/asset/loaders/AssetLoader.js +19 -2
  213. package/src/engine/asset/loaders/GLTFAssetLoader.d.ts.map +1 -1
  214. package/src/engine/asset/loaders/GLTFAssetLoader.js +123 -114
  215. package/src/engine/asset/loaders/JavascriptAssetLoader.d.ts +1 -1
  216. package/src/engine/asset/loaders/JavascriptAssetLoader.d.ts.map +1 -1
  217. package/src/engine/asset/loaders/JavascriptAssetLoader.js +31 -47
  218. package/src/engine/asset/loaders/JsonAssetLoader.js +1 -1
  219. package/src/engine/asset/loaders/SVGAssetLoader.js +2 -2
  220. package/src/engine/asset/loaders/SoundAssetLoader.js +1 -1
  221. package/src/engine/asset/loaders/TextAssetLoader.js +2 -2
  222. package/src/{core → engine/asset/loaders}/font/FontAsset.d.ts +1 -1
  223. package/src/engine/asset/loaders/font/FontAsset.d.ts.map +1 -0
  224. package/src/{core → engine/asset/loaders}/font/FontAsset.js +21 -21
  225. package/src/{core → engine/asset/loaders}/font/FontAssetLoader.d.ts +1 -1
  226. package/src/engine/asset/loaders/font/FontAssetLoader.d.ts.map +1 -0
  227. package/src/{core → engine/asset/loaders}/font/FontAssetLoader.js +20 -20
  228. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts +1 -1
  229. package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts.map +1 -1
  230. package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +11 -20
  231. package/src/engine/asset/loaders/texture/TextureAssetLoader.d.ts.map +1 -1
  232. package/src/engine/asset/loaders/texture/TextureAssetLoader.js +8 -2
  233. package/src/engine/asset/preloader/AssetPreloader.js +1 -1
  234. package/src/engine/ecs/sockets/serialization/AttachmentSocketsAssetLoader.d.ts +1 -1
  235. package/src/engine/ecs/sockets/serialization/AttachmentSocketsAssetLoader.d.ts.map +1 -1
  236. package/src/engine/ecs/sockets/serialization/AttachmentSocketsAssetLoader.js +19 -22
  237. package/src/engine/graphics/FrameThrottle.d.ts +1 -7
  238. package/src/engine/graphics/FrameThrottle.d.ts.map +1 -1
  239. package/src/engine/graphics/FrameThrottle.js +2 -24
  240. package/src/{core/geom/3d/shape/util → engine/graphics/debug}/shape_to_visual_entity.d.ts +1 -1
  241. package/src/engine/graphics/debug/shape_to_visual_entity.d.ts.map +1 -0
  242. package/src/{core/geom/3d/shape/util → engine/graphics/debug}/shape_to_visual_entity.js +159 -159
  243. package/src/{core/geom/3d/tetrahedra → engine/graphics/debug}/visualize_tetrahedral_mesh.d.ts +1 -1
  244. package/src/engine/graphics/debug/visualize_tetrahedral_mesh.d.ts.map +1 -0
  245. package/src/{core/geom/3d/tetrahedra → engine/graphics/debug}/visualize_tetrahedral_mesh.js +46 -46
  246. package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/AnimationGraphDefinitionAssetLoader.d.ts +1 -1
  247. package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/AnimationGraphDefinitionAssetLoader.d.ts.map +1 -1
  248. package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/AnimationGraphDefinitionAssetLoader.js +22 -32
  249. package/src/engine/graphics/particles/particular/engine/emitter/serde/ParameterLookupTableSerializationAdapter.d.ts.map +1 -1
  250. package/src/engine/graphics/particles/particular/engine/emitter/serde/ParameterLookupTableSerializationAdapter.js +2 -76
  251. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.d.ts.map +1 -1
  252. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +2 -427
  253. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTableFlags.d.ts +1 -4
  254. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTableFlags.d.ts.map +1 -1
  255. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTableFlags.js +2 -6
  256. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
  257. package/src/engine/graphics/render/forward_plus/read_frustum_corner.d.ts +1 -8
  258. package/src/engine/graphics/render/forward_plus/read_frustum_corner.d.ts.map +1 -1
  259. package/src/engine/graphics/render/forward_plus/read_frustum_corner.js +2 -14
  260. package/src/engine/graphics/sh3/path_tracer/geometry/compute_triangle_group_aabb3.d.ts +1 -11
  261. package/src/engine/graphics/sh3/path_tracer/geometry/compute_triangle_group_aabb3.d.ts.map +1 -1
  262. package/src/engine/graphics/sh3/path_tracer/geometry/compute_triangle_group_aabb3.js +2 -46
  263. package/src/engine/graphics/sh3/prototypeSH3Probe.js +1 -1
  264. package/src/engine/graphics/texture/3d/scs3d_sample_linear3.d.ts +27 -0
  265. package/src/engine/graphics/texture/3d/scs3d_sample_linear3.d.ts.map +1 -0
  266. package/src/engine/graphics/texture/3d/scs3d_sample_linear3.js +81 -0
  267. package/src/engine/graphics/texture/isImageBitmap.d.ts +1 -6
  268. package/src/engine/graphics/texture/isImageBitmap.d.ts.map +1 -1
  269. package/src/engine/graphics/texture/isImageBitmap.js +2 -12
  270. package/src/{core/process/action → engine/intelligence/behavior/util}/AsynchronousDelayAction.d.ts +2 -2
  271. package/src/engine/intelligence/behavior/util/AsynchronousDelayAction.d.ts.map +1 -0
  272. package/src/{core/process/action → engine/intelligence/behavior/util}/AsynchronousDelayAction.js +55 -55
  273. package/src/engine/network/NetworkSession.d.ts +12 -1
  274. package/src/engine/network/NetworkSession.d.ts.map +1 -1
  275. package/src/engine/network/NetworkSession.js +52 -1
  276. package/src/engine/network/README.md +45 -0
  277. package/src/engine/network/convertPathToURL.d.ts +1 -8
  278. package/src/engine/network/convertPathToURL.d.ts.map +1 -1
  279. package/src/engine/network/convertPathToURL.js +2 -107
  280. package/src/engine/network/core/quantize/quantize_float.d.ts.map +1 -1
  281. package/src/engine/network/core/quantize/quantize_float.js +7 -0
  282. package/src/engine/network/core/quantize/quantize_position.d.ts.map +1 -1
  283. package/src/engine/network/core/quantize/quantize_position.js +12 -1
  284. package/src/engine/network/orchestrator/NetworkPeer.d.ts.map +1 -1
  285. package/src/engine/network/orchestrator/NetworkPeer.js +15 -1
  286. package/src/engine/network/replication/Replicator.d.ts +8 -0
  287. package/src/engine/network/replication/Replicator.d.ts.map +1 -1
  288. package/src/engine/network/replication/Replicator.js +48 -0
  289. package/src/engine/network/transport/Channel.d.ts.map +1 -1
  290. package/src/engine/network/transport/Channel.js +46 -12
  291. package/src/engine/network/transport/ReliableCommandPipeline.d.ts +16 -0
  292. package/src/engine/network/transport/ReliableCommandPipeline.d.ts.map +1 -1
  293. package/src/engine/network/transport/ReliableCommandPipeline.js +29 -0
  294. package/src/engine/network/transport/adapters/NodeUDPTransport.d.ts.map +1 -1
  295. package/src/engine/network/transport/adapters/NodeUDPTransport.js +7 -1
  296. package/src/engine/network/transport/fragments/packet_size.d.ts +5 -5
  297. package/src/engine/network/transport/fragments/packet_size.d.ts.map +1 -1
  298. package/src/engine/network/transport/fragments/packet_size.js +5 -5
  299. package/src/engine/physics/BULLET_REVIEW.md +1 -1
  300. package/src/engine/physics/JOLT_REVIEW.md +2 -2
  301. package/src/engine/physics/PLAN.md +1094 -945
  302. package/src/engine/physics/RAPIER_REVIEW.md +2 -2
  303. package/src/engine/physics/body/BodyStorage.d.ts +2 -12
  304. package/src/engine/physics/body/BodyStorage.d.ts.map +1 -1
  305. package/src/engine/physics/body/BodyStorage.js +406 -452
  306. package/src/engine/physics/body/SolverBodyState.d.ts.map +1 -1
  307. package/src/engine/physics/body/SolverBodyState.js +12 -3
  308. package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts +28 -3
  309. package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts.map +1 -1
  310. package/src/engine/physics/broadphase/compute_fat_world_aabb.js +60 -24
  311. package/src/engine/physics/broadphase/generate_pairs.d.ts +9 -5
  312. package/src/engine/physics/broadphase/generate_pairs.d.ts.map +1 -1
  313. package/src/engine/physics/broadphase/generate_pairs.js +52 -37
  314. package/src/engine/physics/ccd/linear_sweep.d.ts +15 -5
  315. package/src/engine/physics/ccd/linear_sweep.d.ts.map +1 -1
  316. package/src/engine/physics/ccd/linear_sweep.js +122 -40
  317. package/src/engine/physics/constraint/solve_constraints.d.ts.map +1 -1
  318. package/src/engine/physics/constraint/solve_constraints.js +830 -805
  319. package/src/engine/physics/contact/ManifoldStore.d.ts +91 -16
  320. package/src/engine/physics/contact/ManifoldStore.d.ts.map +1 -1
  321. package/src/engine/physics/contact/ManifoldStore.js +204 -60
  322. package/src/engine/physics/ecs/BodyKind.d.ts +7 -3
  323. package/src/engine/physics/ecs/BodyKind.d.ts.map +1 -1
  324. package/src/engine/physics/ecs/BodyKind.js +29 -25
  325. package/src/engine/physics/ecs/Collider.d.ts +7 -0
  326. package/src/engine/physics/ecs/Collider.d.ts.map +1 -1
  327. package/src/engine/physics/ecs/Collider.js +7 -0
  328. package/src/engine/physics/ecs/ColliderSerializationAdapter.js +1 -1
  329. package/src/engine/physics/ecs/PhysicsSystem.d.ts +110 -6
  330. package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
  331. package/src/engine/physics/ecs/PhysicsSystem.js +467 -45
  332. package/src/engine/physics/ecs/RigidBody.d.ts +20 -5
  333. package/src/engine/physics/ecs/RigidBody.d.ts.map +1 -1
  334. package/src/engine/physics/ecs/RigidBody.js +307 -286
  335. package/src/engine/physics/ecs/RigidBodyFlags.d.ts +6 -3
  336. package/src/engine/physics/ecs/RigidBodyFlags.d.ts.map +1 -1
  337. package/src/engine/physics/ecs/RigidBodyFlags.js +31 -28
  338. package/src/engine/physics/ecs/RigidBodySerializationAdapter.d.ts +12 -4
  339. package/src/engine/physics/ecs/RigidBodySerializationAdapter.d.ts.map +1 -1
  340. package/src/engine/physics/ecs/RigidBodySerializationAdapter.js +19 -5
  341. package/src/engine/physics/ecs/RigidBodySerializationUpgrader_0_1.d.ts +10 -0
  342. package/src/engine/physics/ecs/RigidBodySerializationUpgrader_0_1.d.ts.map +1 -0
  343. package/src/engine/physics/ecs/RigidBodySerializationUpgrader_0_1.js +37 -0
  344. package/src/engine/physics/ecs/find_non_finite_physics_state.d.ts +28 -0
  345. package/src/engine/physics/ecs/find_non_finite_physics_state.d.ts.map +1 -0
  346. package/src/engine/physics/ecs/find_non_finite_physics_state.js +76 -0
  347. package/src/engine/physics/events/ContactEventBuffer.d.ts +11 -0
  348. package/src/engine/physics/events/ContactEventBuffer.d.ts.map +1 -1
  349. package/src/engine/physics/events/ContactEventBuffer.js +40 -0
  350. package/src/engine/physics/events/diff_manifolds.d.ts +30 -13
  351. package/src/engine/physics/events/diff_manifolds.d.ts.map +1 -1
  352. package/src/engine/physics/events/diff_manifolds.js +87 -50
  353. package/src/engine/physics/fluid/FluidField.d.ts +45 -17
  354. package/src/engine/physics/fluid/FluidField.d.ts.map +1 -1
  355. package/src/engine/physics/fluid/FluidField.js +53 -23
  356. package/src/engine/physics/fluid/FluidSimulator.d.ts +141 -5
  357. package/src/engine/physics/fluid/FluidSimulator.d.ts.map +1 -1
  358. package/src/engine/physics/fluid/FluidSimulator.js +336 -43
  359. package/src/engine/physics/fluid/REVIEW_02_PLAN.md +114 -0
  360. package/src/engine/physics/fluid/ecs/FluidComponent.d.ts +4 -3
  361. package/src/engine/physics/fluid/ecs/FluidComponent.d.ts.map +1 -1
  362. package/src/engine/physics/fluid/ecs/FluidComponent.js +4 -3
  363. package/src/engine/physics/fluid/ecs/FluidSystem.d.ts +3 -3
  364. package/src/engine/physics/fluid/effector/AmbientWindFluidEffector.d.ts +41 -0
  365. package/src/engine/physics/fluid/effector/AmbientWindFluidEffector.d.ts.map +1 -0
  366. package/src/engine/physics/fluid/effector/AmbientWindFluidEffector.js +124 -0
  367. package/src/engine/physics/fluid/effector/WakeFluidEffector.d.ts +27 -8
  368. package/src/engine/physics/fluid/effector/WakeFluidEffector.d.ts.map +1 -1
  369. package/src/engine/physics/fluid/effector/WakeFluidEffector.js +67 -18
  370. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_scalar.d.ts +42 -0
  371. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_scalar.d.ts.map +1 -0
  372. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_scalar.js +136 -0
  373. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_velocity.d.ts +37 -0
  374. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_velocity.d.ts.map +1 -0
  375. package/src/engine/physics/fluid/solver/v3_grid_advect_maccormack_velocity.js +169 -0
  376. package/src/engine/physics/fluid/solver/v3_grid_advect_sl_velocity.d.ts +36 -0
  377. package/src/engine/physics/fluid/solver/v3_grid_advect_sl_velocity.d.ts.map +1 -0
  378. package/src/engine/physics/fluid/solver/v3_grid_advect_sl_velocity.js +100 -0
  379. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.d.ts +6 -0
  380. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.d.ts.map +1 -1
  381. package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.js +6 -0
  382. package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.d.ts +7 -2
  383. package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.d.ts.map +1 -1
  384. package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.js +17 -12
  385. package/src/engine/physics/fluid/solver/v3_grid_apply_vorticity_confinement.d.ts +42 -0
  386. package/src/engine/physics/fluid/solver/v3_grid_apply_vorticity_confinement.d.ts.map +1 -0
  387. package/src/engine/physics/fluid/solver/v3_grid_apply_vorticity_confinement.js +131 -0
  388. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts +32 -22
  389. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts.map +1 -1
  390. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.js +43 -26
  391. package/src/engine/physics/fluid/solver/v3_grid_patch_edges_constant.d.ts +31 -0
  392. package/src/engine/physics/fluid/solver/v3_grid_patch_edges_constant.d.ts.map +1 -0
  393. package/src/engine/physics/fluid/solver/v3_grid_patch_edges_constant.js +77 -0
  394. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts +26 -19
  395. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts.map +1 -1
  396. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.js +46 -42
  397. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts +38 -10
  398. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts.map +1 -1
  399. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.js +158 -75
  400. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts +22 -17
  401. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts.map +1 -1
  402. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.js +108 -96
  403. package/src/engine/physics/inertia/world_inverse_inertia.d.ts +30 -1
  404. package/src/engine/physics/inertia/world_inverse_inertia.d.ts.map +1 -1
  405. package/src/engine/physics/inertia/world_inverse_inertia.js +160 -116
  406. package/src/engine/physics/integration/integrate_position.js +97 -97
  407. package/src/engine/physics/island/IslandBuilder.d.ts +49 -8
  408. package/src/engine/physics/island/IslandBuilder.d.ts.map +1 -1
  409. package/src/engine/physics/island/IslandBuilder.js +93 -14
  410. package/src/engine/physics/narrowphase/box_box_manifold.d.ts.map +1 -1
  411. package/src/engine/physics/narrowphase/box_box_manifold.js +683 -673
  412. package/src/engine/physics/narrowphase/box_triangle_contact.d.ts.map +1 -1
  413. package/src/engine/physics/narrowphase/box_triangle_contact.js +899 -749
  414. package/src/engine/physics/narrowphase/capsule_contacts.d.ts +27 -0
  415. package/src/engine/physics/narrowphase/capsule_contacts.d.ts.map +1 -1
  416. package/src/engine/physics/narrowphase/capsule_contacts.js +624 -459
  417. package/src/engine/physics/narrowphase/capsule_triangle_contact.d.ts.map +1 -1
  418. package/src/engine/physics/narrowphase/capsule_triangle_contact.js +58 -38
  419. package/src/engine/physics/narrowphase/compute_penetration.d.ts.map +1 -1
  420. package/src/engine/physics/narrowphase/compute_penetration.js +369 -325
  421. package/src/engine/physics/narrowphase/convex_convex_manifold.d.ts +3 -1
  422. package/src/engine/physics/narrowphase/convex_convex_manifold.d.ts.map +1 -1
  423. package/src/engine/physics/narrowphase/convex_convex_manifold.js +568 -422
  424. package/src/engine/physics/narrowphase/decomposition/heightmap_enumerate_triangles.d.ts +6 -3
  425. package/src/engine/physics/narrowphase/decomposition/heightmap_enumerate_triangles.d.ts.map +1 -1
  426. package/src/engine/physics/narrowphase/decomposition/heightmap_enumerate_triangles.js +66 -10
  427. package/src/engine/physics/narrowphase/decomposition/mesh_enumerate_triangles.d.ts +4 -1
  428. package/src/engine/physics/narrowphase/decomposition/mesh_enumerate_triangles.d.ts.map +1 -1
  429. package/src/engine/physics/narrowphase/decomposition/mesh_enumerate_triangles.js +97 -94
  430. package/src/engine/physics/narrowphase/mesh_mesh_tet_manifold.js +117 -117
  431. package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -1
  432. package/src/engine/physics/narrowphase/narrowphase_step.js +1738 -1739
  433. package/src/engine/physics/narrowphase/reduce_manifold_contacts.d.ts +14 -7
  434. package/src/engine/physics/narrowphase/reduce_manifold_contacts.d.ts.map +1 -1
  435. package/src/engine/physics/narrowphase/reduce_manifold_contacts.js +74 -69
  436. package/src/engine/physics/persistence/solver_caches.d.ts +20 -0
  437. package/src/engine/physics/persistence/solver_caches.d.ts.map +1 -0
  438. package/src/engine/physics/persistence/solver_caches.js +309 -0
  439. package/src/engine/physics/queries/overlap_shape.d.ts.map +1 -1
  440. package/src/engine/physics/queries/overlap_shape.js +187 -184
  441. package/src/engine/physics/queries/raycast.d.ts +3 -2
  442. package/src/engine/physics/queries/raycast.d.ts.map +1 -1
  443. package/src/engine/physics/queries/raycast.js +37 -11
  444. package/src/engine/physics/queries/shape_cast.d.ts +18 -5
  445. package/src/engine/physics/queries/shape_cast.d.ts.map +1 -1
  446. package/src/engine/physics/queries/shape_cast.js +417 -393
  447. package/src/engine/physics/solver/solve_contacts.d.ts +22 -6
  448. package/src/engine/physics/solver/solve_contacts.d.ts.map +1 -1
  449. package/src/engine/physics/solver/solve_contacts.js +1482 -1338
  450. package/src/engine/physics/vehicle/RaycastVehicle.d.ts.map +1 -1
  451. package/src/engine/physics/vehicle/RaycastVehicle.js +344 -339
  452. package/src/engine/ui/DraggableAspect.d.ts +12 -3
  453. package/src/engine/ui/DraggableAspect.d.ts.map +1 -1
  454. package/src/engine/ui/DraggableAspect.js +115 -83
  455. package/src/generation/COORDINATES.md +54 -0
  456. package/src/generation/GridTaskGroup.js +2 -2
  457. package/src/generation/REVIEW_01_ACTION_PLAN.md +628 -0
  458. package/src/generation/automata/CaveGeneratorCellularAutomata.d.ts +9 -1
  459. package/src/generation/automata/CaveGeneratorCellularAutomata.d.ts.map +1 -1
  460. package/src/generation/automata/CaveGeneratorCellularAutomata.js +79 -59
  461. package/src/generation/automata/CellularAutomata.d.ts +6 -3
  462. package/src/generation/automata/CellularAutomata.d.ts.map +1 -1
  463. package/src/generation/automata/CellularAutomata.js +22 -19
  464. package/src/generation/filtering/CellFilter.d.ts +17 -0
  465. package/src/generation/filtering/CellFilter.d.ts.map +1 -1
  466. package/src/generation/filtering/CellFilter.js +117 -77
  467. package/src/generation/filtering/CellFilterCellMatcher.d.ts.map +1 -1
  468. package/src/generation/filtering/CellFilterCellMatcher.js +2 -0
  469. package/src/generation/filtering/boolean/CellFilterLiteralBoolean.d.ts +5 -0
  470. package/src/generation/filtering/boolean/CellFilterLiteralBoolean.d.ts.map +1 -1
  471. package/src/generation/filtering/boolean/CellFilterLiteralBoolean.js +15 -0
  472. package/src/generation/filtering/core/CellFilterBinaryOperation.d.ts +0 -1
  473. package/src/generation/filtering/core/CellFilterBinaryOperation.d.ts.map +1 -1
  474. package/src/generation/filtering/core/CellFilterBinaryOperation.js +37 -50
  475. package/src/generation/filtering/core/CellFilterOperationTertiary.d.ts +0 -1
  476. package/src/generation/filtering/core/CellFilterOperationTertiary.d.ts.map +1 -1
  477. package/src/generation/filtering/core/CellFilterOperationTertiary.js +43 -59
  478. package/src/generation/filtering/core/CellFilterUnaryOperation.d.ts +0 -1
  479. package/src/generation/filtering/core/CellFilterUnaryOperation.d.ts.map +1 -1
  480. package/src/generation/filtering/core/CellFilterUnaryOperation.js +29 -33
  481. package/src/generation/filtering/numeric/CellFilterCache.d.ts +1 -0
  482. package/src/generation/filtering/numeric/CellFilterCache.d.ts.map +1 -1
  483. package/src/generation/filtering/numeric/complex/CellFilterAngleToNormal.d.ts +3 -2
  484. package/src/generation/filtering/numeric/complex/CellFilterAngleToNormal.d.ts.map +1 -1
  485. package/src/generation/filtering/numeric/complex/CellFilterAngleToNormal.js +9 -35
  486. package/src/generation/filtering/numeric/complex/CellFilterCurvature.d.ts +0 -1
  487. package/src/generation/filtering/numeric/complex/CellFilterCurvature.d.ts.map +1 -1
  488. package/src/generation/filtering/numeric/complex/CellFilterCurvature.js +19 -43
  489. package/src/generation/filtering/numeric/complex/CellFilterFXAA.d.ts +0 -1
  490. package/src/generation/filtering/numeric/complex/CellFilterFXAA.d.ts.map +1 -1
  491. package/src/generation/filtering/numeric/complex/CellFilterFXAA.js +2 -6
  492. package/src/generation/filtering/numeric/complex/CellFilterGaussianBlur.d.ts.map +1 -1
  493. package/src/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +9 -12
  494. package/src/generation/filtering/numeric/complex/CellFilterSimplexNoise.d.ts.map +1 -1
  495. package/src/generation/filtering/numeric/complex/CellFilterSimplexNoise.js +2 -1
  496. package/src/generation/filtering/numeric/complex/CellFilterSobel.d.ts +0 -1
  497. package/src/generation/filtering/numeric/complex/CellFilterSobel.d.ts.map +1 -1
  498. package/src/generation/filtering/numeric/complex/CellFilterSobel.js +2 -6
  499. package/src/generation/filtering/numeric/math/CellFilterInverseLerp.d.ts +5 -4
  500. package/src/generation/filtering/numeric/math/CellFilterInverseLerp.d.ts.map +1 -1
  501. package/src/generation/filtering/numeric/math/CellFilterInverseLerp.js +5 -4
  502. package/src/generation/filtering/numeric/process/computeFilterSurfaceNormal.d.ts +17 -0
  503. package/src/generation/filtering/numeric/process/computeFilterSurfaceNormal.d.ts.map +1 -0
  504. package/src/generation/filtering/numeric/process/computeFilterSurfaceNormal.js +42 -0
  505. package/src/generation/filtering/numeric/sampling/AbstractCellFilterSampleGridLayer.d.ts.map +1 -1
  506. package/src/generation/filtering/numeric/sampling/AbstractCellFilterSampleGridLayer.js +7 -1
  507. package/src/generation/filtering/numeric/util/populateSampler2DFromCellFilter.d.ts.map +1 -1
  508. package/src/generation/filtering/numeric/util/populateSampler2DFromCellFilter.js +7 -10
  509. package/src/generation/filtering/numeric/util/sampler_from_filter.d.ts.map +1 -1
  510. package/src/generation/filtering/numeric/util/sampler_from_filter.js +2 -1
  511. package/src/generation/grid/GridData.d.ts.map +1 -1
  512. package/src/generation/grid/GridData.js +14 -1
  513. package/src/generation/grid/actions/ContinuousGridCellAction.d.ts +10 -3
  514. package/src/generation/grid/actions/ContinuousGridCellAction.d.ts.map +1 -1
  515. package/src/generation/grid/actions/ContinuousGridCellAction.js +18 -3
  516. package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainHeight.d.ts +11 -1
  517. package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainHeight.d.ts.map +1 -1
  518. package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainHeight.js +13 -3
  519. package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainObstacle.d.ts +1 -1
  520. package/src/generation/grid/actions/ContinuousGridCellActionSetTerrainObstacle.js +2 -2
  521. package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.d.ts +1 -1
  522. package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.d.ts.map +1 -1
  523. package/src/generation/grid/actions/ContinuousGridCellActionWriteObstacle.js +4 -6
  524. package/src/generation/grid/coords/grid_to_texel.d.ts +9 -0
  525. package/src/generation/grid/coords/grid_to_texel.d.ts.map +1 -0
  526. package/src/generation/grid/coords/grid_to_texel.js +10 -0
  527. package/src/generation/grid/coords/texel_to_grid.d.ts +9 -0
  528. package/src/generation/grid/coords/texel_to_grid.d.ts.map +1 -0
  529. package/src/generation/grid/coords/texel_to_grid.js +10 -0
  530. package/src/generation/grid/generation/GridTaskApplyActionToCells.d.ts +2 -2
  531. package/src/generation/grid/generation/GridTaskApplyActionToCells.d.ts.map +1 -1
  532. package/src/generation/grid/generation/GridTaskApplyActionToCells.js +10 -6
  533. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts.map +1 -1
  534. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +20 -21
  535. package/src/generation/grid/generation/GridTaskExecuteRuleTimes.d.ts +7 -0
  536. package/src/generation/grid/generation/GridTaskExecuteRuleTimes.d.ts.map +1 -1
  537. package/src/generation/grid/generation/GridTaskExecuteRuleTimes.js +18 -10
  538. package/src/generation/grid/generation/discrete/GridTaskCellularAutomata.d.ts.map +1 -1
  539. package/src/generation/grid/generation/discrete/GridTaskCellularAutomata.js +16 -7
  540. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.d.ts +5 -3
  541. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.d.ts.map +1 -1
  542. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.js +26 -23
  543. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.d.ts.map +1 -1
  544. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.js +10 -1
  545. package/src/generation/grid/generation/grid/select/CellSupplierBestN.d.ts.map +1 -1
  546. package/src/generation/grid/generation/grid/select/CellSupplierBestN.js +4 -0
  547. package/src/generation/grid/generation/road/GridTaskGenerateRoads.d.ts +15 -8
  548. package/src/generation/grid/generation/road/GridTaskGenerateRoads.d.ts.map +1 -1
  549. package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +89 -92
  550. package/src/generation/markers/GridActionRuleSet.d.ts.map +1 -1
  551. package/src/generation/markers/GridActionRuleSet.js +10 -2
  552. package/src/generation/markers/GridCellActionPlaceMarker.d.ts +11 -0
  553. package/src/generation/markers/GridCellActionPlaceMarker.d.ts.map +1 -1
  554. package/src/generation/markers/GridCellActionPlaceMarker.js +20 -3
  555. package/src/generation/markers/GridCellActionPlaceMarkerGroup.d.ts +3 -1
  556. package/src/generation/markers/GridCellActionPlaceMarkerGroup.d.ts.map +1 -1
  557. package/src/generation/markers/GridCellActionPlaceMarkerGroup.js +9 -2
  558. package/src/generation/markers/MarkerNode.d.ts +8 -3
  559. package/src/generation/markers/MarkerNode.d.ts.map +1 -1
  560. package/src/generation/markers/MarkerNode.js +12 -5
  561. package/src/generation/markers/actions/MarkerNodeActionEntityPlacement.js +1 -1
  562. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessor.d.ts +1 -1
  563. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessor.d.ts.map +1 -1
  564. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessor.js +1 -1
  565. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.d.ts +1 -1
  566. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.d.ts.map +1 -1
  567. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.js +1 -1
  568. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessorRandomRotation.d.ts +1 -1
  569. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessorRandomRotation.d.ts.map +1 -1
  570. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessorRandomRotation.js +2 -2
  571. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessorSequence.d.ts +1 -1
  572. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessorSequence.d.ts.map +1 -1
  573. package/src/generation/markers/actions/placement/MarkerNodeEntityProcessorSequence.js +2 -2
  574. package/src/generation/markers/actions/probability/MarkerNodeActionSelectWeighted.d.ts.map +1 -1
  575. package/src/generation/markers/actions/probability/MarkerNodeActionSelectWeighted.js +6 -4
  576. package/src/generation/markers/actions/probability/MarkerNodeActionWeightedElement.d.ts.map +1 -1
  577. package/src/generation/markers/actions/probability/MarkerNodeActionWeightedElement.js +1 -3
  578. package/src/generation/markers/actions/terrain/MarkerNodeActionPaintTerrain.d.ts.map +1 -1
  579. package/src/generation/markers/actions/terrain/MarkerNodeActionPaintTerrain.js +12 -11
  580. package/src/generation/markers/matcher/MarkerNodeMatcherAnd.js +2 -2
  581. package/src/generation/markers/transform/MarkerNodeTransformer.d.ts +4 -1
  582. package/src/generation/markers/transform/MarkerNodeTransformer.d.ts.map +1 -1
  583. package/src/generation/markers/transform/MarkerNodeTransformer.js +4 -1
  584. package/src/generation/markers/transform/MarkerNodeTransformerAddPositionYFromFilter.d.ts.map +1 -1
  585. package/src/generation/markers/transform/MarkerNodeTransformerAddPositionYFromFilter.js +1 -3
  586. package/src/generation/markers/transform/MarkerNodeTransformerOffsetPosition.d.ts +5 -0
  587. package/src/generation/markers/transform/MarkerNodeTransformerOffsetPosition.d.ts.map +1 -1
  588. package/src/generation/markers/transform/MarkerNodeTransformerOffsetPosition.js +15 -0
  589. package/src/generation/markers/transform/MarkerNodeTransformerRecordProperty.d.ts.map +1 -1
  590. package/src/generation/markers/transform/MarkerNodeTransformerRecordProperty.js +1 -3
  591. package/src/generation/markers/transform/MarkerNodeTransformerYRotateByFilter.d.ts.map +1 -1
  592. package/src/generation/markers/transform/MarkerNodeTransformerYRotateByFilter.js +2 -4
  593. package/src/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.d.ts.map +1 -1
  594. package/src/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.js +1 -3
  595. package/src/generation/placement/GridCellPlacementRule.d.ts.map +1 -1
  596. package/src/generation/placement/GridCellPlacementRule.js +1 -3
  597. package/src/generation/placement/action/GridCellActionWriteFilterToLayer.d.ts.map +1 -1
  598. package/src/generation/placement/action/GridCellActionWriteFilterToLayer.js +8 -10
  599. package/src/generation/placement/action/random/weighted/CellActionSelectWeightedRandom.d.ts.map +1 -1
  600. package/src/generation/placement/action/random/weighted/CellActionSelectWeightedRandom.js +6 -4
  601. package/src/generation/placement/action/random/weighted/WeightedGridCellAction.d.ts.map +1 -1
  602. package/src/generation/placement/action/random/weighted/WeightedGridCellAction.js +1 -3
  603. package/src/generation/rules/CellMatcher.d.ts +3 -1
  604. package/src/generation/rules/CellMatcher.d.ts.map +1 -1
  605. package/src/generation/rules/CellMatcher.js +3 -1
  606. package/src/generation/rules/CellMatcherFromFilter.d.ts.map +1 -1
  607. package/src/generation/rules/CellMatcherFromFilter.js +1 -3
  608. package/src/generation/rules/CellMatcherLayerBitMaskTest.d.ts.map +1 -1
  609. package/src/generation/rules/CellMatcherLayerBitMaskTest.js +6 -20
  610. package/src/generation/test_support/executeTaskTreeSync.d.ts +9 -0
  611. package/src/generation/test_support/executeTaskTreeSync.d.ts.map +1 -0
  612. package/src/generation/test_support/executeTaskTreeSync.js +78 -0
  613. package/src/generation/theme/TerrainLayerRuleAggregator.d.ts +2 -1
  614. package/src/generation/theme/TerrainLayerRuleAggregator.d.ts.map +1 -1
  615. package/src/generation/theme/TerrainLayerRuleAggregator.js +9 -6
  616. package/src/generation/theme/Theme.d.ts +1 -1
  617. package/src/generation/theme/Theme.d.ts.map +1 -1
  618. package/src/generation/theme/Theme.js +2 -2
  619. package/src/generation/theme/ThemeEngine.d.ts +3 -3
  620. package/src/generation/theme/ThemeEngine.d.ts.map +1 -1
  621. package/src/generation/theme/ThemeEngine.js +26 -16
  622. package/src/generation/theme/cell/CellProcessingRule.d.ts +3 -3
  623. package/src/generation/theme/cell/CellProcessingRule.d.ts.map +1 -1
  624. package/src/generation/theme/cell/CellProcessingRule.js +6 -10
  625. package/src/generation/theme/cell/CellProcessingRuleSet.d.ts +1 -1
  626. package/src/generation/theme/cell/CellProcessingRuleSet.d.ts.map +1 -1
  627. package/src/generation/theme/cell/CellProcessingRuleSet.js +2 -2
  628. package/src/view/common/ListView.js +1 -1
  629. package/src/view/elements/BottomLeftResizeHandleView.d.ts.map +1 -1
  630. package/src/view/elements/BottomLeftResizeHandleView.js +13 -5
  631. package/src/core/font/FontAsset.d.ts.map +0 -1
  632. package/src/core/font/FontAssetLoader.d.ts.map +0 -1
  633. package/src/core/geom/3d/shape/util/shape_to_visual_entity.d.ts.map +0 -1
  634. package/src/core/geom/3d/tetrahedra/visualize_tetrahedral_mesh.d.ts.map +0 -1
  635. package/src/core/process/action/AsynchronousDelayAction.d.ts.map +0 -1
  636. package/src/engine/physics/computeInterceptPoint.d.ts.map +0 -1
  637. package/src/engine/physics/fluid/solver/optimal_sor_omega.d.ts.map +0 -1
  638. package/src/engine/physics/gjk/gjk.d.ts.map +0 -1
  639. package/src/engine/physics/gjk/gjk_epa_penetration.d.ts.map +0 -1
  640. package/src/engine/physics/gjk/minkowski_support.d.ts.map +0 -1
  641. package/src/engine/physics/gjk/mpr.d.ts.map +0 -1
  642. package/src/engine/physics/integration/quat_integrate.d.ts.map +0 -1
  643. package/src/engine/physics/island/union_find.d.ts.map +0 -1
  644. package/src/engine/physics/narrowphase/clip_against_axis_uv.d.ts.map +0 -1
  645. package/src/engine/physics/narrowphase/decomposition/aabb_world_to_local.d.ts.map +0 -1
  646. package/src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.d.ts +0 -21
  647. package/src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.d.ts.map +0 -1
  648. package/src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.js +0 -68
  649. package/src/generation/grid/generation/grid/GridTaskGridAlignedNodeGenerator.d.ts +0 -10
  650. package/src/generation/grid/generation/grid/GridTaskGridAlignedNodeGenerator.d.ts.map +0 -1
  651. package/src/generation/grid/generation/grid/GridTaskGridAlignedNodeGenerator.js +0 -17
  652. /package/src/{engine/physics → core/geom/3d}/gjk/NOTES.md +0 -0
  653. /package/src/{engine/physics → core/geom/3d}/gjk/gjk.d.ts +0 -0
  654. /package/src/{engine/physics → core/math/physics/kinematics}/computeInterceptPoint.d.ts +0 -0
@@ -1,945 +1,1094 @@
1
- # Physics engine — state of play
2
-
3
- Tracker for what's built, what's pending, and what's deferred.
4
-
5
- ---
6
-
7
- ## Context
8
-
9
- Deterministic JS rigid-body physics engine for the meep ECS. Target: game
10
- scenarios with up to millions of mostly-sleeping bodies, deterministic replays
11
- for netcode and reproducible debugging, broad shape coverage for common game
12
- collisions. Pure JS — no WASM, no SIMD, no worker threads.
13
-
14
- Architectural references for design choices:
15
- - **Jolt** — pre-allocated body pool, active-list iteration, two-tree
16
- broadphase (static + dynamic).
17
- - **Bullet** — `btPersistentManifold` cache layout with up to 4 points.
18
- - **Box2D / Catto** — sequential impulse with warm-starting, Sutherland-Hodgman
19
- face clipping for box-box.
20
-
21
- ---
22
-
23
- ## Done
24
-
25
- ### Foundations
26
- - `RigidBody`, `Collider`, `BodyKind`, `RigidBodyFlags`, `ColliderFlags`,
27
- `SleepState`, `PhysicsEvents`.
28
- - `BodyStorage`: SoA pool, generation-tracked stable IDs, dense awake list,
29
- min-heap free for deterministic ID reuse.
30
- - `PhysicsSystem`: full public API surface (gravity, force/impulse with and
31
- without application point, torque, velocity setter, wake/sleep, contact
32
- filter callback).
33
- - Binary serialization adapters for `RigidBody` and `Collider` (transient
34
- runtime state deliberately excluded).
35
- - `PairUint32Map`: open-addressed Robin Hood + Fibonacci hash for the
36
- pair → manifold-slot index (the one new collection added to `core/collection/`).
37
-
38
- ### Pipeline (`PhysicsSystem.fixedUpdate`)
39
- 1. Velocity integration (semi-implicit Euler, linear + angular, gravity,
40
- damping, world-frame inverse-inertia for torque)
41
- 2. Per-collider broadphase refit with fat AABB (Box2D-style velocity-padded
42
- slack)
43
- 3. Pair generation: per-leaf query against both BVHs (static + dynamic),
44
- canonical `(min, max)` pairs, dedup via manifold touched flag
45
- 4. Wake propagation for sleeping bodies in the pair list
46
- 5. Narrowphase cross-product over collider lists
47
- 6. Sequential-impulse solver (Catto-style, warm-start, friction, Baumgarte)
48
- 7. Position integration (linear + quaternion)
49
- 8. Sleep test (per-body velocity² below threshold for ≥ 0.5 s)
50
- 9. Manifold diff → `ContactBegin` / `Stay` / `End` event dispatch
51
- 10. `manifolds.advance_frame()` — roll touched bits, evict grace-expired slots
52
-
53
- ### Shape coverage
54
- | Pair | Path | Manifold |
55
- |---|---|---|
56
- | sphere-sphere | closed-form | 1 point |
57
- | sphere-box | closed-form (handles centre-inside-box) | 1 point |
58
- | capsule-sphere | point-on-segment closed-form | 1 point |
59
- | capsule-capsule | segment-segment closest pair | 1 point |
60
- | capsule-box | iterative segment-vs-OBB (primary) + cap-centre sphere-vs-OBB at each endpoint | up to 3 |
61
- | box-box face-face | SAT + Sutherland-Hodgman clipping | up to 4 |
62
- | box-box edge-edge | SAT + segment-segment closest-pair | 1 point |
63
- | sphere / box / capsule × concave (heightmap, mesh) | closed-form `*_triangle_contact` per triangle via decomposition dispatcher | up to a few points per triangle (deepest wins) |
64
- | other convex × concave | per-triangle GJK + EPA via decomposition dispatcher | 1 point per triangle |
65
- | anything else | GJK + EPA, MPR fallback on EPA non-convergence | 1 point |
66
-
67
- ### Non-convex shapes
68
- - **`is_convex` flag** on `AbstractShape3D.prototype` (default `true`).
69
- Overridden to `false` on `HeightMapShape3D`, `MeshShape3D`, `UnionShape3D`.
70
- `TransformedShape3D` inherits via getter that reads the wrapped subject.
71
- - **`HeightMapShape3D`** — orientation-vector + `Sampler2D`-backed terrain
72
- shape. Heights sampled via `sampleChannelCatmullRomUV` (matching the
73
- terrain system's geometry construction). Compute_bounding_box,
74
- contains_point, signed_distance, nearest_point_on_surface all
75
- implemented; `support` throws (non-convex by construction).
76
- - **`Triangle3D`** — buffer-flyweight convex shape. `bind(buffer, offset)`
77
- repoints at 9 consecutive floats in an external Float64Array. Zero
78
- allocation per emission; used by the decomposition path.
79
- - **Triangle decomposition machinery** under
80
- `engine/physics/narrowphase/decomposition/`:
81
- - `TRIANGLE_FLOAT_STRIDE = 10` per triangle (`vA.xyz`, `vB.xyz`,
82
- `vC.xyz`, `feature_id`).
83
- - `heightmap_enumerate_triangles(out, offset, shape, ...aabb)` —
84
- Arvo-projects the convex's AABB into heightmap-local, intersects
85
- with the footprint to derive a cell range, emits 2 triangles per
86
- cell with stable feature_ids.
87
- - `mesh_enumerate_triangles(out, offset, shape, ...aabb)` — linear
88
- O(N) scan over `MeshShape3D.indices` with tight per-triangle AABB
89
- filtering. feature_id = triangle index.
90
- - `aabb_world_to_local(out, world_aabb, pos, rot)` — 8-corner
91
- projection of a world AABB into a body's local frame.
92
- - `decompose_to_triangles(...)` — dispatcher switching on shape
93
- type marker.
94
- - **Narrowphase concave dispatch** in `narrowphase_step.js`: detects
95
- `is_convex === false`, computes convex's world AABB, projects to
96
- concave's local frame, decomposes, per-triangle GJK + EPA with
97
- one-sided face-normal rejection and contact-normal dedup. Concave-vs-
98
- concave dynamic pairs are explicitly refused.
99
-
100
- ### Solver
101
- - Sequential impulse with warm-starting (10 velocity iterations by default).
102
- - Coulomb friction with disk-clamped tangent impulses.
103
- - Baumgarte position correction folded into the velocity solve.
104
- - Full angular Jacobian (`I_w⁻¹ = R · diag · R^T`) and angular impulse
105
- application.
106
- - Public force/impulse-at-point API (`applyForceAt`, `applyImpulseAt`,
107
- `applyTorque`).
108
-
109
- ### Sleep + events
110
- - Per-island **atomic sleep**: an island sleeps when `max(|v|² + |ω|²)`
111
- across all members stays below the threshold long enough; the whole
112
- island sleeps in the same frame. Replaces the per-body chatter on
113
- weakly-connected piles.
114
- - **Atomic wake**: members of a sleeping island are threaded into a
115
- circular doubly-linked list (`sleep_group_next` / `sleep_group_prev`);
116
- waking any one member walks the chain and wakes the rest in the same
117
- call. A 100-block stack hit at the base wakes top-down in one frame
118
- rather than over 100 frames of broadphase propagation.
119
- - `DisableSleep` on any island member exempts the whole island.
120
- - ContactBegin / Stay / End buffer + dispatch through the per-entity
121
- `dataset.sendEvent(entity, PhysicsEvents.ContactBegin, ...)` channel — the
122
- sole contact-event path, delivered to each entity of the pair when a
123
- dataset is attached.
124
-
125
- ### Islands
126
- - **Union-find** with path halving + union by min-index over the awake-body
127
- + touched-contact graph (`engine/physics/island/union_find.js`).
128
- - **`IslandBuilder`** produces deterministic CSR-style output: bodies and
129
- manifold slots grouped by island, sorted ascending within and across
130
- islands. Static / kinematic bodies are constraint anchors only — they
131
- don't merge islands, so disjoint piles on the same floor are separate
132
- islands.
133
- - **Islands feed the sleep test + grouping, not a per-island solver loop.**
134
- The TGS contact solver flattens every island's contacts into one
135
- Gauss-Seidel sweep (`solver/solve_contacts.js`) — islands share no bodies,
136
- so a single flat sweep is identical to per-island sweeps. The partition is
137
- still rebuilt every step and consumed by the atomic-island sleep test and the
138
- joint/contact island grouping; it is also the natural unit for a future
139
- worker-based parallel solve (see Performance / Scale). (Earlier revisions ran
140
- the solver per island; the TGS rewrite flattened it — same result, simpler
141
- loop.)
142
-
143
- ### Compound bodies
144
- - A body has 0..N attached colliders. Each collider has its own world
145
- transform and its own BVH leaf.
146
- - Same-entity colliders, child-entity colliders (via `ParentEntity`), or
147
- hybrids all supported.
148
- - `ColliderObserverSystem` auto-attaches colliders via the dataset when
149
- paired with `PhysicsSystem` in an EntityManager.
150
- - Narrowphase runs the cross-product over both bodies' collider lists per
151
- body-pair, accumulates candidates, reduces to ≤4 contacts by
152
- depth + spread.
153
-
154
- ### Public queries
155
- - `raycast(origin, dir, max_dist, filter?)` — nearest hit across both trees,
156
- **refined to the true shape surface** (narrowphase). `result.t` /
157
- `result.normal` are exact for sphere / box / capsule / mesh / heightmap
158
- colliders (per-leaf analytic ray tests + triangle Möller–Trumbore for
159
- concave); composite convex shapes fall back to the broadphase AABB hit. A ray
160
- crossing a fat leaf AABB but missing the true shape is correctly a miss.
161
- - `shapeCast(ray, shape, rotation, result, filter?)` — broadphase swept
162
- AABB against both BVHs; per-candidate AABB-slab interval narrowing,
163
- coarse step over the narrowed window, GJK bisection to time-of-impact.
164
- Output normal is the true contact-surface normal at the kiss point,
165
- recovered by re-running GJK + EPA at `best_t` on the winning candidate.
166
- Falls back to `-ray.direction` only on EPA degeneracies (NaN / zero
167
- depth). Tests cover axis-aligned, off-axis, and oblique cube-vs-cube;
168
- sphere-vs-smooth-shape near-tangent has documented angular tolerance
169
- bands inherited from EPA on smooth supports.
170
- - `overlap(shape, position, rotation, output, output_offset, filter?)`
171
- — broadphase + per-candidate GJK overlap detection. Writes body_ids
172
- into a caller-sized buffer; returns count. Convex query shapes only
173
- (concave throws). Concave candidates routed through the per-triangle
174
- decomposition path. Designed for speculative kinematic queries on
175
- kinematic bodies (character controllers, AOE selection).
176
-
177
- ### Standalone narrowphase utilities
178
- - `deepest_pair_penetration(out_normal, shapeA, posA, rotA, shapeB, posB,
179
- rotB)` (exported from `narrowphase_step.js`) — runs the **same**
180
- `dispatch_pair` the contact solver consumes for one posed shape pair and
181
- returns the DEEPEST contact's depth + world normal (B → A). The single
182
- source of truth for "minimum-translation between two posed shapes", reused by
183
- `compute_penetration` (and available to any other query).
184
- - `compute_penetration(out_direction, shape_a, pos_a, rot_a, shape_b,
185
- pos_b, rot_b)` — non-system geometry primitive: positive penetration
186
- depth + outward direction (B → A convention) on overlap, 0 otherwise.
187
- **Hardened** — delegates to `deepest_pair_penetration`, so it is correct
188
- (not "correct sometimes") for every shape pair the engine can build:
189
- - sphere / box / capsule pairs → exact closed-form (box-box via SAT, so a
190
- small body resting on a large floor reports the few-cm near-face overlap,
191
- NOT the metres-deep "exit through the far side" that MPR's centroid-seeded
192
- portal used to return);
193
- - general convex pairs → GJK + EPA (exact for polytopes; curved shapes never
194
- reach it — they have closed forms);
195
- - convex × concave → triangle decomposition + the closed-form per-triangle
196
- solvers, bounded to each triangle's true 2-D extent (the old closed-mesh
197
- side-face over-report is gone).
198
- The previous per-triangle half-space test is retained ONLY as a recovery
199
- fallback for the one case the one-sided closed forms can't resolve: a convex
200
- shape that has fully tunnelled to the *inner* side of a concave surface (a
201
- depenetration query must still push it back out — exact for heightmap terrain,
202
- a valid outward push for closed meshes). Concave × concave throws (M×N
203
- triangle pairs out of scope). The spec asserts an "applying out_direction ×
204
- depth separates the shapes" invariant across every convex+convex pair type and
205
- convex+concave, plus exact per-type depths and the small-box-on-huge-floor
206
- regression (3 m → 0.05 m).
207
-
208
- ### Determinism
209
- - Direct typed-array writes on hot paths (bypassing `Vector3#set`'s observer
210
- dispatch) Transform writes still go through `set()` because external
211
- systems subscribe (TransformAttachment, EntityNode, FogOfWarRevealer,
212
- ViewportPosition).
213
- - Active body iteration sorted by body index.
214
- - Pair canonicalisation `(min, max)`.
215
- - Min-heap free list for slot reuse.
216
- - No `Math.random` anywhere in the simulation step.
217
- - Same-runtime bit-exact determinism by design; cross-runtime is a known
218
- future seam.
219
-
220
- ### Migration
221
- - `Motion` / `MotionSystem` / `MotionSerializationAdapter` relocated from
222
- the meep core (`engine/ecs/`) to the game-domain layer
223
- (`mir-engine/model/game/ecs/`). meep no longer ships the legacy shim.
224
-
225
- ### Alternative narrowphase: MPR
226
- - `engine/physics/gjk/mpr.js` Minkowski Portal Refinement (XenoCollide,
227
- Snethen GDC 2009). Single-pass overlap test + MTV computation,
228
- output convention matches EPA so it's drop-in compatible at any
229
- narrowphase call site. Tends to converge in 5–15 iterations on
230
- smooth shapes where EPA stalls (the polytope-on-curved-surface
231
- failure mode the torus-knot reproducer exercised). **Wired as the EPA
232
- non-convergence fallback** in `narrowphase_step` at both the body-level
233
- and per-triangle GJK+EPA paths: when EPA returns a non-positive / non-finite
234
- depth, MPR is tried before giving up. `shape_cast` and `compute_penetration`
235
- use it for the same reason.
236
-
237
- ### Bonus utilities
238
- - `core/geom/3d/line/line3_closest_points_segment_segment.js` generally
239
- useful 3D segment-segment closest-pair via Ericson §5.1.9.
240
- - `core/collection/PairUint32Map.js` — non-allocating
241
- `Map<(u32, u32) u32>` with Robin Hood + Fibonacci hash.
242
-
243
- ---
244
-
245
- ## Limitations / Known caveats
246
-
247
- - **Multi-collider material precision** *resolved for contact materials.* The
248
- narrowphase now combines the specific source-collider pair's friction /
249
- restitution per contact and stores them in the manifold (CONTACT_STRIDE
250
- offsets 14/15); the solver reads them per contact, so mixed-material compound
251
- bodies are accurate (regression test: an asymmetric-friction body yaws when
252
- shoved). Still primary-collider only: the contact-filter callback's
253
- `colliderA/B` arguments and the body-level sensor / concave-dispatch flags
254
- a smaller follow-up.
255
- - **EPA on smooth shapes**: degenerates (no flat face to converge on).
256
- Mitigated by closed-form paths for sphere/cube/capsule pairs and by the
257
- **MPR fallback** on EPA non-convergence; exotic convex shapes vs spheres can
258
- still occasionally fail if both EPA and MPR degenerate.
259
- - **EPA on `Triangle3D`** *resolved.* The concave dispatch now uses the
260
- closed-form `sphere_triangle_contact` / `box_triangle_contact` /
261
- `capsule_triangle_contact` solvers (P1.1a–c) instead of per-triangle GJK+EPA
262
- for those primitives, so a sphere/box/capsule on a heightmap or mesh decelerates
263
- and settles correctly; the `narrowphase_concave.spec.js` "drop and settle"
264
- cases and the mesh torus-knot settle test are **un-skipped**. Per-triangle
265
- GJK+EPA remains only as the fallback for *other* convex shapes vs triangles.
266
- (`compute_penetration` now routes through that same dispatch via
267
- `deepest_pair_penetration` see *Standalone narrowphase utilities* instead
268
- of its old half-space pre-test; the half-space test survives only as a
269
- tunnel-recovery fallback.)
270
- - **Box-box edge-edge contact**: a single point at the true closest-pair of the
271
- two edges (P3.2), not the old body-centre midpoint. This is geometrically
272
- correct and an empirical SAT-source sweep confirms the edge-cross branch
273
- *only* fires for **transverse** edge crossings (inter-edge angle ≈ 83-90°),
274
- where two skew lines meet at a unique point. Near-parallel edge contacts
275
- cannot reach this branch (a near-parallel `edgeA × edgeB` never wins the SAT
276
- minimum) they resolve through the multi-point face-clipping path. So the
277
- once-planned "multi-point edge contact for near-parallel edges" refinement is
278
- **moot**; see the resolved Stability backlog entry.
279
- - **CCD floor only**: speculative margin via the fattened AABB prevents
280
- most tunnelling. No per-body swept shape-cast for very fast objects.
281
- - **Cross-runtime determinism is not guaranteed**: `Math.sin/cos/exp/log`
282
- are ULP-correct but not bit-exact across V8 / SpiderMonkey / JSC.
283
- - **Dynamic concave bodies under TGS** *resolved by per-substep re-detection
284
- (below); kept here for the rationale.* The substep loop normally re-derives
285
- contact geometry analytically from the per-triangle contact feature (witness
286
- anchors + normal) captured once by narrowphase and held fixed for the whole
287
- outer step. For a convex body the contact feature is stable under the small
288
- per-step motion, so this is exact; for a *dynamic concave mesh body* (e.g. a
289
- torus knot rocking on its own lobes) the supporting triangle itself changes
290
- as the body rocks, so freezing the feature would pump a little energy in and
291
- the body would rock / slowly sink instead of settling. Note this is NOT a
292
- contact-precision issue
293
- the knot already uses the exact closed-form box-triangle solver (P1.1b);
294
- the problem is purely that TGS freezes *which* feature is in contact across
295
- substeps. The common concave case a convex dynamic body on static concave
296
- terrainis unaffected (the convex side's feature is stable), and that is
297
- the only concave case the engine targets.
298
-
299
- **Interim fix (implemented): per-substep concave re-detection.** For
300
- contact pairs involving a concave body, the substep loop re-runs the
301
- concave narrowphase geometry at the current substep pose (instead of the
302
- analytic refresh that freezes the feature) and re-prepares those contacts
303
- from the fresh witness/normal/depth so the contact normal tracks the
304
- rocking body and no energy is pumped in. Convex pairs keep the cheap
305
- analytic refresh. This is ~Nx narrowphase cost on concave-involved pairs
306
- (acceptable they're rare), gated by collider convexity. Un-skips the
307
- torus-knot dynamic-settle test.
308
-
309
- **Better long-term fix: convex collision proxies (not raw concave).** Every
310
- major engine (Box2D, Jolt, PhysX, Rapier) requires dynamic bodies to be
311
- convex or convex-decomposed; raw concave meshes are static-only. The right
312
- granularity is a *few* convex pieces NOT the thousands of tets a
313
- volumetric mesher produces (tet count collider/BVH-leaf count, which
314
- explodes the broadphase for an awake body; tet meshing is for a future
315
- FEM/soft-body subsystem, not rigid collision). See the "Convex collision
316
- proxies for dynamic concave bodies" backlog item a 3D convex hull builder
317
- (single-hull proxy covers most dynamic objects) plus an optional
318
- few-hull (V-HACD-style) decomposition. Those supersede the interim
319
- per-substep re-detection once built.
320
-
321
- ---
322
-
323
- ## Backlog (planned, in scope)
324
-
325
- ### Solver quality (next major work)
326
-
327
- These items move the engine from "competent" to "great". TGS is the next
328
- significant solver-architecture change; joints come after, once the TGS
329
- scaffolding is in place.
330
-
331
- - **TGS (Temporal Gauss-Seidel) substepping with split-impulse** Phases
332
- 1–3 **LANDED**. The solver is now a staged TGS pipeline
333
- (`solver/solve_contacts.js`: `prepare_contacts` per substep
334
- [`refresh_contacts` `warm_start_contacts` `solve_velocity`
335
- `solve_position`] `apply_restitution`), driven by the substep loop in
336
- `PhysicsSystem.fixedUpdate`. Defaults: `substeps = 4`,
337
- `velocityIterations = 4`, `positionIterations = 1` (all fields on
338
- `PhysicsSystem`).
339
- - **Phase 1 — split impulse.** Position correction runs on a per-body
340
- pseudo-velocity (`__pseudo_velocity`) folded into the pose by
341
- `integrate_position` and discarded; depth correction never
342
- contaminates persistent velocity.
343
- - **Phase 2 one-shot restitution.** Velocity pass is pure
344
- non-penetration; restitution is a single post-loop pass driving
345
- `vn -e·vn_approach`, gated on a running max normal impulse
346
- (`maxNormalImpulse`) so transient collisions still bounce under
347
- per-substep warm-start.
348
- - **Phase 3 — substep loop.** `substeps` sub-iterations at `h = dt/N`.
349
- Forces consumed once at full `dt` before the loop; gravity applied
350
- per substep; **warm-start replayed per substep** (the crux — a
351
- per-substep impulse balances one substep of gravity, so resting
352
- stacks hold at zero velocity). Contact geometry is re-derived
353
- **analytically** each substep from frozen local witness anchors +
354
- the trusted prepare-time depth (a sign-robust delta), so narrowphase
355
- runs **once** per outer step cheaper than the originally-planned
356
- per-substep match-and-merge refresh, and exact for convex
357
- primitives whose contact feature is stable under small motion.
358
-
359
- Results vs the single-step solver: a 100:1 mass ratio now stacks
360
- instead of crushing through (regression test added); 8-cube stacks
361
- settle to zero velocity and sleep (were impossible long-term under SI);
362
- falling-tower bench cost unchanged (~48 ms/1000 active bodies);
363
- `substeps = 1` reproduces the single-step result bit-for-bit-ish
364
- (one-frame restitution delay aside).
365
-
366
- **Hard-won lessons (for REVIEW_002):**
367
- - Warm-start MUST be per-substep, not once. Replaying a full-frame
368
- impulse once while gravity arrives per substep over-pushes resting
369
- contacts and *explodes* deep stacks. Per-substep warm-start +
370
- per-substep gravity cancel exactly at rest.
371
- - Restitution must gate on the *running max* normal impulse, not the
372
- end-of-loop value per-substep warm-start relaxes a transient
373
- contact's `j_n` back to ~0 by the end, which would suppress the
374
- bounce.
375
- - Analytic separation re-derivation beats per-substep narrowphase
376
- for convex shapes (cheaper, no manifold-lifecycle churn) but is
377
- only as good as the frozen normal see the concave caveat below.
378
-
379
- Follow-ups since the core landed:
380
- - [x] **Box-box SAT reference tie-break deadband** aligned cube
381
- stacks (4–10 high) now settle to zero velocity and sleep; the
382
- reference-face flip-flop that creeped/toppled them is gone.
383
- - [x] **Per-substep contact re-detection for concave pairs** — lifts
384
- the dynamic-concave-body limitation; the torus-knot dynamic-settle
385
- test is un-skipped. Concave pairs re-run narrowphase geometry each
386
- substep (`redetect_concave_contacts`); convex pairs keep the cheap
387
- analytic refresh.
388
-
389
- Remaining (Phases 4–6) now complete:
390
- - [x] Regression coverage: heavy-on-light pyramid (10× capstone on two
391
- light cubes settles + sleeps) and a ragdoll-stub (shoulder
392
- ball-socket + elbow hinge arm hangs, stays articulated, settles).
393
- - [x] REVIEW_002 retrospective `engine/physics/REVIEW_002.md`.
394
-
395
- References: Catto 2018 ("Soft Constraints" GDC talk + the TGS
396
- follow-up); Box2D v3 source (`b2ApplyRestitution`, the substep solver
397
- stages); Rapier as the closest architectural sibling.
398
-
399
- - [x] **Constraints / joints DONE (phases 1–7 below).** One configurable
400
- 6-DOF joint (lock/free/limit/motor/spring + swing-twist cone-twist) plus
401
- the raycast vehicle. Covers chains/ropes, ragdolls, vehicles (incl.
402
- suspension), and the mechanical set (doors, pistons, welds, sliders,
403
- powered hinges/wheels). The design rationale below is kept as history; the
404
- phasing checklist records what landed. Solver/joint retrospective in
405
- `REVIEW_003.md`.
406
-
407
- Original framing (now satisfied): TGS unblocked it (joint-chain
408
- convergence is a TGS sweet spot), warm-start + per-substep + island
409
- machinery was reusable, and the SPOOK compliance dial gave spring
410
- constraints essentially for free.
411
-
412
- **Foundational work (do first): generalise the solver to constraint
413
- rows.** Today `solver/solve_contacts.js` is hard-coded to the
414
- contact-shape constraint (normal + 2 friction tangents, ≥0 clamp,
415
- restitution, penetration bias). Joints are equality / inequality
416
- constraints on relative velocity at anchors, generally bilateral
417
- (impulse may be ±) with optional limits and motors. The clean shape —
418
- and what Jolt / Box2D-v3 do is a **generic constraint row**: a
419
- Jacobian (linear + angular parts per body), an effective mass, a bias
420
- (position error × SPOOK gain, or motor target), and impulse bounds
421
- `[lo, hi]` (`[0,∞)` for a contact/limit, `(−∞,∞)` for an equality,
422
- `[−maxForce·h, +maxForce·h]` for a motor). Each joint type just fills
423
- in its rows; the existing per-body impulse-apply primitive
424
- (`apply_impulse_to_body` + `world_inverse_inertia_apply`), the
425
- per-substep warm-start, the islands, and the split-impulse / SPOOK
426
- position handling are all reused. Contacts become *one* constraint
427
- type among several rather than the hard-coded path.
428
-
429
- The specific constraint set, its use-case mapping, and per-type
430
- architecture-fit assessment are under review (see the constraints
431
- sketch). High level: ball-socket / distance / spring / weld and the
432
- grab constraint are near drop-ins on the row machinery; hinge /
433
- prismatic / cone-twist / motors / limits add angular-row + bounded-row
434
- mechanics (still within the impulse framework); raycast vehicles,
435
- conveyor surface-velocity, and gear/pulley coupling are higher-level
436
- systems or contact modifiers that sit *on top of* the primitives
437
- rather than being generic rows.
438
-
439
- **Decision: build ONE configurable 6-DOF constraint** (PhysX D6 / Jolt
440
- SixDOF), implemented mode-by-mode. The `Joint` ECS component carries
441
- `dofMode[6]` (3 linear, 3 angular) each `{locked|free|limited|spring|
442
- motor}` + per-DOF limit/spring/motor config + warm-start accumulators.
443
- Concrete joints are configs, not new code (ball-socket = lock 3 linear;
444
- hinge = lock 3 linear + 2 angular; weld = lock 6; cone-twist = lock 3
445
- linear + limit 3 angular; suspension = spring 1 linear + lock rest).
446
-
447
- Phasing:
448
- 1. [x] Constraint-row solver as a **parallel row set** in the TGS
449
- substep loop (contacts left untouched, not ported lower risk).
450
- `constraint/solve_constraints.js` reuses `world_inverse_inertia`,
451
- per-substep warm-start, and the SPOOK position bias; `Joint`
452
- component + `link_joint`/`unlink_joint` in PhysicsSystem;
453
- `jointIterations` knob. Bodies need no collider.
454
- 2. [x] **LOCKED linear DOFs → ball-socket.** Pendulum (anchor pinned
455
- to a world pivot, body swings) and a 2-link chain (body↔body,
456
- joints stay connected, chain hangs) pass. **chains, ropes,
457
- pendulums working.**
458
- 3. [x] LOCKED angular + linear DOFs in the frame basis — **weld,
459
- hinge, prismatic done**. Joint frame bases
460
- (`localBasisA`/`localBasisB`); BOTH linear and angular rows now
461
- resolve in frame A's axes (cleared the world-axis linear debt — the
462
- solver is fully frame-relative). Angular: relative rotation
463
- `qD = conj(qA)·qB` small-angle error, ωB−ωA rows + SPOOK bias.
464
- Linear: `C·axis` error, vA−vB rows. `asWeld()` / `asHinge(axis)` /
465
- `asPrismatic(axis)` presets. Verified: weld holds pose + orientation
466
- against an off-centre torque; hinge swings about its free axis only
467
- (locked axes < 0.02); prismatic slides along its one free axis,
468
- locked on the others; all LOCKED-mode tests still green after the
469
- frame-basis rewrite.
470
- 4. [x] LIMITED + MOTOR (bounded rows) doors, pistons, wheel
471
- spin/drive, joint ROM. **LIMITED done** (linear + angular):
472
- `setLinearLimit(axis,lo,hi)` / `setAngularLimit(axis,lo,hi)` set a
473
- per-DOF travel/ROM range. The whole row set is now **one mode-
474
- agnostic solve** parameterised by `(bias, clamp range)`: LOCKED is
475
- the bilateral case (Baumgarte bias, unclamped); LIMITED is a
476
- **speculative (β=1) one-sided velocity constraint** that removes
477
- exactly the approach velocity so the DOF *lands on* its stop (no
478
- penetration, no rebound — an inelastic end-stop) and self-gates when
479
- far from the bound; only the push-out side of the bias is clamped so
480
- a teleport is eased out, not yanked. Verified: a vertical slider
481
- falls freely then stops dead on its lower stop (lands at the bound,
482
- no overshoot/rebound, locked axes held); a spun hinge stops dead on
483
- each ±end-stop with no rebound and holds. Angular position is the
484
- small-angle measure (`2·sin(θ/2)`) accurate for modest ROM, see
485
- phase 6 for wide cones. **MOTOR next** (target-velocity row, impulse
486
- clamped to `±maxForce·h`).
487
- 5. [x] SPRING (SPOOK soft) → suspension, bungees, soft ragdolls.
488
- `setLinearSpring(axis,k,c)` / `setAngularSpring(axis,k,c)`. A
489
- compliant (regularised) row in the same unified solve: per substep
490
- `denom = c + h·k`, compliance `γ = 1/(h·denom)`, restoring bias
491
- `(k/denom)·C`, softened mass `1/(K+γ)`; the iteration carries one
492
- extra `+ γ·λ_accum` term = 0 the LOCKED/LIMITED/MOTOR rows are
493
- bit-for-bit unchanged). Verified: a vertical strut settles at exactly
494
- the m·g/k deflection and a stiffer spring sags less and stays stable;
495
- an undamped spring oscillates about equilibrium (stores energy) while
496
- a damped one comes to rest; a torsional spring holds a gravity-loaded
497
- hinge at its balance angle. Suspension element ready (the simulated-
498
- wheel option for phase 7); also the soft basis for cone-twist.
499
- 6. [x] Cone-twist / swing-twist angular limits ragdolls. Opt-in
500
- `Joint.swingTwist` (or the `asConeTwist(twistLo,twistHi,swingY[,swingZ])`
501
- preset) switches the angular position measure from the per-axis
502
- small-angle vector to a swing-twist decomposition: angular X = twist
503
- about the bone, Y/Z = swing off it, each an **exact** angle. The
504
- existing LIMITED/SPRING/LOCKED rows are reused unchanged on those
505
- positions, so a twist/swing limit holds at the true angle at wide
506
- ROM (a 1.2 rad swing stops at 1.2, where the small-angle proxy
507
- drifts to ~1.287). Verified: exact swing/twist stops, free-within-
508
- cone, twist/swing independence; default (small-angle) path untouched.
509
- **Decision inlined, not the Quaternion method.** Benchmarked the
510
- allocation-free inlined `swing_twist_error` against
511
- `Quaternion.computeSwingAndTwist` (`swing_twist.bench.spec.js`): the
512
- inline is **~5x** faster than the method with reused out-params and
513
- **~10x** vs the naive fresh-allocation form (object property access +
514
- normalize + a quaternion multiply + GC). In the per-substep
515
- per-joint hot loop that margin is worth the duplicated math, so the
516
- solver inlines it (the Quaternion method stays for general callers).
517
- 7. [x] Vehicle layer **raycast-vehicle controller**
518
- (`vehicle/RaycastVehicle.js`): single chassis body + raycast wheels.
519
- Per frame (before `fixedUpdate`) each wheel casts its suspension ray,
520
- applies a spring+damper suspension force along the contact normal
521
- (`applyForceAt`), and a tyre-friction impulse (`applyImpulseAt`)
522
- lateral grip that cancels side-slip plus longitudinal drive/brake,
523
- clamped together to a friction circle μ·N. `addWheel`, `setSteering`,
524
- `setDriveForce`, `setBrake`; per-wheel runtime (contact, compression,
525
- normal, spin) for rendering. A controller on top of the public
526
- `raycast` + force API, not a new constraint; the 6-DOF spring+motor
527
- is the simulated-wheel alternative. Verified: hovers on its springs
528
- (4 contacts, settled), drives/coasts/brakes along its axis, tyre grip
529
- arrests a sideways shove, steering turns it upright, and it free-falls
530
- cleanly when airborne. Note: suspension is one dt-force per frame (not
531
- per-substep), so a resting chassis carries a ~g·h velocity-sample
532
- artifact (it hovers stably; position is steady to sub-cm). Ray
533
- accuracy follows `PhysicsSystem.raycast` now narrowphase-exact for
534
- sphere / box / capsule / mesh / heightmap ground.
535
- 8. [ ] Extras: pulley, gear, conveyor (contact surface-velocity),
536
- breakable-joint flag.
537
-
538
- Foundation gapsboth now closed:
539
- - [x] **Island integration.** Jointed dynamic-dynamic bodies are
540
- unioned into one island (`IslandBuilder` Pass 1b), so a chain /
541
- ragdoll sleeps and wakes as a unit; `__wake_joints` propagates wake
542
- across a joint when one side is awake and the other asleep
543
- (e.g. a kinematic/motor driver pulling a sleeping chain). Verified:
544
- a damped chain settles and both links sleep in one sleep group.
545
- - [x] **Generation-checked body references.** `solve_joints`,
546
- `IslandBuilder` Pass 1b and `__wake_joints` all gate on
547
- `storage.is_valid(packedId)`, so a joint to an unlinked / slot-reused
548
- body goes inert instead of attaching to the wrong body or crashing.
549
- Verified: unlinking a jointed body leaves the joint inert and the
550
- survivor free.
551
-
552
- References: Catto / Box2D-v3 joint solvers; Jolt's `Constraint` base
553
- (`SetupVelocityConstraint` / `WarmStartVelocityConstraint` /
554
- `SolveVelocityConstraint` / `SolvePositionConstraint`); PhysX D6 /
555
- ODE joint taxonomy.
556
-
557
- ### Stability
558
- - [x] **Closed-form triangle-vs-primitive solvers** `sphere_triangle_contact`
559
- / `box_triangle_contact` / `capsule_triangle_contact` (P1.1a–c), wired into
560
- the concave decomposition dispatch in place of per-triangle GJK+EPA for
561
- those primitives. Un-skipped the `narrowphase_concave.spec.js` ball-on-
562
- heightmap / mesh-cube settle tests and the `PhysicsSystem.spec.js`
563
- torus-knot test. Per-triangle GJK+EPA remains only as the fallback for
564
- *other* convex shapes vs triangles. `compute_penetration` now routes
565
- through the shared narrowphase dispatch (`deepest_pair_penetration`), so it
566
- uses the closed-form per-triangle solvers too the old closed-mesh
567
- over-report is gone; the half-space test is retained only as a
568
- tunnel-recovery fallback.
569
- - [x] **Edge-edge multi-point manifold** *resolved by design (no code
570
- change needed).* An empirical SAT-source sweep over a wide range of
571
- box-box orientations shows the single-point edge-cross branch only ever
572
- wins for **transverse** edge crossings (inter-edge angle ≈ 83-90°), where
573
- a single closest-pair point is geometrically exact. A near-parallel edge
574
- pair gives a near-degenerate `edgeA × edgeB` that never becomes the SAT
575
- minimum, so near-parallel ("line") edge contacts resolve through the
576
- multi-point **face-clipping** path instead confirmed by regression
577
- tests in `box_box_manifold.spec.js` (near-parallel tilted boxes → ≥ 2
578
- points; transverse crossing exactly 1 exact point). The originally
579
- planned refinement targeted a case the geometry can't produce, so it is
580
- closed rather than implemented.
581
- - [x] **Per-contact source-collider tracking (materials)** multi-material
582
- compound bodies now get accurate per-contact friction / restitution. The
583
- narrowphase combines the specific (colliderA, colliderB) pair's
584
- coefficients at dispatch time (the only place that knows the source
585
- collider on each side `contact/combine_material.js`) and stamps them
586
- into the manifold (CONTACT_STRIDE grown 14 → 16, offsets 14/15); the
587
- solver reads them per contact instead of from the body's primary collider.
588
- Regression test: an asymmetric-friction compound body yaws when shoved
589
- (the grippy collider drags), and a symmetric control does not. Still
590
- primary-collider-only: the contact-filter callback's collider args and the
591
- body-level sensor / concave flags (smaller follow-up).
592
- - [ ] **Joint-aware island sleep (ragdoll settle quality).** A draped,
593
- self-colliding 10-joint ragdoll does not fully sleep in 10 s surfaced by
594
- a 1000-seed Monte-Carlo sweep (`PhysicsSystem.ragdoll.spec.js`, `.skip`):
595
- for unlucky seeds a distal limb sustains a settled limit cycle (settled
596
- finite-difference accel up to ~1094 m/s² / ~1479 rad/s² at a limb end vs a
597
- ~55 m/s² median bounded, non-growing, penetration-free, so a quality gap
598
- not a divergence). The sleep test today is per-body `|v|²+|ω|²`; an island
599
- over-constrained by cone-twist limits + self-contacts keeps small residual
600
- jiggle above the per-body threshold so it never crosses into sleep.
601
- Candidate fixes: sleep a jointed/contacting island on its AGGREGATE motion
602
- rather than the per-body minimum, and/or a settled-regime relaxation (zero
603
- restitution + extra position iterations) once an island's energy is low.
604
- The sweep flags the worst seeds for replay. (Test infra also adds
605
- per-point kinematics tracking joint anchors + limb ends, with
606
- displacement→velocity→acceleration and the angular equivalents.)
607
- - [x] **Box-on-heightmap settling RESOLVED.** A dynamic box dropped onto a
608
- static HeightMapShape flat seam straddle AND the sloped dip — settles to
609
- full rest; the `PhysicsSystem.heightmap.spec.js` dip-drop reproducer is
610
- un-skipped and passing. Fixed by the combination of the same-feature-id
611
- contact de-dup in `redetect_pair_geometry` (1:1 claimed matching, so the
612
- several contacts one triangle emits all sharing its feature_id — no longer
613
- collapse onto a single candidate) and the HeightMapShape3D
614
- collision-tessellation work; together they give the box a stable per-substep
615
- contact set instead of a churning / collapsing one.
616
-
617
- Root cause, for the record: the historical "never settles" rattle was a
618
- depth divergence between the once-per-step `narrowphase_step` and the
619
- per-substep `redetect_pair_geometry`. At the SAME pose, re-detection
620
- over-reported a box-vs-triangle penetration as ~1 m (the "exit through the
621
- far side" class) where narrowphase reported ~1 cm, launching the box into an
622
- eternal vertical bounce (touch ~1 m over-correction separate → fall back
623
- re-contact). Both paths call the identical `dispatch_pair`, so the
624
- divergence was the same-fid collapse corrupting the matched geometry; with
625
- the de-dup in place the two paths now agree (verified: both report
626
- [0.0100 ×4] at a 0.01-deep flat contact, in-cell and 4-triangle straddle).
627
-
628
- Guards: `narrowphase/redetect_pair_geometry.spec.js` now pins BOTH
629
- invariants contacts sharing a feature_id keep distinct witnesses, and
630
- re-detect depth == narrowphase depth at a fixed pose (in-cell and
631
- 4-triangle seam-straddle cases); `ecs/PhysicsSystem.heightmap.spec.js` pins
632
- the observable settle. The depth-equality regression test the earlier
633
- diagnostic trail asked for is in place, closing this out.
634
-
635
- ### Performance / Scale
636
- - [x] **Per-body linear CCD shape-cast** opt-in continuous collision for
637
- fast movers where the speculative margin isn't enough.
638
- `RigidBodyFlags.CCD` (off by default) + `ccd/linear_sweep.js`.
639
- - **Approach (Box2D `b2_continuousPhysics`-style conservative
640
- advancement).** After the substep solver produces each body's final
641
- pose (between `apply_restitution` and the sleep test), a flagged fast
642
- mover's primary collider is swept along its NET step translation
643
- (start-of-step final pose) through the existing `shape_cast` TOI
644
- engine. On the first blocker the body is clamped to the contact pose
645
- and its inbound normal velocity removed (an inelastic stop); the next
646
- discrete step resolves the now-touching contact with the real
647
- material / restitution. Reuses `shape_cast` wholesale no new
648
- geometry. Start positions captured in Stage 1 over the post-wake awake
649
- set; the pass iterates the awake list in storage order (deterministic).
650
- - **Motion gate absolute slop, NOT body extent.** A body is swept when
651
- it moved more than `CCD_MIN_SWEEP_DISTANCE` (1 mm) this step. The gate
652
- exists only to skip near-stationary bodies (degenerate sweep + cost).
653
- It is deliberately *not* a fraction of the body's own size: tunnelling
654
- risk is set by the **obstacle's** thickness, not the mover's a 2 m
655
- sphere drifting 0.5 m/step still passes clean through a 1 cm floor, so
656
- an extent-based gate would (wrongly) wait until the body moved more
657
- than its own radius and miss every thin-obstacle tunnel below that
658
- speed.
659
- - **No self-clamp on resting/sliding contacts.** The sweep ignores an
660
- impact at `t ≈ 0` (`CCD_INITIAL_OVERLAP_EPS`): an initial overlap is a
661
- contact the body already sits/slides on, owned by the discrete solver,
662
- not a tunnel clamping there would freeze the body to the surface.
663
- - **Measured (falling-tower bench, 1000 random shapes onto a 1 cm floor,
664
- 600 ticks; clean A/B on identical code via `ccdEnabled`).** This bench
665
- is the WRONG validation vehicle for CCD, and the numbers prove it: CCD
666
- off **10/1000 tunnel**, median **42.7 ms**/step; all 1000 flagged →
667
- **50/1000 tunnel**, median **61.6 ms**. CCD makes it *worse*. The bench
668
- is a dense-pile **squeeze-through** scenario 1000 bodies stacked on a
669
- 1 cm floor, forced through by the column's weight over many steps — which
670
- is a *solver* limitation, not a missed single-step fly-through. CCD's
671
- post-solve clamp + velocity-kill fights the solver in a dense settling
672
- pile (it teleports mutually-stacking dynamics and breaks warm-start), so
673
- flagging a whole pile is an anti-pattern. CCD's real job — stopping a
674
- sparse fast mover against thin geometry is validated by
675
- `ccd/linear_sweep.spec.js` (9 tests: a fast cube tunnels a thin floor
676
- without the flag and is stopped with it; deterministic; resting bodies
677
- undisturbed). **Correction:** an earlier version of this entry and the
678
- commit message (`42163b0d4`) claimed a "0/1000 tunnel, 58.2 ms" on-leg
679
- that was never measured (a session tooling glitch); the real on-leg
680
- is 50/1000 / 61.6 ms.
681
- - **Scope (v1, documented):** linear sweep only (orientation fixed
682
- through the sweep); primary same-entity collider (child-entity
683
- colliders, synced outside the step, are not swept); EXACT against
684
- static geometry, APPROXIMATE against other dynamics (their
685
- start-of-step broadphase AABBs); the CCD stop is inelastic (the impact
686
- itself doesn't bounce — restitution applies on the next discrete
687
- contact); Dynamic bodies only. A body both resting on one surface and
688
- tunnelling another in the same step resolves only the resting contact
689
- (the `t 0` skip) rare; the next discrete step catches the rest.
690
- - **Follow-ups (the dense-pile finding points the way):** sweep against
691
- STATIC geometry only by default the dynamic-vs-dynamic clamp is the
692
- source of the dense-pile interference above and is only ever
693
- approximate anyway, so dropping it should make CCD purely additive
694
- (stops you at static walls/floors, never fights the dynamic stack);
695
- a proper TOI sub-solver for bullet-vs-dynamic; rotational / angular
696
- CCD; multi-collider sweep for compound bodies.
697
- - [x] **Broadphase BVH balance SAH rotation.** The dynamic AABB tree
698
- (`core/bvh2/bvh3/BVH.js`, a Box2D port) used SAH-cost insertion but a
699
- *height-only* AVL rotation (`balance_height`): height-balanced yet not
700
- SAH-balanced, so queries walked more nodes than needed. Replaced the
701
- rotation in `bubble_up_update` with `balance_rotate` the Box2D-v3 /
702
- Kensler SAH-reducing rotation (for node A with children B, C, evaluate the
703
- four child↔grandchild swaps and apply the one that most reduces the
704
- surface-area cost). Deterministic; identical pair set.
705
- - Measured (same-session A/B, heavy benches): raycast **−9%**
706
- (28.2→25.6 µs/ray), falling-tower median **−10%**, settling-grid
707
- median **−12%**, and the **990/1000-churn stress −27%**
708
- (63.95→46.68 ms mean over 10k ticks) biggest where the tree churns
709
- hardest. Determinism (8-trial bit-identical) holds.
710
- - **Insertion cost (measured):** `balance_rotate` does 4 surface-area
711
- evaluations per bubble-up level vs `balance_height`'s single height
712
- compare, so *pure bulk insertion* is **~1.4–1.5× slower** the 100k
713
- synthetic insert bench (`BVH.spec.js`, drift-controlled interleaved
714
- A/B) drops from **~37k ~25k inserts/sec** (~27→~40 µs/insert). This
715
- is the balancer's worst case (insert-only, zero queries/refits to
716
- amortise against). It does not show up end-to-end: static trees are
717
- built once then queried forever, dynamic bodies insert once then
718
- refit/query every frame, and even the 990/1000-swap stress test the
719
- maximal insert-churn workload is net **−27%**. Accepted.
720
- - **Tradeoff (documented):** the contact solver's Gauss-Seidel order
721
- follows broadphase traversal order (see `generate_pairs`), so the
722
- different tree shape shifts convergence on near-aligned stacks — the
723
- synthetic 128-cube wall now sleeps at ~10 s (was ~6.9 s). It still
724
- settles, doesn't creep / topple (all bug-guard assertions hold); only
725
- the sleep *time* moved (that test's budget was bumped 9→11 s with a
726
- note). Random-shape scenes (falling tower) were faster *and* settled
727
- fine.
728
- - **Follow-up:** decouple the solve order from tree shape sort the
729
- broadphase pair list by `(idA, idB)` before narrowphase so contact
730
- order is body-id-deterministic regardless of tree shape. Then no tree
731
- change can affect convergence (and the stack settles identically under
732
- either balancer). Has a per-step sort cost + wide test re-baseline, so
733
- it's its own task. `balance_height` is retained for comparison /
734
- fallback.
735
- - [ ] **Per-island parallel solve**: today's island data layout would
736
- allow worker-based solving once `SharedArrayBuffer` is available.
737
- Out-of-scope unless / until SAB is universally usable.
738
-
739
- ### Features
740
- - [ ] **Convex collision proxies for dynamic concave bodies.** The long-term
741
- replacement for the interim per-substep concave re-detection (see
742
- Limitations) and how every major engine handles dynamic non-convex
743
- shapes: collide a *few* convex pieces, never the raw concave mesh.
744
- 1. **3D convex hull builder** (meep has only 2D hulls today
745
- `core/geom/2d/convex-hull/`). A single hull of a mesh is one
746
- collider / one broadphase leaf and covers the overwhelming majority
747
- of dynamic objects (thrown props, debris). Pairs with the existing
748
- "Convex hull shape + eigen-inertia" item below.
749
- 2. **Few-hull (V-HACD-style) approximate convex decomposition** for
750
- shapes whose concavity matters (a cup, a chair): ~8–64 fat convex
751
- hulls = 8–64 colliders, two orders of magnitude below a tet mesh.
752
- Each hull is convex stable contact feature the TGS analytic refresh
753
- is exact no per-substep re-detection, no rocking. Granularity is the
754
- whole point: collider/BVH-leaf count must stay small for an *awake*
755
- dynamic body (the volumetric tet-mesher under `core/geom/3d/tetrahedra/`
756
- is the wrong tool here thousands of pieces and belongs to a future
757
- FEM/soft-body subsystem, not rigid collision).
758
- - [ ] **Convex hull shape** with eigen-based principal-axes inertia
759
- derivation. Hooks `matrix_eigenvalues_in_place` from the existing
760
- linalg layer.
761
- - [~] **Cylinder / cone shapes.**
762
- - [x] **`CylinderShape3D`** Y-aligned solid cylinder (radius + full
763
- height, flat caps; the capsule's flat-cap sibling). Exact `support`,
764
- capped-cylinder SDF, bounds, `contains` / `nearest_point` /
765
- volume-sampling, equals/hash, `'cylinder'` JSON tag, `isCylinderShape3D`
766
- marker. Convex routes through the narrowphase **GJK + EPA** fallback
767
- (no marker dispatch needed); spec asserts overlap-detected +
768
- MTV-separates vs sphere/box. Closed-form cylinder-vs-X contact pairs
769
- are a future refinement (the curved side is the usual smooth-support
770
- EPA case same status as pre-closed-form sphere/capsule).
771
- - [ ] Closed-form cylinder contact pairs (cylinder × box / sphere / capsule
772
- / plane) for multi-point cap manifolds + stable resting.
773
- - [ ] **Cone shape** (+ closed-form / GJK fallback).
774
-
775
- ### Rendering integration
776
- - [ ] **Fixed-step → render interpolation.** Not implemented yet. Physics writes
777
- each body's pose straight into the ECS `Transform` once per fixed step
778
- (`EntityManager.fixedUpdateStepSize`); with a render rate that doesn't match
779
- the fixed rate, the rendered motion aliases (stutter / temporal aliasing,
780
- worst at low fixed rates). Designed as a cross-cutting system (render +
781
- physics-as-producer + network-as-producer), reusing the network package's
782
- agnostic interpolation primitives rather than a physics-local mechanism.
783
- Full design + phasing: **see
784
- [`INTEPOLATION_SYSTEM_PLAN.md`](./INTEPOLATION_SYSTEM_PLAN.md)**. Locked
785
- decisions: a neutral shared interpolation log/adapters (lifted out of
786
- `network/`); physics restores authoritative pose from the log at step start
787
- (no solver rewiring) and records moved bodies' snapshots at step end;
788
- blend `Transform` at `preRender`; O(moving) not O(N); rewind-safe via the
789
- tick-keyed log.
790
-
791
- ### API polish
792
- - [x] **`overlap(shape, position, rotation, output, output_offset,
793
- filter?)`** broadphase + narrowphase overlap query for kinematic
794
- / AOE / selection use cases. Body_ids written into a caller-sized
795
- Uint32Array buffer. Convex query shape only; concave candidates
796
- are routed through the per-triangle decomposition path.
797
- - [x] **`shapeCast(ray, shape, rotation, result, filter?)`** for
798
- character controllers and kinematic shape sweeps. Broadphase
799
- swept-AABB against both BVHs; per-candidate AABB-slab interval
800
- narrowing + coarse step + GJK bisection for time-of-impact. The
801
- output `result.normal` is the true contact-surface normal at the
802
- kiss point, computed by re-running GJK + EPA at `best_t` on the
803
- winning candidate (falls back to `-ray.direction` only on EPA
804
- degeneracies).
805
- - [x] **`compute_penetration(out_direction, shape_a, pos_a, rot_a,
806
- shape_b, pos_b, rot_b)`** standalone geometry primitive (no
807
- PhysicsSystem) for resolving overlap between two shapes at given
808
- poses. Returns depth + outward direction. **Hardened** to route through
809
- the shared narrowphase dispatch (`deepest_pair_penetration`): exact
810
- closed-form for sphere/box/capsule pairs (box-box via SAT), GJK+EPA for
811
- general convex, closed-form per-triangle for convex × concave; the
812
- half-space test is retained only for tunnel recovery.
813
-
814
- ### Raycast narrowphase (done)
815
-
816
- **Problem.** `raycast` (and the suspension ray inside `RaycastVehicle`) resolves
817
- only to the nearest BVH leaf's *inflated* AABB: `result.t` is the distance to
818
- that fattened box and `result.normal` is its face normal. Exact for an
819
- axis-aligned box (modulo the broadphase margin), coarse for spheres / capsules /
820
- rotated boxes / meshes / heightmaps. Refine each candidate against the true
821
- shape to return the exact surface distance + normal. `shapeCast` already does
822
- this for swept convex shapes via GJK+EPA; `raycast` should get the same
823
- treatment with cheap analytic primitives on the hot path.
824
-
825
- **Design.** Mirror `narrowphase_step`'s dispatch: closed-form ray tests for the
826
- common primitives, a generic GJK fallback for the rest. The structural change is
827
- in the BVH walk the nearest *leaf AABB* is **not** the nearest *shape hit* (a
828
- ray can clip a near fat-AABB but miss its shape while hitting a farther one), so
829
- every crossing leaf must be refined, with subtrees pruned by inflated-AABB
830
- `t_near` vs the best *refined* `t` (conservative-correct: a shape hit is always
831
- its tight AABB entry ≥ its inflated AABB entry). A leaf whose ray crosses the
832
- fat AABB but misses the true shape now contributes **no hit** — the key
833
- correctness gain.
834
-
835
- Phasing (each phase: implement spec run from `H:/git/moh` → commit):
836
-
837
- 1. [x] **Ray-primitive helpers** originally landed as `narrowphase/ray_shapes.js`,
838
- later EXTRACTED to `core/geom/3d/{sphere,box,capsule}/{sphere3,box3,capsule3}_raycast.js`
839
- (the (`t`, normal, miss = `Infinity`, first-hit-from-outside) convention is a
840
- fine general raycast contract, and a ray-vs-capsule primitive was otherwise
841
- missing engine-wide; the dispatch still shares one ray→local transform across
842
- them). Built local-frame (unit direction `t` preserved;
843
- rotate the local normal back). Triangle MT is inlined in the concave path
844
- (the existing `computeTriangleRayIntersection` writes a `SurfacePoint3` and
845
- returns no `t` unsuited to the buffer-flyweight loop). Colocated specs.
846
- 2. [x] **Ray-narrowphase dispatch** `narrowphase/refine_ray_hit.js`:
847
- `(shape, position, rotation, ox,oy,oz, dx,dy,dz, tMax, outNormal) t`.
848
- Type-marker dispatch (`isUnitSphereShape3D` / `isBoxShape3D` /
849
- `isCapsuleShape3D`) to the analytic primitives; a generic convex fallback
850
- for `TransformedShape3D` / `UnionShape3D` / other (GJK ray-cast, or reuse
851
- `shape_cast` with a zero-radius `PointShape3D`).
852
- 3. [x] **Concave path** in the dispatch: for `is_convex === false` (mesh /
853
- heightmap), enumerate the triangles overlapping the ray's swept AABB
854
- (`mesh_enumerate_triangles` / `heightmap_enumerate_triangles`), Möller–
855
- Trumbore each, take the nearest; normal from the triangle winding.
856
- 4. [x] **Rewire `queries/raycast.js`**: at each leaf, call `refine_ray_hit` on
857
- the true shape + pose instead of accepting the AABB `t_near`; track the best
858
- refined `(t, body, normal)`; keep subtree pruning on inflated-AABB `t_near`.
859
- Same signature / `PhysicsSurfacePoint` result; drop the AABB-face-normal
860
- block. Multi-collider bodies still resolve the primary collider only
861
- (inherited BVH-leaf limitation; note it).
862
- 5. [x] **Tests**: per-shape exactness (sphere / OBB / capsule / mesh /
863
- heightmap) exact `t` and true normal; the **fat-AABB-cross-but-shape-miss
864
- no hit** case (the correctness win); nearest-of-several across a near miss;
865
- `filter` and `tMax` honoured. Re-verify `RaycastVehicle` (ride height now
866
- exact tighten the test bands if they shift by the old broadphase margin).
867
- 6. [x] **Bench + docs**: a raycast micro-bench (analytic fast-path cost; confirm
868
- the fat-AABB-miss rejection doesn't regress throughput); update the "Public
869
- queries" entry, `raycast.js` header, and the `RaycastVehicle` "AABB-level"
870
- caveat once exact.
871
-
872
- Note: this sharpens `RaycastVehicle` suspension on non-box ground and every
873
- shape query; it does not change the broadphase or any API surface.
874
-
875
- ---
876
-
877
- ## Future / out-of-scope
878
-
879
- These are explicit architectural exclusions or post-v1 explorations.
880
-
881
- ### Architecture
882
- - **Cross-runtime bit-exact determinism**: a soft-float library would
883
- replace `Math.sin/cos/exp/log/pow` in the hot path. The codebase is
884
- already structured to make this a swap-in at `quat_integrate.js` and
885
- tangent-basis construction in `build_manifold.js`. Not pursued because
886
- the same-runtime determinism we have covers the common cases (single-
887
- device replay, networked lockstep where all clients run the same JS
888
- engine).
889
- - **WASM / SIMD**: the engine targets pure-JS portability. SIMD would
890
- invalidate the determinism story (V8 doesn't expose deterministic
891
- Float64x2 ops).
892
- - **Multi-threaded solver**: workers don't share memory cheaply without
893
- `SharedArrayBuffer` plus the COOP/COEP HTTP headers, which are not
894
- always available. Single-threaded is good-enough for the awake-body
895
- budget that matters.
896
- - **Packed-SoA body dynamics state DECIDED AGAINST; do not re-open.** A
897
- reviewer will note that `BodyStorage` is SoA for *identity* (entity /
898
- generation / kind / flags / awake-set) but the per-body *dynamics* state —
899
- velocity, inertia, mass, force/torque accumulators lives on the `RigidBody`
900
- **component object** (each carrying several `Vector3` = `Float64Array` + an
901
- `onChanged` Signal), in a sparse `__bodies[]` array reached by pointer-chase,
902
- not packed by slot. The same is true of `Collider` and `Joint`. This is a
903
- deliberate, settled choice, not an oversight: **meep is an ECS engine, and
904
- `RigidBody` / `Collider` / `Joint` are public-API components.** Them being
905
- first-class objects is a UX choice and uniformity with the rest of the engine
906
- it is what makes them authorable, serializable (`toJSON`/`fromJSON` + binary
907
- adapters), value-diffable (`equals`/`hash` for netcode replication), and
908
- observable (`Vector3.onChanged`), exactly like every other component. A
909
- packed-SoA body pool would buy locality on the *awake* integration sweeps at
910
- the cost of breaking that uniformity and the public component contract. The
911
- design instead leans on "mostly-sleeping" (per-body iteration is over the
912
- *awake* set only), keeps the genuinely O(contacts) inner loop in flat SoA
913
- (manifolds + solver scratch), and has the hot paths index the component
914
- vectors' `Float64Array` backing directly to skip the observer (see
915
- Determinism). This is final do not resurface it as a "fix".
916
- - **Single in-flight solve (module-scoped solver scratch).**
917
- `solver/solve_contacts.js` keeps its cross-stage state (the `g_*` counters and
918
- the `scratch_*` arrays) at module scope one copy shared by all worlds, not
919
- per `PhysicsSystem`. Deliberate: every world reuses one set of scratch, and
920
- it's safe because the engine is single-threaded and steps one `fixedUpdate` at
921
- a time. The ceiling it sets: two `PhysicsSystem` instances cannot be stepped
922
- concurrently or re-entrantly (the second clobbers the first's solver scratch).
923
- Accepted for a single-world, single-threaded engine; lifting it would need
924
- per-system scratch (or a solver-context object threaded through the stages).
925
-
926
- ### Simulation extensions
927
- - **Soft body / cloth / fluids**: the SoA layout in `BodyStorage` and the
928
- manifold cache are rigid-body shaped. A soft-body system would be a
929
- parallel subsystem, not an extension.
930
- - **Reduced-coordinate articulations** (MuJoCo / Featherstone-style):
931
- game-physics audience runs in maximal coordinates by convention. Not
932
- on the roadmap.
933
-
934
- ### Game-side
935
- - **Vehicle physics** (suspensions, drivetrains): a domain layer that
936
- sits on top of the rigid-body primitives, not in `meep/`.
937
- - **Character controllers**: same `engine/control/first-person/` is the
938
- natural home.
939
-
940
- ---
941
-
942
- ## Notable design files
943
-
944
- - Original design plan: `C:\Users\Alex\.claude\plans\let-s-plan-to-implement-transient-harp.md`
945
- - This file (state of play): `engine/physics/PLAN.md`
1
+ # Physics engine — state of play
2
+
3
+ Tracker for what's built, what's pending, and what's deferred.
4
+
5
+ ---
6
+
7
+ ## Context
8
+
9
+ Deterministic JS rigid-body physics engine for the meep ECS. Target: game
10
+ scenarios with up to millions of mostly-sleeping bodies, deterministic replays
11
+ for netcode and reproducible debugging, broad shape coverage for common game
12
+ collisions. Pure JS — no WASM, no SIMD, no worker threads.
13
+
14
+ Architectural references for design choices:
15
+ - **Jolt** — pre-allocated body pool, active-list iteration, two-tree
16
+ broadphase (static + dynamic).
17
+ - **Bullet** — `btPersistentManifold` cache layout with up to 4 points.
18
+ - **Box2D / Catto** — sequential impulse with warm-starting, Sutherland-Hodgman
19
+ face clipping for box-box.
20
+
21
+ ---
22
+
23
+ ## Done
24
+
25
+ ### Foundations
26
+ - `RigidBody`, `Collider`, `BodyKind`, `RigidBodyFlags`, `ColliderFlags`,
27
+ `SleepState`, `PhysicsEvents`.
28
+ - `BodyStorage`: SoA pool, generation-tracked stable IDs, dense awake list,
29
+ min-heap free for deterministic ID reuse.
30
+ - `PhysicsSystem`: full public API surface (gravity, force/impulse with and
31
+ without application point, torque, velocity setter, wake/sleep, contact
32
+ filter callback).
33
+ - Binary serialization adapters for `RigidBody` and `Collider` (transient
34
+ runtime state deliberately excluded).
35
+ - `PairUint32Map`: open-addressed Robin Hood + Fibonacci hash for the
36
+ pair → manifold-slot index (the one new collection added to `core/collection/`).
37
+
38
+ ### Pipeline (`PhysicsSystem.fixedUpdate`)
39
+ 1. Velocity integration (semi-implicit Euler, linear + angular, gravity,
40
+ damping, world-frame inverse-inertia for torque)
41
+ 2. Per-collider broadphase refit with fat AABB (Box2D-style velocity-padded
42
+ slack)
43
+ 3. Pair generation: per-leaf query against both BVHs (static + dynamic),
44
+ canonical `(min, max)` pairs, dedup via manifold touched flag
45
+ 4. Wake propagation for sleeping bodies in the pair list
46
+ 5. Narrowphase cross-product over collider lists
47
+ 6. Sequential-impulse solver (Catto-style, warm-start, friction, Baumgarte)
48
+ 7. Position integration (linear + quaternion)
49
+ 8. Sleep test (per-body velocity² below threshold for ≥ 0.5 s)
50
+ 9. Manifold diff → `ContactBegin` / `Stay` / `End` event dispatch
51
+ 10. `manifolds.advance_frame()` — roll touched bits, evict grace-expired slots
52
+
53
+ ### Shape coverage
54
+ | Pair | Path | Manifold |
55
+ |---|---|---|
56
+ | sphere-sphere | closed-form | 1 point |
57
+ | sphere-box | closed-form (handles centre-inside-box) | 1 point |
58
+ | capsule-sphere | point-on-segment closed-form | 1 point |
59
+ | capsule-capsule | segment-segment closest pair | 1 point |
60
+ | capsule-box | iterative segment-vs-OBB (primary) + cap-centre sphere-vs-OBB at each endpoint | up to 3 |
61
+ | box-box face-face | SAT + Sutherland-Hodgman clipping | up to 4 |
62
+ | box-box edge-edge | SAT + segment-segment closest-pair | 1 point |
63
+ | sphere / box / capsule × concave (heightmap, mesh) | closed-form `*_triangle_contact` per triangle via decomposition dispatcher | up to a few points per triangle (deepest wins) |
64
+ | other convex × concave | per-triangle GJK + EPA via decomposition dispatcher | 1 point per triangle |
65
+ | anything else | GJK + EPA, MPR fallback on EPA non-convergence | 1 point |
66
+
67
+ ### Non-convex shapes
68
+ - **`is_convex` flag** on `AbstractShape3D.prototype` (default `true`).
69
+ Overridden to `false` on `HeightMapShape3D`, `MeshShape3D`, `UnionShape3D`.
70
+ `TransformedShape3D` inherits via getter that reads the wrapped subject.
71
+ - **`HeightMapShape3D`** — orientation-vector + `Sampler2D`-backed terrain
72
+ shape. Heights sampled via `sampleChannelCatmullRomUV` (matching the
73
+ terrain system's geometry construction). Compute_bounding_box,
74
+ contains_point, signed_distance, nearest_point_on_surface all
75
+ implemented; `support` throws (non-convex by construction).
76
+ - **`Triangle3D`** — buffer-flyweight convex shape. `bind(buffer, offset)`
77
+ repoints at 9 consecutive floats in an external Float64Array. Zero
78
+ allocation per emission; used by the decomposition path.
79
+ - **Triangle decomposition machinery** under
80
+ `engine/physics/narrowphase/decomposition/`:
81
+ - `TRIANGLE_FLOAT_STRIDE = 10` per triangle (`vA.xyz`, `vB.xyz`,
82
+ `vC.xyz`, `feature_id`).
83
+ - `heightmap_enumerate_triangles(out, offset, shape, ...aabb)` —
84
+ Arvo-projects the convex's AABB into heightmap-local, intersects
85
+ with the footprint to derive a cell range, emits 2 triangles per
86
+ cell with stable feature_ids.
87
+ - `mesh_enumerate_triangles(out, offset, shape, ...aabb)` — linear
88
+ O(N) scan over `MeshShape3D.indices` with tight per-triangle AABB
89
+ filtering. feature_id = triangle index.
90
+ - `aabb3_transform_oriented_inverse(out, world_aabb, pos, rot)` (now in `core/geom/3d/aabb/`) — 8-corner
91
+ projection of a world AABB into a body's local frame.
92
+ - `decompose_to_triangles(...)` — dispatcher switching on shape
93
+ type marker.
94
+ - **Narrowphase concave dispatch** in `narrowphase_step.js`: detects
95
+ `is_convex === false`, computes convex's world AABB, projects to
96
+ concave's local frame, decomposes, per-triangle GJK + EPA with
97
+ one-sided face-normal rejection and contact-normal dedup. Concave-vs-
98
+ concave dynamic pairs are explicitly refused.
99
+
100
+ ### Solver
101
+ - Sequential impulse with warm-starting (10 velocity iterations by default).
102
+ - Coulomb friction with disk-clamped tangent impulses.
103
+ - Baumgarte position correction folded into the velocity solve.
104
+ - Full angular Jacobian (`I_w⁻¹ = R · diag · R^T`) and angular impulse
105
+ application.
106
+ - Public force/impulse-at-point API (`applyForceAt`, `applyImpulseAt`,
107
+ `applyTorque`).
108
+
109
+ ### Sleep + events
110
+ - Per-island **atomic sleep**: an island sleeps when `max(|v|² + |ω|²)`
111
+ across all members stays below the threshold long enough; the whole
112
+ island sleeps in the same frame. Replaces the per-body chatter on
113
+ weakly-connected piles.
114
+ - **Atomic wake**: members of a sleeping island are threaded into a
115
+ circular doubly-linked list (`sleep_group_next` / `sleep_group_prev`);
116
+ waking any one member walks the chain and wakes the rest in the same
117
+ call. A 100-block stack hit at the base wakes top-down in one frame
118
+ rather than over 100 frames of broadphase propagation.
119
+ - `DisableSleep` on any island member exempts the whole island.
120
+ - ContactBegin / Stay / End buffer + dispatch through the per-entity
121
+ `dataset.sendEvent(entity, PhysicsEvents.ContactBegin, ...)` channel — the
122
+ sole contact-event path, delivered to each entity of the pair when a
123
+ dataset is attached.
124
+
125
+ ### Islands
126
+ - **Union-find** with path halving + union by min-index over the awake-body
127
+ + touched-contact graph (`core/collection/union-find/union_find.js`).
128
+ - **`IslandBuilder`** produces deterministic CSR-style output: bodies and
129
+ manifold slots grouped by island, sorted ascending within and across
130
+ islands. Static / kinematic bodies are constraint anchors only — they
131
+ don't merge islands, so disjoint piles on the same floor are separate
132
+ islands.
133
+ - **Islands feed the sleep test + grouping, not a per-island solver loop.**
134
+ The TGS contact solver flattens every island's contacts into one
135
+ Gauss-Seidel sweep (`solver/solve_contacts.js`) — islands share no bodies,
136
+ so a single flat sweep is identical to per-island sweeps. The partition is
137
+ still rebuilt every step and consumed by the atomic-island sleep test and the
138
+ joint/contact island grouping; it is also the natural unit for a future
139
+ worker-based parallel solve (see Performance / Scale). (Earlier revisions ran
140
+ the solver per island; the TGS rewrite flattened it — same result, simpler
141
+ loop.)
142
+
143
+ ### Compound bodies
144
+ - A body has 0..N attached colliders. Each collider has its own world
145
+ transform and its own BVH leaf.
146
+ - Same-entity colliders, child-entity colliders (via `ParentEntity`), or
147
+ hybrids all supported.
148
+ - `ColliderObserverSystem` auto-attaches colliders via the dataset when
149
+ paired with `PhysicsSystem` in an EntityManager.
150
+ - Narrowphase runs the cross-product over both bodies' collider lists per
151
+ body-pair, accumulates candidates, reduces to ≤4 contacts by
152
+ depth + spread.
153
+
154
+ ### Public queries
155
+ - `raycast(origin, dir, max_dist, filter?)` — nearest hit across both trees,
156
+ **refined to the true shape surface** (narrowphase). `result.t` /
157
+ `result.normal` are exact for sphere / box / capsule / mesh / heightmap
158
+ colliders (per-leaf analytic ray tests + triangle Möller–Trumbore for
159
+ concave); composite convex shapes fall back to the broadphase AABB hit. A ray
160
+ crossing a fat leaf AABB but missing the true shape is correctly a miss.
161
+ - `shapeCast(ray, shape, rotation, result, filter?)` — broadphase swept
162
+ AABB against both BVHs; per-candidate AABB-slab interval narrowing,
163
+ coarse step over the narrowed window, GJK bisection to time-of-impact.
164
+ Output normal is the true contact-surface normal at the kiss point,
165
+ recovered by re-running GJK + EPA at `best_t` on the winning candidate.
166
+ Falls back to `-ray.direction` only on EPA degeneracies (NaN / zero
167
+ depth). Tests cover axis-aligned, off-axis, and oblique cube-vs-cube;
168
+ sphere-vs-smooth-shape near-tangent has documented angular tolerance
169
+ bands inherited from EPA on smooth supports.
170
+ - `overlap(shape, position, rotation, output, output_offset, filter?)`
171
+ — broadphase + per-candidate GJK overlap detection. Writes body_ids
172
+ into a caller-sized buffer; returns count. Convex query shapes only
173
+ (concave throws). Concave candidates routed through the per-triangle
174
+ decomposition path. Designed for speculative kinematic queries on
175
+ kinematic bodies (character controllers, AOE selection).
176
+
177
+ ### Standalone narrowphase utilities
178
+ - `deepest_pair_penetration(out_normal, shapeA, posA, rotA, shapeB, posB,
179
+ rotB)` (exported from `narrowphase_step.js`) — runs the **same**
180
+ `dispatch_pair` the contact solver consumes for one posed shape pair and
181
+ returns the DEEPEST contact's depth + world normal (B → A). The single
182
+ source of truth for "minimum-translation between two posed shapes", reused by
183
+ `compute_penetration` (and available to any other query).
184
+ - `compute_penetration(out_direction, shape_a, pos_a, rot_a, shape_b,
185
+ pos_b, rot_b)` — non-system geometry primitive: positive penetration
186
+ depth + outward direction (B → A convention) on overlap, 0 otherwise.
187
+ **Hardened** — delegates to `deepest_pair_penetration`, so it is correct
188
+ (not "correct sometimes") for every shape pair the engine can build:
189
+ - sphere / box / capsule pairs → exact closed-form (box-box via SAT, so a
190
+ small body resting on a large floor reports the few-cm near-face overlap,
191
+ NOT the metres-deep "exit through the far side" that MPR's centroid-seeded
192
+ portal used to return);
193
+ - general convex pairs → GJK + EPA (exact for polytopes; curved shapes never
194
+ reach it — they have closed forms);
195
+ - convex × concave → triangle decomposition + the closed-form per-triangle
196
+ solvers, bounded to each triangle's true 2-D extent (the old closed-mesh
197
+ side-face over-report is gone).
198
+ The previous per-triangle half-space test is retained ONLY as a recovery
199
+ fallback for the one case the one-sided closed forms can't resolve: a convex
200
+ shape that has fully tunnelled to the *inner* side of a concave surface (a
201
+ depenetration query must still push it back out — exact for heightmap terrain,
202
+ a valid outward push for closed meshes). Concave × concave throws (M×N
203
+ triangle pairs out of scope). The spec asserts an "applying out_direction ×
204
+ depth separates the shapes" invariant across every convex+convex pair type and
205
+ convex+concave, plus exact per-type depths and the small-box-on-huge-floor
206
+ regression (3 m → 0.05 m).
207
+
208
+ ### Determinism — the reconstruction contract (H-series, landed)
209
+ Engine outcomes are a pure function of **body components (keyed by entity
210
+ id) + the exportable solver-cache blob** never of allocation history
211
+ (body slots, manifold slots, joint ids, awake-list order, BVH shape,
212
+ broadphase pad history). A world rebuilt from a snapshot — onto a fresh
213
+ engine, or by remove-all/re-add on a live one continues **bit-identically**
214
+ to the engine that kept running. Verified by `determinism.spec.js`
215
+ (T1 lockstep repeatability; T2 reconstruction equivalence incl. generation
216
+ churn and pad-history wake timing).
217
+
218
+ - Entity-canonical pair A/B roles assigned in the broadphase
219
+ (`generate_pairs`) — roles feed witness sides, normal orientation and the
220
+ tangent basis, so they must derive from the cross-engine identity.
221
+ - Outcome-coupled iteration orders are entity-keyed: island contacts
222
+ (IslandBuilder), joints (`__joints_sorted`), contact events
223
+ (`ContactEventBuffer.sort_canonical` + dispatch normal mirror), CCD pass.
224
+ - `sleepState` + `sleep_timer` are persistent body state (adapter v1 +
225
+ 0→1 upgrader); `link()` honours them, so restored sleepers stay asleep.
226
+ - Stage-0 wake reads persistent manifolds (`prev_touched`), never the
227
+ transient pair list; the precautionary pre-contact wake is an
228
+ edge-triggered swept-tight-AABB proximity predicate (`FLAG_PROX`),
229
+ a pure function of body state.
230
+ - `persistence/solver_caches.js`: entity-keyed export/import of manifolds
231
+ (warm-start impulses + lifecycle bits), joint `dofImpulse`, sleep-group
232
+ chains. Identical worlds serialize to identical bytes.
233
+ - Foundations that predate the H-series: min-heap free lists for
234
+ deterministic slot reuse, no `Math.random` in the step, direct
235
+ typed-array writes on hot paths (Transform writes still go through
236
+ `set()` — external systems subscribe).
237
+ - Same-runtime bit-exact; cross-runtime is a known future seam (see
238
+ Backlog Reconstruction & determinism).
239
+
240
+ ### Migration
241
+ - `Motion` / `MotionSystem` / `MotionSerializationAdapter` relocated from
242
+ the meep core (`engine/ecs/`) to the game-domain layer
243
+ (`mir-engine/model/game/ecs/`). meep no longer ships the legacy shim.
244
+
245
+ ### Alternative narrowphase: MPR
246
+ - `core/geom/3d/gjk/mpr.js` — Minkowski Portal Refinement (XenoCollide,
247
+ Snethen GDC 2009). Single-pass overlap test + MTV computation,
248
+ output convention matches EPA so it's drop-in compatible at any
249
+ narrowphase call site. Tends to converge in 5–15 iterations on
250
+ smooth shapes where EPA stalls (the polytope-on-curved-surface
251
+ failure mode the torus-knot reproducer exercised). **Wired as the EPA
252
+ non-convergence fallback** in `narrowphase_step` at both the body-level
253
+ and per-triangle GJK+EPA paths: when EPA returns a non-positive / non-finite
254
+ depth, MPR is tried before giving up. `shape_cast` and `compute_penetration`
255
+ use it for the same reason.
256
+
257
+ ### Bonus utilities
258
+ - `core/geom/3d/line/line3_closest_points_segment_segment.js` generally
259
+ useful 3D segment-segment closest-pair via Ericson §5.1.9.
260
+ - `core/collection/PairUint32Map.js` non-allocating
261
+ `Map<(u32, u32) u32>` with Robin Hood + Fibonacci hash.
262
+
263
+ ---
264
+
265
+ ## Limitations / Known caveats
266
+
267
+ - **Multi-collider material precision** *resolved for contact materials.* The
268
+ narrowphase now combines the specific source-collider pair's friction /
269
+ restitution per contact and stores them in the manifold (CONTACT_STRIDE
270
+ offsets 14/15); the solver reads them per contact, so mixed-material compound
271
+ bodies are accurate (regression test: an asymmetric-friction body yaws when
272
+ shoved). Still primary-collider only: the contact-filter callback's
273
+ `colliderA/B` arguments and the body-level sensor / concave-dispatch flags
274
+ a smaller follow-up.
275
+ - **EPA on smooth shapes**: degenerates (no flat face to converge on).
276
+ Mitigated by closed-form paths for sphere/cube/capsule pairs and by the
277
+ **MPR fallback** on EPA non-convergence; exotic convex shapes vs spheres can
278
+ still occasionally fail if both EPA and MPR degenerate.
279
+ - **EPA on `Triangle3D`** *resolved.* The concave dispatch now uses the
280
+ closed-form `sphere_triangle_contact` / `box_triangle_contact` /
281
+ `capsule_triangle_contact` solvers (P1.1a–c) instead of per-triangle GJK+EPA
282
+ for those primitives, so a sphere/box/capsule on a heightmap or mesh decelerates
283
+ and settles correctly; the `narrowphase_concave.spec.js` "drop and settle"
284
+ cases and the mesh torus-knot settle test are **un-skipped**. Per-triangle
285
+ GJK+EPA remains only as the fallback for *other* convex shapes vs triangles.
286
+ (`compute_penetration` now routes through that same dispatch via
287
+ `deepest_pair_penetration` see *Standalone narrowphase utilities* instead
288
+ of its old half-space pre-test; the half-space test survives only as a
289
+ tunnel-recovery fallback.)
290
+ - **Box-box edge-edge contact**: a single point at the true closest-pair of the
291
+ two edges (P3.2), not the old body-centre midpoint. This is geometrically
292
+ correct — and an empirical SAT-source sweep confirms the edge-cross branch
293
+ *only* fires for **transverse** edge crossings (inter-edge angle 83-90°),
294
+ where two skew lines meet at a unique point. Near-parallel edge contacts
295
+ cannot reach this branch (a near-parallel `edgeA × edgeB` never wins the SAT
296
+ minimum)they resolve through the multi-point face-clipping path. So the
297
+ once-planned "multi-point edge contact for near-parallel edges" refinement is
298
+ **moot**; see the resolved Stability backlog entry.
299
+ - **CCD floor only**: speculative margin via the fattened AABB prevents
300
+ most tunnelling. No per-body swept shape-cast for very fast objects.
301
+ - **Cross-runtime determinism is not guaranteed**: `Math.sin/cos/exp/log`
302
+ are ULP-correct but not bit-exact across V8 / SpiderMonkey / JSC.
303
+ - **Dynamic concave bodies under TGS** *resolved by per-substep re-detection
304
+ (below); kept here for the rationale.* The substep loop normally re-derives
305
+ contact geometry analytically from the per-triangle contact feature (witness
306
+ anchors + normal) captured once by narrowphase and held fixed for the whole
307
+ outer step. For a convex body the contact feature is stable under the small
308
+ per-step motion, so this is exact; for a *dynamic concave mesh body* (e.g. a
309
+ torus knot rocking on its own lobes) the supporting triangle itself changes
310
+ as the body rocks, so freezing the feature would pump a little energy in and
311
+ the body would rock / slowly sink instead of settling. Note this is NOT a
312
+ contact-precision issue
313
+ the knot already uses the exact closed-form box-triangle solver (P1.1b);
314
+ the problem is purely that TGS freezes *which* feature is in contact across
315
+ substeps. The common concave case a convex dynamic body on static concave
316
+ terrain is unaffected (the convex side's feature is stable), and that is
317
+ the only concave case the engine targets.
318
+
319
+ **Interim fix (implemented): per-substep concave re-detection.** For
320
+ contact pairs involving a concave body, the substep loop re-runs the
321
+ concave narrowphase geometry at the current substep pose (instead of the
322
+ analytic refresh that freezes the feature) and re-prepares those contacts
323
+ from the fresh witness/normal/depth — so the contact normal tracks the
324
+ rocking body and no energy is pumped in. Convex pairs keep the cheap
325
+ analytic refresh. This is ~Nx narrowphase cost on concave-involved pairs
326
+ (acceptable — they're rare), gated by collider convexity. Un-skips the
327
+ torus-knot dynamic-settle test.
328
+
329
+ **Better long-term fix: convex collision proxies (not raw concave).** Every
330
+ major engine (Box2D, Jolt, PhysX, Rapier) requires dynamic bodies to be
331
+ convex or convex-decomposed; raw concave meshes are static-only. The right
332
+ granularity is a *few* convex pieces NOT the thousands of tets a
333
+ volumetric mesher produces (tet count collider/BVH-leaf count, which
334
+ explodes the broadphase for an awake body; tet meshing is for a future
335
+ FEM/soft-body subsystem, not rigid collision). See the "Convex collision
336
+ proxies for dynamic concave bodies" backlog item — a 3D convex hull builder
337
+ (single-hull proxy covers most dynamic objects) plus an optional
338
+ few-hull (V-HACD-style) decomposition. Those supersede the interim
339
+ per-substep re-detection once built.
340
+
341
+ ---
342
+
343
+ ## Backlog (planned, in scope)
344
+
345
+ ### Reconstruction & determinism (engine side done; consumers pending)
346
+
347
+ The engine-side determinism contract is landed (see Done → Determinism).
348
+ These are the follow-ups that build on it:
349
+
350
+ - [ ] **Network late-join wiring (end-to-end).** The engine API exists
351
+ (`write_solver_caches` / `read_solver_caches`, sleep-persistent
352
+ components, the entity-id contract) but nothing consumes it yet.
353
+ Build an end-to-end test through the network package's adapters:
354
+ serialize a live world on the "server", reconstruct on a "client"
355
+ (same entity ids, same link order), verify bit-identical continuation
356
+ over N ticks. This validates the entity-replay assumptions
357
+ (replicated entity ids, joint link order, system config transfer)
358
+ before real netcode depends on them, and decides where the blob rides
359
+ (snapshot message vs. component stream). System config (gravity,
360
+ thresholds, iteration counts, `ccdEnabled`) is part of the snapshot
361
+ contract see `copy_system_config` in `determinism.spec.js` for the
362
+ field list.
363
+ - [ ] **Position correction under stacked load.** Settled penetration is
364
+ pose-chaotic with a heavy tail reaching the limb radius (~0.3 m for
365
+ the ragdoll's capsules) when a body settles wedged under the
366
+ assembly's weight measured across seeds and under either contact-
367
+ role assignment (see the 4-seed table in
368
+ `PhysicsSystem.ragdoll.spec.js`). Pre-existing, not a regression.
369
+ Investigation levers: position iterations (currently 1/substep),
370
+ `MAX_POSITION_BIAS` clamp, depth-proportional stiffening for deep
371
+ static contacts. Success metric: the cross-seed tail of
372
+ `lastSecondMaxPenStatic`, not any single golden seed.
373
+ - [ ] **Sleep groups derived from manifolds (redesign).** Wake-the-island
374
+ currently rides on `sleep_group_next/prev` circular chains threaded at
375
+ atomic-sleep time world-instance body indices that need their own
376
+ section in the solver-cache blob. Deriving the wake set at wake time
377
+ (flood over dormant contacting manifolds + joints among sleepers)
378
+ would delete the fields, the blob section, and the group-restore step
379
+ outright. Needs a per-body manifold adjacency (or an accepted
380
+ O(live-slots) scan per wake call) and a perf check on wake-heavy
381
+ frames. Behavioural delta to design for: force-slept touching bodies
382
+ currently wake independently (separate singleton groups); a
383
+ manifold-derived flood would wake them together.
384
+ - [x] **KILLED — pose-keyed narrowphase memo (measured 2026-06-11).** The
385
+ idea: skip a pair's narrowphase when both collider poses are bit-equal
386
+ to its last run (a pure cache; outcome-neutral by construction, proven
387
+ with a memo-on/off lockstep test). Implemented per-ManifoldStore (a
388
+ process-global cache is unsound — two engines hosting the same pair
389
+ ids at equal poses false-hit each other's slot content), then measured:
390
+ **0.0% hit rate** in every phase of a settling column, including the
391
+ final pre-sleep second. The premise is empirically false: warm-start
392
+ cancellation holds *velocity* near zero, never exactly zero, so awake
393
+ poses drift sub-nanometre every tick and never bit-freeze; sleeping
394
+ pairs never reach narrowphase at all. Reverted as pure overhead.
395
+ Dependent idea for the soft-solver work: a deterministic
396
+ micro-velocity snap-to-zero at the end of the solve would both freeze
397
+ resting poses bit-exact (making this memo viable) AND push
398
+ forever-jiggling islands (deep-column N=20, KEVA) below the sleep
399
+ threshold likely the cheaper end of the same win.
400
+ - [x] **KILLED — solver hot/cold row split (ceiling-measured 2026-06-11).**
401
+ The idea: split the 23-float prepared-contact records by the velocity
402
+ iteration's access pattern (15 hot lanes) for cache density. Measured
403
+ the ceiling first instead of implementing: PADDING the stride 23→31
404
+ (+35% row traffic) moved KEVA-mini by only ~2% — so packing −35% can
405
+ gain at most the same ~2%, far under the ≥10% gate. The velocity
406
+ solve at this scale is dominated by the slot-scattered manifold reads
407
+ (normal + impulses), the body-span gather/scatter and raw FLOPs, not
408
+ by prepared-row density. Not implemented.
409
+ - [x] **KILLED 4×4 manifold block solve (probe-measured 2026-06-11).**
410
+ Pre-integration probe on the deep columns, sweeping iteration budgets:
411
+ depth stability IS iteration-starved (N=30 explodes at velIters 4,
412
+ holds intact at 8 the divergence is convergence failure), but the
413
+ never-sleeping residual is NOT at velIters 16 the N=20 column idles
414
+ at residual 0.83, closer to rest than any other config, and still
415
+ never crosses the sleep threshold; sleep behaviour is non-monotonic
416
+ across budgets. That residual is a hard-constraint limit cycle
417
+ hovering at the threshold a scheme property no amount of
418
+ Gauss-Seidel (sequential or block) removes. A block solve would only
419
+ buy the depth-stability half, which the soft-step scheme change
420
+ covers anyway (Box2D v3 dropped block solving when it adopted soft
421
+ step). Revisit only if post-soft-step iteration budgets remain
422
+ depth-limited.
423
+ - [x] **LANDED Box2D-v3 soft contact step (2026-06-11).** Contact normal
424
+ rows are soft constraints: `b2MakeSoft(hertz, ζ, h)` scales (mass scale
425
+ damps the velocity gain, the impulse-decay term bleeds the accumulator
426
+ the critically-over-damped spring that killed the hard scheme's
427
+ resting limit cycle), a penetration-bias push for penetrating contacts
428
+ (clamped like the old position bias), and a per-substep RELAX pass
429
+ after position integration that strips bias-injected momentum. The
430
+ split-impulse position pass is skipped for contacts when soft; knobs:
431
+ `contactHertz = 30` (0 = bit-exact legacy hard rows), = 10`,
432
+ non-dynamic pairs at hertz, hertz clamped to an eighth of the
433
+ substep rate all pinned from Box2D v3 source.
434
+ A bias-free hybrid (decay without the bias push) was measured FIRST
435
+ and is UNSOUND: the decay bleeds the load-carrying impulse with no
436
+ restoring force, columns sank 3 m. Full v3 it is.
437
+ Measured: deep columns 15/20/30 all sleep (55/57/85 ticks; 20 never
438
+ slept and 30 DIVERGED under hard); KEVA-mini all-ticks median
439
+ 90.8 14.8 ms (sleep arrives much sooner; awake ticks +23% from the
440
+ relax sweep); 24-seed ragdoll sweep: settle-accel medians ~halved,
441
+ impacts unchanged, settled-pen median 0.049 vs ~0.058 hard.
442
+ Velocity-iteration cut REJECTED by measurement: KEVA-mini's
443
+ convergence cliff sits between velIters 3 and 4 (2 never sleeps,
444
+ 3 sleeps far later); 4×4 stays.
445
+ Known trades (re-pinned goldens, all documented in-test): settled
446
+ penetration under load is the soft equilibrium droop (~0.8 mm per
447
+ carried cube-weight); aligned-stack lateral creep grew ~5× (softer
448
+ settle-phase normal impulses lower the friction caps tuning
449
+ candidate: stiffer staticSoftness or friction in the relax pass);
450
+ ragdoll fields idle ~2× livelier (0.74 1.66 residual /704 bodies —
451
+ tuning candidate: align joint hertz/ζ policy with contacts). The
452
+ ragdoll canonical seed moved to 0xBEEF42 (0xDEADB0D's drape pose
453
+ under soft ends in an accelerating dome roll — a growing-tail
454
+ outlier; the sweep keeps covering it).
455
+ - [ ] **Cross-process repeatability of symmetry-degenerate scenes.** The
456
+ perfectly-aligned 10-cube tower's resting drift came out 42/57/73 mm
457
+ across equivalent builds during the soft-step work — each value
458
+ process-stable and ×3 reproducible, shifting across rebuilds whose
459
+ source diffs were assertion-text only. In-process determinism is
460
+ green (T1 lockstep, 8-trial reproducibility bench), so the seam is
461
+ environmental (suspect: jest transform/module environment shaping
462
+ sub-ulp float paths in symmetry-degenerate tie-breaks). Investigate
463
+ whether genuinely identical code can produce different cross-process
464
+ results (would matter for lockstep across restarts) or whether the
465
+ rebuild artefacts differed; degenerate-scene goldens use CLASS bounds
466
+ in the meantime.
467
+ - [ ] **Cross-runtime float determinism audit.** Same-runtime bit-exactness
468
+ is done; running lockstep across *different* JS engines (or versions)
469
+ additionally requires auditing transcendentals — `Math.sin/cos/exp/
470
+ pow` are not spec-pinned (sqrt and arithmetic are IEEE-exact). Only
471
+ worth doing if cross-engine lockstep becomes a real deployment target;
472
+ same-engine replication does not need it.
473
+
474
+ ### Solver quality (next major work)
475
+
476
+ These items move the engine from "competent" to "great". TGS is the next
477
+ significant solver-architecture change; joints come after, once the TGS
478
+ scaffolding is in place.
479
+
480
+ - **TGS (Temporal Gauss-Seidel) substepping with split-impulse** Phases
481
+ 1–3 **LANDED**. The solver is now a staged TGS pipeline
482
+ (`solver/solve_contacts.js`: `prepare_contacts` per substep
483
+ [`refresh_contacts` `warm_start_contacts` `solve_velocity`
484
+ `solve_position`] `apply_restitution`), driven by the substep loop in
485
+ `PhysicsSystem.fixedUpdate`. Defaults: `substeps = 4`,
486
+ `velocityIterations = 4`, `positionIterations = 1` (all fields on
487
+ `PhysicsSystem`).
488
+ - **Phase 1 — split impulse.** Position correction runs on a per-body
489
+ pseudo-velocity (`__pseudo_velocity`) folded into the pose by
490
+ `integrate_position` and discarded; depth correction never
491
+ contaminates persistent velocity.
492
+ - **Phase 2 one-shot restitution.** Velocity pass is pure
493
+ non-penetration; restitution is a single post-loop pass driving
494
+ `vn → -e·vn_approach`, gated on a running max normal impulse
495
+ (`maxNormalImpulse`) so transient collisions still bounce under
496
+ per-substep warm-start.
497
+ - **Phase 3 substep loop.** `substeps` sub-iterations at `h = dt/N`.
498
+ Forces consumed once at full `dt` before the loop; gravity applied
499
+ per substep; **warm-start replayed per substep** (the crux a
500
+ per-substep impulse balances one substep of gravity, so resting
501
+ stacks hold at zero velocity). Contact geometry is re-derived
502
+ **analytically** each substep from frozen local witness anchors +
503
+ the trusted prepare-time depth (a sign-robust delta), so narrowphase
504
+ runs **once** per outer step cheaper than the originally-planned
505
+ per-substep match-and-merge refresh, and exact for convex
506
+ primitives whose contact feature is stable under small motion.
507
+
508
+ Results vs the single-step solver: a 100:1 mass ratio now stacks
509
+ instead of crushing through (regression test added); 8-cube stacks
510
+ settle to zero velocity and sleep (were impossible long-term under SI);
511
+ falling-tower bench cost unchanged (~48 ms/1000 active bodies);
512
+ `substeps = 1` reproduces the single-step result bit-for-bit-ish
513
+ (one-frame restitution delay aside).
514
+
515
+ **Hard-won lessons (for REVIEW_002):**
516
+ - Warm-start MUST be per-substep, not once. Replaying a full-frame
517
+ impulse once while gravity arrives per substep over-pushes resting
518
+ contacts and *explodes* deep stacks. Per-substep warm-start +
519
+ per-substep gravity cancel exactly at rest.
520
+ - Restitution must gate on the *running max* normal impulse, not the
521
+ end-of-loop value per-substep warm-start relaxes a transient
522
+ contact's `j_n` back to ~0 by the end, which would suppress the
523
+ bounce.
524
+ - Analytic separation re-derivation beats per-substep narrowphase
525
+ for convex shapes (cheaper, no manifold-lifecycle churn) but is
526
+ only as good as the frozen normal see the concave caveat below.
527
+
528
+ Follow-ups since the core landed:
529
+ - [x] **Box-box SAT reference tie-break deadband** aligned cube
530
+ stacks (4–10 high) now settle to zero velocity and sleep; the
531
+ reference-face flip-flop that creeped/toppled them is gone.
532
+ - [x] **Per-substep contact re-detection for concave pairs** lifts
533
+ the dynamic-concave-body limitation; the torus-knot dynamic-settle
534
+ test is un-skipped. Concave pairs re-run narrowphase geometry each
535
+ substep (`redetect_concave_contacts`); convex pairs keep the cheap
536
+ analytic refresh.
537
+
538
+ Remaining (Phases 4–6) — now complete:
539
+ - [x] Regression coverage: heavy-on-light pyramid (10× capstone on two
540
+ light cubes settles + sleeps) and a ragdoll-stub (shoulder
541
+ ball-socket + elbow hinge arm hangs, stays articulated, settles).
542
+ - [x] REVIEW_002 retrospective `engine/physics/REVIEW_002.md`.
543
+
544
+ References: Catto 2018 ("Soft Constraints" GDC talk + the TGS
545
+ follow-up); Box2D v3 source (`b2ApplyRestitution`, the substep solver
546
+ stages); Rapier as the closest architectural sibling.
547
+
548
+ - [x] **Constraints / joints DONE (phases 1–7 below).** One configurable
549
+ 6-DOF joint (lock/free/limit/motor/spring + swing-twist cone-twist) plus
550
+ the raycast vehicle. Covers chains/ropes, ragdolls, vehicles (incl.
551
+ suspension), and the mechanical set (doors, pistons, welds, sliders,
552
+ powered hinges/wheels). The design rationale below is kept as history; the
553
+ phasing checklist records what landed. Solver/joint retrospective in
554
+ `REVIEW_003.md`.
555
+
556
+ Original framing (now satisfied): TGS unblocked it (joint-chain
557
+ convergence is a TGS sweet spot), warm-start + per-substep + island
558
+ machinery was reusable, and the SPOOK compliance dial gave spring
559
+ constraints essentially for free.
560
+
561
+ **Foundational work (do first): generalise the solver to constraint
562
+ rows.** Today `solver/solve_contacts.js` is hard-coded to the
563
+ contact-shape constraint (normal + 2 friction tangents, ≥0 clamp,
564
+ restitution, penetration bias). Joints are equality / inequality
565
+ constraints on relative velocity at anchors, generally bilateral
566
+ (impulse may be ±) with optional limits and motors. The clean shape —
567
+ and what Jolt / Box2D-v3 do is a **generic constraint row**: a
568
+ Jacobian (linear + angular parts per body), an effective mass, a bias
569
+ (position error × SPOOK gain, or motor target), and impulse bounds
570
+ `[lo, hi]` (`[0,∞)` for a contact/limit, `(−∞,∞)` for an equality,
571
+ `[−maxForce·h, +maxForce·h]` for a motor). Each joint type just fills
572
+ in its rows; the existing per-body impulse-apply primitive
573
+ (`apply_impulse_to_body` + `world_inverse_inertia_apply`), the
574
+ per-substep warm-start, the islands, and the split-impulse / SPOOK
575
+ position handling are all reused. Contacts become *one* constraint
576
+ type among several rather than the hard-coded path.
577
+
578
+ The specific constraint set, its use-case mapping, and per-type
579
+ architecture-fit assessment are under review (see the constraints
580
+ sketch). High level: ball-socket / distance / spring / weld and the
581
+ grab constraint are near drop-ins on the row machinery; hinge /
582
+ prismatic / cone-twist / motors / limits add angular-row + bounded-row
583
+ mechanics (still within the impulse framework); raycast vehicles,
584
+ conveyor surface-velocity, and gear/pulley coupling are higher-level
585
+ systems or contact modifiers that sit *on top of* the primitives
586
+ rather than being generic rows.
587
+
588
+ **Decision: build ONE configurable 6-DOF constraint** (PhysX D6 / Jolt
589
+ SixDOF), implemented mode-by-mode. The `Joint` ECS component carries
590
+ `dofMode[6]` (3 linear, 3 angular) each `{locked|free|limited|spring|
591
+ motor}` + per-DOF limit/spring/motor config + warm-start accumulators.
592
+ Concrete joints are configs, not new code (ball-socket = lock 3 linear;
593
+ hinge = lock 3 linear + 2 angular; weld = lock 6; cone-twist = lock 3
594
+ linear + limit 3 angular; suspension = spring 1 linear + lock rest).
595
+
596
+ Phasing:
597
+ 1. [x] Constraint-row solver as a **parallel row set** in the TGS
598
+ substep loop (contacts left untouched, not ported lower risk).
599
+ `constraint/solve_constraints.js` reuses `world_inverse_inertia`,
600
+ per-substep warm-start, and the SPOOK position bias; `Joint`
601
+ component + `link_joint`/`unlink_joint` in PhysicsSystem;
602
+ `jointIterations` knob. Bodies need no collider.
603
+ 2. [x] **LOCKED linear DOFs ball-socket.** Pendulum (anchor pinned
604
+ to a world pivot, body swings) and a 2-link chain (body↔body,
605
+ joints stay connected, chain hangs) pass. **chains, ropes,
606
+ pendulums working.**
607
+ 3. [x] LOCKED angular + linear DOFs in the frame basis — **weld,
608
+ hinge, prismatic done**. Joint frame bases
609
+ (`localBasisA`/`localBasisB`); BOTH linear and angular rows now
610
+ resolve in frame A's axes (cleared the world-axis linear debt — the
611
+ solver is fully frame-relative). Angular: relative rotation
612
+ `qD = conj(qA)·qB` small-angle error, ωB−ωA rows + SPOOK bias.
613
+ Linear: `C·axis` error, vA−vB rows. `asWeld()` / `asHinge(axis)` /
614
+ `asPrismatic(axis)` presets. Verified: weld holds pose + orientation
615
+ against an off-centre torque; hinge swings about its free axis only
616
+ (locked axes < 0.02); prismatic slides along its one free axis,
617
+ locked on the others; all LOCKED-mode tests still green after the
618
+ frame-basis rewrite.
619
+ 4. [x] LIMITED + MOTOR (bounded rows) → doors, pistons, wheel
620
+ spin/drive, joint ROM. **LIMITED done** (linear + angular):
621
+ `setLinearLimit(axis,lo,hi)` / `setAngularLimit(axis,lo,hi)` set a
622
+ per-DOF travel/ROM range. The whole row set is now **one mode-
623
+ agnostic solve** parameterised by `(bias, clamp range)`: LOCKED is
624
+ the bilateral case (Baumgarte bias, unclamped); LIMITED is a
625
+ **speculative (β=1) one-sided velocity constraint** that removes
626
+ exactly the approach velocity so the DOF *lands on* its stop (no
627
+ penetration, no rebound — an inelastic end-stop) and self-gates when
628
+ far from the bound; only the push-out side of the bias is clamped so
629
+ a teleport is eased out, not yanked. Verified: a vertical slider
630
+ falls freely then stops dead on its lower stop (lands at the bound,
631
+ no overshoot/rebound, locked axes held); a spun hinge stops dead on
632
+ each ±end-stop with no rebound and holds. Angular position is the
633
+ small-angle measure (`2·sin(θ/2)`) — accurate for modest ROM, see
634
+ phase 6 for wide cones. **MOTOR next** (target-velocity row, impulse
635
+ clamped to `±maxForce·h`).
636
+ 5. [x] SPRING (SPOOK soft) suspension, bungees, soft ragdolls.
637
+ `setLinearSpring(axis,k,c)` / `setAngularSpring(axis,k,c)`. A
638
+ compliant (regularised) row in the same unified solve: per substep
639
+ `denom = c + h·k`, compliance `γ = 1/(h·denom)`, restoring bias
640
+ `(k/denom)·C`, softened mass `1/(K+γ)`; the iteration carries one
641
+ extra `+ γ·λ_accum` term = 0 the LOCKED/LIMITED/MOTOR rows are
642
+ bit-for-bit unchanged). Verified: a vertical strut settles at exactly
643
+ the m·g/k deflection and a stiffer spring sags less and stays stable;
644
+ an undamped spring oscillates about equilibrium (stores energy) while
645
+ a damped one comes to rest; a torsional spring holds a gravity-loaded
646
+ hinge at its balance angle. Suspension element ready (the simulated-
647
+ wheel option for phase 7); also the soft basis for cone-twist.
648
+ 6. [x] Cone-twist / swing-twist angular limits ragdolls. Opt-in
649
+ `Joint.swingTwist` (or the `asConeTwist(twistLo,twistHi,swingY[,swingZ])`
650
+ preset) switches the angular position measure from the per-axis
651
+ small-angle vector to a swing-twist decomposition: angular X = twist
652
+ about the bone, Y/Z = swing off it, each an **exact** angle. The
653
+ existing LIMITED/SPRING/LOCKED rows are reused unchanged on those
654
+ positions, so a twist/swing limit holds at the true angle at wide
655
+ ROM (a 1.2 rad swing stops at 1.2, where the small-angle proxy
656
+ drifts to ~1.287). Verified: exact swing/twist stops, free-within-
657
+ cone, twist/swing independence; default (small-angle) path untouched.
658
+ **Decision — inlined, not the Quaternion method.** Benchmarked the
659
+ allocation-free inlined `swing_twist_error` against
660
+ `Quaternion.computeSwingAndTwist` (`swing_twist.bench.spec.js`): the
661
+ inline is **~5x** faster than the method with reused out-params and
662
+ **~10x** vs the naive fresh-allocation form (object property access +
663
+ normalize + a quaternion multiply + GC). In the per-substep
664
+ per-joint hot loop that margin is worth the duplicated math, so the
665
+ solver inlines it (the Quaternion method stays for general callers).
666
+ 7. [x] Vehicle layer **raycast-vehicle controller**
667
+ (`vehicle/RaycastVehicle.js`): single chassis body + raycast wheels.
668
+ Per frame (before `fixedUpdate`) each wheel casts its suspension ray,
669
+ applies a spring+damper suspension force along the contact normal
670
+ (`applyForceAt`), and a tyre-friction impulse (`applyImpulseAt`) —
671
+ lateral grip that cancels side-slip plus longitudinal drive/brake,
672
+ clamped together to a friction circle μ·N. `addWheel`, `setSteering`,
673
+ `setDriveForce`, `setBrake`; per-wheel runtime (contact, compression,
674
+ normal, spin) for rendering. A controller on top of the public
675
+ `raycast` + force API, not a new constraint; the 6-DOF spring+motor
676
+ is the simulated-wheel alternative. Verified: hovers on its springs
677
+ (4 contacts, settled), drives/coasts/brakes along its axis, tyre grip
678
+ arrests a sideways shove, steering turns it upright, and it free-falls
679
+ cleanly when airborne. Note: suspension is one dt-force per frame (not
680
+ per-substep), so a resting chassis carries a ~g·h velocity-sample
681
+ artifact (it hovers stably; position is steady to sub-cm). Ray
682
+ accuracy follows `PhysicsSystem.raycast` now narrowphase-exact for
683
+ sphere / box / capsule / mesh / heightmap ground.
684
+ 8. [ ] Extras: pulley, gear, conveyor (contact surface-velocity),
685
+ breakable-joint flag.
686
+
687
+ Foundation gaps both now closed:
688
+ - [x] **Island integration.** Jointed dynamic-dynamic bodies are
689
+ unioned into one island (`IslandBuilder` Pass 1b), so a chain /
690
+ ragdoll sleeps and wakes as a unit; `__wake_joints` propagates wake
691
+ across a joint when one side is awake and the other asleep
692
+ (e.g. a kinematic/motor driver pulling a sleeping chain). Verified:
693
+ a damped chain settles and both links sleep in one sleep group.
694
+ - [x] **Generation-checked body references.** `solve_joints`,
695
+ `IslandBuilder` Pass 1b and `__wake_joints` all gate on
696
+ `storage.is_valid(packedId)`, so a joint to an unlinked / slot-reused
697
+ body goes inert instead of attaching to the wrong body or crashing.
698
+ Verified: unlinking a jointed body leaves the joint inert and the
699
+ survivor free.
700
+
701
+ References: Catto / Box2D-v3 joint solvers; Jolt's `Constraint` base
702
+ (`SetupVelocityConstraint` / `WarmStartVelocityConstraint` /
703
+ `SolveVelocityConstraint` / `SolvePositionConstraint`); PhysX D6 /
704
+ ODE joint taxonomy.
705
+
706
+ ### Stability
707
+ - [x] **Closed-form triangle-vs-primitive solvers** `sphere_triangle_contact`
708
+ / `box_triangle_contact` / `capsule_triangle_contact` (P1.1a–c), wired into
709
+ the concave decomposition dispatch in place of per-triangle GJK+EPA for
710
+ those primitives. Un-skipped the `narrowphase_concave.spec.js` ball-on-
711
+ heightmap / mesh-cube settle tests and the `PhysicsSystem.spec.js`
712
+ torus-knot test. Per-triangle GJK+EPA remains only as the fallback for
713
+ *other* convex shapes vs triangles. `compute_penetration` now routes
714
+ through the shared narrowphase dispatch (`deepest_pair_penetration`), so it
715
+ uses the closed-form per-triangle solvers too the old closed-mesh
716
+ over-report is gone; the half-space test is retained only as a
717
+ tunnel-recovery fallback.
718
+ - [x] **Edge-edge multi-point manifold** *resolved by design (no code
719
+ change needed).* An empirical SAT-source sweep over a wide range of
720
+ box-box orientations shows the single-point edge-cross branch only ever
721
+ wins for **transverse** edge crossings (inter-edge angle ≈ 83-90°), where
722
+ a single closest-pair point is geometrically exact. A near-parallel edge
723
+ pair gives a near-degenerate `edgeA × edgeB` that never becomes the SAT
724
+ minimum, so near-parallel ("line") edge contacts resolve through the
725
+ multi-point **face-clipping** path instead confirmed by regression
726
+ tests in `box_box_manifold.spec.js` (near-parallel tilted boxes 2
727
+ points; transverse crossing → exactly 1 exact point). The originally
728
+ planned refinement targeted a case the geometry can't produce, so it is
729
+ closed rather than implemented.
730
+ - [x] **Per-contact source-collider tracking (materials)** multi-material
731
+ compound bodies now get accurate per-contact friction / restitution. The
732
+ narrowphase combines the specific (colliderA, colliderB) pair's
733
+ coefficients at dispatch time (the only place that knows the source
734
+ collider on each side — `contact/combine_material.js`) and stamps them
735
+ into the manifold (CONTACT_STRIDE grown 14 16, offsets 14/15); the
736
+ solver reads them per contact instead of from the body's primary collider.
737
+ Regression test: an asymmetric-friction compound body yaws when shoved
738
+ (the grippy collider drags), and a symmetric control does not. Still
739
+ primary-collider-only: the contact-filter callback's collider args and the
740
+ body-level sensor / concave flags (smaller follow-up).
741
+ - [ ] **Joint-aware island sleep (ragdoll settle quality).** A draped,
742
+ self-colliding 10-joint ragdoll does not fully sleep in 10 s — surfaced by
743
+ a 1000-seed Monte-Carlo sweep (`PhysicsSystem.ragdoll.spec.js`, `.skip`):
744
+ for unlucky seeds a distal limb sustains a settled limit cycle (settled
745
+ finite-difference accel up to ~1094 m// ~1479 rad/s² at a limb end vs a
746
+ ~55 m/ median bounded, non-growing, penetration-free, so a quality gap
747
+ not a divergence). The sleep test today is per-body `|v|²+|ω|²`; an island
748
+ over-constrained by cone-twist limits + self-contacts keeps small residual
749
+ jiggle above the per-body threshold so it never crosses into sleep.
750
+ Candidate fixes: sleep a jointed/contacting island on its AGGREGATE motion
751
+ rather than the per-body minimum, and/or a settled-regime relaxation (zero
752
+ restitution + extra position iterations) once an island's energy is low.
753
+ The sweep flags the worst seeds for replay. (Test infra also adds
754
+ per-point kinematics tracking joint anchors + limb ends, with
755
+ displacement→velocity→acceleration and the angular equivalents.)
756
+ - [x] **Box-on-heightmap settlingRESOLVED.** A dynamic box dropped onto a
757
+ static HeightMapShape flat seam straddle AND the sloped dip — settles to
758
+ full rest; the `PhysicsSystem.heightmap.spec.js` dip-drop reproducer is
759
+ un-skipped and passing. Fixed by the combination of the same-feature-id
760
+ contact de-dup in `redetect_pair_geometry` (1:1 claimed matching, so the
761
+ several contacts one triangle emits — all sharing its feature_id — no longer
762
+ collapse onto a single candidate) and the HeightMapShape3D
763
+ collision-tessellation work; together they give the box a stable per-substep
764
+ contact set instead of a churning / collapsing one.
765
+
766
+ Root cause, for the record: the historical "never settles" rattle was a
767
+ depth divergence between the once-per-step `narrowphase_step` and the
768
+ per-substep `redetect_pair_geometry`. At the SAME pose, re-detection
769
+ over-reported a box-vs-triangle penetration as ~1 m (the "exit through the
770
+ far side" class) where narrowphase reported ~1 cm, launching the box into an
771
+ eternal vertical bounce (touch ~1 m over-correction separate fall back
772
+ re-contact). Both paths call the identical `dispatch_pair`, so the
773
+ divergence was the same-fid collapse corrupting the matched geometry; with
774
+ the de-dup in place the two paths now agree (verified: both report
775
+ [0.0100 ×4] at a 0.01-deep flat contact, in-cell and 4-triangle straddle).
776
+
777
+ Guards: `narrowphase/redetect_pair_geometry.spec.js` now pins BOTH
778
+ invariants contacts sharing a feature_id keep distinct witnesses, and
779
+ re-detect depth == narrowphase depth at a fixed pose (in-cell and
780
+ 4-triangle seam-straddle cases); `ecs/PhysicsSystem.heightmap.spec.js` pins
781
+ the observable settle. The depth-equality regression test the earlier
782
+ diagnostic trail asked for is in place, closing this out.
783
+
784
+ ### Performance / Scale
785
+ - [x] **Per-body linear CCD shape-cast** opt-in continuous collision for
786
+ fast movers where the speculative margin isn't enough.
787
+ `RigidBodyFlags.CCD` (off by default) + `ccd/linear_sweep.js`.
788
+ - **Approach (Box2D `b2_continuousPhysics`-style conservative
789
+ advancement).** After the substep solver produces each body's final
790
+ pose (between `apply_restitution` and the sleep test), a flagged fast
791
+ mover's primary collider is swept along its NET step translation
792
+ (start-of-step final pose) through the existing `shape_cast` TOI
793
+ engine. On the first blocker the body is clamped to the contact pose
794
+ and its inbound normal velocity removed (an inelastic stop); the next
795
+ discrete step resolves the now-touching contact with the real
796
+ material / restitution. Reuses `shape_cast` wholesale — no new
797
+ geometry. Start positions captured in Stage 1 over the post-wake awake
798
+ set; the pass iterates the awake list in storage order (deterministic).
799
+ - **Motion gate absolute slop, NOT body extent.** A body is swept when
800
+ it moved more than `CCD_MIN_SWEEP_DISTANCE` (1 mm) this step. The gate
801
+ exists only to skip near-stationary bodies (degenerate sweep + cost).
802
+ It is deliberately *not* a fraction of the body's own size: tunnelling
803
+ risk is set by the **obstacle's** thickness, not the mover's — a 2 m
804
+ sphere drifting 0.5 m/step still passes clean through a 1 cm floor, so
805
+ an extent-based gate would (wrongly) wait until the body moved more
806
+ than its own radius and miss every thin-obstacle tunnel below that
807
+ speed.
808
+ - **No self-clamp on resting/sliding contacts.** The sweep ignores an
809
+ impact at `t 0` (`CCD_INITIAL_OVERLAP_EPS`): an initial overlap is a
810
+ contact the body already sits/slides on, owned by the discrete solver,
811
+ not a tunnel clamping there would freeze the body to the surface.
812
+ - **Measured (falling-tower bench, 1000 random shapes onto a 1 cm floor,
813
+ 600 ticks; clean A/B on identical code via `ccdEnabled`).** This bench
814
+ is the WRONG validation vehicle for CCD, and the numbers prove it: CCD
815
+ off → **10/1000 tunnel**, median **42.7 ms**/step; all 1000 flagged →
816
+ **50/1000 tunnel**, median **61.6 ms**. CCD makes it *worse*. The bench
817
+ is a dense-pile **squeeze-through** scenario 1000 bodies stacked on a
818
+ 1 cm floor, forced through by the column's weight over many steps — which
819
+ is a *solver* limitation, not a missed single-step fly-through. CCD's
820
+ post-solve clamp + velocity-kill fights the solver in a dense settling
821
+ pile (it teleports mutually-stacking dynamics and breaks warm-start), so
822
+ flagging a whole pile is an anti-pattern. CCD's real job stopping a
823
+ sparse fast mover against thin geometry is validated by
824
+ `ccd/linear_sweep.spec.js` (9 tests: a fast cube tunnels a thin floor
825
+ without the flag and is stopped with it; deterministic; resting bodies
826
+ undisturbed). **Correction:** an earlier version of this entry and the
827
+ commit message (`42163b0d4`) claimed a "0/1000 tunnel, 58.2 ms" on-leg
828
+ that was never measured (a session tooling glitch); the real on-leg
829
+ is 50/1000 / 61.6 ms.
830
+ - **Scope (v1, documented):** linear sweep only (orientation fixed
831
+ through the sweep); primary same-entity collider (child-entity
832
+ colliders, synced outside the step, are not swept); EXACT against
833
+ static geometry, APPROXIMATE against other dynamics (their
834
+ start-of-step broadphase AABBs); the CCD stop is inelastic (the impact
835
+ itself doesn't bounce restitution applies on the next discrete
836
+ contact); Dynamic bodies only. A body both resting on one surface and
837
+ tunnelling another in the same step resolves only the resting contact
838
+ (the `t 0` skip) — rare; the next discrete step catches the rest.
839
+ - **Follow-ups (the dense-pile finding points the way):** sweep against
840
+ STATIC geometry only by default the dynamic-vs-dynamic clamp is the
841
+ source of the dense-pile interference above and is only ever
842
+ approximate anyway, so dropping it should make CCD purely additive
843
+ (stops you at static walls/floors, never fights the dynamic stack);
844
+ a proper TOI sub-solver for bullet-vs-dynamic; rotational / angular
845
+ CCD; multi-collider sweep for compound bodies.
846
+ - [x] **Broadphase BVH balance — SAH rotation.** The dynamic AABB tree
847
+ (`core/bvh2/bvh3/BVH.js`, a Box2D port) used SAH-cost insertion but a
848
+ *height-only* AVL rotation (`balance_height`): height-balanced yet not
849
+ SAH-balanced, so queries walked more nodes than needed. Replaced the
850
+ rotation in `bubble_up_update` with `balance_rotate` the Box2D-v3 /
851
+ Kensler SAH-reducing rotation (for node A with children B, C, evaluate the
852
+ four child↔grandchild swaps and apply the one that most reduces the
853
+ surface-area cost). Deterministic; identical pair set.
854
+ - Measured (same-session A/B, heavy benches): raycast **−9%**
855
+ (28.2→25.6 µs/ray), falling-tower median **−10%**, settling-grid
856
+ median **−12%**, and the **990/1000-churn stress −27%**
857
+ (63.95→46.68 ms mean over 10k ticks) biggest where the tree churns
858
+ hardest. Determinism (8-trial bit-identical) holds.
859
+ - **Insertion cost (measured):** `balance_rotate` does 4 surface-area
860
+ evaluations per bubble-up level vs `balance_height`'s single height
861
+ compare, so *pure bulk insertion* is **~1.4–1.5× slower** — the 100k
862
+ synthetic insert bench (`BVH.spec.js`, drift-controlled interleaved
863
+ A/B) drops from **~37k ~25k inserts/sec** (~27→~40 µs/insert). This
864
+ is the balancer's worst case (insert-only, zero queries/refits to
865
+ amortise against). It does not show up end-to-end: static trees are
866
+ built once then queried forever, dynamic bodies insert once then
867
+ refit/query every frame, and even the 990/1000-swap stress test the
868
+ maximal insert-churn workload is net **−27%**. Accepted.
869
+ - **Tradeoff (documented):** the contact solver's Gauss-Seidel order
870
+ follows broadphase traversal order (see `generate_pairs`), so the
871
+ different tree shape shifts convergence on near-aligned stacks — the
872
+ synthetic 128-cube wall now sleeps at ~10 s (was ~6.9 s). It still
873
+ settles, doesn't creep / topple (all bug-guard assertions hold); only
874
+ the sleep *time* moved (that test's budget was bumped 9→11 s with a
875
+ note). Random-shape scenes (falling tower) were faster *and* settled
876
+ fine.
877
+ - **Follow-up:** decouple the solve order from tree shape — sort the
878
+ broadphase pair list by `(idA, idB)` before narrowphase so contact
879
+ order is body-id-deterministic regardless of tree shape. Then no tree
880
+ change can affect convergence (and the stack settles identically under
881
+ either balancer). Has a per-step sort cost + wide test re-baseline, so
882
+ it's its own task. `balance_height` is retained for comparison /
883
+ fallback.
884
+ - [ ] **Per-island parallel solve**: today's island data layout would
885
+ allow worker-based solving once `SharedArrayBuffer` is available.
886
+ Out-of-scope unless / until SAB is universally usable.
887
+
888
+ ### Features
889
+ - [ ] **Convex collision proxies for dynamic concave bodies.** The long-term
890
+ replacement for the interim per-substep concave re-detection (see
891
+ Limitations) — and how every major engine handles dynamic non-convex
892
+ shapes: collide a *few* convex pieces, never the raw concave mesh.
893
+ 1. **3D convex hull builder** (meep has only 2D hulls today —
894
+ `core/geom/2d/convex-hull/`). A single hull of a mesh is one
895
+ collider / one broadphase leaf and covers the overwhelming majority
896
+ of dynamic objects (thrown props, debris). Pairs with the existing
897
+ "Convex hull shape + eigen-inertia" item below.
898
+ 2. **Few-hull (V-HACD-style) approximate convex decomposition** for
899
+ shapes whose concavity matters (a cup, a chair): ~8–64 fat convex
900
+ hulls = 8–64 colliders, two orders of magnitude below a tet mesh.
901
+ Each hull is convex stable contact feature the TGS analytic refresh
902
+ is exact no per-substep re-detection, no rocking. Granularity is the
903
+ whole point: collider/BVH-leaf count must stay small for an *awake*
904
+ dynamic body (the volumetric tet-mesher under `core/geom/3d/tetrahedra/`
905
+ is the wrong tool here thousands of pieces and belongs to a future
906
+ FEM/soft-body subsystem, not rigid collision).
907
+ - [ ] **Convex hull shape** with eigen-based principal-axes inertia
908
+ derivation. Hooks `matrix_eigenvalues_in_place` from the existing
909
+ linalg layer.
910
+ - [~] **Cylinder / cone shapes.**
911
+ - [x] **`CylinderShape3D`** Y-aligned solid cylinder (radius + full
912
+ height, flat caps; the capsule's flat-cap sibling). Exact `support`,
913
+ capped-cylinder SDF, bounds, `contains` / `nearest_point` /
914
+ volume-sampling, equals/hash, `'cylinder'` JSON tag, `isCylinderShape3D`
915
+ marker. Convex routes through the narrowphase **GJK + EPA** fallback
916
+ (no marker dispatch needed); spec asserts overlap-detected +
917
+ MTV-separates vs sphere/box. Closed-form cylinder-vs-X contact pairs
918
+ are a future refinement (the curved side is the usual smooth-support
919
+ EPA case same status as pre-closed-form sphere/capsule).
920
+ - [ ] Closed-form cylinder contact pairs (cylinder × box / sphere / capsule
921
+ / plane) for multi-point cap manifolds + stable resting.
922
+ - [ ] **Cone shape** (+ closed-form / GJK fallback).
923
+
924
+ ### Rendering integration
925
+ - [ ] **Fixed-step → render interpolation.** Not implemented yet. Physics writes
926
+ each body's pose straight into the ECS `Transform` once per fixed step
927
+ (`EntityManager.fixedUpdateStepSize`); with a render rate that doesn't match
928
+ the fixed rate, the rendered motion aliases (stutter / temporal aliasing,
929
+ worst at low fixed rates). Designed as a cross-cutting system (render +
930
+ physics-as-producer + network-as-producer), reusing the network package's
931
+ agnostic interpolation primitives rather than a physics-local mechanism.
932
+ Full design + phasing: **see
933
+ [`INTEPOLATION_SYSTEM_PLAN.md`](./INTEPOLATION_SYSTEM_PLAN.md)**. Locked
934
+ decisions: a neutral shared interpolation log/adapters (lifted out of
935
+ `network/`); physics restores authoritative pose from the log at step start
936
+ (no solver rewiring) and records moved bodies' snapshots at step end;
937
+ blend `Transform` at `preRender`; O(moving) not O(N); rewind-safe via the
938
+ tick-keyed log.
939
+
940
+ ### API polish
941
+ - [x] **`overlap(shape, position, rotation, output, output_offset,
942
+ filter?)`** broadphase + narrowphase overlap query for kinematic
943
+ / AOE / selection use cases. Body_ids written into a caller-sized
944
+ Uint32Array buffer. Convex query shape only; concave candidates
945
+ are routed through the per-triangle decomposition path.
946
+ - [x] **`shapeCast(ray, shape, rotation, result, filter?)`** for
947
+ character controllers and kinematic shape sweeps. Broadphase
948
+ swept-AABB against both BVHs; per-candidate AABB-slab interval
949
+ narrowing + coarse step + GJK bisection for time-of-impact. The
950
+ output `result.normal` is the true contact-surface normal at the
951
+ kiss point, computed by re-running GJK + EPA at `best_t` on the
952
+ winning candidate (falls back to `-ray.direction` only on EPA
953
+ degeneracies).
954
+ - [x] **`compute_penetration(out_direction, shape_a, pos_a, rot_a,
955
+ shape_b, pos_b, rot_b)`** — standalone geometry primitive (no
956
+ PhysicsSystem) for resolving overlap between two shapes at given
957
+ poses. Returns depth + outward direction. **Hardened** to route through
958
+ the shared narrowphase dispatch (`deepest_pair_penetration`): exact
959
+ closed-form for sphere/box/capsule pairs (box-box via SAT), GJK+EPA for
960
+ general convex, closed-form per-triangle for convex × concave; the
961
+ half-space test is retained only for tunnel recovery.
962
+
963
+ ### Raycast narrowphase (done)
964
+
965
+ **Problem.** `raycast` (and the suspension ray inside `RaycastVehicle`) resolves
966
+ only to the nearest BVH leaf's *inflated* AABB: `result.t` is the distance to
967
+ that fattened box and `result.normal` is its face normal. Exact for an
968
+ axis-aligned box (modulo the broadphase margin), coarse for spheres / capsules /
969
+ rotated boxes / meshes / heightmaps. Refine each candidate against the true
970
+ shape to return the exact surface distance + normal. `shapeCast` already does
971
+ this for swept convex shapes via GJK+EPA; `raycast` should get the same
972
+ treatment with cheap analytic primitives on the hot path.
973
+
974
+ **Design.** Mirror `narrowphase_step`'s dispatch: closed-form ray tests for the
975
+ common primitives, a generic GJK fallback for the rest. The structural change is
976
+ in the BVH walk — the nearest *leaf AABB* is **not** the nearest *shape hit* (a
977
+ ray can clip a near fat-AABB but miss its shape while hitting a farther one), so
978
+ every crossing leaf must be refined, with subtrees pruned by inflated-AABB
979
+ `t_near` vs the best *refined* `t` (conservative-correct: a shape hit is always
980
+ ≥ its tight AABB entry ≥ its inflated AABB entry). A leaf whose ray crosses the
981
+ fat AABB but misses the true shape now contributes **no hit** — the key
982
+ correctness gain.
983
+
984
+ Phasing (each phase: implement → spec → run from `H:/git/moh` → commit):
985
+
986
+ 1. [x] **Ray-primitive helpers** — originally landed as `narrowphase/ray_shapes.js`,
987
+ later EXTRACTED to `core/geom/3d/{sphere,box,capsule}/{sphere3,box3,capsule3}_raycast.js`
988
+ (the (`t`, normal, miss = `Infinity`, first-hit-from-outside) convention is a
989
+ fine general raycast contract, and a ray-vs-capsule primitive was otherwise
990
+ missing engine-wide; the dispatch still shares one ray→local transform across
991
+ them). Built local-frame (unit direction ⇒ `t` preserved;
992
+ rotate the local normal back). Triangle MT is inlined in the concave path
993
+ (the existing `computeTriangleRayIntersection` writes a `SurfacePoint3` and
994
+ returns no `t` — unsuited to the buffer-flyweight loop). Colocated specs.
995
+ 2. [x] **Ray-narrowphase dispatch** `narrowphase/refine_ray_hit.js`:
996
+ `(shape, position, rotation, ox,oy,oz, dx,dy,dz, tMax, outNormal) → t`.
997
+ Type-marker dispatch (`isUnitSphereShape3D` / `isBoxShape3D` /
998
+ `isCapsuleShape3D`) to the analytic primitives; a generic convex fallback
999
+ for `TransformedShape3D` / `UnionShape3D` / other (GJK ray-cast, or reuse
1000
+ `shape_cast` with a zero-radius `PointShape3D`).
1001
+ 3. [x] **Concave path** in the dispatch: for `is_convex === false` (mesh /
1002
+ heightmap), enumerate the triangles overlapping the ray's swept AABB
1003
+ (`mesh_enumerate_triangles` / `heightmap_enumerate_triangles`), Möller–
1004
+ Trumbore each, take the nearest; normal from the triangle winding.
1005
+ 4. [x] **Rewire `queries/raycast.js`**: at each leaf, call `refine_ray_hit` on
1006
+ the true shape + pose instead of accepting the AABB `t_near`; track the best
1007
+ refined `(t, body, normal)`; keep subtree pruning on inflated-AABB `t_near`.
1008
+ Same signature / `PhysicsSurfacePoint` result; drop the AABB-face-normal
1009
+ block. Multi-collider bodies still resolve the primary collider only
1010
+ (inherited BVH-leaf limitation; note it).
1011
+ 5. [x] **Tests**: per-shape exactness (sphere / OBB / capsule / mesh /
1012
+ heightmap) — exact `t` and true normal; the **fat-AABB-cross-but-shape-miss
1013
+ ⇒ no hit** case (the correctness win); nearest-of-several across a near miss;
1014
+ `filter` and `tMax` honoured. Re-verify `RaycastVehicle` (ride height now
1015
+ exact — tighten the test bands if they shift by the old broadphase margin).
1016
+ 6. [x] **Bench + docs**: a raycast micro-bench (analytic fast-path cost; confirm
1017
+ the fat-AABB-miss rejection doesn't regress throughput); update the "Public
1018
+ queries" entry, `raycast.js` header, and the `RaycastVehicle` "AABB-level"
1019
+ caveat once exact.
1020
+
1021
+ Note: this sharpens `RaycastVehicle` suspension on non-box ground and every
1022
+ shape query; it does not change the broadphase or any API surface.
1023
+
1024
+ ---
1025
+
1026
+ ## Future / out-of-scope
1027
+
1028
+ These are explicit architectural exclusions or post-v1 explorations.
1029
+
1030
+ ### Architecture
1031
+ - **Cross-runtime bit-exact determinism**: a soft-float library would
1032
+ replace `Math.sin/cos/exp/log/pow` in the hot path. The codebase is
1033
+ already structured to make this a swap-in at `quat3_integrate.js` and
1034
+ tangent-basis construction in `build_manifold.js`. Not pursued because
1035
+ the same-runtime determinism we have covers the common cases (single-
1036
+ device replay, networked lockstep where all clients run the same JS
1037
+ engine).
1038
+ - **WASM / SIMD**: the engine targets pure-JS portability. SIMD would
1039
+ invalidate the determinism story (V8 doesn't expose deterministic
1040
+ Float64x2 ops).
1041
+ - **Multi-threaded solver**: workers don't share memory cheaply without
1042
+ `SharedArrayBuffer` plus the COOP/COEP HTTP headers, which are not
1043
+ always available. Single-threaded is good-enough for the awake-body
1044
+ budget that matters.
1045
+ - **Packed-SoA body dynamics state — DECIDED AGAINST; do not re-open.** A
1046
+ reviewer will note that `BodyStorage` is SoA for *identity* (entity /
1047
+ generation / kind / flags / awake-set) but the per-body *dynamics* state —
1048
+ velocity, inertia, mass, force/torque accumulators — lives on the `RigidBody`
1049
+ **component object** (each carrying several `Vector3` = `Float64Array` + an
1050
+ `onChanged` Signal), in a sparse `__bodies[]` array reached by pointer-chase,
1051
+ not packed by slot. The same is true of `Collider` and `Joint`. This is a
1052
+ deliberate, settled choice, not an oversight: **meep is an ECS engine, and
1053
+ `RigidBody` / `Collider` / `Joint` are public-API components.** Them being
1054
+ first-class objects is a UX choice and uniformity with the rest of the engine —
1055
+ it is what makes them authorable, serializable (`toJSON`/`fromJSON` + binary
1056
+ adapters), value-diffable (`equals`/`hash` for netcode replication), and
1057
+ observable (`Vector3.onChanged`), exactly like every other component. A
1058
+ packed-SoA body pool would buy locality on the *awake* integration sweeps at
1059
+ the cost of breaking that uniformity and the public component contract. The
1060
+ design instead leans on "mostly-sleeping" (per-body iteration is over the
1061
+ *awake* set only), keeps the genuinely O(contacts) inner loop in flat SoA
1062
+ (manifolds + solver scratch), and has the hot paths index the component
1063
+ vectors' `Float64Array` backing directly to skip the observer (see
1064
+ Determinism). This is final — do not resurface it as a "fix".
1065
+ - **Single in-flight solve (module-scoped solver scratch).**
1066
+ `solver/solve_contacts.js` keeps its cross-stage state (the `g_*` counters and
1067
+ the `scratch_*` arrays) at module scope — one copy shared by all worlds, not
1068
+ per `PhysicsSystem`. Deliberate: every world reuses one set of scratch, and
1069
+ it's safe because the engine is single-threaded and steps one `fixedUpdate` at
1070
+ a time. The ceiling it sets: two `PhysicsSystem` instances cannot be stepped
1071
+ concurrently or re-entrantly (the second clobbers the first's solver scratch).
1072
+ Accepted for a single-world, single-threaded engine; lifting it would need
1073
+ per-system scratch (or a solver-context object threaded through the stages).
1074
+
1075
+ ### Simulation extensions
1076
+ - **Soft body / cloth / fluids**: the SoA layout in `BodyStorage` and the
1077
+ manifold cache are rigid-body shaped. A soft-body system would be a
1078
+ parallel subsystem, not an extension.
1079
+ - **Reduced-coordinate articulations** (MuJoCo / Featherstone-style):
1080
+ game-physics audience runs in maximal coordinates by convention. Not
1081
+ on the roadmap.
1082
+
1083
+ ### Game-side
1084
+ - **Vehicle physics** (suspensions, drivetrains): a domain layer that
1085
+ sits on top of the rigid-body primitives, not in `meep/`.
1086
+ - **Character controllers**: same — `engine/control/first-person/` is the
1087
+ natural home.
1088
+
1089
+ ---
1090
+
1091
+ ## Notable design files
1092
+
1093
+ - Original design plan: `C:\Users\Alex\.claude\plans\let-s-plan-to-implement-transient-harp.md`
1094
+ - This file (state of play): `engine/physics/PLAN.md`