@driftengine/physics 3.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +9 -0
  3. package/README.md +503 -0
  4. package/dist/bodies.d.ts +121 -0
  5. package/dist/bodies.js +298 -0
  6. package/dist/buoyancy.d.ts +46 -0
  7. package/dist/buoyancy.js +45 -0
  8. package/dist/cloth.d.ts +226 -0
  9. package/dist/cloth.js +587 -0
  10. package/dist/collide/aabb.d.ts +10 -0
  11. package/dist/collide/aabb.js +11 -0
  12. package/dist/collide/body.d.ts +202 -0
  13. package/dist/collide/body.js +142 -0
  14. package/dist/collide/eject.d.ts +39 -0
  15. package/dist/collide/eject.js +142 -0
  16. package/dist/collide/index.d.ts +18 -0
  17. package/dist/collide/index.js +5 -0
  18. package/dist/collide/scratch.d.ts +8 -0
  19. package/dist/collide/scratch.js +9 -0
  20. package/dist/collide/segment.d.ts +12 -0
  21. package/dist/collide/segment.js +109 -0
  22. package/dist/collide/sweep.d.ts +3 -0
  23. package/dist/collide/sweep.js +1036 -0
  24. package/dist/colliderSet.d.ts +239 -0
  25. package/dist/colliderSet.js +546 -0
  26. package/dist/compoundContact.d.ts +70 -0
  27. package/dist/compoundContact.js +221 -0
  28. package/dist/controller.d.ts +351 -0
  29. package/dist/controller.js +641 -0
  30. package/dist/cylinder.d.ts +78 -0
  31. package/dist/cylinder.js +294 -0
  32. package/dist/cylinderContact.d.ts +7 -0
  33. package/dist/cylinderContact.js +704 -0
  34. package/dist/decompose.d.ts +105 -0
  35. package/dist/decompose.js +979 -0
  36. package/dist/events.d.ts +43 -0
  37. package/dist/events.js +95 -0
  38. package/dist/executor.d.ts +147 -0
  39. package/dist/executor.js +173 -0
  40. package/dist/faces.d.ts +26 -0
  41. package/dist/faces.js +34 -0
  42. package/dist/fingerprint.d.ts +61 -0
  43. package/dist/fingerprint.js +139 -0
  44. package/dist/groundMotor.d.ts +34 -0
  45. package/dist/groundMotor.js +41 -0
  46. package/dist/heightfieldShape.d.ts +128 -0
  47. package/dist/heightfieldShape.js +328 -0
  48. package/dist/index.d.ts +73 -0
  49. package/dist/index.js +47 -0
  50. package/dist/island.d.ts +55 -0
  51. package/dist/island.js +227 -0
  52. package/dist/islandSolve.d.ts +70 -0
  53. package/dist/islandSolve.js +171 -0
  54. package/dist/islandWorker.d.ts +18 -0
  55. package/dist/islandWorker.js +125 -0
  56. package/dist/joints.d.ts +180 -0
  57. package/dist/joints.js +1094 -0
  58. package/dist/manifold.d.ts +89 -0
  59. package/dist/manifold.js +608 -0
  60. package/dist/mass.d.ts +53 -0
  61. package/dist/mass.js +353 -0
  62. package/dist/meshContact.d.ts +57 -0
  63. package/dist/meshContact.js +393 -0
  64. package/dist/meshShape.d.ts +76 -0
  65. package/dist/meshShape.js +175 -0
  66. package/dist/pairs.d.ts +62 -0
  67. package/dist/pairs.js +154 -0
  68. package/dist/query.d.ts +71 -0
  69. package/dist/query.js +683 -0
  70. package/dist/ragdoll.d.ts +135 -0
  71. package/dist/ragdoll.js +489 -0
  72. package/dist/shape.d.ts +177 -0
  73. package/dist/shape.js +533 -0
  74. package/dist/solver.d.ts +136 -0
  75. package/dist/solver.js +601 -0
  76. package/dist/stage.d.ts +167 -0
  77. package/dist/stage.js +350 -0
  78. package/dist/stallEscape.d.ts +141 -0
  79. package/dist/stallEscape.js +254 -0
  80. package/dist/sweptStep.d.ts +173 -0
  81. package/dist/sweptStep.js +472 -0
  82. package/dist/tree.d.ts +61 -0
  83. package/dist/tree.js +348 -0
  84. package/dist/vehicle.d.ts +154 -0
  85. package/dist/vehicle.js +343 -0
  86. package/dist/workerPool.d.ts +107 -0
  87. package/dist/workerPool.js +239 -0
  88. package/dist/workers.d.ts +37 -0
  89. package/dist/workers.js +35 -0
  90. package/dist/world.d.ts +298 -0
  91. package/dist/world.js +712 -0
  92. package/package.json +55 -0
  93. package/src/bodies.ts +369 -0
  94. package/src/buoyancy.ts +78 -0
  95. package/src/cloth.ts +734 -0
  96. package/src/collide/aabb.ts +28 -0
  97. package/src/collide/body.ts +336 -0
  98. package/src/collide/eject.ts +156 -0
  99. package/src/collide/index.ts +26 -0
  100. package/src/collide/scratch.ts +10 -0
  101. package/src/collide/segment.ts +127 -0
  102. package/src/collide/sweep.ts +1132 -0
  103. package/src/colliderSet.ts +637 -0
  104. package/src/compoundContact.ts +284 -0
  105. package/src/controller.ts +817 -0
  106. package/src/cylinder.ts +340 -0
  107. package/src/cylinderContact.ts +825 -0
  108. package/src/decompose.ts +1198 -0
  109. package/src/events.ts +108 -0
  110. package/src/executor.ts +224 -0
  111. package/src/faces.ts +37 -0
  112. package/src/fingerprint.ts +146 -0
  113. package/src/groundMotor.ts +53 -0
  114. package/src/heightfieldShape.ts +395 -0
  115. package/src/index.ts +164 -0
  116. package/src/island.ts +219 -0
  117. package/src/islandSolve.ts +218 -0
  118. package/src/islandWorker.ts +141 -0
  119. package/src/joints.ts +1367 -0
  120. package/src/manifold.ts +798 -0
  121. package/src/mass.ts +424 -0
  122. package/src/meshContact.ts +443 -0
  123. package/src/meshShape.ts +261 -0
  124. package/src/pairs.ts +169 -0
  125. package/src/query.ts +844 -0
  126. package/src/ragdoll.ts +662 -0
  127. package/src/shape.ts +656 -0
  128. package/src/solver.ts +873 -0
  129. package/src/stage.ts +406 -0
  130. package/src/stallEscape.ts +362 -0
  131. package/src/sweptStep.ts +609 -0
  132. package/src/tree.ts +366 -0
  133. package/src/vehicle.ts +489 -0
  134. package/src/workerPool.ts +283 -0
  135. package/src/workers.ts +38 -0
  136. package/src/world.ts +961 -0
