@adatechnology/game-destruction-three 0.24.4 → 0.25.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
@@ -145,6 +145,8 @@ pane shatters and a thrown chair can lose a leg. `Piece.localCenter` is the cent
145
145
  | Particles (`maxParticles`) | 2500 | 1250 |
146
146
  | Particle burst counts | 100 % | 60 % |
147
147
  | Fragment meshes (`maxFragments`) | 160 | 80, and every second fragment of an event is skipped |
148
+ | Loose pieces simulated at once (`maxAwakePieces`) | no limit (suggested 24) | no limit (suggested 24) |
149
+ | Fragments moving at once (`maxAwakeFragments`) | no limit (suggested 64) | no limit (suggested 64) |
148
150
  | Vertex dents / melt noise on meshes over 20k vertices | yes | skipped |
149
151
 
150
152
  - Particles are two fixed-size ring buffers (additive 40 %, normal 60 %), one draw call each; dead particles cost a loop iteration, nothing else.
@@ -153,6 +155,14 @@ pane shatters and a thrown chair can lose a leg. `Piece.localCenter` is the cent
153
155
  - Heat, char and melt are only read for "active" parts (hot, burning, melting) plus a scan of all parts every 0.4 s.
154
156
  - The explosion light is created on the first explosion (one light in the scene afterwards, intensity 0 at rest) so plan for the one-time shader recompile.
155
157
  - Melt assumes upright meshes (it scales the mesh along its own Y).
158
+ - Debris at rest can cost no simulation and few draws; both are opt-in, so a host that sets nothing simulates and draws exactly as before. Over `maxAwakePieces`
159
+ (`maxAwakeFragments`) the oldest that have come to rest (on the ground, slower than a piece that sleeps; one held up at an angle once it kept its tilt for 1.5 s) sleep where
160
+ they lie, nothing moved. A piece put to sleep so keeps the points it lies on and wakes when any of them loses its support, so nothing is left in the air. With
161
+ `settledBatches` the debris asleep is drawn in batches, one draw per material (made with `createStaticBatcher` of `@adatechnology/game-render-three` from 16 meshes outside a
162
+ batch, at most once a second; copies of one material with equal settings share a batch): its collision is the piece's, unchanged, and a piece that is woken, hit, dented,
163
+ hidden or touched by any event of its object draws on its own again at once. Transparent debris (glass), the meshes of an object burning or charring and meshes over 4000
164
+ vertices draw on their own. `settledBatchStats()` reports the batches. The test room turns the batches on; its awake budget stays off unless
165
+ `debris.maxAwakePieces` / `maxAwakeFragments` are given (`SUGGESTED_MAX_AWAKE_PIECES`, `SUGGESTED_MAX_AWAKE_FRAGMENTS`).
156
166
 
157
167
  ## API
158
168
 
@@ -162,7 +172,7 @@ specFromObject3D(THREE, root, options?: SpecFromObjectOptions): { spec, parts }
162
172
  heatColor(temperatureC: number): number // 0xRRGGBB, 0 below ~450 C, dark red ~500, orange ~800, yellow ~1100, white from 1400
163
173
  ```
164
174
 
165
- `RendererOptions`: `scene`, `world`, `quality`, `maxFragments`, `maxParticles`, `fragmentLife`, `groundAt`, `gravity`, `autoSplit`, `onPiece`, `onSound`,
175
+ `RendererOptions`: `scene`, `world`, `quality`, `maxFragments`, `maxAwakePieces`, `maxAwakeFragments`, `settledBatches`, `maxParticles`, `fragmentLife`, `groundAt`, `gravity`, `autoSplit`, `onPiece`, `onSound`,
166
176
  `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).
167
177
 
168
178
  How long debris stays: `fragmentLife` is the seconds a resting fragment stays before it shrinks away (default 12, `0` = forever), or a `FragmentLifeRule`
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Fragment, Vec3, DebrisKind, HitResult, DestructionWorld, MaterialId, DestructibleSpec, MaterialDef, DamageType } from '@adatechnology/game-destruction';
2
2
  export { Quat, Vec3 } from '@adatechnology/game-destruction';
