@woosh/meep-engine 2.147.0 → 2.149.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.
- package/package.json +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_bridge_islands.d.ts +23 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_bridge_islands.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_bridge_islands.js +295 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts +4 -4
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts.map +1 -1
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.js +48 -52
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts +23 -21
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts.map +1 -1
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.js +41 -406
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts +5 -4
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts.map +1 -1
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.js +400 -395
- package/src/engine/navigation/mesh/NavigationMesh.d.ts +6 -2
- package/src/engine/navigation/mesh/NavigationMesh.d.ts.map +1 -1
- package/src/engine/navigation/mesh/NavigationMesh.js +234 -212
- package/src/engine/navigation/mesh/bt_mesh_face_find_path.d.ts +7 -3
- package/src/engine/navigation/mesh/bt_mesh_face_find_path.d.ts.map +1 -1
- package/src/engine/navigation/mesh/bt_mesh_face_find_path.js +67 -73
- package/src/engine/navigation/mesh/build/enforce_agent_height_clearance.d.ts +16 -5
- package/src/engine/navigation/mesh/build/enforce_agent_height_clearance.d.ts.map +1 -1
- package/src/engine/navigation/mesh/build/enforce_agent_height_clearance.js +262 -147
- package/src/engine/navigation/mesh/build/navmesh_build_topology.d.ts.map +1 -1
- package/src/engine/navigation/mesh/build/navmesh_build_topology.js +33 -3
- package/src/engine/navigation/mesh/bvh_query_nearest_face.d.ts +4 -1
- package/src/engine/navigation/mesh/bvh_query_nearest_face.d.ts.map +1 -1
- package/src/engine/navigation/mesh/bvh_query_nearest_face.js +164 -131
- package/src/engine/physics/body/SolverBodyState.d.ts +142 -0
- package/src/engine/physics/body/SolverBodyState.d.ts.map +1 -0
- package/src/engine/physics/body/SolverBodyState.js +251 -0
- package/src/engine/physics/broadphase/generate_pairs.d.ts +2 -1
- package/src/engine/physics/broadphase/generate_pairs.d.ts.map +1 -1
- package/src/engine/physics/broadphase/generate_pairs.js +110 -108
- package/src/engine/physics/constraint/solve_constraints.d.ts.map +1 -1
- package/src/engine/physics/constraint/solve_constraints.js +691 -673
- package/src/engine/physics/ecs/PhysicsSystem.d.ts +21 -18
- package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
- package/src/engine/physics/ecs/PhysicsSystem.js +223 -91
- package/src/engine/physics/inertia/world_inverse_inertia.d.ts +23 -0
- package/src/engine/physics/inertia/world_inverse_inertia.d.ts.map +1 -1
- package/src/engine/physics/inertia/world_inverse_inertia.js +116 -77
- package/src/engine/physics/integration/integrate_position.d.ts +11 -1
- package/src/engine/physics/integration/integrate_position.d.ts.map +1 -1
- package/src/engine/physics/integration/integrate_position.js +97 -79
- package/src/engine/physics/integration/integrate_velocity.d.ts +12 -3
- package/src/engine/physics/integration/integrate_velocity.d.ts.map +1 -1
- package/src/engine/physics/integration/integrate_velocity.js +201 -160
- package/src/engine/physics/narrowphase/box_box_manifold.d.ts.map +1 -1
- package/src/engine/physics/narrowphase/box_box_manifold.js +750 -665
- package/src/engine/physics/narrowphase/box_triangle_contact.d.ts.map +1 -1
- package/src/engine/physics/narrowphase/box_triangle_contact.js +4 -34
- package/src/engine/physics/narrowphase/clip_against_axis_uv.d.ts +16 -0
- package/src/engine/physics/narrowphase/clip_against_axis_uv.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/clip_against_axis_uv.js +49 -0
- package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -1
- package/src/engine/physics/narrowphase/narrowphase_step.js +24 -3
- package/src/engine/physics/queries/raycast.d.ts.map +1 -1
- package/src/engine/physics/queries/raycast.js +201 -198
- package/src/engine/physics/solver/solve_contacts.d.ts +2 -2
- package/src/engine/physics/solver/solve_contacts.d.ts.map +1 -1
- package/src/engine/physics/solver/solve_contacts.js +1341 -1173
|
@@ -1,1173 +1,1341 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
*
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
let
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*/
|
|
198
|
-
let
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*/
|
|
208
|
-
let
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
const
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
)
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* @param {
|
|
390
|
-
* @param {number}
|
|
391
|
-
* @param {number}
|
|
392
|
-
* @param {
|
|
393
|
-
* @
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
* @param {
|
|
445
|
-
* @param {
|
|
446
|
-
* @param {number}
|
|
447
|
-
* @
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
*
|
|
676
|
-
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
*
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
*
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
*
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
const
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
const
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
const
|
|
820
|
-
|
|
821
|
-
const
|
|
822
|
-
const
|
|
823
|
-
|
|
824
|
-
const
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
const
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
const
|
|
837
|
-
const
|
|
838
|
-
|
|
839
|
-
const
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
const
|
|
1103
|
-
const
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1106
|
-
const
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
const
|
|
1111
|
-
const
|
|
1112
|
-
const
|
|
1113
|
-
|
|
1114
|
-
const
|
|
1115
|
-
const
|
|
1116
|
-
|
|
1117
|
-
const
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
const
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
const
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
*
|
|
1158
|
-
*
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1
|
+
import { v3_quat3_apply } from "../../../core/geom/vec3/v3_quat3_apply.js";
|
|
2
|
+
import { v3_quat3_apply_inverse } from "../../../core/geom/vec3/v3_quat3_apply_inverse.js";
|
|
3
|
+
import { body_id_index } from "../body/BodyStorage.js";
|
|
4
|
+
import {
|
|
5
|
+
SBS_AV_X,
|
|
6
|
+
SBS_AV_Y,
|
|
7
|
+
SBS_AV_Z,
|
|
8
|
+
SBS_INV_I_X,
|
|
9
|
+
SBS_INV_I_Y,
|
|
10
|
+
SBS_INV_I_Z,
|
|
11
|
+
SBS_INV_MASS,
|
|
12
|
+
SBS_LV_X,
|
|
13
|
+
SBS_LV_Y,
|
|
14
|
+
SBS_LV_Z,
|
|
15
|
+
SBS_QW,
|
|
16
|
+
SBS_QX,
|
|
17
|
+
SBS_QY,
|
|
18
|
+
SBS_QZ,
|
|
19
|
+
SBS_STRIDE,
|
|
20
|
+
} from "../body/SolverBodyState.js";
|
|
21
|
+
import { CONTACT_STRIDE } from "../contact/ManifoldStore.js";
|
|
22
|
+
import { ColliderFlags } from "../ecs/ColliderFlags.js";
|
|
23
|
+
import { RigidBodyFlags } from "../ecs/RigidBodyFlags.js";
|
|
24
|
+
import { world_inverse_inertia_apply_raw } from "../inertia/world_inverse_inertia.js";
|
|
25
|
+
import { redetect_pair_geometry } from "../narrowphase/narrowphase_step.js";
|
|
26
|
+
import { friction_cone_clamp } from "./friction_cone.js";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* # TGS split-impulse contact solver (staged)
|
|
30
|
+
*
|
|
31
|
+
* Temporal Gauss-Seidel with Catto-2018 split impulse. The solver runs as a
|
|
32
|
+
* sequence of stages driven by `PhysicsSystem.fixedUpdate`, which owns the
|
|
33
|
+
* substep loop (it has to — velocity/position integration spans every awake
|
|
34
|
+
* body, not just contacts):
|
|
35
|
+
*
|
|
36
|
+
* prepare_contacts(manifolds, system, h) // once per outer step
|
|
37
|
+
* for each substep:
|
|
38
|
+
* (system integrates gravity by h)
|
|
39
|
+
* redetect_concave_contacts(manifolds, system) // concave: fresh narrowphase
|
|
40
|
+
* refresh_contacts(manifolds, system) // convex: analytic re-derive
|
|
41
|
+
* warm_start_contacts(manifolds, system) // replay impulse — per substep!
|
|
42
|
+
* solve_velocity(manifolds, system, iters) // non-penetration + friction
|
|
43
|
+
* solve_position(manifolds, system, pos_iters)
|
|
44
|
+
* (system integrates position by h, folding pseudo-velocity)
|
|
45
|
+
* apply_restitution(manifolds, system) // once, after the loop
|
|
46
|
+
*
|
|
47
|
+
* The three concerns are fully decoupled (Phases 1–2) and substepping
|
|
48
|
+
* (Phase 3) re-runs only the velocity + position solve per substep —
|
|
49
|
+
* narrowphase runs once per outer step. Each substep re-derives the
|
|
50
|
+
* current penetration analytically from the bodies' moved poses and the
|
|
51
|
+
* contact anchors captured at prepare time, so the position correction
|
|
52
|
+
* adapts as the stack settles (the mechanism behind TGS stack stability)
|
|
53
|
+
* without paying for narrowphase N times.
|
|
54
|
+
*
|
|
55
|
+
* Why staged module functions sharing module scratch, rather than one call:
|
|
56
|
+
* the substep loop interleaves solver stages with whole-body integration
|
|
57
|
+
* that lives in the system. The stages communicate through module-scoped
|
|
58
|
+
* scratch + `g_*` state set by `prepare_contacts`; they must be called in
|
|
59
|
+
* order, prepare first, within a single outer step. Single-threaded and
|
|
60
|
+
* deterministic, so the shared state is safe.
|
|
61
|
+
*
|
|
62
|
+
* Contacts from all islands are flattened into one scratch array. Islands
|
|
63
|
+
* are independent (they share no bodies), so a single flat Gauss-Seidel
|
|
64
|
+
* sweep gives the same result as per-island sweeps — the island partition
|
|
65
|
+
* is still built and used by the sleep test, just not needed here.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A pair is "sensor-only" when either body OR either body's primary
|
|
70
|
+
* collider carries the IsSensor flag. The manifold still exists (so
|
|
71
|
+
* Begin/Stay/End events fire from the manifold-diff pass) but no impulse
|
|
72
|
+
* is applied.
|
|
73
|
+
*
|
|
74
|
+
* @param {RigidBody} rbA
|
|
75
|
+
* @param {Collider} colA
|
|
76
|
+
* @param {RigidBody} rbB
|
|
77
|
+
* @param {Collider} colB
|
|
78
|
+
* @returns {boolean}
|
|
79
|
+
*/
|
|
80
|
+
function pair_is_sensor(rbA, colA, rbB, colB) {
|
|
81
|
+
const collider_flags_union = colA.flags | colB.flags;
|
|
82
|
+
const body_flags_union = rbA.flags | rbB.flags;
|
|
83
|
+
|
|
84
|
+
return (body_flags_union & RigidBodyFlags.IsSensor) !== 0
|
|
85
|
+
|| (collider_flags_union & ColliderFlags.IsSensor) !== 0
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Velocity-iteration count per substep. With substepping the per-substep
|
|
90
|
+
* count can be lower than a single-step PGS solver would need, because the
|
|
91
|
+
* outer loop revisits the contact set `substeps` times.
|
|
92
|
+
* @type {number}
|
|
93
|
+
*/
|
|
94
|
+
const DEFAULT_VELOCITY_ITERATIONS = 10;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Position-iteration count per substep (split-impulse pseudo-velocity pass).
|
|
98
|
+
* @type {number}
|
|
99
|
+
*/
|
|
100
|
+
const DEFAULT_POSITION_ITERATIONS = 2;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Penetration allowed without applying position correction. Eliminates
|
|
104
|
+
* micro-jitter at near-zero overlap.
|
|
105
|
+
* @type {number}
|
|
106
|
+
*/
|
|
107
|
+
const PENETRATION_SLOP = 0.005;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* SPOOK contact stiffness `k`. Effectively infinite for rigid-body
|
|
111
|
+
* contact: what the solver actually sees is the regularization
|
|
112
|
+
* `eps = 4 / (h² · k · (1 + 4d))`, negligible at `k = 1e12` but in place
|
|
113
|
+
* as a continuous compliance dial for future soft contacts. Lacoursière
|
|
114
|
+
* 2007; same formulation as cannon-es / AgX.
|
|
115
|
+
* @type {number}
|
|
116
|
+
*/
|
|
117
|
+
const CONTACT_STIFFNESS = 1e12;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* SPOOK contact relaxation `d`. Chosen so `a = 4 / (h(1 + 4d)) = 0.2 / h`,
|
|
121
|
+
* numerically matching the prior Baumgarte β = 0.2 gain. `4/(1+4d)=0.2` →
|
|
122
|
+
* `d = 4.75`. Note `h` here is the SUBSTEP size: position correction is
|
|
123
|
+
* applied per substep, so the gain is derived from the substep `dt`.
|
|
124
|
+
* @type {number}
|
|
125
|
+
*/
|
|
126
|
+
const CONTACT_RELAXATION = 4.75;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Maximum magnitude of the position-correction velocity bias, in m/s.
|
|
130
|
+
* Belt-and-braces against inflated EPA depths (PLAN.md caveat) driving the
|
|
131
|
+
* bias to tens of m/s. Removed once closed-form triangle solvers land.
|
|
132
|
+
* @type {number}
|
|
133
|
+
*/
|
|
134
|
+
const MAX_POSITION_BIAS = 3;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Velocity below which restitution is suppressed (no micro-bounce buzz on
|
|
138
|
+
* resting stacks).
|
|
139
|
+
* @type {number}
|
|
140
|
+
*/
|
|
141
|
+
const RESTITUTION_VELOCITY_THRESHOLD = 1.0;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Per-contact pre-step scratch stride: 23 doubles.
|
|
145
|
+
* 0..2 : localWA (A's contact witness, in A's LOCAL frame — constant)
|
|
146
|
+
* 3..5 : localWB (B's contact witness, in B's LOCAL frame — constant)
|
|
147
|
+
* 6..8 : rA (lever from A's COM to the contact midpoint — refreshed)
|
|
148
|
+
* 9..11: rB (lever from B's COM to the contact midpoint — refreshed)
|
|
149
|
+
* 12..14: t1 (tangent 1, unit, world — constant)
|
|
150
|
+
* 15..17: t2 (tangent 2, unit, world — constant)
|
|
151
|
+
* 18 : m_eff_n
|
|
152
|
+
* 19 : m_eff_t1
|
|
153
|
+
* 20 : m_eff_t2
|
|
154
|
+
* 21 : rest_bias (restitution: `e · vn_approach`, ≤ 0; 0 if not bouncing)
|
|
155
|
+
* 22 : bias_position (depth-correction bias — refreshed each substep)
|
|
156
|
+
*
|
|
157
|
+
* `localWA` / `localWB` are the per-body contact witnesses expressed in body
|
|
158
|
+
* local frames at prepare time. Each substep, `refresh_contacts` rotates
|
|
159
|
+
* them back to world by the body's current pose to recover the moved contact
|
|
160
|
+
* points, re-derives the current penetration depth (anchored on the trusted
|
|
161
|
+
* prepare-time depth via a delta, so it's sign-robust), and rebuilds the
|
|
162
|
+
* impulse lever arms `rA` / `rB` and the position bias.
|
|
163
|
+
* @type {number}
|
|
164
|
+
*/
|
|
165
|
+
const PRE_STRIDE = 23;
|
|
166
|
+
|
|
167
|
+
/** Per-contact index list — 4 uint32 per contact: slot, idx, idxA, idxB. */
|
|
168
|
+
const INDEX_STRIDE = 4;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Per-body pseudo-velocity stride: 3 linear + 3 angular doubles. Owned by
|
|
172
|
+
* PhysicsSystem (`system.__pseudo_velocity`); zeroed each substep before
|
|
173
|
+
* the position pass and folded into the pose by `integrate_position`.
|
|
174
|
+
* @type {number}
|
|
175
|
+
*/
|
|
176
|
+
const PSEUDO_STRIDE = 6;
|
|
177
|
+
|
|
178
|
+
let scratch_pre = new Float64Array(64 * PRE_STRIDE);
|
|
179
|
+
let scratch_idx = new Uint32Array(64 * INDEX_STRIDE);
|
|
180
|
+
let scratch_mu = new Float64Array(64);
|
|
181
|
+
let scratch_pos_jn = new Float64Array(64);
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Per-contact maximum normal impulse seen across the whole outer step's
|
|
185
|
+
* velocity solving (all substeps, all iterations). Reset in
|
|
186
|
+
* {@link prepare_contacts}, updated in {@link solve_velocity}, read by
|
|
187
|
+
* {@link apply_restitution}.
|
|
188
|
+
*
|
|
189
|
+
* Restitution must fire whenever a contact *was* compressive at some point
|
|
190
|
+
* in the step, even if its accumulated impulse later relaxes back to ~0 — a
|
|
191
|
+
* transient collision (ball bouncing, head-on hit) under per-substep
|
|
192
|
+
* warm-start ends the loop with `j_n ≈ 0` because there's no sustained load
|
|
193
|
+
* to hold the impulse up. Gating on this running max (Box2D-v3
|
|
194
|
+
* `maxNormalImpulse`) rather than the end-of-loop `j_n` is what makes
|
|
195
|
+
* bounces fire.
|
|
196
|
+
* @type {Float64Array}
|
|
197
|
+
*/
|
|
198
|
+
let scratch_max_jn = new Float64Array(64);
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Per-contact flag: 1 if the contact's pair involves a concave body, else 0.
|
|
202
|
+
* Concave contacts take the per-substep re-detection path
|
|
203
|
+
* ({@link redetect_concave_contacts}) — their feature genuinely changes as
|
|
204
|
+
* the body rocks, so the analytic refresh that freezes it would pump energy.
|
|
205
|
+
* Convex contacts (flag 0) take the cheap analytic {@link refresh_contacts}.
|
|
206
|
+
* @type {Uint8Array}
|
|
207
|
+
*/
|
|
208
|
+
let scratch_concave = new Uint8Array(64);
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Distinct concave-involved manifold slots touched this step, with the body
|
|
212
|
+
* indices needed to fetch their collider lists for re-detection. Parallel
|
|
213
|
+
* arrays, `g_concave_slot_count` valid entries, filled by
|
|
214
|
+
* {@link prepare_contacts}.
|
|
215
|
+
*/
|
|
216
|
+
let concave_slot = new Uint32Array(32);
|
|
217
|
+
let concave_slot_idxA = new Uint32Array(32);
|
|
218
|
+
let concave_slot_idxB = new Uint32Array(32);
|
|
219
|
+
let g_concave_slot_count = 0;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Shared cross-stage state, set by {@link prepare_contacts} and read by the
|
|
223
|
+
* per-substep stages within the same outer step. Single-threaded, so plain
|
|
224
|
+
* module variables are safe.
|
|
225
|
+
*/
|
|
226
|
+
let g_contact_count = 0;
|
|
227
|
+
let g_spook_a = 0;
|
|
228
|
+
let g_spook_eps = 0;
|
|
229
|
+
|
|
230
|
+
/** Scratch for re-deriving contact world points in {@link refresh_contacts}. */
|
|
231
|
+
const scratch_cp = new Float64Array(6);
|
|
232
|
+
|
|
233
|
+
function ensure_capacity(n) {
|
|
234
|
+
if (scratch_pre.length < n * PRE_STRIDE) {
|
|
235
|
+
scratch_pre = new Float64Array(n * PRE_STRIDE * 2);
|
|
236
|
+
}
|
|
237
|
+
if (scratch_idx.length < n * INDEX_STRIDE) {
|
|
238
|
+
scratch_idx = new Uint32Array(n * INDEX_STRIDE * 2);
|
|
239
|
+
}
|
|
240
|
+
if (scratch_mu.length < n) {
|
|
241
|
+
scratch_mu = new Float64Array(n * 2);
|
|
242
|
+
}
|
|
243
|
+
if (scratch_pos_jn.length < n) {
|
|
244
|
+
scratch_pos_jn = new Float64Array(n * 2);
|
|
245
|
+
}
|
|
246
|
+
if (scratch_max_jn.length < n) {
|
|
247
|
+
scratch_max_jn = new Float64Array(n * 2);
|
|
248
|
+
}
|
|
249
|
+
if (scratch_concave.length < n) {
|
|
250
|
+
scratch_concave = new Uint8Array(n * 2);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function ensure_concave_slot_capacity(n) {
|
|
255
|
+
if (concave_slot.length < n) {
|
|
256
|
+
concave_slot = new Uint32Array(n * 2);
|
|
257
|
+
concave_slot_idxA = new Uint32Array(n * 2);
|
|
258
|
+
concave_slot_idxB = new Uint32Array(n * 2);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Build an orthonormal tangent basis perpendicular to a unit normal.
|
|
264
|
+
*
|
|
265
|
+
* @param {Float64Array} out 6 floats: t1.xyz then t2.xyz
|
|
266
|
+
* @param {number} off
|
|
267
|
+
* @param {number} nx
|
|
268
|
+
* @param {number} ny
|
|
269
|
+
* @param {number} nz
|
|
270
|
+
*/
|
|
271
|
+
function build_tangents(out, off, nx, ny, nz) {
|
|
272
|
+
const ax = nx < 0 ? -nx : nx;
|
|
273
|
+
const ay = ny < 0 ? -ny : ny;
|
|
274
|
+
const az = nz < 0 ? -nz : nz;
|
|
275
|
+
|
|
276
|
+
let rx, ry, rz;
|
|
277
|
+
|
|
278
|
+
if (ax <= ay && ax <= az) {
|
|
279
|
+
rx = 1;
|
|
280
|
+
ry = 0;
|
|
281
|
+
rz = 0;
|
|
282
|
+
} else if (ay <= az) {
|
|
283
|
+
rx = 0;
|
|
284
|
+
ry = 1;
|
|
285
|
+
rz = 0;
|
|
286
|
+
} else {
|
|
287
|
+
rx = 0;
|
|
288
|
+
ry = 0;
|
|
289
|
+
rz = 1;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
let t1x = ny * rz - nz * ry;
|
|
293
|
+
let t1y = nz * rx - nx * rz;
|
|
294
|
+
let t1z = nx * ry - ny * rx;
|
|
295
|
+
|
|
296
|
+
const inv = 1 / Math.sqrt(t1x * t1x + t1y * t1y + t1z * t1z);
|
|
297
|
+
|
|
298
|
+
t1x *= inv;
|
|
299
|
+
t1y *= inv;
|
|
300
|
+
t1z *= inv;
|
|
301
|
+
|
|
302
|
+
const t2x = ny * t1z - nz * t1y;
|
|
303
|
+
const t2y = nz * t1x - nx * t1z;
|
|
304
|
+
const t2z = nx * t1y - ny * t1x;
|
|
305
|
+
|
|
306
|
+
out[off] = t1x;
|
|
307
|
+
out[off + 1] = t1y;
|
|
308
|
+
out[off + 2] = t1z;
|
|
309
|
+
|
|
310
|
+
out[off + 3] = t2x;
|
|
311
|
+
out[off + 4] = t2y;
|
|
312
|
+
out[off + 5] = t2z;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Friction / restitution are no longer combined here: the narrowphase combines
|
|
316
|
+
// the specific source-collider pair's coefficients per contact (so compound
|
|
317
|
+
// bodies with mixed-material colliders are honoured) and stores the result in
|
|
318
|
+
// the manifold (CONTACT_STRIDE offsets 14 / 15). prepare_contacts reads them
|
|
319
|
+
// per contact. See engine/physics/contact/combine_material.js.
|
|
320
|
+
|
|
321
|
+
const scratch_clamp = new Float64Array(2);
|
|
322
|
+
const scratch_inertia_a = new Float64Array(3);
|
|
323
|
+
const scratch_inertia_b = new Float64Array(3);
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Apply an impulse `P` at body-relative offset `r` to persistent velocity
|
|
327
|
+
* (Δv = P/m, Δω = I⁻¹·(r × P)), reading and writing the body's
|
|
328
|
+
* {@link SolverBodyState} span instead of its `RigidBody` / `Transform`
|
|
329
|
+
* objects — flat typed-array access, no dereference, on the hot path.
|
|
330
|
+
*
|
|
331
|
+
* @param {Float64Array} ss solver-body-state data array
|
|
332
|
+
* @param {number} base `body_index * SBS_STRIDE`
|
|
333
|
+
* @param {number} invM
|
|
334
|
+
* @param {number} rx
|
|
335
|
+
* @param {number} ry
|
|
336
|
+
* @param {number} rz
|
|
337
|
+
* @param {number} Px
|
|
338
|
+
* @param {number} Py
|
|
339
|
+
* @param {number} Pz
|
|
340
|
+
* @param {number} sign +1 for body A, -1 for body B
|
|
341
|
+
* @param {Float64Array} scratch_inertia
|
|
342
|
+
*/
|
|
343
|
+
function apply_impulse_to_body(
|
|
344
|
+
ss, base, invM,
|
|
345
|
+
rx, ry, rz,
|
|
346
|
+
Px, Py, Pz,
|
|
347
|
+
sign,
|
|
348
|
+
scratch_inertia
|
|
349
|
+
) {
|
|
350
|
+
|
|
351
|
+
if (invM === 0) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const sPx = sign * Px;
|
|
356
|
+
const sPy = sign * Py;
|
|
357
|
+
const sPz = sign * Pz;
|
|
358
|
+
|
|
359
|
+
ss[base + SBS_LV_X] += sPx * invM;
|
|
360
|
+
ss[base + SBS_LV_Y] += sPy * invM;
|
|
361
|
+
ss[base + SBS_LV_Z] += sPz * invM;
|
|
362
|
+
|
|
363
|
+
const tx = ry * sPz - rz * sPy;
|
|
364
|
+
const ty = rz * sPx - rx * sPz;
|
|
365
|
+
const tz = rx * sPy - ry * sPx;
|
|
366
|
+
|
|
367
|
+
world_inverse_inertia_apply_raw(
|
|
368
|
+
scratch_inertia, 0,
|
|
369
|
+
ss[base + SBS_INV_I_X], ss[base + SBS_INV_I_Y], ss[base + SBS_INV_I_Z],
|
|
370
|
+
ss[base + SBS_QX], ss[base + SBS_QY], ss[base + SBS_QZ], ss[base + SBS_QW],
|
|
371
|
+
tx, ty, tz
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
ss[base + SBS_AV_X] += scratch_inertia[0];
|
|
375
|
+
ss[base + SBS_AV_Y] += scratch_inertia[1];
|
|
376
|
+
ss[base + SBS_AV_Z] += scratch_inertia[2];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Apply a position-pass impulse `P` at body-relative offset `r` to the
|
|
381
|
+
* body's pseudo-velocity (linear + angular) in the `pseudo_velocity` flat
|
|
382
|
+
* buffer. Mirrors {@link apply_impulse_to_body} but the result is consumed
|
|
383
|
+
* by `integrate_position` the same substep and never persists. Inverse
|
|
384
|
+
* inertia / orientation are read from the body's {@link SolverBodyState} span.
|
|
385
|
+
*
|
|
386
|
+
* @param {Float64Array} pseudo_velocity stride = {@link PSEUDO_STRIDE}
|
|
387
|
+
* @param {number} pbase offset = `body_index * PSEUDO_STRIDE`
|
|
388
|
+
* @param {Float64Array} ss solver-body-state data array
|
|
389
|
+
* @param {number} sbase `body_index * SBS_STRIDE`
|
|
390
|
+
* @param {number} invM
|
|
391
|
+
* @param {number} rx
|
|
392
|
+
* @param {number} ry
|
|
393
|
+
* @param {number} rz
|
|
394
|
+
* @param {number} Px
|
|
395
|
+
* @param {number} Py
|
|
396
|
+
* @param {number} Pz
|
|
397
|
+
* @param {number} sign +1 for body A, -1 for body B
|
|
398
|
+
* @param {Float64Array} scratch_inertia
|
|
399
|
+
*/
|
|
400
|
+
function apply_impulse_to_pseudo(
|
|
401
|
+
pseudo_velocity, pbase,
|
|
402
|
+
ss, sbase, invM,
|
|
403
|
+
rx, ry, rz,
|
|
404
|
+
Px, Py, Pz,
|
|
405
|
+
sign,
|
|
406
|
+
scratch_inertia
|
|
407
|
+
) {
|
|
408
|
+
if (invM === 0) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const sPx = sign * Px;
|
|
413
|
+
const sPy = sign * Py;
|
|
414
|
+
const sPz = sign * Pz;
|
|
415
|
+
|
|
416
|
+
pseudo_velocity[pbase] += sPx * invM;
|
|
417
|
+
pseudo_velocity[pbase + 1] += sPy * invM;
|
|
418
|
+
pseudo_velocity[pbase + 2] += sPz * invM;
|
|
419
|
+
|
|
420
|
+
const tx = ry * sPz - rz * sPy;
|
|
421
|
+
const ty = rz * sPx - rx * sPz;
|
|
422
|
+
const tz = rx * sPy - ry * sPx;
|
|
423
|
+
|
|
424
|
+
world_inverse_inertia_apply_raw(
|
|
425
|
+
scratch_inertia, 0,
|
|
426
|
+
ss[sbase + SBS_INV_I_X], ss[sbase + SBS_INV_I_Y], ss[sbase + SBS_INV_I_Z],
|
|
427
|
+
ss[sbase + SBS_QX], ss[sbase + SBS_QY], ss[sbase + SBS_QZ], ss[sbase + SBS_QW],
|
|
428
|
+
tx, ty, tz
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
pseudo_velocity[pbase + 3] += scratch_inertia[0];
|
|
432
|
+
pseudo_velocity[pbase + 4] += scratch_inertia[1];
|
|
433
|
+
pseudo_velocity[pbase + 5] += scratch_inertia[2];
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Quadratic-form contribution of one body to the constraint effective mass
|
|
438
|
+
* along a unit axis: `(r × axis)^T · I⁻¹_world · (r × axis)`. Reads the body's
|
|
439
|
+
* inverse-inertia diagonal + orientation from its {@link SolverBodyState} span.
|
|
440
|
+
* Non-dynamic bodies carry a zero inverse-inertia diagonal there, so the
|
|
441
|
+
* zero-guard returns 0 for them — matching the object path's `kind` guard.
|
|
442
|
+
*
|
|
443
|
+
* @param {Float64Array} ss solver-body-state data array
|
|
444
|
+
* @param {number} base `body_index * SBS_STRIDE`
|
|
445
|
+
* @param {number} rx
|
|
446
|
+
* @param {number} ry
|
|
447
|
+
* @param {number} rz
|
|
448
|
+
* @param {number} ax
|
|
449
|
+
* @param {number} ay
|
|
450
|
+
* @param {number} az
|
|
451
|
+
* @param {Float64Array} scratch_inertia
|
|
452
|
+
* @returns {number}
|
|
453
|
+
*/
|
|
454
|
+
function angular_jacobian_contribution(
|
|
455
|
+
ss, base,
|
|
456
|
+
rx, ry, rz,
|
|
457
|
+
ax, ay, az,
|
|
458
|
+
scratch_inertia
|
|
459
|
+
) {
|
|
460
|
+
const iix = ss[base + SBS_INV_I_X];
|
|
461
|
+
const iiy = ss[base + SBS_INV_I_Y];
|
|
462
|
+
const iiz = ss[base + SBS_INV_I_Z];
|
|
463
|
+
|
|
464
|
+
if (iix === 0 && iiy === 0 && iiz === 0) {
|
|
465
|
+
return 0;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const rxax = ry * az - rz * ay;
|
|
469
|
+
const rxay = rz * ax - rx * az;
|
|
470
|
+
const rxaz = rx * ay - ry * ax;
|
|
471
|
+
|
|
472
|
+
world_inverse_inertia_apply_raw(
|
|
473
|
+
scratch_inertia, 0,
|
|
474
|
+
iix, iiy, iiz,
|
|
475
|
+
ss[base + SBS_QX], ss[base + SBS_QY], ss[base + SBS_QZ], ss[base + SBS_QW],
|
|
476
|
+
rxax, rxay, rxaz
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
return rxax * scratch_inertia[0]
|
|
480
|
+
+ rxay * scratch_inertia[1]
|
|
481
|
+
+ rxaz * scratch_inertia[2];
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Flat count of all touched contacts across every island, plus the slot
|
|
486
|
+
* list to iterate. Islands are concatenated densely in `contact_data`;
|
|
487
|
+
* `contact_offsets[island_count]` is the end of the last island.
|
|
488
|
+
*
|
|
489
|
+
* @param {PhysicsSystem} system
|
|
490
|
+
* @returns {{slot_list: Uint32Array, total_slots: number}|null}
|
|
491
|
+
*/
|
|
492
|
+
function island_slot_range(system) {
|
|
493
|
+
const islands = system.islands;
|
|
494
|
+
|
|
495
|
+
if (islands === undefined || islands === null) {
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const island_count = islands.island_count;
|
|
500
|
+
|
|
501
|
+
if (island_count === 0) {
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return {
|
|
506
|
+
slot_list: islands.contact_data,
|
|
507
|
+
total_slots: islands.contact_offsets[island_count],
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Stage 1 — prepare the contact constraints for an outer step.
|
|
513
|
+
*
|
|
514
|
+
* Packs every touched, non-sensor contact into the flat scratch arrays:
|
|
515
|
+
* local-frame witness anchors, tangent basis, effective masses, friction,
|
|
516
|
+
* the restitution approach velocity, and the warm-start replay (applied
|
|
517
|
+
* once here, not per substep). Computes the SPOOK gains from the SUBSTEP
|
|
518
|
+
* size `dt_sub` because the position correction runs once per substep.
|
|
519
|
+
*
|
|
520
|
+
* @param {ManifoldStore} manifolds
|
|
521
|
+
* @param {PhysicsSystem} system
|
|
522
|
+
* @param {number} dt_sub substep size `dt / substeps`
|
|
523
|
+
* @returns {number} number of contacts prepared (also stored module-side)
|
|
524
|
+
*/
|
|
525
|
+
export function prepare_contacts(manifolds, system, dt_sub) {
|
|
526
|
+
g_contact_count = 0;
|
|
527
|
+
|
|
528
|
+
if (dt_sub <= 0) {
|
|
529
|
+
return 0;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const range = island_slot_range(system);
|
|
533
|
+
|
|
534
|
+
if (range === null) {
|
|
535
|
+
return 0;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const slot_list = range.slot_list;
|
|
539
|
+
const total_slots = range.total_slots;
|
|
540
|
+
|
|
541
|
+
let contact_total = 0;
|
|
542
|
+
|
|
543
|
+
for (let i = 0; i < total_slots; i++) {
|
|
544
|
+
contact_total += manifolds.contact_count(slot_list[i]);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (contact_total === 0) {
|
|
548
|
+
return 0;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
ensure_capacity(contact_total);
|
|
552
|
+
|
|
553
|
+
const denom = 1 + 4 * CONTACT_RELAXATION;
|
|
554
|
+
g_spook_a = 4 / (dt_sub * denom);
|
|
555
|
+
g_spook_eps = 4 / (dt_sub * dt_sub * CONTACT_STIFFNESS * denom);
|
|
556
|
+
|
|
557
|
+
const data = manifolds.data_buffer;
|
|
558
|
+
const pre = scratch_pre;
|
|
559
|
+
const idx = scratch_idx;
|
|
560
|
+
const mus = scratch_mu;
|
|
561
|
+
const pos_jn = scratch_pos_jn;
|
|
562
|
+
const ss = system.__solver_state.data;
|
|
563
|
+
|
|
564
|
+
g_concave_slot_count = 0;
|
|
565
|
+
|
|
566
|
+
let c = 0;
|
|
567
|
+
for (let i = 0; i < total_slots; i++) {
|
|
568
|
+
const slot = slot_list[i];
|
|
569
|
+
|
|
570
|
+
const idxA = body_id_index(manifolds.bodyA(slot));
|
|
571
|
+
const idxB = body_id_index(manifolds.bodyB(slot));
|
|
572
|
+
|
|
573
|
+
const baseA = idxA * SBS_STRIDE;
|
|
574
|
+
const baseB = idxB * SBS_STRIDE;
|
|
575
|
+
|
|
576
|
+
const rbA = system.__bodies[idxA];
|
|
577
|
+
const rbB = system.__bodies[idxB];
|
|
578
|
+
|
|
579
|
+
const trA = system.__transforms[idxA];
|
|
580
|
+
const trB = system.__transforms[idxB];
|
|
581
|
+
|
|
582
|
+
const colA = system.__primary_collider(idxA);
|
|
583
|
+
const colB = system.__primary_collider(idxB);
|
|
584
|
+
|
|
585
|
+
if (colA === null || colB === null) {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (pair_is_sensor(rbA, colA, rbB, colB)) {
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// A pair is "concave" when either side's shape is non-convex. Those
|
|
594
|
+
// contacts take the per-substep re-detection path (the contact
|
|
595
|
+
// feature moves as the body rocks); convex pairs keep the cheap
|
|
596
|
+
// analytic refresh. Recorded once per slot for redetect_concave_contacts.
|
|
597
|
+
const slot_concave = (colA.shape.is_convex === false) || (colB.shape.is_convex === false);
|
|
598
|
+
|
|
599
|
+
if (slot_concave) {
|
|
600
|
+
ensure_concave_slot_capacity(g_concave_slot_count + 1);
|
|
601
|
+
concave_slot[g_concave_slot_count] = slot;
|
|
602
|
+
concave_slot_idxA[g_concave_slot_count] = idxA;
|
|
603
|
+
concave_slot_idxB[g_concave_slot_count] = idxB;
|
|
604
|
+
g_concave_slot_count++;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const invMA = ss[baseA + SBS_INV_MASS];
|
|
608
|
+
const invMB = ss[baseB + SBS_INV_MASS];
|
|
609
|
+
|
|
610
|
+
const cc = manifolds.contact_count(slot);
|
|
611
|
+
const slot_off = manifolds.slot_data_offset(slot);
|
|
612
|
+
|
|
613
|
+
const pAx = trA.position.x, pAy = trA.position.y, pAz = trA.position.z;
|
|
614
|
+
const pBx = trB.position.x, pBy = trB.position.y, pBz = trB.position.z;
|
|
615
|
+
const qA = trA.rotation, qB = trB.rotation;
|
|
616
|
+
|
|
617
|
+
for (let k = 0; k < cc; k++) {
|
|
618
|
+
const off = slot_off + k * CONTACT_STRIDE;
|
|
619
|
+
|
|
620
|
+
// Per-contact combined materials (stamped by the narrowphase from
|
|
621
|
+
// this contact's specific source-collider pair).
|
|
622
|
+
const friction_combined = data[off + 14];
|
|
623
|
+
const restitution_combined = data[off + 15];
|
|
624
|
+
|
|
625
|
+
const wax = data[off], way = data[off + 1], waz = data[off + 2];
|
|
626
|
+
const wbx = data[off + 3], wby = data[off + 4], wbz = data[off + 5];
|
|
627
|
+
const nx = data[off + 6], ny = data[off + 7], nz = data[off + 8];
|
|
628
|
+
|
|
629
|
+
const px = (wax + wbx) * 0.5;
|
|
630
|
+
const py = (way + wby) * 0.5;
|
|
631
|
+
const pz = (waz + wbz) * 0.5;
|
|
632
|
+
|
|
633
|
+
const rax = px - pAx, ray = py - pAy, raz = pz - pAz;
|
|
634
|
+
const rbx = px - pBx, rby = py - pBy, rbz = pz - pBz;
|
|
635
|
+
|
|
636
|
+
const pre_off = c * PRE_STRIDE;
|
|
637
|
+
|
|
638
|
+
// Per-body witness anchors in LOCAL frame (constant across the
|
|
639
|
+
// outer step). localW = R⁻¹ · (witness − COM).
|
|
640
|
+
v3_quat3_apply_inverse(pre, pre_off, wax - pAx, way - pAy, waz - pAz, qA[0], qA[1], qA[2], qA[3]);
|
|
641
|
+
v3_quat3_apply_inverse(pre, pre_off + 3, wbx - pBx, wby - pBy, wbz - pBz, qB[0], qB[1], qB[2], qB[3]);
|
|
642
|
+
|
|
643
|
+
// Lever arms from COM to the contact midpoint (refreshed each
|
|
644
|
+
// substep; seeded here from prepare-time pose).
|
|
645
|
+
pre[pre_off + 6] = rax;
|
|
646
|
+
pre[pre_off + 7] = ray;
|
|
647
|
+
pre[pre_off + 8] = raz;
|
|
648
|
+
pre[pre_off + 9] = rbx;
|
|
649
|
+
pre[pre_off + 10] = rby;
|
|
650
|
+
pre[pre_off + 11] = rbz;
|
|
651
|
+
|
|
652
|
+
build_tangents(pre, pre_off + 12, nx, ny, nz);
|
|
653
|
+
const t1x = pre[pre_off + 12], t1y = pre[pre_off + 13], t1z = pre[pre_off + 14];
|
|
654
|
+
const t2x = pre[pre_off + 15], t2y = pre[pre_off + 16], t2z = pre[pre_off + 17];
|
|
655
|
+
|
|
656
|
+
const k_n = invMA + invMB
|
|
657
|
+
+ angular_jacobian_contribution(ss, baseA, rax, ray, raz, nx, ny, nz, scratch_inertia_a)
|
|
658
|
+
+ angular_jacobian_contribution(ss, baseB, rbx, rby, rbz, nx, ny, nz, scratch_inertia_b);
|
|
659
|
+
const k_t1 = invMA + invMB
|
|
660
|
+
+ angular_jacobian_contribution(ss, baseA, rax, ray, raz, t1x, t1y, t1z, scratch_inertia_a)
|
|
661
|
+
+ angular_jacobian_contribution(ss, baseB, rbx, rby, rbz, t1x, t1y, t1z, scratch_inertia_b);
|
|
662
|
+
const k_t2 = invMA + invMB
|
|
663
|
+
+ angular_jacobian_contribution(ss, baseA, rax, ray, raz, t2x, t2y, t2z, scratch_inertia_a)
|
|
664
|
+
+ angular_jacobian_contribution(ss, baseB, rbx, rby, rbz, t2x, t2y, t2z, scratch_inertia_b);
|
|
665
|
+
|
|
666
|
+
const k_n_eff = k_n + g_spook_eps;
|
|
667
|
+
pre[pre_off + 18] = k_n_eff > 0 ? 1 / k_n_eff : 0;
|
|
668
|
+
pre[pre_off + 19] = k_t1 > 0 ? 1 / k_t1 : 0;
|
|
669
|
+
pre[pre_off + 20] = k_t2 > 0 ? 1 / k_t2 : 0;
|
|
670
|
+
|
|
671
|
+
// Restitution approach velocity (captured once, this is the
|
|
672
|
+
// closing speed entering the step). n is B → A; vn < 0 closing.
|
|
673
|
+
const vAx_at = ss[baseA + SBS_LV_X] + ss[baseA + SBS_AV_Y] * raz - ss[baseA + SBS_AV_Z] * ray;
|
|
674
|
+
const vAy_at = ss[baseA + SBS_LV_Y] + ss[baseA + SBS_AV_Z] * rax - ss[baseA + SBS_AV_X] * raz;
|
|
675
|
+
const vAz_at = ss[baseA + SBS_LV_Z] + ss[baseA + SBS_AV_X] * ray - ss[baseA + SBS_AV_Y] * rax;
|
|
676
|
+
|
|
677
|
+
const vBx_at = ss[baseB + SBS_LV_X] + ss[baseB + SBS_AV_Y] * rbz - ss[baseB + SBS_AV_Z] * rby;
|
|
678
|
+
const vBy_at = ss[baseB + SBS_LV_Y] + ss[baseB + SBS_AV_Z] * rbx - ss[baseB + SBS_AV_X] * rbz;
|
|
679
|
+
const vBz_at = ss[baseB + SBS_LV_Z] + ss[baseB + SBS_AV_X] * rby - ss[baseB + SBS_AV_Y] * rbx;
|
|
680
|
+
|
|
681
|
+
const vn_pre = (vAx_at - vBx_at) * nx + (vAy_at - vBy_at) * ny + (vAz_at - vBz_at) * nz;
|
|
682
|
+
|
|
683
|
+
let rest_bias = 0;
|
|
684
|
+
if (vn_pre < -RESTITUTION_VELOCITY_THRESHOLD) {
|
|
685
|
+
rest_bias = restitution_combined * vn_pre;
|
|
686
|
+
}
|
|
687
|
+
pre[pre_off + 21] = rest_bias;
|
|
688
|
+
pre[pre_off + 22] = 0; // bias_position — filled by refresh_contacts
|
|
689
|
+
|
|
690
|
+
mus[c] = friction_combined;
|
|
691
|
+
pos_jn[c] = 0;
|
|
692
|
+
scratch_max_jn[c] = 0;
|
|
693
|
+
scratch_concave[c] = slot_concave ? 1 : 0;
|
|
694
|
+
|
|
695
|
+
idx[c * INDEX_STRIDE] = slot;
|
|
696
|
+
idx[c * INDEX_STRIDE + 1] = k;
|
|
697
|
+
idx[c * INDEX_STRIDE + 2] = idxA;
|
|
698
|
+
idx[c * INDEX_STRIDE + 3] = idxB;
|
|
699
|
+
|
|
700
|
+
// Warm-start is NOT applied here: under TGS it must be replayed
|
|
701
|
+
// *every substep* (see warm_start_contacts) so that, per substep,
|
|
702
|
+
// the cached impulse balances exactly one substep of gravity.
|
|
703
|
+
// Applying the cached impulse once against a full frame of
|
|
704
|
+
// gravity (the non-substepped pattern) over-pushes resting
|
|
705
|
+
// contacts and jitters / explodes deep stacks.
|
|
706
|
+
|
|
707
|
+
c++;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
g_contact_count = c;
|
|
712
|
+
return c;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Stage 1b (per substep) — warm-start: replay the cached accumulated
|
|
717
|
+
* impulses `(j_n, j_t1, j_t2)` onto persistent velocity using the current
|
|
718
|
+
* (refreshed) lever arms and tangents. Run once per substep, after
|
|
719
|
+
* {@link refresh_contacts} and before {@link solve_velocity}.
|
|
720
|
+
*
|
|
721
|
+
* Per-substep warm-start is the crux of stable TGS: the stored impulse is a
|
|
722
|
+
* per-substep quantity (≈ the impulse to counter one substep of gravity), so
|
|
723
|
+
* replaying it each substep balances that substep's `integrate_velocity_gravity`
|
|
724
|
+
* and a resting contact holds at zero velocity. `solve_velocity` then only
|
|
725
|
+
* has to correct the residual, which converges in a few iterations even for
|
|
726
|
+
* deep chains because each substep carries just `h` of gravity.
|
|
727
|
+
*
|
|
728
|
+
* @param {ManifoldStore} manifolds
|
|
729
|
+
* @param {PhysicsSystem} system
|
|
730
|
+
*/
|
|
731
|
+
export function warm_start_contacts(manifolds, system) {
|
|
732
|
+
const count = g_contact_count;
|
|
733
|
+
if (count === 0) return;
|
|
734
|
+
|
|
735
|
+
const data = manifolds.data_buffer;
|
|
736
|
+
const pre = scratch_pre;
|
|
737
|
+
const idx = scratch_idx;
|
|
738
|
+
const ss = system.__solver_state.data;
|
|
739
|
+
|
|
740
|
+
for (let ci = 0; ci < count; ci++) {
|
|
741
|
+
const slot = idx[ci * INDEX_STRIDE];
|
|
742
|
+
const cidx = idx[ci * INDEX_STRIDE + 1];
|
|
743
|
+
|
|
744
|
+
const baseA = idx[ci * INDEX_STRIDE + 2] * SBS_STRIDE;
|
|
745
|
+
const baseB = idx[ci * INDEX_STRIDE + 3] * SBS_STRIDE;
|
|
746
|
+
|
|
747
|
+
const invMA = ss[baseA + SBS_INV_MASS];
|
|
748
|
+
const invMB = ss[baseB + SBS_INV_MASS];
|
|
749
|
+
|
|
750
|
+
const pre_off = ci * PRE_STRIDE;
|
|
751
|
+
|
|
752
|
+
const rax = pre[pre_off + 6], ray = pre[pre_off + 7], raz = pre[pre_off + 8];
|
|
753
|
+
const rbx = pre[pre_off + 9], rby = pre[pre_off + 10], rbz = pre[pre_off + 11];
|
|
754
|
+
|
|
755
|
+
const t1x = pre[pre_off + 12], t1y = pre[pre_off + 13], t1z = pre[pre_off + 14];
|
|
756
|
+
const t2x = pre[pre_off + 15], t2y = pre[pre_off + 16], t2z = pre[pre_off + 17];
|
|
757
|
+
|
|
758
|
+
const slot_off = manifolds.slot_data_offset(slot);
|
|
759
|
+
const off = slot_off + cidx * CONTACT_STRIDE;
|
|
760
|
+
const nx = data[off + 6], ny = data[off + 7], nz = data[off + 8];
|
|
761
|
+
|
|
762
|
+
const j_n = data[off + 10];
|
|
763
|
+
const j_t1 = data[off + 11];
|
|
764
|
+
const j_t2 = data[off + 12];
|
|
765
|
+
|
|
766
|
+
const Px = nx * j_n + t1x * j_t1 + t2x * j_t2;
|
|
767
|
+
const Py = ny * j_n + t1y * j_t1 + t2y * j_t2;
|
|
768
|
+
const Pz = nz * j_n + t1z * j_t1 + t2z * j_t2;
|
|
769
|
+
|
|
770
|
+
apply_impulse_to_body(ss, baseA, invMA, rax, ray, raz, Px, Py, Pz, +1, scratch_inertia_a);
|
|
771
|
+
apply_impulse_to_body(ss, baseB, invMB, rbx, rby, rbz, Px, Py, Pz, -1, scratch_inertia_b);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Stage 2 (per substep) — re-derive each contact's geometry from the
|
|
777
|
+
* bodies' current poses and the local witness anchors captured at prepare.
|
|
778
|
+
*
|
|
779
|
+
* For each contact:
|
|
780
|
+
* - rotate the stored local witnesses back to world by the current pose to
|
|
781
|
+
* get the moved contact points `cpA`, `cpB`;
|
|
782
|
+
* - current penetration `depth_now = depth0 − Δseparation`, where
|
|
783
|
+
* `Δseparation = (cpA − wA − (cpB − wB)) · n` is the change since prepare.
|
|
784
|
+
* Anchoring on the trusted prepare-time depth makes the sign convention
|
|
785
|
+
* irrelevant — only the analytic delta uses the anchors;
|
|
786
|
+
* - rebuild the impulse levers `rA`/`rB` from the moved midpoint;
|
|
787
|
+
* - recompute the position-correction bias from `depth_now`.
|
|
788
|
+
*
|
|
789
|
+
* The contact normal and tangents are held fixed for the outer step (valid
|
|
790
|
+
* for the small per-step rotation), so they are not recomputed here.
|
|
791
|
+
*
|
|
792
|
+
* @param {ManifoldStore} manifolds
|
|
793
|
+
* @param {Transform[]} transforms
|
|
794
|
+
*/
|
|
795
|
+
export function refresh_contacts(manifolds, transforms) {
|
|
796
|
+
const count = g_contact_count;
|
|
797
|
+
|
|
798
|
+
if (count === 0) {
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
const data = manifolds.data_buffer;
|
|
803
|
+
const pre = scratch_pre;
|
|
804
|
+
const idx = scratch_idx;
|
|
805
|
+
const cp = scratch_cp;
|
|
806
|
+
const spook_a = g_spook_a;
|
|
807
|
+
|
|
808
|
+
for (let ci = 0; ci < count; ci++) {
|
|
809
|
+
// Concave contacts are refreshed by redetect_concave_contacts (fresh
|
|
810
|
+
// narrowphase geometry each substep), not by the analytic rotation of
|
|
811
|
+
// frozen anchors — their feature moves as the body rocks.
|
|
812
|
+
if (scratch_concave[ci] === 1) {
|
|
813
|
+
continue;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const slot = idx[ci * INDEX_STRIDE];
|
|
817
|
+
const cidx = idx[ci * INDEX_STRIDE + 1];
|
|
818
|
+
const idxA = idx[ci * INDEX_STRIDE + 2];
|
|
819
|
+
const idxB = idx[ci * INDEX_STRIDE + 3];
|
|
820
|
+
|
|
821
|
+
const trA = transforms[idxA];
|
|
822
|
+
const trB = transforms[idxB];
|
|
823
|
+
|
|
824
|
+
const slot_off = manifolds.slot_data_offset(slot);
|
|
825
|
+
const off = slot_off + cidx * CONTACT_STRIDE;
|
|
826
|
+
|
|
827
|
+
const wax = data[off], way = data[off + 1], waz = data[off + 2];
|
|
828
|
+
const wbx = data[off + 3], wby = data[off + 4], wbz = data[off + 5];
|
|
829
|
+
const nx = data[off + 6], ny = data[off + 7], nz = data[off + 8];
|
|
830
|
+
|
|
831
|
+
const depth0 = data[off + 9];
|
|
832
|
+
|
|
833
|
+
const pre_off = ci * PRE_STRIDE;
|
|
834
|
+
|
|
835
|
+
const pAx = trA.position[0];
|
|
836
|
+
const pAy = trA.position[1];
|
|
837
|
+
const pAz = trA.position[2];
|
|
838
|
+
|
|
839
|
+
const pBx = trB.position[0];
|
|
840
|
+
const pBy = trB.position[1];
|
|
841
|
+
const pBz = trB.position[2];
|
|
842
|
+
|
|
843
|
+
const qA = trA.rotation;
|
|
844
|
+
const qB = trB.rotation;
|
|
845
|
+
|
|
846
|
+
// Current world contact points: COM + R · localWitness.
|
|
847
|
+
v3_quat3_apply(cp, 0, pre[pre_off], pre[pre_off + 1], pre[pre_off + 2], qA[0], qA[1], qA[2], qA[3]);
|
|
848
|
+
v3_quat3_apply(cp, 3, pre[pre_off + 3], pre[pre_off + 4], pre[pre_off + 5], qB[0], qB[1], qB[2], qB[3]);
|
|
849
|
+
|
|
850
|
+
const cpAx = pAx + cp[0], cpAy = pAy + cp[1], cpAz = pAz + cp[2];
|
|
851
|
+
const cpBx = pBx + cp[3], cpBy = pBy + cp[4], cpBz = pBz + cp[5];
|
|
852
|
+
|
|
853
|
+
// Penetration re-derived as a delta from the trusted prepare depth.
|
|
854
|
+
// Δsep = ((cpA − wA) − (cpB − wB)) · n.
|
|
855
|
+
const dsep = ((cpAx - wax) - (cpBx - wbx)) * nx
|
|
856
|
+
+ ((cpAy - way) - (cpBy - wby)) * ny
|
|
857
|
+
+ ((cpAz - waz) - (cpBz - wbz)) * nz;
|
|
858
|
+
|
|
859
|
+
const depth_now = depth0 - dsep;
|
|
860
|
+
|
|
861
|
+
// Impulse levers from each COM to the current contact midpoint.
|
|
862
|
+
const mx = (cpAx + cpBx) * 0.5;
|
|
863
|
+
const my = (cpAy + cpBy) * 0.5;
|
|
864
|
+
const mz = (cpAz + cpBz) * 0.5;
|
|
865
|
+
|
|
866
|
+
pre[pre_off + 6] = mx - pAx;
|
|
867
|
+
pre[pre_off + 7] = my - pAy;
|
|
868
|
+
pre[pre_off + 8] = mz - pAz;
|
|
869
|
+
pre[pre_off + 9] = mx - pBx;
|
|
870
|
+
pre[pre_off + 10] = my - pBy;
|
|
871
|
+
pre[pre_off + 11] = mz - pBz;
|
|
872
|
+
|
|
873
|
+
let bias_position = 0;
|
|
874
|
+
|
|
875
|
+
if (depth_now > PENETRATION_SLOP) {
|
|
876
|
+
bias_position = -spook_a * (depth_now - PENETRATION_SLOP);
|
|
877
|
+
|
|
878
|
+
if (bias_position < -MAX_POSITION_BIAS) {
|
|
879
|
+
bias_position = -MAX_POSITION_BIAS;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
pre[pre_off + 22] = bias_position;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Stage 2b (per substep) — the concave counterpart of {@link refresh_contacts}.
|
|
889
|
+
*
|
|
890
|
+
* For each concave-involved slot, re-runs the narrowphase geometry at the
|
|
891
|
+
* current substep pose ({@link redetect_pair_geometry}, which rewrites the
|
|
892
|
+
* manifold's witness / normal / depth in place), then re-derives the solver
|
|
893
|
+
* scratch (lever arms, tangent basis, effective masses, position bias) for
|
|
894
|
+
* that slot's contacts from the fresh geometry. This is the whole point of
|
|
895
|
+
* the concave path: a body rocking on a mesh changes which triangle (and
|
|
896
|
+
* normal) it rests on within a single outer step, and freezing that — as the
|
|
897
|
+
* convex analytic refresh does — pumps energy in. Re-detecting gives a
|
|
898
|
+
* correct per-substep normal so the body settles.
|
|
899
|
+
*
|
|
900
|
+
* Cost is ~one narrowphase dispatch per concave slot per substep — acceptable
|
|
901
|
+
* because concave-involved pairs are rare (the common concave case, a convex
|
|
902
|
+
* body on static terrain, is convex on the moving side and never lands here).
|
|
903
|
+
* The contact count is held fixed (redetect updates geometry only), so the
|
|
904
|
+
* scratch stays aligned with prepare.
|
|
905
|
+
*
|
|
906
|
+
* Must run before {@link refresh_contacts} / {@link warm_start_contacts} each
|
|
907
|
+
* substep. `rest_bias` (captured at prepare) and the `scratch_max_jn`
|
|
908
|
+
* restitution gate are preserved.
|
|
909
|
+
*
|
|
910
|
+
* @param {ManifoldStore} manifolds
|
|
911
|
+
* @param {PhysicsSystem} system reads `__body_collider_lists`, `__bodies`,
|
|
912
|
+
* `__transforms`.
|
|
913
|
+
*/
|
|
914
|
+
export function redetect_concave_contacts(manifolds, system) {
|
|
915
|
+
const ns = g_concave_slot_count;
|
|
916
|
+
|
|
917
|
+
if (ns === 0) {
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
const lists = system.__body_collider_lists;
|
|
922
|
+
|
|
923
|
+
// 1. Re-detect fresh geometry into the manifold for each concave slot.
|
|
924
|
+
for (let s = 0; s < ns; s++) {
|
|
925
|
+
redetect_pair_geometry(manifolds, concave_slot[s], lists[concave_slot_idxA[s]], lists[concave_slot_idxB[s]]);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// 2. Re-derive the solver scratch for every concave contact from the
|
|
929
|
+
// fresh manifold geometry (lever arms, tangents, effective masses,
|
|
930
|
+
// position bias). Mirrors prepare's per-contact setup but reads the
|
|
931
|
+
// just-updated witness / normal / depth instead of the prepare-time
|
|
932
|
+
// values; no local-frame anchors are needed since we re-detect rather
|
|
933
|
+
// than rotate frozen anchors.
|
|
934
|
+
const count = g_contact_count;
|
|
935
|
+
const data = manifolds.data_buffer;
|
|
936
|
+
const pre = scratch_pre;
|
|
937
|
+
const idx = scratch_idx;
|
|
938
|
+
const spook_a = g_spook_a;
|
|
939
|
+
const spook_eps = g_spook_eps;
|
|
940
|
+
const ss = system.__solver_state.data;
|
|
941
|
+
|
|
942
|
+
for (let ci = 0; ci < count; ci++) {
|
|
943
|
+
if (scratch_concave[ci] === 0) {
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
const slot = idx[ci * INDEX_STRIDE];
|
|
948
|
+
const cidx = idx[ci * INDEX_STRIDE + 1];
|
|
949
|
+
const idxA = idx[ci * INDEX_STRIDE + 2];
|
|
950
|
+
const idxB = idx[ci * INDEX_STRIDE + 3];
|
|
951
|
+
|
|
952
|
+
const baseA = idxA * SBS_STRIDE;
|
|
953
|
+
const baseB = idxB * SBS_STRIDE;
|
|
954
|
+
|
|
955
|
+
const trA = system.__transforms[idxA];
|
|
956
|
+
const trB = system.__transforms[idxB];
|
|
957
|
+
|
|
958
|
+
const invMA = ss[baseA + SBS_INV_MASS];
|
|
959
|
+
const invMB = ss[baseB + SBS_INV_MASS];
|
|
960
|
+
|
|
961
|
+
const slot_off = manifolds.slot_data_offset(slot);
|
|
962
|
+
const off = slot_off + cidx * CONTACT_STRIDE;
|
|
963
|
+
|
|
964
|
+
const wax = data[off], way = data[off + 1], waz = data[off + 2];
|
|
965
|
+
const wbx = data[off + 3], wby = data[off + 4], wbz = data[off + 5];
|
|
966
|
+
const nx = data[off + 6], ny = data[off + 7], nz = data[off + 8];
|
|
967
|
+
const depth = data[off + 9];
|
|
968
|
+
|
|
969
|
+
const px = (wax + wbx) * 0.5;
|
|
970
|
+
const py = (way + wby) * 0.5;
|
|
971
|
+
const pz = (waz + wbz) * 0.5;
|
|
972
|
+
|
|
973
|
+
const rax = px - trA.position.x, ray = py - trA.position.y, raz = pz - trA.position.z;
|
|
974
|
+
const rbx = px - trB.position.x, rby = py - trB.position.y, rbz = pz - trB.position.z;
|
|
975
|
+
|
|
976
|
+
const pre_off = ci * PRE_STRIDE;
|
|
977
|
+
pre[pre_off + 6] = rax;
|
|
978
|
+
pre[pre_off + 7] = ray;
|
|
979
|
+
pre[pre_off + 8] = raz;
|
|
980
|
+
pre[pre_off + 9] = rbx;
|
|
981
|
+
pre[pre_off + 10] = rby;
|
|
982
|
+
pre[pre_off + 11] = rbz;
|
|
983
|
+
|
|
984
|
+
build_tangents(pre, pre_off + 12, nx, ny, nz);
|
|
985
|
+
const t1x = pre[pre_off + 12], t1y = pre[pre_off + 13], t1z = pre[pre_off + 14];
|
|
986
|
+
const t2x = pre[pre_off + 15], t2y = pre[pre_off + 16], t2z = pre[pre_off + 17];
|
|
987
|
+
|
|
988
|
+
const k_n = invMA + invMB
|
|
989
|
+
+ angular_jacobian_contribution(ss, baseA, rax, ray, raz, nx, ny, nz, scratch_inertia_a)
|
|
990
|
+
+ angular_jacobian_contribution(ss, baseB, rbx, rby, rbz, nx, ny, nz, scratch_inertia_b);
|
|
991
|
+
const k_t1 = invMA + invMB
|
|
992
|
+
+ angular_jacobian_contribution(ss, baseA, rax, ray, raz, t1x, t1y, t1z, scratch_inertia_a)
|
|
993
|
+
+ angular_jacobian_contribution(ss, baseB, rbx, rby, rbz, t1x, t1y, t1z, scratch_inertia_b);
|
|
994
|
+
const k_t2 = invMA + invMB
|
|
995
|
+
+ angular_jacobian_contribution(ss, baseA, rax, ray, raz, t2x, t2y, t2z, scratch_inertia_a)
|
|
996
|
+
+ angular_jacobian_contribution(ss, baseB, rbx, rby, rbz, t2x, t2y, t2z, scratch_inertia_b);
|
|
997
|
+
|
|
998
|
+
const k_n_eff = k_n + spook_eps;
|
|
999
|
+
pre[pre_off + 18] = k_n_eff > 0 ? 1 / k_n_eff : 0;
|
|
1000
|
+
pre[pre_off + 19] = k_t1 > 0 ? 1 / k_t1 : 0;
|
|
1001
|
+
pre[pre_off + 20] = k_t2 > 0 ? 1 / k_t2 : 0;
|
|
1002
|
+
|
|
1003
|
+
let bias_position = 0;
|
|
1004
|
+
|
|
1005
|
+
if (depth > PENETRATION_SLOP) {
|
|
1006
|
+
bias_position = -spook_a * (depth - PENETRATION_SLOP);
|
|
1007
|
+
|
|
1008
|
+
if (bias_position < -MAX_POSITION_BIAS) {
|
|
1009
|
+
bias_position = -MAX_POSITION_BIAS;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
pre[pre_off + 22] = bias_position;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* Stage 3 (per substep) — velocity iterations enforcing pure
|
|
1020
|
+
* non-penetration (`vn → 0`) plus Coulomb-disk friction. No bias: depth
|
|
1021
|
+
* correction is the position pass, restitution is the one-shot pass.
|
|
1022
|
+
*
|
|
1023
|
+
* @param {ManifoldStore} manifolds
|
|
1024
|
+
* @param {PhysicsSystem} system
|
|
1025
|
+
* @param {number} iters
|
|
1026
|
+
*/
|
|
1027
|
+
export function solve_velocity(manifolds, system, iters) {
|
|
1028
|
+
const contact_count = g_contact_count;
|
|
1029
|
+
if (contact_count === 0) return;
|
|
1030
|
+
|
|
1031
|
+
const data = manifolds.data_buffer;
|
|
1032
|
+
const pre = scratch_pre;
|
|
1033
|
+
const idx = scratch_idx;
|
|
1034
|
+
const mus = scratch_mu;
|
|
1035
|
+
const ss = system.__solver_state.data;
|
|
1036
|
+
|
|
1037
|
+
for (let iter = 0; iter < iters; iter++) {
|
|
1038
|
+
for (let ci = 0; ci < contact_count; ci++) {
|
|
1039
|
+
|
|
1040
|
+
const slot = idx[ci * INDEX_STRIDE];
|
|
1041
|
+
const cidx = idx[ci * INDEX_STRIDE + 1];
|
|
1042
|
+
|
|
1043
|
+
const baseA = idx[ci * INDEX_STRIDE + 2] * SBS_STRIDE;
|
|
1044
|
+
const baseB = idx[ci * INDEX_STRIDE + 3] * SBS_STRIDE;
|
|
1045
|
+
|
|
1046
|
+
const invMA = ss[baseA + SBS_INV_MASS];
|
|
1047
|
+
const invMB = ss[baseB + SBS_INV_MASS];
|
|
1048
|
+
|
|
1049
|
+
const pre_off = ci * PRE_STRIDE;
|
|
1050
|
+
|
|
1051
|
+
const rax = pre[pre_off + 6], ray = pre[pre_off + 7], raz = pre[pre_off + 8];
|
|
1052
|
+
const rbx = pre[pre_off + 9], rby = pre[pre_off + 10], rbz = pre[pre_off + 11];
|
|
1053
|
+
|
|
1054
|
+
const t1x = pre[pre_off + 12], t1y = pre[pre_off + 13], t1z = pre[pre_off + 14];
|
|
1055
|
+
const t2x = pre[pre_off + 15], t2y = pre[pre_off + 16], t2z = pre[pre_off + 17];
|
|
1056
|
+
|
|
1057
|
+
const m_eff_n = pre[pre_off + 18];
|
|
1058
|
+
const m_eff_t1 = pre[pre_off + 19];
|
|
1059
|
+
const m_eff_t2 = pre[pre_off + 20];
|
|
1060
|
+
|
|
1061
|
+
const slot_off = manifolds.slot_data_offset(slot);
|
|
1062
|
+
const off = slot_off + cidx * CONTACT_STRIDE;
|
|
1063
|
+
const nx = data[off + 6], ny = data[off + 7], nz = data[off + 8];
|
|
1064
|
+
|
|
1065
|
+
const vAx_at = ss[baseA + SBS_LV_X] + ss[baseA + SBS_AV_Y] * raz - ss[baseA + SBS_AV_Z] * ray;
|
|
1066
|
+
const vAy_at = ss[baseA + SBS_LV_Y] + ss[baseA + SBS_AV_Z] * rax - ss[baseA + SBS_AV_X] * raz;
|
|
1067
|
+
const vAz_at = ss[baseA + SBS_LV_Z] + ss[baseA + SBS_AV_X] * ray - ss[baseA + SBS_AV_Y] * rax;
|
|
1068
|
+
|
|
1069
|
+
const vBx_at = ss[baseB + SBS_LV_X] + ss[baseB + SBS_AV_Y] * rbz - ss[baseB + SBS_AV_Z] * rby;
|
|
1070
|
+
const vBy_at = ss[baseB + SBS_LV_Y] + ss[baseB + SBS_AV_Z] * rbx - ss[baseB + SBS_AV_X] * rbz;
|
|
1071
|
+
const vBz_at = ss[baseB + SBS_LV_Z] + ss[baseB + SBS_AV_X] * rby - ss[baseB + SBS_AV_Y] * rbx;
|
|
1072
|
+
|
|
1073
|
+
const dvx = vAx_at - vBx_at;
|
|
1074
|
+
const dvy = vAy_at - vBy_at;
|
|
1075
|
+
const dvz = vAz_at - vBz_at;
|
|
1076
|
+
|
|
1077
|
+
// --- Normal impulse (non-penetration: drive vn → 0) ---
|
|
1078
|
+
const vn = dvx * nx + dvy * ny + dvz * nz;
|
|
1079
|
+
const j_n_accum = data[off + 10];
|
|
1080
|
+
const lambda_n = -m_eff_n * vn;
|
|
1081
|
+
const sum_n = j_n_accum + lambda_n;
|
|
1082
|
+
const new_j_n = sum_n > 0 ? sum_n : 0;
|
|
1083
|
+
const delta_j_n = new_j_n - j_n_accum;
|
|
1084
|
+
data[off + 10] = new_j_n;
|
|
1085
|
+
|
|
1086
|
+
if (new_j_n > scratch_max_jn[ci]) {
|
|
1087
|
+
scratch_max_jn[ci] = new_j_n;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
if (delta_j_n !== 0) {
|
|
1091
|
+
const Pnx = nx * delta_j_n;
|
|
1092
|
+
const Pny = ny * delta_j_n;
|
|
1093
|
+
const Pnz = nz * delta_j_n;
|
|
1094
|
+
|
|
1095
|
+
apply_impulse_to_body(ss, baseA, invMA, rax, ray, raz, Pnx, Pny, Pnz, +1, scratch_inertia_a);
|
|
1096
|
+
apply_impulse_to_body(ss, baseB, invMB, rbx, rby, rbz, Pnx, Pny, Pnz, -1, scratch_inertia_b);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// --- Friction impulse (Coulomb disk in tangent plane) ---
|
|
1100
|
+
// Re-read velocity from the solver state: the normal impulse above
|
|
1101
|
+
// just mutated it, and friction must see the corrected velocity.
|
|
1102
|
+
const vAx2 = ss[baseA + SBS_LV_X] + ss[baseA + SBS_AV_Y] * raz - ss[baseA + SBS_AV_Z] * ray;
|
|
1103
|
+
const vAy2 = ss[baseA + SBS_LV_Y] + ss[baseA + SBS_AV_Z] * rax - ss[baseA + SBS_AV_X] * raz;
|
|
1104
|
+
const vAz2 = ss[baseA + SBS_LV_Z] + ss[baseA + SBS_AV_X] * ray - ss[baseA + SBS_AV_Y] * rax;
|
|
1105
|
+
|
|
1106
|
+
const vBx2 = ss[baseB + SBS_LV_X] + ss[baseB + SBS_AV_Y] * rbz - ss[baseB + SBS_AV_Z] * rby;
|
|
1107
|
+
const vBy2 = ss[baseB + SBS_LV_Y] + ss[baseB + SBS_AV_Z] * rbx - ss[baseB + SBS_AV_X] * rbz;
|
|
1108
|
+
const vBz2 = ss[baseB + SBS_LV_Z] + ss[baseB + SBS_AV_X] * rby - ss[baseB + SBS_AV_Y] * rbx;
|
|
1109
|
+
|
|
1110
|
+
const dvx2 = vAx2 - vBx2;
|
|
1111
|
+
const dvy2 = vAy2 - vBy2;
|
|
1112
|
+
const dvz2 = vAz2 - vBz2;
|
|
1113
|
+
|
|
1114
|
+
const vt1 = dvx2 * t1x + dvy2 * t1y + dvz2 * t1z;
|
|
1115
|
+
const vt2 = dvx2 * t2x + dvy2 * t2y + dvz2 * t2z;
|
|
1116
|
+
|
|
1117
|
+
const j_t1_accum = data[off + 11];
|
|
1118
|
+
const j_t2_accum = data[off + 12];
|
|
1119
|
+
|
|
1120
|
+
const lambda_t1 = -m_eff_t1 * vt1;
|
|
1121
|
+
const lambda_t2 = -m_eff_t2 * vt2;
|
|
1122
|
+
|
|
1123
|
+
const want_t1 = j_t1_accum + lambda_t1;
|
|
1124
|
+
const want_t2 = j_t2_accum + lambda_t2;
|
|
1125
|
+
|
|
1126
|
+
const max_friction = mus[ci] * new_j_n;
|
|
1127
|
+
|
|
1128
|
+
friction_cone_clamp(scratch_clamp, 0, want_t1, want_t2, max_friction);
|
|
1129
|
+
|
|
1130
|
+
const new_j_t1 = scratch_clamp[0];
|
|
1131
|
+
const new_j_t2 = scratch_clamp[1];
|
|
1132
|
+
|
|
1133
|
+
const delta_t1 = new_j_t1 - j_t1_accum;
|
|
1134
|
+
const delta_t2 = new_j_t2 - j_t2_accum;
|
|
1135
|
+
|
|
1136
|
+
data[off + 11] = new_j_t1;
|
|
1137
|
+
data[off + 12] = new_j_t2;
|
|
1138
|
+
|
|
1139
|
+
if (delta_t1 !== 0 || delta_t2 !== 0) {
|
|
1140
|
+
|
|
1141
|
+
const Ptx = t1x * delta_t1 + t2x * delta_t2;
|
|
1142
|
+
const Pty = t1y * delta_t1 + t2y * delta_t2;
|
|
1143
|
+
const Ptz = t1z * delta_t1 + t2z * delta_t2;
|
|
1144
|
+
|
|
1145
|
+
apply_impulse_to_body(ss, baseA, invMA, rax, ray, raz, Ptx, Pty, Ptz, +1, scratch_inertia_a);
|
|
1146
|
+
apply_impulse_to_body(ss, baseB, invMB, rbx, rby, rbz, Ptx, Pty, Ptz, -1, scratch_inertia_b);
|
|
1147
|
+
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Stage 4 (once, after the substep loop) — one-shot restitution
|
|
1155
|
+
* (Box2D-v3 `b2ApplyRestitution`, Catto 2018). Drives `vn → -e · vn_approach`
|
|
1156
|
+
* exactly once per closing contact, gated on (a) the contact having been
|
|
1157
|
+
* closing faster than the threshold at prepare, and (b) a compressive
|
|
1158
|
+
* normal impulse having formed during the velocity solve. The added impulse
|
|
1159
|
+
* accumulates into the same normal-impulse slot so it composes with
|
|
1160
|
+
* warm-start next frame.
|
|
1161
|
+
*
|
|
1162
|
+
* @param {ManifoldStore} manifolds
|
|
1163
|
+
* @param {PhysicsSystem} system
|
|
1164
|
+
*/
|
|
1165
|
+
export function apply_restitution(manifolds, system) {
|
|
1166
|
+
const contact_count = g_contact_count;
|
|
1167
|
+
if (contact_count === 0) return;
|
|
1168
|
+
|
|
1169
|
+
const data = manifolds.data_buffer;
|
|
1170
|
+
const pre = scratch_pre;
|
|
1171
|
+
const idx = scratch_idx;
|
|
1172
|
+
const ss = system.__solver_state.data;
|
|
1173
|
+
|
|
1174
|
+
for (let ci = 0; ci < contact_count; ci++) {
|
|
1175
|
+
const pre_off = ci * PRE_STRIDE;
|
|
1176
|
+
const rest_bias = pre[pre_off + 21];
|
|
1177
|
+
if (rest_bias === 0) continue;
|
|
1178
|
+
|
|
1179
|
+
const slot = idx[ci * INDEX_STRIDE];
|
|
1180
|
+
const cidx = idx[ci * INDEX_STRIDE + 1];
|
|
1181
|
+
// Gate on the running max normal impulse, not the end-of-loop value:
|
|
1182
|
+
// a transient collision relaxes back to j_n ≈ 0 under per-substep
|
|
1183
|
+
// warm-start, but it WAS compressive, so it should still bounce.
|
|
1184
|
+
if (scratch_max_jn[ci] <= 0) continue;
|
|
1185
|
+
|
|
1186
|
+
const slot_off = manifolds.slot_data_offset(slot);
|
|
1187
|
+
const off = slot_off + cidx * CONTACT_STRIDE;
|
|
1188
|
+
|
|
1189
|
+
const j_n_accum = data[off + 10];
|
|
1190
|
+
|
|
1191
|
+
const baseA = idx[ci * INDEX_STRIDE + 2] * SBS_STRIDE;
|
|
1192
|
+
const baseB = idx[ci * INDEX_STRIDE + 3] * SBS_STRIDE;
|
|
1193
|
+
const invMA = ss[baseA + SBS_INV_MASS];
|
|
1194
|
+
const invMB = ss[baseB + SBS_INV_MASS];
|
|
1195
|
+
|
|
1196
|
+
const rax = pre[pre_off + 6], ray = pre[pre_off + 7], raz = pre[pre_off + 8];
|
|
1197
|
+
const rbx = pre[pre_off + 9], rby = pre[pre_off + 10], rbz = pre[pre_off + 11];
|
|
1198
|
+
const m_eff_n = pre[pre_off + 18];
|
|
1199
|
+
const nx = data[off + 6], ny = data[off + 7], nz = data[off + 8];
|
|
1200
|
+
|
|
1201
|
+
const vAx_at = ss[baseA + SBS_LV_X] + ss[baseA + SBS_AV_Y] * raz - ss[baseA + SBS_AV_Z] * ray;
|
|
1202
|
+
const vAy_at = ss[baseA + SBS_LV_Y] + ss[baseA + SBS_AV_Z] * rax - ss[baseA + SBS_AV_X] * raz;
|
|
1203
|
+
const vAz_at = ss[baseA + SBS_LV_Z] + ss[baseA + SBS_AV_X] * ray - ss[baseA + SBS_AV_Y] * rax;
|
|
1204
|
+
const vBx_at = ss[baseB + SBS_LV_X] + ss[baseB + SBS_AV_Y] * rbz - ss[baseB + SBS_AV_Z] * rby;
|
|
1205
|
+
const vBy_at = ss[baseB + SBS_LV_Y] + ss[baseB + SBS_AV_Z] * rbx - ss[baseB + SBS_AV_X] * rbz;
|
|
1206
|
+
const vBz_at = ss[baseB + SBS_LV_Z] + ss[baseB + SBS_AV_X] * rby - ss[baseB + SBS_AV_Y] * rbx;
|
|
1207
|
+
const vn = (vAx_at - vBx_at) * nx + (vAy_at - vBy_at) * ny + (vAz_at - vBz_at) * nz;
|
|
1208
|
+
|
|
1209
|
+
const lambda = -m_eff_n * (vn + rest_bias);
|
|
1210
|
+
const new_j_n = (j_n_accum + lambda) > 0 ? (j_n_accum + lambda) : 0;
|
|
1211
|
+
const delta = new_j_n - j_n_accum;
|
|
1212
|
+
data[off + 10] = new_j_n;
|
|
1213
|
+
|
|
1214
|
+
if (delta !== 0) {
|
|
1215
|
+
const Px = nx * delta, Py = ny * delta, Pz = nz * delta;
|
|
1216
|
+
apply_impulse_to_body(ss, baseA, invMA, rax, ray, raz, Px, Py, Pz, +1, scratch_inertia_a);
|
|
1217
|
+
apply_impulse_to_body(ss, baseB, invMB, rbx, rby, rbz, Px, Py, Pz, -1, scratch_inertia_b);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
/**
|
|
1223
|
+
* Stage 5 (per substep) — split-impulse position correction. Normal-only
|
|
1224
|
+
* (friction in the pseudo-velocity pass is ill-defined). Reads the per-body
|
|
1225
|
+
* pseudo-velocity, applies a clamped normal impulse driven by the refreshed
|
|
1226
|
+
* `bias_position`, and writes the increment back into the pseudo buffer. The
|
|
1227
|
+
* pose integrator folds pseudo-velocity into `pos += v · dt` and discards it.
|
|
1228
|
+
*
|
|
1229
|
+
* The pseudo buffer must be zeroed by the caller before this stage each
|
|
1230
|
+
* substep (it's a per-substep correction). The position accumulator
|
|
1231
|
+
* `scratch_pos_jn` is likewise reset here per substep.
|
|
1232
|
+
*
|
|
1233
|
+
* @param {ManifoldStore} manifolds
|
|
1234
|
+
* @param {PhysicsSystem} system
|
|
1235
|
+
* @param {number} pos_iters
|
|
1236
|
+
*/
|
|
1237
|
+
export function solve_position(manifolds, system, pos_iters) {
|
|
1238
|
+
const contact_count = g_contact_count;
|
|
1239
|
+
if (contact_count === 0) return;
|
|
1240
|
+
|
|
1241
|
+
const data = manifolds.data_buffer;
|
|
1242
|
+
const pre = scratch_pre;
|
|
1243
|
+
const idx = scratch_idx;
|
|
1244
|
+
const pos_jn = scratch_pos_jn;
|
|
1245
|
+
const pseudoVel = system.__pseudo_velocity;
|
|
1246
|
+
const ss = system.__solver_state.data;
|
|
1247
|
+
|
|
1248
|
+
// Reset the position-impulse accumulator for this substep.
|
|
1249
|
+
for (let ci = 0; ci < contact_count; ci++) pos_jn[ci] = 0;
|
|
1250
|
+
|
|
1251
|
+
for (let iter = 0; iter < pos_iters; iter++) {
|
|
1252
|
+
for (let ci = 0; ci < contact_count; ci++) {
|
|
1253
|
+
const pre_off = ci * PRE_STRIDE;
|
|
1254
|
+
const bias_p = pre[pre_off + 22];
|
|
1255
|
+
if (bias_p === 0) continue;
|
|
1256
|
+
|
|
1257
|
+
const slot = idx[ci * INDEX_STRIDE];
|
|
1258
|
+
const cidx = idx[ci * INDEX_STRIDE + 1];
|
|
1259
|
+
const idxA = idx[ci * INDEX_STRIDE + 2];
|
|
1260
|
+
const idxB = idx[ci * INDEX_STRIDE + 3];
|
|
1261
|
+
const sbaseA = idxA * SBS_STRIDE;
|
|
1262
|
+
const sbaseB = idxB * SBS_STRIDE;
|
|
1263
|
+
const invMA = ss[sbaseA + SBS_INV_MASS];
|
|
1264
|
+
const invMB = ss[sbaseB + SBS_INV_MASS];
|
|
1265
|
+
|
|
1266
|
+
const rax = pre[pre_off + 6], ray = pre[pre_off + 7], raz = pre[pre_off + 8];
|
|
1267
|
+
const rbx = pre[pre_off + 9], rby = pre[pre_off + 10], rbz = pre[pre_off + 11];
|
|
1268
|
+
const m_eff_n = pre[pre_off + 18];
|
|
1269
|
+
|
|
1270
|
+
const slot_off = manifolds.slot_data_offset(slot);
|
|
1271
|
+
const off = slot_off + cidx * CONTACT_STRIDE;
|
|
1272
|
+
const nx = data[off + 6], ny = data[off + 7], nz = data[off + 8];
|
|
1273
|
+
|
|
1274
|
+
const baseA = idxA * PSEUDO_STRIDE;
|
|
1275
|
+
const baseB = idxB * PSEUDO_STRIDE;
|
|
1276
|
+
|
|
1277
|
+
const pslA_x = pseudoVel[baseA], pslA_y = pseudoVel[baseA + 1], pslA_z = pseudoVel[baseA + 2];
|
|
1278
|
+
const psaA_x = pseudoVel[baseA + 3], psaA_y = pseudoVel[baseA + 4], psaA_z = pseudoVel[baseA + 5];
|
|
1279
|
+
const pslB_x = pseudoVel[baseB], pslB_y = pseudoVel[baseB + 1], pslB_z = pseudoVel[baseB + 2];
|
|
1280
|
+
const psaB_x = pseudoVel[baseB + 3], psaB_y = pseudoVel[baseB + 4], psaB_z = pseudoVel[baseB + 5];
|
|
1281
|
+
|
|
1282
|
+
const psvAx_at = pslA_x + psaA_y * raz - psaA_z * ray;
|
|
1283
|
+
const psvAy_at = pslA_y + psaA_z * rax - psaA_x * raz;
|
|
1284
|
+
const psvAz_at = pslA_z + psaA_x * ray - psaA_y * rax;
|
|
1285
|
+
const psvBx_at = pslB_x + psaB_y * rbz - psaB_z * rby;
|
|
1286
|
+
const psvBy_at = pslB_y + psaB_z * rbx - psaB_x * rbz;
|
|
1287
|
+
const psvBz_at = pslB_z + psaB_x * rby - psaB_y * rbx;
|
|
1288
|
+
|
|
1289
|
+
const psdvx = psvAx_at - psvBx_at;
|
|
1290
|
+
const psdvy = psvAy_at - psvBy_at;
|
|
1291
|
+
const psdvz = psvAz_at - psvBz_at;
|
|
1292
|
+
const psvn = psdvx * nx + psdvy * ny + psdvz * nz;
|
|
1293
|
+
|
|
1294
|
+
const jn_accum = pos_jn[ci];
|
|
1295
|
+
const lambda = -m_eff_n * (psvn + bias_p);
|
|
1296
|
+
const sum = jn_accum + lambda;
|
|
1297
|
+
const new_jn = sum > 0 ? sum : 0;
|
|
1298
|
+
const delta = new_jn - jn_accum;
|
|
1299
|
+
pos_jn[ci] = new_jn;
|
|
1300
|
+
|
|
1301
|
+
if (delta !== 0) {
|
|
1302
|
+
const Px = nx * delta;
|
|
1303
|
+
const Py = ny * delta;
|
|
1304
|
+
const Pz = nz * delta;
|
|
1305
|
+
apply_impulse_to_pseudo(pseudoVel, baseA, ss, sbaseA, invMA, rax, ray, raz, Px, Py, Pz, +1, scratch_inertia_a);
|
|
1306
|
+
apply_impulse_to_pseudo(pseudoVel, baseB, ss, sbaseB, invMB, rbx, rby, rbz, Px, Py, Pz, -1, scratch_inertia_b);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
* Convenience single-step driver: prepare → refresh → velocity →
|
|
1314
|
+
* restitution → position, all at the full `dt` (one substep). Equivalent to
|
|
1315
|
+
* the Phase-2 solver. The substepped path in `PhysicsSystem.fixedUpdate`
|
|
1316
|
+
* calls the stages directly; this entry point exists for callers/tests that
|
|
1317
|
+
* want a one-shot solve.
|
|
1318
|
+
*
|
|
1319
|
+
* The position pass writes `system.__pseudo_velocity`; the caller must zero
|
|
1320
|
+
* that buffer before this call and fold it into the pose afterwards.
|
|
1321
|
+
*
|
|
1322
|
+
* @param {ManifoldStore} manifolds
|
|
1323
|
+
* @param {PhysicsSystem} system
|
|
1324
|
+
* @param {number} dt
|
|
1325
|
+
* @param {number} [iters]
|
|
1326
|
+
* @param {number} [pos_iters]
|
|
1327
|
+
*/
|
|
1328
|
+
export function solve_contacts(manifolds, system, dt,
|
|
1329
|
+
iters = DEFAULT_VELOCITY_ITERATIONS,
|
|
1330
|
+
pos_iters = DEFAULT_POSITION_ITERATIONS) {
|
|
1331
|
+
if (dt <= 0) return;
|
|
1332
|
+
if (prepare_contacts(manifolds, system, dt) === 0) return;
|
|
1333
|
+
redetect_concave_contacts(manifolds, system);
|
|
1334
|
+
refresh_contacts(manifolds, system.__transforms);
|
|
1335
|
+
warm_start_contacts(manifolds, system);
|
|
1336
|
+
solve_velocity(manifolds, system, iters);
|
|
1337
|
+
apply_restitution(manifolds, system);
|
|
1338
|
+
solve_position(manifolds, system, pos_iters);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
export { DEFAULT_VELOCITY_ITERATIONS, DEFAULT_POSITION_ITERATIONS };
|