@adatechnology/game-interactables-three 0.7.0 → 0.8.1

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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ActiveEmitter, ObjectSpec, Motion, World, ItemStack, SpanShape, Span, ObjectControlsState } from '@adatechnology/game-interactables';
1
+ import { ActiveEmitter, ObjectSpec, Motion, World, ItemStack, ContainerSpec, SlotSpec, SpanShape, Span, ObjectControlsState } from '@adatechnology/game-interactables';
2
2
  import { LightBudget, SourceHandle } from '@adatechnology/game-render-three';
3
3
  import * as ThreeNS from 'three';
4
4
  import { PropsApi } from '@adatechnology/game-props3d';
@@ -453,11 +453,32 @@ interface ContentsView {
453
453
  /** Discards every item (`discardObject3D`) and the group. */
454
454
  dispose(): void;
455
455
  }
456
+ /**
457
+ * Puts a drawn item (origin at the bottom centre, y up) on a slot: turned by `yaw` about y, and laid on its side when the slot says (`SlotSpec.lay`), with the
458
+ * middle of what then touches the slot at `at`. Exported for the hosts that draw contents of their own, so every room lays the same item the same way.
459
+ */
460
+ declare function placeOnSlot(THREE: ThreeLib, object: ThreeNS.Object3D, at: readonly [number, number, number], yaw?: number, lay?: SlotSpec['lay']): void;
456
461
  /**
457
462
  * The contents of an object's containers as real items. Each slot on a part (a drawer, a door shelf) hangs under a carrier posed with the engine's own pose of
458
463
  * that part, so the items slide or swing with it from the first frame of the motion and `world.slotPosition` always agrees; nothing is built when the motion ends.
459
464
  */
460
465
  declare function createContentsView(THREE: ThreeLib, options: ContentsViewOptions): ContentsView;
466
+ /** What a host without a world (a furniture room) draws in a piece's containers: `drawSlotContents`. */
467
+ interface SlotContentsOptions {
468
+ /** The real model of each stack (the items catalogue's renderer, wear and all), null for an id it does not have. */
469
+ readonly buildItem: ContentsItemBuilder;
470
+ /** What fills the slots the piece leaves free (a pool rolled for a fridge): one stack or null per free slot, in their order. Left out, they stay empty. */
471
+ readonly roll?: (container: ContainerSpec, free: readonly SlotSpec[]) => ReadonlyArray<ItemStack | null>;
472
+ }
473
+ /**
474
+ * Draws the items in a piece's containers for a host that has no interactables world: first what the piece always comes with (`ContainerSpec.contents`, the soap on
475
+ * a washbasin's counter), slot by slot, then what `roll` puts in the slots left free. Each item is laid on its slot like `createContentsView` lays it
476
+ * (`placeOnSlot`), named `contents_<container>_<n>` (n its place among the slots that do not ride a part, which are left out) and tagged
477
+ * `userData.contents = { container, slot, item, qty, data? }`, `slot` its index in the container: the host takes it, and reads its data (a dish's dirt), by those.
478
+ */
479
+ declare function drawSlotContents(THREE: ThreeLib, group: ThreeNS.Object3D, spec: {
480
+ readonly containers?: readonly ContainerSpec[];
481
+ }, options: SlotContentsOptions): ThreeNS.Object3D[];
461
482
 
462
483
  type Wire = NonNullable<ObjectSpec['wires']>[number];
463
484
  /** The colour each kind of wire is drawn in (a grey PVC conduit, a black cable, a dark cord). */
@@ -513,4 +534,4 @@ interface ControlsView {
513
534
  }
514
535
  declare function createControlsView(THREE: ThreeLib, options: ControlsViewOptions): ControlsView;
515
536
 
