@adatechnology/game-items-three 0.1.5 → 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
@@ -20,3 +20,8 @@ scene.add(buildItemLod(THREE, items.get('hammer')).root) // merged, with LOD an
20
20
  ```
21
21
 
22
22
  three.js is a peer dependency (`^0.160`). The global of the IIFE build is `GameItemsThree`.
23
+
24
+ The geometry comes from [`game-shapes`](../game-shapes): the kit's `T` is `shapeGeometries(THREE)`, so the ported builders keep writing
25
+ `new T.CylinderGeometry(...)` and get the same bytes from game-shapes' template cache (a tube still comes from three), and `mergeItem` joins on
26
+ `game-shapes-three`. `tests/exact-golden.test.ts` holds every bit of the 24 models and 25 shapes (alone, merged, half detail, LOD) as the old
27
+ path made them.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as THREE_NS from 'three';
2
- import { Thumbnail, Vec3, AreaPlacement, TestableModule } from '@adatechnology/game-contracts';
2
+ import { ContainerSpec, Thumbnail, Vec3, AreaPlacement, TestableModule } from '@adatechnology/game-contracts';
3
3
  import { FindStack, ItemsCatalog, FindsProvider } from '@adatechnology/game-items';
4
4
 
5
5
  type Three = typeof THREE_NS;
@@ -16,7 +16,9 @@ interface ItemMaterialData {
16
16
  type Vec3Tuple = readonly [number, number, number];
17
17
  /**
18
18
  * The helpers the showcase page defines before its models (`M`, `mesh`, `cyl`, `bx`, `lathe`, `torus`, `extrude`, `G` and the seven material makers), so that the
19
- * builders ported from the page read the same as the originals. `T` is the three.js the kit was made with; `materials` lists every material it made, in order.
19
+ * builders ported from the page read the same as the originals. `T` is the three.js the kit was made with, with its box, cylinder, cone, sphere, plane, lathe, torus and
20
+ * (straight-edged) extrude geometries made by game-shapes (`shapeGeometries`: the same bytes, the same classes, a template cache); `materials` lists every material it made,
21
+ * in order.
20
22
  */
21
23
  interface ItemKit {
22
24
  readonly T: Three;
@@ -38,7 +40,7 @@ interface ItemKit {
38
40
  glass(color: number, opacity: number): THREE_NS.MeshStandardMaterial;
39
41
  }
40
42
  /** The helpers of the showcase page on a given three.js; every kit has its own list of materials. */
41
- declare function createItemKit(T: Three): ItemKit;
43
+ declare function createItemKit(three: Three): ItemKit;
42
44
 
43
45
  /** 0 new, 1 used, 2 spoiled (the three stages of the showcase). */
44
46
  type WearStage = 0 | 1 | 2;
@@ -101,6 +103,8 @@ interface DrawableItem extends ShapeSubject {
101
103
  size: Vec3Tuple;
102
104
  /** Key of a showcase model; without one (or when the model is not registered) the simple shape is drawn. */
103
105
  model?: string;
106
+ /** Real weight in kg; with `destructible` it becomes the mass of the destruction body. */
107
+ weight?: number;
104
108
  }
105
109
  interface BuildItemOptions {
106
110
  /** Wear of the materials, 0 new (default), 1 used, 2 spoiled. */
@@ -109,6 +113,8 @@ interface BuildItemOptions {
109
113
  simple?: boolean;
110
114
  /** Level of detail of the simple shape, 1 (default) or 0.5 for half the segments. */
111
115
  detail?: number;
116
+ /** Write the `userData` that `game-destruction-three`'s `specFromObject3D` reads (material of each mesh, hollow shells, welded parts, skins; see `tagForDestruction`). Default off. */
117
+ destructible?: boolean;
112
118
  /** A kit to draw with (and to collect the materials in); default a new one. */
113
119
  kit?: ItemKit;
114
120
  }
@@ -131,6 +137,82 @@ interface ItemModel {
131
137
  */
132
138
  declare function buildItem(T: typeof THREE_NS, item: DrawableItem, options?: BuildItemOptions): ItemModel;
133
139
 
140
+ /** The destruction material (`game-destruction` id) of each material tag of the kit, for a mesh whose model says nothing else. */
141
+ declare const DESTRUCTION_MATERIAL_BY_TAG: Readonly<Record<string, string>>;
142
+ /** How a model behaves under `game-destruction-three`'s `specFromObject3D`, as `data/destruction.json` keeps it. */
143
+ interface ItemDestruction {
144
+ /** The meshes are thin shells, not solid blocks. */
145
+ readonly hollow?: boolean;
146
+ /** The parts of the model are welded to its largest mesh, so a hit dents and holes them instead of tearing them off. */
147
+ readonly welded?: boolean;
148
+ /** Meshes made of these material tags are skins (labels, coats): drawn on a part, never a part of their own. */
149
+ readonly skinTags?: readonly string[];
150
+ /** Material tag to destruction material id, over `DESTRUCTION_MATERIAL_BY_TAG`. */
151
+ readonly materials?: Readonly<Record<string, string>>;
152
+ /** Segments the cylinder and box meshes of the model are rebuilt with, so a bullet dent (a few millimetres wide) finds vertices to push in. */
153
+ readonly tessellate?: {
154
+ readonly cylinder?: {
155
+ readonly heightSegments: number;
156
+ readonly radialSegments: number;
157
+ };
158
+ readonly box?: {
159
+ readonly widthSegments: number;
160
+ readonly heightSegments: number;
161
+ readonly depthSegments: number;
162
+ };
163
+ };
164
+ }
165
+ /** A family of models that behave alike: one rule for all of them, so adding a model is one id and changing the rule changes them all. */
166
+ interface ItemFamily {
167
+ readonly models: readonly string[];
168
+ readonly rule: ItemDestruction;
169
+ }
170
+ /** What a model holds inside its shell: a liquid (`game-fluids` id) filling `fill` of the inner volume. */
171
+ interface ItemContents {
172
+ readonly liquid: string;
173
+ readonly fill: number;
174
+ /** The shell is a box (a flat tin) and not a cylinder. */
175
+ readonly box?: boolean;
176
+ }
177
+ /** Id of the family a model belongs to (`drink_can`), if any. */
178
+ declare const itemFamily: (modelId: string) => string | undefined;
179
+ declare const itemDestruction: (modelId: string) => ItemDestruction | undefined;
180
+ /** The family ids and their models, as the data gives them. */
181
+ declare const ITEM_FAMILIES: Readonly<Record<string, ItemFamily>>;
182
+ /** The subject of `itemContents`: what `buildItem` draws. */
183
+ interface ContentsSubject {
184
+ readonly model?: string;
185
+ /** Metres. */
186
+ readonly size: readonly [number, number, number];
187
+ /** Kg, shell included. */
188
+ readonly weight?: number;
189
+ }
190
+ /** Id of the welded part that is the whole shell of a container. */
191
+ declare const SHELL_PART_ID = "shell";
192
+ /**
193
+ * The container the model holds (`TestableItem.fluid` of the test room and `PartSpec.contains` of the shell), sized from the item: the inner volume of its
194
+ * box times the fill of the model, never more than the item weighs in that liquid. Undefined for a model that holds nothing.
195
+ */
196
+ declare function itemContents(subject: ContentsSubject): {
197
+ readonly container: ContainerSpec;
198
+ readonly liquid: string;
199
+ readonly liters: number;
200
+ } | undefined;
201
+ /** What `tagForDestruction` needs to know about the item beside its meshes. */
202
+ interface DestructionTagOptions {
203
+ readonly modelId?: string;
204
+ /** Real weight in kg. */
205
+ readonly weight?: number;
206
+ /** Size in metres, for the contents of the shell. */
207
+ readonly size?: readonly [number, number, number];
208
+ }
209
+ /**
210
+ * Writes the `userData` that `specFromObject3D` reads onto the meshes of a drawn item: the destruction material of each mesh from its kit material tag,
211
+ * the item's real weight in kg (`destructionMass`, so the world weighs what the thing weighs) and what the model's family in `data/destruction.json` asks for (hollow shells, welded parts, skins),
212
+ * with the liquid the model holds on its shell (`destructionContains`).
213
+ */
214
+ declare function tagForDestruction(root: THREE_NS.Object3D, options?: DestructionTagOptions): void;
215
+
134
216
  /**
135
217
  * The same item with its meshes joined by material: one mesh and one draw call per material instead of one per part (the "one material for all the items" of the page's
136
218
  * budget, as far as the materials of the kit allow). The materials are the same objects, so `setWear` still reaches them. The model's scale stays on the root.
@@ -378,4 +460,4 @@ interface ScenarioLike {
378
460
  expect(condition: boolean, label: string, data?: Record<string, unknown>): void;
379
461
  }
380
462
 
381
- export { type BudgetReport, type BuildItemOptions, type DrawableItem, FINDS_TABLE_ID, HUMAN_HEIGHT, HUMAN_ID, ITEM_BUDGETS, ITEM_PREFIX, type ItemBudgets, type ItemKit, type ItemLod, type ItemLodOptions, type ItemMaterialData, type ItemModel, type ItemModelBuilder, type ItemModelEntry, type ItemSizeClass, type ItemsAreaState, type ItemsTestModule, type ItemsTestModuleOptions, type LayoutItem, MODEL_BUDGET_DEVIATIONS, ROW_LIMIT, RULER_HEIGHT, RULER_ID, SHAPES, SHELF_HEIGHT, SHELF_PREFIX, SHIPPED_MODELS, SHOWCASE_PREFIX, SHOWCASE_STAND_ID, type ScenarioLike, type ShapeContext, type ShapeId, type ShapeSubject, type ShelfPlan, type ThumbnailRenderOptions, type ThumbnailRenderer, type ThumbnailScene, type Vec3Like, type Vec3Tuple, WEAR_AMOUNT, WEAR_TAGS, WEAR_TARGET, type WearStage, type WearTag, buildItem, buildItemLod, canonicalFrame, checkBudget, composeThumbnailScene, countDrawCalls, countTriangles, createItemKit, createItemsTestModule, cullDistanceOf, drawShape, hasItemModel, isShape, itemModelBuilder, itemModelEntry, itemThumbnail, itemThumbnailSvg, listItemModels, mergeItem, registerItemModel, renderItemThumbnail, setWear, shade, shapeOf, shapeThumbnailSvg, shelvesLayout, sizeClassOf, thumbnailPatch, triangleBudgetOf, unregisterItemModel, wearableMaterials };
463
+ export { type BudgetReport, type BuildItemOptions, type ContentsSubject, DESTRUCTION_MATERIAL_BY_TAG, type DestructionTagOptions, type DrawableItem, FINDS_TABLE_ID, HUMAN_HEIGHT, HUMAN_ID, ITEM_BUDGETS, ITEM_FAMILIES, ITEM_PREFIX, type ItemBudgets, type ItemContents, type ItemDestruction, type ItemFamily, type ItemKit, type ItemLod, type ItemLodOptions, type ItemMaterialData, type ItemModel, type ItemModelBuilder, type ItemModelEntry, type ItemSizeClass, type ItemsAreaState, type ItemsTestModule, type ItemsTestModuleOptions, type LayoutItem, MODEL_BUDGET_DEVIATIONS, ROW_LIMIT, RULER_HEIGHT, RULER_ID, SHAPES, SHELF_HEIGHT, SHELF_PREFIX, SHELL_PART_ID, SHIPPED_MODELS, SHOWCASE_PREFIX, SHOWCASE_STAND_ID, type ScenarioLike, type ShapeContext, type ShapeId, type ShapeSubject, type ShelfPlan, type ThumbnailRenderOptions, type ThumbnailRenderer, type ThumbnailScene, type Vec3Like, type Vec3Tuple, WEAR_AMOUNT, WEAR_TAGS, WEAR_TARGET, type WearStage, type WearTag, buildItem, buildItemLod, canonicalFrame, checkBudget, composeThumbnailScene, countDrawCalls, countTriangles, createItemKit, createItemsTestModule, cullDistanceOf, drawShape, hasItemModel, isShape, itemContents, itemDestruction, itemFamily, itemModelBuilder, itemModelEntry, itemThumbnail, itemThumbnailSvg, listItemModels, mergeItem, registerItemModel, renderItemThumbnail, setWear, shade, shapeOf, shapeThumbnailSvg, shelvesLayout, sizeClassOf, tagForDestruction, thumbnailPatch, triangleBudgetOf, unregisterItemModel, wearableMaterials };