@adatechnology/game-interactables-three 0.4.0 → 0.5.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/index.d.ts +22 -2
- package/dist/index.global.js +87 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +91 -4
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/effects.ts
|
|
2
|
-
import { warnOnce } from "@adatechnology/game-contracts";
|
|
2
|
+
import { markKitOrigin, warnOnce } from "@adatechnology/game-contracts";
|
|
3
3
|
|
|
4
4
|
// src/routed-particles.ts
|
|
5
5
|
var channel = (value) => Math.round(Math.min(1, Math.max(0, value)) * 255);
|
|
@@ -179,7 +179,7 @@ function createEffects(THREE, a, b = {}) {
|
|
|
179
179
|
depthWrite: false,
|
|
180
180
|
blending: additive ? THREE.AdditiveBlending : THREE.NormalBlending
|
|
181
181
|
});
|
|
182
|
-
const points = new THREE.Points(geo, mat);
|
|
182
|
+
const points = markKitOrigin(new THREE.Points(geo, mat), { owner: "game-interactables-three", kind: "effect", id: kind });
|
|
183
183
|
points.frustumCulled = false;
|
|
184
184
|
points.name = `effects:${kind}`;
|
|
185
185
|
scene.add(points);
|
|
@@ -724,7 +724,7 @@ function createEffects(THREE, a, b = {}) {
|
|
|
724
724
|
import { createCord, catenary } from "@adatechnology/game-shapes-three";
|
|
725
725
|
|
|
726
726
|
// src/mesh.ts
|
|
727
|
-
import { markKitOrigin } from "@adatechnology/game-contracts";
|
|
727
|
+
import { markKitOrigin as markKitOrigin2 } from "@adatechnology/game-contracts";
|
|
728
728
|
import { LIGHT_PRIORITY } from "@adatechnology/game-render-three";
|
|
729
729
|
import { createShapeRecorder } from "@adatechnology/game-props3d";
|
|
730
730
|
import { colorChannels, generate } from "@adatechnology/game-shapes";
|
|
@@ -1445,7 +1445,7 @@ function createMeshApi(THREE, options = {}) {
|
|
|
1445
1445
|
});
|
|
1446
1446
|
const batches = buffers.levels[0]?.batches ?? [];
|
|
1447
1447
|
const of = (id) => ({ batches: batches.filter((b) => b.part === id), points: buffers.points.filter((p) => p.part === id) });
|
|
1448
|
-
const group =
|
|
1448
|
+
const group = markKitOrigin2(new THREE.Group(), { owner: "game-interactables-three", kind: "furniture", ...spec ? { id: spec.type } : {} });
|
|
1449
1449
|
group.name = "interactable";
|
|
1450
1450
|
const parts = {};
|
|
1451
1451
|
const body = of(null);
|
|
@@ -1951,6 +1951,92 @@ function wireMeshes(THREE, wires) {
|
|
|
1951
1951
|
}
|
|
1952
1952
|
return meshes;
|
|
1953
1953
|
}
|
|
1954
|
+
|
|
1955
|
+
// src/controls-view.ts
|
|
1956
|
+
import { discardObject3D as discardObject3D2 } from "@adatechnology/game-shapes-three";
|
|
1957
|
+
var FOOD = 8018480;
|
|
1958
|
+
var WATER = 6262704;
|
|
1959
|
+
var URINE = 14204992;
|
|
1960
|
+
var FECES = 5913116;
|
|
1961
|
+
var LIFT = 2e-3;
|
|
1962
|
+
var SOIL_DEPTH = 0.03;
|
|
1963
|
+
function screensOf(THREE, options, screens) {
|
|
1964
|
+
return (options.spec.devices ?? []).flatMap((device) => {
|
|
1965
|
+
if (device.kind !== "screen" || !device.display) return [];
|
|
1966
|
+
const screen = createScreen(THREE, { document: options.document });
|
|
1967
|
+
screens.push(screen);
|
|
1968
|
+
const plane = new THREE.Mesh(new THREE.PlaneGeometry(device.display.w, device.display.h), screen.material);
|
|
1969
|
+
plane.position.set(device.display.center[0], device.display.center[1], device.display.center[2]);
|
|
1970
|
+
plane.name = `screen_${device.id}`;
|
|
1971
|
+
plane.visible = false;
|
|
1972
|
+
const apply2 = (state, dt) => {
|
|
1973
|
+
const lit = state.screens.find((s) => s.device === device.id);
|
|
1974
|
+
plane.visible = !!lit;
|
|
1975
|
+
screen.setOn(!!lit);
|
|
1976
|
+
if (lit && lit.channel !== screen.channel) screen.setChannel(lit.channel);
|
|
1977
|
+
screen.update(dt);
|
|
1978
|
+
};
|
|
1979
|
+
return [{ object: plane, apply: apply2 }];
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
function bowlsOf(THREE, spec) {
|
|
1983
|
+
return (spec.bowls ?? []).map((bowl) => {
|
|
1984
|
+
const material = new THREE.MeshStandardMaterial({ color: bowl.holds === "water" ? WATER : FOOD, roughness: bowl.holds === "water" ? 0.15 : 0.9 });
|
|
1985
|
+
const fill = new THREE.Mesh(new THREE.CylinderGeometry(bowl.radius, bowl.radius, 1, 20), material);
|
|
1986
|
+
fill.name = `bowl_${bowl.id}`;
|
|
1987
|
+
fill.visible = false;
|
|
1988
|
+
const apply2 = (state) => {
|
|
1989
|
+
const share = Math.min(1, (state.bowls[bowl.id] ?? 0) / bowl.capacity);
|
|
1990
|
+
const height = Math.max(1e-3, bowl.depth * share);
|
|
1991
|
+
fill.visible = share > 0;
|
|
1992
|
+
fill.scale.set(1, height, 1);
|
|
1993
|
+
fill.position.set(bowl.center[0], bowl.center[1] + LIFT + height / 2, bowl.center[2]);
|
|
1994
|
+
};
|
|
1995
|
+
return { object: fill, apply: apply2 };
|
|
1996
|
+
});
|
|
1997
|
+
}
|
|
1998
|
+
function soilsOf(THREE, spec) {
|
|
1999
|
+
return (spec.basins ?? []).filter((basin) => basin.soils).map((basin) => {
|
|
2000
|
+
const radius = Math.min(basin.to[0] - basin.from[0], basin.to[2] - basin.from[2]) * 0.3;
|
|
2001
|
+
const lump = new THREE.Mesh(new THREE.SphereGeometry(radius, 12, 8), new THREE.MeshStandardMaterial({ color: FECES, roughness: 0.95 }));
|
|
2002
|
+
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 }));
|
|
2003
|
+
const x = (basin.from[0] + basin.to[0]) / 2;
|
|
2004
|
+
const z = (basin.from[2] + basin.to[2]) / 2;
|
|
2005
|
+
lump.scale.set(1, 0.5, 0.7);
|
|
2006
|
+
lump.position.set(x, basin.from[1] + radius * 0.25 + LIFT, z);
|
|
2007
|
+
tint.position.set(x, basin.from[1] + SOIL_DEPTH, z);
|
|
2008
|
+
const soil = new THREE.Group();
|
|
2009
|
+
soil.name = `soil_${basin.id}`;
|
|
2010
|
+
soil.add(lump, tint);
|
|
2011
|
+
soil.visible = false;
|
|
2012
|
+
const apply2 = (state) => {
|
|
2013
|
+
const now = state.soil[basin.id] ?? "clean";
|
|
2014
|
+
soil.visible = now !== "clean";
|
|
2015
|
+
lump.visible = now === "feces";
|
|
2016
|
+
};
|
|
2017
|
+
return { object: soil, apply: apply2 };
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
|
+
function createControlsView(THREE, options) {
|
|
2021
|
+
const group = new THREE.Group();
|
|
2022
|
+
group.name = "controls-view";
|
|
2023
|
+
options.root.add(group);
|
|
2024
|
+
const screens = [];
|
|
2025
|
+
const drawn = [...screensOf(THREE, options, screens), ...bowlsOf(THREE, options.spec), ...soilsOf(THREE, options.spec)];
|
|
2026
|
+
for (const d of drawn) group.add(d.object);
|
|
2027
|
+
let disposed = false;
|
|
2028
|
+
return {
|
|
2029
|
+
update(state, dt) {
|
|
2030
|
+
for (const d of drawn) d.apply(state, dt);
|
|
2031
|
+
},
|
|
2032
|
+
dispose() {
|
|
2033
|
+
if (disposed) return;
|
|
2034
|
+
disposed = true;
|
|
2035
|
+
for (const screen of screens) screen.dispose();
|
|
2036
|
+
discardObject3D2(group);
|
|
2037
|
+
}
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
1954
2040
|
export {
|
|
1955
2041
|
MATERIAL_KEYS,
|
|
1956
2042
|
WIRE_COLORS,
|
|
@@ -1959,6 +2045,7 @@ export {
|
|
|
1959
2045
|
attachSway,
|
|
1960
2046
|
catenary2 as catenary,
|
|
1961
2047
|
createContentsView,
|
|
2048
|
+
createControlsView,
|
|
1962
2049
|
createCord2 as createCord,
|
|
1963
2050
|
createDefaultMaterials,
|
|
1964
2051
|
createEffects,
|