@woosh/meep-engine 2.139.0 → 2.141.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 (199) hide show
  1. package/package.json +1 -1
  2. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_aabb.d.ts +3 -3
  3. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_aabb.d.ts.map +1 -1
  4. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_aabb.js +4 -4
  5. package/src/{engine/physics/broadphase/aabb_transform_oriented.d.ts → core/geom/3d/aabb/aabb3_transform_oriented.d.ts} +2 -2
  6. package/src/core/geom/3d/aabb/aabb3_transform_oriented.d.ts.map +1 -0
  7. package/src/{engine/physics/broadphase/aabb_transform_oriented.js → core/geom/3d/aabb/aabb3_transform_oriented.js} +1 -1
  8. package/src/core/geom/3d/quaternion/quat3_multiply.d.ts +21 -0
  9. package/src/core/geom/3d/quaternion/quat3_multiply.d.ts.map +1 -0
  10. package/src/core/geom/3d/quaternion/quat3_multiply.js +25 -0
  11. package/src/core/geom/3d/quaternion/quat3_to_matrix3.d.ts +54 -0
  12. package/src/core/geom/3d/quaternion/quat3_to_matrix3.d.ts.map +1 -0
  13. package/src/core/geom/3d/quaternion/quat3_to_matrix3.js +69 -0
  14. package/src/core/geom/3d/shape/AbstractShape3D.d.ts +24 -2
  15. package/src/core/geom/3d/shape/AbstractShape3D.d.ts.map +1 -1
  16. package/src/core/geom/3d/shape/AbstractShape3D.js +24 -1
  17. package/src/core/geom/3d/shape/HeightMapShape3D.d.ts +148 -0
  18. package/src/core/geom/3d/shape/HeightMapShape3D.d.ts.map +1 -0
  19. package/src/core/geom/3d/shape/HeightMapShape3D.js +451 -0
  20. package/src/core/geom/3d/shape/MeshShape3D.d.ts +210 -0
  21. package/src/core/geom/3d/shape/MeshShape3D.d.ts.map +1 -0
  22. package/src/core/geom/3d/shape/MeshShape3D.js +593 -0
  23. package/src/core/geom/3d/shape/TransformedShape3D.d.ts.map +1 -1
  24. package/src/core/geom/3d/shape/TransformedShape3D.js +46 -2
  25. package/src/core/geom/3d/shape/Triangle3D.d.ts +95 -0
  26. package/src/core/geom/3d/shape/Triangle3D.d.ts.map +1 -0
  27. package/src/core/geom/3d/shape/Triangle3D.js +318 -0
  28. package/src/core/geom/3d/shape/UnionShape3D.js +13 -0
  29. package/src/core/geom/3d/shape/shape_mesh_from_geometry.d.ts +30 -0
  30. package/src/core/geom/3d/shape/shape_mesh_from_geometry.d.ts.map +1 -0
  31. package/src/core/geom/3d/shape/shape_mesh_from_geometry.js +64 -0
  32. package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.js +9 -11
  33. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_build_vertex_to_tets_map.d.ts +28 -0
  34. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_build_vertex_to_tets_map.d.ts.map +1 -0
  35. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_build_vertex_to_tets_map.js +48 -0
  36. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.d.ts.map +1 -1
  37. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.js +40 -18
  38. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.d.ts +9 -5
  39. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.d.ts.map +1 -1
  40. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.js +38 -10
  41. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.d.ts +14 -5
  42. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.d.ts.map +1 -1
  43. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.js +47 -5
  44. package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.d.ts +19 -0
  45. package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.d.ts.map +1 -1
  46. package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.js +75 -13
  47. package/src/core/geom/3d/triangle/v3_compute_triangle_normal.d.ts +2 -2
  48. package/src/core/geom/3d/triangle/v3_compute_triangle_normal.d.ts.map +1 -1
  49. package/src/core/geom/3d/triangle/v3_compute_triangle_normal.js +1 -1
  50. package/src/core/geom/vec3/v3_dot_array_array.d.ts +3 -3
  51. package/src/core/geom/vec3/v3_dot_array_array.d.ts.map +1 -1
  52. package/src/core/geom/vec3/v3_dot_array_array.js +2 -2
  53. package/src/core/geom/vec3/v3_negate_array.d.ts +3 -3
  54. package/src/core/geom/vec3/v3_negate_array.d.ts.map +1 -1
  55. package/src/core/geom/vec3/v3_negate_array.js +2 -2
  56. package/src/core/geom/vec3/v3_quat3_apply.d.ts +29 -0
  57. package/src/core/geom/vec3/v3_quat3_apply.d.ts.map +1 -0
  58. package/src/core/geom/vec3/v3_quat3_apply.js +39 -0
  59. package/src/core/geom/vec3/v3_quat3_apply_inverse.d.ts +30 -0
  60. package/src/core/geom/vec3/v3_quat3_apply_inverse.d.ts.map +1 -0
  61. package/src/core/geom/vec3/v3_quat3_apply_inverse.js +41 -0
  62. package/src/core/geom/vec3/v3_triple_cross_product.d.ts +32 -0
  63. package/src/core/geom/vec3/v3_triple_cross_product.d.ts.map +1 -0
  64. package/src/core/geom/vec3/v3_triple_cross_product.js +45 -0
  65. package/src/engine/control/first-person/FirstPersonPlayerController.d.ts +16 -3
  66. package/src/engine/control/first-person/FirstPersonPlayerController.d.ts.map +1 -1
  67. package/src/engine/control/first-person/FirstPersonPlayerController.js +211 -211
  68. package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts +72 -8
  69. package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts.map +1 -1
  70. package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.js +37 -5
  71. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts +101 -3
  72. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
  73. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +1789 -1416
  74. package/src/engine/control/first-person/TODO.md +173 -127
  75. package/src/engine/control/first-person/abilities/Slide.d.ts.map +1 -1
  76. package/src/engine/control/first-person/abilities/Slide.js +9 -1
  77. package/src/engine/control/first-person/prototype_first_person_controller.js +88 -2
  78. package/src/engine/control/first-person/test/buildTestPlayer.d.ts.map +1 -1
  79. package/src/engine/control/first-person/test/buildTestPlayer.js +9 -1
  80. package/src/engine/graphics/geometry/CapsuleGeometry.d.ts +42 -0
  81. package/src/engine/graphics/geometry/CapsuleGeometry.d.ts.map +1 -0
  82. package/src/engine/graphics/geometry/CapsuleGeometry.js +171 -0
  83. package/src/engine/physics/BULLET_REVIEW.md +945 -0
  84. package/src/engine/physics/CANNON_REVIEW.md +1300 -0
  85. package/src/engine/physics/JOLT_REVIEW.md +913 -0
  86. package/src/engine/physics/PLAN.md +578 -236
  87. package/src/engine/physics/RAPIER_REVIEW.md +934 -0
  88. package/src/engine/physics/REVIEW_001_ACTION_PLAN.md +642 -0
  89. package/src/engine/physics/REVIEW_002.md +151 -0
  90. package/src/engine/physics/broadphase/compute_fat_world_aabb.js +2 -2
  91. package/src/engine/physics/constraint/DofMode.d.ts +28 -0
  92. package/src/engine/physics/constraint/DofMode.d.ts.map +1 -0
  93. package/src/engine/physics/constraint/DofMode.js +35 -0
  94. package/src/engine/physics/constraint/solve_constraints.d.ts +16 -0
  95. package/src/engine/physics/constraint/solve_constraints.d.ts.map +1 -0
  96. package/src/engine/physics/constraint/solve_constraints.js +436 -0
  97. package/src/engine/physics/contact/ManifoldStore.d.ts +83 -10
  98. package/src/engine/physics/contact/ManifoldStore.d.ts.map +1 -1
  99. package/src/engine/physics/contact/ManifoldStore.js +608 -499
  100. package/src/engine/physics/ecs/ColliderObserverSystem.d.ts +2 -2
  101. package/src/engine/physics/ecs/ColliderObserverSystem.d.ts.map +1 -1
  102. package/src/engine/physics/ecs/Joint.d.ts +179 -0
  103. package/src/engine/physics/ecs/Joint.d.ts.map +1 -0
  104. package/src/engine/physics/ecs/Joint.js +234 -0
  105. package/src/engine/physics/ecs/PhysicsSystem.d.ts +180 -20
  106. package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
  107. package/src/engine/physics/ecs/PhysicsSystem.js +1423 -1159
  108. package/src/engine/physics/fluid/FluidField.d.ts +14 -10
  109. package/src/engine/physics/fluid/FluidField.d.ts.map +1 -1
  110. package/src/engine/physics/fluid/FluidField.js +14 -10
  111. package/src/engine/physics/fluid/FluidSimulator.js +1 -1
  112. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts +17 -10
  113. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts.map +1 -1
  114. package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.js +18 -11
  115. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts +13 -10
  116. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts.map +1 -1
  117. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.js +18 -13
  118. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts +4 -3
  119. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts.map +1 -1
  120. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.js +15 -11
  121. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts +30 -6
  122. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts.map +1 -1
  123. package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.js +44 -18
  124. package/src/engine/physics/gjk/expanding_polytope_algorithm.d.ts +6 -6
  125. package/src/engine/physics/gjk/expanding_polytope_algorithm.d.ts.map +1 -1
  126. package/src/engine/physics/gjk/expanding_polytope_algorithm.js +68 -22
  127. package/src/engine/physics/gjk/gjk.d.ts +28 -2
  128. package/src/engine/physics/gjk/gjk.d.ts.map +1 -1
  129. package/src/engine/physics/gjk/gjk.js +421 -378
  130. package/src/engine/physics/gjk/minkowski_support.d.ts +37 -0
  131. package/src/engine/physics/gjk/minkowski_support.d.ts.map +1 -0
  132. package/src/engine/physics/gjk/minkowski_support.js +75 -0
  133. package/src/engine/physics/gjk/mpr.d.ts +56 -0
  134. package/src/engine/physics/gjk/mpr.d.ts.map +1 -0
  135. package/src/engine/physics/gjk/mpr.js +344 -0
  136. package/src/engine/physics/inertia/world_inverse_inertia.d.ts +20 -5
  137. package/src/engine/physics/inertia/world_inverse_inertia.d.ts.map +1 -1
  138. package/src/engine/physics/inertia/world_inverse_inertia.js +36 -38
  139. package/src/engine/physics/integration/integrate_position.d.ts +25 -7
  140. package/src/engine/physics/integration/integrate_position.d.ts.map +1 -1
  141. package/src/engine/physics/integration/integrate_position.js +43 -12
  142. package/src/engine/physics/integration/integrate_velocity.d.ts +30 -0
  143. package/src/engine/physics/integration/integrate_velocity.d.ts.map +1 -1
  144. package/src/engine/physics/integration/integrate_velocity.js +82 -1
  145. package/src/engine/physics/island/IslandBuilder.d.ts +4 -1
  146. package/src/engine/physics/island/IslandBuilder.d.ts.map +1 -1
  147. package/src/engine/physics/island/IslandBuilder.js +33 -16
  148. package/src/engine/physics/narrowphase/PosedShape.d.ts +0 -8
  149. package/src/engine/physics/narrowphase/PosedShape.d.ts.map +1 -1
  150. package/src/engine/physics/narrowphase/PosedShape.js +28 -30
  151. package/src/engine/physics/narrowphase/box_box_manifold.d.ts.map +1 -1
  152. package/src/engine/physics/narrowphase/box_box_manifold.js +140 -18
  153. package/src/engine/physics/narrowphase/box_triangle_contact.d.ts +30 -0
  154. package/src/engine/physics/narrowphase/box_triangle_contact.d.ts.map +1 -0
  155. package/src/engine/physics/narrowphase/box_triangle_contact.js +811 -0
  156. package/src/engine/physics/narrowphase/capsule_contacts.d.ts.map +1 -1
  157. package/src/engine/physics/narrowphase/capsule_contacts.js +10 -56
  158. package/src/engine/physics/narrowphase/capsule_triangle_contact.d.ts +71 -0
  159. package/src/engine/physics/narrowphase/capsule_triangle_contact.d.ts.map +1 -0
  160. package/src/engine/physics/narrowphase/capsule_triangle_contact.js +375 -0
  161. package/src/engine/physics/narrowphase/compute_penetration.d.ts +91 -0
  162. package/src/engine/physics/narrowphase/compute_penetration.d.ts.map +1 -0
  163. package/src/engine/physics/narrowphase/compute_penetration.js +396 -0
  164. package/src/engine/physics/narrowphase/decomposition/aabb_world_to_local.d.ts +35 -0
  165. package/src/engine/physics/narrowphase/decomposition/aabb_world_to_local.d.ts.map +1 -0
  166. package/src/engine/physics/narrowphase/decomposition/aabb_world_to_local.js +80 -0
  167. package/src/engine/physics/narrowphase/decomposition/decompose_to_triangles.d.ts +31 -0
  168. package/src/engine/physics/narrowphase/decomposition/decompose_to_triangles.d.ts.map +1 -0
  169. package/src/engine/physics/narrowphase/decomposition/decompose_to_triangles.js +55 -0
  170. package/src/engine/physics/narrowphase/decomposition/heightmap_enumerate_triangles.d.ts +42 -0
  171. package/src/engine/physics/narrowphase/decomposition/heightmap_enumerate_triangles.d.ts.map +1 -0
  172. package/src/engine/physics/narrowphase/decomposition/heightmap_enumerate_triangles.js +204 -0
  173. package/src/engine/physics/narrowphase/decomposition/mesh_enumerate_triangles.d.ts +42 -0
  174. package/src/engine/physics/narrowphase/decomposition/mesh_enumerate_triangles.d.ts.map +1 -0
  175. package/src/engine/physics/narrowphase/decomposition/mesh_enumerate_triangles.js +94 -0
  176. package/src/engine/physics/narrowphase/decomposition/triangle_buffer_layout.d.ts +37 -0
  177. package/src/engine/physics/narrowphase/decomposition/triangle_buffer_layout.d.ts.map +1 -0
  178. package/src/engine/physics/narrowphase/decomposition/triangle_buffer_layout.js +37 -0
  179. package/src/engine/physics/narrowphase/narrowphase_step.d.ts +41 -2
  180. package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -1
  181. package/src/engine/physics/narrowphase/narrowphase_step.js +1497 -382
  182. package/src/engine/physics/narrowphase/sphere_box_contact.d.ts.map +1 -1
  183. package/src/engine/physics/narrowphase/sphere_box_contact.js +16 -23
  184. package/src/engine/physics/narrowphase/sphere_triangle_contact.d.ts +48 -0
  185. package/src/engine/physics/narrowphase/sphere_triangle_contact.d.ts.map +1 -0
  186. package/src/engine/physics/narrowphase/sphere_triangle_contact.js +143 -0
  187. package/src/engine/physics/queries/overlap_shape.d.ts +51 -0
  188. package/src/engine/physics/queries/overlap_shape.d.ts.map +1 -0
  189. package/src/engine/physics/queries/overlap_shape.js +183 -0
  190. package/src/engine/physics/queries/shape_cast.d.ts +56 -0
  191. package/src/engine/physics/queries/shape_cast.d.ts.map +1 -0
  192. package/src/engine/physics/queries/shape_cast.js +387 -0
  193. package/src/engine/physics/solver/solve_contacts.d.ts +146 -32
  194. package/src/engine/physics/solver/solve_contacts.d.ts.map +1 -1
  195. package/src/engine/physics/solver/solve_contacts.js +809 -223
  196. package/src/engine/physics/broadphase/aabb_transform_oriented.d.ts.map +0 -1
  197. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.d.ts +0 -20
  198. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.d.ts.map +0 -1
  199. package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.js +0 -83