516
- export { type CanvasFactory, type ContentsItemBuilder, type ContentsView, type ContentsViewItem, type ContentsViewOptions, type ControlsView, type ControlsViewOptions, type Effects, type EffectsOptions, type EffectsStats, type FinishOptions, type HouseholdApi, MATERIAL_KEYS, type MaterialKey, type MaterialMap, type MergeOptions, type MergedGroup, type MeshApi, type MeshApiOptions, type MeshResult, type MirrorCandidate, type MirrorOptions, type Mirrors, type PerspectiveLike, type PoolKind, type Pose, type PoseBatch, type Quality, type ReflectorConstructor, type Screen, type ScreenOptions, type SpanWire, type SpanWireOptions, type SwayBatch, type SwayHandle, type SwayOptions, type SwayUniforms, type SyncOptions, type ThreeAdapter, type ThreeAdapterOptions, type ThreeLib, type Vec3, WIRE_COLORS, WIRE_RADIUS, applyPose, attachSway, createContentsView, createControlsView, createDefaultMaterials, createEffects, createMeshApi, createMirrors, createScreen, createSpanWire, createThreeAdapter, mergeParts, patchSwayShader, poseOf, rememberRest, standOutCoincidentBoxes, swayMaterial, syncObject, wireMeshes };
537
+ export { type CanvasFactory, type ContentsItemBuilder, type ContentsView, type ContentsViewItem, type ContentsViewOptions, type ControlsView, type ControlsViewOptions, type Effects, type EffectsOptions, type EffectsStats, type FinishOptions, type HouseholdApi, MATERIAL_KEYS, type MaterialKey, type MaterialMap, type MergeOptions, type MergedGroup, type MeshApi, type MeshApiOptions, type MeshResult, type MirrorCandidate, type MirrorOptions, type Mirrors, type PerspectiveLike, type PoolKind, type Pose, type PoseBatch, type Quality, type ReflectorConstructor, type Screen, type ScreenOptions, type SlotContentsOptions, type SpanWire, type SpanWireOptions, type SwayBatch, type SwayHandle, type SwayOptions, type SwayUniforms, type SyncOptions, type ThreeAdapter, type ThreeAdapterOptions, type ThreeLib, type Vec3, WIRE_COLORS, WIRE_RADIUS, applyPose, attachSway, createContentsView, createControlsView, createDefaultMaterials, createEffects, createMeshApi, createMirrors, createScreen, createSpanWire, createThreeAdapter, drawSlotContents, mergeParts, patchSwayShader, placeOnSlot, poseOf, rememberRest, standOutCoincidentBoxes, swayMaterial, syncObject, wireMeshes };
@@ -37,8 +37,10 @@ var GameInteractablesThree = (() => {
37
37
  createScreen: () => createScreen,
38
38
  createSpanWire: () => createSpanWire,
39
39
  createThreeAdapter: () => createThreeAdapter,
40
+ drawSlotContents: () => drawSlotContents,
40
41
  mergeParts: () => mergeParts,
41
42
  patchSwayShader: () => patchSwayShader,
43
+ placeOnSlot: () => placeOnSlot,
42
44
  poseOf: () => poseOf2,
43
45
  rememberRest: () => rememberRest,
44
46
  standOutCoincidentBoxes: () => standOutCoincidentBoxes,
@@ -84,6 +86,8 @@ var GameInteractablesThree = (() => {
84
86
  [DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
85
87
  };
86
88
  var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
89
+ var BODY_FOAM_SURFACES = ["hands", "arms", "torso", "hair", "mouth"];
90
+ var WASH_SURFACES = [...BODY_FOAM_SURFACES, "brush"];
87
91
  var WARNED_KEY = /* @__PURE__ */ Symbol.for("@adatechnology/game-contracts.warned");
88
92
  var warnedKeys = () => {
89
93
  const holder = globalThis;
@@ -4556,6 +4560,24 @@ uniform float swayAmplitude;
4556
4560
  }
4557
4561
 
4558
4562
  // src/contents.ts
4563
+ var LAY_TURN = { x: [0, 0, -Math.PI / 2], z: [Math.PI / 2, 0, 0] };
4564
+ function placeOnSlot(THREE, object2, at, yaw = 0, lay) {
4565
+ object2.position.set(0, 0, 0);
4566
+ object2.rotation.set(0, yaw, 0);
4567
+ if (!lay) {
4568
+ object2.position.set(at[0], at[1], at[2]);
4569
+ return;
4570
+ }
4571
+ const [rx, ry, rz] = LAY_TURN[lay];
4572
+ object2.quaternion.multiply(new THREE.Quaternion().setFromEuler(new THREE.Euler(rx, ry, rz)));
4573
+ const parent = object2.parent;
4574
+ parent?.remove(object2);
4575
+ object2.updateMatrixWorld(true);
4576
+ const box2 = new THREE.Box3().setFromObject(object2);
4577
+ parent?.add(object2);
4578
+ const middle = box2.getCenter(new THREE.Vector3());
4579
+ object2.position.set(at[0] - middle.x, at[1] - box2.min.y, at[2] - middle.z);
4580
+ }
4559
4581
  function createContentsView(THREE, options) {
4560
4582
  const { world, objectId, root, buildItem } = options;
4561
4583
  const group = new THREE.Group();
@@ -4579,19 +4601,18 @@ uniform float swayAmplitude;
4579
4601
  }
4580
4602
  return carrier;
4581
4603
  };
4582
- const place = (object2, carrier, pos, part) => {
4604
+ const place = (object2, carrier, slot, part) => {
4583
4605
  carrier.add(object2);
4584
4606
  if (!part) {
4585
- object2.position.set(pos[0], pos[1], pos[2]);
4607
+ placeOnSlot(THREE, object2, slot.pos, 0, slot.lay);
4586
4608
  return;
4587
4609
  }
4588
4610
  const ry = part.ry ?? 0;
4589
- const x = pos[0] - part.pivot[0];
4590
- const z = pos[2] - part.pivot[2];
4611
+ const x = slot.pos[0] - part.pivot[0];
4612
+ const z = slot.pos[2] - part.pivot[2];
4591
4613
  const c = Math.cos(ry);
4592
4614
  const s = Math.sin(ry);
4593
- object2.position.set(c * x - s * z, pos[1] - part.pivot[1], s * x + c * z);
4594
- object2.rotation.set(0, -ry, 0);
4615
+ placeOnSlot(THREE, object2, [c * x - s * z, slot.pos[1] - part.pivot[1], s * x + c * z], -ry, slot.lay);
4595
4616
  };
4596
4617
  function sync() {
4597
4618
  const live = /* @__PURE__ */ new Set();
@@ -4614,7 +4635,7 @@ uniform float swayAmplitude;
4614
4635
  if (!object2) return;
4615
4636
  object2.name = `contents_${c.id}_${i}`;
4616
4637
  object2.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty, ...stack.data ? { data: stack.data } : {} };
4617
- place(object2, carrierOf(slot.part), slot.pos, slot.part === void 0 ? void 0 : partsById.get(slot.part));
4638
+ place(object2, carrierOf(slot.part), slot, slot.part === void 0 ? void 0 : partsById.get(slot.part));
4618
4639
  now = { type: stack.type, object: object2 };
4619
4640
  drawn.set(key, now);
4620
4641
  }
@@ -4645,6 +4666,33 @@ uniform float swayAmplitude;
4645
4666
  }
4646
4667
  };
4647
4668
  }
