@adatechnology/game-interactables-three 0.4.1 → 0.5.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 +22 -2
- package/dist/index.global.js +86 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActiveEmitter, ObjectSpec, Motion, World, ItemStack } from '@adatechnology/game-interactables';
|
|
1
|
+
import { ActiveEmitter, ObjectSpec, Motion, World, ItemStack, 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';
|
|
@@ -467,4 +467,24 @@ declare const WIRE_RADIUS = 0.006;
|
|
|
467
467
|
/** One tube per wire with two points or more, named by the wire's id, in the object's own space. */
|
|
468
468
|
declare function wireMeshes(THREE: ThreeLib, wires: ObjectSpec['wires']): ThreeNS.Mesh[];
|
|
469
469
|
|
|
470
|
-
|
|
470
|
+
/**
|
|
471
|
+
* What an object's controls show on its drawing (`createObjectControls` of game-interactables): the picture of a screen that is on, on its channel; what is in each
|
|
472
|
+
* bowl, to its level; what a body left in a basin. Everything is drawn from the spec's data (`DeviceSpec.display`, `BowlSpec`, `BasinSpec.soils`), as children of
|
|
473
|
+
* the object's drawing, a few millimetres off the faces they stand on (CLAUDE.md §13), and released with `discardObject3D` when the object goes.
|
|
474
|
+
*/
|
|
475
|
+
|
|
476
|
+
interface ControlsViewOptions {
|
|
477
|
+
readonly spec: ObjectSpec;
|
|
478
|
+
/** The object's drawing (object-local frame). */
|
|
479
|
+
readonly root: ThreeNS.Object3D;
|
|
480
|
+
/** Where the screens' canvases are made. */
|
|
481
|
+
readonly document: CanvasFactory;
|
|
482
|
+
}
|
|
483
|
+
interface ControlsView {
|
|
484
|
+
/** Brings the drawing in line with the controls' state and runs the pictures by `dt` seconds. */
|
|
485
|
+
update(state: ObjectControlsState, dt: number): void;
|
|
486
|
+
dispose(): void;
|
|
487
|
+
}
|
|
488
|
+
declare function createControlsView(THREE: ThreeLib, options: ControlsViewOptions): ControlsView;
|
|
489
|
+
|
|
490
|
+
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 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, createThreeAdapter, mergeParts, patchSwayShader, poseOf, rememberRest, standOutCoincidentBoxes, swayMaterial, syncObject, wireMeshes };
|
package/dist/index.global.js
CHANGED
|
@@ -28,6 +28,7 @@ var GameInteractablesThree = (() => {
|
|
|
28
28
|
attachSway: () => attachSway,
|
|
29
29
|
catenary: () => catenary,
|
|
30
30
|
createContentsView: () => createContentsView,
|
|
31
|
+
createControlsView: () => createControlsView,
|
|
31
32
|
createCord: () => createCord,
|
|
32
33
|
createDefaultMaterials: () => createDefaultMaterials,
|
|
33
34
|
createEffects: () => createEffects,
|
|
@@ -4573,6 +4574,91 @@ uniform float swayAmplitude;
|
|
|
4573
4574
|
}
|
|
4574
4575
|
return meshes;
|
|
4575
4576
|
}
|
|
4577
|
+
|
|
4578
|
+
// src/controls-view.ts
|
|
4579
|
+
var FOOD = 8018480;
|
|
4580
|
+
var WATER = 6262704;
|
|
4581
|
+
var URINE = 14204992;
|
|
4582
|
+
var FECES = 5913116;
|
|
4583
|
+
var LIFT = 2e-3;
|
|
4584
|
+
var SOIL_DEPTH = 0.03;
|
|
4585
|
+
function screensOf(THREE, options, screens) {
|
|
4586
|
+
return (options.spec.devices ?? []).flatMap((device) => {
|
|
4587
|
+
if (device.kind !== "screen" || !device.display) return [];
|
|
4588
|
+
const screen = createScreen(THREE, { document: options.document });
|
|
4589
|
+
screens.push(screen);
|
|
4590
|
+
const plane2 = new THREE.Mesh(new THREE.PlaneGeometry(device.display.w, device.display.h), screen.material);
|
|
4591
|
+
plane2.position.set(device.display.center[0], device.display.center[1], device.display.center[2]);
|
|
4592
|
+
plane2.name = `screen_${device.id}`;
|
|
4593
|
+
plane2.visible = false;
|
|
4594
|
+
const apply2 = (state, dt) => {
|
|
4595
|
+
const lit = state.screens.find((s) => s.device === device.id);
|
|
4596
|
+
plane2.visible = !!lit;
|
|
4597
|
+
screen.setOn(!!lit);
|
|
4598
|
+
if (lit && lit.channel !== screen.channel) screen.setChannel(lit.channel);
|
|
4599
|
+
screen.update(dt);
|
|
4600
|
+
};
|
|
4601
|
+
return [{ object: plane2, apply: apply2 }];
|
|
4602
|
+
});
|
|
4603
|
+
}
|
|
4604
|
+
function bowlsOf(THREE, spec) {
|
|
4605
|
+
return (spec.bowls ?? []).map((bowl) => {
|
|
4606
|
+
const material = new THREE.MeshStandardMaterial({ color: bowl.holds === "water" ? WATER : FOOD, roughness: bowl.holds === "water" ? 0.15 : 0.9 });
|
|
4607
|
+
const fill = new THREE.Mesh(new THREE.CylinderGeometry(bowl.radius, bowl.radius, 1, 20), material);
|
|
4608
|
+
fill.name = `bowl_${bowl.id}`;
|
|
4609
|
+
fill.visible = false;
|
|
4610
|
+
const apply2 = (state) => {
|
|
4611
|
+
const share = Math.min(1, (state.bowls[bowl.id] ?? 0) / bowl.capacity);
|
|
4612
|
+
const height = Math.max(1e-3, bowl.depth * share);
|
|
4613
|
+
fill.visible = share > 0;
|
|
4614
|
+
fill.scale.set(1, height, 1);
|
|
4615
|
+
fill.position.set(bowl.center[0], bowl.center[1] + LIFT + height / 2, bowl.center[2]);
|
|
4616
|
+
};
|
|
4617
|
+
return { object: fill, apply: apply2 };
|
|
4618
|
+
});
|
|
4619
|
+
}
|
|
4620
|
+
function soilsOf(THREE, spec) {
|
|
4621
|
+
return (spec.basins ?? []).filter((basin) => basin.soils).map((basin) => {
|
|
4622
|
+
const radius = Math.min(basin.to[0] - basin.from[0], basin.to[2] - basin.from[2]) * 0.3;
|
|
4623
|
+
const lump = new THREE.Mesh(new THREE.SphereGeometry(radius, 12, 8), new THREE.MeshStandardMaterial({ color: FECES, roughness: 0.95 }));
|
|
4624
|
+
const tint = new THREE.Mesh(new THREE.CylinderGeometry(radius * 1.6, radius * 1.6, 4e-3, 20), new THREE.MeshStandardMaterial({ color: URINE, transparent: true, opacity: 0.55 }));
|
|
4625
|
+
const x = (basin.from[0] + basin.to[0]) / 2;
|
|
4626
|
+
const z = (basin.from[2] + basin.to[2]) / 2;
|
|
4627
|
+
lump.scale.set(1, 0.5, 0.7);
|
|
4628
|
+
lump.position.set(x, basin.from[1] + radius * 0.25 + LIFT, z);
|
|
4629
|
+
tint.position.set(x, basin.from[1] + SOIL_DEPTH, z);
|
|
4630
|
+
const soil = new THREE.Group();
|
|
4631
|
+
soil.name = `soil_${basin.id}`;
|
|
4632
|
+
soil.add(lump, tint);
|
|
4633
|
+
soil.visible = false;
|
|
4634
|
+
const apply2 = (state) => {
|
|
4635
|
+
const now = state.soil[basin.id] ?? "clean";
|
|
4636
|
+
soil.visible = now !== "clean";
|
|
4637
|
+
lump.visible = now === "feces";
|
|
4638
|
+
};
|
|
4639
|
+
return { object: soil, apply: apply2 };
|
|
4640
|
+
});
|
|
4641
|
+
}
|
|
4642
|
+
function createControlsView(THREE, options) {
|
|
4643
|
+
const group = new THREE.Group();
|
|
4644
|
+
group.name = "controls-view";
|
|
4645
|
+
options.root.add(group);
|
|
4646
|
+
const screens = [];
|
|
4647
|
+
const drawn = [...screensOf(THREE, options, screens), ...bowlsOf(THREE, options.spec), ...soilsOf(THREE, options.spec)];
|
|
4648
|
+
for (const d of drawn) group.add(d.object);
|
|
4649
|
+
let disposed = false;
|
|
4650
|
+
return {
|
|
4651
|
+
update(state, dt) {
|
|
4652
|
+
for (const d of drawn) d.apply(state, dt);
|
|
4653
|
+
},
|
|
4654
|
+
dispose() {
|
|
4655
|
+
if (disposed) return;
|
|
4656
|
+
disposed = true;
|
|
4657
|
+
for (const screen of screens) screen.dispose();
|
|
4658
|
+
discardObject3D(group);
|
|
4659
|
+
}
|
|
4660
|
+
};
|
|
4661
|
+
}
|
|
4576
4662
|
return __toCommonJS(index_exports);
|
|
4577
4663
|
})();
|
|
4578
4664
|
//# sourceMappingURL=index.global.js.map
|