@adatechnology/game-destruction-three 1.0.0 → 1.1.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/README.md +8 -0
- package/dist/index.d.ts +26 -5
- package/dist/index.global.js +710 -120
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +580 -95
- package/dist/index.js.map +1 -1
- package/dist/worker-kinds.d.ts +16 -0
- package/dist/worker-kinds.js +40 -2
- package/dist/worker-kinds.js.map +1 -1
- package/package.json +10 -10
package/dist/index.global.js
CHANGED
|
@@ -8561,7 +8561,7 @@ var GameDestructionThree = (() => {
|
|
|
8561
8561
|
return sources;
|
|
8562
8562
|
}
|
|
8563
8563
|
|
|
8564
|
-
// ../game-vfx-three/dist/chunk-
|
|
8564
|
+
// ../game-vfx-three/dist/chunk-ACY6ZQC5.js
|
|
8565
8565
|
var GLOW_VERTEX = `attribute vec4 aP;attribute vec4 aC;varying vec2 vU;varying vec4 vC;
|
|
8566
8566
|
void main(){vec3 R=vec3(viewMatrix[0][0],viewMatrix[1][0],viewMatrix[2][0]);vec3 Up=vec3(viewMatrix[0][1],viewMatrix[1][1],viewMatrix[2][1]);
|
|
8567
8567
|
vec3 wp=aP.xyz+(R*position.x+Up*position.y)*aP.w;vU=position.xy;vC=aC;gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.);}`;
|
|
@@ -9609,8 +9609,48 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9609
9609
|
}
|
|
9610
9610
|
};
|
|
9611
9611
|
}
|
|
9612
|
-
var
|
|
9613
|
-
var
|
|
9612
|
+
var REST_STEP = 15e-4;
|
|
9613
|
+
var REST_TRIES = 8;
|
|
9614
|
+
var SAME_NORMAL = 0.9995;
|
|
9615
|
+
var restBox = () => ({ c: new Float64Array(3), axes: new Float64Array(9), half: new Float64Array(3), ext: new Float64Array(3) });
|
|
9616
|
+
function boxOf(piece, out) {
|
|
9617
|
+
const cx = Math.cos(piece.rx), sx = Math.sin(piece.rx), cy = Math.cos(piece.ry), sy = Math.sin(piece.ry), cz = Math.cos(piece.rz), sz = Math.sin(piece.rz);
|
|
9618
|
+
const a = out.axes;
|
|
9619
|
+
a[0] = cy * cz;
|
|
9620
|
+
a[1] = sx * sy * cz + cx * sz;
|
|
9621
|
+
a[2] = sx * sz - cx * sy * cz;
|
|
9622
|
+
a[3] = -cy * sz;
|
|
9623
|
+
a[4] = cx * cz - sx * sy * sz;
|
|
9624
|
+
a[5] = cx * sy * sz + sx * cz;
|
|
9625
|
+
a[6] = sy;
|
|
9626
|
+
a[7] = -sx * cy;
|
|
9627
|
+
a[8] = cx * cy;
|
|
9628
|
+
out.half[0] = piece.sx / 2;
|
|
9629
|
+
out.half[1] = piece.sy / 2;
|
|
9630
|
+
out.half[2] = piece.sz / 2;
|
|
9631
|
+
out.c[0] = piece.x;
|
|
9632
|
+
out.c[1] = piece.y;
|
|
9633
|
+
out.c[2] = piece.z;
|
|
9634
|
+
for (let w = 0; w < 3; w++) out.ext[w] = Math.abs(a[w]) * out.half[0] + Math.abs(a[3 + w]) * out.half[1] + Math.abs(a[6 + w]) * out.half[2];
|
|
9635
|
+
}
|
|
9636
|
+
function sharedPlane(a, b, push) {
|
|
9637
|
+
for (let w = 0; w < 3; w++) if (Math.abs(a.c[w] - b.c[w]) >= a.ext[w] + b.ext[w] + REST_STEP) return false;
|
|
9638
|
+
for (let i = 0; i < 3; i++) for (let j = 0; j < 3; j++) {
|
|
9639
|
+
const ax = a.axes[3 * i], ay = a.axes[3 * i + 1], az = a.axes[3 * i + 2];
|
|
9640
|
+
const dot3 = ax * b.axes[3 * j] + ay * b.axes[3 * j + 1] + az * b.axes[3 * j + 2];
|
|
9641
|
+
if (Math.abs(dot3) < SAME_NORMAL) continue;
|
|
9642
|
+
const ca = ax * a.c[0] + ay * a.c[1] + az * a.c[2];
|
|
9643
|
+
const cb = ax * b.c[0] + ay * b.c[1] + az * b.c[2];
|
|
9644
|
+
for (let side = -1; side <= 1; side += 2) {
|
|
9645
|
+
if (Math.abs(ca + side * a.half[i] - (cb + side * b.half[j])) >= REST_STEP * 0.75) continue;
|
|
9646
|
+
push[0] = ax * side;
|
|
9647
|
+
push[1] = ay * side;
|
|
9648
|
+
push[2] = az * side;
|
|
9649
|
+
return true;
|
|
9650
|
+
}
|
|
9651
|
+
}
|
|
9652
|
+
return false;
|
|
9653
|
+
}
|
|
9614
9654
|
function debrisLayer(THREE, pool) {
|
|
9615
9655
|
const geometry = new THREE.BoxGeometry(1, 1, 1);
|
|
9616
9656
|
const material = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.45, metalness: 0.25, flatShading: true });
|
|
@@ -9625,6 +9665,36 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9625
9665
|
const matrix = new THREE.Matrix4();
|
|
9626
9666
|
const colour = new THREE.Color();
|
|
9627
9667
|
const hidden = new THREE.Matrix4().makeScale(0, 0, 0);
|
|
9668
|
+
const offset = new Float64Array(DEBRIS_CAPACITY * 3);
|
|
9669
|
+
const settled = new Uint8Array(DEBRIS_CAPACITY);
|
|
9670
|
+
const boxes = Array.from({ length: DEBRIS_CAPACITY }, restBox);
|
|
9671
|
+
const push = new Float64Array(3);
|
|
9672
|
+
const settle = (index) => {
|
|
9673
|
+
const box = boxes[index];
|
|
9674
|
+
boxOf(pool.pieces[index], box);
|
|
9675
|
+
let dx = 0, dy = 0, dz = 0;
|
|
9676
|
+
for (let tries = 0; tries < REST_TRIES; tries++) {
|
|
9677
|
+
let clash = false;
|
|
9678
|
+
for (let other = 0; other < DEBRIS_CAPACITY && !clash; other++) {
|
|
9679
|
+
if (other === index || !settled[other]) continue;
|
|
9680
|
+
if (!sharedPlane(box, boxes[other], push)) continue;
|
|
9681
|
+
clash = true;
|
|
9682
|
+
const up = Math.abs(push[1]) > 0.7;
|
|
9683
|
+
const ux = up ? 0 : push[0], uy = up ? 1 : push[1], uz = up ? 0 : push[2];
|
|
9684
|
+
dx += ux * REST_STEP;
|
|
9685
|
+
dy += uy * REST_STEP;
|
|
9686
|
+
dz += uz * REST_STEP;
|
|
9687
|
+
box.c[0] = box.c[0] + ux * REST_STEP;
|
|
9688
|
+
box.c[1] = box.c[1] + uy * REST_STEP;
|
|
9689
|
+
box.c[2] = box.c[2] + uz * REST_STEP;
|
|
9690
|
+
}
|
|
9691
|
+
if (!clash) break;
|
|
9692
|
+
}
|
|
9693
|
+
offset[3 * index] = dx;
|
|
9694
|
+
offset[3 * index + 1] = dy;
|
|
9695
|
+
offset[3 * index + 2] = dz;
|
|
9696
|
+
settled[index] = 1;
|
|
9697
|
+
};
|
|
9628
9698
|
for (let index = 0; index < DEBRIS_CAPACITY; index++) mesh2.setMatrixAt(index, hidden);
|
|
9629
9699
|
mesh2.setColorAt(0, colour.setHex(16777215));
|
|
9630
9700
|
return {
|
|
@@ -9633,16 +9703,18 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9633
9703
|
let drawn = false;
|
|
9634
9704
|
for (let index = 0; index < DEBRIS_CAPACITY; index++) {
|
|
9635
9705
|
const piece = pool.pieces[index];
|
|
9706
|
+
if (!piece.on || !piece.rest) settled[index] = 0;
|
|
9636
9707
|
if (!piece.on) {
|
|
9637
9708
|
mesh2.setMatrixAt(index, hidden);
|
|
9638
9709
|
continue;
|
|
9639
9710
|
}
|
|
9711
|
+
if (piece.rest && !settled[index]) settle(index);
|
|
9640
9712
|
drawn = true;
|
|
9641
9713
|
const shrink = Math.min(1, piece.life / FADE_SECONDS2);
|
|
9642
9714
|
euler.set(piece.rx, piece.ry, piece.rz);
|
|
9643
9715
|
quaternion.setFromEuler(euler);
|
|
9644
|
-
const
|
|
9645
|
-
matrix.compose(position.set(piece.x, piece.y +
|
|
9716
|
+
const off2 = piece.rest ? 3 * index : -1;
|
|
9717
|
+
matrix.compose(position.set(piece.x + (off2 >= 0 ? offset[off2] : 0), piece.y + (off2 >= 0 ? offset[off2 + 1] : 0), piece.z + (off2 >= 0 ? offset[off2 + 2] : 0)), quaternion, scale.set(piece.sx * shrink, piece.sy * shrink, piece.sz * shrink));
|
|
9646
9718
|
mesh2.setMatrixAt(index, matrix);
|
|
9647
9719
|
mesh2.setColorAt(index, colour.setHex(piece.color));
|
|
9648
9720
|
}
|
|
@@ -11191,18 +11263,18 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11191
11263
|
let by = b[bi + 1];
|
|
11192
11264
|
let bz = b[bi + 2];
|
|
11193
11265
|
let bw = b[bi + 3];
|
|
11194
|
-
let
|
|
11195
|
-
if (
|
|
11266
|
+
let dot3 = ax * bx + ay * by + az * bz + aw * bw;
|
|
11267
|
+
if (dot3 < 0) {
|
|
11196
11268
|
bx = -bx;
|
|
11197
11269
|
by = -by;
|
|
11198
11270
|
bz = -bz;
|
|
11199
11271
|
bw = -bw;
|
|
11200
|
-
|
|
11272
|
+
dot3 = -dot3;
|
|
11201
11273
|
}
|
|
11202
11274
|
let from = 1 - t;
|
|
11203
11275
|
let to = t;
|
|
11204
|
-
if (
|
|
11205
|
-
const angle = Math.acos(
|
|
11276
|
+
if (dot3 < 0.9995) {
|
|
11277
|
+
const angle = Math.acos(dot3);
|
|
11206
11278
|
const sine = Math.sin(angle);
|
|
11207
11279
|
from = Math.sin((1 - t) * angle) / sine;
|
|
11208
11280
|
to = Math.sin(t * angle) / sine;
|
|
@@ -12039,6 +12111,21 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12039
12111
|
return { center: box.center, half };
|
|
12040
12112
|
};
|
|
12041
12113
|
|
|
12114
|
+
// src/built-solids.ts
|
|
12115
|
+
var numbers = (value, count) => Array.isArray(value) && value.length === count && value.every((v) => typeof v === "number" && Number.isFinite(v));
|
|
12116
|
+
var isBuiltSolid = (value) => {
|
|
12117
|
+
if (typeof value !== "object" || value === null) return false;
|
|
12118
|
+
const solid = value;
|
|
12119
|
+
return numbers(solid.center, 3) && numbers(solid.half, 3) && numbers(solid.rotation, 4) && (solid.kind === void 0 || typeof solid.kind === "string");
|
|
12120
|
+
};
|
|
12121
|
+
var builtSolidsOf = (mesh2) => {
|
|
12122
|
+
const list = mesh2.userData.solids;
|
|
12123
|
+
if (!Array.isArray(list) || list.length === 0 || !list.every(isBuiltSolid)) return null;
|
|
12124
|
+
return list;
|
|
12125
|
+
};
|
|
12126
|
+
var ROUND_SIDES = 0.05;
|
|
12127
|
+
var isRoundSolid = (solid) => solid.kind === "cylinder" && Math.abs(solid.half[0] - solid.half[2]) <= ROUND_SIDES * Math.max(solid.half[0], solid.half[2]);
|
|
12128
|
+
|
|
12042
12129
|
// ../game-shapes/dist/index.js
|
|
12043
12130
|
var MIN_HALF = 0.01;
|
|
12044
12131
|
var MAX_DEPTH = 3;
|
|
@@ -12289,6 +12376,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12289
12376
|
// src/static-part-job.ts
|
|
12290
12377
|
var FIT = 0.01;
|
|
12291
12378
|
var FILL = 0.5;
|
|
12379
|
+
var SOLID = 0.5;
|
|
12292
12380
|
var MIN_HALF2 = 5e-3;
|
|
12293
12381
|
var COLLAPSED = 2e-3;
|
|
12294
12382
|
var MIN_FACE = 1e-6;
|
|
@@ -12325,10 +12413,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12325
12413
|
const size = [high[0] - low[0], high[1] - low[1], high[2] - low[2]];
|
|
12326
12414
|
const s = [Math.abs(scale[0]), Math.abs(scale[1]), Math.abs(scale[2])];
|
|
12327
12415
|
if (Math.max(size[0] * s[0], size[1] * s[1], size[2] * s[2]) < COLLAPSED) return [];
|
|
12416
|
+
if (job.solids && job.solids.length > 0) return job.solids.map((solid) => builtSolidIn(solid, pos, quat2, scale));
|
|
12328
12417
|
const centre = [(low[0] + high[0]) / 2, (low[1] + high[1]) / 2, (low[2] + high[2]) / 2];
|
|
12329
12418
|
const half = [size[0] / 2, size[1] / 2, size[2] / 2];
|
|
12330
12419
|
const straight = { center: centre, half, axes: IDENTITY2, tolerance: [FIT / s[0], FIT / s[1], FIT / s[2]] };
|
|
12331
|
-
if (hugs(points, straight) && fillsFaces(points, found, from, straight)) {
|
|
12420
|
+
if (hugs(points, straight) && fillsFaces(points, found, from, straight) && fillsVolume(points, found, from, straight)) {
|
|
12332
12421
|
const [cx, cy, cz] = turn(centre[0] * scale[0], centre[1] * scale[1], centre[2] * scale[2], quat2);
|
|
12333
12422
|
return [{ center: [cx + pos[0], cy + pos[1], cz + pos[2]], half: [Math.max(MIN_HALF2, half[0] * s[0]), Math.max(MIN_HALF2, half[1] * s[1]), Math.max(MIN_HALF2, half[2] * s[2])], rotation: [quat2[0], quat2[1], quat2[2], quat2[3]] }];
|
|
12334
12423
|
}
|
|
@@ -12341,9 +12430,24 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12341
12430
|
world[i + 2] = e[2] * x + e[6] * y + e[10] * z + e[14];
|
|
12342
12431
|
}
|
|
12343
12432
|
const turned = fitOrientedBox(world);
|
|
12344
|
-
if (turned && fitsTurned(world, turned) && fillsFaces(world, found, from, turnedBox(turned))) return [turned];
|
|
12433
|
+
if (turned && fitsTurned(world, turned) && fillsFaces(world, found, from, turnedBox(turned)) && fillsVolume(world, found, from, turnedBox(turned))) return [turned];
|
|
12345
12434
|
return [trimeshOf(world, from, found)];
|
|
12346
12435
|
}
|
|
12436
|
+
var builtSolidIn = (solid, pos, quat2, scale) => {
|
|
12437
|
+
const [cx, cy, cz] = turn(solid.center[0] * scale[0], solid.center[1] * scale[1], solid.center[2] * scale[2], quat2);
|
|
12438
|
+
const [ax, ay, az, aw] = quat2;
|
|
12439
|
+
const [bx, by, bz, bw] = solid.rotation;
|
|
12440
|
+
const turned = Math.abs(bw) < 1 - 1e-9;
|
|
12441
|
+
const even = (Math.abs(scale[0]) + Math.abs(scale[1]) + Math.abs(scale[2])) / 3;
|
|
12442
|
+
const s = turned ? [even, even, even] : [Math.abs(scale[0]), Math.abs(scale[1]), Math.abs(scale[2])];
|
|
12443
|
+
return {
|
|
12444
|
+
...isRoundSolid(solid) && Math.abs(s[0] - s[2]) <= 1e-9 ? { round: true } : {},
|
|
12445
|
+
center: [cx + pos[0], cy + pos[1], cz + pos[2]],
|
|
12446
|
+
half: [Math.max(MIN_HALF2, solid.half[0] * s[0]), Math.max(MIN_HALF2, solid.half[1] * s[1]), Math.max(MIN_HALF2, solid.half[2] * s[2])],
|
|
12447
|
+
// the mesh's turn, then the solid's own
|
|
12448
|
+
rotation: [aw * bx + ax * bw + ay * bz - az * by, aw * by - ax * bz + ay * bw + az * bx, aw * bz + ax * by - ay * bx + az * bw, aw * bw - ax * bx - ay * by - az * bz]
|
|
12449
|
+
};
|
|
12450
|
+
};
|
|
12347
12451
|
var staticSolidsTransfer = (solids) => {
|
|
12348
12452
|
const out = [];
|
|
12349
12453
|
for (const solid of solids) if (solid.mesh) out.push(solid.mesh.vertices.buffer, solid.mesh.indices.buffer);
|
|
@@ -12382,6 +12486,21 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
12382
12486
|
}
|
|
12383
12487
|
return true;
|
|
12384
12488
|
};
|
|
12489
|
+
var fillsVolume = (points, found, from, box) => {
|
|
12490
|
+
if (found.length === 0) return true;
|
|
12491
|
+
const whole = 8 * box.half[0] * box.half[1] * box.half[2];
|
|
12492
|
+
if (!(whole > 0)) return true;
|
|
12493
|
+
const [cx, cy, cz] = box.center;
|
|
12494
|
+
let six = 0;
|
|
12495
|
+
for (let i = 0; i + 2 < found.length; i += 3) {
|
|
12496
|
+
const a = (found[i] - from) * 3, b = (found[i + 1] - from) * 3, c = (found[i + 2] - from) * 3;
|
|
12497
|
+
const ax = points[a] - cx, ay = points[a + 1] - cy, az = points[a + 2] - cz;
|
|
12498
|
+
const bx = points[b] - cx, by = points[b + 1] - cy, bz = points[b + 2] - cz;
|
|
12499
|
+
const dx = points[c] - cx, dy = points[c + 1] - cy, dz = points[c + 2] - cz;
|
|
12500
|
+
six += ax * (by * dz - bz * dy) + ay * (bz * dx - bx * dz) + az * (bx * dy - by * dx);
|
|
12501
|
+
}
|
|
12502
|
+
return Math.abs(six) / 6 >= whole * SOLID;
|
|
12503
|
+
};
|
|
12385
12504
|
var trimeshOf = (world, from, found) => {
|
|
12386
12505
|
const indices = new Uint32Array(found.length);
|
|
12387
12506
|
for (let i = 0; i < found.length; i++) indices[i] = found[i] - from;
|
|
@@ -13373,6 +13492,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13373
13492
|
const quat2 = new THREE.Quaternion();
|
|
13374
13493
|
const scale = new THREE.Vector3();
|
|
13375
13494
|
mv.mesh.matrixWorld.decompose(pos, quat2, scale);
|
|
13495
|
+
const built2 = mv.range ? null : builtSolidsOf(mv.mesh);
|
|
13376
13496
|
return {
|
|
13377
13497
|
points,
|
|
13378
13498
|
matrix: Float64Array.from(matrix),
|
|
@@ -13380,7 +13500,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13380
13500
|
quaternion: [quat2.x, quat2.y, quat2.z, quat2.w],
|
|
13381
13501
|
scale: [scale.x, scale.y, scale.z],
|
|
13382
13502
|
found: Uint32Array.from(trianglesOfPart(mv, local2)),
|
|
13383
|
-
from: local2.from
|
|
13503
|
+
from: local2.from,
|
|
13504
|
+
// a mesh of its own that says what it was built from is held by that (a part of a merged mesh is only some of its mesh)
|
|
13505
|
+
...built2 ? { solids: built2 } : {}
|
|
13384
13506
|
};
|
|
13385
13507
|
};
|
|
13386
13508
|
var trianglesOfRanges = (mv, ranges) => {
|
|
@@ -13424,41 +13546,99 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13424
13546
|
var BOX_VERTICES = 24;
|
|
13425
13547
|
var MAX_BOXES = 16;
|
|
13426
13548
|
var CORNER = 1e-4;
|
|
13427
|
-
var
|
|
13428
|
-
var
|
|
13549
|
+
var RANGED = { share: 0.5, turned: false };
|
|
13550
|
+
var OWN_MESH = { share: 0.8, turned: true };
|
|
13551
|
+
var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
13552
|
+
var quaternionOf = (x, y, z) => {
|
|
13553
|
+
const [m00, m10, m20] = x;
|
|
13554
|
+
const [m01, m11, m21] = y;
|
|
13555
|
+
const [m02, m12, m22] = z;
|
|
13556
|
+
const trace = m00 + m11 + m22;
|
|
13557
|
+
if (trace > 0) {
|
|
13558
|
+
const s2 = 0.5 / Math.sqrt(trace + 1);
|
|
13559
|
+
return [(m21 - m12) * s2, (m02 - m20) * s2, (m10 - m01) * s2, 0.25 / s2];
|
|
13560
|
+
}
|
|
13561
|
+
if (m00 > m11 && m00 > m22) {
|
|
13562
|
+
const s2 = 2 * Math.sqrt(1 + m00 - m11 - m22);
|
|
13563
|
+
return [0.25 * s2, (m01 + m10) / s2, (m02 + m20) / s2, (m21 - m12) / s2];
|
|
13564
|
+
}
|
|
13565
|
+
if (m11 > m22) {
|
|
13566
|
+
const s2 = 2 * Math.sqrt(1 + m11 - m00 - m22);
|
|
13567
|
+
return [(m01 + m10) / s2, 0.25 * s2, (m12 + m21) / s2, (m02 - m20) / s2];
|
|
13568
|
+
}
|
|
13569
|
+
const s = 2 * Math.sqrt(1 + m22 - m00 - m11);
|
|
13570
|
+
return [(m02 + m20) / s, (m12 + m21) / s, 0.25 * s, (m10 - m01) / s];
|
|
13571
|
+
};
|
|
13572
|
+
var straightBoxOf = (points, first) => {
|
|
13573
|
+
const low = [Infinity, Infinity, Infinity];
|
|
13574
|
+
const high = [-Infinity, -Infinity, -Infinity];
|
|
13575
|
+
for (let v = first; v < first + BOX_VERTICES; v++) {
|
|
13576
|
+
for (let k = 0; k < 3; k++) {
|
|
13577
|
+
low[k] = Math.min(low[k], points[v * 3 + k]);
|
|
13578
|
+
high[k] = Math.max(high[k], points[v * 3 + k]);
|
|
13579
|
+
}
|
|
13580
|
+
}
|
|
13581
|
+
const corners = /* @__PURE__ */ new Set();
|
|
13582
|
+
for (let v = first; v < first + BOX_VERTICES; v++) {
|
|
13583
|
+
let corner = 0;
|
|
13584
|
+
for (let k = 0; k < 3; k++) {
|
|
13585
|
+
const x = points[v * 3 + k];
|
|
13586
|
+
if (Math.abs(x - high[k]) <= CORNER) corner |= 1 << k;
|
|
13587
|
+
else if (Math.abs(x - low[k]) > CORNER) return null;
|
|
13588
|
+
}
|
|
13589
|
+
corners.add(corner);
|
|
13590
|
+
}
|
|
13591
|
+
if (corners.size !== 8) return null;
|
|
13592
|
+
return { center: [(low[0] + high[0]) / 2, (low[1] + high[1]) / 2, (low[2] + high[2]) / 2], half: [(high[0] - low[0]) / 2, (high[1] - low[1]) / 2, (high[2] - low[2]) / 2] };
|
|
13593
|
+
};
|
|
13594
|
+
var turnedBoxOf = (points, first) => {
|
|
13595
|
+
const corners = [];
|
|
13596
|
+
for (let v = first; v < first + BOX_VERTICES; v++) {
|
|
13597
|
+
const p = [points[v * 3], points[v * 3 + 1], points[v * 3 + 2]];
|
|
13598
|
+
if (!corners.some((c) => Math.abs(c[0] - p[0]) <= CORNER && Math.abs(c[1] - p[1]) <= CORNER && Math.abs(c[2] - p[2]) <= CORNER)) corners.push(p);
|
|
13599
|
+
}
|
|
13600
|
+
if (corners.length !== 8) return null;
|
|
13601
|
+
const origin = corners[0];
|
|
13602
|
+
const edges = corners.slice(1).map((c) => [c[0] - origin[0], c[1] - origin[1], c[2] - origin[2]]);
|
|
13603
|
+
const lengths = edges.map((e) => Math.hypot(e[0], e[1], e[2]));
|
|
13604
|
+
const square = (i, j) => Math.abs(dot(edges[i], edges[j])) <= CORNER * (lengths[i] + lengths[j] + 1);
|
|
13605
|
+
for (let i = 0; i < 7; i++) for (let j = i + 1; j < 7; j++) for (let k = j + 1; k < 7; k++) {
|
|
13606
|
+
if (!square(i, j) || !square(i, k) || !square(j, k)) continue;
|
|
13607
|
+
const [a, b, c] = [edges[i], edges[j], edges[k]];
|
|
13608
|
+
const sums = [[0, 0, 0], a, b, c, [a[0] + b[0], a[1] + b[1], a[2] + b[2]], [a[0] + c[0], a[1] + c[1], a[2] + c[2]], [b[0] + c[0], b[1] + c[1], b[2] + c[2]], [a[0] + b[0] + c[0], a[1] + b[1] + c[1], a[2] + b[2] + c[2]]];
|
|
13609
|
+
const found = sums.every((s) => corners.some((p) => Math.abs(p[0] - origin[0] - s[0]) <= 4 * CORNER && Math.abs(p[1] - origin[1] - s[1]) <= 4 * CORNER && Math.abs(p[2] - origin[2] - s[2]) <= 4 * CORNER));
|
|
13610
|
+
if (!found) continue;
|
|
13611
|
+
const [la, lb, lc] = [lengths[i], lengths[j], lengths[k]];
|
|
13612
|
+
if (la <= 0 || lb <= 0 || lc <= 0) return null;
|
|
13613
|
+
const x = [a[0] / la, a[1] / la, a[2] / la];
|
|
13614
|
+
const y = [b[0] / lb, b[1] / lb, b[2] / lb];
|
|
13615
|
+
let z = [c[0] / lc, c[1] / lc, c[2] / lc];
|
|
13616
|
+
const cross5 = [x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0]];
|
|
13617
|
+
if (dot(cross5, z) < 0) z = [-z[0], -z[1], -z[2]];
|
|
13618
|
+
const far2 = sums[7];
|
|
13619
|
+
return { center: [origin[0] + far2[0] / 2, origin[1] + far2[1] / 2, origin[2] + far2[2] / 2], half: [la / 2, lb / 2, lc / 2], rotation: quaternionOf(x, y, z) };
|
|
13620
|
+
}
|
|
13621
|
+
return null;
|
|
13622
|
+
};
|
|
13623
|
+
var hollowBoxesOf = (points, rule = RANGED) => {
|
|
13429
13624
|
const count = points.length / 3;
|
|
13430
|
-
if (count % BOX_VERTICES !== 0 || count / BOX_VERTICES < 2 || count / BOX_VERTICES > MAX_BOXES) return null;
|
|
13625
|
+
if (count % BOX_VERTICES !== 0 || count / BOX_VERTICES < (rule.turned ? 1 : 2) || count / BOX_VERTICES > MAX_BOXES) return null;
|
|
13431
13626
|
const boxes = [];
|
|
13432
|
-
const
|
|
13627
|
+
const low = [Infinity, Infinity, Infinity];
|
|
13628
|
+
const high = [-Infinity, -Infinity, -Infinity];
|
|
13433
13629
|
for (let first = 0; first < count; first += BOX_VERTICES) {
|
|
13434
|
-
const
|
|
13435
|
-
|
|
13436
|
-
|
|
13437
|
-
|
|
13438
|
-
|
|
13439
|
-
high[k] = Math.max(high[k], points[v * 3 + k]);
|
|
13440
|
-
}
|
|
13441
|
-
}
|
|
13442
|
-
const corners = /* @__PURE__ */ new Set();
|
|
13443
|
-
for (let v = first; v < first + BOX_VERTICES; v++) {
|
|
13444
|
-
let corner = 0;
|
|
13445
|
-
for (let k = 0; k < 3; k++) {
|
|
13446
|
-
const x = points[v * 3 + k];
|
|
13447
|
-
if (Math.abs(x - high[k]) <= CORNER) corner |= 1 << k;
|
|
13448
|
-
else if (Math.abs(x - low[k]) > CORNER) return null;
|
|
13449
|
-
}
|
|
13450
|
-
corners.add(corner);
|
|
13451
|
-
}
|
|
13452
|
-
if (corners.size !== 8) return null;
|
|
13630
|
+
const box = straightBoxOf(points, first) ?? (rule.turned ? turnedBoxOf(points, first) : null);
|
|
13631
|
+
if (!box) return null;
|
|
13632
|
+
boxes.push(box);
|
|
13633
|
+
}
|
|
13634
|
+
for (let i = 0; i < points.length; i += 3) {
|
|
13453
13635
|
for (let k = 0; k < 3; k++) {
|
|
13454
|
-
|
|
13455
|
-
|
|
13636
|
+
low[k] = Math.min(low[k], points[i + k]);
|
|
13637
|
+
high[k] = Math.max(high[k], points[i + k]);
|
|
13456
13638
|
}
|
|
13457
|
-
boxes.push({ low, high });
|
|
13458
13639
|
}
|
|
13459
|
-
const
|
|
13460
|
-
|
|
13461
|
-
return filled < HOLLOW * volume(all.low, all.high) ? boxes : null;
|
|
13640
|
+
const filled = boxes.reduce((sum, box) => sum + 8 * box.half[0] * box.half[1] * box.half[2], 0);
|
|
13641
|
+
return filled < rule.share * (high[0] - low[0]) * (high[1] - low[1]) * (high[2] - low[2]) ? boxes : null;
|
|
13462
13642
|
};
|
|
13463
13643
|
|
|
13464
13644
|
// src/rigid-pose.ts
|
|
@@ -13510,7 +13690,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13510
13690
|
row(2 * (x * z - y * w), 2 * (y * z + x * w), 1 - 2 * (x * x + y * y))
|
|
13511
13691
|
];
|
|
13512
13692
|
};
|
|
13513
|
-
var shapeOf = (s) =>
|
|
13693
|
+
var shapeOf = (s) => {
|
|
13694
|
+
if (s.mesh) return { kind: "trimesh", vertices: s.mesh.vertices, indices: s.mesh.indices };
|
|
13695
|
+
if (s.round) return { kind: "cylinder", halfHeight: s.half[1], radius: (s.half[0] + s.half[2]) / 2 };
|
|
13696
|
+
return { kind: "box", half: s.half };
|
|
13697
|
+
};
|
|
13514
13698
|
var EngineStatics = class {
|
|
13515
13699
|
constructor(world, material) {
|
|
13516
13700
|
__publicField(this, "world", world);
|
|
@@ -13756,30 +13940,30 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13756
13940
|
var SEGMENT_BOX_ROUNDS = 4;
|
|
13757
13941
|
var PARALLEL2 = 1e-4;
|
|
13758
13942
|
var sub2 = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
13759
|
-
var
|
|
13943
|
+
var dot2 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
13760
13944
|
var along = (a, d, t) => [a[0] + d[0] * t, a[1] + d[1] * t, a[2] + d[2] * t];
|
|
13761
13945
|
var clamp01 = (t) => t < 0 ? 0 : t > 1 ? 1 : t;
|
|
13762
13946
|
var nearestOnSegment = (from, to, p) => {
|
|
13763
13947
|
const d = sub2(to, from);
|
|
13764
|
-
const len2 =
|
|
13765
|
-
return len2 < 1e-12 ? from : along(from, d, clamp01(
|
|
13948
|
+
const len2 = dot2(d, d);
|
|
13949
|
+
return len2 < 1e-12 ? from : along(from, d, clamp01(dot2(sub2(p, from), d) / len2));
|
|
13766
13950
|
};
|
|
13767
13951
|
var nearestOfSegments = (p1, q1, p2, q2) => {
|
|
13768
13952
|
const d1 = sub2(q1, p1);
|
|
13769
13953
|
const d2 = sub2(q2, p2);
|
|
13770
13954
|
const r = sub2(p1, p2);
|
|
13771
|
-
const a =
|
|
13772
|
-
const e =
|
|
13773
|
-
const f =
|
|
13955
|
+
const a = dot2(d1, d1);
|
|
13956
|
+
const e = dot2(d2, d2);
|
|
13957
|
+
const f = dot2(d2, r);
|
|
13774
13958
|
let s = 0;
|
|
13775
13959
|
let t = 0;
|
|
13776
13960
|
if (a < 1e-12 && e < 1e-12) return [p1, p2];
|
|
13777
13961
|
if (a < 1e-12) t = clamp01(f / e);
|
|
13778
13962
|
else {
|
|
13779
|
-
const c =
|
|
13963
|
+
const c = dot2(d1, r);
|
|
13780
13964
|
if (e < 1e-12) s = clamp01(-c / a);
|
|
13781
13965
|
else {
|
|
13782
|
-
const b =
|
|
13966
|
+
const b = dot2(d1, d2);
|
|
13783
13967
|
const denom = a * e - b * b;
|
|
13784
13968
|
if (denom > PARALLEL2 * a * e) s = clamp01((b * f - c * e) / denom);
|
|
13785
13969
|
else {
|
|
@@ -13893,8 +14077,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13893
14077
|
}
|
|
13894
14078
|
const normal = [nx, ny, nz];
|
|
13895
14079
|
const mid = [(a.c[0] + b.c[0]) / 2, (a.c[1] + b.c[1]) / 2, (a.c[2] + b.c[2]) / 2];
|
|
13896
|
-
const middle = (
|
|
13897
|
-
return { point: along(mid, normal, middle -
|
|
14080
|
+
const middle = (dot2(a.c, normal) - reachAlong2(a, nx, ny, nz) + dot2(b.c, normal) + reachAlong2(b, nx, ny, nz)) / 2;
|
|
14081
|
+
return { point: along(mid, normal, middle - dot2(mid, normal)), normal, depth };
|
|
13898
14082
|
};
|
|
13899
14083
|
var LEVEL_SHARE = 1e-3;
|
|
13900
14084
|
var boxBoxAlongGround = (a, b) => {
|
|
@@ -14375,7 +14559,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14375
14559
|
return a.rotation.every((v, i) => Math.abs(v - b.rotation[i]) < FLUSH);
|
|
14376
14560
|
};
|
|
14377
14561
|
var flushAxis = (a, b) => {
|
|
14378
|
-
if (!sameTurn(a, b)) return -1;
|
|
14562
|
+
if (a.round || b.round || a.hull || b.hull || !sameTurn(a, b)) return -1;
|
|
14379
14563
|
let along2 = -1;
|
|
14380
14564
|
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
14381
14565
|
const same2 = Math.abs(a.half[axis2] - b.half[axis2]) < FLUSH && Math.abs(a.center[axis2] - b.center[axis2]) < FLUSH;
|
|
@@ -14899,7 +15083,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14899
15083
|
return { kind: "compound", children: [{ shape: { kind: "cylinder", halfHeight: b.halfExtents[round2.axis], radius: round2.radius }, position: [0, 0, 0], rotation: rotation2 }] };
|
|
14900
15084
|
}
|
|
14901
15085
|
if (b.partBoxes && b.partBoxes.length > 0) {
|
|
14902
|
-
return { kind: "compound", children: mergeFlushBoxes(b.partBoxes).map((part, i) => ({ shape: { kind: "box", half: part.half }, position: part.center, ...part.rotation ? { rotation: part.rotation } : {}, tag: i })) };
|
|
15086
|
+
return { kind: "compound", children: mergeFlushBoxes(b.partBoxes).map((part, i) => ({ shape: part.hull ? { kind: "convex", points: [...part.hull] } : part.round ? { kind: "cylinder", halfHeight: part.half[1], radius: (part.half[0] + part.half[2]) / 2 } : { kind: "box", half: part.half }, position: part.center, ...part.rotation ? { rotation: part.rotation } : {}, tag: i })) };
|
|
14903
15087
|
}
|
|
14904
15088
|
return { kind: "box", half: b.halfExtents };
|
|
14905
15089
|
}
|
|
@@ -17608,6 +17792,33 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
17608
17792
|
return out;
|
|
17609
17793
|
};
|
|
17610
17794
|
var granules = (inp, box, count) => bsp(box, count, [0, 1, 2], inp.rnd).map((b) => ({ center: b.c, size: b.s, q: quat.identity(), shape: "chunk", weight: b.s[0] * b.s[1] * b.s[2] }));
|
|
17795
|
+
var SLAB_MIN = 0.03;
|
|
17796
|
+
var splitAtHit = (root, hit, axes, count, rnd2) => {
|
|
17797
|
+
let pieces = [root];
|
|
17798
|
+
for (const ax of axes) {
|
|
17799
|
+
const half = root.s[ax] / 2;
|
|
17800
|
+
if (hit[ax] - -half < SLAB_MIN || half - hit[ax] < SLAB_MIN) continue;
|
|
17801
|
+
const next = [];
|
|
17802
|
+
for (const b of pieces) {
|
|
17803
|
+
const lo = b.c[ax] - b.s[ax] / 2;
|
|
17804
|
+
const hi = b.c[ax] + b.s[ax] / 2;
|
|
17805
|
+
for (const [from, to] of [[lo, hit[ax]], [hit[ax], hi]]) {
|
|
17806
|
+
const c = [b.c[0], b.c[1], b.c[2]];
|
|
17807
|
+
const s = [b.s[0], b.s[1], b.s[2]];
|
|
17808
|
+
c[ax] = (from + to) / 2;
|
|
17809
|
+
s[ax] = to - from;
|
|
17810
|
+
next.push({ c, s });
|
|
17811
|
+
}
|
|
17812
|
+
}
|
|
17813
|
+
pieces = next;
|
|
17814
|
+
}
|
|
17815
|
+
while (pieces.length < count) {
|
|
17816
|
+
pieces.sort((a, b) => b.s[axes[0]] * b.s[axes[1]] - a.s[axes[0]] * a.s[axes[1]]);
|
|
17817
|
+
const [big, ...rest] = pieces;
|
|
17818
|
+
pieces = [...bsp(big, 2, axes, rnd2), ...rest];
|
|
17819
|
+
}
|
|
17820
|
+
return pieces;
|
|
17821
|
+
};
|
|
17611
17822
|
var CRUMBS = 6;
|
|
17612
17823
|
var severAt = (inp, root, at3, gap) => {
|
|
17613
17824
|
const dims = root.s;
|
|
@@ -17670,7 +17881,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
17670
17881
|
if (inp.cut) return severAt(inp, root, inp.cut.at, inp.cut.gap);
|
|
17671
17882
|
if (inp.form === "plies") return plyBreak(inp, root, maxFragments);
|
|
17672
17883
|
const n2 = Math.min(maxFragments, 2 + Math.floor(rnd2() * 3));
|
|
17673
|
-
|
|
17884
|
+
const slabs = inp.form === "granules" && dims[t] < Math.min(dims[u], dims[v]) / 4 ? splitAtHit(root, inp.hit, [u, v], n2, rnd2) : bsp(root, n2, [0, 1, 2], rnd2);
|
|
17885
|
+
for (const b of slabs) out.push({ center: b.c, size: b.s, q: idq, shape: "slab", weight: b.s[0] * b.s[1] * b.s[2] });
|
|
17674
17886
|
if (inp.form !== "granules") return out;
|
|
17675
17887
|
const crumbs = Math.min(CRUMBS, maxFragments - out.length);
|
|
17676
17888
|
if (crumbs <= 0) return out;
|
|
@@ -25998,6 +26210,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
25998
26210
|
}).events;
|
|
25999
26211
|
},
|
|
26000
26212
|
state: (id) => objects.get(id)?.st ?? impls.get(id)?.impl.state() ?? null,
|
|
26213
|
+
anchoredParts: (id) => objects.get(id)?.parts.filter((p) => p.anchored && !isLost(p)).map((p) => p.spec.id) ?? [],
|
|
26214
|
+
fixedInPlace: (id) => {
|
|
26215
|
+
const o = objects.get(id);
|
|
26216
|
+
return !!o && o.spec.fixed === true && o.parts.some((p) => p.anchored && !isLost(p));
|
|
26217
|
+
},
|
|
26001
26218
|
snapshot: (id) => {
|
|
26002
26219
|
const st = objects.get(id)?.st ?? impls.get(id)?.impl.state();
|
|
26003
26220
|
return st ? clone(st) : null;
|
|
@@ -26653,10 +26870,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
26653
26870
|
const turn2 = angle * share * share * (3 - 2 * share);
|
|
26654
26871
|
const cos2 = Math.cos(turn2);
|
|
26655
26872
|
const sin2 = Math.sin(turn2);
|
|
26656
|
-
const
|
|
26657
|
-
positions[i] = point[0] + rx * cos2 + (ky * rz - kz * ry) * sin2 + kx *
|
|
26658
|
-
positions[i + 1] = point[1] + ry * cos2 + (kz * rx - kx * rz) * sin2 + ky *
|
|
26659
|
-
positions[i + 2] = point[2] + rz * cos2 + (kx * ry - ky * rx) * sin2 + kz *
|
|
26873
|
+
const dot3 = kx * rx + ky * ry + kz * rz;
|
|
26874
|
+
positions[i] = point[0] + rx * cos2 + (ky * rz - kz * ry) * sin2 + kx * dot3 * (1 - cos2);
|
|
26875
|
+
positions[i + 1] = point[1] + ry * cos2 + (kz * rx - kx * rz) * sin2 + ky * dot3 * (1 - cos2);
|
|
26876
|
+
positions[i + 2] = point[2] + rz * cos2 + (kx * ry - ky * rx) * sin2 + kz * dot3 * (1 - cos2);
|
|
26660
26877
|
}
|
|
26661
26878
|
}
|
|
26662
26879
|
|
|
@@ -26825,9 +27042,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
26825
27042
|
const grown = new Uint32Array(size);
|
|
26826
27043
|
grown.set(this.candidates);
|
|
26827
27044
|
this.candidates = grown;
|
|
26828
|
-
const
|
|
26829
|
-
|
|
26830
|
-
this.triangles =
|
|
27045
|
+
const numbers2 = new Uint32Array(Math.max(this.triangles.length, Math.ceil(size / 3)));
|
|
27046
|
+
numbers2.set(this.triangles);
|
|
27047
|
+
this.triangles = numbers2;
|
|
26831
27048
|
this.candidateIndex = new this.THREE.BufferAttribute(this.candidates, 1);
|
|
26832
27049
|
}
|
|
26833
27050
|
};
|
|
@@ -28419,6 +28636,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28419
28636
|
var REBAR_COLOR = 7628380;
|
|
28420
28637
|
var STEEL_DENSITY3 = 7850;
|
|
28421
28638
|
var CHIP_DECAL_EDGE = 0.05;
|
|
28639
|
+
var CHIP_GAP_REACH = 0.03;
|
|
28640
|
+
var CHIP_GAP_SHADE = 0.4;
|
|
28641
|
+
var CHIP_GAP_WIDTH = 1.15;
|
|
28422
28642
|
var CRATER_RADIUS2 = 2.5;
|
|
28423
28643
|
var CRATER_MIN_RADIUS = 0.012;
|
|
28424
28644
|
var CRATER_LIGHTEN = 0.12;
|
|
@@ -28450,10 +28670,71 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28450
28670
|
var HINGE_STILL_SPIN = 0.5;
|
|
28451
28671
|
var PREFIT_SLICE_MS = 1;
|
|
28452
28672
|
var CONTACT_MESHES = 12;
|
|
28453
|
-
var PART_BOX_MESHES =
|
|
28673
|
+
var PART_BOX_MESHES = 96;
|
|
28454
28674
|
var ROUND_SAMPLES = 400;
|
|
28455
|
-
var
|
|
28675
|
+
var ROUND_SIDES2 = 0.12;
|
|
28456
28676
|
var ROUND_SLACK = 1.12;
|
|
28677
|
+
var ROUND_FILL = 0.9;
|
|
28678
|
+
var FILL_GRID = 8;
|
|
28679
|
+
var hullRadiusAt = (profile, radius, at3) => {
|
|
28680
|
+
if (!profile || profile.length < 2) return radius;
|
|
28681
|
+
const hull = [];
|
|
28682
|
+
for (const point of profile) {
|
|
28683
|
+
while (hull.length >= 2) {
|
|
28684
|
+
const [a, ra] = hull[hull.length - 2];
|
|
28685
|
+
const [b, rb] = hull[hull.length - 1];
|
|
28686
|
+
if ((b - a) * (point[1] - ra) - (rb - ra) * (point[0] - a) >= 0) hull.pop();
|
|
28687
|
+
else break;
|
|
28688
|
+
}
|
|
28689
|
+
hull.push(point);
|
|
28690
|
+
}
|
|
28691
|
+
if (at3 <= hull[0][0]) return hull[0][1];
|
|
28692
|
+
for (let i = 1; i < hull.length; i++) {
|
|
28693
|
+
const [a, ra] = hull[i - 1];
|
|
28694
|
+
const [b, rb] = hull[i];
|
|
28695
|
+
if (at3 <= b) return ra + (rb - ra) * (at3 - a) / (b - a || 1);
|
|
28696
|
+
}
|
|
28697
|
+
return hull[hull.length - 1][1];
|
|
28698
|
+
};
|
|
28699
|
+
var insideDrawn = (mesh2, built2, x, y, z) => {
|
|
28700
|
+
if (built2) {
|
|
28701
|
+
for (const solid of built2) {
|
|
28702
|
+
const [qx, qy, qz, qw] = solid.rotation;
|
|
28703
|
+
const px = x - solid.center[0], py = y - solid.center[1], pz = z - solid.center[2];
|
|
28704
|
+
const tx = 2 * (-qy * pz + qz * py), ty = 2 * (-qz * px + qx * pz), tz = 2 * (-qx * py + qy * px);
|
|
28705
|
+
const lx = px + qw * tx - qy * tz + qz * ty, ly = py + qw * ty - qz * tx + qx * tz, lz = pz + qw * tz - qx * ty + qy * tx;
|
|
28706
|
+
const [hx, hy, hz2] = solid.half;
|
|
28707
|
+
if (solid.kind === "cylinder" || solid.kind === "cone") {
|
|
28708
|
+
if (Math.abs(ly) <= hy && (lx / hx) ** 2 + (lz / hz2) ** 2 <= 1) return true;
|
|
28709
|
+
} else if (solid.kind === "sphere") {
|
|
28710
|
+
if ((lx / hx) ** 2 + (ly / hy) ** 2 + (lz / hz2) ** 2 <= 1) return true;
|
|
28711
|
+
} else if (Math.abs(lx) <= hx && Math.abs(ly) <= hy && Math.abs(lz) <= hz2) return true;
|
|
28712
|
+
}
|
|
28713
|
+
return false;
|
|
28714
|
+
}
|
|
28715
|
+
const geometry = mesh2.geometry;
|
|
28716
|
+
const p = geometry.parameters ?? {};
|
|
28717
|
+
const n = (key, fallback2) => typeof p[key] === "number" ? p[key] : fallback2;
|
|
28718
|
+
switch (geometry.type) {
|
|
28719
|
+
case "BoxGeometry":
|
|
28720
|
+
return Math.abs(x) <= n("width", 1) / 2 && Math.abs(y) <= n("height", 1) / 2 && Math.abs(z) <= n("depth", 1) / 2;
|
|
28721
|
+
case "CylinderGeometry":
|
|
28722
|
+
case "ConeGeometry": {
|
|
28723
|
+
const h = n("height", 1) / 2;
|
|
28724
|
+
if (Math.abs(y) > h || p.openEnded === true) return false;
|
|
28725
|
+
const top = geometry.type === "ConeGeometry" ? 0 : n("radiusTop", 1);
|
|
28726
|
+
const bottom = geometry.type === "ConeGeometry" ? n("radius", 1) : n("radiusBottom", 1);
|
|
28727
|
+
return Math.hypot(x, z) <= bottom + (top - bottom) * (y + h) / (2 * h || 1);
|
|
28728
|
+
}
|
|
28729
|
+
case "SphereGeometry":
|
|
28730
|
+
return Math.hypot(x, y, z) <= n("radius", 1);
|
|
28731
|
+
default: {
|
|
28732
|
+
if (!geometry.boundingBox) geometry.computeBoundingBox();
|
|
28733
|
+
const box = geometry.boundingBox;
|
|
28734
|
+
return !!box && x >= box.min.x && x <= box.max.x && y >= box.min.y && y <= box.max.y && z >= box.min.z && z <= box.max.z;
|
|
28735
|
+
}
|
|
28736
|
+
}
|
|
28737
|
+
};
|
|
28457
28738
|
var RIM_POINTS = 12;
|
|
28458
28739
|
var rimPoints = (round2, half) => {
|
|
28459
28740
|
const out = [];
|
|
@@ -28511,6 +28792,16 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28511
28792
|
};
|
|
28512
28793
|
var BROKEN_GAP = 0.03;
|
|
28513
28794
|
var BROKEN_SAMPLES = [[0.5, 0.5], [0.1, 0.1], [0.9, 0.1], [0.1, 0.9], [0.9, 0.9]];
|
|
28795
|
+
var UNDERMINED_MAX = 64;
|
|
28796
|
+
var UNDERMINED_RIM = 0.04;
|
|
28797
|
+
var UNDERMINED_RIM_DROP = 0.05;
|
|
28798
|
+
var UNDERMINED_RIM_RISE = 0.1;
|
|
28799
|
+
var UNDERMINED_STAND = 0.4;
|
|
28800
|
+
var UNDERMINED_KEEP = 0.6;
|
|
28801
|
+
var SOLIDS_MAX = 64;
|
|
28802
|
+
var UNDERMINED_PUSH = 0.6;
|
|
28803
|
+
var UNDERMINED_STILL = 0.05;
|
|
28804
|
+
var SOLID_WELD = 1e-4;
|
|
28514
28805
|
var UNCHECKED_KINDS = /* @__PURE__ */ new Set(["structure", "room", "ground"]);
|
|
28515
28806
|
var FIRE_CEILING_SECONDS = 3600;
|
|
28516
28807
|
var GENERIC_REFERENCE_RADIUS = 15;
|
|
@@ -28658,6 +28949,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28658
28949
|
__publicField(this, "pieceBoxes", /* @__PURE__ */ new WeakMap());
|
|
28659
28950
|
/** Objects broken since the last update: `checkBroken` looks at what is left of them. */
|
|
28660
28951
|
__publicField(this, "broken", /* @__PURE__ */ new Set());
|
|
28952
|
+
/** Discs of ground that changed since the last update (`wakeRegion`): `checkUndermined` looks at what stood on them. */
|
|
28953
|
+
__publicField(this, "undermined", []);
|
|
28661
28954
|
__publicField(this, "staticAt", 0);
|
|
28662
28955
|
__publicField(this, "queue", []);
|
|
28663
28956
|
/** The cover of each body around a part of the world that went off, read as the event is emitted: before the blast tore or moved anything. */
|
|
@@ -29229,8 +29522,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29229
29522
|
mv.mesh.updateWorldMatrix(true, false);
|
|
29230
29523
|
m4.multiplyMatrices(inv, mv.mesh.matrixWorld);
|
|
29231
29524
|
const stride = Math.max(1, Math.floor(pos.count / ROUND_SAMPLES));
|
|
29232
|
-
for (let
|
|
29233
|
-
p.fromBufferAttribute(pos,
|
|
29525
|
+
for (let i2 = 0; i2 < pos.count; i2 += stride) {
|
|
29526
|
+
p.fromBufferAttribute(pos, i2).applyMatrix4(m4);
|
|
29234
29527
|
points.push([p.x - cx, p.y - cy, p.z - cz]);
|
|
29235
29528
|
}
|
|
29236
29529
|
}
|
|
@@ -29238,22 +29531,64 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29238
29531
|
const drawn = new Float64Array(3);
|
|
29239
29532
|
for (const q of points) for (let k = 0; k < 3; k++) drawn[k] = Math.max(drawn[k], Math.abs(q[k]));
|
|
29240
29533
|
const fits = (axis3) => {
|
|
29241
|
-
const [
|
|
29242
|
-
if (Math.abs(half[
|
|
29243
|
-
if (Math.abs(drawn[
|
|
29244
|
-
const reach2 = (drawn[
|
|
29245
|
-
for (const q of points) if (Math.hypot(q[
|
|
29246
|
-
return (half[
|
|
29534
|
+
const [i2, j2] = axis3 === 0 ? [1, 2] : axis3 === 1 ? [0, 2] : [0, 1];
|
|
29535
|
+
if (Math.abs(half[i2] - half[j2]) > ROUND_SIDES2 * Math.max(half[i2], half[j2])) return null;
|
|
29536
|
+
if (Math.abs(drawn[i2] - drawn[j2]) > ROUND_SIDES2 * Math.max(drawn[i2], drawn[j2])) return null;
|
|
29537
|
+
const reach2 = (drawn[i2] + drawn[j2]) / 2;
|
|
29538
|
+
for (const q of points) if (Math.hypot(q[i2], q[j2]) > reach2 * ROUND_SLACK) return null;
|
|
29539
|
+
return (half[i2] + half[j2]) / 2;
|
|
29247
29540
|
};
|
|
29248
29541
|
const radii = [0, 1, 2].map(fits);
|
|
29249
29542
|
if (radii.every((r) => r !== null)) {
|
|
29250
29543
|
const radius2 = (half[0] + half[1] + half[2]) / 3;
|
|
29544
|
+
if (this.drawnShareOf(b, body, (q) => Math.hypot(q[0], q[1], q[2]) <= radius2) < ROUND_FILL) return null;
|
|
29251
29545
|
return { kind: "sphere", axis: 1, radius: radius2, inertia: body.inertiaGiven ?? this.inertiaOf(b, body, "sphere", 1, radius2) };
|
|
29252
29546
|
}
|
|
29253
29547
|
const axis2 = [0, 1, 2].find((k) => radii[k] !== null);
|
|
29254
29548
|
if (axis2 === void 0) return null;
|
|
29255
29549
|
const radius = radii[axis2] ?? 0;
|
|
29256
|
-
|
|
29550
|
+
const profile = profileOf2(points, axis2, half[axis2], radius);
|
|
29551
|
+
const [i, j] = axis2 === 0 ? [1, 2] : axis2 === 1 ? [0, 2] : [0, 1];
|
|
29552
|
+
if (this.drawnShareOf(b, body, (q) => Math.abs(q[axis2]) <= half[axis2] && Math.hypot(q[i], q[j]) <= hullRadiusAt(profile, radius, q[axis2])) < ROUND_FILL) return null;
|
|
29553
|
+
return { kind: "cylinder", axis: axis2, radius, inertia: body.inertiaGiven ?? this.inertiaOf(b, body, "cylinder", axis2, radius), profile };
|
|
29554
|
+
}
|
|
29555
|
+
/** The vertices of a mesh about the centre of its box (`lb`, its own space), scaled as it is drawn: the points of the hull the engine holds it by (`PartBox.hull`). */
|
|
29556
|
+
hullOf(mv, lb, scale) {
|
|
29557
|
+
const own = [];
|
|
29558
|
+
this.visuals.rangePoints(mv, new this.THREE.Matrix4(), own);
|
|
29559
|
+
const c = lb.getCenter(new this.THREE.Vector3());
|
|
29560
|
+
const out = [];
|
|
29561
|
+
for (let i = 0; i < own.length; i += 3) out.push((own[i] - c.x) * Math.abs(scale.x), (own[i + 1] - c.y) * Math.abs(scale.y), (own[i + 2] - c.z) * Math.abs(scale.z));
|
|
29562
|
+
return out;
|
|
29563
|
+
}
|
|
29564
|
+
/**
|
|
29565
|
+
* The share of a round body the engine would hold (`inside`: a point from the piece's centre of mass) that is drawn: a grid of points through its box (`FILL_GRID`), those
|
|
29566
|
+
* inside the body, and of them those inside a primitive of the piece (`insideDrawn`). Primitives that overlap count once (a lamp's glow over its shade).
|
|
29567
|
+
*/
|
|
29568
|
+
drawnShareOf(b, body, inside) {
|
|
29569
|
+
const inv = specFrameInverse(this.THREE, b.root);
|
|
29570
|
+
const meshes = this.meshesOf(b).filter((mv) => this.visuals.shown(mv) && !mv.host).map((mv) => {
|
|
29571
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
29572
|
+
return { mesh: mv.mesh, built: builtSolidsOf(mv.mesh), back: new this.THREE.Matrix4().multiplyMatrices(inv, mv.mesh.matrixWorld).invert() };
|
|
29573
|
+
});
|
|
29574
|
+
const [cx, cy, cz] = body.localCenter;
|
|
29575
|
+
const half = body.halfExtents;
|
|
29576
|
+
const p = new this.THREE.Vector3();
|
|
29577
|
+
let shape = 0;
|
|
29578
|
+
let drawn = 0;
|
|
29579
|
+
for (let a = 0; a < FILL_GRID; a++) for (let c = 0; c < FILL_GRID; c++) for (let d = 0; d < FILL_GRID; d++) {
|
|
29580
|
+
const q = [half[0] * ((a + 0.5) / FILL_GRID * 2 - 1), half[1] * ((c + 0.5) / FILL_GRID * 2 - 1), half[2] * ((d + 0.5) / FILL_GRID * 2 - 1)];
|
|
29581
|
+
if (!inside(q)) continue;
|
|
29582
|
+
shape++;
|
|
29583
|
+
for (const m of meshes) {
|
|
29584
|
+
p.set(q[0] + cx, q[1] + cy, q[2] + cz).applyMatrix4(m.back);
|
|
29585
|
+
if (insideDrawn(m.mesh, m.built, p.x, p.y, p.z)) {
|
|
29586
|
+
drawn++;
|
|
29587
|
+
break;
|
|
29588
|
+
}
|
|
29589
|
+
}
|
|
29590
|
+
}
|
|
29591
|
+
return shape === 0 ? 1 : drawn / shape;
|
|
29257
29592
|
}
|
|
29258
29593
|
pieces() {
|
|
29259
29594
|
return [...this.pieceSys.list];
|
|
@@ -29343,6 +29678,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29343
29678
|
this.work?.beginFrame();
|
|
29344
29679
|
if (!this.attached) this.drainQueue();
|
|
29345
29680
|
this.checkBroken();
|
|
29681
|
+
this.checkUndermined();
|
|
29346
29682
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
29347
29683
|
for (const b of this.bounds.values()) if (b.soilNode && this.world.state(b.id)?.soil?.status === "yielding") this.onSettle(b.id);
|
|
29348
29684
|
this.settlement.update(dt);
|
|
@@ -30401,9 +30737,33 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30401
30737
|
const rotation2 = new T.Quaternion(ev.rotation[0], ev.rotation[1], ev.rotation[2], ev.rotation[3]);
|
|
30402
30738
|
for (const part of this.bounds.get(ev.object)?.parts.values() ?? []) for (const mv of part.meshes) this.visuals.clearDecals(mv, center, half, rotation2);
|
|
30403
30739
|
this.vfx.peekWorkshop()?.decals.clearInside(ev.center, [half.x, half.y, half.z], ev.rotation);
|
|
30740
|
+
if (pv) this.drawChipGap(pv, ev, center, rotation2);
|
|
30404
30741
|
this.vfx.burst("dust", ev.center, [0, 1, 0], ev.units ? Math.min(40, 8 + ev.units.length) : 8, ev.units ? 1.6 : 0.8, { color });
|
|
30405
30742
|
this.impactSound(pv?.material ?? "", ev.center, 0.7, ev.blow);
|
|
30406
30743
|
}
|
|
30744
|
+
/**
|
|
30745
|
+
* The gap a unit leaves in an object the renderer draws whole (a concrete pole, a block, a post): on each outer face the unit reached, the broken inside of its material,
|
|
30746
|
+
* as wide as the unit there, so the bars it bared show in a hole and not on a smooth face. A drawing that cuts its own gaps (the house's breach, `drawnSpalls`) takes none.
|
|
30747
|
+
*/
|
|
30748
|
+
drawChipGap(pv, ev, center, rotation2) {
|
|
30749
|
+
const mv = this.nearestMesh(pv, center);
|
|
30750
|
+
if (!mv || mv.mesh.userData.drawnSpalls?.includes(ev.part)) return;
|
|
30751
|
+
const def = this.world.materials.get(pv.material);
|
|
30752
|
+
const inner = def?.visual?.innerColor ?? fallbackColor(def);
|
|
30753
|
+
const color = [16, 8, 0].reduce((hex, shift) => hex | Math.round((inner >> shift & 255) * CHIP_GAP_SHADE) << shift, 0);
|
|
30754
|
+
const box = this.visuals.worldBox(mv, new this.THREE.Box3());
|
|
30755
|
+
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
30756
|
+
for (const side of [-1, 1]) {
|
|
30757
|
+
const normal = new this.THREE.Vector3(axis2 === 0 ? side : 0, axis2 === 1 ? side : 0, axis2 === 2 ? side : 0).applyQuaternion(rotation2);
|
|
30758
|
+
const face = center.clone().addScaledVector(normal, ev.size[axis2] / 2);
|
|
30759
|
+
const k = Math.abs(normal.x) >= Math.abs(normal.y) && Math.abs(normal.x) >= Math.abs(normal.z) ? "x" : Math.abs(normal.y) >= Math.abs(normal.z) ? "y" : "z";
|
|
30760
|
+
const surface = normal[k] > 0 ? box.max[k] : box.min[k];
|
|
30761
|
+
if (Math.abs(face[k] - surface) > CHIP_GAP_REACH) continue;
|
|
30762
|
+
face[k] = surface;
|
|
30763
|
+
this.visuals.addSpall(mv, face, normal, Math.min(ev.size[(axis2 + 1) % 3], ev.size[(axis2 + 2) % 3]) / 2 * CHIP_GAP_WIDTH, color);
|
|
30764
|
+
}
|
|
30765
|
+
}
|
|
30766
|
+
}
|
|
30407
30767
|
onFracture(ev) {
|
|
30408
30768
|
const b = this.bounds.get(ev.object);
|
|
30409
30769
|
const pv = b?.parts.get(ev.part);
|
|
@@ -30594,7 +30954,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30594
30954
|
if (!old.round) this.setContacts(b, old, this.meshesOf(b).filter((mv) => this.visuals.shown(mv)));
|
|
30595
30955
|
} else if (old.partBoxes) this.fitPartBoxes(b, old);
|
|
30596
30956
|
if (!this.splittingAtLoad) old.sleeping = false;
|
|
30597
|
-
} else if (kitOriginOf(b.root)?.kind === "furniture" && !this.splittingAtLoad) {
|
|
30957
|
+
} else if (kitOriginOf(b.root)?.kind === "furniture" && !this.splittingAtLoad && !this.heldByWorld(objectId)) {
|
|
30598
30958
|
const piece = this.makePiece(objectId);
|
|
30599
30959
|
piece.apart = true;
|
|
30600
30960
|
this.tipIfTopHeavy(b, true);
|
|
@@ -30788,9 +31148,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30788
31148
|
});
|
|
30789
31149
|
if (holds.length !== 1) return null;
|
|
30790
31150
|
const joint = holds[0];
|
|
30791
|
-
const
|
|
30792
|
-
const a =
|
|
30793
|
-
const c =
|
|
31151
|
+
const boxOf2 = (partId) => this.shownBoxes(objectId, partId).reduce((all, one) => all ? all.map((value, k) => k < 3 ? Math.min(value, one[k]) : Math.max(value, one[k])) : [...one], null);
|
|
31152
|
+
const a = boxOf2(joint.a);
|
|
31153
|
+
const c = boxOf2(joint.b);
|
|
30794
31154
|
if (!a || !c) return null;
|
|
30795
31155
|
const point = [0, 0, 0];
|
|
30796
31156
|
for (let k = 0; k < 3; k++) point[k] = (Math.max(a[k], c[k]) + Math.min(a[k + 3], c[k + 3])) / 2;
|
|
@@ -30880,15 +31240,16 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30880
31240
|
if (!body.round) this.setContacts(b, body, left);
|
|
30881
31241
|
}
|
|
30882
31242
|
body.sleeping = false;
|
|
31243
|
+
if (!structural && !body.round && !body.held && kitOriginOf(b.root)?.kind === "furniture" && Math.hypot(...body.velocity) <= UNDERMINED_STILL) this.goOverIfBalanced(b, body, left);
|
|
30883
31244
|
return;
|
|
30884
31245
|
}
|
|
30885
|
-
if (structural) return;
|
|
30886
|
-
const
|
|
30887
|
-
const whole = [...b.parts.values()].flatMap((pv) => pv.meshes).map(
|
|
31246
|
+
if (structural || this.heldByWorld(objectId)) return;
|
|
31247
|
+
const boxOf2 = (mv) => this.visuals.worldBox(mv, new this.THREE.Box3());
|
|
31248
|
+
const whole = [...b.parts.values()].flatMap((pv) => pv.meshes).map(boxOf2).filter((one) => !one.isEmpty());
|
|
30888
31249
|
if (!this.standsOn(objectId, whole.map((one) => [one.min.x, one.min.y, one.min.z, one.max.x, one.max.y, one.max.z]))) return;
|
|
30889
31250
|
const floor2 = Math.min(...whole.map((one) => one.min.y));
|
|
30890
31251
|
const feetOf = (boxes) => boxes.filter((one) => one.min.y < floor2 + FEET_BAND).reduce((feet, one) => feet.union(one), new this.THREE.Box3());
|
|
30891
|
-
const leftBoxes = left.map(
|
|
31252
|
+
const leftBoxes = left.map(boxOf2).filter((one) => !one.isEmpty());
|
|
30892
31253
|
const now = feetOf(leftBoxes);
|
|
30893
31254
|
let away = null;
|
|
30894
31255
|
const was = feetOf(whole);
|
|
@@ -30945,7 +31306,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30945
31306
|
}
|
|
30946
31307
|
releaseIfFloating(objectId) {
|
|
30947
31308
|
const b = this.bounds.get(objectId);
|
|
30948
|
-
if (!b || b.piece || this.pieceSys.get(objectId) || !this.autoSplit || UNCHECKED_KINDS.has(this.kindOf(b))) return false;
|
|
31309
|
+
if (!b || b.piece || this.pieceSys.get(objectId) || !this.autoSplit || UNCHECKED_KINDS.has(this.kindOf(b)) || this.heldByWorld(objectId)) return false;
|
|
30949
31310
|
const boxes = this.shownBoxes(objectId);
|
|
30950
31311
|
if (boxes.length === 0) return false;
|
|
30951
31312
|
const whole = new this.THREE.Box3();
|
|
@@ -30964,6 +31325,139 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30964
31325
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
30965
31326
|
return true;
|
|
30966
31327
|
}
|
|
31328
|
+
/**
|
|
31329
|
+
* The ground changed under what stands on feet (`wakeRegion`: a hole shot, dug or blown in the floor): furniture and what the host lets move (`shoveable`), not a piece yet or
|
|
31330
|
+
* a piece lying still. It looks at its feet again (`lowPoints`): a point of them with nothing left under it (`holdsAt`) no longer holds. While the points that still hold keep its
|
|
31331
|
+
* centre inside their polygon by `UNDERMINED_STAND` it stands (a cabinet on a full base over a small hole); otherwise it becomes a piece if it was not one, its corner over the
|
|
31332
|
+
* gap is started down, and the engine takes it into the hole by its own weight: a bed with a leg over the hole goes down on that corner until its frame meets the floor, and
|
|
31333
|
+
* what lay on it slides or falls off. Structures answer to their own load path.
|
|
31334
|
+
*/
|
|
31335
|
+
checkUndermined() {
|
|
31336
|
+
if (this.undermined.length === 0) return;
|
|
31337
|
+
const discs = this.undermined.splice(0);
|
|
31338
|
+
const inDisc = (x, z, d) => Math.hypot(x - d.x, z - d.z) <= d.radius;
|
|
31339
|
+
for (const b of [...this.bounds.values()]) {
|
|
31340
|
+
if (this.kindOf(b) !== "furniture" && !this.o.shoveable?.(b.id)) continue;
|
|
31341
|
+
const was = b.piece ?? this.pieceSys.get(b.id) ?? null;
|
|
31342
|
+
if (was && (was.held || Math.hypot(...was.velocity) > UNDERMINED_STILL)) continue;
|
|
31343
|
+
const meshes = this.meshesOf(b).filter((mv) => this.visuals.shown(mv));
|
|
31344
|
+
const boxes = meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty());
|
|
31345
|
+
if (boxes.length === 0) continue;
|
|
31346
|
+
const reach2 = boxes.reduce((all, one) => all.union(one), new this.THREE.Box3());
|
|
31347
|
+
if (!discs.some((d) => Math.hypot(Math.max(reach2.min.x - d.x, 0, d.x - reach2.max.x), Math.max(reach2.min.z - d.z, 0, d.z - reach2.max.z)) <= d.radius)) continue;
|
|
31348
|
+
const feet = this.lowPoints(meshes);
|
|
31349
|
+
if (!feet) continue;
|
|
31350
|
+
const { floor: floor2, points } = feet;
|
|
31351
|
+
const held = [];
|
|
31352
|
+
const lost = [];
|
|
31353
|
+
for (const point of points) (this.holdsAt(b.id, point[0], point[1], floor2) ? held : lost).push(point);
|
|
31354
|
+
if (lost.length === 0) continue;
|
|
31355
|
+
if (!lost.some(([x, z]) => discs.some((d) => inDisc(x, z, d) && this.stoodBeside(x, z, d, floor2)))) continue;
|
|
31356
|
+
const centre = centreOfBoxes(boxes);
|
|
31357
|
+
if (this.standsWith(held, points, centre, floor2)) continue;
|
|
31358
|
+
let body;
|
|
31359
|
+
if (was) body = was;
|
|
31360
|
+
else {
|
|
31361
|
+
const piece = this.makePiece(b.id);
|
|
31362
|
+
body = b.piece ?? piece;
|
|
31363
|
+
body.apart = true;
|
|
31364
|
+
this.setContacts(b, body, meshes, true);
|
|
31365
|
+
}
|
|
31366
|
+
const gx = lost.reduce((sum, p) => sum + p[0], 0) / lost.length - centre[0];
|
|
31367
|
+
const gz = lost.reduce((sum, p) => sum + p[1], 0) / lost.length - centre[2];
|
|
31368
|
+
const length = Math.hypot(gx, gz);
|
|
31369
|
+
body.sleeping = false;
|
|
31370
|
+
body.still = 0;
|
|
31371
|
+
body.calmAt = null;
|
|
31372
|
+
if (held.length > 0 && length > 1e-6) this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + gx, floor2, centre[2] + gz]);
|
|
31373
|
+
if (!was) this.o.onLoosened?.(b.id, body, "ground");
|
|
31374
|
+
}
|
|
31375
|
+
}
|
|
31376
|
+
/**
|
|
31377
|
+
* A piece whose feet that still hold keep its centre inside their polygon by less than `UNDERMINED_STAND` per metre of its height is started down over the nearest edge of
|
|
31378
|
+
* that polygon (its weight does the rest); one that stands on nothing falls by itself.
|
|
31379
|
+
*/
|
|
31380
|
+
goOverIfBalanced(b, body, meshes) {
|
|
31381
|
+
const feet = this.lowPoints(meshes);
|
|
31382
|
+
if (!feet) return;
|
|
31383
|
+
const held = feet.points.filter(([x, z]) => this.holdsAt(b.id, x, z, feet.floor));
|
|
31384
|
+
if (held.length < 3) return;
|
|
31385
|
+
const centre = centreOfBoxes(meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty()));
|
|
31386
|
+
if (this.standsWith(held, null, centre, feet.floor)) return;
|
|
31387
|
+
const inside = insideBy(convexHull2(held), [centre[0], centre[2]]);
|
|
31388
|
+
const reach2 = Math.max(body.halfExtents[0], body.halfExtents[2]);
|
|
31389
|
+
this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + inside.out.x * reach2, feet.floor, centre[2] + inside.out.z * reach2]);
|
|
31390
|
+
}
|
|
31391
|
+
/**
|
|
31392
|
+
* Whether what stands on the points `held` of its feet (`all` of them whole) stays up with its centre at `centre`: the centre is inside what holds by `UNDERMINED_STAND` per metre of its height above `floor`, or it keeps
|
|
31393
|
+
* most of the hold it had (`UNDERMINED_KEEP` of how far inside its whole feet `all` the centre was; null when those are gone with a leg).
|
|
31394
|
+
*/
|
|
31395
|
+
standsWith(held, all, centre, floor2) {
|
|
31396
|
+
if (held.length < 3) return false;
|
|
31397
|
+
const now = insideBy(convexHull2([...held]), [centre[0], centre[2]]).depth;
|
|
31398
|
+
if (now > UNDERMINED_STAND * (centre[1] - floor2)) return true;
|
|
31399
|
+
return all !== null && now >= UNDERMINED_KEEP * insideBy(convexHull2([...all]), [centre[0], centre[2]]).depth;
|
|
31400
|
+
}
|
|
31401
|
+
/**
|
|
31402
|
+
* Where `meshes` touch the floor, (x, z) in the world, and how high that floor is (their lowest drawn point); null with nothing drawn. The bottom faces (triangles
|
|
31403
|
+
* within `FEET_BAND` of the lowest point) give their corners, the middles of their sides and their own middles: the base of a cabinet is held along its edges and
|
|
31404
|
+
* across, not only at its four corners, and a mesh merged from a frame and its legs is held under each leg, not in the air between them.
|
|
31405
|
+
*/
|
|
31406
|
+
lowPoints(meshes) {
|
|
31407
|
+
const faces = [];
|
|
31408
|
+
let floor2 = Infinity;
|
|
31409
|
+
for (const mv of meshes) {
|
|
31410
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
31411
|
+
const points = [];
|
|
31412
|
+
this.visuals.rangePoints(mv, mv.mesh.matrixWorld, points);
|
|
31413
|
+
const count = points.length / 3;
|
|
31414
|
+
const index = mv.mesh.geometry.getIndex()?.array;
|
|
31415
|
+
const from = mv.range ? mv.range[0] : 0;
|
|
31416
|
+
const total = index ? index.length : count;
|
|
31417
|
+
for (let i = 0; i + 2 < total; i += 3) {
|
|
31418
|
+
const a = (index ? index[i] : i) - from, b = (index ? index[i + 1] : i + 1) - from, c = (index ? index[i + 2] : i + 2) - from;
|
|
31419
|
+
if (a < 0 || b < 0 || c < 0 || a >= count || b >= count || c >= count) continue;
|
|
31420
|
+
for (const k of [a, b, c]) {
|
|
31421
|
+
faces.push(points[k * 3], points[k * 3 + 1], points[k * 3 + 2]);
|
|
31422
|
+
floor2 = Math.min(floor2, points[k * 3 + 1]);
|
|
31423
|
+
}
|
|
31424
|
+
}
|
|
31425
|
+
}
|
|
31426
|
+
if (faces.length === 0) return null;
|
|
31427
|
+
const out = [];
|
|
31428
|
+
const seen = /* @__PURE__ */ new Set();
|
|
31429
|
+
const add2 = (x, z) => {
|
|
31430
|
+
const key = `${Math.round(x * 1e3)},${Math.round(z * 1e3)}`;
|
|
31431
|
+
if (seen.has(key)) return;
|
|
31432
|
+
seen.add(key);
|
|
31433
|
+
out.push([x, z]);
|
|
31434
|
+
};
|
|
31435
|
+
for (let i = 0; i < faces.length; i += 9) {
|
|
31436
|
+
if (faces[i + 1] > floor2 + FEET_BAND || faces[i + 4] > floor2 + FEET_BAND || faces[i + 7] > floor2 + FEET_BAND) continue;
|
|
31437
|
+
const ax = faces[i], az = faces[i + 2], bx = faces[i + 3], bz = faces[i + 5], cx = faces[i + 6], cz = faces[i + 8];
|
|
31438
|
+
add2(ax, az);
|
|
31439
|
+
add2(bx, bz);
|
|
31440
|
+
add2(cx, cz);
|
|
31441
|
+
add2((ax + bx) / 2, (az + bz) / 2);
|
|
31442
|
+
add2((bx + cx) / 2, (bz + cz) / 2);
|
|
31443
|
+
add2((ax + cx) / 2, (az + cz) / 2);
|
|
31444
|
+
add2((ax + bx + cx) / 3, (az + bz + cz) / 3);
|
|
31445
|
+
}
|
|
31446
|
+
return out.length > 0 ? { floor: floor2, points: out } : null;
|
|
31447
|
+
}
|
|
31448
|
+
/** Whether the ground, a fixed top or a piece (not `objectId` itself) is within `BROKEN_GAP` under the point (x, z) of a foot at height `y`. */
|
|
31449
|
+
holdsAt(objectId, x, z, y) {
|
|
31450
|
+
return Math.max(this.groundAt(x, z), this.staticTopAtBut(objectId, x, z, y, BROKEN_GAP), this.pieceSys.topAt(x, z, y, BROKEN_GAP, objectId)) >= y - BROKEN_GAP;
|
|
31451
|
+
}
|
|
31452
|
+
/** Whether the ground just past the disc `d`, on the way from its middle to the foot at (x, z), is where the object's feet (`floor`) were: it stood on the ground that went. */
|
|
31453
|
+
stoodBeside(x, z, d, floor2) {
|
|
31454
|
+
const fx = x - d.x, fz = z - d.z;
|
|
31455
|
+
const length = Math.hypot(fx, fz);
|
|
31456
|
+
const ux = length > 1e-6 ? fx / length : 1, uz = length > 1e-6 ? fz / length : 0;
|
|
31457
|
+
const reach2 = d.radius + UNDERMINED_RIM;
|
|
31458
|
+
const ground = this.groundAt(d.x + ux * reach2, d.z + uz * reach2);
|
|
31459
|
+
return ground >= floor2 - BROKEN_GAP - UNDERMINED_RIM_DROP && ground <= floor2 + UNDERMINED_RIM_RISE;
|
|
31460
|
+
}
|
|
30967
31461
|
/** Whether the lowest of `boxes` (world boxes of the object `objectId`) has the ground, a fixed top or a piece within `BROKEN_GAP` under it. */
|
|
30968
31462
|
standsOn(objectId, boxes) {
|
|
30969
31463
|
if (boxes.length === 0) return false;
|
|
@@ -30980,6 +31474,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30980
31474
|
return false;
|
|
30981
31475
|
}
|
|
30982
31476
|
/** The kind of kit piece a bound object is, by the mark on its root or the nearest one above it (a house binds a group inside its marked root); '' when unmarked. */
|
|
31477
|
+
/** Whether what is left of the object is fixed where it was laid and still anchored (`DestructionWorld.fixedInPlace`): it stands by its load path, it is never let go as a piece. */
|
|
31478
|
+
heldByWorld(objectId) {
|
|
31479
|
+
return this.world.fixedInPlace(objectId);
|
|
31480
|
+
}
|
|
30983
31481
|
kindOf(b) {
|
|
30984
31482
|
for (let o = b.root; o; o = o.parent) {
|
|
30985
31483
|
const kind = kitOriginOf(o)?.kind;
|
|
@@ -31018,7 +31516,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31018
31516
|
* what holds it and it goes over until the top meets the floor. Past `CONTACT_MESHES` meshes it keeps the corners of its box; up to `PART_BOX_MESHES`, what lands on it lands
|
|
31019
31517
|
* on its parts.
|
|
31020
31518
|
*/
|
|
31021
|
-
setContacts(b, body, meshes) {
|
|
31519
|
+
setContacts(b, body, meshes, fitWhole = false) {
|
|
31022
31520
|
if (meshes.length > PART_BOX_MESHES) {
|
|
31023
31521
|
body.contacts = void 0;
|
|
31024
31522
|
body.partBoxes = void 0;
|
|
@@ -31035,7 +31533,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31035
31533
|
this.visuals.localBox(mv, lb);
|
|
31036
31534
|
if (lb.isEmpty()) continue;
|
|
31037
31535
|
m4.multiplyMatrices(inv, mv.mesh.matrixWorld);
|
|
31038
|
-
this.partBoxesOf(mv, { lb, m4, from: [cx, cy, cz] }, boxes);
|
|
31536
|
+
this.partBoxesOf(mv, { lb, m4, from: [cx, cy, cz], fitWhole }, boxes);
|
|
31039
31537
|
lb.applyMatrix4(m4);
|
|
31040
31538
|
for (let i = 0; i < 8; i++) points.push([(i & 1 ? lb.max.x : lb.min.x) - cx, (i & 2 ? lb.max.y : lb.min.y) - cy, (i & 4 ? lb.max.z : lb.min.z) - cz]);
|
|
31041
31539
|
}
|
|
@@ -31156,28 +31654,67 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31156
31654
|
return own;
|
|
31157
31655
|
}
|
|
31158
31656
|
/**
|
|
31159
|
-
* The boxes of one mesh in the piece's frame, from its centre of mass, turned as the mesh is drawn: a
|
|
31160
|
-
* place in the piece; a part drawn by a range of a merged mesh (a roof sheet in the house's roof mesh) is fitted to its own vertices (`fitOrientedBoxes`), since the box
|
|
31657
|
+
* The boxes of one mesh in the piece's frame, from its centre of mass, turned as the mesh is drawn: a mesh drawn as boxes round the air is those boxes (`hollowBoxesOf`);
|
|
31658
|
+
* else a plain mesh is its geometry's box in its own space, turned by its place in the piece; a part drawn by a range of a merged mesh (a roof sheet in the house's roof mesh) is fitted to its own vertices (`fitOrientedBoxes`), since the box
|
|
31161
31659
|
* of those vertices in the merged mesh's space is the box around a tilted sheet, mostly air.
|
|
31162
31660
|
*/
|
|
31163
31661
|
partBoxesOf(mv, at3, out) {
|
|
31164
31662
|
const [cx, cy, cz] = at3.from;
|
|
31165
|
-
|
|
31166
|
-
|
|
31167
|
-
|
|
31168
|
-
const
|
|
31169
|
-
|
|
31170
|
-
|
|
31171
|
-
|
|
31172
|
-
|
|
31173
|
-
|
|
31174
|
-
|
|
31175
|
-
|
|
31176
|
-
const half = [Math.abs((box.high[0] - box.low[0]) * scale2.x) / 2, Math.abs((box.high[1] - box.low[1]) * scale2.y) / 2, Math.abs((box.high[2] - box.low[2]) * scale2.z) / 2];
|
|
31177
|
-
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half, rotation: [quat3.x, quat3.y, quat3.z, quat3.w] });
|
|
31178
|
-
}
|
|
31179
|
-
return;
|
|
31663
|
+
const built2 = mv.range ? null : builtSolidsOf(mv.mesh);
|
|
31664
|
+
const solids = at3.fitWhole && !mv.range && !built2 ? solidBoxesOf(mv.mesh.geometry) : null;
|
|
31665
|
+
if (solids) {
|
|
31666
|
+
const pos2 = new this.THREE.Vector3();
|
|
31667
|
+
const quat3 = new this.THREE.Quaternion();
|
|
31668
|
+
const scale2 = new this.THREE.Vector3();
|
|
31669
|
+
at3.m4.decompose(pos2, quat3, scale2);
|
|
31670
|
+
for (const box of solids) {
|
|
31671
|
+
const c2 = new this.THREE.Vector3((box[0] + box[3]) / 2, (box[1] + box[4]) / 2, (box[2] + box[5]) / 2).applyMatrix4(at3.m4);
|
|
31672
|
+
const half2 = [Math.max(5e-3, Math.abs((box[3] - box[0]) * scale2.x) / 2), Math.max(5e-3, Math.abs((box[4] - box[1]) * scale2.y) / 2), Math.max(5e-3, Math.abs((box[5] - box[2]) * scale2.z) / 2)];
|
|
31673
|
+
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half: half2, rotation: [quat3.x, quat3.y, quat3.z, quat3.w] });
|
|
31180
31674
|
}
|
|
31675
|
+
return;
|
|
31676
|
+
}
|
|
31677
|
+
if (built2) {
|
|
31678
|
+
const pos2 = new this.THREE.Vector3();
|
|
31679
|
+
const quat3 = new this.THREE.Quaternion();
|
|
31680
|
+
const scale2 = new this.THREE.Vector3();
|
|
31681
|
+
at3.m4.decompose(pos2, quat3, scale2);
|
|
31682
|
+
const c2 = new this.THREE.Vector3();
|
|
31683
|
+
const q = new this.THREE.Quaternion();
|
|
31684
|
+
const even = (Math.abs(scale2.x) + Math.abs(scale2.y) + Math.abs(scale2.z)) / 3;
|
|
31685
|
+
for (const solid of built2) {
|
|
31686
|
+
c2.set(solid.center[0], solid.center[1], solid.center[2]).applyMatrix4(at3.m4);
|
|
31687
|
+
q.set(solid.rotation[0], solid.rotation[1], solid.rotation[2], solid.rotation[3]);
|
|
31688
|
+
const turned = Math.abs(q.w) < 1 - 1e-9;
|
|
31689
|
+
const s = turned ? [even, even, even] : [Math.abs(scale2.x), Math.abs(scale2.y), Math.abs(scale2.z)];
|
|
31690
|
+
q.premultiply(quat3).normalize();
|
|
31691
|
+
const round2 = isRoundSolid(solid) && Math.abs(s[0] - s[2]) <= 1e-9;
|
|
31692
|
+
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half: [Math.max(5e-3, solid.half[0] * s[0]), Math.max(5e-3, solid.half[1] * s[1]), Math.max(5e-3, solid.half[2] * s[2])], rotation: [q.x, q.y, q.z, q.w], ...round2 ? { round: true } : {} });
|
|
31693
|
+
}
|
|
31694
|
+
return;
|
|
31695
|
+
}
|
|
31696
|
+
const own = [];
|
|
31697
|
+
this.visuals.rangePoints(mv, new this.THREE.Matrix4(), own);
|
|
31698
|
+
const drawn = hollowBoxesOf(own, mv.range ? RANGED : OWN_MESH);
|
|
31699
|
+
if (drawn) {
|
|
31700
|
+
const pos2 = new this.THREE.Vector3();
|
|
31701
|
+
const quat3 = new this.THREE.Quaternion();
|
|
31702
|
+
const scale2 = new this.THREE.Vector3();
|
|
31703
|
+
at3.m4.decompose(pos2, quat3, scale2);
|
|
31704
|
+
const c2 = new this.THREE.Vector3();
|
|
31705
|
+
const q = new this.THREE.Quaternion();
|
|
31706
|
+
const even = (Math.abs(scale2.x) + Math.abs(scale2.y) + Math.abs(scale2.z)) / 3;
|
|
31707
|
+
for (const box of drawn) {
|
|
31708
|
+
c2.set(box.center[0], box.center[1], box.center[2]).applyMatrix4(at3.m4);
|
|
31709
|
+
const half2 = box.rotation ? [box.half[0] * even, box.half[1] * even, box.half[2] * even] : [Math.abs(box.half[0] * scale2.x), Math.abs(box.half[1] * scale2.y), Math.abs(box.half[2] * scale2.z)];
|
|
31710
|
+
if (box.rotation) q.set(box.rotation[0], box.rotation[1], box.rotation[2], box.rotation[3]).premultiply(quat3).normalize();
|
|
31711
|
+
else q.copy(quat3);
|
|
31712
|
+
const thin = mv.range ? 0 : 5e-3;
|
|
31713
|
+
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half: [Math.max(thin, half2[0]), Math.max(thin, half2[1]), Math.max(thin, half2[2])], rotation: [q.x, q.y, q.z, q.w] });
|
|
31714
|
+
}
|
|
31715
|
+
return;
|
|
31716
|
+
}
|
|
31717
|
+
if (mv.range) {
|
|
31181
31718
|
if (isRigidPose(at3.m4.elements)) {
|
|
31182
31719
|
const turn2 = new this.THREE.Quaternion().setFromRotationMatrix(at3.m4);
|
|
31183
31720
|
const c2 = new this.THREE.Vector3();
|
|
@@ -31200,11 +31737,14 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31200
31737
|
at3.m4.decompose(pos, quat2, scale);
|
|
31201
31738
|
const c = at3.lb.getCenter(new this.THREE.Vector3()).applyMatrix4(at3.m4);
|
|
31202
31739
|
const size = at3.lb.getSize(new this.THREE.Vector3());
|
|
31203
|
-
|
|
31204
|
-
|
|
31205
|
-
|
|
31206
|
-
|
|
31207
|
-
|
|
31740
|
+
const half = [Math.max(5e-3, Math.abs(size.x * scale.x) / 2), Math.max(5e-3, Math.abs(size.y * scale.y) / 2), Math.max(5e-3, Math.abs(size.z * scale.z) / 2)];
|
|
31741
|
+
const geometry = mv.mesh.geometry;
|
|
31742
|
+
const params = geometry.parameters ?? {};
|
|
31743
|
+
const whole = typeof params.thetaLength !== "number" || Math.abs(params.thetaLength - 2 * Math.PI) < 1e-6;
|
|
31744
|
+
const cylinder = geometry.type === "CylinderGeometry" && !mv.range;
|
|
31745
|
+
const straight = cylinder && whole && params.openEnded !== true && isRoundSolid({ kind: params.radiusTop === params.radiusBottom ? "cylinder" : "cone", half });
|
|
31746
|
+
const curved = !mv.range && !straight && (cylinder || geometry.type === "ConeGeometry" || geometry.type === "SphereGeometry");
|
|
31747
|
+
out.push({ center: [c.x - cx, c.y - cy, c.z - cz], half, rotation: [quat2.x, quat2.y, quat2.z, quat2.w], ...straight ? { round: true } : {}, ...curved ? { hull: this.hullOf(mv, at3.lb, scale) } : {} });
|
|
31208
31748
|
}
|
|
31209
31749
|
/**
|
|
31210
31750
|
* A piece of furniture standing on feet too close for its height (a board on two legs in a line, a lone leg) does not stay up: the box of a piece hides that its weight is up
|
|
@@ -31781,6 +32321,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31781
32321
|
wakeRegion(x, z, radius) {
|
|
31782
32322
|
this.fragments.wakeRegion(x, z, radius);
|
|
31783
32323
|
this.pieceSys.wakeRegion(x, z, radius);
|
|
32324
|
+
if (this.autoSplit && this.undermined.length < UNDERMINED_MAX) this.undermined.push({ x, z, radius });
|
|
31784
32325
|
}
|
|
31785
32326
|
stats() {
|
|
31786
32327
|
return { fragments: this.fragments.count, particles: this.vfx.sprites().live + this.ownedVfxParticles(), pieces: this.pieceSys.list.length, decals: this.visuals.decalCount + this.ground.count };
|
|
@@ -31839,6 +32380,55 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31839
32380
|
};
|
|
31840
32381
|
return ch(16) | ch(8) | ch(0);
|
|
31841
32382
|
}
|
|
32383
|
+
function solidBoxesOf(geometry) {
|
|
32384
|
+
const position = geometry.getAttribute("position");
|
|
32385
|
+
if (!position || position.count <= 24) return null;
|
|
32386
|
+
const parent = new Int32Array(position.count);
|
|
32387
|
+
for (let i = 0; i < parent.length; i++) parent[i] = i;
|
|
32388
|
+
const find = (i) => {
|
|
32389
|
+
while (parent[i] !== i) {
|
|
32390
|
+
parent[i] = parent[parent[i]];
|
|
32391
|
+
i = parent[i];
|
|
32392
|
+
}
|
|
32393
|
+
return i;
|
|
32394
|
+
};
|
|
32395
|
+
const join = (a, b) => {
|
|
32396
|
+
const ra = find(a), rb = find(b);
|
|
32397
|
+
if (ra !== rb) parent[ra] = rb;
|
|
32398
|
+
};
|
|
32399
|
+
const corners = /* @__PURE__ */ new Map();
|
|
32400
|
+
for (let i = 0; i < position.count; i++) {
|
|
32401
|
+
const key = `${Math.round(position.getX(i) / SOLID_WELD)},${Math.round(position.getY(i) / SOLID_WELD)},${Math.round(position.getZ(i) / SOLID_WELD)}`;
|
|
32402
|
+
const first = corners.get(key);
|
|
32403
|
+
if (first === void 0) corners.set(key, i);
|
|
32404
|
+
else join(i, first);
|
|
32405
|
+
}
|
|
32406
|
+
const index = geometry.getIndex();
|
|
32407
|
+
const triangles2 = index ? index.count / 3 : position.count / 3;
|
|
32408
|
+
for (let t = 0; t < triangles2; t++) {
|
|
32409
|
+
const a = index ? index.getX(t * 3) : t * 3;
|
|
32410
|
+
join(a, index ? index.getX(t * 3 + 1) : t * 3 + 1);
|
|
32411
|
+
join(a, index ? index.getX(t * 3 + 2) : t * 3 + 2);
|
|
32412
|
+
}
|
|
32413
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
32414
|
+
for (let i = 0; i < position.count; i++) {
|
|
32415
|
+
const root = find(i);
|
|
32416
|
+
const x = position.getX(i), y = position.getY(i), z = position.getZ(i);
|
|
32417
|
+
const box = boxes.get(root);
|
|
32418
|
+
if (!box) {
|
|
32419
|
+
if (boxes.size >= SOLIDS_MAX) return null;
|
|
32420
|
+
boxes.set(root, [x, y, z, x, y, z]);
|
|
32421
|
+
continue;
|
|
32422
|
+
}
|
|
32423
|
+
box[0] = Math.min(box[0], x);
|
|
32424
|
+
box[1] = Math.min(box[1], y);
|
|
32425
|
+
box[2] = Math.min(box[2], z);
|
|
32426
|
+
box[3] = Math.max(box[3], x);
|
|
32427
|
+
box[4] = Math.max(box[4], y);
|
|
32428
|
+
box[5] = Math.max(box[5], z);
|
|
32429
|
+
}
|
|
32430
|
+
return boxes.size > 1 ? [...boxes.values()] : null;
|
|
32431
|
+
}
|
|
31842
32432
|
function convexHull2(points) {
|
|
31843
32433
|
const sorted = [...points].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
31844
32434
|
if (sorted.length < 3) return sorted;
|
|
@@ -32070,9 +32660,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
32070
32660
|
if (!bases.has(base)) bases.set(base, { id: base, category: tiers[0]?.category ?? "", layers: { close: tiers[0]?.layers.close ?? [] } });
|
|
32071
32661
|
}
|
|
32072
32662
|
for (const sound of bases.values()) {
|
|
32073
|
-
const
|
|
32663
|
+
const numbers2 = options.sounds?.[sound.id] ?? options.defaults?.(sound);
|
|
32074
32664
|
const close = refsOf(sound.layers.close, baseUrl);
|
|
32075
|
-
if (!
|
|
32665
|
+
if (!numbers2 || close.length === 0) continue;
|
|
32076
32666
|
const tiers = (tiersOf.get(sound.id) ?? []).map((tier) => {
|
|
32077
32667
|
const name = splitTier(tier.id).tier;
|
|
32078
32668
|
const tierFar = refsOf(tier.layers.far, baseUrl);
|
|
@@ -32084,20 +32674,20 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
32084
32674
|
const files = [sound, ...tiersOf.get(sound.id) ?? []].flatMap((entry) => Object.values(entry.layers).flatMap((entries2) => entries2 ?? []));
|
|
32085
32675
|
samples.push({
|
|
32086
32676
|
id: sound.id,
|
|
32087
|
-
bus:
|
|
32677
|
+
bus: numbers2.bus,
|
|
32088
32678
|
close,
|
|
32089
32679
|
...far2.length > 0 ? { far: far2 } : {},
|
|
32090
32680
|
...tiers.length > 0 ? { tiers } : {},
|
|
32091
|
-
...
|
|
32092
|
-
...indoor.length > 0 || outdoor.length > 0 ? { tail: { ...indoor.length > 0 ? { indoor } : {}, ...outdoor.length > 0 ? { outdoor } : {}, ...
|
|
32093
|
-
...
|
|
32094
|
-
...
|
|
32095
|
-
...
|
|
32096
|
-
...
|
|
32097
|
-
...
|
|
32098
|
-
...
|
|
32099
|
-
...
|
|
32100
|
-
...
|
|
32681
|
+
...numbers2.crossover ? { crossover: numbers2.crossover } : {},
|
|
32682
|
+
...indoor.length > 0 || outdoor.length > 0 ? { tail: { ...indoor.length > 0 ? { indoor } : {}, ...outdoor.length > 0 ? { outdoor } : {}, ...numbers2.tailGain === void 0 ? {} : { gain: numbers2.tailGain } } } : {},
|
|
32683
|
+
...numbers2.pitch === void 0 ? {} : { pitch: numbers2.pitch },
|
|
32684
|
+
...numbers2.gain === void 0 ? {} : { gain: numbers2.gain },
|
|
32685
|
+
...numbers2.falloff ? { falloff: numbers2.falloff } : {},
|
|
32686
|
+
...numbers2.cutoffK === void 0 ? {} : { cutoffK: numbers2.cutoffK },
|
|
32687
|
+
...numbers2.group ? { group: numbers2.group } : {},
|
|
32688
|
+
...numbers2.priority === void 0 ? {} : { priority: numbers2.priority },
|
|
32689
|
+
...numbers2.choke ? { choke: numbers2.choke } : {},
|
|
32690
|
+
...numbers2.fallback ? { fallback: numbers2.fallback } : {},
|
|
32101
32691
|
sources: files.map((file) => `${file.file}: ${file.source} ${file.author} ${file.license}`)
|
|
32102
32692
|
});
|
|
32103
32693
|
}
|