@adatechnology/game-vfx 0.16.0 → 0.17.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/dist/index.d.ts +44 -4
- package/dist/index.global.js +187 -28
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +187 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1830,6 +1830,7 @@ function createFirePool(capacity, placeholder) {
|
|
|
1830
1830
|
y: 0,
|
|
1831
1831
|
z: 0,
|
|
1832
1832
|
r: 0.6,
|
|
1833
|
+
h: 0,
|
|
1833
1834
|
r0: 0.6,
|
|
1834
1835
|
grow: 0,
|
|
1835
1836
|
life: 6,
|
|
@@ -1855,6 +1856,7 @@ function spawnFire(pool, random, init, handle) {
|
|
|
1855
1856
|
fire.y = init.y ?? 0;
|
|
1856
1857
|
fire.z = init.z ?? 0;
|
|
1857
1858
|
fire.r = init.r ?? 0.6;
|
|
1859
|
+
fire.h = init.h ?? 0;
|
|
1858
1860
|
fire.r0 = init.startRadius ?? fire.r;
|
|
1859
1861
|
fire.grow = init.grow ?? 0;
|
|
1860
1862
|
fire.life = init.life ?? 6;
|
|
@@ -1879,19 +1881,23 @@ function addFire(core, random, init, handle) {
|
|
|
1879
1881
|
core.trace?.fire?.(fire);
|
|
1880
1882
|
return fire;
|
|
1881
1883
|
}
|
|
1884
|
+
var FLAMES_PER_HEIGHT = 1.5;
|
|
1885
|
+
var SMOKE_PER_HEIGHT = 2;
|
|
1882
1886
|
function positionOf(follow) {
|
|
1883
1887
|
return "position" in follow ? follow.position : follow;
|
|
1884
1888
|
}
|
|
1889
|
+
var heightOf = (fire) => fire.h > 0 ? fire.rng.next() * fire.h : 0;
|
|
1890
|
+
var isBody = (follow) => "radius" in follow && "height" in follow;
|
|
1885
1891
|
function emitFlames(core, fire, radius, dt) {
|
|
1886
1892
|
const random = fire.rng;
|
|
1887
|
-
fire.acc += dt * fire.rate * (0.5 + radius * 0.9) * fire.fade * core.clock.lod;
|
|
1893
|
+
fire.acc += dt * fire.rate * (0.5 + radius * 0.9) * (1 + fire.h * FLAMES_PER_HEIGHT) * fire.fade * core.clock.lod;
|
|
1888
1894
|
while (fire.acc >= 1) {
|
|
1889
1895
|
fire.acc -= 1;
|
|
1890
1896
|
const angle = random.next() * Math.PI * 2;
|
|
1891
1897
|
const distance = Math.sqrt(random.next()) * radius;
|
|
1892
1898
|
addPuff(core, random, {
|
|
1893
1899
|
x: fire.x + Math.cos(angle) * distance,
|
|
1894
|
-
y: fire.y + 0.05,
|
|
1900
|
+
y: fire.y + 0.05 + heightOf(fire),
|
|
1895
1901
|
z: fire.z + Math.sin(angle) * distance,
|
|
1896
1902
|
vx: random.between(-0.2, 0.2),
|
|
1897
1903
|
vy: random.between(0.6, 1.4),
|
|
@@ -1913,12 +1919,12 @@ function emitFlames(core, fire, radius, dt) {
|
|
|
1913
1919
|
}
|
|
1914
1920
|
function emitSmoke(core, fire, radius, dt) {
|
|
1915
1921
|
const random = fire.rng;
|
|
1916
|
-
fire.smokeAcc += dt * fire.smoke * (1 + radius * 0.8) * fire.fade * core.clock.lod;
|
|
1922
|
+
fire.smokeAcc += dt * fire.smoke * (1 + radius * 0.8) * (1 + fire.h * SMOKE_PER_HEIGHT) * fire.fade * core.clock.lod;
|
|
1917
1923
|
while (fire.smokeAcc >= 1 && core.layers.smoke) {
|
|
1918
1924
|
fire.smokeAcc -= 1;
|
|
1919
1925
|
addPuff(core, random, {
|
|
1920
1926
|
x: fire.x + random.between(-radius, radius) * 0.5,
|
|
1921
|
-
y: fire.y + 0.6 + radius * 0.3,
|
|
1927
|
+
y: fire.y + fire.h + 0.6 + radius * 0.3,
|
|
1922
1928
|
z: fire.z + random.between(-radius, radius) * 0.5,
|
|
1923
1929
|
vy: random.between(0.8, 1.5),
|
|
1924
1930
|
s0: 0.25,
|
|
@@ -1940,7 +1946,7 @@ function emitEmber(core, fire, radius, dt) {
|
|
|
1940
1946
|
if (!(random.next() < dt * 6 * fire.fade && core.layers.shrapnel)) return;
|
|
1941
1947
|
addSpark(core, {
|
|
1942
1948
|
x: fire.x + random.between(-radius, radius) * 0.6,
|
|
1943
|
-
y: fire.y + 0.4,
|
|
1949
|
+
y: fire.y + 0.4 + heightOf(fire),
|
|
1944
1950
|
z: fire.z + random.between(-radius, radius) * 0.6,
|
|
1945
1951
|
vx: random.between(-0.4, 0.4),
|
|
1946
1952
|
vy: random.between(1.5, 3.2),
|
|
@@ -1964,6 +1970,10 @@ function updateFires(core, dt) {
|
|
|
1964
1970
|
fire.x = point.x + fire.fx;
|
|
1965
1971
|
fire.y = point.y + fire.fy;
|
|
1966
1972
|
fire.z = point.z + fire.fz;
|
|
1973
|
+
if (isBody(fire.follow)) {
|
|
1974
|
+
fire.r = fire.follow.radius;
|
|
1975
|
+
fire.h = fire.follow.height;
|
|
1976
|
+
}
|
|
1967
1977
|
}
|
|
1968
1978
|
const radius = fire.grow ? lerp(fire.r0, fire.r, Math.min(1, fire.t / fire.grow)) : fire.r;
|
|
1969
1979
|
fire.fade = fire.t < fire.life - 1.5 ? Math.min(1, fire.t * 3) : Math.max(0, (fire.life - fire.t) / 1.5);
|
|
@@ -2038,6 +2048,7 @@ var INDEX = { $: "index" };
|
|
|
2038
2048
|
var QUALITY = { $: "quality" };
|
|
2039
2049
|
var FRESH = { $: "fresh" };
|
|
2040
2050
|
var DIRECTION = { $: "direction" };
|
|
2051
|
+
var NORMAL = { $: "normal" };
|
|
2041
2052
|
var CAMERA_POSITION = { $: "cameraPosition" };
|
|
2042
2053
|
|
|
2043
2054
|
// src/effects/steps.ts
|
|
@@ -2593,7 +2604,7 @@ var WEAPONS = ["glock", "ak", "r870", "barrett"];
|
|
|
2593
2604
|
var TIP2 = [-0.8, 1.38, 3.4 - 0.78];
|
|
2594
2605
|
var PORT2 = [-0.76, 1.4, 3.32];
|
|
2595
2606
|
var FORWARD3 = [0, 0, -1];
|
|
2596
|
-
var
|
|
2607
|
+
var NORMAL2 = [0, 0, 1];
|
|
2597
2608
|
var WALL_Z2 = -4.45;
|
|
2598
2609
|
var SHOTS = [[0, 0.45, 0.9], [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6], [0], [0]];
|
|
2599
2610
|
var SHOT_TIME = pick(pick(SHOTS, PARAM), INDEX);
|
|
@@ -2618,8 +2629,8 @@ var MUZZLE_FLASH = {
|
|
|
2618
2629
|
set("target", [add(-0.8, rnd(-0.4, 0.4)), add(1.4, rnd(-0.3, 0.3)), WALL_Z2]),
|
|
2619
2630
|
when(
|
|
2620
2631
|
eq(PARAM, SHOTGUN),
|
|
2621
|
-
[repeat(8, call2("impact", "concrete", [add(-0.8, rnd(-0.5, 0.5)), add(1.4, rnd(-0.4, 0.4)), WALL_Z2],
|
|
2622
|
-
[call2("impact", "concrete", variable("target"),
|
|
2632
|
+
[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))],
|
|
2633
|
+
[call2("impact", "concrete", variable("target"), NORMAL2, ite(eq(PARAM, BARRETT), 2, 1))]
|
|
2623
2634
|
),
|
|
2624
2635
|
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 })])
|
|
2625
2636
|
)
|
|
@@ -3177,6 +3188,8 @@ var RainField = class {
|
|
|
3177
3188
|
__publicField(this, "puddles", WORKSHOP_PUDDLES);
|
|
3178
3189
|
/** Replaces the puddle test (a game knows its own wet spots). */
|
|
3179
3190
|
__publicField(this, "puddleAt");
|
|
3191
|
+
/** Top (world y) of the roof or slab over (x, z), `undefined` for open sky: a streak that falls under it is gone, with no splash and no ring. Unset: nothing is roofed. */
|
|
3192
|
+
__publicField(this, "coverTopAt");
|
|
3180
3193
|
}
|
|
3181
3194
|
/** `initRain` (W321): `count` streaks (thinned by the quality), each drawn at a random place in the box. */
|
|
3182
3195
|
init(count, wind) {
|
|
@@ -3222,6 +3235,13 @@ var RainField = class {
|
|
|
3222
3235
|
positions[o + 3] += slant;
|
|
3223
3236
|
positions[o + 1] -= fall;
|
|
3224
3237
|
positions[o + 4] -= fall;
|
|
3238
|
+
if (this.coverTopAt) {
|
|
3239
|
+
const top = this.coverTopAt(positions[o], positions[o + 2]);
|
|
3240
|
+
if (top !== void 0 && positions[o + 4] < top) {
|
|
3241
|
+
this.restart(o);
|
|
3242
|
+
continue;
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3225
3245
|
const ground = context.groundAt(positions[o], positions[o + 2]);
|
|
3226
3246
|
if (positions[o + 4] < ground) {
|
|
3227
3247
|
const x = positions[o];
|
|
@@ -3237,10 +3257,7 @@ var RainField = class {
|
|
|
3237
3257
|
}
|
|
3238
3258
|
}
|
|
3239
3259
|
}
|
|
3240
|
-
|
|
3241
|
-
const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
|
|
3242
|
-
const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
|
|
3243
|
-
this.set(o, nx, ny, nz);
|
|
3260
|
+
this.restart(o);
|
|
3244
3261
|
}
|
|
3245
3262
|
}
|
|
3246
3263
|
}
|
|
@@ -3248,6 +3265,13 @@ var RainField = class {
|
|
|
3248
3265
|
clear() {
|
|
3249
3266
|
this.on = false;
|
|
3250
3267
|
}
|
|
3268
|
+
restart(offset) {
|
|
3269
|
+
const { random } = this.engine;
|
|
3270
|
+
const nx = random.between(BOX_X[0], BOX_X[1]) + this.centerX;
|
|
3271
|
+
const ny = random.between(REENTRY_HEIGHT[0], REENTRY_HEIGHT[1]);
|
|
3272
|
+
const nz = random.between(BOX_Z[0], BOX_Z[1]) + this.centerZ;
|
|
3273
|
+
this.set(offset, nx, ny, nz);
|
|
3274
|
+
}
|
|
3251
3275
|
set(offset, x, y, z) {
|
|
3252
3276
|
const positions = this.positions;
|
|
3253
3277
|
positions[offset] = x;
|
|
@@ -3857,7 +3881,6 @@ var MATERIAL_EVENT_EFFECTS = [
|
|
|
3857
3881
|
];
|
|
3858
3882
|
|
|
3859
3883
|
// src/effects/events.ts
|
|
3860
|
-
var FACING5 = [0, 0, 1];
|
|
3861
3884
|
var ORIGIN2 = [0, 0, 0];
|
|
3862
3885
|
var FORWARD4 = [0, 0, -1];
|
|
3863
3886
|
var IMPACT_MATERIALS = ["concrete", "metal", "wood", "glass", "flesh", "water"];
|
|
@@ -3867,7 +3890,7 @@ var impactEffect = (material) => ({
|
|
|
3867
3890
|
team: "weapons",
|
|
3868
3891
|
budget: { particles: 40, decals: 1 },
|
|
3869
3892
|
loop: 2,
|
|
3870
|
-
timeline: [call2("impact", material, ORIGIN2,
|
|
3893
|
+
timeline: [call2("impact", material, ORIGIN2, NORMAL, 1, 0)]
|
|
3871
3894
|
});
|
|
3872
3895
|
var muzzleEffect = (weapon) => ({
|
|
3873
3896
|
id: `muzzle_${weapon}`,
|
|
@@ -4073,13 +4096,25 @@ var VIEWMODEL_EFFECTS = [MUZZLE_FLASH2, SMOKE_PUFF, BACKBLAST, FLAME_JET];
|
|
|
4073
4096
|
|
|
4074
4097
|
// src/effects/vehicles/game-effects.ts
|
|
4075
4098
|
var aliasOf = (base, id, changes) => ({ ...base, id, pageId: `vehicle:${id}`, anchor: CAR_ORIGIN2, ...changes });
|
|
4099
|
+
var BODYWORK_IMPACT = {
|
|
4100
|
+
id: "impact_bodywork",
|
|
4101
|
+
pageId: "vehicle:impact_bodywork",
|
|
4102
|
+
team: "vehicles",
|
|
4103
|
+
budget: { particles: 80, debris: 20, lights: 1 },
|
|
4104
|
+
loop: 2,
|
|
4105
|
+
timeline: [call2("bodywork_impact", [0, 0, 0], NORMAL, [variable("dx"), variable("dy"), variable("dz")], variable("bore"), variable("paint"), variable("metal"))]
|
|
4106
|
+
};
|
|
4076
4107
|
var VEHICLE_EFFECTS = [
|
|
4108
|
+
BODYWORK_IMPACT,
|
|
4077
4109
|
/** The engine on fire: `engine_smoke` at its worst condition (black smoke, flames in the hood, a light). */
|
|
4078
4110
|
aliasOf(ENGINE_SMOKE, "vehicle_fire", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 3 }, loop: 12 }),
|
|
4079
4111
|
/** The exhaust of a car under way: `engine_smoke` in the best condition, for half a second so a moving car asks again. */
|
|
4080
4112
|
aliasOf(ENGINE_SMOKE, "vehicle_exhaust", { params: { id: "condition", options: ["100", "60", "30", "10"], default: 0 }, loop: 0.5 }),
|
|
4081
|
-
/**
|
|
4082
|
-
|
|
4113
|
+
/**
|
|
4114
|
+
* A hole in a tank: the page's drips, falling from the point it is played at (the hole). No pool of its own: the pool is the liquid that came out, laid by the
|
|
4115
|
+
* host's fluid world as it leaks (it grows with the volume and spreads by the liquid's own kind), not a drawing of a size the page chose.
|
|
4116
|
+
*/
|
|
4117
|
+
aliasOf(FUEL_LEAK_ONLY, "vehicle_leak", { anchor: TANK, timeline: [] }),
|
|
4083
4118
|
/** The leak caught fire (an incendiary or tracer round, a spark, a fire near): the page's whole sequence, the fire running along the pool to the tank and the blast. */
|
|
4084
4119
|
aliasOf(FUEL_LEAK, "vehicle_leak_ignited", {})
|
|
4085
4120
|
];
|
|
@@ -4817,6 +4852,48 @@ function resolve(value, context) {
|
|
|
4817
4852
|
}
|
|
4818
4853
|
}
|
|
4819
4854
|
|
|
4855
|
+
// src/effects/builders/bodywork.ts
|
|
4856
|
+
var PISTOL_BORE = 9e-3;
|
|
4857
|
+
var BARE_STEEL = 11778236;
|
|
4858
|
+
var DEFAULT_PAINT = 9147290;
|
|
4859
|
+
var DEFAULT_DIRECTION = [0, 0, -1];
|
|
4860
|
+
var MAX_SCALE = 3;
|
|
4861
|
+
var MIN_SCALE = 0.6;
|
|
4862
|
+
function reflected(direction, normal) {
|
|
4863
|
+
const along = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
|
|
4864
|
+
const out = [direction[0] - 2 * along * normal[0], direction[1] - 2 * along * normal[1], direction[2] - 2 * along * normal[2]];
|
|
4865
|
+
const length = Math.hypot(out[0], out[1], out[2]);
|
|
4866
|
+
if (length < 1e-6 || Math.abs(along) > 0.98) return normal;
|
|
4867
|
+
return [out[0] / length, out[1] / length, out[2] / length];
|
|
4868
|
+
}
|
|
4869
|
+
var numberOr = (value, fallback2) => typeof value === "number" && Number.isFinite(value) ? value : fallback2;
|
|
4870
|
+
function bodyworkHitOf(values) {
|
|
4871
|
+
const raw = Array.isArray(values.direction) ? values.direction : [];
|
|
4872
|
+
const direction = raw.length === 3 && raw.every((entry) => typeof entry === "number" && Number.isFinite(entry)) ? [raw[0], raw[1], raw[2]] : DEFAULT_DIRECTION;
|
|
4873
|
+
return { direction, bore: numberOr(values.bore, PISTOL_BORE), paint: numberOr(values.paint, DEFAULT_PAINT), metal: numberOr(values.metal, BARE_STEEL) };
|
|
4874
|
+
}
|
|
4875
|
+
function bodyworkScale(bore) {
|
|
4876
|
+
return Math.min(MAX_SCALE, Math.max(MIN_SCALE, bore / PISTOL_BORE));
|
|
4877
|
+
}
|
|
4878
|
+
function bodyworkImpact(engine, point, normal, hit) {
|
|
4879
|
+
const scale = bodyworkScale(hit.bore);
|
|
4880
|
+
const off = reflected(hit.direction, normal);
|
|
4881
|
+
if (engine.quality < 2) {
|
|
4882
|
+
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 });
|
|
4883
|
+
engine.burst("add", 2, { p: plusScaled(point, normal, 0.01), size: [0.06 * scale, 0.12 * scale], life: 0.05, c0: 16770736, fi: 0 });
|
|
4884
|
+
engine.flash([plusScaled(point, normal, 0.15), 16760432, 1.6 * scale, 0.05, 4]);
|
|
4885
|
+
}
|
|
4886
|
+
const flakes = engine.scaled(Math.round(5 * scale));
|
|
4887
|
+
for (let index = 0; index < flakes; index++) {
|
|
4888
|
+
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 });
|
|
4889
|
+
}
|
|
4890
|
+
const slivers = engine.scaled(Math.round(2 * scale));
|
|
4891
|
+
for (let index = 0; index < slivers; index++) {
|
|
4892
|
+
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 });
|
|
4893
|
+
}
|
|
4894
|
+
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 });
|
|
4895
|
+
}
|
|
4896
|
+
|
|
4820
4897
|
// src/effects/builders/fire.ts
|
|
4821
4898
|
var UP12 = [0, 1, 0];
|
|
4822
4899
|
var ZERO = [0, 0, 0];
|
|
@@ -4971,11 +5048,12 @@ var MACROS = {
|
|
|
4971
5048
|
casing: ({ engine }, [port, type]) => casing(engine, port, type),
|
|
4972
5049
|
chips: ({ engine }, [point, direction, count, spread]) => chips(engine, point, direction, count, spread),
|
|
4973
5050
|
spark_at: ({ engine }, [point, direction, count, spread]) => sparkAt(engine, point, direction, count, spread),
|
|
4974
|
-
rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count)
|
|
5051
|
+
rust_at: ({ engine }, [point, count]) => rustAt(engine, point, count),
|
|
5052
|
+
bodywork_impact: ({ engine }, [point, normal, direction, bore, paint, metal]) => bodyworkImpact(engine, point, normal, bodyworkHitOf({ direction, bore, paint, metal }))
|
|
4975
5053
|
};
|
|
4976
5054
|
|
|
4977
5055
|
// src/effects/instance.ts
|
|
4978
|
-
var
|
|
5056
|
+
var DEFAULT_DIRECTION2 = [0, 0, -1];
|
|
4979
5057
|
var DEFAULT_NORMAL = [0, 1, 0];
|
|
4980
5058
|
var SCREEN_FIELDS = {
|
|
4981
5059
|
shake: "shake",
|
|
@@ -5044,7 +5122,7 @@ var EffectInstance = class {
|
|
|
5044
5122
|
return instance().fresh;
|
|
5045
5123
|
},
|
|
5046
5124
|
get direction() {
|
|
5047
|
-
return instance().setup.direction ??
|
|
5125
|
+
return instance().setup.direction ?? DEFAULT_DIRECTION2;
|
|
5048
5126
|
},
|
|
5049
5127
|
get normal() {
|
|
5050
5128
|
return instance().setup.normal ?? DEFAULT_NORMAL;
|
|
@@ -6841,6 +6919,71 @@ function coneDirection(random, direction, cone, out) {
|
|
|
6841
6919
|
return out;
|
|
6842
6920
|
}
|
|
6843
6921
|
|
|
6922
|
+
// src/workshop/debris-contact.ts
|
|
6923
|
+
var CELL = 0.12;
|
|
6924
|
+
var OBSTACLE_BOUNCE = 0.3;
|
|
6925
|
+
var radiusOf = (piece) => Math.max(piece.sx, piece.sz) * 0.5;
|
|
6926
|
+
var thicknessOf = (piece) => Math.min(piece.sx, piece.sy, piece.sz);
|
|
6927
|
+
var cellKey = (i, k) => (i + 4096) * 8192 + (k + 4096);
|
|
6928
|
+
var RestingGrid = class {
|
|
6929
|
+
constructor() {
|
|
6930
|
+
__publicField(this, "cells", /* @__PURE__ */ new Map());
|
|
6931
|
+
}
|
|
6932
|
+
clear() {
|
|
6933
|
+
for (const list of this.cells.values()) list.length = 0;
|
|
6934
|
+
}
|
|
6935
|
+
rebuild(pieces) {
|
|
6936
|
+
this.clear();
|
|
6937
|
+
for (const piece of pieces) {
|
|
6938
|
+
if (!piece.on || !piece.rest) continue;
|
|
6939
|
+
const key = cellKey(Math.floor(piece.x / CELL), Math.floor(piece.z / CELL));
|
|
6940
|
+
const list = this.cells.get(key);
|
|
6941
|
+
if (list) list.push(piece);
|
|
6942
|
+
else this.cells.set(key, [piece]);
|
|
6943
|
+
}
|
|
6944
|
+
}
|
|
6945
|
+
/** 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. */
|
|
6946
|
+
supportUnder(piece) {
|
|
6947
|
+
const i = Math.floor(piece.x / CELL);
|
|
6948
|
+
const k = Math.floor(piece.z / CELL);
|
|
6949
|
+
const reach = radiusOf(piece);
|
|
6950
|
+
let top = -Infinity;
|
|
6951
|
+
for (let di = -1; di <= 1; di++) {
|
|
6952
|
+
for (let dk = -1; dk <= 1; dk++) {
|
|
6953
|
+
for (const other of this.cells.get(cellKey(i + di, k + dk)) ?? []) {
|
|
6954
|
+
if (other === piece) continue;
|
|
6955
|
+
if (Math.hypot(other.x - piece.x, other.z - piece.z) > reach + radiusOf(other)) continue;
|
|
6956
|
+
const otherTop = other.y + thicknessOf(other) * 0.5;
|
|
6957
|
+
if (otherTop <= piece.y + thicknessOf(piece) * 0.5) top = Math.max(top, otherTop + thicknessOf(piece) * 0.5);
|
|
6958
|
+
}
|
|
6959
|
+
}
|
|
6960
|
+
}
|
|
6961
|
+
return top;
|
|
6962
|
+
}
|
|
6963
|
+
};
|
|
6964
|
+
function pushOutOfObstacles(piece, obstacles) {
|
|
6965
|
+
let moved = false;
|
|
6966
|
+
for (const body of obstacles) {
|
|
6967
|
+
if (piece.y < body.bottom || piece.y > body.top) continue;
|
|
6968
|
+
const dx = piece.x - body.x;
|
|
6969
|
+
const dz = piece.z - body.z;
|
|
6970
|
+
const distance = Math.hypot(dx, dz);
|
|
6971
|
+
const reach = body.radius + radiusOf(piece);
|
|
6972
|
+
if (distance >= reach) continue;
|
|
6973
|
+
const nx = distance > 1e-6 ? dx / distance : 1;
|
|
6974
|
+
const nz = distance > 1e-6 ? dz / distance : 0;
|
|
6975
|
+
piece.x = body.x + nx * reach;
|
|
6976
|
+
piece.z = body.z + nz * reach;
|
|
6977
|
+
const into = piece.vx * nx + piece.vz * nz;
|
|
6978
|
+
if (into < 0) {
|
|
6979
|
+
piece.vx -= (1 + OBSTACLE_BOUNCE) * into * nx;
|
|
6980
|
+
piece.vz -= (1 + OBSTACLE_BOUNCE) * into * nz;
|
|
6981
|
+
}
|
|
6982
|
+
moved = true;
|
|
6983
|
+
}
|
|
6984
|
+
return moved;
|
|
6985
|
+
}
|
|
6986
|
+
|
|
6844
6987
|
// src/workshop/debris.ts
|
|
6845
6988
|
var CAPACITY = 500;
|
|
6846
6989
|
var GRAVITY2 = 9.8;
|
|
@@ -6862,6 +7005,7 @@ var DebrisPool = class {
|
|
|
6862
7005
|
__publicField(this, "count", 0);
|
|
6863
7006
|
__publicField(this, "next", 0);
|
|
6864
7007
|
__publicField(this, "direction", { x: 0, y: 0, z: 0 });
|
|
7008
|
+
__publicField(this, "resting", new RestingGrid());
|
|
6865
7009
|
}
|
|
6866
7010
|
spawn(options) {
|
|
6867
7011
|
const random = this.context.random;
|
|
@@ -6899,14 +7043,21 @@ var DebrisPool = class {
|
|
|
6899
7043
|
}
|
|
6900
7044
|
update(dt) {
|
|
6901
7045
|
this.count = 0;
|
|
7046
|
+
const contacts = this.context.debrisContacts;
|
|
7047
|
+
const obstacles = contacts?.obstacles() ?? [];
|
|
7048
|
+
let moving = false;
|
|
6902
7049
|
for (const piece of this.pieces) {
|
|
6903
7050
|
if (!piece.on) continue;
|
|
6904
|
-
this.count++;
|
|
6905
7051
|
piece.life -= dt;
|
|
6906
|
-
if (piece.life <= 0)
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
7052
|
+
if (piece.life <= 0) piece.on = false;
|
|
7053
|
+
else if (!piece.rest) moving = true;
|
|
7054
|
+
}
|
|
7055
|
+
if (moving && contacts) this.resting.rebuild(this.pieces);
|
|
7056
|
+
else this.resting.clear();
|
|
7057
|
+
for (const piece of this.pieces) {
|
|
7058
|
+
if (!piece.on) continue;
|
|
7059
|
+
this.count++;
|
|
7060
|
+
if (obstacles.length > 0 && pushOutOfObstacles(piece, obstacles)) piece.rest = false;
|
|
6910
7061
|
if (!piece.rest) this.move(piece, dt);
|
|
6911
7062
|
}
|
|
6912
7063
|
}
|
|
@@ -6922,7 +7073,7 @@ var DebrisPool = class {
|
|
|
6922
7073
|
piece.rx += piece.ax * dt;
|
|
6923
7074
|
piece.ry += piece.ay * dt;
|
|
6924
7075
|
piece.rz += piece.az * dt;
|
|
6925
|
-
const groundHeight = this.context.groundAt(piece.x, piece.z) + Math.min(piece.sx, piece.sy, piece.sz) * 0.5;
|
|
7076
|
+
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));
|
|
6926
7077
|
if (piece.y >= groundHeight) return;
|
|
6927
7078
|
piece.y = groundHeight;
|
|
6928
7079
|
piece.vy *= -piece.bounce;
|
|
@@ -7560,7 +7711,6 @@ var QUALITY_MULTIPLIERS = [1, 0.5, 0.2];
|
|
|
7560
7711
|
var FIRE_FLICKER_SWAY = 0.25;
|
|
7561
7712
|
var FIRE_FLICKER_JITTER = 0.08;
|
|
7562
7713
|
var LENS_FADE = 0.16;
|
|
7563
|
-
var FLOOR_NORMAL_Y = 0.9;
|
|
7564
7714
|
function rotate2(q, v) {
|
|
7565
7715
|
const [qx, qy, qz, qw] = q;
|
|
7566
7716
|
const ix = qw * v[0] + qy * v[2] - qz * v[1];
|
|
@@ -7599,6 +7749,14 @@ var WorkshopEngine = class {
|
|
|
7599
7749
|
this.decals = new DecalPool(this.context);
|
|
7600
7750
|
this.lights = new FlashLightPool(this.context);
|
|
7601
7751
|
}
|
|
7752
|
+
/**
|
|
7753
|
+
* 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
|
|
7754
|
+
* upright bodies `obstacles` answers (the player, asked once a frame while a piece moves) stop them and push them. `null` turns it off.
|
|
7755
|
+
*/
|
|
7756
|
+
setDebrisContacts(obstacles) {
|
|
7757
|
+
if (obstacles) this.context.debrisContacts = { obstacles };
|
|
7758
|
+
else delete this.context.debrisContacts;
|
|
7759
|
+
}
|
|
7602
7760
|
get random() {
|
|
7603
7761
|
return this.context.random;
|
|
7604
7762
|
}
|
|
@@ -7690,7 +7848,7 @@ var WorkshopEngine = class {
|
|
|
7690
7848
|
const [x, y, z] = this.place([recipe[0], recipe[1], recipe[2]]);
|
|
7691
7849
|
const options = recipe[5];
|
|
7692
7850
|
const normal = options?.n ? this.turn(options.n) : void 0;
|
|
7693
|
-
const onFloor = !normal
|
|
7851
|
+
const onFloor = !normal;
|
|
7694
7852
|
args = [x, onFloor ? this.context.groundAt(x, z) : y, z, recipe[3], recipe[4], normal ? { ...options, n: normal } : options];
|
|
7695
7853
|
}
|
|
7696
7854
|
this.context.trace?.("decal", args);
|
|
@@ -7919,10 +8077,11 @@ function createVfx(options = {}) {
|
|
|
7919
8077
|
},
|
|
7920
8078
|
fire(fireOptions) {
|
|
7921
8079
|
const handle = ++handles.next;
|
|
7922
|
-
const { point, offset, seed, radius, smokeColor, ...rest } = fireOptions;
|
|
8080
|
+
const { point, offset, seed, radius, height, smokeColor, ...rest } = fireOptions;
|
|
7923
8081
|
addFire(core, streamOf(seed), {
|
|
7924
8082
|
...rest,
|
|
7925
8083
|
r: radius,
|
|
8084
|
+
...height !== void 0 ? { h: height } : {},
|
|
7926
8085
|
x: point[0],
|
|
7927
8086
|
y: point[1],
|
|
7928
8087
|
z: point[2],
|