@adatechnology/game-destruction-three 0.26.5 → 0.26.6
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/dist/ground-worker.global.js.map +1 -1
- package/dist/ground-worker.js.map +1 -1
- package/dist/index.global.js +225 -37
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +189 -15
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.global.js
CHANGED
|
@@ -8559,7 +8559,7 @@ var GameDestructionThree = (() => {
|
|
|
8559
8559
|
return sources;
|
|
8560
8560
|
}
|
|
8561
8561
|
|
|
8562
|
-
// ../game-vfx-three/dist/chunk-
|
|
8562
|
+
// ../game-vfx-three/dist/chunk-EE6XER4D.js
|
|
8563
8563
|
var GLOW_VERTEX = `attribute vec4 aP;attribute vec4 aC;varying vec2 vU;varying vec4 vC;
|
|
8564
8564
|
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
8565
|
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 +8575,22 @@ float vn(vec3 x){vec3 i=floor(x),f=fract(x);f=f*f*(3.-2.*f);
|
|
|
8575
8575
|
`;
|
|
8576
8576
|
var PUFF_VERTEX = `${GL_NOISE}
|
|
8577
8577
|
attribute vec4 aP;attribute vec4 aD;attribute vec3 aC;
|
|
8578
|
-
varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;
|
|
8578
|
+
varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
|
|
8579
8579
|
void main(){
|
|
8580
8580
|
vec3 p=position;
|
|
8581
|
+
vec3 q=normalize(position);
|
|
8581
8582
|
float s=aD.z;
|
|
8582
8583
|
float n=vn(p*1.6+vec3(s*11.0,s*7.0,s*3.0));
|
|
8583
8584
|
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;
|
|
8585
|
+
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;
|
|
8586
|
+
vL=p;vN=q;
|
|
8586
8587
|
vec3 wp=aP.xyz+p*aP.w;
|
|
8587
8588
|
vWP=wp;vD=aD;vC=aC;
|
|
8588
8589
|
gl_Position=projectionMatrix*viewMatrix*vec4(wp,1.0);
|
|
8589
8590
|
}`;
|
|
8590
8591
|
var PUFF_FRAGMENT = `${GL_NOISE}
|
|
8591
8592
|
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;
|
|
8593
|
+
varying vec3 vWP;varying vec3 vL;varying vec4 vD;varying vec3 vC;varying vec3 vN;
|
|
8593
8594
|
vec3 L(vec3 c){return pow(c,vec3(2.2));}
|
|
8594
8595
|
vec3 ramp(float h){
|
|
8595
8596
|
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 +8600,35 @@ vec3 ramp(float h){
|
|
|
8599
8600
|
return mix(c3,c4,clamp((h-.8)/.4,0.,1.));
|
|
8600
8601
|
}
|
|
8601
8602
|
void main(){
|
|
8602
|
-
vec3 N=normalize(cross(dFdx(vWP),dFdy(vWP)));
|
|
8603
8603
|
float age=vD.x,heat=vD.y,kind=vD.w;
|
|
8604
8604
|
float n=vn(vL*2.4+vD.z*13.0);
|
|
8605
|
-
|
|
8606
|
-
|
|
8605
|
+
// the sphere's own normal, roughened by the noise: a billowing cloud, never facets
|
|
8606
|
+
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;
|
|
8607
|
+
vec3 N=normalize(normalize(vN)+g*.9);
|
|
8608
|
+
vec3 V=normalize(cameraPosition-vWP);
|
|
8607
8609
|
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)
|
|
8610
|
+
float light=.42+.62*smoothstep(-.1,.9,lam);
|
|
8610
8611
|
float dark=1.-smoothstep(.02,.12,dot(vC,vec3(.2126,.7152,.0722)));
|
|
8611
8612
|
vec3 alb=max(vC,vec3(.055)*dark);
|
|
8612
|
-
vec3 col=alb*(vec3(.5,.56,.7)*
|
|
8613
|
-
float rim=pow(1.-clamp(abs(dot(
|
|
8613
|
+
vec3 col=alb*(vec3(.5,.56,.7)*light*1.05+vec3(.2,.19,.18)+uGround*(.4-.4*N.y));
|
|
8614
|
+
float rim=pow(1.-clamp(abs(dot(normalize(vN),V)),0.,1.),2.);
|
|
8614
8615
|
col+=dark*rim*(uSky*.9+alb);
|
|
8615
8616
|
vec3 tg=uGlowPos-vWP;float dg=length(tg)+.001;
|
|
8616
8617
|
float gi=uGlowI/(1.+dg*dg*.05)*(.3+.7*max(dot(N,tg/dg),0.));
|
|
8617
8618
|
col+=uGlowCol*gi*alb*1.6;
|
|
8619
|
+
// seen through: thin where the camera grazes the puff, thicker where the noise is, thinning out with age
|
|
8620
|
+
float facing=abs(dot(normalize(vN),V));
|
|
8621
|
+
float alpha=smoothstep(.0,.75,facing)*(.35+.65*smoothstep(.2,.8,n))*(1.-smoothstep(.3,1.,age))*.78;
|
|
8618
8622
|
float h=heat*(.72+.56*n)+heat*(-N.y)*.18;
|
|
8619
8623
|
if(h>.05){
|
|
8620
|
-
|
|
8621
|
-
|
|
8622
|
-
col=mix(col,fc,
|
|
8624
|
+
vec3 fc=ramp(clamp(h,0.,1.2))*(1.1+3.1*h);
|
|
8625
|
+
float hot=smoothstep(.04,.2,h);
|
|
8626
|
+
col=mix(col,fc,hot);
|
|
8627
|
+
alpha=max(alpha,hot*smoothstep(.0,.45,facing)*(1.-smoothstep(.5,1.,age)));
|
|
8623
8628
|
}
|
|
8624
8629
|
if(kind>2.5&&kind<3.5){col+=vec3(.02,.025,.03);}
|
|
8625
|
-
|
|
8630
|
+
if(alpha<.01)discard;
|
|
8631
|
+
gl_FragColor=vec4(col,alpha);
|
|
8626
8632
|
#include <tonemapping_fragment>
|
|
8627
8633
|
#include <colorspace_fragment>
|
|
8628
8634
|
}`;
|
|
@@ -8657,10 +8663,11 @@ void main(){
|
|
|
8657
8663
|
function dynamic(THREE, array, size) {
|
|
8658
8664
|
return new THREE.InstancedBufferAttribute(array, size).setUsage(THREE.DynamicDrawUsage);
|
|
8659
8665
|
}
|
|
8666
|
+
var PUFF_DETAIL = 2;
|
|
8660
8667
|
function createPuffLayer(THREE, pool, uniforms) {
|
|
8661
8668
|
const capacity = pool.capacity;
|
|
8662
8669
|
const geometry = new THREE.InstancedBufferGeometry();
|
|
8663
|
-
geometry.setAttribute("position", new THREE.IcosahedronGeometry(1,
|
|
8670
|
+
geometry.setAttribute("position", new THREE.IcosahedronGeometry(1, PUFF_DETAIL).getAttribute("position"));
|
|
8664
8671
|
const a = new Float32Array(capacity * 4);
|
|
8665
8672
|
const d = new Float32Array(capacity * 4);
|
|
8666
8673
|
const c = new Float32Array(capacity * 3);
|
|
@@ -8669,7 +8676,7 @@ void main(){
|
|
|
8669
8676
|
geometry.setAttribute("aD", attributes[1]);
|
|
8670
8677
|
geometry.setAttribute("aC", attributes[2]);
|
|
8671
8678
|
geometry.instanceCount = 0;
|
|
8672
|
-
const material = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT });
|
|
8679
|
+
const material = new THREE.ShaderMaterial({ uniforms, vertexShader: PUFF_VERTEX, fragmentShader: PUFF_FRAGMENT, transparent: true, depthWrite: false });
|
|
8673
8680
|
const mesh2 = new THREE.Mesh(geometry, material);
|
|
8674
8681
|
mesh2.name = "vfx-puffs";
|
|
8675
8682
|
mesh2.frustumCulled = false;
|
|
@@ -10242,6 +10249,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
10242
10249
|
const ordered2 = [...big, ...small];
|
|
10243
10250
|
return { physics: ordered2.slice(0, Math.max(0, count)), chips: ordered2.slice(Math.max(0, count)) };
|
|
10244
10251
|
};
|
|
10252
|
+
var POSE = new Float64Array(7);
|
|
10253
|
+
var VELOCITY = new Float64Array(6);
|
|
10254
|
+
var POSE2 = new Float64Array(7);
|
|
10245
10255
|
var BEFORE_ORDER = ["crowd", "actors"];
|
|
10246
10256
|
var AFTER_ORDER = ["contacts", "rules"];
|
|
10247
10257
|
var STEP_EPSILON = 1e-9;
|
|
@@ -10254,7 +10264,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
10254
10264
|
const phases = { crowd: [], actors: [], contacts: [], rules: [] };
|
|
10255
10265
|
let accumulator = 0;
|
|
10256
10266
|
const h = world.fixedStep;
|
|
10257
|
-
const
|
|
10267
|
+
const add3 = (phase, order2) => {
|
|
10258
10268
|
phases[order2] = [...phases[order2], phase];
|
|
10259
10269
|
return () => {
|
|
10260
10270
|
phases[order2] = phases[order2].filter((registered) => registered !== phase);
|
|
@@ -10284,7 +10294,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
10284
10294
|
frame2.alpha = 0;
|
|
10285
10295
|
run(steps, steps * h);
|
|
10286
10296
|
};
|
|
10287
|
-
return { world, frame: frame2, add:
|
|
10297
|
+
return { world, frame: frame2, add: add3, step, stepFixed };
|
|
10288
10298
|
};
|
|
10289
10299
|
var isPhysicsLoop = (value) => "frame" in value && "add" in value;
|
|
10290
10300
|
var DEFAULT_WORK_BUDGET_MS = 4;
|
|
@@ -11947,6 +11957,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
11947
11957
|
const [x, y, z, w] = r;
|
|
11948
11958
|
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
11959
|
};
|
|
11960
|
+
var HINGE_RELEASE = 40 * Math.PI / 180;
|
|
11961
|
+
var HINGE_SECONDS = 1.5;
|
|
11950
11962
|
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
11963
|
var squareBoxOf = (box) => {
|
|
11952
11964
|
const r = box.rotation;
|
|
@@ -14019,6 +14031,47 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14019
14031
|
}
|
|
14020
14032
|
};
|
|
14021
14033
|
|
|
14034
|
+
// src/merge-flush-boxes.ts
|
|
14035
|
+
var FLUSH = 1e-4;
|
|
14036
|
+
var sameTurn = (a, b) => {
|
|
14037
|
+
if (!a.rotation && !b.rotation) return true;
|
|
14038
|
+
if (!a.rotation || !b.rotation) return false;
|
|
14039
|
+
return a.rotation.every((v, i) => Math.abs(v - b.rotation[i]) < FLUSH);
|
|
14040
|
+
};
|
|
14041
|
+
var flushAxis = (a, b) => {
|
|
14042
|
+
if (!sameTurn(a, b)) return -1;
|
|
14043
|
+
let along2 = -1;
|
|
14044
|
+
for (let axis2 = 0; axis2 < 3; axis2++) {
|
|
14045
|
+
const same2 = Math.abs(a.half[axis2] - b.half[axis2]) < FLUSH && Math.abs(a.center[axis2] - b.center[axis2]) < FLUSH;
|
|
14046
|
+
if (same2) continue;
|
|
14047
|
+
if (along2 >= 0) return -1;
|
|
14048
|
+
along2 = axis2;
|
|
14049
|
+
}
|
|
14050
|
+
if (along2 < 0) return -1;
|
|
14051
|
+
return Math.abs(Math.abs(a.center[along2] - b.center[along2]) - a.half[along2] - b.half[along2]) < FLUSH ? along2 : -1;
|
|
14052
|
+
};
|
|
14053
|
+
function mergeFlushBoxes(boxes) {
|
|
14054
|
+
const out = [...boxes];
|
|
14055
|
+
for (let i = 0; i < out.length; i++) {
|
|
14056
|
+
for (let j = i + 1; j < out.length; j++) {
|
|
14057
|
+
const a = out[i];
|
|
14058
|
+
const axis2 = flushAxis(a, out[j]);
|
|
14059
|
+
if (axis2 < 0) continue;
|
|
14060
|
+
const b = out[j];
|
|
14061
|
+
const low = Math.min(a.center[axis2] - a.half[axis2], b.center[axis2] - b.half[axis2]);
|
|
14062
|
+
const high = Math.max(a.center[axis2] + a.half[axis2], b.center[axis2] + b.half[axis2]);
|
|
14063
|
+
const center = [a.center[0], a.center[1], a.center[2]];
|
|
14064
|
+
const half = [a.half[0], a.half[1], a.half[2]];
|
|
14065
|
+
center[axis2] = (low + high) / 2;
|
|
14066
|
+
half[axis2] = (high - low) / 2;
|
|
14067
|
+
out[i] = { center, half, ...a.rotation ? { rotation: a.rotation } : {} };
|
|
14068
|
+
out.splice(j, 1);
|
|
14069
|
+
j = i;
|
|
14070
|
+
}
|
|
14071
|
+
}
|
|
14072
|
+
return out;
|
|
14073
|
+
}
|
|
14074
|
+
|
|
14022
14075
|
// src/engine-pieces.ts
|
|
14023
14076
|
var GROUND_WORKER_FRAMES = 2;
|
|
14024
14077
|
var wasCoarseOf = (tile) => !tile.slab && tile.collision.length < tile.heights.length;
|
|
@@ -14056,6 +14109,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14056
14109
|
var TOPPLE = 3;
|
|
14057
14110
|
var HOLD_MARGIN = 4;
|
|
14058
14111
|
var SIDE_DEAD = 0.01;
|
|
14112
|
+
var BOX_FOOT = 0.02;
|
|
14059
14113
|
var PUSH_SPIN = 0.3;
|
|
14060
14114
|
var STEADY_TURN = 0.1;
|
|
14061
14115
|
var STEADY_SECONDS = 1.5;
|
|
@@ -14114,6 +14168,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14114
14168
|
__publicField(this, "pose", new Float64Array(7));
|
|
14115
14169
|
__publicField(this, "velocity", new Float64Array(6));
|
|
14116
14170
|
__publicField(this, "contactXYZ", new Float32Array(48));
|
|
14171
|
+
/** The pieces hung on a hinge: the fixed anchor at the screw and the joint that holds them to it. */
|
|
14172
|
+
__publicField(this, "hung", /* @__PURE__ */ new Map());
|
|
14117
14173
|
__publicField(this, "outAxis", new Float64Array(3));
|
|
14118
14174
|
__publicField(this, "wayAxis", new Float64Array(3));
|
|
14119
14175
|
/** The centre `readBack` reads into (the sweep may move it). */
|
|
@@ -14164,6 +14220,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14164
14220
|
remove(b, wakeNeighbours = true) {
|
|
14165
14221
|
const link = this.links.get(b);
|
|
14166
14222
|
if (!link) return;
|
|
14223
|
+
const held = this.hung.get(b);
|
|
14224
|
+
if (held) this.letGo(b, held);
|
|
14167
14225
|
this.world.removeBody(link.id);
|
|
14168
14226
|
if (wakeNeighbours && (b.sleeping || link.sleeping)) this.wakeAround(b, link.pos);
|
|
14169
14227
|
this.byUser.delete(link.user);
|
|
@@ -14304,6 +14362,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14304
14362
|
this.applyDueGround();
|
|
14305
14363
|
this.layBlastGround();
|
|
14306
14364
|
this.makeBodies(each);
|
|
14365
|
+
each((b) => this.hang(b));
|
|
14307
14366
|
each((b) => this.sync(b, dt, h));
|
|
14308
14367
|
if (this.schedule) this.layGroundLater(each, dt);
|
|
14309
14368
|
else this.layGround(each, dt);
|
|
@@ -14337,8 +14396,44 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14337
14396
|
this.readActive(awake);
|
|
14338
14397
|
awake.walk((b) => this.readBack(b, dt, time, this.active));
|
|
14339
14398
|
} else for (const b of list) this.readBack(b, dt, time, null);
|
|
14399
|
+
this.wearHinges(dt);
|
|
14340
14400
|
this.knock(time);
|
|
14341
14401
|
}
|
|
14402
|
+
/** 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. */
|
|
14403
|
+
hang(b) {
|
|
14404
|
+
const hinge = b.hinge;
|
|
14405
|
+
const link = this.links.get(b);
|
|
14406
|
+
if (!hinge || !link || this.hung.has(b)) return;
|
|
14407
|
+
const c = this.centre(b);
|
|
14408
|
+
const dx = c.x - hinge.point[0];
|
|
14409
|
+
const dz = c.z - hinge.point[2];
|
|
14410
|
+
const along2 = Math.hypot(dx, dz);
|
|
14411
|
+
const axis2 = along2 < 1e-3 ? [0, 0, 1] : [dz / along2, 0, -dx / along2];
|
|
14412
|
+
const anchor = this.world.createBody({ shape: { kind: "box", half: [5e-3, 5e-3, 5e-3] }, motion: "static", position: hinge.point, user: 0 });
|
|
14413
|
+
this.world.ignorePair(anchor, link.id, true);
|
|
14414
|
+
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 });
|
|
14415
|
+
this.hung.set(b, { anchor, joint });
|
|
14416
|
+
}
|
|
14417
|
+
/** The screw tears out: past `HINGE_RELEASE` of turn, or after `HINGE_SECONDS`, the piece falls free. */
|
|
14418
|
+
wearHinges(dt) {
|
|
14419
|
+
for (const [b, held] of this.hung) {
|
|
14420
|
+
const hinge = b.hinge;
|
|
14421
|
+
if (hinge) {
|
|
14422
|
+
hinge.seconds -= dt;
|
|
14423
|
+
const [x, y, z, w] = hinge.from;
|
|
14424
|
+
const q = b.root.quaternion;
|
|
14425
|
+
const turned = 2 * Math.acos(Math.min(1, Math.abs(q.x * x + q.y * y + q.z * z + q.w * w)));
|
|
14426
|
+
if (turned < HINGE_RELEASE && hinge.seconds > 0) continue;
|
|
14427
|
+
}
|
|
14428
|
+
this.letGo(b, held);
|
|
14429
|
+
}
|
|
14430
|
+
}
|
|
14431
|
+
letGo(b, held) {
|
|
14432
|
+
this.world.removeJoint(held.joint);
|
|
14433
|
+
this.world.removeBody(held.anchor);
|
|
14434
|
+
this.hung.delete(b);
|
|
14435
|
+
b.hinge = void 0;
|
|
14436
|
+
}
|
|
14342
14437
|
/** 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
14438
|
readActive(awake) {
|
|
14344
14439
|
this.active.clear();
|
|
@@ -14422,7 +14517,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14422
14517
|
return { kind: "compound", children: [{ shape: { kind: "cylinder", halfHeight: b.halfExtents[round2.axis], radius: round2.radius }, position: [0, 0, 0], rotation: rotation2 }] };
|
|
14423
14518
|
}
|
|
14424
14519
|
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 })) };
|
|
14520
|
+
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
14521
|
}
|
|
14427
14522
|
return { kind: "box", half: b.halfExtents };
|
|
14428
14523
|
}
|
|
@@ -14488,8 +14583,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14488
14583
|
return {
|
|
14489
14584
|
frictionStatic: b.friction?.static ?? MU_STATIC,
|
|
14490
14585
|
frictionDynamic: b.friction?.dynamic ?? MU_DYNAMIC,
|
|
14491
|
-
|
|
14492
|
-
restitution: b.round ? b.restitution ?? SLAM_BOUNCE : 0,
|
|
14586
|
+
restitution: b.restitution ?? SLAM_BOUNCE,
|
|
14493
14587
|
rolling: b.friction?.rolling ?? ROLLING_RESISTANCE
|
|
14494
14588
|
};
|
|
14495
14589
|
}
|
|
@@ -14734,8 +14828,16 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14734
14828
|
this.slip(b, link, false);
|
|
14735
14829
|
return;
|
|
14736
14830
|
}
|
|
14737
|
-
const c = this.centre(b);
|
|
14738
14831
|
const q = b.root.quaternion;
|
|
14832
|
+
const c = this.centre(b);
|
|
14833
|
+
let shiftX = 0, shiftY = 0, shiftZ = 0;
|
|
14834
|
+
if (b.massCentre) {
|
|
14835
|
+
this.w.set(b.massCentre[0], b.massCentre[1], b.massCentre[2]).applyQuaternion(q);
|
|
14836
|
+
shiftX = this.w.x;
|
|
14837
|
+
shiftY = this.w.y;
|
|
14838
|
+
shiftZ = this.w.z;
|
|
14839
|
+
c.add(this.w);
|
|
14840
|
+
}
|
|
14739
14841
|
let low = Infinity;
|
|
14740
14842
|
for (let i = 0; i < n; i++) low = Math.min(low, this.contactXYZ[i * 3 + 1] - c.y);
|
|
14741
14843
|
let x0 = Infinity, x1 = -Infinity, z0 = Infinity, z1 = -Infinity;
|
|
@@ -14747,6 +14849,23 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
14747
14849
|
z0 = Math.min(z0, rz);
|
|
14748
14850
|
z1 = Math.max(z1, rz);
|
|
14749
14851
|
}
|
|
14852
|
+
if (!b.contacts && !b.round && !b.apart) {
|
|
14853
|
+
const [hx, hy, hz2] = b.halfExtents;
|
|
14854
|
+
const corner = this.w;
|
|
14855
|
+
let lowest = Infinity;
|
|
14856
|
+
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);
|
|
14857
|
+
if (Math.abs(lowest - low) < BOX_FOOT) {
|
|
14858
|
+
for (let k = 0; k < 8; k++) {
|
|
14859
|
+
corner.set(k & 1 ? hx : -hx, k & 2 ? hy : -hy, k & 4 ? hz2 : -hz2).applyQuaternion(q);
|
|
14860
|
+
if (corner.y - shiftY > lowest + BOX_FOOT) continue;
|
|
14861
|
+
x0 = Math.min(x0, corner.x - shiftX);
|
|
14862
|
+
x1 = Math.max(x1, corner.x - shiftX);
|
|
14863
|
+
z0 = Math.min(z0, corner.z - shiftZ);
|
|
14864
|
+
z1 = Math.max(z1, corner.z - shiftZ);
|
|
14865
|
+
}
|
|
14866
|
+
low = Math.min(low, lowest);
|
|
14867
|
+
}
|
|
14868
|
+
}
|
|
14750
14869
|
const height = -low;
|
|
14751
14870
|
const wx = x1 - x0;
|
|
14752
14871
|
const wz = z1 - z0;
|
|
@@ -15148,7 +15267,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15148
15267
|
replaceGround(tile, made2, ix, iz, material) {
|
|
15149
15268
|
if (tile) this.world.removeBody(tile.ground);
|
|
15150
15269
|
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 });
|
|
15270
|
+
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
15271
|
}
|
|
15153
15272
|
/** 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
15273
|
layVolume(t, tile, material) {
|
|
@@ -15172,7 +15291,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15172
15291
|
}
|
|
15173
15292
|
stepBoxes(boxes) {
|
|
15174
15293
|
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]] });
|
|
15294
|
+
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
15295
|
return { kind: "compound", children };
|
|
15177
15296
|
}
|
|
15178
15297
|
/** The host's fixed boxes, one static body per object (`EngineStatics`). */
|
|
@@ -15395,6 +15514,10 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15395
15514
|
var SLIP_SPEED = 0.02;
|
|
15396
15515
|
var ROLLING_RESISTANCE2 = 0.015;
|
|
15397
15516
|
var ROUND_LYING = Math.SQRT1_2;
|
|
15517
|
+
var MIN_PIECE_HALF = 1e-3;
|
|
15518
|
+
var OWN_MIN_PIECE_HALF = 0.01;
|
|
15519
|
+
var OWN_MIN_MEASURED_HALF = 0.02;
|
|
15520
|
+
var minPieceHalf = (physics) => physics === "own" ? OWN_MIN_MEASURED_HALF : MIN_PIECE_HALF;
|
|
15398
15521
|
var SLEEP_AFTER = 0.5;
|
|
15399
15522
|
var STILL_SPEED2 = 0.12;
|
|
15400
15523
|
var STILL_SPIN2 = 0.45;
|
|
@@ -15414,6 +15537,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15414
15537
|
var TIP_LYING = 0.25;
|
|
15415
15538
|
var TIP_SECONDS = 3;
|
|
15416
15539
|
var STEP = 0.03;
|
|
15540
|
+
var WAKE_SAMPLES = 4;
|
|
15541
|
+
var WAKE_DROP = 0.05;
|
|
15417
15542
|
var WARM_SLOTS = 8 + 12 * 7;
|
|
15418
15543
|
var SOLVER_PASSES = 10;
|
|
15419
15544
|
var SIDE_BOUNCE = 0.1;
|
|
@@ -15441,8 +15566,6 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15441
15566
|
var MAX_COLLISION_STEPS = 8;
|
|
15442
15567
|
var MIN_ROUND_RADIUS = 5e-3;
|
|
15443
15568
|
var BOUNCE_MIN_SPEED = 0.1;
|
|
15444
|
-
var HINGE_RELEASE = 40 * Math.PI / 180;
|
|
15445
|
-
var HINGE_SECONDS = 1.5;
|
|
15446
15569
|
var BOX_IMPACT_SPEED = 1.5;
|
|
15447
15570
|
var KNOCK_FLAT = 0.5;
|
|
15448
15571
|
var SEPARATE_SPEED = 1.5;
|
|
@@ -15508,6 +15631,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15508
15631
|
__publicField(this, "m");
|
|
15509
15632
|
__publicField(this, "hingeM");
|
|
15510
15633
|
__publicField(this, "ax");
|
|
15634
|
+
__publicField(this, "wakeBox");
|
|
15511
15635
|
__publicField(this, "solids", []);
|
|
15512
15636
|
/** The engine stepping the pieces (`PieceSystemOptions.physics`), or null for the kit's own solver. */
|
|
15513
15637
|
__publicField(this, "engine");
|
|
@@ -15598,6 +15722,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15598
15722
|
this.m = new THREE.Matrix4();
|
|
15599
15723
|
this.hingeM = new THREE.Matrix4();
|
|
15600
15724
|
this.ax = new THREE.Vector3();
|
|
15725
|
+
this.wakeBox = new THREE.Box3();
|
|
15601
15726
|
const resolved = resolvePhysics(o.physics);
|
|
15602
15727
|
this.loop = resolved?.loop ?? null;
|
|
15603
15728
|
this.stepsItself = resolved?.stepsItself ?? false;
|
|
@@ -15762,10 +15887,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15762
15887
|
}
|
|
15763
15888
|
/**
|
|
15764
15889
|
* 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`.
|
|
15890
|
+
* 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
15891
|
*/
|
|
15767
15892
|
hinge(body, point) {
|
|
15768
|
-
if (this.engine) return;
|
|
15769
15893
|
const c = this.centerOf(body, this.p);
|
|
15770
15894
|
const q = body.root.quaternion;
|
|
15771
15895
|
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 +15908,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15784
15908
|
return existing;
|
|
15785
15909
|
}
|
|
15786
15910
|
const awake = this.awake;
|
|
15911
|
+
const least = this.engine ? MIN_PIECE_HALF : OWN_MIN_PIECE_HALF;
|
|
15787
15912
|
let asleep = false;
|
|
15788
15913
|
let inHand = false;
|
|
15789
15914
|
const body = {
|
|
@@ -15793,7 +15918,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15793
15918
|
root,
|
|
15794
15919
|
velocity: velocity ? [...velocity] : [0, 0, 0],
|
|
15795
15920
|
angularVelocity: angular ? [...angular] : [0, 0, 0],
|
|
15796
|
-
halfExtents: [Math.max(
|
|
15921
|
+
halfExtents: [Math.max(least, halfExtents[0]), Math.max(least, halfExtents[1]), Math.max(least, halfExtents[2])],
|
|
15797
15922
|
mass: Math.max(0.05, mass),
|
|
15798
15923
|
// 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
15924
|
get sleeping() {
|
|
@@ -15993,12 +16118,31 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
15993
16118
|
wakeRegion(x, z, radius) {
|
|
15994
16119
|
this.engine?.groundChanged(x, z, radius);
|
|
15995
16120
|
for (const b of this.list) {
|
|
15996
|
-
if (!b.sleeping || b.held
|
|
16121
|
+
if (!b.sleeping || b.held) continue;
|
|
16122
|
+
if (Math.hypot(b.root.position.x - x, b.root.position.z - z) > radius && !this.lostGroundIn(b, x, z, radius)) continue;
|
|
15997
16123
|
b.sleeping = false;
|
|
15998
16124
|
b.still = 0;
|
|
15999
16125
|
b.calmAt = null;
|
|
16000
16126
|
}
|
|
16001
16127
|
}
|
|
16128
|
+
/**
|
|
16129
|
+
* 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:
|
|
16130
|
+
* 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).
|
|
16131
|
+
*/
|
|
16132
|
+
lostGroundIn(b, x, z, radius) {
|
|
16133
|
+
const center = this.centerOf(b, this.ax);
|
|
16134
|
+
if (Math.hypot(center.x - x, center.z - z) > radius + Math.hypot(b.halfExtents[0], b.halfExtents[2])) return false;
|
|
16135
|
+
const box = this.wakeBox.setFromObject(b.root);
|
|
16136
|
+
for (let i = 0; i <= WAKE_SAMPLES; i++) {
|
|
16137
|
+
for (let k = 0; k <= WAKE_SAMPLES; k++) {
|
|
16138
|
+
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;
|
|
16139
|
+
if (Math.hypot(px - x, pz - z) > radius) continue;
|
|
16140
|
+
const support = Math.max(this.o.groundAt(px, pz), this.o.staticTopAt?.(px, pz, box.min.y, STEP) ?? -Infinity);
|
|
16141
|
+
if (support < box.min.y - WAKE_DROP) return true;
|
|
16142
|
+
}
|
|
16143
|
+
}
|
|
16144
|
+
return false;
|
|
16145
|
+
}
|
|
16002
16146
|
/** 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
16147
|
beginTick() {
|
|
16004
16148
|
const trail = this.trail;
|
|
@@ -16793,7 +16937,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16793
16937
|
let awake = 0;
|
|
16794
16938
|
for (const b of this.list) {
|
|
16795
16939
|
if (b.sleeping || b.held) continue;
|
|
16796
|
-
if (b.balancing && this.
|
|
16940
|
+
if (this.hasComeToRest(b) && (b.balancing || b.still >= SLEEP_AFTER && !b.hinge && !this.onSteepSupport(b))) this.sleepByBudget(b);
|
|
16797
16941
|
else awake++;
|
|
16798
16942
|
}
|
|
16799
16943
|
for (const b of this.list) {
|
|
@@ -16869,7 +17013,9 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
16869
17013
|
}
|
|
16870
17014
|
/** Sleeps sooner than it would by itself, so it answers to every point it lies on (`restPoints`). */
|
|
16871
17015
|
sleepByBudget(b) {
|
|
17016
|
+
const steady = b.steady;
|
|
16872
17017
|
this.sleep(b);
|
|
17018
|
+
b.steady = steady;
|
|
16873
17019
|
b.restPoints = this.restPointsOf(b);
|
|
16874
17020
|
}
|
|
16875
17021
|
hasComeToRest(b) {
|
|
@@ -24744,6 +24890,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
24744
24890
|
return reach2;
|
|
24745
24891
|
};
|
|
24746
24892
|
let blastTntPerJoule = TNT_PER_JOULE;
|
|
24893
|
+
let blastHasCharge = false;
|
|
24747
24894
|
let blastFireball = chargeFireball(0);
|
|
24748
24895
|
const burstFuel = (p) => {
|
|
24749
24896
|
const c = p.spec.contains;
|
|
@@ -24848,7 +24995,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
24848
24995
|
}
|
|
24849
24996
|
for (const im of [...impls.values()]) {
|
|
24850
24997
|
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 } : {} }));
|
|
24998
|
+
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
24999
|
yield "part";
|
|
24853
25000
|
}
|
|
24854
25001
|
return out;
|
|
@@ -24973,7 +25120,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
24973
25120
|
den += f;
|
|
24974
25121
|
}
|
|
24975
25122
|
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 } : {} });
|
|
25123
|
+
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
25124
|
results.set(im, res);
|
|
24978
25125
|
report(im).shelter = k;
|
|
24979
25126
|
}
|
|
@@ -25315,13 +25462,16 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
25315
25462
|
const fireball = charge?.fuel ? fuelFireball(charge.fuel) : chargeFireball(energy * tntPerJoule);
|
|
25316
25463
|
const inBlast = (fn) => {
|
|
25317
25464
|
const outer = blastTntPerJoule;
|
|
25465
|
+
const outerHasCharge = blastHasCharge;
|
|
25318
25466
|
const outerFireball = blastFireball;
|
|
25319
25467
|
blastTntPerJoule = tntPerJoule;
|
|
25468
|
+
blastHasCharge = charge?.tnt !== void 0;
|
|
25320
25469
|
blastFireball = fireball;
|
|
25321
25470
|
try {
|
|
25322
25471
|
return fn();
|
|
25323
25472
|
} finally {
|
|
25324
25473
|
blastTntPerJoule = outer;
|
|
25474
|
+
blastHasCharge = outerHasCharge;
|
|
25325
25475
|
blastFireball = outerFireball;
|
|
25326
25476
|
}
|
|
25327
25477
|
};
|
|
@@ -28719,7 +28869,6 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
28719
28869
|
var PART_BOX_MESHES = 64;
|
|
28720
28870
|
var ROUND_SAMPLES = 400;
|
|
28721
28871
|
var ROUND_SIDES = 0.12;
|
|
28722
|
-
var MIN_PIECE_HALF = 0.02;
|
|
28723
28872
|
var ROUND_SLACK = 1.12;
|
|
28724
28873
|
var RIM_POINTS = 12;
|
|
28725
28874
|
var rimPoints = (round2, half) => {
|
|
@@ -29295,7 +29444,8 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
29295
29444
|
}
|
|
29296
29445
|
if (total.isEmpty()) return { half: [0.25, 0.25, 0.25], center: new this.THREE.Vector3() };
|
|
29297
29446
|
const size = total.getSize(new this.THREE.Vector3());
|
|
29298
|
-
|
|
29447
|
+
const least = minPieceHalf(this.o.physics);
|
|
29448
|
+
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
29449
|
}
|
|
29300
29450
|
/**
|
|
29301
29451
|
* 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
|
|
@@ -30809,6 +30959,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30809
30959
|
old.halfExtents = half;
|
|
30810
30960
|
this.pieceSys.setCenter(old, center);
|
|
30811
30961
|
old.mass = Math.max(MIN_PIECE_MASS_KG, this.massOf(objectId) - (old.massOffset ?? 0));
|
|
30962
|
+
old.apart = true;
|
|
30812
30963
|
if (old.contacts || old.round) {
|
|
30813
30964
|
this.fitSurface(b, old);
|
|
30814
30965
|
if (!old.round) this.setContacts(b, old, this.meshesOf(b).filter((mv) => this.visuals.shown(mv)));
|
|
@@ -30816,6 +30967,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
30816
30967
|
if (!this.splittingAtLoad) old.sleeping = false;
|
|
30817
30968
|
} else if (kitOriginOf(b.root)?.kind === "furniture" && !this.splittingAtLoad) {
|
|
30818
30969
|
const piece = this.makePiece(objectId);
|
|
30970
|
+
piece.apart = true;
|
|
30819
30971
|
this.tipIfTopHeavy(b, true);
|
|
30820
30972
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
30821
30973
|
}
|
|
@@ -31067,6 +31219,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31067
31219
|
}
|
|
31068
31220
|
const piece = this.pieceSys.create(newId, group, half, center, this.massOf(newId), vel, ang);
|
|
31069
31221
|
nb.piece = piece;
|
|
31222
|
+
piece.apart = true;
|
|
31070
31223
|
this.fitSurface(nb, piece);
|
|
31071
31224
|
this.fitPartBoxes(nb, piece);
|
|
31072
31225
|
const resting = this.splittingAtLoad && this.pieceSys.restIfSupported(piece);
|
|
@@ -31092,6 +31245,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31092
31245
|
body.halfExtents = half;
|
|
31093
31246
|
this.pieceSys.setCenter(body, center);
|
|
31094
31247
|
body.mass = Math.max(MIN_PIECE_MASS_KG, this.massOf(objectId) - (body.massOffset ?? 0));
|
|
31248
|
+
body.apart = true;
|
|
31095
31249
|
if (!structural) {
|
|
31096
31250
|
this.fitSurface(b, body);
|
|
31097
31251
|
if (!body.round) this.setContacts(b, body, left);
|
|
@@ -31123,6 +31277,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31123
31277
|
away = hull.length >= 3 ? inside.out : null;
|
|
31124
31278
|
}
|
|
31125
31279
|
const piece = this.makePiece(objectId);
|
|
31280
|
+
(b.piece ?? piece).apart = true;
|
|
31126
31281
|
this.setContacts(b, b.piece ?? piece, left);
|
|
31127
31282
|
const loose = b.piece;
|
|
31128
31283
|
if (away && loose) {
|
|
@@ -31174,6 +31329,7 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31174
31329
|
}
|
|
31175
31330
|
if (!this.standsOn(objectId, wholeBoxes) || this.standsOn(objectId, boxes)) return false;
|
|
31176
31331
|
const piece = this.makePiece(objectId);
|
|
31332
|
+
(b.piece ?? piece).apart = true;
|
|
31177
31333
|
this.setContacts(b, b.piece ?? piece, this.meshesOf(b).filter((mv) => this.visuals.shown(mv)));
|
|
31178
31334
|
this.tipIfTopHeavy(b);
|
|
31179
31335
|
this.o.onLoosened?.(objectId, piece, "apart");
|
|
@@ -31256,6 +31412,38 @@ vec3 c=mix(uDeep,uFoam,dome>.5?.8:.65+.35*vY);float alpha=body*vA;if(alpha<.004)
|
|
|
31256
31412
|
}
|
|
31257
31413
|
body.contacts = points.length > 0 && meshes.length <= CONTACT_MESHES ? points : void 0;
|
|
31258
31414
|
body.partBoxes = boxes.length > 1 || boxes.length === 1 && isTurned(boxes[0]) ? boxes : void 0;
|
|
31415
|
+
body.massCentre = this.massCentreOf(b, body);
|
|
31416
|
+
}
|
|
31417
|
+
/** 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. */
|
|
31418
|
+
massCentreOf(b, body) {
|
|
31419
|
+
if (b.parts.size < 2) return void 0;
|
|
31420
|
+
const inv = specFrameInverse(this.THREE, b.root);
|
|
31421
|
+
const m4 = new this.THREE.Matrix4();
|
|
31422
|
+
const lb = new this.THREE.Box3();
|
|
31423
|
+
const box = new this.THREE.Box3();
|
|
31424
|
+
const middle = new this.THREE.Vector3();
|
|
31425
|
+
let weight = 0;
|
|
31426
|
+
const sum = [0, 0, 0];
|
|
31427
|
+
for (const [partId, pv] of b.parts) {
|
|
31428
|
+
const mass = pv.gone === "none" ? this.world.part(b.id, partId)?.mass ?? 0 : 0;
|
|
31429
|
+
if (mass <= 0) continue;
|
|
31430
|
+
box.makeEmpty();
|
|
31431
|
+
for (const mv of pv.meshes) {
|
|
31432
|
+
if (!this.visuals.shown(mv)) continue;
|
|
31433
|
+
mv.mesh.updateWorldMatrix(true, false);
|
|
31434
|
+
this.visuals.localBox(mv, lb);
|
|
31435
|
+
if (!lb.isEmpty()) box.union(lb.applyMatrix4(m4.multiplyMatrices(inv, mv.mesh.matrixWorld)));
|
|
31436
|
+
}
|
|
31437
|
+
if (box.isEmpty()) continue;
|
|
31438
|
+
box.getCenter(middle);
|
|
31439
|
+
sum[0] += middle.x * mass;
|
|
31440
|
+
sum[1] += middle.y * mass;
|
|
31441
|
+
sum[2] += middle.z * mass;
|
|
31442
|
+
weight += mass;
|
|
31443
|
+
}
|
|
31444
|
+
if (weight <= 0) return void 0;
|
|
31445
|
+
const [cx, cy, cz] = body.localCenter;
|
|
31446
|
+
return [sum[0] / weight - cx, sum[1] / weight - cy, sum[2] / weight - cz];
|
|
31259
31447
|
}
|
|
31260
31448
|
/** `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
31449
|
fitRanged(mv, points) {
|