@adatechnology/game-destruction-three 0.11.0 → 0.11.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
@@ -1651,6 +1651,21 @@ var Visuals = class {
1651
1651
  d.geometry?.dispose();
1652
1652
  this.decalCount = Math.max(0, this.decalCount - 1);
1653
1653
  }
1654
+ /**
1655
+ * Takes away the decals of a mesh that sit inside a box (world `center`, `half` extents along the axes of the world `rotation`): the surface they
1656
+ * marked is gone (a unit came out of the wall with its bullet holes and spalls).
1657
+ */
1658
+ clearDecals(mv, center, half, rotation) {
1659
+ const inv = rotation.clone().invert();
1660
+ const p = new this.THREE.Vector3();
1661
+ for (let i = mv.decals.length - 1; i >= 0; i--) {
1662
+ const d = mv.decals[i];
1663
+ d.obj.getWorldPosition(p).sub(center).applyQuaternion(inv);
1664
+ if (Math.abs(p.x) > half.x || Math.abs(p.y) > half.y || Math.abs(p.z) > half.z) continue;
1665
+ this.disposeDecal(d);
1666
+ mv.decals.splice(i, 1);
1667
+ }
1668
+ }
1654
1669
  addHole(mv, worldPoint, worldNormal, diameter) {
1655
1670
  const { s, pos, quat } = this.decalPose(mv.mesh, worldPoint, worldNormal, 25e-4);
1656
1671
  const work = mv.host ? mv.host.work : mv.work;
@@ -2133,6 +2148,7 @@ var Visuals = class {
2133
2148
  // src/renderer.ts
2134
2149
  var rendererCount = 0;
2135
2150
  var COLLAPSE_CLOUD_KG = 1e3;
2151
+ var CHIP_DECAL_EDGE = 0.05;
2136
2152
  var IMPACT_TAGS = ["metal", "glass", "wood"];
2137
2153
  var GLOW_FROM_C = 430;
2138
2154
  var QUEUE_CAP = 4e3;
@@ -2696,7 +2712,7 @@ var Renderer = class {
2696
2712
  break;
2697
2713
  }
2698
2714
  case "debris":
2699
- this.vfx.burst(ev.kind, ev.point, ev.normal, ev.count, ev.speed > 0 ? ev.speed : DEFAULT_SPEED[ev.kind] ?? 1, this.debrisOptions(ev.kind, ev.object, ev.part));
2715
+ this.vfx.burst(ev.kind, ev.point, ev.normal, ev.count, ev.speed > 0 ? ev.speed : DEFAULT_SPEED[ev.kind] ?? 1, this.debrisOptions(ev.kind, ev.object, ev.part, ev.material));
2700
2716
  break;
2701
2717
  case "fracture":
2702
2718
  this.onFracture(ev);
@@ -2869,10 +2885,11 @@ var Renderer = class {
2869
2885
  }
2870
2886
  return def ? fallbackColor(def.id, def) : null;
2871
2887
  }
2872
- debrisOptions(kind, objectId, partId) {
2888
+ debrisOptions(kind, objectId, partId, material) {
2873
2889
  const pv = this.partVis(objectId, partId);
2874
- const def = pv ? this.world.materials.get(pv.material) : void 0;
2890
+ const def = this.world.materials.get(material ?? pv?.material ?? "");
2875
2891
  if (kind === "smoke") return { color: SMOKE_TONES[def?.thermal.smoke ?? "grey"] };
2892
+ if ((kind === "dust" || kind === "chips") && def?.visual?.innerColor !== void 0) return { color: def.visual.innerColor };
2876
2893
  if (kind === "fibers" || kind === "leaves") {
2877
2894
  if (def?.visual?.innerColor !== void 0) return { color: def.visual.innerColor };
2878
2895
  const c = pv ? this.visuals.baseColorHex(pv.meshes[0] ?? {}) : -1;
@@ -2980,8 +2997,11 @@ var Renderer = class {
2980
2997
  const mv = this.nearestMesh(pv, wp);
2981
2998
  if (!mv) return;
2982
2999
  const def = this.world.materials.get(pv.material);
2983
- this.playEvent({ kind: "spall", material: this.impactMaterial(def) }, ev.point);
2984
- this.visuals.addSpall(mv, wp, this.faceNormal(mv, wp), Math.sqrt(ev.area / Math.PI), fallbackColor(pv.material, def));
3000
+ const normal = this.faceNormal(mv, wp);
3001
+ const core = def?.visual?.innerColor;
3002
+ if (core !== void 0) this.vfx.burst("chips", ev.point, [normal.x, normal.y, normal.z], 5, 2.5, { color: core });
3003
+ else this.playEvent({ kind: "spall", material: this.impactMaterial(def) }, ev.point);
3004
+ this.visuals.addSpall(mv, wp, normal, Math.sqrt(ev.area / Math.PI), core ?? fallbackColor(pv.material, def));
2985
3005
  }
2986
3006
  /**
2987
3007
  * Stage 2 of a staged part: the unit-sized fragments come out and the part stays drawn (hiding it is what `fracture` does). The opening itself
@@ -3004,8 +3024,9 @@ var Renderer = class {
3004
3024
  this.sound(impactKey(def), ev.opening.center, 0.8);
3005
3025
  }
3006
3026
  /**
3007
- * A unit came out of a wall of units: the unit flies as a fragment with a puff of its dust. The gap itself is the drawing's (the house renderer redraws
3008
- * the wall as its courses without that unit); a part drawn as one box keeps its box.
3027
+ * A unit came out of a wall of units: the unit flies as a fragment with a puff of its dust, and the marks drawn on it (bullet holes, spalls, the impact
3028
+ * marks of the effects) go with it. The gap itself is the drawing's (the house renderer cuts the wall where the unit was); a part drawn as one box
3029
+ * keeps its box.
3009
3030
  */
3010
3031
  onChip(ev) {
3011
3032
  const pv = this.partVis(ev.object, ev.part);
@@ -3017,7 +3038,13 @@ var Renderer = class {
3017
3038
  const tone2 = fr.inner && fdef?.visual?.innerColor !== void 0 ? fdef.visual.innerColor : fdef === def ? color : fallbackColor(fr.material, fdef);
3018
3039
  this.fragments.spawn(fr, this.fragments.materialFor(fr.material, tone2, false), ev.object, maxAlive);
3019
3040
  }
3020
- if (!this.playEvent({ kind: "spall", material: this.impactMaterial(def) }, ev.center)) this.vfx.burst("dust", ev.center, [0, 1, 0], 6, 0.8, { color });
3041
+ const T = this.THREE;
3042
+ const center = new T.Vector3(ev.center[0], ev.center[1], ev.center[2]);
3043
+ const half = new T.Vector3(ev.size[0] / 2 + CHIP_DECAL_EDGE, ev.size[1] / 2 + CHIP_DECAL_EDGE, ev.size[2] / 2 + CHIP_DECAL_EDGE);
3044
+ const rotation = new T.Quaternion(ev.rotation[0], ev.rotation[1], ev.rotation[2], ev.rotation[3]);
3045
+ for (const part of this.bounds.get(ev.object)?.parts.values() ?? []) for (const mv of part.meshes) this.visuals.clearDecals(mv, center, half, rotation);
3046
+ this.vfx.peekWorkshop()?.decals.clearInside(ev.center, [half.x, half.y, half.z], ev.rotation);
3047
+ this.vfx.burst("dust", ev.center, [0, 1, 0], 8, 0.8, { color });
3021
3048
  this.sound(impactKey(def), ev.center, 0.7);
3022
3049
  }
3023
3050
  onFracture(ev) {