@adatechnology/game-destruction-three 0.4.0 → 0.5.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
@@ -5,7 +5,7 @@ package draws them on your meshes: vertex dents, bullet-hole and crack decals, c
5
5
  physics, loose pieces after a part comes off, and pooled particles (fire, smoke, sparks, dust, shards, splinters, ...).
6
6
 
7
7
  - Nothing is changed in place: geometry and materials are cloned on the first visual change of a mesh, and `restore` / `clear` give the originals back.
8
- - Two pooled `THREE.Points` (additive and normal blending) draw every particle, with a soft sprite computed in the shader (no texture asset).
8
+ - Blasts and the fires of burning parts are drawn by the effects world of [`@adatechnology/game-vfx`](../game-vfx) (an `explode` event plays `ev.effect ?? 'generic'`, scaled by the radius when it names none). Pass the world the host shares in `vfx`; without it the renderer makes its own world and its own `game-vfx-three` layer and steps them in `update`. Debris, sparks, drips and leaks still use two pooled `THREE.Points` (additive and normal blending), with a soft sprite computed in the shader (no texture asset); they move to the shared sprite pool when `game-vfx` gets one.
9
9
  - `three` is a peer dependency used for types only: you pass your own `THREE` instance at runtime.
10
10
  - Sounds are not played: you get keys (`impact_metal`, `shatter_glass`, ...) through `onSound`.
11
11
 
@@ -145,9 +145,9 @@ heatColor(temperatureC: number): number // 0xRRGGBB, 0 below ~450 C, dark red ~5
145
145
  ```
146
146
 
147
147
  `RendererOptions`: `scene`, `world`, `quality`, `maxFragments`, `maxParticles`, `fragmentLife`, `groundAt`, `gravity`, `autoSplit`, `onPiece`, `onSound`,
148
- `explosionLight`, `pointScale` (point size in pixels per metre at 1 m; about `viewportHeight / (2 tan(fov / 2))`, default 700).
148
+ `vfx` (shared effects world), `camera` (of the own world, when `vfx` is not given), `pointScale` (point size in pixels per metre at 1 m; about `viewportHeight / (2 tan(fov / 2))`, default 700).
149
149
 
150
- `DestructionRenderer`: `bind`, `unbind`, `makePiece`, `pieces`, `piece`, `impulse`, `update`, `emit`, `explode`, `clear`, `restore`, `stats`, `dispose`.
150
+ `DestructionRenderer`: `bind`, `unbind`, `makePiece`, `pieces`, `piece`, `impulse`, `update`, `emit`, `explode(point, energy, radius, { effect?, direction?, visual? })` (`visual: false` keeps only the shove and the sound, for a host that played the effect itself), `clear`, `restore`, `stats`, `dispose`.
151
151
  `clear()` removes fragments, decals, puddles and particles from the scene and restores every bound mesh; `dispose()` also unsubscribes from the world.
152
152
 
153
153
  ## Português
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as THREE_NS from 'three';
2
2
  import { Vec3, DebrisKind, DestructionWorld, MaterialId, DestructibleSpec } from '@adatechnology/game-destruction';
3
3
  export { Quat, Vec3 } from '@adatechnology/game-destruction';
4
+ import { VfxWorld, SpriteKind } from '@adatechnology/game-vfx';
4
5
 
5
6
  /**
6
7
  * Public types of @adatechnology/game-destruction-three.
@@ -35,8 +36,15 @@ interface RendererOptions {
35
36
  onPiece?: (piece: Piece) => void;
36
37
  /** Called when a sound should play; the host maps keys to audio (e.g. `impact_metal`, `shatter_glass`, `ignite`, `explode`). */
37
38
  onSound?: (key: string, point: Vec3, volume: number) => void;
38
- /** A point light flashes on explosions (default true; costs one light). */
39
- explosionLight?: boolean;
39
+ /**
40
+ * The effects world that draws blasts and fires. Pass the one the host shares with the other renderers (and step it, through its
41
+ * `VfxRenderer.update`, once per frame); without it the renderer makes its own world and its own three layer and steps them in `update`.
42
+ */
43
+ vfx?: VfxWorld;
44
+ /** Which effect each destruction event plays (default `EVENT_EFFECTS_MAP` of `@adatechnology/game-vfx`): `spall`, `stage`, `expose`, `collapse`. Add, change or take out entries to tune it. */
45
+ eventEffects?: Readonly<Record<string, string | Readonly<Record<string, string>>>>;
46
+ /** Camera of the own effects world (distance LOD, shake); only read when `vfx` is not given. Default: a camera at the origin. */
47
+ camera?: THREE_NS.Camera;
40
48
  /**
41
49
  * Particle size scale in pixels per metre at one metre from the camera, roughly `viewportHeight / (2 * tan(fov / 2))` (default 700). Set it
42
50
  * when the viewport is much smaller or larger than about 720 px tall so smoke and fire keep their physical size.
@@ -85,6 +93,15 @@ interface Piece {
85
93
  /** While held by a player the renderer does not integrate it. */
86
94
  held: boolean;
87
95
  }
96
+ /** Options of `DestructionRenderer.explode`. */
97
+ interface ExplodeOptions {
98
+ /** Id of the effect to play (an explosive id of the effects catalogue). Default `generic`. */
99
+ readonly effect?: string;
100
+ /** Where the blast is aimed (a shaped charge). */
101
+ readonly direction?: Vec3;
102
+ /** `false`: the host drew the blast, only the shove and the sound are left. Default `true`. */
103
+ readonly visual?: boolean;
104
+ }
88
105
  interface DestructionRenderer {
89
106
  /** Attach a world object to its three.js root. */
90
107
  bind(objectId: string, root: Object3D, options?: BindOptions): void;
@@ -102,8 +119,12 @@ interface DestructionRenderer {
102
119
  update(dt: number): void;
103
120
  /** Emit particles directly (muzzle flashes, extinguisher foam, tool sparks). */
104
121
  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;
122
+ /**
123
+ * Draw a blast that has no exploding part (a grenade, a rocket): the effect (`options.effect`, an id of the effects catalogue, else `generic`
124
+ * scaled by the radius), sound and a shove on pieces in range. Call it next to `world.explode`, which emits no event of its own. A host that
125
+ * already played the effect itself passes `visual: false` and keeps only the shove and the sound.
126
+ */
127
+ explode(point: Vec3, energy: number, radius: number, options?: ExplodeOptions): void;
107
128
  /** Remove every fragment, decal and particle, restore every bound mesh to its original geometry and colours. */
108
129
  clear(): void;
109
130
  /** Restore one object (after `world.reset`). */
@@ -166,7 +187,7 @@ declare function specFromObject3D(THREE: ThreeNamespace, root: Object3D, options
166
187
  */
167
188
  declare function heatColor(temperatureC: number): number;
168
189
 
169
- /** Every particle kind the renderer can emit. */
170
- type ParticleKind = DebrisKind | 'fire' | 'flash' | 'foam';
190
+ /** Every particle kind the renderer can emit (the game's sprite kinds, see `@adatechnology/game-vfx`). */
191
+ type ParticleKind = SpriteKind;
171
192
 
172
- export { type BindOptions, type DestructionRenderer, type Mesh, type MeshRange, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, type RendererOptions, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, createDestructionRenderer, heatColor, specFromObject3D };
193
+ export { type BindOptions, type DestructionRenderer, type ExplodeOptions, type Mesh, type MeshRange, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, type RendererOptions, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, createDestructionRenderer, heatColor, specFromObject3D };