@adatechnology/game-destruction-three 0.7.2 → 0.8.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 +10 -0
- package/dist/index.d.ts +18 -2
- package/dist/index.global.js +558 -144
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +282 -49
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -71,6 +71,12 @@ renderer.impulse(id, [0, 40, -120], [2, 0.6, -3])
|
|
|
71
71
|
equals a part id, else by the part box that contains the mesh centre. `specFromObject3D` reads `userData.destructionMaterial`,
|
|
72
72
|
`destructionPart` (a part id, or `{ id, material?, parent?, kind? }`: `parent` + `kind` attach the part to its parent with a joint of that kind), `destructionIgnore`, `destructionTags` and `hollow`.
|
|
73
73
|
|
|
74
|
+
For picking, `bind` and the loose pieces write back to the meshes: every mesh of a part has `userData.destructionPart` (the part id) and
|
|
75
|
+
`userData.destructionObject` (the id of the world object the part belongs to now; a loose piece made by `splitGroup` has an id of its own, the same one
|
|
76
|
+
`renderer.piece(id)` and `world.state(id)` use), also on the mesh a vertex-range part gets when it leaves a merged mesh. A raycast hit goes to
|
|
77
|
+
`world.hitPart(hit.object.userData.destructionObject, hit.object.userData.destructionPart, ...)`. Purely visual meshes (fracture fragments, decals, ground
|
|
78
|
+
stains) have `userData.destructionDebris = true`: skip them when picking. Parts drawn by a range of a merged mesh share it, so the merged mesh itself carries no part id.
|
|
79
|
+
|
|
74
80
|
### Parts of a merged mesh
|
|
75
81
|
|
|
76
82
|
A building or a baked model often has one merged mesh for many parts. Bind each part by the vertex range it occupies (`{ mesh, range: [v0, v1] }`,
|
|
@@ -114,6 +120,10 @@ loose meshes. An invalid range (outside the geometry or empty) throws from `bind
|
|
|
114
120
|
| `leak` | stream of drops (or a faint puff for gas) from the hole while the part still has liters | |
|
|
115
121
|
| `explode` | flash, fire, smoke, dust and sparks, a pooled `PointLight` pulse, impulses on pieces and fragments in range | `explode` |
|
|
116
122
|
|
|
123
|
+
`settle` (an object with `DestructibleSpec.soil` settled or tilted): on the first one the renderer moves the children of the bound root under a group named
|
|
124
|
+
`destruction-soil` and gives it `ObjectState.soil.offset`, updated every frame while the soil yields; the root keeps the host's pose, which is what
|
|
125
|
+
`syncTransform` keeps sending to the world.
|
|
126
|
+
|
|
117
127
|
`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.
|
|
118
128
|
|
|
119
129
|
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' })`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as THREE_NS from 'three';
|
|
2
2
|
import { Vec3, DebrisKind, HitResult, DestructionWorld, MaterialId, DestructibleSpec } from '@adatechnology/game-destruction';
|
|
3
3
|
export { Quat, Vec3 } from '@adatechnology/game-destruction';
|
|
4
|
+
import { WarmUpProbes, BlastShoveOptions, Vec3 as Vec3$1 } from '@adatechnology/game-contracts';
|
|
4
5
|
import { VfxWorld, SpriteKind } from '@adatechnology/game-vfx';
|
|
5
6
|
import { LoopRecipe, SoundBank, SoundRecipe, AudioEngine } from '@adatechnology/game-audio';
|
|
6
|
-
import { Vec3 as Vec3$1 } from '@adatechnology/game-contracts';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Public types of @adatechnology/game-destruction-three.
|
|
@@ -36,6 +36,18 @@ interface RendererOptions {
|
|
|
36
36
|
autoSplit?: boolean;
|
|
37
37
|
/** Called when a loose piece is created (the bench registers it as grabbable). */
|
|
38
38
|
onPiece?: (piece: Piece) => void;
|
|
39
|
+
/**
|
|
40
|
+
* 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).
|
|
41
|
+
* The defaults give the pieces the speed the blast always gave them, with the cap lowered to 20 m/s.
|
|
42
|
+
*/
|
|
43
|
+
blastShove?: BlastShoveOptions;
|
|
44
|
+
/**
|
|
45
|
+
* Bound objects that have no piece but that a blast may move anyway (a fridge, a table: heavy, so not grabbable, but not nailed down either): when this answers true for an object a blast
|
|
46
|
+
* 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.
|
|
47
|
+
*/
|
|
48
|
+
shoveable?: (objectId: string) => boolean;
|
|
49
|
+
/** Called when a blast made a bound object a piece (see `shoveable`). */
|
|
50
|
+
onLoosened?: (objectId: string, piece: Piece) => void;
|
|
39
51
|
/** 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. */
|
|
40
52
|
onSound?: (key: string, point: Vec3, volume: number) => void;
|
|
41
53
|
/**
|
|
@@ -142,6 +154,8 @@ interface DestructionRenderer {
|
|
|
142
154
|
pieces: number;
|
|
143
155
|
decals: number;
|
|
144
156
|
};
|
|
157
|
+
/** 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. */
|
|
158
|
+
warmUpProbes(): WarmUpProbes;
|
|
145
159
|
/** Bars of exposed rebar drawn now (`expose` events; one instanced mesh per part). */
|
|
146
160
|
rebarCount(): number;
|
|
147
161
|
dispose(): void;
|
|
@@ -180,9 +194,11 @@ interface PartHint {
|
|
|
180
194
|
}
|
|
181
195
|
/**
|
|
182
196
|
* Build a `DestructibleSpec` from a three.js object: one part per mesh (meshes sharing `userData.destructionPart` become one part), each an
|
|
183
|
-
* axis-aligned box in the root's
|
|
197
|
+
* axis-aligned box in metres in the root's frame (its position and rotation removed, its world scale kept; rotation omitted), with the material taken from `options.materialOf`, `userData.destructionMaterial`
|
|
184
198
|
* or a guess from the names. Tiny meshes are merged into the part they overlap most; joints are inferred from touching parts.
|
|
185
199
|
*
|
|
200
|
+
* `userData.destructionContains` (`{ fluid, liters }`) makes the part a container: a hole through it leaks. `root.userData.destructionMass` (kg) fixes the total mass, split between the parts in proportion to their volume, density and fill.
|
|
201
|
+
* A mesh with `userData.destructionSkin` (a label, a coat) joins the part it overlaps most instead of becoming a part: it stays drawn and bound to that part (decals, dents) but never breaks off.
|
|
186
202
|
* Meshes that are invisible or have `userData.destructionIgnore` (or sit under such an object) are skipped. The result also tells which meshes
|
|
187
203
|
* became which part, ready to be passed to `bind`.
|
|
188
204
|
*/
|