@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
1,407 lines (1,406 loc) • 1.6 MB
JavaScript
const xo = "169.19", vE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 }, ME = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 }, mM = 0, zm = 1, gM = 2, SE = 3, TE = 0, yg = 1, xM = 2, di = 3, nr = 0, fn = 1, Ts = 2, rs = 0, Tr = 1, ku = 2, Um = 3, Om = 4, yM = 5, vr = 100, _M = 101, vM = 102, MM = 103, SM = 104, TM = 200, bM = 201, wM = 202, AM = 203, Hu = 204, Gu = 205, EM = 206, NM = 207, CM = 208, RM = 209, IM = 210, PM = 211, LM = 212, DM = 213, FM = 214, Wu = 0, Xu = 1, qu = 2, No = 3, $u = 4, Yu = 5, Zu = 6, Ju = 7, Ya = 0, _g = 1, vg = 2, ki = 0, Mg = 1, Sg = 2, Tg = 3, bg = 4, zM = 5, wg = 6, Ag = 7, Bm = "attached", UM = "detached", qd = 300, Ci = 301, Hi = 302, Co = 303, Ro = 304, Oo = 306, Io = 1e3, Oi = 1001, nl = 1002, rn = 1003, Eg = 1004, bE = 1004, Sr = 1005, wE = 1005, He = 1006, yo = 1007, AE = 1007, mi = 1008, OM = 1008, Ns = 1009, Ng = 1010, Cg = 1011, Va = 1012, Za = 1013, ls = 1014, jn = 1015, Wn = 1016, $d = 1017, Yd = 1018, Po = 1020, Rg = 35902, Ig = 35899, Pg = 1021, Lg = 1022, Gn = 1023, Dg = 1024, Fg = 1025, _o = 1026, Lo = 1027, Zd = 1028, Al = 1029, il = 1030, Jd = 1031, EE = 1032, Kd = 1033, Vc = 33776, kc = 33777, Hc = 33778, Gc = 33779, Ku = 35840, ju = 35841, Qu = 35842, td = 35843, ed = 36196, nd = 37492, id = 37496, sd = 37808, rd = 37809, od = 37810, ad = 37811, cd = 37812, ld = 37813, hd = 37814, ud = 37815, dd = 37816, pd = 37817, fd = 37818, md = 37819, gd = 37820, xd = 37821, Wc = 36492, yd = 36494, _d = 36495, zg = 36283, vd = 36284, Md = 36285, Sd = 36286, BM = 2200, VM = 2201, kM = 2202, sl = 2300, Td = 2301, Ru = 2302, ho = 2400, uo = 2401, rl = 2402, jd = 2500, Ug = 2501, NE = 0, CE = 1, RE = 2, HM = 3200, GM = 3201, IE = 3202, PE = 3203, Cs = 0, Og = 1, ns = "", Jn = "srgb", Ri = "srgb-linear", Qd = "display-p3", El = "display-p3-linear", ol = "linear", Be = "srgb", al = "rec709", cl = "p3", LE = 0, ro = 7680, DE = 7681, FE = 7682, zE = 7683, UE = 34055, OE = 34056, BE = 5386, VE = 512, kE = 513, HE = 514, GE = 515, WE = 516, XE = 517, qE = 518, Vm = 519, WM = 512, Bg = 513, XM = 514, Vg = 515, qM = 516, $M = 517, YM = 518, ZM = 519, ka = 35044, Na = 35048, $E = 35040, YE = 35045, ZE = 35049, JE = 35041, KE = 35046, jE = 35050, QE = 35042, tN = "100", km = "300 es", Bi = 2e3, Do = 2001;
let Gi = class {
addEventListener(t, e) {
this._listeners === void 0 && (this._listeners = {});
const n = this._listeners;
n[t] === void 0 && (n[t] = []), n[t].indexOf(e) === -1 && n[t].push(e);
}
hasEventListener(t, e) {
if (this._listeners === void 0) return !1;
const n = this._listeners;
return n[t] !== void 0 && n[t].indexOf(e) !== -1;
}
removeEventListener(t, e) {
if (this._listeners === void 0) return;
const i = this._listeners[t];
if (i !== void 0) {
const s = i.indexOf(e);
s !== -1 && i.splice(s, 1);
}
}
dispatchEvent(t) {
if (this._listeners === void 0) return;
const n = this._listeners[t.type];
if (n !== void 0) {
t.target = this;
const i = n.slice(0);
for (let s = 0, o = i.length; s < o; s++)
i[s].call(this, t);
t.target = null;
}
}
};
const On = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"];
let oy = 1234567;
const vo = Math.PI / 180, Ha = 180 / Math.PI;
function Ni() {
const r = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, e = Math.random() * 4294967295 | 0, n = Math.random() * 4294967295 | 0;
return (On[r & 255] + On[r >> 8 & 255] + On[r >> 16 & 255] + On[r >> 24 & 255] + "-" + On[t & 255] + On[t >> 8 & 255] + "-" + On[t >> 16 & 15 | 64] + On[t >> 24 & 255] + "-" + On[e & 63 | 128] + On[e >> 8 & 255] + "-" + On[e >> 16 & 255] + On[e >> 24 & 255] + On[n & 255] + On[n >> 8 & 255] + On[n >> 16 & 255] + On[n >> 24 & 255]).toLowerCase();
}
function Qe(r, t, e) {
return Math.max(t, Math.min(e, r));
}
function kg(r, t) {
return (r % t + t) % t;
}
function eN(r, t, e, n, i) {
return n + (r - t) * (i - n) / (e - t);
}
function nN(r, t, e) {
return r !== t ? (e - r) / (t - r) : 0;
}
function Xc(r, t, e) {
return (1 - e) * r + e * t;
}
function iN(r, t, e, n) {
return Xc(r, t, 1 - Math.exp(-e * n));
}
function sN(r, t = 1) {
return t - Math.abs(kg(r, t * 2) - t);
}
function rN(r, t, e) {
return r <= t ? 0 : r >= e ? 1 : (r = (r - t) / (e - t), r * r * (3 - 2 * r));
}
function oN(r, t, e) {
return r <= t ? 0 : r >= e ? 1 : (r = (r - t) / (e - t), r * r * r * (r * (r * 6 - 15) + 10));
}
function aN(r, t) {
return r + Math.floor(Math.random() * (t - r + 1));
}
function cN(r, t) {
return r + Math.random() * (t - r);
}
function lN(r) {
return r * (0.5 - Math.random());
}
function hN(r) {
r !== void 0 && (oy = r);
let t = oy += 1831565813;
return t = Math.imul(t ^ t >>> 15, t | 1), t ^= t + Math.imul(t ^ t >>> 7, t | 61), ((t ^ t >>> 14) >>> 0) / 4294967296;
}
function uN(r) {
return r * vo;
}
function dN(r) {
return r * Ha;
}
function pN(r) {
return (r & r - 1) === 0 && r !== 0;
}
function fN(r) {
return Math.pow(2, Math.ceil(Math.log(r) / Math.LN2));
}
function mN(r) {
return Math.pow(2, Math.floor(Math.log(r) / Math.LN2));
}
function gN(r, t, e, n, i) {
const s = Math.cos, o = Math.sin, a = s(e / 2), c = o(e / 2), l = s((t + n) / 2), h = o((t + n) / 2), u = s((t - n) / 2), d = o((t - n) / 2), p = s((n - t) / 2), f = o((n - t) / 2);
switch (i) {
case "XYX":
r.set(a * h, c * u, c * d, a * l);
break;
case "YZY":
r.set(c * d, a * h, c * u, a * l);
break;
case "ZXZ":
r.set(c * u, c * d, a * h, a * l);
break;
case "XZX":
r.set(a * h, c * f, c * p, a * l);
break;
case "YXY":
r.set(c * p, a * h, c * f, a * l);
break;
case "ZYZ":
r.set(c * f, c * p, a * h, a * l);
break;
default:
console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: " + i);
}
}
function Kn(r, t) {
switch (t.constructor) {
case Float32Array:
return r;
case Uint32Array:
return r / 4294967295;
case Uint16Array:
return r / 65535;
case Uint8Array:
return r / 255;
case Int32Array:
return Math.max(r / 2147483647, -1);
case Int16Array:
return Math.max(r / 32767, -1);
case Int8Array:
return Math.max(r / 127, -1);
default:
throw new Error("Invalid component type.");
}
}
function ce(r, t) {
switch (t.constructor) {
case Float32Array:
return r;
case Uint32Array:
return Math.round(r * 4294967295);
case Uint16Array:
return Math.round(r * 65535);
case Uint8Array:
return Math.round(r * 255);
case Int32Array:
return Math.round(r * 2147483647);
case Int16Array:
return Math.round(r * 32767);
case Int8Array:
return Math.round(r * 127);
default:
throw new Error("Invalid component type.");
}
}
const Hg = {
DEG2RAD: vo,
RAD2DEG: Ha,
generateUUID: Ni,
clamp: Qe,
euclideanModulo: kg,
mapLinear: eN,
inverseLerp: nN,
lerp: Xc,
damp: iN,
pingpong: sN,
smoothstep: rN,
smootherstep: oN,
randInt: aN,
randFloat: cN,
randFloatSpread: lN,
seededRandom: hN,
degToRad: uN,
radToDeg: dN,
isPowerOfTwo: pN,
ceilPowerOfTwo: fN,
floorPowerOfTwo: mN,
setQuaternionFromProperEuler: gN,
normalize: ce,
denormalize: Kn
};
let Q = class JM {
constructor(t = 0, e = 0) {
JM.prototype.isVector2 = !0, this.x = t, this.y = e;
}
get width() {
return this.x;
}
set width(t) {
this.x = t;
}
get height() {
return this.y;
}
set height(t) {
this.y = t;
}
set(t, e) {
return this.x = t, this.y = e, this;
}
setScalar(t) {
return this.x = t, this.y = t, this;
}
setX(t) {
return this.x = t, this;
}
setY(t) {
return this.y = t, this;
}
setComponent(t, e) {
switch (t) {
case 0:
this.x = e;
break;
case 1:
this.y = e;
break;
default:
throw new Error("index is out of range: " + t);
}
return this;
}
getComponent(t) {
switch (t) {
case 0:
return this.x;
case 1:
return this.y;
default:
throw new Error("index is out of range: " + t);
}
}
clone() {
return new this.constructor(this.x, this.y);
}
copy(t) {
return this.x = t.x, this.y = t.y, this;
}
add(t) {
return this.x += t.x, this.y += t.y, this;
}
addScalar(t) {
return this.x += t, this.y += t, this;
}
addVectors(t, e) {
return this.x = t.x + e.x, this.y = t.y + e.y, this;
}
addScaledVector(t, e) {
return this.x += t.x * e, this.y += t.y * e, this;
}
sub(t) {
return this.x -= t.x, this.y -= t.y, this;
}
subScalar(t) {
return this.x -= t, this.y -= t, this;
}
subVectors(t, e) {
return this.x = t.x - e.x, this.y = t.y - e.y, this;
}
multiply(t) {
return this.x *= t.x, this.y *= t.y, this;
}
multiplyScalar(t) {
return this.x *= t, this.y *= t, this;
}
divide(t) {
return this.x /= t.x, this.y /= t.y, this;
}
divideScalar(t) {
return this.multiplyScalar(1 / t);
}
applyMatrix3(t) {
const e = this.x, n = this.y, i = t.elements;
return this.x = i[0] * e + i[3] * n + i[6], this.y = i[1] * e + i[4] * n + i[7], this;
}
min(t) {
return this.x = Math.min(this.x, t.x), this.y = Math.min(this.y, t.y), this;
}
max(t) {
return this.x = Math.max(this.x, t.x), this.y = Math.max(this.y, t.y), this;
}
clamp(t, e) {
return this.x = Math.max(t.x, Math.min(e.x, this.x)), this.y = Math.max(t.y, Math.min(e.y, this.y)), this;
}
clampScalar(t, e) {
return this.x = Math.max(t, Math.min(e, this.x)), this.y = Math.max(t, Math.min(e, this.y)), this;
}
clampLength(t, e) {
const n = this.length();
return this.divideScalar(n || 1).multiplyScalar(Math.max(t, Math.min(e, n)));
}
floor() {
return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this;
}
ceil() {
return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this;
}
round() {
return this.x = Math.round(this.x), this.y = Math.round(this.y), this;
}
roundToZero() {
return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this;
}
negate() {
return this.x = -this.x, this.y = -this.y, this;
}
dot(t) {
return this.x * t.x + this.y * t.y;
}
cross(t) {
return this.x * t.y - this.y * t.x;
}
lengthSq() {
return this.x * this.x + this.y * this.y;
}
length() {
return Math.sqrt(this.x * this.x + this.y * this.y);
}
manhattanLength() {
return Math.abs(this.x) + Math.abs(this.y);
}
normalize() {
return this.divideScalar(this.length() || 1);
}
angle() {
return Math.atan2(-this.y, -this.x) + Math.PI;
}
angleTo(t) {
const e = Math.sqrt(this.lengthSq() * t.lengthSq());
if (e === 0) return Math.PI / 2;
const n = this.dot(t) / e;
return Math.acos(Qe(n, -1, 1));
}
distanceTo(t) {
return Math.sqrt(this.distanceToSquared(t));
}
distanceToSquared(t) {
const e = this.x - t.x, n = this.y - t.y;
return e * e + n * n;
}
manhattanDistanceTo(t) {
return Math.abs(this.x - t.x) + Math.abs(this.y - t.y);
}
setLength(t) {
return this.normalize().multiplyScalar(t);
}
lerp(t, e) {
return this.x += (t.x - this.x) * e, this.y += (t.y - this.y) * e, this;
}
lerpVectors(t, e, n) {
return this.x = t.x + (e.x - t.x) * n, this.y = t.y + (e.y - t.y) * n, this;
}
equals(t) {
return t.x === this.x && t.y === this.y;
}
fromArray(t, e = 0) {
return this.x = t[e], this.y = t[e + 1], this;
}
toArray(t = [], e = 0) {
return t[e] = this.x, t[e + 1] = this.y, t;
}
fromBufferAttribute(t, e) {
return this.x = t.getX(e), this.y = t.getY(e), this;
}
rotateAround(t, e) {
const n = Math.cos(e), i = Math.sin(e), s = this.x - t.x, o = this.y - t.y;
return this.x = s * n - o * i + t.x, this.y = s * i + o * n + t.y, this;
}
random() {
return this.x = Math.random(), this.y = Math.random(), this;
}
*[Symbol.iterator]() {
yield this.x, yield this.y;
}
}, ie = class KM {
constructor(t, e, n, i, s, o, a, c, l) {
KM.prototype.isMatrix3 = !0, this.elements = [
1,
0,
0,
0,
1,
0,
0,
0,
1
], t !== void 0 && this.set(t, e, n, i, s, o, a, c, l);
}
set(t, e, n, i, s, o, a, c, l) {
const h = this.elements;
return h[0] = t, h[1] = i, h[2] = a, h[3] = e, h[4] = s, h[5] = c, h[6] = n, h[7] = o, h[8] = l, this;
}
identity() {
return this.set(
1,
0,
0,
0,
1,
0,
0,
0,
1
), this;
}
copy(t) {
const e = this.elements, n = t.elements;
return e[0] = n[0], e[1] = n[1], e[2] = n[2], e[3] = n[3], e[4] = n[4], e[5] = n[5], e[6] = n[6], e[7] = n[7], e[8] = n[8], this;
}
extractBasis(t, e, n) {
return t.setFromMatrix3Column(this, 0), e.setFromMatrix3Column(this, 1), n.setFromMatrix3Column(this, 2), this;
}
setFromMatrix4(t) {
const e = t.elements;
return this.set(
e[0],
e[4],
e[8],
e[1],
e[5],
e[9],
e[2],
e[6],
e[10]
), this;
}
multiply(t) {
return this.multiplyMatrices(this, t);
}
premultiply(t) {
return this.multiplyMatrices(t, this);
}
multiplyMatrices(t, e) {
const n = t.elements, i = e.elements, s = this.elements, o = n[0], a = n[3], c = n[6], l = n[1], h = n[4], u = n[7], d = n[2], p = n[5], f = n[8], x = i[0], m = i[3], g = i[6], _ = i[1], y = i[4], v = i[7], C = i[2], S = i[5], T = i[8];
return s[0] = o * x + a * _ + c * C, s[3] = o * m + a * y + c * S, s[6] = o * g + a * v + c * T, s[1] = l * x + h * _ + u * C, s[4] = l * m + h * y + u * S, s[7] = l * g + h * v + u * T, s[2] = d * x + p * _ + f * C, s[5] = d * m + p * y + f * S, s[8] = d * g + p * v + f * T, this;
}
multiplyScalar(t) {
const e = this.elements;
return e[0] *= t, e[3] *= t, e[6] *= t, e[1] *= t, e[4] *= t, e[7] *= t, e[2] *= t, e[5] *= t, e[8] *= t, this;
}
determinant() {
const t = this.elements, e = t[0], n = t[1], i = t[2], s = t[3], o = t[4], a = t[5], c = t[6], l = t[7], h = t[8];
return e * o * h - e * a * l - n * s * h + n * a * c + i * s * l - i * o * c;
}
invert() {
const t = this.elements, e = t[0], n = t[1], i = t[2], s = t[3], o = t[4], a = t[5], c = t[6], l = t[7], h = t[8], u = h * o - a * l, d = a * c - h * s, p = l * s - o * c, f = e * u + n * d + i * p;
if (f === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
const x = 1 / f;
return t[0] = u * x, t[1] = (i * l - h * n) * x, t[2] = (a * n - i * o) * x, t[3] = d * x, t[4] = (h * e - i * c) * x, t[5] = (i * s - a * e) * x, t[6] = p * x, t[7] = (n * c - l * e) * x, t[8] = (o * e - n * s) * x, this;
}
transpose() {
let t;
const e = this.elements;
return t = e[1], e[1] = e[3], e[3] = t, t = e[2], e[2] = e[6], e[6] = t, t = e[5], e[5] = e[7], e[7] = t, this;
}
getNormalMatrix(t) {
return this.setFromMatrix4(t).invert().transpose();
}
transposeIntoArray(t) {
const e = this.elements;
return t[0] = e[0], t[1] = e[3], t[2] = e[6], t[3] = e[1], t[4] = e[4], t[5] = e[7], t[6] = e[2], t[7] = e[5], t[8] = e[8], this;
}
setUvTransform(t, e, n, i, s, o, a) {
const c = Math.cos(s), l = Math.sin(s);
return this.set(
n * c,
n * l,
-n * (c * o + l * a) + o + t,
-i * l,
i * c,
-i * (-l * o + c * a) + a + e,
0,
0,
1
), this;
}
//
scale(t, e) {
return this.premultiply(Qp.makeScale(t, e)), this;
}
rotate(t) {
return this.premultiply(Qp.makeRotation(-t)), this;
}
translate(t, e) {
return this.premultiply(Qp.makeTranslation(t, e)), this;
}
// for 2D Transforms
makeTranslation(t, e) {
return t.isVector2 ? this.set(
1,
0,
t.x,
0,
1,
t.y,
0,
0,
1
) : this.set(
1,
0,
t,
0,
1,
e,
0,
0,
1
), this;
}
makeRotation(t) {
const e = Math.cos(t), n = Math.sin(t);
return this.set(
e,
-n,
0,
n,
e,
0,
0,
0,
1
), this;
}
makeScale(t, e) {
return this.set(
t,
0,
0,
0,
e,
0,
0,
0,
1
), this;
}
//
equals(t) {
const e = this.elements, n = t.elements;
for (let i = 0; i < 9; i++)
if (e[i] !== n[i]) return !1;
return !0;
}
fromArray(t, e = 0) {
for (let n = 0; n < 9; n++)
this.elements[n] = t[n + e];
return this;
}
toArray(t = [], e = 0) {
const n = this.elements;
return t[e] = n[0], t[e + 1] = n[1], t[e + 2] = n[2], t[e + 3] = n[3], t[e + 4] = n[4], t[e + 5] = n[5], t[e + 6] = n[6], t[e + 7] = n[7], t[e + 8] = n[8], t;
}
clone() {
return new this.constructor().fromArray(this.elements);
}
};
const Qp = /* @__PURE__ */ new ie();
function jM(r) {
for (let t = r.length - 1; t >= 0; --t)
if (r[t] >= 65535) return !0;
return !1;
}
const xN = {
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array
};
function Ca(r, t) {
return new xN[r](t);
}
function ll(r) {
return document.createElementNS("http://www.w3.org/1999/xhtml", r);
}
function QM() {
const r = ll("canvas");
return r.style.display = "block", r;
}
const ay = {};
function Iu(r) {
r in ay || (ay[r] = !0, console.warn(r));
}
function yN(r, t, e) {
return new Promise(function(n, i) {
function s() {
switch (r.clientWaitSync(t, r.SYNC_FLUSH_COMMANDS_BIT, 0)) {
case r.WAIT_FAILED:
i();
break;
case r.TIMEOUT_EXPIRED:
setTimeout(s, e);
break;
default:
n();
}
}
setTimeout(s, e);
});
}
function _N(r) {
const t = r.elements;
t[2] = 0.5 * t[2] + 0.5 * t[3], t[6] = 0.5 * t[6] + 0.5 * t[7], t[10] = 0.5 * t[10] + 0.5 * t[11], t[14] = 0.5 * t[14] + 0.5 * t[15];
}
function vN(r) {
const t = r.elements;
t[11] === -1 ? (t[10] = -t[10] - 1, t[14] = -t[14]) : (t[10] = -t[10], t[14] = -t[14] + 1);
}
const cy = /* @__PURE__ */ new ie().set(
0.8224621,
0.177538,
0,
0.0331941,
0.9668058,
0,
0.0170827,
0.0723974,
0.9105199
), ly = /* @__PURE__ */ new ie().set(
1.2249401,
-0.2249404,
0,
-0.0420569,
1.0420571,
0,
-0.0196376,
-0.0786361,
1.0982735
), pc = {
[Ri]: {
transfer: ol,
primaries: al,
luminanceCoefficients: [0.2126, 0.7152, 0.0722],
toReference: (r) => r,
fromReference: (r) => r
},
[Jn]: {
transfer: Be,
primaries: al,
luminanceCoefficients: [0.2126, 0.7152, 0.0722],
toReference: (r) => r.convertSRGBToLinear(),
fromReference: (r) => r.convertLinearToSRGB()
},
[El]: {
transfer: ol,
primaries: cl,
luminanceCoefficients: [0.2289, 0.6917, 0.0793],
toReference: (r) => r.applyMatrix3(ly),
fromReference: (r) => r.applyMatrix3(cy)
},
[Qd]: {
transfer: Be,
primaries: cl,
luminanceCoefficients: [0.2289, 0.6917, 0.0793],
toReference: (r) => r.convertSRGBToLinear().applyMatrix3(ly),
fromReference: (r) => r.applyMatrix3(cy).convertLinearToSRGB()
}
}, MN = /* @__PURE__ */ new Set([Ri, El]), ye = {
enabled: !0,
_workingColorSpace: Ri,
get workingColorSpace() {
return this._workingColorSpace;
},
set workingColorSpace(r) {
if (!MN.has(r))
throw new Error(`Unsupported working color space, "${r}".`);
this._workingColorSpace = r;
},
convert: function(r, t, e) {
if (this.enabled === !1 || t === e || !t || !e)
return r;
const n = pc[t].toReference, i = pc[e].fromReference;
return i(n(r));
},
fromWorkingColorSpace: function(r, t) {
return this.convert(r, this._workingColorSpace, t);
},
toWorkingColorSpace: function(r, t) {
return this.convert(r, t, this._workingColorSpace);
},
getPrimaries: function(r) {
return pc[r].primaries;
},
getTransfer: function(r) {
return r === ns ? ol : pc[r].transfer;
},
getLuminanceCoefficients: function(r, t = this._workingColorSpace) {
return r.fromArray(pc[t].luminanceCoefficients);
}
};
function za(r) {
return r < 0.04045 ? r * 0.0773993808 : Math.pow(r * 0.9478672986 + 0.0521327014, 2.4);
}
function tf(r) {
return r < 31308e-7 ? r * 12.92 : 1.055 * Math.pow(r, 0.41666) - 0.055;
}
let Xo, tS = class {
static getDataURL(t) {
if (/^data:/i.test(t.src) || typeof HTMLCanvasElement > "u")
return t.src;
let e;
if (t instanceof HTMLCanvasElement)
e = t;
else {
Xo === void 0 && (Xo = ll("canvas")), Xo.width = t.width, Xo.height = t.height;
const n = Xo.getContext("2d");
t instanceof ImageData ? n.putImageData(t, 0, 0) : n.drawImage(t, 0, 0, t.width, t.height), e = Xo;
}
return e.width > 2048 || e.height > 2048 ? (console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons", t), e.toDataURL("image/jpeg", 0.6)) : e.toDataURL("image/png");
}
static sRGBToLinear(t) {
if (typeof HTMLImageElement < "u" && t instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && t instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && t instanceof ImageBitmap) {
const e = ll("canvas");
e.width = t.width, e.height = t.height;
const n = e.getContext("2d");
n.drawImage(t, 0, 0, t.width, t.height);
const i = n.getImageData(0, 0, t.width, t.height), s = i.data;
for (let o = 0; o < s.length; o++)
s[o] = za(s[o] / 255) * 255;
return n.putImageData(i, 0, 0), e;
} else if (t.data) {
const e = t.data.slice(0);
for (let n = 0; n < e.length; n++)
e instanceof Uint8Array || e instanceof Uint8ClampedArray ? e[n] = Math.floor(za(e[n] / 255) * 255) : e[n] = za(e[n]);
return {
data: e,
width: t.width,
height: t.height
};
} else
return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."), t;
}
}, SN = 0, po = class {
constructor(t = null) {
this.isSource = !0, Object.defineProperty(this, "id", { value: SN++ }), this.uuid = Ni(), this.data = t, this.dataReady = !0, this.version = 0;
}
set needsUpdate(t) {
t === !0 && this.version++;
}
toJSON(t) {
const e = t === void 0 || typeof t == "string";
if (!e && t.images[this.uuid] !== void 0)
return t.images[this.uuid];
const n = {
uuid: this.uuid,
url: ""
}, i = this.data;
if (i !== null) {
let s;
if (Array.isArray(i)) {
s = [];
for (let o = 0, a = i.length; o < a; o++)
i[o].isDataTexture ? s.push(ef(i[o].image)) : s.push(ef(i[o]));
} else
s = ef(i);
n.url = s;
}
return e || (t.images[this.uuid] = n), n;
}
};
function ef(r) {
return typeof HTMLImageElement < "u" && r instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && r instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && r instanceof ImageBitmap ? tS.getDataURL(r) : r.data ? {
data: Array.from(r.data),
width: r.width,
height: r.height,
type: r.data.constructor.name
} : (console.warn("THREE.Texture: Unable to serialize Texture."), {});
}
let TN = 0, yn = class Pu extends Gi {
constructor(t = Pu.DEFAULT_IMAGE, e = Pu.DEFAULT_MAPPING, n = Oi, i = Oi, s = He, o = mi, a = Gn, c = Ns, l = Pu.DEFAULT_ANISOTROPY, h = ns) {
super(), this.isTexture = !0, Object.defineProperty(this, "id", { value: TN++ }), this.uuid = Ni(), this.name = "", this.source = new po(t), this.mipmaps = [], this.mapping = e, this.channel = 0, this.wrapS = n, this.wrapT = i, this.magFilter = s, this.minFilter = o, this.anisotropy = l, this.format = a, this.internalFormat = null, this.type = c, this.offset = new Q(0, 0), this.repeat = new Q(1, 1), this.center = new Q(0, 0), this.rotation = 0, this.matrixAutoUpdate = !0, this.matrix = new ie(), this.generateMipmaps = !0, this.premultiplyAlpha = !1, this.flipY = !0, this.unpackAlignment = 4, this.colorSpace = h, this.userData = {}, this.version = 0, this.onUpdate = null, this.isRenderTargetTexture = !1, this.pmremVersion = 0;
}
get image() {
return this.source.data;
}
set image(t = null) {
this.source.data = t;
}
updateMatrix() {
this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
}
clone() {
return new this.constructor().copy(this);
}
copy(t) {
return this.name = t.name, this.source = t.source, this.mipmaps = t.mipmaps.slice(0), this.mapping = t.mapping, this.channel = t.channel, this.wrapS = t.wrapS, this.wrapT = t.wrapT, this.magFilter = t.magFilter, this.minFilter = t.minFilter, this.anisotropy = t.anisotropy, this.format = t.format, this.internalFormat = t.internalFormat, this.type = t.type, this.offset.copy(t.offset), this.repeat.copy(t.repeat), this.center.copy(t.center), this.rotation = t.rotation, this.matrixAutoUpdate = t.matrixAutoUpdate, this.matrix.copy(t.matrix), this.generateMipmaps = t.generateMipmaps, this.premultiplyAlpha = t.premultiplyAlpha, this.flipY = t.flipY, this.unpackAlignment = t.unpackAlignment, this.colorSpace = t.colorSpace, this.userData = JSON.parse(JSON.stringify(t.userData)), this.needsUpdate = !0, this;
}
toJSON(t) {
const e = t === void 0 || typeof t == "string";
if (!e && t.textures[this.uuid] !== void 0)
return t.textures[this.uuid];
const n = {
metadata: {
version: 4.6,
type: "Texture",
generator: "Texture.toJSON"
},
uuid: this.uuid,
name: this.name,
image: this.source.toJSON(t).uuid,
mapping: this.mapping,
channel: this.channel,
repeat: [this.repeat.x, this.repeat.y],
offset: [this.offset.x, this.offset.y],
center: [this.center.x, this.center.y],
rotation: this.rotation,
wrap: [this.wrapS, this.wrapT],
format: this.format,
internalFormat: this.internalFormat,
type: this.type,
colorSpace: this.colorSpace,
minFilter: this.minFilter,
magFilter: this.magFilter,
anisotropy: this.anisotropy,
flipY: this.flipY,
generateMipmaps: this.generateMipmaps,
premultiplyAlpha: this.premultiplyAlpha,
unpackAlignment: this.unpackAlignment
};
return Object.keys(this.userData).length > 0 && (n.userData = this.userData), e || (t.textures[this.uuid] = n), n;
}
dispose() {
this.dispatchEvent({ type: "dispose" });
}
transformUv(t) {
if (this.mapping !== qd) return t;
if (t.applyMatrix3(this.matrix), t.x < 0 || t.x > 1)
switch (this.wrapS) {
case Io:
t.x = t.x - Math.floor(t.x);
break;
case Oi:
t.x = t.x < 0 ? 0 : 1;
break;
case nl:
Math.abs(Math.floor(t.x) % 2) === 1 ? t.x = Math.ceil(t.x) - t.x : t.x = t.x - Math.floor(t.x);
break;
}
if (t.y < 0 || t.y > 1)
switch (this.wrapT) {
case Io:
t.y = t.y - Math.floor(t.y);
break;
case Oi:
t.y = t.y < 0 ? 0 : 1;
break;
case nl:
Math.abs(Math.floor(t.y) % 2) === 1 ? t.y = Math.ceil(t.y) - t.y : t.y = t.y - Math.floor(t.y);
break;
}
return this.flipY && (t.y = 1 - t.y), t;
}
set needsUpdate(t) {
t === !0 && (this.version++, this.source.needsUpdate = !0);
}
set needsPMREMUpdate(t) {
t === !0 && this.pmremVersion++;
}
};
yn.DEFAULT_IMAGE = null;
yn.DEFAULT_MAPPING = qd;
yn.DEFAULT_ANISOTROPY = 4;
let le = class eS {
constructor(t = 0, e = 0, n = 0, i = 1) {
eS.prototype.isVector4 = !0, this.x = t, this.y = e, this.z = n, this.w = i;
}
get width() {
return this.z;
}
set width(t) {
this.z = t;
}
get height() {
return this.w;
}
set height(t) {
this.w = t;
}
set(t, e, n, i) {
return this.x = t, this.y = e, this.z = n, this.w = i, this;
}
setScalar(t) {
return this.x = t, this.y = t, this.z = t, this.w = t, this;
}
setX(t) {
return this.x = t, this;
}
setY(t) {
return this.y = t, this;
}
setZ(t) {
return this.z = t, this;
}
setW(t) {
return this.w = t, this;
}
setComponent(t, e) {
switch (t) {
case 0:
this.x = e;
break;
case 1:
this.y = e;
break;
case 2:
this.z = e;
break;
case 3:
this.w = e;
break;
default:
throw new Error("index is out of range: " + t);
}
return this;
}
getComponent(t) {
switch (t) {
case 0:
return this.x;
case 1:
return this.y;
case 2:
return this.z;
case 3:
return this.w;
default:
throw new Error("index is out of range: " + t);
}
}
clone() {
return new this.constructor(this.x, this.y, this.z, this.w);
}
copy(t) {
return this.x = t.x, this.y = t.y, this.z = t.z, this.w = t.w !== void 0 ? t.w : 1, this;
}
add(t) {
return this.x += t.x, this.y += t.y, this.z += t.z, this.w += t.w, this;
}
addScalar(t) {
return this.x += t, this.y += t, this.z += t, this.w += t, this;
}
addVectors(t, e) {
return this.x = t.x + e.x, this.y = t.y + e.y, this.z = t.z + e.z, this.w = t.w + e.w, this;
}
addScaledVector(t, e) {
return this.x += t.x * e, this.y += t.y * e, this.z += t.z * e, this.w += t.w * e, this;
}
sub(t) {
return this.x -= t.x, this.y -= t.y, this.z -= t.z, this.w -= t.w, this;
}
subScalar(t) {
return this.x -= t, this.y -= t, this.z -= t, this.w -= t, this;
}
subVectors(t, e) {
return this.x = t.x - e.x, this.y = t.y - e.y, this.z = t.z - e.z, this.w = t.w - e.w, this;
}
multiply(t) {
return this.x *= t.x, this.y *= t.y, this.z *= t.z, this.w *= t.w, this;
}
multiplyScalar(t) {
return this.x *= t, this.y *= t, this.z *= t, this.w *= t, this;
}
applyMatrix4(t) {
const e = this.x, n = this.y, i = this.z, s = this.w, o = t.elements;
return this.x = o[0] * e + o[4] * n + o[8] * i + o[12] * s, this.y = o[1] * e + o[5] * n + o[9] * i + o[13] * s, this.z = o[2] * e + o[6] * n + o[10] * i + o[14] * s, this.w = o[3] * e + o[7] * n + o[11] * i + o[15] * s, this;
}
divideScalar(t) {
return this.multiplyScalar(1 / t);
}
setAxisAngleFromQuaternion(t) {
this.w = 2 * Math.acos(t.w);
const e = Math.sqrt(1 - t.w * t.w);
return e < 1e-4 ? (this.x = 1, this.y = 0, this.z = 0) : (this.x = t.x / e, this.y = t.y / e, this.z = t.z / e), this;
}
setAxisAngleFromRotationMatrix(t) {
let e, n, i, s;
const c = t.elements, l = c[0], h = c[4], u = c[8], d = c[1], p = c[5], f = c[9], x = c[2], m = c[6], g = c[10];
if (Math.abs(h - d) < 0.01 && Math.abs(u - x) < 0.01 && Math.abs(f - m) < 0.01) {
if (Math.abs(h + d) < 0.1 && Math.abs(u + x) < 0.1 && Math.abs(f + m) < 0.1 && Math.abs(l + p + g - 3) < 0.1)
return this.set(1, 0, 0, 0), this;
e = Math.PI;
const y = (l + 1) / 2, v = (p + 1) / 2, C = (g + 1) / 2, S = (h + d) / 4, T = (u + x) / 4, A = (f + m) / 4;
return y > v && y > C ? y < 0.01 ? (n = 0, i = 0.707106781, s = 0.707106781) : (n = Math.sqrt(y), i = S / n, s = T / n) : v > C ? v < 0.01 ? (n = 0.707106781, i = 0, s = 0.707106781) : (i = Math.sqrt(v), n = S / i, s = A / i) : C < 0.01 ? (n = 0.707106781, i = 0.707106781, s = 0) : (s = Math.sqrt(C), n = T / s, i = A / s), this.set(n, i, s, e), this;
}
let _ = Math.sqrt((m - f) * (m - f) + (u - x) * (u - x) + (d - h) * (d - h));
return Math.abs(_) < 1e-3 && (_ = 1), this.x = (m - f) / _, this.y = (u - x) / _, this.z = (d - h) / _, this.w = Math.acos((l + p + g - 1) / 2), this;
}
setFromMatrixPosition(t) {
const e = t.elements;
return this.x = e[12], this.y = e[13], this.z = e[14], this.w = e[15], this;
}
min(t) {
return this.x = Math.min(this.x, t.x), this.y = Math.min(this.y, t.y), this.z = Math.min(this.z, t.z), this.w = Math.min(this.w, t.w), this;
}
max(t) {
return this.x = Math.max(this.x, t.x), this.y = Math.max(this.y, t.y), this.z = Math.max(this.z, t.z), this.w = Math.max(this.w, t.w), this;
}
clamp(t, e) {
return this.x = Math.max(t.x, Math.min(e.x, this.x)), this.y = Math.max(t.y, Math.min(e.y, this.y)), this.z = Math.max(t.z, Math.min(e.z, this.z)), this.w = Math.max(t.w, Math.min(e.w, this.w)), this;
}
clampScalar(t, e) {
return this.x = Math.max(t, Math.min(e, this.x)), this.y = Math.max(t, Math.min(e, this.y)), this.z = Math.max(t, Math.min(e, this.z)), this.w = Math.max(t, Math.min(e, this.w)), this;
}
clampLength(t, e) {
const n = this.length();
return this.divideScalar(n || 1).multiplyScalar(Math.max(t, Math.min(e, n)));
}
floor() {
return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this.z = Math.floor(this.z), this.w = Math.floor(this.w), this;
}
ceil() {
return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this.z = Math.ceil(this.z), this.w = Math.ceil(this.w), this;
}
round() {
return this.x = Math.round(this.x), this.y = Math.round(this.y), this.z = Math.round(this.z), this.w = Math.round(this.w), this;
}
roundToZero() {
return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this.z = Math.trunc(this.z), this.w = Math.trunc(this.w), this;
}
negate() {
return this.x = -this.x, this.y = -this.y, this.z = -this.z, this.w = -this.w, this;
}
dot(t) {
return this.x * t.x + this.y * t.y + this.z * t.z + this.w * t.w;
}
lengthSq() {
return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
}
length() {
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
}
manhattanLength() {
return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
}
normalize() {
return this.divideScalar(this.length() || 1);
}
setLength(t) {
return this.normalize().multiplyScalar(t);
}
lerp(t, e) {
return this.x += (t.x - this.x) * e, this.y += (t.y - this.y) * e, this.z += (t.z - this.z) * e, this.w += (t.w - this.w) * e, this;
}
lerpVectors(t, e, n) {
return this.x = t.x + (e.x - t.x) * n, this.y = t.y + (e.y - t.y) * n, this.z = t.z + (e.z - t.z) * n, this.w = t.w + (e.w - t.w) * n, this;
}
equals(t) {
return t.x === this.x && t.y === this.y && t.z === this.z && t.w === this.w;
}
fromArray(t, e = 0) {
return this.x = t[e], this.y = t[e + 1], this.z = t[e + 2], this.w = t[e + 3], this;
}
toArray(t = [], e = 0) {
return t[e] = this.x, t[e + 1] = this.y, t[e + 2] = this.z, t[e + 3] = this.w, t;
}
fromBufferAttribute(t, e) {
return this.x = t.getX(e), this.y = t.getY(e), this.z = t.getZ(e), this.w = t.getW(e), this;
}
random() {
return this.x = Math.random(), this.y = Math.random(), this.z = Math.random(), this.w = Math.random(), this;
}
*[Symbol.iterator]() {
yield this.x, yield this.y, yield this.z, yield this.w;
}
};
class mn extends Gi {
constructor(t = 1, e = 1, n = {}) {
super(), this.isRenderTarget = !0, this.width = t, this.height = e, this.depth = 1, this.scissor = new le(0, 0, t, e), this.scissorTest = !1, this.viewport = new le(0, 0, t, e);
const i = { width: t, height: e, depth: 1 };
n = Object.assign({
generateMipmaps: !1,
internalFormat: null,
minFilter: He,
depthBuffer: !0,
stencilBuffer: !1,
resolveDepthBuffer: !0,
resolveStencilBuffer: !0,
depthTexture: null,
samples: 0,
count: 1
}, n);
const s = new yn(i, n.mapping, n.wrapS, n.wrapT, n.magFilter, n.minFilter, n.format, n.type, n.anisotropy, n.colorSpace);
s.flipY = !1, s.generateMipmaps = n.generateMipmaps, s.internalFormat = n.internalFormat, this.textures = [];
const o = n.count;
for (let a = 0; a < o; a++)
this.textures[a] = s.clone(), this.textures[a].isRenderTargetTexture = !0;
this.depthBuffer = n.depthBuffer, this.stencilBuffer = n.stencilBuffer, this.resolveDepthBuffer = n.resolveDepthBuffer, this.resolveStencilBuffer = n.resolveStencilBuffer, this.depthTexture = n.depthTexture, this.samples = n.samples;
}
get texture() {
return this.textures[0];
}
set texture(t) {
this.textures[0] = t;
}
setSize(t, e, n = 1) {
if (this.width !== t || this.height !== e || this.depth !== n) {
this.width = t, this.height = e, this.depth = n;
for (let i = 0, s = this.textures.length; i < s; i++)
this.textures[i].image.width = t, this.textures[i].image.height = e, this.textures[i].image.depth = n;
this.dispose();
}
this.viewport.set(0, 0, t, e), this.scissor.set(0, 0, t, e);
}
clone() {
return new this.constructor().copy(this);
}
copy(t) {
this.width = t.width, this.height = t.height, this.depth = t.depth, this.scissor.copy(t.scissor), this.scissorTest = t.scissorTest, this.viewport.copy(t.viewport), this.textures.length = 0;
for (let n = 0, i = t.textures.length; n < i; n++)
this.textures[n] = t.textures[n].clone(), this.textures[n].isRenderTargetTexture = !0;
const e = Object.assign({}, t.texture.image);
return this.texture.source = new po(e), this.depthBuffer = t.depthBuffer, this.stencilBuffer = t.stencilBuffer, this.resolveDepthBuffer = t.resolveDepthBuffer, this.resolveStencilBuffer = t.resolveStencilBuffer, t.depthTexture !== null && (this.depthTexture = t.depthTexture.clone()), this.samples = t.samples, this;
}
dispose() {
this.dispatchEvent({ type: "dispose" });
}
}
class hs extends mn {
constructor(t = 1, e = 1, n = {}) {
super(t, e, n), this.isWebGLRenderTarget = !0;
}
}
class Nl extends yn {
constructor(t = null, e = 1, n = 1, i = 1) {
super(null), this.isDataArrayTexture = !0, this.image = { data: t, width: e, height: n, depth: i }, this.magFilter = rn, this.minFilter = rn, this.wrapR = Oi, this.generateMipmaps = !1, this.flipY = !1, this.unpackAlignment = 1, this.layerUpdates = /* @__PURE__ */ new Set();
}
addLayerUpdate(t) {
this.layerUpdates.add(t);
}
clearLayerUpdates() {
this.layerUpdates.clear();
}
}
class bN extends hs {
constructor(t = 1, e = 1, n = 1, i = {}) {
super(t, e, i), this.isWebGLArrayRenderTarget = !0, this.depth = n, this.texture = new Nl(null, t, e, n), this.texture.isRenderTargetTexture = !0;
}
}
class Gg extends yn {
constructor(t = null, e = 1, n = 1, i = 1) {
super(null), this.isData3DTexture = !0, this.image = { data: t, width: e, height: n, depth: i }, this.magFilter = rn, this.minFilter = rn, this.wrapR = Oi, this.generateMipmaps = !1, this.flipY = !1, this.unpackAlignment = 1;
}
}
class wN extends hs {
constructor(t = 1, e = 1, n = 1, i = {}) {
super(t, e, i), this.isWebGL3DRenderTarget = !0, this.depth = n, this.texture = new Gg(null, t, e, n), this.texture.isRenderTargetTexture = !0;
}
}
let ei = class {
constructor(t = 0, e = 0, n = 0, i = 1) {
this.isQuaternion = !0, this._x = t, this._y = e, this._z = n, this._w = i;
}
static slerpFlat(t, e, n, i, s, o, a) {
let c = n[i + 0], l = n[i + 1], h = n[i + 2], u = n[i + 3];
const d = s[o + 0], p = s[o + 1], f = s[o + 2], x = s[o + 3];
if (a === 0) {
t[e + 0] = c, t[e + 1] = l, t[e + 2] = h, t[e + 3] = u;
return;
}
if (a === 1) {
t[e + 0] = d, t[e + 1] = p, t[e + 2] = f, t[e + 3] = x;
return;
}
if (u !== x || c !== d || l !== p || h !== f) {
let m = 1 - a;
const g = c * d + l * p + h * f + u * x, _ = g >= 0 ? 1 : -1, y = 1 - g * g;
if (y > Number.EPSILON) {
const C = Math.sqrt(y), S = Math.atan2(C, g * _);
m = Math.sin(m * S) / C, a = Math.sin(a * S) / C;
}
const v = a * _;
if (c = c * m + d * v, l = l * m + p * v, h = h * m + f * v, u = u * m + x * v, m === 1 - a) {
const C = 1 / Math.sqrt(c * c + l * l + h * h + u * u);
c *= C, l *= C, h *= C, u *= C;
}
}
t[e] = c, t[e + 1] = l, t[e + 2] = h, t[e + 3] = u;
}
static multiplyQuaternionsFlat(t, e, n, i, s, o) {
const a = n[i], c = n[i + 1], l = n[i + 2], h = n[i + 3], u = s[o], d = s[o + 1], p = s[o + 2], f = s[o + 3];
return t[e] = a * f + h * u + c * p - l * d, t[e + 1] = c * f + h * d + l * u - a * p, t[e + 2] = l * f + h * p + a * d - c * u, t[e + 3] = h * f - a * u - c * d - l * p, t;
}
get x() {
return this._x;
}
set x(t) {
this._x = t, this._onChangeCallback();
}
get y() {
return this._y;
}
set y(t) {
this._y = t, this._onChangeCallback();
}
get z() {
return this._z;
}
set z(t) {
this._z = t, this._onChangeCallback();
}
get w() {
return this._w;
}
set w(t) {
this._w = t, this._onChangeCallback();
}
set(t, e, n, i) {
return this._x = t, this._y = e, this._z = n, this._w = i, this._onChangeCallback(), this;
}
clone() {
return new this.constructor(this._x, this._y, this._z, this._w);
}
copy(t) {
return this._x = t.x, this._y = t.y, this._z = t.z, this._w = t.w, this._onChangeCallback(), this;
}
setFromEuler(t, e = !0) {
const n = t._x, i = t._y, s = t._z, o = t._order, a = Math.cos, c = Math.sin, l = a(n / 2), h = a(i / 2), u = a(s / 2), d = c(n / 2), p = c(i / 2), f = c(s / 2);
switch (o) {
case "XYZ":
this._x = d * h * u + l * p * f, this._y = l * p * u - d * h * f, this._z = l * h * f + d * p * u, this._w = l * h * u - d * p * f;
break;
case "YXZ":
this._x = d * h * u + l * p * f, this._y = l * p * u - d * h * f, this._z = l * h * f - d * p * u, this._w = l * h * u + d * p * f;
break;
case "ZXY":
this._x = d * h * u - l * p * f, this._y = l * p * u + d * h * f, this._z = l * h * f + d * p * u, this._w = l * h * u - d * p * f;
break;
case "ZYX":
this._x = d * h * u - l * p * f, this._y = l * p * u + d * h * f, this._z = l * h * f - d * p * u, this._w = l * h * u + d * p * f;
break;
case "YZX":
this._x = d * h * u + l * p * f, this._y = l * p * u + d * h * f, this._z = l * h * f - d * p * u, this._w = l * h * u - d * p * f;
break;
case "XZY":
this._x = d * h * u - l * p * f, this._y = l * p * u - d * h * f, this._z = l * h * f + d * p * u, this._w = l * h * u + d * p * f;
break;
default:
console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + o);
}
return e === !0 && this._onChangeCallback(), this;
}
setFromAxisAngle(t, e) {
const n = e / 2, i = Math.sin(n);
return this._x = t.x * i, this._y = t.y * i, this._z = t.z * i, this._w = Math.cos(n), this._onChangeCallback(), this;
}
setFromRotationMatrix(t) {
const e = t.elements, n = e[0], i = e[4], s = e[8], o = e[1], a = e[5], c = e[9], l = e[2], h = e[6], u = e[10], d = n + a + u;
if (d > 0) {
const p = 0.5 / Math.sqrt(d + 1);
this._w = 0.25 / p, this._x = (h - c) * p, this._y = (s - l) * p, this._z = (o - i) * p;
} else if (n > a && n > u) {
const p = 2 * Math.sqrt(1 + n - a - u);
this._w = (h - c) / p, this._x = 0.25 * p, this._y = (i + o) / p, this._z = (s + l) / p;
} else if (a > u) {
const p = 2 * Math.sqrt(1 + a - n - u);
this._w = (s - l) / p, this._x = (i + o) / p, this._y = 0.25 * p, this._z = (c + h) / p;
} else {
const p = 2 * Math.sqrt(1 + u - n - a);
this._w = (o - i) / p, this._x = (s + l) / p, this._y = (c + h) / p, this._z = 0.25 * p;
}
return this._onChangeCallback(), this;
}
setFromUnitVectors(t, e) {
let n = t.dot(e) + 1;
return n < Number.EPSILON ? (n = 0, Math.abs(t.x) > Math.abs(t.z) ? (this._x = -t.y, this._y = t.x, this._z = 0, this._w = n) : (this._x = 0, this._y = -t.z, this._z = t.y, this._w = n)) : (this._x = t.y * e.z - t.z * e.y, this._y = t.z * e.x - t.x * e.z, this._z = t.x * e.y - t.y * e.x, this._w = n), this.normalize();
}
angleTo(t) {
return 2 * Math.acos(Math.abs(Qe(this.dot(t), -1, 1)));
}
rotateTowards(t, e) {
const n = this.angleTo(t);
if (n === 0) return this;
const i = Math.min(1, e / n);
return this.slerp(t, i), this;
}
identity() {
return this.set(0, 0, 0, 1);
}
invert() {
return this.conjugate();
}
conjugate() {
return this._x *= -1, this._y *= -1, this._z *= -1, this._onChangeCallback(), this;
}
dot(t) {
return this._x * t._x + this._y * t._y + this._z * t._z + this._w * t._w;
}
lengthSq() {
return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
}
length() {
return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
}
normalize() {
let t = this.length();
return t === 0 ? (this._x = 0, this._y = 0, this._z = 0, this._w = 1) : (t = 1 / t, this._x = this._x * t, this._y = this._y * t, this._z = this._z * t, this._w = this._w * t), this._onChangeCallback(), this;
}
multiply(t) {
return this.multiplyQuaternions(this, t);
}
premultiply(t) {
return this.multiplyQuaternions(t, this);
}
multiplyQuaternions(t, e) {
const n = t._x, i = t._y, s = t._z, o = t._w, a = e._x, c = e._y, l = e._z, h = e._w;
return this._x = n * h + o * a + i * l - s * c, this._y = i * h + o * c + s * a - n * l, this._z = s * h + o * l + n * c - i * a, this._w = o * h - n * a - i * c - s * l, this._onChangeCallback(), this;
}
slerp(t, e) {
if (e === 0) return this;
if (e === 1) return this.copy(t);
const n = this._x, i = this._y, s = this._z, o = this._w;
let a = o * t._w + n * t._x + i * t._y + s * t._z;
if (a < 0 ? (this._w = -t._w, this._x = -t._x, this._y = -t._y, this._z = -t._z, a = -a) : this.copy(t), a >= 1)
return this._w = o, this._x = n, this._y = i, this._z = s, this;
const c = 1 - a * a;
if (c <= Number.EPSILON) {
const p = 1 - e;
return this._w = p * o + e * this._w, this._x = p * n + e * this._x, this._y = p * i + e * this._y, this._z = p * s + e * this._z, this.normalize(), this;
}
const l = Math.sqrt(c), h = Math.atan2(l, a), u = Math.sin((1 - e) * h) / l, d = Math.sin(e * h) / l;
return this._w = o * u + this._w * d, this._x = n * u + this._x * d, this._y = i * u + this._y * d, this._z = s * u + this._z * d, this._onChangeCallback(), this;
}
slerpQuaternions(t, e, n) {
return this.copy(t).slerp(e, n);
}
random() {
const t = 2 * Math.PI * Math.random(), e = 2 * Math.PI * Math.random(), n = Math.random(), i = Math.sqrt(1 - n), s = Math.sqrt(n);
return this.set(
i * Math.sin(t),
i * Math.cos(t),
s * Math.sin(e),
s * Math.cos(e)
);
}
equals(t) {
return t._x === this._x && t._y === this._y && t._z === this._z && t._w === this._w;
}
fromArray(t, e = 0) {
return this._x = t[e], this._y = t[e + 1], this._z = t[e + 2], this._w = t[e + 3], this._onChangeCallback(), this;
}
toArray(t = [], e = 0) {
return t[e] = this._x, t[e + 1] = this._y, t[e + 2] = this._z, t[e + 3] = this._w, t;
}
fromBufferAttribute(t, e) {
return this._x = t.getX(e), this._y = t.getY(e), this._z = t.getZ(e), this._w = t.getW(e), this._onChangeCallback(), this;
}
toJSON() {
return this.toArray();
}
_onChange(t) {
return this._onChangeCallback = t, this;
}
_onChangeCallback() {
}
*[Symbol.iterator]() {
yield this._x, yield this._y, yield this._z, yield this._w;
}
}, R = class nS {
constructor(t = 0, e = 0, n = 0) {
nS.prototype.isVector3 = !0, this.x = t, this.y = e, this.z = n;
}
set(t, e, n) {
return n === void 0 && (n = this.z), this.x = t, this.y = e, this.z = n, this;
}
setScalar(t) {
return this.x = t, this.y = t, this.z = t, this;
}
setX(t) {
return this.x = t, this;
}
setY(t) {
return this.y = t, this;
}
setZ(t) {
return this.z = t, this;
}
setComponent(t, e) {
switch (t) {
case 0:
this.x = e;
break;
case 1:
this.y = e;
break;
case 2:
this.z = e;
break;
default:
throw new Error("index is out of range: " + t);
}
return this;
}
getComponent(t) {
switch (t) {
case 0:
return this.x;