@adatechnology/game-destruction-three 0.2.0 → 0.3.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 CHANGED
@@ -111,6 +111,8 @@ loose meshes. An invalid range (outside the geometry or empty) throws from `bind
111
111
  | `leak` | stream of drops (or a faint puff for gas) from the hole while the part still has liters | |
112
112
  | `explode` | flash, fire, smoke, dust and sparks, a pooled `PointLight` pulse, impulses on pieces and fragments in range | `explode` |
113
113
 
114
+ `world.explode` emits no event of its own (only a part with `explodes` does), so a host that detonates a grenade or rocket calls `renderer.explode(point, energy, radius)` next to it to get the same flash, fire, smoke, light, sound and shove.
115
+
114
116
  Pieces report hard landings: above 3 m/s the renderer calls `world.hit(id, { type: 'blunt', energy: 0.5 m v^2, radius: 0.08, direction: [0, -1, 0], source: 'fall' })`
115
117
  (throttled to once per 0.15 s per piece; the object's transform is synced to the world first, so the hit lands on the right spot), so a dropped glass
116
118
  pane shatters and a thrown chair can lose a leg. `Piece.localCenter` is the centre of mass relative to the root origin (it moves when a part breaks off).
@@ -142,7 +144,7 @@ heatColor(temperatureC: number): number // 0xRRGGBB, 0 below ~450 C, dark red ~5
142
144
  `RendererOptions`: `scene`, `world`, `quality`, `maxFragments`, `maxParticles`, `fragmentLife`, `groundAt`, `gravity`, `autoSplit`, `onPiece`, `onSound`,
143
145
  `explosionLight`, `pointScale` (point size in pixels per metre at 1 m; about `viewportHeight / (2 tan(fov / 2))`, default 700).
144
146
 
145
- `DestructionRenderer`: `bind`, `unbind`, `makePiece`, `pieces`, `piece`, `impulse`, `update`, `emit`, `clear`, `restore`, `stats`, `dispose`.
147
+ `DestructionRenderer`: `bind`, `unbind`, `makePiece`, `pieces`, `piece`, `impulse`, `update`, `emit`, `explode`, `clear`, `restore`, `stats`, `dispose`.
146
148
  `clear()` removes fragments, decals, puddles and particles from the scene and restores every bound mesh; `dispose()` also unsubscribes from the world.
147
149
 
148
150
  ## Português
package/dist/index.d.ts CHANGED
@@ -102,6 +102,8 @@ interface DestructionRenderer {
102
102
  update(dt: number): void;
103
103
  /** Emit particles directly (muzzle flashes, extinguisher foam, tool sparks). */
104
104
  emit(kind: DebrisKind | 'fire' | 'flash' | 'foam', point: Vec3, normal: Vec3, count: number, speed?: number): void;
105
+ /** Draw a blast that has no exploding part (a grenade, a rocket): flash, fire, smoke, light, sound and a shove on pieces in range. Call it next to `world.explode`, which emits no event of its own. */
106
+ explode(point: Vec3, energy: number, radius: number): void;
105
107
  /** Remove every fragment, decal and particle, restore every bound mesh to its original geometry and colours. */
106
108
  clear(): void;
107
109
  /** Restore one object (after `world.reset`). */
@@ -440,6 +440,8 @@ void main() {
440
440
  __publicField(this, "alphaMul");
441
441
  __publicField(this, "tag");
442
442
  __publicField(this, "colorHex");
443
+ __publicField(this, "rgbStart");
444
+ __publicField(this, "rgbEnd");
443
445
  __publicField(this, "bounced");
444
446
  const n = Math.max(1, capacity);
445
447
  this.pos = new Float32Array(n * 3);
@@ -456,6 +458,8 @@ void main() {
456
458
  this.alphaMul = new Float32Array(n);
457
459
  this.tag = new Int32Array(n);
458
460
  this.colorHex = new Int32Array(n);
461
+ this.rgbStart = new Float32Array(n * 3);
462
+ this.rgbEnd = new Float32Array(n * 3);
459
463
  this.bounced = new Uint8Array(n);
460
464
  this.geometry = new THREE.BufferGeometry();
461
465
  const attr = (a, size) => {
@@ -503,6 +507,8 @@ void main() {
503
507
  this.alphaMul[i] = o?.alpha ?? 1;
504
508
  this.tag[i] = o?.tag ?? 0;
505
509
  this.colorHex[i] = o?.color ?? -1;
510
+ this.rgbStart.set(hexToRgb(o?.color ?? def.c0), i * 3);
511
+ this.rgbEnd.set(hexToRgb(o?.color ?? def.c1), i * 3);
506
512
  this.bounced[i] = 0;
507
513
  this.siz[i] = this.size0[i];
508
514
  this.alp[i] = 0;
@@ -596,13 +602,9 @@ void main() {
596
602
  this.pos[i3 + 1] = y;
597
603
  this.pos[i3 + 2] = z;
598
604
  this.siz[i] = this.size0[i] * lerp(1, def.grow, t);
599
- const c0 = this.colorHex[i] >= 0 ? this.colorHex[i] : def.c0;
600
- const c1 = this.colorHex[i] >= 0 ? this.colorHex[i] : def.c1;
601
- const a = hexToRgb(c0);
602
- const b = hexToRgb(c1);
603
- this.col[i3] = lerp(a[0], b[0], t);
604
- this.col[i3 + 1] = lerp(a[1], b[1], t);
605
- this.col[i3 + 2] = lerp(a[2], b[2], t);
605
+ this.col[i3] = lerp(this.rgbStart[i3], this.rgbEnd[i3], t);
606
+ this.col[i3 + 1] = lerp(this.rgbStart[i3 + 1], this.rgbEnd[i3 + 1], t);
607
+ this.col[i3 + 2] = lerp(this.rgbStart[i3 + 2], this.rgbEnd[i3 + 2], t);
606
608
  let env = t < def.fadeIn ? t / def.fadeIn : 1 - (t - def.fadeIn) / (1 - def.fadeIn);
607
609
  if (def.flicker) env *= 1 - def.flicker * (0.5 + 0.5 * Math.sin(age * 38 + this.seed[i] * 50));
608
610
  this.alp[i] = clamp(env, 0, 1) * def.alpha * this.alphaMul[i];
@@ -3934,6 +3936,9 @@ void main() {
3934
3936
  emit(kind, point, normal, count, speed) {
3935
3937
  this.particles.burst(kind, point, normal, count, speed ?? DEFAULT_SPEED[kind] ?? 1, kind === "smoke" ? { color: SMOKE_TONES.grey } : void 0);
3936
3938
  }
3939
+ explode(point, energy, radius) {
3940
+ this.onExplode({ type: "explode", object: "", part: "", time: this.time, point, energy, radius });
3941
+ }
3937
3942
  restore(objectId) {
3938
3943
  const homes = /* @__PURE__ */ new Set([objectId]);
3939
3944
  const self = this.bounds.get(objectId);