@@ -1,4 +1,3 @@
1
- import { assert } from "../../../core/assert.js";
2
1
  import { array_copy } from "../../../core/collection/array/array_copy.js";
3
2
  import { array_swap } from "../../../core/collection/array/array_swap.js";
4
3
  import { v3_compute_triangle_normal } from "../../../core/geom/3d/triangle/v3_compute_triangle_normal.js";
@@ -7,7 +6,30 @@ import { v3_dot_array_array } from "../../../core/geom/vec3/v3_dot_array_array.j
7
6
 
8
7
  import { v3_negate_array } from "../../../core/geom/vec3/v3_negate_array.js";
9
8
 
10
- const EPA_TOLERANCE = 0.0001;
9
+ /**
10
+ * Convergence tolerance — relative to the current closest-face distance,
11
+ * floored at an absolute epsilon to prevent zero-distance loops.
12
+ *
13
+ * Why relative, not absolute (P2.2). An absolute `EPA_TOLERANCE = 1e-4`
14
+ * works for mid-scale contacts (a few millimetres deep on metre-sized
15
+ * bodies) but degrades for shallow contacts: when the closest-face
16
+ * distance is ~1e-5 m (sub-mm overlaps that the speculative-margin path
17
+ * handles), `1e-4` is *larger than the depth itself*, so EPA terminates
18
+ * with whatever intermediate face it happens to have, producing a noisy
19
+ * normal direction. Jolt's `EPSILON_REL_DIST_SQ` and similar
20
+ * formulations scale tolerance with the current distance.
21
+ *
22
+ * Note: only the TOLERANCE was made relative as part of P2.2. The
23
+ * convergence-path RESULT magnitude is intentionally left as
24
+ * `dot_p_search_dir` (the new support point's projection) — switching
25
+ * to `min_dist` was tried and caused energy injection in the closed-
26
+ * form-dispatch paths that share the EPA depth metric (e.g.
27
+ * sphere-vs-sphere stack regressions). See REVIEW_001_ACTION_PLAN.md.
28
+ *
29
+ * @type {number}
30
+ */
31
+ const EPA_TOLERANCE_REL = 1e-4;
32
+ const EPA_TOLERANCE_ABS = 1e-6;
11
33
  const EPA_MAX_NUM_FACES = 64;
