@adatechnology/game-interactables-three 0.6.3 → 0.7.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.js CHANGED
@@ -1901,7 +1901,7 @@ function createContentsView(THREE, options) {
1901
1901
  const object = buildItem(stack, THREE);
1902
1902
  if (!object) return;
1903
1903
  object.name = `contents_${c.id}_${i}`;
1904
- object.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty };
1904
+ object.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty, ...stack.data ? { data: stack.data } : {} };
1905
1905
  place(object, carrierOf(slot.part), slot.pos, slot.part === void 0 ? void 0 : partsById.get(slot.part));
1906
1906
  now = { type: stack.type, object };
1907
1907
  drawn.set(key, now);
@@ -2054,6 +2054,10 @@ var URINE = 14204992;
2054
2054
  var FECES = 5913116;
2055
2055
  var LIFT = 2e-3;
2056
2056
  var SOIL_DEPTH = 0.03;
2057
+ var PAPER = 15921386;
2058
+ var MAX_CONTENTS = 12;
2059
+ var SWIRL_STREAKS = 3;
2060
+ var SWIRL_ARC = Math.PI * 0.9;
2057
2061
  function screensOf(THREE, options, screens) {
2058
2062
  return (options.spec.devices ?? []).flatMap((device) => {
2059
2063
  if (device.kind !== "screen" || !device.display) return [];
@@ -2090,7 +2094,7 @@ function bowlsOf(THREE, spec) {
2090
2094
  });
2091
2095
  }
2092
2096
  function soilsOf(THREE, spec) {
2093
- return (spec.basins ?? []).filter((basin) => basin.soils).map((basin) => {
2097
+ return (spec.basins ?? []).filter((basin) => basin.soils && !basin.drain).map((basin) => {
2094
2098
  const radius = Math.min(basin.to[0] - basin.from[0], basin.to[2] - basin.from[2]) * 0.3;
2095
2099
  const lump = new THREE.Mesh(new THREE.SphereGeometry(radius, 12, 8), new THREE.MeshStandardMaterial({ color: FECES, roughness: 0.95 }));
2096
2100
  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 +2115,85 @@ function soilsOf(THREE, spec) {
2111
2115
  return { object: soil, apply: apply2 };
2112
2116
  });
2113
2117
  }
2118
+ function contentMesh(THREE, kind) {
2119
+ if (kind === "paper") return new THREE.Mesh(new THREE.SphereGeometry(0.022, 8, 6), new THREE.MeshStandardMaterial({ color: PAPER, roughness: 1 }));
2120
+ if (kind === "urine") return new THREE.Mesh(new THREE.CircleGeometry(1, 20), new THREE.MeshStandardMaterial({ color: URINE, transparent: true, opacity: 0.45, depthWrite: false }));
2121
+ const lump = new THREE.Mesh(new THREE.CapsuleGeometry(0.016, 0.07, 4, 8), new THREE.MeshStandardMaterial({ color: FECES, roughness: 0.95 }));
2122
+ return lump;
2123
+ }
2124
+ function drainOf(THREE, basin) {
2125
+ const group = new THREE.Group();
2126
+ group.name = `drain_${basin.id}`;
2127
+ const cx = (basin.from[0] + basin.to[0]) / 2;
2128
+ const cz = (basin.from[2] + basin.to[2]) / 2;
2129
+ const radius = Math.min(basin.to[0] - basin.from[0], basin.to[2] - basin.from[2]) / 2;
2130
+ const pool = /* @__PURE__ */ new Map();
2131
+ const take = (kind, used2) => {
2132
+ const list = pool.get(kind) ?? [];
2133
+ pool.set(kind, list);
2134
+ const at = used2.get(kind) ?? 0;
2135
+ used2.set(kind, at + 1);
2136
+ let mesh = list[at];
2137
+ if (!mesh) {
2138
+ mesh = contentMesh(THREE, kind);
2139
+ mesh.name = `content_${kind}_${at}`;
2140
+ list.push(mesh);
2141
+ group.add(mesh);
2142
+ }
2143
+ mesh.visible = true;
2144
+ return mesh;
2145
+ };
2146
+ const streakMaterial = new THREE.MeshBasicMaterial({ color: 15398136, transparent: true, opacity: 0, depthWrite: false, side: THREE.DoubleSide });
2147
+ const streaks = Array.from({ length: SWIRL_STREAKS }, (_, i) => {
2148
+ const inner = radius * (0.15 + i * 0.22);
2149
+ const streak = new THREE.Mesh(new THREE.RingGeometry(inner, inner + radius * 0.1, 24, 1, 0, SWIRL_ARC), streakMaterial);
2150
+ streak.rotation.x = -Math.PI / 2;
2151
+ streak.name = `swirl_${i}`;
2152
+ group.add(streak);
2153
+ return streak;
2154
+ });
2155
+ const used = /* @__PURE__ */ new Map();
2156
+ let drawn;
2157
+ const apply2 = (state) => {
2158
+ const drain = state.drains?.[basin.id];
2159
+ if (drain === drawn) return;
2160
+ drawn = drain;
2161
+ for (const list of pool.values()) for (const mesh of list) mesh.visible = false;
2162
+ if (!drain) return;
2163
+ const surface = basin.from[1] + drain.level;
2164
+ streakMaterial.opacity = Math.min(0.55, drain.swirl * 0.7);
2165
+ for (let i = 0; i < streaks.length; i++) {
2166
+ const streak = streaks[i];
2167
+ streak.visible = drain.swirl > 0.05;
2168
+ streak.position.set(cx, surface + LIFT, cz);
2169
+ streak.rotation.z = drain.turned * (1 + (SWIRL_STREAKS - 1 - i) * 0.3) + i * Math.PI * 2 / SWIRL_STREAKS;
2170
+ }
2171
+ used.clear();
2172
+ for (let i = 0; i < Math.min(MAX_CONTENTS, drain.contents.length); i++) {
2173
+ const c = drain.contents[i];
2174
+ if (c.kind === "object") continue;
2175
+ const mesh = take(c.kind, used);
2176
+ const y = surface + (basin.from[1] - surface) * c.depth;
2177
+ const r = radius * 0.8 * c.radius;
2178
+ if (c.kind === "urine") {
2179
+ mesh.scale.setScalar(radius * 0.9);
2180
+ mesh.rotation.set(-Math.PI / 2, 0, 0);
2181
+ mesh.position.set(cx, surface + LIFT * 2, cz);
2182
+ continue;
2183
+ }
2184
+ mesh.position.set(cx + Math.cos(c.angle) * r, y - (c.depth === 0 ? 6e-3 : 0), cz + Math.sin(c.angle) * r);
2185
+ mesh.rotation.set(Math.PI / 2, 0, c.angle);
2186
+ }
2187
+ };
2188
+ return { object: group, apply: apply2 };
2189
+ }
2114
2190
  function createControlsView(THREE, options) {
2115
2191
  const group = new THREE.Group();
2116
2192
  group.name = "controls-view";
2117
2193
  options.root.add(group);
2118
2194
  const screens = [];
2119
- const drawn = [...screensOf(THREE, options, screens), ...bowlsOf(THREE, options.spec), ...soilsOf(THREE, options.spec)];
2195
+ const drained = (options.spec.basins ?? []).filter((basin) => basin.drain).map((basin) => drainOf(THREE, basin));
2196
+ const drawn = [...screensOf(THREE, options, screens), ...bowlsOf(THREE, options.spec), ...soilsOf(THREE, options.spec), ...drained];
2120
2197
  for (const d of drawn) group.add(d.object);
2121
2198
  let disposed = false;
2122
2199
  return {