@adatechnology/game-destruction-three 0.29.3 → 1.1.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
@@ -98,6 +98,14 @@ material, into a new mesh that becomes the loose piece, and the range is collaps
98
98
  melted or burnt-out part vanishes the same way. `restore` and `clear` put the merged mesh's original geometry and material back and remove the
99
99
  loose meshes. An invalid range (outside the geometry or empty) throws from `bind`.
100
100
 
101
+ ### A mesh that says what it was built from (`userData.solids`)
102
+
103
+ A mesh of its own (not a range of a merged one) may list the solids it was built from in `userData.solids`: `{ center, half, rotation }` each, in the mesh's
104
+ space (`ShapeSolid` of `@adatechnology/game-shapes`; the mesh api of `@adatechnology/game-interactables-three` writes it). The renderer then holds the mesh by
105
+ that list, fixed (one box of the engine per solid) and let go (the boxes of the piece), and reads no vertex back: a kennel is its boards with its doorway open,
106
+ a stool is its four legs and its seat with the floor free under it. The list is read as data: one entry that is not a solid and the mesh is measured from what
107
+ is drawn, as a mesh with no list is (a house, a vehicle). CLAUDE.md §12 and spec 019.
108
+
101
109
  ## What each event draws
102
110
 
103
111
  | Event | Visual | Sound key |
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Vec3, Fragment, DebrisKind, HitResult, DestructionWorld, MaterialId, DestructibleSpec, MaterialDef, DestructionEvent, BlastOptions, DamageType } from '@adatechnology/game-destruction';
2
2
  export { Quat, Vec3 } from '@adatechnology/game-destruction';
3
- import { WorkerCoordinator, KitOrigin, DeferredQueue, DeferredQueueOptions, WarmUpProbes, BlastShoveOptions, TaskKind, Vec3 as Vec3$1 } from '@adatechnology/game-contracts';
3
+ import { WorkerCoordinator, KitOrigin, HostSolid, DeferredQueue, DeferredQueueOptions, WarmUpProbes, BlastShoveOptions, TaskKind, Vec3 as Vec3$1 } from '@adatechnology/game-contracts';
4
4
  import { HeightPatch } from '@adatechnology/game-terrain';
5
5
  import { WorkerLike, WorkerScopeLike } from '@adatechnology/game-shapes';
6
6
  import { Quat, WorkBudgetOptions, PhysicsLoop, SeamWorld, PhysicsEngine, WorldDesc, BlastQuery, BodyId } from '@adatechnology/game-physics';