@@ -0,0 +1,109 @@
1
+ import { ColliderSet } from '../colliderSet.js';
2
+ import { hits } from './scratch.js';
3
+ /** What a ray hits: a segment tested against a collider set. */
4
+ /** Below this, a slab is treated as parallel to the segment. */
5
+ const PARALLEL_EPSILON = 1e-8;
6
+ /**
7
+ * Nearest obstruction along the segment `origin → origin + delta`, returned as
8
+ * a fraction of the segment in [0, 1] — 1 meaning unobstructed.
9
+ *
10
+ * Boxes are expanded by `radius`, which approximates sweeping a sphere: the
11
+ * caller (the third-person camera boom) then stops clear of surfaces instead of
12
+ * grazing them. Allocation-free; slab method, one pass over the boxes.
13
+ *
14
+ * Render-side only. Nothing here may be called from `simulate()`.
15
+ */
16
+ export function segmentHit(ox, oy, oz, dx, dy, dz, boxes, radius) {
17
+ let nearest = 1;
18
+ const count = boxes.query(Math.min(ox, ox + dx) - radius, Math.min(oy, oy + dy) - radius, Math.min(oz, oz + dz) - radius, Math.max(ox, ox + dx) + radius, Math.max(oy, oy + dy) + radius, Math.max(oz, oz + dz) + radius, hits);
19
+ const data = boxes.data;
20
+ // Support of the contact that finally clamps the move; true when unblocked.
21
+ let clampSupport = true;
22
+ for (let h = 0; h < count; h++) {
23
+ const index = hits[h] ?? 0;
24
+ const o = index * 6;
25
+ let tmin = 0;
26
+ let tmax = nearest;
27
+ let hit = true;
28
+ /*
29
+ * A shaped collider is clipped against its own face planes instead of its
30
+ * box's. The box is only the broad phase, and treating it as solid here is
31
+ * what made the camera pull in over the empty corner of every banked
32
+ * stretch, and a grapple anchor on drawn air. Each face direction bounds
33
+ * the shape as a slab of its vertex projections; a hull with fewer than
34
+ * three face lines cannot be bounded that way and keeps the box answer.
35
+ */
36
+ const shape = boxes.shapeAt(index);
37
+ if (shape !== undefined && shape.faceNormals.length >= 9) {
38
+ const fn = shape.faceNormals;
39
+ const v = shape.vertices;
40
+ for (let f = 0; f < fn.length && hit; f += 3) {
41
+ const nx = fn[f] ?? 0;
42
+ const ny = fn[f + 1] ?? 0;
43
+ const nz = fn[f + 2] ?? 0;
44
+ let lo = Infinity;
45
+ let hi = -Infinity;
46
+ for (let i = 0; i < v.length; i += 3) {
47
+ const p = (v[i] ?? 0) * nx + (v[i + 1] ?? 0) * ny + (v[i + 2] ?? 0) * nz;
48
+ if (p < lo)
49
+ lo = p;
50
+ if (p > hi)
51
+ hi = p;
52
+ }
53
+ lo -= shape.radius + radius;
54
+ hi += shape.radius + radius;
55
+ const at = ox * nx + oy * ny + oz * nz;
56
+ const rate = dx * nx + dy * ny + dz * nz;
57
+ if (rate > -PARALLEL_EPSILON && rate < PARALLEL_EPSILON) {
58
+ if (at < lo || at > hi)
59
+ hit = false;
60
+ continue;
61
+ }
62
+ let t1 = (lo - at) / rate;
63
+ let t2 = (hi - at) / rate;
64
+ if (t1 > t2) {
65
+ const swap = t1;
66
+ t1 = t2;
67
+ t2 = swap;
68
+ }
69
+ if (t1 > tmin)
70
+ tmin = t1;
71
+ if (t2 < tmax)
72
+ tmax = t2;
73
+ if (tmin > tmax)
74
+ hit = false;
75
+ }
76
+ if (hit && tmin < nearest)
77
+ nearest = tmin;
78
+ continue;
79
+ }
80
+ for (let axis = 0; axis < 3 && hit; axis++) {
81
+ const at = axis === 0 ? ox : axis === 1 ? oy : oz;
82
+ const d = axis === 0 ? dx : axis === 1 ? dy : dz;
83
+ const lo = (data[o + axis] ?? 0) - radius;
84
+ const hi = (data[o + 3 + axis] ?? 0) + radius;
85
+ if (d > -PARALLEL_EPSILON && d < PARALLEL_EPSILON) {
86
+ // Parallel to this slab: a miss unless the origin already lies inside.
87
+ if (at < lo || at > hi)
88
+ hit = false;
89
+ continue;
90
+ }
91
+ let t1 = (lo - at) / d;
92
+ let t2 = (hi - at) / d;
93
+ if (t1 > t2) {
94
+ const swap = t1;
95
+ t1 = t2;
96
+ t2 = swap;
97
+ }
98
+ if (t1 > tmin)
99
+ tmin = t1;
100
+ if (t2 < tmax)
101
+ tmax = t2;
102
+ if (tmin > tmax)
103
+ hit = false;
104
+ }
105
+ if (hit && tmin < nearest)
106
+ nearest = tmin;
107
+ }
108
+ return nearest;
109
+ }
@@ -0,0 +1,3 @@
1
+ import { ColliderSet } from '../colliderSet.ts';
2
+ import type { Axis, Body } from './body.ts';
3
+ export declare function moveAxis(body: Body, boxes: ColliderSet, axis: Axis, delta: number): number;