@series-inc/rundot-syncplay 6.0.0-rc.2 → 6.0.0-rc.21

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 (329) hide show
  1. package/README.md +133 -0
  2. package/core/deterministic-math.d.ts +75 -1
  3. package/core/native/instance_ledger.hpp +1095 -0
  4. package/core/native/legacy_checkpoint_ids.hpp +107 -0
  5. package/core/native/physics/abi.cpp +39 -211
  6. package/core/native/physics/abi.hpp +2 -6
  7. package/core/native/physics/articulation.cpp +1434 -0
  8. package/core/native/physics/articulation.hpp +279 -0
  9. package/core/native/physics/buoyancy.cpp +1588 -0
  10. package/core/native/physics/buoyancy.hpp +254 -0
  11. package/core/native/physics/capsule_triangle.cpp +168 -0
  12. package/core/native/physics/capsule_triangle.hpp +40 -0
  13. package/core/native/physics/capsule_triangle_native.inc +291 -0
  14. package/core/native/physics/certified_sum.hpp +218 -0
  15. package/core/native/physics/character.cpp +638 -0
  16. package/core/native/physics/character.hpp +169 -0
  17. package/core/native/physics/checkpoint_schema.hpp +379 -0
  18. package/core/native/physics/cloth.cpp +1401 -0
  19. package/core/native/physics/cloth.hpp +357 -0
  20. package/core/native/physics/constraint_rows.cpp +363 -2
  21. package/core/native/physics/constraint_rows.hpp +72 -1
  22. package/core/native/physics/deformable_query.cpp +1630 -0
  23. package/core/native/physics/deformable_query.hpp +578 -0
  24. package/core/native/physics/distance.cpp +1166 -0
  25. package/core/native/physics/distance.hpp +151 -0
  26. package/core/native/physics/exact/exact-applied.cpp +101 -0
  27. package/core/native/physics/exact/exact-applied.hpp +112 -0
  28. package/core/native/physics/exact/exact-dyadic.cpp +691 -0
  29. package/core/native/physics/exact/exact-dyadic.hpp +58 -0
  30. package/core/native/physics/exact/exact-operation.hpp +51 -0
  31. package/core/native/physics/exact/word-core.hpp +262 -0
  32. package/core/native/physics/extended_abi.cpp +1242 -0
  33. package/core/native/physics/extended_abi.hpp +355 -0
  34. package/core/native/physics/extended_abi_characters.cpp +261 -0
  35. package/core/native/physics/extended_abi_characters.hpp +434 -0
  36. package/core/native/physics/extended_abi_core_features.cpp +713 -0
  37. package/core/native/physics/extended_abi_core_features.hpp +226 -0
  38. package/core/native/physics/extended_abi_deformables.cpp +448 -0
  39. package/core/native/physics/extended_abi_deformables.hpp +867 -0
  40. package/core/native/physics/extended_abi_vehicles.cpp +411 -0
  41. package/core/native/physics/extended_abi_vehicles.hpp +222 -0
  42. package/core/native/physics/fracture.cpp +1981 -0
  43. package/core/native/physics/fracture.hpp +460 -0
  44. package/core/native/physics/gear.cpp +563 -0
  45. package/core/native/physics/gear.hpp +158 -0
  46. package/core/native/physics/geometry_memory.hpp +476 -0
  47. package/core/native/physics/geometry_store.cpp +547 -0
  48. package/core/native/physics/geometry_store.hpp +134 -0
  49. package/core/native/physics/lag_compensation.cpp +1626 -0
  50. package/core/native/physics/lag_compensation.hpp +405 -0
  51. package/core/native/physics/mass_properties.cpp +449 -0
  52. package/core/native/physics/mass_properties.hpp +23 -0
  53. package/core/native/physics/material_pose.hpp +988 -0
  54. package/core/native/physics/particles.cpp +1065 -0
  55. package/core/native/physics/particles.hpp +261 -0
  56. package/core/native/physics/path_joint.cpp +781 -0
  57. package/core/native/physics/path_joint.hpp +154 -0
  58. package/core/native/physics/physics.cpp +13043 -1065
  59. package/core/native/physics/physics.hpp +184 -8
  60. package/core/native/physics/planar_deformable.cpp +2433 -0
  61. package/core/native/physics/planar_deformable.hpp +889 -0
  62. package/core/native/physics/platformer_2d.cpp +1353 -0
  63. package/core/native/physics/platformer_2d.hpp +340 -0
  64. package/core/native/physics/powered_ragdoll.cpp +1100 -0
  65. package/core/native/physics/powered_ragdoll.hpp +279 -0
  66. package/core/native/physics/powertrain.cpp +586 -0
  67. package/core/native/physics/powertrain.hpp +180 -0
  68. package/core/native/physics/pulley.cpp +311 -0
  69. package/core/native/physics/pulley.hpp +121 -0
  70. package/core/native/physics/ragdoll.cpp +586 -0
  71. package/core/native/physics/ragdoll.hpp +221 -0
  72. package/core/native/physics/rope.cpp +692 -0
  73. package/core/native/physics/rope.hpp +215 -0
  74. package/core/native/physics/rounded_convex.cpp +1229 -0
  75. package/core/native/physics/rounded_convex.hpp +287 -0
  76. package/core/native/physics/sdf_geometry.cpp +1821 -0
  77. package/core/native/physics/sdf_geometry.hpp +474 -0
  78. package/core/native/physics/soft_body.cpp +1449 -0
  79. package/core/native/physics/soft_body.hpp +328 -0
  80. package/core/native/physics/soft_collision.cpp +1862 -0
  81. package/core/native/physics/soft_collision.hpp +561 -0
  82. package/core/native/physics/surface_velocity.cpp +366 -0
  83. package/core/native/physics/surface_velocity.hpp +243 -0
  84. package/core/native/physics/topology.cpp +357 -39
  85. package/core/native/physics/topology.hpp +97 -6
  86. package/core/native/physics/tracks.cpp +1179 -0
  87. package/core/native/physics/tracks.hpp +404 -0
  88. package/core/native/physics/vehicle.cpp +629 -0
  89. package/core/native/physics/vehicle.hpp +191 -0
  90. package/core/native/physics/voxel_cooking.cpp +1929 -0
  91. package/core/native/physics/voxel_cooking.hpp +395 -0
  92. package/core/native/physics/world.cpp +5290 -854
  93. package/core/native/physics/world.hpp +796 -24
  94. package/core/native/physics/world_abi.cpp +3840 -306
  95. package/core/native/physics/world_abi.hpp +530 -10
  96. package/core/native/physics/world_digest_visitor.hpp +277 -0
  97. package/core/native/physics/world_strong_digest.hpp +557 -0
  98. package/core/native/physics2d/ccd.cpp +1302 -0
  99. package/core/native/physics2d/ccd.hpp +141 -0
  100. package/core/native/physics2d/checkpoint_memory.hpp +349 -0
  101. package/core/native/physics2d/clock_primitives.hpp +138 -0
  102. package/core/native/physics2d/commands.cpp +174 -28
  103. package/core/native/physics2d/commands.hpp +3 -1
  104. package/core/native/physics2d/compound.cpp +581 -0
  105. package/core/native/physics2d/compound.hpp +248 -0
  106. package/core/native/physics2d/contour.cpp +325 -0
  107. package/core/native/physics2d/contour.hpp +143 -0
  108. package/core/native/physics2d/frame_scope.hpp +124 -0
  109. package/core/native/physics2d/joint_phases.hpp +93 -0
  110. package/core/native/physics2d/joints.cpp +587 -150
  111. package/core/native/physics2d/joints.hpp +5 -0
  112. package/core/native/physics2d/memory_private.hpp +125 -0
  113. package/core/native/physics2d/owned_abi.cpp +1354 -879
  114. package/core/native/physics2d/owned_abi.hpp +190 -52
  115. package/core/native/physics2d/phase_test_hooks.hpp +17 -0
  116. package/core/native/physics2d/physics2d.cpp +2073 -120
  117. package/core/native/physics2d/physics2d.hpp +154 -2
  118. package/core/native/physics2d/queries.cpp +1055 -79
  119. package/core/native/physics2d/queries.hpp +71 -5
  120. package/core/native/physics2d/world.cpp +1313 -353
  121. package/core/native/physics2d/world.hpp +124 -13
  122. package/core/native/sha256/sha256_compress_unsigned.hpp +68 -0
  123. package/core/native/sha256/sha256_fips_constants.hpp +24 -0
  124. package/core/native/sha256/sha256_length.hpp +56 -0
  125. package/core/native/sha256/sha256_memo.hpp +48 -0
  126. package/core/native/sha256/sha256_sink.hpp +234 -0
  127. package/core/physics2d-owned.d.ts +466 -126
  128. package/core/runtime.d.ts +192 -19
  129. package/core/scripts/build-native.mjs +34 -0
  130. package/core/scripts/build-wasm-physics.mjs +272 -23
  131. package/core/scripts/extended-physics-profile.mjs +634 -0
  132. package/core/scripts/generate-physics2d-vectors.mjs +59 -0
  133. package/core/src/kinetix-deterministic-math.d.ts +2 -0
  134. package/core/src/kinetix-deterministic-math.mjs +513 -27
  135. package/core/src/kinetix-owned-runtime-adapter.mjs +788 -0
  136. package/core/src/kinetix-runtime-adapter-utils.mjs +54 -6
  137. package/core/src/kinetix-runtime-contract.mjs +55 -9
  138. package/core/src/kinetix-runtime-identity.mjs +12 -1
  139. package/core/src/kinetix-session-config.mjs +7 -2
  140. package/core/src/kinetix-state-report.mjs +36 -0
  141. package/core/src/physics/abi-constants.mjs +5 -4
  142. package/core/src/physics/articulation.d.mts +194 -0
  143. package/core/src/physics/articulation.mjs +1141 -0
  144. package/core/src/physics/buoyancy.d.mts +143 -0
  145. package/core/src/physics/buoyancy.mjs +268 -0
  146. package/core/src/physics/cloth.d.mts +314 -0
  147. package/core/src/physics/cloth.mjs +1156 -0
  148. package/core/src/physics/deformable-query.d.mts +217 -0
  149. package/core/src/physics/deformable-query.mjs +1412 -0
  150. package/core/src/physics/distance.d.mts +160 -0
  151. package/core/src/physics/distance.mjs +175 -0
  152. package/core/src/physics/extended-wasm-instance.d.mts +5 -0
  153. package/core/src/physics/extended-wasm-instance.mjs +48 -0
  154. package/core/src/physics/feature-api.d.mts +74 -0
  155. package/core/src/physics/feature-api.mjs +98 -0
  156. package/core/src/physics/fracture.d.mts +133 -0
  157. package/core/src/physics/fracture.mjs +1324 -0
  158. package/core/src/physics/gear.d.mts +585 -0
  159. package/core/src/physics/gear.mjs +955 -0
  160. package/core/src/physics/lag-compensation.d.mts +101 -0
  161. package/core/src/physics/lag-compensation.mjs +1100 -0
  162. package/core/src/physics/mass-properties.d.mts +114 -0
  163. package/core/src/physics/mass-properties.mjs +137 -468
  164. package/core/src/physics/particles.d.mts +177 -0
  165. package/core/src/physics/particles.mjs +758 -0
  166. package/core/src/physics/path-joint.d.mts +171 -0
  167. package/core/src/physics/path-joint.mjs +1231 -0
  168. package/core/src/physics/physics-extended-wasm-module.generated.mjs +13 -0
  169. package/core/src/physics/physics-profile-wasm-module.generated.mjs +48 -0
  170. package/core/src/physics/physics-wasm-module.generated.mjs +34 -5
  171. package/core/src/physics/powered-ragdoll.d.mts +188 -0
  172. package/core/src/physics/powered-ragdoll.mjs +1043 -0
  173. package/core/src/physics/powertrain.d.mts +260 -0
  174. package/core/src/physics/powertrain.mjs +621 -0
  175. package/core/src/physics/pulley.d.mts +98 -0
  176. package/core/src/physics/pulley.mjs +686 -0
  177. package/core/src/physics/ragdoll.d.mts +289 -0
  178. package/core/src/physics/ragdoll.mjs +1323 -0
  179. package/core/src/physics/rope.d.mts +241 -0
  180. package/core/src/physics/rope.mjs +319 -0
  181. package/core/src/physics/rounded-convex.d.mts +328 -0
  182. package/core/src/physics/rounded-convex.mjs +1404 -0
  183. package/core/src/physics/sdf-geometry.d.mts +117 -0
  184. package/core/src/physics/sdf-geometry.mjs +1204 -0
  185. package/core/src/physics/soft-body.d.mts +144 -0
  186. package/core/src/physics/soft-body.mjs +1285 -0
  187. package/core/src/physics/soft-collision.d.mts +651 -0
  188. package/core/src/physics/soft-collision.mjs +1883 -0
  189. package/core/src/physics/surface-velocity.d.mts +156 -0
  190. package/core/src/physics/surface-velocity.mjs +722 -0
  191. package/core/src/physics/tracks.d.mts +411 -0
  192. package/core/src/physics/tracks.mjs +1074 -0
  193. package/core/src/physics/vehicle.d.mts +3 -0
  194. package/core/src/physics/vehicle.mjs +172 -0
  195. package/core/src/physics/voxel-cooking.d.mts +219 -0
  196. package/core/src/physics/voxel-cooking.mjs +1499 -0
  197. package/core/src/physics/voxel-swept-quad.mjs +110 -0
  198. package/core/src/physics/wasm-instance.mjs +160 -23
  199. package/core/src/physics/world.d.mts +62 -0
  200. package/core/src/physics/world.mjs +1947 -152
  201. package/core/src/physics2d/body-state.mjs +218 -15
  202. package/core/src/physics2d/collision.d.mts +52 -0
  203. package/core/src/physics2d/collision.mjs +234 -0
  204. package/core/src/physics2d/compound.mjs +454 -0
  205. package/core/src/physics2d/contour-state.mjs +771 -0
  206. package/core/src/physics2d/feature-api.d.mts +211 -0
  207. package/core/src/physics2d/feature-api.mjs +3 -0
  208. package/core/src/physics2d/fluid-state.mjs +145 -0
  209. package/core/src/physics2d/joint-state.mjs +1 -1
  210. package/core/src/physics2d/owned-queries.mjs +3 -1
  211. package/core/src/physics2d/owned-transport.mjs +268 -122
  212. package/core/src/physics2d/owned-world.mjs +353 -230
  213. package/core/src/physics2d/particle-fluid.d.mts +152 -0
  214. package/core/src/physics2d/particle-fluid.mjs +233 -0
  215. package/core/src/physics2d/physics2d-wasm-module.generated.mjs +27 -10
  216. package/core/src/physics2d/query-codec.mjs +61 -13
  217. package/core/src/physics2d/submerged-geometry.d.mts +51 -0
  218. package/core/src/physics2d/submerged-geometry.mjs +186 -0
  219. package/core/src/runtime.mjs +23 -0
  220. package/core/src/shared/bytes.d.mts +2 -0
  221. package/core/src/shared/bytes.mjs +33 -0
  222. package/core/src/shared/sha256.d.mts +3 -0
  223. package/core/src/shared/sha256.mjs +72 -22
  224. package/core/units.d.ts +50 -0
  225. package/core/world.d.ts +253 -5
  226. package/dist/authority-room.d.ts +9 -0
  227. package/dist/authority-room.js +45 -16
  228. package/dist/browser.d.ts +6 -5
  229. package/dist/browser.js +4 -3
  230. package/dist/cadence.d.ts +7 -0
  231. package/dist/cadence.js +19 -0
  232. package/dist/canonical.d.ts +1 -0
  233. package/dist/canonical.js +3 -0
  234. package/dist/checksum-policy.d.ts +10 -0
  235. package/dist/checksum-policy.js +14 -0
  236. package/dist/collider-cooking-hull.d.ts +18 -0
  237. package/dist/collider-cooking-hull.js +248 -0
  238. package/dist/collider-cooking.d.ts +140 -0
  239. package/dist/collider-cooking.js +794 -0
  240. package/dist/compat/v5.d.ts +121 -0
  241. package/dist/compat/v5.js +479 -0
  242. package/dist/creator.d.ts +7 -6
  243. package/dist/creator.js +4 -3
  244. package/dist/game-byte-section.d.ts +36 -0
  245. package/dist/game-byte-section.js +350 -0
  246. package/dist/index.d.ts +13 -6
  247. package/dist/index.js +9 -4
  248. package/dist/instant-replay.d.ts +27 -2
  249. package/dist/instant-replay.js +91 -16
  250. package/dist/lag-compensation3d.js +11 -10
  251. package/dist/match-log.d.ts +21 -4
  252. package/dist/match-log.js +92 -9
  253. package/dist/math.d.ts +2 -0
  254. package/dist/math.js +1 -0
  255. package/dist/modules/character-3d.d.ts +16 -1
  256. package/dist/modules/character-3d.js +42 -5
  257. package/dist/modules/combat.js +6 -5
  258. package/dist/movement3d-revision1.d.ts +2 -0
  259. package/dist/movement3d-revision1.js +973 -0
  260. package/dist/movement3d.d.ts +53 -3
  261. package/dist/movement3d.js +917 -247
  262. package/dist/networked-client.d.ts +15 -0
  263. package/dist/networked-client.js +378 -105
  264. package/dist/node.d.ts +3 -2
  265. package/dist/node.js +2 -1
  266. package/dist/physics/2d.d.ts +38 -4
  267. package/dist/physics/2d.js +57 -36
  268. package/dist/physics/3d.d.ts +755 -111
  269. package/dist/physics/3d.js +2355 -158
  270. package/dist/physics/edit-result-graph.d.ts +36 -0
  271. package/dist/physics/edit-result-graph.js +141 -0
  272. package/dist/physics/game-codec3d.d.ts +41 -0
  273. package/dist/physics/game-codec3d.js +544 -0
  274. package/dist/physics/installed-checkpoint3d.d.ts +13 -0
  275. package/dist/physics/installed-checkpoint3d.js +120 -0
  276. package/dist/physics/installed-runtime3d.d.ts +51 -0
  277. package/dist/physics/installed-runtime3d.js +372 -0
  278. package/dist/physics/installed-state-commitment3d.d.ts +2 -0
  279. package/dist/physics/installed-state-commitment3d.js +24 -0
  280. package/dist/physics/units.d.ts +38 -0
  281. package/dist/physics/units.js +56 -0
  282. package/dist/physics/vehicle-state3d.d.ts +93 -0
  283. package/dist/physics/vehicle-state3d.js +1191 -0
  284. package/dist/physics/voxel-body-state.d.ts +61 -0
  285. package/dist/physics/voxel-body-state.js +410 -0
  286. package/dist/r3f-render-adapter.d.ts +59 -1
  287. package/dist/r3f-render-adapter.js +137 -2
  288. package/dist/replay.d.ts +13 -0
  289. package/dist/replay.js +95 -70
  290. package/dist/run-room-transport.js +5 -1
  291. package/dist/runner.d.ts +17 -2
  292. package/dist/runner.js +472 -84
  293. package/dist/runtime-cleanup.d.ts +54 -0
  294. package/dist/runtime-cleanup.js +266 -0
  295. package/dist/runtime-lease.d.ts +11 -1
  296. package/dist/runtime-lease.js +23 -10
  297. package/dist/runtime-room-metadata.d.ts +2 -8
  298. package/dist/runtime-room-metadata.js +11 -14
  299. package/dist/runtime-session.d.ts +8 -0
  300. package/dist/runtime-session.js +222 -58
  301. package/dist/schema-codegen.js +3 -0
  302. package/dist/schema-dsl-binary.d.ts +10 -4
  303. package/dist/schema-dsl-binary.js +375 -76
  304. package/dist/scratch-pool.d.ts +32 -0
  305. package/dist/scratch-pool.js +60 -0
  306. package/dist/sdk-session.d.ts +1 -0
  307. package/dist/sdk-session.js +4 -0
  308. package/dist/secret-config.js +2 -60
  309. package/dist/secret-crypto.js +70 -36
  310. package/dist/session-snapshot.d.ts +15 -4
  311. package/dist/session-snapshot.js +35 -33
  312. package/dist/session-wire.js +14 -22
  313. package/dist/sparse-set.d.ts +1 -0
  314. package/dist/sparse-set.js +22 -0
  315. package/dist/spatial/spatial-grid-3d.d.ts +41 -0
  316. package/dist/spatial/spatial-grid-3d.js +115 -0
  317. package/dist/synctest.d.ts +9 -0
  318. package/dist/synctest.js +106 -17
  319. package/dist/testing-network.d.ts +2 -0
  320. package/dist/testing-network.js +122 -18
  321. package/dist/testing.d.ts +27 -6
  322. package/dist/testing.js +297 -56
  323. package/dist/tools/index.d.ts +3 -2
  324. package/dist/tools/index.js +3 -2
  325. package/dist/tools/module-certification.d.ts +6 -0
  326. package/dist/tools/module-certification.js +26 -2
  327. package/package.json +18 -5
  328. package/core/scripts/run-box3d-benchmark.mjs +0 -350
  329. package/core/src/physics/index.mjs +0 -3169
