@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.
@@ -3069,13 +3069,16 @@ void main() {
3069
3069
  for (const u of Object.values(uniforms)) if (isTexture(u?.value)) out.add(u.value);
3070
3070
  }
3071
3071
  }
3072
+ var isInstanced = (o) => o.isInstancedMesh === true;
3072
3073
  function collect(roots) {
3073
3074
  const geometries = /* @__PURE__ */ new Set();
3074
3075
  const materials = /* @__PURE__ */ new Set();
3075
3076
  const textures = /* @__PURE__ */ new Set();
3076
3077
  const skeletons = /* @__PURE__ */ new Set();
3078
+ const instanced = /* @__PURE__ */ new Set();
3077
3079
  for (const root of roots) {
3078
3080
  root.traverse((object2) => {
3081
+ if (isInstanced(object2)) instanced.add(object2);
3079
3082
  const o = object2;
3080
3083
  if (o.geometry && typeof o.geometry.dispose === "function") geometries.add(o.geometry);
3081
3084
  if (o.skeleton && typeof o.skeleton.dispose === "function") skeletons.add(o.skeleton);
@@ -3087,7 +3090,7 @@ void main() {
3087
3090
  }
3088
3091
  });
3089
3092
  }
3090
- return { geometries, materials, textures, skeletons };
3093
+ return { geometries, materials, textures, skeletons, instanced };
3091
3094
  }
3092
3095
  var marked = /* @__PURE__ */ new WeakSet();
3093
3096
  var shared = (r) => r.userData?.shared === true || marked.has(r);
@@ -3132,6 +3135,7 @@ void main() {
3132
3135
  report.textures++;
3133
3136
  }
3134
3137
  for (const s of found.skeletons) s.dispose();
3138
+ for (const mesh2 of found.instanced) mesh2.dispose();
3135
3139
  return report;
3136
3140
  }
3137
3141
  function discardObject3D(objects, options = {}) {
@@ -4609,7 +4613,7 @@ uniform float swayAmplitude;
4609
4613
  const object2 = buildItem(stack, THREE);
4610
4614
  if (!object2) return;
4611
4615
  object2.name = `contents_${c.id}_${i}`;
4612
- object2.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty };
4616
+ object2.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty, ...stack.data ? { data: stack.data } : {} };
4613
4617
  place(object2, carrierOf(slot.part), slot.pos, slot.part === void 0 ? void 0 : partsById.get(slot.part));
4614
4618
  now = { type: stack.type, object: object2 };
4615
4619
  drawn.set(key, now);
@@ -4756,6 +4760,10 @@ uniform float swayAmplitude;
4756
4760
  var FECES = 5913116;
4757
4761
  var LIFT = 2e-3;
4758
4762
  var SOIL_DEPTH = 0.03;
4763
+ var PAPER = 15921386;
4764
+ var MAX_CONTENTS = 12;
4765
+ var SWIRL_STREAKS = 3;
4766
+ var SWIRL_ARC = Math.PI * 0.9;
4759
4767
  function screensOf(THREE, options, screens) {
4760
4768
  return (options.spec.devices ?? []).flatMap((device) => {
4761
4769
  if (device.kind !== "screen" || !device.display) return [];
@@ -4792,7 +4800,7 @@ uniform float swayAmplitude;
4792
4800
  });
4793
4801
  }
4794
4802
  function soilsOf(THREE, spec) {
4795
- return (spec.basins ?? []).filter((basin) => basin.soils).map((basin) => {
4803
+ return (spec.basins ?? []).filter((basin) => basin.soils && !basin.drain).map((basin) => {
4796
4804
  const radius = Math.min(basin.to[0] - basin.from[0], basin.to[2] - basin.from[2]) * 0.3;
4797
4805
  const lump = new THREE.Mesh(new THREE.SphereGeometry(radius, 12, 8), new THREE.MeshStandardMaterial({ color: FECES, roughness: 0.95 }));
4798
4806
  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 }));
@@ -4813,12 +4821,85 @@ uniform float swayAmplitude;
4813
4821
  return { object: soil, apply: apply2 };
4814
4822
  });
4815
4823
  }
