@adatechnology/game-interactables-three 0.5.1 → 0.6.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/README.md +8 -2
- package/dist/index.d.ts +30 -4
- package/dist/index.global.js +174 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +96 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -730,7 +730,7 @@ import { createShapeRecorder } from "@adatechnology/game-props3d";
|
|
|
730
730
|
import { colorChannels, generate } from "@adatechnology/game-shapes";
|
|
731
731
|
|
|
732
732
|
// src/types.ts
|
|
733
|
-
var MATERIAL_KEYS = ["plain", "metal", "wood", "glass", "fabric", "plant", "water", "emissive", "atlas_picture", "atlas_floor"];
|
|
733
|
+
var MATERIAL_KEYS = ["plain", "metal", "wood", "glass", "fabric", "foam", "plant", "water", "emissive", "atlas_picture", "atlas_floor"];
|
|
734
734
|
|
|
735
735
|
// src/pose.ts
|
|
736
736
|
import { poseOf as enginePoseOf } from "@adatechnology/game-interactables";
|
|
@@ -1351,6 +1351,7 @@ function createDefaultMaterials(THREE, quality = "high") {
|
|
|
1351
1351
|
wood: solid ?? std({ roughness: 0.8 }),
|
|
1352
1352
|
glass: std({ roughness: 0.05, transparent: true, opacity: 0.35, depthWrite: false }),
|
|
1353
1353
|
fabric: solid ?? std({ roughness: 1 }),
|
|
1354
|
+
foam: solid ?? std({ roughness: 1 }),
|
|
1354
1355
|
plant: std({ roughness: 0.9, side: THREE.DoubleSide }),
|
|
1355
1356
|
water: std({ roughness: 0.1, transparent: true, opacity: 0.7, depthWrite: false }),
|
|
1356
1357
|
emissive: new THREE.MeshBasicMaterial({ vertexColors: true }),
|
|
@@ -1952,6 +1953,99 @@ function wireMeshes(THREE, wires) {
|
|
|
1952
1953
|
return meshes;
|
|
1953
1954
|
}
|
|
1954
1955
|
|
|
1956
|
+
// src/span-wire.ts
|
|
1957
|
+
import { hangTail, solveSpan } from "@adatechnology/game-interactables";
|
|
1958
|
+
var MOVED = 1e-3;
|
|
1959
|
+
function tubeGeometry(THREE, rings, sides) {
|
|
1960
|
+
const geometry = new THREE.BufferGeometry();
|
|
1961
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array(rings * sides * 3), 3));
|
|
1962
|
+
geometry.setAttribute("normal", new THREE.BufferAttribute(new Float32Array(rings * sides * 3), 3));
|
|
1963
|
+
const index = [];
|
|
1964
|
+
for (let r = 0; r + 1 < rings; r++) {
|
|
1965
|
+
for (let s = 0; s < sides; s++) {
|
|
1966
|
+
const a = r * sides + s;
|
|
1967
|
+
const b = r * sides + (s + 1) % sides;
|
|
1968
|
+
index.push(a, a + sides, b, b, a + sides, b + sides);
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
geometry.setIndex(index);
|
|
1972
|
+
return geometry;
|
|
1973
|
+
}
|
|
1974
|
+
function frameAt(points, i) {
|
|
1975
|
+
const before = points[Math.max(0, i - 1)];
|
|
1976
|
+
const after = points[Math.min(points.length - 1, i + 1)];
|
|
1977
|
+
const length = Math.hypot(after[0] - before[0], after[1] - before[1], after[2] - before[2]) || 1;
|
|
1978
|
+
const t = [(after[0] - before[0]) / length, (after[1] - before[1]) / length, (after[2] - before[2]) / length];
|
|
1979
|
+
const upright = Math.abs(t[1]) > 0.9;
|
|
1980
|
+
const raw = upright ? [0, t[2], -t[1]] : [-t[2], 0, t[0]];
|
|
1981
|
+
const nl = Math.hypot(raw[0], raw[1], raw[2]) || 1;
|
|
1982
|
+
const n = [raw[0] / nl, raw[1] / nl, raw[2] / nl];
|
|
1983
|
+
return { n, b: [t[1] * n[2] - t[2] * n[1], t[2] * n[0] - t[0] * n[2], t[0] * n[1] - t[1] * n[0]] };
|
|
1984
|
+
}
|
|
1985
|
+
function writeTube(geometry, points, radius, sides) {
|
|
1986
|
+
const position = geometry.getAttribute("position");
|
|
1987
|
+
const normal = geometry.getAttribute("normal");
|
|
1988
|
+
for (let i = 0; i < points.length; i++) {
|
|
1989
|
+
const { n, b } = frameAt(points, i);
|
|
1990
|
+
const p = points[i];
|
|
1991
|
+
for (let s = 0; s < sides; s++) {
|
|
1992
|
+
const angle = s / sides * Math.PI * 2;
|
|
1993
|
+
const ox = n[0] * Math.cos(angle) + b[0] * Math.sin(angle);
|
|
1994
|
+
const oy = n[1] * Math.cos(angle) + b[1] * Math.sin(angle);
|
|
1995
|
+
const oz = n[2] * Math.cos(angle) + b[2] * Math.sin(angle);
|
|
1996
|
+
position.setXYZ(i * sides + s, p[0] + ox * radius, p[1] + oy * radius, p[2] + oz * radius);
|
|
1997
|
+
normal.setXYZ(i * sides + s, ox, oy, oz);
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
position.needsUpdate = true;
|
|
2001
|
+
normal.needsUpdate = true;
|
|
2002
|
+
geometry.computeBoundingSphere();
|
|
2003
|
+
geometry.computeBoundingBox();
|
|
2004
|
+
}
|
|
2005
|
+
var movedFrom = (last, now) => !last || Math.hypot(now[0] - last[0], now[1] - last[1], now[2] - last[2]) > MOVED;
|
|
2006
|
+
function createSpanWire(THREE, options) {
|
|
2007
|
+
const segments = Math.max(2, Math.floor(options.segments ?? 16));
|
|
2008
|
+
const sides = Math.max(3, Math.floor(options.radialSegments ?? 5));
|
|
2009
|
+
const geometry = tubeGeometry(THREE, segments, sides);
|
|
2010
|
+
const mesh = new THREE.Mesh(geometry, options.material);
|
|
2011
|
+
mesh.name = "span-wire";
|
|
2012
|
+
mesh.castShadow = true;
|
|
2013
|
+
const ground = options.ground ? { ground: options.ground } : {};
|
|
2014
|
+
const clearance = options.radius;
|
|
2015
|
+
let snapped = null;
|
|
2016
|
+
let lastFrom = null;
|
|
2017
|
+
let lastTo = null;
|
|
2018
|
+
return {
|
|
2019
|
+
mesh,
|
|
2020
|
+
get snapped() {
|
|
2021
|
+
return snapped;
|
|
2022
|
+
},
|
|
2023
|
+
update(from, to) {
|
|
2024
|
+
if (!movedFrom(lastFrom, from) && !movedFrom(lastTo, to)) return null;
|
|
2025
|
+
lastFrom = [from[0], from[1], from[2]];
|
|
2026
|
+
lastTo = [to[0], to[1], to[2]];
|
|
2027
|
+
const shape = solveSpan({ span: options.span, from, to, segments, clearance, ...ground });
|
|
2028
|
+
if (!snapped && shape.snaps) {
|
|
2029
|
+
snapped = shape.snaps;
|
|
2030
|
+
options.onSnap?.(shape.snaps, shape);
|
|
2031
|
+
}
|
|
2032
|
+
if (!snapped) {
|
|
2033
|
+
writeTube(geometry, shape.points, options.radius, sides);
|
|
2034
|
+
return shape;
|
|
2035
|
+
}
|
|
2036
|
+
const anchor = snapped === "from" ? to : from;
|
|
2037
|
+
const other = snapped === "from" ? from : to;
|
|
2038
|
+
const toward = [other[0] - anchor[0], 0, other[2] - anchor[2]];
|
|
2039
|
+
writeTube(geometry, hangTail({ anchor, length: options.span.length, toward, segments, clearance, ...ground }), options.radius, sides);
|
|
2040
|
+
return shape;
|
|
2041
|
+
},
|
|
2042
|
+
dispose() {
|
|
2043
|
+
mesh.removeFromParent();
|
|
2044
|
+
geometry.dispose();
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
|
|
1955
2049
|
// src/controls-view.ts
|
|
1956
2050
|
import { discardObject3D as discardObject3D2 } from "@adatechnology/game-shapes-three";
|
|
1957
2051
|
var FOOD = 8018480;
|
|
@@ -2052,6 +2146,7 @@ export {
|
|
|
2052
2146
|
createMeshApi,
|
|
2053
2147
|
createMirrors,
|
|
2054
2148
|
createScreen,
|
|
2149
|
+
createSpanWire,
|
|
2055
2150
|
createThreeAdapter,
|
|
2056
2151
|
mergeParts,
|
|
2057
2152
|
patchSwayShader,
|