@adatechnology/game-vfx-three 0.10.11 → 0.10.13
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
CHANGED
|
@@ -2117,6 +2117,7 @@ var GameVfxThree = (() => {
|
|
|
2117
2117
|
var QUALITY = { $: "quality" };
|
|
2118
2118
|
var FRESH = { $: "fresh" };
|
|
2119
2119
|
var DIRECTION = { $: "direction" };
|
|
2120
|
+
var NORMAL = { $: "normal" };
|
|
2120
2121
|
var CAMERA_POSITION = { $: "cameraPosition" };
|
|
2121
2122
|
var burst = (system, count, spawn2) => ({ op: "burst", system, count, spawn: spawn2 });
|
|
2122
2123
|
var spawn = (system, options) => ({ op: "spawn", system, spawn: options });
|
|
@@ -2638,7 +2639,7 @@ var GameVfxThree = (() => {
|
|
|
2638
2639
|
var TIP2 = [-0.8, 1.38, 3.4 - 0.78];
|
|
2639
2640
|
var PORT2 = [-0.76, 1.4, 3.32];
|
|
2640
2641
|
var FORWARD3 = [0, 0, -1];
|
|
2641
|
-
var
|
|
2642
|
+
var NORMAL2 = [0, 0, 1];
|
|
2642
2643
|
var WALL_Z2 = -4.45;
|
|
2643
2644
|
var SHOTS = [[0, 0.45, 0.9], [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6], [0], [0]];
|
|
2644
2645
|
var SHOT_TIME = pick(pick(SHOTS, PARAM), INDEX);
|
|
@@ -2663,8 +2664,8 @@ var GameVfxThree = (() => {
|
|
|
2663
2664
|
set("target", [add(-0.8, rnd(-0.4, 0.4)), add(1.4, rnd(-0.3, 0.3)), WALL_Z2]),
|
|
2664
2665
|
when(
|
|
2665
2666
|
eq(PARAM, SHOTGUN),
|
|
2666
|
-
[repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2],
|
|
2667
|
-
[call2("impact", "concrete", variable("target"),
|
|
2667
|
+
[repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2], NORMAL2, 0.35))],
|
|
2668
|
+
[call2("impact", "concrete", variable("target"), NORMAL2, ite(eq(PARAM, BARRETT), 2, 1))]
|
|
2668
2669
|
),
|
|
2669
2670
|
when(and(eq(PARAM, AK), eq(mod(round(mul(SHOT_TIME, 10)), 3), 0)), [spawn("streak", { p: TIP2, dir: FORWARD3, cone: 0, sp: 90, life: 0.09, len: 0.025, c0: 16752704, a: 1 })])
|
|
2670
2671
|
)
|
|
@@ -3847,7 +3848,6 @@ var GameVfxThree = (() => {
|
|
|
3847
3848
|
...DEBRIS_EFFECT_FAMILIES.flatMap((family) => [stageCrack(family), breachDust(family), collapseDust(family)]),
|
|
3848
3849
|
REBAR_EXPOSE
|
|
3849
3850
|
];
|
|
3850
|
-
var FACING5 = [0, 0, 1];
|
|
3851
3851
|
var ORIGIN2 = [0, 0, 0];
|
|
3852
3852
|
var FORWARD4 = [0, 0, -1];
|
|
3853
3853
|
var IMPACT_MATERIALS = ["concrete", "metal", "wood", "glass", "flesh", "water"];
|
|
@@ -3857,7 +3857,7 @@ var GameVfxThree = (() => {
|
|
|
3857
3857
|
team: "weapons",
|
|
3858
3858
|
budget: { particles: 40, decals: 1 },
|
|
3859
3859
|
loop: 2,
|
|
3860
|
-
timeline: [call2("impact", material2, ORIGIN2,
|
|
3860
|
+
timeline: [call2("impact", material2, ORIGIN2, NORMAL, 1, 0)]
|
|
3861
3861
|
});
|
|
3862
3862
|
var muzzleEffect = (weapon) => ({
|
|
3863
3863
|
id: `muzzle_${weapon}`,
|
|
@@ -4059,7 +4059,16 @@ var GameVfxThree = (() => {
|
|
|
4059
4059
|
};
|
|
4060
4060
|
var VIEWMODEL_EFFECTS = [MUZZLE_FLASH2, SMOKE_PUFF, BACKBLAST, FLAME_JET];
|
|
4061
4061
|
var aliasOf = (base, id, changes) => ({ ...base, id, pageId: `vehicle:${id}`, anchor: CAR_ORIGIN2, ...changes });
|
|
4062
|
+
var BODYWORK_IMPACT = {
|
|
4063
|
+
id: "impact_bodywork",
|
|
4064
|
+
pageId: "vehicle:impact_bodywork",
|
|
4065
|
+
team: "vehicles",
|
|
4066
|
+
budget: { particles: 80, debris: 20, lights: 1 },
|
|
4067
|
+
loop: 2,
|
|
4068
|
+
timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
|
|
4069
|
+
};
|
|
4062
4070
|
var VEHICLE_EFFECTS = [
|
|
4071
|
+
BODYWORK_IMPACT,
|
|
4063
4072
|
/** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
|
|
4064
4073
|
aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
|
|
4065
4074
|
/** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
|
|
@@ -4764,6 +4773,46 @@ var GameVfxThree = (() => {
|
|
|
4764
4773
|
return evaluateCall(value.$, args.map((entry) => resolve(entry, context)));
|
|
4765
4774
|
}
|
|
4766
4775
|
}
|
|
4776
|
+
var PISTOL_BORE = 9e-3;
|
|
4777
|
+
var BARE_STEEL = 11778236;
|
|
4778
|
+
var DEFAULT_PAINT = 9147290;
|
|
4779
|
+
var DEFAULT_DIRECTION = [0, 0, -1];
|
|
4780
|
+
var MAX_SCALE = 3;
|
|
4781
|
+
var MIN_SCALE = 0.6;
|
|
4782
|
+
function reflected(direction, normal) {
|
|
4783
|
+
const along = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
|
|
4784
|
+
const out = [direction[0] - 2 * along * normal[0], direction[1] - 2 * along * normal[1], direction[2] - 2 * along * normal[2]];
|
|
4785
|
+
const length = Math.hypot(out[0], out[1], out[2]);
|
|
4786
|
+
if (length < 1e-6 || Math.abs(along) > 0.98) return normal;
|
|
4787
|
+
return [out[0] / length, out[1] / length, out[2] / length];
|
|
4788
|
+
}
|
|
4789
|
+
var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
|
|
4790
|
+
function bodyworkHitOf(values) {
|
|
4791
|
+
const raw = Array.isArray(values.direction) ? values.direction : [];
|
|
4792
|
+
const direction = raw.length === 3 && raw.every((entry) => typeof entry === "number" && Number.isFinite(entry)) ? [raw[0], raw[1], raw[2]] : DEFAULT_DIRECTION;
|
|
4793
|
+
return { direction, bore: numberOr(values.bore, PISTOL_BORE), paint: numberOr(values.paint, DEFAULT_PAINT), metal: numberOr(values.metal, BARE_STEEL) };
|
|
4794
|
+
}
|
|
4795
|
+
function bodyworkScale(bore) {
|
|
4796
|
+
return Math.min(MAX_SCALE, Math.max(MIN_SCALE, bore / PISTOL_BORE));
|
|
4797
|
+
}
|
|
4798
|
+
function bodyworkImpact(engine, point, normal, hit) {
|
|
4799
|
+
const scale = bodyworkScale(hit.bore);
|
|
4800
|
+
const off = reflected(hit.direction, normal);
|
|
4801
|
+
if (engine.quality < 2) {
|
|
4802
|
+
engine.burst("streak", Math.round(14 * scale), { p: point, dir: off, cone: 0.75, sp: [4, 12], life: [0.08, 0.3], len: 0.03, c0: 16774352, c1: 16738840, g: 9.8, gnd: 2 });
|
|
4803
|
+
engine.burst("add", 2, { p: plusScaled(point, normal, 0.01), size: [0.06 * scale, 0.12 * scale], life: 0.05, c0: 16770736, fi: 0 });
|
|
4804
|
+
engine.flash([plusScaled(point, normal, 0.15), 16760432, 1.6 * scale, 0.05, 4]);
|
|
4805
|
+
}
|
|
4806
|
+
const flakes = engine.scaled(Math.round(5 * scale));
|
|
4807
|
+
for (let index = 0; index < flakes; index++) {
|
|
4808
|
+
engine.debrisPiece({ p: point, dir: normal, cone: 0.9, sp: [1.2, 3.5], size: [8e-3 * scale, 12e-4, 6e-3 * scale], k: [0.5, 1.4], c: hit.paint, life: 6, bounce: 0.2 });
|
|
4809
|
+
}
|
|
4810
|
+
const slivers = engine.scaled(Math.round(2 * scale));
|
|
4811
|
+
for (let index = 0; index < slivers; index++) {
|
|
4812
|
+
engine.debrisPiece({ p: point, dir: off, cone: 0.6, sp: [2.5, 6], size: [25e-4, 15e-4, 0.01 * scale], k: [0.6, 1.3], c: hit.metal, life: 6, bounce: 0.35 });
|
|
4813
|
+
}
|
|
4814
|
+
engine.burst("normal", Math.round(6 * scale), { p: point, dir: normal, cone: 0.7, sp: [0.4, 1.4], drag: 2.5, life: [0.4, 0.9], size: [0.03, 0.07], grow: 3, c0: hit.paint, a: 0.45, g: -0.05 });
|
|
4815
|
+
}
|
|
4767
4816
|
var UP12 = [0, 1, 0];
|
|
4768
4817
|
var ZERO = [0, 0, 0];
|
|
4769
4818
|
var FULL_TURN_DRAWN = 6.283;
|
|
@@ -4913,9 +4962,10 @@ var GameVfxThree = (() => {
|
|
|
4913
4962
|
casing: ({ engine }, [port, type]) => casing(engine, port, type),
|
|
4914
4963
|
chips: ({ engine }, [point, direction, count, spread]) => chips(engine, point, direction, count, spread),
|
|
4915
4964
|
spark_at: ({ engine }, [point, direction, count, spread]) => sparkAt(engine, point, direction, count, spread),
|
|
4916
|
-
rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count)
|
|
4965
|
+
rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count),
|
|
4966
|
+
bodywork_impact: ({ engine }, [point, normal, direction, bore, paint2, metal]) => bodyworkImpact(engine, point, normal, bodyworkHitOf({ direction, bore, paint: paint2, metal }))
|
|
4917
4967
|
};
|
|
4918
|
-
var
|
|
4968
|
+
var DEFAULT_DIRECTION2 = [0, 0, -1];
|
|
4919
4969
|
var DEFAULT_NORMAL = [0, 1, 0];
|
|
4920
4970
|
var SCREEN_FIELDS = {
|
|
4921
4971
|
shake: "shake",
|
|
@@ -4982,7 +5032,7 @@ var GameVfxThree = (() => {
|
|
|
4982
5032
|
return instance().fresh;
|
|
4983
5033
|
},
|
|
4984
5034
|
get direction() {
|
|
4985
|
-
return instance().setup.direction ??
|
|
5035
|
+
return instance().setup.direction ?? DEFAULT_DIRECTION2;
|
|
4986
5036
|
},
|
|
4987
5037
|
get normal() {
|
|
4988
5038
|
return instance().setup.normal ?? DEFAULT_NORMAL;
|
|
@@ -6740,6 +6790,69 @@ var GameVfxThree = (() => {
|
|
|
6740
6790
|
addScaled(out, tangentB, sinTilt * Math.sin(phase));
|
|
6741
6791
|
return out;
|
|
6742
6792
|
}
|
|
6793
|
+
var CELL = 0.12;
|
|
6794
|
+
var OBSTACLE_BOUNCE = 0.3;
|
|
6795
|
+
var radiusOf = (piece) => Math.max(piece.sx, piece.sz) * 0.5;
|
|
6796
|
+
var thicknessOf = (piece) => Math.min(piece.sx, piece.sy, piece.sz);
|
|
6797
|
+
var cellKey = (i, k) => (i + 4096) * 8192 + (k + 4096);
|
|
6798
|
+
var RestingGrid = class {
|
|
6799
|
+
constructor() {
|
|
6800
|
+
__publicField(this, "cells", /* @__PURE__ */ new Map());
|
|
6801
|
+
}
|
|
6802
|
+
clear() {
|
|
6803
|
+
for (const list of this.cells.values()) list.length = 0;
|
|
6804
|
+
}
|
|
6805
|
+
rebuild(pieces) {
|
|
6806
|
+
this.clear();
|
|
6807
|
+
for (const piece of pieces) {
|
|
6808
|
+
if (!piece.on || !piece.rest) continue;
|
|
6809
|
+
const key = cellKey(Math.floor(piece.x / CELL), Math.floor(piece.z / CELL));
|
|
6810
|
+
const list = this.cells.get(key);
|
|
6811
|
+
if (list) list.push(piece);
|
|
6812
|
+
else this.cells.set(key, [piece]);
|
|
6813
|
+
}
|
|
6814
|
+
}
|
|
6815
|
+
/** The height a piece at `piece`'s place lands at on the pieces under it (the top of the highest one it overlaps), or `-Infinity` over none. */
|
|
6816
|
+
supportUnder(piece) {
|
|
6817
|
+
const i = Math.floor(piece.x / CELL);
|
|
6818
|
+
const k = Math.floor(piece.z / CELL);
|
|
6819
|
+
const reach = radiusOf(piece);
|
|
6820
|
+
let top = -Infinity;
|
|
6821
|
+
for (let di = -1; di <= 1; di++) {
|
|
6822
|
+
for (let dk = -1; dk <= 1; dk++) {
|
|
6823
|
+
for (const other of this.cells.get(cellKey(i + di, k + dk)) ?? []) {
|
|
6824
|
+
if (other === piece) continue;
|
|
6825
|
+
if (Math.hypot(other.x - piece.x, other.z - piece.z) > reach + radiusOf(other)) continue;
|
|
6826
|
+
const otherTop = other.y + thicknessOf(other) * 0.5;
|
|
6827
|
+
if (otherTop <= piece.y + thicknessOf(piece) * 0.5) top = Math.max(top, otherTop + thicknessOf(piece) * 0.5);
|
|
6828
|
+
}
|
|
6829
|
+
}
|
|
6830
|
+
}
|
|
6831
|
+
return top;
|
|
6832
|
+
}
|
|
6833
|
+
};
|
|
6834
|
+
function pushOutOfObstacles(piece, obstacles) {
|
|
6835
|
+
let moved = false;
|
|
6836
|
+
for (const body of obstacles) {
|
|
6837
|
+
if (piece.y < body.bottom || piece.y > body.top) continue;
|
|
6838
|
+
const dx = piece.x - body.x;
|
|
6839
|
+
const dz = piece.z - body.z;
|
|
6840
|
+
const distance = Math.hypot(dx, dz);
|
|
6841
|
+
const reach = body.radius + radiusOf(piece);
|
|
6842
|
+
if (distance >= reach) continue;
|
|
6843
|
+
const nx = distance > 1e-6 ? dx / distance : 1;
|
|
6844
|
+
const nz = distance > 1e-6 ? dz / distance : 0;
|
|
6845
|
+
piece.x = body.x + nx * reach;
|
|
6846
|
+
piece.z = body.z + nz * reach;
|
|
6847
|
+
const into = piece.vx * nx + piece.vz * nz;
|
|
6848
|
+
if (into < 0) {
|
|
6849
|
+
piece.vx -= (1 + OBSTACLE_BOUNCE) * into * nx;
|
|
6850
|
+
piece.vz -= (1 + OBSTACLE_BOUNCE) * into * nz;
|
|
6851
|
+
}
|
|
6852
|
+
moved = true;
|
|
6853
|
+
}
|
|
6854
|
+
return moved;
|
|
6855
|
+
}
|
|
6743
6856
|
var CAPACITY = 500;
|
|
6744
6857
|
var GRAVITY2 = 9.8;
|
|
6745
6858
|
var QUARTER_TURN4 = 1.5708;
|
|
@@ -6760,6 +6873,7 @@ var GameVfxThree = (() => {
|
|
|
6760
6873
|
__publicField(this, "count", 0);
|
|
6761
6874
|
__publicField(this, "next", 0);
|
|
6762
6875
|
__publicField(this, "direction", { x: 0, y: 0, z: 0 });
|
|
6876
|
+
__publicField(this, "resting", new RestingGrid());
|
|
6763
6877
|
}
|
|
6764
6878
|
spawn(options) {
|
|
6765
6879
|
const random = this.context.random;
|
|
@@ -6797,14 +6911,21 @@ var GameVfxThree = (() => {
|
|
|
6797
6911
|
}
|
|
6798
6912
|
update(dt) {
|
|
6799
6913
|
this.count = 0;
|
|
6914
|
+
const contacts = this.context.debrisContacts;
|
|
6915
|
+
const obstacles = contacts?.obstacles() ?? [];
|
|
6916
|
+
let moving = false;
|
|
6800
6917
|
for (const piece of this.pieces) {
|
|
6801
6918
|
if (!piece.on) continue;
|
|
6802
|
-
this.count++;
|
|
6803
6919
|
piece.life -= dt;
|
|
6804
|
-
if (piece.life <= 0)
|
|
6805
|
-
|
|
6806
|
-
|
|
6807
|
-
|
|
6920
|
+
if (piece.life <= 0) piece.on = false;
|
|
6921
|
+
else if (!piece.rest) moving = true;
|
|
6922
|
+
}
|
|
6923
|
+
if (moving && contacts) this.resting.rebuild(this.pieces);
|
|
6924
|
+
else this.resting.clear();
|
|
6925
|
+
for (const piece of this.pieces) {
|
|
6926
|
+
if (!piece.on) continue;
|
|
6927
|
+
this.count++;
|
|
6928
|
+
if (obstacles.length > 0 && pushOutOfObstacles(piece, obstacles)) piece.rest = false;
|
|
6808
6929
|
if (!piece.rest) this.move(piece, dt);
|
|
6809
6930
|
}
|
|
6810
6931
|
}
|
|
@@ -6820,7 +6941,7 @@ var GameVfxThree = (() => {
|
|
|
6820
6941
|
piece.rx += piece.ax * dt;
|
|
6821
6942
|
piece.ry += piece.ay * dt;
|
|
6822
6943
|
piece.rz += piece.az * dt;
|
|
6823
|
-
const groundHeight = this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5;
|
|
6944
|
+
const groundHeight = Math.max(this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5, this.resting.supportUnder(piece));
|
|
6824
6945
|
if (piece.y >= groundHeight) return;
|
|
6825
6946
|
piece.y = groundHeight;
|
|
6826
6947
|
piece.vy *= -piece.bounce;
|
|
@@ -7442,7 +7563,6 @@ var GameVfxThree = (() => {
|
|
|
7442
7563
|
var FIRE_FLICKER_SWAY = 0.25;
|
|
7443
7564
|
var FIRE_FLICKER_JITTER = 0.08;
|
|
7444
7565
|
var LENS_FADE = 0.16;
|
|
7445
|
-
var FLOOR_NORMAL_Y = 0.9;
|
|
7446
7566
|
function rotate2(q, v) {
|
|
7447
7567
|
const [qx, qy, qz, qw] = q;
|
|
7448
7568
|
const ix = qw * v[0] + qy * v[2] - qz * v[1];
|
|
@@ -7480,6 +7600,14 @@ var GameVfxThree = (() => {
|
|
|
7480
7600
|
this.decals = new DecalPool(this.context);
|
|
7481
7601
|
this.lights = new FlashLightPool(this.context);
|
|
7482
7602
|
}
|
|
7603
|
+
/**
|
|
7604
|
+
* Turns on the touch of the debris pieces (a game's world; the Workshop page's recording has none): they pile on the pieces at rest under them, and the
|
|
7605
|
+
* upright bodies `obstacles` answers (the player, asked once a frame while a piece moves) stop them and push them. `null` turns it off.
|
|
7606
|
+
*/
|
|
7607
|
+
setDebrisContacts(obstacles) {
|
|
7608
|
+
if (obstacles) this.context.debrisContacts = { obstacles };
|
|
7609
|
+
else delete this.context.debrisContacts;
|
|
7610
|
+
}
|
|
7483
7611
|
get random() {
|
|
7484
7612
|
return this.context.random;
|
|
7485
7613
|
}
|
|
@@ -7571,7 +7699,7 @@ var GameVfxThree = (() => {
|
|
|
7571
7699
|
const [x, y, z] = this.place([recipe[0], recipe[1], recipe[2]]);
|
|
7572
7700
|
const options = recipe[5];
|
|
7573
7701
|
const normal = options?.n ? this.turn(options.n) : void 0;
|
|
7574
|
-
const onFloor = !normal
|
|
7702
|
+
const onFloor = !normal;
|
|
7575
7703
|
args = [x, onFloor ? this.context.groundAt(x, z) : y, z, recipe[3], recipe[4], normal ? { ...options, n: normal } : options];
|
|
7576
7704
|
}
|
|
7577
7705
|
this.context.trace?.("decal", args);
|
|
@@ -9838,8 +9966,48 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9838
9966
|
}
|
|
9839
9967
|
};
|
|
9840
9968
|
}
|
|
9841
|
-
var
|
|
9842
|
-
var
|
|
9969
|
+
var REST_STEP = 15e-4;
|
|
9970
|
+
var REST_TRIES = 8;
|
|
9971
|
+
var SAME_NORMAL = 0.9995;
|
|
9972
|
+
var restBox = () => ({ c: new Float64Array(3), axes: new Float64Array(9), half: new Float64Array(3), ext: new Float64Array(3) });
|
|
9973
|
+
function boxOf(piece, out) {
|
|
9974
|
+
const cx = Math.cos(piece.rx), sx = Math.sin(piece.rx), cy = Math.cos(piece.ry), sy = Math.sin(piece.ry), cz = Math.cos(piece.rz), sz = Math.sin(piece.rz);
|
|
9975
|
+
const a = out.axes;
|
|
9976
|
+
a[0] = cy * cz;
|
|
9977
|
+
a[1] = sx * sy * cz + cx * sz;
|
|
9978
|
+
a[2] = sx * sz - cx * sy * cz;
|
|
9979
|
+
a[3] = -cy * sz;
|
|
9980
|
+
a[4] = cx * cz - sx * sy * sz;
|
|
9981
|
+
a[5] = cx * sy * sz + sx * cz;
|
|
9982
|
+
a[6] = sy;
|
|
9983
|
+
a[7] = -sx * cy;
|
|
9984
|
+
a[8] = cx * cy;
|
|
9985
|
+
out.half[0] = piece.sx / 2;
|
|
9986
|
+
out.half[1] = piece.sy / 2;
|
|
9987
|
+
out.half[2] = piece.sz / 2;
|
|
9988
|
+
out.c[0] = piece.x;
|
|
9989
|
+
out.c[1] = piece.y;
|
|
9990
|
+
out.c[2] = piece.z;
|
|
9991
|
+
for (let w = 0; w < 3; w++) out.ext[w] = Math.abs(a[w]) * out.half[0] + Math.abs(a[3 + w]) * out.half[1] + Math.abs(a[6 + w]) * out.half[2];
|
|
9992
|
+
}
|
|
9993
|
+
function sharedPlane(a, b, push) {
|
|
9994
|
+
for (let w = 0; w < 3; w++) if (Math.abs(a.c[w] - b.c[w]) >= a.ext[w] + b.ext[w] + REST_STEP) return false;
|
|
9995
|
+
for (let i = 0; i < 3; i++) for (let j = 0; j < 3; j++) {
|
|
9996
|
+
const ax = a.axes[3 * i], ay = a.axes[3 * i + 1], az = a.axes[3 * i + 2];
|
|
9997
|
+
const dot = ax * b.axes[3 * j] + ay * b.axes[3 * j + 1] + az * b.axes[3 * j + 2];
|
|
9998
|
+
if (Math.abs(dot) < SAME_NORMAL) continue;
|
|
9999
|
+
const ca = ax * a.c[0] + ay * a.c[1] + az * a.c[2];
|
|
10000
|
+
const cb = ax * b.c[0] + ay * b.c[1] + az * b.c[2];
|
|
10001
|
+
for (let side = -1; side <= 1; side += 2) {
|
|
10002
|
+
if (Math.abs(ca + side * a.half[i] - (cb + side * b.half[j])) >= REST_STEP * 0.75) continue;
|
|
10003
|
+
push[0] = ax * side;
|
|
10004
|
+
push[1] = ay * side;
|
|
10005
|
+
push[2] = az * side;
|
|
10006
|
+
return true;
|
|
10007
|
+
}
|
|
10008
|
+
}
|
|
10009
|
+
return false;
|
|
10010
|
+
}
|
|
9843
10011
|
function debrisLayer(THREE, pool) {
|
|
9844
10012
|
const geometry = new THREE.BoxGeometry(1, 1, 1);
|
|
9845
10013
|
const material2 = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.45, metalness: 0.25, flatShading: true });
|
|
@@ -9854,6 +10022,36 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9854
10022
|
const matrix = new THREE.Matrix4();
|
|
9855
10023
|
const colour = new THREE.Color();
|
|
9856
10024
|
const hidden = new THREE.Matrix4().makeScale(0, 0, 0);
|
|
10025
|
+
const offset = new Float64Array(DEBRIS_CAPACITY * 3);
|
|
10026
|
+
const settled = new Uint8Array(DEBRIS_CAPACITY);
|
|
10027
|
+
const boxes = Array.from({ length: DEBRIS_CAPACITY }, restBox);
|
|
10028
|
+
const push = new Float64Array(3);
|
|
10029
|
+
const settle = (index) => {
|
|
10030
|
+
const box = boxes[index];
|
|
10031
|
+
boxOf(pool.pieces[index], box);
|
|
10032
|
+
let dx = 0, dy = 0, dz = 0;
|
|
10033
|
+
for (let tries = 0; tries < REST_TRIES; tries++) {
|
|
10034
|
+
let clash = false;
|
|
10035
|
+
for (let other = 0; other < DEBRIS_CAPACITY && !clash; other++) {
|
|
10036
|
+
if (other === index || !settled[other]) continue;
|
|
10037
|
+
if (!sharedPlane(box, boxes[other], push)) continue;
|
|
10038
|
+
clash = true;
|
|
10039
|
+
const up = Math.abs(push[1]) > 0.7;
|
|
10040
|
+
const ux = up ? 0 : push[0], uy = up ? 1 : push[1], uz = up ? 0 : push[2];
|
|
10041
|
+
dx += ux * REST_STEP;
|
|
10042
|
+
dy += uy * REST_STEP;
|
|
10043
|
+
dz += uz * REST_STEP;
|
|
10044
|
+
box.c[0] = box.c[0] + ux * REST_STEP;
|
|
10045
|
+
box.c[1] = box.c[1] + uy * REST_STEP;
|
|
10046
|
+
box.c[2] = box.c[2] + uz * REST_STEP;
|
|
10047
|
+
}
|
|
10048
|
+
if (!clash) break;
|
|
10049
|
+
}
|
|
10050
|
+
offset[3 * index] = dx;
|
|
10051
|
+
offset[3 * index + 1] = dy;
|
|
10052
|
+
offset[3 * index + 2] = dz;
|
|
10053
|
+
settled[index] = 1;
|
|
10054
|
+
};
|
|
9857
10055
|
for (let index = 0; index < DEBRIS_CAPACITY; index++) mesh2.setMatrixAt(index, hidden);
|
|
9858
10056
|
mesh2.setColorAt(0, colour.setHex(16777215));
|
|
9859
10057
|
return {
|
|
@@ -9862,16 +10060,18 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
|
|
|
9862
10060
|
let drawn = false;
|
|
9863
10061
|
for (let index = 0; index < DEBRIS_CAPACITY; index++) {
|
|
9864
10062
|
const piece = pool.pieces[index];
|
|
10063
|
+
if (!piece.on || !piece.rest) settled[index] = 0;
|
|
9865
10064
|
if (!piece.on) {
|
|
9866
10065
|
mesh2.setMatrixAt(index, hidden);
|
|
9867
10066
|
continue;
|
|
9868
10067
|
}
|
|
10068
|
+
if (piece.rest && !settled[index]) settle(index);
|
|
9869
10069
|
drawn = true;
|
|
9870
10070
|
const shrink = Math.min(1, piece.life / FADE_SECONDS2);
|
|
9871
10071
|
euler.set(piece.rx, piece.ry, piece.rz);
|
|
9872
10072
|
quaternion.setFromEuler(euler);
|
|
9873
|
-
const
|
|
9874
|
-
matrix.compose(position.set(piece.x, piece.y +
|
|
10073
|
+
const off = piece.rest ? 3 * index : -1;
|
|
10074
|
+
matrix.compose(position.set(piece.x + (off >= 0 ? offset[off] : 0), piece.y + (off >= 0 ? offset[off + 1] : 0), piece.z + (off >= 0 ? offset[off + 2] : 0)), quaternion, scale.set(piece.sx * shrink, piece.sy * shrink, piece.sz * shrink));
|
|
9875
10075
|
mesh2.setMatrixAt(index, matrix);
|
|
9876
10076
|
mesh2.setColorAt(index, colour.setHex(piece.color));
|
|
9877
10077
|
}
|