@adatechnology/game-destruction-three 0.26.5 → 0.27.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 +4 -0
- package/dist/ground-worker.global.js.map +1 -1
- package/dist/ground-worker.js.map +1 -1
- package/dist/index.d.ts +37 -24
- package/dist/index.global.js +508 -51
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +341 -19
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.global.js
CHANGED
|
@@ -401,7 +401,8 @@ var GameDestructionThree = (() => {
|
|
|
401
401
|
PIECE_BOXES: "destruction.piece-boxes",
|
|
402
402
|
STATIC_COLLIDERS: "destruction.static-colliders",
|
|
403
403
|
SHAPES_GENERATE: "shapes.generate",
|
|
404
|
-
WORLD_REGION: "world.region"
|
|
404
|
+
WORLD_REGION: "world.region",
|
|
405
|
+
VEHICLE_HULL_PLAN: "vehicles.hull-plan"
|
|
405
406
|
};
|
|
406
407
|
var WORKER_KIND_DEFAULTS = {
|
|
407
408
|
[WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
|
|
@@ -409,7 +410,8 @@ var GameDestructionThree = (() => {
|
|
|
409
410
|
[WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
|
|
410
411
|
[WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
|
|
411
412
|
[WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
|
|
412
|
-
[WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" }
|
|
413
|
+
[WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" },
|
|
414
|
+
[WORKER_KIND_ID.VEHICLE_HULL_PLAN]: { lane: "build", priority: 120, late: "keep-waiting" }
|
|
413
415
|
};
|
|
414
416
|
var WORKER_INPUT_LOST = "WorkerTaskInputLost";
|
|
415
417
|
var isWorkerInputLost = (error) => error instanceof Error && error.name === WORKER_INPUT_LOST;
|
|
@@ -8559,7 +8561,7 @@ var GameDestructionThree = (() => {
|
|
|
8559
8561
|
return sources;
|
|
8560
8562
|
}
|
|
8561
8563
|
|
|
8562
|
-
// ../game-vfx-three/dist/chunk-
|
|
8564
|
+
// ../game-vfx-three/dist/chunk-EE6XER4D.js
|
|
8563
8565
|
var GLOW_VERTEX = `attribute vec4 aP;attribute vec4 aC;varying vec2 vU;varying vec4 vC;
|
|
8564
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]);
|
|
8565
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.);}`;
|
|
@@ -8575,21 +8577,22 @@ float vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);
|
|
|
8575
8577
|
`;
|
|
8576
8578
|
var PUFF_VERTEX = `${GL_NOISE}
|
|
8577
8579
|
attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
|
|
8578
|
-
varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
|
|
8580
|
+
varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
|
|
8579
8581
|
void main(){
|
|
8580
8582
|
vec3 p=position;
|
|
8583
|
+
vec3 q=normalize(position);
|
|
8581
8584
|
float s=aD.z;
|
|
8582
8585
|
float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
|
|
8583
8586
|
p*=0.78+0.5*n;
|
|
8584
|
-
float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;
|
|
8585
|
-
vL=p;
|
|
8587
|
+
float a=s*6.2831;float c=cos(a),si=sin(a);p.xz=mat2(c,-si,si,c)*p.xz;q.xz=mat2(c,-si,si,c)*q.xz;
|
|
8588
|
+
vL=p;vN=q;
|
|
8586
8589
|
vec3 wp=aP.xyz+p*aP.w;
|
|
8587
8590
|
vWP=wp;vD=aD;vC=aC;
|
|
8588
8591
|
gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
|
|
8589
8592
|
}`;
|
|
8590
8593
|
var PUFF_FRAGMENT = `${GL_NOISE}
|
|
8591
8594
|
uniform vec3 uLight;uniform vec3 uSky;uniform vec3 uGround;uniform vec3 uGlowPos;uniform vec3 uGlowCol;uniform float uGlowI;
|
|
8592
|
-
varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
|
|
8595
|
+
varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
|
|
8593
8596
|
vec3 L(vec3 c){return pow(c,vec3(2.2));}
|
|
8594
8597
|
vec3 ramp(float h){
|
|
8595
8598
|
vec3 c0=L(vec3(.36,.07,.03)),c1=L(vec3(.76,.21,.1)),c2=L(vec3(1.,.54,.16)),c3=L(vec3(1.,.83,.42)),c4=L(vec3(1.,.96,.84));
|
|
@@ -8599,30 +8602,35 @@ vec3 ramp(float h){
|
|
|
8599
8602
|
return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
|
|
8600
8603
|
}
|
|
8601
8604
|
void main(){
|
|
8602
|
-
vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));
|
|
8603
8605
|
float age=vD.x,heat=vD.y,kind=vD.w;
|
|
8604
8606
|
float n=vn(vL*2.4+vD.z*13.0);
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
+
// the sphere's own normal, roughened by the noise: a billowing cloud, never facets
|
|
8608
|
+
vec3 g=vec3(vn(vL*3.1+vD.z*5.0),vn(vL*3.1+vD.z*5.0+7.3),vn(vL*3.1+vD.z*5.0+13.7))-.5;
|
|
8609
|
+
vec3 N=normalize(normalize(vN)+g*.9);
|
|
8610
|
+
vec3 V=normalize(cameraPosition-vWP);
|
|
8607
8611
|
float lam=max(dot(N,uLight),0.);
|
|
8608
|
-
float
|
|
8609
|
-
// soot: a dark smoke still scatters some light, so it never goes flat black, and its rim takes the sky so its volume reads (only the dark puffs; the rest as the Lab)
|
|
8612
|
+
float light=.42+.62*smoothstep(-.1,.9,lam);
|
|
8610
8613
|
float dark=1.-smoothstep(.02,.12,dot(vC,vec3(.2126,.7152,.0722)));
|
|
8611
8614
|
vec3 alb=max(vC,vec3(.055)*dark);
|
|
8612
|
-
vec3 col=alb*(vec3(.5,.56,.7)*
|
|
8613
|
-
float rim=pow(1.-clamp(abs(dot(
|
|
8615
|
+
vec3 col=alb*(vec3(.5,.56,.7)*light*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));
|
|
8616
|
+
float rim=pow(1.-clamp(abs(dot(normalize(vN),V)),0.,1.),2.);
|
|
8614
8617
|
col+=dark*rim*(uSky*.9+alb);
|
|
8615
8618
|
vec3 tg=uGlowPos-vWP;float dg=length(tg)+.001;
|
|
8616
8619
|
float gi=uGlowI/(1.+dg*dg*.05)*(.3+.7*max(dot(N,tg/dg),0.));
|
|
8617
8620
|
col+=uGlowCol*gi*alb*1.6;
|
|
8621
|
+
// seen through: thin where the camera grazes the puff, thicker where the noise is, thinning out with age
|
|
8622
|
+
float facing=abs(dot(normalize(vN),V));
|
|
8623
|
+
float alpha=smoothstep(.0,.75,facing)*(.35+.65*smoothstep(.2,.8,n))*(1.-smoothstep(.3,1.,age))*.78;
|
|
8618
8624
|
float h=heat*(.72+.56*n)+heat*(-N.y)*.18;
|
|
8619
8625
|
if(h>.05){
|
|
8620
|
-
|
|
8621
|
-
|
|
8622
|
-
col=mix(col,fc,
|
|
8626
|
+
vec3 fc=ramp(clamp(h,0.,1.2))*(1.1+3.1*h);
|
|
8627
|
+
float hot=smoothstep(.04,.2,h);
|
|
8628
|
+
col=mix(col,fc,hot);
|
|
8629
|
+
alpha=max(alpha,hot*smoothstep(.0,.45,facing)*(1.-smoothstep(.5,1.,age)));
|
|
8623
8630
|
}
|
|
8624
8631
|
if(kind>2.5&&kind<3.5){col+=vec3(.02,.025,.03);}
|
|
8625
|
-
|
|
8632
|
+
if(alpha<.01)discard;
|
|
8633
|
+
gl_FragColor=vec4(col,alpha);
|
|
8626
8634
|
#include <tonemapping_fragment>
|
|
8627
8635
|
#include <colorspace_fragment>
|
|
8628
8636
|
}`;
|
|
@@ -8657,10 +8665,11 @@ void main(){
|
|
|
8657
8665
|
function dynamic(THREE, array, size) {
|
|
8658
8666
|
return new THREE.InstancedBufferAttribute(array, size).setUsage(THREE.DynamicDrawUsage);
|
|
8659
8667
|
}
|
|
8668
|
+
var PUFF_DETAIL = 2;
|
|
8660
8669
|
function createPuffLayer(THREE, pool, uniforms) {
|
|
8661
8670
|
const capacity = pool.capacity;
|
|
8662
8671
|
const geometry = new THREE.InstancedBufferGeometry();
|
|
8663
|
-
geometry.setAttribute("position", new THREE.IcosahedronGeometry(1,
|
|
8672
|
+
geometry.setAttribute("position", new THREE.IcosahedronGeometry(1, PUFF_DETAIL).getAttribute("position"));
|
|
8664
8673
|
const a = new Float32Array(capacity * 4);
|
|
8665
8674
|
const d = new Float32Array(capacity * 4);
|
|
8666
8675
|
const c = new Float32Array(capacity * 3);
|
|
@@ -8669,7 +8678,7 @@ void main(){
|
|
|
8669
8678
|
geometry.setAttribute("aD", attributes[1]);
|
|
8670
8679
|
geometry.setAttribute("aC", attributes[2]);
|
|
8671
8680
|
geometry.instanceCount = 0;
|
|
8672
|
-
const material = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT });
|
|
8681
|
+
const material = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT, transparent: true, depthWrite: false });
|
|
8673
8682
|
const mesh2 = new THREE.Mesh(geometry, material);
|
|
8674
8683
|
mesh2.name = "vfx-puffs";
|
|
8675
8684
|
mesh2.frustumCulled = false;
|
|
@@ -10242,6 +10251,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
10242
10251
|
const ordered2 = [...big, ...small];
|
|
10243
10252
|
return { physics: ordered2.slice(0, Math.max(0, count)), chips: ordered2.slice(Math.max(0, count)) };
|
|
10244
10253
|
};
|
|
10254
|
+
var POSE = new Float64Array(7);
|
|
10255
|
+
var VELOCITY = new Float64Array(6);
|
|
10256
|
+
var POSE2 = new Float64Array(7);
|
|
10245
10257
|
var BEFORE_ORDER = ["crowd", "actors"];
|
|
10246
10258
|
var AFTER_ORDER = ["contacts", "rules"];
|
|
10247
10259
|
var STEP_EPSILON = 1e-9;
|
|
@@ -10254,7 +10266,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
10254
10266
|
const phases = { crowd: [], actors: [], contacts: [], rules: [] };
|
|
10255
10267
|
let accumulator = 0;
|
|
10256
10268
|
const h = world.fixedStep;
|
|
10257
|
-
const
|
|
10269
|
+
const add3 = (phase, order2) => {
|
|
10258
10270
|
phases[order2] = [...phases[order2], phase];
|
|
10259
10271
|
return () => {
|
|
10260
10272
|
phases[order2] = phases[order2].filter((registered) => registered !== phase);
|
|
@@ -10284,7 +10296,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
10284
10296
|
frame2.alpha = 0;
|
|
10285
10297
|
run(steps, steps * h);
|
|
10286
10298
|
};
|
|
10287
|
-
return { world, frame: frame2, add:
|
|
10299
|
+
return { world, frame: frame2, add: add3, step, stepFixed };
|
|
10288
10300
|
};
|
|
10289
10301
|
var isPhysicsLoop = (value) => "frame" in value && "add" in value;
|
|
10290
10302
|
var DEFAULT_WORK_BUDGET_MS = 4;
|
|
@@ -10420,6 +10432,73 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
10420
10432
|
this.entries = state.map((entry) => ({ ...entry }));
|
|
10421
10433
|
}
|
|
10422
10434
|
};
|
|
10435
|
+
var GOLDEN_ANGLE = Math.PI * (1 + Math.sqrt(5));
|
|
10436
|
+
var DEFAULT_BODIES_MAX2 = 64;
|
|
10437
|
+
var createImpactReader = (loop, options) => {
|
|
10438
|
+
const world = loop.world;
|
|
10439
|
+
const capacity = options.bodiesMax ?? DEFAULT_BODIES_MAX2;
|
|
10440
|
+
let size = 4;
|
|
10441
|
+
while (size < capacity * 2) size *= 2;
|
|
10442
|
+
const mask = size - 1;
|
|
10443
|
+
const tableKey = new Int32Array(size);
|
|
10444
|
+
const tableStamp = new Uint32Array(size);
|
|
10445
|
+
const tableSlot = new Int32Array(size);
|
|
10446
|
+
let stamp = 0;
|
|
10447
|
+
let told = 0;
|
|
10448
|
+
const bodies = new Int32Array(capacity);
|
|
10449
|
+
const others = new Int32Array(capacity);
|
|
10450
|
+
const impulses = new Float32Array(capacity);
|
|
10451
|
+
const approaches = new Float32Array(capacity);
|
|
10452
|
+
const points = new Float32Array(capacity * 3);
|
|
10453
|
+
const normals = new Float32Array(capacity * 3);
|
|
10454
|
+
const impact3 = { body: 0, other: 0, impulse: 0, approach: 0, point: [0, 0, 0], normal: [0, 0, 0] };
|
|
10455
|
+
const keep = (c, body, other, row, sign) => {
|
|
10456
|
+
let at3 = Math.imul(body, 2654435761) & mask;
|
|
10457
|
+
while (tableStamp[at3] === stamp && tableKey[at3] !== body) at3 = at3 + 1 & mask;
|
|
10458
|
+
let slot;
|
|
10459
|
+
if (tableStamp[at3] === stamp) slot = tableSlot[at3];
|
|
10460
|
+
else {
|
|
10461
|
+
if (told >= capacity || options.accepts && !options.accepts(body)) return;
|
|
10462
|
+
slot = told++;
|
|
10463
|
+
tableStamp[at3] = stamp;
|
|
10464
|
+
tableKey[at3] = body;
|
|
10465
|
+
tableSlot[at3] = slot;
|
|
10466
|
+
impulses[slot] = 0;
|
|
10467
|
+
bodies[slot] = body;
|
|
10468
|
+
}
|
|
10469
|
+
if (c.impulse[row] <= impulses[slot]) return;
|
|
10470
|
+
others[slot] = other;
|
|
10471
|
+
impulses[slot] = c.impulse[row];
|
|
10472
|
+
approaches[slot] = c.approach[row];
|
|
10473
|
+
for (let k = 0; k < 3; k++) {
|
|
10474
|
+
points[slot * 3 + k] = c.point[row * 3 + k];
|
|
10475
|
+
normals[slot * 3 + k] = c.normal[row * 3 + k] * sign;
|
|
10476
|
+
}
|
|
10477
|
+
};
|
|
10478
|
+
const afterSteps = () => {
|
|
10479
|
+
const c = world.contacts;
|
|
10480
|
+
stamp++;
|
|
10481
|
+
told = 0;
|
|
10482
|
+
for (let row = 0; row < c.count; row++) {
|
|
10483
|
+
if (c.impulse[row] < options.minImpulse) continue;
|
|
10484
|
+
keep(c, c.a[row], c.b[row], row, 1);
|
|
10485
|
+
keep(c, c.b[row], c.a[row], row, -1);
|
|
10486
|
+
}
|
|
10487
|
+
const count = told;
|
|
10488
|
+
for (let slot = 0; slot < count; slot++) {
|
|
10489
|
+
impact3.body = bodies[slot];
|
|
10490
|
+
impact3.other = others[slot];
|
|
10491
|
+
impact3.impulse = impulses[slot];
|
|
10492
|
+
impact3.approach = approaches[slot];
|
|
10493
|
+
for (let k = 0; k < 3; k++) {
|
|
10494
|
+
impact3.point[k] = points[slot * 3 + k];
|
|
10495
|
+
impact3.normal[k] = normals[slot * 3 + k];
|
|
10496
|
+
}
|
|
10497
|
+
if (impact3.impulse > 0) options.onImpact(impact3);
|
|
10498
|
+
}
|
|
10499
|
+
};
|
|
10500
|
+
return loop.add({ afterSteps }, "contacts");
|
|
10501
|
+
};
|
|
10423
10502
|
|
|
10424
10503
|
// src/blast-debris.ts
|
|
10425
10504
|
var BLAST_DEBRIS_DEFAULTS = {
|
|
@@ -11947,6 +12026,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11947
12026
|
const [x, y, z, w] = r;
|
|
11948
12027
|
return [1 - 2 * (y * y + z * z), 2 * (x * y - z * w), 2 * (x * z + y * w), 2 * (x * y + z * w), 1 - 2 * (x * x + z * z), 2 * (y * z - x * w), 2 * (x * z - y * w), 2 * (y * z + x * w), 1 - 2 * (x * x + y * y)];
|
|
11949
12028
|
};
|
|
12029
|
+
var HINGE_RELEASE = 40 * Math.PI / 180;
|
|
12030
|
+
var HINGE_SECONDS = 1.5;
|
|
11950
12031
|
var isTurned = (box) => box.rotation !== void 0 && rows(box.rotation).some((v) => Math.abs(v) > 1e-6 && Math.abs(Math.abs(v) - 1) > 1e-6);
|
|
11951
12032
|
var squareBoxOf = (box) => {
|
|
11952
12033
|
const r = box.rotation;
|
|
@@ -13411,6 +13492,11 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13411
13492
|
var sameShape = (a, b) => near(a.center, b.center) && near(a.half, b.half) && near(a.rotation, b.rotation) && sameMesh(a.mesh, b.mesh);
|
|
13412
13493
|
var sameBox = (a, b) => a === b || sameShape(a, b) && sameFriction(a.friction, b.friction);
|
|
13413
13494
|
var sameSolids = (a, b) => a.length === b.length && a.every((s, i) => sameBox(s, b[i]));
|
|
13495
|
+
var NONE = /* @__PURE__ */ new Set();
|
|
13496
|
+
var partOfKey = (key) => {
|
|
13497
|
+
const colon = key.lastIndexOf(":");
|
|
13498
|
+
return colon < 0 || !/^\d+$/.test(key.slice(colon + 1)) ? key : key.slice(0, colon);
|
|
13499
|
+
};
|
|
13414
13500
|
var hasSize = (s) => s.half[0] > 0 && s.half[1] > 0 && s.half[2] > 0;
|
|
13415
13501
|
var shapeOf = (s) => s.mesh ? { kind: "trimesh", vertices: s.mesh.vertices, indices: s.mesh.indices } : { kind: "box", half: s.half };
|
|
13416
13502
|
var EngineStatics = class {
|
|
@@ -13422,32 +13508,55 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13422
13508
|
__publicField(this, "changed", /* @__PURE__ */ new Set());
|
|
13423
13509
|
/** Every body it holds now: what a piece made or put is checked against (`EnginePieces.outOfStatics`; the ground has its own rule). */
|
|
13424
13510
|
__publicField(this, "ids", /* @__PURE__ */ new Set());
|
|
13511
|
+
/** The object each held body is a part of (what a ray that meets the body says about the object). */
|
|
13512
|
+
__publicField(this, "ownerOf", /* @__PURE__ */ new Map());
|
|
13513
|
+
/** The part of the object each held body draws (the key without its mesh number): what a blow on the body hits. */
|
|
13514
|
+
__publicField(this, "partOf", /* @__PURE__ */ new Map());
|
|
13515
|
+
/** Changes whenever an answer of `covers` may have (an object came, went, or was fitted again). */
|
|
13516
|
+
__publicField(this, "coverageRevision", 0);
|
|
13517
|
+
__publicField(this, "unsure", NONE);
|
|
13425
13518
|
}
|
|
13426
13519
|
/** Whether the engine has a body for the object's drawn parts (what the kit's sweep need not set a piece back from). */
|
|
13427
13520
|
has(objectId) {
|
|
13428
13521
|
const f = this.bodies.get(objectId);
|
|
13429
13522
|
return f !== void 0 && f.held.size > 0;
|
|
13430
13523
|
}
|
|
13431
|
-
|
|
13524
|
+
/**
|
|
13525
|
+
* Whether every part a ray can hit has its body: only then is a ray's miss of its bodies a miss of the object. An object whose list is only partly measured, or leaves out a part the
|
|
13526
|
+
* world still tests (a loose or hidden one), is not covered: `lay`'s `unsure`.
|
|
13527
|
+
*/
|
|
13528
|
+
covers(objectId) {
|
|
13529
|
+
const f = this.bodies.get(objectId);
|
|
13530
|
+
return f !== void 0 && f.held.size > 0 && f.waiting === 0 && !this.unsure.has(objectId);
|
|
13531
|
+
}
|
|
13532
|
+
/** `now` is the host's list per object; `unsure` names the objects whose list is not all of what a ray can hit (see `covers`). */
|
|
13533
|
+
lay(now, unsure = NONE) {
|
|
13432
13534
|
this.changed.clear();
|
|
13535
|
+
if (unsure.size !== this.unsure.size || [...unsure].some((id) => !this.unsure.has(id))) {
|
|
13536
|
+
this.unsure = new Set(unsure);
|
|
13537
|
+
this.coverageRevision++;
|
|
13538
|
+
}
|
|
13433
13539
|
for (const [id, f] of this.bodies) {
|
|
13434
13540
|
if (now.has(id)) continue;
|
|
13435
13541
|
for (const h of f.held.values()) this.release(h, f.settled);
|
|
13436
13542
|
this.bodies.delete(id);
|
|
13543
|
+
this.coverageRevision++;
|
|
13437
13544
|
}
|
|
13438
13545
|
const budget = { triangles: TRIANGLES_PER_UPDATE };
|
|
13439
13546
|
for (const [id, solids] of now) {
|
|
13440
13547
|
const f = this.bodies.get(id);
|
|
13441
13548
|
if (f?.solids === solids && f.waiting === 0) continue;
|
|
13442
|
-
const fixed = f ?? { solids, held: /* @__PURE__ */ new Map(), waiting: 0, settled: false };
|
|
13549
|
+
const fixed = f ?? { objectId: id, solids, held: /* @__PURE__ */ new Map(), waiting: 0, settled: false };
|
|
13443
13550
|
this.bodies.set(id, fixed);
|
|
13444
13551
|
fixed.solids = solids;
|
|
13552
|
+
this.coverageRevision++;
|
|
13445
13553
|
this.fit(fixed, budget);
|
|
13446
13554
|
}
|
|
13447
13555
|
}
|
|
13448
13556
|
clear() {
|
|
13449
13557
|
for (const f of this.bodies.values()) for (const h of f.held.values()) this.drop(h.id);
|
|
13450
13558
|
this.bodies.clear();
|
|
13559
|
+
this.coverageRevision++;
|
|
13451
13560
|
this.changed.clear();
|
|
13452
13561
|
}
|
|
13453
13562
|
/** The object's parts of a list by name, the ones with a size only. */
|
|
@@ -13495,6 +13604,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13495
13604
|
const id = ids[i];
|
|
13496
13605
|
f.held.set(x.key, { solid: x.solid, id });
|
|
13497
13606
|
this.ids.add(id);
|
|
13607
|
+
this.ownerOf.set(id, f.objectId);
|
|
13608
|
+
this.partOf.set(id, partOfKey(x.key));
|
|
13498
13609
|
this.changed.add(id);
|
|
13499
13610
|
if (f.settled) this.wakeAround(x.solid);
|
|
13500
13611
|
});
|
|
@@ -13525,6 +13636,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13525
13636
|
}
|
|
13526
13637
|
drop(id) {
|
|
13527
13638
|
this.ids.delete(id);
|
|
13639
|
+
this.ownerOf.delete(id);
|
|
13640
|
+
this.partOf.delete(id);
|
|
13528
13641
|
this.world.removeBody(id);
|
|
13529
13642
|
}
|
|
13530
13643
|
wakeAround(s) {
|
|
@@ -13853,6 +13966,35 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
13853
13966
|
return null;
|
|
13854
13967
|
}
|
|
13855
13968
|
|
|
13969
|
+
// src/engine-impacts.ts
|
|
13970
|
+
var DEFAULT_MIN_IMPULSE = 30;
|
|
13971
|
+
var DEFAULT_HITS_MAX = 32;
|
|
13972
|
+
var DEFAULT_CONTACT_RADIUS = 0.1;
|
|
13973
|
+
var createEngineImpacts = (loop, statics, destruction, options = {}) => {
|
|
13974
|
+
const hitsMax = options.hitsMax ?? DEFAULT_HITS_MAX;
|
|
13975
|
+
const radius = options.contactRadius ?? DEFAULT_CONTACT_RADIUS;
|
|
13976
|
+
return createImpactReader(loop, {
|
|
13977
|
+
minImpulse: options.minImpulse ?? DEFAULT_MIN_IMPULSE,
|
|
13978
|
+
bodiesMax: hitsMax,
|
|
13979
|
+
accepts: (body) => statics.ownerOf.has(body),
|
|
13980
|
+
onImpact: (impact3) => {
|
|
13981
|
+
const object = statics.ownerOf.get(impact3.body);
|
|
13982
|
+
const part = statics.partOf.get(impact3.body);
|
|
13983
|
+
if (object === void 0 || part === void 0 || destruction.part(object, part) === null) return;
|
|
13984
|
+
const hit = {
|
|
13985
|
+
type: "blunt",
|
|
13986
|
+
point: [impact3.point[0], impact3.point[1], impact3.point[2]],
|
|
13987
|
+
direction: [-impact3.normal[0], -impact3.normal[1], -impact3.normal[2]],
|
|
13988
|
+
energy: 0.5 * impact3.impulse * impact3.approach,
|
|
13989
|
+
radius,
|
|
13990
|
+
part,
|
|
13991
|
+
source: "engine"
|
|
13992
|
+
};
|
|
13993
|
+
destruction.hitPart(object, part, hit);
|
|
13994
|
+
}
|
|
13995
|
+
});
|
|
13996
|
+
};
|
|
13997
|
+
|
|
13856
13998
|
// src/engine-ground-heights.ts
|
|
13857
13999
|
var changedHeights = (before, after2, size) => {
|
|
13858
14000
|
let minX = size;
|
|
@@ -14019,6 +14161,96 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14019
14161
|
}
|
|
14020
14162
|
};
|
|
14021
14163
|
|
|
14164
|
+
// src/engine-rays.ts
|
|
14165
|
+
var RAY_MARGIN = 0.25;
|
|
14166
|
+
var LONGEST_RAY = 2e3;
|
|
14167
|
+
var FIXED_ONLY = { layers: ["static"] };
|
|
14168
|
+
var createEngineRayBroadPhase = (world, statics) => {
|
|
14169
|
+
const hits = [];
|
|
14170
|
+
const inside = [];
|
|
14171
|
+
const met = /* @__PURE__ */ new Set();
|
|
14172
|
+
const metList = [];
|
|
14173
|
+
const from = [0, 0, 0];
|
|
14174
|
+
const toward2 = [0, 0, 0];
|
|
14175
|
+
return {
|
|
14176
|
+
begin(origin, direction, maxDistance) {
|
|
14177
|
+
if (!(maxDistance <= LONGEST_RAY)) return false;
|
|
14178
|
+
met.clear();
|
|
14179
|
+
metList.length = 0;
|
|
14180
|
+
from[0] = origin[0];
|
|
14181
|
+
from[1] = origin[1];
|
|
14182
|
+
from[2] = origin[2];
|
|
14183
|
+
toward2[0] = direction[0];
|
|
14184
|
+
toward2[1] = direction[1];
|
|
14185
|
+
toward2[2] = direction[2];
|
|
14186
|
+
const count = world.sphereCastAll(from, toward2, maxDistance, RAY_MARGIN, hits, FIXED_ONLY);
|
|
14187
|
+
for (let i = 0; i < count; i++) {
|
|
14188
|
+
const owner = statics.ownerOf.get(hits[i].body);
|
|
14189
|
+
if (owner !== void 0 && !met.has(owner)) {
|
|
14190
|
+
met.add(owner);
|
|
14191
|
+
metList.push(owner);
|
|
14192
|
+
}
|
|
14193
|
+
}
|
|
14194
|
+
const around = world.overlapSphere(from, RAY_MARGIN, inside, FIXED_ONLY);
|
|
14195
|
+
for (let i = 0; i < around; i++) {
|
|
14196
|
+
const owner = statics.ownerOf.get(inside[i]);
|
|
14197
|
+
if (owner !== void 0 && !met.has(owner)) {
|
|
14198
|
+
met.add(owner);
|
|
14199
|
+
metList.push(owner);
|
|
14200
|
+
}
|
|
14201
|
+
}
|
|
14202
|
+
return true;
|
|
14203
|
+
},
|
|
14204
|
+
mayMeet: (objectId) => !statics.covers(objectId) || met.has(objectId),
|
|
14205
|
+
candidates: {
|
|
14206
|
+
met: () => metList,
|
|
14207
|
+
covers: (objectId) => statics.covers(objectId),
|
|
14208
|
+
revision: () => statics.coverageRevision
|
|
14209
|
+
}
|
|
14210
|
+
};
|
|
14211
|
+
};
|
|
14212
|
+
|
|
14213
|
+
// src/merge-flush-boxes.ts
|
|
14214
|
+
var FLUSH = 1e-4;
|
|
14215
|
+
var sameTurn = (a, b) => {
|
|
14216
|
+
if (!a.rotation && !b.rotation) return true;
|
|
14217
|
+
if (!a.rotation || !b.rotation) return false;
|
|
14218
|
+
return a.rotation.every((v, i) => Math.abs(v - b.rotation[i]) < FLUSH);
|
|
14219
|
+
};
|
|
14220
|
+
var flushAxis = (a, b) => {
|
|
14221
|
+
if (!sameTurn(a, b)) return -1;
|
|
14222
|
+
let along2 = -1;
|
|
14223
|
+
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
14224
|
+
const same2 = Math.abs(a.half[axis2] - b.half[axis2]) < FLUSH && Math.abs(a.center[axis2] - b.center[axis2]) < FLUSH;
|
|
14225
|
+
if (same2) continue;
|
|
14226
|
+
if (along2 >= 0) return -1;
|
|
14227
|
+
along2 = axis2;
|
|
14228
|
+
}
|
|
14229
|
+
if (along2 < 0) return -1;
|
|
14230
|
+
return Math.abs(Math.abs(a.center[along2] - b.center[along2]) - a.half[along2] - b.half[along2]) < FLUSH ? along2 : -1;
|
|
14231
|
+
};
|
|
14232
|
+
function mergeFlushBoxes(boxes) {
|
|
14233
|
+
const out = [...boxes];
|
|
14234
|
+
for (let i = 0; i < out.length; i++) {
|
|
14235
|
+
for (let j = i + 1; j < out.length; j++) {
|
|
14236
|
+
const a = out[i];
|
|
14237
|
+
const axis2 = flushAxis(a, out[j]);
|
|
14238
|
+
if (axis2 < 0) continue;
|
|
14239
|
+
const b = out[j];
|
|
14240
|
+
const low = Math.min(a.center[axis2] - a.half[axis2], b.center[axis2] - b.half[axis2]);
|
|
14241
|
+
const high = Math.max(a.center[axis2] + a.half[axis2], b.center[axis2] + b.half[axis2]);
|
|
14242
|
+
const center = [a.center[0], a.center[1], a.center[2]];
|
|
14243
|
+
const half = [a.half[0], a.half[1], a.half[2]];
|
|
14244
|
+
center[axis2] = (low + high) / 2;
|
|
14245
|
+
half[axis2] = (high - low) / 2;
|
|
14246
|
+
out[i] = { center, half, ...a.rotation ? { rotation: a.rotation } : {} };
|
|
14247
|
+
out.splice(j, 1);
|
|
14248
|
+
j = i;
|
|
14249
|
+
}
|
|
14250
|
+
}
|
|
14251
|
+
return out;
|
|
14252
|
+
}
|
|
14253
|
+
|
|
14022
14254
|
// src/engine-pieces.ts
|
|
14023
14255
|
var GROUND_WORKER_FRAMES = 2;
|
|
14024
14256
|
var wasCoarseOf = (tile) => !tile.slab && tile.collision.length < tile.heights.length;
|
|
@@ -14056,6 +14288,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14056
14288
|
var TOPPLE = 3;
|
|
14057
14289
|
var HOLD_MARGIN = 4;
|
|
14058
14290
|
var SIDE_DEAD = 0.01;
|
|
14291
|
+
var BOX_FOOT = 0.02;
|
|
14059
14292
|
var PUSH_SPIN = 0.3;
|
|
14060
14293
|
var STEADY_TURN = 0.1;
|
|
14061
14294
|
var STEADY_SECONDS = 1.5;
|
|
@@ -14114,6 +14347,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14114
14347
|
__publicField(this, "pose", new Float64Array(7));
|
|
14115
14348
|
__publicField(this, "velocity", new Float64Array(6));
|
|
14116
14349
|
__publicField(this, "contactXYZ", new Float32Array(48));
|
|
14350
|
+
/** The pieces hung on a hinge: the fixed anchor at the screw and the joint that holds them to it. */
|
|
14351
|
+
__publicField(this, "hung", /* @__PURE__ */ new Map());
|
|
14117
14352
|
__publicField(this, "outAxis", new Float64Array(3));
|
|
14118
14353
|
__publicField(this, "wayAxis", new Float64Array(3));
|
|
14119
14354
|
/** The centre `readBack` reads into (the sweep may move it). */
|
|
@@ -14151,6 +14386,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14151
14386
|
this.schedule = o.groundWorker ? new GroundSchedule(o.groundWorker, Math.max(1, Math.round(o.groundWorkerFrames ?? GROUND_WORKER_FRAMES))) : null;
|
|
14152
14387
|
if (this.schedule) this.warmGround(this.schedule);
|
|
14153
14388
|
}
|
|
14389
|
+
/** The fixed bodies as a broad phase for the destruction world's rays (`engine-rays.ts`). */
|
|
14390
|
+
rayBroadPhase() {
|
|
14391
|
+
return createEngineRayBroadPhase(this.world, this.statics);
|
|
14392
|
+
}
|
|
14154
14393
|
/** The worker's first job, a sloped tile with steps away from the host's ground (no host call): its code is parsed and hot before the first blast asks for real ones. */
|
|
14155
14394
|
warmGround(schedule) {
|
|
14156
14395
|
const warmGround = (x, z) => 0.3 * x - 0.2 * z + 0.15 * Math.floor(x / 0.37) + 0.05 * Math.sin(3 * z);
|
|
@@ -14164,6 +14403,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14164
14403
|
remove(b, wakeNeighbours = true) {
|
|
14165
14404
|
const link = this.links.get(b);
|
|
14166
14405
|
if (!link) return;
|
|
14406
|
+
const held = this.hung.get(b);
|
|
14407
|
+
if (held) this.letGo(b, held);
|
|
14167
14408
|
this.world.removeBody(link.id);
|
|
14168
14409
|
if (wakeNeighbours && (b.sleeping || link.sleeping)) this.wakeAround(b, link.pos);
|
|
14169
14410
|
this.byUser.delete(link.user);
|
|
@@ -14304,6 +14545,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14304
14545
|
this.applyDueGround();
|
|
14305
14546
|
this.layBlastGround();
|
|
14306
14547
|
this.makeBodies(each);
|
|
14548
|
+
each((b) => this.hang(b));
|
|
14307
14549
|
each((b) => this.sync(b, dt, h));
|
|
14308
14550
|
if (this.schedule) this.layGroundLater(each, dt);
|
|
14309
14551
|
else this.layGround(each, dt);
|
|
@@ -14337,8 +14579,44 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14337
14579
|
this.readActive(awake);
|
|
14338
14580
|
awake.walk((b) => this.readBack(b, dt, time, this.active));
|
|
14339
14581
|
} else for (const b of list) this.readBack(b, dt, time, null);
|
|
14582
|
+
this.wearHinges(dt);
|
|
14340
14583
|
this.knock(time);
|
|
14341
14584
|
}
|
|
14585
|
+
/** A piece with a hinge asked for (`PieceSystem.hinge`) gets a fixed anchor at the screw and a hinge joint to it, once its body exists. It swings in the vertical plane through the screw and its centre. */
|
|
14586
|
+
hang(b) {
|
|
14587
|
+
const hinge = b.hinge;
|
|
14588
|
+
const link = this.links.get(b);
|
|
14589
|
+
if (!hinge || !link || this.hung.has(b)) return;
|
|
14590
|
+
const c = this.centre(b);
|
|
14591
|
+
const dx = c.x - hinge.point[0];
|
|
14592
|
+
const dz = c.z - hinge.point[2];
|
|
14593
|
+
const along2 = Math.hypot(dx, dz);
|
|
14594
|
+
const axis2 = along2 < 1e-3 ? [0, 0, 1] : [dz / along2, 0, -dx / along2];
|
|
14595
|
+
const anchor = this.world.createBody({ shape: { kind: "box", half: [5e-3, 5e-3, 5e-3] }, motion: "static", position: hinge.point, user: 0 });
|
|
14596
|
+
this.world.ignorePair(anchor, link.id, true);
|
|
14597
|
+
const joint = this.world.createJoint({ kind: "hinge", a: anchor, b: link.id, point: hinge.point, axis: axis2, normal: [0, 1, 0], min: -Math.PI / 2, max: Math.PI / 2 });
|
|
14598
|
+
this.hung.set(b, { anchor, joint });
|
|
14599
|
+
}
|
|
14600
|
+
/** The screw tears out: past `HINGE_RELEASE` of turn, or after `HINGE_SECONDS`, the piece falls free. */
|
|
14601
|
+
wearHinges(dt) {
|
|
14602
|
+
for (const [b, held] of this.hung) {
|
|
14603
|
+
const hinge = b.hinge;
|
|
14604
|
+
if (hinge) {
|
|
14605
|
+
hinge.seconds -= dt;
|
|
14606
|
+
const [x, y, z, w] = hinge.from;
|
|
14607
|
+
const q = b.root.quaternion;
|
|
14608
|
+
const turned = 2 * Math.acos(Math.min(1, Math.abs(q.x * x + q.y * y + q.z * z + q.w * w)));
|
|
14609
|
+
if (turned < HINGE_RELEASE && hinge.seconds > 0) continue;
|
|
14610
|
+
}
|
|
14611
|
+
this.letGo(b, held);
|
|
14612
|
+
}
|
|
14613
|
+
}
|
|
14614
|
+
letGo(b, held) {
|
|
14615
|
+
this.world.removeJoint(held.joint);
|
|
14616
|
+
this.world.removeBody(held.anchor);
|
|
14617
|
+
this.hung.delete(b);
|
|
14618
|
+
b.hinge = void 0;
|
|
14619
|
+
}
|
|
14342
14620
|
/** The engine's awake bodies in one crossing: a sleeping piece one of them wakes (a blow) is among the awake pieces from now on, and read back in this same step. */
|
|
14343
14621
|
readActive(awake) {
|
|
14344
14622
|
this.active.clear();
|
|
@@ -14422,7 +14700,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14422
14700
|
return { kind: "compound", children: [{ shape: { kind: "cylinder", halfHeight: b.halfExtents[round2.axis], radius: round2.radius }, position: [0, 0, 0], rotation: rotation2 }] };
|
|
14423
14701
|
}
|
|
14424
14702
|
if (b.partBoxes && b.partBoxes.length > 0) {
|
|
14425
|
-
return { kind: "compound", children: b.partBoxes.map((part, i) => ({ shape: { kind: "box", half: part.half }, position: part.center, ...part.rotation ? { rotation: part.rotation } : {}, tag: i })) };
|
|
14703
|
+
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 })) };
|
|
14426
14704
|
}
|
|
14427
14705
|
return { kind: "box", half: b.halfExtents };
|
|
14428
14706
|
}
|
|
@@ -14488,8 +14766,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14488
14766
|
return {
|
|
14489
14767
|
frictionStatic: b.friction?.static ?? MU_STATIC,
|
|
14490
14768
|
frictionDynamic: b.friction?.dynamic ?? MU_DYNAMIC,
|
|
14491
|
-
|
|
14492
|
-
restitution: b.round ? b.restitution ?? SLAM_BOUNCE : 0,
|
|
14769
|
+
restitution: b.restitution ?? SLAM_BOUNCE,
|
|
14493
14770
|
rolling: b.friction?.rolling ?? ROLLING_RESISTANCE
|
|
14494
14771
|
};
|
|
14495
14772
|
}
|
|
@@ -14734,8 +15011,16 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14734
15011
|
this.slip(b, link, false);
|
|
14735
15012
|
return;
|
|
14736
15013
|
}
|
|
14737
|
-
const c = this.centre(b);
|
|
14738
15014
|
const q = b.root.quaternion;
|
|
15015
|
+
const c = this.centre(b);
|
|
15016
|
+
let shiftX = 0, shiftY = 0, shiftZ = 0;
|
|
15017
|
+
if (b.massCentre) {
|
|
15018
|
+
this.w.set(b.massCentre[0], b.massCentre[1], b.massCentre[2]).applyQuaternion(q);
|
|
15019
|
+
shiftX = this.w.x;
|
|
15020
|
+
shiftY = this.w.y;
|
|
15021
|
+
shiftZ = this.w.z;
|
|
15022
|
+
c.add(this.w);
|
|
15023
|
+
}
|
|
14739
15024
|
let low = Infinity;
|
|
14740
15025
|
for (let i = 0; i < n; i++) low = Math.min(low, this.contactXYZ[i * 3 + 1] - c.y);
|
|
14741
15026
|
let x0 = Infinity, x1 = -Infinity, z0 = Infinity, z1 = -Infinity;
|
|
@@ -14747,6 +15032,23 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14747
15032
|
z0 = Math.min(z0, rz);
|
|
14748
15033
|
z1 = Math.max(z1, rz);
|
|
14749
15034
|
}
|
|
15035
|
+
if (!b.contacts && !b.round && !b.apart) {
|
|
15036
|
+
const [hx, hy, hz2] = b.halfExtents;
|
|
15037
|
+
const corner = this.w;
|
|
15038
|
+
let lowest = Infinity;
|
|
15039
|
+
for (let k = 0; k < 8; k++) lowest = Math.min(lowest, corner.set(k & 1 ? hx : -hx, k & 2 ? hy : -hy, k & 4 ? hz2 : -hz2).applyQuaternion(q).y - shiftY);
|
|
15040
|
+
if (Math.abs(lowest - low) < BOX_FOOT) {
|
|
15041
|
+
for (let k = 0; k < 8; k++) {
|
|
15042
|
+
corner.set(k & 1 ? hx : -hx, k & 2 ? hy : -hy, k & 4 ? hz2 : -hz2).applyQuaternion(q);
|
|
15043
|
+
if (corner.y - shiftY > lowest + BOX_FOOT) continue;
|
|
15044
|
+
x0 = Math.min(x0, corner.x - shiftX);
|
|
15045
|
+
x1 = Math.max(x1, corner.x - shiftX);
|
|
15046
|
+
z0 = Math.min(z0, corner.z - shiftZ);
|
|
15047
|
+
z1 = Math.max(z1, corner.z - shiftZ);
|
|
15048
|
+
}
|
|
15049
|
+
low = Math.min(low, lowest);
|
|
15050
|
+
}
|
|
15051
|
+
}
|
|
14750
15052
|
const height = -low;
|
|
14751
15053
|
const wx = x1 - x0;
|
|
14752
15054
|
const wz = z1 - z0;
|
|
@@ -15148,7 +15450,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15148
15450
|
replaceGround(tile, made2, ix, iz, material) {
|
|
15149
15451
|
if (tile) this.world.removeBody(tile.ground);
|
|
15150
15452
|
if (made2.level === null) return this.world.createBody({ shape: this.heightField(made2, ix, iz), motion: "static", position: [0, 0, 0], material, user: 0 });
|
|
15151
|
-
return this.world.createBody({ shape: { kind: "box", half: [TILE / 2, 0.5, TILE / 2] }, motion: "static", position: [(ix + 0.5) * TILE, made2.level - 0.5, (iz + 0.5) * TILE], material, user: 0 });
|
|
15453
|
+
return this.world.createBody({ shape: { kind: "box", half: [TILE / 2, 0.5, TILE / 2], convexRadius: 0 }, motion: "static", position: [(ix + 0.5) * TILE, made2.level - 0.5, (iz + 0.5) * TILE], material, user: 0 });
|
|
15152
15454
|
}
|
|
15153
15455
|
/** The solid under a height field, on its own body, swapped in place when the ground changed; none under a slab. Boxes only: a box costs nothing to make, a hull did (T3.8ag). */
|
|
15154
15456
|
layVolume(t, tile, material) {
|
|
@@ -15172,13 +15474,13 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15172
15474
|
}
|
|
15173
15475
|
stepBoxes(boxes) {
|
|
15174
15476
|
const children = [];
|
|
15175
|
-
for (let i = 0; i < boxes.length; i += 6) children.push({ shape: { kind: "box", half: [boxes[i + 3], boxes[i + 4], boxes[i + 5]] }, position: [boxes[i], boxes[i + 1], boxes[i + 2]] });
|
|
15477
|
+
for (let i = 0; i < boxes.length; i += 6) children.push({ shape: { kind: "box", half: [boxes[i + 3], boxes[i + 4], boxes[i + 5]], convexRadius: 0 }, position: [boxes[i], boxes[i + 1], boxes[i + 2]] });
|
|
15176
15478
|
return { kind: "compound", children };
|
|
15177
15479
|
}
|
|
15178
15480
|
/** The host's fixed boxes, one static body per object (`EngineStatics`). */
|
|
15179
15481
|
layStatics() {
|
|
15180
15482
|
const now = this.o.staticSolids?.();
|
|
15181
|
-
if (now) this.statics.lay(now);
|
|
15483
|
+
if (now) this.statics.lay(now, this.o.staticUnsure?.());
|
|
15182
15484
|
}
|
|
15183
15485
|
keepApart(apart2) {
|
|
15184
15486
|
for (const key of this.ignored) {
|
|
@@ -15395,6 +15697,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15395
15697
|
var SLIP_SPEED = 0.02;
|
|
15396
15698
|
var ROLLING_RESISTANCE2 = 0.015;
|
|
15397
15699
|
var ROUND_LYING = Math.SQRT1_2;
|
|
15700
|
+
var MIN_PIECE_HALF = 1e-3;
|
|
15701
|
+
var OWN_MIN_PIECE_HALF = 0.01;
|
|
15702
|
+
var OWN_MIN_MEASURED_HALF = 0.02;
|
|
15703
|
+
var minPieceHalf = (physics) => physics === "own" ? OWN_MIN_MEASURED_HALF : MIN_PIECE_HALF;
|
|
15398
15704
|
var SLEEP_AFTER = 0.5;
|
|
15399
15705
|
var STILL_SPEED2 = 0.12;
|
|
15400
15706
|
var STILL_SPIN2 = 0.45;
|
|
@@ -15414,6 +15720,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15414
15720
|
var TIP_LYING = 0.25;
|
|
15415
15721
|
var TIP_SECONDS = 3;
|
|
15416
15722
|
var STEP = 0.03;
|
|
15723
|
+
var WAKE_SAMPLES = 4;
|
|
15724
|
+
var WAKE_DROP = 0.05;
|
|
15417
15725
|
var WARM_SLOTS = 8 + 12 * 7;
|
|
15418
15726
|
var SOLVER_PASSES = 10;
|
|
15419
15727
|
var SIDE_BOUNCE = 0.1;
|
|
@@ -15441,8 +15749,6 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15441
15749
|
var MAX_COLLISION_STEPS = 8;
|
|
15442
15750
|
var MIN_ROUND_RADIUS = 5e-3;
|
|
15443
15751
|
var BOUNCE_MIN_SPEED = 0.1;
|
|
15444
|
-
var HINGE_RELEASE = 40 * Math.PI / 180;
|
|
15445
|
-
var HINGE_SECONDS = 1.5;
|
|
15446
15752
|
var BOX_IMPACT_SPEED = 1.5;
|
|
15447
15753
|
var KNOCK_FLAT = 0.5;
|
|
15448
15754
|
var SEPARATE_SPEED = 1.5;
|
|
@@ -15508,6 +15814,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15508
15814
|
__publicField(this, "m");
|
|
15509
15815
|
__publicField(this, "hingeM");
|
|
15510
15816
|
__publicField(this, "ax");
|
|
15817
|
+
__publicField(this, "wakeBox");
|
|
15511
15818
|
__publicField(this, "solids", []);
|
|
15512
15819
|
/** The engine stepping the pieces (`PieceSystemOptions.physics`), or null for the kit's own solver. */
|
|
15513
15820
|
__publicField(this, "engine");
|
|
@@ -15598,6 +15905,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15598
15905
|
this.m = new THREE.Matrix4();
|
|
15599
15906
|
this.hingeM = new THREE.Matrix4();
|
|
15600
15907
|
this.ax = new THREE.Vector3();
|
|
15908
|
+
this.wakeBox = new THREE.Box3();
|
|
15601
15909
|
const resolved = resolvePhysics(o.physics);
|
|
15602
15910
|
this.loop = resolved?.loop ?? null;
|
|
15603
15911
|
this.stepsItself = resolved?.stepsItself ?? false;
|
|
@@ -15612,6 +15920,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15612
15920
|
...o.blastGroundTiles !== void 0 ? { blastTiles: o.blastGroundTiles } : {},
|
|
15613
15921
|
gravity: o.gravity,
|
|
15614
15922
|
staticSolids: o.staticSolids,
|
|
15923
|
+
staticUnsure: o.staticUnsure,
|
|
15615
15924
|
sweep: o.sweep,
|
|
15616
15925
|
onSlam: o.onSlam,
|
|
15617
15926
|
onKnock: o.onKnock,
|
|
@@ -15623,6 +15932,14 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15623
15932
|
this.groundWorker = o.groundWorker ?? null;
|
|
15624
15933
|
if (resolved && !resolved.stepsItself) this.joinLoop(resolved.loop, this.engine);
|
|
15625
15934
|
}
|
|
15935
|
+
/** Contact blows on the fixed parts become `blunt` hits of `destruction` (`engine-impacts.ts`); null when the pieces are not in the engine's loop. Returns the way to stop it. */
|
|
15936
|
+
contactHits(destruction, options) {
|
|
15937
|
+
return this.engine && this.loop ? createEngineImpacts(this.loop, this.engine.statics, destruction, options) : null;
|
|
15938
|
+
}
|
|
15939
|
+
/** The engine's fixed bodies as the broad phase of the world's rays, or null when the pieces are not in the engine. */
|
|
15940
|
+
rayBroadPhase() {
|
|
15941
|
+
return this.engine?.rayBroadPhase() ?? null;
|
|
15942
|
+
}
|
|
15626
15943
|
/**
|
|
15627
15944
|
* The loop mode: the system's work goes into the loop's phases. `prepare` (sync, kinematic targets, the kit's rules that came before the step) runs in the first fixed step of
|
|
15628
15945
|
* a frame; a held piece's target again in each later one; the read-back and knock sounds after the steps (`contacts`); the budget and the measure after those (`rules`).
|
|
@@ -15762,10 +16079,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15762
16079
|
}
|
|
15763
16080
|
/**
|
|
15764
16081
|
* Hangs a piece on a hinge at `point` (world): that point of it stays where it is while the rest swings down about it, as a shelf that lost the side at one end swings on
|
|
15765
|
-
* the screw at the other and pours what lay on it off its free end. It lets go past `HINGE_RELEASE` or `HINGE_SECONDS`.
|
|
16082
|
+
* the screw at the other and pours what lay on it off its free end. It lets go past `HINGE_RELEASE` or `HINGE_SECONDS`. On the engine it is a hinge joint to a fixed anchor (`EnginePieces.hang`).
|
|
15766
16083
|
*/
|
|
15767
16084
|
hinge(body, point) {
|
|
15768
|
-
if (this.engine) return;
|
|
15769
16085
|
const c = this.centerOf(body, this.p);
|
|
15770
16086
|
const q = body.root.quaternion;
|
|
15771
16087
|
const local2 = this.ax.set(point[0] - c.x, point[1] - c.y, point[2] - c.z).applyQuaternion(this.dq.copy(q).invert());
|
|
@@ -15784,6 +16100,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15784
16100
|
return existing;
|
|
15785
16101
|
}
|
|
15786
16102
|
const awake = this.awake;
|
|
16103
|
+
const least = this.engine ? MIN_PIECE_HALF : OWN_MIN_PIECE_HALF;
|
|
15787
16104
|
let asleep = false;
|
|
15788
16105
|
let inHand = false;
|
|
15789
16106
|
const body = {
|
|
@@ -15793,7 +16110,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15793
16110
|
root,
|
|
15794
16111
|
velocity: velocity ? [...velocity] : [0, 0, 0],
|
|
15795
16112
|
angularVelocity: angular ? [...angular] : [0, 0, 0],
|
|
15796
|
-
halfExtents: [Math.max(
|
|
16113
|
+
halfExtents: [Math.max(least, halfExtents[0]), Math.max(least, halfExtents[1]), Math.max(least, halfExtents[2])],
|
|
15797
16114
|
mass: Math.max(0.05, mass),
|
|
15798
16115
|
// asleep or held is read and written as a plain flag; waking or taking it in hand puts the piece among the awake ones
|
|
15799
16116
|
get sleeping() {
|
|
@@ -15993,12 +16310,31 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15993
16310
|
wakeRegion(x, z, radius) {
|
|
15994
16311
|
this.engine?.groundChanged(x, z, radius);
|
|
15995
16312
|
for (const b of this.list) {
|
|
15996
|
-
if (!b.sleeping || b.held
|
|
16313
|
+
if (!b.sleeping || b.held) continue;
|
|
16314
|
+
if (Math.hypot(b.root.position.x - x, b.root.position.z - z) > radius && !this.lostGroundIn(b, x, z, radius)) continue;
|
|
15997
16315
|
b.sleeping = false;
|
|
15998
16316
|
b.still = 0;
|
|
15999
16317
|
b.calmAt = null;
|
|
16000
16318
|
}
|
|
16001
16319
|
}
|
|
16320
|
+
/**
|
|
16321
|
+
* A piece whose root is elsewhere (cut from a whole object, its root is that object's origin) that lies in the disc, with the ground gone from under part of its footprint:
|
|
16322
|
+
* where it lies is read from its drawn box, and only a support that went down wakes it (a piece the disc only passes over stays asleep).
|
|
16323
|
+
*/
|
|
16324
|
+
lostGroundIn(b, x, z, radius) {
|
|
16325
|
+
const center = this.centerOf(b, this.ax);
|
|
16326
|
+
if (Math.hypot(center.x - x, center.z - z) > radius + Math.hypot(b.halfExtents[0], b.halfExtents[2])) return false;
|
|
16327
|
+
const box = this.wakeBox.setFromObject(b.root);
|
|
16328
|
+
for (let i = 0; i <= WAKE_SAMPLES; i++) {
|
|
16329
|
+
for (let k = 0; k <= WAKE_SAMPLES; k++) {
|
|
16330
|
+
const px = box.min.x + (box.max.x - box.min.x) * i / WAKE_SAMPLES, pz = box.min.z + (box.max.z - box.min.z) * k / WAKE_SAMPLES;
|
|
16331
|
+
if (Math.hypot(px - x, pz - z) > radius) continue;
|
|
16332
|
+
const support = Math.max(this.o.groundAt(px, pz), this.o.staticTopAt?.(px, pz, box.min.y, STEP) ?? -Infinity);
|
|
16333
|
+
if (support < box.min.y - WAKE_DROP) return true;
|
|
16334
|
+
}
|
|
16335
|
+
}
|
|
16336
|
+
return false;
|
|
16337
|
+
}
|
|
16002
16338
|
/** A step is about to move the pieces: the roots go back to the step's pose and the awake ones are recorded as the previous one (`interpolate`). */
|
|
16003
16339
|
beginTick() {
|
|
16004
16340
|
const trail = this.trail;
|
|
@@ -16793,7 +17129,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16793
17129
|
let awake = 0;
|
|
16794
17130
|
for (const b of this.list) {
|
|
16795
17131
|
if (b.sleeping || b.held) continue;
|
|
16796
|
-
if (b.balancing && this.
|
|
17132
|
+
if (this.hasComeToRest(b) && (b.balancing || b.still >= SLEEP_AFTER && !b.hinge && !this.onSteepSupport(b))) this.sleepByBudget(b);
|
|
16797
17133
|
else awake++;
|
|
16798
17134
|
}
|
|
16799
17135
|
for (const b of this.list) {
|
|
@@ -16869,7 +17205,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16869
17205
|
}
|
|
16870
17206
|
/** Sleeps sooner than it would by itself, so it answers to every point it lies on (`restPoints`). */
|
|
16871
17207
|
sleepByBudget(b) {
|
|
17208
|
+
const steady = b.steady;
|
|
16872
17209
|
this.sleep(b);
|
|
17210
|
+
b.steady = steady;
|
|
16873
17211
|
b.restPoints = this.restPointsOf(b);
|
|
16874
17212
|
}
|
|
16875
17213
|
hasComeToRest(b) {
|
|
@@ -21221,6 +21559,20 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
21221
21559
|
let time = 0;
|
|
21222
21560
|
let counter = 0;
|
|
21223
21561
|
const objects = /* @__PURE__ */ new Map();
|
|
21562
|
+
const slots = /* @__PURE__ */ new Map();
|
|
21563
|
+
let slotCounter = 0;
|
|
21564
|
+
let objectsRevision = 0;
|
|
21565
|
+
const putObject = (id, object) => {
|
|
21566
|
+
if (!objects.has(id)) slots.set(id, ++slotCounter);
|
|
21567
|
+
objectsRevision++;
|
|
21568
|
+
objects.set(id, object);
|
|
21569
|
+
};
|
|
21570
|
+
const dropObject = (id) => {
|
|
21571
|
+
if (objects.delete(id)) {
|
|
21572
|
+
slots.delete(id);
|
|
21573
|
+
objectsRevision++;
|
|
21574
|
+
}
|
|
21575
|
+
};
|
|
21224
21576
|
const listeners = /* @__PURE__ */ new Map();
|
|
21225
21577
|
let cur = [];
|
|
21226
21578
|
const blasts = [];
|
|
@@ -23111,18 +23463,52 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
23111
23463
|
if (o.soil?.sets.size) restCarry.soilSets = Object.fromEntries(o.soil.sets);
|
|
23112
23464
|
const rest = build2(sub3(inOld), o.id, o.soil ? o.base.pos : pos, o.soil ? o.base.rot : rot, restCarry);
|
|
23113
23465
|
dirtyHosted.delete(o);
|
|
23114
|
-
|
|
23115
|
-
for (const [nid, object] of fresh)
|
|
23466
|
+
putObject(o.id, rest);
|
|
23467
|
+
for (const [nid, object] of fresh) putObject(nid, object);
|
|
23116
23468
|
return fresh.map(([nid]) => nid);
|
|
23117
23469
|
};
|
|
23470
|
+
let rayBroad = null;
|
|
23471
|
+
let uncovered = [];
|
|
23472
|
+
let uncoveredFor = { hook: null, coverage: -1, objects: -1 };
|
|
23473
|
+
const metObjects = [];
|
|
23474
|
+
const rayObjects = [];
|
|
23475
|
+
const candidatesOf = (hook) => {
|
|
23476
|
+
const asked = hook.candidates;
|
|
23477
|
+
if (!asked) return null;
|
|
23478
|
+
const coverage = asked.revision();
|
|
23479
|
+
if (uncoveredFor.hook !== hook || uncoveredFor.coverage !== coverage || uncoveredFor.objects !== objectsRevision) {
|
|
23480
|
+
uncovered = [];
|
|
23481
|
+
for (const o of objects.values()) if (!asked.covers(o.id)) uncovered.push(o);
|
|
23482
|
+
uncoveredFor = { hook, coverage, objects: objectsRevision };
|
|
23483
|
+
}
|
|
23484
|
+
if (uncovered.length * 2 > objects.size) return null;
|
|
23485
|
+
metObjects.length = 0;
|
|
23486
|
+
for (const id of asked.met()) {
|
|
23487
|
+
const o = objects.get(id);
|
|
23488
|
+
if (o && asked.covers(id)) metObjects.push(o);
|
|
23489
|
+
}
|
|
23490
|
+
metObjects.sort((a, b) => slots.get(a.id) - slots.get(b.id));
|
|
23491
|
+
rayObjects.length = 0;
|
|
23492
|
+
let m = 0;
|
|
23493
|
+
let u = 0;
|
|
23494
|
+
while (m < metObjects.length || u < uncovered.length) {
|
|
23495
|
+
const takeMet = u >= uncovered.length || m < metObjects.length && slots.get(metObjects[m].id) < slots.get(uncovered[u].id);
|
|
23496
|
+
rayObjects.push(takeMet ? metObjects[m++] : uncovered[u++]);
|
|
23497
|
+
}
|
|
23498
|
+
return rayObjects;
|
|
23499
|
+
};
|
|
23118
23500
|
const raycastInternal = (origin, dir, maxDist, ignore, worldOnly = false, precise = false, skip = {}, scope) => {
|
|
23119
23501
|
const d = vec.normalize(dir);
|
|
23502
|
+
const asked = rayBroad && !scope && rayBroad.begin(origin, d, maxDist) ? rayBroad : null;
|
|
23503
|
+
const candidates = asked ? candidatesOf(asked) : null;
|
|
23504
|
+
const outside = candidates ? null : asked;
|
|
23120
23505
|
const minRadius = skip.minObjectRadius ?? 0;
|
|
23121
23506
|
let best = null;
|
|
23122
23507
|
const counts = sweepCounts;
|
|
23123
|
-
for (const o of scope ? scope.objects : objects.values()) {
|
|
23508
|
+
for (const o of scope ? scope.objects : candidates ?? objects.values()) {
|
|
23124
23509
|
if (counts) counts.objectVisits++;
|
|
23125
23510
|
if (skip.skipLoose && o.loose || o.br < minRadius) continue;
|
|
23511
|
+
if (outside && !outside.mayMeet(o.id)) continue;
|
|
23126
23512
|
if (raySphereMiss(origin, d, worldCentreOf(o), o.br, best ? Math.min(maxDist, best.distance) : maxDist)) continue;
|
|
23127
23513
|
const qi = quat.conjugate(o.st.rotation);
|
|
23128
23514
|
const lo = rotateVec(qi, vec.sub(origin, o.st.position));
|
|
@@ -24744,6 +25130,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
24744
25130
|
return reach2;
|
|
24745
25131
|
};
|
|
24746
25132
|
let blastTntPerJoule = TNT_PER_JOULE;
|
|
25133
|
+
let blastHasCharge = false;
|
|
24747
25134
|
let blastFireball = chargeFireball(0);
|
|
24748
25135
|
const burstFuel = (p) => {
|
|
24749
25136
|
const c = p.spec.contains;
|
|
@@ -24848,7 +25235,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
24848
25235
|
}
|
|
24849
25236
|
for (const im of [...impls.values()]) {
|
|
24850
25237
|
if (!implInRange(im, point, radius)) continue;
|
|
24851
|
-
out.push(implHit(im, { type: "explosive", point, energy, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...src !== void 0 ? { source: src } : {} }));
|
|
25238
|
+
out.push(implHit(im, { type: "explosive", point, energy, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule, ...blastHasCharge ? { hasCharge: true } : {}, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...src !== void 0 ? { source: src } : {} }));
|
|
24852
25239
|
yield "part";
|
|
24853
25240
|
}
|
|
24854
25241
|
return out;
|
|
@@ -24973,7 +25360,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
24973
25360
|
den += f;
|
|
24974
25361
|
}
|
|
24975
25362
|
const k = den > 0 ? num / den : 1;
|
|
24976
|
-
const res = implHit(im, { type: "explosive", point, energy: E * k, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule * k, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...shelter ? { shelter: k } : {}, ...src !== void 0 ? { source: src } : {} });
|
|
25363
|
+
const res = implHit(im, { type: "explosive", point, energy: E * k, radius, fireball: blastFireball, tnt: energy * blastTntPerJoule * k, ...blastHasCharge ? { hasCharge: true } : {}, ...lethal !== void 0 ? { lethalRadius: lethal } : {}, ...shelter ? { shelter: k } : {}, ...src !== void 0 ? { source: src } : {} });
|
|
24977
25364
|
results.set(im, res);
|
|
24978
25365
|
report(im).shelter = k;
|
|
24979
25366
|
}
|
|
@@ -25315,13 +25702,16 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
25315
25702
|
const fireball = charge?.fuel ? fuelFireball(charge.fuel) : chargeFireball(energy * tntPerJoule);
|
|
25316
25703
|
const inBlast = (fn) => {
|
|
25317
25704
|
const outer = blastTntPerJoule;
|
|
25705
|
+
const outerHasCharge = blastHasCharge;
|
|
25318
25706
|
const outerFireball = blastFireball;
|
|
25319
25707
|
blastTntPerJoule = tntPerJoule;
|
|
25708
|
+
blastHasCharge = charge?.tnt !== void 0;
|
|
25320
25709
|
blastFireball = fireball;
|
|
25321
25710
|
try {
|
|
25322
25711
|
return fn();
|
|
25323
25712
|
} finally {
|
|
25324
25713
|
blastTntPerJoule = outer;
|
|
25714
|
+
blastHasCharge = outerHasCharge;
|
|
25325
25715
|
blastFireball = outerFireball;
|
|
25326
25716
|
}
|
|
25327
25717
|
};
|
|
@@ -25871,7 +26261,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
25871
26261
|
finishExplosions();
|
|
25872
26262
|
const id = opts.id ?? nextId();
|
|
25873
26263
|
if (taken(id)) throw new Error(`object "${id}" already exists`);
|
|
25874
|
-
|
|
26264
|
+
putObject(id, build2(resolveSpec(spec), id, opts.position ?? [0, 0, 0], opts.rotation ?? [0, 0, 0, 1]));
|
|
25875
26265
|
return id;
|
|
25876
26266
|
},
|
|
25877
26267
|
register(impl, opts = {}) {
|
|
@@ -25906,7 +26296,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
25906
26296
|
impls.get(id)?.impl.dispose?.();
|
|
25907
26297
|
const existing = objects.get(id);
|
|
25908
26298
|
if (existing) dirtyHosted.delete(existing);
|
|
25909
|
-
|
|
26299
|
+
dropObject(id);
|
|
25910
26300
|
impls.delete(id);
|
|
25911
26301
|
},
|
|
25912
26302
|
has: (id) => taken(id),
|
|
@@ -26025,6 +26415,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
26025
26415
|
},
|
|
26026
26416
|
beginExplosion,
|
|
26027
26417
|
cancelExplosions,
|
|
26418
|
+
setRayBroadPhase(broadPhase2) {
|
|
26419
|
+
rayBroad = broadPhase2;
|
|
26420
|
+
},
|
|
26028
26421
|
groundLoss(loss) {
|
|
26029
26422
|
if (!(loss.radius > 0) || !(loss.depth > 0) || !Number.isFinite(loss.x) || !Number.isFinite(loss.z)) return;
|
|
26030
26423
|
pendingLosses.push({ ...loss });
|
|
@@ -26279,7 +26672,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
26279
26672
|
}
|
|
26280
26673
|
const o = getObj(id);
|
|
26281
26674
|
dirtyHosted.delete(o);
|
|
26282
|
-
|
|
26675
|
+
putObject(id, build2(o.spec, id, o.base.pos, o.base.rot));
|
|
26283
26676
|
},
|
|
26284
26677
|
on(type, fn) {
|
|
26285
26678
|
const known = listeners.get(type) ?? [];
|
|
@@ -26308,17 +26701,19 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
26308
26701
|
finishExplosions();
|
|
26309
26702
|
const existing = objects.get(id);
|
|
26310
26703
|
if (existing) dirtyHosted.delete(existing);
|
|
26311
|
-
|
|
26704
|
+
putObject(id, buildFromEntry(entry, id));
|
|
26312
26705
|
},
|
|
26313
26706
|
load(snap) {
|
|
26314
26707
|
cancelExplosions();
|
|
26315
26708
|
if (snap.version !== 1) throw new Error(`unsupported snapshot version ${String(snap.version)}`);
|
|
26316
26709
|
dirtyHosted.clear();
|
|
26317
26710
|
objects.clear();
|
|
26711
|
+
slots.clear();
|
|
26712
|
+
objectsRevision++;
|
|
26318
26713
|
time = snap.time;
|
|
26319
26714
|
rng.set(snap.rng);
|
|
26320
26715
|
counter = snap.counter ?? 0;
|
|
26321
|
-
for (const e of snap.objects)
|
|
26716
|
+
for (const e of snap.objects) putObject(e.id, buildFromEntry(e, e.id));
|
|
26322
26717
|
for (const e of snap.impls ?? []) {
|
|
26323
26718
|
const im = impls.get(e.id);
|
|
26324
26719
|
if (!im) continue;
|
|
@@ -28719,7 +29114,6 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28719
29114
|
var PART_BOX_MESHES = 64;
|
|
28720
29115
|
var ROUND_SAMPLES = 400;
|
|
28721
29116
|
var ROUND_SIDES = 0.12;
|
|
28722
|
-
var MIN_PIECE_HALF = 0.02;
|
|
28723
29117
|
var ROUND_SLACK = 1.12;
|
|
28724
29118
|
var RIM_POINTS = 12;
|
|
28725
29119
|
var rimPoints = (round2, half) => {
|
|
@@ -28899,6 +29293,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28899
29293
|
__publicField(this, "staticBoxes", /* @__PURE__ */ new Map());
|
|
28900
29294
|
/** `staticSolids` per object, kept until `staticNow` measures the object again for a reason. */
|
|
28901
29295
|
__publicField(this, "solidCache", /* @__PURE__ */ new Map());
|
|
29296
|
+
/** The objects whose last `staticSolids` list is not all of what a ray can hit: measured in part, or with a loose or hidden part left out. */
|
|
29297
|
+
__publicField(this, "unsureSolids", /* @__PURE__ */ new Set());
|
|
28902
29298
|
/** The objects `staticNow` measured again for a reason (an event, a moved root, boxes that changed): their `staticSolids` are measured again too. */
|
|
28903
29299
|
__publicField(this, "solidStale", /* @__PURE__ */ new Set());
|
|
28904
29300
|
/** The world matrix of each root when `staticNow` last measured it. */
|
|
@@ -29029,6 +29425,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29029
29425
|
__publicField(this, "time", 0);
|
|
29030
29426
|
__publicField(this, "scanTimer", 0);
|
|
29031
29427
|
__publicField(this, "disposed", false);
|
|
29428
|
+
__publicField(this, "stopContactHits", null);
|
|
29032
29429
|
__publicField(this, "box");
|
|
29033
29430
|
__publicField(this, "tmpQ");
|
|
29034
29431
|
__publicField(this, "v1");
|
|
@@ -29104,6 +29501,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29104
29501
|
...o.blastGroundTiles !== void 0 ? { blastGroundTiles: o.blastGroundTiles } : {},
|
|
29105
29502
|
staticTopAt: (x, z, y, step) => this.staticTopAt(x, z, y, step),
|
|
29106
29503
|
staticSolids: () => this.staticSolids(),
|
|
29504
|
+
staticUnsure: () => this.unsureSolids,
|
|
29107
29505
|
gravity: this.gravity,
|
|
29108
29506
|
scene: o.scene,
|
|
29109
29507
|
maxAwake: o.maxAwakePieces ?? Infinity,
|
|
@@ -29120,6 +29518,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29120
29518
|
this.landingSound(b.objectId, point, clamp6(speed / 10, 0.2, 1));
|
|
29121
29519
|
}
|
|
29122
29520
|
});
|
|
29521
|
+
if (o.rayBroadPhase) this.world.setRayBroadPhase(this.pieceSys.rayBroadPhase());
|
|
29522
|
+
if (o.contactHits) this.stopContactHits = this.pieceSys.contactHits(this.world, o.contactHits === true ? void 0 : o.contactHits);
|
|
29123
29523
|
this.unsubscribe = this.world.on("*", (ev) => {
|
|
29124
29524
|
if (ev.type === "explode") this.coverWhenWentOff.set(ev, this.coverAround(ev));
|
|
29125
29525
|
if (this.queue.length < QUEUE_CAP || isStructuralEvent(ev)) this.queue.push(ev);
|
|
@@ -29295,7 +29695,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29295
29695
|
}
|
|
29296
29696
|
if (total.isEmpty()) return { half: [0.25, 0.25, 0.25], center: new this.THREE.Vector3() };
|
|
29297
29697
|
const size = total.getSize(new this.THREE.Vector3());
|
|
29298
|
-
|
|
29698
|
+
const least = minPieceHalf(this.o.physics);
|
|
29699
|
+
return { half: [Math.max(least, size.x / 2), Math.max(least, size.y / 2), Math.max(least, size.z / 2)], center: total.getCenter(new this.THREE.Vector3()) };
|
|
29299
29700
|
}
|
|
29300
29701
|
/**
|
|
29301
29702
|
* A hosted body's boxes (`hostedSolids`: its damage zones) cut to the box of what its root draws, in the root's frame: the zones reach past the drawn body (17 cm each
|
|
@@ -29982,6 +30383,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29982
30383
|
const budget = { left: VERTICES_PER_UPDATE, incomplete: false, updated: this.measuredMeshes, workers: this.o.workers ?? null };
|
|
29983
30384
|
try {
|
|
29984
30385
|
this.measureEach(now, budget, out);
|
|
30386
|
+
this.unsureSolids.clear();
|
|
30387
|
+
for (const id of out.keys()) {
|
|
30388
|
+
if (this.solidStale.has(id) || this.solidCache.get(id)?.leftOut) this.unsureSolids.add(id);
|
|
30389
|
+
}
|
|
29985
30390
|
} finally {
|
|
29986
30391
|
this.measuredMeshes.clear();
|
|
29987
30392
|
}
|
|
@@ -30004,14 +30409,26 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30004
30409
|
budget.incomplete = false;
|
|
30005
30410
|
const solids = this.measureSolids(id, budget);
|
|
30006
30411
|
if (budget.incomplete) this.solidStale.add(id);
|
|
30412
|
+
const leftOut = this.hasUnlistedPart(id);
|
|
30007
30413
|
if (cached && sameSolids(cached.solids, solids)) {
|
|
30414
|
+
cached.leftOut = leftOut;
|
|
30008
30415
|
out.set(id, cached.solids);
|
|
30009
30416
|
continue;
|
|
30010
30417
|
}
|
|
30011
|
-
this.solidCache.set(id, { solids });
|
|
30418
|
+
this.solidCache.set(id, { solids, leftOut });
|
|
30012
30419
|
out.set(id, solids);
|
|
30013
30420
|
}
|
|
30014
30421
|
}
|
|
30422
|
+
/** Whether a part the world still lets a ray hit is not in the object's list: a loose or hidden mesh (a lost part is no hit either). */
|
|
30423
|
+
hasUnlistedPart(id) {
|
|
30424
|
+
const b = this.bounds.get(id);
|
|
30425
|
+
if (!b) return false;
|
|
30426
|
+
for (const pv of b.parts.values()) {
|
|
30427
|
+
if (pv.gone !== "none") continue;
|
|
30428
|
+
if (pv.meshes.some((mv) => mv.loose || !this.visuals.shown(mv))) return true;
|
|
30429
|
+
}
|
|
30430
|
+
return false;
|
|
30431
|
+
}
|
|
30015
30432
|
/**
|
|
30016
30433
|
* Every fixed thing the object draws as what it collides as (`drawnSolidsOf`): a box where one fits the part, the triangles where not, a part of a merged mesh by its own
|
|
30017
30434
|
* vertices, a mesh of any width. What is hidden, broken or loose is not drawn, so it is not here.
|
|
@@ -30809,6 +31226,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30809
31226
|
old.halfExtents = half;
|
|
30810
31227
|
this.pieceSys.setCenter(old, center);
|
|
30811
31228
|
old.mass = Math.max(MIN_PIECE_MASS_KG, this.massOf(objectId) - (old.massOffset ?? 0));
|
|
31229
|
+
old.apart = true;
|
|
30812
31230
|
if (old.contacts || old.round) {
|
|
30813
31231
|
this.fitSurface(b, old);
|
|
30814
31232
|
if (!old.round) this.setContacts(b, old, this.meshesOf(b).filter((mv) => this.visuals.shown(mv)));
|
|
@@ -30816,6 +31234,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30816
31234
|
if (!this.splittingAtLoad) old.sleeping = false;
|
|
30817
31235
|
} else if (kitOriginOf(b.root)?.kind === "furniture" && !this.splittingAtLoad) {
|
|
30818
31236
|
const piece = this.makePiece(objectId);
|
|
31237
|
+
piece.apart = true;
|
|
30819
31238
|
this.tipIfTopHeavy(b, true);
|
|
30820
31239
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
30821
31240
|
}
|
|
@@ -31067,6 +31486,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31067
31486
|
}
|
|
31068
31487
|
const piece = this.pieceSys.create(newId, group, half, center, this.massOf(newId), vel, ang);
|
|
31069
31488
|
nb.piece = piece;
|
|
31489
|
+
piece.apart = true;
|
|
31070
31490
|
this.fitSurface(nb, piece);
|
|
31071
31491
|
this.fitPartBoxes(nb, piece);
|
|
31072
31492
|
const resting = this.splittingAtLoad && this.pieceSys.restIfSupported(piece);
|
|
@@ -31092,6 +31512,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31092
31512
|
body.halfExtents = half;
|
|
31093
31513
|
this.pieceSys.setCenter(body, center);
|
|
31094
31514
|
body.mass = Math.max(MIN_PIECE_MASS_KG, this.massOf(objectId) - (body.massOffset ?? 0));
|
|
31515
|
+
body.apart = true;
|
|
31095
31516
|
if (!structural) {
|
|
31096
31517
|
this.fitSurface(b, body);
|
|
31097
31518
|
if (!body.round) this.setContacts(b, body, left);
|
|
@@ -31123,6 +31544,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31123
31544
|
away = hull.length >= 3 ? inside.out : null;
|
|
31124
31545
|
}
|
|
31125
31546
|
const piece = this.makePiece(objectId);
|
|
31547
|
+
(b.piece ?? piece).apart = true;
|
|
31126
31548
|
this.setContacts(b, b.piece ?? piece, left);
|
|
31127
31549
|
const loose = b.piece;
|
|
31128
31550
|
if (away && loose) {
|
|
@@ -31174,6 +31596,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31174
31596
|
}
|
|
31175
31597
|
if (!this.standsOn(objectId, wholeBoxes) || this.standsOn(objectId, boxes)) return false;
|
|
31176
31598
|
const piece = this.makePiece(objectId);
|
|
31599
|
+
(b.piece ?? piece).apart = true;
|
|
31177
31600
|
this.setContacts(b, b.piece ?? piece, this.meshesOf(b).filter((mv) => this.visuals.shown(mv)));
|
|
31178
31601
|
this.tipIfTopHeavy(b);
|
|
31179
31602
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
@@ -31256,6 +31679,38 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31256
31679
|
}
|
|
31257
31680
|
body.contacts = points.length > 0 && meshes.length <= CONTACT_MESHES ? points : void 0;
|
|
31258
31681
|
body.partBoxes = boxes.length > 1 || boxes.length === 1 && isTurned(boxes[0]) ? boxes : void 0;
|
|
31682
|
+
body.massCentre = this.massCentreOf(b, body);
|
|
31683
|
+
}
|
|
31684
|
+
/** Where the weight of what is drawn of `b` is, from the middle of its box (`PieceBody.massCentre`): each part's box centre weighed by the part's mass. */
|
|
31685
|
+
massCentreOf(b, body) {
|
|
31686
|
+
if (b.parts.size < 2) return void 0;
|
|
31687
|
+
const inv = specFrameInverse(this.THREE, b.root);
|
|
31688
|
+
const m4 = new this.THREE.Matrix4();
|
|
31689
|
+
const lb = new this.THREE.Box3();
|
|
31690
|
+
const box = new this.THREE.Box3();
|
|
31691
|
+
const middle = new this.THREE.Vector3();
|
|
31692
|
+
let weight = 0;
|
|
31693
|
+
const sum = [0, 0, 0];
|
|
31694
|
+
for (const [partId, pv] of b.parts) {
|
|
31695
|
+
const mass = pv.gone === "none" ? this.world.part(b.id, partId)?.mass ?? 0 : 0;
|
|
31696
|
+
if (mass <= 0) continue;
|
|
31697
|
+
box.makeEmpty();
|
|
31698
|
+
for (const mv of pv.meshes) {
|
|
31699
|
+
if (!this.visuals.shown(mv)) continue;
|
|
31700
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
31701
|
+
this.visuals.localBox(mv, lb);
|
|
31702
|
+
if (!lb.isEmpty()) box.union(lb.applyMatrix4(m4.multiplyMatrices(inv, mv.mesh.matrixWorld)));
|
|
31703
|
+
}
|
|
31704
|
+
if (box.isEmpty()) continue;
|
|
31705
|
+
box.getCenter(middle);
|
|
31706
|
+
sum[0] += middle.x * mass;
|
|
31707
|
+
sum[1] += middle.y * mass;
|
|
31708
|
+
sum[2] += middle.z * mass;
|
|
31709
|
+
weight += mass;
|
|
31710
|
+
}
|
|
31711
|
+
if (weight <= 0) return void 0;
|
|
31712
|
+
const [cx, cy, cz] = body.localCenter;
|
|
31713
|
+
return [sum[0] / weight - cx, sum[1] / weight - cy, sum[2] / weight - cz];
|
|
31259
31714
|
}
|
|
31260
31715
|
/** `fitOrientedBoxes` of a ranged part's points, taken from what it gave before when the points and the triangles are the very same numbers. */
|
|
31261
31716
|
fitRanged(mv, points) {
|
|
@@ -32000,6 +32455,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
32000
32455
|
this.releaseWarmProbes();
|
|
32001
32456
|
if (this.disposed) return;
|
|
32002
32457
|
this.unsubscribe();
|
|
32458
|
+
if (this.o.rayBroadPhase) this.world.setRayBroadPhase(null);
|
|
32459
|
+
this.stopContactHits?.();
|
|
32003
32460
|
this.clear();
|
|
32004
32461
|
for (const id of [...this.bounds.keys()]) this.unbind(id);
|
|
32005
32462
|
this.fragments.dispose();
|