4669
+ function drawSlotContents(THREE, group, spec, options) {
4670
+ const drawn = [];
4671
+ const draw = (container, slot, index, at, stack) => {
4672
+ const object2 = options.buildItem(stack, THREE);
4673
+ if (!object2) return;
4674
+ group.add(object2);
4675
+ placeOnSlot(THREE, object2, slot.pos, 0, slot.lay);
4676
+ object2.name = `contents_${container.id}_${at}`;
4677
+ object2.userData.contents = { container: container.id, slot: index, item: stack.type, qty: stack.qty, ...stack.data ? { data: stack.data } : {} };
4678
+ drawn.push(object2);
4679
+ };
4680
+ for (const container of spec.containers ?? []) {
4681
+ const slots = container.slots.map((slot, index) => ({ slot, index })).filter(({ slot }) => !slot.part);
4682
+ const fixed = container.contents ?? [];
4683
+ slots.forEach(({ slot, index }, at) => {
4684
+ const stack = fixed[index];
4685
+ if (stack) draw(container, slot, index, at, stack);
4686
+ });
4687
+ const free = slots.map((entry, at) => ({ ...entry, at })).filter(({ index }) => !fixed[index]);
4688
+ if (!options.roll || free.length === 0) continue;
4689
+ options.roll(container, free.map(({ slot }) => slot)).forEach((stack, n) => {
4690
+ const entry = free[n];
4691
+ if (stack && entry) draw(container, entry.slot, entry.index, entry.at, stack);
4692
+ });
4693
+ }
4694
+ return drawn;
4695
+ }
4648
4696
 
4649
4697
  // src/wires.ts
4650
4698
  var WIRE_COLORS = { conduit: 13618628, cable: 2762532, drop: 1381653, cord: 1776413 };