@adatechnology/game-destruction-three 0.8.0 → 0.8.1

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.js CHANGED
@@ -1054,7 +1054,8 @@ var DecalKit = class {
1054
1054
  depthWrite: false,
1055
1055
  polygonOffset: true,
1056
1056
  polygonOffsetFactor: -4,
1057
- polygonOffsetUnits: -4
1057
+ polygonOffsetUnits: -4,
1058
+ side: this.THREE.DoubleSide
1058
1059
  }));
1059
1060
  }
1060
1061
  /** Opaque patch in the colour of what shows under a spalled coat. */
@@ -1447,6 +1448,27 @@ var Visuals = class {
1447
1448
  }
1448
1449
  addHole(mv, worldPoint, worldNormal, diameter) {
1449
1450
  const { s, pos, quat } = this.decalPose(mv.mesh, worldPoint, worldNormal, 25e-4);
1451
+ const work = mv.host ? mv.host.work : mv.work;
1452
+ if (work && mv.touched) {
1453
+ const ln = worldNormal.clone().transformDirection(this.m4.copy(mv.mesh.matrixWorld).invert()).normalize();
1454
+ let minDistSq = Infinity;
1455
+ let nearestDisp = 0;
1456
+ const from = mv.range ? mv.range[0] * 3 : 0;
1457
+ const to = mv.range ? mv.range[1] * 3 : work.length;
1458
+ for (let i = from; i < to; i += 3) {
1459
+ const dx = work[i] - pos.x;
1460
+ const dy = work[i + 1] - pos.y;
1461
+ const dz = work[i + 2] - pos.z;
1462
+ const d2 = dx * dx + dy * dy + dz * dz;
1463
+ if (d2 < minDistSq) {
1464
+ minDistSq = d2;
1465
+ nearestDisp = dx * ln.x + dy * ln.y + dz * ln.z;
1466
+ }
1467
+ }
1468
+ if (minDistSq < (0.06 / s) ** 2 && nearestDisp < 0) {
1469
+ pos.addScaledVector(ln, nearestDisp);
1470
+ }
1471
+ }
1450
1472
  const disc = new this.THREE.Mesh(this.kit.discGeometry(), this.kit.discMaterial());
1451
1473
  disc.position.copy(pos);
1452
1474
  disc.quaternion.copy(quat);
@@ -1918,7 +1940,13 @@ var FLUID_COLORS = {
1918
1940
  gas: 15921906,
1919
1941
  sap: 12098362,
1920
1942
  acid: 10211900,
1921
- blood: 9046538
1943
+ blood: 9046538,
1944
+ soda: 3808786,
1945
+ coffee: 3875860,
1946
+ beer: 14259516,
1947
+ milk: 16052714,
1948
+ wine: 7016479,
1949
+ juice: 15238923
1922
1950
  };
1923
1951
  var SMOKE_TONES = { white: 15132390, grey: 9079434, black: 2763306 };
1924
1952
  var DEFAULT_SPEED = {
@@ -2447,13 +2475,39 @@ var Renderer = class {
2447
2475
  }
2448
2476
  case "leak": {
2449
2477
  const key = `${ev.object}|${ev.part}`;
2478
+ const b = this.bounds.get(ev.object);
2479
+ let localPoint;
2480
+ let localDirection;
2481
+ if (b) {
2482
+ b.root.updateWorldMatrix(true, false);
2483
+ const inv = new this.THREE.Matrix4().copy(b.root.matrixWorld).invert();
2484
+ const lp = this.v1.set(ev.point[0], ev.point[1], ev.point[2]).applyMatrix4(inv);
2485
+ const ld = this.v2.set(ev.direction[0], ev.direction[1], ev.direction[2]).transformDirection(inv).normalize();
2486
+ localPoint = [lp.x, lp.y, lp.z];
2487
+ localDirection = [ld.x, ld.y, ld.z];
2488
+ }
2450
2489
  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);
2451
2490
  if (same) {
2452
2491
  same.rate = ev.rate;
2453
2492
  same.direction = ev.direction;
2493
+ if (localPoint) same.localPoint = localPoint;
2494
+ if (localDirection) same.localDirection = localDirection;
2454
2495
  } else {
2455
2496
  if (this.leaks.length >= 24) this.leaks.shift();
2456
- this.leaks.push({ object: ev.object, part: ev.part, fluid: ev.fluid, point: ev.point, direction: ev.direction, rate: ev.rate, pressurized: ev.pressurized, acc: 0, opened: this.world.part(ev.object, ev.part)?.holes.some((h) => h.through) ?? false });
2497
+ this.leaks.push({
2498
+ object: ev.object,
2499
+ part: ev.part,
2500
+ fluid: ev.fluid,
2501
+ point: ev.point,
2502
+ direction: ev.direction,
2503
+ rate: ev.rate,
2504
+ pressurized: ev.pressurized,
2505
+ acc: 0,
2506
+ opened: this.world.part(ev.object, ev.part)?.holes.some((h) => h.through) ?? false,
2507
+ localPoint,
2508
+ localDirection,
2509
+ life: 0
2510
+ });
2457
2511
  }
2458
2512
  void key;
2459
2513
  break;
@@ -2889,21 +2943,44 @@ var Renderer = class {
2889
2943
  updateLeaks(dt) {
2890
2944
  for (let i = this.leaks.length - 1; i >= 0; i--) {
2891
2945
  const l = this.leaks[i];
2946
+ const b = this.bounds.get(l.object);
2892
2947
  const ps = this.world.part(l.object, l.part);
2893
- if (!ps || ps.liters === void 0 || ps.liters <= 0 || l.opened && !ps.holes.some((h) => h.through)) {
2948
+ if (!b || !ps || ps.liters === void 0 || ps.liters <= 1e-4 || l.opened && !ps.holes.some((h) => h.through)) {
2894
2949
  this.leaks.splice(i, 1);
2895
2950
  continue;
2896
2951
  }
2952
+ l.life = (l.life ?? 0) + dt;
2953
+ if (l.pressurized && l.life > 0.8) l.pressurized = false;
2954
+ if (l.lastLiters !== void 0 && Math.abs(ps.liters - l.lastLiters) < 1e-5) {
2955
+ l.idleSeconds = (l.idleSeconds ?? 0) + dt;
2956
+ if (l.idleSeconds > 0.4) {
2957
+ this.leaks.splice(i, 1);
2958
+ continue;
2959
+ }
2960
+ } else {
2961
+ l.idleSeconds = 0;
2962
+ l.lastLiters = ps.liters;
2963
+ }
2964
+ let pt = l.point;
2965
+ let dir = l.direction;
2966
+ if (l.localPoint && l.localDirection) {
2967
+ b.root.updateWorldMatrix(true, false);
2968
+ const wp = this.v1.set(l.localPoint[0], l.localPoint[1], l.localPoint[2]).applyMatrix4(b.root.matrixWorld);
2969
+ const wd = this.v2.set(l.localDirection[0], l.localDirection[1], l.localDirection[2]).transformDirection(b.root.matrixWorld).normalize();
2970
+ pt = [wp.x, wp.y, wp.z];
2971
+ dir = [wd.x, wd.y, wd.z];
2972
+ l.point = pt;
2973
+ l.direction = dir;
2974
+ }
2897
2975
  l.acc += clamp(20 + l.rate * 400, 15, 120) * dt;
2898
2976
  const color = FLUID_COLORS[l.fluid] ?? 11184810;
2899
- const d = l.direction;
2900
- const dl = Math.hypot(d[0], d[1], d[2]) || 1;
2977
+ const dl = Math.hypot(dir[0], dir[1], dir[2]) || 1;
2901
2978
  const sp = l.pressurized ? 2.5 + this.rng() * 1.5 : 0.3 + this.rng() * 0.3;
2902
2979
  while (l.acc >= 1) {
2903
2980
  l.acc -= 1;
2904
- const vel = [d[0] / dl * sp + (this.rng() - 0.5) * 0.25, d[1] / dl * sp + (this.rng() - 0.5) * 0.25, d[2] / dl * sp + (this.rng() - 0.5) * 0.25];
2905
- if (l.fluid === "gas") this.vfx.spawn("steam", l.point, vel, { color, size: 0.5, alpha: 0.5 });
2906
- else this.vfx.spawn("drips", l.point, vel, { color, tag: this.rng() < 0.03 ? this.tagOf(l.object) : 0, owner: this.owner });
2981
+ 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];
2982
+ if (l.fluid === "gas") this.vfx.spawn("steam", pt, vel, { color, size: 0.5, alpha: 0.5 });
2983
+ else this.vfx.spawn("drips", pt, vel, { color, tag: this.rng() < 0.03 ? this.tagOf(l.object) : 0, owner: this.owner });
2907
2984
  }
2908
2985
  }
2909
2986
  }