@adatechnology/game-destruction-three 1.0.0 → 1.1.1
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 +741 -125
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +611 -100
- 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 +12 -12
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;
|
|
@@ -14443,6 +14627,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14443
14627
|
var RING_SEGMENTS = 16;
|
|
14444
14628
|
var TOPPLE = 3;
|
|
14445
14629
|
var HOLD_MARGIN = 4;
|
|
14630
|
+
var HOLD_MARGIN_REAL = 6;
|
|
14631
|
+
var holdPush = (params) => {
|
|
14632
|
+
const e = Math.abs(params.edge);
|
|
14633
|
+
const arm = params.height * params.height + e * e;
|
|
14634
|
+
if (arm <= 0) return 0;
|
|
14635
|
+
return Math.min(HOLD_MARGIN * params.gravity * e / arm, HOLD_MARGIN_REAL * params.gravity * e / (params.turning + arm));
|
|
14636
|
+
};
|
|
14446
14637
|
var SIDE_DEAD = 0.01;
|
|
14447
14638
|
var BOX_FOOT = 0.02;
|
|
14448
14639
|
var PUSH_SPIN = 0.3;
|
|
@@ -14899,7 +15090,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14899
15090
|
return { kind: "compound", children: [{ shape: { kind: "cylinder", halfHeight: b.halfExtents[round2.axis], radius: round2.radius }, position: [0, 0, 0], rotation: rotation2 }] };
|
|
14900
15091
|
}
|
|
14901
15092
|
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 })) };
|
|
15093
|
+
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
15094
|
}
|
|
14904
15095
|
return { kind: "box", half: b.halfExtents };
|
|
14905
15096
|
}
|
|
@@ -15205,11 +15396,24 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15205
15396
|
/**
|
|
15206
15397
|
* The push (rad/s2) that turns a piece about the edge of its support at `edge` (m from its centre, `height` m above it): the kit's `TOPPLE`, and on a support narrow both ways (a leg, a pole: a plate on its
|
|
15207
15398
|
* edge is narrow one way only) at least what beats gravity's hold (at most `g |edge| / (height^2 + edge^2)` for any shape: a 5 cm leg 74 cm tall held against `TOPPLE` alone and stood for ever). Not where only
|
|
15208
|
-
* the contacts of one instant sit off its centre: a box rocking on a table's edge reads like that, and stays.
|
|
15399
|
+
* the contacts of one instant sit off its centre: a box rocking on a table's edge reads like that, and stays. `turning` is the piece's own inertia about that edge's
|
|
15400
|
+
* axis (`turningOf`): the strong push is bounded by it (`holdPush`).
|
|
15209
15401
|
*/
|
|
15210
|
-
topplePush(edge, height, isNarrow) {
|
|
15402
|
+
topplePush(edge, height, isNarrow, turning) {
|
|
15211
15403
|
const push = TOPPLE * Math.min(height, 1);
|
|
15212
|
-
return isNarrow ? Math.max(push,
|
|
15404
|
+
return isNarrow ? Math.max(push, holdPush({ edge, height, gravity: this.o.gravity, turning })) : push;
|
|
15405
|
+
}
|
|
15406
|
+
/**
|
|
15407
|
+
* The moment of inertia of the piece per kilogram (m²) about the world axis `axis` (0 x, 2 z) through its centre of mass, as the box it is: what resists its turning
|
|
15408
|
+
* about the edge it would go over (`holdPush`).
|
|
15409
|
+
*/
|
|
15410
|
+
turningOf(b, axis2) {
|
|
15411
|
+
const [hx, hy, hz2] = b.halfExtents;
|
|
15412
|
+
const { x, y, z, w } = b.root.quaternion;
|
|
15413
|
+
const ax = axis2 === 0 ? 1 - 2 * (y * y + z * z) : 2 * (x * z - y * w);
|
|
15414
|
+
const ay = axis2 === 0 ? 2 * (x * y - z * w) : 2 * (y * z + x * w);
|
|
15415
|
+
const az = axis2 === 0 ? 2 * (x * z + y * w) : 1 - 2 * (x * x + y * y);
|
|
15416
|
+
return ((hy * hy + hz2 * hz2) * ax * ax + (hx * hx + hz2 * hz2) * ay * ay + (hx * hx + hy * hy) * az * az) / 3;
|
|
15213
15417
|
}
|
|
15214
15418
|
topple(b, dt) {
|
|
15215
15419
|
const link = this.links.get(b);
|
|
@@ -15277,7 +15481,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15277
15481
|
const v = b.velocity;
|
|
15278
15482
|
if (wx <= wz) {
|
|
15279
15483
|
const edge = dirX > 0 ? x1 : x0;
|
|
15280
|
-
const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN) * dt : 0;
|
|
15484
|
+
const dw = edge * dirX > 0 ? -dirX * this.topplePush(edge, height, isColumn && Math.abs(w[2]) < PUSH_SPIN, this.turningOf(b, 2)) * dt : 0;
|
|
15281
15485
|
const rx = -edge;
|
|
15282
15486
|
const ry = -low;
|
|
15283
15487
|
w[2] += dw;
|
|
@@ -15285,7 +15489,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15285
15489
|
v[1] += dw * rx;
|
|
15286
15490
|
} else {
|
|
15287
15491
|
const edge = dirZ > 0 ? z1 : z0;
|
|
15288
|
-
const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN) * dt : 0;
|
|
15492
|
+
const dw = edge * dirZ > 0 ? dirZ * this.topplePush(edge, height, isColumn && Math.abs(w[0]) < PUSH_SPIN, this.turningOf(b, 0)) * dt : 0;
|
|
15289
15493
|
const rz = -edge;
|
|
15290
15494
|
const ry = -low;
|
|
15291
15495
|
w[0] += dw;
|
|
@@ -17608,6 +17812,33 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
17608
17812
|
return out;
|
|
17609
17813
|
};
|
|
17610
17814
|
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] }));
|
|
17815
|
+
var SLAB_MIN = 0.03;
|
|
17816
|
+
var splitAtHit = (root, hit, axes, count, rnd2) => {
|
|
17817
|
+
let pieces = [root];
|
|
17818
|
+
for (const ax of axes) {
|
|
17819
|
+
const half = root.s[ax] / 2;
|
|
17820
|
+
if (hit[ax] - -half < SLAB_MIN || half - hit[ax] < SLAB_MIN) continue;
|
|
17821
|
+
const next = [];
|
|
17822
|
+
for (const b of pieces) {
|
|
17823
|
+
const lo = b.c[ax] - b.s[ax] / 2;
|
|
17824
|
+
const hi = b.c[ax] + b.s[ax] / 2;
|
|
17825
|
+
for (const [from, to] of [[lo, hit[ax]], [hit[ax], hi]]) {
|
|
17826
|
+
const c = [b.c[0], b.c[1], b.c[2]];
|
|
17827
|
+
const s = [b.s[0], b.s[1], b.s[2]];
|
|
17828
|
+
c[ax] = (from + to) / 2;
|
|
17829
|
+
s[ax] = to - from;
|
|
17830
|
+
next.push({ c, s });
|
|
17831
|
+
}
|
|
17832
|
+
}
|
|
17833
|
+
pieces = next;
|
|
17834
|
+
}
|
|
17835
|
+
while (pieces.length < count) {
|
|
17836
|
+
pieces.sort((a, b) => b.s[axes[0]] * b.s[axes[1]] - a.s[axes[0]] * a.s[axes[1]]);
|
|
17837
|
+
const [big, ...rest] = pieces;
|
|
17838
|
+
pieces = [...bsp(big, 2, axes, rnd2), ...rest];
|
|
17839
|
+
}
|
|
17840
|
+
return pieces;
|
|
17841
|
+
};
|
|
17611
17842
|
var CRUMBS = 6;
|
|
17612
17843
|
var severAt = (inp, root, at3, gap) => {
|
|
17613
17844
|
const dims = root.s;
|
|
@@ -17670,7 +17901,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
17670
17901
|
if (inp.cut) return severAt(inp, root, inp.cut.at, inp.cut.gap);
|
|
17671
17902
|
if (inp.form === "plies") return plyBreak(inp, root, maxFragments);
|
|
17672
17903
|
const n2 = Math.min(maxFragments, 2 + Math.floor(rnd2() * 3));
|
|
17673
|
-
|
|
17904
|
+
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);
|
|
17905
|
+
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
17906
|
if (inp.form !== "granules") return out;
|
|
17675
17907
|
const crumbs = Math.min(CRUMBS, maxFragments - out.length);
|
|
17676
17908
|
if (crumbs <= 0) return out;
|
|
@@ -25998,6 +26230,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
25998
26230
|
}).events;
|
|
25999
26231
|
},
|
|
26000
26232
|
state: (id) => objects.get(id)?.st ?? impls.get(id)?.impl.state() ?? null,
|
|
26233
|
+
anchoredParts: (id) => objects.get(id)?.parts.filter((p) => p.anchored && !isLost(p)).map((p) => p.spec.id) ?? [],
|
|
26234
|
+
fixedInPlace: (id) => {
|
|
26235
|
+
const o = objects.get(id);
|
|
26236
|
+
return !!o && o.spec.fixed === true && o.parts.some((p) => p.anchored && !isLost(p));
|
|
26237
|
+
},
|
|
26001
26238
|
snapshot: (id) => {
|
|
26002
26239
|
const st = objects.get(id)?.st ?? impls.get(id)?.impl.state();
|
|
26003
26240
|
return st ? clone(st) : null;
|
|
@@ -26653,10 +26890,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
26653
26890
|
const turn2 = angle * share * share * (3 - 2 * share);
|
|
26654
26891
|
const cos2 = Math.cos(turn2);
|
|
26655
26892
|
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 *
|
|
26893
|
+
const dot3 = kx * rx + ky * ry + kz * rz;
|
|
26894
|
+
positions[i] = point[0] + rx * cos2 + (ky * rz - kz * ry) * sin2 + kx * dot3 * (1 - cos2);
|
|
26895
|
+
positions[i + 1] = point[1] + ry * cos2 + (kz * rx - kx * rz) * sin2 + ky * dot3 * (1 - cos2);
|
|
26896
|
+
positions[i + 2] = point[2] + rz * cos2 + (kx * ry - ky * rx) * sin2 + kz * dot3 * (1 - cos2);
|
|
26660
26897
|
}
|
|
26661
26898
|
}
|
|
26662
26899
|
|
|
@@ -26825,9 +27062,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
26825
27062
|
const grown = new Uint32Array(size);
|
|
26826
27063
|
grown.set(this.candidates);
|
|
26827
27064
|
this.candidates = grown;
|
|
26828
|
-
const
|
|
26829
|
-
|
|
26830
|
-
this.triangles =
|
|
27065
|
+
const numbers2 = new Uint32Array(Math.max(this.triangles.length, Math.ceil(size / 3)));
|
|
27066
|
+
numbers2.set(this.triangles);
|
|
27067
|
+
this.triangles = numbers2;
|
|
26831
27068
|
this.candidateIndex = new this.THREE.BufferAttribute(this.candidates, 1);
|
|
26832
27069
|
}
|
|
26833
27070
|
};
|
|
@@ -28419,6 +28656,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28419
28656
|
var REBAR_COLOR = 7628380;
|
|
28420
28657
|
var STEEL_DENSITY3 = 7850;
|
|
28421
28658
|
var CHIP_DECAL_EDGE = 0.05;
|
|
28659
|
+
var CHIP_GAP_REACH = 0.03;
|
|
28660
|
+
var CHIP_GAP_SHADE = 0.4;
|
|
28661
|
+
var CHIP_GAP_WIDTH = 1.15;
|
|
28422
28662
|
var CRATER_RADIUS2 = 2.5;
|
|
28423
28663
|
var CRATER_MIN_RADIUS = 0.012;
|
|
28424
28664
|
var CRATER_LIGHTEN = 0.12;
|
|
@@ -28450,10 +28690,71 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28450
28690
|
var HINGE_STILL_SPIN = 0.5;
|
|
28451
28691
|
var PREFIT_SLICE_MS = 1;
|
|
28452
28692
|
var CONTACT_MESHES = 12;
|
|
28453
|
-
var PART_BOX_MESHES =
|
|
28693
|
+
var PART_BOX_MESHES = 96;
|
|
28454
28694
|
var ROUND_SAMPLES = 400;
|
|
28455
|
-
var
|
|
28695
|
+
var ROUND_SIDES2 = 0.12;
|
|
28456
28696
|
var ROUND_SLACK = 1.12;
|
|
28697
|
+
var ROUND_FILL = 0.9;
|
|
28698
|
+
var FILL_GRID = 8;
|
|
28699
|
+
var hullRadiusAt = (profile, radius, at3) => {
|
|
28700
|
+
if (!profile || profile.length < 2) return radius;
|
|
28701
|
+
const hull = [];
|
|
28702
|
+
for (const point of profile) {
|
|
28703
|
+
while (hull.length >= 2) {
|
|
28704
|
+
const [a, ra] = hull[hull.length - 2];
|
|
28705
|
+
const [b, rb] = hull[hull.length - 1];
|
|
28706
|
+
if ((b - a) * (point[1] - ra) - (rb - ra) * (point[0] - a) >= 0) hull.pop();
|
|
28707
|
+
else break;
|
|
28708
|
+
}
|
|
28709
|
+
hull.push(point);
|
|
28710
|
+
}
|
|
28711
|
+
if (at3 <= hull[0][0]) return hull[0][1];
|
|
28712
|
+
for (let i = 1; i < hull.length; i++) {
|
|
28713
|
+
const [a, ra] = hull[i - 1];
|
|
28714
|
+
const [b, rb] = hull[i];
|
|
28715
|
+
if (at3 <= b) return ra + (rb - ra) * (at3 - a) / (b - a || 1);
|
|
28716
|
+
}
|
|
28717
|
+
return hull[hull.length - 1][1];
|
|
28718
|
+
};
|
|
28719
|
+
var insideDrawn = (mesh2, built2, x, y, z) => {
|
|
28720
|
+
if (built2) {
|
|
28721
|
+
for (const solid of built2) {
|
|
28722
|
+
const [qx, qy, qz, qw] = solid.rotation;
|
|
28723
|
+
const px = x - solid.center[0], py = y - solid.center[1], pz = z - solid.center[2];
|
|
28724
|
+
const tx = 2 * (-qy * pz + qz * py), ty = 2 * (-qz * px + qx * pz), tz = 2 * (-qx * py + qy * px);
|
|
28725
|
+
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;
|
|
28726
|
+
const [hx, hy, hz2] = solid.half;
|
|
28727
|
+
if (solid.kind === "cylinder" || solid.kind === "cone") {
|
|
28728
|
+
if (Math.abs(ly) <= hy && (lx / hx) ** 2 + (lz / hz2) ** 2 <= 1) return true;
|
|
28729
|
+
} else if (solid.kind === "sphere") {
|
|
28730
|
+
if ((lx / hx) ** 2 + (ly / hy) ** 2 + (lz / hz2) ** 2 <= 1) return true;
|
|
28731
|
+
} else if (Math.abs(lx) <= hx && Math.abs(ly) <= hy && Math.abs(lz) <= hz2) return true;
|
|
28732
|
+
}
|
|
28733
|
+
return false;
|
|
28734
|
+
}
|
|
28735
|
+
const geometry = mesh2.geometry;
|
|
28736
|
+
const p = geometry.parameters ?? {};
|
|
28737
|
+
const n = (key, fallback2) => typeof p[key] === "number" ? p[key] : fallback2;
|
|
28738
|
+
switch (geometry.type) {
|
|
28739
|
+
case "BoxGeometry":
|
|
28740
|
+
return Math.abs(x) <= n("width", 1) / 2 && Math.abs(y) <= n("height", 1) / 2 && Math.abs(z) <= n("depth", 1) / 2;
|
|
28741
|
+
case "CylinderGeometry":
|
|
28742
|
+
case "ConeGeometry": {
|
|
28743
|
+
const h = n("height", 1) / 2;
|
|
28744
|
+
if (Math.abs(y) > h || p.openEnded === true) return false;
|
|
28745
|
+
const top = geometry.type === "ConeGeometry" ? 0 : n("radiusTop", 1);
|
|
28746
|
+
const bottom = geometry.type === "ConeGeometry" ? n("radius", 1) : n("radiusBottom", 1);
|
|
28747
|
+
return Math.hypot(x, z) <= bottom + (top - bottom) * (y + h) / (2 * h || 1);
|
|
28748
|
+
}
|
|
28749
|
+
case "SphereGeometry":
|
|
28750
|
+
return Math.hypot(x, y, z) <= n("radius", 1);
|
|
28751
|
+
default: {
|
|
28752
|
+
if (!geometry.boundingBox) geometry.computeBoundingBox();
|
|
28753
|
+
const box = geometry.boundingBox;
|
|
28754
|
+
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;
|
|
28755
|
+
}
|
|
28756
|
+
}
|
|
28757
|
+
};
|
|
28457
28758
|
var RIM_POINTS = 12;
|
|
28458
28759
|
var rimPoints = (round2, half) => {
|
|
28459
28760
|
const out = [];
|
|
@@ -28511,6 +28812,16 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28511
28812
|
};
|
|
28512
28813
|
var BROKEN_GAP = 0.03;
|
|
28513
28814
|
var BROKEN_SAMPLES = [[0.5, 0.5], [0.1, 0.1], [0.9, 0.1], [0.1, 0.9], [0.9, 0.9]];
|
|
28815
|
+
var UNDERMINED_MAX = 64;
|
|
28816
|
+
var UNDERMINED_RIM = 0.04;
|
|
28817
|
+
var UNDERMINED_RIM_DROP = 0.05;
|
|
28818
|
+
var UNDERMINED_RIM_RISE = 0.1;
|
|
28819
|
+
var UNDERMINED_STAND = 0.4;
|
|
28820
|
+
var UNDERMINED_KEEP = 0.6;
|
|
28821
|
+
var SOLIDS_MAX = 64;
|
|
28822
|
+
var UNDERMINED_PUSH = 0.6;
|
|
28823
|
+
var UNDERMINED_STILL = 0.05;
|
|
28824
|
+
var SOLID_WELD = 1e-4;
|
|
28514
28825
|
var UNCHECKED_KINDS = /* @__PURE__ */ new Set(["structure", "room", "ground"]);
|
|
28515
28826
|
var FIRE_CEILING_SECONDS = 3600;
|
|
28516
28827
|
var GENERIC_REFERENCE_RADIUS = 15;
|
|
@@ -28658,6 +28969,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28658
28969
|
__publicField(this, "pieceBoxes", /* @__PURE__ */ new WeakMap());
|
|
28659
28970
|
/** Objects broken since the last update: `checkBroken` looks at what is left of them. */
|
|
28660
28971
|
__publicField(this, "broken", /* @__PURE__ */ new Set());
|
|
28972
|
+
/** Discs of ground that changed since the last update (`wakeRegion`): `checkUndermined` looks at what stood on them. */
|
|
28973
|
+
__publicField(this, "undermined", []);
|
|
28661
28974
|
__publicField(this, "staticAt", 0);
|
|
28662
28975
|
__publicField(this, "queue", []);
|
|
28663
28976
|
/** 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 +29542,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29229
29542
|
mv.mesh.updateWorldMatrix(true, false);
|
|
29230
29543
|
m4.multiplyMatrices(inv, mv.mesh.matrixWorld);
|
|
29231
29544
|
const stride = Math.max(1, Math.floor(pos.count / ROUND_SAMPLES));
|
|
29232
|
-
for (let
|
|
29233
|
-
p.fromBufferAttribute(pos,
|
|
29545
|
+
for (let i2 = 0; i2 < pos.count; i2 += stride) {
|
|
29546
|
+
p.fromBufferAttribute(pos, i2).applyMatrix4(m4);
|
|
29234
29547
|
points.push([p.x - cx, p.y - cy, p.z - cz]);
|
|
29235
29548
|
}
|
|
29236
29549
|
}
|
|
@@ -29238,22 +29551,64 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29238
29551
|
const drawn = new Float64Array(3);
|
|
29239
29552
|
for (const q of points) for (let k = 0; k < 3; k++) drawn[k] = Math.max(drawn[k], Math.abs(q[k]));
|
|
29240
29553
|
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[
|
|
29554
|
+
const [i2, j2] = axis3 === 0 ? [1, 2] : axis3 === 1 ? [0, 2] : [0, 1];
|
|
29555
|
+
if (Math.abs(half[i2] - half[j2]) > ROUND_SIDES2 * Math.max(half[i2], half[j2])) return null;
|
|
29556
|
+
if (Math.abs(drawn[i2] - drawn[j2]) > ROUND_SIDES2 * Math.max(drawn[i2], drawn[j2])) return null;
|
|
29557
|
+
const reach2 = (drawn[i2] + drawn[j2]) / 2;
|
|
29558
|
+
for (const q of points) if (Math.hypot(q[i2], q[j2]) > reach2 * ROUND_SLACK) return null;
|
|
29559
|
+
return (half[i2] + half[j2]) / 2;
|
|
29247
29560
|
};
|
|
29248
29561
|
const radii = [0, 1, 2].map(fits);
|
|
29249
29562
|
if (radii.every((r) => r !== null)) {
|
|
29250
29563
|
const radius2 = (half[0] + half[1] + half[2]) / 3;
|
|
29564
|
+
if (this.drawnShareOf(b, body, (q) => Math.hypot(q[0], q[1], q[2]) <= radius2) < ROUND_FILL) return null;
|
|
29251
29565
|
return { kind: "sphere", axis: 1, radius: radius2, inertia: body.inertiaGiven ?? this.inertiaOf(b, body, "sphere", 1, radius2) };
|
|
29252
29566
|
}
|
|
29253
29567
|
const axis2 = [0, 1, 2].find((k) => radii[k] !== null);
|
|
29254
29568
|
if (axis2 === void 0) return null;
|
|
29255
29569
|
const radius = radii[axis2] ?? 0;
|
|
29256
|
-
|
|
29570
|
+
const profile = profileOf2(points, axis2, half[axis2], radius);
|
|
29571
|
+
const [i, j] = axis2 === 0 ? [1, 2] : axis2 === 1 ? [0, 2] : [0, 1];
|
|
29572
|
+
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;
|
|
29573
|
+
return { kind: "cylinder", axis: axis2, radius, inertia: body.inertiaGiven ?? this.inertiaOf(b, body, "cylinder", axis2, radius), profile };
|
|
29574
|
+
}
|
|
29575
|
+
/** 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`). */
|
|
29576
|
+
hullOf(mv, lb, scale) {
|
|
29577
|
+
const own = [];
|
|
29578
|
+
this.visuals.rangePoints(mv, new this.THREE.Matrix4(), own);
|
|
29579
|
+
const c = lb.getCenter(new this.THREE.Vector3());
|
|
29580
|
+
const out = [];
|
|
29581
|
+
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));
|
|
29582
|
+
return out;
|
|
29583
|
+
}
|
|
29584
|
+
/**
|
|
29585
|
+
* 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
|
|
29586
|
+
* 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).
|
|
29587
|
+
*/
|
|
29588
|
+
drawnShareOf(b, body, inside) {
|
|
29589
|
+
const inv = specFrameInverse(this.THREE, b.root);
|
|
29590
|
+
const meshes = this.meshesOf(b).filter((mv) => this.visuals.shown(mv) && !mv.host).map((mv) => {
|
|
29591
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
29592
|
+
return { mesh: mv.mesh, built: builtSolidsOf(mv.mesh), back: new this.THREE.Matrix4().multiplyMatrices(inv, mv.mesh.matrixWorld).invert() };
|
|
29593
|
+
});
|
|
29594
|
+
const [cx, cy, cz] = body.localCenter;
|
|
29595
|
+
const half = body.halfExtents;
|
|
29596
|
+
const p = new this.THREE.Vector3();
|
|
29597
|
+
let shape = 0;
|
|
29598
|
+
let drawn = 0;
|
|
29599
|
+
for (let a = 0; a < FILL_GRID; a++) for (let c = 0; c < FILL_GRID; c++) for (let d = 0; d < FILL_GRID; d++) {
|
|
29600
|
+
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)];
|
|
29601
|
+
if (!inside(q)) continue;
|
|
29602
|
+
shape++;
|
|
29603
|
+
for (const m of meshes) {
|
|
29604
|
+
p.set(q[0] + cx, q[1] + cy, q[2] + cz).applyMatrix4(m.back);
|
|
29605
|
+
if (insideDrawn(m.mesh, m.built, p.x, p.y, p.z)) {
|
|
29606
|
+
drawn++;
|
|
29607
|
+
break;
|
|
29608
|
+
}
|
|
29609
|
+
}
|
|
29610
|
+
}
|
|
29611
|
+
return shape === 0 ? 1 : drawn / shape;
|
|
29257
29612
|
}
|
|
29258
29613
|
pieces() {
|
|
29259
29614
|
return [...this.pieceSys.list];
|
|
@@ -29343,6 +29698,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29343
29698
|
this.work?.beginFrame();
|
|
29344
29699
|
if (!this.attached) this.drainQueue();
|
|
29345
29700
|
this.checkBroken();
|
|
29701
|
+
this.checkUndermined();
|
|
29346
29702
|
for (const b of this.bounds.values()) b.onFrame?.(dt);
|
|
29347
29703
|
for (const b of this.bounds.values()) if (b.soilNode && this.world.state(b.id)?.soil?.status === "yielding") this.onSettle(b.id);
|
|
29348
29704
|
this.settlement.update(dt);
|
|
@@ -30401,9 +30757,33 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30401
30757
|
const rotation2 = new T.Quaternion(ev.rotation[0], ev.rotation[1], ev.rotation[2], ev.rotation[3]);
|
|
30402
30758
|
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
30759
|
this.vfx.peekWorkshop()?.decals.clearInside(ev.center, [half.x, half.y, half.z], ev.rotation);
|
|
30760
|
+
if (pv) this.drawChipGap(pv, ev, center, rotation2);
|
|
30404
30761
|
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
30762
|
this.impactSound(pv?.material ?? "", ev.center, 0.7, ev.blow);
|
|
30406
30763
|
}
|
|
30764
|
+
/**
|
|
30765
|
+
* 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,
|
|
30766
|
+
* 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.
|
|
30767
|
+
*/
|
|
30768
|
+
drawChipGap(pv, ev, center, rotation2) {
|
|
30769
|
+
const mv = this.nearestMesh(pv, center);
|
|
30770
|
+
if (!mv || mv.mesh.userData.drawnSpalls?.includes(ev.part)) return;
|
|
30771
|
+
const def = this.world.materials.get(pv.material);
|
|
30772
|
+
const inner = def?.visual?.innerColor ?? fallbackColor(def);
|
|
30773
|
+
const color = [16, 8, 0].reduce((hex, shift) => hex | Math.round((inner >> shift & 255) * CHIP_GAP_SHADE) << shift, 0);
|
|
30774
|
+
const box = this.visuals.worldBox(mv, new this.THREE.Box3());
|
|
30775
|
+
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
30776
|
+
for (const side of [-1, 1]) {
|
|
30777
|
+
const normal = new this.THREE.Vector3(axis2 === 0 ? side : 0, axis2 === 1 ? side : 0, axis2 === 2 ? side : 0).applyQuaternion(rotation2);
|
|
30778
|
+
const face = center.clone().addScaledVector(normal, ev.size[axis2] / 2);
|
|
30779
|
+
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";
|
|
30780
|
+
const surface = normal[k] > 0 ? box.max[k] : box.min[k];
|
|
30781
|
+
if (Math.abs(face[k] - surface) > CHIP_GAP_REACH) continue;
|
|
30782
|
+
face[k] = surface;
|
|
30783
|
+
this.visuals.addSpall(mv, face, normal, Math.min(ev.size[(axis2 + 1) % 3], ev.size[(axis2 + 2) % 3]) / 2 * CHIP_GAP_WIDTH, color);
|
|
30784
|
+
}
|
|
30785
|
+
}
|
|
30786
|
+
}
|
|
30407
30787
|
onFracture(ev) {
|
|
30408
30788
|
const b = this.bounds.get(ev.object);
|
|
30409
30789
|
const pv = b?.parts.get(ev.part);
|
|
@@ -30594,7 +30974,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30594
30974
|
if (!old.round) this.setContacts(b, old, this.meshesOf(b).filter((mv) => this.visuals.shown(mv)));
|
|
30595
30975
|
} else if (old.partBoxes) this.fitPartBoxes(b, old);
|
|
30596
30976
|
if (!this.splittingAtLoad) old.sleeping = false;
|
|
30597
|
-
} else if (kitOriginOf(b.root)?.kind === "furniture" && !this.splittingAtLoad) {
|
|
30977
|
+
} else if (kitOriginOf(b.root)?.kind === "furniture" && !this.splittingAtLoad && !this.heldByWorld(objectId)) {
|
|
30598
30978
|
const piece = this.makePiece(objectId);
|
|
30599
30979
|
piece.apart = true;
|
|
30600
30980
|
this.tipIfTopHeavy(b, true);
|
|
@@ -30788,9 +31168,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30788
31168
|
});
|
|
30789
31169
|
if (holds.length !== 1) return null;
|
|
30790
31170
|
const joint = holds[0];
|
|
30791
|
-
const
|
|
30792
|
-
const a =
|
|
30793
|
-
const c =
|
|
31171
|
+
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);
|
|
31172
|
+
const a = boxOf2(joint.a);
|
|
31173
|
+
const c = boxOf2(joint.b);
|
|
30794
31174
|
if (!a || !c) return null;
|
|
30795
31175
|
const point = [0, 0, 0];
|
|
30796
31176
|
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 +31260,16 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30880
31260
|
if (!body.round) this.setContacts(b, body, left);
|
|
30881
31261
|
}
|
|
30882
31262
|
body.sleeping = false;
|
|
31263
|
+
if (!structural && !body.round && !body.held && kitOriginOf(b.root)?.kind === "furniture" && Math.hypot(...body.velocity) <= UNDERMINED_STILL) this.goOverIfBalanced(b, body, left);
|
|
30883
31264
|
return;
|
|
30884
31265
|
}
|
|
30885
|
-
if (structural) return;
|
|
30886
|
-
const
|
|
30887
|
-
const whole = [...b.parts.values()].flatMap((pv) => pv.meshes).map(
|
|
31266
|
+
if (structural || this.heldByWorld(objectId)) return;
|
|
31267
|
+
const boxOf2 = (mv) => this.visuals.worldBox(mv, new this.THREE.Box3());
|
|
31268
|
+
const whole = [...b.parts.values()].flatMap((pv) => pv.meshes).map(boxOf2).filter((one) => !one.isEmpty());
|
|
30888
31269
|
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
31270
|
const floor2 = Math.min(...whole.map((one) => one.min.y));
|
|
30890
31271
|
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(
|
|
31272
|
+
const leftBoxes = left.map(boxOf2).filter((one) => !one.isEmpty());
|
|
30892
31273
|
const now = feetOf(leftBoxes);
|
|
30893
31274
|
let away = null;
|
|
30894
31275
|
const was = feetOf(whole);
|
|
@@ -30945,7 +31326,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30945
31326
|
}
|
|
30946
31327
|
releaseIfFloating(objectId) {
|
|
30947
31328
|
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;
|
|
31329
|
+
if (!b || b.piece || this.pieceSys.get(objectId) || !this.autoSplit || UNCHECKED_KINDS.has(this.kindOf(b)) || this.heldByWorld(objectId)) return false;
|
|
30949
31330
|
const boxes = this.shownBoxes(objectId);
|
|
30950
31331
|
if (boxes.length === 0) return false;
|
|
30951
31332
|
const whole = new this.THREE.Box3();
|
|
@@ -30964,6 +31345,145 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30964
31345
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
30965
31346
|
return true;
|
|
30966
31347
|
}
|
|
31348
|
+
/**
|
|
31349
|
+
* 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
|
|
31350
|
+
* 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
|
|
31351
|
+
* 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
|
|
31352
|
+
* 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
|
|
31353
|
+
* what lay on it slides or falls off. Structures answer to their own load path.
|
|
31354
|
+
*/
|
|
31355
|
+
checkUndermined() {
|
|
31356
|
+
if (this.undermined.length === 0) return;
|
|
31357
|
+
const discs = this.undermined.splice(0);
|
|
31358
|
+
const inDisc = (x, z, d) => Math.hypot(x - d.x, z - d.z) <= d.radius;
|
|
31359
|
+
for (const b of [...this.bounds.values()]) {
|
|
31360
|
+
if (this.kindOf(b) !== "furniture" && !this.o.shoveable?.(b.id)) continue;
|
|
31361
|
+
const was = b.piece ?? this.pieceSys.get(b.id) ?? null;
|
|
31362
|
+
if (was && (was.held || Math.hypot(...was.velocity) > UNDERMINED_STILL)) continue;
|
|
31363
|
+
const meshes = this.meshesOf(b).filter((mv) => this.visuals.shown(mv));
|
|
31364
|
+
const boxes = meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty());
|
|
31365
|
+
if (boxes.length === 0) continue;
|
|
31366
|
+
const reach2 = boxes.reduce((all, one) => all.union(one), new this.THREE.Box3());
|
|
31367
|
+
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;
|
|
31368
|
+
const feet = this.lowPoints(meshes);
|
|
31369
|
+
if (!feet) continue;
|
|
31370
|
+
const { floor: floor2, points } = feet;
|
|
31371
|
+
const held = [];
|
|
31372
|
+
const lost = [];
|
|
31373
|
+
for (const point of points) (this.holdsAt(b.id, point[0], point[1], floor2) ? held : lost).push(point);
|
|
31374
|
+
if (lost.length === 0) continue;
|
|
31375
|
+
if (!lost.some(([x, z]) => discs.some((d) => inDisc(x, z, d) && this.stoodBeside(x, z, d, floor2)))) continue;
|
|
31376
|
+
const centre = centreOfBoxes(boxes);
|
|
31377
|
+
if (this.standsWith(held, points, centre, floor2)) continue;
|
|
31378
|
+
let body;
|
|
31379
|
+
if (was) body = was;
|
|
31380
|
+
else {
|
|
31381
|
+
const piece = this.makePiece(b.id);
|
|
31382
|
+
body = b.piece ?? piece;
|
|
31383
|
+
body.apart = true;
|
|
31384
|
+
this.setContacts(b, body, meshes, true);
|
|
31385
|
+
}
|
|
31386
|
+
const gx = lost.reduce((sum, p) => sum + p[0], 0) / lost.length - centre[0];
|
|
31387
|
+
const gz = lost.reduce((sum, p) => sum + p[1], 0) / lost.length - centre[2];
|
|
31388
|
+
const length = Math.hypot(gx, gz);
|
|
31389
|
+
body.sleeping = false;
|
|
31390
|
+
body.still = 0;
|
|
31391
|
+
body.calmAt = null;
|
|
31392
|
+
if (held.length > 0 && length > 1e-6) this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + gx, floor2, centre[2] + gz]);
|
|
31393
|
+
if (!was) this.o.onLoosened?.(b.id, body, "ground");
|
|
31394
|
+
}
|
|
31395
|
+
}
|
|
31396
|
+
/**
|
|
31397
|
+
* 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
|
|
31398
|
+
* that polygon (its weight does the rest); one that stands on nothing falls by itself.
|
|
31399
|
+
*/
|
|
31400
|
+
goOverIfBalanced(b, body, meshes) {
|
|
31401
|
+
const feet = this.lowPoints(meshes);
|
|
31402
|
+
if (!feet) return;
|
|
31403
|
+
const held = feet.points.filter(([x, z]) => this.holdsAt(b.id, x, z, feet.floor));
|
|
31404
|
+
if (held.length < 3) return;
|
|
31405
|
+
const centre = centreOfBoxes(meshes.map((mv) => this.visuals.worldBox(mv, new this.THREE.Box3())).filter((one) => !one.isEmpty()));
|
|
31406
|
+
if (this.standsWith(held, null, centre, feet.floor)) return;
|
|
31407
|
+
const inside = insideBy(convexHull2(held), [centre[0], centre[2]]);
|
|
31408
|
+
const reach2 = this.reachAlong(body, inside.out.x, inside.out.z);
|
|
31409
|
+
this.pieceSys.impulse(body, [0, -body.mass * UNDERMINED_PUSH, 0], [centre[0] + inside.out.x * reach2, feet.floor, centre[2] + inside.out.z * reach2]);
|
|
31410
|
+
}
|
|
31411
|
+
/** How far (m) the box of a piece reaches from its middle along the level direction (x, z), turned as it is: the support of its box that way. */
|
|
31412
|
+
reachAlong(body, x, z) {
|
|
31413
|
+
const e = new this.THREE.Matrix4().makeRotationFromQuaternion(body.root.quaternion).elements;
|
|
31414
|
+
const [hx, hy, hz2] = body.halfExtents;
|
|
31415
|
+
return hx * Math.abs(e[0] * x + e[2] * z) + hy * Math.abs(e[4] * x + e[6] * z) + hz2 * Math.abs(e[8] * x + e[10] * z);
|
|
31416
|
+
}
|
|
31417
|
+
/**
|
|
31418
|
+
* 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
|
|
31419
|
+
* 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).
|
|
31420
|
+
*/
|
|
31421
|
+
standsWith(held, all, centre, floor2) {
|
|
31422
|
+
if (held.length < 3) return false;
|
|
31423
|
+
const now = insideBy(convexHull2([...held]), [centre[0], centre[2]]).depth;
|
|
31424
|
+
if (now > UNDERMINED_STAND * (centre[1] - floor2)) return true;
|
|
31425
|
+
return all !== null && now >= UNDERMINED_KEEP * insideBy(convexHull2([...all]), [centre[0], centre[2]]).depth;
|
|
31426
|
+
}
|
|
31427
|
+
/**
|
|
31428
|
+
* 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
|
|
31429
|
+
* 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
|
|
31430
|
+
* 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.
|
|
31431
|
+
*/
|
|
31432
|
+
lowPoints(meshes) {
|
|
31433
|
+
const faces = [];
|
|
31434
|
+
let floor2 = Infinity;
|
|
31435
|
+
for (const mv of meshes) {
|
|
31436
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
31437
|
+
const points = [];
|
|
31438
|
+
this.visuals.rangePoints(mv, mv.mesh.matrixWorld, points);
|
|
31439
|
+
const count = points.length / 3;
|
|
31440
|
+
const index = mv.mesh.geometry.getIndex()?.array;
|
|
31441
|
+
const from = mv.range ? mv.range[0] : 0;
|
|
31442
|
+
const total = index ? index.length : count;
|
|
31443
|
+
for (let i = 0; i + 2 < total; i += 3) {
|
|
31444
|
+
const a = (index ? index[i] : i) - from, b = (index ? index[i + 1] : i + 1) - from, c = (index ? index[i + 2] : i + 2) - from;
|
|
31445
|
+
if (a < 0 || b < 0 || c < 0 || a >= count || b >= count || c >= count) continue;
|
|
31446
|
+
for (const k of [a, b, c]) {
|
|
31447
|
+
faces.push(points[k * 3], points[k * 3 + 1], points[k * 3 + 2]);
|
|
31448
|
+
floor2 = Math.min(floor2, points[k * 3 + 1]);
|
|
31449
|
+
}
|
|
31450
|
+
}
|
|
31451
|
+
}
|
|
31452
|
+
if (faces.length === 0) return null;
|
|
31453
|
+
const out = [];
|
|
31454
|
+
const seen = /* @__PURE__ */ new Set();
|
|
31455
|
+
const add2 = (x, z) => {
|
|
31456
|
+
const key = `${Math.round(x * 1e3)},${Math.round(z * 1e3)}`;
|
|
31457
|
+
if (seen.has(key)) return;
|
|
31458
|
+
seen.add(key);
|
|
31459
|
+
out.push([x, z]);
|
|
31460
|
+
};
|
|
31461
|
+
for (let i = 0; i < faces.length; i += 9) {
|
|
31462
|
+
if (faces[i + 1] > floor2 + FEET_BAND || faces[i + 4] > floor2 + FEET_BAND || faces[i + 7] > floor2 + FEET_BAND) continue;
|
|
31463
|
+
const ax = faces[i], az = faces[i + 2], bx = faces[i + 3], bz = faces[i + 5], cx = faces[i + 6], cz = faces[i + 8];
|
|
31464
|
+
add2(ax, az);
|
|
31465
|
+
add2(bx, bz);
|
|
31466
|
+
add2(cx, cz);
|
|
31467
|
+
add2((ax + bx) / 2, (az + bz) / 2);
|
|
31468
|
+
add2((bx + cx) / 2, (bz + cz) / 2);
|
|
31469
|
+
add2((ax + cx) / 2, (az + cz) / 2);
|
|
31470
|
+
add2((ax + bx + cx) / 3, (az + bz + cz) / 3);
|
|
31471
|
+
}
|
|
31472
|
+
return out.length > 0 ? { floor: floor2, points: out } : null;
|
|
31473
|
+
}
|
|
31474
|
+
/** 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`. */
|
|
31475
|
+
holdsAt(objectId, x, z, y) {
|
|
31476
|
+
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;
|
|
31477
|
+
}
|
|
31478
|
+
/** 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. */
|
|
31479
|
+
stoodBeside(x, z, d, floor2) {
|
|
31480
|
+
const fx = x - d.x, fz = z - d.z;
|
|
31481
|
+
const length = Math.hypot(fx, fz);
|
|
31482
|
+
const ux = length > 1e-6 ? fx / length : 1, uz = length > 1e-6 ? fz / length : 0;
|
|
31483
|
+
const reach2 = d.radius + UNDERMINED_RIM;
|
|
31484
|
+
const ground = this.groundAt(d.x + ux * reach2, d.z + uz * reach2);
|
|
31485
|
+
return ground >= floor2 - BROKEN_GAP - UNDERMINED_RIM_DROP && ground <= floor2 + UNDERMINED_RIM_RISE;
|
|
31486
|
+
}
|
|
30967
31487
|
/** 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
31488
|
standsOn(objectId, boxes) {
|
|
30969
31489
|
if (boxes.length === 0) return false;
|
|
@@ -30980,6 +31500,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30980
31500
|
return false;
|
|
30981
31501
|
}
|
|
30982
31502
|
/** 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. */
|
|
31503
|
+
/** 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. */
|
|
31504
|
+
heldByWorld(objectId) {
|
|
31505
|
+
return this.world.fixedInPlace(objectId);
|
|
31506
|
+
}
|
|
30983
31507
|
kindOf(b) {
|
|
30984
31508
|
for (let o = b.root; o; o = o.parent) {
|
|
30985
31509
|
const kind = kitOriginOf(o)?.kind;
|
|
@@ -31018,7 +31542,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31018
31542
|
* 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
31543
|
* on its parts.
|
|
31020
31544
|
*/
|
|
31021
|
-
setContacts(b, body, meshes) {
|
|
31545
|
+
setContacts(b, body, meshes, fitWhole = false) {
|
|
31022
31546
|
if (meshes.length > PART_BOX_MESHES) {
|
|
31023
31547
|
body.contacts = void 0;
|
|
31024
31548
|
body.partBoxes = void 0;
|
|
@@ -31035,7 +31559,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31035
31559
|
this.visuals.localBox(mv, lb);
|
|
31036
31560
|
if (lb.isEmpty()) continue;
|
|
31037
31561
|
m4.multiplyMatrices(inv, mv.mesh.matrixWorld);
|
|
31038
|
-
this.partBoxesOf(mv, { lb, m4, from: [cx, cy, cz] }, boxes);
|
|
31562
|
+
this.partBoxesOf(mv, { lb, m4, from: [cx, cy, cz], fitWhole }, boxes);
|
|
31039
31563
|
lb.applyMatrix4(m4);
|
|
31040
31564
|
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
31565
|
}
|
|
@@ -31156,28 +31680,67 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31156
31680
|
return own;
|
|
31157
31681
|
}
|
|
31158
31682
|
/**
|
|
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
|
|
31683
|
+
* 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`);
|
|
31684
|
+
* 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
31685
|
* of those vertices in the merged mesh's space is the box around a tilted sheet, mostly air.
|
|
31162
31686
|
*/
|
|
31163
31687
|
partBoxesOf(mv, at3, out) {
|
|
31164
31688
|
const [cx, cy, cz] = at3.from;
|
|
31165
|
-
|
|
31166
|
-
|
|
31167
|
-
|
|
31168
|
-
const
|
|
31169
|
-
|
|
31170
|
-
|
|
31171
|
-
|
|
31172
|
-
|
|
31173
|
-
|
|
31174
|
-
|
|
31175
|
-
|
|
31176
|
-
|
|
31177
|
-
|
|
31178
|
-
|
|
31179
|
-
|
|
31689
|
+
const built2 = mv.range ? null : builtSolidsOf(mv.mesh);
|
|
31690
|
+
const solids = at3.fitWhole && !mv.range && !built2 ? solidBoxesOf(mv.mesh.geometry) : null;
|
|
31691
|
+
if (solids) {
|
|
31692
|
+
const pos2 = new this.THREE.Vector3();
|
|
31693
|
+
const quat3 = new this.THREE.Quaternion();
|
|
31694
|
+
const scale2 = new this.THREE.Vector3();
|
|
31695
|
+
at3.m4.decompose(pos2, quat3, scale2);
|
|
31696
|
+
for (const box of solids) {
|
|
31697
|
+
const c2 = new this.THREE.Vector3((box[0] + box[3]) / 2, (box[1] + box[4]) / 2, (box[2] + box[5]) / 2).applyMatrix4(at3.m4);
|
|
31698
|
+
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)];
|
|
31699
|
+
out.push({ center: [c2.x - cx, c2.y - cy, c2.z - cz], half: half2, rotation: [quat3.x, quat3.y, quat3.z, quat3.w] });
|
|
31700
|
+
}
|
|
31701
|
+
return;
|
|
31702
|
+
}
|
|
31703
|
+
if (built2) {
|
|
31704
|
+
const pos2 = new this.THREE.Vector3();
|
|
31705
|
+
const quat3 = new this.THREE.Quaternion();
|
|
31706
|
+
const scale2 = new this.THREE.Vector3();
|
|
31707
|
+
at3.m4.decompose(pos2, quat3, scale2);
|
|
31708
|
+
const c2 = new this.THREE.Vector3();
|
|
31709
|
+
const q = new this.THREE.Quaternion();
|
|
31710
|
+
const even = (Math.abs(scale2.x) + Math.abs(scale2.y) + Math.abs(scale2.z)) / 3;
|
|
31711
|
+
for (const solid of built2) {
|
|
31712
|
+
c2.set(solid.center[0], solid.center[1], solid.center[2]).applyMatrix4(at3.m4);
|
|
31713
|
+
q.set(solid.rotation[0], solid.rotation[1], solid.rotation[2], solid.rotation[3]);
|
|
31714
|
+
const turned = Math.abs(q.w) < 1 - 1e-9;
|
|
31715
|
+
const s = turned ? [even, even, even] : [Math.abs(scale2.x), Math.abs(scale2.y), Math.abs(scale2.z)];
|
|
31716
|
+
q.premultiply(quat3).normalize();
|
|
31717
|
+
const round2 = isRoundSolid(solid) && Math.abs(s[0] - s[2]) <= 1e-9;
|
|
31718
|
+
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 } : {} });
|
|
31719
|
+
}
|
|
31720
|
+
return;
|
|
31721
|
+
}
|
|
31722
|
+
const own = [];
|
|
31723
|
+
this.visuals.rangePoints(mv, new this.THREE.Matrix4(), own);
|
|
31724
|
+
const drawn = hollowBoxesOf(own, mv.range ? RANGED : OWN_MESH);
|
|
31725
|
+
if (drawn) {
|
|
31726
|
+
const pos2 = new this.THREE.Vector3();
|
|
31727
|
+
const quat3 = new this.THREE.Quaternion();
|
|
31728
|
+
const scale2 = new this.THREE.Vector3();
|
|
31729
|
+
at3.m4.decompose(pos2, quat3, scale2);
|
|
31730
|
+
const c2 = new this.THREE.Vector3();
|
|
31731
|
+
const q = new this.THREE.Quaternion();
|
|
31732
|
+
const even = (Math.abs(scale2.x) + Math.abs(scale2.y) + Math.abs(scale2.z)) / 3;
|
|
31733
|
+
for (const box of drawn) {
|
|
31734
|
+
c2.set(box.center[0], box.center[1], box.center[2]).applyMatrix4(at3.m4);
|
|
31735
|
+
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)];
|
|
31736
|
+
if (box.rotation) q.set(box.rotation[0], box.rotation[1], box.rotation[2], box.rotation[3]).premultiply(quat3).normalize();
|
|
31737
|
+
else q.copy(quat3);
|
|
31738
|
+
const thin = mv.range ? 0 : 5e-3;
|
|
31739
|
+
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] });
|
|
31180
31740
|
}
|
|
31741
|
+
return;
|
|
31742
|
+
}
|
|
31743
|
+
if (mv.range) {
|
|
31181
31744
|
if (isRigidPose(at3.m4.elements)) {
|
|
31182
31745
|
const turn2 = new this.THREE.Quaternion().setFromRotationMatrix(at3.m4);
|
|
31183
31746
|
const c2 = new this.THREE.Vector3();
|
|
@@ -31200,11 +31763,14 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31200
31763
|
at3.m4.decompose(pos, quat2, scale);
|
|
31201
31764
|
const c = at3.lb.getCenter(new this.THREE.Vector3()).applyMatrix4(at3.m4);
|
|
31202
31765
|
const size = at3.lb.getSize(new this.THREE.Vector3());
|
|
31203
|
-
|
|
31204
|
-
|
|
31205
|
-
|
|
31206
|
-
|
|
31207
|
-
|
|
31766
|
+
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)];
|
|
31767
|
+
const geometry = mv.mesh.geometry;
|
|
31768
|
+
const params = geometry.parameters ?? {};
|
|
31769
|
+
const whole = typeof params.thetaLength !== "number" || Math.abs(params.thetaLength - 2 * Math.PI) < 1e-6;
|
|
31770
|
+
const cylinder = geometry.type === "CylinderGeometry" && !mv.range;
|
|
31771
|
+
const straight = cylinder && whole && params.openEnded !== true && isRoundSolid({ kind: params.radiusTop === params.radiusBottom ? "cylinder" : "cone", half });
|
|
31772
|
+
const curved = !mv.range && !straight && (cylinder || geometry.type === "ConeGeometry" || geometry.type === "SphereGeometry");
|
|
31773
|
+
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
31774
|
}
|
|
31209
31775
|
/**
|
|
31210
31776
|
* 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 +32347,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31781
32347
|
wakeRegion(x, z, radius) {
|
|
31782
32348
|
this.fragments.wakeRegion(x, z, radius);
|
|
31783
32349
|
this.pieceSys.wakeRegion(x, z, radius);
|
|
32350
|
+
if (this.autoSplit && this.undermined.length < UNDERMINED_MAX) this.undermined.push({ x, z, radius });
|
|
31784
32351
|
}
|
|
31785
32352
|
stats() {
|
|
31786
32353
|
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 +32406,55 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31839
32406
|
};
|
|
31840
32407
|
return ch(16) | ch(8) | ch(0);
|
|
31841
32408
|
}
|
|
32409
|
+
function solidBoxesOf(geometry) {
|
|
32410
|
+
const position = geometry.getAttribute("position");
|
|
32411
|
+
if (!position || position.count <= 24) return null;
|
|
32412
|
+
const parent = new Int32Array(position.count);
|
|
32413
|
+
for (let i = 0; i < parent.length; i++) parent[i] = i;
|
|
32414
|
+
const find = (i) => {
|
|
32415
|
+
while (parent[i] !== i) {
|
|
32416
|
+
parent[i] = parent[parent[i]];
|
|
32417
|
+
i = parent[i];
|
|
32418
|
+
}
|
|
32419
|
+
return i;
|
|
32420
|
+
};
|
|
32421
|
+
const join = (a, b) => {
|
|
32422
|
+
const ra = find(a), rb = find(b);
|
|
32423
|
+
if (ra !== rb) parent[ra] = rb;
|
|
32424
|
+
};
|
|
32425
|
+
const corners = /* @__PURE__ */ new Map();
|
|
32426
|
+
for (let i = 0; i < position.count; i++) {
|
|
32427
|
+
const key = `${Math.round(position.getX(i) / SOLID_WELD)},${Math.round(position.getY(i) / SOLID_WELD)},${Math.round(position.getZ(i) / SOLID_WELD)}`;
|
|
32428
|
+
const first = corners.get(key);
|
|
32429
|
+
if (first === void 0) corners.set(key, i);
|
|
32430
|
+
else join(i, first);
|
|
32431
|
+
}
|
|
32432
|
+
const index = geometry.getIndex();
|
|
32433
|
+
const triangles2 = index ? index.count / 3 : position.count / 3;
|
|
32434
|
+
for (let t = 0; t < triangles2; t++) {
|
|
32435
|
+
const a = index ? index.getX(t * 3) : t * 3;
|
|
32436
|
+
join(a, index ? index.getX(t * 3 + 1) : t * 3 + 1);
|
|
32437
|
+
join(a, index ? index.getX(t * 3 + 2) : t * 3 + 2);
|
|
32438
|
+
}
|
|
32439
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
32440
|
+
for (let i = 0; i < position.count; i++) {
|
|
32441
|
+
const root = find(i);
|
|
32442
|
+
const x = position.getX(i), y = position.getY(i), z = position.getZ(i);
|
|
32443
|
+
const box = boxes.get(root);
|
|
32444
|
+
if (!box) {
|
|
32445
|
+
if (boxes.size >= SOLIDS_MAX) return null;
|
|
32446
|
+
boxes.set(root, [x, y, z, x, y, z]);
|
|
32447
|
+
continue;
|
|
32448
|
+
}
|
|
32449
|
+
box[0] = Math.min(box[0], x);
|
|
32450
|
+
box[1] = Math.min(box[1], y);
|
|
32451
|
+
box[2] = Math.min(box[2], z);
|
|
32452
|
+
box[3] = Math.max(box[3], x);
|
|
32453
|
+
box[4] = Math.max(box[4], y);
|
|
32454
|
+
box[5] = Math.max(box[5], z);
|
|
32455
|
+
}
|
|
32456
|
+
return boxes.size > 1 ? [...boxes.values()] : null;
|
|
32457
|
+
}
|
|
31842
32458
|
function convexHull2(points) {
|
|
31843
32459
|
const sorted = [...points].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
31844
32460
|
if (sorted.length < 3) return sorted;
|
|
@@ -32070,9 +32686,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
32070
32686
|
if (!bases.has(base)) bases.set(base, { id: base, category: tiers[0]?.category ?? "", layers: { close: tiers[0]?.layers.close ?? [] } });
|
|
32071
32687
|
}
|
|
32072
32688
|
for (const sound of bases.values()) {
|
|
32073
|
-
const
|
|
32689
|
+
const numbers2 = options.sounds?.[sound.id] ?? options.defaults?.(sound);
|
|
32074
32690
|
const close = refsOf(sound.layers.close, baseUrl);
|
|
32075
|
-
if (!
|
|
32691
|
+
if (!numbers2 || close.length === 0) continue;
|
|
32076
32692
|
const tiers = (tiersOf.get(sound.id) ?? []).map((tier) => {
|
|
32077
32693
|
const name = splitTier(tier.id).tier;
|
|
32078
32694
|
const tierFar = refsOf(tier.layers.far, baseUrl);
|
|
@@ -32084,20 +32700,20 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
32084
32700
|
const files = [sound, ...tiersOf.get(sound.id) ?? []].flatMap((entry) => Object.values(entry.layers).flatMap((entries2) => entries2 ?? []));
|
|
32085
32701
|
samples.push({
|
|
32086
32702
|
id: sound.id,
|
|
32087
|
-
bus:
|
|
32703
|
+
bus: numbers2.bus,
|
|
32088
32704
|
close,
|
|
32089
32705
|
...far2.length > 0 ? { far: far2 } : {},
|
|
32090
32706
|
...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
|
-
...
|
|
32707
|
+
...numbers2.crossover ? { crossover: numbers2.crossover } : {},
|
|
32708
|
+
...indoor.length > 0 || outdoor.length > 0 ? { tail: { ...indoor.length > 0 ? { indoor } : {}, ...outdoor.length > 0 ? { outdoor } : {}, ...numbers2.tailGain === void 0 ? {} : { gain: numbers2.tailGain } } } : {},
|
|
32709
|
+
...numbers2.pitch === void 0 ? {} : { pitch: numbers2.pitch },
|
|
32710
|
+
...numbers2.gain === void 0 ? {} : { gain: numbers2.gain },
|
|
32711
|
+
...numbers2.falloff ? { falloff: numbers2.falloff } : {},
|
|
32712
|
+
...numbers2.cutoffK === void 0 ? {} : { cutoffK: numbers2.cutoffK },
|
|
32713
|
+
...numbers2.group ? { group: numbers2.group } : {},
|
|
32714
|
+
...numbers2.priority === void 0 ? {} : { priority: numbers2.priority },
|
|
32715
|
+
...numbers2.choke ? { choke: numbers2.choke } : {},
|
|
32716
|
+
...numbers2.fallback ? { fallback: numbers2.fallback } : {},
|
|
32101
32717
|
sources: files.map((file) => `${file.file}: ${file.source} ${file.author} ${file.license}`)
|
|
32102
32718
|
});
|
|
32103
32719
|
}
|