@adatechnology/game-destruction-three 0.4.0 → 0.6.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 +5 -5
- package/dist/index.d.ts +94 -8
- package/dist/index.global.js +8363 -548
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +326 -461
- package/dist/index.js.map +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@ 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
|
-
-
|
|
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
|
+
- The renderer plays nothing: you get keys (`impact_metal`, `shatter_glass`, `burn_loop`, `burn_end`, ...) through `onSound`. `createDestructionSound(engine)` is the sound bank for them on a [`@adatechnology/game-audio`](../game-audio) engine: the Cena de Arte's material sounds (clang, wood, glass, crumble, thud, boom...) and the game's explosion thump, a fire loop that follows how many parts burn, and a key table (`style: 'art_scene' | 'game'`, `keys` to replace) so a game changes what each key plays.
|
|
11
11
|
|
|
12
12
|
Contracts live in [`@adatechnology/game-contracts`](../game-contracts); the types are re-exported here, so existing imports keep working.
|
|
13
13
|
|
|
@@ -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
|
-
`
|
|
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
|
|
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
|
|
@@ -155,7 +155,7 @@ heatColor(temperatureC: number): number // 0xRRGGBB, 0 below ~450 C, dark red ~5
|
|
|
155
155
|
Renderizador three.js para o `@adatechnology/game-destruction`. O núcleo decide o que cada golpe faz e devolve eventos; este pacote desenha: amassados
|
|
156
156
|
nos vértices, furos de bala e rachaduras, carbonização e brilho de calor, derretimento e poças, fragmentos com física leve, peças soltas e partículas
|
|
157
157
|
em pool (fogo, fumaça, faíscas, poeira, cacos, lascas). Geometria e materiais só são clonados na primeira mudança visual de uma malha, e `restore` /
|
|
158
|
-
`clear` devolvem os originais.
|
|
158
|
+
`clear` devolvem os originais. O renderer não toca nada: o jogo recebe chaves (`impact_metal`, `shatter_glass`, `burn_loop`, `burn_end`, ...) em `onSound`; `createDestructionSound(engine)` é o banco de sons delas no `game-audio` (sons dos materiais da Cena de Arte, o estouro do jogo, o laço de fogo e a tabela chave → som, trocável).
|
|
159
159
|
|
|
160
160
|
Uso: `specFromObject3D(THREE, modelo)` gera a especificação e o mapa parte -> malhas; registre no mundo com `world.add(spec)`, ligue com
|
|
161
161
|
`renderer.bind(id, modelo, { parts })` e chame `world.update(dt)` e `renderer.update(dt)` a cada quadro. Com `quality: 'low'` os orçamentos de
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
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';
|
|
5
|
+
import { LoopRecipe, SoundBank, SoundRecipe, AudioEngine } from '@adatechnology/game-audio';
|
|
6
|
+
import { Vec3 as Vec3$1 } from '@adatechnology/game-contracts';
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Public types of @adatechnology/game-destruction-three.
|
|
@@ -33,10 +36,17 @@ interface RendererOptions {
|
|
|
33
36
|
autoSplit?: boolean;
|
|
34
37
|
/** Called when a loose piece is created (the bench registers it as grabbable). */
|
|
35
38
|
onPiece?: (piece: Piece) => void;
|
|
36
|
-
/** Called when a sound should play; the host maps keys to audio (e.g. `impact_metal`, `shatter_glass`, `ignite`, `explode`). */
|
|
39
|
+
/** Called when a sound should play; the host maps keys to audio (e.g. `impact_metal`, `shatter_glass`, `ignite`, `explode`). `burn_loop` is sent when a part starts to burn and `burn_end` when it burns out or is put out. */
|
|
37
40
|
onSound?: (key: string, point: Vec3, volume: number) => void;
|
|
38
|
-
/**
|
|
39
|
-
|
|
41
|
+
/**
|
|
42
|
+
* The effects world that draws blasts and fires. Pass the one the host shares with the other renderers (and step it, through its
|
|
43
|
+
* `VfxRenderer.update`, once per frame); without it the renderer makes its own world and its own three layer and steps them in `update`.
|
|
44
|
+
*/
|
|
45
|
+
vfx?: VfxWorld;
|
|
46
|
+
/** 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. */
|
|
47
|
+
eventEffects?: Readonly<Record<string, string | Readonly<Record<string, string>>>>;
|
|
48
|
+
/** Camera of the own effects world (distance LOD, shake); only read when `vfx` is not given. Default: a camera at the origin. */
|
|
49
|
+
camera?: THREE_NS.Camera;
|
|
40
50
|
/**
|
|
41
51
|
* Particle size scale in pixels per metre at one metre from the camera, roughly `viewportHeight / (2 * tan(fov / 2))` (default 700). Set it
|
|
42
52
|
* when the viewport is much smaller or larger than about 720 px tall so smoke and fire keep their physical size.
|
|
@@ -85,6 +95,15 @@ interface Piece {
|
|
|
85
95
|
/** While held by a player the renderer does not integrate it. */
|
|
86
96
|
held: boolean;
|
|
87
97
|
}
|
|
98
|
+
/** Options of `DestructionRenderer.explode`. */
|
|
99
|
+
interface ExplodeOptions {
|
|
100
|
+
/** Id of the effect to play (an explosive id of the effects catalogue). Default `generic`. */
|
|
101
|
+
readonly effect?: string;
|
|
102
|
+
/** Where the blast is aimed (a shaped charge). */
|
|
103
|
+
readonly direction?: Vec3;
|
|
104
|
+
/** `false`: the host drew the blast, only the shove and the sound are left. Default `true`. */
|
|
105
|
+
readonly visual?: boolean;
|
|
106
|
+
}
|
|
88
107
|
interface DestructionRenderer {
|
|
89
108
|
/** Attach a world object to its three.js root. */
|
|
90
109
|
bind(objectId: string, root: Object3D, options?: BindOptions): void;
|
|
@@ -102,8 +121,12 @@ interface DestructionRenderer {
|
|
|
102
121
|
update(dt: number): void;
|
|
103
122
|
/** Emit particles directly (muzzle flashes, extinguisher foam, tool sparks). */
|
|
104
123
|
emit(kind: DebrisKind | 'fire' | 'flash' | 'foam', point: Vec3, normal: Vec3, count: number, speed?: number): void;
|
|
105
|
-
/**
|
|
106
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Draw a blast that has no exploding part (a grenade, a rocket): the effect (`options.effect`, an id of the effects catalogue, else `generic`
|
|
126
|
+
* 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
|
|
127
|
+
* already played the effect itself passes `visual: false` and keeps only the shove and the sound.
|
|
128
|
+
*/
|
|
129
|
+
explode(point: Vec3, energy: number, radius: number, options?: ExplodeOptions): void;
|
|
107
130
|
/** Remove every fragment, decal and particle, restore every bound mesh to its original geometry and colours. */
|
|
108
131
|
clear(): void;
|
|
109
132
|
/** Restore one object (after `world.reset`). */
|
|
@@ -166,7 +189,70 @@ declare function specFromObject3D(THREE: ThreeNamespace, root: Object3D, options
|
|
|
166
189
|
*/
|
|
167
190
|
declare function heatColor(temperatureC: number): number;
|
|
168
191
|
|
|
169
|
-
/**
|
|
170
|
-
|
|
192
|
+
/** The art scene's destruction sounds, each with the team name in its `sources`. */
|
|
193
|
+
declare const SCENE_SOUNDS: readonly SoundRecipe[];
|
|
194
|
+
/** The game's explosion thump: a sine from 70 to 28 Hz over 1.2 s, `1.4 / (1 + d² × 0.002)` (jogo L68278). */
|
|
195
|
+
declare const EXPLOSION_BOOM: SoundRecipe;
|
|
196
|
+
/**
|
|
197
|
+
* The fire loop of the art scene (cena L1316): noise through a 1800 Hz bandpass (Q 0.6) into a gain that starts at 0. The page never raises it, so it is
|
|
198
|
+
* silent there; here `createDestructionSound` raises it while something burns (the level is the kit's, in `fire`).
|
|
199
|
+
*/
|
|
200
|
+
declare const BURN_LOOP: LoopRecipe;
|
|
201
|
+
declare const DESTRUCTION_SOUND_BANK: SoundBank;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* What a sound key plays: the recipe, its params, a scale on the volume the renderer gives, and (optionally) a louder recipe above a volume
|
|
205
|
+
* (a big blast gets the long boom).
|
|
206
|
+
*/
|
|
207
|
+
type SoundKeyRule = {
|
|
208
|
+
readonly sound: string;
|
|
209
|
+
readonly params?: Readonly<Record<string, number>>;
|
|
210
|
+
readonly volumeScale?: number;
|
|
211
|
+
readonly above?: {
|
|
212
|
+
readonly volume: number;
|
|
213
|
+
readonly sound: string;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
type DestructionSoundStyle = 'art_scene' | 'game';
|
|
217
|
+
/**
|
|
218
|
+
* The keys `createDestructionRenderer` sends to `onSound`, mapped to the sounds the teams delivered. The Cena de Arte has a sound for every material
|
|
219
|
+
* (clang, wood, glass, crumble, thud...); the game has four classes (impact, glass, wood, explosion) and its own explosion thump. Which team sound answers
|
|
220
|
+
* which key is the kit's choice (the teams call the sounds, not the renderer's keys), so it is data: `keys` replaces any entry.
|
|
221
|
+
*/
|
|
222
|
+
declare const DESTRUCTION_SOUND_KEYS: Readonly<Record<DestructionSoundStyle, Readonly<Record<string, SoundKeyRule>>>>;
|
|
223
|
+
type DestructionSoundOptions = {
|
|
224
|
+
/** Which team answers the keys (default `art_scene`, the kit mix). `game` falls back to the art scene for the keys the game has no sound for. */
|
|
225
|
+
readonly style?: DestructionSoundStyle;
|
|
226
|
+
/** Replaces or adds a key's rule; `null` silences it. */
|
|
227
|
+
readonly keys?: Readonly<Record<string, SoundKeyRule | null>>;
|
|
228
|
+
/** The fire loop: the volume each burning part adds and the most it reaches (the page never raises it, so these are the kit's). */
|
|
229
|
+
readonly fire?: {
|
|
230
|
+
readonly perFire?: number;
|
|
231
|
+
readonly max?: number;
|
|
232
|
+
};
|
|
233
|
+
/** Burn loop on or off (default on). */
|
|
234
|
+
readonly burnLoop?: boolean;
|
|
235
|
+
};
|
|
236
|
+
type DestructionSound = {
|
|
237
|
+
/** Pass to `createDestructionRenderer({ onSound })`. */
|
|
238
|
+
readonly onSound: (key: string, point: Vec3$1, volume: number) => void;
|
|
239
|
+
/** The rule a key resolves to, if any. */
|
|
240
|
+
rule(key: string): SoundKeyRule | undefined;
|
|
241
|
+
/** Parts burning now. */
|
|
242
|
+
readonly burning: () => number;
|
|
243
|
+
dispose(): void;
|
|
244
|
+
};
|
|
245
|
+
declare const DEFAULT_FIRE: {
|
|
246
|
+
readonly perFire: 0.05;
|
|
247
|
+
readonly max: 0.2;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Plays the renderer's sound keys on a game-audio engine: the bank is registered in the engine, a key becomes a positional sound at the point, and
|
|
251
|
+
* `burn_loop` / `burn_end` (a part starts to burn, a part burns out or is put out) drive one fire loop whose volume follows how many parts burn.
|
|
252
|
+
*/
|
|
253
|
+
declare function createDestructionSound(engine: AudioEngine, options?: DestructionSoundOptions): DestructionSound;
|
|
254
|
+
|
|
255
|
+
/** Every particle kind the renderer can emit (the game's sprite kinds, see `@adatechnology/game-vfx`). */
|
|
256
|
+
type ParticleKind = SpriteKind;
|
|
171
257
|
|
|
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 };
|
|
258
|
+
export { BURN_LOOP, type BindOptions, DEFAULT_FIRE, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EXPLOSION_BOOM, type ExplodeOptions, type Mesh, type MeshRange, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, type RendererOptions, SCENE_SOUNDS, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, createDestructionRenderer, createDestructionSound, heatColor, specFromObject3D };
|