@adatechnology/game-vfx 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/index.d.ts +113 -95
- package/dist/index.global.js +94 -7
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +94 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1395,8 +1395,61 @@ function streamFor(eventSeed) {
|
|
|
1395
1395
|
return lehmer(mixEventSeed(eventSeed));
|
|
1396
1396
|
}
|
|
1397
1397
|
|
|
1398
|
-
// src/
|
|
1398
|
+
// src/solids.ts
|
|
1399
1399
|
var SKIN = 5e-3;
|
|
1400
|
+
var Solids = class {
|
|
1401
|
+
constructor() {
|
|
1402
|
+
__publicField(this, "queries", /* @__PURE__ */ new Map());
|
|
1403
|
+
__publicField(this, "list", []);
|
|
1404
|
+
__publicField(this, "hit", { x: 0, y: 0, z: 0, nx: 0, ny: 0, nz: 0 });
|
|
1405
|
+
}
|
|
1406
|
+
get empty() {
|
|
1407
|
+
return this.list.length === 0;
|
|
1408
|
+
}
|
|
1409
|
+
/** Declares or (with `null`) ends the solids `id` answers for. */
|
|
1410
|
+
set(id, query2) {
|
|
1411
|
+
if (query2) this.queries.set(id, query2);
|
|
1412
|
+
else this.queries.delete(id);
|
|
1413
|
+
this.list = [...this.queries.values()];
|
|
1414
|
+
}
|
|
1415
|
+
clear() {
|
|
1416
|
+
this.queries.clear();
|
|
1417
|
+
this.list = [];
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* Stops a step that goes into a solid: `out` gets the nearest hit, put back `pad` metres off the surface (never behind where the step began) and
|
|
1421
|
+
* the surface's normal. Answers whether the step was stopped.
|
|
1422
|
+
*/
|
|
1423
|
+
stop(move, pad, out) {
|
|
1424
|
+
const dx = move.x1 - move.x0;
|
|
1425
|
+
const dy = move.y1 - move.y0;
|
|
1426
|
+
const dz = move.z1 - move.z0;
|
|
1427
|
+
const length = Math.hypot(dx, dy, dz);
|
|
1428
|
+
if (!(length > 0)) return false;
|
|
1429
|
+
let nearest = Infinity;
|
|
1430
|
+
for (const query2 of this.list) {
|
|
1431
|
+
if (!query2(move, this.hit)) continue;
|
|
1432
|
+
const reached = ((this.hit.x - move.x0) * dx + (this.hit.y - move.y0) * dy + (this.hit.z - move.z0) * dz) / length;
|
|
1433
|
+
if (reached >= nearest) continue;
|
|
1434
|
+
nearest = reached;
|
|
1435
|
+
out.x = this.hit.x;
|
|
1436
|
+
out.y = this.hit.y;
|
|
1437
|
+
out.z = this.hit.z;
|
|
1438
|
+
out.nx = this.hit.nx;
|
|
1439
|
+
out.ny = this.hit.ny;
|
|
1440
|
+
out.nz = this.hit.nz;
|
|
1441
|
+
}
|
|
1442
|
+
if (nearest === Infinity) return false;
|
|
1443
|
+
const back = Math.min(Math.max(pad, 0) + SKIN, Math.max(nearest, 0));
|
|
1444
|
+
out.x -= dx / length * back;
|
|
1445
|
+
out.y -= dy / length * back;
|
|
1446
|
+
out.z -= dz / length * back;
|
|
1447
|
+
return true;
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
// src/enclosures.ts
|
|
1452
|
+
var SKIN2 = 5e-3;
|
|
1400
1453
|
var MAX_PAD = 0.45;
|
|
1401
1454
|
function rotation(q) {
|
|
1402
1455
|
const [x, y, z, w] = q ?? [0, 0, 0, 1];
|
|
@@ -1428,10 +1481,15 @@ var Enclosures = class {
|
|
|
1428
1481
|
__publicField(this, "q", new Float64Array(3));
|
|
1429
1482
|
__publicField(this, "h", new Float64Array(3));
|
|
1430
1483
|
__publicField(this, "move", { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 });
|
|
1484
|
+
__publicField(this, "solids", new Solids());
|
|
1431
1485
|
this.random = lehmer(seed);
|
|
1432
1486
|
}
|
|
1433
1487
|
get empty() {
|
|
1434
|
-
return this.list.length === 0;
|
|
1488
|
+
return this.list.length === 0 && this.solids.empty;
|
|
1489
|
+
}
|
|
1490
|
+
/** Declares or (with `null`) ends the host solids `id` answers for (a destruction world's walls): what is carried stops at them and passes only their holes. */
|
|
1491
|
+
solid(id, query2) {
|
|
1492
|
+
this.solids.set(id, query2);
|
|
1435
1493
|
}
|
|
1436
1494
|
get size() {
|
|
1437
1495
|
return this.list.length;
|
|
@@ -1514,6 +1572,10 @@ var Enclosures = class {
|
|
|
1514
1572
|
return this.confineMove(move, dt);
|
|
1515
1573
|
}
|
|
1516
1574
|
confineMove(move, dt) {
|
|
1575
|
+
if (this.confineSpaces(move, dt)) return true;
|
|
1576
|
+
return !this.solids.empty && this.solids.stop(move, Math.min(Math.max(0, move.pad), MAX_PAD), this.out);
|
|
1577
|
+
}
|
|
1578
|
+
confineSpaces(move, dt) {
|
|
1517
1579
|
const list = this.list;
|
|
1518
1580
|
if (list.length === 0) return false;
|
|
1519
1581
|
const { x0, y0, z0, x1, y1, z1 } = move;
|
|
@@ -1554,7 +1616,7 @@ var Enclosures = class {
|
|
|
1554
1616
|
}
|
|
1555
1617
|
}
|
|
1556
1618
|
sign = l1[axis2] < 0 ? -1 : 1;
|
|
1557
|
-
for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] -
|
|
1619
|
+
for (let a = 0; a < 3; a++) l1[a] = Math.min(h[a] - SKIN2, Math.max(-(h[a] - SKIN2), l1[a]));
|
|
1558
1620
|
sign = -sign;
|
|
1559
1621
|
} else {
|
|
1560
1622
|
const padded0 = Math.abs(l0[0]) <= s.hx + p && Math.abs(l0[1]) <= s.hy + p && Math.abs(l0[2]) <= s.hz + p;
|
|
@@ -1571,7 +1633,7 @@ var Enclosures = class {
|
|
|
1571
1633
|
}
|
|
1572
1634
|
}
|
|
1573
1635
|
sign = l0[axis2] < 0 ? -1 : 1;
|
|
1574
|
-
l1[axis2] = sign * (h[axis2] + bound +
|
|
1636
|
+
l1[axis2] = sign * (h[axis2] + bound + SKIN2);
|
|
1575
1637
|
}
|
|
1576
1638
|
const r = s.r;
|
|
1577
1639
|
const out = this.out;
|
|
@@ -5742,6 +5804,24 @@ function composeFlash(context) {
|
|
|
5742
5804
|
screen2.flashDecay = 0.5;
|
|
5743
5805
|
}
|
|
5744
5806
|
}
|
|
5807
|
+
var BIRTH = { x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0, pad: 0 };
|
|
5808
|
+
function bornFrom(core, puff3, ox, oy, oz) {
|
|
5809
|
+
const confiner = core.confiner;
|
|
5810
|
+
if (confiner.empty) return;
|
|
5811
|
+
BIRTH.x0 = ox;
|
|
5812
|
+
BIRTH.y0 = oy;
|
|
5813
|
+
BIRTH.z0 = oz;
|
|
5814
|
+
BIRTH.x1 = puff3.x;
|
|
5815
|
+
BIRTH.y1 = puff3.y;
|
|
5816
|
+
BIRTH.z1 = puff3.z;
|
|
5817
|
+
BIRTH.pad = puff3.s0 * PAD_OF_SIZE;
|
|
5818
|
+
if (!confiner.confineMove(BIRTH, 0)) return;
|
|
5819
|
+
const out = confiner.out;
|
|
5820
|
+
puff3.x = out.x;
|
|
5821
|
+
puff3.y = out.y;
|
|
5822
|
+
puff3.z = out.z;
|
|
5823
|
+
slideInto(out, puff3);
|
|
5824
|
+
}
|
|
5745
5825
|
function composeFireballs(context) {
|
|
5746
5826
|
const { core, def, random, x, y, z, size, scale, direction } = context;
|
|
5747
5827
|
if (!core.layers.fire || !def.fireballs) return;
|
|
@@ -5758,7 +5838,7 @@ function composeFireballs(context) {
|
|
|
5758
5838
|
const life = random.between(def.smoke.life * 0.7, def.smoke.life);
|
|
5759
5839
|
const h0 = random.between(1.05, 1.35) * heat;
|
|
5760
5840
|
const hl = fuel ? random.between(0.8, 1.4) * (def.heatLifeScale ?? 1) : random.between(0.22, 0.42);
|
|
5761
|
-
addPuff(core, random, {
|
|
5841
|
+
const fireball = addPuff(core, random, {
|
|
5762
5842
|
x: x + d.x * size * 0.15,
|
|
5763
5843
|
y: y + size * 0.25 + d.y * size * 0.1,
|
|
5764
5844
|
z: z + d.z * size * 0.15,
|
|
@@ -5777,6 +5857,7 @@ function composeFireballs(context) {
|
|
|
5777
5857
|
color: context.smokeColor,
|
|
5778
5858
|
kind: 0
|
|
5779
5859
|
});
|
|
5860
|
+
bornFrom(core, fireball, x, y, z);
|
|
5780
5861
|
}
|
|
5781
5862
|
}
|
|
5782
5863
|
function composeSmoke(context) {
|
|
@@ -5790,7 +5871,7 @@ function composeSmoke(context) {
|
|
|
5790
5871
|
const s1 = size * random.between(0.55, 0.85);
|
|
5791
5872
|
const sg = size * random.between(0.18, 0.3);
|
|
5792
5873
|
const life = random.between(def.smoke.life * 0.7, def.smoke.life * 1.1);
|
|
5793
|
-
addPuff(core, random, {
|
|
5874
|
+
const smoke = addPuff(core, random, {
|
|
5794
5875
|
x: x + d.x * size * 0.6,
|
|
5795
5876
|
y: y + size * 0.4 + d.y * size * 0.5,
|
|
5796
5877
|
z: z + d.z * size * 0.6,
|
|
@@ -5809,6 +5890,7 @@ function composeSmoke(context) {
|
|
|
5809
5890
|
color: context.smokeColor,
|
|
5810
5891
|
kind: def.smoke.kind ?? 0
|
|
5811
5892
|
});
|
|
5893
|
+
bornFrom(core, smoke, x, y, z);
|
|
5812
5894
|
}
|
|
5813
5895
|
}
|
|
5814
5896
|
function composeShock(context) {
|
|
@@ -5833,7 +5915,7 @@ function composeDust(context) {
|
|
|
5833
5915
|
const s1 = size * random.between(0.5, 0.8);
|
|
5834
5916
|
const sg = size * random.between(0.2, 0.35);
|
|
5835
5917
|
const life = random.between(2.2, 4);
|
|
5836
|
-
addPuff(core, random, {
|
|
5918
|
+
const dust = addPuff(core, random, {
|
|
5837
5919
|
x: x + Math.cos(angle) * 0.3,
|
|
5838
5920
|
y: 0.15,
|
|
5839
5921
|
z: z + Math.sin(angle) * 0.3,
|
|
@@ -5850,6 +5932,7 @@ function composeDust(context) {
|
|
|
5850
5932
|
color,
|
|
5851
5933
|
kind: 1
|
|
5852
5934
|
});
|
|
5935
|
+
bornFrom(core, dust, x, 0.15, z);
|
|
5853
5936
|
}
|
|
5854
5937
|
}
|
|
5855
5938
|
function coneAngle(context) {
|
|
@@ -7969,6 +8052,7 @@ function createVfx(options = {}) {
|
|
|
7969
8052
|
});
|
|
7970
8053
|
const core = {
|
|
7971
8054
|
profile,
|
|
8055
|
+
confiner: enclosures,
|
|
7972
8056
|
puffs: createPuffPool(profile.puffs),
|
|
7973
8057
|
sparks: createSparkPool(profile.sparks),
|
|
7974
8058
|
glows: createGlowPool(profile.glows),
|
|
@@ -8109,6 +8193,9 @@ function createVfx(options = {}) {
|
|
|
8109
8193
|
enclose(id, enclosure) {
|
|
8110
8194
|
enclosures.set(id, enclosure);
|
|
8111
8195
|
},
|
|
8196
|
+
solid(id, query2) {
|
|
8197
|
+
enclosures.solid(id, query2);
|
|
8198
|
+
},
|
|
8112
8199
|
enclosures: () => enclosures,
|
|
8113
8200
|
stop(handle) {
|
|
8114
8201
|
player?.stop(handle);
|