@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,306 lines • 629 kB
JavaScript
import { Object3D as gc, PlaneGeometry as vc, Layers as Br, MeshBasicMaterial as sa, DoubleSide as Xs, AdditiveBlending as Sc, InstancedBufferAttribute as mn, DynamicDrawUsage as ee, InstancedBufferGeometry as Kl, Uniform$1 as Re, ShaderMaterial as Ys, BufferGeometry as yi, BufferAttribute as he, Mesh as Zr, MeshStandardMaterial as Ql, MeshPhysicalMaterial as tu, ShaderChunk as eu, Triangle as Mn, Vector3 as H, Box3 as Le, Matrix4 as Oe, Line3 as tn, Plane as xc, Vector2 as hn, BackSide as nu, REVISION as _c, Ray as iu, FrontSide as oa, LineSegments as bc, LineLoop as Tc, Line as Cc, Points as Mc, Sphere as ru, BatchedMesh as su, Matrix3 as ou, Vector4 as To, SkinnedMesh as au, InterpolateDiscrete as cu, InterpolateLinear as wc, AnimationClip as lu, QuaternionKeyframeTrack as uu, ColorKeyframeTrack as hu, VectorKeyframeTrack as fu, BooleanKeyframeTrack as du, NumberKeyframeTrack as pu, PropertyBinding as aa } from "./three.js";
function Kr(r) {
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
}
var vs = { exports: {} }, Ss = { exports: {} }, ca;
function mu() {
return ca || (ca = 1, (function() {
var r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", t = {
// Bit-wise rotation left
rotl: function(e, n) {
return e << n | e >>> 32 - n;
},
// Bit-wise rotation right
rotr: function(e, n) {
return e << 32 - n | e >>> n;
},
// Swap big-endian to little-endian and vice versa
endian: function(e) {
if (e.constructor == Number)
return t.rotl(e, 8) & 16711935 | t.rotl(e, 24) & 4278255360;
for (var n = 0; n < e.length; n++)
e[n] = t.endian(e[n]);
return e;
},
// Generate an array of any length of random bytes
randomBytes: function(e) {
for (var n = []; e > 0; e--)
n.push(Math.floor(Math.random() * 256));
return n;
},
// Convert a byte array to big-endian 32-bit words
bytesToWords: function(e) {
for (var n = [], i = 0, s = 0; i < e.length; i++, s += 8)
n[s >>> 5] |= e[i] << 24 - s % 32;
return n;
},
// Convert big-endian 32-bit words to a byte array
wordsToBytes: function(e) {
for (var n = [], i = 0; i < e.length * 32; i += 8)
n.push(e[i >>> 5] >>> 24 - i % 32 & 255);
return n;
},
// Convert a byte array to a hex string
bytesToHex: function(e) {
for (var n = [], i = 0; i < e.length; i++)
n.push((e[i] >>> 4).toString(16)), n.push((e[i] & 15).toString(16));
return n.join("");
},
// Convert a hex string to a byte array
hexToBytes: function(e) {
for (var n = [], i = 0; i < e.length; i += 2)
n.push(parseInt(e.substr(i, 2), 16));
return n;
},
// Convert a byte array to a base-64 string
bytesToBase64: function(e) {
for (var n = [], i = 0; i < e.length; i += 3)
for (var s = e[i] << 16 | e[i + 1] << 8 | e[i + 2], a = 0; a < 4; a++)
i * 8 + a * 6 <= e.length * 8 ? n.push(r.charAt(s >>> 6 * (3 - a) & 63)) : n.push("=");
return n.join("");
},
// Convert a base-64 string to a byte array
base64ToBytes: function(e) {
e = e.replace(/[^A-Z0-9+\/]/ig, "");
for (var n = [], i = 0, s = 0; i < e.length; s = ++i % 4)
s != 0 && n.push((r.indexOf(e.charAt(i - 1)) & Math.pow(2, -2 * s + 8) - 1) << s * 2 | r.indexOf(e.charAt(i)) >>> 6 - s * 2);
return n;
}
};
Ss.exports = t;
})()), Ss.exports;
}
var xs, la;
function ua() {
if (la) return xs;
la = 1;
var r = {
// UTF-8 encoding
utf8: {
// Convert a string to a byte array
stringToBytes: function(t) {
return r.bin.stringToBytes(unescape(encodeURIComponent(t)));
},
// Convert a byte array to a string
bytesToString: function(t) {
return decodeURIComponent(escape(r.bin.bytesToString(t)));
}
},
// Binary encoding
bin: {
// Convert a string to a byte array
stringToBytes: function(t) {
for (var e = [], n = 0; n < t.length; n++)
e.push(t.charCodeAt(n) & 255);
return e;
},
// Convert a byte array to a string
bytesToString: function(t) {
for (var e = [], n = 0; n < t.length; n++)
e.push(String.fromCharCode(t[n]));
return e.join("");
}
}
};
return xs = r, xs;
}
var _s, ha;
function yu() {
if (ha) return _s;
ha = 1, _s = function(e) {
return e != null && (r(e) || t(e) || !!e._isBuffer);
};
function r(e) {
return !!e.constructor && typeof e.constructor.isBuffer == "function" && e.constructor.isBuffer(e);
}
function t(e) {
return typeof e.readFloatLE == "function" && typeof e.slice == "function" && r(e.slice(0, 0));
}
return _s;
}
var fa;
function gu() {
return fa || (fa = 1, (function() {
var r = mu(), t = ua().utf8, e = yu(), n = ua().bin, i = function(s, a) {
s.constructor == String ? a && a.encoding === "binary" ? s = n.stringToBytes(s) : s = t.stringToBytes(s) : e(s) ? s = Array.prototype.slice.call(s, 0) : !Array.isArray(s) && s.constructor !== Uint8Array && (s = s.toString());
for (var o = r.bytesToWords(s), c = s.length * 8, l = 1732584193, u = -271733879, f = -1732584194, p = 271733878, m = 0; m < o.length; m++)
o[m] = (o[m] << 8 | o[m] >>> 24) & 16711935 | (o[m] << 24 | o[m] >>> 8) & 4278255360;
o[c >>> 5] |= 128 << c % 32, o[(c + 64 >>> 9 << 4) + 14] = c;
for (var x = i._ff, T = i._gg, g = i._hh, v = i._ii, m = 0; m < o.length; m += 16) {
var _ = l, b = u, C = f, M = p;
l = x(l, u, f, p, o[m + 0], 7, -680876936), p = x(p, l, u, f, o[m + 1], 12, -389564586), f = x(f, p, l, u, o[m + 2], 17, 606105819), u = x(u, f, p, l, o[m + 3], 22, -1044525330), l = x(l, u, f, p, o[m + 4], 7, -176418897), p = x(p, l, u, f, o[m + 5], 12, 1200080426), f = x(f, p, l, u, o[m + 6], 17, -1473231341), u = x(u, f, p, l, o[m + 7], 22, -45705983), l = x(l, u, f, p, o[m + 8], 7, 1770035416), p = x(p, l, u, f, o[m + 9], 12, -1958414417), f = x(f, p, l, u, o[m + 10], 17, -42063), u = x(u, f, p, l, o[m + 11], 22, -1990404162), l = x(l, u, f, p, o[m + 12], 7, 1804603682), p = x(p, l, u, f, o[m + 13], 12, -40341101), f = x(f, p, l, u, o[m + 14], 17, -1502002290), u = x(u, f, p, l, o[m + 15], 22, 1236535329), l = T(l, u, f, p, o[m + 1], 5, -165796510), p = T(p, l, u, f, o[m + 6], 9, -1069501632), f = T(f, p, l, u, o[m + 11], 14, 643717713), u = T(u, f, p, l, o[m + 0], 20, -373897302), l = T(l, u, f, p, o[m + 5], 5, -701558691), p = T(p, l, u, f, o[m + 10], 9, 38016083), f = T(f, p, l, u, o[m + 15], 14, -660478335), u = T(u, f, p, l, o[m + 4], 20, -405537848), l = T(l, u, f, p, o[m + 9], 5, 568446438), p = T(p, l, u, f, o[m + 14], 9, -1019803690), f = T(f, p, l, u, o[m + 3], 14, -187363961), u = T(u, f, p, l, o[m + 8], 20, 1163531501), l = T(l, u, f, p, o[m + 13], 5, -1444681467), p = T(p, l, u, f, o[m + 2], 9, -51403784), f = T(f, p, l, u, o[m + 7], 14, 1735328473), u = T(u, f, p, l, o[m + 12], 20, -1926607734), l = g(l, u, f, p, o[m + 5], 4, -378558), p = g(p, l, u, f, o[m + 8], 11, -2022574463), f = g(f, p, l, u, o[m + 11], 16, 1839030562), u = g(u, f, p, l, o[m + 14], 23, -35309556), l = g(l, u, f, p, o[m + 1], 4, -1530992060), p = g(p, l, u, f, o[m + 4], 11, 1272893353), f = g(f, p, l, u, o[m + 7], 16, -155497632), u = g(u, f, p, l, o[m + 10], 23, -1094730640), l = g(l, u, f, p, o[m + 13], 4, 681279174), p = g(p, l, u, f, o[m + 0], 11, -358537222), f = g(f, p, l, u, o[m + 3], 16, -722521979), u = g(u, f, p, l, o[m + 6], 23, 76029189), l = g(l, u, f, p, o[m + 9], 4, -640364487), p = g(p, l, u, f, o[m + 12], 11, -421815835), f = g(f, p, l, u, o[m + 15], 16, 530742520), u = g(u, f, p, l, o[m + 2], 23, -995338651), l = v(l, u, f, p, o[m + 0], 6, -198630844), p = v(p, l, u, f, o[m + 7], 10, 1126891415), f = v(f, p, l, u, o[m + 14], 15, -1416354905), u = v(u, f, p, l, o[m + 5], 21, -57434055), l = v(l, u, f, p, o[m + 12], 6, 1700485571), p = v(p, l, u, f, o[m + 3], 10, -1894986606), f = v(f, p, l, u, o[m + 10], 15, -1051523), u = v(u, f, p, l, o[m + 1], 21, -2054922799), l = v(l, u, f, p, o[m + 8], 6, 1873313359), p = v(p, l, u, f, o[m + 15], 10, -30611744), f = v(f, p, l, u, o[m + 6], 15, -1560198380), u = v(u, f, p, l, o[m + 13], 21, 1309151649), l = v(l, u, f, p, o[m + 4], 6, -145523070), p = v(p, l, u, f, o[m + 11], 10, -1120210379), f = v(f, p, l, u, o[m + 2], 15, 718787259), u = v(u, f, p, l, o[m + 9], 21, -343485551), l = l + _ >>> 0, u = u + b >>> 0, f = f + C >>> 0, p = p + M >>> 0;
}
return r.endian([l, u, f, p]);
};
i._ff = function(s, a, o, c, l, u, f) {
var p = s + (a & o | ~a & c) + (l >>> 0) + f;
return (p << u | p >>> 32 - u) + a;
}, i._gg = function(s, a, o, c, l, u, f) {
var p = s + (a & c | o & ~c) + (l >>> 0) + f;
return (p << u | p >>> 32 - u) + a;
}, i._hh = function(s, a, o, c, l, u, f) {
var p = s + (a ^ o ^ c) + (l >>> 0) + f;
return (p << u | p >>> 32 - u) + a;
}, i._ii = function(s, a, o, c, l, u, f) {
var p = s + (o ^ (a | ~c)) + (l >>> 0) + f;
return (p << u | p >>> 32 - u) + a;
}, i._blocksize = 16, i._digestsize = 16, vs.exports = function(s, a) {
if (s == null)
throw new Error("Illegal argument " + s);
var o = r.wordsToBytes(i(s, a));
return a && a.asBytes ? o : a && a.asString ? n.bytesToString(o) : r.bytesToHex(o);
};
})()), vs.exports;
}
var vu = gu();
const Su = /* @__PURE__ */ Kr(vu), Dd = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
default: Su
}, Symbol.toStringTag, { value: "Module" })), xu = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
function _u(r) {
return typeof r == "string" && xu.test(r);
}
const Lt = [];
for (let r = 0; r < 256; ++r)
Lt.push((r + 256).toString(16).slice(1));
function bu(r, t = 0) {
return Lt[r[t + 0]] + Lt[r[t + 1]] + Lt[r[t + 2]] + Lt[r[t + 3]] + "-" + Lt[r[t + 4]] + Lt[r[t + 5]] + "-" + Lt[r[t + 6]] + Lt[r[t + 7]] + "-" + Lt[r[t + 8]] + Lt[r[t + 9]] + "-" + Lt[r[t + 10]] + Lt[r[t + 11]] + Lt[r[t + 12]] + Lt[r[t + 13]] + Lt[r[t + 14]] + Lt[r[t + 15]];
}
function Tu(r) {
if (!_u(r))
throw TypeError("Invalid UUID");
let t;
const e = new Uint8Array(16);
return e[0] = (t = parseInt(r.slice(0, 8), 16)) >>> 24, e[1] = t >>> 16 & 255, e[2] = t >>> 8 & 255, e[3] = t & 255, e[4] = (t = parseInt(r.slice(9, 13), 16)) >>> 8, e[5] = t & 255, e[6] = (t = parseInt(r.slice(14, 18), 16)) >>> 8, e[7] = t & 255, e[8] = (t = parseInt(r.slice(19, 23), 16)) >>> 8, e[9] = t & 255, e[10] = (t = parseInt(r.slice(24, 36), 16)) / 1099511627776 & 255, e[11] = t / 4294967296 & 255, e[12] = t >>> 24 & 255, e[13] = t >>> 16 & 255, e[14] = t >>> 8 & 255, e[15] = t & 255, e;
}
function Cu(r) {
r = unescape(encodeURIComponent(r));
const t = [];
for (let e = 0; e < r.length; ++e)
t.push(r.charCodeAt(e));
return t;
}
const Mu = "6ba7b810-9dad-11d1-80b4-00c04fd430c8", wu = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
function Pu(r, t, e) {
function n(i, s, a, o) {
var c;
if (typeof i == "string" && (i = Cu(i)), typeof s == "string" && (s = Tu(s)), ((c = s) === null || c === void 0 ? void 0 : c.length) !== 16)
throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
let l = new Uint8Array(16 + i.length);
if (l.set(s), l.set(i, s.length), l = e(l), l[6] = l[6] & 15 | t, l[8] = l[8] & 63 | 128, a) {
o = o || 0;
for (let u = 0; u < 16; ++u)
a[o + u] = l[u];
return a;
}
return bu(l);
}
try {
n.name = r;
} catch {
}
return n.DNS = Mu, n.URL = wu, n;
}
function Eu(r, t, e, n) {
switch (r) {
case 0:
return t & e ^ ~t & n;
case 1:
return t ^ e ^ n;
case 2:
return t & e ^ t & n ^ e & n;
case 3:
return t ^ e ^ n;
}
}
function bs(r, t) {
return r << t | r >>> 32 - t;
}
function ku(r) {
const t = [1518500249, 1859775393, 2400959708, 3395469782], e = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
if (typeof r == "string") {
const a = unescape(encodeURIComponent(r));
r = [];
for (let o = 0; o < a.length; ++o)
r.push(a.charCodeAt(o));
} else Array.isArray(r) || (r = Array.prototype.slice.call(r));
r.push(128);
const n = r.length / 4 + 2, i = Math.ceil(n / 16), s = new Array(i);
for (let a = 0; a < i; ++a) {
const o = new Uint32Array(16);
for (let c = 0; c < 16; ++c)
o[c] = r[a * 64 + c * 4] << 24 | r[a * 64 + c * 4 + 1] << 16 | r[a * 64 + c * 4 + 2] << 8 | r[a * 64 + c * 4 + 3];
s[a] = o;
}
s[i - 1][14] = (r.length - 1) * 8 / Math.pow(2, 32), s[i - 1][14] = Math.floor(s[i - 1][14]), s[i - 1][15] = (r.length - 1) * 8 & 4294967295;
for (let a = 0; a < i; ++a) {
const o = new Uint32Array(80);
for (let m = 0; m < 16; ++m)
o[m] = s[a][m];
for (let m = 16; m < 80; ++m)
o[m] = bs(o[m - 3] ^ o[m - 8] ^ o[m - 14] ^ o[m - 16], 1);
let c = e[0], l = e[1], u = e[2], f = e[3], p = e[4];
for (let m = 0; m < 80; ++m) {
const x = Math.floor(m / 20), T = bs(c, 5) + Eu(x, l, u, f) + p + t[x] + o[m] >>> 0;
p = f, f = u, u = bs(l, 30) >>> 0, l = c, c = T;
}
e[0] = e[0] + c >>> 0, e[1] = e[1] + l >>> 0, e[2] = e[2] + u >>> 0, e[3] = e[3] + f >>> 0, e[4] = e[4] + p >>> 0;
}
return [e[0] >> 24 & 255, e[0] >> 16 & 255, e[0] >> 8 & 255, e[0] & 255, e[1] >> 24 & 255, e[1] >> 16 & 255, e[1] >> 8 & 255, e[1] & 255, e[2] >> 24 & 255, e[2] >> 16 & 255, e[2] >> 8 & 255, e[2] & 255, e[3] >> 24 & 255, e[3] >> 16 & 255, e[3] >> 8 & 255, e[3] & 255, e[4] >> 24 & 255, e[4] >> 16 & 255, e[4] >> 8 & 255, e[4] & 255];
}
const Fd = Pu("v5", 80, ku), Ts = 2, Ue = 4, Ze = 4, Ru = 4, an = new Int32Array(2), da = new Float32Array(an.buffer), pa = new Float64Array(an.buffer), cr = new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;
class Qe {
constructor(t, e) {
this.low = t | 0, this.high = e | 0;
}
static create(t, e) {
return t == 0 && e == 0 ? Qe.ZERO : new Qe(t, e);
}
toFloat64() {
return (this.low >>> 0) + this.high * 4294967296;
}
equals(t) {
return this.low == t.low && this.high == t.high;
}
}
Qe.ZERO = new Qe(0, 0);
var Zs;
(function(r) {
r[r.UTF8_BYTES = 1] = "UTF8_BYTES", r[r.UTF16_STRING = 2] = "UTF16_STRING";
})(Zs || (Zs = {}));
class Jr {
/**
* Create a new ByteBuffer with a given array of bytes (`Uint8Array`)
*/
constructor(t) {
this.bytes_ = t, this.position_ = 0;
}
/**
* Create and allocate a new ByteBuffer with a given size.
*/
static allocate(t) {
return new Jr(new Uint8Array(t));
}
clear() {
this.position_ = 0;
}
/**
* Get the underlying `Uint8Array`.
*/
bytes() {
return this.bytes_;
}
/**
* Get the buffer's position.
*/
position() {
return this.position_;
}
/**
* Set the buffer's position.
*/
setPosition(t) {
this.position_ = t;
}
/**
* Get the buffer's capacity.
*/
capacity() {
return this.bytes_.length;
}
readInt8(t) {
return this.readUint8(t) << 24 >> 24;
}
readUint8(t) {
return this.bytes_[t];
}
readInt16(t) {
return this.readUint16(t) << 16 >> 16;
}
readUint16(t) {
return this.bytes_[t] | this.bytes_[t + 1] << 8;
}
readInt32(t) {
return this.bytes_[t] | this.bytes_[t + 1] << 8 | this.bytes_[t + 2] << 16 | this.bytes_[t + 3] << 24;
}
readUint32(t) {
return this.readInt32(t) >>> 0;
}
readInt64(t) {
return new Qe(this.readInt32(t), this.readInt32(t + 4));
}
readUint64(t) {
return new Qe(this.readUint32(t), this.readUint32(t + 4));
}
readFloat32(t) {
return an[0] = this.readInt32(t), da[0];
}
readFloat64(t) {
return an[cr ? 0 : 1] = this.readInt32(t), an[cr ? 1 : 0] = this.readInt32(t + 4), pa[0];
}
writeInt8(t, e) {
this.bytes_[t] = e;
}
writeUint8(t, e) {
this.bytes_[t] = e;
}
writeInt16(t, e) {
this.bytes_[t] = e, this.bytes_[t + 1] = e >> 8;
}
writeUint16(t, e) {
this.bytes_[t] = e, this.bytes_[t + 1] = e >> 8;
}
writeInt32(t, e) {
this.bytes_[t] = e, this.bytes_[t + 1] = e >> 8, this.bytes_[t + 2] = e >> 16, this.bytes_[t + 3] = e >> 24;
}
writeUint32(t, e) {
this.bytes_[t] = e, this.bytes_[t + 1] = e >> 8, this.bytes_[t + 2] = e >> 16, this.bytes_[t + 3] = e >> 24;
}
writeInt64(t, e) {
this.writeInt32(t, e.low), this.writeInt32(t + 4, e.high);
}
writeUint64(t, e) {
this.writeUint32(t, e.low), this.writeUint32(t + 4, e.high);
}
writeFloat32(t, e) {
da[0] = e, this.writeInt32(t, an[0]);
}
writeFloat64(t, e) {
pa[0] = e, this.writeInt32(t, an[cr ? 0 : 1]), this.writeInt32(t + 4, an[cr ? 1 : 0]);
}
/**
* Return the file identifier. Behavior is undefined for FlatBuffers whose
* schema does not include a file_identifier (likely points at padding or the
* start of a the root vtable).
*/
getBufferIdentifier() {
if (this.bytes_.length < this.position_ + Ue + Ze)
throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");
let t = "";
for (let e = 0; e < Ze; e++)
t += String.fromCharCode(this.readInt8(this.position_ + Ue + e));
return t;
}
/**
* Look up a field in the vtable, return an offset into the object, or 0 if the
* field is not present.
*/
__offset(t, e) {
const n = t - this.readInt32(t);
return e < this.readInt16(n) ? this.readInt16(n + e) : 0;
}
/**
* Initialize any Table-derived type to point to the union at the given offset.
*/
__union(t, e) {
return t.bb_pos = e + this.readInt32(e), t.bb = this, t;
}
/**
* Create a JavaScript string from UTF-8 data stored inside the FlatBuffer.
* This allocates a new string and converts to wide chars upon each access.
*
* To avoid the conversion to UTF-16, pass Encoding.UTF8_BYTES as
* the "optionalEncoding" argument. This is useful for avoiding conversion to
* and from UTF-16 when the data will just be packaged back up in another
* FlatBuffer later on.
*
* @param offset
* @param opt_encoding Defaults to UTF16_STRING
*/
__string(t, e) {
t += this.readInt32(t);
const n = this.readInt32(t);
let i = "", s = 0;
if (t += Ue, e === Zs.UTF8_BYTES)
return this.bytes_.subarray(t, t + n);
for (; s < n; ) {
let a;
const o = this.readUint8(t + s++);
if (o < 192)
a = o;
else {
const c = this.readUint8(t + s++);
if (o < 224)
a = (o & 31) << 6 | c & 63;
else {
const l = this.readUint8(t + s++);
if (o < 240)
a = (o & 15) << 12 | (c & 63) << 6 | l & 63;
else {
const u = this.readUint8(t + s++);
a = (o & 7) << 18 | (c & 63) << 12 | (l & 63) << 6 | u & 63;
}
}
}
a < 65536 ? i += String.fromCharCode(a) : (a -= 65536, i += String.fromCharCode((a >> 10) + 55296, (a & 1023) + 56320));
}
return i;
}
/**
* Handle unions that can contain string as its member, if a Table-derived type then initialize it,
* if a string then return a new one
*
* WARNING: strings are immutable in JS so we can't change the string that the user gave us, this
* makes the behaviour of __union_with_string different compared to __union
*/
__union_with_string(t, e) {
return typeof t == "string" ? this.__string(e) : this.__union(t, e);
}
/**
* Retrieve the relative offset stored at "offset"
*/
__indirect(t) {
return t + this.readInt32(t);
}
/**
* Get the start of data of a vector whose offset is stored at "offset" in this object.
*/
__vector(t) {
return t + this.readInt32(t) + Ue;
}
/**
* Get the length of a vector whose offset is stored at "offset" in this object.
*/
__vector_len(t) {
return this.readInt32(t + this.readInt32(t));
}
__has_identifier(t) {
if (t.length != Ze)
throw new Error("FlatBuffers: file identifier must be length " + Ze);
for (let e = 0; e < Ze; e++)
if (t.charCodeAt(e) != this.readInt8(this.position() + Ue + e))
return !1;
return !0;
}
/**
* A helper function to avoid generated code depending on this file directly.
*/
createLong(t, e) {
return Qe.create(t, e);
}
/**
* A helper function for generating list for obj api
*/
createScalarList(t, e) {
const n = [];
for (let i = 0; i < e; ++i)
t(i) !== null && n.push(t(i));
return n;
}
/**
* A helper function for generating list for obj api
* @param listAccessor function that accepts an index and return data at that index
* @param listLength listLength
* @param res result list
*/
createObjList(t, e) {
const n = [];
for (let i = 0; i < e; ++i) {
const s = t(i);
s !== null && n.push(s.unpack());
}
return n;
}
}
class Pc {
/**
* Create a FlatBufferBuilder.
*/
constructor(t) {
this.minalign = 1, this.vtable = null, this.vtable_in_use = 0, this.isNested = !1, this.object_start = 0, this.vtables = [], this.vector_num_elems = 0, this.force_defaults = !1, this.string_maps = null;
let e;
t ? e = t : e = 1024, this.bb = Jr.allocate(e), this.space = e;
}
clear() {
this.bb.clear(), this.space = this.bb.capacity(), this.minalign = 1, this.vtable = null, this.vtable_in_use = 0, this.isNested = !1, this.object_start = 0, this.vtables = [], this.vector_num_elems = 0, this.force_defaults = !1, this.string_maps = null;
}
/**
* In order to save space, fields that are set to their default value
* don't get serialized into the buffer. Forcing defaults provides a
* way to manually disable this optimization.
*
* @param forceDefaults true always serializes default values
*/
forceDefaults(t) {
this.force_defaults = t;
}
/**
* Get the ByteBuffer representing the FlatBuffer. Only call this after you've
* called finish(). The actual data starts at the ByteBuffer's current position,
* not necessarily at 0.
*/
dataBuffer() {
return this.bb;
}
/**
* Get the bytes representing the FlatBuffer. Only call this after you've
* called finish().
*/
asUint8Array() {
return this.bb.bytes().subarray(this.bb.position(), this.bb.position() + this.offset());
}
/**
* Prepare to write an element of `size` after `additional_bytes` have been
* written, e.g. if you write a string, you need to align such the int length
* field is aligned to 4 bytes, and the string data follows it directly. If all
* you need to do is alignment, `additional_bytes` will be 0.
*
* @param size This is the of the new element to write
* @param additional_bytes The padding size
*/
prep(t, e) {
t > this.minalign && (this.minalign = t);
const n = ~(this.bb.capacity() - this.space + e) + 1 & t - 1;
for (; this.space < n + t + e; ) {
const i = this.bb.capacity();
this.bb = Pc.growByteBuffer(this.bb), this.space += this.bb.capacity() - i;
}
this.pad(n);
}
pad(t) {
for (let e = 0; e < t; e++)
this.bb.writeInt8(--this.space, 0);
}
writeInt8(t) {
this.bb.writeInt8(this.space -= 1, t);
}
writeInt16(t) {
this.bb.writeInt16(this.space -= 2, t);
}
writeInt32(t) {
this.bb.writeInt32(this.space -= 4, t);
}
writeInt64(t) {
this.bb.writeInt64(this.space -= 8, t);
}
writeFloat32(t) {
this.bb.writeFloat32(this.space -= 4, t);
}
writeFloat64(t) {
this.bb.writeFloat64(this.space -= 8, t);
}
/**
* Add an `int8` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int8` to add the the buffer.
*/
addInt8(t) {
this.prep(1, 0), this.writeInt8(t);
}
/**
* Add an `int16` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int16` to add the the buffer.
*/
addInt16(t) {
this.prep(2, 0), this.writeInt16(t);
}
/**
* Add an `int32` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int32` to add the the buffer.
*/
addInt32(t) {
this.prep(4, 0), this.writeInt32(t);
}
/**
* Add an `int64` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int64` to add the the buffer.
*/
addInt64(t) {
this.prep(8, 0), this.writeInt64(t);
}
/**
* Add a `float32` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `float32` to add the the buffer.
*/
addFloat32(t) {
this.prep(4, 0), this.writeFloat32(t);
}
/**
* Add a `float64` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `float64` to add the the buffer.
*/
addFloat64(t) {
this.prep(8, 0), this.writeFloat64(t);
}
addFieldInt8(t, e, n) {
(this.force_defaults || e != n) && (this.addInt8(e), this.slot(t));
}
addFieldInt16(t, e, n) {
(this.force_defaults || e != n) && (this.addInt16(e), this.slot(t));
}
addFieldInt32(t, e, n) {
(this.force_defaults || e != n) && (this.addInt32(e), this.slot(t));
}
addFieldInt64(t, e, n) {
(this.force_defaults || !e.equals(n)) && (this.addInt64(e), this.slot(t));
}
addFieldFloat32(t, e, n) {
(this.force_defaults || e != n) && (this.addFloat32(e), this.slot(t));
}
addFieldFloat64(t, e, n) {
(this.force_defaults || e != n) && (this.addFloat64(e), this.slot(t));
}
addFieldOffset(t, e, n) {
(this.force_defaults || e != n) && (this.addOffset(e), this.slot(t));
}
/**
* Structs are stored inline, so nothing additional is being added. `d` is always 0.
*/
addFieldStruct(t, e, n) {
e != n && (this.nested(e), this.slot(t));
}
/**
* Structures are always stored inline, they need to be created right
* where they're used. You'll get this assertion failure if you
* created it elsewhere.
*/
nested(t) {
if (t != this.offset())
throw new Error("FlatBuffers: struct must be serialized inline.");
}
/**
* Should not be creating any other object, string or vector
* while an object is being constructed
*/
notNested() {
if (this.isNested)
throw new Error("FlatBuffers: object serialization must not be nested.");
}
/**
* Set the current vtable at `voffset` to the current location in the buffer.
*/
slot(t) {
this.vtable !== null && (this.vtable[t] = this.offset());
}
/**
* @returns Offset relative to the end of the buffer.
*/
offset() {
return this.bb.capacity() - this.space;
}
/**
* Doubles the size of the backing ByteBuffer and copies the old data towards
* the end of the new buffer (since we build the buffer backwards).
*
* @param bb The current buffer with the existing data
* @returns A new byte buffer with the old data copied
* to it. The data is located at the end of the buffer.
*
* uint8Array.set() formally takes {Array<number>|ArrayBufferView}, so to pass
* it a uint8Array we need to suppress the type check:
* @suppress {checkTypes}
*/
static growByteBuffer(t) {
const e = t.capacity();
if (e & 3221225472)
throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");
const n = e << 1, i = Jr.allocate(n);
return i.setPosition(n - e), i.bytes().set(t.bytes(), n - e), i;
}
/**
* Adds on offset, relative to where it will be written.
*
* @param offset The offset to add.
*/
addOffset(t) {
this.prep(Ue, 0), this.writeInt32(this.offset() - t + Ue);
}
/**
* Start encoding a new object in the buffer. Users will not usually need to
* call this directly. The FlatBuffers compiler will generate helper methods
* that call this method internally.
*/
startObject(t) {
this.notNested(), this.vtable == null && (this.vtable = []), this.vtable_in_use = t;
for (let e = 0; e < t; e++)
this.vtable[e] = 0;
this.isNested = !0, this.object_start = this.offset();
}
/**
* Finish off writing the object that is under construction.
*
* @returns The offset to the object inside `dataBuffer`
*/
endObject() {
if (this.vtable == null || !this.isNested)
throw new Error("FlatBuffers: endObject called without startObject");
this.addInt32(0);
const t = this.offset();
let e = this.vtable_in_use - 1;
for (; e >= 0 && this.vtable[e] == 0; e--)
;
const n = e + 1;
for (; e >= 0; e--)
this.addInt16(this.vtable[e] != 0 ? t - this.vtable[e] : 0);
const i = 2;
this.addInt16(t - this.object_start);
const s = (n + i) * Ts;
this.addInt16(s);
let a = 0;
const o = this.space;
t: for (e = 0; e < this.vtables.length; e++) {
const c = this.bb.capacity() - this.vtables[e];
if (s == this.bb.readInt16(c)) {
for (let l = Ts; l < s; l += Ts)
if (this.bb.readInt16(o + l) != this.bb.readInt16(c + l))
continue t;
a = this.vtables[e];
break;
}
}
return a ? (this.space = this.bb.capacity() - t, this.bb.writeInt32(this.space, a - t)) : (this.vtables.push(this.offset()), this.bb.writeInt32(this.bb.capacity() - t, this.offset() - t)), this.isNested = !1, t;
}
/**
* Finalize a buffer, poiting to the given `root_table`.
*/
finish(t, e, n) {
const i = n ? Ru : 0;
if (e) {
const s = e;
if (this.prep(this.minalign, Ue + Ze + i), s.length != Ze)
throw new Error("FlatBuffers: file identifier must be length " + Ze);
for (let a = Ze - 1; a >= 0; a--)
this.writeInt8(s.charCodeAt(a));
}
this.prep(this.minalign, Ue + i), this.addOffset(t), i && this.addInt32(this.bb.capacity() - this.space), this.bb.setPosition(this.space);
}
/**
* Finalize a size prefixed buffer, pointing to the given `root_table`.
*/
finishSizePrefixed(t, e) {
this.finish(t, e, !0);
}
/**
* This checks a required field has been set in a given table that has
* just been constructed.
*/
requiredField(t, e) {
const n = this.bb.capacity() - t, i = n - this.bb.readInt32(n);
if (!(this.bb.readInt16(i + e) != 0))
throw new Error("FlatBuffers: field " + e + " must be set");
}
/**
* Start a new array/vector of objects. Users usually will not call
* this directly. The FlatBuffers compiler will create a start/end
* method for vector types in generated code.
*
* @param elem_size The size of each element in the array
* @param num_elems The number of elements in the array
* @param alignment The alignment of the array
*/
startVector(t, e, n) {
this.notNested(), this.vector_num_elems = e, this.prep(Ue, t * e), this.prep(n, t * e);
}
/**
* Finish off the creation of an array and all its elements. The array must be
* created with `startVector`.
*
* @returns The offset at which the newly created array
* starts.
*/
endVector() {
return this.writeInt32(this.vector_num_elems), this.offset();
}
/**
* Encode the string `s` in the buffer using UTF-8. If the string passed has
* already been seen, we return the offset of the already written string
*
* @param s The string to encode
* @return The offset in the buffer where the encoded string starts
*/
createSharedString(t) {
if (!t)
return 0;
if (this.string_maps || (this.string_maps = /* @__PURE__ */ new Map()), this.string_maps.has(t))
return this.string_maps.get(t);
const e = this.createString(t);
return this.string_maps.set(t, e), e;
}
/**
* Encode the string `s` in the buffer using UTF-8. If a Uint8Array is passed
* instead of a string, it is assumed to contain valid UTF-8 encoded data.
*
* @param s The string to encode
* @return The offset in the buffer where the encoded string starts
*/
createString(t) {
if (!t)
return 0;
let e;
if (t instanceof Uint8Array)
e = t;
else {
e = [];
let n = 0;
for (; n < t.length; ) {
let i;
const s = t.charCodeAt(n++);
if (s < 55296 || s >= 56320)
i = s;
else {
const a = t.charCodeAt(n++);
i = (s << 10) + a + -56613888;
}
i < 128 ? e.push(i) : (i < 2048 ? e.push(i >> 6 & 31 | 192) : (i < 65536 ? e.push(i >> 12 & 15 | 224) : e.push(i >> 18 & 7 | 240, i >> 12 & 63 | 128), e.push(i >> 6 & 63 | 128)), e.push(i & 63 | 128));
}
}
this.addInt8(0), this.startVector(1, e.length, 1), this.bb.setPosition(this.space -= e.length);
for (let n = 0, i = this.space, s = this.bb.bytes(); n < e.length; n++)
s[i++] = e[n];
return this.endVector();
}
/**
* A helper function to avoid generated code depending on this file directly.
*/
createLong(t, e) {
return Qe.create(t, e);
}
/**
* A helper function to pack an object
*
* @returns offset of obj
*/
createObjectOffset(t) {
return t === null ? 0 : typeof t == "string" ? this.createString(t) : t.pack(this);
}
/**
* A helper function to pack a list of object
*
* @returns list of offsets of each non null object
*/
createObjectOffsetList(t) {
const e = [];
for (let n = 0; n < t.length; ++n) {
const i = t[n];
if (i !== null)
e.push(this.createObjectOffset(i));
else
throw new Error("FlatBuffers: Argument for createObjectOffsetList cannot contain null.");
}
return e;
}
createStructOffsetList(t, e) {
return e(this, t.length), this.createObjectOffsetList(t), this.endVector();
}
}
const It = {
ComponentState: Object.freeze({
DEFAULT: "default",
TOUCHED: "touched",
PRESSED: "pressed"
}),
ComponentProperty: Object.freeze({
BUTTON: "button",
X_AXIS: "xAxis",
Y_AXIS: "yAxis",
STATE: "state"
}),
ButtonTouchThreshold: 0.05,
AxisTouchThreshold: 0.1,
VisualResponseProperty: Object.freeze({
TRANSFORM: "transform",
VISIBILITY: "visibility"
})
};
async function Ec(r) {
const t = await fetch(r);
if (t.ok)
return t.json();
throw new Error(t.statusText);
}
async function Au(r) {
return await Ec(`${r}/profilesList.json`);
}
async function Ld(r, t, e = null, n = !0) {
if (!r)
throw new Error("No xrInputSource supplied");
const i = await Au(t);
let s;
if (r.profiles.some((c) => {
const l = i[c];
return l && (s = {
profileId: c,
profilePath: `${t}/${l.path}`,
deprecated: !!l.deprecated
}), !!s;
}), !s) {
if (!e)
throw new Error("No matching profile name found");
const c = i[e];
if (!c)
throw new Error(`No matching profile name found and default profile "${e}" missing.`);
s = {
profileId: e,
profilePath: `${t}/${c.path}`,
deprecated: !!c.deprecated
};
}
const a = await Ec(s.profilePath);
let o;
if (n) {
let c;
if (r.handedness === "any" ? c = a.layouts[Object.keys(a.layouts)[0]] : c = a.layouts[r.handedness], !c)
throw new Error(
`No matching handedness, ${r.handedness}, in profile ${s.profileId}`
);
c.assetPath && (o = s.profilePath.replace("profile.json", c.assetPath));
}
return { profile: a, assetPath: o };
}
const Ou = {
xAxis: 0,
yAxis: 0,
button: 0,
state: It.ComponentState.DEFAULT
};
function zu(r = 0, t = 0) {
let e = r, n = t;
if (Math.sqrt(r * r + t * t) > 1) {
const a = Math.atan2(t, r);
e = Math.cos(a), n = Math.sin(a);
}
return {
normalizedXAxis: e * 0.5 + 0.5,
normalizedYAxis: n * 0.5 + 0.5
};
}
class Iu {
constructor(t) {
this.componentProperty = t.componentProperty, this.states = t.states, this.valueNodeName = t.valueNodeName, this.valueNodeProperty = t.valueNodeProperty, this.valueNodeProperty === It.VisualResponseProperty.TRANSFORM && (this.minNodeName = t.minNodeName, this.maxNodeName = t.maxNodeName), this.value = 0, this.updateFromComponent(Ou);
}
/**
* Computes the visual response's interpolation weight based on component state
* @param {Object} componentValues - The component from which to update
* @param {number} xAxis - The reported X axis value of the component
* @param {number} yAxis - The reported Y axis value of the component
* @param {number} button - The reported value of the component's button
* @param {string} state - The component's active state
*/
updateFromComponent({
xAxis: t,
yAxis: e,
button: n,
state: i
}) {
const { normalizedXAxis: s, normalizedYAxis: a } = zu(t, e);
switch (this.componentProperty) {
case It.ComponentProperty.X_AXIS:
this.value = this.states.includes(i) ? s : 0.5;
break;
case It.ComponentProperty.Y_AXIS:
this.value = this.states.includes(i) ? a : 0.5;
break;
case It.ComponentProperty.BUTTON:
this.value = this.states.includes(i) ? n : 0;
break;
case It.ComponentProperty.STATE:
this.valueNodeProperty === It.VisualResponseProperty.VISIBILITY ? this.value = this.states.includes(i) : this.value = this.states.includes(i) ? 1 : 0;
break;
default:
throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`);
}
}
}
class Bu {
/**
* @param {Object} componentId - Id of the component
* @param {Object} componentDescription - Description of the component to be created
*/
constructor(t, e) {
if (!t || !e || !e.visualResponses || !e.gamepadIndices || Object.keys(e.gamepadIndices).length === 0)
throw new Error("Invalid arguments supplied");
this.id = t, this.type = e.type, this.rootNodeName = e.rootNodeName, this.touchPointNodeName = e.touchPointNodeName, this.visualResponses = {}, Object.keys(e.visualResponses).forEach((n) => {
const i = new Iu(e.visualResponses[n]);
this.visualResponses[n] = i;
}), this.gamepadIndices = Object.assign({}, e.gamepadIndices), this.values = {
state: It.ComponentState.DEFAULT,
button: this.gamepadIndices.button !== void 0 ? 0 : void 0,
xAxis: this.gamepadIndices.xAxis !== void 0 ? 0 : void 0,
yAxis: this.gamepadIndices.yAxis !== void 0 ? 0 : void 0
};
}
get data() {
return { id: this.id, ...this.values };
}
/**
* @description Poll for updated data based on current gamepad state
* @param {Object} gamepad - The gamepad object from which the component data should be polled
*/
updateFromGamepad(t) {
if (this.values.state = It.ComponentState.DEFAULT, this.gamepadIndices.button !== void 0 && t.buttons.length > this.gamepadIndices.button) {
const e = t.buttons[this.gamepadIndices.button];
this.values.button = e.value, this.values.button = this.values.button < 0 ? 0 : this.values.button, this.values.button = this.values.button > 1 ? 1 : this.values.button, e.pressed || this.values.button === 1 ? this.values.state = It.ComponentState.PRESSED : (e.touched || this.values.button > It.ButtonTouchThreshold) && (this.values.state = It.ComponentState.TOUCHED);
}
this.gamepadIndices.xAxis !== void 0 && t.axes.length > this.gamepadIndices.xAxis && (this.values.xAxis = t.axes[this.gamepadIndices.xAxis], this.values.xAxis = this.values.xAxis < -1 ? -1 : this.values.xAxis, this.values.xAxis = this.values.xAxis > 1 ? 1 : this.values.xAxis, this.values.state === It.ComponentState.DEFAULT && Math.abs(this.values.xAxis) > It.AxisTouchThreshold && (this.values.state = It.ComponentState.TOUCHED)), this.gamepadIndices.yAxis !== void 0 && t.axes.length > this.gamepadIndices.yAxis && (this.values.yAxis = t.axes[this.gamepadIndices.yAxis], this.values.yAxis = this.values.yAxis < -1 ? -1 : this.values.yAxis, this.values.yAxis = this.values.yAxis > 1 ? 1 : this.values.yAxis, this.values.state === It.ComponentState.DEFAULT && Math.abs(this.values.yAxis) > It.AxisTouchThreshold && (this.values.state = It.ComponentState.TOUCHED)), Object.values(this.visualResponses).forEach((e) => {
e.updateFromComponent(this.values);
});
}
}
class Vd {
/**
* @param {Object} xrInputSource - The XRInputSource to build the MotionController around
* @param {Object} profile - The best matched profile description for the supplied xrInputSource
* @param {Object} assetUrl
*/
constructor(t, e, n) {
if (!t)
throw new Error("No xrInputSource supplied");
if (!e)
throw new Error("No profile supplied");
this.xrInputSource = t, this.assetUrl = n, this.id = e.profileId, this.layoutDescription = e.layouts[t.handedness], this.components = {}, Object.keys(this.layoutDescription.components).forEach((i) => {
const s = this.layoutDescription.components[i];
this.components[i] = new Bu(i, s);
}), this.updateFromGamepad();
}
get gripSpace() {
return this.xrInputSource.gripSpace;
}
get targetRaySpace() {
return this.xrInputSource.targetRaySpace;
}
/**
* @description Returns a subset of component data for simplified debugging
*/
get data() {
const t = [];
return Object.values(this.components).forEach((e) => {
t.push(e.data);
}), t;
}
/**
* @description Poll for updated data based on current gamepad state
*/
updateFromGamepad() {
Object.values(this.components).forEach((t) => {
t.updateFromGamepad(this.xrInputSource.gamepad);
});
}
}
const Wt = ["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 ma = 1234567;
const kc = Math.PI / 180, Rc = 180 / Math.PI;
function Nu() {
const r = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, e = Math.random() * 4294967295 | 0, n = Math.random() * 4294967295 | 0;
return (Wt[r & 255] + Wt[r >> 8 & 255] + Wt[r >> 16 & 255] + Wt[r >> 24 & 255] + "-" + Wt[t & 255] + Wt[t >> 8 & 255] + "-" + Wt[t >> 16 & 15 | 64] + Wt[t >> 24 & 255] + "-" + Wt[e & 63 | 128] + Wt[e >> 8 & 255] + "-" + Wt[e >> 16 & 255] + Wt[e >> 24 & 255] + Wt[n & 255] + Wt[n >> 8 & 255] + Wt[n >> 16 & 255] + Wt[n >> 24 & 255]).toLowerCase();
}
function Ne(r, t, e) {
return Math.max(t, Math.min(e, r));
}
function Ac(r, t) {
return (r % t + t) % t;
}
function Uu(r, t, e, n, i) {
return n + (r - t) * (i - n) / (e - t);
}
function Du(r, t, e) {
return r !== t ? (e - r) / (t - r) : 0;
}
function Oc(r, t, e) {
return (1 - e) * r + e * t;
}
function Fu(r, t, e, n) {
return Oc(r, t, 1 - Math.exp(-e * n));
}
function Lu(r, t = 1) {
return t - Math.abs(Ac(r, t * 2) - t);
}
function Vu(r, t, e) {
return r <= t ? 0 : r >= e ? 1 : (r = (r - t) / (e - t), r * r * (3 - 2 * r));
}
function Ju(r, t, e) {
return r <= t ? 0 : r >= e ? 1 : (r = (r - t) / (e - t), r * r * r * (r * (r * 6 - 15) + 10));
}
function ju(r, t) {
return r + Math.floor(Math.random() * (t - r + 1));
}
function Gu(r, t) {
return r + Math.random() * (t - r);
}
function Wu(r) {
return r * (0.5 - Math.random());
}
function $u(r) {
r !== void 0 && (ma = r);
let t = ma += 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 Hu(r) {
return r * kc;
}
function qu(r) {
return r * Rc;
}
function Xu(r) {
return (r & r - 1) === 0 && r !== 0;
}
function Yu(r) {
return Math.pow(2, Math.ceil(Math.log(r) / Math.LN2));
}
function Zu(r) {
return Math.pow(2, Math.floor(Math.log(r) / Math.LN2));
}
function Ku(r, t, e, n, i) {
const s = Math.cos, a = Math.sin, o = s(e / 2), c = a(e / 2), l = s((t + n) / 2), u = a((t + n) / 2), f = s((t - n) / 2), p = a((t - n) / 2), m = s((n - t) / 2), x = a((n - t) / 2);
switch (i) {
case "XYX":
r.set(o * u, c * f, c * p, o * l);
break;
case "YZY":
r.set(c * p, o * u, c * f, o * l);
break;
case "ZXZ":
r.set(c * f, c * p, o * u, o * l);
break;
case "XZX":
r.set(o * u, c * x, c * m, o * l);
break;
case "YXY":
r.set(c * m, o * u, c * x, o * l);
break;
case "ZYZ":
r.set(c * x, c * m, o * u, o * l);
break;
default:
console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: " + i);
}
}
function Qu(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 th(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 Zn = {
DEG2RAD: kc,
RAD2DEG: Rc,
generateUUID: Nu,
clamp: Ne,
euclideanModulo: Ac,
mapLinear: Uu,
inverseLerp: Du,
lerp: Oc,
damp: Fu,
pingpong: Lu,
smoothstep: Vu,
smootherstep: Ju,
randInt: ju,
randFloat: Gu,
randFloatSpread: Wu,
seededRandom: $u,
degToRad: Hu,
radToDeg: qu,
isPowerOfTwo: Xu,
ceilPowerOfTwo: Yu,
floorPowerOfTwo: Zu,
setQuaternionFromProperEuler: Ku,
normalize: th,
denormalize: Qu
};
class rt {
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, a, o) {
let c = n[i + 0], l = n[i + 1], u = n[i + 2], f = n[i + 3];
const p = s[a + 0], m = s[a + 1], x = s[a + 2], T = s[a + 3];
if (o === 0) {
t[e + 0] = c, t[e + 1] = l, t[e + 2] = u, t[e + 3] = f;
return;
}
if (o === 1) {
t[e + 0] = p, t[e + 1] = m, t[e + 2] = x, t[e + 3] = T;
return;
}
if (f !== T || c !== p || l !== m || u !== x) {
let g = 1 - o;
const v = c * p + l * m + u * x + f * T, _ = v >= 0 ? 1 : -1, b = 1 - v * v;
if (b > Number.EPSILON) {
const M = Math.sqrt(b), P = Math.atan2(M, v * _);
g = Math.sin(g * P) / M, o = Math.sin(o * P) / M;
}
const C = o * _;
if (c = c * g + p * C, l = l * g + m * C, u = u * g + x * C, f = f * g + T * C, g === 1 - o) {
const M = 1 / Math.sqrt(c * c + l * l + u * u + f * f);
c *= M, l *= M, u *= M, f *= M;
}
}
t[e] = c, t[e + 1] = l, t[e + 2] = u, t[e + 3] = f;
}
static multiplyQuaternionsFlat(t, e, n, i, s, a) {
const o = n[i], c = n[i + 1], l = n[i + 2], u = n[i + 3], f = s[a], p = s[a + 1], m = s[a + 2], x = s[a + 3];
return t[e] = o * x + u * f + c * m - l * p, t[e + 1] = c * x + u * p + l * f - o * m, t[e + 2] = l * x + u * m + o * p - c * f, t[e + 3] = u * x - o * f - c * p - l * m, 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 rt(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, a = t._order, o = Math.cos, c = Math.sin, l = o(n / 2), u = o(i / 2), f = o(s / 2), p = c(n / 2), m = c(i / 2), x = c(s / 2);
switch (a) {
case "XYZ":
this._x = p * u * f + l * m * x, this._y = l * m * f - p * u * x, this._z = l * u * x + p * m * f, this._w = l * u * f - p * m * x;
break;
case "YXZ":
this._x = p * u * f + l * m * x, this._y = l * m * f - p * u * x, this._z = l * u * x - p * m * f,