12
34
  const EPA_MAX_NUM_LOOSE_EDGES = 32;
13
35
  const EPA_MAX_NUM_ITERATIONS = 64;
@@ -16,16 +38,31 @@ const FACE_ELEMENT_COUNT = 3 * 4;
16
38
 
17
39
  const EDGE_ELEMENT_COUNT = 2 * 3;
18
40
 
19
- //Array of faces, each with 3 verts and a normal
20
- const faces = new Float32Array(EPA_MAX_NUM_FACES * FACE_ELEMENT_COUNT);
41
+ /**
42
+ * Polytope face buffer. Float64 throughout — EPA's expand-and-recompute
43
+ * step iterates up to {@link EPA_MAX_NUM_ITERATIONS} times, each
44
+ * iteration rebuilds face normals via cross products, and tests them
45
+ * against accumulated support points; the per-iteration error in
46
+ * Float32 compounds and noticeably slows convergence on shapes with
47
+ * many similar-magnitude faces (anything with subtle curvature). The
48
+ * memory footprint of the upgrade is the buffer's size doubling — a
49
+ * few KB at most.
50
+ *
51
+ * Layout per face: 3 vec3 vertices + 1 vec3 normal = 12 floats.
52
+ * @type {Float64Array}
53
+ */
54
+ const faces = new Float64Array(EPA_MAX_NUM_FACES * FACE_ELEMENT_COUNT);
21
55
 