3
- import { DeferredQueue, WarmUpProbes, BlastShoveOptions, Vec3 as Vec3$1 } from '@adatechnology/game-contracts';
3
+ import { KitOrigin, DeferredQueue, WarmUpProbes, BlastShoveOptions, Vec3 as Vec3$1 } from '@adatechnology/game-contracts';
4
4
  import * as THREE_NS from 'three';
5
5
  import { VfxWorld, SpriteKind } from '@adatechnology/game-vfx';
6
6
  import { LoopRecipe, SoundBank, SoundRecipe, Falloff, AudioEngine, SampleDefaults, SfxManifest } from '@adatechnology/game-audio';
@@ -8,6 +8,30 @@ import { LoopRecipe, SoundBank, SoundRecipe, Falloff, AudioEngine, SampleDefault
8
8
  /** What a fragment's resting time can depend on: the fragment (its material, size, shape) and the id of the object it came from. */
9
9
  type FragmentLifeRule = (fragment: Fragment, objectId: string) => number;
10
10
 
11
+ /** How the debris at rest is drawn in batches (`RendererOptions.settledBatches`). */
12
+ interface SettledBatchOptions {
13
+ /** Draw the debris at rest in batches (default true). */
14
+ readonly enabled?: boolean;
15
+ /** Debris meshes at rest outside a batch before the batches are made again (default 16). */
16
+ readonly minMeshes?: number;
17
+ /** Seconds at least between two makings of the batches (default 1). */
18
+ readonly intervalSeconds?: number;
19
+ /** Milliseconds of merging per update while the batches are made (default 2): what is not merged yet draws on its own meanwhile. */
20
+ readonly budgetMs?: number;
21
+ /** Vertices of the largest mesh a batch takes (default 4000): a bigger one (a slab come down whole) draws on its own. */
22
+ readonly maxVertices?: number;
23
+ }
24
+ /** What the batches of the debris at rest hold now (`DestructionRenderer.settledBatchStats`). */
25
+ interface SettledBatchStats {
26
+ /** Draws of the batches: one per material, shadow and attribute set. */
27
+ readonly batches: number;
28
+ /** Debris meshes drawn by a batch instead of on their own. */
29
+ readonly batched: number;
30
+ }
31
+ declare const SETTLED_BATCH_DEFAULTS: Required<SettledBatchOptions>;
32
+ /** Where the batches come from when their meshes do not all come from one piece of the kit. */
33
+ declare const SETTLED_BATCH_ORIGIN: KitOrigin;
34
+
11
35
  /**
12
36
  * Public types of @adatechnology/game-destruction-three.
13
37
  *
@@ -45,6 +69,20 @@ interface RendererOptions {
45
69
  quality?: Quality;
46
70
  /** Upper bound of live fragment meshes (default 160; oldest fade first). */
47
71
  maxFragments?: number;
72
+ /**
73
+ * Most loose pieces simulated at once (default no limit; a game loop starts from `SUGGESTED_MAX_AWAKE_PIECES`, 24). Over it the oldest pieces that have come to rest (on the
74
+ * ground, slower than a piece that sleeps, and one held up at an angle once it kept its tilt for 1.5 s) sleep where they lie at once; nothing is moved. With a limit, one held
75
+ * up at an angle that kept its tilt sleeps under it too (by itself it never does). One put to sleep so wakes as any other (hit, knocked) and when any point it lay on loses its
76
+ * support.
77
+ */
78
+ maxAwakePieces?: number;
79
+ /** Most fragments moving at once (default no limit; `SUGGESTED_MAX_AWAKE_FRAGMENTS`, 64): over it the oldest at rest on what is under them sleep where they lie. */
80
+ maxAwakeFragments?: number;
81
+ /**
82
+ * Draw the debris at rest in batches, a draw per material (`SettledBatchOptions`; `{}` for the defaults). Omitted, every debris mesh draws on its own, as before. Only the
83
+ * drawing changes: the collision is each piece's own.
84
+ */
85
+ settledBatches?: SettledBatchOptions;
48
86
  /**
49
87
  * Milliseconds of one `update` spent applying queued world events (default `Infinity`: every event is drawn
50
88
  * in the `update` that receives it, so what a caller reads right after is final). A game loop sets a finite budget (the test room uses 8): what is left waits for the
@@ -65,6 +103,8 @@ interface RendererOptions {
65
103
  autoSplit?: boolean;
66
104
  /** Called when a loose piece is created (the bench registers it as grabbable). */
67
105
  onPiece?: (piece: Piece) => void;
106
+ /** Called by `release` with the ids of the pieces it took out of the world, so a host that kept them (`onPiece`) forgets them. */
107
+ onReleased?: (pieceIds: readonly string[]) => void;
68
108
  /**
69
109
  * The numbers of the shove a blast gives to the pieces (`BlastShoveOptions` of game-contracts: how much of the energy becomes speed, the fastest throw, the lift, the falloff).
70
110
  * The defaults give the pieces the speed the blast always gave them, with the cap lowered to 20 m/s.
@@ -196,6 +236,14 @@ interface DestructionRenderer {
196
236
  /** Attach a world object to its three.js root. */
197
237
  bind(objectId: string, root: Object3D, options?: BindOptions): void;
198
238
  unbind(objectId: string): void;
239
+ /**
240
+ * The object leaves for good (a house replaced, a module cleared): every piece that split from it leaves the world, and every effect of it and of
241
+ * its pieces (fires, burn sounds, leaks, events still waiting, fragments, ground marks, bare bars, sprites, flames and smoke) goes at once; then it is
242
+ * unbound. The object itself stays in the world for whoever added it to remove. Returns the ids of the pieces removed (also told to `onReleased`).
243
+ */
244
+ release(objectId: string): string[];
245
+ /** What split from the object leaves the world with all its effects, as `release` does, and the object keeps its binding (a reset). Returns the ids removed. */
246
+ releasePieces(objectId: string): string[];
199
247
  /** Make a bound object a physical piece (bench items that can be thrown). */
200
248
  makePiece(objectId: string, options?: MakePieceOptions): Piece;
201
249
  pieces(): Piece[];
@@ -246,6 +294,8 @@ interface DestructionRenderer {
246
294
  pieces: number;
247
295
  decals: number;
248
296
  };
297
+ /** The draws of the batches of the debris at rest and how many debris meshes they draw (`RendererOptions.settledBatches`). */
298
+ settledBatchStats?(): SettledBatchStats;
249
299
  /** Meshes that use the materials of the hole, patch and crack decals, to render once so that the first hit does not build their shader programs in the middle of a frame. */
250
300
  warmUpProbes(): WarmUpProbes;
251
301
  /** Bars of exposed rebar drawn now (`expose` events; one instanced mesh per part). */
@@ -274,6 +324,9 @@ interface SpecFromObjectResult {
274
324
  parts: Record<string, Object3D[]>;
275
325
  }
276
326
 
327
+ /** Most loose pieces and fragments simulated at once a game loop can start from (`RendererOptions.maxAwakePieces`, `maxAwakeFragments`; the default is no limit). */
328
+ declare const SUGGESTED_MAX_AWAKE_PIECES = 24;
329
+ declare const SUGGESTED_MAX_AWAKE_FRAGMENTS = 64;
277
330
  /** Sound key for an impact on a material. */
278
331
  declare function impactKey(def: MaterialDef | undefined): string;
279
332
  /** Sound key (`shot_*`) of a round striking this material: sharper than a blow (a tink on steel, a crack on glass); a host without it plays the `impact_*`. */
@@ -425,6 +478,12 @@ declare const impactSoundIds: (rules?: Readonly<Record<string, SoundKeyRule>>) =
425
478
  * 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.
426
479
  */
427
480
  declare const DESTRUCTION_SOUND_KEYS: Readonly<Record<DestructionSoundStyle, Readonly<Record<string, SoundKeyRule>>>>;
481
+ /**
482
+ * Every sound an explosion and what it leaves can play: the boom of each blast family, the far rumble and the indoor tail, the fire loops and
483
+ * crackles, and each blow, break and fall on a material (`impactSoundIds` of `rules`). A game preloads them (`AudioEngine.preload`) so that no
484
+ * first blast decodes its recordings in play; derived from the tables, so a new family or material rule is covered with no list to update.
485
+ */
486
+ declare const blastSoundIds: (rules?: Readonly<Record<string, SoundKeyRule>>) => string[];
428
487
  type DestructionSoundOptions = {
429
488
  /** 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. */
430
489
  readonly style?: DestructionSoundStyle;
@@ -527,4 +586,4 @@ declare function blastFireSampleBank(manifest: SfxManifest, options?: BlastFireS
527
586
  /** Every particle kind the renderer can emit (the game's sprite kinds, see `@adatechnology/game-vfx`). */
528
587
  type ParticleKind = SpriteKind;
529
588
 
530
- export { BIG_BLAST_RADIUS, BLAST_FALLOFF, BLAST_FAR_DISTANCE, BLAST_FAR_FALLOFF, BLAST_FIRE_SAMPLES, BLAST_KINDS, BLAST_KIND_OF, BLAST_SOUNDS, BLAST_SOUND_OF, BURN_LOOP, type BindOptions, type BlastFireSampleBankOptions, type BlastFireSampleDefaults, type BlastKind, DEFAULT_CRACKLES, DEFAULT_FIRE, DEFAULT_INDOOR_CONFINEMENT, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, DRAG_SOUNDS, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EXPLOSION_BOOM, type ExplodeOptions, FIRE_FADE_SECONDS, FIRE_FALLOFF, FIRE_LOOP, FIRE_SOUNDS, type FragmentLifeRule, GRENADE_PIN_PULL, IMPACT_FAMILY_TAGS, IMPACT_SOUNDS, IMPACT_SOUND_KEYS, type ImpactFamily, type ImpactKeys, type LooseBody, type MakePieceOptions, type Mesh, type MeshRange, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, ROCKET_MOTOR_LOOP, type RendererOptions, SCENE_SOUNDS, SMOKE_HISS_LOOP, type SolidBox, type SoundDetail, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, blastFireSampleBank, breakSoundKeys, createDestructionRenderer, createDestructionSound, dragSoundKey, heatColor, impactFamily, impactKey, impactSoundIds, impactSoundKeys, ricochetSoundKeys, shotKey, specFromObject3D };
589
+ export { BIG_BLAST_RADIUS, BLAST_FALLOFF, BLAST_FAR_DISTANCE, BLAST_FAR_FALLOFF, BLAST_FIRE_SAMPLES, BLAST_KINDS, BLAST_KIND_OF, BLAST_SOUNDS, BLAST_SOUND_OF, BURN_LOOP, type BindOptions, type BlastFireSampleBankOptions, type BlastFireSampleDefaults, type BlastKind, DEFAULT_CRACKLES, DEFAULT_FIRE, DEFAULT_INDOOR_CONFINEMENT, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, DRAG_SOUNDS, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EXPLOSION_BOOM, type ExplodeOptions, FIRE_FADE_SECONDS, FIRE_FALLOFF, FIRE_LOOP, FIRE_SOUNDS, type FragmentLifeRule, GRENADE_PIN_PULL, IMPACT_FAMILY_TAGS, IMPACT_SOUNDS, IMPACT_SOUND_KEYS, type ImpactFamily, type ImpactKeys, type LooseBody, type MakePieceOptions, type Mesh, type MeshRange, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, ROCKET_MOTOR_LOOP, type RendererOptions, SCENE_SOUNDS, SETTLED_BATCH_DEFAULTS, SETTLED_BATCH_ORIGIN, SMOKE_HISS_LOOP, SUGGESTED_MAX_AWAKE_FRAGMENTS, SUGGESTED_MAX_AWAKE_PIECES, type SettledBatchOptions, type SettledBatchStats, type SolidBox, type SoundDetail, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, blastFireSampleBank, blastSoundIds, breakSoundKeys, createDestructionRenderer, createDestructionSound, dragSoundKey, heatColor, impactFamily, impactKey, impactSoundIds, impactSoundKeys, ricochetSoundKeys, shotKey, specFromObject3D };