@adatechnology/game-destruction-three 0.1.1 → 0.2.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
@@ -71,6 +71,27 @@ 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
+ ### Parts of a merged mesh
75
+
76
+ 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] }`,
77
+ end exclusive; a part value can also be an array mixing meshes and ranges):
78
+
79
+ ```js
80
+ renderer.bind(houseId, houseRoot, { parts: {
81
+ wall_north: { mesh: merged, range: [0, 1280] },
82
+ wall_south: { mesh: merged, range: [1280, 2610] },
83
+ door: doorMesh, // plain meshes still work
84
+ } })
85
+ ```
86
+
87
+ For indexed geometry the faces whose three vertices all lie in the range belong to the part; for non-indexed geometry the range is the part's
88
+ triangles. Dents move only the range's vertices; char and heat go to the range's vertex colours (the mesh gets a `color` attribute, and a cloned
89
+ material with `vertexColors`, when it has none); hole and crack decals stay on the part; melt squashes and widens only the range. When the part
90
+ detaches or collapses (`detach` and `collapse` events), its faces are copied, with their dents and colours and the merged mesh's transform and
91
+ material, into a new mesh that becomes the loose piece, and the range is collapsed to a point in the merged mesh so it vanishes there. A broken,
92
+ 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
93
+ loose meshes. An invalid range (outside the geometry or empty) throws from `bind`.
94
+
74
95
  ## What each event draws
75
96
 
76
97
  | Event | Visual | Sound key |
package/dist/index.d.ts CHANGED
@@ -43,13 +43,29 @@ interface RendererOptions {
43
43
  */
44
44
  pointScale?: number;
45
45
  }
46
+ /**
47
+ * A part drawn by a range of the vertices of a mesh it shares with other parts (a merged house, a baked car body). `range` is `[v0, v1)`: vertex
48
+ * indices of the mesh's geometry, the end exclusive. For indexed geometry the faces whose three vertices all lie in the range belong to the part;
49
+ * for non-indexed geometry the range is the part's triangles (three vertices each).
50
+ *
51
+ * Dents, char and heat colours (through vertex colours: the mesh gets a `color` attribute and its material `vertexColors` when it has none) and
52
+ * melt change only that range, and hole and crack decals are attached to the part. When the part detaches or collapses, its faces are copied
53
+ * into a new mesh with the merged mesh's transform and material (a loose piece) and the range is collapsed to a point in the merged mesh, so it
54
+ * disappears from there. A broken, melted or burnt-out part collapses too. `restore` and `clear` give the merged mesh its original geometry and
55
+ * material back and remove the loose meshes.
56
+ */
57
+ interface MeshRange {
58
+ mesh: Mesh;
59
+ /** Vertex index range `[v0, v1)` of `mesh.geometry`. */
60
+ range: [number, number];
61
+ }
46
62
  /** Options of `bind`. */
47
63
  interface BindOptions {
48
64
  /**
49
- * Part id -> meshes that draw it. When omitted, every Mesh under the root with `userData.destructionPart` (or whose name equals a part id) is
65
+ * Part id -> meshes that draw it (a mesh or group, a list of them, a `MeshRange`, or a list mixing both). When omitted, every Mesh under the root with `userData.destructionPart` (or whose name equals a part id) is
50
66
  * used; meshes with neither are matched to the part whose box contains the mesh's bounding-box centre.
51
67
  */
52
- parts?: Record<string, Object3D | Object3D[]>;
68
+ parts?: Record<string, Object3D | MeshRange | Array<Object3D | MeshRange>>;
53
69
  /** Keep the world transform in sync from the root's matrixWorld every update (default true). */
54
70
  syncTransform?: boolean;
55
71
  }
@@ -149,4 +165,4 @@ declare function heatColor(temperatureC: number): number;
149
165
  /** Every particle kind the renderer can emit. */
150
166
  type ParticleKind = DebrisKind | 'fire' | 'flash' | 'foam';
151
167
 
152
- export { type BindOptions, type DestructionRenderer, type Mesh, type Object3D, type PartHint, type ParticleKind, type Piece, type Quality, type RendererOptions, type SpecFromObjectOptions, type SpecFromObjectResult, type ThreeNamespace, createDestructionRenderer, heatColor, specFromObject3D };
168
+ 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 };