@adatechnology/game-destruction-three 0.8.0 → 0.8.2
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/index.global.js +94 -10
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +86 -9
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.global.js
CHANGED
|
@@ -52,6 +52,13 @@ var GameDestructionThree = (() => {
|
|
|
52
52
|
const length = Math.hypot(direction[0], direction[1], direction[2]);
|
|
53
53
|
return { speed, direction: [direction[0] / length, direction[1] / length, direction[2] / length], distance, falloff };
|
|
54
54
|
}
|
|
55
|
+
var KIT_ORIGIN_KEY = "kitOrigin";
|
|
56
|
+
function markKitOrigin(object, origin) {
|
|
57
|
+
const node = object;
|
|
58
|
+
node.userData = node.userData ?? {};
|
|
59
|
+
node.userData[KIT_ORIGIN_KEY] = { ...origin };
|
|
60
|
+
return object;
|
|
61
|
+
}
|
|
55
62
|
|
|
56
63
|
// ../game-vfx/dist/index.js
|
|
57
64
|
var __defProp2 = Object.defineProperty;
|
|
@@ -8418,7 +8425,7 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
8418
8425
|
for (const mesh2 of anchors.meshes) mesh2.material.dispose();
|
|
8419
8426
|
anchors = void 0;
|
|
8420
8427
|
};
|
|
8421
|
-
const root = new THREE.Group();
|
|
8428
|
+
const root = markKitOrigin(new THREE.Group(), { owner: "game-vfx-three", kind: "effect" });
|
|
8422
8429
|
options.scene.add(root);
|
|
8423
8430
|
const direction = new THREE.Vector3(...options.lightDirection ?? LAB_LIGHT_DIRECTION).normalize();
|
|
8424
8431
|
const sky = hexToLinearRgb(SKY_COLOR);
|
|
@@ -10770,7 +10777,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
10770
10777
|
depthWrite: false,
|
|
10771
10778
|
polygonOffset: true,
|
|
10772
10779
|
polygonOffsetFactor: -4,
|
|
10773
|
-
polygonOffsetUnits: -4
|
|
10780
|
+
polygonOffsetUnits: -4,
|
|
10781
|
+
side: this.THREE.DoubleSide
|
|
10774
10782
|
}));
|
|
10775
10783
|
}
|
|
10776
10784
|
/** Opaque patch in the colour of what shows under a spalled coat. */
|
|
@@ -11163,6 +11171,27 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
11163
11171
|
}
|
|
11164
11172
|
addHole(mv, worldPoint, worldNormal, diameter) {
|
|
11165
11173
|
const { s, pos, quat: quat2 } = this.decalPose(mv.mesh, worldPoint, worldNormal, 25e-4);
|
|
11174
|
+
const work = mv.host ? mv.host.work : mv.work;
|
|
11175
|
+
if (work && mv.touched) {
|
|
11176
|
+
const ln = worldNormal.clone().transformDirection(this.m4.copy(mv.mesh.matrixWorld).invert()).normalize();
|
|
11177
|
+
let minDistSq = Infinity;
|
|
11178
|
+
let nearestDisp = 0;
|
|
11179
|
+
const from = mv.range ? mv.range[0] * 3 : 0;
|
|
11180
|
+
const to = mv.range ? mv.range[1] * 3 : work.length;
|
|
11181
|
+
for (let i = from; i < to; i += 3) {
|
|
11182
|
+
const dx = work[i] - pos.x;
|
|
11183
|
+
const dy = work[i + 1] - pos.y;
|
|
11184
|
+
const dz = work[i + 2] - pos.z;
|
|
11185
|
+
const d2 = dx * dx + dy * dy + dz * dz;
|
|
11186
|
+
if (d2 < minDistSq) {
|
|
11187
|
+
minDistSq = d2;
|
|
11188
|
+
nearestDisp = dx * ln.x + dy * ln.y + dz * ln.z;
|
|
11189
|
+
}
|
|
11190
|
+
}
|
|
11191
|
+
if (minDistSq < (0.06 / s) ** 2 && nearestDisp < 0) {
|
|
11192
|
+
pos.addScaledVector(ln, nearestDisp);
|
|
11193
|
+
}
|
|
11194
|
+
}
|
|
11166
11195
|
const disc = new this.THREE.Mesh(this.kit.discGeometry(), this.kit.discMaterial());
|
|
11167
11196
|
disc.position.copy(pos);
|
|
11168
11197
|
disc.quaternion.copy(quat2);
|
|
@@ -11634,7 +11663,13 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
11634
11663
|
gas: 15921906,
|
|
11635
11664
|
sap: 12098362,
|
|
11636
11665
|
acid: 10211900,
|
|
11637
|
-
blood: 9046538
|
|
11666
|
+
blood: 9046538,
|
|
11667
|
+
soda: 3808786,
|
|
11668
|
+
coffee: 3875860,
|
|
11669
|
+
beer: 14259516,
|
|
11670
|
+
milk: 16052714,
|
|
11671
|
+
wine: 7016479,
|
|
11672
|
+
juice: 15238923
|
|
11638
11673
|
};
|
|
11639
11674
|
var SMOKE_TONES = { white: 15132390, grey: 9079434, black: 2763306 };
|
|
11640
11675
|
var DEFAULT_SPEED = {
|
|
@@ -12163,13 +12198,39 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
12163
12198
|
}
|
|
12164
12199
|
case "leak": {
|
|
12165
12200
|
const key = `${ev.object}|${ev.part}`;
|
|
12201
|
+
const b = this.bounds.get(ev.object);
|
|
12202
|
+
let localPoint;
|
|
12203
|
+
let localDirection;
|
|
12204
|
+
if (b) {
|
|
12205
|
+
b.root.updateWorldMatrix(true, false);
|
|
12206
|
+
const inv = new this.THREE.Matrix4().copy(b.root.matrixWorld).invert();
|
|
12207
|
+
const lp = this.v1.set(ev.point[0], ev.point[1], ev.point[2]).applyMatrix4(inv);
|
|
12208
|
+
const ld = this.v2.set(ev.direction[0], ev.direction[1], ev.direction[2]).transformDirection(inv).normalize();
|
|
12209
|
+
localPoint = [lp.x, lp.y, lp.z];
|
|
12210
|
+
localDirection = [ld.x, ld.y, ld.z];
|
|
12211
|
+
}
|
|
12166
12212
|
const same = this.leaks.find((l) => l.object === ev.object && l.part === ev.part && Math.hypot(l.point[0] - ev.point[0], l.point[1] - ev.point[1], l.point[2] - ev.point[2]) < 0.03);
|
|
12167
12213
|
if (same) {
|
|
12168
12214
|
same.rate = ev.rate;
|
|
12169
12215
|
same.direction = ev.direction;
|
|
12216
|
+
if (localPoint) same.localPoint = localPoint;
|
|
12217
|
+
if (localDirection) same.localDirection = localDirection;
|
|
12170
12218
|
} else {
|
|
12171
12219
|
if (this.leaks.length >= 24) this.leaks.shift();
|
|
12172
|
-
this.leaks.push({
|
|
12220
|
+
this.leaks.push({
|
|
12221
|
+
object: ev.object,
|
|
12222
|
+
part: ev.part,
|
|
12223
|
+
fluid: ev.fluid,
|
|
12224
|
+
point: ev.point,
|
|
12225
|
+
direction: ev.direction,
|
|
12226
|
+
rate: ev.rate,
|
|
12227
|
+
pressurized: ev.pressurized,
|
|
12228
|
+
acc: 0,
|
|
12229
|
+
opened: this.world.part(ev.object, ev.part)?.holes.some((h) => h.through) ?? false,
|
|
12230
|
+
localPoint,
|
|
12231
|
+
localDirection,
|
|
12232
|
+
life: 0
|
|
12233
|
+
});
|
|
12173
12234
|
}
|
|
12174
12235
|
void key;
|
|
12175
12236
|
break;
|
|
@@ -12605,21 +12666,44 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
12605
12666
|
updateLeaks(dt) {
|
|
12606
12667
|
for (let i = this.leaks.length - 1; i >= 0; i--) {
|
|
12607
12668
|
const l = this.leaks[i];
|
|
12669
|
+
const b = this.bounds.get(l.object);
|
|
12608
12670
|
const ps = this.world.part(l.object, l.part);
|
|
12609
|
-
if (!ps || ps.liters === void 0 || ps.liters <=
|
|
12671
|
+
if (!b || !ps || ps.liters === void 0 || ps.liters <= 1e-4 || l.opened && !ps.holes.some((h) => h.through)) {
|
|
12610
12672
|
this.leaks.splice(i, 1);
|
|
12611
12673
|
continue;
|
|
12612
12674
|
}
|
|
12675
|
+
l.life = (l.life ?? 0) + dt;
|
|
12676
|
+
if (l.pressurized && l.life > 0.8) l.pressurized = false;
|
|
12677
|
+
if (l.lastLiters !== void 0 && Math.abs(ps.liters - l.lastLiters) < 1e-5) {
|
|
12678
|
+
l.idleSeconds = (l.idleSeconds ?? 0) + dt;
|
|
12679
|
+
if (l.idleSeconds > 0.4) {
|
|
12680
|
+
this.leaks.splice(i, 1);
|
|
12681
|
+
continue;
|
|
12682
|
+
}
|
|
12683
|
+
} else {
|
|
12684
|
+
l.idleSeconds = 0;
|
|
12685
|
+
l.lastLiters = ps.liters;
|
|
12686
|
+
}
|
|
12687
|
+
let pt = l.point;
|
|
12688
|
+
let dir = l.direction;
|
|
12689
|
+
if (l.localPoint && l.localDirection) {
|
|
12690
|
+
b.root.updateWorldMatrix(true, false);
|
|
12691
|
+
const wp = this.v1.set(l.localPoint[0], l.localPoint[1], l.localPoint[2]).applyMatrix4(b.root.matrixWorld);
|
|
12692
|
+
const wd = this.v2.set(l.localDirection[0], l.localDirection[1], l.localDirection[2]).transformDirection(b.root.matrixWorld).normalize();
|
|
12693
|
+
pt = [wp.x, wp.y, wp.z];
|
|
12694
|
+
dir = [wd.x, wd.y, wd.z];
|
|
12695
|
+
l.point = pt;
|
|
12696
|
+
l.direction = dir;
|
|
12697
|
+
}
|
|
12613
12698
|
l.acc += clamp6(20 + l.rate * 400, 15, 120) * dt;
|
|
12614
12699
|
const color = FLUID_COLORS[l.fluid] ?? 11184810;
|
|
12615
|
-
const
|
|
12616
|
-
const dl = Math.hypot(d[0], d[1], d[2]) || 1;
|
|
12700
|
+
const dl = Math.hypot(dir[0], dir[1], dir[2]) || 1;
|
|
12617
12701
|
const sp = l.pressurized ? 2.5 + this.rng() * 1.5 : 0.3 + this.rng() * 0.3;
|
|
12618
12702
|
while (l.acc >= 1) {
|
|
12619
12703
|
l.acc -= 1;
|
|
12620
|
-
const vel = [
|
|
12621
|
-
if (l.fluid === "gas") this.vfx.spawn("steam",
|
|
12622
|
-
else this.vfx.spawn("drips",
|
|
12704
|
+
const vel = [dir[0] / dl * sp + (this.rng() - 0.5) * 0.25, dir[1] / dl * sp + (this.rng() - 0.5) * 0.25, dir[2] / dl * sp + (this.rng() - 0.5) * 0.25];
|
|
12705
|
+
if (l.fluid === "gas") this.vfx.spawn("steam", pt, vel, { color, size: 0.5, alpha: 0.5 });
|
|
12706
|
+
else this.vfx.spawn("drips", pt, vel, { color, tag: this.rng() < 0.03 ? this.tagOf(l.object) : 0, owner: this.owner });
|
|
12623
12707
|
}
|
|
12624
12708
|
}
|
|
12625
12709
|
}
|