22
56
  /**
23
- * keep track of edges we need to fix after removing faces
24
- * @type {Float32Array}
57
+ * Edges we need to fix after removing faces. Same Float64 motivation
58
+ * as {@link faces} — endpoints are vertex coords pulled out of `faces`,
59
+ * and any precision loss here propagates back into the next face when
60
+ * the polytope is rebuilt.
61
+ * @type {Float64Array}
25
62
  */
26
- const loose_edges = new Float32Array(EPA_MAX_NUM_LOOSE_EDGES * EDGE_ELEMENT_COUNT);
63
+ const loose_edges = new Float64Array(EPA_MAX_NUM_LOOSE_EDGES * EDGE_ELEMENT_COUNT);
27
64
 
28
- const scratch_v3 = new Float32Array(3);
65
+ const scratch_v3 = new Float64Array(3);
29
66
 
30
67
  /**
31
68
  *
@@ -39,7 +76,7 @@ function write_v3(target, target_index, v) {
39
76
 
40
77
  /**
41
78
  *
42
- * @param {number[]|Float32Array} faces
79
+ * @param {number[]|Float64Array} faces
43
80
  * @param {number} index
44
81
  * @param {number[]} a
45
82
  * @param {number[]} b
@@ -64,12 +101,12 @@ function write_face(faces, index, a, b, c) {
64
101
 
65
102
  /**
66
103
  * TODO: needs to be tested thoroughly, intended to be working with GJK
67
- * @param {number[]} result
104
+ * @param {number[]|Float64Array} result
68
105
  * @param {number} result_offset
69
- * @param {number[]} a
70
- * @param {number[]} b
71
- * @param {number[]} c
72
- * @param {number[]} d
106
+ * @param {number[]|Float64Array} a
107
+ * @param {number[]|Float64Array} b
108
+ * @param {number[]|Float64Array} c
109
+ * @param {number[]|Float64Array} d
73
110
  * @param {AbstractShape3D} coll1
74
111
  * @param {AbstractShape3D} coll2
75
112
  */