@@ -0,0 +1,955 @@
1
+ /**
2
+ * 3D Gear and Rack-and-Pinion Constraints (J11 capability).
3
+ *
4
+ * Implements angular-to-angular gear coupling and angular-to-linear rack-and-pinion coupling.
5
+ * Features:
6
+ * - Deterministic double-precision calculations.
7
+ * - Sign and ratio conventions:
8
+ * - Positive ratio: opposing directions (standard external mesh: wB = -ratio * wA).
9
+ * - Negative ratio: same direction (internal ring gear / idler mesh: wB = |ratio| * wA).
10
+ * - Rack & pinion: linear displacement xB + ratio * thetaA = phase.
11
+ * - Rest phase offset calibration.
12
+ * - Limits: Free (bilateral), Locked (equal limits), or Limited (travel range [lower, upper]).
13
+ * - Soft constraint support (frequencyHz, dampingRatio, maxForce).
14
+ * - Joint break thresholds (breakForce, breakTorque).
15
+ * - Dynamic parameter edits (ratio, phase, limits) preserving warm state safely.
16
+ * - Closed kinematic loop & multi-gear train support via iterative Gauss-Seidel impulse solver.
17
+ */
18
+
19
+ export const GEAR_ABI_VERSION = 1;
20
+ export const GEAR_CONFIG_STRIDE = 26;
21
+ export const GEAR_STATE_STRIDE = 12;
22
+ export const GEAR_TELEMETRY_STRIDE = 8;
23
+
24
+ import {
25
+ ensureExtendedInstance,
26
+ extendedPhysicsReady,
27
+ } from './extended-wasm-instance.mjs';
28
+ import {
29
+ physicsExtendedWasmModuleBase64,
30
+ } from './physics-extended-wasm-module.generated.mjs';
31
+
32
+ let defaultExtendedInstance = null;
33
+
34
+ function decodeBase64(value) {
35
+ if (typeof atob === 'function') {
36
+ const decoded = atob(value);
37
+ const bytes = new Uint8Array(decoded.length);
38
+ for (let index = 0; index < decoded.length; index += 1) bytes[index] = decoded.charCodeAt(index);
39
+ return bytes;
40
+ }
41
+ if (typeof Buffer !== 'undefined') return Uint8Array.from(Buffer.from(value, 'base64'));
42
+ throw new Error('KINETIX_EXTENDED_PHYSICS_BASE64_UNAVAILABLE: Base64 decoding unavailable');
43
+ }
44
+
45
+ export function requireExtendedInstance() {
46
+ if (defaultExtendedInstance !== null) return defaultExtendedInstance;
47
+ try {
48
+ const bytes = decodeBase64(physicsExtendedWasmModuleBase64);
49
+ const mod = new WebAssembly.Module(bytes);
50
+ const inst = new WebAssembly.Instance(mod, {});
51
+ inst.exports._initialize?.();
52
+ defaultExtendedInstance = inst;
53
+ return defaultExtendedInstance;
54
+ } catch (error) {
55
+ const detail = error instanceof Error ? error.message : String(error);
56
+ throw new Error(
57
+ `KINETIX_EXTENDED_PHYSICS_NOT_INITIALIZED: Extended WASM physics instance is not initialized (${detail}). Await extendedPhysicsReady() or ensureExtendedInstance() before calling gear solver.`,
58
+ { cause: error }
59
+ );
60
+ }
61
+ }
62
+
63
+ export function setExtendedInstance(instance) {
64
+ defaultExtendedInstance = instance;
65
+ }
66
+
67
+ export async function initGearWasm() {
68
+ if (defaultExtendedInstance !== null) return defaultExtendedInstance;
69
+ await extendedPhysicsReady();
70
+ defaultExtendedInstance = await ensureExtendedInstance();
71
+ return defaultExtendedInstance;
72
+ }
73
+
74
+ export const wasmEntryPointsUsed = Object.freeze([
75
+ 'rundot_kinetix_ext_abi_version',
76
+ 'rundot_kinetix_ext_gear_config_stride',
77
+ 'rundot_kinetix_ext_gear_state_stride',
78
+ 'rundot_kinetix_ext_gear_telemetry_stride',
79
+ 'rundot_kinetix_ext_gear_stride',
80
+ 'rundot_kinetix_ext_gear_size',
81
+ 'rundot_kinetix_ext_gear_solve',
82
+ 'rundot_kinetix_ext_gear_step',
83
+ ]);
84
+
85
+ let scratchBase = 0;
86
+
87
+ function allocateScratchBuffer(instance, byteCount) {
88
+ if (typeof instance.exports.malloc === 'function') {
89
+ const ptr = instance.exports.malloc(byteCount);
90
+ if (!ptr) {
91
+ throw new Error('KINETIX_EXTENDED_PHYSICS_MALLOC_FAILED: Out of memory');
92
+ }
93
+ return {
94
+ ptr,
95
+ free() {
96
+ if (typeof instance.exports.free === 'function') {
97
+ instance.exports.free(ptr);
98
+ }
99
+ },
100
+ };
101
+ }
102
+
103
+ const memory = instance.exports.memory;
104
+ const alignedBytes = (byteCount + 15) & ~15;
105
+ if (!scratchBase) {
106
+ scratchBase = memory.buffer.byteLength;
107
+ }
108
+ const neededBytes = scratchBase + alignedBytes;
109
+ if (neededBytes > memory.buffer.byteLength) {
110
+ const pages = Math.ceil((neededBytes - memory.buffer.byteLength) / 65536);
111
+ memory.grow(pages);
112
+ }
113
+ return {
114
+ ptr: scratchBase,
115
+ free() {
116
+ // Reusable scratch space
117
+ },
118
+ };
119
+ }
120
+
121
+ export const GEAR_JOINT_TYPE_CODES = Object.freeze({
122
+ gear: 10,
123
+ rack: 11,
124
+ rackAndPinion: 11,
125
+ });
126
+
127
+ export const GearCouplingMode = Object.freeze({
128
+ AngularAngular: 0, // Gear: angular DOF of A to angular DOF of B
129
+ AngularLinear: 1, // Rack & Pinion: angular DOF of A (pinion) to linear DOF of B (rack)
130
+ LinearAngular: 2, // Rack & Pinion: linear DOF of A (rack) to angular DOF of B (pinion)
131
+ });
132
+
133
+ export const GearLimitMode = Object.freeze({
134
+ Free: 0,
135
+ Locked: 1,
136
+ Limited: 2,
137
+ });
138
+
139
+ export const GearStatus = Object.freeze({
140
+ Success: 0,
141
+ InvalidInput: -1,
142
+ InvalidBodies: -2,
143
+ InvalidRatio: -3,
144
+ Broken: -4,
145
+ });
146
+
147
+ const PI = 3.1415926535897932384626433832795;
148
+ const TWO_PI = 2.0 * PI;
149
+
150
+ export function wrapJointAngle(angle) {
151
+ let a = angle;
152
+ while (a > PI) a -= TWO_PI;
153
+ while (a < -PI) a += TWO_PI;
154
+ return a;
155
+ }
156
+
157
+ export function addVec3(a, b) {
158
+ return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
159
+ }
160
+
161
+ export function subVec3(a, b) {
162
+ return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
163
+ }
164
+
165
+ export function scaleVec3(v, s) {
166
+ return { x: v.x * s, y: v.y * s, z: v.z * s };
167
+ }
168
+
169
+ export function dotVec3(a, b) {
170
+ return a.x * b.x + a.y * b.y + a.z * b.z;
171
+ }
172
+
173
+ export function crossVec3(a, b) {
174
+ return {
175
+ x: a.y * b.z - a.z * b.y,
176
+ y: a.z * b.x - a.x * b.z,
177
+ z: a.x * b.y - a.y * b.x,
178
+ };
179
+ }
180
+
181
+ export function lengthSquaredVec3(v) {
182
+ return dotVec3(v, v);
183
+ }
184
+
185
+ export function lengthVec3(v) {
186
+ const sq = lengthSquaredVec3(v);
187
+ return sq > 0.0 ? Math.sqrt(sq) : 0.0;
188
+ }
189
+
190
+ export function normalizeVec3(v) {
191
+ const len = lengthVec3(v);
192
+ if (len <= 1e-15) return { x: 1.0, y: 0.0, z: 0.0 };
193
+ const inv = 1.0 / len;
194
+ return { x: v.x * inv, y: v.y * inv, z: v.z * inv };
195
+ }
196
+
197
+ export function rotateByQuat(q, v) {
198
+ const u = { x: q.x, y: q.y, z: q.z };
199
+ const uv = crossVec3(u, v);
200
+ const uuv = crossVec3(u, uv);
201
+ return addVec3(v, addVec3(scaleVec3(uv, 2.0 * q.w), scaleVec3(uuv, 2.0)));
202
+ }
203
+
204
+ export function multiplyQuat(a, b) {
205
+ return {
206
+ x: a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
207
+ y: a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,
208
+ z: a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
209
+ w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
210
+ };
211
+ }
212
+
213
+ export function conjugateQuat(q) {
214
+ return { x: -q.x, y: -q.y, z: -q.z, w: q.w };
215
+ }
216
+
217
+ export function normalizeQuat(q) {
218
+ const normSq = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
219
+ if (!(normSq > 1e-24)) return { x: 0.0, y: 0.0, z: 0.0, w: 1.0 };
220
+ const invNorm = 1.0 / Math.sqrt(normSq);
221
+ return { x: q.x * invNorm, y: q.y * invNorm, z: q.z * invNorm, w: q.w * invNorm };
222
+ }
223
+
224
+ export function constraintSoftness(error, dt, hertz = 0.0, dampingRatio = 1.0, maximumForceOrTorque = 0.0) {
225
+ const result = {
226
+ effectiveMass: 0.0,
227
+ bias: 0.0,
228
+ massScale: 1.0,
229
+ impulseScale: 0.0,
230
+ accumulatedImpulse: 0.0,
231
+ lower: -Number.POSITIVE_INFINITY,
232
+ upper: Number.POSITIVE_INFINITY,
233
+ };
234
+ if (hertz <= 0.0) {
235
+ result.bias = (0.2 * error) / dt;
236
+ } else {
237
+ const omega = TWO_PI * hertz;
238
+ const a1 = 2.0 * Math.max(0.0, dampingRatio) + dt * omega;
239
+ const a2 = dt * omega * a1;
240
+ result.bias = (omega / a1) * error;
241
+ result.massScale = a2 / (1.0 + a2);
242
+ result.impulseScale = 1.0 / (1.0 + a2);
243
+ }
244
+ if (maximumForceOrTorque > 0.0) {
245
+ result.lower = -maximumForceOrTorque * dt;
246
+ result.upper = maximumForceOrTorque * dt;
247
+ }
248
+ return result;
249
+ }
250
+
251
+ export function normalizeGearJoint(joint) {
252
+ if (!joint || typeof joint !== 'object') {
253
+ throw new Error('KINETIX_PHYSICS_JOINT_INVALID: expected joint record');
254
+ }
255
+ const id = typeof joint.id === 'string' && joint.id.length > 0 ? joint.id : 'gear_joint';
256
+ const type = String(joint.type ?? 'gear').toLowerCase();
257
+ if (GEAR_JOINT_TYPE_CODES[type] === undefined) {
258
+ throw new Error(`KINETIX_PHYSICS_JOINT_TYPE_UNSUPPORTED: joint type '${type}' not recognized by gear/rack solver`);
259
+ }
260
+
261
+ const bodyA = joint.bodyA !== undefined ? joint.bodyA : joint.a;
262
+ const bodyB = joint.bodyB !== undefined ? joint.bodyB : joint.b;
263
+ if (bodyA === undefined || bodyB === undefined) {
264
+ throw new Error('KINETIX_PHYSICS_JOINT_BODIES_INVALID: joint requires bodyA and bodyB');
265
+ }
266
+
267
+ const ratio = joint.ratio !== undefined ? joint.ratio : 1.0;
268
+ if (typeof ratio !== 'number' || !Number.isFinite(ratio) || ratio === 0.0) {
269
+ throw new Error('KINETIX_PHYSICS_GEAR_RATIO_INVALID: ratio must be a non-zero finite number');
270
+ }
271
+
272
+ const isRack = type === 'rack' || type === 'rackandpinion';
273
+ const mode = joint.mode !== undefined
274
+ ? joint.mode
275
+ : isRack
276
+ ? GearCouplingMode.AngularLinear
277
+ : GearCouplingMode.AngularAngular;
278
+
279
+ const phase = Number.isFinite(joint.phase) ? joint.phase : 0.0;
280
+ const axisA = normalizeVec3(joint.axisA ?? { x: 1.0, y: 0.0, z: 0.0 });
281
+ const axisB = normalizeVec3(joint.axisB ?? { x: 1.0, y: 0.0, z: 0.0 });
282
+ const anchorA = joint.anchorA ? { x: joint.anchorA.x ?? 0.0, y: joint.anchorA.y ?? 0.0, z: joint.anchorA.z ?? 0.0 } : { x: 0.0, y: 0.0, z: 0.0 };
283
+ const anchorB = joint.anchorB ? { x: joint.anchorB.x ?? 0.0, y: joint.anchorB.y ?? 0.0, z: joint.anchorB.z ?? 0.0 } : { x: 0.0, y: 0.0, z: 0.0 };
284
+
285
+ let limitMode = GearLimitMode.Free;
286
+ let lowerLimit = Number.isFinite(joint.lowerLimit) ? joint.lowerLimit : (joint.minAngle ?? (joint.minTranslation ?? 0.0));
287
+ let upperLimit = Number.isFinite(joint.upperLimit) ? joint.upperLimit : (joint.maxAngle ?? (joint.maxTranslation ?? 0.0));
288
+
289
+ if (joint.limitMode !== undefined) {
290
+ limitMode = joint.limitMode;
291
+ } else if (joint.enableLimit === true) {
292
+ limitMode = lowerLimit === upperLimit ? GearLimitMode.Locked : GearLimitMode.Limited;
293
+ }
294
+
295
+ const frequencyHz = Number.isFinite(joint.frequencyHz) ? joint.frequencyHz : (joint.hertz ?? 0.0);
296
+ const dampingRatio = Number.isFinite(joint.dampingRatio) ? joint.dampingRatio : 1.0;
297
+ const maxForce = Number.isFinite(joint.maxForce) ? joint.maxForce : (joint.maxTorque ?? 0.0);
298
+ const breakForce = Number.isFinite(joint.breakForce) ? joint.breakForce : 0.0;
299
+ const breakTorque = Number.isFinite(joint.breakTorque) ? joint.breakTorque : 0.0;
300
+ const enabled = joint.enabled !== false;
301
+
302
+ return {
303
+ id,
304
+ type,
305
+ bodyA,
306
+ bodyB,
307
+ mode,
308
+ ratio,
309
+ phase,
310
+ axisA,
311
+ axisB,
312
+ anchorA,
313
+ anchorB,
314
+ limitMode,
315
+ lowerLimit,
316
+ upperLimit,
317
+ frequencyHz,
318
+ dampingRatio,
319
+ maxForce,
320
+ breakForce,
321
+ breakTorque,
322
+ enabled,
323
+ referenceOrientationA: joint.referenceOrientationA ? normalizeQuat(joint.referenceOrientationA) : { x: 0, y: 0, z: 0, w: 1 },
324
+ referenceOrientationB: joint.referenceOrientationB ? normalizeQuat(joint.referenceOrientationB) : { x: 0, y: 0, z: 0, w: 1 },
325
+ referencePositionB: joint.referencePositionB ? { ...joint.referencePositionB } : { x: 0, y: 0, z: 0 },
326
+ };
327
+ }
328
+
329
+ export function createGearState() {
330
+ return {
331
+ unwrappedCoordinateA: 0.0,
332
+ previousWrappedAngleA: 0.0,
333
+ unwrappedCoordinateB: 0.0,
334
+ previousWrappedAngleB: 0.0,
335
+ coordinate: 0.0,
336
+ speed: 0.0,
337
+ accumulatedImpulse: 0.0,
338
+ reactionForce: 0.0,
339
+ reactionTorque: 0.0,
340
+ broken: false,
341
+ initialized: false,
342
+ };
343
+ }
344
+
345
+ export function createGearConstraint(options = {}) {
346
+ const config = normalizeGearJoint({ ...options, type: 'gear' });
347
+ const state = createGearState();
348
+ return { config, state };
349
+ }
350
+
351
+ export function createRackAndPinionConstraint(options = {}) {
352
+ const config = normalizeGearJoint({ ...options, type: 'rack' });
353
+ const state = createGearState();
354
+ return { config, state };
355
+ }
356
+
357
+ function computeBodyAngle(body, refOrientation, localAxis) {
358
+ const qCurrent = normalizeQuat({
359
+ x: body.orientationX ?? 0.0,
360
+ y: body.orientationY ?? 0.0,
361
+ z: body.orientationZ ?? 0.0,
362
+ w: body.orientationW ?? 1.0,
363
+ });
364
+ let qRel = multiplyQuat(conjugateQuat(refOrientation), qCurrent);
365
+ if (qRel.w < 0.0) {
366
+ qRel = { x: -qRel.x, y: -qRel.y, z: -qRel.z, w: -qRel.w };
367
+ }
368
+ const proj = dotVec3({ x: qRel.x, y: qRel.y, z: qRel.z }, localAxis);
369
+ return wrapJointAngle(2.0 * Math.atan2(proj, qRel.w));
370
+ }
371
+
372
+ export function evaluateGearKinematics(config, state, bodyA, bodyB) {
373
+ if (config.ratio === 0.0 || !Number.isFinite(config.ratio)) {
374
+ return GearStatus.InvalidRatio;
375
+ }
376
+ if (!config.enabled || state.broken) {
377
+ return state.broken ? GearStatus.Broken : GearStatus.Success;
378
+ }
379
+
380
+ const qA = normalizeQuat({ x: bodyA.orientationX ?? 0, y: bodyA.orientationY ?? 0, z: bodyA.orientationZ ?? 0, w: bodyA.orientationW ?? 1 });
381
+ const qB = normalizeQuat({ x: bodyB.orientationX ?? 0, y: bodyB.orientationY ?? 0, z: bodyB.orientationZ ?? 0, w: bodyB.orientationW ?? 1 });
382
+ const uA = rotateByQuat(qA, normalizeVec3(config.axisA));
383
+ const uB = rotateByQuat(qB, normalizeVec3(config.axisB));
384
+
385
+ let coordA = 0.0;
386
+ let speedA = 0.0;
387
+ let coordB = 0.0;
388
+ let speedB = 0.0;
389
+
390
+ if (config.mode === GearCouplingMode.AngularAngular) {
391
+ const rawAngleA = computeBodyAngle(bodyA, config.referenceOrientationA, normalizeVec3(config.axisA));
392
+ const rawAngleB = computeBodyAngle(bodyB, config.referenceOrientationB, normalizeVec3(config.axisB));
393
+
394
+ if (!state.initialized) {
395
+ state.previousWrappedAngleA = rawAngleA;
396
+ state.unwrappedCoordinateA = rawAngleA;
397
+ state.previousWrappedAngleB = rawAngleB;
398
+ state.unwrappedCoordinateB = rawAngleB;
399
+ state.initialized = true;
400
+ } else {
401
+ const deltaA = wrapJointAngle(rawAngleA - state.previousWrappedAngleA);
402
+ state.unwrappedCoordinateA += deltaA;
403
+ state.previousWrappedAngleA = rawAngleA;
404
+
405
+ const deltaB = wrapJointAngle(rawAngleB - state.previousWrappedAngleB);
406
+ state.unwrappedCoordinateB += deltaB;
407
+ state.previousWrappedAngleB = rawAngleB;
408
+ }
409
+ coordA = state.unwrappedCoordinateA;
410
+ coordB = state.unwrappedCoordinateB;
411
+ speedA = dotVec3({ x: bodyA.angularVelX ?? 0, y: bodyA.angularVelY ?? 0, z: bodyA.angularVelZ ?? 0 }, uA);
412
+ speedB = dotVec3({ x: bodyB.angularVelX ?? 0, y: bodyB.angularVelY ?? 0, z: bodyB.angularVelZ ?? 0 }, uB);
413
+ } else if (config.mode === GearCouplingMode.AngularLinear) {
414
+ const rawAngleA = computeBodyAngle(bodyA, config.referenceOrientationA, normalizeVec3(config.axisA));
415
+ if (!state.initialized) {
416
+ state.previousWrappedAngleA = rawAngleA;
417
+ state.unwrappedCoordinateA = rawAngleA;
418
+ state.previousWrappedAngleB = 0.0;
419
+ state.unwrappedCoordinateB = 0.0;
420
+ state.initialized = true;
421
+ } else {
422
+ const deltaA = wrapJointAngle(rawAngleA - state.previousWrappedAngleA);
423
+ state.unwrappedCoordinateA += deltaA;
424
+ state.previousWrappedAngleA = rawAngleA;
425
+ }
426
+ coordA = state.unwrappedCoordinateA;
427
+ speedA = dotVec3({ x: bodyA.angularVelX ?? 0, y: bodyA.angularVelY ?? 0, z: bodyA.angularVelZ ?? 0 }, uA);
428
+
429
+ const posB = { x: bodyB.x ?? 0, y: bodyB.y ?? 0, z: bodyB.z ?? 0 };
430
+ const wB = addVec3(posB, rotateByQuat(qB, config.anchorB));
431
+ const comB = addVec3(posB, rotateByQuat(qB, { x: bodyB.centerOfMassX ?? 0, y: bodyB.centerOfMassY ?? 0, z: bodyB.centerOfMassZ ?? 0 }));
432
+ const rB = subVec3(wB, comB);
433
+ const vB_lin = { x: bodyB.vx ?? 0, y: bodyB.vy ?? 0, z: bodyB.vz ?? 0 };
434
+ const wB_ang = { x: bodyB.angularVelX ?? 0, y: bodyB.angularVelY ?? 0, z: bodyB.angularVelZ ?? 0 };
435
+ const vAnchorB = addVec3(vB_lin, crossVec3(wB_ang, rB));
436
+
437
+ coordB = dotVec3(subVec3(wB, config.referencePositionB), uB);
438
+ state.unwrappedCoordinateB = coordB;
439
+ speedB = dotVec3(vAnchorB, uB);
440
+ } else if (config.mode === GearCouplingMode.LinearAngular) {
441
+ const rawAngleB = computeBodyAngle(bodyB, config.referenceOrientationB, normalizeVec3(config.axisB));
442
+ if (!state.initialized) {
443
+ state.previousWrappedAngleA = 0.0;
444
+ state.unwrappedCoordinateA = 0.0;
445
+ state.previousWrappedAngleB = rawAngleB;
446
+ state.unwrappedCoordinateB = rawAngleB;
447
+ state.initialized = true;
448
+ } else {
449
+ const deltaB = wrapJointAngle(rawAngleB - state.previousWrappedAngleB);
450
+ state.unwrappedCoordinateB += deltaB;
451
+ state.previousWrappedAngleB = rawAngleB;
452
+ }
453
+ coordB = state.unwrappedCoordinateB;
454
+ speedB = dotVec3({ x: bodyB.angularVelX ?? 0, y: bodyB.angularVelY ?? 0, z: bodyB.angularVelZ ?? 0 }, uB);
455
+
456
+ const posA = { x: bodyA.x ?? 0, y: bodyA.y ?? 0, z: bodyA.z ?? 0 };
457
+ const wA = addVec3(posA, rotateByQuat(qA, config.anchorA));
458
+ const comA = addVec3(posA, rotateByQuat(qA, { x: bodyA.centerOfMassX ?? 0, y: bodyA.centerOfMassY ?? 0, z: bodyA.centerOfMassZ ?? 0 }));
459
+ const rA = subVec3(wA, comA);
460
+ const vA_lin = { x: bodyA.vx ?? 0, y: bodyA.vy ?? 0, z: bodyA.vz ?? 0 };
461
+ const wA_ang = { x: bodyA.angularVelX ?? 0, y: bodyA.angularVelY ?? 0, z: bodyA.angularVelZ ?? 0 };
462
+ const vAnchorA = addVec3(vA_lin, crossVec3(wA_ang, rA));
463
+
464
+ coordA = dotVec3(subVec3(wA, config.referencePositionB), uA);
465
+ state.unwrappedCoordinateA = coordA;
466
+ speedA = dotVec3(vAnchorA, uA);
467
+ }
468
+
469
+ state.coordinate = coordB + config.ratio * coordA;
470
+ state.speed = speedB + config.ratio * speedA;
471
+
472
+ return GearStatus.Success;
473
+ }
474
+
475
+ export function buildGearConstraintRows(config, state, bodyA, bodyB, dt) {
476
+ if (dt <= 0.0) return [];
477
+ const status = evaluateGearKinematics(config, state, bodyA, bodyB);
478
+ if (status !== GearStatus.Success) return [];
479
+
480
+ const ratioScale = Math.max(1.0, Math.abs(config.ratio));
481
+ const coeffA = config.ratio / ratioScale;
482
+ const coeffB = 1.0 / ratioScale;
483
+
484
+ const qA = normalizeQuat({ x: bodyA.orientationX ?? 0, y: bodyA.orientationY ?? 0, z: bodyA.orientationZ ?? 0, w: bodyA.orientationW ?? 1 });
485
+ const qB = normalizeQuat({ x: bodyB.orientationX ?? 0, y: bodyB.orientationY ?? 0, z: bodyB.orientationZ ?? 0, w: bodyB.orientationW ?? 1 });
486
+ const uA = rotateByQuat(qA, normalizeVec3(config.axisA));
487
+ const uB = rotateByQuat(qB, normalizeVec3(config.axisB));
488
+
489
+ let jacobianA = [0, 0, 0, 0, 0, 0];
490
+ let jacobianB = [0, 0, 0, 0, 0, 0];
491
+
492
+ if (config.mode === GearCouplingMode.AngularAngular) {
493
+ jacobianA = [0.0, 0.0, 0.0, coeffA * uA.x, coeffA * uA.y, coeffA * uA.z];
494
+ jacobianB = [0.0, 0.0, 0.0, coeffB * uB.x, coeffB * uB.y, coeffB * uB.z];
495
+ } else if (config.mode === GearCouplingMode.AngularLinear) {
496
+ const posB = { x: bodyB.x ?? 0, y: bodyB.y ?? 0, z: bodyB.z ?? 0 };
497
+ const wB = addVec3(posB, rotateByQuat(qB, config.anchorB));
498
+ const comB = addVec3(posB, rotateByQuat(qB, { x: bodyB.centerOfMassX ?? 0, y: bodyB.centerOfMassY ?? 0, z: bodyB.centerOfMassZ ?? 0 }));
499
+ const rB = subVec3(wB, comB);
500
+ const tauB = crossVec3(rB, uB);
501
+
502
+ jacobianA = [0.0, 0.0, 0.0, coeffA * uA.x, coeffA * uA.y, coeffA * uA.z];
503
+ jacobianB = [coeffB * uB.x, coeffB * uB.y, coeffB * uB.z, coeffB * tauB.x, coeffB * tauB.y, coeffB * tauB.z];
504
+ } else if (config.mode === GearCouplingMode.LinearAngular) {
505
+ const posA = { x: bodyA.x ?? 0, y: bodyA.y ?? 0, z: bodyA.z ?? 0 };
506
+ const wA = addVec3(posA, rotateByQuat(qA, config.anchorA));
507
+ const comA = addVec3(posA, rotateByQuat(qA, { x: bodyA.centerOfMassX ?? 0, y: bodyA.centerOfMassY ?? 0, z: bodyA.centerOfMassZ ?? 0 }));
508
+ const rA = subVec3(wA, comA);
509
+ const tauA = crossVec3(rA, uA);
510
+
511
+ jacobianA = [coeffA * uA.x, coeffA * uA.y, coeffA * uA.z, coeffA * tauA.x, coeffA * tauA.y, coeffA * tauA.z];
512
+ jacobianB = [0.0, 0.0, 0.0, coeffB * uB.x, coeffB * uB.y, coeffB * uB.z];
513
+ }
514
+
515
+ const C = state.coordinate;
516
+ let scalar = null;
517
+
518
+ if (config.limitMode === GearLimitMode.Free) {
519
+ const error = (C - config.phase) / ratioScale;
520
+ scalar = constraintSoftness(error, dt, config.frequencyHz, config.dampingRatio, config.maxForce);
521
+ } else if (config.limitMode === GearLimitMode.Locked) {
522
+ const error = (C - config.phase) / ratioScale;
523
+ scalar = constraintSoftness(error, dt, config.frequencyHz, config.dampingRatio, config.maxForce);
524
+ } else if (config.limitMode === GearLimitMode.Limited) {
525
+ if (config.lowerLimit === config.upperLimit) {
526
+ const error = (C - config.lowerLimit) / ratioScale;
527
+ scalar = constraintSoftness(error, dt, config.frequencyHz, config.dampingRatio, config.maxForce);
528
+ } else if (C < config.lowerLimit) {
529
+ const error = (C - config.lowerLimit) / ratioScale;
530
+ scalar = constraintSoftness(error, dt, config.frequencyHz, config.dampingRatio, config.maxForce);
531
+ scalar.lower = 0.0;
532
+ scalar.upper = config.maxForce > 0.0 ? config.maxForce * dt : Number.POSITIVE_INFINITY;
533
+ } else if (C > config.upperLimit) {
534
+ const error = (C - config.upperLimit) / ratioScale;
535
+ scalar = constraintSoftness(error, dt, config.frequencyHz, config.dampingRatio, config.maxForce);
536
+ scalar.lower = config.maxForce > 0.0 ? -config.maxForce * dt : -Number.POSITIVE_INFINITY;
537
+ scalar.upper = 0.0;
538
+ } else {
539
+ state.accumulatedImpulse = 0.0;
540
+ return [];
541
+ }
542
+ }
543
+
544
+ scalar.accumulatedImpulse = state.accumulatedImpulse;
545
+
546
+ return [{
547
+ bodyA: config.bodyA,
548
+ bodyB: config.bodyB,
549
+ jacobianA,
550
+ jacobianB,
551
+ angularResponseA: [0, 0, 0],
552
+ angularResponseB: [0, 0, 0],
553
+ scalar,
554
+ }];
555
+ }
556
+
557
+ export function defaultMobility(body) {
558
+ const dynamic = (body.dynamic !== false) && !body.sleeping;
559
+ const invMass = dynamic && (body.mass ?? 1.0) > 0.0 ? 1.0 / body.mass : 0.0;
560
+ const invIxx = dynamic && (body.inertiaXX ?? 1.0) > 0.0 ? 1.0 / body.inertiaXX : 0.0;
561
+ const invIyy = dynamic && (body.inertiaYY ?? 1.0) > 0.0 ? 1.0 / body.inertiaYY : 0.0;
562
+ const invIzz = dynamic && (body.inertiaZZ ?? 1.0) > 0.0 ? 1.0 / body.inertiaZZ : 0.0;
563
+ return {
564
+ inverseLinear: [invMass, invMass, invMass],
565
+ inverseAngular: [invIxx, 0.0, 0.0, invIyy, 0.0, invIzz],
566
+ };
567
+ }
568
+
569
+ export function prepareGearConstraintRow(row, mobilityA, mobilityB) {
570
+ const mult = (invAng, ang) => [
571
+ invAng[0] * ang[0] + invAng[1] * ang[1] + invAng[2] * ang[2],
572
+ invAng[1] * ang[0] + invAng[3] * ang[1] + invAng[4] * ang[2],
573
+ invAng[2] * ang[0] + invAng[4] * ang[1] + invAng[5] * ang[2],
574
+ ];
575
+ const angA = [row.jacobianA[3], row.jacobianA[4], row.jacobianA[5]];
576
+ const angB = [row.jacobianB[3], row.jacobianB[4], row.jacobianB[5]];
577
+ row.angularResponseA = mult(mobilityA.inverseAngular, angA);
578
+ row.angularResponseB = mult(mobilityB.inverseAngular, angB);
579
+
580
+ let invMass = 0.0;
581
+ for (let i = 0; i < 3; ++i) {
582
+ invMass += row.jacobianA[i] * row.jacobianA[i] * mobilityA.inverseLinear[i]
583
+ + row.jacobianB[i] * row.jacobianB[i] * mobilityB.inverseLinear[i];
584
+ }
585
+ invMass += angA[0] * row.angularResponseA[0] + angA[1] * row.angularResponseA[1] + angA[2] * row.angularResponseA[2]
586
+ + angB[0] * row.angularResponseB[0] + angB[1] * row.angularResponseB[1] + angB[2] * row.angularResponseB[2];
587
+
588
+ row.scalar.effectiveMass = invMass > 0.0 ? 1.0 / invMass : 0.0;
589
+ return true;
590
+ }
591
+
592
+ export function applyGearConstraintImpulse(row, bodyA, bodyB, mobilityA, mobilityB, impulse) {
593
+ if (impulse === 0.0) return;
594
+ bodyA.vx = (bodyA.vx ?? 0.0) + row.jacobianA[0] * mobilityA.inverseLinear[0] * impulse;
595
+ bodyA.vy = (bodyA.vy ?? 0.0) + row.jacobianA[1] * mobilityA.inverseLinear[1] * impulse;
596
+ bodyA.vz = (bodyA.vz ?? 0.0) + row.jacobianA[2] * mobilityA.inverseLinear[2] * impulse;
597
+ bodyA.angularVelX = (bodyA.angularVelX ?? 0.0) + row.angularResponseA[0] * impulse;
598
+ bodyA.angularVelY = (bodyA.angularVelY ?? 0.0) + row.angularResponseA[1] * impulse;
599
+ bodyA.angularVelZ = (bodyA.angularVelZ ?? 0.0) + row.angularResponseA[2] * impulse;
600
+
601
+ bodyB.vx = (bodyB.vx ?? 0.0) + row.jacobianB[0] * mobilityB.inverseLinear[0] * impulse;
602
+ bodyB.vy = (bodyB.vy ?? 0.0) + row.jacobianB[1] * mobilityB.inverseLinear[1] * impulse;
603
+ bodyB.vz = (bodyB.vz ?? 0.0) + row.jacobianB[2] * mobilityB.inverseLinear[2] * impulse;
604
+ bodyB.angularVelX = (bodyB.angularVelX ?? 0.0) + row.angularResponseB[0] * impulse;
605
+ bodyB.angularVelY = (bodyB.angularVelY ?? 0.0) + row.angularResponseB[1] * impulse;
606
+ bodyB.angularVelZ = (bodyB.angularVelZ ?? 0.0) + row.angularResponseB[2] * impulse;
607
+ }
608
+
609
+ export function solveGearConstraintRow(row, bodyA, bodyB, mobilityA, mobilityB) {
610
+ const velA = (bodyA.vx ?? 0) * row.jacobianA[0] + (bodyA.vy ?? 0) * row.jacobianA[1] + (bodyA.vz ?? 0) * row.jacobianA[2]
611
+ + (bodyA.angularVelX ?? 0) * row.jacobianA[3] + (bodyA.angularVelY ?? 0) * row.jacobianA[4] + (bodyA.angularVelZ ?? 0) * row.jacobianA[5];
612
+ const velB = (bodyB.vx ?? 0) * row.jacobianB[0] + (bodyB.vy ?? 0) * row.jacobianB[1] + (bodyB.vz ?? 0) * row.jacobianB[2]
613
+ + (bodyB.angularVelX ?? 0) * row.jacobianB[3] + (bodyB.angularVelY ?? 0) * row.jacobianB[4] + (bodyB.angularVelZ ?? 0) * row.jacobianB[5];
614
+
615
+ const scalar = row.scalar;
616
+ const previous = scalar.accumulatedImpulse;
617
+ const delta = -scalar.massScale * scalar.effectiveMass * (velA + velB + scalar.bias)
618
+ - scalar.impulseScale * previous;
619
+
620
+ let clamped = previous + delta;
621
+ if (clamped < scalar.lower) clamped = scalar.lower;
622
+ if (clamped > scalar.upper) clamped = scalar.upper;
623
+ scalar.accumulatedImpulse = clamped;
624
+
625
+ const applied = clamped - previous;
626
+ applyGearConstraintImpulse(row, bodyA, bodyB, mobilityA, mobilityB, applied);
627
+ return applied;
628
+ }
629
+
630
+ export function solveGearConstraints(configs, states, bodies, mobilities, dt, iterations = 4, options = {}) {
631
+ if (typeof mobilities === 'number') {
632
+ options = dt && typeof dt === 'object' ? dt : {};
633
+ iterations = typeof dt === 'number' ? dt : 4;
634
+ dt = mobilities;
635
+ mobilities = null;
636
+ }
637
+
638
+ if (!configs || configs.length === 0 || dt <= 0.0 || iterations <= 0) return 0;
639
+ if (!bodies || bodies.length === 0) return 0;
640
+
641
+ const instance = requireExtendedInstance();
642
+ const exports = instance.exports;
643
+
644
+ const configStride = exports.rundot_kinetix_ext_gear_config_stride();
645
+ const stateStride = exports.rundot_kinetix_ext_gear_state_stride();
646
+ const bodyStride = 44;
647
+
648
+ // Additional ABI stride and size queries
649
+ const telemetryStride = exports.rundot_kinetix_ext_gear_telemetry_stride?.() ?? GEAR_TELEMETRY_STRIDE;
650
+ const gearStride = exports.rundot_kinetix_ext_gear_stride?.() ?? GEAR_CONFIG_STRIDE;
651
+ const gearSize = exports.rundot_kinetix_ext_gear_size?.() ?? GEAR_CONFIG_STRIDE;
652
+
653
+ const configCount = configs.length;
654
+ const bodyCount = bodies instanceof Float64Array ? (bodies.length / bodyStride) : bodies.length;
655
+
656
+ const configDoubles = configCount * configStride;
657
+ const stateDoubles = configCount * stateStride;
658
+ const bodyDoubles = bodyCount * bodyStride;
659
+ const totalDoubles = configDoubles + stateDoubles + bodyDoubles;
660
+ const totalBytes = totalDoubles * 8;
661
+
662
+ const scratch = allocateScratchBuffer(instance, totalBytes);
663
+ try {
664
+ const memory = exports.memory;
665
+ const configPtr = scratch.ptr;
666
+ const statePtr = configPtr + configDoubles * 8;
667
+ const bodyPtr = statePtr + stateDoubles * 8;
668
+
669
+ const configView = new Float64Array(memory.buffer, configPtr, configDoubles);
670
+ const stateView = new Float64Array(memory.buffer, statePtr, stateDoubles);
671
+ const bodyView = new Float64Array(memory.buffer, bodyPtr, bodyDoubles);
672
+
673
+ // Marshal configs
674
+ for (let i = 0; i < configCount; ++i) {
675
+ const c = configs[i];
676
+ const offset = i * configStride;
677
+ configView[offset + 0] = c.bodyA ?? 0;
678
+ configView[offset + 1] = c.bodyB ?? 0;
679
+ configView[offset + 2] = c.mode ?? GearCouplingMode.AngularAngular;
680
+ configView[offset + 3] = c.ratio ?? 1.0;
681
+ configView[offset + 4] = c.phase ?? 0.0;
682
+ configView[offset + 5] = c.axisA?.x ?? 1.0;
683
+ configView[offset + 6] = c.axisA?.y ?? 0.0;
684
+ configView[offset + 7] = c.axisA?.z ?? 0.0;
685
+ configView[offset + 8] = c.axisB?.x ?? 1.0;
686
+ configView[offset + 9] = c.axisB?.y ?? 0.0;
687
+ configView[offset + 10] = c.axisB?.z ?? 0.0;
688
+ configView[offset + 11] = c.anchorA?.x ?? 0.0;
689
+ configView[offset + 12] = c.anchorA?.y ?? 0.0;
690
+ configView[offset + 13] = c.anchorA?.z ?? 0.0;
691
+ configView[offset + 14] = c.anchorB?.x ?? 0.0;
692
+ configView[offset + 15] = c.anchorB?.y ?? 0.0;
693
+ configView[offset + 16] = c.anchorB?.z ?? 0.0;
694
+ configView[offset + 17] = c.limitMode ?? GearLimitMode.Free;
695
+ configView[offset + 18] = c.lowerLimit ?? 0.0;
696
+ configView[offset + 19] = c.upperLimit ?? 0.0;
697
+ configView[offset + 20] = c.frequencyHz ?? 0.0;
698
+ configView[offset + 21] = c.dampingRatio ?? 1.0;
699
+ configView[offset + 22] = c.maxForce ?? 0.0;
700
+ configView[offset + 23] = c.breakForce ?? 0.0;
701
+ configView[offset + 24] = c.breakTorque ?? 0.0;
702
+ configView[offset + 25] = (c.enabled !== false) ? 1.0 : 0.0;
703
+ }
704
+
705
+ // Marshal states
706
+ for (let i = 0; i < configCount; ++i) {
707
+ const s = states[i];
708
+ const offset = i * stateStride;
709
+ if (s) {
710
+ stateView[offset + 0] = s.unwrappedCoordinateA ?? 0.0;
711
+ stateView[offset + 1] = s.previousWrappedAngleA ?? 0.0;
712
+ stateView[offset + 2] = s.unwrappedCoordinateB ?? 0.0;
713
+ stateView[offset + 3] = s.previousWrappedAngleB ?? 0.0;
714
+ stateView[offset + 4] = s.coordinate ?? 0.0;
715
+ stateView[offset + 5] = s.speed ?? 0.0;
716
+ stateView[offset + 6] = s.accumulatedImpulse ?? 0.0;
717
+ stateView[offset + 7] = s.reactionForce ?? 0.0;
718
+ stateView[offset + 8] = s.reactionTorque ?? 0.0;
719
+ stateView[offset + 9] = s.broken ? 1.0 : 0.0;
720
+ stateView[offset + 10] = s.initialized ? 1.0 : 0.0;
721
+ stateView[offset + 11] = 0.0;
722
+ }
723
+ }
724
+
725
+ // Marshal bodies
726
+ if (bodies instanceof Float64Array) {
727
+ bodyView.set(bodies.subarray(0, bodyDoubles));
728
+ } else {
729
+ for (let b = 0; b < bodyCount; ++b) {
730
+ const body = bodies[b];
731
+ const offset = b * bodyStride;
732
+ if (body instanceof Float64Array) {
733
+ bodyView.set(body.subarray(0, bodyStride), offset);
734
+ continue;
735
+ }
736
+
737
+ bodyView[offset + 0] = body.x ?? 0.0;
738
+ bodyView[offset + 1] = body.y ?? 0.0;
739
+ bodyView[offset + 2] = body.z ?? 0.0;
740
+ bodyView[offset + 3] = body.vx ?? 0.0;
741
+ bodyView[offset + 4] = body.vy ?? 0.0;
742
+ bodyView[offset + 5] = body.vz ?? 0.0;
743
+
744
+ const dynamic = (body.dynamic !== false) && body.kind !== 'static';
745
+ const kinematic = body.kinematic === true || body.kind === 'kinematic';
746
+ const kind = dynamic ? 1 : (kinematic ? 2 : 0);
747
+ const sleeping = (dynamic && body.sleeping) ? 0b10000 : 0;
748
+ const motionType = kind | sleeping | 0b100000;
749
+ bodyView[offset + 9] = motionType;
750
+
751
+ bodyView[offset + 10] = 0.0;
752
+ bodyView[offset + 13] = body.gravityScale ?? 1.0;
753
+ bodyView[offset + 14] = body.linearDamping ?? 0.0;
754
+
755
+ const angVelX = body.angularVelX ?? body.angularVel?.x ?? 0.0;
756
+ const angVelY = body.angularVelY ?? body.angularVel?.y ?? 0.0;
757
+ const angVelZ = body.angularVelZ ?? body.angularVel?.z ?? 0.0;
758
+ bodyView[offset + 15] = angVelX;
759
+ bodyView[offset + 16] = angVelY;
760
+ bodyView[offset + 17] = angVelZ;
761
+ bodyView[offset + 18] = (body.mass ?? 1.0) > 0.0 ? body.mass : 1.0;
762
+ bodyView[offset + 19] = angVelX;
763
+ bodyView[offset + 20] = angVelY;
764
+ bodyView[offset + 21] = angVelZ;
765
+
766
+ const qx = body.orientationX ?? body.orientation?.x ?? 0.0;
767
+ const qy = body.orientationY ?? body.orientation?.y ?? 0.0;
768
+ const qz = body.orientationZ ?? body.orientation?.z ?? 0.0;
769
+ const qw = body.orientationW ?? body.orientation?.w ?? 1.0;
770
+ bodyView[offset + 22] = qx;
771
+ bodyView[offset + 23] = qy;
772
+ bodyView[offset + 24] = qz;
773
+ bodyView[offset + 25] = qw;
774
+
775
+ bodyView[offset + 26] = body.angularDamping ?? 0.0;
776
+ bodyView[offset + 27] = body.friction ?? 0.0;
777
+ bodyView[offset + 28] = body.restitution ?? 0.0;
778
+ bodyView[offset + 29] = 0.0;
779
+ bodyView[offset + 30] = 0.0;
780
+
781
+ const ixx = body.inertiaXX ?? body.inertia?.xx ?? 1.0;
782
+ const iyy = body.inertiaYY ?? body.inertia?.yy ?? 1.0;
783
+ const izz = body.inertiaZZ ?? body.inertia?.zz ?? 1.0;
784
+ bodyView[offset + 31] = ixx > 0.0 ? ixx : 1.0;
785
+ bodyView[offset + 32] = iyy > 0.0 ? iyy : 1.0;
786
+ bodyView[offset + 33] = izz > 0.0 ? izz : 1.0;
787
+ bodyView[offset + 34] = body.inertiaXY ?? body.inertia?.xy ?? 0.0;
788
+ bodyView[offset + 35] = body.inertiaXZ ?? body.inertia?.xz ?? 0.0;
789
+ bodyView[offset + 36] = body.inertiaYZ ?? body.inertia?.yz ?? 0.0;
790
+ bodyView[offset + 37] = body.centerOfMassX ?? body.centerOfMass?.x ?? 0.0;
791
+ bodyView[offset + 38] = body.centerOfMassY ?? body.centerOfMass?.y ?? 0.0;
792
+ bodyView[offset + 39] = body.centerOfMassZ ?? body.centerOfMass?.z ?? 0.0;
793
+ }
794
+ }
795
+
796
+ // Call WASM solver entry point (or step entry point if specified)
797
+ const solverFn = (options?.useStep || options?.useStepEntryPoint)
798
+ ? exports.rundot_kinetix_ext_gear_step
799
+ : exports.rundot_kinetix_ext_gear_solve;
800
+
801
+ const status = solverFn(configPtr, configCount, statePtr, bodyPtr, bodyCount, dt, iterations);
802
+ if (status < 0) {
803
+ return status;
804
+ }
805
+
806
+ // Read back states
807
+ for (let i = 0; i < configCount; ++i) {
808
+ const s = states[i];
809
+ if (!s) continue;
810
+ const offset = i * stateStride;
811
+ s.unwrappedCoordinateA = stateView[offset + 0];
812
+ s.previousWrappedAngleA = stateView[offset + 1];
813
+ s.unwrappedCoordinateB = stateView[offset + 2];
814
+ s.previousWrappedAngleB = stateView[offset + 3];
815
+ s.coordinate = stateView[offset + 4];
816
+ s.speed = stateView[offset + 5];
817
+ s.accumulatedImpulse = stateView[offset + 6];
818
+ s.reactionForce = stateView[offset + 7];
819
+ s.reactionTorque = stateView[offset + 8];
820
+ s.broken = stateView[offset + 9] !== 0.0;
821
+ s.initialized = stateView[offset + 10] !== 0.0;
822
+ }
823
+
824
+ // Read back bodies
825
+ if (bodies instanceof Float64Array) {
826
+ bodies.set(bodyView.subarray(0, bodyDoubles));
827
+ } else {
828
+ for (let b = 0; b < bodyCount; ++b) {
829
+ const body = bodies[b];
830
+ const offset = b * bodyStride;
831
+ if (body instanceof Float64Array) {
832
+ body.set(bodyView.subarray(offset, offset + bodyStride));
833
+ continue;
834
+ }
835
+ body.vx = bodyView[offset + 3];
836
+ body.vy = bodyView[offset + 4];
837
+ body.vz = bodyView[offset + 5];
838
+ body.angularVelX = bodyView[offset + 19];
839
+ body.angularVelY = bodyView[offset + 20];
840
+ body.angularVelZ = bodyView[offset + 21];
841
+ if (body.angularVel && typeof body.angularVel === 'object') {
842
+ body.angularVel.x = bodyView[offset + 19];
843
+ body.angularVel.y = bodyView[offset + 20];
844
+ body.angularVel.z = bodyView[offset + 21];
845
+ }
846
+ }
847
+ }
848
+
849
+ let activeCount = 0;
850
+ for (let i = 0; i < configCount; ++i) {
851
+ if (configs[i].enabled !== false && !states[i]?.broken) {
852
+ activeCount++;
853
+ }
854
+ }
855
+ return activeCount;
856
+ } finally {
857
+ scratch.free();
858
+ }
859
+ }
860
+
861
+ export function editGearRatio(config, state, newRatio) {
862
+ if (typeof newRatio === 'number' && Number.isFinite(newRatio) && newRatio !== 0.0) {
863
+ config.ratio = newRatio;
864
+ state.accumulatedImpulse = 0.0;
865
+ }
866
+ }
867
+
868
+ export function editGearPhase(config, newPhase) {
869
+ if (typeof newPhase === 'number' && Number.isFinite(newPhase)) {
870
+ config.phase = newPhase;
871
+ }
872
+ }
873
+
874
+ export function editGearLimits(config, limitMode, lower, upper) {
875
+ config.limitMode = limitMode;
876
+ config.lowerLimit = lower;
877
+ config.upperLimit = upper;
878
+ }
879
+
880
+ export function resetGearWarmState(state) {
881
+ state.accumulatedImpulse = 0.0;
882
+ state.reactionForce = 0.0;
883
+ state.reactionTorque = 0.0;
884
+ state.initialized = false;
885
+ state.broken = false;
886
+ }
887
+
888
+ export function createGearSimulation(options = {}) {
889
+ const bodies = [];
890
+ const configs = [];
891
+ const states = [];
892
+ const bodyMap = new Map();
893
+
894
+ const addBody = (def) => {
895
+ const id = def.id ?? `body_${bodies.length}`;
896
+ const idx = bodies.length;
897
+ const body = {
898
+ id,
899
+ x: def.x ?? 0.0,
900
+ y: def.y ?? 0.0,
901
+ z: def.z ?? 0.0,
902
+ vx: def.vx ?? 0.0,
903
+ vy: def.vy ?? 0.0,
904
+ vz: def.vz ?? 0.0,
905
+ orientationX: def.orientationX ?? 0.0,
906
+ orientationY: def.orientationY ?? 0.0,
907
+ orientationZ: def.orientationZ ?? 0.0,
908
+ orientationW: def.orientationW ?? 1.0,
909
+ angularVelX: def.angularVelX ?? 0.0,
910
+ angularVelY: def.angularVelY ?? 0.0,
911
+ angularVelZ: def.angularVelZ ?? 0.0,
912
+ mass: def.mass ?? 1.0,
913
+ dynamic: def.dynamic !== false,
914
+ inertiaXX: def.inertiaXX ?? 1.0,
915
+ inertiaYY: def.inertiaYY ?? 1.0,
916
+ inertiaZZ: def.inertiaZZ ?? 1.0,
917
+ centerOfMassX: def.centerOfMassX ?? 0.0,
918
+ centerOfMassY: def.centerOfMassY ?? 0.0,
919
+ centerOfMassZ: def.centerOfMassZ ?? 0.0,
920
+ };
921
+ bodies.push(body);
922
+ bodyMap.set(id, idx);
923
+ return idx;
924
+ };
925
+
926
+ const addJoint = (jointDef) => {
927
+ const aIdx = typeof jointDef.bodyA === 'number' ? jointDef.bodyA : bodyMap.get(jointDef.bodyA ?? jointDef.a);
928
+ const bIdx = typeof jointDef.bodyB === 'number' ? jointDef.bodyB : bodyMap.get(jointDef.bodyB ?? jointDef.b);
929
+ const normalized = normalizeGearJoint({ ...jointDef, bodyA: aIdx, bodyB: bIdx });
930
+ const state = createGearState();
931
+ configs.push(normalized);
932
+ states.push(state);
933
+ return configs.length - 1;
934
+ };
935
+
936
+ if (Array.isArray(options.bodies)) {
937
+ for (const b of options.bodies) addBody(b);
938
+ }
939
+ if (Array.isArray(options.joints)) {
940
+ for (const j of options.joints) addJoint(j);
941
+ }
942
+
943
+ return {
944
+ bodies,
945
+ configs,
946
+ states,
947
+ addBody,
948
+ addJoint,
949
+ };
950
+ }
951
+
952
+ export function stepGearSimulation(sim, dt, iterations = 4) {
953
+ const mobilities = sim.bodies.map(defaultMobility);
954
+ return solveGearConstraints(sim.configs, sim.states, sim.bodies, mobilities, dt, iterations, { useStep: true });
955
+ }