4824
+ function contentMesh(THREE, kind) {
4825
+ if (kind === "paper") return new THREE.Mesh(new THREE.SphereGeometry(0.022, 8, 6), new THREE.MeshStandardMaterial({ color: PAPER, roughness: 1 }));
4826
+ if (kind === "urine") return new THREE.Mesh(new THREE.CircleGeometry(1, 20), new THREE.MeshStandardMaterial({ color: URINE, transparent: true, opacity: 0.45, depthWrite: false }));
4827
+ const lump = new THREE.Mesh(new THREE.CapsuleGeometry(0.016, 0.07, 4, 8), new THREE.MeshStandardMaterial({ color: FECES, roughness: 0.95 }));
4828
+ return lump;
4829
+ }
4830
+ function drainOf(THREE, basin) {
4831
+ const group = new THREE.Group();
4832
+ group.name = `drain_${basin.id}`;
4833
+ const cx = (basin.from[0] + basin.to[0]) / 2;
4834
+ const cz = (basin.from[2] + basin.to[2]) / 2;
4835
+ const radius = Math.min(basin.to[0] - basin.from[0], basin.to[2] - basin.from[2]) / 2;
4836
+ const pool = /* @__PURE__ */ new Map();
4837
+ const take = (kind, used2) => {
4838
+ const list2 = pool.get(kind) ?? [];
4839
+ pool.set(kind, list2);
4840
+ const at = used2.get(kind) ?? 0;
4841
+ used2.set(kind, at + 1);
4842
+ let mesh2 = list2[at];
4843
+ if (!mesh2) {
4844
+ mesh2 = contentMesh(THREE, kind);
4845
+ mesh2.name = `content_${kind}_${at}`;
4846
+ list2.push(mesh2);
4847
+ group.add(mesh2);
4848
+ }
4849
+ mesh2.visible = true;
4850
+ return mesh2;
4851
+ };
4852
+ const streakMaterial = new THREE.MeshBasicMaterial({ color: 15398136, transparent: true, opacity: 0, depthWrite: false, side: THREE.DoubleSide });
4853
+ const streaks = Array.from({ length: SWIRL_STREAKS }, (_, i) => {
4854
+ const inner = radius * (0.15 + i * 0.22);
4855
+ const streak = new THREE.Mesh(new THREE.RingGeometry(inner, inner + radius * 0.1, 24, 1, 0, SWIRL_ARC), streakMaterial);
4856
+ streak.rotation.x = -Math.PI / 2;
4857
+ streak.name = `swirl_${i}`;
4858
+ group.add(streak);
4859
+ return streak;
4860
+ });
4861
+ const used = /* @__PURE__ */ new Map();
4862
+ let drawn;
4863
+ const apply2 = (state) => {
4864
+ const drain = state.drains?.[basin.id];
4865
+ if (drain === drawn) return;
4866
+ drawn = drain;
4867
+ for (const list2 of pool.values()) for (const mesh2 of list2) mesh2.visible = false;
4868
+ if (!drain) return;
4869
+ const surface = basin.from[1] + drain.level;
4870
+ streakMaterial.opacity = Math.min(0.55, drain.swirl * 0.7);
4871
+ for (let i = 0; i < streaks.length; i++) {
4872
+ const streak = streaks[i];
4873
+ streak.visible = drain.swirl > 0.05;
4874
+ streak.position.set(cx, surface + LIFT, cz);
4875
+ streak.rotation.z = drain.turned * (1 + (SWIRL_STREAKS - 1 - i) * 0.3) + i * Math.PI * 2 / SWIRL_STREAKS;
4876
+ }
4877
+ used.clear();
4878
+ for (let i = 0; i < Math.min(MAX_CONTENTS, drain.contents.length); i++) {
4879
+ const c = drain.contents[i];
4880
+ if (c.kind === "object") continue;
4881
+ const mesh2 = take(c.kind, used);
4882
+ const y = surface + (basin.from[1] - surface) * c.depth;
4883
+ const r = radius * 0.8 * c.radius;
4884
+ if (c.kind === "urine") {
4885
+ mesh2.scale.setScalar(radius * 0.9);
4886
+ mesh2.rotation.set(-Math.PI / 2, 0, 0);
4887
+ mesh2.position.set(cx, surface + LIFT * 2, cz);
4888
+ continue;
4889
+ }
4890
+ mesh2.position.set(cx + Math.cos(c.angle) * r, y - (c.depth === 0 ? 6e-3 : 0), cz + Math.sin(c.angle) * r);
4891
+ mesh2.rotation.set(Math.PI / 2, 0, c.angle);
4892
+ }
4893
+ };
4894
+ return { object: group, apply: apply2 };
4895
+ }
4816
4896
  function createControlsView(THREE, options) {
4817
4897
  const group = new THREE.Group();
4818
4898
  group.name = "controls-view";
4819
4899
  options.root.add(group);
4820
4900
  const screens = [];
4821
- const drawn = [...screensOf(THREE, options, screens), ...bowlsOf(THREE, options.spec), ...soilsOf(THREE, options.spec)];
4901
+ const drained = (options.spec.basins ?? []).filter((basin) => basin.drain).map((basin) => drainOf(THREE, basin));
4902
+ const drawn = [...screensOf(THREE, options, screens), ...bowlsOf(THREE, options.spec), ...soilsOf(THREE, options.spec), ...drained];
4822
4903
  for (const d of drawn) group.add(d.object);
4823
4904
  let disposed = false;
4824
4905
  return {