@@ -117,10 +154,6 @@ export function expanding_polytope_algorithm(
117
154
  const search_dir_y = faces[closest_face_normal_offset + 1];
118
155
  const search_dir_z = faces[closest_face_normal_offset + 2];
119
156
 
120
- if (search_dir_x === 0 && search_dir_y === 0 && search_dir_z === 0) {
121
- debugger;
122
- }
123
-
124
157
  // build new support point to expand polytope
125
158
 
126
159
  coll2.support(scratch_v3, 0, search_dir_x, search_dir_y, search_dir_z);
@@ -141,7 +174,14 @@ export function expanding_polytope_algorithm(
141
174
 
142
175
  const dot_p_search_dir = v3_dot(p_x, p_y, p_z, search_dir_x, search_dir_y, search_dir_z);
143
176
 
144
- if (dot_p_search_dir - min_dist < EPA_TOLERANCE) {
177
+ // Adaptive convergence (P2.2). Terminate when the new support
178
+ // point's projection onto the current search direction is
179
+ // within a RELATIVE tolerance of the current closest-face
180
+ // distance — scales with depth instead of the fixed absolute
181
+ // EPA_TOLERANCE = 1e-4 that was too coarse for sub-mm contacts.
182
+ const min_dist_abs = min_dist < 0 ? -min_dist : min_dist;
183
+ const tol_floor = min_dist_abs > EPA_TOLERANCE_ABS ? min_dist_abs : EPA_TOLERANCE_ABS;
184
+ if (dot_p_search_dir - min_dist < EPA_TOLERANCE_REL * tol_floor) {
145
185
  //Convergence (new point is not significantly further from origin)
146
186
 
147
187
  result[result_offset] = search_dir_x * dot_p_search_dir;
@@ -311,9 +351,15 @@ export function expanding_polytope_algorithm(
311
351
  }
312
352
  }
313
353
 
314
- console.warn("EPA did not converge");
315
-
316
- //Return most recent closest point
354
+ // Iteration cap reached without convergence. Return the
355
+ // closest-face approximation rather than warning — this is the
356
+ // expected outcome on smooth / high-complexity shapes (a torus knot
357
+ // collider produces it dozens of times per frame while the player
358
+ // is in contact). The narrowphase consumer treats any depth that
359
+ // isn't strictly positive + finite as a miss, so a degenerate
360
+ // closest-face result is filtered upstream. PLAN.md already lists
361
+ // EPA-on-smooth-shapes as a known limitation; the actionable fix
362
+ // is MPR / hierarchical support, not console spam.
317
363
  const closest_face_offset = closest_face * FACE_ELEMENT_COUNT;
318
364
  const closest_face_normal_offset = closest_face_offset + 3 * 3;
319
365
 
@@ -7,10 +7,36 @@
7
7
  *
8
8
  * Adapted from https://github.com/kevinmoran/GJK/blob/master/GJK.h
9
9
  *
10
- * @param {number[]|Float32Array} simplex Working buffer for simplex vertices (4 vec3s). Must have length >= 12.
10
+ * @param {number[]|Float64Array} simplex Working buffer for simplex vertices (4 vec3s). Must have length >= 12.
11
11
  * @param {AbstractShape3D} shape_a
12
12
  * @param {AbstractShape3D} shape_b
13
13
  * @returns {boolean} true if the shapes intersect
14
14
  */
15
- export function gjk(simplex: number[] | Float32Array, shape_a: AbstractShape3D, shape_b: AbstractShape3D): boolean;
15
+ export function gjk(simplex: number[] | Float64Array, shape_a: AbstractShape3D, shape_b: AbstractShape3D): boolean;
16
+ /**
17
+ * Separating-axis-cached variant of {@link gjk}. The 3 floats at
18
+ * `axis_buffer[axis_offset..+2]` are used as the initial search
19
+ * direction (seed) AND are overwritten with the final search direction
20
+ * on exit. The narrowphase keeps a per-manifold-slot cache of these
21
+ * three floats so quiescent contacts converge in 1–2 iterations next
22
+ * frame instead of ~6–10 from a cold `(1, 0, 0)` start (Bullet's
23
+ * `m_cachedSeparatingAxis` and Jolt's `ioV` use the same pattern).
24
+ *
25
+ * The same primitive doubles as a separating-axis cache for the
26
+ * "no-overlap" path: when GJK returns false, the final direction is
27
+ * roughly the separating axis, and next frame's first iteration
28
+ * detects separation immediately.
29
+ *
30
+ * Writeback is automatic — `gjk_core` mutates a `subarray` view of
31
+ * `axis_buffer`, so on return `axis_buffer[axis_offset..+2]` holds the
32
+ * final direction. No try/finally needed.
33
+ *
34
+ * @param {number[]|Float64Array} simplex
35
+ * @param {AbstractShape3D} shape_a
36
+ * @param {AbstractShape3D} shape_b
37
+ * @param {Float64Array} axis_buffer
38
+ * @param {number} axis_offset
39
+ * @returns {boolean}
40
+ */
41
+ export function gjk_with_axis(simplex: number[] | Float64Array, shape_a: AbstractShape3D, shape_b: AbstractShape3D, axis_buffer: Float64Array, axis_offset: number): boolean;
16
42
  //# sourceMappingURL=gjk.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gjk.d.ts","sourceRoot":"","sources":["../../../../../src/engine/physics/gjk/gjk.js"],"names":[],"mappings":"AAmDA;;;;;;;;;;;;;GAaG;AACH,6BALW,MAAM,EAAE,GAAC,YAAY,uDAGnB,OAAO,CAkGnB"}
1
+ {"version":3,"file":"gjk.d.ts","sourceRoot":"","sources":["../../../../../src/engine/physics/gjk/gjk.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;GAaG;AACH,6BALW,MAAM,EAAE,GAAC,YAAY,uDAGnB,OAAO,CAWnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,uCAPW,MAAM,EAAE,GAAC,YAAY,mEAGrB,YAAY,eACZ,MAAM,GACJ,OAAO,CAqBnB"}