@@ -127,6 +127,8 @@ interface StaticSolid {
127
127
  readonly mesh?: StaticMesh;
128
128
  /** Names the part across lists (a part measured again is the same part): without it, the place in the list. */
129
129
  readonly key?: string;
130
+ /** A round primitive: a cylinder along the solid's own y, its radius the mean of its x and z halves (see `PartBox.round`). */
131
+ readonly round?: true;
130
132
  /** The Coulomb friction and rolling resistance of the part's material; without it the body has the ground's. */
131
133
  readonly friction?: {
132
134
  readonly static: number;
@@ -275,9 +277,9 @@ declare const splitWorkUnits: (costs: Required<WorkUnitCosts>, size: {
275
277
 
276
278
  /**
277
279
  * The physics a seam is handed, always by its host and always spelled out: a `PhysicsLoop` (the host steps it; the seam registers phases), a world (the seam makes its own loop
278
- * and steps it in its `update`), or `'own'` (the kit's own solver, until it goes).
280
+ * and steps it in its `update`).
279
281
  */
280
- type PiecePhysics = PhysicsLoop | SeamWorld | 'own';
282
+ type PiecePhysics = PhysicsLoop | SeamWorld;
281
283
  declare class PhysicsOptionError extends Error {
282
284
  readonly code = "PHYSICS_OPTION";
283
285
  constructor(message: string);
@@ -310,7 +312,7 @@ declare const SETTLED_BATCH_DEFAULTS: Required<SettledBatchOptions>;
310
312
  /** Where the batches come from when their meshes do not all come from one piece of the kit. */
311
313
  declare const SETTLED_BATCH_ORIGIN: KitOrigin;
312
314
 
313
- /** What the warm-up runs on: the engine whose body creation, compounds and ground it heats (without one, the kit's own solver), and the numbers of the throwaway world. */
315
+ /** What the warm-up runs on: the engine whose body creation, compounds and ground it heats (without one there is nothing to warm), and the numbers of the throwaway world. */
314
316
  interface JitWarmUpOptions {
315
317
  readonly engine?: PhysicsEngine;
316
318
  /** The world the engine makes for the warm-up (default `KIT_WORLD`: the same code runs as in the game's world). */
@@ -322,7 +324,7 @@ interface JitWarmUpReport {
322
324
  readonly fragments: number;
323
325
  }
324
326
  /**
325
- * Runs the first explosion once, off screen, so the code it needs is warm when the real one comes. Once per engine (and once for the kit's own solver): a second call is a
327
+ * Runs the first explosion once, off screen, so the code it needs is warm when the real one comes. Once per engine: a second call, or a call with no engine, is a
326
328
  * no-op (`undefined`). `makeRenderer` is the renderer factory of the package, so the throwaway renderer is the real one.
327
329
  */
328
330
  declare const warmUpDestructionJit: (THREE: ThreeNamespace, makeRenderer: (options: RendererOptions) => DestructionRenderer, options?: JitWarmUpOptions) => JitWarmUpReport | undefined;
@@ -339,6 +341,8 @@ type ThreeNamespace = typeof THREE_NS;
339
341
  type Object3D = THREE_NS.Object3D;
340
342
  type Mesh = THREE_NS.Mesh;
341
343
  type Quality = 'low' | 'medium' | 'high';
344
+ /** Why the renderer made a bound object a piece on its own (`RendererOptions.onLoosened`). */
345
+ type LoosenCause = 'blast' | 'apart' | 'ground';
342
346
  /** What a sound key carries besides the point and the volume: the named explosion and its size, how enclosed it was, how long a leak lasts. */
343
347
  interface SoundDetail {
344
348
  /** An impact or a break: the keys to try before the key itself, most specific first (material and blow, material, family and blow, family). */
@@ -437,7 +441,7 @@ interface RendererOptions {
437
441
  * Run one explosion on a small throwaway wall once, when the first renderer is made, so the code the first real explosion needs (fracture, split, oriented boxes, engine bodies,
438
442
  * the ground under the pieces) is not cold: the first one costs about twice the later ones without it. Off screen, in a world and a renderer of its own, all freed; the game's
439
443
  * state and random streams are not touched. Default on, once per process and engine; `false` turns it off. Give `{ engine }` (the `PhysicsEngine` the host made its world from)
440
- * to heat the engine's own paths too; without it the kit's own solver and the code the engines share are what runs.
444
+ * to heat the engine's own paths too; without it there is no warm-up.
441
445
  */
442
446
  jitWarmUp?: boolean | JitWarmUpOptions;
443
447
  /** Upper bound of live particles (default 2500). */
@@ -450,13 +454,13 @@ interface RendererOptions {
450
454
  /** Ground height at (x, z) for fragments, pieces and drips (default 0). */
451
455
  groundAt?: (x: number, z: number) => number;
452
456
  /**
453
- * The terrain alone at (x, z): soil, lot, street, crater; never the top of a table or the floor of a house. With an engine (`physics` other than `'own'`) the ground it stands the pieces
454
- * on is this, because every drawn fixed thing is a body of its own there (`staticSolids`) and a top in both would be ground twice. Default `groundAt`; the kit's own solver ignores it.
457
+ * The terrain alone at (x, z): soil, lot, street, crater; never the top of a table or the floor of a house. The ground the engine stands the pieces
458
+ * on is this, because every drawn fixed thing is a body of its own there (`staticSolids`) and a top in both would be ground twice. Default `groundAt`.
455
459
  */
456
460
  terrainAt?: (x: number, z: number) => number;
457
461
  /**
458
462
  * The rolling resistance (C_rr) of the terrain's surface at (x, z), from its material (`TerrainMaterial.rolling`: grass, soil and sand hold a rolling can or rod back far
459
- * more than asphalt), or undefined for the default (0.015, a hard floor). Read at the middle of the 2 m tile the point is in, the same in both solvers; only where a round
463
+ * more than asphalt), or undefined for the default (0.015, a hard floor). Read at the middle of the 2 m tile the point is in; only where a round
460
464
  * piece stands on the terrain itself (not on a top, a fixed thing or another piece). A round piece rolls by the larger of its own and this one.
461
465
  */
462
466
  terrainRollingAt?: (x: number, z: number) => number | undefined;
@@ -523,8 +527,11 @@ interface RendererOptions {
523
527
  * reaches with enough speed, the renderer makes it a piece (`makePiece`) and shoves it, and tells `onLoosened`. Without it only the pieces move. Never answer true for a wall or a fixture.
524
528
  */
525
529
  shoveable?: (objectId: string) => boolean;
526
- /** Called when the renderer made a bound object a piece on its own: a blast shoved it (`blast`, see `shoveable`), or furniture came apart and what stayed is loose too (`apart`). */
527
- onLoosened?: (objectId: string, piece: Piece, cause: 'blast' | 'apart') => void;
530
+ /**
531
+ * Called when the renderer made a bound object a piece on its own: a blast shoved it (`blast`, see `shoveable`), furniture came apart and what stayed is loose too (`apart`),
532
+ * or the ground under its feet went (`ground`: a hole dug or blown under a leg of a bed, see `wakeRegion`) and it goes over into the gap.
533
+ */
534
+ onLoosened?: (objectId: string, piece: Piece, cause: LoosenCause) => void;
528
535
  /**
529
536
  * After each break of a bound object (a part broke, came off, burned out or the object fell apart) the renderer checks it on the next update: what is left of an object that
530
537
  * is not a piece must stand on something (the ground, a fixed top, a piece). One left over air is made a piece on the spot and falls (`released` true); either way the host
@@ -686,6 +693,11 @@ interface DestructionRenderer {
686
693
  * taller and kick what is light.
687
694
  */
688
695
  solidsNear(x: number, z: number, radius: number): SolidBox[];
696
+ /**
697
+ * Gives the physics engine fixed bodies of a module that has no bound object (a house's walls): the boxes as `source` says them, asked every update, under the name `id`. Null takes
698
+ * them away. A world with no engine ignores them.
699
+ */
700
+ setHostSolids(id: string, source: (() => readonly HostSolid[]) | null): void;
689
701
  /** Push a piece (throws, blasts). */
690
702
  impulse(objectId: string, impulse: Vec3, point?: Vec3): void;
691
703
  /** Integrate fragments, pieces and particles; apply pending visual changes. Call once per frame after `world.update`. */
@@ -923,6 +935,18 @@ type BlastPacer = {
923
935
  */
924
936
  declare function createBlastPacer(options: BlastPacerOptions): BlastPacer;
925
937
 
938
+ /**
939
+ * One solid a mesh was built from (spec 019): its own box in the mesh's space, turned as it was drawn (`rotation`: x, y, z, w). The builder of the mesh lists them in
940
+ * `userData.solids` (`ShapeSolid` of game-shapes, by the mesh api of game-interactables-three): the piece is then held by what was drawn, with no vertex read back.
941
+ */
942
+ interface BuiltSolid {
943
+ readonly center: readonly [number, number, number];
944
+ readonly half: readonly [number, number, number];
945
+ readonly rotation: readonly [number, number, number, number];
946
+ /** What drew it (`'box'`, `'cylinder'`...): a cylinder is held as a cylinder along its own y. */
947
+ readonly kind?: string;
948
+ }
949
+
926
950
  /**
927
951
  * One fixed drawn part to measure (`measureStaticPart`): plain arrays, so it crosses to a worker (`destruction.static-colliders`). The main thread reads the vertices,
928
952
  * the triangles and the mesh's world matrix (with three's own `decompose` of it); the measuring is here.
@@ -939,10 +963,12 @@ interface StaticPartJob {
939
963
  /** The triangles of the part as vertex numbers of the host (three each), `from` its first vertex. */
940
964
  readonly found: Uint32Array;
941
965
  readonly from: number;
966
+ /** The solids the mesh was built from (`builtSolidsOf`), in the mesh's frame: with them the part is those boxes, and nothing is measured. */
967
+ readonly solids?: readonly BuiltSolid[];
942
968
  }
943
969
  /**
944
- * What a fixed drawn part collides as, in world space, for an engine: one box turned as drawn where a box fits it (every corner has a vertex within `FIT` and its
945
- * triangles cover its faces), else the box turned to fit the world vertices where that one fits, else the triangles as drawn (`mesh`, static only). A part collapsed to
970
+ * What a fixed drawn part collides as, in world space, for an engine: one box turned as drawn where a box fits it (every corner has a vertex within `FIT`, its
971
+ * triangles cover its faces and enclose `SOLID` of it), else the box turned to fit the world vertices where that one fits, else the triangles as drawn (`mesh`, static only). A part collapsed to
946
972
  * a point is nothing (`CLAUDE.md` §12). A pure function of the job: the worker and the main thread give the same bits (`staticCollidersKind`).
947
973
  */
948
974
  declare function measureStaticPart(job: StaticPartJob): StaticSolid[];
@@ -1221,4 +1247,4 @@ declare function blastFireSampleBank(manifest: SfxManifest, options?: BlastFireS
1221
1247
  /** Every particle kind the renderer can emit (the game's sprite kinds, see `@adatechnology/game-vfx`). */
1222
1248
  type ParticleKind = SpriteKind;
1223
1249
 
1224
- export { BIG_BLAST_RADIUS, BLAST_DEBRIS_DEFAULTS, BLAST_FALLOFF, BLAST_FAR_DISTANCE, BLAST_FAR_FALLOFF, BLAST_FIRE_SAMPLES, BLAST_KINDS, BLAST_KIND_OF, BLAST_RAYS_PER_FRAME, BLAST_SOUNDS, BLAST_SOUND_OF, BLAST_WAVE_PARTS_PER_FRAME, BURN_LOOP, type BindOptions, type BlastDebrisOptions, type BlastFireSampleBankOptions, type BlastFireSampleDefaults, type BlastKind, type BlastPacer, type BlastPacerOptions, type BlastWake, DEFAULT_CRACKLES, DEFAULT_FIRE, DEFAULT_INDOOR_CONFINEMENT, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, DESTRUCTION_VOICE_GROUPS, DRAG_SOUNDS, type DebrisCostOptions, type DebrisCostSample, type DeferredQueueRegistration, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EVENT_APPLY_WEIGHT, EVENT_CLASS, EXPLOSION_BOOM, type EventClass, type ExplodeOptions, type ExplosionWorkOptions, FIRE_FADE_SECONDS, FIRE_FALLOFF, FIRE_LOOP, FIRE_SOUNDS, type FarDebrisAction, type FarDebrisOptions, type FragmentLifeRule, GRENADE_PIN_PULL, GROUND_WORKER_FRAMES, type GroundPatchRead, type GroundTileJob, type GroundTileResult, type GroundWorkerPort, IMPACT_BURST_GROUP, IMPACT_FAMILY_TAGS, IMPACT_SOUNDS, IMPACT_SOUND_KEYS, type ImpactFamily, type ImpactKeys, type JitWarmUpOptions, type JitWarmUpReport, type LooseBody, MIN_PIECE_MASS_KG, type MakePieceOptions, type Mesh, type MeshRange, type Object3D, type PacedBlast, type PartHint, type ParticleKind, PhysicsOptionError, type Piece, type PiecePhysics, type Quality, ROCKET_MOTOR_LOOP, type RendererOptions, type ResolvedBlastDebris, SCENE_SOUNDS, SETTLED_BATCH_DEFAULTS, SETTLED_BATCH_ORIGIN, SMOKE_HISS_LOOP, STRUCTURAL_UNITS_PER_FRAME, SUGGESTED_MAX_AWAKE_FRAGMENTS, SUGGESTED_MAX_AWAKE_PIECES, type SettledBatchOptions, type SettledBatchStats, type SolidBox, type SoundDetail, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type StaticPartJob, type ThreeNamespace, WORK_UNIT_DEFAULTS, type WorkUnitCosts, bandLength, blastFireSampleBank, blastSoundIds, breakSoundKeys, computeGroundTile, createBlastPacer, createCoordinatorGroundPort, createDestructionRenderer, createDestructionSound, createInlineGroundPort, createMainThreadGroundPort, createWorkerGroundPort, dragSoundKey, eventApplyWeight, groundTilesKind, heatColor, impactFamily, impactKey, impactSoundIds, impactSoundKeys, installGroundWorker, measureStaticPart, readGroundBand, readGroundPatch, resolveBlastDebris, resolveWorkUnitCosts, ricochetSoundKeys, shotKey, specFromObject3D, splitWorkUnits, staticCollidersKind, warmUpDestructionJit };
1250
+ export { BIG_BLAST_RADIUS, BLAST_DEBRIS_DEFAULTS, BLAST_FALLOFF, BLAST_FAR_DISTANCE, BLAST_FAR_FALLOFF, BLAST_FIRE_SAMPLES, BLAST_KINDS, BLAST_KIND_OF, BLAST_RAYS_PER_FRAME, BLAST_SOUNDS, BLAST_SOUND_OF, BLAST_WAVE_PARTS_PER_FRAME, BURN_LOOP, type BindOptions, type BlastDebrisOptions, type BlastFireSampleBankOptions, type BlastFireSampleDefaults, type BlastKind, type BlastPacer, type BlastPacerOptions, type BlastWake, DEFAULT_CRACKLES, DEFAULT_FIRE, DEFAULT_INDOOR_CONFINEMENT, DESTRUCTION_SOUND_BANK, DESTRUCTION_SOUND_KEYS, DESTRUCTION_VOICE_GROUPS, DRAG_SOUNDS, type DebrisCostOptions, type DebrisCostSample, type DeferredQueueRegistration, type DestructionRenderer, type DestructionSound, type DestructionSoundOptions, type DestructionSoundStyle, EVENT_APPLY_WEIGHT, EVENT_CLASS, EXPLOSION_BOOM, type EventClass, type ExplodeOptions, type ExplosionWorkOptions, FIRE_FADE_SECONDS, FIRE_FALLOFF, FIRE_LOOP, FIRE_SOUNDS, type FarDebrisAction, type FarDebrisOptions, type FragmentLifeRule, GRENADE_PIN_PULL, GROUND_WORKER_FRAMES, type GroundPatchRead, type GroundTileJob, type GroundTileResult, type GroundWorkerPort, IMPACT_BURST_GROUP, IMPACT_FAMILY_TAGS, IMPACT_SOUNDS, IMPACT_SOUND_KEYS, type ImpactFamily, type ImpactKeys, type JitWarmUpOptions, type JitWarmUpReport, type LooseBody, type LoosenCause, MIN_PIECE_MASS_KG, type MakePieceOptions, type Mesh, type MeshRange, type Object3D, type PacedBlast, type PartHint, type ParticleKind, PhysicsOptionError, type Piece, type PiecePhysics, type Quality, ROCKET_MOTOR_LOOP, type RendererOptions, type ResolvedBlastDebris, SCENE_SOUNDS, SETTLED_BATCH_DEFAULTS, SETTLED_BATCH_ORIGIN, SMOKE_HISS_LOOP, STRUCTURAL_UNITS_PER_FRAME, SUGGESTED_MAX_AWAKE_FRAGMENTS, SUGGESTED_MAX_AWAKE_PIECES, type SettledBatchOptions, type SettledBatchStats, type SolidBox, type SoundDetail, type SoundKeyRule, type SpecFromObjectOptions, type SpecFromObjectResult, type StaticPartJob, type ThreeNamespace, WORK_UNIT_DEFAULTS, type WorkUnitCosts, bandLength, blastFireSampleBank, blastSoundIds, breakSoundKeys, computeGroundTile, createBlastPacer, createCoordinatorGroundPort, createDestructionRenderer, createDestructionSound, createInlineGroundPort, createMainThreadGroundPort, createWorkerGroundPort, dragSoundKey, eventApplyWeight, groundTilesKind, heatColor, impactFamily, impactKey, impactSoundIds, impactSoundKeys, installGroundWorker, measureStaticPart, readGroundBand, readGroundPatch, resolveBlastDebris, resolveWorkUnitCosts, ricochetSoundKeys, shotKey, specFromObject3D, splitWorkUnits, staticCollidersKind, warmUpDestructionJit };