@adatechnology/game-interactables-three 0.6.3 → 0.8.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 +23 -2
- package/dist/index.global.js +140 -11
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +133 -10
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1844,6 +1844,24 @@ function createThreeAdapter(THREE, options = {}) {
|
|
|
1844
1844
|
|
|
1845
1845
|
// src/contents.ts
|
|
1846
1846
|
import { discardObject3D } from "@adatechnology/game-shapes-three";
|
|
1847
|
+
var LAY_TURN = { x: [0, 0, -Math.PI / 2], z: [Math.PI / 2, 0, 0] };
|
|
1848
|
+
function placeOnSlot(THREE, object, at, yaw = 0, lay) {
|
|
1849
|
+
object.position.set(0, 0, 0);
|
|
1850
|
+
object.rotation.set(0, yaw, 0);
|
|
1851
|
+
if (!lay) {
|
|
1852
|
+
object.position.set(at[0], at[1], at[2]);
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
const [rx, ry, rz] = LAY_TURN[lay];
|
|
1856
|
+
object.quaternion.multiply(new THREE.Quaternion().setFromEuler(new THREE.Euler(rx, ry, rz)));
|
|
1857
|
+
const parent = object.parent;
|
|
1858
|
+
parent?.remove(object);
|
|
1859
|
+
object.updateMatrixWorld(true);
|
|
1860
|
+
const box = new THREE.Box3().setFromObject(object);
|
|
1861
|
+
parent?.add(object);
|
|
1862
|
+
const middle = box.getCenter(new THREE.Vector3());
|
|
1863
|
+
object.position.set(at[0] - middle.x, at[1] - box.min.y, at[2] - middle.z);
|
|
1864
|
+
}
|
|
1847
1865
|
function createContentsView(THREE, options) {
|
|
1848
1866
|
const { world, objectId, root, buildItem } = options;
|
|
1849
1867
|
const group = new THREE.Group();
|
|
@@ -1867,19 +1885,18 @@ function createContentsView(THREE, options) {
|
|
|
1867
1885
|
}
|
|
1868
1886
|
return carrier;
|
|
1869
1887
|
};
|
|
1870
|
-
const place = (object, carrier,
|
|
1888
|
+
const place = (object, carrier, slot, part) => {
|
|
1871
1889
|
carrier.add(object);
|
|
1872
1890
|
if (!part) {
|
|
1873
|
-
object.
|
|
1891
|
+
placeOnSlot(THREE, object, slot.pos, 0, slot.lay);
|
|
1874
1892
|
return;
|
|
1875
1893
|
}
|
|
1876
1894
|
const ry = part.ry ?? 0;
|
|
1877
|
-
const x = pos[0] - part.pivot[0];
|
|
1878
|
-
const z = pos[2] - part.pivot[2];
|
|
1895
|
+
const x = slot.pos[0] - part.pivot[0];
|
|
1896
|
+
const z = slot.pos[2] - part.pivot[2];
|
|
1879
1897
|
const c = Math.cos(ry);
|
|
1880
1898
|
const s = Math.sin(ry);
|
|
1881
|
-
object
|
|
1882
|
-
object.rotation.set(0, -ry, 0);
|
|
1899
|
+
placeOnSlot(THREE, object, [c * x - s * z, slot.pos[1] - part.pivot[1], s * x + c * z], -ry, slot.lay);
|
|
1883
1900
|
};
|
|
1884
1901
|
function sync() {
|
|
1885
1902
|
const live = /* @__PURE__ */ new Set();
|
|
@@ -1901,8 +1918,8 @@ function createContentsView(THREE, options) {
|
|
|
1901
1918
|
const object = buildItem(stack, THREE);
|
|
1902
1919
|
if (!object) return;
|
|
1903
1920
|
object.name = `contents_${c.id}_${i}`;
|
|
1904
|
-
object.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty };
|
|
1905
|
-
place(object, carrierOf(slot.part), slot
|
|
1921
|
+
object.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty, ...stack.data ? { data: stack.data } : {} };
|
|
1922
|
+
place(object, carrierOf(slot.part), slot, slot.part === void 0 ? void 0 : partsById.get(slot.part));
|
|
1906
1923
|
now = { type: stack.type, object };
|
|
1907
1924
|
drawn.set(key, now);
|
|
1908
1925
|
}
|
|
@@ -1933,6 +1950,33 @@ function createContentsView(THREE, options) {
|
|
|
1933
1950
|
}
|
|
1934
1951
|
};
|
|
1935
1952
|
}
|
|
1953
|
+
function drawSlotContents(THREE, group, spec, options) {
|
|
1954
|
+
const drawn = [];
|
|
1955
|
+
const draw = (container, slot, index, at, stack) => {
|
|
1956
|
+
const object = options.buildItem(stack, THREE);
|
|
1957
|
+
if (!object) return;
|
|
1958
|
+
group.add(object);
|
|
1959
|
+
placeOnSlot(THREE, object, slot.pos, 0, slot.lay);
|
|
1960
|
+
object.name = `contents_${container.id}_${at}`;
|
|
1961
|
+
object.userData.contents = { container: container.id, slot: index, item: stack.type, qty: stack.qty, ...stack.data ? { data: stack.data } : {} };
|
|
1962
|
+
drawn.push(object);
|
|
1963
|
+
};
|
|
1964
|
+
for (const container of spec.containers ?? []) {
|
|
1965
|
+
const slots = container.slots.map((slot, index) => ({ slot, index })).filter(({ slot }) => !slot.part);
|
|
1966
|
+
const fixed = container.contents ?? [];
|
|
1967
|
+
slots.forEach(({ slot, index }, at) => {
|
|
1968
|
+
const stack = fixed[index];
|
|
1969
|
+
if (stack) draw(container, slot, index, at, stack);
|
|
1970
|
+
});
|
|
1971
|
+
const free = slots.map((entry, at) => ({ ...entry, at })).filter(({ index }) => !fixed[index]);
|
|
1972
|
+
if (!options.roll || free.length === 0) continue;
|
|
1973
|
+
options.roll(container, free.map(({ slot }) => slot)).forEach((stack, n) => {
|
|
1974
|
+
const entry = free[n];
|
|
1975
|
+
if (stack && entry) draw(container, entry.slot, entry.index, entry.at, stack);
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
return drawn;
|
|
1979
|
+
}
|
|
1936
1980
|
|
|
1937
1981
|
// src/cord.ts
|
|
1938
1982
|
import { catenary as catenary2, createCord as createCord2 } from "@adatechnology/game-shapes-three";
|
|
@@ -2054,6 +2098,10 @@ var URINE = 14204992;
|
|
|
2054
2098
|
var FECES = 5913116;
|
|
2055
2099
|
var LIFT = 2e-3;
|
|
2056
2100
|
var SOIL_DEPTH = 0.03;
|
|
2101
|
+
var PAPER = 15921386;
|
|
2102
|
+
var MAX_CONTENTS = 12;
|
|
2103
|
+
var SWIRL_STREAKS = 3;
|
|
2104
|
+
var SWIRL_ARC = Math.PI * 0.9;
|
|
2057
2105
|
function screensOf(THREE, options, screens) {
|
|
2058
2106
|
return (options.spec.devices ?? []).flatMap((device) => {
|
|
2059
2107
|
if (device.kind !== "screen" || !device.display) return [];
|
|
@@ -2090,7 +2138,7 @@ function bowlsOf(THREE, spec) {
|
|
|
2090
2138
|
});
|
|
2091
2139
|
}
|
|
2092
2140
|
function soilsOf(THREE, spec) {
|
|
2093
|
-
return (spec.basins ?? []).filter((basin) => basin.soils).map((basin) => {
|
|
2141
|
+
return (spec.basins ?? []).filter((basin) => basin.soils && !basin.drain).map((basin) => {
|
|
2094
2142
|
const radius = Math.min(basin.to[0] - basin.from[0], basin.to[2] - basin.from[2]) * 0.3;
|
|
2095
2143
|
const lump = new THREE.Mesh(new THREE.SphereGeometry(radius, 12, 8), new THREE.MeshStandardMaterial({ color: FECES, roughness: 0.95 }));
|
|
2096
2144
|
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 }));
|
|
@@ -2111,12 +2159,85 @@ function soilsOf(THREE, spec) {
|
|
|
2111
2159
|
return { object: soil, apply: apply2 };
|
|
2112
2160
|
});
|
|
2113
2161
|
}
|
|
2162
|
+
function contentMesh(THREE, kind) {
|
|
2163
|
+
if (kind === "paper") return new THREE.Mesh(new THREE.SphereGeometry(0.022, 8, 6), new THREE.MeshStandardMaterial({ color: PAPER, roughness: 1 }));
|
|
2164
|
+
if (kind === "urine") return new THREE.Mesh(new THREE.CircleGeometry(1, 20), new THREE.MeshStandardMaterial({ color: URINE, transparent: true, opacity: 0.45, depthWrite: false }));
|
|
2165
|
+
const lump = new THREE.Mesh(new THREE.CapsuleGeometry(0.016, 0.07, 4, 8), new THREE.MeshStandardMaterial({ color: FECES, roughness: 0.95 }));
|
|
2166
|
+
return lump;
|
|
2167
|
+
}
|
|
2168
|
+
function drainOf(THREE, basin) {
|
|
2169
|
+
const group = new THREE.Group();
|
|
2170
|
+
group.name = `drain_${basin.id}`;
|
|
2171
|
+
const cx = (basin.from[0] + basin.to[0]) / 2;
|
|
2172
|
+
const cz = (basin.from[2] + basin.to[2]) / 2;
|
|
2173
|
+
const radius = Math.min(basin.to[0] - basin.from[0], basin.to[2] - basin.from[2]) / 2;
|
|
2174
|
+
const pool = /* @__PURE__ */ new Map();
|
|
2175
|
+
const take = (kind, used2) => {
|
|
2176
|
+
const list = pool.get(kind) ?? [];
|
|
2177
|
+
pool.set(kind, list);
|
|
2178
|
+
const at = used2.get(kind) ?? 0;
|
|
2179
|
+
used2.set(kind, at + 1);
|
|
2180
|
+
let mesh = list[at];
|
|
2181
|
+
if (!mesh) {
|
|
2182
|
+
mesh = contentMesh(THREE, kind);
|
|
2183
|
+
mesh.name = `content_${kind}_${at}`;
|
|
2184
|
+
list.push(mesh);
|
|
2185
|
+
group.add(mesh);
|
|
2186
|
+
}
|
|
2187
|
+
mesh.visible = true;
|
|
2188
|
+
return mesh;
|
|
2189
|
+
};
|
|
2190
|
+
const streakMaterial = new THREE.MeshBasicMaterial({ color: 15398136, transparent: true, opacity: 0, depthWrite: false, side: THREE.DoubleSide });
|
|
2191
|
+
const streaks = Array.from({ length: SWIRL_STREAKS }, (_, i) => {
|
|
2192
|
+
const inner = radius * (0.15 + i * 0.22);
|
|
2193
|
+
const streak = new THREE.Mesh(new THREE.RingGeometry(inner, inner + radius * 0.1, 24, 1, 0, SWIRL_ARC), streakMaterial);
|
|
2194
|
+
streak.rotation.x = -Math.PI / 2;
|
|
2195
|
+
streak.name = `swirl_${i}`;
|
|
2196
|
+
group.add(streak);
|
|
2197
|
+
return streak;
|
|
2198
|
+
});
|
|
2199
|
+
const used = /* @__PURE__ */ new Map();
|
|
2200
|
+
let drawn;
|
|
2201
|
+
const apply2 = (state) => {
|
|
2202
|
+
const drain = state.drains?.[basin.id];
|
|
2203
|
+
if (drain === drawn) return;
|
|
2204
|
+
drawn = drain;
|
|
2205
|
+
for (const list of pool.values()) for (const mesh of list) mesh.visible = false;
|
|
2206
|
+
if (!drain) return;
|
|
2207
|
+
const surface = basin.from[1] + drain.level;
|
|
2208
|
+
streakMaterial.opacity = Math.min(0.55, drain.swirl * 0.7);
|
|
2209
|
+
for (let i = 0; i < streaks.length; i++) {
|
|
2210
|
+
const streak = streaks[i];
|
|
2211
|
+
streak.visible = drain.swirl > 0.05;
|
|
2212
|
+
streak.position.set(cx, surface + LIFT, cz);
|
|
2213
|
+
streak.rotation.z = drain.turned * (1 + (SWIRL_STREAKS - 1 - i) * 0.3) + i * Math.PI * 2 / SWIRL_STREAKS;
|
|
2214
|
+
}
|
|
2215
|
+
used.clear();
|
|
2216
|
+
for (let i = 0; i < Math.min(MAX_CONTENTS, drain.contents.length); i++) {
|
|
2217
|
+
const c = drain.contents[i];
|
|
2218
|
+
if (c.kind === "object") continue;
|
|
2219
|
+
const mesh = take(c.kind, used);
|
|
2220
|
+
const y = surface + (basin.from[1] - surface) * c.depth;
|
|
2221
|
+
const r = radius * 0.8 * c.radius;
|
|
2222
|
+
if (c.kind === "urine") {
|
|
2223
|
+
mesh.scale.setScalar(radius * 0.9);
|
|
2224
|
+
mesh.rotation.set(-Math.PI / 2, 0, 0);
|
|
2225
|
+
mesh.position.set(cx, surface + LIFT * 2, cz);
|
|
2226
|
+
continue;
|
|
2227
|
+
}
|
|
2228
|
+
mesh.position.set(cx + Math.cos(c.angle) * r, y - (c.depth === 0 ? 6e-3 : 0), cz + Math.sin(c.angle) * r);
|
|
2229
|
+
mesh.rotation.set(Math.PI / 2, 0, c.angle);
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
return { object: group, apply: apply2 };
|
|
2233
|
+
}
|
|
2114
2234
|
function createControlsView(THREE, options) {
|
|
2115
2235
|
const group = new THREE.Group();
|
|
2116
2236
|
group.name = "controls-view";
|
|
2117
2237
|
options.root.add(group);
|
|
2118
2238
|
const screens = [];
|
|
2119
|
-
const
|
|
2239
|
+
const drained = (options.spec.basins ?? []).filter((basin) => basin.drain).map((basin) => drainOf(THREE, basin));
|
|
2240
|
+
const drawn = [...screensOf(THREE, options, screens), ...bowlsOf(THREE, options.spec), ...soilsOf(THREE, options.spec), ...drained];
|
|
2120
2241
|
for (const d of drawn) group.add(d.object);
|
|
2121
2242
|
let disposed = false;
|
|
2122
2243
|
return {
|
|
@@ -2148,8 +2269,10 @@ export {
|
|
|
2148
2269
|
createScreen,
|
|
2149
2270
|
createSpanWire,
|
|
2150
2271
|
createThreeAdapter,
|
|
2272
|
+
drawSlotContents,
|
|
2151
2273
|
mergeParts,
|
|
2152
2274
|
patchSwayShader,
|
|
2275
|
+
placeOnSlot,
|
|
2153
2276
|
poseOf,
|
|
2154
2277
|
rememberRest,
|
|
2155
2278
|
standOutCoincidentBoxes,
|