@adatechnology/game-items-three 0.13.0 → 0.14.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/dist/{chunk-FCEKW7F6.js → chunk-XJG7IGO3.js} +124 -7
- package/dist/chunk-XJG7IGO3.js.map +1 -0
- package/dist/index.d.ts +19 -9
- package/dist/index.global.js +663 -432
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/{testing-DbKHUIwv.d.ts → testing-C96KjBjB.d.ts} +5 -3
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +12 -12
- package/dist/chunk-FCEKW7F6.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -69,17 +69,23 @@ import {
|
|
|
69
69
|
triangleBudgetOf,
|
|
70
70
|
turnItem,
|
|
71
71
|
unregisterItemModel,
|
|
72
|
+
wearOfAge,
|
|
73
|
+
wearOfFreshness,
|
|
72
74
|
wearableMaterials
|
|
73
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-XJG7IGO3.js";
|
|
74
76
|
|
|
75
77
|
// src/contained.ts
|
|
76
78
|
function createContainedItemModel(items, options = {}) {
|
|
79
|
+
const { rules, ...build } = options;
|
|
77
80
|
const byId = /* @__PURE__ */ new Map();
|
|
78
81
|
for (const item of items) byId.set(item.id, item);
|
|
79
82
|
return (stack, T) => {
|
|
80
83
|
const item = byId.get(stack.type);
|
|
81
84
|
if (!item) return null;
|
|
82
|
-
const
|
|
85
|
+
const ageDays = stack.data?.["ageDays"];
|
|
86
|
+
const aged = typeof ageDays === "number" ? wearOfAge(item, ageDays, rules) : 0;
|
|
87
|
+
const wear = Math.max(build.wear ?? 0, aged);
|
|
88
|
+
const model = buildItem(T, item, wear > 0 ? { ...build, wear } : build);
|
|
83
89
|
model.root.userData.item = { id: item.id, kind: model.kind };
|
|
84
90
|
const dirt = stack.data?.["dirt"];
|
|
85
91
|
if (typeof dirt === "number" && dirt > 0) setItemDirt(T, model.root, dirt);
|
|
@@ -211,6 +217,8 @@ export {
|
|
|
211
217
|
triangleBudgetOf,
|
|
212
218
|
turnItem,
|
|
213
219
|
unregisterItemModel,
|
|
220
|
+
wearOfAge,
|
|
221
|
+
wearOfFreshness,
|
|
214
222
|
wearableMaterials
|
|
215
223
|
};
|
|
216
224
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contained.ts","../src/item-models.ts","../src/merge.ts","../src/lod.ts","../src/models/instance.ts"],"sourcesContent":["import type * as THREE_NS from 'three'\n\nimport { buildItem } from './build-item'\nimport type { BuildItemOptions, DrawableItem } from './build-item'\nimport { setItemDirt } from './wash'\n\n/** A stack held in a container (`ItemStack` of game-interactables): the item id and its free data. */\nexport interface ContainedStack {\n readonly type: string\n /** The stack's free data: `dirt` (0 clean to 1 caked) draws the food left on it (a plate left dirty in a sink). */\n readonly data?: Readonly<Record<string, unknown>>\n}\n\n/** What `createContainedItemModel` returns: the real model of a stack drawn with the caller's `THREE`, or null for an id the catalogue does not have. */\nexport type ContainedItemModel = (stack: ContainedStack, T: typeof THREE_NS) => THREE_NS.Object3D | null\n\n/**\n * The model of the items inside furniture, for `createContentsView` of game-interactables-three and `interactives.itemModel` of game-floorplan-three: each\n * stack is drawn by `buildItem` from the catalogue (the team's model where there is one, the item's own shape otherwise), never a stand-in. Every item gets its\n * own materials, so the view can discard it alone when it is taken. `root.userData.item` says what was drawn (`{ id, kind }`); a stack with `data.dirt` is drawn\n * dirty (`setItemDirt`), the same as the item once it is in the world.\n */\nexport function createContainedItemModel(items: Iterable<DrawableItem>, options: Omit<BuildItemOptions, 'kit'> = {}): ContainedItemModel {\n const byId = new Map<string, DrawableItem>()\n for (const item of items) byId.set(item.id, item)\n return (stack, T) => {\n const item = byId.get(stack.type)\n if (!item) return null\n const model = buildItem(T, item, options)\n model.root.userData.item = { id: item.id, kind: model.kind }\n const dirt = stack.data?.['dirt']\n if (typeof dirt === 'number' && dirt > 0) setItemDirt(T, model.root, dirt)\n return model.root\n }\n}\n","import { buildItem } from './build-item'\nimport { hasItemModel } from './models/registry'\n\n/** The item models as a source a weapon or an explosive can draw with (`ItemModels` of game-weapons-three): a host lends it as `items`. */\nexport const itemModels = { has: hasItemModel, build: buildItem } as const\n","import { mergeByMaterial } from '@adatechnology/game-shapes-three'\nimport type * as THREE_NS from 'three'\n\nimport type { ItemModel } from './build-item'\n\n/**\n * 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\n * 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.\n */\nexport function mergeItem(T: typeof THREE_NS, model: ItemModel): ItemModel {\n model.root.updateMatrixWorld(true)\n const merged = new T.Group()\n merged.name = model.root.name\n merged.scale.copy(model.root.scale)\n merged.userData = { ...model.root.userData }\n // baked into the space of the root, which leaves the root's own scale out of the geometry\n merged.add(...mergeByMaterial(T, model.root, model.root))\n return { ...model, root: merged }\n}\n","import type * as THREE_NS from 'three'\n\nimport { ITEM_BUDGETS, cullDistanceOf } from './budgets'\nimport type { ItemBudgets } from './budgets'\nimport { buildItem } from './build-item'\nimport type { BuildItemOptions, DrawableItem, ItemModel } from './build-item'\nimport { createItemKit } from './kit'\nimport { mergeItem } from './merge'\n\nexport interface ItemLodOptions extends Omit<BuildItemOptions, 'simple' | 'detail' | 'kit'> {\n budgets?: ItemBudgets\n /** Join the meshes of each level by material (default true). */\n merge?: boolean\n /** Distance of the second level in metres; default a third of the distance at which the item disappears. */\n lod1Distance?: number\n}\n\nexport interface ItemLod {\n /** Add this to the scene and call `update(camera)` (or let the renderer do it). */\n readonly root: THREE_NS.LOD\n /** Full detail: the showcase model, or the shape at full segments. */\n readonly near: ItemModel\n /** The simple shape at half the segments. */\n readonly far: ItemModel\n /** Metres from the camera at which the item is no longer drawn. */\n readonly cullDistance: number\n readonly lod1Distance: number\n}\n\n/**\n * Three levels of an item: the model (or the shape) up close, the simple shape at half the segments from `lod1Distance`, and nothing from the distance of its class\n * (a small item goes at 30 m, a large one at 60 m).\n */\nexport function buildItemLod(T: typeof THREE_NS, item: DrawableItem, options: ItemLodOptions = {}): ItemLod {\n const budgets = options.budgets ?? ITEM_BUDGETS\n const cullDistance = cullDistanceOf(item.size, budgets)\n const lod1Distance = options.lod1Distance ?? cullDistance / 3\n const joined = (model: ItemModel): ItemModel => (options.merge === false ? model : mergeItem(T, model))\n const wear = { ...(options.wear === undefined ? {} : { wear: options.wear }), ...(options.models === undefined ? {} : { models: options.models }) }\n const near = joined(buildItem(T, item, { ...wear, kit: createItemKit(T) }))\n const far = joined(buildItem(T, item, { ...wear, simple: true, detail: budgets.lod1Ratio, kit: createItemKit(T) }))\n const root = new T.LOD()\n root.name = item.id\n root.addLevel(near.root, 0)\n root.addLevel(far.root, lod1Distance)\n root.addLevel(new T.Group(), cullDistance)\n root.userData.wear = options.wear ?? 0\n return { root, near, far, cullDistance, lod1Distance }\n}\n","import { applyPatches, mergeById, removeIds } from '@adatechnology/game-contracts'\nimport type { DeepPartial, Thumbnail } from '@adatechnology/game-contracts'\nimport type * as THREE_NS from 'three'\n\nimport { buildItem } from '../build-item'\nimport { buildItemLod } from '../lod'\nimport type { ItemLod, ItemLodOptions } from '../lod'\nimport { itemThumbnail } from '../thumbnails'\nimport type { BuildItemOptions, DrawableItem, ItemModel } from '../build-item'\nimport { registryOver } from './registry'\nimport type { ItemModelBuilder, ItemModelEntry, ItemModelRegistry } from './registry'\nimport { SHIPPED_MODELS } from './shipped'\n\nexport interface ItemModelRecord {\n readonly entry: ItemModelEntry\n readonly builder: ItemModelBuilder\n}\n\nexport interface ItemModelsOptions {\n /** Models added to the shipped ones; one with the id of a shipped model replaces it. */\n readonly packs?: readonly (readonly ItemModelRecord[])[]\n /** Changes to an entry by item id (`scale`, `teamBox`), merged field by field. */\n readonly patch?: Readonly<Record<string, DeepPartial<ItemModelEntry>>>\n /** Item ids whose model is taken out (the item then gets its simple shape). */\n readonly remove?: readonly string[]\n}\n\nexport interface ItemModels extends ItemModelRegistry {\n /** `buildItem` that reads this set of models. */\n build(T: typeof THREE_NS, item: DrawableItem, options?: Omit<BuildItemOptions, 'models'>): ItemModel\n /** `buildItemLod` that reads this set of models. */\n buildLod(T: typeof THREE_NS, item: DrawableItem, options?: Omit<ItemLodOptions, 'models'>): ItemLod\n /** `itemThumbnail` that asks this set whether the item has a model. */\n thumbnail(item: DrawableItem): Thumbnail\n}\n\ntype Keyed = ItemModelRecord & { readonly id: string }\n\n/** A set of item models of its own: the shipped ones plus `packs`, `patch` and `remove`. Nothing is shared with any other set on the page. */\nexport function createItemModels(options: ItemModelsOptions = {}): ItemModels {\n const keyed = (record: ItemModelRecord): Keyed => ({ ...record, id: record.entry.id })\n const records = mergeById(SHIPPED_MODELS.map(keyed), (options.packs ?? []).flat().map(keyed))\n applyPatches(records, Object.fromEntries(Object.entries(options.patch ?? {}).map(([id, entry]) => [id, { entry }])) as Readonly<Record<string, DeepPartial<Keyed>>>)\n removeIds(records, options.remove)\n const registry = registryOver(new Map([...records].map(([id, record]) => [id, record.entry])), new Map([...records].map(([id, record]) => [id, record.builder])))\n const models: ItemModels = {\n ...registry,\n build: (T, item, buildOptions = {}) => buildItem(T, item, { ...buildOptions, models: registry }),\n buildLod: (T, item, lodOptions = {}) => buildItemLod(T, item, { ...lodOptions, models: registry }),\n thumbnail: (item) => itemThumbnail(item, registry),\n }\n return models\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBO,SAAS,yBAAyB,OAA+B,UAAyC,CAAC,GAAuB;AACvI,QAAM,OAAO,oBAAI,IAA0B;AAC3C,aAAW,QAAQ,MAAO,MAAK,IAAI,KAAK,IAAI,IAAI;AAChD,SAAO,CAAC,OAAO,MAAM;AACnB,UAAM,OAAO,KAAK,IAAI,MAA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AS,CAAC;AAAA,IAC/F,UAAU,CAAC,GAAG,MAAM,aAAa,CAAC,MAAM,aAAa,GAAG,MAAM,EAAE,GAAG,YAAY,QAAQ,SAAS,CAAC;AAAA,IACjG,WAAW,CAAC,SAAS,cAAc,MAAM,QAAQ;AAAA,EACnD;AACA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/contained.ts","../src/item-models.ts","../src/merge.ts","../src/lod.ts","../src/models/instance.ts"],"sourcesContent":["import type * as THREE_NS from 'three'\n\nimport type { ItemRules } from '@adatechnology/game-items'\n\nimport { buildItem } from './build-item'\nimport type { BuildItemOptions, DrawableItem } from './build-item'\nimport { setItemDirt } from './wash'\nimport { wearOfAge } from './wear'\nimport type { WearStage } from './wear'\n\n/** A stack held in a container (`ItemStack` of game-interactables): the item id and its free data (a find's age, `ageDays`). */\nexport interface ContainedStack {\n readonly type: string\n /** The stack's free data: `ageDays` (the age a find is rolled with) wears the item by its freshness, `dirt` (0 clean to 1 caked) draws the food left on it (a plate left dirty in a sink). */\n readonly data?: Readonly<Record<string, unknown>>\n}\n\n/** How a contained item is drawn: `buildItem`'s options, and the rules its age is read by (the catalogue's; the default rules when left out). */\nexport type ContainedItemOptions = Omit<BuildItemOptions, 'kit'> & { readonly rules?: ItemRules }\n\n/** What `createContainedItemModel` returns: the real model of a stack drawn with the caller's `THREE`, or null for an id the catalogue does not have. */\nexport type ContainedItemModel = (stack: ContainedStack, T: typeof THREE_NS) => THREE_NS.Object3D | null\n\n/**\n * The model of the items inside furniture, for `createContentsView` of game-interactables-three and `interactives.itemModel` of game-floorplan-three: each\n * stack is drawn by `buildItem` from the catalogue (the team's model where there is one, the item's own shape otherwise), never a stand-in. Every item gets its\n * own materials, so the view can discard it alone when it is taken. `root.userData.item` says what was drawn (`{ id, kind }`). A stack with an age (`data.ageDays`)\n * shows the wear of its freshness, and one with `data.dirt` is drawn dirty (`setItemDirt`), the same as the item once it is in the world.\n */\nexport function createContainedItemModel(items: Iterable<DrawableItem & { readonly shelfLife?: number }>, options: ContainedItemOptions = {}): ContainedItemModel {\n const { rules, ...build } = options\n const byId = new Map<string, DrawableItem & { readonly shelfLife?: number }>()\n for (const item of items) byId.set(item.id, item)\n return (stack, T) => {\n const item = byId.get(stack.type)\n if (!item) return null\n const ageDays = stack.data?.['ageDays']\n const aged = typeof ageDays === 'number' ? wearOfAge(item, ageDays, rules) : 0\n const wear = Math.max(build.wear ?? 0, aged) as WearStage\n const model = buildItem(T, item, wear > 0 ? { ...build, wear } : build)\n model.root.userData.item = { id: item.id, kind: model.kind }\n const dirt = stack.data?.['dirt']\n if (typeof dirt === 'number' && dirt > 0) setItemDirt(T, model.root, dirt)\n return model.root\n }\n}\n","import { buildItem } from './build-item'\nimport { hasItemModel } from './models/registry'\n\n/** The item models as a source a weapon or an explosive can draw with (`ItemModels` of game-weapons-three): a host lends it as `items`. */\nexport const itemModels = { has: hasItemModel, build: buildItem } as const\n","import { mergeByMaterial } from '@adatechnology/game-shapes-three'\nimport type * as THREE_NS from 'three'\n\nimport type { ItemModel } from './build-item'\n\n/**\n * 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\n * 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.\n */\nexport function mergeItem(T: typeof THREE_NS, model: ItemModel): ItemModel {\n model.root.updateMatrixWorld(true)\n const merged = new T.Group()\n merged.name = model.root.name\n merged.scale.copy(model.root.scale)\n merged.userData = { ...model.root.userData }\n // baked into the space of the root, which leaves the root's own scale out of the geometry\n merged.add(...mergeByMaterial(T, model.root, model.root))\n return { ...model, root: merged }\n}\n","import type * as THREE_NS from 'three'\n\nimport { ITEM_BUDGETS, cullDistanceOf } from './budgets'\nimport type { ItemBudgets } from './budgets'\nimport { buildItem } from './build-item'\nimport type { BuildItemOptions, DrawableItem, ItemModel } from './build-item'\nimport { createItemKit } from './kit'\nimport { mergeItem } from './merge'\n\nexport interface ItemLodOptions extends Omit<BuildItemOptions, 'simple' | 'detail' | 'kit'> {\n budgets?: ItemBudgets\n /** Join the meshes of each level by material (default true). */\n merge?: boolean\n /** Distance of the second level in metres; default a third of the distance at which the item disappears. */\n lod1Distance?: number\n}\n\nexport interface ItemLod {\n /** Add this to the scene and call `update(camera)` (or let the renderer do it). */\n readonly root: THREE_NS.LOD\n /** Full detail: the showcase model, or the shape at full segments. */\n readonly near: ItemModel\n /** The simple shape at half the segments. */\n readonly far: ItemModel\n /** Metres from the camera at which the item is no longer drawn. */\n readonly cullDistance: number\n readonly lod1Distance: number\n}\n\n/**\n * Three levels of an item: the model (or the shape) up close, the simple shape at half the segments from `lod1Distance`, and nothing from the distance of its class\n * (a small item goes at 30 m, a large one at 60 m).\n */\nexport function buildItemLod(T: typeof THREE_NS, item: DrawableItem, options: ItemLodOptions = {}): ItemLod {\n const budgets = options.budgets ?? ITEM_BUDGETS\n const cullDistance = cullDistanceOf(item.size, budgets)\n const lod1Distance = options.lod1Distance ?? cullDistance / 3\n const joined = (model: ItemModel): ItemModel => (options.merge === false ? model : mergeItem(T, model))\n const wear = { ...(options.wear === undefined ? {} : { wear: options.wear }), ...(options.models === undefined ? {} : { models: options.models }) }\n const near = joined(buildItem(T, item, { ...wear, kit: createItemKit(T) }))\n const far = joined(buildItem(T, item, { ...wear, simple: true, detail: budgets.lod1Ratio, kit: createItemKit(T) }))\n const root = new T.LOD()\n root.name = item.id\n root.addLevel(near.root, 0)\n root.addLevel(far.root, lod1Distance)\n root.addLevel(new T.Group(), cullDistance)\n root.userData.wear = options.wear ?? 0\n return { root, near, far, cullDistance, lod1Distance }\n}\n","import { applyPatches, mergeById, removeIds } from '@adatechnology/game-contracts'\nimport type { DeepPartial, Thumbnail } from '@adatechnology/game-contracts'\nimport type * as THREE_NS from 'three'\n\nimport { buildItem } from '../build-item'\nimport { buildItemLod } from '../lod'\nimport type { ItemLod, ItemLodOptions } from '../lod'\nimport { itemThumbnail } from '../thumbnails'\nimport type { BuildItemOptions, DrawableItem, ItemModel } from '../build-item'\nimport { registryOver } from './registry'\nimport type { ItemModelBuilder, ItemModelEntry, ItemModelRegistry } from './registry'\nimport { SHIPPED_MODELS } from './shipped'\n\nexport interface ItemModelRecord {\n readonly entry: ItemModelEntry\n readonly builder: ItemModelBuilder\n}\n\nexport interface ItemModelsOptions {\n /** Models added to the shipped ones; one with the id of a shipped model replaces it. */\n readonly packs?: readonly (readonly ItemModelRecord[])[]\n /** Changes to an entry by item id (`scale`, `teamBox`), merged field by field. */\n readonly patch?: Readonly<Record<string, DeepPartial<ItemModelEntry>>>\n /** Item ids whose model is taken out (the item then gets its simple shape). */\n readonly remove?: readonly string[]\n}\n\nexport interface ItemModels extends ItemModelRegistry {\n /** `buildItem` that reads this set of models. */\n build(T: typeof THREE_NS, item: DrawableItem, options?: Omit<BuildItemOptions, 'models'>): ItemModel\n /** `buildItemLod` that reads this set of models. */\n buildLod(T: typeof THREE_NS, item: DrawableItem, options?: Omit<ItemLodOptions, 'models'>): ItemLod\n /** `itemThumbnail` that asks this set whether the item has a model. */\n thumbnail(item: DrawableItem): Thumbnail\n}\n\ntype Keyed = ItemModelRecord & { readonly id: string }\n\n/** A set of item models of its own: the shipped ones plus `packs`, `patch` and `remove`. Nothing is shared with any other set on the page. */\nexport function createItemModels(options: ItemModelsOptions = {}): ItemModels {\n const keyed = (record: ItemModelRecord): Keyed => ({ ...record, id: record.entry.id })\n const records = mergeById(SHIPPED_MODELS.map(keyed), (options.packs ?? []).flat().map(keyed))\n applyPatches(records, Object.fromEntries(Object.entries(options.patch ?? {}).map(([id, entry]) => [id, { entry }])) as Readonly<Record<string, DeepPartial<Keyed>>>)\n removeIds(records, options.remove)\n const registry = registryOver(new Map([...records].map(([id, record]) => [id, record.entry])), new Map([...records].map(([id, record]) => [id, record.builder])))\n const models: ItemModels = {\n ...registry,\n build: (T, item, buildOptions = {}) => buildItem(T, item, { ...buildOptions, models: registry }),\n buildLod: (T, item, lodOptions = {}) => buildItemLod(T, item, { ...lodOptions, models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IAAI,KAAK,CAAC;AAC5F,eAAa,SAAS,OAAO,YAAY,OAAO,QAAQ,QAAQ,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAiD;AACnK,YAAU,SAAS,QAAQ,MAAM;AACjC,QAAM,WAAW,aAAa,IAAI,IAAI,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,MAAM,MAAM,CAAC,IAAI,OAAO,KAAK,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,MAAM,MAAM,CAAC,IAAI,OAAO,OAAO,CAAC,CAAC,CAAC;AAChK,QAAM,SAAqB;AAAA,IACzB,GAAG;AAAA,IACH,OAAO,CAAC,GAAG,MAAM,eAAe,CAAC,MAAM,UAAU,GAAG,MAAM,EAAE,GAAG,cAAc,QAAQ,SAAS,CAAC;AAAA,IAC/F,UAAU,CAAC,GAAG,MAAM,aAAa,CAAC,MAAM,aAAa,GAAG,MAAM,EAAE,GAAG,YAAY,QAAQ,SAAS,CAAC;AAAA,IACjG,WAAW,CAAC,SAAS,cAAc,MAAM,QAAQ;AAAA,EACnD;AACA,SAAO;AACT;","names":[]}
|
|
@@ -44,9 +44,6 @@ interface ItemKit {
|
|
|
44
44
|
/** The helpers of the showcase page on a given three.js; every kit has its own list of materials. */
|
|
45
45
|
declare function createItemKit(three: Three): ItemKit;
|
|
46
46
|
|
|
47
|
-
/** A builder of the showcase, ported as it is: it draws in the page's units and returns the group. Kept apart from the registry so a model can name its type without reaching the list of shipped models. */
|
|
48
|
-
type ItemModelBuilder = (kit: ItemKit) => THREE_NS.Group;
|
|
49
|
-
|
|
50
47
|
/** One model of the showcase as `data/models.json` keeps it: the item it draws, the id the team gave it, the box it has in the units of the page and the scale to metres. */
|
|
51
48
|
interface ItemModelEntry {
|
|
52
49
|
/** Catalog id of the item (`canned_beans`). */
|
|
@@ -58,6 +55,11 @@ interface ItemModelEntry {
|
|
|
58
55
|
/** Metres per unit of the page, from one real measure of the object. */
|
|
59
56
|
readonly scale: number;
|
|
60
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* A builder of the showcase, ported as it is: it draws in the page's units and returns the group.
|
|
60
|
+
* It lives apart from `registry.ts` because the registry imports every builder (`shipped.ts`): a builder that took its type from the registry closed a cycle (`registry` → `shipped` → builder → `registry`).
|
|
61
|
+
*/
|
|
62
|
+
type ItemModelBuilder = (kit: ItemKit) => THREE_NS.Group;
|
|
61
63
|
|
|
62
64
|
/** The models of one registry: what `buildItem` reads through its `models` option. */
|
|
63
65
|
interface ItemModelRegistry {
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { F as FINDS_TABLE_ID, H as HUMAN_HEIGHT, d as HUMAN_ID, g as ItemsAreaState, h as ItemsTestModule, i as ItemsTestModuleOptions, j as RULER_HEIGHT, k as RULER_ID, n as SHOWCASE_STAND_ID, o as ScenarioLike, s as createItemsTestModule } from './testing-
|
|
1
|
+
export { F as FINDS_TABLE_ID, H as HUMAN_HEIGHT, d as HUMAN_ID, g as ItemsAreaState, h as ItemsTestModule, i as ItemsTestModuleOptions, j as RULER_HEIGHT, k as RULER_ID, n as SHOWCASE_STAND_ID, o as ScenarioLike, s as createItemsTestModule } from './testing-C96KjBjB.js';
|
|
2
2
|
import 'three';
|
|
3
3
|
import '@adatechnology/game-contracts';
|
|
4
4
|
import '@adatechnology/game-items';
|
package/dist/testing.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adatechnology/game-items-three",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "three.js presentation for @adatechnology/game-items: the 24 models of the Itens do Vale Cinzento showcase at real size, simple shapes at real size for every other item, wear (new, used, spoiled) on the materials, merge by material, LOD and the draw budgets of the team.",
|
|
6
6
|
"keywords": [
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@adatechnology/game-
|
|
46
|
-
"@adatechnology/game-
|
|
47
|
-
"@adatechnology/game-fluids": "^0.
|
|
48
|
-
"@adatechnology/game-interactables": "^0.
|
|
49
|
-
"@adatechnology/game-items": "^0.
|
|
45
|
+
"@adatechnology/game-floorplan-three": "^12.0.0",
|
|
46
|
+
"@adatechnology/game-contracts": "^0.51.0",
|
|
47
|
+
"@adatechnology/game-fluids": "^0.8.0",
|
|
48
|
+
"@adatechnology/game-interactables": "^0.14.0",
|
|
49
|
+
"@adatechnology/game-items": "^0.9.0",
|
|
50
50
|
"@adatechnology/game-shapes-three": "^0.5.1"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"tsup": "^8.5.1",
|
|
61
61
|
"typescript": "^5.7.3",
|
|
62
62
|
"vitest": "^3.2.4",
|
|
63
|
-
"@adatechnology/game-destruction": "^0.38.
|
|
64
|
-
"@adatechnology/game-destruction-three": "^1.10.
|
|
65
|
-
"@adatechnology/game-interactables-household": "^0.
|
|
66
|
-
"@adatechnology/game-
|
|
67
|
-
"@adatechnology/game-
|
|
63
|
+
"@adatechnology/game-destruction": "^0.38.1",
|
|
64
|
+
"@adatechnology/game-destruction-three": "^1.10.2",
|
|
65
|
+
"@adatechnology/game-interactables-household": "^0.10.0",
|
|
66
|
+
"@adatechnology/game-items-goods": "^0.9.0",
|
|
67
|
+
"@adatechnology/game-interactables-three": "^0.8.0",
|
|
68
68
|
"@adatechnology/game-physics": "^0.11.2",
|
|
69
69
|
"@adatechnology/game-physics-jolt": "^0.7.8",
|
|
70
|
-
"@adatechnology/game-test-room": "^1.12.
|
|
70
|
+
"@adatechnology/game-test-room": "^1.12.1",
|
|
71
71
|
"@adatechnology/golden-tool": "^0.0.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|