@adatechnology/game-interactables-three 0.2.18 → 0.3.1
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 +38 -2
- package/dist/index.global.js +179 -3
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1795,6 +1795,98 @@ function createThreeAdapter(THREE, options = {}) {
|
|
|
1795
1795
|
};
|
|
1796
1796
|
}
|
|
1797
1797
|
|
|
1798
|
+
// src/contents.ts
|
|
1799
|
+
import { discardObject3D } from "@adatechnology/game-shapes-three";
|
|
1800
|
+
function createContentsView(THREE, options) {
|
|
1801
|
+
const { world, objectId, root, buildItem } = options;
|
|
1802
|
+
const group = new THREE.Group();
|
|
1803
|
+
group.name = `contents:${objectId}`;
|
|
1804
|
+
root.add(group);
|
|
1805
|
+
const carriers = /* @__PURE__ */ new Map();
|
|
1806
|
+
const drawn = /* @__PURE__ */ new Map();
|
|
1807
|
+
const spec = world.get(objectId)?.spec;
|
|
1808
|
+
const partsById = new Map((spec?.parts ?? []).map((p) => [p.id, p]));
|
|
1809
|
+
const carrierOf = (partId) => {
|
|
1810
|
+
const part = partId === void 0 ? void 0 : partsById.get(partId);
|
|
1811
|
+
if (!part) return group;
|
|
1812
|
+
let carrier = carriers.get(part.id);
|
|
1813
|
+
if (!carrier) {
|
|
1814
|
+
carrier = new THREE.Group();
|
|
1815
|
+
carrier.name = `contents:${part.id}`;
|
|
1816
|
+
carrier.position.set(part.pivot[0], part.pivot[1], part.pivot[2]);
|
|
1817
|
+
carrier.rotation.set(0, part.ry ?? 0, 0);
|
|
1818
|
+
group.add(carrier);
|
|
1819
|
+
carriers.set(part.id, carrier);
|
|
1820
|
+
}
|
|
1821
|
+
return carrier;
|
|
1822
|
+
};
|
|
1823
|
+
const place = (object, carrier, pos, part) => {
|
|
1824
|
+
carrier.add(object);
|
|
1825
|
+
if (!part) {
|
|
1826
|
+
object.position.set(pos[0], pos[1], pos[2]);
|
|
1827
|
+
return;
|
|
1828
|
+
}
|
|
1829
|
+
const ry = part.ry ?? 0;
|
|
1830
|
+
const x = pos[0] - part.pivot[0];
|
|
1831
|
+
const z = pos[2] - part.pivot[2];
|
|
1832
|
+
const c = Math.cos(ry);
|
|
1833
|
+
const s = Math.sin(ry);
|
|
1834
|
+
object.position.set(c * x - s * z, pos[1] - part.pivot[1], s * x + c * z);
|
|
1835
|
+
object.rotation.set(0, -ry, 0);
|
|
1836
|
+
};
|
|
1837
|
+
function sync() {
|
|
1838
|
+
const live = /* @__PURE__ */ new Set();
|
|
1839
|
+
for (const c of spec?.containers ?? []) {
|
|
1840
|
+
const shown = c.access === void 0 || world.partT(objectId, c.access) > 0;
|
|
1841
|
+
const stacks = world.contents(objectId, c.id);
|
|
1842
|
+
c.slots.forEach((slot, i) => {
|
|
1843
|
+
const stack = stacks[i];
|
|
1844
|
+
const key = `${c.id}#${i}`;
|
|
1845
|
+
const had = drawn.get(key);
|
|
1846
|
+
if (had && (!stack || stack.type !== had.type)) {
|
|
1847
|
+
discardObject3D(had.object);
|
|
1848
|
+
drawn.delete(key);
|
|
1849
|
+
}
|
|
1850
|
+
if (!stack) return;
|
|
1851
|
+
live.add(key);
|
|
1852
|
+
let now = drawn.get(key);
|
|
1853
|
+
if (!now) {
|
|
1854
|
+
const object = buildItem(stack, THREE);
|
|
1855
|
+
if (!object) return;
|
|
1856
|
+
object.name = `contents_${c.id}_${i}`;
|
|
1857
|
+
object.userData.contents = { object: objectId, container: c.id, slot: i, item: stack.type, qty: stack.qty };
|
|
1858
|
+
place(object, carrierOf(slot.part), slot.pos, slot.part === void 0 ? void 0 : partsById.get(slot.part));
|
|
1859
|
+
now = { type: stack.type, object };
|
|
1860
|
+
drawn.set(key, now);
|
|
1861
|
+
}
|
|
1862
|
+
now.object.visible = shown;
|
|
1863
|
+
});
|
|
1864
|
+
}
|
|
1865
|
+
for (const [key, d] of drawn) {
|
|
1866
|
+
if (live.has(key)) continue;
|
|
1867
|
+
discardObject3D(d.object);
|
|
1868
|
+
drawn.delete(key);
|
|
1869
|
+
}
|
|
1870
|
+
for (const [partId, carrier] of carriers) {
|
|
1871
|
+
const part = partsById.get(partId);
|
|
1872
|
+
if (part) applyPose(THREE, carrier, part.motion, world.partT(objectId, partId));
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
return {
|
|
1876
|
+
group,
|
|
1877
|
+
sync,
|
|
1878
|
+
items: () => [...drawn].map(([key, d]) => {
|
|
1879
|
+
const cut = key.lastIndexOf("#");
|
|
1880
|
+
return { container: key.slice(0, cut), slot: Number(key.slice(cut + 1)), type: d.type, object: d.object };
|
|
1881
|
+
}),
|
|
1882
|
+
dispose() {
|
|
1883
|
+
discardObject3D(group);
|
|
1884
|
+
drawn.clear();
|
|
1885
|
+
carriers.clear();
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1798
1890
|
// src/cord.ts
|
|
1799
1891
|
import { catenary as catenary2, createCord as createCord2 } from "@adatechnology/game-shapes-three";
|
|
1800
1892
|
|
|
@@ -1820,6 +1912,7 @@ export {
|
|
|
1820
1912
|
applyPose,
|
|
1821
1913
|
attachSway,
|
|
1822
1914
|
catenary2 as catenary,
|
|
1915
|
+
createContentsView,
|
|
1823
1916
|
createCord2 as createCord,
|
|
1824
1917
|
createDefaultMaterials,
|
|
1825
1918
|
createEffects,
|