UNPKG

gpu-curtains

Version:

gpu-curtains is a 3D WebGPU rendering engine. It can be used as a standalone 3D engine, but also includes extra classes focused on mapping 3d objects to DOM elements; It allows users to synchronize values such as position, sizing, or scale between them.

1,306 lines 608 kB
var sa = Object.defineProperty; var x = (M, _) => sa(M, "name", { value: _, configurable: !0 }); (function(M, _) { typeof exports == "object" && typeof module < "u" ? _(exports) : typeof define == "function" && define.amd ? define(["exports"], _) : (M = typeof globalThis < "u" ? globalThis : M || self, _(M.window = M.window || {})); })(this, function(M) { Object.defineProperty(M, Symbol.toStringTag, { value: "Module" }); const _ = x(() => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => { const t = Math.random() * 16 | 0; return (e === "x" ? t : t & 3 | 8).toString(16).toUpperCase(); }), "generateUUID"), Ne = x((e) => e.replace(/(?:^\w|[A-Z]|\b\w)/g, (t, i) => i === 0 ? t.toLowerCase() : t.toUpperCase()).replace(/\s+/g, ""), "toCamelCase"), Te = x((e) => { const t = Ne(e); return t.charAt(0).toUpperCase() + t.slice(1); }, "toKebabCase"); let zt = 0; const F = x((e) => { zt > 100 || (console.warn(zt === 100 ? "GPUCurtains: too many warnings thrown, stop logging." : e), zt++); }, "throwWarning"), ee = x((e) => { throw new Error(e); }, "throwError"); var re = class Je { static { x(this, "Quat"); } constructor(t = new Float32Array([ 0, 0, 0, 1 ]), i = "XYZ") { this.type = "Quat", this.elements = t, this.axisOrder = i; } setFromArray(t = new Float32Array([ 0, 0, 0, 1 ])) { return this.elements[0] = t[0], this.elements[1] = t[1], this.elements[2] = t[2], this.elements[3] = t[3], this; } setAxisOrder(t = "XYZ") { switch (t = t.toUpperCase(), t) { case "XYZ": case "YXZ": case "ZXY": case "ZYX": case "YZX": case "XZY": this.axisOrder = t; break; default: this.axisOrder = "XYZ"; } return this; } copy(t = new Je()) { return this.elements.set(t.elements), this.axisOrder = t.axisOrder, this; } clone() { return new Je().copy(this); } equals(t = new Je()) { return this.elements[0] === t.elements[0] && this.elements[1] === t.elements[1] && this.elements[2] === t.elements[2] && this.elements[3] === t.elements[3] && this.axisOrder === t.axisOrder; } setFromVec3(t) { const i = t.x * .5, s = t.y * .5, r = t.z * .5, n = Math.cos(i), a = Math.cos(s), o = Math.cos(r), l = Math.sin(i), h = Math.sin(s), u = Math.sin(r); return this.axisOrder === "XYZ" ? (this.elements[0] = l * a * o + n * h * u, this.elements[1] = n * h * o - l * a * u, this.elements[2] = n * a * u + l * h * o, this.elements[3] = n * a * o - l * h * u) : this.axisOrder === "YXZ" ? (this.elements[0] = l * a * o + n * h * u, this.elements[1] = n * h * o - l * a * u, this.elements[2] = n * a * u - l * h * o, this.elements[3] = n * a * o + l * h * u) : this.axisOrder === "ZXY" ? (this.elements[0] = l * a * o - n * h * u, this.elements[1] = n * h * o + l * a * u, this.elements[2] = n * a * u + l * h * o, this.elements[3] = n * a * o - l * h * u) : this.axisOrder === "ZYX" ? (this.elements[0] = l * a * o - n * h * u, this.elements[1] = n * h * o + l * a * u, this.elements[2] = n * a * u - l * h * o, this.elements[3] = n * a * o + l * h * u) : this.axisOrder === "YZX" ? (this.elements[0] = l * a * o + n * h * u, this.elements[1] = n * h * o + l * a * u, this.elements[2] = n * a * u - l * h * o, this.elements[3] = n * a * o - l * h * u) : this.axisOrder === "XZY" && (this.elements[0] = l * a * o - n * h * u, this.elements[1] = n * h * o - l * a * u, this.elements[2] = n * a * u + l * h * o, this.elements[3] = n * a * o + l * h * u), this; } setFromAxisAngle(t, i = 0) { const s = i / 2, r = Math.sin(s); return this.elements[0] = t.x * r, this.elements[1] = t.y * r, this.elements[2] = t.z * r, this.elements[3] = Math.cos(s), this; } setFromRotationMatrix(t) { const i = t.elements, s = i[0], r = i[4], n = i[8], a = i[1], o = i[5], l = i[9], h = i[2], u = i[6], c = i[10], d = s + o + c; if (d > 0) { const p = .5 / Math.sqrt(d + 1); this.elements[3] = .25 / p, this.elements[0] = (u - l) * p, this.elements[1] = (n - h) * p, this.elements[2] = (a - r) * p; } else if (s > o && s > c) { const p = 2 * Math.sqrt(1 + s - o - c); this.elements[3] = (u - l) / p, this.elements[0] = .25 * p, this.elements[1] = (r + a) / p, this.elements[2] = (n + h) / p; } else if (o > c) { const p = 2 * Math.sqrt(1 + o - s - c); this.elements[3] = (n - h) / p, this.elements[0] = (r + a) / p, this.elements[1] = .25 * p, this.elements[2] = (l + u) / p; } else { const p = 2 * Math.sqrt(1 + c - s - o); this.elements[3] = (a - r) / p, this.elements[0] = (n + h) / p, this.elements[1] = (l + u) / p, this.elements[2] = .25 * p; } return this; } lengthSq() { return this.elements[0] * this.elements[0] + this.elements[1] * this.elements[1] + this.elements[2] * this.elements[2] + this.elements[3] * this.elements[3]; } length() { return Math.sqrt(this.lengthSq()); } normalize() { let t = this.length(); return t === 0 ? (this.elements[0] = 0, this.elements[1] = 0, this.elements[2] = 0, this.elements[3] = 1) : (t = 1 / t, this.elements[0] = this.elements[0] * t, this.elements[1] = this.elements[1] * t, this.elements[2] = this.elements[2] * t, this.elements[3] = this.elements[3] * t), this; } slerp(t = new Je(), i = 0) { if (i === 0) return this; if (i === 1) return this.copy(t); const s = this.elements[0], r = this.elements[1], n = this.elements[2], a = this.elements[3]; let o = a * t.elements[3] + s * t.elements[0] + r * t.elements[1] + n * t.elements[2]; if (o < 0 ? (this.elements[3] = -t.elements[3], this.elements[0] = -t.elements[0], this.elements[1] = -t.elements[1], this.elements[2] = -t.elements[2], o = -o) : this.copy(t), o >= 1) return this.elements[3] = a, this.elements[0] = s, this.elements[1] = r, this.elements[2] = n, this; const l = 1 - o * o; if (l <= Number.EPSILON) { const p = 1 - i; return this.elements[3] = p * a + i * this.elements[3], this.elements[0] = p * s + i * this.elements[0], this.elements[1] = p * r + i * this.elements[1], this.elements[2] = p * n + i * this.elements[2], this.normalize(), this; } const h = Math.sqrt(l), u = Math.atan2(h, o), c = Math.sin((1 - i) * u) / h, d = Math.sin(i * u) / h; return this.elements[3] = a * c + this.elements[3] * d, this.elements[0] = s * c + this.elements[0] * d, this.elements[1] = r * c + this.elements[1] * d, this.elements[2] = n * c + this.elements[2] * d, this; } }, b = class X { static { x(this, "Vec3"); } constructor(t = 0, i = t, s = t) { this.type = "Vec3", this._x = t, this._y = i, this._z = s; } get x() { return this._x; } set x(t) { const i = t !== this._x; this._x = t, i && this._onChangeCallback && this._onChangeCallback(); } get y() { return this._y; } set y(t) { const i = t !== this._y; this._y = t, i && this._onChangeCallback && this._onChangeCallback(); } get z() { return this._z; } set z(t) { const i = t !== this._z; this._z = t, i && this._onChangeCallback && this._onChangeCallback(); } onChange(t) { return t && (this._onChangeCallback = t), this; } set(t = 0, i = t, s = t) { return this.x = t, this.y = i, this.z = s, this; } add(t = new X()) { return this.x += t.x, this.y += t.y, this.z += t.z, this; } addScalar(t = 0) { return this.x += t, this.y += t, this.z += t, this; } sub(t = new X()) { return this.x -= t.x, this.y -= t.y, this.z -= t.z, this; } subScalar(t = 0) { return this.x -= t, this.y -= t, this.z -= t, this; } multiply(t = new X(1)) { return this.x *= t.x, this.y *= t.y, this.z *= t.z, this; } multiplyScalar(t = 1) { return this.x *= t, this.y *= t, this.z *= t, this; } divide(t = new X(1)) { return this.x /= t.x, this.y /= t.y, this.z /= t.z, this; } divideScalar(t = 1) { return this.x /= t, this.y /= t, this.z /= t, this; } copy(t = new X()) { return this.x = t.x, this.y = t.y, this.z = t.z, this; } clone() { return new X(this.x, this.y, this.z); } max(t = new X()) { 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; } min(t = new X()) { 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; } clamp(t = new X(), i = new X()) { return this.x = Math.max(t.x, Math.min(i.x, this.x)), this.y = Math.max(t.y, Math.min(i.y, this.y)), this.z = Math.max(t.z, Math.min(i.z, this.z)), this; } equals(t = new X()) { return this.x === t.x && this.y === t.y && this.z === t.z; } lengthSq() { return this.x * this.x + this.y * this.y + this.z * this.z; } length() { return Math.sqrt(this.lengthSq()); } distance(t = new X()) { return Math.hypot(t.x - this.x, t.y - this.y, t.z - this.z); } normalize() { let t = this.lengthSq(); return t > 0 && (t = 1 / Math.sqrt(t)), this.x *= t, this.y *= t, this.z *= t, this; } dot(t = new X()) { return this.x * t.x + this.y * t.y + this.z * t.z; } cross(t = new X()) { return this.crossVectors(this, t); } crossVectors(t = new X(), i = new X()) { const s = t.x, r = t.y, n = t.z, a = i.x, o = i.y, l = i.z; return this.x = r * l - n * o, this.y = n * a - s * l, this.z = s * o - r * a, this; } lerp(t = new X(), i = 1) { return this.x += (t.x - this.x) * i, this.y += (t.y - this.y) * i, this.z += (t.z - this.z) * i, this; } applyMat4(t) { const i = this._x, s = this._y, r = this._z, n = t.elements; let a = n[3] * i + n[7] * s + n[11] * r + n[15]; return a = a || 1, this.x = (n[0] * i + n[4] * s + n[8] * r + n[12]) / a, this.y = (n[1] * i + n[5] * s + n[9] * r + n[13]) / a, this.z = (n[2] * i + n[6] * s + n[10] * r + n[14]) / a, this; } setFromMatrixPosition(t) { const i = t.elements; return this.x = i[12], this.y = i[13], this.z = i[14], this; } applyQuat(t = new re()) { const i = this.x, s = this.y, r = this.z, n = t.elements[0], a = t.elements[1], o = t.elements[2], l = t.elements[3], h = 2 * (a * r - o * s), u = 2 * (o * i - n * r), c = 2 * (n * s - a * i); return this.x = i + l * h + a * c - o * u, this.y = s + l * u + o * h - n * c, this.z = r + l * c + n * u - a * h, this; } applyAxisAngle(t = new X(), i = 0, s = new re()) { return this.applyQuat(s.setFromAxisAngle(t, i)); } transformDirection(t) { const i = this.x, s = this.y, r = this.z, n = t.elements; return this.x = n[0] * i + n[4] * s + n[8] * r, this.y = n[1] * i + n[5] * s + n[9] * r, this.z = n[2] * i + n[6] * s + n[10] * r, this.normalize(); } project(t) { return this.applyMat4(t.viewMatrix).applyMat4(t.projectionMatrix), this; } unproject(t) { return this.applyMat4(t.projectionMatrix.getInverse()).applyMat4(t.modelMatrix), this; } }; const Q = new b(), ne = new b(), j = new b(); var k = class Ee { static { x(this, "Mat4"); } constructor(t = new Float32Array([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ])) { this.type = "Mat4", this.elements = t; } set(t, i, s, r, n, a, o, l, h, u, c, d, p, f, y, m) { const g = this.elements; return g[0] = t, g[1] = i, g[2] = s, g[3] = r, g[4] = n, g[5] = a, g[6] = o, g[7] = l, g[8] = h, g[9] = u, g[10] = c, g[11] = d, g[12] = p, g[13] = f, g[14] = y, g[15] = m, this; } identity() { return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), this; } setFromArray(t = new Float32Array([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]), i = 0) { for (let s = 0; s < this.elements.length; s++) this.elements[s] = t[s + i]; return this; } copy(t = new Ee()) { const i = t.elements; return this.elements[0] = i[0], this.elements[1] = i[1], this.elements[2] = i[2], this.elements[3] = i[3], this.elements[4] = i[4], this.elements[5] = i[5], this.elements[6] = i[6], this.elements[7] = i[7], this.elements[8] = i[8], this.elements[9] = i[9], this.elements[10] = i[10], this.elements[11] = i[11], this.elements[12] = i[12], this.elements[13] = i[13], this.elements[14] = i[14], this.elements[15] = i[15], this; } clone() { return new Ee().copy(this); } multiply(t = new Ee()) { return this.multiplyMatrices(this, t); } premultiply(t = new Ee()) { return this.multiplyMatrices(t, this); } multiplyMatrices(t = new Ee(), i = new Ee()) { const s = t.elements, r = i.elements, n = this.elements, a = s[0], o = s[4], l = s[8], h = s[12], u = s[1], c = s[5], d = s[9], p = s[13], f = s[2], y = s[6], m = s[10], g = s[14], v = s[3], T = s[7], w = s[11], C = s[15], S = r[0], B = r[4], P = r[8], R = r[12], A = r[1], z = r[5], D = r[9], L = r[13], O = r[2], E = r[6], V = r[10], $ = r[14], U = r[3], W = r[7], K = r[11], J = r[15]; return n[0] = a * S + o * A + l * O + h * U, n[4] = a * B + o * z + l * E + h * W, n[8] = a * P + o * D + l * V + h * K, n[12] = a * R + o * L + l * $ + h * J, n[1] = u * S + c * A + d * O + p * U, n[5] = u * B + c * z + d * E + p * W, n[9] = u * P + c * D + d * V + p * K, n[13] = u * R + c * L + d * $ + p * J, n[2] = f * S + y * A + m * O + g * U, n[6] = f * B + y * z + m * E + g * W, n[10] = f * P + y * D + m * V + g * K, n[14] = f * R + y * L + m * $ + g * J, n[3] = v * S + T * A + w * O + C * U, n[7] = v * B + T * z + w * E + C * W, n[11] = v * P + T * D + w * V + C * K, n[15] = v * R + T * L + w * $ + C * J, this; } premultiplyTranslate(t = new b()) { const a = t.x, o = t.y, l = t.z, h = this.elements, u = this.elements, c = h[0], d = h[4], p = h[8], f = h[12], y = h[1], m = h[5], g = h[9], v = h[13], T = h[2], w = h[6], C = h[10], S = h[14], B = h[3], P = h[7], R = h[11], A = h[15]; return u[0] = 1 * c + a * B, u[4] = 1 * d + a * P, u[8] = 1 * p + a * R, u[12] = 1 * f + a * A, u[1] = 1 * y + o * B, u[5] = 1 * m + o * P, u[9] = 1 * g + o * R, u[13] = 1 * v + o * A, u[2] = 1 * T + l * B, u[6] = 1 * w + l * P, u[10] = 1 * C + l * R, u[14] = 1 * S + l * A, u[3] = 1 * B, u[7] = 1 * P, u[11] = 1 * R, u[15] = 1 * A, this; } premultiplyScale(t = new b()) { const i = this.elements, s = this.elements, r = t.x, n = t.y, a = t.z, o = 1, l = i[0], h = i[4], u = i[8], c = i[12], d = i[1], p = i[5], f = i[9], y = i[13], m = i[2], g = i[6], v = i[10], T = i[14], w = i[3], C = i[7], S = i[11], B = i[15]; return s[0] = r * l, s[4] = r * h, s[8] = r * u, s[12] = r * c, s[1] = n * d, s[5] = n * p, s[9] = n * f, s[13] = n * y, s[2] = a * m, s[6] = a * g, s[10] = a * v, s[14] = a * T, s[3] = o * w, s[7] = o * C, s[11] = o * S, s[15] = o * B, this; } determinant() { const t = this.elements, i = t[0], s = t[4], r = t[8], n = t[12], a = t[1], o = t[5], l = t[9], h = t[13], u = t[2], c = t[6], d = t[10], p = t[14], f = t[3], y = t[7], m = t[11], g = t[15], v = l * p - h * d, T = o * p - h * c, w = o * d - l * c, C = a * p - h * u, S = a * d - l * u, B = a * c - o * u; return i * (y * v - m * T + g * w) - s * (f * v - m * C + g * S) + r * (f * T - y * C + g * B) - n * (f * w - y * S + m * B); } invert() { const t = this.elements, i = t[0], s = t[1], r = t[2], n = t[3], a = t[4], o = t[5], l = t[6], h = t[7], u = t[8], c = t[9], d = t[10], p = t[11], f = t[12], y = t[13], m = t[14], g = t[15], v = c * m * h - y * d * h + y * l * p - o * m * p - c * l * g + o * d * g, T = f * d * h - u * m * h - f * l * p + a * m * p + u * l * g - a * d * g, w = u * y * h - f * c * h + f * o * p - a * y * p - u * o * g + a * c * g, C = f * c * l - u * y * l - f * o * d + a * y * d + u * o * m - a * c * m, S = i * v + s * T + r * w + n * C; if (S === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); const B = 1 / S; return t[0] = v * B, t[1] = (y * d * n - c * m * n - y * r * p + s * m * p + c * r * g - s * d * g) * B, t[2] = (o * m * n - y * l * n + y * r * h - s * m * h - o * r * g + s * l * g) * B, t[3] = (c * l * n - o * d * n - c * r * h + s * d * h + o * r * p - s * l * p) * B, t[4] = T * B, t[5] = (u * m * n - f * d * n + f * r * p - i * m * p - u * r * g + i * d * g) * B, t[6] = (f * l * n - a * m * n - f * r * h + i * m * h + a * r * g - i * l * g) * B, t[7] = (a * d * n - u * l * n + u * r * h - i * d * h - a * r * p + i * l * p) * B, t[8] = w * B, t[9] = (f * c * n - u * y * n - f * s * p + i * y * p + u * s * g - i * c * g) * B, t[10] = (a * y * n - f * o * n + f * s * h - i * y * h - a * s * g + i * o * g) * B, t[11] = (u * o * n - a * c * n - u * s * h + i * c * h + a * s * p - i * o * p) * B, t[12] = C * B, t[13] = (u * y * r - f * c * r + f * s * d - i * y * d - u * s * m + i * c * m) * B, t[14] = (f * o * r - a * y * r - f * s * l + i * y * l + a * s * m - i * o * m) * B, t[15] = (a * c * r - u * o * r + u * s * l - i * c * l - a * s * d + i * o * d) * B, this; } getInverse() { return this.clone().invert(); } transpose() { let t; const i = this.elements; return t = i[1], i[1] = i[4], i[4] = t, t = i[2], i[2] = i[8], i[8] = t, t = i[3], i[3] = i[12], i[12] = t, t = i[6], i[6] = i[9], i[9] = t, t = i[7], i[7] = i[13], i[13] = t, t = i[11], i[11] = i[14], i[14] = t, this; } translate(t = new b()) { const i = this.elements; return i[12] = i[0] * t.x + i[4] * t.y + i[8] * t.z + i[12], i[13] = i[1] * t.x + i[5] * t.y + i[9] * t.z + i[13], i[14] = i[2] * t.x + i[6] * t.y + i[10] * t.z + i[14], i[15] = i[3] * t.x + i[7] * t.y + i[11] * t.z + i[15], this; } getTranslation(t = new b()) { return t.set(this.elements[12], this.elements[13], this.elements[14]); } scale(t = new b()) { const i = this.elements; return i[0] *= t.x, i[1] *= t.x, i[2] *= t.x, i[3] *= t.x, i[4] *= t.y, i[5] *= t.y, i[6] *= t.y, i[7] *= t.y, i[8] *= t.z, i[9] *= t.z, i[10] *= t.z, i[11] *= t.z, this; } rotateFromQuaternion(t = new re()) { const i = this.elements, s = t.elements[0], r = t.elements[1], n = t.elements[2], a = t.elements[3], o = s + s, l = r + r, h = n + n, u = s * o, c = s * l, d = s * h, p = r * l, f = r * h, y = n * h, m = a * o, g = a * l, v = a * h; return i[0] = 1 - (p + y), i[4] = c - v, i[8] = d + g, i[1] = c + v, i[5] = 1 - (u + y), i[9] = f - m, i[2] = d - g, i[6] = f + m, i[10] = 1 - (u + p), this; } getScale(t = new b()) { const i = this.elements; let s = i[0], r = i[1], n = i[2], a = i[4], o = i[5], l = i[6], h = i[8], u = i[9], c = i[10]; return t.set(Math.sqrt(s * s + r * r + n * n), Math.sqrt(a * a + o * o + l * l), Math.sqrt(h * h + u * u + c * c)), t; } getRotation(t = new re()) { const i = this.getScale(); let s = 1 / i.x, r = 1 / i.y, n = 1 / i.z; const a = this.elements, o = t.elements; let l = a[0] * s, h = a[1] * r, u = a[2] * n, c = a[4] * s, d = a[5] * r, p = a[6] * n, f = a[8] * s, y = a[9] * r, m = a[10] * n, g = l + d + m, v = 0; return g > 0 ? (v = Math.sqrt(g + 1) * 2, o[3] = .25 * v, o[0] = (p - y) / v, o[1] = (f - u) / v, o[2] = (h - c) / v) : l > d && l > m ? (v = Math.sqrt(1 + l - d - m) * 2, o[3] = (p - y) / v, o[0] = .25 * v, o[1] = (h + c) / v, o[2] = (f + u) / v) : d > m ? (v = Math.sqrt(1 + d - l - m) * 2, o[3] = (f - u) / v, o[0] = (h + c) / v, o[1] = .25 * v, o[2] = (p + y) / v) : (v = Math.sqrt(1 + m - l - d) * 2, o[3] = (h - c) / v, o[0] = (f + u) / v, o[1] = (p + y) / v, o[2] = .25 * v), t; } getMaxScaleOnAxis() { const t = this.elements, i = t[0] * t[0] + t[1] * t[1] + t[2] * t[2], s = t[4] * t[4] + t[5] * t[5] + t[6] * t[6], r = t[8] * t[8] + t[9] * t[9] + t[10] * t[10]; return Math.sqrt(Math.max(i, s, r)); } compose(t = new b(), i = new re(), s = new b(1)) { const r = this.elements, n = i.elements[0], a = i.elements[1], o = i.elements[2], l = i.elements[3], h = n + n, u = a + a, c = o + o, d = n * h, p = n * u, f = n * c, y = a * u, m = a * c, g = o * c, v = l * h, T = l * u, w = l * c, C = s.x, S = s.y, B = s.z; return r[0] = (1 - (y + g)) * C, r[1] = (p + w) * C, r[2] = (f - T) * C, r[3] = 0, r[4] = (p - w) * S, r[5] = (1 - (d + g)) * S, r[6] = (m + v) * S, r[7] = 0, r[8] = (f + T) * B, r[9] = (m - v) * B, r[10] = (1 - (d + y)) * B, r[11] = 0, r[12] = t.x, r[13] = t.y, r[14] = t.z, r[15] = 1, this; } composeFromOrigin(t = new b(), i = new re(), s = new b(1), r = new b()) { const n = this.elements, a = i.elements[0], o = i.elements[1], l = i.elements[2], h = i.elements[3], u = a + a, c = o + o, d = l + l, p = a * u, f = a * c, y = a * d, m = o * c, g = o * d, v = l * d, T = h * u, w = h * c, C = h * d, S = s.x, B = s.y, P = s.z, R = r.x, A = r.y, z = r.z, D = (1 - (m + v)) * S, L = (f + C) * S, O = (y - w) * S, E = (f - C) * B, V = (1 - (p + v)) * B, $ = (g + T) * B, U = (y + w) * P, W = (g - T) * P, K = (1 - (p + m)) * P; return n[0] = D, n[1] = L, n[2] = O, n[3] = 0, n[4] = E, n[5] = V, n[6] = $, n[7] = 0, n[8] = U, n[9] = W, n[10] = K, n[11] = 0, n[12] = t.x + R - (D * R + E * A + U * z), n[13] = t.y + A - (L * R + V * A + W * z), n[14] = t.z + z - (O * R + $ * A + K * z), n[15] = 1, this; } lookAt(t = new b(), i = new b(), s = new b(0, 1, 0)) { const r = this.elements; return j.copy(t).sub(i), j.lengthSq() === 0 && (j.z = 1), j.normalize(), Q.crossVectors(s, j), Q.lengthSq() === 0 && (Math.abs(s.z) === 1 ? j.x += 1e-4 : j.z += 1e-4, j.normalize(), Q.crossVectors(s, j)), Q.normalize(), ne.crossVectors(j, Q), r[0] = Q.x, r[1] = Q.y, r[2] = Q.z, r[3] = 0, r[4] = ne.x, r[5] = ne.y, r[6] = ne.z, r[7] = 0, r[8] = j.x, r[9] = j.y, r[10] = j.z, r[11] = 0, r[12] = t.x, r[13] = t.y, r[14] = t.z, r[15] = 1, this; } makeView(t = new b(), i = new b(), s = new b(0, 1, 0)) { const r = this.elements; return j.copy(t).sub(i).normalize(), Q.crossVectors(s, j).normalize(), ne.crossVectors(j, Q).normalize(), r[0] = Q.x, r[1] = ne.x, r[2] = j.x, r[3] = 0, r[4] = Q.y, r[5] = ne.y, r[6] = j.y, r[7] = 0, r[8] = Q.z, r[9] = ne.z, r[10] = j.z, r[11] = 0, r[12] = -(Q.x * t.x + Q.y * t.y + Q.z * t.z), r[13] = -(ne.x * t.x + ne.y * t.y + ne.z * t.z), r[14] = -(j.x * t.x + j.y * t.y + j.z * t.z), r[15] = 1, this; } makeOrthographic({ left: t = -1, right: i = 1, bottom: s = -1, top: r = 1, near: n = .1, far: a = 50 }) { const o = this.elements; return o[0] = 2 / (i - t), o[1] = 0, o[2] = 0, o[3] = 0, o[4] = 0, o[5] = 2 / (r - s), o[6] = 0, o[7] = 0, o[8] = 0, o[9] = 0, o[10] = 1 / (n - a), o[11] = 0, o[12] = (i + t) / (t - i), o[13] = (r + s) / (s - r), o[14] = n / (n - a), o[15] = 1, this; } makePerspective({ fov: t = 90, aspect: i = 1, near: s = .1, far: r = 150 }) { const n = s * Math.tan(Math.PI / 180 * .5 * t), a = 2 * n, o = i * a, l = -.5 * o, h = l + o, u = n - a, c = 2 * s / (h - l), d = 2 * s / (n - u), p = (h + l) / (h - l), f = (n + u) / (n - u), y = -r / (r - s), m = -r * s / (r - s); return this.set(c, 0, 0, 0, 0, d, 0, 0, p, f, y, -1, 0, 0, m, 0), this; } }; let Ks = 0; const Xs = new k(); var ae = class { static { x(this, "Object3D"); } #e; #t; #i; constructor() { this.#e = null, this.children = [], this.matricesNeedUpdate = !1, this.up = new b(0, 1, 0), this.actualPosition = new b(), Object.defineProperty(this, "object3DIndex", { value: Ks++ }), this.setMatrices(), this.setTransforms(), this.#t = !0, this.#i = !0; } get visible() { return this.#t && this.#i; } set visible(e) { this.#t = e, this.children.forEach((t) => t.parentVisibility = this.parentVisibility && e); } get parentVisibility() { return this.#i; } set parentVisibility(e) { this.#i = e, this.children.forEach((t) => t.parentVisibility = this.visible && e); } get parent() { return this.#e; } set parent(e) { this.#e && e && this.#e.object3DIndex === e.object3DIndex || (this.#e && (this.#e.children = this.#e.children.filter((t) => t.object3DIndex !== this.object3DIndex)), e && this.shouldUpdateWorldMatrix(), this.#e = e, this.#e?.children.push(this), this.parentVisibility = this.#e ? this.#e.visible : !0); } setTransforms() { this.transforms = { origin: { model: new b() }, quaternion: new re(), rotation: new b(), position: { world: new b() }, scale: new b(1) }, this.rotation.onChange(() => this.applyRotation()), this.position.onChange(() => this.applyPosition()), this.scale.onChange(() => this.applyScale()), this.transformOrigin.onChange(() => this.applyTransformOrigin()); } get rotation() { return this.transforms.rotation; } set rotation(e) { this.transforms.rotation = e, this.applyRotation(); } get quaternion() { return this.transforms.quaternion; } set quaternion(e) { this.transforms.quaternion = e; } get position() { return this.transforms.position.world; } set position(e) { this.transforms.position.world = e; } get scale() { return this.transforms.scale; } set scale(e) { this.transforms.scale = e, this.applyScale(); } get transformOrigin() { return this.transforms.origin.model; } set transformOrigin(e) { this.transforms.origin.model = e; } applyRotation() { this.quaternion.setFromVec3(this.rotation), this.shouldUpdateModelMatrix(); } applyPosition() { this.shouldUpdateModelMatrix(); } applyScale() { this.shouldUpdateModelMatrix(); } applyTransformOrigin() { this.shouldUpdateModelMatrix(); } setMatrices() { this.matrices = { model: { matrix: new k(), shouldUpdate: !0, onUpdate: x(() => this.updateModelMatrix(), "onUpdate") }, world: { matrix: new k(), shouldUpdate: !0, onUpdate: x(() => this.updateWorldMatrix(), "onUpdate") } }; } get modelMatrix() { return this.matrices.model.matrix; } set modelMatrix(e) { this.matrices.model.matrix = e, this.shouldUpdateModelMatrix(); } shouldUpdateModelMatrix() { this.matrices.model.shouldUpdate = !0, this.shouldUpdateWorldMatrix(); } get worldMatrix() { return this.matrices.world.matrix; } set worldMatrix(e) { this.matrices.world.matrix = e, this.shouldUpdateWorldMatrix(); } shouldUpdateWorldMatrix() { this.matrices.world.shouldUpdate = !0; } lookAt(e = new b()) { this.updateModelMatrix(), this.updateWorldMatrix(!0, !1), this.actualPosition.x === 0 && this.actualPosition.y !== 0 && this.actualPosition.z === 0 ? this.up.set(0, 0, 1) : this.up.set(0, 1, 0), this.applyLookAt(e, this.actualPosition); } applyLookAt(e, t) { const i = Xs.lookAt(e, t, this.up); this.quaternion.setFromRotationMatrix(i), this.shouldUpdateModelMatrix(); } updateModelMatrix() { this.modelMatrix = this.modelMatrix.composeFromOrigin(this.position, this.quaternion, this.scale, this.transformOrigin), this.shouldUpdateWorldMatrix(); } updateWorldMatrix(e = !1, t = !0) { if (this.parent ? (e && this.parent.updateWorldMatrix(!0, !1), this.worldMatrix.multiplyMatrices(this.parent.worldMatrix, this.modelMatrix)) : this.worldMatrix.copy(this.modelMatrix), this.worldMatrix.getTranslation(this.actualPosition), t) for (let i = 0, s = this.children.length; i < s; i++) this.children[i].shouldUpdateWorldMatrix(); } shouldUpdateMatrices() { this.matricesNeedUpdate = !!Object.values(this.matrices).find((e) => e.shouldUpdate); } updateMatrixStack() { if (this.shouldUpdateMatrices(), this.matricesNeedUpdate) for (const e in this.matrices) this.matrices[e].shouldUpdate && (this.matrices[e].onUpdate(), this.matrices[e].shouldUpdate = !1); for (let e = 0, t = this.children.length; e < t; e++) this.children[e].updateMatrixStack(); } destroy() { for (let e = 0, t = this.children.length; e < t; e++) this.children[e] && (this.children[e].parent = null); this.parent = null; } }; const At = x((e, t = "GPURenderer", i) => { ee(i ? `Unable to create ${i} because the ${t} is not defined: ${e}` : `The ${t} is not defined: ${e}`); }, "formatRendererError"), G = x((e, t) => (e = e && e.renderer || e, e && (e.type === "GPURenderer" || e.type === "GPUCameraRenderer" || e.type === "GPUCurtainsRenderer") || At(e, "GPURenderer", t), e), "isRenderer"), xe = x((e, t) => (e = e && e.renderer || e, e && (e.type === "GPUCameraRenderer" || e.type === "GPUCurtainsRenderer") || At(e, "GPUCameraRenderer", t), e), "isCameraRenderer"), Ie = x((e, t) => (e = e && e.renderer || e, e && e.type === "GPUCurtainsRenderer" || At(e, "GPUCurtainsRenderer", t), e), "isCurtainsRenderer"), Ys = x((e) => "geometry" in e && "material" in e && e instanceof ae ? e : !1, "isProjectedMesh"), Lt = typeof GPUShaderStage < "u" ? GPUShaderStage : { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 }, ce = typeof GPUBufferUsage < "u" ? GPUBufferUsage : { MAP_READ: 1, MAP_WRITE: 2, COPY_SRC: 4, COPY_DST: 8, INDEX: 16, VERTEX: 32, UNIFORM: 64, STORAGE: 128, INDIRECT: 256, QUERY_RESOLVE: 512 }, Ve = typeof GPUTextureUsage < "u" ? GPUTextureUsage : { COPY_SRC: 1, COPY_DST: 2, TEXTURE_BINDING: 4, STORAGE_BINDING: 8, RENDER_ATTACHMENT: 16, TRANSIENT_ATTACHMENT: 32 }, Zs = new Map([ ["vertex", Lt.VERTEX], ["fragment", Lt.FRAGMENT], ["compute", Lt.COMPUTE] ]), Js = x((e = []) => e.reduce((t, i) => t | Zs.get(i), 0), "getBindingVisibility"), Qs = { i32: { numElements: 1, align: 4, size: 4, type: "i32", View: Int32Array }, u32: { numElements: 1, align: 4, size: 4, type: "u32", View: Uint32Array }, f32: { numElements: 1, align: 4, size: 4, type: "f32", View: Float32Array }, f16: { numElements: 1, align: 2, size: 2, type: "u16", View: Uint16Array }, vec2f: { numElements: 2, align: 8, size: 8, type: "f32", View: Float32Array }, vec2i: { numElements: 2, align: 8, size: 8, type: "i32", View: Int32Array }, vec2u: { numElements: 2, align: 8, size: 8, type: "u32", View: Uint32Array }, vec2h: { numElements: 2, align: 4, size: 4, type: "u16", View: Uint16Array }, vec3i: { numElements: 3, align: 16, size: 12, type: "i32", View: Int32Array }, vec3u: { numElements: 3, align: 16, size: 12, type: "u32", View: Uint32Array }, vec3f: { numElements: 3, align: 16, size: 12, type: "f32", View: Float32Array }, vec3h: { numElements: 3, align: 8, size: 6, type: "u16", View: Uint16Array }, vec4i: { numElements: 4, align: 16, size: 16, type: "i32", View: Int32Array }, vec4u: { numElements: 4, align: 16, size: 16, type: "u32", View: Uint32Array }, vec4f: { numElements: 4, align: 16, size: 16, type: "f32", View: Float32Array }, vec4h: { numElements: 4, align: 8, size: 8, type: "u16", View: Uint16Array }, mat2x2f: { numElements: 4, align: 8, size: 16, type: "f32", View: Float32Array }, mat2x2h: { numElements: 4, align: 4, size: 8, type: "u16", View: Uint16Array }, mat3x2f: { numElements: 6, align: 8, size: 24, type: "f32", View: Float32Array }, mat3x2h: { numElements: 6, align: 4, size: 12, type: "u16", View: Uint16Array }, mat4x2f: { numElements: 8, align: 8, size: 32, type: "f32", View: Float32Array }, mat4x2h: { numElements: 8, align: 4, size: 16, type: "u16", View: Uint16Array }, mat2x3f: { numElements: 8, align: 16, size: 32, pad: [3, 1], type: "f32", View: Float32Array }, mat2x3h: { numElements: 8, align: 8, size: 16, pad: [3, 1], type: "u16", View: Uint16Array }, mat3x3f: { numElements: 12, align: 16, size: 48, pad: [3, 1], type: "f32", View: Float32Array }, mat3x3h: { numElements: 12, align: 8, size: 24, pad: [3, 1], type: "u16", View: Uint16Array }, mat4x3f: { numElements: 16, align: 16, size: 64, pad: [3, 1], type: "f32", View: Float32Array }, mat4x3h: { numElements: 16, align: 8, size: 32, pad: [3, 1], type: "u16", View: Uint16Array }, mat2x4f: { numElements: 8, align: 16, size: 32, type: "f32", View: Float32Array }, mat2x4h: { numElements: 8, align: 8, size: 16, type: "u16", View: Uint16Array }, mat3x4f: { numElements: 12, align: 16, size: 48, pad: [3, 1], type: "f32", View: Float32Array }, mat3x4h: { numElements: 12, align: 8, size: 24, pad: [3, 1], type: "u16", View: Uint16Array }, mat4x4f: { numElements: 16, align: 16, size: 64, type: "f32", View: Float32Array }, mat4x4h: { numElements: 16, align: 8, size: 32, type: "u16", View: Uint16Array } }, vi = x((e) => Qs[e], "getBufferLayout"), tt = x((e) => e.bindingType === "storage" ? `var<${e.bindingType}, ${e.options.access}>` : "var<uniform>", "getBindingWGSLVarType"), er = x((e) => e.bindingType === "externalTexture" ? `var ${e.name}: texture_external;` : e.bindingType === "storage" ? `var ${e.name}: texture_storage_${e.options.viewDimension.replace("-", "_")}<${e.options.format}, ${e.options.access}>;` : e.bindingType === "depth" ? `var ${e.name}: texture_depth${e.options.multisampled ? "_multisampled" : ""}_${e.options.viewDimension.replace("-", "_")};` : `var ${e.name}: texture${e.options.multisampled ? "_multisampled" : ""}_${e.options.viewDimension.replace("-", "_")}<f32>;`, "getTextureBindingWGSLVarType"), bi = x((e) => e.bindingType === "storage" && e.options.access === "read_write" ? "storage" : e.bindingType === "storage" ? "read-only-storage" : "uniform", "getBindGroupLayoutBindingType"), tr = x((e) => { switch (e.bindingType) { case "externalTexture": return { externalTexture: {} }; case "storage": return { storageTexture: { format: e.options.format, viewDimension: e.options.viewDimension } }; case "texture": return { texture: { multisampled: e.options.multisampled, viewDimension: e.options.viewDimension, sampleType: e.options.multisampled || e.options.format.indexOf("depth") !== -1 ? "unfilterable-float" : "float" } }; case "depth": return { texture: { multisampled: e.options.multisampled, viewDimension: e.options.viewDimension, sampleType: "depth" } }; default: return null; } }, "getBindGroupLayoutTextureBindingType"), ir = x((e) => { switch (e.bindingType) { case "externalTexture": return `externalTexture,${e.visibility},`; case "storage": return `storageTexture,${e.options.format},${e.options.viewDimension},${e.visibility},`; case "texture": return `texture,${e.options.multisampled},${e.options.viewDimension},${e.options.multisampled ? "unfilterable-float" : "float"},${e.visibility},`; case "depth": return `depthTexture,${e.options.format},${e.options.viewDimension},${e.visibility},`; default: return `${e.visibility},`; } }, "getBindGroupLayoutTextureBindingCacheKey"); var it = class { static { x(this, "Binding"); } constructor({ label: e = "Uniform", name: t = "uniform", bindingType: i = "uniform", visibility: s = [ "vertex", "fragment", "compute" ] }) { this.label = e, this.name = Ne(t), this.bindingType = i, this.visibility = Js(s), this.options = { label: e, name: t, bindingType: i, visibility: s }, this.shouldResetBindGroup = !1, this.shouldResetBindGroupLayout = !1, this.cacheKey = `${i},${this.visibility},`; } }, I = class ie { static { x(this, "Vec2"); } constructor(t = 0, i = t) { this.type = "Vec2", this._x = t, this._y = i; } get x() { return this._x; } set x(t) { const i = t !== this._x; this._x = t, i && this._onChangeCallback && this._onChangeCallback(); } get y() { return this._y; } set y(t) { const i = t !== this._y; this._y = t, i && this._onChangeCallback && this._onChangeCallback(); } onChange(t) { return t && (this._onChangeCallback = t), this; } set(t = 0, i = t) { return this.x = t, this.y = i, this; } add(t = new ie()) { return this.x += t.x, this.y += t.y, this; } addScalar(t = 0) { return this.x += t, this.y += t, this; } sub(t = new ie()) { return this.x -= t.x, this.y -= t.y, this; } subScalar(t = 0) { return this.x -= t, this.y -= t, this; } multiply(t = new ie(1)) { return this.x *= t.x, this.y *= t.y, this; } multiplyScalar(t = 1) { return this.x *= t, this.y *= t, this; } divide(t = new ie(1)) { return this.x /= t.x, this.y /= t.y, this; } divideScalar(t = 1) { return this.x /= t, this.y /= t, this; } copy(t = new ie()) { return this.x = t.x, this.y = t.y, this; } clone() { return new ie(this.x, this.y); } max(t = new ie()) { return this.x = Math.max(this.x, t.x), this.y = Math.max(this.y, t.y), this; } min(t = new ie()) { return this.x = Math.min(this.x, t.x), this.y = Math.min(this.y, t.y), this; } clamp(t = new ie(), i = new ie()) { return this.x = Math.max(t.x, Math.min(i.x, this.x)), this.y = Math.max(t.y, Math.min(i.y, this.y)), this; } equals(t = new ie()) { return this.x === t.x && this.y === t.y; } lengthSq() { return this.x * this.x + this.y * this.y; } length() { return Math.sqrt(this.lengthSq()); } normalize() { let t = this.x * this.x + this.y * this.y; return t > 0 && (t = 1 / Math.sqrt(t)), this.x *= t, this.y *= t, this; } dot(t = new ie()) { return this.x * t.x + this.y * t.y; } lerp(t = new ie(), i = 1) { return this.x += (t.x - this.x) * i, this.y += (t.y - this.y) * i, this; } }; var de = class yi { static { x(this, "BufferElement"); } constructor({ name: t, key: i, type: s = "f32" }) { this.name = t, this.key = i, this.type = s, this.baseType = yi.getBaseType(this.type), this.bufferLayout = vi(this.baseType), this.alignment = { start: { row: 0, byte: 0 }, end: { row: 0, byte: 0 } }, this.setValue = null; } static getType(t) { return t.replace("array", "").replace("<", "").replace(">", ""); } static getBaseType(t) { return yi.getType(t.replace("atomic", "").replace("array", "").replaceAll("<", "").replaceAll(">", "")); } get rowCount() { return this.alignment.end.row - this.alignment.start.row + 1; } get byteCount() { return Math.abs(this.endOffset - this.startOffset) + 1; } get paddedByteCount() { return (this.alignment.end.row + 1) * 16; } get startOffset() { return this.getByteCountAtPosition(this.alignment.start); } get startOffsetToIndex() { return this.startOffset / 4; } get endOffset() { return this.getByteCountAtPosition(this.alignment.end); } get endOffsetToIndex() { return Math.floor(this.endOffset / 4); } getPositionAtOffset(t = 0) { return { row: Math.floor(t / 16), byte: t % 16 }; } getByteCountAtPosition(t = { row: 0, byte: 0 }) { return t.row * 16 + t.byte; } applyOverflowToPosition(t = { row: 0, byte: 0 }) { if (t.byte > 15) { const i = t.byte % 16; t.row += Math.floor(t.byte / 16), t.byte = i; } return t; } getByteCountBetweenPositions(t = { row: 0, byte: 0 }, i = { row: 0, byte: 0 }) { return Math.abs(this.getByteCountAtPosition(i) - this.getByteCountAtPosition(t)); } getElementAlignment(t = { row: 0, byte: 0 }) { const i = { start: t, end: t }, { size: s, align: r } = this.bufferLayout; return t.byte % r !== 0 && (t.byte += t.byte % r), (s <= 16 && t.byte + s > 16 || s > 16 && (t.byte > 16 || t.byte > 0)) && (t.row += 1, t.byte = 0), i.end = { row: t.row + Math.ceil(s / 16) - 1, byte: t.byte + (s % 16 === 0 ? 15 : s % 16 - 1) }, i.end = this.applyOverflowToPosition(i.end), i; } setAlignmentFromPosition(t = { row: 0, byte: 0 }) { this.alignment = this.getElementAlignment(t); } setAlignment(t = 0, i = 0) { this.setAlignmentFromPosition(this.getPositionAtOffset(t)); } setView(t, i) { this.view = new this.bufferLayout.View(t, this.startOffset, this.byteCount / this.bufferLayout.View.BYTES_PER_ELEMENT); } setValueFromNumber(t) { this.view[0] = t; } setValueFromVec2(t) { this.view[0] = t.x ?? t[0] ?? 0, this.view[1] = t.y ?? t[1] ?? 0; } setValueFromVec3(t) { this.view[0] = t.x ?? t[0] ?? 0, this.view[1] = t.y ?? t[1] ?? 0, this.view[2] = t.z ?? t[2] ?? 0; } setValueFromMat4OrQuat(t) { this.view.set(t.elements); } setValueFromMat3(t) { this.setValueFromArrayWithPad(t.elements); } setValueFromArray(t) { this.view.set(t); } setValueFromArrayWithPad(t) { for (let i = 0, s = 0; i < this.view.length; i += this.bufferLayout.pad[0] + this.bufferLayout.pad[1], s++) for (let r = 0; r < this.bufferLayout.pad[0]; r++) this.view[i + r] = t[i + r - s]; } update(t) { this.setValue || (this.setValue = ((i) => { if (typeof i == "number") return this.setValueFromNumber; if (this.type === "vec2f") return this.setValueFromVec2; if (this.type === "vec3f") return this.setValueFromVec3; if (this.type === "mat3x3f") return i.elements ? this.setValueFromMat3 : this.setValueFromArrayWithPad; if (i.elements) return this.setValueFromMat4OrQuat; if (ArrayBuffer.isView(i) || Array.isArray(i)) return this.bufferLayout.pad ? this.setValueFromArrayWithPad : this.setValueFromArray; F(`${this.constructor.name}: value passed to ${this.name} cannot be used: ${i}`); })(t)), this.setValue(t); } extractDataFromBufferResult(t) { return t.slice(this.startOffsetToIndex, this.endOffsetToIndex); } }, wi = class extends de { static { x(this, "BufferArrayElement"); } constructor({ name: e, key: t, type: i = "f32", arrayLength: s = 1 }) { super({ name: e, key: t, type: i }), this.arrayLength = s, this.numElements = Math.ceil(this.arrayLength / this.bufferLayout.numElements); } get arrayStrideToIndex() { return this.arrayStride / 4; } setAlignment(e = 0, t = 0) { t !== 0 && (e = Math.ceil(e / t) * t), super.setAlignment(e); const i = t !== 0 ? Math.ceil(this.endOffset / t) * t - 1 : this.endOffset, s = this.getElementAlignment(this.getPositionAtOffset(i + 1)); this.arrayStride = this.getByteCountBetweenPositions(this.alignment.end, s.end), this.alignment.end = this.getPositionAtOffset(this.endOffset + this.arrayStride * (this.numElements - 1)), t !== 0 && (this.alignment.end.byte = Math.max(this.alignment.end.byte, t - 1)); } setValueFromArray(e) { let t = 0; const i = this.byteCount / this.bufferLayout.View.BYTES_PER_ELEMENT, s = Math.ceil(i / this.numElements); for (let r = 0; r < this.numElements; r++) for (let n = 0; n < this.bufferLayout.numElements; n++) this.view[n + r * s] = e[t], t++; } }, Dt = class extends wi { static { x(this, "BufferInterleavedArrayElement"); } constructor({ name: e, key: t, type: i = "f32", arrayLength: s = 1 }) { super({ name: e, key: t, type: i, arrayLength: s }), this.arrayStride = 1, this.arrayLength = s, this.numElements = Math.ceil(this.arrayLength / this.bufferLayout.numElements); } get byteCount() { return this.bufferLayout.size * this.numElements; } setAlignment(e = 0, t = 0) { this.alignment = this.getElementAlignment(this.getPositionAtOffset(e)), this.arrayStride = t, this.alignment.end = this.getPositionAtOffset(this.endOffset + t * (this.numElements - 1)); } setView(e, t) { this.view = new this.bufferLayout.View(this.bufferLayout.numElements * this.numElements), this.viewSetFunction = ((i) => { switch (this.bufferLayout.View) { case Int32Array: return i.setInt32.bind(i); case Uint16Array: return i.setUint16.bind(i); case Uint32Array: return i.setUint32.bind(i); case Float32Array: default: return i.setFloat32.bind(i); } })(t); } update(e) { super.update(e); for (let t = 0; t < this.numElements; t++) { const i = this.view.subarray(t * this.bufferLayout.numElements, t * this.bufferLayout.numElements + this.bufferLayout.numElements), s = this.startOffset + t * this.arrayStride; i.forEach((r, n) => { this.viewSetFunction(s + n * this.bufferLayout.View.BYTES_PER_ELEMENT, r, !0); }); } } extractDataFromBufferResult(e) { const t = new Float32Array(this.arrayLength); for (let i = 0; i < this.numElements; i++) { const s = this.startOffsetToIndex + i * this.arrayStrideToIndex; for (let r = 0; r < this.bufferLayout.numElements; r++) t[i * this.bufferLayout.numElements + r] = e[s + r]; } return t; } }; const sr = new Map([ ["copySrc", ce.COPY_SRC], ["copyDst", ce.COPY_DST], ["index", ce.INDEX], ["indirect", ce.INDIRECT], ["mapRead", ce.MAP_READ], ["mapWrite", ce.MAP_WRITE], ["queryResolve", ce.QUERY_RESOLVE], ["storage", ce.STORAGE], ["uniform", ce.UNIFORM], ["vertex", ce.VERTEX] ]), Ti = x((e = []) => e.reduce((t, i) => t | sr.get(i), 0), "getBufferUsages"); var Pe = class { static { x(this, "Buffer"); } constructor({ label: e = "Buffer", size: t = 0, usage: i = ["copySrc", "copyDst"], mappedAtCreation: s = !1 } = {}) { this.type = "Buffer", this.reset(), this.uuid = _(), this.consumers = /* @__PURE__ */ new Set(), this.options = { label: e, size: t, usage: Ti(i), mappedAtCreation: s }; } reset() { this.GPUBuffer = null; } set size(e) { this.options.size = e; } createBuffer(e, t = {}) { const { usage: i, ...s } = t; this.options = { ...this.options, ...s, ...i !== void 0 && { usage: Ti(i) } }, this.setBuffer(e.createBuffer(this)); } setBuffer(e) { this.GPUBuffer = e; } copy(e, t = !1) { t && this.destroy(), this.options = e.options, this.GPUBuffer = e.GPUBuffer, this.consumers = new Set([...this.consumers, ...e.consumers]); } async mapBufferAsync() { if (!this.GPUBuffer || this.GPUBuffer.mapState !== "unmapped") return new Float32Array(0); await this.GPUBuffer.mapAsync(GPUMapMode.READ); const e = new Float32Array(this.GPUBuffer.getMappedRange().slice(0)); return this.GPUBuffer.unmap(), e; } destroy() { this.GPUBuffer?.destroy(), this.reset(), this.consumers.clear(); } }, Z = class Pt extends it { static { x(this, "BufferBinding"); } #e; constructor({ label: t = "Uniform", name: i = "uniform", bindingType: s, visibility: r, useStruct: n = !0, access: a = "read", usage: o = [], struct: l = {}, childrenBindings: h = [], buffer: u = null, parent: c = null, minOffset: d = 256, offset: p = 0 }) { s = s ?? "uniform", super({ label: t, name: i, bindingType: s, visibility: r }), this.options = { ...this.options, useStruct: n, access: a, usage: o, struct: l, childrenBindings: h, buffer: u, parent: c, minOffset: d, offset: p }, this.cacheKey += `${n},${a},`, this.arrayBufferSize = 0, this.shouldUpdate = !1, this.useStruct = n, this.bufferElements = [], this.inputs = {}, this.buffer = this.options.buffer ?? new Pe(), Object.keys(l).length && (this.setBindings(l), this.setInputsAlignment()), this.setChildrenBindings(h), (Object.keys(l).length || this.childrenBindings.length) && (this.setBufferAttributes(), this.setWGSLFragment()), this.parent = c; } static cloneStruct(t) { return Object.keys(t).reduce((i, s) => { const r = t[s]; let n; return Array.isArray(r.value) || ArrayBuffer.isView(r.value) ? n = new r.value.constructor(r.value.length) : typeof r.value == "number" ? n = 0 : n = new r.value.constructor(), { ...i, [s]: { type: r.type, value: n } }; }, {}); } get parent() { return this.#e; } set parent(t) { if (t) { this.parentView = new DataView(t.arrayBuffer, this.offset, this.getMinOffsetSize(this.arrayBufferSize)); const i = x((s) => [...x((n) => n.bufferElements, "getBufferElements")(s), s.childrenBindings.map((n) => i(n)).flat()].flat(), "getAllBufferElements"); this.parentViewSetBufferEls = i(this).map((s) => { switch (s.bufferLayout.View) { case Int32Array: return { bufferElement: s, viewSetFunction: this.parentView.setInt32.bind(this.parentView) }; case Uint16Array: return { bufferElement: s, viewSetFunction: this.parentView.setUint16.bind(this.parentView) }; case Uint32Array: return { bufferElement: s, viewSetFunction: this.parentView.setUint32.bind(this.parentView) }; case Float32Array: default: return { bufferElement: s, viewSetFunction: this.parentView.setFloat32.bind(this.parentView) }; } }), !this.parent && this.buffer.GPUBuffer && !this.options.buffer && this.buffer.destroy(); } else this.parentView = null, this.parentViewSetBufferEls = null; this.#e = t; } getMinOffsetSize(t) { return Math.ceil(t / this.options.minOffset) * this.options.minOffset; } get offset() { return this.getMinOffsetSize(this.options.offset * this.getMinOffsetSize(this.arrayBufferSize)); } get resourceLayout() { return { buffer: { type: bi(this) }, ...this.parent && { offset: this.offset, size: this.arrayBufferSize } }; } get resourceLayoutCacheKey() { return `buffer,${bi(this)},${this.visibility},`; } get resource() { return { buffer: this.parent ? this.parent.buffer.GPUBuffer : this.buffer.GPUBuffer, ...this.parent && { offset: this.offset, size: this.arrayBufferSize } }; } clone(t = {}) { let { struct: i, childrenBindings: s, parent: r, ...n } = t; const { label: a, name: o, bindingType: l, visibility: h, useStruct: u, access: c, usage: d } = this.options; n = { label: a, name: o, bindingType: l, visibility: h, useStruct: u, access: c, usage: d, ...n }; const p = new this.constructor(n); return i = i || Pt.cloneStruct(this.options.struct), p.options.struct = i, p.setBindings(i), p.arrayBufferSize = this.arrayBufferSize, p.arrayBuffer = new ArrayBuffer(p.arrayBufferSize), p.arrayView = new DataView(p.arrayBuff