@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.
- package/LICENSE +202 -0
- package/NOTICE +9 -0
- package/README.md +503 -0
- package/dist/bodies.d.ts +121 -0
- package/dist/bodies.js +298 -0
- package/dist/buoyancy.d.ts +46 -0
- package/dist/buoyancy.js +45 -0
- package/dist/cloth.d.ts +226 -0
- package/dist/cloth.js +587 -0
- package/dist/collide/aabb.d.ts +10 -0
- package/dist/collide/aabb.js +11 -0
- package/dist/collide/body.d.ts +202 -0
- package/dist/collide/body.js +142 -0
- package/dist/collide/eject.d.ts +39 -0
- package/dist/collide/eject.js +142 -0
- package/dist/collide/index.d.ts +18 -0
- package/dist/collide/index.js +5 -0
- package/dist/collide/scratch.d.ts +8 -0
- package/dist/collide/scratch.js +9 -0
- package/dist/collide/segment.d.ts +12 -0
- package/dist/collide/segment.js +109 -0
- package/dist/collide/sweep.d.ts +3 -0
- package/dist/collide/sweep.js +1036 -0
- package/dist/colliderSet.d.ts +239 -0
- package/dist/colliderSet.js +546 -0
- package/dist/compoundContact.d.ts +70 -0
- package/dist/compoundContact.js +221 -0
- package/dist/controller.d.ts +351 -0
- package/dist/controller.js +641 -0
- package/dist/cylinder.d.ts +78 -0
- package/dist/cylinder.js +294 -0
- package/dist/cylinderContact.d.ts +7 -0
- package/dist/cylinderContact.js +704 -0
- package/dist/decompose.d.ts +105 -0
- package/dist/decompose.js +979 -0
- package/dist/events.d.ts +43 -0
- package/dist/events.js +95 -0
- package/dist/executor.d.ts +147 -0
- package/dist/executor.js +173 -0
- package/dist/faces.d.ts +26 -0
- package/dist/faces.js +34 -0
- package/dist/fingerprint.d.ts +61 -0
- package/dist/fingerprint.js +139 -0
- package/dist/groundMotor.d.ts +34 -0
- package/dist/groundMotor.js +41 -0
- package/dist/heightfieldShape.d.ts +128 -0
- package/dist/heightfieldShape.js +328 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +47 -0
- package/dist/island.d.ts +55 -0
- package/dist/island.js +227 -0
- package/dist/islandSolve.d.ts +70 -0
- package/dist/islandSolve.js +171 -0
- package/dist/islandWorker.d.ts +18 -0
- package/dist/islandWorker.js +125 -0
- package/dist/joints.d.ts +180 -0
- package/dist/joints.js +1094 -0
- package/dist/manifold.d.ts +89 -0
- package/dist/manifold.js +608 -0
- package/dist/mass.d.ts +53 -0
- package/dist/mass.js +353 -0
- package/dist/meshContact.d.ts +57 -0
- package/dist/meshContact.js +393 -0
- package/dist/meshShape.d.ts +76 -0
- package/dist/meshShape.js +175 -0
- package/dist/pairs.d.ts +62 -0
- package/dist/pairs.js +154 -0
- package/dist/query.d.ts +71 -0
- package/dist/query.js +683 -0
- package/dist/ragdoll.d.ts +135 -0
- package/dist/ragdoll.js +489 -0
- package/dist/shape.d.ts +177 -0
- package/dist/shape.js +533 -0
- package/dist/solver.d.ts +136 -0
- package/dist/solver.js +601 -0
- package/dist/stage.d.ts +167 -0
- package/dist/stage.js +350 -0
- package/dist/stallEscape.d.ts +141 -0
- package/dist/stallEscape.js +254 -0
- package/dist/sweptStep.d.ts +173 -0
- package/dist/sweptStep.js +472 -0
- package/dist/tree.d.ts +61 -0
- package/dist/tree.js +348 -0
- package/dist/vehicle.d.ts +154 -0
- package/dist/vehicle.js +343 -0
- package/dist/workerPool.d.ts +107 -0
- package/dist/workerPool.js +239 -0
- package/dist/workers.d.ts +37 -0
- package/dist/workers.js +35 -0
- package/dist/world.d.ts +298 -0
- package/dist/world.js +712 -0
- package/package.json +55 -0
- package/src/bodies.ts +369 -0
- package/src/buoyancy.ts +78 -0
- package/src/cloth.ts +734 -0
- package/src/collide/aabb.ts +28 -0
- package/src/collide/body.ts +336 -0
- package/src/collide/eject.ts +156 -0
- package/src/collide/index.ts +26 -0
- package/src/collide/scratch.ts +10 -0
- package/src/collide/segment.ts +127 -0
- package/src/collide/sweep.ts +1132 -0
- package/src/colliderSet.ts +637 -0
- package/src/compoundContact.ts +284 -0
- package/src/controller.ts +817 -0
- package/src/cylinder.ts +340 -0
- package/src/cylinderContact.ts +825 -0
- package/src/decompose.ts +1198 -0
- package/src/events.ts +108 -0
- package/src/executor.ts +224 -0
- package/src/faces.ts +37 -0
- package/src/fingerprint.ts +146 -0
- package/src/groundMotor.ts +53 -0
- package/src/heightfieldShape.ts +395 -0
- package/src/index.ts +164 -0
- package/src/island.ts +219 -0
- package/src/islandSolve.ts +218 -0
- package/src/islandWorker.ts +141 -0
- package/src/joints.ts +1367 -0
- package/src/manifold.ts +798 -0
- package/src/mass.ts +424 -0
- package/src/meshContact.ts +443 -0
- package/src/meshShape.ts +261 -0
- package/src/pairs.ts +169 -0
- package/src/query.ts +844 -0
- package/src/ragdoll.ts +662 -0
- package/src/shape.ts +656 -0
- package/src/solver.ts +873 -0
- package/src/stage.ts +406 -0
- package/src/stallEscape.ts +362 -0
- package/src/sweptStep.ts +609 -0
- package/src/tree.ts +366 -0
- package/src/vehicle.ts +489 -0
- package/src/workerPool.ts +283 -0
- package/src/workers.ts +38 -0
- 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
|
+
}
|