@adatechnology/game-interactables-three 0.6.2 → 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.global.js +102 -20
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +80 -3
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.global.js
CHANGED
|
@@ -3029,28 +3029,29 @@ void main() {
|
|
|
3029
3029
|
// ../game-shapes-three/dist/index.js
|
|
3030
3030
|
function catenary(a, b, sag, n = 12) {
|
|
3031
3031
|
const count = Math.max(2, Math.floor(n));
|
|
3032
|
-
const span =
|
|
3033
|
-
const depth = Math.max(0, sag);
|
|
3032
|
+
const { span, c } = catenaryOf(a[0], a[1], a[2], b[0], b[1], b[2], sag);
|
|
3034
3033
|
const out = [];
|
|
3035
|
-
let shape = () => 0;
|
|
3036
|
-
if (depth > 1e-6 && span > 1e-6) {
|
|
3037
|
-
let lo = 1e-4;
|
|
3038
|
-
let hi = span * 1e3;
|
|
3039
|
-
for (let i = 0; i < 80; i++) {
|
|
3040
|
-
const c2 = (lo + hi) / 2;
|
|
3041
|
-
const d = c2 * (Math.cosh(span / (2 * c2)) - 1);
|
|
3042
|
-
if (d > depth) lo = c2;
|
|
3043
|
-
else hi = c2;
|
|
3044
|
-
}
|
|
3045
|
-
const c = (lo + hi) / 2;
|
|
3046
|
-
shape = (s) => c * (Math.cosh((s - 0.5) * span / c) - Math.cosh(span / (2 * c)));
|
|
3047
|
-
}
|
|
3048
3034
|
for (let i = 0; i < count; i++) {
|
|
3049
3035
|
const s = i / (count - 1);
|
|
3050
|
-
out.push([a[0] + (b[0] - a[0]) * s, a[1] + (b[1] - a[1]) * s +
|
|
3036
|
+
out.push([a[0] + (b[0] - a[0]) * s, a[1] + (b[1] - a[1]) * s + catenaryDrop(span, c, s), a[2] + (b[2] - a[2]) * s]);
|
|
3051
3037
|
}
|
|
3052
3038
|
return out;
|
|
3053
3039
|
}
|
|
3040
|
+
var catenaryOf = (ax, ay, az, bx, by, bz, sag) => {
|
|
3041
|
+
const span = Math.hypot(bx - ax, bz - az) || Math.hypot(bx - ax, by - ay, bz - az);
|
|
3042
|
+
const depth = Math.max(0, sag);
|
|
3043
|
+
if (depth <= 1e-6 || span <= 1e-6) return { span, c: 0 };
|
|
3044
|
+
let lo = 1e-4;
|
|
3045
|
+
let hi = span * 1e3;
|
|
3046
|
+
for (let i = 0; i < 80; i++) {
|
|
3047
|
+
const c = (lo + hi) / 2;
|
|
3048
|
+
const d = c * (Math.cosh(span / (2 * c)) - 1);
|
|
3049
|
+
if (d > depth) lo = c;
|
|
3050
|
+
else hi = c;
|
|
3051
|
+
}
|
|
3052
|
+
return { span, c: (lo + hi) / 2 };
|
|
3053
|
+
};
|
|
3054
|
+
var catenaryDrop = (span, c, s) => c > 0 ? c * (Math.cosh((s - 0.5) * span / c) - Math.cosh(span / (2 * c))) : 0;
|
|
3054
3055
|
function createCord(THREE, points, radius, material, radialSegments = 5) {
|
|
3055
3056
|
if (points.length < 2) throw new Error("createCord needs at least two points");
|
|
3056
3057
|
const curve = new THREE.CatmullRomCurve3(points.map((p) => new THREE.Vector3(p[0], p[1], p[2])), false, "centripetal");
|
|
@@ -3068,13 +3069,16 @@ void main() {
|
|
|
3068
3069
|
for (const u of Object.values(uniforms)) if (isTexture(u?.value)) out.add(u.value);
|
|
3069
3070
|
}
|
|
3070
3071
|
}
|
|
3072
|
+
var isInstanced = (o) => o.isInstancedMesh === true;
|
|
3071
3073
|
function collect(roots) {
|
|
3072
3074
|
const geometries = /* @__PURE__ */ new Set();
|
|
3073
3075
|
const materials = /* @__PURE__ */ new Set();
|
|
3074
3076
|
const textures = /* @__PURE__ */ new Set();
|
|
3075
3077
|
const skeletons = /* @__PURE__ */ new Set();
|
|
3078
|
+
const instanced = /* @__PURE__ */ new Set();
|
|
3076
3079
|
for (const root of roots) {
|
|
3077
3080
|
root.traverse((object2) => {
|
|
3081
|
+
if (isInstanced(object2)) instanced.add(object2);
|
|
3078
3082
|
const o = object2;
|
|
3079
3083
|
if (o.geometry && typeof o.geometry.dispose === "function") geometries.add(o.geometry);
|
|
3080
3084
|
if (o.skeleton && typeof o.skeleton.dispose === "function") skeletons.add(o.skeleton);
|
|
@@ -3086,7 +3090,7 @@ void main() {
|
|
|
3086
3090
|
}
|
|
3087
3091
|
});
|
|
3088
3092
|
}
|
|
3089
|
-
return { geometries, materials, textures, skeletons };
|
|
3093
|
+
return { geometries, materials, textures, skeletons, instanced };
|
|
3090
3094
|
}
|
|
3091
3095
|
var marked = /* @__PURE__ */ new WeakSet();
|
|
3092
3096
|
var shared = (r) => r.userData?.shared === true || marked.has(r);
|
|
@@ -3131,6 +3135,7 @@ void main() {
|
|
|
3131
3135
|
report.textures++;
|
|
3132
3136
|
}
|
|
3133
3137
|
for (const s of found.skeletons) s.dispose();
|
|
3138
|
+
for (const mesh2 of found.instanced) mesh2.dispose();
|
|
3134
3139
|
return report;
|
|
3135
3140
|
}
|
|
3136
3141
|
function discardObject3D(objects, options = {}) {
|
|
@@ -4608,7 +4613,7 @@ uniform float swayAmplitude;
|
|
|
4608
4613
|
const object2 = buildItem(stack, THREE);
|
|
4609
4614
|
if (!object2) return;
|
|
4610
4615
|
object2.name = `contents_${c.id}_${i}`;
|
|
4611
|
-
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 } : {} };
|
|
4612
4617
|
place(object2, carrierOf(slot.part), slot.pos, slot.part === void 0 ? void 0 : partsById.get(slot.part));
|
|
4613
4618
|
now = { type: stack.type, object: object2 };
|
|
4614
4619
|
drawn.set(key, now);
|
|
@@ -4755,6 +4760,10 @@ uniform float swayAmplitude;
|
|
|
4755
4760
|
var FECES = 5913116;
|
|
4756
4761
|
var LIFT = 2e-3;
|
|
4757
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;
|
|
4758
4767
|
function screensOf(THREE, options, screens) {
|
|
4759
4768
|
return (options.spec.devices ?? []).flatMap((device) => {
|
|
4760
4769
|
if (device.kind !== "screen" || !device.display) return [];
|
|
@@ -4791,7 +4800,7 @@ uniform float swayAmplitude;
|
|
|
4791
4800
|
});
|
|
4792
4801
|
}
|
|
4793
4802
|
function soilsOf(THREE, spec) {
|
|
4794
|
-
return (spec.basins ?? []).filter((basin) => basin.soils).map((basin) => {
|
|
4803
|
+
return (spec.basins ?? []).filter((basin) => basin.soils && !basin.drain).map((basin) => {
|
|
4795
4804
|
const radius = Math.min(basin.to[0] - basin.from[0], basin.to[2] - basin.from[2]) * 0.3;
|
|
4796
4805
|
const lump = new THREE.Mesh(new THREE.SphereGeometry(radius, 12, 8), new THREE.MeshStandardMaterial({ color: FECES, roughness: 0.95 }));
|
|
4797
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 }));
|
|
@@ -4812,12 +4821,85 @@ uniform float swayAmplitude;
|
|
|
4812
4821
|
return { object: soil, apply: apply2 };
|
|
4813
4822
|
});
|
|
4814
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
|
+
}
|
|
4815
4896
|
function createControlsView(THREE, options) {
|
|
4816
4897
|
const group = new THREE.Group();
|
|
4817
4898
|
group.name = "controls-view";
|
|
4818
4899
|
options.root.add(group);
|
|
4819
4900
|
const screens = [];
|
|
4820
|
-
const
|
|
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];
|
|
4821
4903
|
for (const d of drawn) group.add(d.object);
|
|
4822
4904
|
let disposed = false;
|
|
4823
4905
|
return {
|