// deno-fmt-ignore-file
// deno-lint-ignore-file
// This code was bundled using `deno bundle` and it's not recommended to edit it manually

var vl = "173", Dd = {
    LEFT: 0,
    MIDDLE: 1,
    RIGHT: 2,
    ROTATE: 0,
    DOLLY: 1,
    PAN: 2
}, Ld = {
    ROTATE: 0,
    PAN: 1,
    DOLLY_PAN: 2,
    DOLLY_ROTATE: 3
}, Ud = 0, Wd = 1, Hd = 2, qd = 3, Gd = 0, Xd = 1, Jd = 2, Zd = 3, dr = 0, Al = 1, Yd = 2, Ul = 0, ea = 1, $d = 2, Qd = 3, jd = 4, Kd = 5, ia = 100, tp = 101, ep = 102, ip = 103, sp = 104, np = 200, rp = 201, op = 202, ap = 203, sa = 204, na = 205, hp = 206, lp = 207, cp = 208, up = 209, dp = 210, pp = 211, fp = 212, mp = 213, yp = 214, gp = 0, xp = 1, bp = 2, ra = 3, wp = 4, Mp = 5, _p = 6, vp = 7, Do = 0, Ap = 1, Sp = 2, Tp = 0, Ip = 1, Cp = 2, zp = 3, Fp = 4, Bp = 5, Ep = 6, Rp = 7, oa = "attached", Wl = "detached", Lo = 300, Uo = 301, Hl = 302, ql = 303, Gl = 304, Xl = 306, pr = 1e3, Ht = 1001, fr = 1002, Ut = 1003, Jl = 1004, kp = 1004, Zl = 1005, Pp = 1005, Et = 1006, Yl = 1007, Op = 1007, vn = 1008, Np = 1008, Sl = 1009, $l = 1010, Ql = 1011, jl = 1012, Kl = 1013, Wo = 1014, pi = 1015, tc = 1016, ec = 1017, ic = 1018, sc = 1020, nc = 35902, rc = 1021, oc = 1022, Li = 1023, ac = 1024, hc = 1025, Cn = 1026, aa = 1027, Tl = 1028, Il = 1029, lc = 1030, cc = 1031, Vp = 1032, uc = 1033, dc = 33776, pc = 33777, fc = 33778, mc = 33779, yc = 35840, gc = 35841, xc = 35842, bc = 35843, wc = 36196, Mc = 37492, _c = 37496, vc = 37808, Ac = 37809, Sc = 37810, Tc = 37811, Ic = 37812, Cc = 37813, zc = 37814, Fc = 37815, Bc = 37816, Ec = 37817, Rc = 37818, kc = 37819, Pc = 37820, Oc = 37821, Nc = 36492, Vc = 36494, Dc = 36495, Lc = 36283, Uc = 36284, Wc = 36285, Hc = 36286, qc = 2200, Gc = 2201, Xc = 2202, Gs = 2300, mr = 2301, zn = 2302, hi = 2400, li = 2401, Xs = 2402, Ho = 2500, Cl = 2501, Dp = 0, Lp = 1, Up = 2, Jc = 3200, Wp = 3201, Hp = 3202, qp = 3203, _i = 0, Gp = 1, zl = "", Bt = "srgb", ha = "srgb-linear", la = "linear", Fn = "srgb", Xp = 0, qe = 7680, Jp = 7681, Zp = 7682, Yp = 7683, $p = 34055, Qp = 34056, jp = 5386, Kp = 512, tf = 513, ef = 514, sf = 515, nf = 516, rf = 517, of = 518, ca = 519, af = 512, hf = 513, lf = 514, cf = 515, uf = 516, df = 517, pf = 518, ff = 519, Js = 35044, mf = 35048, yf = 35040, gf = 35045, xf = 35049, bf = 35041, wf = 35046, Mf = 35050, _f = 35042, vf = "100", Af = "300 es", oe = 2e3, Zs = 2001, Sf = {
    COMPUTE: "compute",
    RENDER: "render"
}, qt = class {
    addEventListener(t, e) {
        this._listeners === void 0 && (this._listeners = {});
        let i = this._listeners;
        i[t] === void 0 && (i[t] = []), i[t].indexOf(e) === -1 && i[t].push(e);
    }
    hasEventListener(t, e) {
        let i = this._listeners;
        return i === void 0 ? !1 : i[t] !== void 0 && i[t].indexOf(e) !== -1;
    }
    removeEventListener(t, e) {
        let i = this._listeners;
        if (i === void 0) return;
        let s = i[t];
        if (s !== void 0) {
            let n = s.indexOf(e);
            n !== -1 && s.splice(n, 1);
        }
    }
    dispatchEvent(t) {
        let e = this._listeners;
        if (e === void 0) return;
        let i = e[t.type];
        if (i !== void 0) {
            t.target = this;
            let s = i.slice(0);
            for(let n = 0, r = s.length; n < r; n++)s[n].call(this, t);
            t.target = null;
        }
    }
}, ut = [
    "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"
], ua = 1234567, De = Math.PI / 180, Ui = 180 / Math.PI;
function It() {
    let h = Math.random() * 4294967295 | 0, t = Math.random() * 4294967295 | 0, e = Math.random() * 4294967295 | 0, i = Math.random() * 4294967295 | 0;
    return (ut[h & 255] + ut[h >> 8 & 255] + ut[h >> 16 & 255] + ut[h >> 24 & 255] + "-" + ut[t & 255] + ut[t >> 8 & 255] + "-" + ut[t >> 16 & 15 | 64] + ut[t >> 24 & 255] + "-" + ut[e & 63 | 128] + ut[e >> 8 & 255] + "-" + ut[e >> 16 & 255] + ut[e >> 24 & 255] + ut[i & 255] + ut[i >> 8 & 255] + ut[i >> 16 & 255] + ut[i >> 24 & 255]).toLowerCase();
}
function N(h, t, e) {
    return Math.max(t, Math.min(e, h));
}
function qo(h, t) {
    return (h % t + t) % t;
}
function Zc(h, t, e, i, s) {
    return i + (h - t) * (s - i) / (e - t);
}
function Yc(h, t, e) {
    return h !== t ? (e - h) / (t - h) : 0;
}
function Ni(h, t, e) {
    return (1 - e) * h + e * t;
}
function $c(h, t, e, i) {
    return Ni(h, t, 1 - Math.exp(-e * i));
}
function Qc(h, t = 1) {
    return t - Math.abs(qo(h, t * 2) - t);
}
function jc(h, t, e) {
    return h <= t ? 0 : h >= e ? 1 : (h = (h - t) / (e - t), h * h * (3 - 2 * h));
}
function Kc(h, t, e) {
    return h <= t ? 0 : h >= e ? 1 : (h = (h - t) / (e - t), h * h * h * (h * (h * 6 - 15) + 10));
}
function tu(h, t) {
    return h + Math.floor(Math.random() * (t - h + 1));
}
function eu(h, t) {
    return h + Math.random() * (t - h);
}
function iu(h) {
    return h * (.5 - Math.random());
}
function su(h) {
    h !== void 0 && (ua = h);
    let t = ua += 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 nu(h) {
    return h * De;
}
function ru(h) {
    return h * Ui;
}
function ou(h) {
    return (h & h - 1) === 0 && h !== 0;
}
function au(h) {
    return Math.pow(2, Math.ceil(Math.log(h) / Math.LN2));
}
function hu(h) {
    return Math.pow(2, Math.floor(Math.log(h) / Math.LN2));
}
function lu(h, t, e, i, s) {
    let n = Math.cos, r = Math.sin, o = n(e / 2), a = r(e / 2), l = n((t + i) / 2), c = r((t + i) / 2), u = n((t - i) / 2), d = r((t - i) / 2), p = n((i - t) / 2), f = r((i - t) / 2);
    switch(s){
        case "XYX":
            h.set(o * c, a * u, a * d, o * l);
            break;
        case "YZY":
            h.set(a * d, o * c, a * u, o * l);
            break;
        case "ZXZ":
            h.set(a * u, a * d, o * c, o * l);
            break;
        case "XZX":
            h.set(o * c, a * f, a * p, o * l);
            break;
        case "YXY":
            h.set(a * p, o * c, a * f, o * l);
            break;
        case "ZYZ":
            h.set(a * f, a * p, o * c, o * l);
            break;
        default:
            console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: " + s);
    }
}
function xt(h, t) {
    switch(t.constructor){
        case Float32Array:
            return h;
        case Uint32Array:
            return h / 4294967295;
        case Uint16Array:
            return h / 65535;
        case Uint8Array:
            return h / 255;
        case Int32Array:
            return Math.max(h / 2147483647, -1);
        case Int16Array:
            return Math.max(h / 32767, -1);
        case Int8Array:
            return Math.max(h / 127, -1);
        default:
            throw new Error("Invalid component type.");
    }
}
function V(h, t) {
    switch(t.constructor){
        case Float32Array:
            return h;
        case Uint32Array:
            return Math.round(h * 4294967295);
        case Uint16Array:
            return Math.round(h * 65535);
        case Uint8Array:
            return Math.round(h * 255);
        case Int32Array:
            return Math.round(h * 2147483647);
        case Int16Array:
            return Math.round(h * 32767);
        case Int8Array:
            return Math.round(h * 127);
        default:
            throw new Error("Invalid component type.");
    }
}
var Tf = {
    DEG2RAD: De,
    RAD2DEG: Ui,
    generateUUID: It,
    clamp: N,
    euclideanModulo: qo,
    mapLinear: Zc,
    inverseLerp: Yc,
    lerp: Ni,
    damp: $c,
    pingpong: Qc,
    smoothstep: jc,
    smootherstep: Kc,
    randInt: tu,
    randFloat: eu,
    randFloatSpread: iu,
    seededRandom: su,
    degToRad: nu,
    radToDeg: ru,
    isPowerOfTwo: ou,
    ceilPowerOfTwo: au,
    floorPowerOfTwo: hu,
    setQuaternionFromProperEuler: lu,
    normalize: V,
    denormalize: xt
}, T = class h {
    constructor(t = 0, e = 0){
        h.prototype.isVector2 = !0, this.x = t, this.y = e;
    }
    get width() {
        return this.x;
    }
    set width(t) {
        this.x = t;
    }
    get height() {
        return this.y;
    }
    set height(t) {
        this.y = t;
    }
    set(t, e) {
        return this.x = t, this.y = e, this;
    }
    setScalar(t) {
        return this.x = t, this.y = t, this;
    }
    setX(t) {
        return this.x = t, this;
    }
    setY(t) {
        return this.y = t, this;
    }
    setComponent(t, e) {
        switch(t){
            case 0:
                this.x = e;
                break;
            case 1:
                this.y = e;
                break;
            default:
                throw new Error("index is out of range: " + t);
        }
        return this;
    }
    getComponent(t) {
        switch(t){
            case 0:
                return this.x;
            case 1:
                return this.y;
            default:
                throw new Error("index is out of range: " + t);
        }
    }
    clone() {
        return new this.constructor(this.x, this.y);
    }
    copy(t) {
        return this.x = t.x, this.y = t.y, this;
    }
    add(t) {
        return this.x += t.x, this.y += t.y, this;
    }
    addScalar(t) {
        return this.x += t, this.y += t, this;
    }
    addVectors(t, e) {
        return this.x = t.x + e.x, this.y = t.y + e.y, this;
    }
    addScaledVector(t, e) {
        return this.x += t.x * e, this.y += t.y * e, this;
    }
    sub(t) {
        return this.x -= t.x, this.y -= t.y, this;
    }
    subScalar(t) {
        return this.x -= t, this.y -= t, this;
    }
    subVectors(t, e) {
        return this.x = t.x - e.x, this.y = t.y - e.y, this;
    }
    multiply(t) {
        return this.x *= t.x, this.y *= t.y, this;
    }
    multiplyScalar(t) {
        return this.x *= t, this.y *= t, this;
    }
    divide(t) {
        return this.x /= t.x, this.y /= t.y, this;
    }
    divideScalar(t) {
        return this.multiplyScalar(1 / t);
    }
    applyMatrix3(t) {
        let e = this.x, i = this.y, s = t.elements;
        return this.x = s[0] * e + s[3] * i + s[6], this.y = s[1] * e + s[4] * i + s[7], this;
    }
    min(t) {
        return this.x = Math.min(this.x, t.x), this.y = Math.min(this.y, t.y), this;
    }
    max(t) {
        return this.x = Math.max(this.x, t.x), this.y = Math.max(this.y, t.y), this;
    }
    clamp(t, e) {
        return this.x = N(this.x, t.x, e.x), this.y = N(this.y, t.y, e.y), this;
    }
    clampScalar(t, e) {
        return this.x = N(this.x, t, e), this.y = N(this.y, t, e), this;
    }
    clampLength(t, e) {
        let i = this.length();
        return this.divideScalar(i || 1).multiplyScalar(N(i, t, e));
    }
    floor() {
        return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this;
    }
    ceil() {
        return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this;
    }
    round() {
        return this.x = Math.round(this.x), this.y = Math.round(this.y), this;
    }
    roundToZero() {
        return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this;
    }
    negate() {
        return this.x = -this.x, this.y = -this.y, this;
    }
    dot(t) {
        return this.x * t.x + this.y * t.y;
    }
    cross(t) {
        return this.x * t.y - this.y * t.x;
    }
    lengthSq() {
        return this.x * this.x + this.y * this.y;
    }
    length() {
        return Math.sqrt(this.x * this.x + this.y * this.y);
    }
    manhattanLength() {
        return Math.abs(this.x) + Math.abs(this.y);
    }
    normalize() {
        return this.divideScalar(this.length() || 1);
    }
    angle() {
        return Math.atan2(-this.y, -this.x) + Math.PI;
    }
    angleTo(t) {
        let e = Math.sqrt(this.lengthSq() * t.lengthSq());
        if (e === 0) return Math.PI / 2;
        let i = this.dot(t) / e;
        return Math.acos(N(i, -1, 1));
    }
    distanceTo(t) {
        return Math.sqrt(this.distanceToSquared(t));
    }
    distanceToSquared(t) {
        let e = this.x - t.x, i = this.y - t.y;
        return e * e + i * i;
    }
    manhattanDistanceTo(t) {
        return Math.abs(this.x - t.x) + Math.abs(this.y - t.y);
    }
    setLength(t) {
        return this.normalize().multiplyScalar(t);
    }
    lerp(t, e) {
        return this.x += (t.x - this.x) * e, this.y += (t.y - this.y) * e, this;
    }
    lerpVectors(t, e, i) {
        return this.x = t.x + (e.x - t.x) * i, this.y = t.y + (e.y - t.y) * i, this;
    }
    equals(t) {
        return t.x === this.x && t.y === this.y;
    }
    fromArray(t, e = 0) {
        return this.x = t[e], this.y = t[e + 1], this;
    }
    toArray(t = [], e = 0) {
        return t[e] = this.x, t[e + 1] = this.y, t;
    }
    fromBufferAttribute(t, e) {
        return this.x = t.getX(e), this.y = t.getY(e), this;
    }
    rotateAround(t, e) {
        let i = Math.cos(e), s = Math.sin(e), n = this.x - t.x, r = this.y - t.y;
        return this.x = n * i - r * s + t.x, this.y = n * s + r * i + t.y, this;
    }
    random() {
        return this.x = Math.random(), this.y = Math.random(), this;
    }
    *[Symbol.iterator]() {
        yield this.x, yield this.y;
    }
}, Gt = class h {
    constructor(t, e, i, s, n, r, o, a, l){
        h.prototype.isMatrix3 = !0, this.elements = [
            1,
            0,
            0,
            0,
            1,
            0,
            0,
            0,
            1
        ], t !== void 0 && this.set(t, e, i, s, n, r, o, a, l);
    }
    set(t, e, i, s, n, r, o, a, l) {
        let c = this.elements;
        return c[0] = t, c[1] = s, c[2] = o, c[3] = e, c[4] = n, c[5] = a, c[6] = i, c[7] = r, c[8] = l, this;
    }
    identity() {
        return this.set(1, 0, 0, 0, 1, 0, 0, 0, 1), this;
    }
    copy(t) {
        let e = this.elements, i = t.elements;
        return e[0] = i[0], e[1] = i[1], e[2] = i[2], e[3] = i[3], e[4] = i[4], e[5] = i[5], e[6] = i[6], e[7] = i[7], e[8] = i[8], this;
    }
    extractBasis(t, e, i) {
        return t.setFromMatrix3Column(this, 0), e.setFromMatrix3Column(this, 1), i.setFromMatrix3Column(this, 2), this;
    }
    setFromMatrix4(t) {
        let e = t.elements;
        return this.set(e[0], e[4], e[8], e[1], e[5], e[9], e[2], e[6], e[10]), this;
    }
    multiply(t) {
        return this.multiplyMatrices(this, t);
    }
    premultiply(t) {
        return this.multiplyMatrices(t, this);
    }
    multiplyMatrices(t, e) {
        let i = t.elements, s = e.elements, n = this.elements, r = i[0], o = i[3], a = i[6], l = i[1], c = i[4], u = i[7], d = i[2], p = i[5], f = i[8], m = s[0], y1 = s[3], g = s[6], x1 = s[1], b = s[4], M = s[7], _ = s[2], v = s[5], S = s[8];
        return n[0] = r * m + o * x1 + a * _, n[3] = r * y1 + o * b + a * v, n[6] = r * g + o * M + a * S, n[1] = l * m + c * x1 + u * _, n[4] = l * y1 + c * b + u * v, n[7] = l * g + c * M + u * S, n[2] = d * m + p * x1 + f * _, n[5] = d * y1 + p * b + f * v, n[8] = d * g + p * M + f * S, this;
    }
    multiplyScalar(t) {
        let e = this.elements;
        return e[0] *= t, e[3] *= t, e[6] *= t, e[1] *= t, e[4] *= t, e[7] *= t, e[2] *= t, e[5] *= t, e[8] *= t, this;
    }
    determinant() {
        let t = this.elements, e = t[0], i = t[1], s = t[2], n = t[3], r = t[4], o = t[5], a = t[6], l = t[7], c = t[8];
        return e * r * c - e * o * l - i * n * c + i * o * a + s * n * l - s * r * a;
    }
    invert() {
        let t = this.elements, e = t[0], i = t[1], s = t[2], n = t[3], r = t[4], o = t[5], a = t[6], l = t[7], c = t[8], u = c * r - o * l, d = o * a - c * n, p = l * n - r * a, f = e * u + i * d + s * p;
        if (f === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
        let m = 1 / f;
        return t[0] = u * m, t[1] = (s * l - c * i) * m, t[2] = (o * i - s * r) * m, t[3] = d * m, t[4] = (c * e - s * a) * m, t[5] = (s * n - o * e) * m, t[6] = p * m, t[7] = (i * a - l * e) * m, t[8] = (r * e - i * n) * m, this;
    }
    transpose() {
        let t, e = this.elements;
        return t = e[1], e[1] = e[3], e[3] = t, t = e[2], e[2] = e[6], e[6] = t, t = e[5], e[5] = e[7], e[7] = t, this;
    }
    getNormalMatrix(t) {
        return this.setFromMatrix4(t).invert().transpose();
    }
    transposeIntoArray(t) {
        let e = this.elements;
        return t[0] = e[0], t[1] = e[3], t[2] = e[6], t[3] = e[1], t[4] = e[4], t[5] = e[7], t[6] = e[2], t[7] = e[5], t[8] = e[8], this;
    }
    setUvTransform(t, e, i, s, n, r, o) {
        let a = Math.cos(n), l = Math.sin(n);
        return this.set(i * a, i * l, -i * (a * r + l * o) + r + t, -s * l, s * a, -s * (-l * r + a * o) + o + e, 0, 0, 1), this;
    }
    scale(t, e) {
        return this.premultiply(Bn.makeScale(t, e)), this;
    }
    rotate(t) {
        return this.premultiply(Bn.makeRotation(-t)), this;
    }
    translate(t, e) {
        return this.premultiply(Bn.makeTranslation(t, e)), this;
    }
    makeTranslation(t, e) {
        return t.isVector2 ? this.set(1, 0, t.x, 0, 1, t.y, 0, 0, 1) : this.set(1, 0, t, 0, 1, e, 0, 0, 1), this;
    }
    makeRotation(t) {
        let e = Math.cos(t), i = Math.sin(t);
        return this.set(e, -i, 0, i, e, 0, 0, 0, 1), this;
    }
    makeScale(t, e) {
        return this.set(t, 0, 0, 0, e, 0, 0, 0, 1), this;
    }
    equals(t) {
        let e = this.elements, i = t.elements;
        for(let s = 0; s < 9; s++)if (e[s] !== i[s]) return !1;
        return !0;
    }
    fromArray(t, e = 0) {
        for(let i = 0; i < 9; i++)this.elements[i] = t[i + e];
        return this;
    }
    toArray(t = [], e = 0) {
        let i = this.elements;
        return t[e] = i[0], t[e + 1] = i[1], t[e + 2] = i[2], t[e + 3] = i[3], t[e + 4] = i[4], t[e + 5] = i[5], t[e + 6] = i[6], t[e + 7] = i[7], t[e + 8] = i[8], t;
    }
    clone() {
        return new this.constructor().fromArray(this.elements);
    }
}, Bn = new Gt;
function cu(h) {
    for(let t = h.length - 1; t >= 0; --t)if (h[t] >= 65535) return !0;
    return !1;
}
var uu = {
    Int8Array,
    Uint8Array,
    Uint8ClampedArray,
    Int16Array,
    Uint16Array,
    Int32Array,
    Uint32Array,
    Float32Array,
    Float64Array
};
function ci(h, t) {
    return new uu[h](t);
}
function Ys(h) {
    return document.createElementNS("http://www.w3.org/1999/xhtml", h);
}
function If() {
    let h = Ys("canvas");
    return h.style.display = "block", h;
}
var da = {};
function Cf(h) {
    h in da || (da[h] = !0, console.warn(h));
}
function zf(h, t, e) {
    return new Promise(function(i, s) {
        function n() {
            switch(h.clientWaitSync(t, h.SYNC_FLUSH_COMMANDS_BIT, 0)){
                case h.WAIT_FAILED:
                    s();
                    break;
                case h.TIMEOUT_EXPIRED:
                    setTimeout(n, e);
                    break;
                default:
                    i();
            }
        }
        setTimeout(n, e);
    });
}
function Ff(h) {
    let t = h.elements;
    t[2] = .5 * t[2] + .5 * t[3], t[6] = .5 * t[6] + .5 * t[7], t[10] = .5 * t[10] + .5 * t[11], t[14] = .5 * t[14] + .5 * t[15];
}
function Bf(h) {
    let t = h.elements;
    t[11] === -1 ? (t[10] = -t[10] - 1, t[14] = -t[14]) : (t[10] = -t[10], t[14] = -t[14] + 1);
}
var pa = new Gt().set(.4123908, .3575843, .1804808, .212639, .7151687, .0721923, .0193308, .1191948, .9505322), fa = new Gt().set(3.2409699, -1.5373832, -.4986108, -.9692436, 1.8759675, .0415551, .0556301, -.203977, 1.0569715);
function du() {
    let h = {
        enabled: !0,
        workingColorSpace: ha,
        spaces: {},
        convert: function(s, n, r) {
            return this.enabled === !1 || n === r || !n || !r || (this.spaces[n].transfer === Fn && (s.r = ae(s.r), s.g = ae(s.g), s.b = ae(s.b)), this.spaces[n].primaries !== this.spaces[r].primaries && (s.applyMatrix3(this.spaces[n].toXYZ), s.applyMatrix3(this.spaces[r].fromXYZ)), this.spaces[r].transfer === Fn && (s.r = di(s.r), s.g = di(s.g), s.b = di(s.b))), s;
        },
        fromWorkingColorSpace: function(s, n) {
            return this.convert(s, this.workingColorSpace, n);
        },
        toWorkingColorSpace: function(s, n) {
            return this.convert(s, n, this.workingColorSpace);
        },
        getPrimaries: function(s) {
            return this.spaces[s].primaries;
        },
        getTransfer: function(s) {
            return s === zl ? la : this.spaces[s].transfer;
        },
        getLuminanceCoefficients: function(s, n = this.workingColorSpace) {
            return s.fromArray(this.spaces[n].luminanceCoefficients);
        },
        define: function(s) {
            Object.assign(this.spaces, s);
        },
        _getMatrix: function(s, n, r) {
            return s.copy(this.spaces[n].toXYZ).multiply(this.spaces[r].fromXYZ);
        },
        _getDrawingBufferColorSpace: function(s) {
            return this.spaces[s].outputColorSpaceConfig.drawingBufferColorSpace;
        },
        _getUnpackColorSpace: function(s = this.workingColorSpace) {
            return this.spaces[s].workingColorSpaceConfig.unpackColorSpace;
        }
    }, t = [
        .64,
        .33,
        .3,
        .6,
        .15,
        .06
    ], e = [
        .2126,
        .7152,
        .0722
    ], i = [
        .3127,
        .329
    ];
    return h.define({
        [ha]: {
            primaries: t,
            whitePoint: i,
            transfer: la,
            toXYZ: pa,
            fromXYZ: fa,
            luminanceCoefficients: e,
            workingColorSpaceConfig: {
                unpackColorSpace: Bt
            },
            outputColorSpaceConfig: {
                drawingBufferColorSpace: Bt
            }
        },
        [Bt]: {
            primaries: t,
            whitePoint: i,
            transfer: Fn,
            toXYZ: pa,
            fromXYZ: fa,
            luminanceCoefficients: e,
            outputColorSpaceConfig: {
                drawingBufferColorSpace: Bt
            }
        }
    }), h;
}
var Tt = du();
function ae(h) {
    return h < .04045 ? h * .0773993808 : Math.pow(h * .9478672986 + .0521327014, 2.4);
}
function di(h) {
    return h < .0031308 ? h * 12.92 : 1.055 * Math.pow(h, .41666) - .055;
}
var Ge, yr = class {
    static getDataURL(t) {
        if (/^data:/i.test(t.src) || typeof HTMLCanvasElement > "u") return t.src;
        let e;
        if (t instanceof HTMLCanvasElement) e = t;
        else {
            Ge === void 0 && (Ge = Ys("canvas")), Ge.width = t.width, Ge.height = t.height;
            let i = Ge.getContext("2d");
            t instanceof ImageData ? i.putImageData(t, 0, 0) : i.drawImage(t, 0, 0, t.width, t.height), e = Ge;
        }
        return e.toDataURL("image/png");
    }
    static sRGBToLinear(t) {
        if (typeof HTMLImageElement < "u" && t instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && t instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && t instanceof ImageBitmap) {
            let e = Ys("canvas");
            e.width = t.width, e.height = t.height;
            let i = e.getContext("2d");
            i.drawImage(t, 0, 0, t.width, t.height);
            let s = i.getImageData(0, 0, t.width, t.height), n = s.data;
            for(let r = 0; r < n.length; r++)n[r] = ae(n[r] / 255) * 255;
            return i.putImageData(s, 0, 0), e;
        } else if (t.data) {
            let e = t.data.slice(0);
            for(let i = 0; i < e.length; i++)e instanceof Uint8Array || e instanceof Uint8ClampedArray ? e[i] = Math.floor(ae(e[i] / 255) * 255) : e[i] = ae(e[i]);
            return {
                data: e,
                width: t.width,
                height: t.height
            };
        } else return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."), t;
    }
}, pu = 0, be = class {
    constructor(t = null){
        this.isSource = !0, Object.defineProperty(this, "id", {
            value: pu++
        }), this.uuid = It(), this.data = t, this.dataReady = !0, this.version = 0;
    }
    set needsUpdate(t) {
        t === !0 && this.version++;
    }
    toJSON(t) {
        let e = t === void 0 || typeof t == "string";
        if (!e && t.images[this.uuid] !== void 0) return t.images[this.uuid];
        let i = {
            uuid: this.uuid,
            url: ""
        }, s = this.data;
        if (s !== null) {
            let n;
            if (Array.isArray(s)) {
                n = [];
                for(let r = 0, o = s.length; r < o; r++)s[r].isDataTexture ? n.push(En(s[r].image)) : n.push(En(s[r]));
            } else n = En(s);
            i.url = n;
        }
        return e || (t.images[this.uuid] = i), i;
    }
};
function En(h) {
    return typeof HTMLImageElement < "u" && h instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && h instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && h instanceof ImageBitmap ? yr.getDataURL(h) : h.data ? {
        data: Array.from(h.data),
        width: h.width,
        height: h.height,
        type: h.data.constructor.name
    } : (console.warn("THREE.Texture: Unable to serialize Texture."), {});
}
var fu = 0, lt = class h extends qt {
    constructor(t = h.DEFAULT_IMAGE, e = h.DEFAULT_MAPPING, i = Ht, s = Ht, n = Et, r = vn, o = Li, a = Sl, l = h.DEFAULT_ANISOTROPY, c = zl){
        super(), this.isTexture = !0, Object.defineProperty(this, "id", {
            value: fu++
        }), this.uuid = It(), this.name = "", this.source = new be(t), this.mipmaps = [], this.mapping = e, this.channel = 0, this.wrapS = i, this.wrapT = s, this.magFilter = n, this.minFilter = r, this.anisotropy = l, this.format = o, this.internalFormat = null, this.type = a, this.offset = new T(0, 0), this.repeat = new T(1, 1), this.center = new T(0, 0), this.rotation = 0, this.matrixAutoUpdate = !0, this.matrix = new Gt, this.generateMipmaps = !0, this.premultiplyAlpha = !1, this.flipY = !0, this.unpackAlignment = 4, this.colorSpace = c, this.userData = {}, this.version = 0, this.onUpdate = null, this.renderTarget = null, this.isRenderTargetTexture = !1, this.pmremVersion = 0;
    }
    get image() {
        return this.source.data;
    }
    set image(t = null) {
        this.source.data = t;
    }
    updateMatrix() {
        this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
    }
    clone() {
        return new this.constructor().copy(this);
    }
    copy(t) {
        return this.name = t.name, this.source = t.source, this.mipmaps = t.mipmaps.slice(0), this.mapping = t.mapping, this.channel = t.channel, this.wrapS = t.wrapS, this.wrapT = t.wrapT, this.magFilter = t.magFilter, this.minFilter = t.minFilter, this.anisotropy = t.anisotropy, this.format = t.format, this.internalFormat = t.internalFormat, this.type = t.type, this.offset.copy(t.offset), this.repeat.copy(t.repeat), this.center.copy(t.center), this.rotation = t.rotation, this.matrixAutoUpdate = t.matrixAutoUpdate, this.matrix.copy(t.matrix), this.generateMipmaps = t.generateMipmaps, this.premultiplyAlpha = t.premultiplyAlpha, this.flipY = t.flipY, this.unpackAlignment = t.unpackAlignment, this.colorSpace = t.colorSpace, this.renderTarget = t.renderTarget, this.isRenderTargetTexture = t.isRenderTargetTexture, this.userData = JSON.parse(JSON.stringify(t.userData)), this.needsUpdate = !0, this;
    }
    toJSON(t) {
        let e = t === void 0 || typeof t == "string";
        if (!e && t.textures[this.uuid] !== void 0) return t.textures[this.uuid];
        let i = {
            metadata: {
                version: 4.6,
                type: "Texture",
                generator: "Texture.toJSON"
            },
            uuid: this.uuid,
            name: this.name,
            image: this.source.toJSON(t).uuid,
            mapping: this.mapping,
            channel: this.channel,
            repeat: [
                this.repeat.x,
                this.repeat.y
            ],
            offset: [
                this.offset.x,
                this.offset.y
            ],
            center: [
                this.center.x,
                this.center.y
            ],
            rotation: this.rotation,
            wrap: [
                this.wrapS,
                this.wrapT
            ],
            format: this.format,
            internalFormat: this.internalFormat,
            type: this.type,
            colorSpace: this.colorSpace,
            minFilter: this.minFilter,
            magFilter: this.magFilter,
            anisotropy: this.anisotropy,
            flipY: this.flipY,
            generateMipmaps: this.generateMipmaps,
            premultiplyAlpha: this.premultiplyAlpha,
            unpackAlignment: this.unpackAlignment
        };
        return Object.keys(this.userData).length > 0 && (i.userData = this.userData), e || (t.textures[this.uuid] = i), i;
    }
    dispose() {
        this.dispatchEvent({
            type: "dispose"
        });
    }
    transformUv(t) {
        if (this.mapping !== Lo) return t;
        if (t.applyMatrix3(this.matrix), t.x < 0 || t.x > 1) switch(this.wrapS){
            case pr:
                t.x = t.x - Math.floor(t.x);
                break;
            case Ht:
                t.x = t.x < 0 ? 0 : 1;
                break;
            case fr:
                Math.abs(Math.floor(t.x) % 2) === 1 ? t.x = Math.ceil(t.x) - t.x : t.x = t.x - Math.floor(t.x);
                break;
        }
        if (t.y < 0 || t.y > 1) switch(this.wrapT){
            case pr:
                t.y = t.y - Math.floor(t.y);
                break;
            case Ht:
                t.y = t.y < 0 ? 0 : 1;
                break;
            case fr:
                Math.abs(Math.floor(t.y) % 2) === 1 ? t.y = Math.ceil(t.y) - t.y : t.y = t.y - Math.floor(t.y);
                break;
        }
        return this.flipY && (t.y = 1 - t.y), t;
    }
    set needsUpdate(t) {
        t === !0 && (this.version++, this.source.needsUpdate = !0);
    }
    set needsPMREMUpdate(t) {
        t === !0 && this.pmremVersion++;
    }
};
lt.DEFAULT_IMAGE = null;
lt.DEFAULT_MAPPING = Lo;
lt.DEFAULT_ANISOTROPY = 1;
var ot = class h {
    constructor(t = 0, e = 0, i = 0, s = 1){
        h.prototype.isVector4 = !0, this.x = t, this.y = e, this.z = i, this.w = s;
    }
    get width() {
        return this.z;
    }
    set width(t) {
        this.z = t;
    }
    get height() {
        return this.w;
    }
    set height(t) {
        this.w = t;
    }
    set(t, e, i, s) {
        return this.x = t, this.y = e, this.z = i, this.w = s, this;
    }
    setScalar(t) {
        return this.x = t, this.y = t, this.z = t, this.w = t, this;
    }
    setX(t) {
        return this.x = t, this;
    }
    setY(t) {
        return this.y = t, this;
    }
    setZ(t) {
        return this.z = t, this;
    }
    setW(t) {
        return this.w = t, this;
    }
    setComponent(t, e) {
        switch(t){
            case 0:
                this.x = e;
                break;
            case 1:
                this.y = e;
                break;
            case 2:
                this.z = e;
                break;
            case 3:
                this.w = e;
                break;
            default:
                throw new Error("index is out of range: " + t);
        }
        return this;
    }
    getComponent(t) {
        switch(t){
            case 0:
                return this.x;
            case 1:
                return this.y;
            case 2:
                return this.z;
            case 3:
                return this.w;
            default:
                throw new Error("index is out of range: " + t);
        }
    }
    clone() {
        return new this.constructor(this.x, this.y, this.z, this.w);
    }
    copy(t) {
        return this.x = t.x, this.y = t.y, this.z = t.z, this.w = t.w !== void 0 ? t.w : 1, this;
    }
    add(t) {
        return this.x += t.x, this.y += t.y, this.z += t.z, this.w += t.w, this;
    }
    addScalar(t) {
        return this.x += t, this.y += t, this.z += t, this.w += t, this;
    }
    addVectors(t, e) {
        return this.x = t.x + e.x, this.y = t.y + e.y, this.z = t.z + e.z, this.w = t.w + e.w, this;
    }
    addScaledVector(t, e) {
        return this.x += t.x * e, this.y += t.y * e, this.z += t.z * e, this.w += t.w * e, this;
    }
    sub(t) {
        return this.x -= t.x, this.y -= t.y, this.z -= t.z, this.w -= t.w, this;
    }
    subScalar(t) {
        return this.x -= t, this.y -= t, this.z -= t, this.w -= t, this;
    }
    subVectors(t, e) {
        return this.x = t.x - e.x, this.y = t.y - e.y, this.z = t.z - e.z, this.w = t.w - e.w, this;
    }
    multiply(t) {
        return this.x *= t.x, this.y *= t.y, this.z *= t.z, this.w *= t.w, this;
    }
    multiplyScalar(t) {
        return this.x *= t, this.y *= t, this.z *= t, this.w *= t, this;
    }
    applyMatrix4(t) {
        let e = this.x, i = this.y, s = this.z, n = this.w, r = t.elements;
        return this.x = r[0] * e + r[4] * i + r[8] * s + r[12] * n, this.y = r[1] * e + r[5] * i + r[9] * s + r[13] * n, this.z = r[2] * e + r[6] * i + r[10] * s + r[14] * n, this.w = r[3] * e + r[7] * i + r[11] * s + r[15] * n, this;
    }
    divide(t) {
        return this.x /= t.x, this.y /= t.y, this.z /= t.z, this.w /= t.w, this;
    }
    divideScalar(t) {
        return this.multiplyScalar(1 / t);
    }
    setAxisAngleFromQuaternion(t) {
        this.w = 2 * Math.acos(t.w);
        let e = Math.sqrt(1 - t.w * t.w);
        return e < 1e-4 ? (this.x = 1, this.y = 0, this.z = 0) : (this.x = t.x / e, this.y = t.y / e, this.z = t.z / e), this;
    }
    setAxisAngleFromRotationMatrix(t) {
        let e, i, s, n, a = t.elements, l = a[0], c = a[4], u = a[8], d = a[1], p = a[5], f = a[9], m = a[2], y1 = a[6], g = a[10];
        if (Math.abs(c - d) < .01 && Math.abs(u - m) < .01 && Math.abs(f - y1) < .01) {
            if (Math.abs(c + d) < .1 && Math.abs(u + m) < .1 && Math.abs(f + y1) < .1 && Math.abs(l + p + g - 3) < .1) return this.set(1, 0, 0, 0), this;
            e = Math.PI;
            let b = (l + 1) / 2, M = (p + 1) / 2, _ = (g + 1) / 2, v = (c + d) / 4, S = (u + m) / 4, A = (f + y1) / 4;
            return b > M && b > _ ? b < .01 ? (i = 0, s = .707106781, n = .707106781) : (i = Math.sqrt(b), s = v / i, n = S / i) : M > _ ? M < .01 ? (i = .707106781, s = 0, n = .707106781) : (s = Math.sqrt(M), i = v / s, n = A / s) : _ < .01 ? (i = .707106781, s = .707106781, n = 0) : (n = Math.sqrt(_), i = S / n, s = A / n), this.set(i, s, n, e), this;
        }
        let x1 = Math.sqrt((y1 - f) * (y1 - f) + (u - m) * (u - m) + (d - c) * (d - c));
        return Math.abs(x1) < .001 && (x1 = 1), this.x = (y1 - f) / x1, this.y = (u - m) / x1, this.z = (d - c) / x1, this.w = Math.acos((l + p + g - 1) / 2), this;
    }
    setFromMatrixPosition(t) {
        let e = t.elements;
        return this.x = e[12], this.y = e[13], this.z = e[14], this.w = e[15], this;
    }
    min(t) {
        return this.x = Math.min(this.x, t.x), this.y = Math.min(this.y, t.y), this.z = Math.min(this.z, t.z), this.w = Math.min(this.w, t.w), this;
    }
    max(t) {
        return this.x = Math.max(this.x, t.x), this.y = Math.max(this.y, t.y), this.z = Math.max(this.z, t.z), this.w = Math.max(this.w, t.w), this;
    }
    clamp(t, e) {
        return this.x = N(this.x, t.x, e.x), this.y = N(this.y, t.y, e.y), this.z = N(this.z, t.z, e.z), this.w = N(this.w, t.w, e.w), this;
    }
    clampScalar(t, e) {
        return this.x = N(this.x, t, e), this.y = N(this.y, t, e), this.z = N(this.z, t, e), this.w = N(this.w, t, e), this;
    }
    clampLength(t, e) {
        let i = this.length();
        return this.divideScalar(i || 1).multiplyScalar(N(i, t, e));
    }
    floor() {
        return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this.z = Math.floor(this.z), this.w = Math.floor(this.w), this;
    }
    ceil() {
        return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this.z = Math.ceil(this.z), this.w = Math.ceil(this.w), this;
    }
    round() {
        return this.x = Math.round(this.x), this.y = Math.round(this.y), this.z = Math.round(this.z), this.w = Math.round(this.w), this;
    }
    roundToZero() {
        return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this.z = Math.trunc(this.z), this.w = Math.trunc(this.w), this;
    }
    negate() {
        return this.x = -this.x, this.y = -this.y, this.z = -this.z, this.w = -this.w, this;
    }
    dot(t) {
        return this.x * t.x + this.y * t.y + this.z * t.z + this.w * t.w;
    }
    lengthSq() {
        return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
    }
    length() {
        return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
    }
    manhattanLength() {
        return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
    }
    normalize() {
        return this.divideScalar(this.length() || 1);
    }
    setLength(t) {
        return this.normalize().multiplyScalar(t);
    }
    lerp(t, e) {
        return this.x += (t.x - this.x) * e, this.y += (t.y - this.y) * e, this.z += (t.z - this.z) * e, this.w += (t.w - this.w) * e, this;
    }
    lerpVectors(t, e, i) {
        return this.x = t.x + (e.x - t.x) * i, this.y = t.y + (e.y - t.y) * i, this.z = t.z + (e.z - t.z) * i, this.w = t.w + (e.w - t.w) * i, this;
    }
    equals(t) {
        return t.x === this.x && t.y === this.y && t.z === this.z && t.w === this.w;
    }
    fromArray(t, e = 0) {
        return this.x = t[e], this.y = t[e + 1], this.z = t[e + 2], this.w = t[e + 3], this;
    }
    toArray(t = [], e = 0) {
        return t[e] = this.x, t[e + 1] = this.y, t[e + 2] = this.z, t[e + 3] = this.w, t;
    }
    fromBufferAttribute(t, e) {
        return this.x = t.getX(e), this.y = t.getY(e), this.z = t.getZ(e), this.w = t.getW(e), this;
    }
    random() {
        return this.x = Math.random(), this.y = Math.random(), this.z = Math.random(), this.w = Math.random(), this;
    }
    *[Symbol.iterator]() {
        yield this.x, yield this.y, yield this.z, yield this.w;
    }
}, Wi = class extends qt {
    constructor(t = 1, e = 1, i = {}){
        super(), this.isRenderTarget = !0, this.width = t, this.height = e, this.depth = 1, this.scissor = new ot(0, 0, t, e), this.scissorTest = !1, this.viewport = new ot(0, 0, t, e);
        let s = {
            width: t,
            height: e,
            depth: 1
        };
        i = Object.assign({
            generateMipmaps: !1,
            internalFormat: null,
            minFilter: Et,
            depthBuffer: !0,
            stencilBuffer: !1,
            resolveDepthBuffer: !0,
            resolveStencilBuffer: !0,
            depthTexture: null,
            samples: 0,
            count: 1
        }, i);
        let n = new lt(s, i.mapping, i.wrapS, i.wrapT, i.magFilter, i.minFilter, i.format, i.type, i.anisotropy, i.colorSpace);
        n.flipY = !1, n.generateMipmaps = i.generateMipmaps, n.internalFormat = i.internalFormat, this.textures = [];
        let r = i.count;
        for(let o = 0; o < r; o++)this.textures[o] = n.clone(), this.textures[o].isRenderTargetTexture = !0, this.textures[o].renderTarget = this;
        this.depthBuffer = i.depthBuffer, this.stencilBuffer = i.stencilBuffer, this.resolveDepthBuffer = i.resolveDepthBuffer, this.resolveStencilBuffer = i.resolveStencilBuffer, this._depthTexture = null, this.depthTexture = i.depthTexture, this.samples = i.samples;
    }
    get texture() {
        return this.textures[0];
    }
    set texture(t) {
        this.textures[0] = t;
    }
    set depthTexture(t) {
        this._depthTexture !== null && (this._depthTexture.renderTarget = null), t !== null && (t.renderTarget = this), this._depthTexture = t;
    }
    get depthTexture() {
        return this._depthTexture;
    }
    setSize(t, e, i = 1) {
        if (this.width !== t || this.height !== e || this.depth !== i) {
            this.width = t, this.height = e, this.depth = i;
            for(let s = 0, n = this.textures.length; s < n; s++)this.textures[s].image.width = t, this.textures[s].image.height = e, this.textures[s].image.depth = i;
            this.dispose();
        }
        this.viewport.set(0, 0, t, e), this.scissor.set(0, 0, t, e);
    }
    clone() {
        return new this.constructor().copy(this);
    }
    copy(t) {
        this.width = t.width, this.height = t.height, this.depth = t.depth, this.scissor.copy(t.scissor), this.scissorTest = t.scissorTest, this.viewport.copy(t.viewport), this.textures.length = 0;
        for(let i = 0, s = t.textures.length; i < s; i++)this.textures[i] = t.textures[i].clone(), this.textures[i].isRenderTargetTexture = !0, this.textures[i].renderTarget = this;
        let e = Object.assign({}, t.texture.image);
        return this.texture.source = new be(e), this.depthBuffer = t.depthBuffer, this.stencilBuffer = t.stencilBuffer, this.resolveDepthBuffer = t.resolveDepthBuffer, this.resolveStencilBuffer = t.resolveStencilBuffer, t.depthTexture !== null && (this.depthTexture = t.depthTexture.clone()), this.samples = t.samples, this;
    }
    dispose() {
        this.dispatchEvent({
            type: "dispose"
        });
    }
}, Hi = class extends Wi {
    constructor(t = 1, e = 1, i = {}){
        super(t, e, i), this.isWebGLRenderTarget = !0;
    }
}, $s = class extends lt {
    constructor(t = null, e = 1, i = 1, s = 1){
        super(null), this.isDataArrayTexture = !0, this.image = {
            data: t,
            width: e,
            height: i,
            depth: s
        }, this.magFilter = Ut, this.minFilter = Ut, this.wrapR = Ht, this.generateMipmaps = !1, this.flipY = !1, this.unpackAlignment = 1, this.layerUpdates = new Set;
    }
    addLayerUpdate(t) {
        this.layerUpdates.add(t);
    }
    clearLayerUpdates() {
        this.layerUpdates.clear();
    }
}, ma = class extends Hi {
    constructor(t = 1, e = 1, i = 1, s = {}){
        super(t, e, s), this.isWebGLArrayRenderTarget = !0, this.depth = i, this.texture = new $s(null, t, e, i), this.texture.isRenderTargetTexture = !0;
    }
}, Qs = class extends lt {
    constructor(t = null, e = 1, i = 1, s = 1){
        super(null), this.isData3DTexture = !0, this.image = {
            data: t,
            width: e,
            height: i,
            depth: s
        }, this.magFilter = Ut, this.minFilter = Ut, this.wrapR = Ht, this.generateMipmaps = !1, this.flipY = !1, this.unpackAlignment = 1;
    }
}, ya = class extends Hi {
    constructor(t = 1, e = 1, i = 1, s = {}){
        super(t, e, s), this.isWebGL3DRenderTarget = !0, this.depth = i, this.texture = new Qs(null, t, e, i), this.texture.isRenderTargetTexture = !0;
    }
}, bt = class {
    constructor(t = 0, e = 0, i = 0, s = 1){
        this.isQuaternion = !0, this._x = t, this._y = e, this._z = i, this._w = s;
    }
    static slerpFlat(t, e, i, s, n, r, o) {
        let a = i[s + 0], l = i[s + 1], c = i[s + 2], u = i[s + 3], d = n[r + 0], p = n[r + 1], f = n[r + 2], m = n[r + 3];
        if (o === 0) {
            t[e + 0] = a, t[e + 1] = l, t[e + 2] = c, t[e + 3] = u;
            return;
        }
        if (o === 1) {
            t[e + 0] = d, t[e + 1] = p, t[e + 2] = f, t[e + 3] = m;
            return;
        }
        if (u !== m || a !== d || l !== p || c !== f) {
            let y1 = 1 - o, g = a * d + l * p + c * f + u * m, x1 = g >= 0 ? 1 : -1, b = 1 - g * g;
            if (b > Number.EPSILON) {
                let _ = Math.sqrt(b), v = Math.atan2(_, g * x1);
                y1 = Math.sin(y1 * v) / _, o = Math.sin(o * v) / _;
            }
            let M = o * x1;
            if (a = a * y1 + d * M, l = l * y1 + p * M, c = c * y1 + f * M, u = u * y1 + m * M, y1 === 1 - o) {
                let _ = 1 / Math.sqrt(a * a + l * l + c * c + u * u);
                a *= _, l *= _, c *= _, u *= _;
            }
        }
        t[e] = a, t[e + 1] = l, t[e + 2] = c, t[e + 3] = u;
    }
    static multiplyQuaternionsFlat(t, e, i, s, n, r) {
        let o = i[s], a = i[s + 1], l = i[s + 2], c = i[s + 3], u = n[r], d = n[r + 1], p = n[r + 2], f = n[r + 3];
        return t[e] = o * f + c * u + a * p - l * d, t[e + 1] = a * f + c * d + l * u - o * p, t[e + 2] = l * f + c * p + o * d - a * u, t[e + 3] = c * f - o * u - a * d - l * p, t;
    }
    get x() {
        return this._x;
    }
    set x(t) {
        this._x = t, this._onChangeCallback();
    }
    get y() {
        return this._y;
    }
    set y(t) {
        this._y = t, this._onChangeCallback();
    }
    get z() {
        return this._z;
    }
    set z(t) {
        this._z = t, this._onChangeCallback();
    }
    get w() {
        return this._w;
    }
    set w(t) {
        this._w = t, this._onChangeCallback();
    }
    set(t, e, i, s) {
        return this._x = t, this._y = e, this._z = i, this._w = s, this._onChangeCallback(), this;
    }
    clone() {
        return new this.constructor(this._x, this._y, this._z, this._w);
    }
    copy(t) {
        return this._x = t.x, this._y = t.y, this._z = t.z, this._w = t.w, this._onChangeCallback(), this;
    }
    setFromEuler(t, e = !0) {
        let i = t._x, s = t._y, n = t._z, r = t._order, o = Math.cos, a = Math.sin, l = o(i / 2), c = o(s / 2), u = o(n / 2), d = a(i / 2), p = a(s / 2), f = a(n / 2);
        switch(r){
            case "XYZ":
                this._x = d * c * u + l * p * f, this._y = l * p * u - d * c * f, this._z = l * c * f + d * p * u, this._w = l * c * u - d * p * f;
                break;
            case "YXZ":
                this._x = d * c * u + l * p * f, this._y = l * p * u - d * c * f, this._z = l * c * f - d * p * u, this._w = l * c * u + d * p * f;
                break;
            case "ZXY":
                this._x = d * c * u - l * p * f, this._y = l * p * u + d * c * f, this._z = l * c * f + d * p * u, this._w = l * c * u - d * p * f;
                break;
            case "ZYX":
                this._x = d * c * u - l * p * f, this._y = l * p * u + d * c * f, this._z = l * c * f - d * p * u, this._w = l * c * u + d * p * f;
                break;
            case "YZX":
                this._x = d * c * u + l * p * f, this._y = l * p * u + d * c * f, this._z = l * c * f - d * p * u, this._w = l * c * u - d * p * f;
                break;
            case "XZY":
                this._x = d * c * u - l * p * f, this._y = l * p * u - d * c * f, this._z = l * c * f + d * p * u, this._w = l * c * u + d * p * f;
                break;
            default:
                console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + r);
        }
        return e === !0 && this._onChangeCallback(), this;
    }
    setFromAxisAngle(t, e) {
        let i = e / 2, s = Math.sin(i);
        return this._x = t.x * s, this._y = t.y * s, this._z = t.z * s, this._w = Math.cos(i), this._onChangeCallback(), this;
    }
    setFromRotationMatrix(t) {
        let e = t.elements, i = e[0], s = e[4], n = e[8], r = e[1], o = e[5], a = e[9], l = e[2], c = e[6], u = e[10], d = i + o + u;
        if (d > 0) {
            let p = .5 / Math.sqrt(d + 1);
            this._w = .25 / p, this._x = (c - a) * p, this._y = (n - l) * p, this._z = (r - s) * p;
        } else if (i > o && i > u) {
            let p = 2 * Math.sqrt(1 + i - o - u);
            this._w = (c - a) / p, this._x = .25 * p, this._y = (s + r) / p, this._z = (n + l) / p;
        } else if (o > u) {
            let p = 2 * Math.sqrt(1 + o - i - u);
            this._w = (n - l) / p, this._x = (s + r) / p, this._y = .25 * p, this._z = (a + c) / p;
        } else {
            let p = 2 * Math.sqrt(1 + u - i - o);
            this._w = (r - s) / p, this._x = (n + l) / p, this._y = (a + c) / p, this._z = .25 * p;
        }
        return this._onChangeCallback(), this;
    }
    setFromUnitVectors(t, e) {
        let i = t.dot(e) + 1;
        return i < Number.EPSILON ? (i = 0, Math.abs(t.x) > Math.abs(t.z) ? (this._x = -t.y, this._y = t.x, this._z = 0, this._w = i) : (this._x = 0, this._y = -t.z, this._z = t.y, this._w = i)) : (this._x = t.y * e.z - t.z * e.y, this._y = t.z * e.x - t.x * e.z, this._z = t.x * e.y - t.y * e.x, this._w = i), this.normalize();
    }
    angleTo(t) {
        return 2 * Math.acos(Math.abs(N(this.dot(t), -1, 1)));
    }
    rotateTowards(t, e) {
        let i = this.angleTo(t);
        if (i === 0) return this;
        let s = Math.min(1, e / i);
        return this.slerp(t, s), this;
    }
    identity() {
        return this.set(0, 0, 0, 1);
    }
    invert() {
        return this.conjugate();
    }
    conjugate() {
        return this._x *= -1, this._y *= -1, this._z *= -1, this._onChangeCallback(), this;
    }
    dot(t) {
        return this._x * t._x + this._y * t._y + this._z * t._z + this._w * t._w;
    }
    lengthSq() {
        return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
    }
    length() {
        return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
    }
    normalize() {
        let t = this.length();
        return t === 0 ? (this._x = 0, this._y = 0, this._z = 0, this._w = 1) : (t = 1 / t, this._x = this._x * t, this._y = this._y * t, this._z = this._z * t, this._w = this._w * t), this._onChangeCallback(), this;
    }
    multiply(t) {
        return this.multiplyQuaternions(this, t);
    }
    premultiply(t) {
        return this.multiplyQuaternions(t, this);
    }
    multiplyQuaternions(t, e) {
        let i = t._x, s = t._y, n = t._z, r = t._w, o = e._x, a = e._y, l = e._z, c = e._w;
        return this._x = i * c + r * o + s * l - n * a, this._y = s * c + r * a + n * o - i * l, this._z = n * c + r * l + i * a - s * o, this._w = r * c - i * o - s * a - n * l, this._onChangeCallback(), this;
    }
    slerp(t, e) {
        if (e === 0) return this;
        if (e === 1) return this.copy(t);
        let i = this._x, s = this._y, n = this._z, r = this._w, o = r * t._w + i * t._x + s * t._y + n * t._z;
        if (o < 0 ? (this._w = -t._w, this._x = -t._x, this._y = -t._y, this._z = -t._z, o = -o) : this.copy(t), o >= 1) return this._w = r, this._x = i, this._y = s, this._z = n, this;
        let a = 1 - o * o;
        if (a <= Number.EPSILON) {
            let p = 1 - e;
            return this._w = p * r + e * this._w, this._x = p * i + e * this._x, this._y = p * s + e * this._y, this._z = p * n + e * this._z, this.normalize(), this;
        }
        let l = Math.sqrt(a), c = Math.atan2(l, o), u = Math.sin((1 - e) * c) / l, d = Math.sin(e * c) / l;
        return this._w = r * u + this._w * d, this._x = i * u + this._x * d, this._y = s * u + this._y * d, this._z = n * u + this._z * d, this._onChangeCallback(), this;
    }
    slerpQuaternions(t, e, i) {
        return this.copy(t).slerp(e, i);
    }
    random() {
        let t = 2 * Math.PI * Math.random(), e = 2 * Math.PI * Math.random(), i = Math.random(), s = Math.sqrt(1 - i), n = Math.sqrt(i);
        return this.set(s * Math.sin(t), s * Math.cos(t), n * Math.sin(e), n * Math.cos(e));
    }
    equals(t) {
        return t._x === this._x && t._y === this._y && t._z === this._z && t._w === this._w;
    }
    fromArray(t, e = 0) {
        return this._x = t[e], this._y = t[e + 1], this._z = t[e + 2], this._w = t[e + 3], this._onChangeCallback(), this;
    }
    toArray(t = [], e = 0) {
        return t[e] = this._x, t[e + 1] = this._y, t[e + 2] = this._z, t[e + 3] = this._w, t;
    }
    fromBufferAttribute(t, e) {
        return this._x = t.getX(e), this._y = t.getY(e), this._z = t.getZ(e), this._w = t.getW(e), this._onChangeCallback(), this;
    }
    toJSON() {
        return this.toArray();
    }
    _onChange(t) {
        return this._onChangeCallback = t, this;
    }
    _onChangeCallback() {}
    *[Symbol.iterator]() {
        yield this._x, yield this._y, yield this._z, yield this._w;
    }
}, w = class h {
    constructor(t = 0, e = 0, i = 0){
        h.prototype.isVector3 = !0, this.x = t, this.y = e, this.z = i;
    }
    set(t, e, i) {
        return i === void 0 && (i = this.z), this.x = t, this.y = e, this.z = i, this;
    }
    setScalar(t) {
        return this.x = t, this.y = t, this.z = t, this;
    }
    setX(t) {
        return this.x = t, this;
    }
    setY(t) {
        return this.y = t, this;
    }
    setZ(t) {
        return this.z = t, this;
    }
    setComponent(t, e) {
        switch(t){
            case 0:
                this.x = e;
                break;
            case 1:
                this.y = e;
                break;
            case 2:
                this.z = e;
                break;
            default:
                throw new Error("index is out of range: " + t);
        }
        return this;
    }
    getComponent(t) {
        switch(t){
            case 0:
                return this.x;
            case 1:
                return this.y;
            case 2:
                return this.z;
            default:
                throw new Error("index is out of range: " + t);
        }
    }
    clone() {
        return new this.constructor(this.x, this.y, this.z);
    }
    copy(t) {
        return this.x = t.x, this.y = t.y, this.z = t.z, this;
    }
    add(t) {
        return this.x += t.x, this.y += t.y, this.z += t.z, this;
    }
    addScalar(t) {
        return this.x += t, this.y += t, this.z += t, this;
    }
    addVectors(t, e) {
        return this.x = t.x + e.x, this.y = t.y + e.y, this.z = t.z + e.z, this;
    }
    addScaledVector(t, e) {
        return this.x += t.x * e, this.y += t.y * e, this.z += t.z * e, this;
    }
    sub(t) {
        return this.x -= t.x, this.y -= t.y, this.z -= t.z, this;
    }
    subScalar(t) {
        return this.x -= t, this.y -= t, this.z -= t, this;
    }
    subVectors(t, e) {
        return this.x = t.x - e.x, this.y = t.y - e.y, this.z = t.z - e.z, this;
    }
    multiply(t) {
        return this.x *= t.x, this.y *= t.y, this.z *= t.z, this;
    }
    multiplyScalar(t) {
        return this.x *= t, this.y *= t, this.z *= t, this;
    }
    multiplyVectors(t, e) {
        return this.x = t.x * e.x, this.y = t.y * e.y, this.z = t.z * e.z, this;
    }
    applyEuler(t) {
        return this.applyQuaternion(ga.setFromEuler(t));
    }
    applyAxisAngle(t, e) {
        return this.applyQuaternion(ga.setFromAxisAngle(t, e));
    }
    applyMatrix3(t) {
        let e = this.x, i = this.y, s = this.z, n = t.elements;
        return this.x = n[0] * e + n[3] * i + n[6] * s, this.y = n[1] * e + n[4] * i + n[7] * s, this.z = n[2] * e + n[5] * i + n[8] * s, this;
    }
    applyNormalMatrix(t) {
        return this.applyMatrix3(t).normalize();
    }
    applyMatrix4(t) {
        let e = this.x, i = this.y, s = this.z, n = t.elements, r = 1 / (n[3] * e + n[7] * i + n[11] * s + n[15]);
        return this.x = (n[0] * e + n[4] * i + n[8] * s + n[12]) * r, this.y = (n[1] * e + n[5] * i + n[9] * s + n[13]) * r, this.z = (n[2] * e + n[6] * i + n[10] * s + n[14]) * r, this;
    }
    applyQuaternion(t) {
        let e = this.x, i = this.y, s = this.z, n = t.x, r = t.y, o = t.z, a = t.w, l = 2 * (r * s - o * i), c = 2 * (o * e - n * s), u = 2 * (n * i - r * e);
        return this.x = e + a * l + r * u - o * c, this.y = i + a * c + o * l - n * u, this.z = s + a * u + n * c - r * l, this;
    }
    project(t) {
        return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix);
    }
    unproject(t) {
        return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld);
    }
    transformDirection(t) {
        let e = this.x, i = this.y, s = this.z, n = t.elements;
        return this.x = n[0] * e + n[4] * i + n[8] * s, this.y = n[1] * e + n[5] * i + n[9] * s, this.z = n[2] * e + n[6] * i + n[10] * s, this.normalize();
    }
    divide(t) {
        return this.x /= t.x, this.y /= t.y, this.z /= t.z, this;
    }
    divideScalar(t) {
        return this.multiplyScalar(1 / t);
    }
    min(t) {
        return this.x = Math.min(this.x, t.x), this.y = Math.min(this.y, t.y), this.z = Math.min(this.z, t.z), this;
    }
    max(t) {
        return this.x = Math.max(this.x, t.x), this.y = Math.max(this.y, t.y), this.z = Math.max(this.z, t.z), this;
    }
    clamp(t, e) {
        return this.x = N(this.x, t.x, e.x), this.y = N(this.y, t.y, e.y), this.z = N(this.z, t.z, e.z), this;
    }
    clampScalar(t, e) {
        return this.x = N(this.x, t, e), this.y = N(this.y, t, e), this.z = N(this.z, t, e), this;
    }
    clampLength(t, e) {
        let i = this.length();
        return this.divideScalar(i || 1).multiplyScalar(N(i, t, e));
    }
    floor() {
        return this.x = Math.floor(this.x), this.y = Math.floor(this.y), this.z = Math.floor(this.z), this;
    }
    ceil() {
        return this.x = Math.ceil(this.x), this.y = Math.ceil(this.y), this.z = Math.ceil(this.z), this;
    }
    round() {
        return this.x = Math.round(this.x), this.y = Math.round(this.y), this.z = Math.round(this.z), this;
    }
    roundToZero() {
        return this.x = Math.trunc(this.x), this.y = Math.trunc(this.y), this.z = Math.trunc(this.z), this;
    }
    negate() {
        return this.x = -this.x, this.y = -this.y, this.z = -this.z, this;
    }
    dot(t) {
        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.x * this.x + this.y * this.y + this.z * this.z);
    }
    manhattanLength() {
        return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
    }
    normalize() {
        return this.divideScalar(this.length() || 1);
    }
    setLength(t) {
        return this.normalize().multiplyScalar(t);
    }
    lerp(t, e) {
        return this.x += (t.x - this.x) * e, this.y += (t.y - this.y) * e, this.z += (t.z - this.z) * e, this;
    }
    lerpVectors(t, e, i) {
        return this.x = t.x + (e.x - t.x) * i, this.y = t.y + (e.y - t.y) * i, this.z = t.z + (e.z - t.z) * i, this;
    }
    cross(t) {
        return this.crossVectors(this, t);
    }
    crossVectors(t, e) {
        let i = t.x, s = t.y, n = t.z, r = e.x, o = e.y, a = e.z;
        return this.x = s * a - n * o, this.y = n * r - i * a, this.z = i * o - s * r, this;
    }
    projectOnVector(t) {
        let e = t.lengthSq();
        if (e === 0) return this.set(0, 0, 0);
        let i = t.dot(this) / e;
        return this.copy(t).multiplyScalar(i);
    }
    projectOnPlane(t) {
        return Rn.copy(this).projectOnVector(t), this.sub(Rn);
    }
    reflect(t) {
        return this.sub(Rn.copy(t).multiplyScalar(2 * this.dot(t)));
    }
    angleTo(t) {
        let e = Math.sqrt(this.lengthSq() * t.lengthSq());
        if (e === 0) return Math.PI / 2;
        let i = this.dot(t) / e;
        return Math.acos(N(i, -1, 1));
    }
    distanceTo(t) {
        return Math.sqrt(this.distanceToSquared(t));
    }
    distanceToSquared(t) {
        let e = this.x - t.x, i = this.y - t.y, s = this.z - t.z;
        return e * e + i * i + s * s;
    }
    manhattanDistanceTo(t) {
        return Math.abs(this.x - t.x) + Math.abs(this.y - t.y) + Math.abs(this.z - t.z);
    }
    setFromSpherical(t) {
        return this.setFromSphericalCoords(t.radius, t.phi, t.theta);
    }
    setFromSphericalCoords(t, e, i) {
        let s = Math.sin(e) * t;
        return this.x = s * Math.sin(i), this.y = Math.cos(e) * t, this.z = s * Math.cos(i), this;
    }
    setFromCylindrical(t) {
        return this.setFromCylindricalCoords(t.radius, t.theta, t.y);
    }
    setFromCylindricalCoords(t, e, i) {
        return this.x = t * Math.sin(e), this.y = i, this.z = t * Math.cos(e), this;
    }
    setFromMatrixPosition(t) {
        let e = t.elements;
        return this.x = e[12], this.y = e[13], this.z = e[14], this;
    }
    setFromMatrixScale(t) {
        let e = this.setFromMatrixColumn(t, 0).length(), i = this.setFromMatrixColumn(t, 1).length(), s = this.setFromMatrixColumn(t, 2).length();
        return this.x = e, this.y = i, this.z = s, this;
    }
    setFromMatrixColumn(t, e) {
        return this.fromArray(t.elements, e * 4);
    }
    setFromMatrix3Column(t, e) {
        return this.fromArray(t.elements, e * 3);
    }
    setFromEuler(t) {
        return this.x = t._x, this.y = t._y, this.z = t._z, this;
    }
    setFromColor(t) {
        return this.x = t.r, this.y = t.g, this.z = t.b, this;
    }
    equals(t) {
        return t.x === this.x && t.y === this.y && t.z === this.z;
    }
    fromArray(t, e = 0) {
        return this.x = t[e], this.y = t[e + 1], this.z = t[e + 2], this;
    }
    toArray(t = [], e = 0) {
        return t[e] = this.x, t[e + 1] = this.y, t[e + 2] = this.z, t;
    }
    fromBufferAttribute(t, e) {
        return this.x = t.getX(e), this.y = t.getY(e), this.z = t.getZ(e), this;
    }
    random() {
        return this.x = Math.random(), this.y = Math.random(), this.z = Math.random(), this;
    }
    randomDirection() {
        let t = Math.random() * Math.PI * 2, e = Math.random() * 2 - 1, i = Math.sqrt(1 - e * e);
        return this.x = i * Math.cos(t), this.y = e, this.z = i * Math.sin(t), this;
    }
    *[Symbol.iterator]() {
        yield this.x, yield this.y, yield this.z;
    }
}, Rn = new w, ga = new bt, ft = class {
    constructor(t = new w(1 / 0, 1 / 0, 1 / 0), e = new w(-1 / 0, -1 / 0, -1 / 0)){
        this.isBox3 = !0, this.min = t, this.max = e;
    }
    set(t, e) {
        return this.min.copy(t), this.max.copy(e), this;
    }
    setFromArray(t) {
        this.makeEmpty();
        for(let e = 0, i = t.length; e < i; e += 3)this.expandByPoint(Nt.fromArray(t, e));
        return this;
    }
    setFromBufferAttribute(t) {
        this.makeEmpty();
        for(let e = 0, i = t.count; e < i; e++)this.expandByPoint(Nt.fromBufferAttribute(t, e));
        return this;
    }
    setFromPoints(t) {
        this.makeEmpty();
        for(let e = 0, i = t.length; e < i; e++)this.expandByPoint(t[e]);
        return this;
    }
    setFromCenterAndSize(t, e) {
        let i = Nt.copy(e).multiplyScalar(.5);
        return this.min.copy(t).sub(i), this.max.copy(t).add(i), this;
    }
    setFromObject(t, e = !1) {
        return this.makeEmpty(), this.expandByObject(t, e);
    }
    clone() {
        return new this.constructor().copy(this);
    }
    copy(t) {
        return this.min.copy(t.min), this.max.copy(t.max), this;
    }
    makeEmpty() {
        return this.min.x = this.min.y = this.min.z = 1 / 0, this.max.x = this.max.y = this.max.z = -1 / 0, this;
    }
    isEmpty() {
        return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
    }
    getCenter(t) {
        return this.isEmpty() ? t.set(0, 0, 0) : t.addVectors(this.min, this.max).multiplyScalar(.5);
    }
    getSize(t) {
        return this.isEmpty() ? t.set(0, 0, 0) : t.subVectors(this.max, this.min);
    }
    expandByPoint(t) {
        return this.min.min(t), this.max.max(t), this;
    }
    expandByVector(t) {
        return this.min.sub(t), this.max.add(t), this;
    }
    expandByScalar(t) {
        return this.min.addScalar(-t), this.max.addScalar(t), this;
    }
    expandByObject(t, e = !1) {
        t.updateWorldMatrix(!1, !1);
        let i = t.geometry;
        if (i !== void 0) {
            let n = i.getAttribute("position");
            if (e === !0 && n !== void 0 && t.isInstancedMesh !== !0) for(let r = 0, o = n.count; r < o; r++)t.isMesh === !0 ? t.getVertexPosition(r, Nt) : Nt.fromBufferAttribute(n, r), Nt.applyMatrix4(t.matrixWorld), this.expandByPoint(Nt);
            else t.boundingBox !== void 0 ? (t.boundingBox === null && t.computeBoundingBox(), ss.copy(t.boundingBox)) : (i.boundingBox === null && i.computeBoundingBox(), ss.copy(i.boundingBox)), ss.applyMatrix4(t.matrixWorld), this.union(ss);
        }
        let s = t.children;
        for(let n = 0, r = s.length; n < r; n++)this.expandByObject(s[n], e);
        return this;
    }
    containsPoint(t) {
        return t.x >= this.min.x && t.x <= this.max.x && t.y >= this.min.y && t.y <= this.max.y && t.z >= this.min.z && t.z <= this.max.z;
    }
    containsBox(t) {
        return this.min.x <= t.min.x && t.max.x <= this.max.x && this.min.y <= t.min.y && t.max.y <= this.max.y && this.min.z <= t.min.z && t.max.z <= this.max.z;
    }
    getParameter(t, e) {
        return e.set((t.x - this.min.x) / (this.max.x - this.min.x), (t.y - this.min.y) / (this.max.y - this.min.y), (t.z - this.min.z) / (this.max.z - this.min.z));
    }
    intersectsBox(t) {
        return t.max.x >= this.min.x && t.min.x <= this.max.x && t.max.y >= this.min.y && t.min.y <= this.max.y && t.max.z >= this.min.z && t.min.z <= this.max.z;
    }
    intersectsSphere(t) {
        return this.clampPoint(t.center, Nt), Nt.distanceToSquared(t.center) <= t.radius * t.radius;
    }
    intersectsPlane(t) {
        let e, i;
        return t.normal.x > 0 ? (e = t.normal.x * this.min.x, i = t.normal.x * this.max.x) : (e = t.normal.x * this.max.x, i = t.normal.x * this.min.x), t.normal.y > 0 ? (e += t.normal.y * this.min.y, i += t.normal.y * this.max.y) : (e += t.normal.y * this.max.y, i += t.normal.y * this.min.y), t.normal.z > 0 ? (e += t.normal.z * this.min.z, i += t.normal.z * this.max.z) : (e += t.normal.z * this.max.z, i += t.normal.z * this.min.z), e <= -t.constant && i >= -t.constant;
    }
    intersectsTriangle(t) {
        if (this.isEmpty()) return !1;
        this.getCenter(Ai), ns.subVectors(this.max, Ai), Xe.subVectors(t.a, Ai), Je.subVectors(t.b, Ai), Ze.subVectors(t.c, Ai), ue.subVectors(Je, Xe), de.subVectors(Ze, Je), Te.subVectors(Xe, Ze);
        let e = [
            0,
            -ue.z,
            ue.y,
            0,
            -de.z,
            de.y,
            0,
            -Te.z,
            Te.y,
            ue.z,
            0,
            -ue.x,
            de.z,
            0,
            -de.x,
            Te.z,
            0,
            -Te.x,
            -ue.y,
            ue.x,
            0,
            -de.y,
            de.x,
            0,
            -Te.y,
            Te.x,
            0
        ];
        return !kn(e, Xe, Je, Ze, ns) || (e = [
            1,
            0,
            0,
            0,
            1,
            0,
            0,
            0,
            1
        ], !kn(e, Xe, Je, Ze, ns)) ? !1 : (rs.crossVectors(ue, de), e = [
            rs.x,
            rs.y,
            rs.z
        ], kn(e, Xe, Je, Ze, ns));
    }
    clampPoint(t, e) {
        return e.copy(t).clamp(this.min, this.max);
    }
    distanceToPoint(t) {
        return this.clampPoint(t, Nt).distanceTo(t);
    }
    getBoundingSphere(t) {
        return this.isEmpty() ? t.makeEmpty() : (this.getCenter(t.center), t.radius = this.getSize(Nt).length() * .5), t;
    }
    intersect(t) {
        return this.min.max(t.min), this.max.min(t.max), this.isEmpty() && this.makeEmpty(), this;
    }
    union(t) {
        return this.min.min(t.min), this.max.max(t.max), this;
    }
    applyMatrix4(t) {
        return this.isEmpty() ? this : (jt[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(t), jt[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(t), jt[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(t), jt[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(t), jt[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(t), jt[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(t), jt[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(t), jt[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(t), this.setFromPoints(jt), this);
    }
    translate(t) {
        return this.min.add(t), this.max.add(t), this;
    }
    equals(t) {
        return t.min.equals(this.min) && t.max.equals(this.max);
    }
}, jt = [
    new w,
    new w,
    new w,
    new w,
    new w,
    new w,
    new w,
    new w
], Nt = new w, ss = new ft, Xe = new w, Je = new w, Ze = new w, ue = new w, de = new w, Te = new w, Ai = new w, ns = new w, rs = new w, Ie = new w;
function kn(h, t, e, i, s) {
    for(let n = 0, r = h.length - 3; n <= r; n += 3){
        Ie.fromArray(h, n);
        let o = s.x * Math.abs(Ie.x) + s.y * Math.abs(Ie.y) + s.z * Math.abs(Ie.z), a = t.dot(Ie), l = e.dot(Ie), c = i.dot(Ie);
        if (Math.max(-Math.max(a, l, c), Math.min(a, l, c)) > o) return !1;
    }
    return !0;
}
var mu = new ft, Si = new w, Pn = new w, ht = class {
    constructor(t = new w, e = -1){
        this.isSphere = !0, this.center = t, this.radius = e;
    }
    set(t, e) {
        return this.center.copy(t), this.radius = e, this;
    }
    setFromPoints(t, e) {
        let i = this.center;
        e !== void 0 ? i.copy(e) : mu.setFromPoints(t).getCenter(i);
        let s = 0;
        for(let n = 0, r = t.length; n < r; n++)s = Math.max(s, i.distanceToSquared(t[n]));
        return this.radius = Math.sqrt(s), this;
    }
    copy(t) {
        return this.center.copy(t.center), this.radius = t.radius, this;
    }
    isEmpty() {
        return this.radius < 0;
    }
    makeEmpty() {
        return this.center.set(0, 0, 0), this.radius = -1, this;
    }
    containsPoint(t) {
        return t.distanceToSquared(this.center) <= this.radius * this.radius;
    }
    distanceToPoint(t) {
        return t.distanceTo(this.center) - this.radius;
    }
    intersectsSphere(t) {
        let e = this.radius + t.radius;
        return t.center.distanceToSquared(this.center) <= e * e;
    }
    intersectsBox(t) {
        return t.intersectsSphere(this);
    }
    intersectsPlane(t) {
        return Math.abs(t.distanceToPoint(this.center)) <= this.radius;
    }
    clampPoint(t, e) {
        let i = this.center.distanceToSquared(t);
        return e.copy(t), i > this.radius * this.radius && (e.sub(this.center).normalize(), e.multiplyScalar(this.radius).add(this.center)), e;
    }
    getBoundingBox(t) {
        return this.isEmpty() ? (t.makeEmpty(), t) : (t.set(this.center, this.center), t.expandByScalar(this.radius), t);
    }
    applyMatrix4(t) {
        return this.center.applyMatrix4(t), this.radius = this.radius * t.getMaxScaleOnAxis(), this;
    }
    translate(t) {
        return this.center.add(t), this;
    }
    expandByPoint(t) {
        if (this.isEmpty()) return this.center.copy(t), this.radius = 0, this;
        Si.subVectors(t, this.center);
        let e = Si.lengthSq();
        if (e > this.radius * this.radius) {
            let i = Math.sqrt(e), s = (i - this.radius) * .5;
            this.center.addScaledVector(Si, s / i), this.radius += s;
        }
        return this;
    }
    union(t) {
        return t.isEmpty() ? this : this.isEmpty() ? (this.copy(t), this) : (this.center.equals(t.center) === !0 ? this.radius = Math.max(this.radius, t.radius) : (Pn.subVectors(t.center, this.center).setLength(t.radius), this.expandByPoint(Si.copy(t.center).add(Pn)), this.expandByPoint(Si.copy(t.center).sub(Pn))), this);
    }
    equals(t) {
        return t.center.equals(this.center) && t.radius === this.radius;
    }
    clone() {
        return new this.constructor().copy(this);
    }
}, Kt = new w, On = new w, os = new w, pe = new w, Nn = new w, as = new w, Vn = new w, Le = class {
    constructor(t = new w, e = new w(0, 0, -1)){
        this.origin = t, this.direction = e;
    }
    set(t, e) {
        return this.origin.copy(t), this.direction.copy(e), this;
    }
    copy(t) {
        return this.origin.copy(t.origin), this.direction.copy(t.direction), this;
    }
    at(t, e) {
        return e.copy(this.origin).addScaledVector(this.direction, t);
    }
    lookAt(t) {
        return this.direction.copy(t).sub(this.origin).normalize(), this;
    }
    recast(t) {
        return this.origin.copy(this.at(t, Kt)), this;
    }
    closestPointToPoint(t, e) {
        e.subVectors(t, this.origin);
        let i = e.dot(this.direction);
        return i < 0 ? e.copy(this.origin) : e.copy(this.origin).addScaledVector(this.direction, i);
    }
    distanceToPoint(t) {
        return Math.sqrt(this.distanceSqToPoint(t));
    }
    distanceSqToPoint(t) {
        let e = Kt.subVectors(t, this.origin).dot(this.direction);
        return e < 0 ? this.origin.distanceToSquared(t) : (Kt.copy(this.origin).addScaledVector(this.direction, e), Kt.distanceToSquared(t));
    }
    distanceSqToSegment(t, e, i, s) {
        On.copy(t).add(e).multiplyScalar(.5), os.copy(e).sub(t).normalize(), pe.copy(this.origin).sub(On);
        let n = t.distanceTo(e) * .5, r = -this.direction.dot(os), o = pe.dot(this.direction), a = -pe.dot(os), l = pe.lengthSq(), c = Math.abs(1 - r * r), u, d, p, f;
        if (c > 0) if (u = r * a - o, d = r * o - a, f = n * c, u >= 0) if (d >= -f) if (d <= f) {
            let m = 1 / c;
            u *= m, d *= m, p = u * (u + r * d + 2 * o) + d * (r * u + d + 2 * a) + l;
        } else d = n, u = Math.max(0, -(r * d + o)), p = -u * u + d * (d + 2 * a) + l;
        else d = -n, u = Math.max(0, -(r * d + o)), p = -u * u + d * (d + 2 * a) + l;
        else d <= -f ? (u = Math.max(0, -(-r * n + o)), d = u > 0 ? -n : Math.min(Math.max(-n, -a), n), p = -u * u + d * (d + 2 * a) + l) : d <= f ? (u = 0, d = Math.min(Math.max(-n, -a), n), p = d * (d + 2 * a) + l) : (u = Math.max(0, -(r * n + o)), d = u > 0 ? n : Math.min(Math.max(-n, -a), n), p = -u * u + d * (d + 2 * a) + l);
        else d = r > 0 ? -n : n, u = Math.max(0, -(r * d + o)), p = -u * u + d * (d + 2 * a) + l;
        return i && i.copy(this.origin).addScaledVector(this.direction, u), s && s.copy(On).addScaledVector(os, d), p;
    }
    intersectSphere(t, e) {
        Kt.subVectors(t.center, this.origin);
        let i = Kt.dot(this.direction), s = Kt.dot(Kt) - i * i, n = t.radius * t.radius;
        if (s > n) return null;
        let r = Math.sqrt(n - s), o = i - r, a = i + r;
        return a < 0 ? null : o < 0 ? this.at(a, e) : this.at(o, e);
    }
    intersectsSphere(t) {
        return this.distanceSqToPoint(t.center) <= t.radius * t.radius;
    }
    distanceToPlane(t) {
        let e = t.normal.dot(this.direction);
        if (e === 0) return t.distanceToPoint(this.origin) === 0 ? 0 : null;
        let i = -(this.origin.dot(t.normal) + t.constant) / e;
        return i >= 0 ? i : null;
    }
    intersectPlane(t, e) {
        let i = this.distanceToPlane(t);
        return i === null ? null : this.at(i, e);
    }
    intersectsPlane(t) {
        let e = t.distanceToPoint(this.origin);
        return e === 0 || t.normal.dot(this.direction) * e < 0;
    }
    intersectBox(t, e) {
        let i, s, n, r, o, a, l = 1 / this.direction.x, c = 1 / this.direction.y, u = 1 / this.direction.z, d = this.origin;
        return l >= 0 ? (i = (t.min.x - d.x) * l, s = (t.max.x - d.x) * l) : (i = (t.max.x - d.x) * l, s = (t.min.x - d.x) * l), c >= 0 ? (n = (t.min.y - d.y) * c, r = (t.max.y - d.y) * c) : (n = (t.max.y - d.y) * c, r = (t.min.y - d.y) * c), i > r || n > s || ((n > i || isNaN(i)) && (i = n), (r < s || isNaN(s)) && (s = r), u >= 0 ? (o = (t.min.z - d.z) * u, a = (t.max.z - d.z) * u) : (o = (t.max.z - d.z) * u, a = (t.min.z - d.z) * u), i > a || o > s) || ((o > i || i !== i) && (i = o), (a < s || s !== s) && (s = a), s < 0) ? null : this.at(i >= 0 ? i : s, e);
    }
    intersectsBox(t) {
        return this.intersectBox(t, Kt) !== null;
    }
    intersectTriangle(t, e, i, s, n) {
        Nn.subVectors(e, t), as.subVectors(i, t), Vn.crossVectors(Nn, as);
        let r = this.direction.dot(Vn), o;
        if (r > 0) {
            if (s) return null;
            o = 1;
        } else if (r < 0) o = -1, r = -r;
        else return null;
        pe.subVectors(this.origin, t);
        let a = o * this.direction.dot(as.crossVectors(pe, as));
        if (a < 0) return null;
        let l = o * this.direction.dot(Nn.cross(pe));
        if (l < 0 || a + l > r) return null;
        let c = -o * pe.dot(Vn);
        return c < 0 ? null : this.at(c / r, n);
    }
    applyMatrix4(t) {
        return this.origin.applyMatrix4(t), this.direction.transformDirection(t), this;
    }
    equals(t) {
        return t.origin.equals(this.origin) && t.direction.equals(this.direction);
    }
    clone() {
        return new this.constructor().copy(this);
    }
}, D = class h {
    constructor(t, e, i, s, n, r, o, a, l, c, u, d, p, f, m, y1){
        h.prototype.isMatrix4 = !0, this.elements = [
            1,
            0,
            0,
            0,
            0,
            1,
            0,
            0,
            0,
            0,
            1,
            0,
            0,
            0,
            0,
            1
        ], t !== void 0 && this.set(t, e, i, s, n, r, o, a, l, c, u, d, p, f, m, y1);
    }
    set(t, e, i, s, n, r, o, a, l, c, u, d, p, f, m, y1) {
        let g = this.elements;
        return g[0] = t, g[4] = e, g[8] = i, g[12] = s, g[1] = n, g[5] = r, g[9] = o, g[13] = a, g[2] = l, g[6] = c, g[10] = u, g[14] = d, g[3] = p, g[7] = f, g[11] = m, g[15] = y1, this;
    }
    identity() {
        return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), this;
    }
    clone() {
        return new h().fromArray(this.elements);
    }
    copy(t) {
        let e = this.elements, i = t.elements;
        return e[0] = i[0], e[1] = i[1], e[2] = i[2], e[3] = i[3], e[4] = i[4], e[5] = i[5], e[6] = i[6], e[7] = i[7], e[8] = i[8], e[9] = i[9], e[10] = i[10], e[11] = i[11], e[12] = i[12], e[13] = i[13], e[14] = i[14], e[15] = i[15], this;
    }
    copyPosition(t) {
        let e = this.elements, i = t.elements;
        return e[12] = i[12], e[13] = i[13], e[14] = i[14], this;
    }
    setFromMatrix3(t) {
        let e = t.elements;
        return this.set(e[0], e[3], e[6], 0, e[1], e[4], e[7], 0, e[2], e[5], e[8], 0, 0, 0, 0, 1), this;
    }
    extractBasis(t, e, i) {
        return t.setFromMatrixColumn(this, 0), e.setFromMatrixColumn(this, 1), i.setFromMatrixColumn(this, 2), this;
    }
    makeBasis(t, e, i) {
        return this.set(t.x, e.x, i.x, 0, t.y, e.y, i.y, 0, t.z, e.z, i.z, 0, 0, 0, 0, 1), this;
    }
    extractRotation(t) {
        let e = this.elements, i = t.elements, s = 1 / Ye.setFromMatrixColumn(t, 0).length(), n = 1 / Ye.setFromMatrixColumn(t, 1).length(), r = 1 / Ye.setFromMatrixColumn(t, 2).length();
        return e[0] = i[0] * s, e[1] = i[1] * s, e[2] = i[2] * s, e[3] = 0, e[4] = i[4] * n, e[5] = i[5] * n, e[6] = i[6] * n, e[7] = 0, e[8] = i[8] * r, e[9] = i[9] * r, e[10] = i[10] * r, e[11] = 0, e[12] = 0, e[13] = 0, e[14] = 0, e[15] = 1, this;
    }
    makeRotationFromEuler(t) {
        let e = this.elements, i = t.x, s = t.y, n = t.z, r = Math.cos(i), o = Math.sin(i), a = Math.cos(s), l = Math.sin(s), c = Math.cos(n), u = Math.sin(n);
        if (t.order === "XYZ") {
            let d = r * c, p = r * u, f = o * c, m = o * u;
            e[0] = a * c, e[4] = -a * u, e[8] = l, e[1] = p + f * l, e[5] = d - m * l, e[9] = -o * a, e[2] = m - d * l, e[6] = f + p * l, e[10] = r * a;
        } else if (t.order === "YXZ") {
            let d = a * c, p = a * u, f = l * c, m = l * u;
            e[0] = d + m * o, e[4] = f * o - p, e[8] = r * l, e[1] = r * u, e[5] = r * c, e[9] = -o, e[2] = p * o - f, e[6] = m + d * o, e[10] = r * a;
        } else if (t.order === "ZXY") {
            let d = a * c, p = a * u, f = l * c, m = l * u;
            e[0] = d - m * o, e[4] = -r * u, e[8] = f + p * o, e[1] = p + f * o, e[5] = r * c, e[9] = m - d * o, e[2] = -r * l, e[6] = o, e[10] = r * a;
        } else if (t.order === "ZYX") {
            let d = r * c, p = r * u, f = o * c, m = o * u;
            e[0] = a * c, e[4] = f * l - p, e[8] = d * l + m, e[1] = a * u, e[5] = m * l + d, e[9] = p * l - f, e[2] = -l, e[6] = o * a, e[10] = r * a;
        } else if (t.order === "YZX") {
            let d = r * a, p = r * l, f = o * a, m = o * l;
            e[0] = a * c, e[4] = m - d * u, e[8] = f * u + p, e[1] = u, e[5] = r * c, e[9] = -o * c, e[2] = -l * c, e[6] = p * u + f, e[10] = d - m * u;
        } else if (t.order === "XZY") {
            let d = r * a, p = r * l, f = o * a, m = o * l;
            e[0] = a * c, e[4] = -u, e[8] = l * c, e[1] = d * u + m, e[5] = r * c, e[9] = p * u - f, e[2] = f * u - p, e[6] = o * c, e[10] = m * u + d;
        }
        return e[3] = 0, e[7] = 0, e[11] = 0, e[12] = 0, e[13] = 0, e[14] = 0, e[15] = 1, this;
    }
    makeRotationFromQuaternion(t) {
        return this.compose(yu, t, gu);
    }
    lookAt(t, e, i) {
        let s = this.elements;
        return At.subVectors(t, e), At.lengthSq() === 0 && (At.z = 1), At.normalize(), fe.crossVectors(i, At), fe.lengthSq() === 0 && (Math.abs(i.z) === 1 ? At.x += 1e-4 : At.z += 1e-4, At.normalize(), fe.crossVectors(i, At)), fe.normalize(), hs.crossVectors(At, fe), s[0] = fe.x, s[4] = hs.x, s[8] = At.x, s[1] = fe.y, s[5] = hs.y, s[9] = At.y, s[2] = fe.z, s[6] = hs.z, s[10] = At.z, this;
    }
    multiply(t) {
        return this.multiplyMatrices(this, t);
    }
    premultiply(t) {
        return this.multiplyMatrices(t, this);
    }
    multiplyMatrices(t, e) {
        let i = t.elements, s = e.elements, n = this.elements, r = i[0], o = i[4], a = i[8], l = i[12], c = i[1], u = i[5], d = i[9], p = i[13], f = i[2], m = i[6], y1 = i[10], g = i[14], x1 = i[3], b = i[7], M = i[11], _ = i[15], v = s[0], S = s[4], A = s[8], I = s[12], C = s[1], k = s[5], U = s[9], W = s[13], H = s[2], Y = s[6], Q = s[10], zt = s[14], Pt = s[3], j = s[7], st = s[11], K = s[15];
        return n[0] = r * v + o * C + a * H + l * Pt, n[4] = r * S + o * k + a * Y + l * j, n[8] = r * A + o * U + a * Q + l * st, n[12] = r * I + o * W + a * zt + l * K, n[1] = c * v + u * C + d * H + p * Pt, n[5] = c * S + u * k + d * Y + p * j, n[9] = c * A + u * U + d * Q + p * st, n[13] = c * I + u * W + d * zt + p * K, n[2] = f * v + m * C + y1 * H + g * Pt, n[6] = f * S + m * k + y1 * Y + g * j, n[10] = f * A + m * U + y1 * Q + g * st, n[14] = f * I + m * W + y1 * zt + g * K, n[3] = x1 * v + b * C + M * H + _ * Pt, n[7] = x1 * S + b * k + M * Y + _ * j, n[11] = x1 * A + b * U + M * Q + _ * st, n[15] = x1 * I + b * W + M * zt + _ * K, this;
    }
    multiplyScalar(t) {
        let e = this.elements;
        return e[0] *= t, e[4] *= t, e[8] *= t, e[12] *= t, e[1] *= t, e[5] *= t, e[9] *= t, e[13] *= t, e[2] *= t, e[6] *= t, e[10] *= t, e[14] *= t, e[3] *= t, e[7] *= t, e[11] *= t, e[15] *= t, this;
    }
    determinant() {
        let t = this.elements, e = t[0], i = t[4], s = t[8], n = t[12], r = t[1], o = t[5], a = t[9], l = t[13], c = t[2], u = t[6], d = t[10], p = t[14], f = t[3], m = t[7], y1 = t[11], g = t[15];
        return f * (+n * a * u - s * l * u - n * o * d + i * l * d + s * o * p - i * a * p) + m * (+e * a * p - e * l * d + n * r * d - s * r * p + s * l * c - n * a * c) + y1 * (+e * l * u - e * o * p - n * r * u + i * r * p + n * o * c - i * l * c) + g * (-s * o * c - e * a * u + e * o * d + s * r * u - i * r * d + i * a * c);
    }
    transpose() {
        let t = this.elements, e;
        return e = t[1], t[1] = t[4], t[4] = e, e = t[2], t[2] = t[8], t[8] = e, e = t[6], t[6] = t[9], t[9] = e, e = t[3], t[3] = t[12], t[12] = e, e = t[7], t[7] = t[13], t[13] = e, e = t[11], t[11] = t[14], t[14] = e, this;
    }
    setPosition(t, e, i) {
        let s = this.elements;
        return t.isVector3 ? (s[12] = t.x, s[13] = t.y, s[14] = t.z) : (s[12] = t, s[13] = e, s[14] = i), this;
    }
    invert() {
        let t = this.elements, e = t[0], i = t[1], s = t[2], n = t[3], r = t[4], o = t[5], a = t[6], l = t[7], c = t[8], u = t[9], d = t[10], p = t[11], f = t[12], m = t[13], y1 = t[14], g = t[15], x1 = u * y1 * l - m * d * l + m * a * p - o * y1 * p - u * a * g + o * d * g, b = f * d * l - c * y1 * l - f * a * p + r * y1 * p + c * a * g - r * d * g, M = c * m * l - f * u * l + f * o * p - r * m * p - c * o * g + r * u * g, _ = f * u * a - c * m * a - f * o * d + r * m * d + c * o * y1 - r * u * y1, v = e * x1 + i * b + s * M + n * _;
        if (v === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        let S = 1 / v;
        return t[0] = x1 * S, t[1] = (m * d * n - u * y1 * n - m * s * p + i * y1 * p + u * s * g - i * d * g) * S, t[2] = (o * y1 * n - m * a * n + m * s * l - i * y1 * l - o * s * g + i * a * g) * S, t[3] = (u * a * n - o * d * n - u * s * l + i * d * l + o * s * p - i * a * p) * S, t[4] = b * S, t[5] = (c * y1 * n - f * d * n + f * s * p - e * y1 * p - c * s * g + e * d * g) * S, t[6] = (f * a * n - r * y1 * n - f * s * l + e * y1 * l + r * s * g - e * a * g) * S, t[7] = (r * d * n - c * a * n + c * s * l - e * d * l - r * s * p + e * a * p) * S, t[8] = M * S, t[9] = (f * u * n - c * m * n - f * i * p + e * m * p + c * i * g - e * u * g) * S, t[10] = (r * m * n - f * o * n + f * i * l - e * m * l - r * i * g + e * o * g) * S, t[11] = (c * o * n - r * u * n - c * i * l + e * u * l + r * i * p - e * o * p) * S, t[12] = _ * S, t[13] = (c * m * s - f * u * s + f * i * d - e * m * d - c * i * y1 + e * u * y1) * S, t[14] = (f * o * s - r * m * s - f * i * a + e * m * a + r * i * y1 - e * o * y1) * S, t[15] = (r * u * s - c * o * s + c * i * a - e * u * a - r * i * d + e * o * d) * S, this;
    }
    scale(t) {
        let e = this.elements, i = t.x, s = t.y, n = t.z;
        return e[0] *= i, e[4] *= s, e[8] *= n, e[1] *= i, e[5] *= s, e[9] *= n, e[2] *= i, e[6] *= s, e[10] *= n, e[3] *= i, e[7] *= s, e[11] *= n, this;
    }
    getMaxScaleOnAxis() {
        let t = this.elements, e = t[0] * t[0] + t[1] * t[1] + t[2] * t[2], i = t[4] * t[4] + t[5] * t[5] + t[6] * t[6], s = t[8] * t[8] + t[9] * t[9] + t[10] * t[10];
        return Math.sqrt(Math.max(e, i, s));
    }
    makeTranslation(t, e, i) {
        return t.isVector3 ? this.set(1, 0, 0, t.x, 0, 1, 0, t.y, 0, 0, 1, t.z, 0, 0, 0, 1) : this.set(1, 0, 0, t, 0, 1, 0, e, 0, 0, 1, i, 0, 0, 0, 1), this;
    }
    makeRotationX(t) {
        let e = Math.cos(t), i = Math.sin(t);
        return this.set(1, 0, 0, 0, 0, e, -i, 0, 0, i, e, 0, 0, 0, 0, 1), this;
    }
    makeRotationY(t) {
        let e = Math.cos(t), i = Math.sin(t);
        return this.set(e, 0, i, 0, 0, 1, 0, 0, -i, 0, e, 0, 0, 0, 0, 1), this;
    }
    makeRotationZ(t) {
        let e = Math.cos(t), i = Math.sin(t);
        return this.set(e, -i, 0, 0, i, e, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), this;
    }
    makeRotationAxis(t, e) {
        let i = Math.cos(e), s = Math.sin(e), n = 1 - i, r = t.x, o = t.y, a = t.z, l = n * r, c = n * o;
        return this.set(l * r + i, l * o - s * a, l * a + s * o, 0, l * o + s * a, c * o + i, c * a - s * r, 0, l * a - s * o, c * a + s * r, n * a * a + i, 0, 0, 0, 0, 1), this;
    }
    makeScale(t, e, i) {
        return this.set(t, 0, 0, 0, 0, e, 0, 0, 0, 0, i, 0, 0, 0, 0, 1), this;
    }
    makeShear(t, e, i, s, n, r) {
        return this.set(1, i, n, 0, t, 1, r, 0, e, s, 1, 0, 0, 0, 0, 1), this;
    }
    compose(t, e, i) {
        let s = this.elements, n = e._x, r = e._y, o = e._z, a = e._w, l = n + n, c = r + r, u = o + o, d = n * l, p = n * c, f = n * u, m = r * c, y1 = r * u, g = o * u, x1 = a * l, b = a * c, M = a * u, _ = i.x, v = i.y, S = i.z;
        return s[0] = (1 - (m + g)) * _, s[1] = (p + M) * _, s[2] = (f - b) * _, s[3] = 0, s[4] = (p - M) * v, s[5] = (1 - (d + g)) * v, s[6] = (y1 + x1) * v, s[7] = 0, s[8] = (f + b) * S, s[9] = (y1 - x1) * S, s[10] = (1 - (d + m)) * S, s[11] = 0, s[12] = t.x, s[13] = t.y, s[14] = t.z, s[15] = 1, this;
    }
    decompose(t, e, i) {
        let s = this.elements, n = Ye.set(s[0], s[1], s[2]).length(), r = Ye.set(s[4], s[5], s[6]).length(), o = Ye.set(s[8], s[9], s[10]).length();
        this.determinant() < 0 && (n = -n), t.x = s[12], t.y = s[13], t.z = s[14], Vt.copy(this);
        let l = 1 / n, c = 1 / r, u = 1 / o;
        return Vt.elements[0] *= l, Vt.elements[1] *= l, Vt.elements[2] *= l, Vt.elements[4] *= c, Vt.elements[5] *= c, Vt.elements[6] *= c, Vt.elements[8] *= u, Vt.elements[9] *= u, Vt.elements[10] *= u, e.setFromRotationMatrix(Vt), i.x = n, i.y = r, i.z = o, this;
    }
    makePerspective(t, e, i, s, n, r, o = oe) {
        let a = this.elements, l = 2 * n / (e - t), c = 2 * n / (i - s), u = (e + t) / (e - t), d = (i + s) / (i - s), p, f;
        if (o === oe) p = -(r + n) / (r - n), f = -2 * r * n / (r - n);
        else if (o === Zs) p = -r / (r - n), f = -r * n / (r - n);
        else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: " + o);
        return a[0] = l, a[4] = 0, a[8] = u, a[12] = 0, a[1] = 0, a[5] = c, a[9] = d, a[13] = 0, a[2] = 0, a[6] = 0, a[10] = p, a[14] = f, a[3] = 0, a[7] = 0, a[11] = -1, a[15] = 0, this;
    }
    makeOrthographic(t, e, i, s, n, r, o = oe) {
        let a = this.elements, l = 1 / (e - t), c = 1 / (i - s), u = 1 / (r - n), d = (e + t) * l, p = (i + s) * c, f, m;
        if (o === oe) f = (r + n) * u, m = -2 * u;
        else if (o === Zs) f = n * u, m = -1 * u;
        else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: " + o);
        return a[0] = 2 * l, a[4] = 0, a[8] = 0, a[12] = -d, a[1] = 0, a[5] = 2 * c, a[9] = 0, a[13] = -p, a[2] = 0, a[6] = 0, a[10] = m, a[14] = -f, a[3] = 0, a[7] = 0, a[11] = 0, a[15] = 1, this;
    }
    equals(t) {
        let e = this.elements, i = t.elements;
        for(let s = 0; s < 16; s++)if (e[s] !== i[s]) return !1;
        return !0;
    }
    fromArray(t, e = 0) {
        for(let i = 0; i < 16; i++)this.elements[i] = t[i + e];
        return this;
    }
    toArray(t = [], e = 0) {
        let i = this.elements;
        return t[e] = i[0], t[e + 1] = i[1], t[e + 2] = i[2], t[e + 3] = i[3], t[e + 4] = i[4], t[e + 5] = i[5], t[e + 6] = i[6], t[e + 7] = i[7], t[e + 8] = i[8], t[e + 9] = i[9], t[e + 10] = i[10], t[e + 11] = i[11], t[e + 12] = i[12], t[e + 13] = i[13], t[e + 14] = i[14], t[e + 15] = i[15], t;
    }
}, Ye = new w, Vt = new D, yu = new w(0, 0, 0), gu = new w(1, 1, 1), fe = new w, hs = new w, At = new w, xa = new D, ba = new bt, Xt = class h {
    constructor(t = 0, e = 0, i = 0, s = h.DEFAULT_ORDER){
        this.isEuler = !0, this._x = t, this._y = e, this._z = i, this._order = s;
    }
    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 order() {
        return this._order;
    }
    set order(t) {
        this._order = t, this._onChangeCallback();
    }
    set(t, e, i, s = this._order) {
        return this._x = t, this._y = e, this._z = i, this._order = s, this._onChangeCallback(), this;
    }
    clone() {
        return new this.constructor(this._x, this._y, this._z, this._order);
    }
    copy(t) {
        return this._x = t._x, this._y = t._y, this._z = t._z, this._order = t._order, this._onChangeCallback(), this;
    }
    setFromRotationMatrix(t, e = this._order, i = !0) {
        let s = t.elements, n = s[0], r = s[4], o = s[8], a = s[1], l = s[5], c = s[9], u = s[2], d = s[6], p = s[10];
        switch(e){
            case "XYZ":
                this._y = Math.asin(N(o, -1, 1)), Math.abs(o) < .9999999 ? (this._x = Math.atan2(-c, p), this._z = Math.atan2(-r, n)) : (this._x = Math.atan2(d, l), this._z = 0);
                break;
            case "YXZ":
                this._x = Math.asin(-N(c, -1, 1)), Math.abs(c) < .9999999 ? (this._y = Math.atan2(o, p), this._z = Math.atan2(a, l)) : (this._y = Math.atan2(-u, n), this._z = 0);
                break;
            case "ZXY":
                this._x = Math.asin(N(d, -1, 1)), Math.abs(d) < .9999999 ? (this._y = Math.atan2(-u, p), this._z = Math.atan2(-r, l)) : (this._y = 0, this._z = Math.atan2(a, n));
                break;
            case "ZYX":
                this._y = Math.asin(-N(u, -1, 1)), Math.abs(u) < .9999999 ? (this._x = Math.atan2(d, p), this._z = Math.atan2(a, n)) : (this._x = 0, this._z = Math.atan2(-r, l));
                break;
            case "YZX":
                this._z = Math.asin(N(a, -1, 1)), Math.abs(a) < .9999999 ? (this._x = Math.atan2(-c, l), this._y = Math.atan2(-u, n)) : (this._x = 0, this._y = Math.atan2(o, p));
                break;
            case "XZY":
                this._z = Math.asin(-N(r, -1, 1)), Math.abs(r) < .9999999 ? (this._x = Math.atan2(d, l), this._y = Math.atan2(o, n)) : (this._x = Math.atan2(-c, p), this._y = 0);
                break;
            default:
                console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: " + e);
        }
        return this._order = e, i === !0 && this._onChangeCallback(), this;
    }
    setFromQuaternion(t, e, i) {
        return xa.makeRotationFromQuaternion(t), this.setFromRotationMatrix(xa, e, i);
    }
    setFromVector3(t, e = this._order) {
        return this.set(t.x, t.y, t.z, e);
    }
    reorder(t) {
        return ba.setFromEuler(this), this.setFromQuaternion(ba, t);
    }
    equals(t) {
        return t._x === this._x && t._y === this._y && t._z === this._z && t._order === this._order;
    }
    fromArray(t) {
        return this._x = t[0], this._y = t[1], this._z = t[2], t[3] !== void 0 && (this._order = t[3]), this._onChangeCallback(), this;
    }
    toArray(t = [], e = 0) {
        return t[e] = this._x, t[e + 1] = this._y, t[e + 2] = this._z, t[e + 3] = this._order, t;
    }
    _onChange(t) {
        return this._onChangeCallback = t, this;
    }
    _onChangeCallback() {}
    *[Symbol.iterator]() {
        yield this._x, yield this._y, yield this._z, yield this._order;
    }
};
Xt.DEFAULT_ORDER = "XYZ";
var js = class {
    constructor(){
        this.mask = 1;
    }
    set(t) {
        this.mask = (1 << t | 0) >>> 0;
    }
    enable(t) {
        this.mask |= 1 << t | 0;
    }
    enableAll() {
        this.mask = -1;
    }
    toggle(t) {
        this.mask ^= 1 << t | 0;
    }
    disable(t) {
        this.mask &= ~(1 << t | 0);
    }
    disableAll() {
        this.mask = 0;
    }
    test(t) {
        return (this.mask & t.mask) !== 0;
    }
    isEnabled(t) {
        return (this.mask & (1 << t | 0)) !== 0;
    }
}, xu = 0, wa = new w, $e = new bt, te = new D, ls = new w, Ti = new w, bu = new w, wu = new bt, Ma = new w(1, 0, 0), _a = new w(0, 1, 0), va = new w(0, 0, 1), Aa = {
    type: "added"
}, Mu = {
    type: "removed"
}, Qe = {
    type: "childadded",
    child: null
}, Dn = {
    type: "childremoved",
    child: null
}, G = class h extends qt {
    constructor(){
        super(), this.isObject3D = !0, Object.defineProperty(this, "id", {
            value: xu++
        }), this.uuid = It(), this.name = "", this.type = "Object3D", this.parent = null, this.children = [], this.up = h.DEFAULT_UP.clone();
        let t = new w, e = new Xt, i = new bt, s = new w(1, 1, 1);
        function n() {
            i.setFromEuler(e, !1);
        }
        function r() {
            e.setFromQuaternion(i, void 0, !1);
        }
        e._onChange(n), i._onChange(r), Object.defineProperties(this, {
            position: {
                configurable: !0,
                enumerable: !0,
                value: t
            },
            rotation: {
                configurable: !0,
                enumerable: !0,
                value: e
            },
            quaternion: {
                configurable: !0,
                enumerable: !0,
                value: i
            },
            scale: {
                configurable: !0,
                enumerable: !0,
                value: s
            },
            modelViewMatrix: {
                value: new D
            },
            normalMatrix: {
                value: new Gt
            }
        }), this.matrix = new D, this.matrixWorld = new D, this.matrixAutoUpdate = h.DEFAULT_MATRIX_AUTO_UPDATE, this.matrixWorldAutoUpdate = h.DEFAULT_MATRIX_WORLD_AUTO_UPDATE, this.matrixWorldNeedsUpdate = !1, this.layers = new js, this.visible = !0, this.castShadow = !1, this.receiveShadow = !1, this.frustumCulled = !0, this.renderOrder = 0, this.animations = [], this.userData = {};
    }
    onBeforeShadow() {}
    onAfterShadow() {}
    onBeforeRender() {}
    onAfterRender() {}
    applyMatrix4(t) {
        this.matrixAutoUpdate && this.updateMatrix(), this.matrix.premultiply(t), this.matrix.decompose(this.position, this.quaternion, this.scale);
    }
    applyQuaternion(t) {
        return this.quaternion.premultiply(t), this;
    }
    setRotationFromAxisAngle(t, e) {
        this.quaternion.setFromAxisAngle(t, e);
    }
    setRotationFromEuler(t) {
        this.quaternion.setFromEuler(t, !0);
    }
    setRotationFromMatrix(t) {
        this.quaternion.setFromRotationMatrix(t);
    }
    setRotationFromQuaternion(t) {
        this.quaternion.copy(t);
    }
    rotateOnAxis(t, e) {
        return $e.setFromAxisAngle(t, e), this.quaternion.multiply($e), this;
    }
    rotateOnWorldAxis(t, e) {
        return $e.setFromAxisAngle(t, e), this.quaternion.premultiply($e), this;
    }
    rotateX(t) {
        return this.rotateOnAxis(Ma, t);
    }
    rotateY(t) {
        return this.rotateOnAxis(_a, t);
    }
    rotateZ(t) {
        return this.rotateOnAxis(va, t);
    }
    translateOnAxis(t, e) {
        return wa.copy(t).applyQuaternion(this.quaternion), this.position.add(wa.multiplyScalar(e)), this;
    }
    translateX(t) {
        return this.translateOnAxis(Ma, t);
    }
    translateY(t) {
        return this.translateOnAxis(_a, t);
    }
    translateZ(t) {
        return this.translateOnAxis(va, t);
    }
    localToWorld(t) {
        return this.updateWorldMatrix(!0, !1), t.applyMatrix4(this.matrixWorld);
    }
    worldToLocal(t) {
        return this.updateWorldMatrix(!0, !1), t.applyMatrix4(te.copy(this.matrixWorld).invert());
    }
    lookAt(t, e, i) {
        t.isVector3 ? ls.copy(t) : ls.set(t, e, i);
        let s = this.parent;
        this.updateWorldMatrix(!0, !1), Ti.setFromMatrixPosition(this.matrixWorld), this.isCamera || this.isLight ? te.lookAt(Ti, ls, this.up) : te.lookAt(ls, Ti, this.up), this.quaternion.setFromRotationMatrix(te), s && (te.extractRotation(s.matrixWorld), $e.setFromRotationMatrix(te), this.quaternion.premultiply($e.invert()));
    }
    add(t) {
        if (arguments.length > 1) {
            for(let e = 0; e < arguments.length; e++)this.add(arguments[e]);
            return this;
        }
        return t === this ? (console.error("THREE.Object3D.add: object can't be added as a child of itself.", t), this) : (t && t.isObject3D ? (t.removeFromParent(), t.parent = this, this.children.push(t), t.dispatchEvent(Aa), Qe.child = t, this.dispatchEvent(Qe), Qe.child = null) : console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", t), this);
    }
    remove(t) {
        if (arguments.length > 1) {
            for(let i = 0; i < arguments.length; i++)this.remove(arguments[i]);
            return this;
        }
        let e = this.children.indexOf(t);
        return e !== -1 && (t.parent = null, this.children.splice(e, 1), t.dispatchEvent(Mu), Dn.child = t, this.dispatchEvent(Dn), Dn.child = null), this;
    }
    removeFromParent() {
        let t = this.parent;
        return t !== null && t.remove(this), this;
    }
    clear() {
        return this.remove(...this.children);
    }
    attach(t) {
        return this.updateWorldMatrix(!0, !1), te.copy(this.matrixWorld).invert(), t.parent !== null && (t.parent.updateWorldMatrix(!0, !1), te.multiply(t.parent.matrixWorld)), t.applyMatrix4(te), t.removeFromParent(), t.parent = this, this.children.push(t), t.updateWorldMatrix(!1, !0), t.dispatchEvent(Aa), Qe.child = t, this.dispatchEvent(Qe), Qe.child = null, this;
    }
    getObjectById(t) {
        return this.getObjectByProperty("id", t);
    }
    getObjectByName(t) {
        return this.getObjectByProperty("name", t);
    }
    getObjectByProperty(t, e) {
        if (this[t] === e) return this;
        for(let i = 0, s = this.children.length; i < s; i++){
            let r = this.children[i].getObjectByProperty(t, e);
            if (r !== void 0) return r;
        }
    }
    getObjectsByProperty(t, e, i = []) {
        this[t] === e && i.push(this);
        let s = this.children;
        for(let n = 0, r = s.length; n < r; n++)s[n].getObjectsByProperty(t, e, i);
        return i;
    }
    getWorldPosition(t) {
        return this.updateWorldMatrix(!0, !1), t.setFromMatrixPosition(this.matrixWorld);
    }
    getWorldQuaternion(t) {
        return this.updateWorldMatrix(!0, !1), this.matrixWorld.decompose(Ti, t, bu), t;
    }
    getWorldScale(t) {
        return this.updateWorldMatrix(!0, !1), this.matrixWorld.decompose(Ti, wu, t), t;
    }
    getWorldDirection(t) {
        this.updateWorldMatrix(!0, !1);
        let e = this.matrixWorld.elements;
        return t.set(e[8], e[9], e[10]).normalize();
    }
    raycast() {}
    traverse(t) {
        t(this);
        let e = this.children;
        for(let i = 0, s = e.length; i < s; i++)e[i].traverse(t);
    }
    traverseVisible(t) {
        if (this.visible === !1) return;
        t(this);
        let e = this.children;
        for(let i = 0, s = e.length; i < s; i++)e[i].traverseVisible(t);
    }
    traverseAncestors(t) {
        let e = this.parent;
        e !== null && (t(e), e.traverseAncestors(t));
    }
    updateMatrix() {
        this.matrix.compose(this.position, this.quaternion, this.scale), this.matrixWorldNeedsUpdate = !0;
    }
    updateMatrixWorld(t) {
        this.matrixAutoUpdate && this.updateMatrix(), (this.matrixWorldNeedsUpdate || t) && (this.matrixWorldAutoUpdate === !0 && (this.parent === null ? this.matrixWorld.copy(this.matrix) : this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix)), this.matrixWorldNeedsUpdate = !1, t = !0);
        let e = this.children;
        for(let i = 0, s = e.length; i < s; i++)e[i].updateMatrixWorld(t);
    }
    updateWorldMatrix(t, e) {
        let i = this.parent;
        if (t === !0 && i !== null && i.updateWorldMatrix(!0, !1), this.matrixAutoUpdate && this.updateMatrix(), this.matrixWorldAutoUpdate === !0 && (this.parent === null ? this.matrixWorld.copy(this.matrix) : this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix)), e === !0) {
            let s = this.children;
            for(let n = 0, r = s.length; n < r; n++)s[n].updateWorldMatrix(!1, !0);
        }
    }
    toJSON(t) {
        let e = t === void 0 || typeof t == "string", i = {};
        e && (t = {
            geometries: {},
            materials: {},
            textures: {},
            images: {},
            shapes: {},
            skeletons: {},
            animations: {},
            nodes: {}
        }, i.metadata = {
            version: 4.6,
            type: "Object",
            generator: "Object3D.toJSON"
        });
        let s = {};
        s.uuid = this.uuid, s.type = this.type, this.name !== "" && (s.name = this.name), this.castShadow === !0 && (s.castShadow = !0), this.receiveShadow === !0 && (s.receiveShadow = !0), this.visible === !1 && (s.visible = !1), this.frustumCulled === !1 && (s.frustumCulled = !1), this.renderOrder !== 0 && (s.renderOrder = this.renderOrder), Object.keys(this.userData).length > 0 && (s.userData = this.userData), s.layers = this.layers.mask, s.matrix = this.matrix.toArray(), s.up = this.up.toArray(), this.matrixAutoUpdate === !1 && (s.matrixAutoUpdate = !1), this.isInstancedMesh && (s.type = "InstancedMesh", s.count = this.count, s.instanceMatrix = this.instanceMatrix.toJSON(), this.instanceColor !== null && (s.instanceColor = this.instanceColor.toJSON())), this.isBatchedMesh && (s.type = "BatchedMesh", s.perObjectFrustumCulled = this.perObjectFrustumCulled, s.sortObjects = this.sortObjects, s.drawRanges = this._drawRanges, s.reservedRanges = this._reservedRanges, s.visibility = this._visibility, s.active = this._active, s.bounds = this._bounds.map((o)=>({
                boxInitialized: o.boxInitialized,
                boxMin: o.box.min.toArray(),
                boxMax: o.box.max.toArray(),
                sphereInitialized: o.sphereInitialized,
                sphereRadius: o.sphere.radius,
                sphereCenter: o.sphere.center.toArray()
            })), s.maxInstanceCount = this._maxInstanceCount, s.maxVertexCount = this._maxVertexCount, s.maxIndexCount = this._maxIndexCount, s.geometryInitialized = this._geometryInitialized, s.geometryCount = this._geometryCount, s.matricesTexture = this._matricesTexture.toJSON(t), this._colorsTexture !== null && (s.colorsTexture = this._colorsTexture.toJSON(t)), this.boundingSphere !== null && (s.boundingSphere = {
            center: s.boundingSphere.center.toArray(),
            radius: s.boundingSphere.radius
        }), this.boundingBox !== null && (s.boundingBox = {
            min: s.boundingBox.min.toArray(),
            max: s.boundingBox.max.toArray()
        }));
        function n(o, a) {
            return o[a.uuid] === void 0 && (o[a.uuid] = a.toJSON(t)), a.uuid;
        }
        if (this.isScene) this.background && (this.background.isColor ? s.background = this.background.toJSON() : this.background.isTexture && (s.background = this.background.toJSON(t).uuid)), this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== !0 && (s.environment = this.environment.toJSON(t).uuid);
        else if (this.isMesh || this.isLine || this.isPoints) {
            s.geometry = n(t.geometries, this.geometry);
            let o = this.geometry.parameters;
            if (o !== void 0 && o.shapes !== void 0) {
                let a = o.shapes;
                if (Array.isArray(a)) for(let l = 0, c = a.length; l < c; l++){
                    let u = a[l];
                    n(t.shapes, u);
                }
                else n(t.shapes, a);
            }
        }
        if (this.isSkinnedMesh && (s.bindMode = this.bindMode, s.bindMatrix = this.bindMatrix.toArray(), this.skeleton !== void 0 && (n(t.skeletons, this.skeleton), s.skeleton = this.skeleton.uuid)), this.material !== void 0) if (Array.isArray(this.material)) {
            let o = [];
            for(let a = 0, l = this.material.length; a < l; a++)o.push(n(t.materials, this.material[a]));
            s.material = o;
        } else s.material = n(t.materials, this.material);
        if (this.children.length > 0) {
            s.children = [];
            for(let o = 0; o < this.children.length; o++)s.children.push(this.children[o].toJSON(t).object);
        }
        if (this.animations.length > 0) {
            s.animations = [];
            for(let o = 0; o < this.animations.length; o++){
                let a = this.animations[o];
                s.animations.push(n(t.animations, a));
            }
        }
        if (e) {
            let o = r(t.geometries), a = r(t.materials), l = r(t.textures), c = r(t.images), u = r(t.shapes), d = r(t.skeletons), p = r(t.animations), f = r(t.nodes);
            o.length > 0 && (i.geometries = o), a.length > 0 && (i.materials = a), l.length > 0 && (i.textures = l), c.length > 0 && (i.images = c), u.length > 0 && (i.shapes = u), d.length > 0 && (i.skeletons = d), p.length > 0 && (i.animations = p), f.length > 0 && (i.nodes = f);
        }
        return i.object = s, i;
        function r(o) {
            let a = [];
            for(let l in o){
                let c = o[l];
                delete c.metadata, a.push(c);
            }
            return a;
        }
    }
    clone(t) {
        return new this.constructor().copy(this, t);
    }
    copy(t, e = !0) {
        if (this.name = t.name, this.up.copy(t.up), this.position.copy(t.position), this.rotation.order = t.rotation.order, this.quaternion.copy(t.quaternion), this.scale.copy(t.scale), this.matrix.copy(t.matrix), this.matrixWorld.copy(t.matrixWorld), this.matrixAutoUpdate = t.matrixAutoUpdate, this.matrixWorldAutoUpdate = t.matrixWorldAutoUpdate, this.matrixWorldNeedsUpdate = t.matrixWorldNeedsUpdate, this.layers.mask = t.layers.mask, this.visible = t.visible, this.castShadow = t.castShadow, this.receiveShadow = t.receiveShadow, this.frustumCulled = t.frustumCulled, this.renderOrder = t.renderOrder, this.animations = t.animations.slice(), this.userData = JSON.parse(JSON.stringify(t.userData)), e === !0) for(let i = 0; i < t.children.length; i++){
            let s = t.children[i];
            this.add(s.clone());
        }
        return this;
    }
};
G.DEFAULT_UP = new w(0, 1, 0);
G.DEFAULT_MATRIX_AUTO_UPDATE = !0;
G.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = !0;
var Dt = new w, ee = new w, Ln = new w, ie = new w, je = new w, Ke = new w, Sa = new w, Un = new w, Wn = new w, Hn = new w, qn = new ot, Gn = new ot, Xn = new ot, ne = class h {
    constructor(t = new w, e = new w, i = new w){
        this.a = t, this.b = e, this.c = i;
    }
    static getNormal(t, e, i, s) {
        s.subVectors(i, e), Dt.subVectors(t, e), s.cross(Dt);
        let n = s.lengthSq();
        return n > 0 ? s.multiplyScalar(1 / Math.sqrt(n)) : s.set(0, 0, 0);
    }
    static getBarycoord(t, e, i, s, n) {
        Dt.subVectors(s, e), ee.subVectors(i, e), Ln.subVectors(t, e);
        let r = Dt.dot(Dt), o = Dt.dot(ee), a = Dt.dot(Ln), l = ee.dot(ee), c = ee.dot(Ln), u = r * l - o * o;
        if (u === 0) return n.set(0, 0, 0), null;
        let d = 1 / u, p = (l * a - o * c) * d, f = (r * c - o * a) * d;
        return n.set(1 - p - f, f, p);
    }
    static containsPoint(t, e, i, s) {
        return this.getBarycoord(t, e, i, s, ie) === null ? !1 : ie.x >= 0 && ie.y >= 0 && ie.x + ie.y <= 1;
    }
    static getInterpolation(t, e, i, s, n, r, o, a) {
        return this.getBarycoord(t, e, i, s, ie) === null ? (a.x = 0, a.y = 0, "z" in a && (a.z = 0), "w" in a && (a.w = 0), null) : (a.setScalar(0), a.addScaledVector(n, ie.x), a.addScaledVector(r, ie.y), a.addScaledVector(o, ie.z), a);
    }
    static getInterpolatedAttribute(t, e, i, s, n, r) {
        return qn.setScalar(0), Gn.setScalar(0), Xn.setScalar(0), qn.fromBufferAttribute(t, e), Gn.fromBufferAttribute(t, i), Xn.fromBufferAttribute(t, s), r.setScalar(0), r.addScaledVector(qn, n.x), r.addScaledVector(Gn, n.y), r.addScaledVector(Xn, n.z), r;
    }
    static isFrontFacing(t, e, i, s) {
        return Dt.subVectors(i, e), ee.subVectors(t, e), Dt.cross(ee).dot(s) < 0;
    }
    set(t, e, i) {
        return this.a.copy(t), this.b.copy(e), this.c.copy(i), this;
    }
    setFromPointsAndIndices(t, e, i, s) {
        return this.a.copy(t[e]), this.b.copy(t[i]), this.c.copy(t[s]), this;
    }
    setFromAttributeAndIndices(t, e, i, s) {
        return this.a.fromBufferAttribute(t, e), this.b.fromBufferAttribute(t, i), this.c.fromBufferAttribute(t, s), this;
    }
    clone() {
        return new this.constructor().copy(this);
    }
    copy(t) {
        return this.a.copy(t.a), this.b.copy(t.b), this.c.copy(t.c), this;
    }
    getArea() {
        return Dt.subVectors(this.c, this.b), ee.subVectors(this.a, this.b), Dt.cross(ee).length() * .5;
    }
    getMidpoint(t) {
        return t.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
    }
    getNormal(t) {
        return h.getNormal(this.a, this.b, this.c, t);
    }
    getPlane(t) {
        return t.setFromCoplanarPoints(this.a, this.b, this.c);
    }
    getBarycoord(t, e) {
        return h.getBarycoord(t, this.a, this.b, this.c, e);
    }
    getInterpolation(t, e, i, s, n) {
        return h.getInterpolation(t, this.a, this.b, this.c, e, i, s, n);
    }
    containsPoint(t) {
        return h.containsPoint(t, this.a, this.b, this.c);
    }
    isFrontFacing(t) {
        return h.isFrontFacing(this.a, this.b, this.c, t);
    }
    intersectsBox(t) {
        return t.intersectsTriangle(this);
    }
    closestPointToPoint(t, e) {
        let i = this.a, s = this.b, n = this.c, r, o;
        je.subVectors(s, i), Ke.subVectors(n, i), Un.subVectors(t, i);
        let a = je.dot(Un), l = Ke.dot(Un);
        if (a <= 0 && l <= 0) return e.copy(i);
        Wn.subVectors(t, s);
        let c = je.dot(Wn), u = Ke.dot(Wn);
        if (c >= 0 && u <= c) return e.copy(s);
        let d = a * u - c * l;
        if (d <= 0 && a >= 0 && c <= 0) return r = a / (a - c), e.copy(i).addScaledVector(je, r);
        Hn.subVectors(t, n);
        let p = je.dot(Hn), f = Ke.dot(Hn);
        if (f >= 0 && p <= f) return e.copy(n);
        let m = p * l - a * f;
        if (m <= 0 && l >= 0 && f <= 0) return o = l / (l - f), e.copy(i).addScaledVector(Ke, o);
        let y1 = c * f - p * u;
        if (y1 <= 0 && u - c >= 0 && p - f >= 0) return Sa.subVectors(n, s), o = (u - c) / (u - c + (p - f)), e.copy(s).addScaledVector(Sa, o);
        let g = 1 / (y1 + m + d);
        return r = m * g, o = d * g, e.copy(i).addScaledVector(je, r).addScaledVector(Ke, o);
    }
    equals(t) {
        return t.a.equals(this.a) && t.b.equals(this.b) && t.c.equals(this.c);
    }
}, Fl = {
    aliceblue: 15792383,
    antiquewhite: 16444375,
    aqua: 65535,
    aquamarine: 8388564,
    azure: 15794175,
    beige: 16119260,
    bisque: 16770244,
    black: 0,
    blanchedalmond: 16772045,
    blue: 255,
    blueviolet: 9055202,
    brown: 10824234,
    burlywood: 14596231,
    cadetblue: 6266528,
    chartreuse: 8388352,
    chocolate: 13789470,
    coral: 16744272,
    cornflowerblue: 6591981,
    cornsilk: 16775388,
    crimson: 14423100,
    cyan: 65535,
    darkblue: 139,
    darkcyan: 35723,
    darkgoldenrod: 12092939,
    darkgray: 11119017,
    darkgreen: 25600,
    darkgrey: 11119017,
    darkkhaki: 12433259,
    darkmagenta: 9109643,
    darkolivegreen: 5597999,
    darkorange: 16747520,
    darkorchid: 10040012,
    darkred: 9109504,
    darksalmon: 15308410,
    darkseagreen: 9419919,
    darkslateblue: 4734347,
    darkslategray: 3100495,
    darkslategrey: 3100495,
    darkturquoise: 52945,
    darkviolet: 9699539,
    deeppink: 16716947,
    deepskyblue: 49151,
    dimgray: 6908265,
    dimgrey: 6908265,
    dodgerblue: 2003199,
    firebrick: 11674146,
    floralwhite: 16775920,
    forestgreen: 2263842,
    fuchsia: 16711935,
    gainsboro: 14474460,
    ghostwhite: 16316671,
    gold: 16766720,
    goldenrod: 14329120,
    gray: 8421504,
    green: 32768,
    greenyellow: 11403055,
    grey: 8421504,
    honeydew: 15794160,
    hotpink: 16738740,
    indianred: 13458524,
    indigo: 4915330,
    ivory: 16777200,
    khaki: 15787660,
    lavender: 15132410,
    lavenderblush: 16773365,
    lawngreen: 8190976,
    lemonchiffon: 16775885,
    lightblue: 11393254,
    lightcoral: 15761536,
    lightcyan: 14745599,
    lightgoldenrodyellow: 16448210,
    lightgray: 13882323,
    lightgreen: 9498256,
    lightgrey: 13882323,
    lightpink: 16758465,
    lightsalmon: 16752762,
    lightseagreen: 2142890,
    lightskyblue: 8900346,
    lightslategray: 7833753,
    lightslategrey: 7833753,
    lightsteelblue: 11584734,
    lightyellow: 16777184,
    lime: 65280,
    limegreen: 3329330,
    linen: 16445670,
    magenta: 16711935,
    maroon: 8388608,
    mediumaquamarine: 6737322,
    mediumblue: 205,
    mediumorchid: 12211667,
    mediumpurple: 9662683,
    mediumseagreen: 3978097,
    mediumslateblue: 8087790,
    mediumspringgreen: 64154,
    mediumturquoise: 4772300,
    mediumvioletred: 13047173,
    midnightblue: 1644912,
    mintcream: 16121850,
    mistyrose: 16770273,
    moccasin: 16770229,
    navajowhite: 16768685,
    navy: 128,
    oldlace: 16643558,
    olive: 8421376,
    olivedrab: 7048739,
    orange: 16753920,
    orangered: 16729344,
    orchid: 14315734,
    palegoldenrod: 15657130,
    palegreen: 10025880,
    paleturquoise: 11529966,
    palevioletred: 14381203,
    papayawhip: 16773077,
    peachpuff: 16767673,
    peru: 13468991,
    pink: 16761035,
    plum: 14524637,
    powderblue: 11591910,
    purple: 8388736,
    rebeccapurple: 6697881,
    red: 16711680,
    rosybrown: 12357519,
    royalblue: 4286945,
    saddlebrown: 9127187,
    salmon: 16416882,
    sandybrown: 16032864,
    seagreen: 3050327,
    seashell: 16774638,
    sienna: 10506797,
    silver: 12632256,
    skyblue: 8900331,
    slateblue: 6970061,
    slategray: 7372944,
    slategrey: 7372944,
    snow: 16775930,
    springgreen: 65407,
    steelblue: 4620980,
    tan: 13808780,
    teal: 32896,
    thistle: 14204888,
    tomato: 16737095,
    turquoise: 4251856,
    violet: 15631086,
    wheat: 16113331,
    white: 16777215,
    whitesmoke: 16119285,
    yellow: 16776960,
    yellowgreen: 10145074
}, me = {
    h: 0,
    s: 0,
    l: 0
}, cs = {
    h: 0,
    s: 0,
    l: 0
};
function Jn(h, t, e) {
    return e < 0 && (e += 1), e > 1 && (e -= 1), e < 1 / 6 ? h + (t - h) * 6 * e : e < 1 / 2 ? t : e < 2 / 3 ? h + (t - h) * 6 * (2 / 3 - e) : h;
}
var P = class {
    constructor(t, e, i){
        return this.isColor = !0, this.r = 1, this.g = 1, this.b = 1, this.set(t, e, i);
    }
    set(t, e, i) {
        if (e === void 0 && i === void 0) {
            let s = t;
            s && s.isColor ? this.copy(s) : typeof s == "number" ? this.setHex(s) : typeof s == "string" && this.setStyle(s);
        } else this.setRGB(t, e, i);
        return this;
    }
    setScalar(t) {
        return this.r = t, this.g = t, this.b = t, this;
    }
    setHex(t, e = Bt) {
        return t = Math.floor(t), this.r = (t >> 16 & 255) / 255, this.g = (t >> 8 & 255) / 255, this.b = (t & 255) / 255, Tt.toWorkingColorSpace(this, e), this;
    }
    setRGB(t, e, i, s = Tt.workingColorSpace) {
        return this.r = t, this.g = e, this.b = i, Tt.toWorkingColorSpace(this, s), this;
    }
    setHSL(t, e, i, s = Tt.workingColorSpace) {
        if (t = qo(t, 1), e = N(e, 0, 1), i = N(i, 0, 1), e === 0) this.r = this.g = this.b = i;
        else {
            let n = i <= .5 ? i * (1 + e) : i + e - i * e, r = 2 * i - n;
            this.r = Jn(r, n, t + 1 / 3), this.g = Jn(r, n, t), this.b = Jn(r, n, t - 1 / 3);
        }
        return Tt.toWorkingColorSpace(this, s), this;
    }
    setStyle(t, e = Bt) {
        function i(n) {
            n !== void 0 && parseFloat(n) < 1 && console.warn("THREE.Color: Alpha component of " + t + " will be ignored.");
        }
        let s;
        if (s = /^(\w+)\(([^\)]*)\)/.exec(t)) {
            let n, r = s[1], o = s[2];
            switch(r){
                case "rgb":
                case "rgba":
                    if (n = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o)) return i(n[4]), this.setRGB(Math.min(255, parseInt(n[1], 10)) / 255, Math.min(255, parseInt(n[2], 10)) / 255, Math.min(255, parseInt(n[3], 10)) / 255, e);
                    if (n = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o)) return i(n[4]), this.setRGB(Math.min(100, parseInt(n[1], 10)) / 100, Math.min(100, parseInt(n[2], 10)) / 100, Math.min(100, parseInt(n[3], 10)) / 100, e);
                    break;
                case "hsl":
                case "hsla":
                    if (n = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o)) return i(n[4]), this.setHSL(parseFloat(n[1]) / 360, parseFloat(n[2]) / 100, parseFloat(n[3]) / 100, e);
                    break;
                default:
                    console.warn("THREE.Color: Unknown color model " + t);
            }
        } else if (s = /^\#([A-Fa-f\d]+)$/.exec(t)) {
            let n = s[1], r = n.length;
            if (r === 3) return this.setRGB(parseInt(n.charAt(0), 16) / 15, parseInt(n.charAt(1), 16) / 15, parseInt(n.charAt(2), 16) / 15, e);
            if (r === 6) return this.setHex(parseInt(n, 16), e);
            console.warn("THREE.Color: Invalid hex color " + t);
        } else if (t && t.length > 0) return this.setColorName(t, e);
        return this;
    }
    setColorName(t, e = Bt) {
        let i = Fl[t.toLowerCase()];
        return i !== void 0 ? this.setHex(i, e) : console.warn("THREE.Color: Unknown color " + t), this;
    }
    clone() {
        return new this.constructor(this.r, this.g, this.b);
    }
    copy(t) {
        return this.r = t.r, this.g = t.g, this.b = t.b, this;
    }
    copySRGBToLinear(t) {
        return this.r = ae(t.r), this.g = ae(t.g), this.b = ae(t.b), this;
    }
    copyLinearToSRGB(t) {
        return this.r = di(t.r), this.g = di(t.g), this.b = di(t.b), this;
    }
    convertSRGBToLinear() {
        return this.copySRGBToLinear(this), this;
    }
    convertLinearToSRGB() {
        return this.copyLinearToSRGB(this), this;
    }
    getHex(t = Bt) {
        return Tt.fromWorkingColorSpace(dt.copy(this), t), Math.round(N(dt.r * 255, 0, 255)) * 65536 + Math.round(N(dt.g * 255, 0, 255)) * 256 + Math.round(N(dt.b * 255, 0, 255));
    }
    getHexString(t = Bt) {
        return ("000000" + this.getHex(t).toString(16)).slice(-6);
    }
    getHSL(t, e = Tt.workingColorSpace) {
        Tt.fromWorkingColorSpace(dt.copy(this), e);
        let i = dt.r, s = dt.g, n = dt.b, r = Math.max(i, s, n), o = Math.min(i, s, n), a, l, c = (o + r) / 2;
        if (o === r) a = 0, l = 0;
        else {
            let u = r - o;
            switch(l = c <= .5 ? u / (r + o) : u / (2 - r - o), r){
                case i:
                    a = (s - n) / u + (s < n ? 6 : 0);
                    break;
                case s:
                    a = (n - i) / u + 2;
                    break;
                case n:
                    a = (i - s) / u + 4;
                    break;
            }
            a /= 6;
        }
        return t.h = a, t.s = l, t.l = c, t;
    }
    getRGB(t, e = Tt.workingColorSpace) {
        return Tt.fromWorkingColorSpace(dt.copy(this), e), t.r = dt.r, t.g = dt.g, t.b = dt.b, t;
    }
    getStyle(t = Bt) {
        Tt.fromWorkingColorSpace(dt.copy(this), t);
        let e = dt.r, i = dt.g, s = dt.b;
        return t !== Bt ? `color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${s.toFixed(3)})` : `rgb(${Math.round(e * 255)},${Math.round(i * 255)},${Math.round(s * 255)})`;
    }
    offsetHSL(t, e, i) {
        return this.getHSL(me), this.setHSL(me.h + t, me.s + e, me.l + i);
    }
    add(t) {
        return this.r += t.r, this.g += t.g, this.b += t.b, this;
    }
    addColors(t, e) {
        return this.r = t.r + e.r, this.g = t.g + e.g, this.b = t.b + e.b, this;
    }
    addScalar(t) {
        return this.r += t, this.g += t, this.b += t, this;
    }
    sub(t) {
        return this.r = Math.max(0, this.r - t.r), this.g = Math.max(0, this.g - t.g), this.b = Math.max(0, this.b - t.b), this;
    }
    multiply(t) {
        return this.r *= t.r, this.g *= t.g, this.b *= t.b, this;
    }
    multiplyScalar(t) {
        return this.r *= t, this.g *= t, this.b *= t, this;
    }
    lerp(t, e) {
        return this.r += (t.r - this.r) * e, this.g += (t.g - this.g) * e, this.b += (t.b - this.b) * e, this;
    }
    lerpColors(t, e, i) {
        return this.r = t.r + (e.r - t.r) * i, this.g = t.g + (e.g - t.g) * i, this.b = t.b + (e.b - t.b) * i, this;
    }
    lerpHSL(t, e) {
        this.getHSL(me), t.getHSL(cs);
        let i = Ni(me.h, cs.h, e), s = Ni(me.s, cs.s, e), n = Ni(me.l, cs.l, e);
        return this.setHSL(i, s, n), this;
    }
    setFromVector3(t) {
        return this.r = t.x, this.g = t.y, this.b = t.z, this;
    }
    applyMatrix3(t) {
        let e = this.r, i = this.g, s = this.b, n = t.elements;
        return this.r = n[0] * e + n[3] * i + n[6] * s, this.g = n[1] * e + n[4] * i + n[7] * s, this.b = n[2] * e + n[5] * i + n[8] * s, this;
    }
    equals(t) {
        return t.r === this.r && t.g === this.g && t.b === this.b;
    }
    fromArray(t, e = 0) {
        return this.r = t[e], this.g = t[e + 1], this.b = t[e + 2], this;
    }
    toArray(t = [], e = 0) {
        return t[e] = this.r, t[e + 1] = this.g, t[e + 2] = this.b, t;
    }
    fromBufferAttribute(t, e) {
        return this.r = t.getX(e), this.g = t.getY(e), this.b = t.getZ(e), this;
    }
    toJSON() {
        return this.getHex();
    }
    *[Symbol.iterator]() {
        yield this.r, yield this.g, yield this.b;
    }
}, dt = new P;
P.NAMES = Fl;
var _u = 0, ct = class extends qt {
    constructor(){
        super(), this.isMaterial = !0, Object.defineProperty(this, "id", {
            value: _u++
        }), this.uuid = It(), this.name = "", this.type = "Material", this.blending = ea, this.side = dr, this.vertexColors = !1, this.opacity = 1, this.transparent = !1, this.alphaHash = !1, this.blendSrc = sa, this.blendDst = na, this.blendEquation = ia, this.blendSrcAlpha = null, this.blendDstAlpha = null, this.blendEquationAlpha = null, this.blendColor = new P(0, 0, 0), this.blendAlpha = 0, this.depthFunc = ra, this.depthTest = !0, this.depthWrite = !0, this.stencilWriteMask = 255, this.stencilFunc = ca, this.stencilRef = 0, this.stencilFuncMask = 255, this.stencilFail = qe, this.stencilZFail = qe, this.stencilZPass = qe, this.stencilWrite = !1, this.clippingPlanes = null, this.clipIntersection = !1, this.clipShadows = !1, this.shadowSide = null, this.colorWrite = !0, this.precision = null, this.polygonOffset = !1, this.polygonOffsetFactor = 0, this.polygonOffsetUnits = 0, this.dithering = !1, this.alphaToCoverage = !1, this.premultipliedAlpha = !1, this.forceSinglePass = !1, this.visible = !0, this.toneMapped = !0, this.userData = {}, this.version = 0, this._alphaTest = 0;
    }
    get alphaTest() {
        return this._alphaTest;
    }
    set alphaTest(t) {
        this._alphaTest > 0 != t > 0 && this.version++, this._alphaTest = t;
    }
    onBeforeRender() {}
    onBeforeCompile() {}
    customProgramCacheKey() {
        return this.onBeforeCompile.toString();
    }
    setValues(t) {
        if (t !== void 0) for(let e in t){
            let i = t[e];
            if (i === void 0) {
                console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);
                continue;
            }
            let s = this[e];
            if (s === void 0) {
                console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`);
                continue;
            }
            s && s.isColor ? s.set(i) : s && s.isVector3 && i && i.isVector3 ? s.copy(i) : this[e] = i;
        }
    }
    toJSON(t) {
        let e = t === void 0 || typeof t == "string";
        e && (t = {
            textures: {},
            images: {}
        });
        let i = {
            metadata: {
                version: 4.6,
                type: "Material",
                generator: "Material.toJSON"
            }
        };
        i.uuid = this.uuid, i.type = this.type, this.name !== "" && (i.name = this.name), this.color && this.color.isColor && (i.color = this.color.getHex()), this.roughness !== void 0 && (i.roughness = this.roughness), this.metalness !== void 0 && (i.metalness = this.metalness), this.sheen !== void 0 && (i.sheen = this.sheen), this.sheenColor && this.sheenColor.isColor && (i.sheenColor = this.sheenColor.getHex()), this.sheenRoughness !== void 0 && (i.sheenRoughness = this.sheenRoughness), this.emissive && this.emissive.isColor && (i.emissive = this.emissive.getHex()), this.emissiveIntensity !== void 0 && this.emissiveIntensity !== 1 && (i.emissiveIntensity = this.emissiveIntensity), this.specular && this.specular.isColor && (i.specular = this.specular.getHex()), this.specularIntensity !== void 0 && (i.specularIntensity = this.specularIntensity), this.specularColor && this.specularColor.isColor && (i.specularColor = this.specularColor.getHex()), this.shininess !== void 0 && (i.shininess = this.shininess), this.clearcoat !== void 0 && (i.clearcoat = this.clearcoat), this.clearcoatRoughness !== void 0 && (i.clearcoatRoughness = this.clearcoatRoughness), this.clearcoatMap && this.clearcoatMap.isTexture && (i.clearcoatMap = this.clearcoatMap.toJSON(t).uuid), this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture && (i.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(t).uuid), this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture && (i.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(t).uuid, i.clearcoatNormalScale = this.clearcoatNormalScale.toArray()), this.dispersion !== void 0 && (i.dispersion = this.dispersion), this.iridescence !== void 0 && (i.iridescence = this.iridescence), this.iridescenceIOR !== void 0 && (i.iridescenceIOR = this.iridescenceIOR), this.iridescenceThicknessRange !== void 0 && (i.iridescenceThicknessRange = this.iridescenceThicknessRange), this.iridescenceMap && this.iridescenceMap.isTexture && (i.iridescenceMap = this.iridescenceMap.toJSON(t).uuid), this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture && (i.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON(t).uuid), this.anisotropy !== void 0 && (i.anisotropy = this.anisotropy), this.anisotropyRotation !== void 0 && (i.anisotropyRotation = this.anisotropyRotation), this.anisotropyMap && this.anisotropyMap.isTexture && (i.anisotropyMap = this.anisotropyMap.toJSON(t).uuid), this.map && this.map.isTexture && (i.map = this.map.toJSON(t).uuid), this.matcap && this.matcap.isTexture && (i.matcap = this.matcap.toJSON(t).uuid), this.alphaMap && this.alphaMap.isTexture && (i.alphaMap = this.alphaMap.toJSON(t).uuid), this.lightMap && this.lightMap.isTexture && (i.lightMap = this.lightMap.toJSON(t).uuid, i.lightMapIntensity = this.lightMapIntensity), this.aoMap && this.aoMap.isTexture && (i.aoMap = this.aoMap.toJSON(t).uuid, i.aoMapIntensity = this.aoMapIntensity), this.bumpMap && this.bumpMap.isTexture && (i.bumpMap = this.bumpMap.toJSON(t).uuid, i.bumpScale = this.bumpScale), this.normalMap && this.normalMap.isTexture && (i.normalMap = this.normalMap.toJSON(t).uuid, i.normalMapType = this.normalMapType, i.normalScale = this.normalScale.toArray()), this.displacementMap && this.displacementMap.isTexture && (i.displacementMap = this.displacementMap.toJSON(t).uuid, i.displacementScale = this.displacementScale, i.displacementBias = this.displacementBias), this.roughnessMap && this.roughnessMap.isTexture && (i.roughnessMap = this.roughnessMap.toJSON(t).uuid), this.metalnessMap && this.metalnessMap.isTexture && (i.metalnessMap = this.metalnessMap.toJSON(t).uuid), this.emissiveMap && this.emissiveMap.isTexture && (i.emissiveMap = this.emissiveMap.toJSON(t).uuid), this.specularMap && this.specularMap.isTexture && (i.specularMap = this.specularMap.toJSON(t).uuid), this.specularIntensityMap && this.specularIntensityMap.isTexture && (i.specularIntensityMap = this.specularIntensityMap.toJSON(t).uuid), this.specularColorMap && this.specularColorMap.isTexture && (i.specularColorMap = this.specularColorMap.toJSON(t).uuid), this.envMap && this.envMap.isTexture && (i.envMap = this.envMap.toJSON(t).uuid, this.combine !== void 0 && (i.combine = this.combine)), this.envMapRotation !== void 0 && (i.envMapRotation = this.envMapRotation.toArray()), this.envMapIntensity !== void 0 && (i.envMapIntensity = this.envMapIntensity), this.reflectivity !== void 0 && (i.reflectivity = this.reflectivity), this.refractionRatio !== void 0 && (i.refractionRatio = this.refractionRatio), this.gradientMap && this.gradientMap.isTexture && (i.gradientMap = this.gradientMap.toJSON(t).uuid), this.transmission !== void 0 && (i.transmission = this.transmission), this.transmissionMap && this.transmissionMap.isTexture && (i.transmissionMap = this.transmissionMap.toJSON(t).uuid), this.thickness !== void 0 && (i.thickness = this.thickness), this.thicknessMap && this.thicknessMap.isTexture && (i.thicknessMap = this.thicknessMap.toJSON(t).uuid), this.attenuationDistance !== void 0 && this.attenuationDistance !== 1 / 0 && (i.attenuationDistance = this.attenuationDistance), this.attenuationColor !== void 0 && (i.attenuationColor = this.attenuationColor.getHex()), this.size !== void 0 && (i.size = this.size), this.shadowSide !== null && (i.shadowSide = this.shadowSide), this.sizeAttenuation !== void 0 && (i.sizeAttenuation = this.sizeAttenuation), this.blending !== ea && (i.blending = this.blending), this.side !== dr && (i.side = this.side), this.vertexColors === !0 && (i.vertexColors = !0), this.opacity < 1 && (i.opacity = this.opacity), this.transparent === !0 && (i.transparent = !0), this.blendSrc !== sa && (i.blendSrc = this.blendSrc), this.blendDst !== na && (i.blendDst = this.blendDst), this.blendEquation !== ia && (i.blendEquation = this.blendEquation), this.blendSrcAlpha !== null && (i.blendSrcAlpha = this.blendSrcAlpha), this.blendDstAlpha !== null && (i.blendDstAlpha = this.blendDstAlpha), this.blendEquationAlpha !== null && (i.blendEquationAlpha = this.blendEquationAlpha), this.blendColor && this.blendColor.isColor && (i.blendColor = this.blendColor.getHex()), this.blendAlpha !== 0 && (i.blendAlpha = this.blendAlpha), this.depthFunc !== ra && (i.depthFunc = this.depthFunc), this.depthTest === !1 && (i.depthTest = this.depthTest), this.depthWrite === !1 && (i.depthWrite = this.depthWrite), this.colorWrite === !1 && (i.colorWrite = this.colorWrite), this.stencilWriteMask !== 255 && (i.stencilWriteMask = this.stencilWriteMask), this.stencilFunc !== ca && (i.stencilFunc = this.stencilFunc), this.stencilRef !== 0 && (i.stencilRef = this.stencilRef), this.stencilFuncMask !== 255 && (i.stencilFuncMask = this.stencilFuncMask), this.stencilFail !== qe && (i.stencilFail = this.stencilFail), this.stencilZFail !== qe && (i.stencilZFail = this.stencilZFail), this.stencilZPass !== qe && (i.stencilZPass = this.stencilZPass), this.stencilWrite === !0 && (i.stencilWrite = this.stencilWrite), this.rotation !== void 0 && this.rotation !== 0 && (i.rotation = this.rotation), this.polygonOffset === !0 && (i.polygonOffset = !0), this.polygonOffsetFactor !== 0 && (i.polygonOffsetFactor = this.polygonOffsetFactor), this.polygonOffsetUnits !== 0 && (i.polygonOffsetUnits = this.polygonOffsetUnits), this.linewidth !== void 0 && this.linewidth !== 1 && (i.linewidth = this.linewidth), this.dashSize !== void 0 && (i.dashSize = this.dashSize), this.gapSize !== void 0 && (i.gapSize = this.gapSize), this.scale !== void 0 && (i.scale = this.scale), this.dithering === !0 && (i.dithering = !0), this.alphaTest > 0 && (i.alphaTest = this.alphaTest), this.alphaHash === !0 && (i.alphaHash = !0), this.alphaToCoverage === !0 && (i.alphaToCoverage = !0), this.premultipliedAlpha === !0 && (i.premultipliedAlpha = !0), this.forceSinglePass === !0 && (i.forceSinglePass = !0), this.wireframe === !0 && (i.wireframe = !0), this.wireframeLinewidth > 1 && (i.wireframeLinewidth = this.wireframeLinewidth), this.wireframeLinecap !== "round" && (i.wireframeLinecap = this.wireframeLinecap), this.wireframeLinejoin !== "round" && (i.wireframeLinejoin = this.wireframeLinejoin), this.flatShading === !0 && (i.flatShading = !0), this.visible === !1 && (i.visible = !1), this.toneMapped === !1 && (i.toneMapped = !1), this.fog === !1 && (i.fog = !1), Object.keys(this.userData).length > 0 && (i.userData = this.userData);
        function s(n) {
            let r = [];
            for(let o in n){
                let a = n[o];
                delete a.metadata, r.push(a);
            }
            return r;
        }
        if (e) {
            let n = s(t.textures), r = s(t.images);
            n.length > 0 && (i.textures = n), r.length > 0 && (i.images = r);
        }
        return i;
    }
    clone() {
        return new this.constructor().copy(this);
    }
    copy(t) {
        this.name = t.name, this.blending = t.blending, this.side = t.side, this.vertexColors = t.vertexColors, this.opacity = t.opacity, this.transparent = t.transparent, this.blendSrc = t.blendSrc, this.blendDst = t.blendDst, this.blendEquation = t.blendEquation, this.blendSrcAlpha = t.blendSrcAlpha, this.blendDstAlpha = t.blendDstAlpha, this.blendEquationAlpha = t.blendEquationAlpha, this.blendColor.copy(t.blendColor), this.blendAlpha = t.blendAlpha, this.depthFunc = t.depthFunc, this.depthTest = t.depthTest, this.depthWrite = t.depthWrite, this.stencilWriteMask = t.stencilWriteMask, this.stencilFunc = t.stencilFunc, this.stencilRef = t.stencilRef, this.stencilFuncMask = t.stencilFuncMask, this.stencilFail = t.stencilFail, this.stencilZFail = t.stencilZFail, this.stencilZPass = t.stencilZPass, this.stencilWrite = t.stencilWrite;
        let e = t.clippingPlanes, i = null;
        if (e !== null) {
            let s = e.length;
            i = new Array(s);
            for(let n = 0; n !== s; ++n)i[n] = e[n].clone();
        }
        return this.clippingPlanes = i, this.clipIntersection = t.clipIntersection, this.clipShadows = t.clipShadows, this.shadowSide = t.shadowSide, this.colorWrite = t.colorWrite, this.precision = t.precision, this.polygonOffset = t.polygonOffset, this.polygonOffsetFactor = t.polygonOffsetFactor, this.polygonOffsetUnits = t.polygonOffsetUnits, this.dithering = t.dithering, this.alphaTest = t.alphaTest, this.alphaHash = t.alphaHash, this.alphaToCoverage = t.alphaToCoverage, this.premultipliedAlpha = t.premultipliedAlpha, this.forceSinglePass = t.forceSinglePass, this.visible = t.visible, this.toneMapped = t.toneMapped, this.userData = JSON.parse(JSON.stringify(t.userData)), this;
    }
    dispose() {
        this.dispatchEvent({
            type: "dispose"
        });
    }
    set needsUpdate(t) {
        t === !0 && this.version++;
    }
    onBuild() {
        console.warn("Material: onBuild() has been removed.");
    }
}, _e = class extends ct {
    constructor(t){
        super(), this.isMeshBasicMaterial = !0, this.type = "MeshBasicMaterial", this.color = new P(16777215), this.map = null, this.lightMap = null, this.lightMapIntensity = 1, this.aoMap = null, this.aoMapIntensity = 1, this.specularMap = null, this.alphaMap = null, this.envMap = null, this.envMapRotation = new Xt, this.combine = Do, this.reflectivity = 1, this.refractionRatio = .98, this.wireframe = !1, this.wireframeLinewidth = 1, this.wireframeLinecap = "round", this.wireframeLinejoin = "round", this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.color.copy(t.color), this.map = t.map, this.lightMap = t.lightMap, this.lightMapIntensity = t.lightMapIntensity, this.aoMap = t.aoMap, this.aoMapIntensity = t.aoMapIntensity, this.specularMap = t.specularMap, this.alphaMap = t.alphaMap, this.envMap = t.envMap, this.envMapRotation.copy(t.envMapRotation), this.combine = t.combine, this.reflectivity = t.reflectivity, this.refractionRatio = t.refractionRatio, this.wireframe = t.wireframe, this.wireframeLinewidth = t.wireframeLinewidth, this.wireframeLinecap = t.wireframeLinecap, this.wireframeLinejoin = t.wireframeLinejoin, this.fog = t.fog, this;
    }
}, re = vu();
function vu() {
    let h = new ArrayBuffer(4), t = new Float32Array(h), e = new Uint32Array(h), i = new Uint32Array(512), s = new Uint32Array(512);
    for(let a = 0; a < 256; ++a){
        let l = a - 127;
        l < -27 ? (i[a] = 0, i[a | 256] = 32768, s[a] = 24, s[a | 256] = 24) : l < -14 ? (i[a] = 1024 >> -l - 14, i[a | 256] = 1024 >> -l - 14 | 32768, s[a] = -l - 1, s[a | 256] = -l - 1) : l <= 15 ? (i[a] = l + 15 << 10, i[a | 256] = l + 15 << 10 | 32768, s[a] = 13, s[a | 256] = 13) : l < 128 ? (i[a] = 31744, i[a | 256] = 64512, s[a] = 24, s[a | 256] = 24) : (i[a] = 31744, i[a | 256] = 64512, s[a] = 13, s[a | 256] = 13);
    }
    let n = new Uint32Array(2048), r = new Uint32Array(64), o = new Uint32Array(64);
    for(let a = 1; a < 1024; ++a){
        let l = a << 13, c = 0;
        for(; !(l & 8388608);)l <<= 1, c -= 8388608;
        l &= -8388609, c += 947912704, n[a] = l | c;
    }
    for(let a = 1024; a < 2048; ++a)n[a] = 939524096 + (a - 1024 << 13);
    for(let a = 1; a < 31; ++a)r[a] = a << 23;
    r[31] = 1199570944, r[32] = 2147483648;
    for(let a = 33; a < 63; ++a)r[a] = 2147483648 + (a - 32 << 23);
    r[63] = 3347054592;
    for(let a = 1; a < 64; ++a)a !== 32 && (o[a] = 1024);
    return {
        floatView: t,
        uint32View: e,
        baseTable: i,
        shiftTable: s,
        mantissaTable: n,
        exponentTable: r,
        offsetTable: o
    };
}
function _t(h) {
    Math.abs(h) > 65504 && console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."), h = N(h, -65504, 65504), re.floatView[0] = h;
    let t = re.uint32View[0], e = t >> 23 & 511;
    return re.baseTable[e] + ((t & 8388607) >> re.shiftTable[e]);
}
function Oi(h) {
    let t = h >> 10;
    return re.uint32View[0] = re.mantissaTable[re.offsetTable[t] + (h & 1023)] + re.exponentTable[t], re.floatView[0];
}
var Ef = {
    toHalfFloat: _t,
    fromHalfFloat: Oi
}, nt = new w, us = new T, Au = 0, Z = class {
    constructor(t, e, i = !1){
        if (Array.isArray(t)) throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");
        this.isBufferAttribute = !0, Object.defineProperty(this, "id", {
            value: Au++
        }), this.name = "", this.array = t, this.itemSize = e, this.count = t !== void 0 ? t.length / e : 0, this.normalized = i, this.usage = Js, this.updateRanges = [], this.gpuType = pi, this.version = 0;
    }
    onUploadCallback() {}
    set needsUpdate(t) {
        t === !0 && this.version++;
    }
    setUsage(t) {
        return this.usage = t, this;
    }
    addUpdateRange(t, e) {
        this.updateRanges.push({
            start: t,
            count: e
        });
    }
    clearUpdateRanges() {
        this.updateRanges.length = 0;
    }
    copy(t) {
        return this.name = t.name, this.array = new t.array.constructor(t.array), this.itemSize = t.itemSize, this.count = t.count, this.normalized = t.normalized, this.usage = t.usage, this.gpuType = t.gpuType, this;
    }
    copyAt(t, e, i) {
        t *= this.itemSize, i *= e.itemSize;
        for(let s = 0, n = this.itemSize; s < n; s++)this.array[t + s] = e.array[i + s];
        return this;
    }
    copyArray(t) {
        return this.array.set(t), this;
    }
    applyMatrix3(t) {
        if (this.itemSize === 2) for(let e = 0, i = this.count; e < i; e++)us.fromBufferAttribute(this, e), us.applyMatrix3(t), this.setXY(e, us.x, us.y);
        else if (this.itemSize === 3) for(let e = 0, i = this.count; e < i; e++)nt.fromBufferAttribute(this, e), nt.applyMatrix3(t), this.setXYZ(e, nt.x, nt.y, nt.z);
        return this;
    }
    applyMatrix4(t) {
        for(let e = 0, i = this.count; e < i; e++)nt.fromBufferAttribute(this, e), nt.applyMatrix4(t), this.setXYZ(e, nt.x, nt.y, nt.z);
        return this;
    }
    applyNormalMatrix(t) {
        for(let e = 0, i = this.count; e < i; e++)nt.fromBufferAttribute(this, e), nt.applyNormalMatrix(t), this.setXYZ(e, nt.x, nt.y, nt.z);
        return this;
    }
    transformDirection(t) {
        for(let e = 0, i = this.count; e < i; e++)nt.fromBufferAttribute(this, e), nt.transformDirection(t), this.setXYZ(e, nt.x, nt.y, nt.z);
        return this;
    }
    set(t, e = 0) {
        return this.array.set(t, e), this;
    }
    getComponent(t, e) {
        let i = this.array[t * this.itemSize + e];
        return this.normalized && (i = xt(i, this.array)), i;
    }
    setComponent(t, e, i) {
        return this.normalized && (i = V(i, this.array)), this.array[t * this.itemSize + e] = i, this;
    }
    getX(t) {
        let e = this.array[t * this.itemSize];
        return this.normalized && (e = xt(e, this.array)), e;
    }
    setX(t, e) {
        return this.normalized && (e = V(e, this.array)), this.array[t * this.itemSize] = e, this;
    }
    getY(t) {
        let e = this.array[t * this.itemSize + 1];
        return this.normalized && (e = xt(e, this.array)), e;
    }
    setY(t, e) {
        return this.normalized && (e = V(e, this.array)), this.array[t * this.itemSize + 1] = e, this;
    }
    getZ(t) {
        let e = this.array[t * this.itemSize + 2];
        return this.normalized && (e = xt(e, this.array)), e;
    }
    setZ(t, e) {
        return this.normalized && (e = V(e, this.array)), this.array[t * this.itemSize + 2] = e, this;
    }
    getW(t) {
        let e = this.array[t * this.itemSize + 3];
        return this.normalized && (e = xt(e, this.array)), e;
    }
    setW(t, e) {
        return this.normalized && (e = V(e, this.array)), this.array[t * this.itemSize + 3] = e, this;
    }
    setXY(t, e, i) {
        return t *= this.itemSize, this.normalized && (e = V(e, this.array), i = V(i, this.array)), this.array[t + 0] = e, this.array[t + 1] = i, this;
    }
    setXYZ(t, e, i, s) {
        return t *= this.itemSize, this.normalized && (e = V(e, this.array), i = V(i, this.array), s = V(s, this.array)), this.array[t + 0] = e, this.array[t + 1] = i, this.array[t + 2] = s, this;
    }
    setXYZW(t, e, i, s, n) {
        return t *= this.itemSize, this.normalized && (e = V(e, this.array), i = V(i, this.array), s = V(s, this.array), n = V(n, this.array)), this.array[t + 0] = e, this.array[t + 1] = i, this.array[t + 2] = s, this.array[t + 3] = n, this;
    }
    onUpload(t) {
        return this.onUploadCallback = t, this;
    }
    clone() {
        return new this.constructor(this.array, this.itemSize).copy(this);
    }
    toJSON() {
        let t = {
            itemSize: this.itemSize,
            type: this.array.constructor.name,
            array: Array.from(this.array),
            normalized: this.normalized
        };
        return this.name !== "" && (t.name = this.name), this.usage !== Js && (t.usage = this.usage), t;
    }
}, Ta = class extends Z {
    constructor(t, e, i){
        super(new Int8Array(t), e, i);
    }
}, Ia = class extends Z {
    constructor(t, e, i){
        super(new Uint8Array(t), e, i);
    }
}, Ca = class extends Z {
    constructor(t, e, i){
        super(new Uint8ClampedArray(t), e, i);
    }
}, za = class extends Z {
    constructor(t, e, i){
        super(new Int16Array(t), e, i);
    }
}, gr = class extends Z {
    constructor(t, e, i){
        super(new Uint16Array(t), e, i);
    }
}, Fa = class extends Z {
    constructor(t, e, i){
        super(new Int32Array(t), e, i);
    }
}, xr = class extends Z {
    constructor(t, e, i){
        super(new Uint32Array(t), e, i);
    }
}, Ba = class extends Z {
    constructor(t, e, i){
        super(new Uint16Array(t), e, i), this.isFloat16BufferAttribute = !0;
    }
    getX(t) {
        let e = Oi(this.array[t * this.itemSize]);
        return this.normalized && (e = xt(e, this.array)), e;
    }
    setX(t, e) {
        return this.normalized && (e = V(e, this.array)), this.array[t * this.itemSize] = _t(e), this;
    }
    getY(t) {
        let e = Oi(this.array[t * this.itemSize + 1]);
        return this.normalized && (e = xt(e, this.array)), e;
    }
    setY(t, e) {
        return this.normalized && (e = V(e, this.array)), this.array[t * this.itemSize + 1] = _t(e), this;
    }
    getZ(t) {
        let e = Oi(this.array[t * this.itemSize + 2]);
        return this.normalized && (e = xt(e, this.array)), e;
    }
    setZ(t, e) {
        return this.normalized && (e = V(e, this.array)), this.array[t * this.itemSize + 2] = _t(e), this;
    }
    getW(t) {
        let e = Oi(this.array[t * this.itemSize + 3]);
        return this.normalized && (e = xt(e, this.array)), e;
    }
    setW(t, e) {
        return this.normalized && (e = V(e, this.array)), this.array[t * this.itemSize + 3] = _t(e), this;
    }
    setXY(t, e, i) {
        return t *= this.itemSize, this.normalized && (e = V(e, this.array), i = V(i, this.array)), this.array[t + 0] = _t(e), this.array[t + 1] = _t(i), this;
    }
    setXYZ(t, e, i, s) {
        return t *= this.itemSize, this.normalized && (e = V(e, this.array), i = V(i, this.array), s = V(s, this.array)), this.array[t + 0] = _t(e), this.array[t + 1] = _t(i), this.array[t + 2] = _t(s), this;
    }
    setXYZW(t, e, i, s, n) {
        return t *= this.itemSize, this.normalized && (e = V(e, this.array), i = V(i, this.array), s = V(s, this.array), n = V(n, this.array)), this.array[t + 0] = _t(e), this.array[t + 1] = _t(i), this.array[t + 2] = _t(s), this.array[t + 3] = _t(n), this;
    }
}, E = class extends Z {
    constructor(t, e, i){
        super(new Float32Array(t), e, i);
    }
}, Su = 0, Ft = new D, Zn = new G, ti = new w, St = new ft, Ii = new ft, rt = new w, L = class h extends qt {
    constructor(){
        super(), this.isBufferGeometry = !0, Object.defineProperty(this, "id", {
            value: Su++
        }), this.uuid = It(), this.name = "", this.type = "BufferGeometry", this.index = null, this.indirect = null, this.attributes = {}, this.morphAttributes = {}, this.morphTargetsRelative = !1, this.groups = [], this.boundingBox = null, this.boundingSphere = null, this.drawRange = {
            start: 0,
            count: 1 / 0
        }, this.userData = {};
    }
    getIndex() {
        return this.index;
    }
    setIndex(t) {
        return Array.isArray(t) ? this.index = new (cu(t) ? xr : gr)(t, 1) : this.index = t, this;
    }
    setIndirect(t) {
        return this.indirect = t, this;
    }
    getIndirect() {
        return this.indirect;
    }
    getAttribute(t) {
        return this.attributes[t];
    }
    setAttribute(t, e) {
        return this.attributes[t] = e, this;
    }
    deleteAttribute(t) {
        return delete this.attributes[t], this;
    }
    hasAttribute(t) {
        return this.attributes[t] !== void 0;
    }
    addGroup(t, e, i = 0) {
        this.groups.push({
            start: t,
            count: e,
            materialIndex: i
        });
    }
    clearGroups() {
        this.groups = [];
    }
    setDrawRange(t, e) {
        this.drawRange.start = t, this.drawRange.count = e;
    }
    applyMatrix4(t) {
        let e = this.attributes.position;
        e !== void 0 && (e.applyMatrix4(t), e.needsUpdate = !0);
        let i = this.attributes.normal;
        if (i !== void 0) {
            let n = new Gt().getNormalMatrix(t);
            i.applyNormalMatrix(n), i.needsUpdate = !0;
        }
        let s = this.attributes.tangent;
        return s !== void 0 && (s.transformDirection(t), s.needsUpdate = !0), this.boundingBox !== null && this.computeBoundingBox(), this.boundingSphere !== null && this.computeBoundingSphere(), this;
    }
    applyQuaternion(t) {
        return Ft.makeRotationFromQuaternion(t), this.applyMatrix4(Ft), this;
    }
    rotateX(t) {
        return Ft.makeRotationX(t), this.applyMatrix4(Ft), this;
    }
    rotateY(t) {
        return Ft.makeRotationY(t), this.applyMatrix4(Ft), this;
    }
    rotateZ(t) {
        return Ft.makeRotationZ(t), this.applyMatrix4(Ft), this;
    }
    translate(t, e, i) {
        return Ft.makeTranslation(t, e, i), this.applyMatrix4(Ft), this;
    }
    scale(t, e, i) {
        return Ft.makeScale(t, e, i), this.applyMatrix4(Ft), this;
    }
    lookAt(t) {
        return Zn.lookAt(t), Zn.updateMatrix(), this.applyMatrix4(Zn.matrix), this;
    }
    center() {
        return this.computeBoundingBox(), this.boundingBox.getCenter(ti).negate(), this.translate(ti.x, ti.y, ti.z), this;
    }
    setFromPoints(t) {
        let e = this.getAttribute("position");
        if (e === void 0) {
            let i = [];
            for(let s = 0, n = t.length; s < n; s++){
                let r = t[s];
                i.push(r.x, r.y, r.z || 0);
            }
            this.setAttribute("position", new E(i, 3));
        } else {
            let i = Math.min(t.length, e.count);
            for(let s = 0; s < i; s++){
                let n = t[s];
                e.setXYZ(s, n.x, n.y, n.z || 0);
            }
            t.length > e.count && console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."), e.needsUpdate = !0;
        }
        return this;
    }
    computeBoundingBox() {
        this.boundingBox === null && (this.boundingBox = new ft);
        let t = this.attributes.position, e = this.morphAttributes.position;
        if (t && t.isGLBufferAttribute) {
            console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.", this), this.boundingBox.set(new w(-1 / 0, -1 / 0, -1 / 0), new w(1 / 0, 1 / 0, 1 / 0));
            return;
        }
        if (t !== void 0) {
            if (this.boundingBox.setFromBufferAttribute(t), e) for(let i = 0, s = e.length; i < s; i++){
                let n = e[i];
                St.setFromBufferAttribute(n), this.morphTargetsRelative ? (rt.addVectors(this.boundingBox.min, St.min), this.boundingBox.expandByPoint(rt), rt.addVectors(this.boundingBox.max, St.max), this.boundingBox.expandByPoint(rt)) : (this.boundingBox.expandByPoint(St.min), this.boundingBox.expandByPoint(St.max));
            }
        } else this.boundingBox.makeEmpty();
        (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) && console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
    }
    computeBoundingSphere() {
        this.boundingSphere === null && (this.boundingSphere = new ht);
        let t = this.attributes.position, e = this.morphAttributes.position;
        if (t && t.isGLBufferAttribute) {
            console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.", this), this.boundingSphere.set(new w, 1 / 0);
            return;
        }
        if (t) {
            let i = this.boundingSphere.center;
            if (St.setFromBufferAttribute(t), e) for(let n = 0, r = e.length; n < r; n++){
                let o = e[n];
                Ii.setFromBufferAttribute(o), this.morphTargetsRelative ? (rt.addVectors(St.min, Ii.min), St.expandByPoint(rt), rt.addVectors(St.max, Ii.max), St.expandByPoint(rt)) : (St.expandByPoint(Ii.min), St.expandByPoint(Ii.max));
            }
            St.getCenter(i);
            let s = 0;
            for(let n = 0, r = t.count; n < r; n++)rt.fromBufferAttribute(t, n), s = Math.max(s, i.distanceToSquared(rt));
            if (e) for(let n = 0, r = e.length; n < r; n++){
                let o = e[n], a = this.morphTargetsRelative;
                for(let l = 0, c = o.count; l < c; l++)rt.fromBufferAttribute(o, l), a && (ti.fromBufferAttribute(t, l), rt.add(ti)), s = Math.max(s, i.distanceToSquared(rt));
            }
            this.boundingSphere.radius = Math.sqrt(s), isNaN(this.boundingSphere.radius) && console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
        }
    }
    computeTangents() {
        let t = this.index, e = this.attributes;
        if (t === null || e.position === void 0 || e.normal === void 0 || e.uv === void 0) {
            console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");
            return;
        }
        let i = e.position, s = e.normal, n = e.uv;
        this.hasAttribute("tangent") === !1 && this.setAttribute("tangent", new Z(new Float32Array(4 * i.count), 4));
        let r = this.getAttribute("tangent"), o = [], a = [];
        for(let A = 0; A < i.count; A++)o[A] = new w, a[A] = new w;
        let l = new w, c = new w, u = new w, d = new T, p = new T, f = new T, m = new w, y1 = new w;
        function g(A, I, C) {
            l.fromBufferAttribute(i, A), c.fromBufferAttribute(i, I), u.fromBufferAttribute(i, C), d.fromBufferAttribute(n, A), p.fromBufferAttribute(n, I), f.fromBufferAttribute(n, C), c.sub(l), u.sub(l), p.sub(d), f.sub(d);
            let k = 1 / (p.x * f.y - f.x * p.y);
            isFinite(k) && (m.copy(c).multiplyScalar(f.y).addScaledVector(u, -p.y).multiplyScalar(k), y1.copy(u).multiplyScalar(p.x).addScaledVector(c, -f.x).multiplyScalar(k), o[A].add(m), o[I].add(m), o[C].add(m), a[A].add(y1), a[I].add(y1), a[C].add(y1));
        }
        let x1 = this.groups;
        x1.length === 0 && (x1 = [
            {
                start: 0,
                count: t.count
            }
        ]);
        for(let A = 0, I = x1.length; A < I; ++A){
            let C = x1[A], k = C.start, U = C.count;
            for(let W = k, H = k + U; W < H; W += 3)g(t.getX(W + 0), t.getX(W + 1), t.getX(W + 2));
        }
        let b = new w, M = new w, _ = new w, v = new w;
        function S(A) {
            _.fromBufferAttribute(s, A), v.copy(_);
            let I = o[A];
            b.copy(I), b.sub(_.multiplyScalar(_.dot(I))).normalize(), M.crossVectors(v, I);
            let k = M.dot(a[A]) < 0 ? -1 : 1;
            r.setXYZW(A, b.x, b.y, b.z, k);
        }
        for(let A = 0, I = x1.length; A < I; ++A){
            let C = x1[A], k = C.start, U = C.count;
            for(let W = k, H = k + U; W < H; W += 3)S(t.getX(W + 0)), S(t.getX(W + 1)), S(t.getX(W + 2));
        }
    }
    computeVertexNormals() {
        let t = this.index, e = this.getAttribute("position");
        if (e !== void 0) {
            let i = this.getAttribute("normal");
            if (i === void 0) i = new Z(new Float32Array(e.count * 3), 3), this.setAttribute("normal", i);
            else for(let d = 0, p = i.count; d < p; d++)i.setXYZ(d, 0, 0, 0);
            let s = new w, n = new w, r = new w, o = new w, a = new w, l = new w, c = new w, u = new w;
            if (t) for(let d = 0, p = t.count; d < p; d += 3){
                let f = t.getX(d + 0), m = t.getX(d + 1), y1 = t.getX(d + 2);
                s.fromBufferAttribute(e, f), n.fromBufferAttribute(e, m), r.fromBufferAttribute(e, y1), c.subVectors(r, n), u.subVectors(s, n), c.cross(u), o.fromBufferAttribute(i, f), a.fromBufferAttribute(i, m), l.fromBufferAttribute(i, y1), o.add(c), a.add(c), l.add(c), i.setXYZ(f, o.x, o.y, o.z), i.setXYZ(m, a.x, a.y, a.z), i.setXYZ(y1, l.x, l.y, l.z);
            }
            else for(let d = 0, p = e.count; d < p; d += 3)s.fromBufferAttribute(e, d + 0), n.fromBufferAttribute(e, d + 1), r.fromBufferAttribute(e, d + 2), c.subVectors(r, n), u.subVectors(s, n), c.cross(u), i.setXYZ(d + 0, c.x, c.y, c.z), i.setXYZ(d + 1, c.x, c.y, c.z), i.setXYZ(d + 2, c.x, c.y, c.z);
            this.normalizeNormals(), i.needsUpdate = !0;
        }
    }
    normalizeNormals() {
        let t = this.attributes.normal;
        for(let e = 0, i = t.count; e < i; e++)rt.fromBufferAttribute(t, e), rt.normalize(), t.setXYZ(e, rt.x, rt.y, rt.z);
    }
    toNonIndexed() {
        function t(o, a) {
            let l = o.array, c = o.itemSize, u = o.normalized, d = new l.constructor(a.length * c), p = 0, f = 0;
            for(let m = 0, y1 = a.length; m < y1; m++){
                o.isInterleavedBufferAttribute ? p = a[m] * o.data.stride + o.offset : p = a[m] * c;
                for(let g = 0; g < c; g++)d[f++] = l[p++];
            }
            return new Z(d, c, u);
        }
        if (this.index === null) return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."), this;
        let e = new h, i = this.index.array, s = this.attributes;
        for(let o in s){
            let a = s[o], l = t(a, i);
            e.setAttribute(o, l);
        }
        let n = this.morphAttributes;
        for(let o in n){
            let a = [], l = n[o];
            for(let c = 0, u = l.length; c < u; c++){
                let d = l[c], p = t(d, i);
                a.push(p);
            }
            e.morphAttributes[o] = a;
        }
        e.morphTargetsRelative = this.morphTargetsRelative;
        let r = this.groups;
        for(let o = 0, a = r.length; o < a; o++){
            let l = r[o];
            e.addGroup(l.start, l.count, l.materialIndex);
        }
        return e;
    }
    toJSON() {
        let t = {
            metadata: {
                version: 4.6,
                type: "BufferGeometry",
                generator: "BufferGeometry.toJSON"
            }
        };
        if (t.uuid = this.uuid, t.type = this.type, this.name !== "" && (t.name = this.name), Object.keys(this.userData).length > 0 && (t.userData = this.userData), this.parameters !== void 0) {
            let a = this.parameters;
            for(let l in a)a[l] !== void 0 && (t[l] = a[l]);
            return t;
        }
        t.data = {
            attributes: {}
        };
        let e = this.index;
        e !== null && (t.data.index = {
            type: e.array.constructor.name,
            array: Array.prototype.slice.call(e.array)
        });
        let i = this.attributes;
        for(let a in i){
            let l = i[a];
            t.data.attributes[a] = l.toJSON(t.data);
        }
        let s = {}, n = !1;
        for(let a in this.morphAttributes){
            let l = this.morphAttributes[a], c = [];
            for(let u = 0, d = l.length; u < d; u++){
                let p = l[u];
                c.push(p.toJSON(t.data));
            }
            c.length > 0 && (s[a] = c, n = !0);
        }
        n && (t.data.morphAttributes = s, t.data.morphTargetsRelative = this.morphTargetsRelative);
        let r = this.groups;
        r.length > 0 && (t.data.groups = JSON.parse(JSON.stringify(r)));
        let o = this.boundingSphere;
        return o !== null && (t.data.boundingSphere = {
            center: o.center.toArray(),
            radius: o.radius
        }), t;
    }
    clone() {
        return new this.constructor().copy(this);
    }
    copy(t) {
        this.index = null, this.attributes = {}, this.morphAttributes = {}, this.groups = [], this.boundingBox = null, this.boundingSphere = null;
        let e = {};
        this.name = t.name;
        let i = t.index;
        i !== null && this.setIndex(i.clone(e));
        let s = t.attributes;
        for(let l in s){
            let c = s[l];
            this.setAttribute(l, c.clone(e));
        }
        let n = t.morphAttributes;
        for(let l in n){
            let c = [], u = n[l];
            for(let d = 0, p = u.length; d < p; d++)c.push(u[d].clone(e));
            this.morphAttributes[l] = c;
        }
        this.morphTargetsRelative = t.morphTargetsRelative;
        let r = t.groups;
        for(let l = 0, c = r.length; l < c; l++){
            let u = r[l];
            this.addGroup(u.start, u.count, u.materialIndex);
        }
        let o = t.boundingBox;
        o !== null && (this.boundingBox = o.clone());
        let a = t.boundingSphere;
        return a !== null && (this.boundingSphere = a.clone()), this.drawRange.start = t.drawRange.start, this.drawRange.count = t.drawRange.count, this.userData = t.userData, this;
    }
    dispose() {
        this.dispatchEvent({
            type: "dispose"
        });
    }
}, Ea = new D, Ce = new Le, ds = new ht, Ra = new w, ps = new w, fs = new w, ms = new w, Yn = new w, ys = new w, ka = new w, gs = new w, Ct = class extends G {
    constructor(t = new L, e = new _e){
        super(), this.isMesh = !0, this.type = "Mesh", this.geometry = t, this.material = e, this.updateMorphTargets();
    }
    copy(t, e) {
        return super.copy(t, e), t.morphTargetInfluences !== void 0 && (this.morphTargetInfluences = t.morphTargetInfluences.slice()), t.morphTargetDictionary !== void 0 && (this.morphTargetDictionary = Object.assign({}, t.morphTargetDictionary)), this.material = Array.isArray(t.material) ? t.material.slice() : t.material, this.geometry = t.geometry, this;
    }
    updateMorphTargets() {
        let e = this.geometry.morphAttributes, i = Object.keys(e);
        if (i.length > 0) {
            let s = e[i[0]];
            if (s !== void 0) {
                this.morphTargetInfluences = [], this.morphTargetDictionary = {};
                for(let n = 0, r = s.length; n < r; n++){
                    let o = s[n].name || String(n);
                    this.morphTargetInfluences.push(0), this.morphTargetDictionary[o] = n;
                }
            }
        }
    }
    getVertexPosition(t, e) {
        let i = this.geometry, s = i.attributes.position, n = i.morphAttributes.position, r = i.morphTargetsRelative;
        e.fromBufferAttribute(s, t);
        let o = this.morphTargetInfluences;
        if (n && o) {
            ys.set(0, 0, 0);
            for(let a = 0, l = n.length; a < l; a++){
                let c = o[a], u = n[a];
                c !== 0 && (Yn.fromBufferAttribute(u, t), r ? ys.addScaledVector(Yn, c) : ys.addScaledVector(Yn.sub(e), c));
            }
            e.add(ys);
        }
        return e;
    }
    raycast(t, e) {
        let i = this.geometry, s = this.material, n = this.matrixWorld;
        s !== void 0 && (i.boundingSphere === null && i.computeBoundingSphere(), ds.copy(i.boundingSphere), ds.applyMatrix4(n), Ce.copy(t.ray).recast(t.near), !(ds.containsPoint(Ce.origin) === !1 && (Ce.intersectSphere(ds, Ra) === null || Ce.origin.distanceToSquared(Ra) > (t.far - t.near) ** 2)) && (Ea.copy(n).invert(), Ce.copy(t.ray).applyMatrix4(Ea), !(i.boundingBox !== null && Ce.intersectsBox(i.boundingBox) === !1) && this._computeIntersections(t, e, Ce)));
    }
    _computeIntersections(t, e, i) {
        let s, n = this.geometry, r = this.material, o = n.index, a = n.attributes.position, l = n.attributes.uv, c = n.attributes.uv1, u = n.attributes.normal, d = n.groups, p = n.drawRange;
        if (o !== null) if (Array.isArray(r)) for(let f = 0, m = d.length; f < m; f++){
            let y1 = d[f], g = r[y1.materialIndex], x1 = Math.max(y1.start, p.start), b = Math.min(o.count, Math.min(y1.start + y1.count, p.start + p.count));
            for(let M = x1, _ = b; M < _; M += 3){
                let v = o.getX(M), S = o.getX(M + 1), A = o.getX(M + 2);
                s = xs(this, g, t, i, l, c, u, v, S, A), s && (s.faceIndex = Math.floor(M / 3), s.face.materialIndex = y1.materialIndex, e.push(s));
            }
        }
        else {
            let f = Math.max(0, p.start), m = Math.min(o.count, p.start + p.count);
            for(let y1 = f, g = m; y1 < g; y1 += 3){
                let x1 = o.getX(y1), b = o.getX(y1 + 1), M = o.getX(y1 + 2);
                s = xs(this, r, t, i, l, c, u, x1, b, M), s && (s.faceIndex = Math.floor(y1 / 3), e.push(s));
            }
        }
        else if (a !== void 0) if (Array.isArray(r)) for(let f = 0, m = d.length; f < m; f++){
            let y1 = d[f], g = r[y1.materialIndex], x1 = Math.max(y1.start, p.start), b = Math.min(a.count, Math.min(y1.start + y1.count, p.start + p.count));
            for(let M = x1, _ = b; M < _; M += 3){
                let v = M, S = M + 1, A = M + 2;
                s = xs(this, g, t, i, l, c, u, v, S, A), s && (s.faceIndex = Math.floor(M / 3), s.face.materialIndex = y1.materialIndex, e.push(s));
            }
        }
        else {
            let f = Math.max(0, p.start), m = Math.min(a.count, p.start + p.count);
            for(let y1 = f, g = m; y1 < g; y1 += 3){
                let x1 = y1, b = y1 + 1, M = y1 + 2;
                s = xs(this, r, t, i, l, c, u, x1, b, M), s && (s.faceIndex = Math.floor(y1 / 3), e.push(s));
            }
        }
    }
};
function Tu(h, t, e, i, s, n, r, o) {
    let a;
    if (t.side === Al ? a = i.intersectTriangle(r, n, s, !0, o) : a = i.intersectTriangle(s, n, r, t.side === dr, o), a === null) return null;
    gs.copy(o), gs.applyMatrix4(h.matrixWorld);
    let l = e.ray.origin.distanceTo(gs);
    return l < e.near || l > e.far ? null : {
        distance: l,
        point: gs.clone(),
        object: h
    };
}
function xs(h, t, e, i, s, n, r, o, a, l) {
    h.getVertexPosition(o, ps), h.getVertexPosition(a, fs), h.getVertexPosition(l, ms);
    let c = Tu(h, t, e, i, ps, fs, ms, ka);
    if (c) {
        let u = new w;
        ne.getBarycoord(ka, ps, fs, ms, u), s && (c.uv = ne.getInterpolatedAttribute(s, o, a, l, u, new T)), n && (c.uv1 = ne.getInterpolatedAttribute(n, o, a, l, u, new T)), r && (c.normal = ne.getInterpolatedAttribute(r, o, a, l, u, new w), c.normal.dot(i.direction) > 0 && c.normal.multiplyScalar(-1));
        let d = {
            a: o,
            b: a,
            c: l,
            normal: new w,
            materialIndex: 0
        };
        ne.getNormal(ps, fs, ms, d.normal), c.face = d, c.barycoord = u;
    }
    return c;
}
var Ks = class h extends L {
    constructor(t = 1, e = 1, i = 1, s = 1, n = 1, r = 1){
        super(), this.type = "BoxGeometry", this.parameters = {
            width: t,
            height: e,
            depth: i,
            widthSegments: s,
            heightSegments: n,
            depthSegments: r
        };
        let o = this;
        s = Math.floor(s), n = Math.floor(n), r = Math.floor(r);
        let a = [], l = [], c = [], u = [], d = 0, p = 0;
        f("z", "y", "x", -1, -1, i, e, t, r, n, 0), f("z", "y", "x", 1, -1, i, e, -t, r, n, 1), f("x", "z", "y", 1, 1, t, i, e, s, r, 2), f("x", "z", "y", 1, -1, t, i, -e, s, r, 3), f("x", "y", "z", 1, -1, t, e, i, s, n, 4), f("x", "y", "z", -1, -1, t, e, -i, s, n, 5), this.setIndex(a), this.setAttribute("position", new E(l, 3)), this.setAttribute("normal", new E(c, 3)), this.setAttribute("uv", new E(u, 2));
        function f(m, y1, g, x1, b, M, _, v, S, A, I) {
            let C = M / S, k = _ / A, U = M / 2, W = _ / 2, H = v / 2, Y = S + 1, Q = A + 1, zt = 0, Pt = 0, j = new w;
            for(let st = 0; st < Q; st++){
                let K = st * k - W;
                for(let Ot = 0; Ot < Y; Ot++){
                    let Se = Ot * C - U;
                    j[m] = Se * x1, j[y1] = K * b, j[g] = H, l.push(j.x, j.y, j.z), j[m] = 0, j[y1] = 0, j[g] = v > 0 ? 1 : -1, c.push(j.x, j.y, j.z), u.push(Ot / S), u.push(1 - st / A), zt += 1;
                }
            }
            for(let st = 0; st < A; st++)for(let K = 0; K < S; K++){
                let Ot = d + K + Y * st, Se = d + K + Y * (st + 1), Tn = d + (K + 1) + Y * (st + 1), es = d + (K + 1) + Y * st;
                a.push(Ot, Se, es), a.push(Se, Tn, es), Pt += 6;
            }
            o.addGroup(p, Pt, I), p += Pt, d += zt;
        }
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.width, t.height, t.depth, t.widthSegments, t.heightSegments, t.depthSegments);
    }
};
function An(h) {
    let t = {};
    for(let e in h){
        t[e] = {};
        for(let i in h[e]){
            let s = h[e][i];
            s && (s.isColor || s.isMatrix3 || s.isMatrix4 || s.isVector2 || s.isVector3 || s.isVector4 || s.isTexture || s.isQuaternion) ? s.isRenderTargetTexture ? (console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."), t[e][i] = null) : t[e][i] = s.clone() : Array.isArray(s) ? t[e][i] = s.slice() : t[e][i] = s;
        }
    }
    return t;
}
function Iu(h) {
    let t = {};
    for(let e = 0; e < h.length; e++){
        let i = An(h[e]);
        for(let s in i)t[s] = i[s];
    }
    return t;
}
function Cu(h) {
    let t = [];
    for(let e = 0; e < h.length; e++)t.push(h[e].clone());
    return t;
}
function Rf(h) {
    let t = h.getRenderTarget();
    return t === null ? h.outputColorSpace : t.isXRRenderTarget === !0 ? t.texture.colorSpace : Tt.workingColorSpace;
}
var kf = {
    clone: An,
    merge: Iu
}, zu = `void main() {
	gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`, Fu = `void main() {
	gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
}`, qi = class extends ct {
    constructor(t){
        super(), this.isShaderMaterial = !0, this.type = "ShaderMaterial", this.defines = {}, this.uniforms = {}, this.uniformsGroups = [], this.vertexShader = zu, this.fragmentShader = Fu, this.linewidth = 1, this.wireframe = !1, this.wireframeLinewidth = 1, this.fog = !1, this.lights = !1, this.clipping = !1, this.forceSinglePass = !0, this.extensions = {
            clipCullDistance: !1,
            multiDraw: !1
        }, this.defaultAttributeValues = {
            color: [
                1,
                1,
                1
            ],
            uv: [
                0,
                0
            ],
            uv1: [
                0,
                0
            ]
        }, this.index0AttributeName = void 0, this.uniformsNeedUpdate = !1, this.glslVersion = null, t !== void 0 && this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.fragmentShader = t.fragmentShader, this.vertexShader = t.vertexShader, this.uniforms = An(t.uniforms), this.uniformsGroups = Cu(t.uniformsGroups), this.defines = Object.assign({}, t.defines), this.wireframe = t.wireframe, this.wireframeLinewidth = t.wireframeLinewidth, this.fog = t.fog, this.lights = t.lights, this.clipping = t.clipping, this.extensions = Object.assign({}, t.extensions), this.glslVersion = t.glslVersion, this;
    }
    toJSON(t) {
        let e = super.toJSON(t);
        e.glslVersion = this.glslVersion, e.uniforms = {};
        for(let s in this.uniforms){
            let r = this.uniforms[s].value;
            r && r.isTexture ? e.uniforms[s] = {
                type: "t",
                value: r.toJSON(t).uuid
            } : r && r.isColor ? e.uniforms[s] = {
                type: "c",
                value: r.getHex()
            } : r && r.isVector2 ? e.uniforms[s] = {
                type: "v2",
                value: r.toArray()
            } : r && r.isVector3 ? e.uniforms[s] = {
                type: "v3",
                value: r.toArray()
            } : r && r.isVector4 ? e.uniforms[s] = {
                type: "v4",
                value: r.toArray()
            } : r && r.isMatrix3 ? e.uniforms[s] = {
                type: "m3",
                value: r.toArray()
            } : r && r.isMatrix4 ? e.uniforms[s] = {
                type: "m4",
                value: r.toArray()
            } : e.uniforms[s] = {
                value: r
            };
        }
        Object.keys(this.defines).length > 0 && (e.defines = this.defines), e.vertexShader = this.vertexShader, e.fragmentShader = this.fragmentShader, e.lights = this.lights, e.clipping = this.clipping;
        let i = {};
        for(let s in this.extensions)this.extensions[s] === !0 && (i[s] = !0);
        return Object.keys(i).length > 0 && (e.extensions = i), e;
    }
}, Gi = class extends G {
    constructor(){
        super(), this.isCamera = !0, this.type = "Camera", this.matrixWorldInverse = new D, this.projectionMatrix = new D, this.projectionMatrixInverse = new D, this.coordinateSystem = oe;
    }
    copy(t, e) {
        return super.copy(t, e), this.matrixWorldInverse.copy(t.matrixWorldInverse), this.projectionMatrix.copy(t.projectionMatrix), this.projectionMatrixInverse.copy(t.projectionMatrixInverse), this.coordinateSystem = t.coordinateSystem, this;
    }
    getWorldDirection(t) {
        return super.getWorldDirection(t).negate();
    }
    updateMatrixWorld(t) {
        super.updateMatrixWorld(t), this.matrixWorldInverse.copy(this.matrixWorld).invert();
    }
    updateWorldMatrix(t, e) {
        super.updateWorldMatrix(t, e), this.matrixWorldInverse.copy(this.matrixWorld).invert();
    }
    clone() {
        return new this.constructor().copy(this);
    }
}, ye = new w, Pa = new T, Oa = new T, vt = class extends Gi {
    constructor(t = 50, e = 1, i = .1, s = 2e3){
        super(), this.isPerspectiveCamera = !0, this.type = "PerspectiveCamera", this.fov = t, this.zoom = 1, this.near = i, this.far = s, this.focus = 10, this.aspect = e, this.view = null, this.filmGauge = 35, this.filmOffset = 0, this.updateProjectionMatrix();
    }
    copy(t, e) {
        return super.copy(t, e), this.fov = t.fov, this.zoom = t.zoom, this.near = t.near, this.far = t.far, this.focus = t.focus, this.aspect = t.aspect, this.view = t.view === null ? null : Object.assign({}, t.view), this.filmGauge = t.filmGauge, this.filmOffset = t.filmOffset, this;
    }
    setFocalLength(t) {
        let e = .5 * this.getFilmHeight() / t;
        this.fov = Ui * 2 * Math.atan(e), this.updateProjectionMatrix();
    }
    getFocalLength() {
        let t = Math.tan(De * .5 * this.fov);
        return .5 * this.getFilmHeight() / t;
    }
    getEffectiveFOV() {
        return Ui * 2 * Math.atan(Math.tan(De * .5 * this.fov) / this.zoom);
    }
    getFilmWidth() {
        return this.filmGauge * Math.min(this.aspect, 1);
    }
    getFilmHeight() {
        return this.filmGauge / Math.max(this.aspect, 1);
    }
    getViewBounds(t, e, i) {
        ye.set(-1, -1, .5).applyMatrix4(this.projectionMatrixInverse), e.set(ye.x, ye.y).multiplyScalar(-t / ye.z), ye.set(1, 1, .5).applyMatrix4(this.projectionMatrixInverse), i.set(ye.x, ye.y).multiplyScalar(-t / ye.z);
    }
    getViewSize(t, e) {
        return this.getViewBounds(t, Pa, Oa), e.subVectors(Oa, Pa);
    }
    setViewOffset(t, e, i, s, n, r) {
        this.aspect = t / e, this.view === null && (this.view = {
            enabled: !0,
            fullWidth: 1,
            fullHeight: 1,
            offsetX: 0,
            offsetY: 0,
            width: 1,
            height: 1
        }), this.view.enabled = !0, this.view.fullWidth = t, this.view.fullHeight = e, this.view.offsetX = i, this.view.offsetY = s, this.view.width = n, this.view.height = r, this.updateProjectionMatrix();
    }
    clearViewOffset() {
        this.view !== null && (this.view.enabled = !1), this.updateProjectionMatrix();
    }
    updateProjectionMatrix() {
        let t = this.near, e = t * Math.tan(De * .5 * this.fov) / this.zoom, i = 2 * e, s = this.aspect * i, n = -.5 * s, r = this.view;
        if (this.view !== null && this.view.enabled) {
            let a = r.fullWidth, l = r.fullHeight;
            n += r.offsetX * s / a, e -= r.offsetY * i / l, s *= r.width / a, i *= r.height / l;
        }
        let o = this.filmOffset;
        o !== 0 && (n += t * o / this.getFilmWidth()), this.projectionMatrix.makePerspective(n, n + s, e, e - i, t, this.far, this.coordinateSystem), this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
    }
    toJSON(t) {
        let e = super.toJSON(t);
        return e.object.fov = this.fov, e.object.zoom = this.zoom, e.object.near = this.near, e.object.far = this.far, e.object.focus = this.focus, e.object.aspect = this.aspect, this.view !== null && (e.object.view = Object.assign({}, this.view)), e.object.filmGauge = this.filmGauge, e.object.filmOffset = this.filmOffset, e;
    }
}, ei = -90, ii = 1, br = class extends G {
    constructor(t, e, i){
        super(), this.type = "CubeCamera", this.renderTarget = i, this.coordinateSystem = null, this.activeMipmapLevel = 0;
        let s = new vt(ei, ii, t, e);
        s.layers = this.layers, this.add(s);
        let n = new vt(ei, ii, t, e);
        n.layers = this.layers, this.add(n);
        let r = new vt(ei, ii, t, e);
        r.layers = this.layers, this.add(r);
        let o = new vt(ei, ii, t, e);
        o.layers = this.layers, this.add(o);
        let a = new vt(ei, ii, t, e);
        a.layers = this.layers, this.add(a);
        let l = new vt(ei, ii, t, e);
        l.layers = this.layers, this.add(l);
    }
    updateCoordinateSystem() {
        let t = this.coordinateSystem, e = this.children.concat(), [i, s, n, r, o, a] = e;
        for (let l of e)this.remove(l);
        if (t === oe) i.up.set(0, 1, 0), i.lookAt(1, 0, 0), s.up.set(0, 1, 0), s.lookAt(-1, 0, 0), n.up.set(0, 0, -1), n.lookAt(0, 1, 0), r.up.set(0, 0, 1), r.lookAt(0, -1, 0), o.up.set(0, 1, 0), o.lookAt(0, 0, 1), a.up.set(0, 1, 0), a.lookAt(0, 0, -1);
        else if (t === Zs) i.up.set(0, -1, 0), i.lookAt(-1, 0, 0), s.up.set(0, -1, 0), s.lookAt(1, 0, 0), n.up.set(0, 0, 1), n.lookAt(0, 1, 0), r.up.set(0, 0, -1), r.lookAt(0, -1, 0), o.up.set(0, -1, 0), o.lookAt(0, 0, 1), a.up.set(0, -1, 0), a.lookAt(0, 0, -1);
        else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: " + t);
        for (let l of e)this.add(l), l.updateMatrixWorld();
    }
    update(t, e) {
        this.parent === null && this.updateMatrixWorld();
        let { renderTarget: i , activeMipmapLevel: s  } = this;
        this.coordinateSystem !== t.coordinateSystem && (this.coordinateSystem = t.coordinateSystem, this.updateCoordinateSystem());
        let [n, r, o, a, l, c] = this.children, u = t.getRenderTarget(), d = t.getActiveCubeFace(), p = t.getActiveMipmapLevel(), f = t.xr.enabled;
        t.xr.enabled = !1;
        let m = i.texture.generateMipmaps;
        i.texture.generateMipmaps = !1, t.setRenderTarget(i, 0, s), t.render(e, n), t.setRenderTarget(i, 1, s), t.render(e, r), t.setRenderTarget(i, 2, s), t.render(e, o), t.setRenderTarget(i, 3, s), t.render(e, a), t.setRenderTarget(i, 4, s), t.render(e, l), i.texture.generateMipmaps = m, t.setRenderTarget(i, 5, s), t.render(e, c), t.setRenderTarget(u, d, p), t.xr.enabled = f, i.texture.needsPMREMUpdate = !0;
    }
}, Xi = class extends lt {
    constructor(t, e, i, s, n, r, o, a, l, c){
        t = t !== void 0 ? t : [], e = e !== void 0 ? e : Uo, super(t, e, i, s, n, r, o, a, l, c), this.isCubeTexture = !0, this.flipY = !1;
    }
    get images() {
        return this.image;
    }
    set images(t) {
        this.image = t;
    }
}, Na = class extends Hi {
    constructor(t = 1, e = {}){
        super(t, t, e), this.isWebGLCubeRenderTarget = !0;
        let i = {
            width: t,
            height: t,
            depth: 1
        }, s = [
            i,
            i,
            i,
            i,
            i,
            i
        ];
        this.texture = new Xi(s, e.mapping, e.wrapS, e.wrapT, e.magFilter, e.minFilter, e.format, e.type, e.anisotropy, e.colorSpace), this.texture.isRenderTargetTexture = !0, this.texture.generateMipmaps = e.generateMipmaps !== void 0 ? e.generateMipmaps : !1, this.texture.minFilter = e.minFilter !== void 0 ? e.minFilter : Et;
    }
    fromEquirectangularTexture(t, e) {
        this.texture.type = e.type, this.texture.colorSpace = e.colorSpace, this.texture.generateMipmaps = e.generateMipmaps, this.texture.minFilter = e.minFilter, this.texture.magFilter = e.magFilter;
        let i = {
            uniforms: {
                tEquirect: {
                    value: null
                }
            },
            vertexShader: `

				varying vec3 vWorldDirection;

				vec3 transformDirection( in vec3 dir, in mat4 matrix ) {

					return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );

				}

				void main() {

					vWorldDirection = transformDirection( position, modelMatrix );

					#include <begin_vertex>
					#include <project_vertex>

				}
			`,
            fragmentShader: `

				uniform sampler2D tEquirect;

				varying vec3 vWorldDirection;

				#include <common>

				void main() {

					vec3 direction = normalize( vWorldDirection );

					vec2 sampleUV = equirectUv( direction );

					gl_FragColor = texture2D( tEquirect, sampleUV );

				}
			`
        }, s = new Ks(5, 5, 5), n = new qi({
            name: "CubemapFromEquirect",
            uniforms: An(i.uniforms),
            vertexShader: i.vertexShader,
            fragmentShader: i.fragmentShader,
            side: Al,
            blending: Ul
        });
        n.uniforms.tEquirect.value = e;
        let r = new Ct(s, n), o = e.minFilter;
        return e.minFilter === vn && (e.minFilter = Et), new br(1, 10, this).update(t, r), e.minFilter = o, r.geometry.dispose(), r.material.dispose(), this;
    }
    clear(t, e, i, s) {
        let n = t.getRenderTarget();
        for(let r = 0; r < 6; r++)t.setRenderTarget(this, r), t.clear(e, i, s);
        t.setRenderTarget(n);
    }
}, Ne = class extends G {
    constructor(){
        super(), this.isGroup = !0, this.type = "Group";
    }
}, Bu = {
    type: "move"
}, Va = class {
    constructor(){
        this._targetRay = null, this._grip = null, this._hand = null;
    }
    getHandSpace() {
        return this._hand === null && (this._hand = new Ne, this._hand.matrixAutoUpdate = !1, this._hand.visible = !1, this._hand.joints = {}, this._hand.inputState = {
            pinching: !1
        }), this._hand;
    }
    getTargetRaySpace() {
        return this._targetRay === null && (this._targetRay = new Ne, this._targetRay.matrixAutoUpdate = !1, this._targetRay.visible = !1, this._targetRay.hasLinearVelocity = !1, this._targetRay.linearVelocity = new w, this._targetRay.hasAngularVelocity = !1, this._targetRay.angularVelocity = new w), this._targetRay;
    }
    getGripSpace() {
        return this._grip === null && (this._grip = new Ne, this._grip.matrixAutoUpdate = !1, this._grip.visible = !1, this._grip.hasLinearVelocity = !1, this._grip.linearVelocity = new w, this._grip.hasAngularVelocity = !1, this._grip.angularVelocity = new w), this._grip;
    }
    dispatchEvent(t) {
        return this._targetRay !== null && this._targetRay.dispatchEvent(t), this._grip !== null && this._grip.dispatchEvent(t), this._hand !== null && this._hand.dispatchEvent(t), this;
    }
    connect(t) {
        if (t && t.hand) {
            let e = this._hand;
            if (e) for (let i of t.hand.values())this._getHandJoint(e, i);
        }
        return this.dispatchEvent({
            type: "connected",
            data: t
        }), this;
    }
    disconnect(t) {
        return this.dispatchEvent({
            type: "disconnected",
            data: t
        }), this._targetRay !== null && (this._targetRay.visible = !1), this._grip !== null && (this._grip.visible = !1), this._hand !== null && (this._hand.visible = !1), this;
    }
    update(t, e, i) {
        let s = null, n = null, r = null, o = this._targetRay, a = this._grip, l = this._hand;
        if (t && e.session.visibilityState !== "visible-blurred") {
            if (l && t.hand) {
                r = !0;
                for (let m of t.hand.values()){
                    let y1 = e.getJointPose(m, i), g = this._getHandJoint(l, m);
                    y1 !== null && (g.matrix.fromArray(y1.transform.matrix), g.matrix.decompose(g.position, g.rotation, g.scale), g.matrixWorldNeedsUpdate = !0, g.jointRadius = y1.radius), g.visible = y1 !== null;
                }
                let c = l.joints["index-finger-tip"], u = l.joints["thumb-tip"], d = c.position.distanceTo(u.position), p = .02, f = .005;
                l.inputState.pinching && d > p + f ? (l.inputState.pinching = !1, this.dispatchEvent({
                    type: "pinchend",
                    handedness: t.handedness,
                    target: this
                })) : !l.inputState.pinching && d <= p - f && (l.inputState.pinching = !0, this.dispatchEvent({
                    type: "pinchstart",
                    handedness: t.handedness,
                    target: this
                }));
            } else a !== null && t.gripSpace && (n = e.getPose(t.gripSpace, i), n !== null && (a.matrix.fromArray(n.transform.matrix), a.matrix.decompose(a.position, a.rotation, a.scale), a.matrixWorldNeedsUpdate = !0, n.linearVelocity ? (a.hasLinearVelocity = !0, a.linearVelocity.copy(n.linearVelocity)) : a.hasLinearVelocity = !1, n.angularVelocity ? (a.hasAngularVelocity = !0, a.angularVelocity.copy(n.angularVelocity)) : a.hasAngularVelocity = !1));
            o !== null && (s = e.getPose(t.targetRaySpace, i), s === null && n !== null && (s = n), s !== null && (o.matrix.fromArray(s.transform.matrix), o.matrix.decompose(o.position, o.rotation, o.scale), o.matrixWorldNeedsUpdate = !0, s.linearVelocity ? (o.hasLinearVelocity = !0, o.linearVelocity.copy(s.linearVelocity)) : o.hasLinearVelocity = !1, s.angularVelocity ? (o.hasAngularVelocity = !0, o.angularVelocity.copy(s.angularVelocity)) : o.hasAngularVelocity = !1, this.dispatchEvent(Bu)));
        }
        return o !== null && (o.visible = s !== null), a !== null && (a.visible = n !== null), l !== null && (l.visible = r !== null), this;
    }
    _getHandJoint(t, e) {
        if (t.joints[e.jointName] === void 0) {
            let i = new Ne;
            i.matrixAutoUpdate = !1, i.visible = !1, t.joints[e.jointName] = i, t.add(i);
        }
        return t.joints[e.jointName];
    }
}, wr = class h {
    constructor(t, e = 25e-5){
        this.isFogExp2 = !0, this.name = "", this.color = new P(t), this.density = e;
    }
    clone() {
        return new h(this.color, this.density);
    }
    toJSON() {
        return {
            type: "FogExp2",
            name: this.name,
            color: this.color.getHex(),
            density: this.density
        };
    }
}, Mr = class h {
    constructor(t, e = 1, i = 1e3){
        this.isFog = !0, this.name = "", this.color = new P(t), this.near = e, this.far = i;
    }
    clone() {
        return new h(this.color, this.near, this.far);
    }
    toJSON() {
        return {
            type: "Fog",
            name: this.name,
            color: this.color.getHex(),
            near: this.near,
            far: this.far
        };
    }
}, _r = class extends G {
    constructor(){
        super(), this.isScene = !0, this.type = "Scene", this.background = null, this.environment = null, this.fog = null, this.backgroundBlurriness = 0, this.backgroundIntensity = 1, this.backgroundRotation = new Xt, this.environmentIntensity = 1, this.environmentRotation = new Xt, this.overrideMaterial = null, typeof __THREE_DEVTOOLS__ < "u" && __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe", {
            detail: this
        }));
    }
    copy(t, e) {
        return super.copy(t, e), t.background !== null && (this.background = t.background.clone()), t.environment !== null && (this.environment = t.environment.clone()), t.fog !== null && (this.fog = t.fog.clone()), this.backgroundBlurriness = t.backgroundBlurriness, this.backgroundIntensity = t.backgroundIntensity, this.backgroundRotation.copy(t.backgroundRotation), this.environmentIntensity = t.environmentIntensity, this.environmentRotation.copy(t.environmentRotation), t.overrideMaterial !== null && (this.overrideMaterial = t.overrideMaterial.clone()), this.matrixAutoUpdate = t.matrixAutoUpdate, this;
    }
    toJSON(t) {
        let e = super.toJSON(t);
        return this.fog !== null && (e.object.fog = this.fog.toJSON()), this.backgroundBlurriness > 0 && (e.object.backgroundBlurriness = this.backgroundBlurriness), this.backgroundIntensity !== 1 && (e.object.backgroundIntensity = this.backgroundIntensity), e.object.backgroundRotation = this.backgroundRotation.toArray(), this.environmentIntensity !== 1 && (e.object.environmentIntensity = this.environmentIntensity), e.object.environmentRotation = this.environmentRotation.toArray(), e;
    }
}, Ji = class {
    constructor(t, e){
        this.isInterleavedBuffer = !0, this.array = t, this.stride = e, this.count = t !== void 0 ? t.length / e : 0, this.usage = Js, this.updateRanges = [], this.version = 0, this.uuid = It();
    }
    onUploadCallback() {}
    set needsUpdate(t) {
        t === !0 && this.version++;
    }
    setUsage(t) {
        return this.usage = t, this;
    }
    addUpdateRange(t, e) {
        this.updateRanges.push({
            start: t,
            count: e
        });
    }
    clearUpdateRanges() {
        this.updateRanges.length = 0;
    }
    copy(t) {
        return this.array = new t.array.constructor(t.array), this.count = t.count, this.stride = t.stride, this.usage = t.usage, this;
    }
    copyAt(t, e, i) {
        t *= this.stride, i *= e.stride;
        for(let s = 0, n = this.stride; s < n; s++)this.array[t + s] = e.array[i + s];
        return this;
    }
    set(t, e = 0) {
        return this.array.set(t, e), this;
    }
    clone(t) {
        t.arrayBuffers === void 0 && (t.arrayBuffers = {}), this.array.buffer._uuid === void 0 && (this.array.buffer._uuid = It()), t.arrayBuffers[this.array.buffer._uuid] === void 0 && (t.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer);
        let e = new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]), i = new this.constructor(e, this.stride);
        return i.setUsage(this.usage), i;
    }
    onUpload(t) {
        return this.onUploadCallback = t, this;
    }
    toJSON(t) {
        return t.arrayBuffers === void 0 && (t.arrayBuffers = {}), this.array.buffer._uuid === void 0 && (this.array.buffer._uuid = It()), t.arrayBuffers[this.array.buffer._uuid] === void 0 && (t.arrayBuffers[this.array.buffer._uuid] = Array.from(new Uint32Array(this.array.buffer))), {
            uuid: this.uuid,
            buffer: this.array.buffer._uuid,
            type: this.array.constructor.name,
            stride: this.stride
        };
    }
}, gt = new w, fi = class h {
    constructor(t, e, i, s = !1){
        this.isInterleavedBufferAttribute = !0, this.name = "", this.data = t, this.itemSize = e, this.offset = i, this.normalized = s;
    }
    get count() {
        return this.data.count;
    }
    get array() {
        return this.data.array;
    }
    set needsUpdate(t) {
        this.data.needsUpdate = t;
    }
    applyMatrix4(t) {
        for(let e = 0, i = this.data.count; e < i; e++)gt.fromBufferAttribute(this, e), gt.applyMatrix4(t), this.setXYZ(e, gt.x, gt.y, gt.z);
        return this;
    }
    applyNormalMatrix(t) {
        for(let e = 0, i = this.count; e < i; e++)gt.fromBufferAttribute(this, e), gt.applyNormalMatrix(t), this.setXYZ(e, gt.x, gt.y, gt.z);
        return this;
    }
    transformDirection(t) {
        for(let e = 0, i = this.count; e < i; e++)gt.fromBufferAttribute(this, e), gt.transformDirection(t), this.setXYZ(e, gt.x, gt.y, gt.z);
        return this;
    }
    getComponent(t, e) {
        let i = this.array[t * this.data.stride + this.offset + e];
        return this.normalized && (i = xt(i, this.array)), i;
    }
    setComponent(t, e, i) {
        return this.normalized && (i = V(i, this.array)), this.data.array[t * this.data.stride + this.offset + e] = i, this;
    }
    setX(t, e) {
        return this.normalized && (e = V(e, this.array)), this.data.array[t * this.data.stride + this.offset] = e, this;
    }
    setY(t, e) {
        return this.normalized && (e = V(e, this.array)), this.data.array[t * this.data.stride + this.offset + 1] = e, this;
    }
    setZ(t, e) {
        return this.normalized && (e = V(e, this.array)), this.data.array[t * this.data.stride + this.offset + 2] = e, this;
    }
    setW(t, e) {
        return this.normalized && (e = V(e, this.array)), this.data.array[t * this.data.stride + this.offset + 3] = e, this;
    }
    getX(t) {
        let e = this.data.array[t * this.data.stride + this.offset];
        return this.normalized && (e = xt(e, this.array)), e;
    }
    getY(t) {
        let e = this.data.array[t * this.data.stride + this.offset + 1];
        return this.normalized && (e = xt(e, this.array)), e;
    }
    getZ(t) {
        let e = this.data.array[t * this.data.stride + this.offset + 2];
        return this.normalized && (e = xt(e, this.array)), e;
    }
    getW(t) {
        let e = this.data.array[t * this.data.stride + this.offset + 3];
        return this.normalized && (e = xt(e, this.array)), e;
    }
    setXY(t, e, i) {
        return t = t * this.data.stride + this.offset, this.normalized && (e = V(e, this.array), i = V(i, this.array)), this.data.array[t + 0] = e, this.data.array[t + 1] = i, this;
    }
    setXYZ(t, e, i, s) {
        return t = t * this.data.stride + this.offset, this.normalized && (e = V(e, this.array), i = V(i, this.array), s = V(s, this.array)), this.data.array[t + 0] = e, this.data.array[t + 1] = i, this.data.array[t + 2] = s, this;
    }
    setXYZW(t, e, i, s, n) {
        return t = t * this.data.stride + this.offset, this.normalized && (e = V(e, this.array), i = V(i, this.array), s = V(s, this.array), n = V(n, this.array)), this.data.array[t + 0] = e, this.data.array[t + 1] = i, this.data.array[t + 2] = s, this.data.array[t + 3] = n, this;
    }
    clone(t) {
        if (t === void 0) {
            console.log("THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");
            let e = [];
            for(let i = 0; i < this.count; i++){
                let s = i * this.data.stride + this.offset;
                for(let n = 0; n < this.itemSize; n++)e.push(this.data.array[s + n]);
            }
            return new Z(new this.array.constructor(e), this.itemSize, this.normalized);
        } else return t.interleavedBuffers === void 0 && (t.interleavedBuffers = {}), t.interleavedBuffers[this.data.uuid] === void 0 && (t.interleavedBuffers[this.data.uuid] = this.data.clone(t)), new h(t.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
    }
    toJSON(t) {
        if (t === void 0) {
            console.log("THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");
            let e = [];
            for(let i = 0; i < this.count; i++){
                let s = i * this.data.stride + this.offset;
                for(let n = 0; n < this.itemSize; n++)e.push(this.data.array[s + n]);
            }
            return {
                itemSize: this.itemSize,
                type: this.array.constructor.name,
                array: e,
                normalized: this.normalized
            };
        } else return t.interleavedBuffers === void 0 && (t.interleavedBuffers = {}), t.interleavedBuffers[this.data.uuid] === void 0 && (t.interleavedBuffers[this.data.uuid] = this.data.toJSON(t)), {
            isInterleavedBufferAttribute: !0,
            itemSize: this.itemSize,
            data: this.data.uuid,
            offset: this.offset,
            normalized: this.normalized
        };
    }
}, tn = class extends ct {
    constructor(t){
        super(), this.isSpriteMaterial = !0, this.type = "SpriteMaterial", this.color = new P(16777215), this.map = null, this.alphaMap = null, this.rotation = 0, this.sizeAttenuation = !0, this.transparent = !0, this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.color.copy(t.color), this.map = t.map, this.alphaMap = t.alphaMap, this.rotation = t.rotation, this.sizeAttenuation = t.sizeAttenuation, this.fog = t.fog, this;
    }
}, si, Ci = new w, ni = new w, ri = new w, oi = new T, zi = new T, Bl = new D, bs = new w, Fi = new w, ws = new w, Da = new T, $n = new T, La = new T, vr = class extends G {
    constructor(t = new tn){
        if (super(), this.isSprite = !0, this.type = "Sprite", si === void 0) {
            si = new L;
            let e = new Float32Array([
                -.5,
                -.5,
                0,
                0,
                0,
                .5,
                -.5,
                0,
                1,
                0,
                .5,
                .5,
                0,
                1,
                1,
                -.5,
                .5,
                0,
                0,
                1
            ]), i = new Ji(e, 5);
            si.setIndex([
                0,
                1,
                2,
                0,
                2,
                3
            ]), si.setAttribute("position", new fi(i, 3, 0, !1)), si.setAttribute("uv", new fi(i, 2, 3, !1));
        }
        this.geometry = si, this.material = t, this.center = new T(.5, .5);
    }
    raycast(t, e) {
        t.camera === null && console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'), ni.setFromMatrixScale(this.matrixWorld), Bl.copy(t.camera.matrixWorld), this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse, this.matrixWorld), ri.setFromMatrixPosition(this.modelViewMatrix), t.camera.isPerspectiveCamera && this.material.sizeAttenuation === !1 && ni.multiplyScalar(-ri.z);
        let i = this.material.rotation, s, n;
        i !== 0 && (n = Math.cos(i), s = Math.sin(i));
        let r = this.center;
        Ms(bs.set(-.5, -.5, 0), ri, r, ni, s, n), Ms(Fi.set(.5, -.5, 0), ri, r, ni, s, n), Ms(ws.set(.5, .5, 0), ri, r, ni, s, n), Da.set(0, 0), $n.set(1, 0), La.set(1, 1);
        let o = t.ray.intersectTriangle(bs, Fi, ws, !1, Ci);
        if (o === null && (Ms(Fi.set(-.5, .5, 0), ri, r, ni, s, n), $n.set(0, 1), o = t.ray.intersectTriangle(bs, ws, Fi, !1, Ci), o === null)) return;
        let a = t.ray.origin.distanceTo(Ci);
        a < t.near || a > t.far || e.push({
            distance: a,
            point: Ci.clone(),
            uv: ne.getInterpolation(Ci, bs, Fi, ws, Da, $n, La, new T),
            face: null,
            object: this
        });
    }
    copy(t, e) {
        return super.copy(t, e), t.center !== void 0 && this.center.copy(t.center), this.material = t.material, this;
    }
};
function Ms(h, t, e, i, s, n) {
    oi.subVectors(h, e).addScalar(.5).multiply(i), s !== void 0 ? (zi.x = n * oi.x - s * oi.y, zi.y = s * oi.x + n * oi.y) : zi.copy(oi), h.copy(t), h.x += zi.x, h.y += zi.y, h.applyMatrix4(Bl);
}
var _s = new w, Ua = new w, Ar = class extends G {
    constructor(){
        super(), this._currentLevel = 0, this.type = "LOD", Object.defineProperties(this, {
            levels: {
                enumerable: !0,
                value: []
            },
            isLOD: {
                value: !0
            }
        }), this.autoUpdate = !0;
    }
    copy(t) {
        super.copy(t, !1);
        let e = t.levels;
        for(let i = 0, s = e.length; i < s; i++){
            let n = e[i];
            this.addLevel(n.object.clone(), n.distance, n.hysteresis);
        }
        return this.autoUpdate = t.autoUpdate, this;
    }
    addLevel(t, e = 0, i = 0) {
        e = Math.abs(e);
        let s = this.levels, n;
        for(n = 0; n < s.length && !(e < s[n].distance); n++);
        return s.splice(n, 0, {
            distance: e,
            hysteresis: i,
            object: t
        }), this.add(t), this;
    }
    removeLevel(t) {
        let e = this.levels;
        for(let i = 0; i < e.length; i++)if (e[i].distance === t) {
            let s = e.splice(i, 1);
            return this.remove(s[0].object), !0;
        }
        return !1;
    }
    getCurrentLevel() {
        return this._currentLevel;
    }
    getObjectForDistance(t) {
        let e = this.levels;
        if (e.length > 0) {
            let i, s;
            for(i = 1, s = e.length; i < s; i++){
                let n = e[i].distance;
                if (e[i].object.visible && (n -= n * e[i].hysteresis), t < n) break;
            }
            return e[i - 1].object;
        }
        return null;
    }
    raycast(t, e) {
        if (this.levels.length > 0) {
            _s.setFromMatrixPosition(this.matrixWorld);
            let s = t.ray.origin.distanceTo(_s);
            this.getObjectForDistance(s).raycast(t, e);
        }
    }
    update(t) {
        let e = this.levels;
        if (e.length > 1) {
            _s.setFromMatrixPosition(t.matrixWorld), Ua.setFromMatrixPosition(this.matrixWorld);
            let i = _s.distanceTo(Ua) / t.zoom;
            e[0].object.visible = !0;
            let s, n;
            for(s = 1, n = e.length; s < n; s++){
                let r = e[s].distance;
                if (e[s].object.visible && (r -= r * e[s].hysteresis), i >= r) e[s - 1].object.visible = !1, e[s].object.visible = !0;
                else break;
            }
            for(this._currentLevel = s - 1; s < n; s++)e[s].object.visible = !1;
        }
    }
    toJSON(t) {
        let e = super.toJSON(t);
        this.autoUpdate === !1 && (e.object.autoUpdate = !1), e.object.levels = [];
        let i = this.levels;
        for(let s = 0, n = i.length; s < n; s++){
            let r = i[s];
            e.object.levels.push({
                object: r.object.uuid,
                distance: r.distance,
                hysteresis: r.hysteresis
            });
        }
        return e;
    }
}, Wa = new w, Ha = new ot, qa = new ot, Eu = new w, Ga = new D, vs = new w, Qn = new ht, Xa = new D, jn = new Le, Sr = class extends Ct {
    constructor(t, e){
        super(t, e), this.isSkinnedMesh = !0, this.type = "SkinnedMesh", this.bindMode = oa, this.bindMatrix = new D, this.bindMatrixInverse = new D, this.boundingBox = null, this.boundingSphere = null;
    }
    computeBoundingBox() {
        let t = this.geometry;
        this.boundingBox === null && (this.boundingBox = new ft), this.boundingBox.makeEmpty();
        let e = t.getAttribute("position");
        for(let i = 0; i < e.count; i++)this.getVertexPosition(i, vs), this.boundingBox.expandByPoint(vs);
    }
    computeBoundingSphere() {
        let t = this.geometry;
        this.boundingSphere === null && (this.boundingSphere = new ht), this.boundingSphere.makeEmpty();
        let e = t.getAttribute("position");
        for(let i = 0; i < e.count; i++)this.getVertexPosition(i, vs), this.boundingSphere.expandByPoint(vs);
    }
    copy(t, e) {
        return super.copy(t, e), this.bindMode = t.bindMode, this.bindMatrix.copy(t.bindMatrix), this.bindMatrixInverse.copy(t.bindMatrixInverse), this.skeleton = t.skeleton, t.boundingBox !== null && (this.boundingBox = t.boundingBox.clone()), t.boundingSphere !== null && (this.boundingSphere = t.boundingSphere.clone()), this;
    }
    raycast(t, e) {
        let i = this.material, s = this.matrixWorld;
        i !== void 0 && (this.boundingSphere === null && this.computeBoundingSphere(), Qn.copy(this.boundingSphere), Qn.applyMatrix4(s), t.ray.intersectsSphere(Qn) !== !1 && (Xa.copy(s).invert(), jn.copy(t.ray).applyMatrix4(Xa), !(this.boundingBox !== null && jn.intersectsBox(this.boundingBox) === !1) && this._computeIntersections(t, e, jn)));
    }
    getVertexPosition(t, e) {
        return super.getVertexPosition(t, e), this.applyBoneTransform(t, e), e;
    }
    bind(t, e) {
        this.skeleton = t, e === void 0 && (this.updateMatrixWorld(!0), this.skeleton.calculateInverses(), e = this.matrixWorld), this.bindMatrix.copy(e), this.bindMatrixInverse.copy(e).invert();
    }
    pose() {
        this.skeleton.pose();
    }
    normalizeSkinWeights() {
        let t = new ot, e = this.geometry.attributes.skinWeight;
        for(let i = 0, s = e.count; i < s; i++){
            t.fromBufferAttribute(e, i);
            let n = 1 / t.manhattanLength();
            n !== 1 / 0 ? t.multiplyScalar(n) : t.set(1, 0, 0, 0), e.setXYZW(i, t.x, t.y, t.z, t.w);
        }
    }
    updateMatrixWorld(t) {
        super.updateMatrixWorld(t), this.bindMode === oa ? this.bindMatrixInverse.copy(this.matrixWorld).invert() : this.bindMode === Wl ? this.bindMatrixInverse.copy(this.bindMatrix).invert() : console.warn("THREE.SkinnedMesh: Unrecognized bindMode: " + this.bindMode);
    }
    applyBoneTransform(t, e) {
        let i = this.skeleton, s = this.geometry;
        Ha.fromBufferAttribute(s.attributes.skinIndex, t), qa.fromBufferAttribute(s.attributes.skinWeight, t), Wa.copy(e).applyMatrix4(this.bindMatrix), e.set(0, 0, 0);
        for(let n = 0; n < 4; n++){
            let r = qa.getComponent(n);
            if (r !== 0) {
                let o = Ha.getComponent(n);
                Ga.multiplyMatrices(i.bones[o].matrixWorld, i.boneInverses[o]), e.addScaledVector(Eu.copy(Wa).applyMatrix4(Ga), r);
            }
        }
        return e.applyMatrix4(this.bindMatrixInverse);
    }
}, en = class extends G {
    constructor(){
        super(), this.isBone = !0, this.type = "Bone";
    }
}, Lt = class extends lt {
    constructor(t = null, e = 1, i = 1, s, n, r, o, a, l = Ut, c = Ut, u, d){
        super(null, r, o, a, l, c, s, n, u, d), this.isDataTexture = !0, this.image = {
            data: t,
            width: e,
            height: i
        }, this.generateMipmaps = !1, this.flipY = !1, this.unpackAlignment = 1;
    }
}, Ja = new D, Ru = new D, Tr = class h {
    constructor(t = [], e = []){
        this.uuid = It(), this.bones = t.slice(0), this.boneInverses = e, this.boneMatrices = null, this.boneTexture = null, this.init();
    }
    init() {
        let t = this.bones, e = this.boneInverses;
        if (this.boneMatrices = new Float32Array(t.length * 16), e.length === 0) this.calculateInverses();
        else if (t.length !== e.length) {
            console.warn("THREE.Skeleton: Number of inverse bone matrices does not match amount of bones."), this.boneInverses = [];
            for(let i = 0, s = this.bones.length; i < s; i++)this.boneInverses.push(new D);
        }
    }
    calculateInverses() {
        this.boneInverses.length = 0;
        for(let t = 0, e = this.bones.length; t < e; t++){
            let i = new D;
            this.bones[t] && i.copy(this.bones[t].matrixWorld).invert(), this.boneInverses.push(i);
        }
    }
    pose() {
        for(let t = 0, e = this.bones.length; t < e; t++){
            let i = this.bones[t];
            i && i.matrixWorld.copy(this.boneInverses[t]).invert();
        }
        for(let t = 0, e = this.bones.length; t < e; t++){
            let i = this.bones[t];
            i && (i.parent && i.parent.isBone ? (i.matrix.copy(i.parent.matrixWorld).invert(), i.matrix.multiply(i.matrixWorld)) : i.matrix.copy(i.matrixWorld), i.matrix.decompose(i.position, i.quaternion, i.scale));
        }
    }
    update() {
        let t = this.bones, e = this.boneInverses, i = this.boneMatrices, s = this.boneTexture;
        for(let n = 0, r = t.length; n < r; n++){
            let o = t[n] ? t[n].matrixWorld : Ru;
            Ja.multiplyMatrices(o, e[n]), Ja.toArray(i, n * 16);
        }
        s !== null && (s.needsUpdate = !0);
    }
    clone() {
        return new h(this.bones, this.boneInverses);
    }
    computeBoneTexture() {
        let t = Math.sqrt(this.bones.length * 4);
        t = Math.ceil(t / 4) * 4, t = Math.max(t, 4);
        let e = new Float32Array(t * t * 4);
        e.set(this.boneMatrices);
        let i = new Lt(e, t, t, Li, pi);
        return i.needsUpdate = !0, this.boneMatrices = e, this.boneTexture = i, this;
    }
    getBoneByName(t) {
        for(let e = 0, i = this.bones.length; e < i; e++){
            let s = this.bones[e];
            if (s.name === t) return s;
        }
    }
    dispose() {
        this.boneTexture !== null && (this.boneTexture.dispose(), this.boneTexture = null);
    }
    fromJSON(t, e) {
        this.uuid = t.uuid;
        for(let i = 0, s = t.bones.length; i < s; i++){
            let n = t.bones[i], r = e[n];
            r === void 0 && (console.warn("THREE.Skeleton: No bone found with UUID:", n), r = new en), this.bones.push(r), this.boneInverses.push(new D().fromArray(t.boneInverses[i]));
        }
        return this.init(), this;
    }
    toJSON() {
        let t = {
            metadata: {
                version: 4.6,
                type: "Skeleton",
                generator: "Skeleton.toJSON"
            },
            bones: [],
            boneInverses: []
        };
        t.uuid = this.uuid;
        let e = this.bones, i = this.boneInverses;
        for(let s = 0, n = e.length; s < n; s++){
            let r = e[s];
            t.bones.push(r.uuid);
            let o = i[s];
            t.boneInverses.push(o.toArray());
        }
        return t;
    }
}, Ue = class extends Z {
    constructor(t, e, i, s = 1){
        super(t, e, i), this.isInstancedBufferAttribute = !0, this.meshPerAttribute = s;
    }
    copy(t) {
        return super.copy(t), this.meshPerAttribute = t.meshPerAttribute, this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.meshPerAttribute = this.meshPerAttribute, t.isInstancedBufferAttribute = !0, t;
    }
}, ai = new D, Za = new D, As = [], Ya = new ft, ku = new D, Bi = new Ct, Ei = new ht, Ir = class extends Ct {
    constructor(t, e, i){
        super(t, e), this.isInstancedMesh = !0, this.instanceMatrix = new Ue(new Float32Array(i * 16), 16), this.instanceColor = null, this.morphTexture = null, this.count = i, this.boundingBox = null, this.boundingSphere = null;
        for(let s = 0; s < i; s++)this.setMatrixAt(s, ku);
    }
    computeBoundingBox() {
        let t = this.geometry, e = this.count;
        this.boundingBox === null && (this.boundingBox = new ft), t.boundingBox === null && t.computeBoundingBox(), this.boundingBox.makeEmpty();
        for(let i = 0; i < e; i++)this.getMatrixAt(i, ai), Ya.copy(t.boundingBox).applyMatrix4(ai), this.boundingBox.union(Ya);
    }
    computeBoundingSphere() {
        let t = this.geometry, e = this.count;
        this.boundingSphere === null && (this.boundingSphere = new ht), t.boundingSphere === null && t.computeBoundingSphere(), this.boundingSphere.makeEmpty();
        for(let i = 0; i < e; i++)this.getMatrixAt(i, ai), Ei.copy(t.boundingSphere).applyMatrix4(ai), this.boundingSphere.union(Ei);
    }
    copy(t, e) {
        return super.copy(t, e), this.instanceMatrix.copy(t.instanceMatrix), t.morphTexture !== null && (this.morphTexture = t.morphTexture.clone()), t.instanceColor !== null && (this.instanceColor = t.instanceColor.clone()), this.count = t.count, t.boundingBox !== null && (this.boundingBox = t.boundingBox.clone()), t.boundingSphere !== null && (this.boundingSphere = t.boundingSphere.clone()), this;
    }
    getColorAt(t, e) {
        e.fromArray(this.instanceColor.array, t * 3);
    }
    getMatrixAt(t, e) {
        e.fromArray(this.instanceMatrix.array, t * 16);
    }
    getMorphAt(t, e) {
        let i = e.morphTargetInfluences, s = this.morphTexture.source.data.data, n = i.length + 1, r = t * n + 1;
        for(let o = 0; o < i.length; o++)i[o] = s[r + o];
    }
    raycast(t, e) {
        let i = this.matrixWorld, s = this.count;
        if (Bi.geometry = this.geometry, Bi.material = this.material, Bi.material !== void 0 && (this.boundingSphere === null && this.computeBoundingSphere(), Ei.copy(this.boundingSphere), Ei.applyMatrix4(i), t.ray.intersectsSphere(Ei) !== !1)) for(let n = 0; n < s; n++){
            this.getMatrixAt(n, ai), Za.multiplyMatrices(i, ai), Bi.matrixWorld = Za, Bi.raycast(t, As);
            for(let r = 0, o = As.length; r < o; r++){
                let a = As[r];
                a.instanceId = n, a.object = this, e.push(a);
            }
            As.length = 0;
        }
    }
    setColorAt(t, e) {
        this.instanceColor === null && (this.instanceColor = new Ue(new Float32Array(this.instanceMatrix.count * 3).fill(1), 3)), e.toArray(this.instanceColor.array, t * 3);
    }
    setMatrixAt(t, e) {
        e.toArray(this.instanceMatrix.array, t * 16);
    }
    setMorphAt(t, e) {
        let i = e.morphTargetInfluences, s = i.length + 1;
        this.morphTexture === null && (this.morphTexture = new Lt(new Float32Array(s * this.count), s, this.count, Tl, pi));
        let n = this.morphTexture.source.data.data, r = 0;
        for(let l = 0; l < i.length; l++)r += i[l];
        let o = this.geometry.morphTargetsRelative ? 1 : 1 - r, a = s * t;
        n[a] = o, n.set(i, a + 1);
    }
    updateMorphTargets() {}
    dispose() {
        return this.dispatchEvent({
            type: "dispose"
        }), this.morphTexture !== null && (this.morphTexture.dispose(), this.morphTexture = null), this;
    }
}, Kn = new w, Pu = new w, Ou = new Gt, xe = class {
    constructor(t = new w(1, 0, 0), e = 0){
        this.isPlane = !0, this.normal = t, this.constant = e;
    }
    set(t, e) {
        return this.normal.copy(t), this.constant = e, this;
    }
    setComponents(t, e, i, s) {
        return this.normal.set(t, e, i), this.constant = s, this;
    }
    setFromNormalAndCoplanarPoint(t, e) {
        return this.normal.copy(t), this.constant = -e.dot(this.normal), this;
    }
    setFromCoplanarPoints(t, e, i) {
        let s = Kn.subVectors(i, e).cross(Pu.subVectors(t, e)).normalize();
        return this.setFromNormalAndCoplanarPoint(s, t), this;
    }
    copy(t) {
        return this.normal.copy(t.normal), this.constant = t.constant, this;
    }
    normalize() {
        let t = 1 / this.normal.length();
        return this.normal.multiplyScalar(t), this.constant *= t, this;
    }
    negate() {
        return this.constant *= -1, this.normal.negate(), this;
    }
    distanceToPoint(t) {
        return this.normal.dot(t) + this.constant;
    }
    distanceToSphere(t) {
        return this.distanceToPoint(t.center) - t.radius;
    }
    projectPoint(t, e) {
        return e.copy(t).addScaledVector(this.normal, -this.distanceToPoint(t));
    }
    intersectLine(t, e) {
        let i = t.delta(Kn), s = this.normal.dot(i);
        if (s === 0) return this.distanceToPoint(t.start) === 0 ? e.copy(t.start) : null;
        let n = -(t.start.dot(this.normal) + this.constant) / s;
        return n < 0 || n > 1 ? null : e.copy(t.start).addScaledVector(i, n);
    }
    intersectsLine(t) {
        let e = this.distanceToPoint(t.start), i = this.distanceToPoint(t.end);
        return e < 0 && i > 0 || i < 0 && e > 0;
    }
    intersectsBox(t) {
        return t.intersectsPlane(this);
    }
    intersectsSphere(t) {
        return t.intersectsPlane(this);
    }
    coplanarPoint(t) {
        return t.copy(this.normal).multiplyScalar(-this.constant);
    }
    applyMatrix4(t, e) {
        let i = e || Ou.getNormalMatrix(t), s = this.coplanarPoint(Kn).applyMatrix4(t), n = this.normal.applyMatrix3(i).normalize();
        return this.constant = -s.dot(n), this;
    }
    translate(t) {
        return this.constant -= t.dot(this.normal), this;
    }
    equals(t) {
        return t.normal.equals(this.normal) && t.constant === this.constant;
    }
    clone() {
        return new this.constructor().copy(this);
    }
}, ze = new ht, Ss = new w, sn = class {
    constructor(t = new xe, e = new xe, i = new xe, s = new xe, n = new xe, r = new xe){
        this.planes = [
            t,
            e,
            i,
            s,
            n,
            r
        ];
    }
    set(t, e, i, s, n, r) {
        let o = this.planes;
        return o[0].copy(t), o[1].copy(e), o[2].copy(i), o[3].copy(s), o[4].copy(n), o[5].copy(r), this;
    }
    copy(t) {
        let e = this.planes;
        for(let i = 0; i < 6; i++)e[i].copy(t.planes[i]);
        return this;
    }
    setFromProjectionMatrix(t, e = oe) {
        let i = this.planes, s = t.elements, n = s[0], r = s[1], o = s[2], a = s[3], l = s[4], c = s[5], u = s[6], d = s[7], p = s[8], f = s[9], m = s[10], y1 = s[11], g = s[12], x1 = s[13], b = s[14], M = s[15];
        if (i[0].setComponents(a - n, d - l, y1 - p, M - g).normalize(), i[1].setComponents(a + n, d + l, y1 + p, M + g).normalize(), i[2].setComponents(a + r, d + c, y1 + f, M + x1).normalize(), i[3].setComponents(a - r, d - c, y1 - f, M - x1).normalize(), i[4].setComponents(a - o, d - u, y1 - m, M - b).normalize(), e === oe) i[5].setComponents(a + o, d + u, y1 + m, M + b).normalize();
        else if (e === Zs) i[5].setComponents(o, u, m, b).normalize();
        else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: " + e);
        return this;
    }
    intersectsObject(t) {
        if (t.boundingSphere !== void 0) t.boundingSphere === null && t.computeBoundingSphere(), ze.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);
        else {
            let e = t.geometry;
            e.boundingSphere === null && e.computeBoundingSphere(), ze.copy(e.boundingSphere).applyMatrix4(t.matrixWorld);
        }
        return this.intersectsSphere(ze);
    }
    intersectsSprite(t) {
        return ze.center.set(0, 0, 0), ze.radius = .7071067811865476, ze.applyMatrix4(t.matrixWorld), this.intersectsSphere(ze);
    }
    intersectsSphere(t) {
        let e = this.planes, i = t.center, s = -t.radius;
        for(let n = 0; n < 6; n++)if (e[n].distanceToPoint(i) < s) return !1;
        return !0;
    }
    intersectsBox(t) {
        let e = this.planes;
        for(let i = 0; i < 6; i++){
            let s = e[i];
            if (Ss.x = s.normal.x > 0 ? t.max.x : t.min.x, Ss.y = s.normal.y > 0 ? t.max.y : t.min.y, Ss.z = s.normal.z > 0 ? t.max.z : t.min.z, s.distanceToPoint(Ss) < 0) return !1;
        }
        return !0;
    }
    containsPoint(t) {
        let e = this.planes;
        for(let i = 0; i < 6; i++)if (e[i].distanceToPoint(t) < 0) return !1;
        return !0;
    }
    clone() {
        return new this.constructor().copy(this);
    }
};
function tr(h, t) {
    return h - t;
}
function Nu(h, t) {
    return h.z - t.z;
}
function Vu(h, t) {
    return t.z - h.z;
}
var Cr = class {
    constructor(){
        this.index = 0, this.pool = [], this.list = [];
    }
    push(t, e, i, s) {
        let n = this.pool, r = this.list;
        this.index >= n.length && n.push({
            start: -1,
            count: -1,
            z: -1,
            index: -1
        });
        let o = n[this.index];
        r.push(o), this.index++, o.start = t, o.count = e, o.z = i, o.index = s;
    }
    reset() {
        this.list.length = 0, this.index = 0;
    }
}, Mt = new D, Du = new P(1, 1, 1), er = new sn, Ts = new ft, Fe = new ht, Ri = new w, $a = new w, Lu = new w, ir = new Cr, pt = new Ct, Is = [];
function Uu(h, t, e = 0) {
    let i = t.itemSize;
    if (h.isInterleavedBufferAttribute || h.array.constructor !== t.array.constructor) {
        let s = h.count;
        for(let n = 0; n < s; n++)for(let r = 0; r < i; r++)t.setComponent(n + e, r, h.getComponent(n, r));
    } else t.array.set(h.array, e * i);
    t.needsUpdate = !0;
}
function Be(h, t) {
    if (h.constructor !== t.constructor) {
        let e = Math.min(h.length, t.length);
        for(let i = 0; i < e; i++)t[i] = h[i];
    } else {
        let e = Math.min(h.length, t.length);
        t.set(new h.constructor(h.buffer, 0, e));
    }
}
var zr = class extends Ct {
    get maxInstanceCount() {
        return this._maxInstanceCount;
    }
    get instanceCount() {
        return this._instanceInfo.length - this._availableInstanceIds.length;
    }
    get unusedVertexCount() {
        return this._maxVertexCount - this._nextVertexStart;
    }
    get unusedIndexCount() {
        return this._maxIndexCount - this._nextIndexStart;
    }
    constructor(t, e, i = e * 2, s){
        super(new L, s), this.isBatchedMesh = !0, this.perObjectFrustumCulled = !0, this.sortObjects = !0, this.boundingBox = null, this.boundingSphere = null, this.customSort = null, this._instanceInfo = [], this._geometryInfo = [], this._availableInstanceIds = [], this._availableGeometryIds = [], this._nextIndexStart = 0, this._nextVertexStart = 0, this._geometryCount = 0, this._visibilityChanged = !0, this._geometryInitialized = !1, this._maxInstanceCount = t, this._maxVertexCount = e, this._maxIndexCount = i, this._multiDrawCounts = new Int32Array(t), this._multiDrawStarts = new Int32Array(t), this._multiDrawCount = 0, this._multiDrawInstances = null, this._matricesTexture = null, this._indirectTexture = null, this._colorsTexture = null, this._initMatricesTexture(), this._initIndirectTexture();
    }
    _initMatricesTexture() {
        let t = Math.sqrt(this._maxInstanceCount * 4);
        t = Math.ceil(t / 4) * 4, t = Math.max(t, 4);
        let e = new Float32Array(t * t * 4), i = new Lt(e, t, t, Li, pi);
        this._matricesTexture = i;
    }
    _initIndirectTexture() {
        let t = Math.sqrt(this._maxInstanceCount);
        t = Math.ceil(t);
        let e = new Uint32Array(t * t), i = new Lt(e, t, t, Il, Wo);
        this._indirectTexture = i;
    }
    _initColorsTexture() {
        let t = Math.sqrt(this._maxInstanceCount);
        t = Math.ceil(t);
        let e = new Float32Array(t * t * 4).fill(1), i = new Lt(e, t, t, Li, pi);
        i.colorSpace = Tt.workingColorSpace, this._colorsTexture = i;
    }
    _initializeGeometry(t) {
        let e = this.geometry, i = this._maxVertexCount, s = this._maxIndexCount;
        if (this._geometryInitialized === !1) {
            for(let n in t.attributes){
                let r = t.getAttribute(n), { array: o , itemSize: a , normalized: l  } = r, c = new o.constructor(i * a), u = new Z(c, a, l);
                e.setAttribute(n, u);
            }
            if (t.getIndex() !== null) {
                let n = i > 65535 ? new Uint32Array(s) : new Uint16Array(s);
                e.setIndex(new Z(n, 1));
            }
            this._geometryInitialized = !0;
        }
    }
    _validateGeometry(t) {
        let e = this.geometry;
        if (!!t.getIndex() != !!e.getIndex()) throw new Error('THREE.BatchedMesh: All geometries must consistently have "index".');
        for(let i in e.attributes){
            if (!t.hasAttribute(i)) throw new Error(`THREE.BatchedMesh: Added geometry missing "${i}". All geometries must have consistent attributes.`);
            let s = t.getAttribute(i), n = e.getAttribute(i);
            if (s.itemSize !== n.itemSize || s.normalized !== n.normalized) throw new Error("THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.");
        }
    }
    validateInstanceId(t) {
        let e = this._instanceInfo;
        if (t < 0 || t >= e.length || e[t].active === !1) throw new Error(`THREE.BatchedMesh: Invalid instanceId ${t}. Instance is either out of range or has been deleted.`);
    }
    validateGeometryId(t) {
        let e = this._geometryInfo;
        if (t < 0 || t >= e.length || e[t].active === !1) throw new Error(`THREE.BatchedMesh: Invalid geometryId ${t}. Geometry is either out of range or has been deleted.`);
    }
    setCustomSort(t) {
        return this.customSort = t, this;
    }
    computeBoundingBox() {
        this.boundingBox === null && (this.boundingBox = new ft);
        let t = this.boundingBox, e = this._instanceInfo;
        t.makeEmpty();
        for(let i = 0, s = e.length; i < s; i++){
            if (e[i].active === !1) continue;
            let n = e[i].geometryIndex;
            this.getMatrixAt(i, Mt), this.getBoundingBoxAt(n, Ts).applyMatrix4(Mt), t.union(Ts);
        }
    }
    computeBoundingSphere() {
        this.boundingSphere === null && (this.boundingSphere = new ht);
        let t = this.boundingSphere, e = this._instanceInfo;
        t.makeEmpty();
        for(let i = 0, s = e.length; i < s; i++){
            if (e[i].active === !1) continue;
            let n = e[i].geometryIndex;
            this.getMatrixAt(i, Mt), this.getBoundingSphereAt(n, Fe).applyMatrix4(Mt), t.union(Fe);
        }
    }
    addInstance(t) {
        if (this._instanceInfo.length >= this.maxInstanceCount && this._availableInstanceIds.length === 0) throw new Error("THREE.BatchedMesh: Maximum item count reached.");
        let i = {
            visible: !0,
            active: !0,
            geometryIndex: t
        }, s = null;
        this._availableInstanceIds.length > 0 ? (this._availableInstanceIds.sort(tr), s = this._availableInstanceIds.shift(), this._instanceInfo[s] = i) : (s = this._instanceInfo.length, this._instanceInfo.push(i));
        let n = this._matricesTexture;
        Mt.identity().toArray(n.image.data, s * 16), n.needsUpdate = !0;
        let r = this._colorsTexture;
        return r && (Du.toArray(r.image.data, s * 4), r.needsUpdate = !0), this._visibilityChanged = !0, s;
    }
    addGeometry(t, e = -1, i = -1) {
        this._initializeGeometry(t), this._validateGeometry(t);
        let s = {
            vertexStart: -1,
            vertexCount: -1,
            reservedVertexCount: -1,
            indexStart: -1,
            indexCount: -1,
            reservedIndexCount: -1,
            start: -1,
            count: -1,
            boundingBox: null,
            boundingSphere: null,
            active: !0
        }, n = this._geometryInfo;
        s.vertexStart = this._nextVertexStart, s.reservedVertexCount = e === -1 ? t.getAttribute("position").count : e;
        let r = t.getIndex();
        if (r !== null && (s.indexStart = this._nextIndexStart, s.reservedIndexCount = i === -1 ? r.count : i), s.indexStart !== -1 && s.indexStart + s.reservedIndexCount > this._maxIndexCount || s.vertexStart + s.reservedVertexCount > this._maxVertexCount) throw new Error("THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.");
        let a;
        return this._availableGeometryIds.length > 0 ? (this._availableGeometryIds.sort(tr), a = this._availableGeometryIds.shift(), n[a] = s) : (a = this._geometryCount, this._geometryCount++, n.push(s)), this.setGeometryAt(a, t), this._nextIndexStart = s.indexStart + s.reservedIndexCount, this._nextVertexStart = s.vertexStart + s.reservedVertexCount, a;
    }
    setGeometryAt(t, e) {
        if (t >= this._geometryCount) throw new Error("THREE.BatchedMesh: Maximum geometry count reached.");
        this._validateGeometry(e);
        let i = this.geometry, s = i.getIndex() !== null, n = i.getIndex(), r = e.getIndex(), o = this._geometryInfo[t];
        if (s && r.count > o.reservedIndexCount || e.attributes.position.count > o.reservedVertexCount) throw new Error("THREE.BatchedMesh: Reserved space not large enough for provided geometry.");
        let a = o.vertexStart, l = o.reservedVertexCount;
        o.vertexCount = e.getAttribute("position").count;
        for(let c in i.attributes){
            let u = e.getAttribute(c), d = i.getAttribute(c);
            Uu(u, d, a);
            let p = u.itemSize;
            for(let f = u.count, m = l; f < m; f++){
                let y1 = a + f;
                for(let g = 0; g < p; g++)d.setComponent(y1, g, 0);
            }
            d.needsUpdate = !0, d.addUpdateRange(a * p, l * p);
        }
        if (s) {
            let c = o.indexStart, u = o.reservedIndexCount;
            o.indexCount = e.getIndex().count;
            for(let d = 0; d < r.count; d++)n.setX(c + d, a + r.getX(d));
            for(let d = r.count, p = u; d < p; d++)n.setX(c + d, a);
            n.needsUpdate = !0, n.addUpdateRange(c, o.reservedIndexCount);
        }
        return o.start = s ? o.indexStart : o.vertexStart, o.count = s ? o.indexCount : o.vertexCount, o.boundingBox = null, e.boundingBox !== null && (o.boundingBox = e.boundingBox.clone()), o.boundingSphere = null, e.boundingSphere !== null && (o.boundingSphere = e.boundingSphere.clone()), this._visibilityChanged = !0, t;
    }
    deleteGeometry(t) {
        let e = this._geometryInfo;
        if (t >= e.length || e[t].active === !1) return this;
        let i = this._instanceInfo;
        for(let s = 0, n = i.length; s < n; s++)i[s].active && i[s].geometryIndex === t && this.deleteInstance(s);
        return e[t].active = !1, this._availableGeometryIds.push(t), this._visibilityChanged = !0, this;
    }
    deleteInstance(t) {
        return this.validateInstanceId(t), this._instanceInfo[t].active = !1, this._availableInstanceIds.push(t), this._visibilityChanged = !0, this;
    }
    optimize() {
        let t = 0, e = 0, i = this._geometryInfo, s = i.map((r, o)=>o).sort((r, o)=>i[r].vertexStart - i[o].vertexStart), n = this.geometry;
        for(let r = 0, o = i.length; r < o; r++){
            let a = s[r], l = i[a];
            if (l.active !== !1) {
                if (n.index !== null) {
                    if (l.indexStart !== e) {
                        let { indexStart: c , vertexStart: u , reservedIndexCount: d  } = l, p = n.index, f = p.array, m = t - u;
                        for(let y1 = c; y1 < c + d; y1++)f[y1] = f[y1] + m;
                        p.array.copyWithin(e, c, c + d), p.addUpdateRange(e, d), l.indexStart = e;
                    }
                    e += l.reservedIndexCount;
                }
                if (l.vertexStart !== t) {
                    let { vertexStart: c , reservedVertexCount: u  } = l, d = n.attributes;
                    for(let p in d){
                        let f = d[p], { array: m , itemSize: y1  } = f;
                        m.copyWithin(t * y1, c * y1, (c + u) * y1), f.addUpdateRange(t * y1, u * y1);
                    }
                    l.vertexStart = t;
                }
                t += l.reservedVertexCount, l.start = n.index ? l.indexStart : l.vertexStart, this._nextIndexStart = n.index ? l.indexStart + l.reservedIndexCount : 0, this._nextVertexStart = l.vertexStart + l.reservedVertexCount;
            }
        }
        return this;
    }
    getBoundingBoxAt(t, e) {
        if (t >= this._geometryCount) return null;
        let i = this.geometry, s = this._geometryInfo[t];
        if (s.boundingBox === null) {
            let n = new ft, r = i.index, o = i.attributes.position;
            for(let a = s.start, l = s.start + s.count; a < l; a++){
                let c = a;
                r && (c = r.getX(c)), n.expandByPoint(Ri.fromBufferAttribute(o, c));
            }
            s.boundingBox = n;
        }
        return e.copy(s.boundingBox), e;
    }
    getBoundingSphereAt(t, e) {
        if (t >= this._geometryCount) return null;
        let i = this.geometry, s = this._geometryInfo[t];
        if (s.boundingSphere === null) {
            let n = new ht;
            this.getBoundingBoxAt(t, Ts), Ts.getCenter(n.center);
            let r = i.index, o = i.attributes.position, a = 0;
            for(let l = s.start, c = s.start + s.count; l < c; l++){
                let u = l;
                r && (u = r.getX(u)), Ri.fromBufferAttribute(o, u), a = Math.max(a, n.center.distanceToSquared(Ri));
            }
            n.radius = Math.sqrt(a), s.boundingSphere = n;
        }
        return e.copy(s.boundingSphere), e;
    }
    setMatrixAt(t, e) {
        this.validateInstanceId(t);
        let i = this._matricesTexture, s = this._matricesTexture.image.data;
        return e.toArray(s, t * 16), i.needsUpdate = !0, this;
    }
    getMatrixAt(t, e) {
        return this.validateInstanceId(t), e.fromArray(this._matricesTexture.image.data, t * 16);
    }
    setColorAt(t, e) {
        return this.validateInstanceId(t), this._colorsTexture === null && this._initColorsTexture(), e.toArray(this._colorsTexture.image.data, t * 4), this._colorsTexture.needsUpdate = !0, this;
    }
    getColorAt(t, e) {
        return this.validateInstanceId(t), e.fromArray(this._colorsTexture.image.data, t * 4);
    }
    setVisibleAt(t, e) {
        return this.validateInstanceId(t), this._instanceInfo[t].visible === e ? this : (this._instanceInfo[t].visible = e, this._visibilityChanged = !0, this);
    }
    getVisibleAt(t) {
        return this.validateInstanceId(t), this._instanceInfo[t].visible;
    }
    setGeometryIdAt(t, e) {
        return this.validateInstanceId(t), this.validateGeometryId(e), this._instanceInfo[t].geometryIndex = e, this;
    }
    getGeometryIdAt(t) {
        return this.validateInstanceId(t), this._instanceInfo[t].geometryIndex;
    }
    getGeometryRangeAt(t, e = {}) {
        this.validateGeometryId(t);
        let i = this._geometryInfo[t];
        return e.vertexStart = i.vertexStart, e.vertexCount = i.vertexCount, e.reservedVertexCount = i.reservedVertexCount, e.indexStart = i.indexStart, e.indexCount = i.indexCount, e.reservedIndexCount = i.reservedIndexCount, e.start = i.start, e.count = i.count, e;
    }
    setInstanceCount(t) {
        let e = this._availableInstanceIds, i = this._instanceInfo;
        for(e.sort(tr); e[e.length - 1] === i.length;)i.pop(), e.pop();
        if (t < i.length) throw new Error(`BatchedMesh: Instance ids outside the range ${t} are being used. Cannot shrink instance count.`);
        let s = new Int32Array(t), n = new Int32Array(t);
        Be(this._multiDrawCounts, s), Be(this._multiDrawStarts, n), this._multiDrawCounts = s, this._multiDrawStarts = n, this._maxInstanceCount = t;
        let r = this._indirectTexture, o = this._matricesTexture, a = this._colorsTexture;
        r.dispose(), this._initIndirectTexture(), Be(r.image.data, this._indirectTexture.image.data), o.dispose(), this._initMatricesTexture(), Be(o.image.data, this._matricesTexture.image.data), a && (a.dispose(), this._initColorsTexture(), Be(a.image.data, this._colorsTexture.image.data));
    }
    setGeometrySize(t, e) {
        let i = [
            ...this._geometryInfo
        ].filter((o)=>o.active);
        if (Math.max(...i.map((o)=>o.vertexStart + o.reservedVertexCount)) > t) throw new Error(`BatchedMesh: Geometry vertex values are being used outside the range ${e}. Cannot shrink further.`);
        if (this.geometry.index && Math.max(...i.map((a)=>a.indexStart + a.reservedIndexCount)) > e) throw new Error(`BatchedMesh: Geometry index values are being used outside the range ${e}. Cannot shrink further.`);
        let n = this.geometry;
        n.dispose(), this._maxVertexCount = t, this._maxIndexCount = e, this._geometryInitialized && (this._geometryInitialized = !1, this.geometry = new L, this._initializeGeometry(n));
        let r = this.geometry;
        n.index && Be(n.index.array, r.index.array);
        for(let o in n.attributes)Be(n.attributes[o].array, r.attributes[o].array);
    }
    raycast(t, e) {
        let i = this._instanceInfo, s = this._geometryInfo, n = this.matrixWorld, r = this.geometry;
        pt.material = this.material, pt.geometry.index = r.index, pt.geometry.attributes = r.attributes, pt.geometry.boundingBox === null && (pt.geometry.boundingBox = new ft), pt.geometry.boundingSphere === null && (pt.geometry.boundingSphere = new ht);
        for(let o = 0, a = i.length; o < a; o++){
            if (!i[o].visible || !i[o].active) continue;
            let l = i[o].geometryIndex, c = s[l];
            pt.geometry.setDrawRange(c.start, c.count), this.getMatrixAt(o, pt.matrixWorld).premultiply(n), this.getBoundingBoxAt(l, pt.geometry.boundingBox), this.getBoundingSphereAt(l, pt.geometry.boundingSphere), pt.raycast(t, Is);
            for(let u = 0, d = Is.length; u < d; u++){
                let p = Is[u];
                p.object = this, p.batchId = o, e.push(p);
            }
            Is.length = 0;
        }
        pt.material = null, pt.geometry.index = null, pt.geometry.attributes = {}, pt.geometry.setDrawRange(0, 1 / 0);
    }
    copy(t) {
        return super.copy(t), this.geometry = t.geometry.clone(), this.perObjectFrustumCulled = t.perObjectFrustumCulled, this.sortObjects = t.sortObjects, this.boundingBox = t.boundingBox !== null ? t.boundingBox.clone() : null, this.boundingSphere = t.boundingSphere !== null ? t.boundingSphere.clone() : null, this._geometryInfo = t._geometryInfo.map((e)=>({
                ...e,
                boundingBox: e.boundingBox !== null ? e.boundingBox.clone() : null,
                boundingSphere: e.boundingSphere !== null ? e.boundingSphere.clone() : null
            })), this._instanceInfo = t._instanceInfo.map((e)=>({
                ...e
            })), this._maxInstanceCount = t._maxInstanceCount, this._maxVertexCount = t._maxVertexCount, this._maxIndexCount = t._maxIndexCount, this._geometryInitialized = t._geometryInitialized, this._geometryCount = t._geometryCount, this._multiDrawCounts = t._multiDrawCounts.slice(), this._multiDrawStarts = t._multiDrawStarts.slice(), this._matricesTexture = t._matricesTexture.clone(), this._matricesTexture.image.data = this._matricesTexture.image.data.slice(), this._colorsTexture !== null && (this._colorsTexture = t._colorsTexture.clone(), this._colorsTexture.image.data = this._colorsTexture.image.data.slice()), this;
    }
    dispose() {
        return this.geometry.dispose(), this._matricesTexture.dispose(), this._matricesTexture = null, this._indirectTexture.dispose(), this._indirectTexture = null, this._colorsTexture !== null && (this._colorsTexture.dispose(), this._colorsTexture = null), this;
    }
    onBeforeRender(t, e, i, s, n) {
        if (!this._visibilityChanged && !this.perObjectFrustumCulled && !this.sortObjects) return;
        let r = s.getIndex(), o = r === null ? 1 : r.array.BYTES_PER_ELEMENT, a = this._instanceInfo, l = this._multiDrawStarts, c = this._multiDrawCounts, u = this._geometryInfo, d = this.perObjectFrustumCulled, p = this._indirectTexture, f = p.image.data;
        d && (Mt.multiplyMatrices(i.projectionMatrix, i.matrixWorldInverse).multiply(this.matrixWorld), er.setFromProjectionMatrix(Mt, t.coordinateSystem));
        let m = 0;
        if (this.sortObjects) {
            Mt.copy(this.matrixWorld).invert(), Ri.setFromMatrixPosition(i.matrixWorld).applyMatrix4(Mt), $a.set(0, 0, -1).transformDirection(i.matrixWorld).transformDirection(Mt);
            for(let x1 = 0, b = a.length; x1 < b; x1++)if (a[x1].visible && a[x1].active) {
                let M = a[x1].geometryIndex;
                this.getMatrixAt(x1, Mt), this.getBoundingSphereAt(M, Fe).applyMatrix4(Mt);
                let _ = !1;
                if (d && (_ = !er.intersectsSphere(Fe)), !_) {
                    let v = u[M], S = Lu.subVectors(Fe.center, Ri).dot($a);
                    ir.push(v.start, v.count, S, x1);
                }
            }
            let y1 = ir.list, g = this.customSort;
            g === null ? y1.sort(n.transparent ? Vu : Nu) : g.call(this, y1, i);
            for(let x1 = 0, b = y1.length; x1 < b; x1++){
                let M = y1[x1];
                l[m] = M.start * o, c[m] = M.count, f[m] = M.index, m++;
            }
            ir.reset();
        } else for(let y1 = 0, g = a.length; y1 < g; y1++)if (a[y1].visible && a[y1].active) {
            let x1 = a[y1].geometryIndex, b = !1;
            if (d && (this.getMatrixAt(y1, Mt), this.getBoundingSphereAt(x1, Fe).applyMatrix4(Mt), b = !er.intersectsSphere(Fe)), !b) {
                let M = u[x1];
                l[m] = M.start * o, c[m] = M.count, f[m] = y1, m++;
            }
        }
        p.needsUpdate = !0, this._multiDrawCount = m, this._visibilityChanged = !1;
    }
    onBeforeShadow(t, e, i, s, n, r) {
        this.onBeforeRender(t, null, s, n, r);
    }
}, mt = class extends ct {
    constructor(t){
        super(), this.isLineBasicMaterial = !0, this.type = "LineBasicMaterial", this.color = new P(16777215), this.map = null, this.linewidth = 1, this.linecap = "round", this.linejoin = "round", this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.color.copy(t.color), this.map = t.map, this.linewidth = t.linewidth, this.linecap = t.linecap, this.linejoin = t.linejoin, this.fog = t.fog, this;
    }
}, nn = new w, rn = new w, Qa = new D, ki = new Le, Cs = new ht, sr = new w, ja = new w, le = class extends G {
    constructor(t = new L, e = new mt){
        super(), this.isLine = !0, this.type = "Line", this.geometry = t, this.material = e, this.updateMorphTargets();
    }
    copy(t, e) {
        return super.copy(t, e), this.material = Array.isArray(t.material) ? t.material.slice() : t.material, this.geometry = t.geometry, this;
    }
    computeLineDistances() {
        let t = this.geometry;
        if (t.index === null) {
            let e = t.attributes.position, i = [
                0
            ];
            for(let s = 1, n = e.count; s < n; s++)nn.fromBufferAttribute(e, s - 1), rn.fromBufferAttribute(e, s), i[s] = i[s - 1], i[s] += nn.distanceTo(rn);
            t.setAttribute("lineDistance", new E(i, 1));
        } else console.warn("THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");
        return this;
    }
    raycast(t, e) {
        let i = this.geometry, s = this.matrixWorld, n = t.params.Line.threshold, r = i.drawRange;
        if (i.boundingSphere === null && i.computeBoundingSphere(), Cs.copy(i.boundingSphere), Cs.applyMatrix4(s), Cs.radius += n, t.ray.intersectsSphere(Cs) === !1) return;
        Qa.copy(s).invert(), ki.copy(t.ray).applyMatrix4(Qa);
        let o = n / ((this.scale.x + this.scale.y + this.scale.z) / 3), a = o * o, l = this.isLineSegments ? 2 : 1, c = i.index, d = i.attributes.position;
        if (c !== null) {
            let p = Math.max(0, r.start), f = Math.min(c.count, r.start + r.count);
            for(let m = p, y1 = f - 1; m < y1; m += l){
                let g = c.getX(m), x1 = c.getX(m + 1), b = zs(this, t, ki, a, g, x1, m);
                b && e.push(b);
            }
            if (this.isLineLoop) {
                let m = c.getX(f - 1), y1 = c.getX(p), g = zs(this, t, ki, a, m, y1, f - 1);
                g && e.push(g);
            }
        } else {
            let p = Math.max(0, r.start), f = Math.min(d.count, r.start + r.count);
            for(let m = p, y1 = f - 1; m < y1; m += l){
                let g = zs(this, t, ki, a, m, m + 1, m);
                g && e.push(g);
            }
            if (this.isLineLoop) {
                let m = zs(this, t, ki, a, f - 1, p, f - 1);
                m && e.push(m);
            }
        }
    }
    updateMorphTargets() {
        let e = this.geometry.morphAttributes, i = Object.keys(e);
        if (i.length > 0) {
            let s = e[i[0]];
            if (s !== void 0) {
                this.morphTargetInfluences = [], this.morphTargetDictionary = {};
                for(let n = 0, r = s.length; n < r; n++){
                    let o = s[n].name || String(n);
                    this.morphTargetInfluences.push(0), this.morphTargetDictionary[o] = n;
                }
            }
        }
    }
};
function zs(h, t, e, i, s, n, r) {
    let o = h.geometry.attributes.position;
    if (nn.fromBufferAttribute(o, s), rn.fromBufferAttribute(o, n), e.distanceSqToSegment(nn, rn, sr, ja) > i) return;
    sr.applyMatrix4(h.matrixWorld);
    let l = t.ray.origin.distanceTo(sr);
    if (!(l < t.near || l > t.far)) return {
        distance: l,
        point: ja.clone().applyMatrix4(h.matrixWorld),
        index: r,
        face: null,
        faceIndex: null,
        barycoord: null,
        object: h
    };
}
var Ka = new w, th = new w, Wt = class extends le {
    constructor(t, e){
        super(t, e), this.isLineSegments = !0, this.type = "LineSegments";
    }
    computeLineDistances() {
        let t = this.geometry;
        if (t.index === null) {
            let e = t.attributes.position, i = [];
            for(let s = 0, n = e.count; s < n; s += 2)Ka.fromBufferAttribute(e, s), th.fromBufferAttribute(e, s + 1), i[s] = s === 0 ? 0 : i[s - 1], i[s + 1] = i[s] + Ka.distanceTo(th);
            t.setAttribute("lineDistance", new E(i, 1));
        } else console.warn("THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");
        return this;
    }
}, Fr = class extends le {
    constructor(t, e){
        super(t, e), this.isLineLoop = !0, this.type = "LineLoop";
    }
}, on = class extends ct {
    constructor(t){
        super(), this.isPointsMaterial = !0, this.type = "PointsMaterial", this.color = new P(16777215), this.map = null, this.alphaMap = null, this.size = 1, this.sizeAttenuation = !0, this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.color.copy(t.color), this.map = t.map, this.alphaMap = t.alphaMap, this.size = t.size, this.sizeAttenuation = t.sizeAttenuation, this.fog = t.fog, this;
    }
}, eh = new D, Br = new Le, Fs = new ht, Bs = new w, Er = class extends G {
    constructor(t = new L, e = new on){
        super(), this.isPoints = !0, this.type = "Points", this.geometry = t, this.material = e, this.updateMorphTargets();
    }
    copy(t, e) {
        return super.copy(t, e), this.material = Array.isArray(t.material) ? t.material.slice() : t.material, this.geometry = t.geometry, this;
    }
    raycast(t, e) {
        let i = this.geometry, s = this.matrixWorld, n = t.params.Points.threshold, r = i.drawRange;
        if (i.boundingSphere === null && i.computeBoundingSphere(), Fs.copy(i.boundingSphere), Fs.applyMatrix4(s), Fs.radius += n, t.ray.intersectsSphere(Fs) === !1) return;
        eh.copy(s).invert(), Br.copy(t.ray).applyMatrix4(eh);
        let o = n / ((this.scale.x + this.scale.y + this.scale.z) / 3), a = o * o, l = i.index, u = i.attributes.position;
        if (l !== null) {
            let d = Math.max(0, r.start), p = Math.min(l.count, r.start + r.count);
            for(let f = d, m = p; f < m; f++){
                let y1 = l.getX(f);
                Bs.fromBufferAttribute(u, y1), ih(Bs, y1, a, s, t, e, this);
            }
        } else {
            let d = Math.max(0, r.start), p = Math.min(u.count, r.start + r.count);
            for(let f = d, m = p; f < m; f++)Bs.fromBufferAttribute(u, f), ih(Bs, f, a, s, t, e, this);
        }
    }
    updateMorphTargets() {
        let e = this.geometry.morphAttributes, i = Object.keys(e);
        if (i.length > 0) {
            let s = e[i[0]];
            if (s !== void 0) {
                this.morphTargetInfluences = [], this.morphTargetDictionary = {};
                for(let n = 0, r = s.length; n < r; n++){
                    let o = s[n].name || String(n);
                    this.morphTargetInfluences.push(0), this.morphTargetDictionary[o] = n;
                }
            }
        }
    }
};
function ih(h, t, e, i, s, n, r) {
    let o = Br.distanceSqToPoint(h);
    if (o < e) {
        let a = new w;
        Br.closestPointToPoint(h, a), a.applyMatrix4(i);
        let l = s.ray.origin.distanceTo(a);
        if (l < s.near || l > s.far) return;
        n.push({
            distance: l,
            distanceToRay: Math.sqrt(o),
            point: a,
            index: t,
            face: null,
            faceIndex: null,
            barycoord: null,
            object: r
        });
    }
}
var Rr = class extends lt {
    constructor(t, e, i, s, n, r, o, a, l){
        super(t, e, i, s, n, r, o, a, l), this.isVideoTexture = !0, this.minFilter = r !== void 0 ? r : Et, this.magFilter = n !== void 0 ? n : Et, this.generateMipmaps = !1;
        let c = this;
        function u() {
            c.needsUpdate = !0, t.requestVideoFrameCallback(u);
        }
        "requestVideoFrameCallback" in t && t.requestVideoFrameCallback(u);
    }
    clone() {
        return new this.constructor(this.image).copy(this);
    }
    update() {
        let t = this.image;
        "requestVideoFrameCallback" in t === !1 && t.readyState >= t.HAVE_CURRENT_DATA && (this.needsUpdate = !0);
    }
}, sh = class extends Rr {
    constructor(t, e, i, s, n, r, o, a){
        super({}, t, e, i, s, n, r, o, a), this.isVideoFrameTexture = !0;
    }
    update() {}
    clone() {
        return new this.constructor().copy(this);
    }
    setFrame(t) {
        this.image = t, this.needsUpdate = !0;
    }
}, nh = class extends lt {
    constructor(t, e){
        super({
            width: t,
            height: e
        }), this.isFramebufferTexture = !0, this.magFilter = Ut, this.minFilter = Ut, this.generateMipmaps = !1, this.needsUpdate = !0;
    }
}, Zi = class extends lt {
    constructor(t, e, i, s, n, r, o, a, l, c, u, d){
        super(null, r, o, a, l, c, s, n, u, d), this.isCompressedTexture = !0, this.image = {
            width: e,
            height: i
        }, this.mipmaps = t, this.flipY = !1, this.generateMipmaps = !1;
    }
}, rh = class extends Zi {
    constructor(t, e, i, s, n, r){
        super(t, e, i, n, r), this.isCompressedArrayTexture = !0, this.image.depth = s, this.wrapR = Ht, this.layerUpdates = new Set;
    }
    addLayerUpdate(t) {
        this.layerUpdates.add(t);
    }
    clearLayerUpdates() {
        this.layerUpdates.clear();
    }
}, oh = class extends Zi {
    constructor(t, e, i){
        super(void 0, t[0].width, t[0].height, e, i, Uo), this.isCompressedCubeTexture = !0, this.isCubeTexture = !0, this.image = t;
    }
}, ah = class extends lt {
    constructor(t, e, i, s, n, r, o, a, l){
        super(t, e, i, s, n, r, o, a, l), this.isCanvasTexture = !0, this.needsUpdate = !0;
    }
}, hh = class extends lt {
    constructor(t, e, i, s, n, r, o, a, l, c = Cn){
        if (c !== Cn && c !== aa) throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");
        i === void 0 && c === Cn && (i = Wo), i === void 0 && c === aa && (i = sc), super(null, s, n, r, o, a, c, i, l), this.isDepthTexture = !0, this.image = {
            width: t,
            height: e
        }, this.magFilter = o !== void 0 ? o : Ut, this.minFilter = a !== void 0 ? a : Ut, this.flipY = !1, this.generateMipmaps = !1, this.compareFunction = null;
    }
    copy(t) {
        return super.copy(t), this.compareFunction = t.compareFunction, this;
    }
    toJSON(t) {
        let e = super.toJSON(t);
        return this.compareFunction !== null && (e.compareFunction = this.compareFunction), e;
    }
}, Rt = class {
    constructor(){
        this.type = "Curve", this.arcLengthDivisions = 200;
    }
    getPoint() {
        return console.warn("THREE.Curve: .getPoint() not implemented."), null;
    }
    getPointAt(t, e) {
        let i = this.getUtoTmapping(t);
        return this.getPoint(i, e);
    }
    getPoints(t = 5) {
        let e = [];
        for(let i = 0; i <= t; i++)e.push(this.getPoint(i / t));
        return e;
    }
    getSpacedPoints(t = 5) {
        let e = [];
        for(let i = 0; i <= t; i++)e.push(this.getPointAt(i / t));
        return e;
    }
    getLength() {
        let t = this.getLengths();
        return t[t.length - 1];
    }
    getLengths(t = this.arcLengthDivisions) {
        if (this.cacheArcLengths && this.cacheArcLengths.length === t + 1 && !this.needsUpdate) return this.cacheArcLengths;
        this.needsUpdate = !1;
        let e = [], i, s = this.getPoint(0), n = 0;
        e.push(0);
        for(let r = 1; r <= t; r++)i = this.getPoint(r / t), n += i.distanceTo(s), e.push(n), s = i;
        return this.cacheArcLengths = e, e;
    }
    updateArcLengths() {
        this.needsUpdate = !0, this.getLengths();
    }
    getUtoTmapping(t, e) {
        let i = this.getLengths(), s = 0, n = i.length, r;
        e ? r = e : r = t * i[n - 1];
        let o = 0, a = n - 1, l;
        for(; o <= a;)if (s = Math.floor(o + (a - o) / 2), l = i[s] - r, l < 0) o = s + 1;
        else if (l > 0) a = s - 1;
        else {
            a = s;
            break;
        }
        if (s = a, i[s] === r) return s / (n - 1);
        let c = i[s], d = i[s + 1] - c, p = (r - c) / d;
        return (s + p) / (n - 1);
    }
    getTangent(t, e) {
        let s = t - 1e-4, n = t + 1e-4;
        s < 0 && (s = 0), n > 1 && (n = 1);
        let r = this.getPoint(s), o = this.getPoint(n), a = e || (r.isVector2 ? new T : new w);
        return a.copy(o).sub(r).normalize(), a;
    }
    getTangentAt(t, e) {
        let i = this.getUtoTmapping(t);
        return this.getTangent(i, e);
    }
    computeFrenetFrames(t, e) {
        let i = new w, s = [], n = [], r = [], o = new w, a = new D;
        for(let p = 0; p <= t; p++){
            let f = p / t;
            s[p] = this.getTangentAt(f, new w);
        }
        n[0] = new w, r[0] = new w;
        let l = Number.MAX_VALUE, c = Math.abs(s[0].x), u = Math.abs(s[0].y), d = Math.abs(s[0].z);
        c <= l && (l = c, i.set(1, 0, 0)), u <= l && (l = u, i.set(0, 1, 0)), d <= l && i.set(0, 0, 1), o.crossVectors(s[0], i).normalize(), n[0].crossVectors(s[0], o), r[0].crossVectors(s[0], n[0]);
        for(let p = 1; p <= t; p++){
            if (n[p] = n[p - 1].clone(), r[p] = r[p - 1].clone(), o.crossVectors(s[p - 1], s[p]), o.length() > Number.EPSILON) {
                o.normalize();
                let f = Math.acos(N(s[p - 1].dot(s[p]), -1, 1));
                n[p].applyMatrix4(a.makeRotationAxis(o, f));
            }
            r[p].crossVectors(s[p], n[p]);
        }
        if (e === !0) {
            let p = Math.acos(N(n[0].dot(n[t]), -1, 1));
            p /= t, s[0].dot(o.crossVectors(n[0], n[t])) > 0 && (p = -p);
            for(let f = 1; f <= t; f++)n[f].applyMatrix4(a.makeRotationAxis(s[f], p * f)), r[f].crossVectors(s[f], n[f]);
        }
        return {
            tangents: s,
            normals: n,
            binormals: r
        };
    }
    clone() {
        return new this.constructor().copy(this);
    }
    copy(t) {
        return this.arcLengthDivisions = t.arcLengthDivisions, this;
    }
    toJSON() {
        let t = {
            metadata: {
                version: 4.6,
                type: "Curve",
                generator: "Curve.toJSON"
            }
        };
        return t.arcLengthDivisions = this.arcLengthDivisions, t.type = this.type, t;
    }
    fromJSON(t) {
        return this.arcLengthDivisions = t.arcLengthDivisions, this;
    }
}, Yi = class extends Rt {
    constructor(t = 0, e = 0, i = 1, s = 1, n = 0, r = Math.PI * 2, o = !1, a = 0){
        super(), this.isEllipseCurve = !0, this.type = "EllipseCurve", this.aX = t, this.aY = e, this.xRadius = i, this.yRadius = s, this.aStartAngle = n, this.aEndAngle = r, this.aClockwise = o, this.aRotation = a;
    }
    getPoint(t, e = new T) {
        let i = e, s = Math.PI * 2, n = this.aEndAngle - this.aStartAngle, r = Math.abs(n) < Number.EPSILON;
        for(; n < 0;)n += s;
        for(; n > s;)n -= s;
        n < Number.EPSILON && (r ? n = 0 : n = s), this.aClockwise === !0 && !r && (n === s ? n = -s : n = n - s);
        let o = this.aStartAngle + t * n, a = this.aX + this.xRadius * Math.cos(o), l = this.aY + this.yRadius * Math.sin(o);
        if (this.aRotation !== 0) {
            let c = Math.cos(this.aRotation), u = Math.sin(this.aRotation), d = a - this.aX, p = l - this.aY;
            a = d * c - p * u + this.aX, l = d * u + p * c + this.aY;
        }
        return i.set(a, l);
    }
    copy(t) {
        return super.copy(t), this.aX = t.aX, this.aY = t.aY, this.xRadius = t.xRadius, this.yRadius = t.yRadius, this.aStartAngle = t.aStartAngle, this.aEndAngle = t.aEndAngle, this.aClockwise = t.aClockwise, this.aRotation = t.aRotation, this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.aX = this.aX, t.aY = this.aY, t.xRadius = this.xRadius, t.yRadius = this.yRadius, t.aStartAngle = this.aStartAngle, t.aEndAngle = this.aEndAngle, t.aClockwise = this.aClockwise, t.aRotation = this.aRotation, t;
    }
    fromJSON(t) {
        return super.fromJSON(t), this.aX = t.aX, this.aY = t.aY, this.xRadius = t.xRadius, this.yRadius = t.yRadius, this.aStartAngle = t.aStartAngle, this.aEndAngle = t.aEndAngle, this.aClockwise = t.aClockwise, this.aRotation = t.aRotation, this;
    }
}, kr = class extends Yi {
    constructor(t, e, i, s, n, r){
        super(t, e, i, i, s, n, r), this.isArcCurve = !0, this.type = "ArcCurve";
    }
};
function Go() {
    let h = 0, t = 0, e = 0, i = 0;
    function s(n, r, o, a) {
        h = n, t = o, e = -3 * n + 3 * r - 2 * o - a, i = 2 * n - 2 * r + o + a;
    }
    return {
        initCatmullRom: function(n, r, o, a, l) {
            s(r, o, l * (o - n), l * (a - r));
        },
        initNonuniformCatmullRom: function(n, r, o, a, l, c, u) {
            let d = (r - n) / l - (o - n) / (l + c) + (o - r) / c, p = (o - r) / c - (a - r) / (c + u) + (a - o) / u;
            d *= c, p *= c, s(r, o, d, p);
        },
        calc: function(n) {
            let r = n * n, o = r * n;
            return h + t * n + e * r + i * o;
        }
    };
}
var Es = new w, nr = new Go, rr = new Go, or = new Go, Pr = class extends Rt {
    constructor(t = [], e = !1, i = "centripetal", s = .5){
        super(), this.isCatmullRomCurve3 = !0, this.type = "CatmullRomCurve3", this.points = t, this.closed = e, this.curveType = i, this.tension = s;
    }
    getPoint(t, e = new w) {
        let i = e, s = this.points, n = s.length, r = (n - (this.closed ? 0 : 1)) * t, o = Math.floor(r), a = r - o;
        this.closed ? o += o > 0 ? 0 : (Math.floor(Math.abs(o) / n) + 1) * n : a === 0 && o === n - 1 && (o = n - 2, a = 1);
        let l, c;
        this.closed || o > 0 ? l = s[(o - 1) % n] : (Es.subVectors(s[0], s[1]).add(s[0]), l = Es);
        let u = s[o % n], d = s[(o + 1) % n];
        if (this.closed || o + 2 < n ? c = s[(o + 2) % n] : (Es.subVectors(s[n - 1], s[n - 2]).add(s[n - 1]), c = Es), this.curveType === "centripetal" || this.curveType === "chordal") {
            let p = this.curveType === "chordal" ? .5 : .25, f = Math.pow(l.distanceToSquared(u), p), m = Math.pow(u.distanceToSquared(d), p), y1 = Math.pow(d.distanceToSquared(c), p);
            m < 1e-4 && (m = 1), f < 1e-4 && (f = m), y1 < 1e-4 && (y1 = m), nr.initNonuniformCatmullRom(l.x, u.x, d.x, c.x, f, m, y1), rr.initNonuniformCatmullRom(l.y, u.y, d.y, c.y, f, m, y1), or.initNonuniformCatmullRom(l.z, u.z, d.z, c.z, f, m, y1);
        } else this.curveType === "catmullrom" && (nr.initCatmullRom(l.x, u.x, d.x, c.x, this.tension), rr.initCatmullRom(l.y, u.y, d.y, c.y, this.tension), or.initCatmullRom(l.z, u.z, d.z, c.z, this.tension));
        return i.set(nr.calc(a), rr.calc(a), or.calc(a)), i;
    }
    copy(t) {
        super.copy(t), this.points = [];
        for(let e = 0, i = t.points.length; e < i; e++){
            let s = t.points[e];
            this.points.push(s.clone());
        }
        return this.closed = t.closed, this.curveType = t.curveType, this.tension = t.tension, this;
    }
    toJSON() {
        let t = super.toJSON();
        t.points = [];
        for(let e = 0, i = this.points.length; e < i; e++){
            let s = this.points[e];
            t.points.push(s.toArray());
        }
        return t.closed = this.closed, t.curveType = this.curveType, t.tension = this.tension, t;
    }
    fromJSON(t) {
        super.fromJSON(t), this.points = [];
        for(let e = 0, i = t.points.length; e < i; e++){
            let s = t.points[e];
            this.points.push(new w().fromArray(s));
        }
        return this.closed = t.closed, this.curveType = t.curveType, this.tension = t.tension, this;
    }
};
function lh(h, t, e, i, s) {
    let n = (i - t) * .5, r = (s - e) * .5, o = h * h, a = h * o;
    return (2 * e - 2 * i + n + r) * a + (-3 * e + 3 * i - 2 * n - r) * o + n * h + e;
}
function Wu(h, t) {
    let e = 1 - h;
    return e * e * t;
}
function Hu(h, t) {
    return 2 * (1 - h) * h * t;
}
function qu(h, t) {
    return h * h * t;
}
function Vi(h, t, e, i) {
    return Wu(h, t) + Hu(h, e) + qu(h, i);
}
function Gu(h, t) {
    let e = 1 - h;
    return e * e * e * t;
}
function Xu(h, t) {
    let e = 1 - h;
    return 3 * e * e * h * t;
}
function Ju(h, t) {
    return 3 * (1 - h) * h * h * t;
}
function Zu(h, t) {
    return h * h * h * t;
}
function Di(h, t, e, i, s) {
    return Gu(h, t) + Xu(h, e) + Ju(h, i) + Zu(h, s);
}
var an = class extends Rt {
    constructor(t = new T, e = new T, i = new T, s = new T){
        super(), this.isCubicBezierCurve = !0, this.type = "CubicBezierCurve", this.v0 = t, this.v1 = e, this.v2 = i, this.v3 = s;
    }
    getPoint(t, e = new T) {
        let i = e, s = this.v0, n = this.v1, r = this.v2, o = this.v3;
        return i.set(Di(t, s.x, n.x, r.x, o.x), Di(t, s.y, n.y, r.y, o.y)), i;
    }
    copy(t) {
        return super.copy(t), this.v0.copy(t.v0), this.v1.copy(t.v1), this.v2.copy(t.v2), this.v3.copy(t.v3), this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.v0 = this.v0.toArray(), t.v1 = this.v1.toArray(), t.v2 = this.v2.toArray(), t.v3 = this.v3.toArray(), t;
    }
    fromJSON(t) {
        return super.fromJSON(t), this.v0.fromArray(t.v0), this.v1.fromArray(t.v1), this.v2.fromArray(t.v2), this.v3.fromArray(t.v3), this;
    }
}, Or = class extends Rt {
    constructor(t = new w, e = new w, i = new w, s = new w){
        super(), this.isCubicBezierCurve3 = !0, this.type = "CubicBezierCurve3", this.v0 = t, this.v1 = e, this.v2 = i, this.v3 = s;
    }
    getPoint(t, e = new w) {
        let i = e, s = this.v0, n = this.v1, r = this.v2, o = this.v3;
        return i.set(Di(t, s.x, n.x, r.x, o.x), Di(t, s.y, n.y, r.y, o.y), Di(t, s.z, n.z, r.z, o.z)), i;
    }
    copy(t) {
        return super.copy(t), this.v0.copy(t.v0), this.v1.copy(t.v1), this.v2.copy(t.v2), this.v3.copy(t.v3), this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.v0 = this.v0.toArray(), t.v1 = this.v1.toArray(), t.v2 = this.v2.toArray(), t.v3 = this.v3.toArray(), t;
    }
    fromJSON(t) {
        return super.fromJSON(t), this.v0.fromArray(t.v0), this.v1.fromArray(t.v1), this.v2.fromArray(t.v2), this.v3.fromArray(t.v3), this;
    }
}, hn = class extends Rt {
    constructor(t = new T, e = new T){
        super(), this.isLineCurve = !0, this.type = "LineCurve", this.v1 = t, this.v2 = e;
    }
    getPoint(t, e = new T) {
        let i = e;
        return t === 1 ? i.copy(this.v2) : (i.copy(this.v2).sub(this.v1), i.multiplyScalar(t).add(this.v1)), i;
    }
    getPointAt(t, e) {
        return this.getPoint(t, e);
    }
    getTangent(t, e = new T) {
        return e.subVectors(this.v2, this.v1).normalize();
    }
    getTangentAt(t, e) {
        return this.getTangent(t, e);
    }
    copy(t) {
        return super.copy(t), this.v1.copy(t.v1), this.v2.copy(t.v2), this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.v1 = this.v1.toArray(), t.v2 = this.v2.toArray(), t;
    }
    fromJSON(t) {
        return super.fromJSON(t), this.v1.fromArray(t.v1), this.v2.fromArray(t.v2), this;
    }
}, Nr = class extends Rt {
    constructor(t = new w, e = new w){
        super(), this.isLineCurve3 = !0, this.type = "LineCurve3", this.v1 = t, this.v2 = e;
    }
    getPoint(t, e = new w) {
        let i = e;
        return t === 1 ? i.copy(this.v2) : (i.copy(this.v2).sub(this.v1), i.multiplyScalar(t).add(this.v1)), i;
    }
    getPointAt(t, e) {
        return this.getPoint(t, e);
    }
    getTangent(t, e = new w) {
        return e.subVectors(this.v2, this.v1).normalize();
    }
    getTangentAt(t, e) {
        return this.getTangent(t, e);
    }
    copy(t) {
        return super.copy(t), this.v1.copy(t.v1), this.v2.copy(t.v2), this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.v1 = this.v1.toArray(), t.v2 = this.v2.toArray(), t;
    }
    fromJSON(t) {
        return super.fromJSON(t), this.v1.fromArray(t.v1), this.v2.fromArray(t.v2), this;
    }
}, ln = class extends Rt {
    constructor(t = new T, e = new T, i = new T){
        super(), this.isQuadraticBezierCurve = !0, this.type = "QuadraticBezierCurve", this.v0 = t, this.v1 = e, this.v2 = i;
    }
    getPoint(t, e = new T) {
        let i = e, s = this.v0, n = this.v1, r = this.v2;
        return i.set(Vi(t, s.x, n.x, r.x), Vi(t, s.y, n.y, r.y)), i;
    }
    copy(t) {
        return super.copy(t), this.v0.copy(t.v0), this.v1.copy(t.v1), this.v2.copy(t.v2), this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.v0 = this.v0.toArray(), t.v1 = this.v1.toArray(), t.v2 = this.v2.toArray(), t;
    }
    fromJSON(t) {
        return super.fromJSON(t), this.v0.fromArray(t.v0), this.v1.fromArray(t.v1), this.v2.fromArray(t.v2), this;
    }
}, cn = class extends Rt {
    constructor(t = new w, e = new w, i = new w){
        super(), this.isQuadraticBezierCurve3 = !0, this.type = "QuadraticBezierCurve3", this.v0 = t, this.v1 = e, this.v2 = i;
    }
    getPoint(t, e = new w) {
        let i = e, s = this.v0, n = this.v1, r = this.v2;
        return i.set(Vi(t, s.x, n.x, r.x), Vi(t, s.y, n.y, r.y), Vi(t, s.z, n.z, r.z)), i;
    }
    copy(t) {
        return super.copy(t), this.v0.copy(t.v0), this.v1.copy(t.v1), this.v2.copy(t.v2), this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.v0 = this.v0.toArray(), t.v1 = this.v1.toArray(), t.v2 = this.v2.toArray(), t;
    }
    fromJSON(t) {
        return super.fromJSON(t), this.v0.fromArray(t.v0), this.v1.fromArray(t.v1), this.v2.fromArray(t.v2), this;
    }
}, un = class extends Rt {
    constructor(t = []){
        super(), this.isSplineCurve = !0, this.type = "SplineCurve", this.points = t;
    }
    getPoint(t, e = new T) {
        let i = e, s = this.points, n = (s.length - 1) * t, r = Math.floor(n), o = n - r, a = s[r === 0 ? r : r - 1], l = s[r], c = s[r > s.length - 2 ? s.length - 1 : r + 1], u = s[r > s.length - 3 ? s.length - 1 : r + 2];
        return i.set(lh(o, a.x, l.x, c.x, u.x), lh(o, a.y, l.y, c.y, u.y)), i;
    }
    copy(t) {
        super.copy(t), this.points = [];
        for(let e = 0, i = t.points.length; e < i; e++){
            let s = t.points[e];
            this.points.push(s.clone());
        }
        return this;
    }
    toJSON() {
        let t = super.toJSON();
        t.points = [];
        for(let e = 0, i = this.points.length; e < i; e++){
            let s = this.points[e];
            t.points.push(s.toArray());
        }
        return t;
    }
    fromJSON(t) {
        super.fromJSON(t), this.points = [];
        for(let e = 0, i = t.points.length; e < i; e++){
            let s = t.points[e];
            this.points.push(new T().fromArray(s));
        }
        return this;
    }
}, dn = Object.freeze({
    __proto__: null,
    ArcCurve: kr,
    CatmullRomCurve3: Pr,
    CubicBezierCurve: an,
    CubicBezierCurve3: Or,
    EllipseCurve: Yi,
    LineCurve: hn,
    LineCurve3: Nr,
    QuadraticBezierCurve: ln,
    QuadraticBezierCurve3: cn,
    SplineCurve: un
}), Vr = class extends Rt {
    constructor(){
        super(), this.type = "CurvePath", this.curves = [], this.autoClose = !1;
    }
    add(t) {
        this.curves.push(t);
    }
    closePath() {
        let t = this.curves[0].getPoint(0), e = this.curves[this.curves.length - 1].getPoint(1);
        if (!t.equals(e)) {
            let i = t.isVector2 === !0 ? "LineCurve" : "LineCurve3";
            this.curves.push(new dn[i](e, t));
        }
        return this;
    }
    getPoint(t, e) {
        let i = t * this.getLength(), s = this.getCurveLengths(), n = 0;
        for(; n < s.length;){
            if (s[n] >= i) {
                let r = s[n] - i, o = this.curves[n], a = o.getLength(), l = a === 0 ? 0 : 1 - r / a;
                return o.getPointAt(l, e);
            }
            n++;
        }
        return null;
    }
    getLength() {
        let t = this.getCurveLengths();
        return t[t.length - 1];
    }
    updateArcLengths() {
        this.needsUpdate = !0, this.cacheLengths = null, this.getCurveLengths();
    }
    getCurveLengths() {
        if (this.cacheLengths && this.cacheLengths.length === this.curves.length) return this.cacheLengths;
        let t = [], e = 0;
        for(let i = 0, s = this.curves.length; i < s; i++)e += this.curves[i].getLength(), t.push(e);
        return this.cacheLengths = t, t;
    }
    getSpacedPoints(t = 40) {
        let e = [];
        for(let i = 0; i <= t; i++)e.push(this.getPoint(i / t));
        return this.autoClose && e.push(e[0]), e;
    }
    getPoints(t = 12) {
        let e = [], i;
        for(let s = 0, n = this.curves; s < n.length; s++){
            let r = n[s], o = r.isEllipseCurve ? t * 2 : r.isLineCurve || r.isLineCurve3 ? 1 : r.isSplineCurve ? t * r.points.length : t, a = r.getPoints(o);
            for(let l = 0; l < a.length; l++){
                let c = a[l];
                i && i.equals(c) || (e.push(c), i = c);
            }
        }
        return this.autoClose && e.length > 1 && !e[e.length - 1].equals(e[0]) && e.push(e[0]), e;
    }
    copy(t) {
        super.copy(t), this.curves = [];
        for(let e = 0, i = t.curves.length; e < i; e++){
            let s = t.curves[e];
            this.curves.push(s.clone());
        }
        return this.autoClose = t.autoClose, this;
    }
    toJSON() {
        let t = super.toJSON();
        t.autoClose = this.autoClose, t.curves = [];
        for(let e = 0, i = this.curves.length; e < i; e++){
            let s = this.curves[e];
            t.curves.push(s.toJSON());
        }
        return t;
    }
    fromJSON(t) {
        super.fromJSON(t), this.autoClose = t.autoClose, this.curves = [];
        for(let e = 0, i = t.curves.length; e < i; e++){
            let s = t.curves[e];
            this.curves.push(new dn[s.type]().fromJSON(s));
        }
        return this;
    }
}, mi = class extends Vr {
    constructor(t){
        super(), this.type = "Path", this.currentPoint = new T, t && this.setFromPoints(t);
    }
    setFromPoints(t) {
        this.moveTo(t[0].x, t[0].y);
        for(let e = 1, i = t.length; e < i; e++)this.lineTo(t[e].x, t[e].y);
        return this;
    }
    moveTo(t, e) {
        return this.currentPoint.set(t, e), this;
    }
    lineTo(t, e) {
        let i = new hn(this.currentPoint.clone(), new T(t, e));
        return this.curves.push(i), this.currentPoint.set(t, e), this;
    }
    quadraticCurveTo(t, e, i, s) {
        let n = new ln(this.currentPoint.clone(), new T(t, e), new T(i, s));
        return this.curves.push(n), this.currentPoint.set(i, s), this;
    }
    bezierCurveTo(t, e, i, s, n, r) {
        let o = new an(this.currentPoint.clone(), new T(t, e), new T(i, s), new T(n, r));
        return this.curves.push(o), this.currentPoint.set(n, r), this;
    }
    splineThru(t) {
        let e = [
            this.currentPoint.clone()
        ].concat(t), i = new un(e);
        return this.curves.push(i), this.currentPoint.copy(t[t.length - 1]), this;
    }
    arc(t, e, i, s, n, r) {
        let o = this.currentPoint.x, a = this.currentPoint.y;
        return this.absarc(t + o, e + a, i, s, n, r), this;
    }
    absarc(t, e, i, s, n, r) {
        return this.absellipse(t, e, i, i, s, n, r), this;
    }
    ellipse(t, e, i, s, n, r, o, a) {
        let l = this.currentPoint.x, c = this.currentPoint.y;
        return this.absellipse(t + l, e + c, i, s, n, r, o, a), this;
    }
    absellipse(t, e, i, s, n, r, o, a) {
        let l = new Yi(t, e, i, s, n, r, o, a);
        if (this.curves.length > 0) {
            let u = l.getPoint(0);
            u.equals(this.currentPoint) || this.lineTo(u.x, u.y);
        }
        this.curves.push(l);
        let c = l.getPoint(1);
        return this.currentPoint.copy(c), this;
    }
    copy(t) {
        return super.copy(t), this.currentPoint.copy(t.currentPoint), this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.currentPoint = this.currentPoint.toArray(), t;
    }
    fromJSON(t) {
        return super.fromJSON(t), this.currentPoint.fromArray(t.currentPoint), this;
    }
}, pn = class h extends L {
    constructor(t = [
        new T(0, -.5),
        new T(.5, 0),
        new T(0, .5)
    ], e = 12, i = 0, s = Math.PI * 2){
        super(), this.type = "LatheGeometry", this.parameters = {
            points: t,
            segments: e,
            phiStart: i,
            phiLength: s
        }, e = Math.floor(e), s = N(s, 0, Math.PI * 2);
        let n = [], r = [], o = [], a = [], l = [], c = 1 / e, u = new w, d = new T, p = new w, f = new w, m = new w, y1 = 0, g = 0;
        for(let x1 = 0; x1 <= t.length - 1; x1++)switch(x1){
            case 0:
                y1 = t[x1 + 1].x - t[x1].x, g = t[x1 + 1].y - t[x1].y, p.x = g * 1, p.y = -y1, p.z = g * 0, m.copy(p), p.normalize(), a.push(p.x, p.y, p.z);
                break;
            case t.length - 1:
                a.push(m.x, m.y, m.z);
                break;
            default:
                y1 = t[x1 + 1].x - t[x1].x, g = t[x1 + 1].y - t[x1].y, p.x = g * 1, p.y = -y1, p.z = g * 0, f.copy(p), p.x += m.x, p.y += m.y, p.z += m.z, p.normalize(), a.push(p.x, p.y, p.z), m.copy(f);
        }
        for(let x1 = 0; x1 <= e; x1++){
            let b = i + x1 * c * s, M = Math.sin(b), _ = Math.cos(b);
            for(let v = 0; v <= t.length - 1; v++){
                u.x = t[v].x * M, u.y = t[v].y, u.z = t[v].x * _, r.push(u.x, u.y, u.z), d.x = x1 / e, d.y = v / (t.length - 1), o.push(d.x, d.y);
                let S = a[3 * v + 0] * M, A = a[3 * v + 1], I = a[3 * v + 0] * _;
                l.push(S, A, I);
            }
        }
        for(let x1 = 0; x1 < e; x1++)for(let b = 0; b < t.length - 1; b++){
            let M = b + x1 * t.length, _ = M, v = M + t.length, S = M + t.length + 1, A = M + 1;
            n.push(_, v, A), n.push(S, A, v);
        }
        this.setIndex(n), this.setAttribute("position", new E(r, 3)), this.setAttribute("uv", new E(o, 2)), this.setAttribute("normal", new E(l, 3));
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.points, t.segments, t.phiStart, t.phiLength);
    }
}, Dr = class h extends pn {
    constructor(t = 1, e = 1, i = 4, s = 8){
        let n = new mi;
        n.absarc(0, -e / 2, t, Math.PI * 1.5, 0), n.absarc(0, e / 2, t, 0, Math.PI * .5), super(n.getPoints(i), s), this.type = "CapsuleGeometry", this.parameters = {
            radius: t,
            length: e,
            capSegments: i,
            radialSegments: s
        };
    }
    static fromJSON(t) {
        return new h(t.radius, t.length, t.capSegments, t.radialSegments);
    }
}, Lr = class h extends L {
    constructor(t = 1, e = 32, i = 0, s = Math.PI * 2){
        super(), this.type = "CircleGeometry", this.parameters = {
            radius: t,
            segments: e,
            thetaStart: i,
            thetaLength: s
        }, e = Math.max(3, e);
        let n = [], r = [], o = [], a = [], l = new w, c = new T;
        r.push(0, 0, 0), o.push(0, 0, 1), a.push(.5, .5);
        for(let u = 0, d = 3; u <= e; u++, d += 3){
            let p = i + u / e * s;
            l.x = t * Math.cos(p), l.y = t * Math.sin(p), r.push(l.x, l.y, l.z), o.push(0, 0, 1), c.x = (r[d] / t + 1) / 2, c.y = (r[d + 1] / t + 1) / 2, a.push(c.x, c.y);
        }
        for(let u = 1; u <= e; u++)n.push(u, u + 1, 0);
        this.setIndex(n), this.setAttribute("position", new E(r, 3)), this.setAttribute("normal", new E(o, 3)), this.setAttribute("uv", new E(a, 2));
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.radius, t.segments, t.thetaStart, t.thetaLength);
    }
}, $i = class h extends L {
    constructor(t = 1, e = 1, i = 1, s = 32, n = 1, r = !1, o = 0, a = Math.PI * 2){
        super(), this.type = "CylinderGeometry", this.parameters = {
            radiusTop: t,
            radiusBottom: e,
            height: i,
            radialSegments: s,
            heightSegments: n,
            openEnded: r,
            thetaStart: o,
            thetaLength: a
        };
        let l = this;
        s = Math.floor(s), n = Math.floor(n);
        let c = [], u = [], d = [], p = [], f = 0, m = [], y1 = i / 2, g = 0;
        x1(), r === !1 && (t > 0 && b(!0), e > 0 && b(!1)), this.setIndex(c), this.setAttribute("position", new E(u, 3)), this.setAttribute("normal", new E(d, 3)), this.setAttribute("uv", new E(p, 2));
        function x1() {
            let M = new w, _ = new w, v = 0, S = (e - t) / i;
            for(let A = 0; A <= n; A++){
                let I = [], C = A / n, k = C * (e - t) + t;
                for(let U = 0; U <= s; U++){
                    let W = U / s, H = W * a + o, Y = Math.sin(H), Q = Math.cos(H);
                    _.x = k * Y, _.y = -C * i + y1, _.z = k * Q, u.push(_.x, _.y, _.z), M.set(Y, S, Q).normalize(), d.push(M.x, M.y, M.z), p.push(W, 1 - C), I.push(f++);
                }
                m.push(I);
            }
            for(let A = 0; A < s; A++)for(let I = 0; I < n; I++){
                let C = m[I][A], k = m[I + 1][A], U = m[I + 1][A + 1], W = m[I][A + 1];
                (t > 0 || I !== 0) && (c.push(C, k, W), v += 3), (e > 0 || I !== n - 1) && (c.push(k, U, W), v += 3);
            }
            l.addGroup(g, v, 0), g += v;
        }
        function b(M) {
            let _ = f, v = new T, S = new w, A = 0, I = M === !0 ? t : e, C = M === !0 ? 1 : -1;
            for(let U = 1; U <= s; U++)u.push(0, y1 * C, 0), d.push(0, C, 0), p.push(.5, .5), f++;
            let k = f;
            for(let U = 0; U <= s; U++){
                let H = U / s * a + o, Y = Math.cos(H), Q = Math.sin(H);
                S.x = I * Q, S.y = y1 * C, S.z = I * Y, u.push(S.x, S.y, S.z), d.push(0, C, 0), v.x = Y * .5 + .5, v.y = Q * .5 * C + .5, p.push(v.x, v.y), f++;
            }
            for(let U = 0; U < s; U++){
                let W = _ + U, H = k + U;
                M === !0 ? c.push(H, H + 1, W) : c.push(H + 1, H, W), A += 3;
            }
            l.addGroup(g, A, M === !0 ? 1 : 2), g += A;
        }
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.radiusTop, t.radiusBottom, t.height, t.radialSegments, t.heightSegments, t.openEnded, t.thetaStart, t.thetaLength);
    }
}, Ur = class h extends $i {
    constructor(t = 1, e = 1, i = 32, s = 1, n = !1, r = 0, o = Math.PI * 2){
        super(0, t, e, i, s, n, r, o), this.type = "ConeGeometry", this.parameters = {
            radius: t,
            height: e,
            radialSegments: i,
            heightSegments: s,
            openEnded: n,
            thetaStart: r,
            thetaLength: o
        };
    }
    static fromJSON(t) {
        return new h(t.radius, t.height, t.radialSegments, t.heightSegments, t.openEnded, t.thetaStart, t.thetaLength);
    }
}, We = class h extends L {
    constructor(t = [], e = [], i = 1, s = 0){
        super(), this.type = "PolyhedronGeometry", this.parameters = {
            vertices: t,
            indices: e,
            radius: i,
            detail: s
        };
        let n = [], r = [];
        o(s), l(i), c(), this.setAttribute("position", new E(n, 3)), this.setAttribute("normal", new E(n.slice(), 3)), this.setAttribute("uv", new E(r, 2)), s === 0 ? this.computeVertexNormals() : this.normalizeNormals();
        function o(x1) {
            let b = new w, M = new w, _ = new w;
            for(let v = 0; v < e.length; v += 3)p(e[v + 0], b), p(e[v + 1], M), p(e[v + 2], _), a(b, M, _, x1);
        }
        function a(x1, b, M, _) {
            let v = _ + 1, S = [];
            for(let A = 0; A <= v; A++){
                S[A] = [];
                let I = x1.clone().lerp(M, A / v), C = b.clone().lerp(M, A / v), k = v - A;
                for(let U = 0; U <= k; U++)U === 0 && A === v ? S[A][U] = I : S[A][U] = I.clone().lerp(C, U / k);
            }
            for(let A = 0; A < v; A++)for(let I = 0; I < 2 * (v - A) - 1; I++){
                let C = Math.floor(I / 2);
                I % 2 === 0 ? (d(S[A][C + 1]), d(S[A + 1][C]), d(S[A][C])) : (d(S[A][C + 1]), d(S[A + 1][C + 1]), d(S[A + 1][C]));
            }
        }
        function l(x1) {
            let b = new w;
            for(let M = 0; M < n.length; M += 3)b.x = n[M + 0], b.y = n[M + 1], b.z = n[M + 2], b.normalize().multiplyScalar(x1), n[M + 0] = b.x, n[M + 1] = b.y, n[M + 2] = b.z;
        }
        function c() {
            let x1 = new w;
            for(let b = 0; b < n.length; b += 3){
                x1.x = n[b + 0], x1.y = n[b + 1], x1.z = n[b + 2];
                let M = y1(x1) / 2 / Math.PI + .5, _ = g(x1) / Math.PI + .5;
                r.push(M, 1 - _);
            }
            f(), u();
        }
        function u() {
            for(let x1 = 0; x1 < r.length; x1 += 6){
                let b = r[x1 + 0], M = r[x1 + 2], _ = r[x1 + 4], v = Math.max(b, M, _), S = Math.min(b, M, _);
                v > .9 && S < .1 && (b < .2 && (r[x1 + 0] += 1), M < .2 && (r[x1 + 2] += 1), _ < .2 && (r[x1 + 4] += 1));
            }
        }
        function d(x1) {
            n.push(x1.x, x1.y, x1.z);
        }
        function p(x1, b) {
            let M = x1 * 3;
            b.x = t[M + 0], b.y = t[M + 1], b.z = t[M + 2];
        }
        function f() {
            let x1 = new w, b = new w, M = new w, _ = new w, v = new T, S = new T, A = new T;
            for(let I = 0, C = 0; I < n.length; I += 9, C += 6){
                x1.set(n[I + 0], n[I + 1], n[I + 2]), b.set(n[I + 3], n[I + 4], n[I + 5]), M.set(n[I + 6], n[I + 7], n[I + 8]), v.set(r[C + 0], r[C + 1]), S.set(r[C + 2], r[C + 3]), A.set(r[C + 4], r[C + 5]), _.copy(x1).add(b).add(M).divideScalar(3);
                let k = y1(_);
                m(v, C + 0, x1, k), m(S, C + 2, b, k), m(A, C + 4, M, k);
            }
        }
        function m(x1, b, M, _) {
            _ < 0 && x1.x === 1 && (r[b] = x1.x - 1), M.x === 0 && M.z === 0 && (r[b] = _ / 2 / Math.PI + .5);
        }
        function y1(x1) {
            return Math.atan2(x1.z, -x1.x);
        }
        function g(x1) {
            return Math.atan2(-x1.y, Math.sqrt(x1.x * x1.x + x1.z * x1.z));
        }
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.vertices, t.indices, t.radius, t.details);
    }
}, Wr = class h extends We {
    constructor(t = 1, e = 0){
        let i = (1 + Math.sqrt(5)) / 2, s = 1 / i, n = [
            -1,
            -1,
            -1,
            -1,
            -1,
            1,
            -1,
            1,
            -1,
            -1,
            1,
            1,
            1,
            -1,
            -1,
            1,
            -1,
            1,
            1,
            1,
            -1,
            1,
            1,
            1,
            0,
            -s,
            -i,
            0,
            -s,
            i,
            0,
            s,
            -i,
            0,
            s,
            i,
            -s,
            -i,
            0,
            -s,
            i,
            0,
            s,
            -i,
            0,
            s,
            i,
            0,
            -i,
            0,
            -s,
            i,
            0,
            -s,
            -i,
            0,
            s,
            i,
            0,
            s
        ], r = [
            3,
            11,
            7,
            3,
            7,
            15,
            3,
            15,
            13,
            7,
            19,
            17,
            7,
            17,
            6,
            7,
            6,
            15,
            17,
            4,
            8,
            17,
            8,
            10,
            17,
            10,
            6,
            8,
            0,
            16,
            8,
            16,
            2,
            8,
            2,
            10,
            0,
            12,
            1,
            0,
            1,
            18,
            0,
            18,
            16,
            6,
            10,
            2,
            6,
            2,
            13,
            6,
            13,
            15,
            2,
            16,
            18,
            2,
            18,
            3,
            2,
            3,
            13,
            18,
            1,
            9,
            18,
            9,
            11,
            18,
            11,
            3,
            4,
            14,
            12,
            4,
            12,
            0,
            4,
            0,
            8,
            11,
            9,
            5,
            11,
            5,
            19,
            11,
            19,
            7,
            19,
            5,
            14,
            19,
            14,
            4,
            19,
            4,
            17,
            1,
            12,
            14,
            1,
            14,
            5,
            1,
            5,
            9
        ];
        super(n, r, t, e), this.type = "DodecahedronGeometry", this.parameters = {
            radius: t,
            detail: e
        };
    }
    static fromJSON(t) {
        return new h(t.radius, t.detail);
    }
}, Rs = new w, ks = new w, ar = new w, Ps = new ne, Hr = class extends L {
    constructor(t = null, e = 1){
        if (super(), this.type = "EdgesGeometry", this.parameters = {
            geometry: t,
            thresholdAngle: e
        }, t !== null) {
            let s = Math.pow(10, 4), n = Math.cos(De * e), r = t.getIndex(), o = t.getAttribute("position"), a = r ? r.count : o.count, l = [
                0,
                0,
                0
            ], c = [
                "a",
                "b",
                "c"
            ], u = new Array(3), d = {}, p = [];
            for(let f = 0; f < a; f += 3){
                r ? (l[0] = r.getX(f), l[1] = r.getX(f + 1), l[2] = r.getX(f + 2)) : (l[0] = f, l[1] = f + 1, l[2] = f + 2);
                let { a: m , b: y1 , c: g  } = Ps;
                if (m.fromBufferAttribute(o, l[0]), y1.fromBufferAttribute(o, l[1]), g.fromBufferAttribute(o, l[2]), Ps.getNormal(ar), u[0] = `${Math.round(m.x * s)},${Math.round(m.y * s)},${Math.round(m.z * s)}`, u[1] = `${Math.round(y1.x * s)},${Math.round(y1.y * s)},${Math.round(y1.z * s)}`, u[2] = `${Math.round(g.x * s)},${Math.round(g.y * s)},${Math.round(g.z * s)}`, !(u[0] === u[1] || u[1] === u[2] || u[2] === u[0])) for(let x1 = 0; x1 < 3; x1++){
                    let b = (x1 + 1) % 3, M = u[x1], _ = u[b], v = Ps[c[x1]], S = Ps[c[b]], A = `${M}_${_}`, I = `${_}_${M}`;
                    I in d && d[I] ? (ar.dot(d[I].normal) <= n && (p.push(v.x, v.y, v.z), p.push(S.x, S.y, S.z)), d[I] = null) : A in d || (d[A] = {
                        index0: l[x1],
                        index1: l[b],
                        normal: ar.clone()
                    });
                }
            }
            for(let f in d)if (d[f]) {
                let { index0: m , index1: y1  } = d[f];
                Rs.fromBufferAttribute(o, m), ks.fromBufferAttribute(o, y1), p.push(Rs.x, Rs.y, Rs.z), p.push(ks.x, ks.y, ks.z);
            }
            this.setAttribute("position", new E(p, 3));
        }
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
}, Me = class extends mi {
    constructor(t){
        super(t), this.uuid = It(), this.type = "Shape", this.holes = [];
    }
    getPointsHoles(t) {
        let e = [];
        for(let i = 0, s = this.holes.length; i < s; i++)e[i] = this.holes[i].getPoints(t);
        return e;
    }
    extractPoints(t) {
        return {
            shape: this.getPoints(t),
            holes: this.getPointsHoles(t)
        };
    }
    copy(t) {
        super.copy(t), this.holes = [];
        for(let e = 0, i = t.holes.length; e < i; e++){
            let s = t.holes[e];
            this.holes.push(s.clone());
        }
        return this;
    }
    toJSON() {
        let t = super.toJSON();
        t.uuid = this.uuid, t.holes = [];
        for(let e = 0, i = this.holes.length; e < i; e++){
            let s = this.holes[e];
            t.holes.push(s.toJSON());
        }
        return t;
    }
    fromJSON(t) {
        super.fromJSON(t), this.uuid = t.uuid, this.holes = [];
        for(let e = 0, i = t.holes.length; e < i; e++){
            let s = t.holes[e];
            this.holes.push(new mi().fromJSON(s));
        }
        return this;
    }
}, Yu = {
    triangulate: function(h, t, e = 2) {
        let i = t && t.length, s = i ? t[0] * e : h.length, n = El(h, 0, s, e, !0), r = [];
        if (!n || n.next === n.prev) return r;
        let o, a, l, c, u, d, p;
        if (i && (n = td(h, t, n, e)), h.length > 80 * e) {
            o = l = h[0], a = c = h[1];
            for(let f = e; f < s; f += e)u = h[f], d = h[f + 1], u < o && (o = u), d < a && (a = d), u > l && (l = u), d > c && (c = d);
            p = Math.max(l - o, c - a), p = p !== 0 ? 32767 / p : 0;
        }
        return Qi(n, r, e, o, a, p, 0), r;
    }
};
function El(h, t, e, i, s) {
    let n, r;
    if (s === ud(h, t, e, i) > 0) for(n = t; n < e; n += i)r = ch(n, h[n], h[n + 1], r);
    else for(n = e - i; n >= t; n -= i)r = ch(n, h[n], h[n + 1], r);
    return r && Sn(r, r.next) && (Ki(r), r = r.next), r;
}
function He(h, t) {
    if (!h) return h;
    t || (t = h);
    let e = h, i;
    do if (i = !1, !e.steiner && (Sn(e, e.next) || $(e.prev, e, e.next) === 0)) {
        if (Ki(e), e = t = e.prev, e === e.next) break;
        i = !0;
    } else e = e.next;
    while (i || e !== t)
    return t;
}
function Qi(h, t, e, i, s, n, r) {
    if (!h) return;
    !r && n && rd(h, i, s, n);
    let o = h, a, l;
    for(; h.prev !== h.next;){
        if (a = h.prev, l = h.next, n ? Qu(h, i, s, n) : $u(h)) {
            t.push(a.i / e | 0), t.push(h.i / e | 0), t.push(l.i / e | 0), Ki(h), h = l.next, o = l.next;
            continue;
        }
        if (h = l, h === o) {
            r ? r === 1 ? (h = ju(He(h), t, e), Qi(h, t, e, i, s, n, 2)) : r === 2 && Ku(h, t, e, i, s, n) : Qi(He(h), t, e, i, s, n, 1);
            break;
        }
    }
}
function $u(h) {
    let t = h.prev, e = h, i = h.next;
    if ($(t, e, i) >= 0) return !1;
    let s = t.x, n = e.x, r = i.x, o = t.y, a = e.y, l = i.y, c = s < n ? s < r ? s : r : n < r ? n : r, u = o < a ? o < l ? o : l : a < l ? a : l, d = s > n ? s > r ? s : r : n > r ? n : r, p = o > a ? o > l ? o : l : a > l ? a : l, f = i.next;
    for(; f !== t;){
        if (f.x >= c && f.x <= d && f.y >= u && f.y <= p && ui(s, o, n, a, r, l, f.x, f.y) && $(f.prev, f, f.next) >= 0) return !1;
        f = f.next;
    }
    return !0;
}
function Qu(h, t, e, i) {
    let s = h.prev, n = h, r = h.next;
    if ($(s, n, r) >= 0) return !1;
    let o = s.x, a = n.x, l = r.x, c = s.y, u = n.y, d = r.y, p = o < a ? o < l ? o : l : a < l ? a : l, f = c < u ? c < d ? c : d : u < d ? u : d, m = o > a ? o > l ? o : l : a > l ? a : l, y1 = c > u ? c > d ? c : d : u > d ? u : d, g = qr(p, f, t, e, i), x1 = qr(m, y1, t, e, i), b = h.prevZ, M = h.nextZ;
    for(; b && b.z >= g && M && M.z <= x1;){
        if (b.x >= p && b.x <= m && b.y >= f && b.y <= y1 && b !== s && b !== r && ui(o, c, a, u, l, d, b.x, b.y) && $(b.prev, b, b.next) >= 0 || (b = b.prevZ, M.x >= p && M.x <= m && M.y >= f && M.y <= y1 && M !== s && M !== r && ui(o, c, a, u, l, d, M.x, M.y) && $(M.prev, M, M.next) >= 0)) return !1;
        M = M.nextZ;
    }
    for(; b && b.z >= g;){
        if (b.x >= p && b.x <= m && b.y >= f && b.y <= y1 && b !== s && b !== r && ui(o, c, a, u, l, d, b.x, b.y) && $(b.prev, b, b.next) >= 0) return !1;
        b = b.prevZ;
    }
    for(; M && M.z <= x1;){
        if (M.x >= p && M.x <= m && M.y >= f && M.y <= y1 && M !== s && M !== r && ui(o, c, a, u, l, d, M.x, M.y) && $(M.prev, M, M.next) >= 0) return !1;
        M = M.nextZ;
    }
    return !0;
}
function ju(h, t, e) {
    let i = h;
    do {
        let s = i.prev, n = i.next.next;
        !Sn(s, n) && Rl(s, i, i.next, n) && ji(s, n) && ji(n, s) && (t.push(s.i / e | 0), t.push(i.i / e | 0), t.push(n.i / e | 0), Ki(i), Ki(i.next), i = h = n), i = i.next;
    }while (i !== h)
    return He(i);
}
function Ku(h, t, e, i, s, n) {
    let r = h;
    do {
        let o = r.next.next;
        for(; o !== r.prev;){
            if (r.i !== o.i && hd(r, o)) {
                let a = kl(r, o);
                r = He(r, r.next), a = He(a, a.next), Qi(r, t, e, i, s, n, 0), Qi(a, t, e, i, s, n, 0);
                return;
            }
            o = o.next;
        }
        r = r.next;
    }while (r !== h)
}
function td(h, t, e, i) {
    let s = [], n, r, o, a, l;
    for(n = 0, r = t.length; n < r; n++)o = t[n] * i, a = n < r - 1 ? t[n + 1] * i : h.length, l = El(h, o, a, i, !1), l === l.next && (l.steiner = !0), s.push(ad(l));
    for(s.sort(ed), n = 0; n < s.length; n++)e = id(s[n], e);
    return e;
}
function ed(h, t) {
    return h.x - t.x;
}
function id(h, t) {
    let e = sd(h, t);
    if (!e) return t;
    let i = kl(e, h);
    return He(i, i.next), He(e, e.next);
}
function sd(h, t) {
    let e = t, i = -1 / 0, s, n = h.x, r = h.y;
    do {
        if (r <= e.y && r >= e.next.y && e.next.y !== e.y) {
            let d = e.x + (r - e.y) * (e.next.x - e.x) / (e.next.y - e.y);
            if (d <= n && d > i && (i = d, s = e.x < e.next.x ? e : e.next, d === n)) return s;
        }
        e = e.next;
    }while (e !== t)
    if (!s) return null;
    let o = s, a = s.x, l = s.y, c = 1 / 0, u;
    e = s;
    do n >= e.x && e.x >= a && n !== e.x && ui(r < l ? n : i, r, a, l, r < l ? i : n, r, e.x, e.y) && (u = Math.abs(r - e.y) / (n - e.x), ji(e, h) && (u < c || u === c && (e.x > s.x || e.x === s.x && nd(s, e))) && (s = e, c = u)), e = e.next;
    while (e !== o)
    return s;
}
function nd(h, t) {
    return $(h.prev, h, t.prev) < 0 && $(t.next, h, h.next) < 0;
}
function rd(h, t, e, i) {
    let s = h;
    do s.z === 0 && (s.z = qr(s.x, s.y, t, e, i)), s.prevZ = s.prev, s.nextZ = s.next, s = s.next;
    while (s !== h)
    s.prevZ.nextZ = null, s.prevZ = null, od(s);
}
function od(h) {
    let t, e, i, s, n, r, o, a, l = 1;
    do {
        for(e = h, h = null, n = null, r = 0; e;){
            for(r++, i = e, o = 0, t = 0; t < l && (o++, i = i.nextZ, !!i); t++);
            for(a = l; o > 0 || a > 0 && i;)o !== 0 && (a === 0 || !i || e.z <= i.z) ? (s = e, e = e.nextZ, o--) : (s = i, i = i.nextZ, a--), n ? n.nextZ = s : h = s, s.prevZ = n, n = s;
            e = i;
        }
        n.nextZ = null, l *= 2;
    }while (r > 1)
    return h;
}
function qr(h, t, e, i, s) {
    return h = (h - e) * s | 0, t = (t - i) * s | 0, h = (h | h << 8) & 16711935, h = (h | h << 4) & 252645135, h = (h | h << 2) & 858993459, h = (h | h << 1) & 1431655765, t = (t | t << 8) & 16711935, t = (t | t << 4) & 252645135, t = (t | t << 2) & 858993459, t = (t | t << 1) & 1431655765, h | t << 1;
}
function ad(h) {
    let t = h, e = h;
    do (t.x < e.x || t.x === e.x && t.y < e.y) && (e = t), t = t.next;
    while (t !== h)
    return e;
}
function ui(h, t, e, i, s, n, r, o) {
    return (s - r) * (t - o) >= (h - r) * (n - o) && (h - r) * (i - o) >= (e - r) * (t - o) && (e - r) * (n - o) >= (s - r) * (i - o);
}
function hd(h, t) {
    return h.next.i !== t.i && h.prev.i !== t.i && !ld(h, t) && (ji(h, t) && ji(t, h) && cd(h, t) && ($(h.prev, h, t.prev) || $(h, t.prev, t)) || Sn(h, t) && $(h.prev, h, h.next) > 0 && $(t.prev, t, t.next) > 0);
}
function $(h, t, e) {
    return (t.y - h.y) * (e.x - t.x) - (t.x - h.x) * (e.y - t.y);
}
function Sn(h, t) {
    return h.x === t.x && h.y === t.y;
}
function Rl(h, t, e, i) {
    let s = Ns($(h, t, e)), n = Ns($(h, t, i)), r = Ns($(e, i, h)), o = Ns($(e, i, t));
    return !!(s !== n && r !== o || s === 0 && Os(h, e, t) || n === 0 && Os(h, i, t) || r === 0 && Os(e, h, i) || o === 0 && Os(e, t, i));
}
function Os(h, t, e) {
    return t.x <= Math.max(h.x, e.x) && t.x >= Math.min(h.x, e.x) && t.y <= Math.max(h.y, e.y) && t.y >= Math.min(h.y, e.y);
}
function Ns(h) {
    return h > 0 ? 1 : h < 0 ? -1 : 0;
}
function ld(h, t) {
    let e = h;
    do {
        if (e.i !== h.i && e.next.i !== h.i && e.i !== t.i && e.next.i !== t.i && Rl(e, e.next, h, t)) return !0;
        e = e.next;
    }while (e !== h)
    return !1;
}
function ji(h, t) {
    return $(h.prev, h, h.next) < 0 ? $(h, t, h.next) >= 0 && $(h, h.prev, t) >= 0 : $(h, t, h.prev) < 0 || $(h, h.next, t) < 0;
}
function cd(h, t) {
    let e = h, i = !1, s = (h.x + t.x) / 2, n = (h.y + t.y) / 2;
    do e.y > n != e.next.y > n && e.next.y !== e.y && s < (e.next.x - e.x) * (n - e.y) / (e.next.y - e.y) + e.x && (i = !i), e = e.next;
    while (e !== h)
    return i;
}
function kl(h, t) {
    let e = new Gr(h.i, h.x, h.y), i = new Gr(t.i, t.x, t.y), s = h.next, n = t.prev;
    return h.next = t, t.prev = h, e.next = s, s.prev = e, i.next = e, e.prev = i, n.next = i, i.prev = n, i;
}
function ch(h, t, e, i) {
    let s = new Gr(h, t, e);
    return i ? (s.next = i.next, s.prev = i, i.next.prev = s, i.next = s) : (s.prev = s, s.next = s), s;
}
function Ki(h) {
    h.next.prev = h.prev, h.prev.next = h.next, h.prevZ && (h.prevZ.nextZ = h.nextZ), h.nextZ && (h.nextZ.prevZ = h.prevZ);
}
function Gr(h, t, e) {
    this.i = h, this.x = t, this.y = e, this.prev = null, this.next = null, this.z = 0, this.prevZ = null, this.nextZ = null, this.steiner = !1;
}
function ud(h, t, e, i) {
    let s = 0;
    for(let n = t, r = e - i; n < e; n += i)s += (h[r] - h[n]) * (h[n + 1] + h[r + 1]), r = n;
    return s;
}
var he = class h {
    static area(t) {
        let e = t.length, i = 0;
        for(let s = e - 1, n = 0; n < e; s = n++)i += t[s].x * t[n].y - t[n].x * t[s].y;
        return i * .5;
    }
    static isClockWise(t) {
        return h.area(t) < 0;
    }
    static triangulateShape(t, e) {
        let i = [], s = [], n = [];
        uh(t), dh(i, t);
        let r = t.length;
        e.forEach(uh);
        for(let a = 0; a < e.length; a++)s.push(r), r += e[a].length, dh(i, e[a]);
        let o = Yu.triangulate(i, s);
        for(let a = 0; a < o.length; a += 3)n.push(o.slice(a, a + 3));
        return n;
    }
};
function uh(h) {
    let t = h.length;
    t > 2 && h[t - 1].equals(h[0]) && h.pop();
}
function dh(h, t) {
    for(let e = 0; e < t.length; e++)h.push(t[e].x), h.push(t[e].y);
}
var Xr = class h extends L {
    constructor(t = new Me([
        new T(.5, .5),
        new T(-.5, .5),
        new T(-.5, -.5),
        new T(.5, -.5)
    ]), e = {}){
        super(), this.type = "ExtrudeGeometry", this.parameters = {
            shapes: t,
            options: e
        }, t = Array.isArray(t) ? t : [
            t
        ];
        let i = this, s = [], n = [];
        for(let o = 0, a = t.length; o < a; o++){
            let l = t[o];
            r(l);
        }
        this.setAttribute("position", new E(s, 3)), this.setAttribute("uv", new E(n, 2)), this.computeVertexNormals();
        function r(o) {
            let a = [], l = e.curveSegments !== void 0 ? e.curveSegments : 12, c = e.steps !== void 0 ? e.steps : 1, u = e.depth !== void 0 ? e.depth : 1, d = e.bevelEnabled !== void 0 ? e.bevelEnabled : !0, p = e.bevelThickness !== void 0 ? e.bevelThickness : .2, f = e.bevelSize !== void 0 ? e.bevelSize : p - .1, m = e.bevelOffset !== void 0 ? e.bevelOffset : 0, y1 = e.bevelSegments !== void 0 ? e.bevelSegments : 3, g = e.extrudePath, x1 = e.UVGenerator !== void 0 ? e.UVGenerator : dd, b, M = !1, _, v, S, A;
            g && (b = g.getSpacedPoints(c), M = !0, d = !1, _ = g.computeFrenetFrames(c, !1), v = new w, S = new w, A = new w), d || (y1 = 0, p = 0, f = 0, m = 0);
            let I = o.extractPoints(l), C = I.shape, k = I.holes;
            if (!he.isClockWise(C)) {
                C = C.reverse();
                for(let z = 0, F = k.length; z < F; z++){
                    let B = k[z];
                    he.isClockWise(B) && (k[z] = B.reverse());
                }
            }
            let W = he.triangulateShape(C, k), H = C;
            for(let z = 0, F = k.length; z < F; z++){
                let B = k[z];
                C = C.concat(B);
            }
            function Y(z, F, B) {
                return F || console.error("THREE.ExtrudeGeometry: vec does not exist"), z.clone().addScaledVector(F, B);
            }
            let Q = C.length, zt = W.length;
            function Pt(z, F, B) {
                let O, R, q, X = z.x - F.x, tt = z.y - F.y, yt = B.x - z.x, at = B.y - z.y, vi = X * X + tt * tt, In = X * at - tt * yt;
                if (Math.abs(In) > Number.EPSILON) {
                    let Qt = Math.sqrt(vi), $o = Math.sqrt(yt * yt + at * at), Qo = F.x - tt / Qt, jo = F.y + X / Qt, Dl = B.x - at / $o, Ll = B.y + yt / $o, Ko = ((Dl - Qo) * at - (Ll - jo) * yt) / (X * at - tt * yt);
                    O = Qo + X * Ko - z.x, R = jo + tt * Ko - z.y;
                    let ta = O * O + R * R;
                    if (ta <= 2) return new T(O, R);
                    q = Math.sqrt(ta / 2);
                } else {
                    let Qt = !1;
                    X > Number.EPSILON ? yt > Number.EPSILON && (Qt = !0) : X < -Number.EPSILON ? yt < -Number.EPSILON && (Qt = !0) : Math.sign(tt) === Math.sign(at) && (Qt = !0), Qt ? (O = -tt, R = X, q = Math.sqrt(vi)) : (O = X, R = tt, q = Math.sqrt(vi / 2));
                }
                return new T(O / q, R / q);
            }
            let j = [];
            for(let z = 0, F = H.length, B = F - 1, O = z + 1; z < F; z++, B++, O++)B === F && (B = 0), O === F && (O = 0), j[z] = Pt(H[z], H[B], H[O]);
            let st = [], K, Ot = j.concat();
            for(let z = 0, F = k.length; z < F; z++){
                let B = k[z];
                K = [];
                for(let O = 0, R = B.length, q = R - 1, X = O + 1; O < R; O++, q++, X++)q === R && (q = 0), X === R && (X = 0), K[O] = Pt(B[O], B[q], B[X]);
                st.push(K), Ot = Ot.concat(K);
            }
            for(let z = 0; z < y1; z++){
                let F = z / y1, B = p * Math.cos(F * Math.PI / 2), O = f * Math.sin(F * Math.PI / 2) + m;
                for(let R = 0, q = H.length; R < q; R++){
                    let X = Y(H[R], j[R], O);
                    Zt(X.x, X.y, -B);
                }
                for(let R = 0, q = k.length; R < q; R++){
                    let X = k[R];
                    K = st[R];
                    for(let tt = 0, yt = X.length; tt < yt; tt++){
                        let at = Y(X[tt], K[tt], O);
                        Zt(at.x, at.y, -B);
                    }
                }
            }
            let Se = f + m;
            for(let z = 0; z < Q; z++){
                let F = d ? Y(C[z], Ot[z], Se) : C[z];
                M ? (S.copy(_.normals[0]).multiplyScalar(F.x), v.copy(_.binormals[0]).multiplyScalar(F.y), A.copy(b[0]).add(S).add(v), Zt(A.x, A.y, A.z)) : Zt(F.x, F.y, 0);
            }
            for(let z = 1; z <= c; z++)for(let F = 0; F < Q; F++){
                let B = d ? Y(C[F], Ot[F], Se) : C[F];
                M ? (S.copy(_.normals[z]).multiplyScalar(B.x), v.copy(_.binormals[z]).multiplyScalar(B.y), A.copy(b[z]).add(S).add(v), Zt(A.x, A.y, A.z)) : Zt(B.x, B.y, u / c * z);
            }
            for(let z = y1 - 1; z >= 0; z--){
                let F = z / y1, B = p * Math.cos(F * Math.PI / 2), O = f * Math.sin(F * Math.PI / 2) + m;
                for(let R = 0, q = H.length; R < q; R++){
                    let X = Y(H[R], j[R], O);
                    Zt(X.x, X.y, u + B);
                }
                for(let R = 0, q = k.length; R < q; R++){
                    let X = k[R];
                    K = st[R];
                    for(let tt = 0, yt = X.length; tt < yt; tt++){
                        let at = Y(X[tt], K[tt], O);
                        M ? Zt(at.x, at.y + b[c - 1].y, b[c - 1].x + B) : Zt(at.x, at.y, u + B);
                    }
                }
            }
            Tn(), es();
            function Tn() {
                let z = s.length / 3;
                if (d) {
                    let F = 0, B = Q * F;
                    for(let O = 0; O < zt; O++){
                        let R = W[O];
                        is(R[2] + B, R[1] + B, R[0] + B);
                    }
                    F = c + y1 * 2, B = Q * F;
                    for(let O = 0; O < zt; O++){
                        let R = W[O];
                        is(R[0] + B, R[1] + B, R[2] + B);
                    }
                } else {
                    for(let F = 0; F < zt; F++){
                        let B = W[F];
                        is(B[2], B[1], B[0]);
                    }
                    for(let F = 0; F < zt; F++){
                        let B = W[F];
                        is(B[0] + Q * c, B[1] + Q * c, B[2] + Q * c);
                    }
                }
                i.addGroup(z, s.length / 3 - z, 0);
            }
            function es() {
                let z = s.length / 3, F = 0;
                Yo(H, F), F += H.length;
                for(let B = 0, O = k.length; B < O; B++){
                    let R = k[B];
                    Yo(R, F), F += R.length;
                }
                i.addGroup(z, s.length / 3 - z, 1);
            }
            function Yo(z, F) {
                let B = z.length;
                for(; --B >= 0;){
                    let O = B, R = B - 1;
                    R < 0 && (R = z.length - 1);
                    for(let q = 0, X = c + y1 * 2; q < X; q++){
                        let tt = Q * q, yt = Q * (q + 1), at = F + O + tt, vi = F + R + tt, In = F + R + yt, Qt = F + O + yt;
                        Vl(at, vi, In, Qt);
                    }
                }
            }
            function Zt(z, F, B) {
                a.push(z), a.push(F), a.push(B);
            }
            function is(z, F, B) {
                Yt(z), Yt(F), Yt(B);
                let O = s.length / 3, R = x1.generateTopUV(i, s, O - 3, O - 2, O - 1);
                $t(R[0]), $t(R[1]), $t(R[2]);
            }
            function Vl(z, F, B, O) {
                Yt(z), Yt(F), Yt(O), Yt(F), Yt(B), Yt(O);
                let R = s.length / 3, q = x1.generateSideWallUV(i, s, R - 6, R - 3, R - 2, R - 1);
                $t(q[0]), $t(q[1]), $t(q[3]), $t(q[1]), $t(q[2]), $t(q[3]);
            }
            function Yt(z) {
                s.push(a[z * 3 + 0]), s.push(a[z * 3 + 1]), s.push(a[z * 3 + 2]);
            }
            function $t(z) {
                n.push(z.x), n.push(z.y);
            }
        }
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    toJSON() {
        let t = super.toJSON(), e = this.parameters.shapes, i = this.parameters.options;
        return pd(e, i, t);
    }
    static fromJSON(t, e) {
        let i = [];
        for(let n = 0, r = t.shapes.length; n < r; n++){
            let o = e[t.shapes[n]];
            i.push(o);
        }
        let s = t.options.extrudePath;
        return s !== void 0 && (t.options.extrudePath = new dn[s.type]().fromJSON(s)), new h(i, t.options);
    }
}, dd = {
    generateTopUV: function(h, t, e, i, s) {
        let n = t[e * 3], r = t[e * 3 + 1], o = t[i * 3], a = t[i * 3 + 1], l = t[s * 3], c = t[s * 3 + 1];
        return [
            new T(n, r),
            new T(o, a),
            new T(l, c)
        ];
    },
    generateSideWallUV: function(h, t, e, i, s, n) {
        let r = t[e * 3], o = t[e * 3 + 1], a = t[e * 3 + 2], l = t[i * 3], c = t[i * 3 + 1], u = t[i * 3 + 2], d = t[s * 3], p = t[s * 3 + 1], f = t[s * 3 + 2], m = t[n * 3], y1 = t[n * 3 + 1], g = t[n * 3 + 2];
        return Math.abs(o - c) < Math.abs(r - l) ? [
            new T(r, 1 - a),
            new T(l, 1 - u),
            new T(d, 1 - f),
            new T(m, 1 - g)
        ] : [
            new T(o, 1 - a),
            new T(c, 1 - u),
            new T(p, 1 - f),
            new T(y1, 1 - g)
        ];
    }
};
function pd(h, t, e) {
    if (e.shapes = [], Array.isArray(h)) for(let i = 0, s = h.length; i < s; i++){
        let n = h[i];
        e.shapes.push(n.uuid);
    }
    else e.shapes.push(h.uuid);
    return e.options = Object.assign({}, t), t.extrudePath !== void 0 && (e.options.extrudePath = t.extrudePath.toJSON()), e;
}
var Jr = class h extends We {
    constructor(t = 1, e = 0){
        let i = (1 + Math.sqrt(5)) / 2, s = [
            -1,
            i,
            0,
            1,
            i,
            0,
            -1,
            -i,
            0,
            1,
            -i,
            0,
            0,
            -1,
            i,
            0,
            1,
            i,
            0,
            -1,
            -i,
            0,
            1,
            -i,
            i,
            0,
            -1,
            i,
            0,
            1,
            -i,
            0,
            -1,
            -i,
            0,
            1
        ], n = [
            0,
            11,
            5,
            0,
            5,
            1,
            0,
            1,
            7,
            0,
            7,
            10,
            0,
            10,
            11,
            1,
            5,
            9,
            5,
            11,
            4,
            11,
            10,
            2,
            10,
            7,
            6,
            7,
            1,
            8,
            3,
            9,
            4,
            3,
            4,
            2,
            3,
            2,
            6,
            3,
            6,
            8,
            3,
            8,
            9,
            4,
            9,
            5,
            2,
            4,
            11,
            6,
            2,
            10,
            8,
            6,
            7,
            9,
            8,
            1
        ];
        super(s, n, t, e), this.type = "IcosahedronGeometry", this.parameters = {
            radius: t,
            detail: e
        };
    }
    static fromJSON(t) {
        return new h(t.radius, t.detail);
    }
}, fn = class h extends We {
    constructor(t = 1, e = 0){
        let i = [
            1,
            0,
            0,
            -1,
            0,
            0,
            0,
            1,
            0,
            0,
            -1,
            0,
            0,
            0,
            1,
            0,
            0,
            -1
        ], s = [
            0,
            2,
            4,
            0,
            4,
            3,
            0,
            3,
            5,
            0,
            5,
            2,
            1,
            2,
            5,
            1,
            5,
            3,
            1,
            3,
            4,
            1,
            4,
            2
        ];
        super(i, s, t, e), this.type = "OctahedronGeometry", this.parameters = {
            radius: t,
            detail: e
        };
    }
    static fromJSON(t) {
        return new h(t.radius, t.detail);
    }
}, Zr = class h extends L {
    constructor(t = 1, e = 1, i = 1, s = 1){
        super(), this.type = "PlaneGeometry", this.parameters = {
            width: t,
            height: e,
            widthSegments: i,
            heightSegments: s
        };
        let n = t / 2, r = e / 2, o = Math.floor(i), a = Math.floor(s), l = o + 1, c = a + 1, u = t / o, d = e / a, p = [], f = [], m = [], y1 = [];
        for(let g = 0; g < c; g++){
            let x1 = g * d - r;
            for(let b = 0; b < l; b++){
                let M = b * u - n;
                f.push(M, -x1, 0), m.push(0, 0, 1), y1.push(b / o), y1.push(1 - g / a);
            }
        }
        for(let g = 0; g < a; g++)for(let x1 = 0; x1 < o; x1++){
            let b = x1 + l * g, M = x1 + l * (g + 1), _ = x1 + 1 + l * (g + 1), v = x1 + 1 + l * g;
            p.push(b, M, v), p.push(M, _, v);
        }
        this.setIndex(p), this.setAttribute("position", new E(f, 3)), this.setAttribute("normal", new E(m, 3)), this.setAttribute("uv", new E(y1, 2));
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.width, t.height, t.widthSegments, t.heightSegments);
    }
}, Yr = class h extends L {
    constructor(t = .5, e = 1, i = 32, s = 1, n = 0, r = Math.PI * 2){
        super(), this.type = "RingGeometry", this.parameters = {
            innerRadius: t,
            outerRadius: e,
            thetaSegments: i,
            phiSegments: s,
            thetaStart: n,
            thetaLength: r
        }, i = Math.max(3, i), s = Math.max(1, s);
        let o = [], a = [], l = [], c = [], u = t, d = (e - t) / s, p = new w, f = new T;
        for(let m = 0; m <= s; m++){
            for(let y1 = 0; y1 <= i; y1++){
                let g = n + y1 / i * r;
                p.x = u * Math.cos(g), p.y = u * Math.sin(g), a.push(p.x, p.y, p.z), l.push(0, 0, 1), f.x = (p.x / e + 1) / 2, f.y = (p.y / e + 1) / 2, c.push(f.x, f.y);
            }
            u += d;
        }
        for(let m = 0; m < s; m++){
            let y1 = m * (i + 1);
            for(let g = 0; g < i; g++){
                let x1 = g + y1, b = x1, M = x1 + i + 1, _ = x1 + i + 2, v = x1 + 1;
                o.push(b, M, v), o.push(M, _, v);
            }
        }
        this.setIndex(o), this.setAttribute("position", new E(a, 3)), this.setAttribute("normal", new E(l, 3)), this.setAttribute("uv", new E(c, 2));
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.innerRadius, t.outerRadius, t.thetaSegments, t.phiSegments, t.thetaStart, t.thetaLength);
    }
}, $r = class h extends L {
    constructor(t = new Me([
        new T(0, .5),
        new T(-.5, -.5),
        new T(.5, -.5)
    ]), e = 12){
        super(), this.type = "ShapeGeometry", this.parameters = {
            shapes: t,
            curveSegments: e
        };
        let i = [], s = [], n = [], r = [], o = 0, a = 0;
        if (Array.isArray(t) === !1) l(t);
        else for(let c = 0; c < t.length; c++)l(t[c]), this.addGroup(o, a, c), o += a, a = 0;
        this.setIndex(i), this.setAttribute("position", new E(s, 3)), this.setAttribute("normal", new E(n, 3)), this.setAttribute("uv", new E(r, 2));
        function l(c) {
            let u = s.length / 3, d = c.extractPoints(e), p = d.shape, f = d.holes;
            he.isClockWise(p) === !1 && (p = p.reverse());
            for(let y1 = 0, g = f.length; y1 < g; y1++){
                let x1 = f[y1];
                he.isClockWise(x1) === !0 && (f[y1] = x1.reverse());
            }
            let m = he.triangulateShape(p, f);
            for(let y1 = 0, g = f.length; y1 < g; y1++){
                let x1 = f[y1];
                p = p.concat(x1);
            }
            for(let y1 = 0, g = p.length; y1 < g; y1++){
                let x1 = p[y1];
                s.push(x1.x, x1.y, 0), n.push(0, 0, 1), r.push(x1.x, x1.y);
            }
            for(let y1 = 0, g = m.length; y1 < g; y1++){
                let x1 = m[y1], b = x1[0] + u, M = x1[1] + u, _ = x1[2] + u;
                i.push(b, M, _), a += 3;
            }
        }
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    toJSON() {
        let t = super.toJSON(), e = this.parameters.shapes;
        return fd(e, t);
    }
    static fromJSON(t, e) {
        let i = [];
        for(let s = 0, n = t.shapes.length; s < n; s++){
            let r = e[t.shapes[s]];
            i.push(r);
        }
        return new h(i, t.curveSegments);
    }
};
function fd(h, t) {
    if (t.shapes = [], Array.isArray(h)) for(let e = 0, i = h.length; e < i; e++){
        let s = h[e];
        t.shapes.push(s.uuid);
    }
    else t.shapes.push(h.uuid);
    return t;
}
var mn = class h extends L {
    constructor(t = 1, e = 32, i = 16, s = 0, n = Math.PI * 2, r = 0, o = Math.PI){
        super(), this.type = "SphereGeometry", this.parameters = {
            radius: t,
            widthSegments: e,
            heightSegments: i,
            phiStart: s,
            phiLength: n,
            thetaStart: r,
            thetaLength: o
        }, e = Math.max(3, Math.floor(e)), i = Math.max(2, Math.floor(i));
        let a = Math.min(r + o, Math.PI), l = 0, c = [], u = new w, d = new w, p = [], f = [], m = [], y1 = [];
        for(let g = 0; g <= i; g++){
            let x1 = [], b = g / i, M = 0;
            g === 0 && r === 0 ? M = .5 / e : g === i && a === Math.PI && (M = -.5 / e);
            for(let _ = 0; _ <= e; _++){
                let v = _ / e;
                u.x = -t * Math.cos(s + v * n) * Math.sin(r + b * o), u.y = t * Math.cos(r + b * o), u.z = t * Math.sin(s + v * n) * Math.sin(r + b * o), f.push(u.x, u.y, u.z), d.copy(u).normalize(), m.push(d.x, d.y, d.z), y1.push(v + M, 1 - b), x1.push(l++);
            }
            c.push(x1);
        }
        for(let g = 0; g < i; g++)for(let x1 = 0; x1 < e; x1++){
            let b = c[g][x1 + 1], M = c[g][x1], _ = c[g + 1][x1], v = c[g + 1][x1 + 1];
            (g !== 0 || r > 0) && p.push(b, M, v), (g !== i - 1 || a < Math.PI) && p.push(M, _, v);
        }
        this.setIndex(p), this.setAttribute("position", new E(f, 3)), this.setAttribute("normal", new E(m, 3)), this.setAttribute("uv", new E(y1, 2));
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.radius, t.widthSegments, t.heightSegments, t.phiStart, t.phiLength, t.thetaStart, t.thetaLength);
    }
}, Qr = class h extends We {
    constructor(t = 1, e = 0){
        let i = [
            1,
            1,
            1,
            -1,
            -1,
            1,
            -1,
            1,
            -1,
            1,
            -1,
            -1
        ], s = [
            2,
            1,
            0,
            0,
            3,
            2,
            1,
            3,
            0,
            2,
            3,
            1
        ];
        super(i, s, t, e), this.type = "TetrahedronGeometry", this.parameters = {
            radius: t,
            detail: e
        };
    }
    static fromJSON(t) {
        return new h(t.radius, t.detail);
    }
}, jr = class h extends L {
    constructor(t = 1, e = .4, i = 12, s = 48, n = Math.PI * 2){
        super(), this.type = "TorusGeometry", this.parameters = {
            radius: t,
            tube: e,
            radialSegments: i,
            tubularSegments: s,
            arc: n
        }, i = Math.floor(i), s = Math.floor(s);
        let r = [], o = [], a = [], l = [], c = new w, u = new w, d = new w;
        for(let p = 0; p <= i; p++)for(let f = 0; f <= s; f++){
            let m = f / s * n, y1 = p / i * Math.PI * 2;
            u.x = (t + e * Math.cos(y1)) * Math.cos(m), u.y = (t + e * Math.cos(y1)) * Math.sin(m), u.z = e * Math.sin(y1), o.push(u.x, u.y, u.z), c.x = t * Math.cos(m), c.y = t * Math.sin(m), d.subVectors(u, c).normalize(), a.push(d.x, d.y, d.z), l.push(f / s), l.push(p / i);
        }
        for(let p = 1; p <= i; p++)for(let f = 1; f <= s; f++){
            let m = (s + 1) * p + f - 1, y1 = (s + 1) * (p - 1) + f - 1, g = (s + 1) * (p - 1) + f, x1 = (s + 1) * p + f;
            r.push(m, y1, x1), r.push(y1, g, x1);
        }
        this.setIndex(r), this.setAttribute("position", new E(o, 3)), this.setAttribute("normal", new E(a, 3)), this.setAttribute("uv", new E(l, 2));
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.radius, t.tube, t.radialSegments, t.tubularSegments, t.arc);
    }
}, Kr = class h extends L {
    constructor(t = 1, e = .4, i = 64, s = 8, n = 2, r = 3){
        super(), this.type = "TorusKnotGeometry", this.parameters = {
            radius: t,
            tube: e,
            tubularSegments: i,
            radialSegments: s,
            p: n,
            q: r
        }, i = Math.floor(i), s = Math.floor(s);
        let o = [], a = [], l = [], c = [], u = new w, d = new w, p = new w, f = new w, m = new w, y1 = new w, g = new w;
        for(let b = 0; b <= i; ++b){
            let M = b / i * n * Math.PI * 2;
            x1(M, n, r, t, p), x1(M + .01, n, r, t, f), y1.subVectors(f, p), g.addVectors(f, p), m.crossVectors(y1, g), g.crossVectors(m, y1), m.normalize(), g.normalize();
            for(let _ = 0; _ <= s; ++_){
                let v = _ / s * Math.PI * 2, S = -e * Math.cos(v), A = e * Math.sin(v);
                u.x = p.x + (S * g.x + A * m.x), u.y = p.y + (S * g.y + A * m.y), u.z = p.z + (S * g.z + A * m.z), a.push(u.x, u.y, u.z), d.subVectors(u, p).normalize(), l.push(d.x, d.y, d.z), c.push(b / i), c.push(_ / s);
            }
        }
        for(let b = 1; b <= i; b++)for(let M = 1; M <= s; M++){
            let _ = (s + 1) * (b - 1) + (M - 1), v = (s + 1) * b + (M - 1), S = (s + 1) * b + M, A = (s + 1) * (b - 1) + M;
            o.push(_, v, A), o.push(v, S, A);
        }
        this.setIndex(o), this.setAttribute("position", new E(a, 3)), this.setAttribute("normal", new E(l, 3)), this.setAttribute("uv", new E(c, 2));
        function x1(b, M, _, v, S) {
            let A = Math.cos(b), I = Math.sin(b), C = _ / M * b, k = Math.cos(C);
            S.x = v * (2 + k) * .5 * A, S.y = v * (2 + k) * I * .5, S.z = v * Math.sin(C) * .5;
        }
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    static fromJSON(t) {
        return new h(t.radius, t.tube, t.tubularSegments, t.radialSegments, t.p, t.q);
    }
}, to = class h extends L {
    constructor(t = new cn(new w(-1, -1, 0), new w(-1, 1, 0), new w(1, 1, 0)), e = 64, i = 1, s = 8, n = !1){
        super(), this.type = "TubeGeometry", this.parameters = {
            path: t,
            tubularSegments: e,
            radius: i,
            radialSegments: s,
            closed: n
        };
        let r = t.computeFrenetFrames(e, n);
        this.tangents = r.tangents, this.normals = r.normals, this.binormals = r.binormals;
        let o = new w, a = new w, l = new T, c = new w, u = [], d = [], p = [], f = [];
        m(), this.setIndex(f), this.setAttribute("position", new E(u, 3)), this.setAttribute("normal", new E(d, 3)), this.setAttribute("uv", new E(p, 2));
        function m() {
            for(let b = 0; b < e; b++)y1(b);
            y1(n === !1 ? e : 0), x1(), g();
        }
        function y1(b) {
            c = t.getPointAt(b / e, c);
            let M = r.normals[b], _ = r.binormals[b];
            for(let v = 0; v <= s; v++){
                let S = v / s * Math.PI * 2, A = Math.sin(S), I = -Math.cos(S);
                a.x = I * M.x + A * _.x, a.y = I * M.y + A * _.y, a.z = I * M.z + A * _.z, a.normalize(), d.push(a.x, a.y, a.z), o.x = c.x + i * a.x, o.y = c.y + i * a.y, o.z = c.z + i * a.z, u.push(o.x, o.y, o.z);
            }
        }
        function g() {
            for(let b = 1; b <= e; b++)for(let M = 1; M <= s; M++){
                let _ = (s + 1) * (b - 1) + (M - 1), v = (s + 1) * b + (M - 1), S = (s + 1) * b + M, A = (s + 1) * (b - 1) + M;
                f.push(_, v, A), f.push(v, S, A);
            }
        }
        function x1() {
            for(let b = 0; b <= e; b++)for(let M = 0; M <= s; M++)l.x = b / e, l.y = M / s, p.push(l.x, l.y);
        }
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.path = this.parameters.path.toJSON(), t;
    }
    static fromJSON(t) {
        return new h(new dn[t.path.type]().fromJSON(t.path), t.tubularSegments, t.radius, t.radialSegments, t.closed);
    }
}, eo = class extends L {
    constructor(t = null){
        if (super(), this.type = "WireframeGeometry", this.parameters = {
            geometry: t
        }, t !== null) {
            let e = [], i = new Set, s = new w, n = new w;
            if (t.index !== null) {
                let r = t.attributes.position, o = t.index, a = t.groups;
                a.length === 0 && (a = [
                    {
                        start: 0,
                        count: o.count,
                        materialIndex: 0
                    }
                ]);
                for(let l = 0, c = a.length; l < c; ++l){
                    let u = a[l], d = u.start, p = u.count;
                    for(let f = d, m = d + p; f < m; f += 3)for(let y1 = 0; y1 < 3; y1++){
                        let g = o.getX(f + y1), x1 = o.getX(f + (y1 + 1) % 3);
                        s.fromBufferAttribute(r, g), n.fromBufferAttribute(r, x1), ph(s, n, i) === !0 && (e.push(s.x, s.y, s.z), e.push(n.x, n.y, n.z));
                    }
                }
            } else {
                let r = t.attributes.position;
                for(let o = 0, a = r.count / 3; o < a; o++)for(let l = 0; l < 3; l++){
                    let c = 3 * o + l, u = 3 * o + (l + 1) % 3;
                    s.fromBufferAttribute(r, c), n.fromBufferAttribute(r, u), ph(s, n, i) === !0 && (e.push(s.x, s.y, s.z), e.push(n.x, n.y, n.z));
                }
            }
            this.setAttribute("position", new E(e, 3));
        }
    }
    copy(t) {
        return super.copy(t), this.parameters = Object.assign({}, t.parameters), this;
    }
};
function ph(h, t, e) {
    let i = `${h.x},${h.y},${h.z}-${t.x},${t.y},${t.z}`, s = `${t.x},${t.y},${t.z}-${h.x},${h.y},${h.z}`;
    return e.has(i) === !0 || e.has(s) === !0 ? !1 : (e.add(i), e.add(s), !0);
}
var fh = Object.freeze({
    __proto__: null,
    BoxGeometry: Ks,
    CapsuleGeometry: Dr,
    CircleGeometry: Lr,
    ConeGeometry: Ur,
    CylinderGeometry: $i,
    DodecahedronGeometry: Wr,
    EdgesGeometry: Hr,
    ExtrudeGeometry: Xr,
    IcosahedronGeometry: Jr,
    LatheGeometry: pn,
    OctahedronGeometry: fn,
    PlaneGeometry: Zr,
    PolyhedronGeometry: We,
    RingGeometry: Yr,
    ShapeGeometry: $r,
    SphereGeometry: mn,
    TetrahedronGeometry: Qr,
    TorusGeometry: jr,
    TorusKnotGeometry: Kr,
    TubeGeometry: to,
    WireframeGeometry: eo
}), io = class extends ct {
    constructor(t){
        super(), this.isShadowMaterial = !0, this.type = "ShadowMaterial", this.color = new P(0), this.transparent = !0, this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.color.copy(t.color), this.fog = t.fog, this;
    }
}, so = class extends qi {
    constructor(t){
        super(t), this.isRawShaderMaterial = !0, this.type = "RawShaderMaterial";
    }
}, yn = class extends ct {
    constructor(t){
        super(), this.isMeshStandardMaterial = !0, this.type = "MeshStandardMaterial", this.defines = {
            STANDARD: ""
        }, this.color = new P(16777215), this.roughness = 1, this.metalness = 0, this.map = null, this.lightMap = null, this.lightMapIntensity = 1, this.aoMap = null, this.aoMapIntensity = 1, this.emissive = new P(0), this.emissiveIntensity = 1, this.emissiveMap = null, this.bumpMap = null, this.bumpScale = 1, this.normalMap = null, this.normalMapType = _i, this.normalScale = new T(1, 1), this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.roughnessMap = null, this.metalnessMap = null, this.alphaMap = null, this.envMap = null, this.envMapRotation = new Xt, this.envMapIntensity = 1, this.wireframe = !1, this.wireframeLinewidth = 1, this.wireframeLinecap = "round", this.wireframeLinejoin = "round", this.flatShading = !1, this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.defines = {
            STANDARD: ""
        }, this.color.copy(t.color), this.roughness = t.roughness, this.metalness = t.metalness, this.map = t.map, this.lightMap = t.lightMap, this.lightMapIntensity = t.lightMapIntensity, this.aoMap = t.aoMap, this.aoMapIntensity = t.aoMapIntensity, this.emissive.copy(t.emissive), this.emissiveMap = t.emissiveMap, this.emissiveIntensity = t.emissiveIntensity, this.bumpMap = t.bumpMap, this.bumpScale = t.bumpScale, this.normalMap = t.normalMap, this.normalMapType = t.normalMapType, this.normalScale.copy(t.normalScale), this.displacementMap = t.displacementMap, this.displacementScale = t.displacementScale, this.displacementBias = t.displacementBias, this.roughnessMap = t.roughnessMap, this.metalnessMap = t.metalnessMap, this.alphaMap = t.alphaMap, this.envMap = t.envMap, this.envMapRotation.copy(t.envMapRotation), this.envMapIntensity = t.envMapIntensity, this.wireframe = t.wireframe, this.wireframeLinewidth = t.wireframeLinewidth, this.wireframeLinecap = t.wireframeLinecap, this.wireframeLinejoin = t.wireframeLinejoin, this.flatShading = t.flatShading, this.fog = t.fog, this;
    }
}, no = class extends yn {
    constructor(t){
        super(), this.isMeshPhysicalMaterial = !0, this.defines = {
            STANDARD: "",
            PHYSICAL: ""
        }, this.type = "MeshPhysicalMaterial", this.anisotropyRotation = 0, this.anisotropyMap = null, this.clearcoatMap = null, this.clearcoatRoughness = 0, this.clearcoatRoughnessMap = null, this.clearcoatNormalScale = new T(1, 1), this.clearcoatNormalMap = null, this.ior = 1.5, Object.defineProperty(this, "reflectivity", {
            get: function() {
                return N(2.5 * (this.ior - 1) / (this.ior + 1), 0, 1);
            },
            set: function(e) {
                this.ior = (1 + .4 * e) / (1 - .4 * e);
            }
        }), this.iridescenceMap = null, this.iridescenceIOR = 1.3, this.iridescenceThicknessRange = [
            100,
            400
        ], this.iridescenceThicknessMap = null, this.sheenColor = new P(0), this.sheenColorMap = null, this.sheenRoughness = 1, this.sheenRoughnessMap = null, this.transmissionMap = null, this.thickness = 0, this.thicknessMap = null, this.attenuationDistance = 1 / 0, this.attenuationColor = new P(1, 1, 1), this.specularIntensity = 1, this.specularIntensityMap = null, this.specularColor = new P(1, 1, 1), this.specularColorMap = null, this._anisotropy = 0, this._clearcoat = 0, this._dispersion = 0, this._iridescence = 0, this._sheen = 0, this._transmission = 0, this.setValues(t);
    }
    get anisotropy() {
        return this._anisotropy;
    }
    set anisotropy(t) {
        this._anisotropy > 0 != t > 0 && this.version++, this._anisotropy = t;
    }
    get clearcoat() {
        return this._clearcoat;
    }
    set clearcoat(t) {
        this._clearcoat > 0 != t > 0 && this.version++, this._clearcoat = t;
    }
    get iridescence() {
        return this._iridescence;
    }
    set iridescence(t) {
        this._iridescence > 0 != t > 0 && this.version++, this._iridescence = t;
    }
    get dispersion() {
        return this._dispersion;
    }
    set dispersion(t) {
        this._dispersion > 0 != t > 0 && this.version++, this._dispersion = t;
    }
    get sheen() {
        return this._sheen;
    }
    set sheen(t) {
        this._sheen > 0 != t > 0 && this.version++, this._sheen = t;
    }
    get transmission() {
        return this._transmission;
    }
    set transmission(t) {
        this._transmission > 0 != t > 0 && this.version++, this._transmission = t;
    }
    copy(t) {
        return super.copy(t), this.defines = {
            STANDARD: "",
            PHYSICAL: ""
        }, this.anisotropy = t.anisotropy, this.anisotropyRotation = t.anisotropyRotation, this.anisotropyMap = t.anisotropyMap, this.clearcoat = t.clearcoat, this.clearcoatMap = t.clearcoatMap, this.clearcoatRoughness = t.clearcoatRoughness, this.clearcoatRoughnessMap = t.clearcoatRoughnessMap, this.clearcoatNormalMap = t.clearcoatNormalMap, this.clearcoatNormalScale.copy(t.clearcoatNormalScale), this.dispersion = t.dispersion, this.ior = t.ior, this.iridescence = t.iridescence, this.iridescenceMap = t.iridescenceMap, this.iridescenceIOR = t.iridescenceIOR, this.iridescenceThicknessRange = [
            ...t.iridescenceThicknessRange
        ], this.iridescenceThicknessMap = t.iridescenceThicknessMap, this.sheen = t.sheen, this.sheenColor.copy(t.sheenColor), this.sheenColorMap = t.sheenColorMap, this.sheenRoughness = t.sheenRoughness, this.sheenRoughnessMap = t.sheenRoughnessMap, this.transmission = t.transmission, this.transmissionMap = t.transmissionMap, this.thickness = t.thickness, this.thicknessMap = t.thicknessMap, this.attenuationDistance = t.attenuationDistance, this.attenuationColor.copy(t.attenuationColor), this.specularIntensity = t.specularIntensity, this.specularIntensityMap = t.specularIntensityMap, this.specularColor.copy(t.specularColor), this.specularColorMap = t.specularColorMap, this;
    }
}, ro = class extends ct {
    constructor(t){
        super(), this.isMeshPhongMaterial = !0, this.type = "MeshPhongMaterial", this.color = new P(16777215), this.specular = new P(1118481), this.shininess = 30, this.map = null, this.lightMap = null, this.lightMapIntensity = 1, this.aoMap = null, this.aoMapIntensity = 1, this.emissive = new P(0), this.emissiveIntensity = 1, this.emissiveMap = null, this.bumpMap = null, this.bumpScale = 1, this.normalMap = null, this.normalMapType = _i, this.normalScale = new T(1, 1), this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.specularMap = null, this.alphaMap = null, this.envMap = null, this.envMapRotation = new Xt, this.combine = Do, this.reflectivity = 1, this.refractionRatio = .98, this.wireframe = !1, this.wireframeLinewidth = 1, this.wireframeLinecap = "round", this.wireframeLinejoin = "round", this.flatShading = !1, this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.color.copy(t.color), this.specular.copy(t.specular), this.shininess = t.shininess, this.map = t.map, this.lightMap = t.lightMap, this.lightMapIntensity = t.lightMapIntensity, this.aoMap = t.aoMap, this.aoMapIntensity = t.aoMapIntensity, this.emissive.copy(t.emissive), this.emissiveMap = t.emissiveMap, this.emissiveIntensity = t.emissiveIntensity, this.bumpMap = t.bumpMap, this.bumpScale = t.bumpScale, this.normalMap = t.normalMap, this.normalMapType = t.normalMapType, this.normalScale.copy(t.normalScale), this.displacementMap = t.displacementMap, this.displacementScale = t.displacementScale, this.displacementBias = t.displacementBias, this.specularMap = t.specularMap, this.alphaMap = t.alphaMap, this.envMap = t.envMap, this.envMapRotation.copy(t.envMapRotation), this.combine = t.combine, this.reflectivity = t.reflectivity, this.refractionRatio = t.refractionRatio, this.wireframe = t.wireframe, this.wireframeLinewidth = t.wireframeLinewidth, this.wireframeLinecap = t.wireframeLinecap, this.wireframeLinejoin = t.wireframeLinejoin, this.flatShading = t.flatShading, this.fog = t.fog, this;
    }
}, oo = class extends ct {
    constructor(t){
        super(), this.isMeshToonMaterial = !0, this.defines = {
            TOON: ""
        }, this.type = "MeshToonMaterial", this.color = new P(16777215), this.map = null, this.gradientMap = null, this.lightMap = null, this.lightMapIntensity = 1, this.aoMap = null, this.aoMapIntensity = 1, this.emissive = new P(0), this.emissiveIntensity = 1, this.emissiveMap = null, this.bumpMap = null, this.bumpScale = 1, this.normalMap = null, this.normalMapType = _i, this.normalScale = new T(1, 1), this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.alphaMap = null, this.wireframe = !1, this.wireframeLinewidth = 1, this.wireframeLinecap = "round", this.wireframeLinejoin = "round", this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.color.copy(t.color), this.map = t.map, this.gradientMap = t.gradientMap, this.lightMap = t.lightMap, this.lightMapIntensity = t.lightMapIntensity, this.aoMap = t.aoMap, this.aoMapIntensity = t.aoMapIntensity, this.emissive.copy(t.emissive), this.emissiveMap = t.emissiveMap, this.emissiveIntensity = t.emissiveIntensity, this.bumpMap = t.bumpMap, this.bumpScale = t.bumpScale, this.normalMap = t.normalMap, this.normalMapType = t.normalMapType, this.normalScale.copy(t.normalScale), this.displacementMap = t.displacementMap, this.displacementScale = t.displacementScale, this.displacementBias = t.displacementBias, this.alphaMap = t.alphaMap, this.wireframe = t.wireframe, this.wireframeLinewidth = t.wireframeLinewidth, this.wireframeLinecap = t.wireframeLinecap, this.wireframeLinejoin = t.wireframeLinejoin, this.fog = t.fog, this;
    }
}, ao = class extends ct {
    constructor(t){
        super(), this.isMeshNormalMaterial = !0, this.type = "MeshNormalMaterial", this.bumpMap = null, this.bumpScale = 1, this.normalMap = null, this.normalMapType = _i, this.normalScale = new T(1, 1), this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.wireframe = !1, this.wireframeLinewidth = 1, this.flatShading = !1, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.bumpMap = t.bumpMap, this.bumpScale = t.bumpScale, this.normalMap = t.normalMap, this.normalMapType = t.normalMapType, this.normalScale.copy(t.normalScale), this.displacementMap = t.displacementMap, this.displacementScale = t.displacementScale, this.displacementBias = t.displacementBias, this.wireframe = t.wireframe, this.wireframeLinewidth = t.wireframeLinewidth, this.flatShading = t.flatShading, this;
    }
}, ho = class extends ct {
    constructor(t){
        super(), this.isMeshLambertMaterial = !0, this.type = "MeshLambertMaterial", this.color = new P(16777215), this.map = null, this.lightMap = null, this.lightMapIntensity = 1, this.aoMap = null, this.aoMapIntensity = 1, this.emissive = new P(0), this.emissiveIntensity = 1, this.emissiveMap = null, this.bumpMap = null, this.bumpScale = 1, this.normalMap = null, this.normalMapType = _i, this.normalScale = new T(1, 1), this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.specularMap = null, this.alphaMap = null, this.envMap = null, this.envMapRotation = new Xt, this.combine = Do, this.reflectivity = 1, this.refractionRatio = .98, this.wireframe = !1, this.wireframeLinewidth = 1, this.wireframeLinecap = "round", this.wireframeLinejoin = "round", this.flatShading = !1, this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.color.copy(t.color), this.map = t.map, this.lightMap = t.lightMap, this.lightMapIntensity = t.lightMapIntensity, this.aoMap = t.aoMap, this.aoMapIntensity = t.aoMapIntensity, this.emissive.copy(t.emissive), this.emissiveMap = t.emissiveMap, this.emissiveIntensity = t.emissiveIntensity, this.bumpMap = t.bumpMap, this.bumpScale = t.bumpScale, this.normalMap = t.normalMap, this.normalMapType = t.normalMapType, this.normalScale.copy(t.normalScale), this.displacementMap = t.displacementMap, this.displacementScale = t.displacementScale, this.displacementBias = t.displacementBias, this.specularMap = t.specularMap, this.alphaMap = t.alphaMap, this.envMap = t.envMap, this.envMapRotation.copy(t.envMapRotation), this.combine = t.combine, this.reflectivity = t.reflectivity, this.refractionRatio = t.refractionRatio, this.wireframe = t.wireframe, this.wireframeLinewidth = t.wireframeLinewidth, this.wireframeLinecap = t.wireframeLinecap, this.wireframeLinejoin = t.wireframeLinejoin, this.flatShading = t.flatShading, this.fog = t.fog, this;
    }
}, lo = class extends ct {
    constructor(t){
        super(), this.isMeshDepthMaterial = !0, this.type = "MeshDepthMaterial", this.depthPacking = Jc, this.map = null, this.alphaMap = null, this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.wireframe = !1, this.wireframeLinewidth = 1, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.depthPacking = t.depthPacking, this.map = t.map, this.alphaMap = t.alphaMap, this.displacementMap = t.displacementMap, this.displacementScale = t.displacementScale, this.displacementBias = t.displacementBias, this.wireframe = t.wireframe, this.wireframeLinewidth = t.wireframeLinewidth, this;
    }
}, co = class extends ct {
    constructor(t){
        super(), this.isMeshDistanceMaterial = !0, this.type = "MeshDistanceMaterial", this.map = null, this.alphaMap = null, this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.map = t.map, this.alphaMap = t.alphaMap, this.displacementMap = t.displacementMap, this.displacementScale = t.displacementScale, this.displacementBias = t.displacementBias, this;
    }
}, uo = class extends ct {
    constructor(t){
        super(), this.isMeshMatcapMaterial = !0, this.defines = {
            MATCAP: ""
        }, this.type = "MeshMatcapMaterial", this.color = new P(16777215), this.matcap = null, this.map = null, this.bumpMap = null, this.bumpScale = 1, this.normalMap = null, this.normalMapType = _i, this.normalScale = new T(1, 1), this.displacementMap = null, this.displacementScale = 1, this.displacementBias = 0, this.alphaMap = null, this.flatShading = !1, this.fog = !0, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.defines = {
            MATCAP: ""
        }, this.color.copy(t.color), this.matcap = t.matcap, this.map = t.map, this.bumpMap = t.bumpMap, this.bumpScale = t.bumpScale, this.normalMap = t.normalMap, this.normalMapType = t.normalMapType, this.normalScale.copy(t.normalScale), this.displacementMap = t.displacementMap, this.displacementScale = t.displacementScale, this.displacementBias = t.displacementBias, this.alphaMap = t.alphaMap, this.flatShading = t.flatShading, this.fog = t.fog, this;
    }
}, po = class extends mt {
    constructor(t){
        super(), this.isLineDashedMaterial = !0, this.type = "LineDashedMaterial", this.scale = 1, this.dashSize = 3, this.gapSize = 1, this.setValues(t);
    }
    copy(t) {
        return super.copy(t), this.scale = t.scale, this.dashSize = t.dashSize, this.gapSize = t.gapSize, this;
    }
};
function Ve(h, t, e) {
    return !h || !e && h.constructor === t ? h : typeof t.BYTES_PER_ELEMENT == "number" ? new t(h) : Array.prototype.slice.call(h);
}
function Pl(h) {
    return ArrayBuffer.isView(h) && !(h instanceof DataView);
}
function Ol(h) {
    function t(s, n) {
        return h[s] - h[n];
    }
    let e = h.length, i = new Array(e);
    for(let s = 0; s !== e; ++s)i[s] = s;
    return i.sort(t), i;
}
function fo(h, t, e) {
    let i = h.length, s = new h.constructor(i);
    for(let n = 0, r = 0; r !== i; ++n){
        let o = e[n] * t;
        for(let a = 0; a !== t; ++a)s[r++] = h[o + a];
    }
    return s;
}
function Xo(h, t, e, i) {
    let s = 1, n = h[0];
    for(; n !== void 0 && n[i] === void 0;)n = h[s++];
    if (n === void 0) return;
    let r = n[i];
    if (r !== void 0) if (Array.isArray(r)) do r = n[i], r !== void 0 && (t.push(n.time), e.push.apply(e, r)), n = h[s++];
    while (n !== void 0)
    else if (r.toArray !== void 0) do r = n[i], r !== void 0 && (t.push(n.time), r.toArray(e, e.length)), n = h[s++];
    while (n !== void 0)
    else do r = n[i], r !== void 0 && (t.push(n.time), e.push(r)), n = h[s++];
    while (n !== void 0)
}
function md(h, t, e, i, s = 30) {
    let n = h.clone();
    n.name = t;
    let r = [];
    for(let a = 0; a < n.tracks.length; ++a){
        let l = n.tracks[a], c = l.getValueSize(), u = [], d = [];
        for(let p = 0; p < l.times.length; ++p){
            let f = l.times[p] * s;
            if (!(f < e || f >= i)) {
                u.push(l.times[p]);
                for(let m = 0; m < c; ++m)d.push(l.values[p * c + m]);
            }
        }
        u.length !== 0 && (l.times = Ve(u, l.times.constructor), l.values = Ve(d, l.values.constructor), r.push(l));
    }
    n.tracks = r;
    let o = 1 / 0;
    for(let a = 0; a < n.tracks.length; ++a)o > n.tracks[a].times[0] && (o = n.tracks[a].times[0]);
    for(let a = 0; a < n.tracks.length; ++a)n.tracks[a].shift(-1 * o);
    return n.resetDuration(), n;
}
function yd(h, t = 0, e = h, i = 30) {
    i <= 0 && (i = 30);
    let s = e.tracks.length, n = t / i;
    for(let r = 0; r < s; ++r){
        let o = e.tracks[r], a = o.ValueTypeName;
        if (a === "bool" || a === "string") continue;
        let l = h.tracks.find(function(g) {
            return g.name === o.name && g.ValueTypeName === a;
        });
        if (l === void 0) continue;
        let c = 0, u = o.getValueSize();
        o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline && (c = u / 3);
        let d = 0, p = l.getValueSize();
        l.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline && (d = p / 3);
        let f = o.times.length - 1, m;
        if (n <= o.times[0]) {
            let g = c, x1 = u - c;
            m = o.values.slice(g, x1);
        } else if (n >= o.times[f]) {
            let g = f * u + c, x1 = g + u - c;
            m = o.values.slice(g, x1);
        } else {
            let g = o.createInterpolant(), x1 = c, b = u - c;
            g.evaluate(n), m = g.resultBuffer.slice(x1, b);
        }
        a === "quaternion" && new bt().fromArray(m).normalize().conjugate().toArray(m);
        let y1 = l.times.length;
        for(let g = 0; g < y1; ++g){
            let x1 = g * p + d;
            if (a === "quaternion") bt.multiplyQuaternionsFlat(l.values, x1, m, 0, l.values, x1);
            else {
                let b = p - d * 2;
                for(let M = 0; M < b; ++M)l.values[x1 + M] -= m[M];
            }
        }
    }
    return h.blendMode = Cl, h;
}
var Pf = {
    convertArray: Ve,
    isTypedArray: Pl,
    getKeyframeOrder: Ol,
    sortedArray: fo,
    flattenJSON: Xo,
    subclip: md,
    makeClipAdditive: yd
}, yi = class {
    constructor(t, e, i, s){
        this.parameterPositions = t, this._cachedIndex = 0, this.resultBuffer = s !== void 0 ? s : new e.constructor(i), this.sampleValues = e, this.valueSize = i, this.settings = null, this.DefaultSettings_ = {};
    }
    evaluate(t) {
        let e = this.parameterPositions, i = this._cachedIndex, s = e[i], n = e[i - 1];
        t: {
            e: {
                let r;
                i: {
                    s: if (!(t < s)) {
                        for(let o = i + 2;;){
                            if (s === void 0) {
                                if (t < n) break s;
                                return i = e.length, this._cachedIndex = i, this.copySampleValue_(i - 1);
                            }
                            if (i === o) break;
                            if (n = s, s = e[++i], t < s) break e;
                        }
                        r = e.length;
                        break i;
                    }
                    if (!(t >= n)) {
                        let o = e[1];
                        t < o && (i = 2, n = o);
                        for(let a = i - 2;;){
                            if (n === void 0) return this._cachedIndex = 0, this.copySampleValue_(0);
                            if (i === a) break;
                            if (s = n, n = e[--i - 1], t >= n) break e;
                        }
                        r = i, i = 0;
                        break i;
                    }
                    break t;
                }
                for(; i < r;){
                    let o = i + r >>> 1;
                    t < e[o] ? r = o : i = o + 1;
                }
                if (s = e[i], n = e[i - 1], n === void 0) return this._cachedIndex = 0, this.copySampleValue_(0);
                if (s === void 0) return i = e.length, this._cachedIndex = i, this.copySampleValue_(i - 1);
            }
            this._cachedIndex = i, this.intervalChanged_(i, n, s);
        }
        return this.interpolate_(i, n, t, s);
    }
    getSettings_() {
        return this.settings || this.DefaultSettings_;
    }
    copySampleValue_(t) {
        let e = this.resultBuffer, i = this.sampleValues, s = this.valueSize, n = t * s;
        for(let r = 0; r !== s; ++r)e[r] = i[n + r];
        return e;
    }
    interpolate_() {
        throw new Error("call to abstract method");
    }
    intervalChanged_() {}
}, mo = class extends yi {
    constructor(t, e, i, s){
        super(t, e, i, s), this._weightPrev = -0, this._offsetPrev = -0, this._weightNext = -0, this._offsetNext = -0, this.DefaultSettings_ = {
            endingStart: hi,
            endingEnd: hi
        };
    }
    intervalChanged_(t, e, i) {
        let s = this.parameterPositions, n = t - 2, r = t + 1, o = s[n], a = s[r];
        if (o === void 0) switch(this.getSettings_().endingStart){
            case li:
                n = t, o = 2 * e - i;
                break;
            case Xs:
                n = s.length - 2, o = e + s[n] - s[n + 1];
                break;
            default:
                n = t, o = i;
        }
        if (a === void 0) switch(this.getSettings_().endingEnd){
            case li:
                r = t, a = 2 * i - e;
                break;
            case Xs:
                r = 1, a = i + s[1] - s[0];
                break;
            default:
                r = t - 1, a = e;
        }
        let l = (i - e) * .5, c = this.valueSize;
        this._weightPrev = l / (e - o), this._weightNext = l / (a - i), this._offsetPrev = n * c, this._offsetNext = r * c;
    }
    interpolate_(t, e, i, s) {
        let n = this.resultBuffer, r = this.sampleValues, o = this.valueSize, a = t * o, l = a - o, c = this._offsetPrev, u = this._offsetNext, d = this._weightPrev, p = this._weightNext, f = (i - e) / (s - e), m = f * f, y1 = m * f, g = -d * y1 + 2 * d * m - d * f, x1 = (1 + d) * y1 + (-1.5 - 2 * d) * m + (-.5 + d) * f + 1, b = (-1 - p) * y1 + (1.5 + p) * m + .5 * f, M = p * y1 - p * m;
        for(let _ = 0; _ !== o; ++_)n[_] = g * r[c + _] + x1 * r[l + _] + b * r[a + _] + M * r[u + _];
        return n;
    }
}, gn = class extends yi {
    constructor(t, e, i, s){
        super(t, e, i, s);
    }
    interpolate_(t, e, i, s) {
        let n = this.resultBuffer, r = this.sampleValues, o = this.valueSize, a = t * o, l = a - o, c = (i - e) / (s - e), u = 1 - c;
        for(let d = 0; d !== o; ++d)n[d] = r[l + d] * u + r[a + d] * c;
        return n;
    }
}, yo = class extends yi {
    constructor(t, e, i, s){
        super(t, e, i, s);
    }
    interpolate_(t) {
        return this.copySampleValue_(t - 1);
    }
}, kt = class {
    constructor(t, e, i, s){
        if (t === void 0) throw new Error("THREE.KeyframeTrack: track name is undefined");
        if (e === void 0 || e.length === 0) throw new Error("THREE.KeyframeTrack: no keyframes in track named " + t);
        this.name = t, this.times = Ve(e, this.TimeBufferType), this.values = Ve(i, this.ValueBufferType), this.setInterpolation(s || this.DefaultInterpolation);
    }
    static toJSON(t) {
        let e = t.constructor, i;
        if (e.toJSON !== this.toJSON) i = e.toJSON(t);
        else {
            i = {
                name: t.name,
                times: Ve(t.times, Array),
                values: Ve(t.values, Array)
            };
            let s = t.getInterpolation();
            s !== t.DefaultInterpolation && (i.interpolation = s);
        }
        return i.type = t.ValueTypeName, i;
    }
    InterpolantFactoryMethodDiscrete(t) {
        return new yo(this.times, this.values, this.getValueSize(), t);
    }
    InterpolantFactoryMethodLinear(t) {
        return new gn(this.times, this.values, this.getValueSize(), t);
    }
    InterpolantFactoryMethodSmooth(t) {
        return new mo(this.times, this.values, this.getValueSize(), t);
    }
    setInterpolation(t) {
        let e;
        switch(t){
            case Gs:
                e = this.InterpolantFactoryMethodDiscrete;
                break;
            case mr:
                e = this.InterpolantFactoryMethodLinear;
                break;
            case zn:
                e = this.InterpolantFactoryMethodSmooth;
                break;
        }
        if (e === void 0) {
            let i = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name;
            if (this.createInterpolant === void 0) if (t !== this.DefaultInterpolation) this.setInterpolation(this.DefaultInterpolation);
            else throw new Error(i);
            return console.warn("THREE.KeyframeTrack:", i), this;
        }
        return this.createInterpolant = e, this;
    }
    getInterpolation() {
        switch(this.createInterpolant){
            case this.InterpolantFactoryMethodDiscrete:
                return Gs;
            case this.InterpolantFactoryMethodLinear:
                return mr;
            case this.InterpolantFactoryMethodSmooth:
                return zn;
        }
    }
    getValueSize() {
        return this.values.length / this.times.length;
    }
    shift(t) {
        if (t !== 0) {
            let e = this.times;
            for(let i = 0, s = e.length; i !== s; ++i)e[i] += t;
        }
        return this;
    }
    scale(t) {
        if (t !== 1) {
            let e = this.times;
            for(let i = 0, s = e.length; i !== s; ++i)e[i] *= t;
        }
        return this;
    }
    trim(t, e) {
        let i = this.times, s = i.length, n = 0, r = s - 1;
        for(; n !== s && i[n] < t;)++n;
        for(; r !== -1 && i[r] > e;)--r;
        if (++r, n !== 0 || r !== s) {
            n >= r && (r = Math.max(r, 1), n = r - 1);
            let o = this.getValueSize();
            this.times = i.slice(n, r), this.values = this.values.slice(n * o, r * o);
        }
        return this;
    }
    validate() {
        let t = !0, e = this.getValueSize();
        e - Math.floor(e) !== 0 && (console.error("THREE.KeyframeTrack: Invalid value size in track.", this), t = !1);
        let i = this.times, s = this.values, n = i.length;
        n === 0 && (console.error("THREE.KeyframeTrack: Track is empty.", this), t = !1);
        let r = null;
        for(let o = 0; o !== n; o++){
            let a = i[o];
            if (typeof a == "number" && isNaN(a)) {
                console.error("THREE.KeyframeTrack: Time is not a valid number.", this, o, a), t = !1;
                break;
            }
            if (r !== null && r > a) {
                console.error("THREE.KeyframeTrack: Out of order keys.", this, o, a, r), t = !1;
                break;
            }
            r = a;
        }
        if (s !== void 0 && Pl(s)) for(let o = 0, a = s.length; o !== a; ++o){
            let l = s[o];
            if (isNaN(l)) {
                console.error("THREE.KeyframeTrack: Value is not a valid number.", this, o, l), t = !1;
                break;
            }
        }
        return t;
    }
    optimize() {
        let t = this.times.slice(), e = this.values.slice(), i = this.getValueSize(), s = this.getInterpolation() === zn, n = t.length - 1, r = 1;
        for(let o = 1; o < n; ++o){
            let a = !1, l = t[o], c = t[o + 1];
            if (l !== c && (o !== 1 || l !== t[0])) if (s) a = !0;
            else {
                let u = o * i, d = u - i, p = u + i;
                for(let f = 0; f !== i; ++f){
                    let m = e[u + f];
                    if (m !== e[d + f] || m !== e[p + f]) {
                        a = !0;
                        break;
                    }
                }
            }
            if (a) {
                if (o !== r) {
                    t[r] = t[o];
                    let u = o * i, d = r * i;
                    for(let p = 0; p !== i; ++p)e[d + p] = e[u + p];
                }
                ++r;
            }
        }
        if (n > 0) {
            t[r] = t[n];
            for(let o = n * i, a = r * i, l = 0; l !== i; ++l)e[a + l] = e[o + l];
            ++r;
        }
        return r !== t.length ? (this.times = t.slice(0, r), this.values = e.slice(0, r * i)) : (this.times = t, this.values = e), this;
    }
    clone() {
        let t = this.times.slice(), e = this.values.slice(), i = this.constructor, s = new i(this.name, t, e);
        return s.createInterpolant = this.createInterpolant, s;
    }
};
kt.prototype.TimeBufferType = Float32Array;
kt.prototype.ValueBufferType = Float32Array;
kt.prototype.DefaultInterpolation = mr;
var ve = class extends kt {
    constructor(t, e, i){
        super(t, e, i);
    }
};
ve.prototype.ValueTypeName = "bool";
ve.prototype.ValueBufferType = Array;
ve.prototype.DefaultInterpolation = Gs;
ve.prototype.InterpolantFactoryMethodLinear = void 0;
ve.prototype.InterpolantFactoryMethodSmooth = void 0;
var xn = class extends kt {
};
xn.prototype.ValueTypeName = "color";
var gi = class extends kt {
};
gi.prototype.ValueTypeName = "number";
var go = class extends yi {
    constructor(t, e, i, s){
        super(t, e, i, s);
    }
    interpolate_(t, e, i, s) {
        let n = this.resultBuffer, r = this.sampleValues, o = this.valueSize, a = (i - e) / (s - e), l = t * o;
        for(let c = l + o; l !== c; l += 4)bt.slerpFlat(n, 0, r, l - o, r, l, a);
        return n;
    }
}, xi = class extends kt {
    InterpolantFactoryMethodLinear(t) {
        return new go(this.times, this.values, this.getValueSize(), t);
    }
};
xi.prototype.ValueTypeName = "quaternion";
xi.prototype.InterpolantFactoryMethodSmooth = void 0;
var Ae = class extends kt {
    constructor(t, e, i){
        super(t, e, i);
    }
};
Ae.prototype.ValueTypeName = "string";
Ae.prototype.ValueBufferType = Array;
Ae.prototype.DefaultInterpolation = Gs;
Ae.prototype.InterpolantFactoryMethodLinear = void 0;
Ae.prototype.InterpolantFactoryMethodSmooth = void 0;
var bi = class extends kt {
};
bi.prototype.ValueTypeName = "vector";
var wi = class {
    constructor(t = "", e = -1, i = [], s = Ho){
        this.name = t, this.tracks = i, this.duration = e, this.blendMode = s, this.uuid = It(), this.duration < 0 && this.resetDuration();
    }
    static parse(t) {
        let e = [], i = t.tracks, s = 1 / (t.fps || 1);
        for(let r = 0, o = i.length; r !== o; ++r)e.push(xd(i[r]).scale(s));
        let n = new this(t.name, t.duration, e, t.blendMode);
        return n.uuid = t.uuid, n;
    }
    static toJSON(t) {
        let e = [], i = t.tracks, s = {
            name: t.name,
            duration: t.duration,
            tracks: e,
            uuid: t.uuid,
            blendMode: t.blendMode
        };
        for(let n = 0, r = i.length; n !== r; ++n)e.push(kt.toJSON(i[n]));
        return s;
    }
    static CreateFromMorphTargetSequence(t, e, i, s) {
        let n = e.length, r = [];
        for(let o = 0; o < n; o++){
            let a = [], l = [];
            a.push((o + n - 1) % n, o, (o + 1) % n), l.push(0, 1, 0);
            let c = Ol(a);
            a = fo(a, 1, c), l = fo(l, 1, c), !s && a[0] === 0 && (a.push(n), l.push(l[0])), r.push(new gi(".morphTargetInfluences[" + e[o].name + "]", a, l).scale(1 / i));
        }
        return new this(t, -1, r);
    }
    static findByName(t, e) {
        let i = t;
        if (!Array.isArray(t)) {
            let s = t;
            i = s.geometry && s.geometry.animations || s.animations;
        }
        for(let s = 0; s < i.length; s++)if (i[s].name === e) return i[s];
        return null;
    }
    static CreateClipsFromMorphTargetSequences(t, e, i) {
        let s = {}, n = /^([\w-]*?)([\d]+)$/;
        for(let o = 0, a = t.length; o < a; o++){
            let l = t[o], c = l.name.match(n);
            if (c && c.length > 1) {
                let u = c[1], d = s[u];
                d || (s[u] = d = []), d.push(l);
            }
        }
        let r = [];
        for(let o in s)r.push(this.CreateFromMorphTargetSequence(o, s[o], e, i));
        return r;
    }
    static parseAnimation(t, e) {
        if (!t) return console.error("THREE.AnimationClip: No animation in JSONLoader data."), null;
        let i = function(u, d, p, f, m) {
            if (p.length !== 0) {
                let y1 = [], g = [];
                Xo(p, y1, g, f), y1.length !== 0 && m.push(new u(d, y1, g));
            }
        }, s = [], n = t.name || "default", r = t.fps || 30, o = t.blendMode, a = t.length || -1, l = t.hierarchy || [];
        for(let u = 0; u < l.length; u++){
            let d = l[u].keys;
            if (!(!d || d.length === 0)) if (d[0].morphTargets) {
                let p = {}, f;
                for(f = 0; f < d.length; f++)if (d[f].morphTargets) for(let m = 0; m < d[f].morphTargets.length; m++)p[d[f].morphTargets[m]] = -1;
                for(let m in p){
                    let y1 = [], g = [];
                    for(let x1 = 0; x1 !== d[f].morphTargets.length; ++x1){
                        let b = d[f];
                        y1.push(b.time), g.push(b.morphTarget === m ? 1 : 0);
                    }
                    s.push(new gi(".morphTargetInfluence[" + m + "]", y1, g));
                }
                a = p.length * r;
            } else {
                let p = ".bones[" + e[u].name + "]";
                i(bi, p + ".position", d, "pos", s), i(xi, p + ".quaternion", d, "rot", s), i(bi, p + ".scale", d, "scl", s);
            }
        }
        return s.length === 0 ? null : new this(n, a, s, o);
    }
    resetDuration() {
        let t = this.tracks, e = 0;
        for(let i = 0, s = t.length; i !== s; ++i){
            let n = this.tracks[i];
            e = Math.max(e, n.times[n.times.length - 1]);
        }
        return this.duration = e, this;
    }
    trim() {
        for(let t = 0; t < this.tracks.length; t++)this.tracks[t].trim(0, this.duration);
        return this;
    }
    validate() {
        let t = !0;
        for(let e = 0; e < this.tracks.length; e++)t = t && this.tracks[e].validate();
        return t;
    }
    optimize() {
        for(let t = 0; t < this.tracks.length; t++)this.tracks[t].optimize();
        return this;
    }
    clone() {
        let t = [];
        for(let e = 0; e < this.tracks.length; e++)t.push(this.tracks[e].clone());
        return new this.constructor(this.name, this.duration, t, this.blendMode);
    }
    toJSON() {
        return this.constructor.toJSON(this);
    }
};
function gd(h) {
    switch(h.toLowerCase()){
        case "scalar":
        case "double":
        case "float":
        case "number":
        case "integer":
            return gi;
        case "vector":
        case "vector2":
        case "vector3":
        case "vector4":
            return bi;
        case "color":
            return xn;
        case "quaternion":
            return xi;
        case "bool":
        case "boolean":
            return ve;
        case "string":
            return Ae;
    }
    throw new Error("THREE.KeyframeTrack: Unsupported typeName: " + h);
}
function xd(h) {
    if (h.type === void 0) throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");
    let t = gd(h.type);
    if (h.times === void 0) {
        let e = [], i = [];
        Xo(h.keys, e, i, "value"), h.times = e, h.values = i;
    }
    return t.parse !== void 0 ? t.parse(h) : new t(h.name, h.times, h.values, h.interpolation);
}
var we = {
    enabled: !1,
    files: {},
    add: function(h, t) {
        this.enabled !== !1 && (this.files[h] = t);
    },
    get: function(h) {
        if (this.enabled !== !1) return this.files[h];
    },
    remove: function(h) {
        delete this.files[h];
    },
    clear: function() {
        this.files = {};
    }
}, bn = class {
    constructor(t, e, i){
        let s = this, n = !1, r = 0, o = 0, a, l = [];
        this.onStart = void 0, this.onLoad = t, this.onProgress = e, this.onError = i, this.itemStart = function(c) {
            o++, n === !1 && s.onStart !== void 0 && s.onStart(c, r, o), n = !0;
        }, this.itemEnd = function(c) {
            r++, s.onProgress !== void 0 && s.onProgress(c, r, o), r === o && (n = !1, s.onLoad !== void 0 && s.onLoad());
        }, this.itemError = function(c) {
            s.onError !== void 0 && s.onError(c);
        }, this.resolveURL = function(c) {
            return a ? a(c) : c;
        }, this.setURLModifier = function(c) {
            return a = c, this;
        }, this.addHandler = function(c, u) {
            return l.push(c, u), this;
        }, this.removeHandler = function(c) {
            let u = l.indexOf(c);
            return u !== -1 && l.splice(u, 2), this;
        }, this.getHandler = function(c) {
            for(let u = 0, d = l.length; u < d; u += 2){
                let p = l[u], f = l[u + 1];
                if (p.global && (p.lastIndex = 0), p.test(c)) return f;
            }
            return null;
        };
    }
}, bd = new bn, wt = class {
    constructor(t){
        this.manager = t !== void 0 ? t : bd, this.crossOrigin = "anonymous", this.withCredentials = !1, this.path = "", this.resourcePath = "", this.requestHeader = {};
    }
    load() {}
    loadAsync(t, e) {
        let i = this;
        return new Promise(function(s, n) {
            i.load(t, s, e, n);
        });
    }
    parse() {}
    setCrossOrigin(t) {
        return this.crossOrigin = t, this;
    }
    setWithCredentials(t) {
        return this.withCredentials = t, this;
    }
    setPath(t) {
        return this.path = t, this;
    }
    setResourcePath(t) {
        return this.resourcePath = t, this;
    }
    setRequestHeader(t) {
        return this.requestHeader = t, this;
    }
};
wt.DEFAULT_MATERIAL_NAME = "__DEFAULT";
var se = {}, xo = class extends Error {
    constructor(t, e){
        super(t), this.response = e;
    }
}, Jt = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        t === void 0 && (t = ""), this.path !== void 0 && (t = this.path + t), t = this.manager.resolveURL(t);
        let n = we.get(t);
        if (n !== void 0) return this.manager.itemStart(t), setTimeout(()=>{
            e && e(n), this.manager.itemEnd(t);
        }, 0), n;
        if (se[t] !== void 0) {
            se[t].push({
                onLoad: e,
                onProgress: i,
                onError: s
            });
            return;
        }
        se[t] = [], se[t].push({
            onLoad: e,
            onProgress: i,
            onError: s
        });
        let r = new Request(t, {
            headers: new Headers(this.requestHeader),
            credentials: this.withCredentials ? "include" : "same-origin"
        }), o = this.mimeType, a = this.responseType;
        fetch(r).then((l)=>{
            if (l.status === 200 || l.status === 0) {
                if (l.status === 0 && console.warn("THREE.FileLoader: HTTP Status 0 received."), typeof ReadableStream > "u" || l.body === void 0 || l.body.getReader === void 0) return l;
                let c = se[t], u = l.body.getReader(), d = l.headers.get("X-File-Size") || l.headers.get("Content-Length"), p = d ? parseInt(d) : 0, f = p !== 0, m = 0, y1 = new ReadableStream({
                    start (g) {
                        x1();
                        function x1() {
                            u.read().then(({ done: b , value: M  })=>{
                                if (b) g.close();
                                else {
                                    m += M.byteLength;
                                    let _ = new ProgressEvent("progress", {
                                        lengthComputable: f,
                                        loaded: m,
                                        total: p
                                    });
                                    for(let v = 0, S = c.length; v < S; v++){
                                        let A = c[v];
                                        A.onProgress && A.onProgress(_);
                                    }
                                    g.enqueue(M), x1();
                                }
                            }, (b)=>{
                                g.error(b);
                            });
                        }
                    }
                });
                return new Response(y1);
            } else throw new xo(`fetch for "${l.url}" responded with ${l.status}: ${l.statusText}`, l);
        }).then((l)=>{
            switch(a){
                case "arraybuffer":
                    return l.arrayBuffer();
                case "blob":
                    return l.blob();
                case "document":
                    return l.text().then((c)=>new DOMParser().parseFromString(c, o));
                case "json":
                    return l.json();
                default:
                    if (o === void 0) return l.text();
                    {
                        let u = /charset="?([^;"\s]*)"?/i.exec(o), d = u && u[1] ? u[1].toLowerCase() : void 0, p = new TextDecoder(d);
                        return l.arrayBuffer().then((f)=>p.decode(f));
                    }
            }
        }).then((l)=>{
            we.add(t, l);
            let c = se[t];
            delete se[t];
            for(let u = 0, d = c.length; u < d; u++){
                let p = c[u];
                p.onLoad && p.onLoad(l);
            }
        }).catch((l)=>{
            let c = se[t];
            if (c === void 0) throw this.manager.itemError(t), l;
            delete se[t];
            for(let u = 0, d = c.length; u < d; u++){
                let p = c[u];
                p.onError && p.onError(l);
            }
            this.manager.itemError(t);
        }).finally(()=>{
            this.manager.itemEnd(t);
        }), this.manager.itemStart(t);
    }
    setResponseType(t) {
        return this.responseType = t, this;
    }
    setMimeType(t) {
        return this.mimeType = t, this;
    }
}, mh = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        let n = this, r = new Jt(this.manager);
        r.setPath(this.path), r.setRequestHeader(this.requestHeader), r.setWithCredentials(this.withCredentials), r.load(t, function(o) {
            try {
                e(n.parse(JSON.parse(o)));
            } catch (a) {
                s ? s(a) : console.error(a), n.manager.itemError(t);
            }
        }, i, s);
    }
    parse(t) {
        let e = [];
        for(let i = 0; i < t.length; i++){
            let s = wi.parse(t[i]);
            e.push(s);
        }
        return e;
    }
}, yh = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        let n = this, r = [], o = new Zi, a = new Jt(this.manager);
        a.setPath(this.path), a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setWithCredentials(n.withCredentials);
        let l = 0;
        function c(u) {
            a.load(t[u], function(d) {
                let p = n.parse(d, !0);
                r[u] = {
                    width: p.width,
                    height: p.height,
                    format: p.format,
                    mipmaps: p.mipmaps
                }, l += 1, l === 6 && (p.mipmapCount === 1 && (o.minFilter = Et), o.image = r, o.format = p.format, o.needsUpdate = !0, e && e(o));
            }, i, s);
        }
        if (Array.isArray(t)) for(let u = 0, d = t.length; u < d; ++u)c(u);
        else a.load(t, function(u) {
            let d = n.parse(u, !0);
            if (d.isCubemap) {
                let p = d.mipmaps.length / d.mipmapCount;
                for(let f = 0; f < p; f++){
                    r[f] = {
                        mipmaps: []
                    };
                    for(let m = 0; m < d.mipmapCount; m++)r[f].mipmaps.push(d.mipmaps[f * d.mipmapCount + m]), r[f].format = d.format, r[f].width = d.width, r[f].height = d.height;
                }
                o.image = r;
            } else o.image.width = d.width, o.image.height = d.height, o.mipmaps = d.mipmaps;
            d.mipmapCount === 1 && (o.minFilter = Et), o.format = d.format, o.needsUpdate = !0, e && e(o);
        }, i, s);
        return o;
    }
}, Mi = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        this.path !== void 0 && (t = this.path + t), t = this.manager.resolveURL(t);
        let n = this, r = we.get(t);
        if (r !== void 0) return n.manager.itemStart(t), setTimeout(function() {
            e && e(r), n.manager.itemEnd(t);
        }, 0), r;
        let o = Ys("img");
        function a() {
            c(), we.add(t, this), e && e(this), n.manager.itemEnd(t);
        }
        function l(u) {
            c(), s && s(u), n.manager.itemError(t), n.manager.itemEnd(t);
        }
        function c() {
            o.removeEventListener("load", a, !1), o.removeEventListener("error", l, !1);
        }
        return o.addEventListener("load", a, !1), o.addEventListener("error", l, !1), t.slice(0, 5) !== "data:" && this.crossOrigin !== void 0 && (o.crossOrigin = this.crossOrigin), n.manager.itemStart(t), o.src = t, o;
    }
}, gh = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        let n = new Xi;
        n.colorSpace = Bt;
        let r = new Mi(this.manager);
        r.setCrossOrigin(this.crossOrigin), r.setPath(this.path);
        let o = 0;
        function a(l) {
            r.load(t[l], function(c) {
                n.images[l] = c, o++, o === 6 && (n.needsUpdate = !0, e && e(n));
            }, void 0, s);
        }
        for(let l = 0; l < t.length; ++l)a(l);
        return n;
    }
}, xh = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        let n = this, r = new Lt, o = new Jt(this.manager);
        return o.setResponseType("arraybuffer"), o.setRequestHeader(this.requestHeader), o.setPath(this.path), o.setWithCredentials(n.withCredentials), o.load(t, function(a) {
            let l;
            try {
                l = n.parse(a);
            } catch (c) {
                if (s !== void 0) s(c);
                else {
                    console.error(c);
                    return;
                }
            }
            l.image !== void 0 ? r.image = l.image : l.data !== void 0 && (r.image.width = l.width, r.image.height = l.height, r.image.data = l.data), r.wrapS = l.wrapS !== void 0 ? l.wrapS : Ht, r.wrapT = l.wrapT !== void 0 ? l.wrapT : Ht, r.magFilter = l.magFilter !== void 0 ? l.magFilter : Et, r.minFilter = l.minFilter !== void 0 ? l.minFilter : Et, r.anisotropy = l.anisotropy !== void 0 ? l.anisotropy : 1, l.colorSpace !== void 0 && (r.colorSpace = l.colorSpace), l.flipY !== void 0 && (r.flipY = l.flipY), l.format !== void 0 && (r.format = l.format), l.type !== void 0 && (r.type = l.type), l.mipmaps !== void 0 && (r.mipmaps = l.mipmaps, r.minFilter = vn), l.mipmapCount === 1 && (r.minFilter = Et), l.generateMipmaps !== void 0 && (r.generateMipmaps = l.generateMipmaps), r.needsUpdate = !0, e && e(r, l);
        }, i, s), r;
    }
}, bh = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        let n = new lt, r = new Mi(this.manager);
        return r.setCrossOrigin(this.crossOrigin), r.setPath(this.path), r.load(t, function(o) {
            n.image = o, n.needsUpdate = !0, e !== void 0 && e(n);
        }, i, s), n;
    }
}, ce = class extends G {
    constructor(t, e = 1){
        super(), this.isLight = !0, this.type = "Light", this.color = new P(t), this.intensity = e;
    }
    dispose() {}
    copy(t, e) {
        return super.copy(t, e), this.color.copy(t.color), this.intensity = t.intensity, this;
    }
    toJSON(t) {
        let e = super.toJSON(t);
        return e.object.color = this.color.getHex(), e.object.intensity = this.intensity, this.groundColor !== void 0 && (e.object.groundColor = this.groundColor.getHex()), this.distance !== void 0 && (e.object.distance = this.distance), this.angle !== void 0 && (e.object.angle = this.angle), this.decay !== void 0 && (e.object.decay = this.decay), this.penumbra !== void 0 && (e.object.penumbra = this.penumbra), this.shadow !== void 0 && (e.object.shadow = this.shadow.toJSON()), this.target !== void 0 && (e.object.target = this.target.uuid), e;
    }
}, bo = class extends ce {
    constructor(t, e, i){
        super(t, i), this.isHemisphereLight = !0, this.type = "HemisphereLight", this.position.copy(G.DEFAULT_UP), this.updateMatrix(), this.groundColor = new P(e);
    }
    copy(t, e) {
        return super.copy(t, e), this.groundColor.copy(t.groundColor), this;
    }
}, hr = new D, wh = new w, Mh = new w, ts = class {
    constructor(t){
        this.camera = t, this.intensity = 1, this.bias = 0, this.normalBias = 0, this.radius = 1, this.blurSamples = 8, this.mapSize = new T(512, 512), this.map = null, this.mapPass = null, this.matrix = new D, this.autoUpdate = !0, this.needsUpdate = !1, this._frustum = new sn, this._frameExtents = new T(1, 1), this._viewportCount = 1, this._viewports = [
            new ot(0, 0, 1, 1)
        ];
    }
    getViewportCount() {
        return this._viewportCount;
    }
    getFrustum() {
        return this._frustum;
    }
    updateMatrices(t) {
        let e = this.camera, i = this.matrix;
        wh.setFromMatrixPosition(t.matrixWorld), e.position.copy(wh), Mh.setFromMatrixPosition(t.target.matrixWorld), e.lookAt(Mh), e.updateMatrixWorld(), hr.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse), this._frustum.setFromProjectionMatrix(hr), i.set(.5, 0, 0, .5, 0, .5, 0, .5, 0, 0, .5, .5, 0, 0, 0, 1), i.multiply(hr);
    }
    getViewport(t) {
        return this._viewports[t];
    }
    getFrameExtents() {
        return this._frameExtents;
    }
    dispose() {
        this.map && this.map.dispose(), this.mapPass && this.mapPass.dispose();
    }
    copy(t) {
        return this.camera = t.camera.clone(), this.intensity = t.intensity, this.bias = t.bias, this.radius = t.radius, this.mapSize.copy(t.mapSize), this;
    }
    clone() {
        return new this.constructor().copy(this);
    }
    toJSON() {
        let t = {};
        return this.intensity !== 1 && (t.intensity = this.intensity), this.bias !== 0 && (t.bias = this.bias), this.normalBias !== 0 && (t.normalBias = this.normalBias), this.radius !== 1 && (t.radius = this.radius), (this.mapSize.x !== 512 || this.mapSize.y !== 512) && (t.mapSize = this.mapSize.toArray()), t.camera = this.camera.toJSON(!1).object, delete t.camera.matrix, t;
    }
}, wo = class extends ts {
    constructor(){
        super(new vt(50, 1, .5, 500)), this.isSpotLightShadow = !0, this.focus = 1;
    }
    updateMatrices(t) {
        let e = this.camera, i = Ui * 2 * t.angle * this.focus, s = this.mapSize.width / this.mapSize.height, n = t.distance || e.far;
        (i !== e.fov || s !== e.aspect || n !== e.far) && (e.fov = i, e.aspect = s, e.far = n, e.updateProjectionMatrix()), super.updateMatrices(t);
    }
    copy(t) {
        return super.copy(t), this.focus = t.focus, this;
    }
}, Mo = class extends ce {
    constructor(t, e, i = 0, s = Math.PI / 3, n = 0, r = 2){
        super(t, e), this.isSpotLight = !0, this.type = "SpotLight", this.position.copy(G.DEFAULT_UP), this.updateMatrix(), this.target = new G, this.distance = i, this.angle = s, this.penumbra = n, this.decay = r, this.map = null, this.shadow = new wo;
    }
    get power() {
        return this.intensity * Math.PI;
    }
    set power(t) {
        this.intensity = t / Math.PI;
    }
    dispose() {
        this.shadow.dispose();
    }
    copy(t, e) {
        return super.copy(t, e), this.distance = t.distance, this.angle = t.angle, this.penumbra = t.penumbra, this.decay = t.decay, this.target = t.target.clone(), this.shadow = t.shadow.clone(), this;
    }
}, _h = new D, Pi = new w, lr = new w, _o = class extends ts {
    constructor(){
        super(new vt(90, 1, .5, 500)), this.isPointLightShadow = !0, this._frameExtents = new T(4, 2), this._viewportCount = 6, this._viewports = [
            new ot(2, 1, 1, 1),
            new ot(0, 1, 1, 1),
            new ot(3, 1, 1, 1),
            new ot(1, 1, 1, 1),
            new ot(3, 0, 1, 1),
            new ot(1, 0, 1, 1)
        ], this._cubeDirections = [
            new w(1, 0, 0),
            new w(-1, 0, 0),
            new w(0, 0, 1),
            new w(0, 0, -1),
            new w(0, 1, 0),
            new w(0, -1, 0)
        ], this._cubeUps = [
            new w(0, 1, 0),
            new w(0, 1, 0),
            new w(0, 1, 0),
            new w(0, 1, 0),
            new w(0, 0, 1),
            new w(0, 0, -1)
        ];
    }
    updateMatrices(t, e = 0) {
        let i = this.camera, s = this.matrix, n = t.distance || i.far;
        n !== i.far && (i.far = n, i.updateProjectionMatrix()), Pi.setFromMatrixPosition(t.matrixWorld), i.position.copy(Pi), lr.copy(i.position), lr.add(this._cubeDirections[e]), i.up.copy(this._cubeUps[e]), i.lookAt(lr), i.updateMatrixWorld(), s.makeTranslation(-Pi.x, -Pi.y, -Pi.z), _h.multiplyMatrices(i.projectionMatrix, i.matrixWorldInverse), this._frustum.setFromProjectionMatrix(_h);
    }
}, vo = class extends ce {
    constructor(t, e, i = 0, s = 2){
        super(t, e), this.isPointLight = !0, this.type = "PointLight", this.distance = i, this.decay = s, this.shadow = new _o;
    }
    get power() {
        return this.intensity * 4 * Math.PI;
    }
    set power(t) {
        this.intensity = t / (4 * Math.PI);
    }
    dispose() {
        this.shadow.dispose();
    }
    copy(t, e) {
        return super.copy(t, e), this.distance = t.distance, this.decay = t.decay, this.shadow = t.shadow.clone(), this;
    }
}, wn = class extends Gi {
    constructor(t = -1, e = 1, i = 1, s = -1, n = .1, r = 2e3){
        super(), this.isOrthographicCamera = !0, this.type = "OrthographicCamera", this.zoom = 1, this.view = null, this.left = t, this.right = e, this.top = i, this.bottom = s, this.near = n, this.far = r, this.updateProjectionMatrix();
    }
    copy(t, e) {
        return super.copy(t, e), this.left = t.left, this.right = t.right, this.top = t.top, this.bottom = t.bottom, this.near = t.near, this.far = t.far, this.zoom = t.zoom, this.view = t.view === null ? null : Object.assign({}, t.view), this;
    }
    setViewOffset(t, e, i, s, n, r) {
        this.view === null && (this.view = {
            enabled: !0,
            fullWidth: 1,
            fullHeight: 1,
            offsetX: 0,
            offsetY: 0,
            width: 1,
            height: 1
        }), this.view.enabled = !0, this.view.fullWidth = t, this.view.fullHeight = e, this.view.offsetX = i, this.view.offsetY = s, this.view.width = n, this.view.height = r, this.updateProjectionMatrix();
    }
    clearViewOffset() {
        this.view !== null && (this.view.enabled = !1), this.updateProjectionMatrix();
    }
    updateProjectionMatrix() {
        let t = (this.right - this.left) / (2 * this.zoom), e = (this.top - this.bottom) / (2 * this.zoom), i = (this.right + this.left) / 2, s = (this.top + this.bottom) / 2, n = i - t, r = i + t, o = s + e, a = s - e;
        if (this.view !== null && this.view.enabled) {
            let l = (this.right - this.left) / this.view.fullWidth / this.zoom, c = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
            n += l * this.view.offsetX, r = n + l * this.view.width, o -= c * this.view.offsetY, a = o - c * this.view.height;
        }
        this.projectionMatrix.makeOrthographic(n, r, o, a, this.near, this.far, this.coordinateSystem), this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
    }
    toJSON(t) {
        let e = super.toJSON(t);
        return e.object.zoom = this.zoom, e.object.left = this.left, e.object.right = this.right, e.object.top = this.top, e.object.bottom = this.bottom, e.object.near = this.near, e.object.far = this.far, this.view !== null && (e.object.view = Object.assign({}, this.view)), e;
    }
}, Ao = class extends ts {
    constructor(){
        super(new wn(-5, 5, 5, -5, .5, 500)), this.isDirectionalLightShadow = !0;
    }
}, So = class extends ce {
    constructor(t, e){
        super(t, e), this.isDirectionalLight = !0, this.type = "DirectionalLight", this.position.copy(G.DEFAULT_UP), this.updateMatrix(), this.target = new G, this.shadow = new Ao;
    }
    dispose() {
        this.shadow.dispose();
    }
    copy(t) {
        return super.copy(t), this.target = t.target.clone(), this.shadow = t.shadow.clone(), this;
    }
}, To = class extends ce {
    constructor(t, e){
        super(t, e), this.isAmbientLight = !0, this.type = "AmbientLight";
    }
}, Io = class extends ce {
    constructor(t, e, i = 10, s = 10){
        super(t, e), this.isRectAreaLight = !0, this.type = "RectAreaLight", this.width = i, this.height = s;
    }
    get power() {
        return this.intensity * this.width * this.height * Math.PI;
    }
    set power(t) {
        this.intensity = t / (this.width * this.height * Math.PI);
    }
    copy(t) {
        return super.copy(t), this.width = t.width, this.height = t.height, this;
    }
    toJSON(t) {
        let e = super.toJSON(t);
        return e.object.width = this.width, e.object.height = this.height, e;
    }
}, Co = class {
    constructor(){
        this.isSphericalHarmonics3 = !0, this.coefficients = [];
        for(let t = 0; t < 9; t++)this.coefficients.push(new w);
    }
    set(t) {
        for(let e = 0; e < 9; e++)this.coefficients[e].copy(t[e]);
        return this;
    }
    zero() {
        for(let t = 0; t < 9; t++)this.coefficients[t].set(0, 0, 0);
        return this;
    }
    getAt(t, e) {
        let i = t.x, s = t.y, n = t.z, r = this.coefficients;
        return e.copy(r[0]).multiplyScalar(.282095), e.addScaledVector(r[1], .488603 * s), e.addScaledVector(r[2], .488603 * n), e.addScaledVector(r[3], .488603 * i), e.addScaledVector(r[4], 1.092548 * (i * s)), e.addScaledVector(r[5], 1.092548 * (s * n)), e.addScaledVector(r[6], .315392 * (3 * n * n - 1)), e.addScaledVector(r[7], 1.092548 * (i * n)), e.addScaledVector(r[8], .546274 * (i * i - s * s)), e;
    }
    getIrradianceAt(t, e) {
        let i = t.x, s = t.y, n = t.z, r = this.coefficients;
        return e.copy(r[0]).multiplyScalar(.886227), e.addScaledVector(r[1], 2 * .511664 * s), e.addScaledVector(r[2], 2 * .511664 * n), e.addScaledVector(r[3], 2 * .511664 * i), e.addScaledVector(r[4], 2 * .429043 * i * s), e.addScaledVector(r[5], 2 * .429043 * s * n), e.addScaledVector(r[6], .743125 * n * n - .247708), e.addScaledVector(r[7], 2 * .429043 * i * n), e.addScaledVector(r[8], .429043 * (i * i - s * s)), e;
    }
    add(t) {
        for(let e = 0; e < 9; e++)this.coefficients[e].add(t.coefficients[e]);
        return this;
    }
    addScaledSH(t, e) {
        for(let i = 0; i < 9; i++)this.coefficients[i].addScaledVector(t.coefficients[i], e);
        return this;
    }
    scale(t) {
        for(let e = 0; e < 9; e++)this.coefficients[e].multiplyScalar(t);
        return this;
    }
    lerp(t, e) {
        for(let i = 0; i < 9; i++)this.coefficients[i].lerp(t.coefficients[i], e);
        return this;
    }
    equals(t) {
        for(let e = 0; e < 9; e++)if (!this.coefficients[e].equals(t.coefficients[e])) return !1;
        return !0;
    }
    copy(t) {
        return this.set(t.coefficients);
    }
    clone() {
        return new this.constructor().copy(this);
    }
    fromArray(t, e = 0) {
        let i = this.coefficients;
        for(let s = 0; s < 9; s++)i[s].fromArray(t, e + s * 3);
        return this;
    }
    toArray(t = [], e = 0) {
        let i = this.coefficients;
        for(let s = 0; s < 9; s++)i[s].toArray(t, e + s * 3);
        return t;
    }
    static getBasisAt(t, e) {
        let i = t.x, s = t.y, n = t.z;
        e[0] = .282095, e[1] = .488603 * s, e[2] = .488603 * n, e[3] = .488603 * i, e[4] = 1.092548 * i * s, e[5] = 1.092548 * s * n, e[6] = .315392 * (3 * n * n - 1), e[7] = 1.092548 * i * n, e[8] = .546274 * (i * i - s * s);
    }
}, zo = class extends ce {
    constructor(t = new Co, e = 1){
        super(void 0, e), this.isLightProbe = !0, this.sh = t;
    }
    copy(t) {
        return super.copy(t), this.sh.copy(t.sh), this;
    }
    fromJSON(t) {
        return this.intensity = t.intensity, this.sh.fromArray(t.sh), this;
    }
    toJSON(t) {
        let e = super.toJSON(t);
        return e.object.sh = this.sh.toArray(), e;
    }
}, Fo = class h extends wt {
    constructor(t){
        super(t), this.textures = {};
    }
    load(t, e, i, s) {
        let n = this, r = new Jt(n.manager);
        r.setPath(n.path), r.setRequestHeader(n.requestHeader), r.setWithCredentials(n.withCredentials), r.load(t, function(o) {
            try {
                e(n.parse(JSON.parse(o)));
            } catch (a) {
                s ? s(a) : console.error(a), n.manager.itemError(t);
            }
        }, i, s);
    }
    parse(t) {
        let e = this.textures;
        function i(n) {
            return e[n] === void 0 && console.warn("THREE.MaterialLoader: Undefined texture", n), e[n];
        }
        let s = this.createMaterialFromType(t.type);
        if (t.uuid !== void 0 && (s.uuid = t.uuid), t.name !== void 0 && (s.name = t.name), t.color !== void 0 && s.color !== void 0 && s.color.setHex(t.color), t.roughness !== void 0 && (s.roughness = t.roughness), t.metalness !== void 0 && (s.metalness = t.metalness), t.sheen !== void 0 && (s.sheen = t.sheen), t.sheenColor !== void 0 && (s.sheenColor = new P().setHex(t.sheenColor)), t.sheenRoughness !== void 0 && (s.sheenRoughness = t.sheenRoughness), t.emissive !== void 0 && s.emissive !== void 0 && s.emissive.setHex(t.emissive), t.specular !== void 0 && s.specular !== void 0 && s.specular.setHex(t.specular), t.specularIntensity !== void 0 && (s.specularIntensity = t.specularIntensity), t.specularColor !== void 0 && s.specularColor !== void 0 && s.specularColor.setHex(t.specularColor), t.shininess !== void 0 && (s.shininess = t.shininess), t.clearcoat !== void 0 && (s.clearcoat = t.clearcoat), t.clearcoatRoughness !== void 0 && (s.clearcoatRoughness = t.clearcoatRoughness), t.dispersion !== void 0 && (s.dispersion = t.dispersion), t.iridescence !== void 0 && (s.iridescence = t.iridescence), t.iridescenceIOR !== void 0 && (s.iridescenceIOR = t.iridescenceIOR), t.iridescenceThicknessRange !== void 0 && (s.iridescenceThicknessRange = t.iridescenceThicknessRange), t.transmission !== void 0 && (s.transmission = t.transmission), t.thickness !== void 0 && (s.thickness = t.thickness), t.attenuationDistance !== void 0 && (s.attenuationDistance = t.attenuationDistance), t.attenuationColor !== void 0 && s.attenuationColor !== void 0 && s.attenuationColor.setHex(t.attenuationColor), t.anisotropy !== void 0 && (s.anisotropy = t.anisotropy), t.anisotropyRotation !== void 0 && (s.anisotropyRotation = t.anisotropyRotation), t.fog !== void 0 && (s.fog = t.fog), t.flatShading !== void 0 && (s.flatShading = t.flatShading), t.blending !== void 0 && (s.blending = t.blending), t.combine !== void 0 && (s.combine = t.combine), t.side !== void 0 && (s.side = t.side), t.shadowSide !== void 0 && (s.shadowSide = t.shadowSide), t.opacity !== void 0 && (s.opacity = t.opacity), t.transparent !== void 0 && (s.transparent = t.transparent), t.alphaTest !== void 0 && (s.alphaTest = t.alphaTest), t.alphaHash !== void 0 && (s.alphaHash = t.alphaHash), t.depthFunc !== void 0 && (s.depthFunc = t.depthFunc), t.depthTest !== void 0 && (s.depthTest = t.depthTest), t.depthWrite !== void 0 && (s.depthWrite = t.depthWrite), t.colorWrite !== void 0 && (s.colorWrite = t.colorWrite), t.blendSrc !== void 0 && (s.blendSrc = t.blendSrc), t.blendDst !== void 0 && (s.blendDst = t.blendDst), t.blendEquation !== void 0 && (s.blendEquation = t.blendEquation), t.blendSrcAlpha !== void 0 && (s.blendSrcAlpha = t.blendSrcAlpha), t.blendDstAlpha !== void 0 && (s.blendDstAlpha = t.blendDstAlpha), t.blendEquationAlpha !== void 0 && (s.blendEquationAlpha = t.blendEquationAlpha), t.blendColor !== void 0 && s.blendColor !== void 0 && s.blendColor.setHex(t.blendColor), t.blendAlpha !== void 0 && (s.blendAlpha = t.blendAlpha), t.stencilWriteMask !== void 0 && (s.stencilWriteMask = t.stencilWriteMask), t.stencilFunc !== void 0 && (s.stencilFunc = t.stencilFunc), t.stencilRef !== void 0 && (s.stencilRef = t.stencilRef), t.stencilFuncMask !== void 0 && (s.stencilFuncMask = t.stencilFuncMask), t.stencilFail !== void 0 && (s.stencilFail = t.stencilFail), t.stencilZFail !== void 0 && (s.stencilZFail = t.stencilZFail), t.stencilZPass !== void 0 && (s.stencilZPass = t.stencilZPass), t.stencilWrite !== void 0 && (s.stencilWrite = t.stencilWrite), t.wireframe !== void 0 && (s.wireframe = t.wireframe), t.wireframeLinewidth !== void 0 && (s.wireframeLinewidth = t.wireframeLinewidth), t.wireframeLinecap !== void 0 && (s.wireframeLinecap = t.wireframeLinecap), t.wireframeLinejoin !== void 0 && (s.wireframeLinejoin = t.wireframeLinejoin), t.rotation !== void 0 && (s.rotation = t.rotation), t.linewidth !== void 0 && (s.linewidth = t.linewidth), t.dashSize !== void 0 && (s.dashSize = t.dashSize), t.gapSize !== void 0 && (s.gapSize = t.gapSize), t.scale !== void 0 && (s.scale = t.scale), t.polygonOffset !== void 0 && (s.polygonOffset = t.polygonOffset), t.polygonOffsetFactor !== void 0 && (s.polygonOffsetFactor = t.polygonOffsetFactor), t.polygonOffsetUnits !== void 0 && (s.polygonOffsetUnits = t.polygonOffsetUnits), t.dithering !== void 0 && (s.dithering = t.dithering), t.alphaToCoverage !== void 0 && (s.alphaToCoverage = t.alphaToCoverage), t.premultipliedAlpha !== void 0 && (s.premultipliedAlpha = t.premultipliedAlpha), t.forceSinglePass !== void 0 && (s.forceSinglePass = t.forceSinglePass), t.visible !== void 0 && (s.visible = t.visible), t.toneMapped !== void 0 && (s.toneMapped = t.toneMapped), t.userData !== void 0 && (s.userData = t.userData), t.vertexColors !== void 0 && (typeof t.vertexColors == "number" ? s.vertexColors = t.vertexColors > 0 : s.vertexColors = t.vertexColors), t.uniforms !== void 0) for(let n in t.uniforms){
            let r = t.uniforms[n];
            switch(s.uniforms[n] = {}, r.type){
                case "t":
                    s.uniforms[n].value = i(r.value);
                    break;
                case "c":
                    s.uniforms[n].value = new P().setHex(r.value);
                    break;
                case "v2":
                    s.uniforms[n].value = new T().fromArray(r.value);
                    break;
                case "v3":
                    s.uniforms[n].value = new w().fromArray(r.value);
                    break;
                case "v4":
                    s.uniforms[n].value = new ot().fromArray(r.value);
                    break;
                case "m3":
                    s.uniforms[n].value = new Gt().fromArray(r.value);
                    break;
                case "m4":
                    s.uniforms[n].value = new D().fromArray(r.value);
                    break;
                default:
                    s.uniforms[n].value = r.value;
            }
        }
        if (t.defines !== void 0 && (s.defines = t.defines), t.vertexShader !== void 0 && (s.vertexShader = t.vertexShader), t.fragmentShader !== void 0 && (s.fragmentShader = t.fragmentShader), t.glslVersion !== void 0 && (s.glslVersion = t.glslVersion), t.extensions !== void 0) for(let n in t.extensions)s.extensions[n] = t.extensions[n];
        if (t.lights !== void 0 && (s.lights = t.lights), t.clipping !== void 0 && (s.clipping = t.clipping), t.size !== void 0 && (s.size = t.size), t.sizeAttenuation !== void 0 && (s.sizeAttenuation = t.sizeAttenuation), t.map !== void 0 && (s.map = i(t.map)), t.matcap !== void 0 && (s.matcap = i(t.matcap)), t.alphaMap !== void 0 && (s.alphaMap = i(t.alphaMap)), t.bumpMap !== void 0 && (s.bumpMap = i(t.bumpMap)), t.bumpScale !== void 0 && (s.bumpScale = t.bumpScale), t.normalMap !== void 0 && (s.normalMap = i(t.normalMap)), t.normalMapType !== void 0 && (s.normalMapType = t.normalMapType), t.normalScale !== void 0) {
            let n = t.normalScale;
            Array.isArray(n) === !1 && (n = [
                n,
                n
            ]), s.normalScale = new T().fromArray(n);
        }
        return t.displacementMap !== void 0 && (s.displacementMap = i(t.displacementMap)), t.displacementScale !== void 0 && (s.displacementScale = t.displacementScale), t.displacementBias !== void 0 && (s.displacementBias = t.displacementBias), t.roughnessMap !== void 0 && (s.roughnessMap = i(t.roughnessMap)), t.metalnessMap !== void 0 && (s.metalnessMap = i(t.metalnessMap)), t.emissiveMap !== void 0 && (s.emissiveMap = i(t.emissiveMap)), t.emissiveIntensity !== void 0 && (s.emissiveIntensity = t.emissiveIntensity), t.specularMap !== void 0 && (s.specularMap = i(t.specularMap)), t.specularIntensityMap !== void 0 && (s.specularIntensityMap = i(t.specularIntensityMap)), t.specularColorMap !== void 0 && (s.specularColorMap = i(t.specularColorMap)), t.envMap !== void 0 && (s.envMap = i(t.envMap)), t.envMapRotation !== void 0 && s.envMapRotation.fromArray(t.envMapRotation), t.envMapIntensity !== void 0 && (s.envMapIntensity = t.envMapIntensity), t.reflectivity !== void 0 && (s.reflectivity = t.reflectivity), t.refractionRatio !== void 0 && (s.refractionRatio = t.refractionRatio), t.lightMap !== void 0 && (s.lightMap = i(t.lightMap)), t.lightMapIntensity !== void 0 && (s.lightMapIntensity = t.lightMapIntensity), t.aoMap !== void 0 && (s.aoMap = i(t.aoMap)), t.aoMapIntensity !== void 0 && (s.aoMapIntensity = t.aoMapIntensity), t.gradientMap !== void 0 && (s.gradientMap = i(t.gradientMap)), t.clearcoatMap !== void 0 && (s.clearcoatMap = i(t.clearcoatMap)), t.clearcoatRoughnessMap !== void 0 && (s.clearcoatRoughnessMap = i(t.clearcoatRoughnessMap)), t.clearcoatNormalMap !== void 0 && (s.clearcoatNormalMap = i(t.clearcoatNormalMap)), t.clearcoatNormalScale !== void 0 && (s.clearcoatNormalScale = new T().fromArray(t.clearcoatNormalScale)), t.iridescenceMap !== void 0 && (s.iridescenceMap = i(t.iridescenceMap)), t.iridescenceThicknessMap !== void 0 && (s.iridescenceThicknessMap = i(t.iridescenceThicknessMap)), t.transmissionMap !== void 0 && (s.transmissionMap = i(t.transmissionMap)), t.thicknessMap !== void 0 && (s.thicknessMap = i(t.thicknessMap)), t.anisotropyMap !== void 0 && (s.anisotropyMap = i(t.anisotropyMap)), t.sheenColorMap !== void 0 && (s.sheenColorMap = i(t.sheenColorMap)), t.sheenRoughnessMap !== void 0 && (s.sheenRoughnessMap = i(t.sheenRoughnessMap)), s;
    }
    setTextures(t) {
        return this.textures = t, this;
    }
    createMaterialFromType(t) {
        return h.createMaterialFromType(t);
    }
    static createMaterialFromType(t) {
        let e = {
            ShadowMaterial: io,
            SpriteMaterial: tn,
            RawShaderMaterial: so,
            ShaderMaterial: qi,
            PointsMaterial: on,
            MeshPhysicalMaterial: no,
            MeshStandardMaterial: yn,
            MeshPhongMaterial: ro,
            MeshToonMaterial: oo,
            MeshNormalMaterial: ao,
            MeshLambertMaterial: ho,
            MeshDepthMaterial: lo,
            MeshDistanceMaterial: co,
            MeshBasicMaterial: _e,
            MeshMatcapMaterial: uo,
            LineDashedMaterial: po,
            LineBasicMaterial: mt,
            Material: ct
        };
        return new e[t];
    }
}, Mn = class {
    static decodeText(t) {
        if (console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."), typeof TextDecoder < "u") return new TextDecoder().decode(t);
        let e = "";
        for(let i = 0, s = t.length; i < s; i++)e += String.fromCharCode(t[i]);
        try {
            return decodeURIComponent(escape(e));
        } catch  {
            return e;
        }
    }
    static extractUrlBase(t) {
        let e = t.lastIndexOf("/");
        return e === -1 ? "./" : t.slice(0, e + 1);
    }
    static resolveURL(t, e) {
        return typeof t != "string" || t === "" ? "" : (/^https?:\/\//i.test(e) && /^\//.test(t) && (e = e.replace(/(^https?:\/\/[^\/]+).*/i, "$1")), /^(https?:)?\/\//i.test(t) || /^data:.*,.*$/i.test(t) || /^blob:.*$/i.test(t) ? t : e + t);
    }
}, Bo = class extends L {
    constructor(){
        super(), this.isInstancedBufferGeometry = !0, this.type = "InstancedBufferGeometry", this.instanceCount = 1 / 0;
    }
    copy(t) {
        return super.copy(t), this.instanceCount = t.instanceCount, this;
    }
    toJSON() {
        let t = super.toJSON();
        return t.instanceCount = this.instanceCount, t.isInstancedBufferGeometry = !0, t;
    }
}, Eo = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        let n = this, r = new Jt(n.manager);
        r.setPath(n.path), r.setRequestHeader(n.requestHeader), r.setWithCredentials(n.withCredentials), r.load(t, function(o) {
            try {
                e(n.parse(JSON.parse(o)));
            } catch (a) {
                s ? s(a) : console.error(a), n.manager.itemError(t);
            }
        }, i, s);
    }
    parse(t) {
        let e = {}, i = {};
        function s(p, f) {
            if (e[f] !== void 0) return e[f];
            let y1 = p.interleavedBuffers[f], g = n(p, y1.buffer), x1 = ci(y1.type, g), b = new Ji(x1, y1.stride);
            return b.uuid = y1.uuid, e[f] = b, b;
        }
        function n(p, f) {
            if (i[f] !== void 0) return i[f];
            let y1 = p.arrayBuffers[f], g = new Uint32Array(y1).buffer;
            return i[f] = g, g;
        }
        let r = t.isInstancedBufferGeometry ? new Bo : new L, o = t.data.index;
        if (o !== void 0) {
            let p = ci(o.type, o.array);
            r.setIndex(new Z(p, 1));
        }
        let a = t.data.attributes;
        for(let p in a){
            let f = a[p], m;
            if (f.isInterleavedBufferAttribute) {
                let y1 = s(t.data, f.data);
                m = new fi(y1, f.itemSize, f.offset, f.normalized);
            } else {
                let y1 = ci(f.type, f.array), g = f.isInstancedBufferAttribute ? Ue : Z;
                m = new g(y1, f.itemSize, f.normalized);
            }
            f.name !== void 0 && (m.name = f.name), f.usage !== void 0 && m.setUsage(f.usage), r.setAttribute(p, m);
        }
        let l = t.data.morphAttributes;
        if (l) for(let p in l){
            let f = l[p], m = [];
            for(let y1 = 0, g = f.length; y1 < g; y1++){
                let x1 = f[y1], b;
                if (x1.isInterleavedBufferAttribute) {
                    let M = s(t.data, x1.data);
                    b = new fi(M, x1.itemSize, x1.offset, x1.normalized);
                } else {
                    let M = ci(x1.type, x1.array);
                    b = new Z(M, x1.itemSize, x1.normalized);
                }
                x1.name !== void 0 && (b.name = x1.name), m.push(b);
            }
            r.morphAttributes[p] = m;
        }
        t.data.morphTargetsRelative && (r.morphTargetsRelative = !0);
        let u = t.data.groups || t.data.drawcalls || t.data.offsets;
        if (u !== void 0) for(let p = 0, f = u.length; p !== f; ++p){
            let m = u[p];
            r.addGroup(m.start, m.count, m.materialIndex);
        }
        let d = t.data.boundingSphere;
        if (d !== void 0) {
            let p = new w;
            d.center !== void 0 && p.fromArray(d.center), r.boundingSphere = new ht(p, d.radius);
        }
        return t.name && (r.name = t.name), t.userData && (r.userData = t.userData), r;
    }
}, vh = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        let n = this, r = this.path === "" ? Mn.extractUrlBase(t) : this.path;
        this.resourcePath = this.resourcePath || r;
        let o = new Jt(this.manager);
        o.setPath(this.path), o.setRequestHeader(this.requestHeader), o.setWithCredentials(this.withCredentials), o.load(t, function(a) {
            let l = null;
            try {
                l = JSON.parse(a);
            } catch (u) {
                s !== void 0 && s(u), console.error("THREE:ObjectLoader: Can't parse " + t + ".", u.message);
                return;
            }
            let c = l.metadata;
            if (c === void 0 || c.type === void 0 || c.type.toLowerCase() === "geometry") {
                s !== void 0 && s(new Error("THREE.ObjectLoader: Can't load " + t)), console.error("THREE.ObjectLoader: Can't load " + t);
                return;
            }
            n.parse(l, e);
        }, i, s);
    }
    async loadAsync(t, e) {
        let i = this, s = this.path === "" ? Mn.extractUrlBase(t) : this.path;
        this.resourcePath = this.resourcePath || s;
        let n = new Jt(this.manager);
        n.setPath(this.path), n.setRequestHeader(this.requestHeader), n.setWithCredentials(this.withCredentials);
        let r = await n.loadAsync(t, e), o = JSON.parse(r), a = o.metadata;
        if (a === void 0 || a.type === void 0 || a.type.toLowerCase() === "geometry") throw new Error("THREE.ObjectLoader: Can't load " + t);
        return await i.parseAsync(o);
    }
    parse(t, e) {
        let i = this.parseAnimations(t.animations), s = this.parseShapes(t.shapes), n = this.parseGeometries(t.geometries, s), r = this.parseImages(t.images, function() {
            e !== void 0 && e(l);
        }), o = this.parseTextures(t.textures, r), a = this.parseMaterials(t.materials, o), l = this.parseObject(t.object, n, a, o, i), c = this.parseSkeletons(t.skeletons, l);
        if (this.bindSkeletons(l, c), this.bindLightTargets(l), e !== void 0) {
            let u = !1;
            for(let d in r)if (r[d].data instanceof HTMLImageElement) {
                u = !0;
                break;
            }
            u === !1 && e(l);
        }
        return l;
    }
    async parseAsync(t) {
        let e = this.parseAnimations(t.animations), i = this.parseShapes(t.shapes), s = this.parseGeometries(t.geometries, i), n = await this.parseImagesAsync(t.images), r = this.parseTextures(t.textures, n), o = this.parseMaterials(t.materials, r), a = this.parseObject(t.object, s, o, r, e), l = this.parseSkeletons(t.skeletons, a);
        return this.bindSkeletons(a, l), this.bindLightTargets(a), a;
    }
    parseShapes(t) {
        let e = {};
        if (t !== void 0) for(let i = 0, s = t.length; i < s; i++){
            let n = new Me().fromJSON(t[i]);
            e[n.uuid] = n;
        }
        return e;
    }
    parseSkeletons(t, e) {
        let i = {}, s = {};
        if (e.traverse(function(n) {
            n.isBone && (s[n.uuid] = n);
        }), t !== void 0) for(let n = 0, r = t.length; n < r; n++){
            let o = new Tr().fromJSON(t[n], s);
            i[o.uuid] = o;
        }
        return i;
    }
    parseGeometries(t, e) {
        let i = {};
        if (t !== void 0) {
            let s = new Eo;
            for(let n = 0, r = t.length; n < r; n++){
                let o, a = t[n];
                switch(a.type){
                    case "BufferGeometry":
                    case "InstancedBufferGeometry":
                        o = s.parse(a);
                        break;
                    default:
                        a.type in fh ? o = fh[a.type].fromJSON(a, e) : console.warn(`THREE.ObjectLoader: Unsupported geometry type "${a.type}"`);
                }
                o.uuid = a.uuid, a.name !== void 0 && (o.name = a.name), a.userData !== void 0 && (o.userData = a.userData), i[a.uuid] = o;
            }
        }
        return i;
    }
    parseMaterials(t, e) {
        let i = {}, s = {};
        if (t !== void 0) {
            let n = new Fo;
            n.setTextures(e);
            for(let r = 0, o = t.length; r < o; r++){
                let a = t[r];
                i[a.uuid] === void 0 && (i[a.uuid] = n.parse(a)), s[a.uuid] = i[a.uuid];
            }
        }
        return s;
    }
    parseAnimations(t) {
        let e = {};
        if (t !== void 0) for(let i = 0; i < t.length; i++){
            let s = t[i], n = wi.parse(s);
            e[n.uuid] = n;
        }
        return e;
    }
    parseImages(t, e) {
        let i = this, s = {}, n;
        function r(a) {
            return i.manager.itemStart(a), n.load(a, function() {
                i.manager.itemEnd(a);
            }, void 0, function() {
                i.manager.itemError(a), i.manager.itemEnd(a);
            });
        }
        function o(a) {
            if (typeof a == "string") {
                let l = a, c = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(l) ? l : i.resourcePath + l;
                return r(c);
            } else return a.data ? {
                data: ci(a.type, a.data),
                width: a.width,
                height: a.height
            } : null;
        }
        if (t !== void 0 && t.length > 0) {
            let a = new bn(e);
            n = new Mi(a), n.setCrossOrigin(this.crossOrigin);
            for(let l = 0, c = t.length; l < c; l++){
                let u = t[l], d = u.url;
                if (Array.isArray(d)) {
                    let p = [];
                    for(let f = 0, m = d.length; f < m; f++){
                        let y1 = d[f], g = o(y1);
                        g !== null && (g instanceof HTMLImageElement ? p.push(g) : p.push(new Lt(g.data, g.width, g.height)));
                    }
                    s[u.uuid] = new be(p);
                } else {
                    let p = o(u.url);
                    s[u.uuid] = new be(p);
                }
            }
        }
        return s;
    }
    async parseImagesAsync(t) {
        let e = this, i = {}, s;
        async function n(r) {
            if (typeof r == "string") {
                let o = r, a = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(o) ? o : e.resourcePath + o;
                return await s.loadAsync(a);
            } else return r.data ? {
                data: ci(r.type, r.data),
                width: r.width,
                height: r.height
            } : null;
        }
        if (t !== void 0 && t.length > 0) {
            s = new Mi(this.manager), s.setCrossOrigin(this.crossOrigin);
            for(let r = 0, o = t.length; r < o; r++){
                let a = t[r], l = a.url;
                if (Array.isArray(l)) {
                    let c = [];
                    for(let u = 0, d = l.length; u < d; u++){
                        let p = l[u], f = await n(p);
                        f !== null && (f instanceof HTMLImageElement ? c.push(f) : c.push(new Lt(f.data, f.width, f.height)));
                    }
                    i[a.uuid] = new be(c);
                } else {
                    let c = await n(a.url);
                    i[a.uuid] = new be(c);
                }
            }
        }
        return i;
    }
    parseTextures(t, e) {
        function i(n, r) {
            return typeof n == "number" ? n : (console.warn("THREE.ObjectLoader.parseTexture: Constant should be in numeric form.", n), r[n]);
        }
        let s = {};
        if (t !== void 0) for(let n = 0, r = t.length; n < r; n++){
            let o = t[n];
            o.image === void 0 && console.warn('THREE.ObjectLoader: No "image" specified for', o.uuid), e[o.image] === void 0 && console.warn("THREE.ObjectLoader: Undefined image", o.image);
            let a = e[o.image], l = a.data, c;
            Array.isArray(l) ? (c = new Xi, l.length === 6 && (c.needsUpdate = !0)) : (l && l.data ? c = new Lt : c = new lt, l && (c.needsUpdate = !0)), c.source = a, c.uuid = o.uuid, o.name !== void 0 && (c.name = o.name), o.mapping !== void 0 && (c.mapping = i(o.mapping, wd)), o.channel !== void 0 && (c.channel = o.channel), o.offset !== void 0 && c.offset.fromArray(o.offset), o.repeat !== void 0 && c.repeat.fromArray(o.repeat), o.center !== void 0 && c.center.fromArray(o.center), o.rotation !== void 0 && (c.rotation = o.rotation), o.wrap !== void 0 && (c.wrapS = i(o.wrap[0], Ah), c.wrapT = i(o.wrap[1], Ah)), o.format !== void 0 && (c.format = o.format), o.internalFormat !== void 0 && (c.internalFormat = o.internalFormat), o.type !== void 0 && (c.type = o.type), o.colorSpace !== void 0 && (c.colorSpace = o.colorSpace), o.minFilter !== void 0 && (c.minFilter = i(o.minFilter, Sh)), o.magFilter !== void 0 && (c.magFilter = i(o.magFilter, Sh)), o.anisotropy !== void 0 && (c.anisotropy = o.anisotropy), o.flipY !== void 0 && (c.flipY = o.flipY), o.generateMipmaps !== void 0 && (c.generateMipmaps = o.generateMipmaps), o.premultiplyAlpha !== void 0 && (c.premultiplyAlpha = o.premultiplyAlpha), o.unpackAlignment !== void 0 && (c.unpackAlignment = o.unpackAlignment), o.compareFunction !== void 0 && (c.compareFunction = o.compareFunction), o.userData !== void 0 && (c.userData = o.userData), s[o.uuid] = c;
        }
        return s;
    }
    parseObject(t, e, i, s, n) {
        let r;
        function o(d) {
            return e[d] === void 0 && console.warn("THREE.ObjectLoader: Undefined geometry", d), e[d];
        }
        function a(d) {
            if (d !== void 0) {
                if (Array.isArray(d)) {
                    let p = [];
                    for(let f = 0, m = d.length; f < m; f++){
                        let y1 = d[f];
                        i[y1] === void 0 && console.warn("THREE.ObjectLoader: Undefined material", y1), p.push(i[y1]);
                    }
                    return p;
                }
                return i[d] === void 0 && console.warn("THREE.ObjectLoader: Undefined material", d), i[d];
            }
        }
        function l(d) {
            return s[d] === void 0 && console.warn("THREE.ObjectLoader: Undefined texture", d), s[d];
        }
        let c, u;
        switch(t.type){
            case "Scene":
                r = new _r, t.background !== void 0 && (Number.isInteger(t.background) ? r.background = new P(t.background) : r.background = l(t.background)), t.environment !== void 0 && (r.environment = l(t.environment)), t.fog !== void 0 && (t.fog.type === "Fog" ? r.fog = new Mr(t.fog.color, t.fog.near, t.fog.far) : t.fog.type === "FogExp2" && (r.fog = new wr(t.fog.color, t.fog.density)), t.fog.name !== "" && (r.fog.name = t.fog.name)), t.backgroundBlurriness !== void 0 && (r.backgroundBlurriness = t.backgroundBlurriness), t.backgroundIntensity !== void 0 && (r.backgroundIntensity = t.backgroundIntensity), t.backgroundRotation !== void 0 && r.backgroundRotation.fromArray(t.backgroundRotation), t.environmentIntensity !== void 0 && (r.environmentIntensity = t.environmentIntensity), t.environmentRotation !== void 0 && r.environmentRotation.fromArray(t.environmentRotation);
                break;
            case "PerspectiveCamera":
                r = new vt(t.fov, t.aspect, t.near, t.far), t.focus !== void 0 && (r.focus = t.focus), t.zoom !== void 0 && (r.zoom = t.zoom), t.filmGauge !== void 0 && (r.filmGauge = t.filmGauge), t.filmOffset !== void 0 && (r.filmOffset = t.filmOffset), t.view !== void 0 && (r.view = Object.assign({}, t.view));
                break;
            case "OrthographicCamera":
                r = new wn(t.left, t.right, t.top, t.bottom, t.near, t.far), t.zoom !== void 0 && (r.zoom = t.zoom), t.view !== void 0 && (r.view = Object.assign({}, t.view));
                break;
            case "AmbientLight":
                r = new To(t.color, t.intensity);
                break;
            case "DirectionalLight":
                r = new So(t.color, t.intensity), r.target = t.target || "";
                break;
            case "PointLight":
                r = new vo(t.color, t.intensity, t.distance, t.decay);
                break;
            case "RectAreaLight":
                r = new Io(t.color, t.intensity, t.width, t.height);
                break;
            case "SpotLight":
                r = new Mo(t.color, t.intensity, t.distance, t.angle, t.penumbra, t.decay), r.target = t.target || "";
                break;
            case "HemisphereLight":
                r = new bo(t.color, t.groundColor, t.intensity);
                break;
            case "LightProbe":
                r = new zo().fromJSON(t);
                break;
            case "SkinnedMesh":
                c = o(t.geometry), u = a(t.material), r = new Sr(c, u), t.bindMode !== void 0 && (r.bindMode = t.bindMode), t.bindMatrix !== void 0 && r.bindMatrix.fromArray(t.bindMatrix), t.skeleton !== void 0 && (r.skeleton = t.skeleton);
                break;
            case "Mesh":
                c = o(t.geometry), u = a(t.material), r = new Ct(c, u);
                break;
            case "InstancedMesh":
                c = o(t.geometry), u = a(t.material);
                let d = t.count, p = t.instanceMatrix, f = t.instanceColor;
                r = new Ir(c, u, d), r.instanceMatrix = new Ue(new Float32Array(p.array), 16), f !== void 0 && (r.instanceColor = new Ue(new Float32Array(f.array), f.itemSize));
                break;
            case "BatchedMesh":
                c = o(t.geometry), u = a(t.material), r = new zr(t.maxInstanceCount, t.maxVertexCount, t.maxIndexCount, u), r.geometry = c, r.perObjectFrustumCulled = t.perObjectFrustumCulled, r.sortObjects = t.sortObjects, r._drawRanges = t.drawRanges, r._reservedRanges = t.reservedRanges, r._visibility = t.visibility, r._active = t.active, r._bounds = t.bounds.map((m)=>{
                    let y1 = new ft;
                    y1.min.fromArray(m.boxMin), y1.max.fromArray(m.boxMax);
                    let g = new ht;
                    return g.radius = m.sphereRadius, g.center.fromArray(m.sphereCenter), {
                        boxInitialized: m.boxInitialized,
                        box: y1,
                        sphereInitialized: m.sphereInitialized,
                        sphere: g
                    };
                }), r._maxInstanceCount = t.maxInstanceCount, r._maxVertexCount = t.maxVertexCount, r._maxIndexCount = t.maxIndexCount, r._geometryInitialized = t.geometryInitialized, r._geometryCount = t.geometryCount, r._matricesTexture = l(t.matricesTexture.uuid), t.colorsTexture !== void 0 && (r._colorsTexture = l(t.colorsTexture.uuid));
                break;
            case "LOD":
                r = new Ar;
                break;
            case "Line":
                r = new le(o(t.geometry), a(t.material));
                break;
            case "LineLoop":
                r = new Fr(o(t.geometry), a(t.material));
                break;
            case "LineSegments":
                r = new Wt(o(t.geometry), a(t.material));
                break;
            case "PointCloud":
            case "Points":
                r = new Er(o(t.geometry), a(t.material));
                break;
            case "Sprite":
                r = new vr(a(t.material));
                break;
            case "Group":
                r = new Ne;
                break;
            case "Bone":
                r = new en;
                break;
            default:
                r = new G;
        }
        if (r.uuid = t.uuid, t.name !== void 0 && (r.name = t.name), t.matrix !== void 0 ? (r.matrix.fromArray(t.matrix), t.matrixAutoUpdate !== void 0 && (r.matrixAutoUpdate = t.matrixAutoUpdate), r.matrixAutoUpdate && r.matrix.decompose(r.position, r.quaternion, r.scale)) : (t.position !== void 0 && r.position.fromArray(t.position), t.rotation !== void 0 && r.rotation.fromArray(t.rotation), t.quaternion !== void 0 && r.quaternion.fromArray(t.quaternion), t.scale !== void 0 && r.scale.fromArray(t.scale)), t.up !== void 0 && r.up.fromArray(t.up), t.castShadow !== void 0 && (r.castShadow = t.castShadow), t.receiveShadow !== void 0 && (r.receiveShadow = t.receiveShadow), t.shadow && (t.shadow.intensity !== void 0 && (r.shadow.intensity = t.shadow.intensity), t.shadow.bias !== void 0 && (r.shadow.bias = t.shadow.bias), t.shadow.normalBias !== void 0 && (r.shadow.normalBias = t.shadow.normalBias), t.shadow.radius !== void 0 && (r.shadow.radius = t.shadow.radius), t.shadow.mapSize !== void 0 && r.shadow.mapSize.fromArray(t.shadow.mapSize), t.shadow.camera !== void 0 && (r.shadow.camera = this.parseObject(t.shadow.camera))), t.visible !== void 0 && (r.visible = t.visible), t.frustumCulled !== void 0 && (r.frustumCulled = t.frustumCulled), t.renderOrder !== void 0 && (r.renderOrder = t.renderOrder), t.userData !== void 0 && (r.userData = t.userData), t.layers !== void 0 && (r.layers.mask = t.layers), t.children !== void 0) {
            let d = t.children;
            for(let p = 0; p < d.length; p++)r.add(this.parseObject(d[p], e, i, s, n));
        }
        if (t.animations !== void 0) {
            let d = t.animations;
            for(let p = 0; p < d.length; p++){
                let f = d[p];
                r.animations.push(n[f]);
            }
        }
        if (t.type === "LOD") {
            t.autoUpdate !== void 0 && (r.autoUpdate = t.autoUpdate);
            let d = t.levels;
            for(let p = 0; p < d.length; p++){
                let f = d[p], m = r.getObjectByProperty("uuid", f.object);
                m !== void 0 && r.addLevel(m, f.distance, f.hysteresis);
            }
        }
        return r;
    }
    bindSkeletons(t, e) {
        Object.keys(e).length !== 0 && t.traverse(function(i) {
            if (i.isSkinnedMesh === !0 && i.skeleton !== void 0) {
                let s = e[i.skeleton];
                s === void 0 ? console.warn("THREE.ObjectLoader: No skeleton found with UUID:", i.skeleton) : i.bind(s, i.bindMatrix);
            }
        });
    }
    bindLightTargets(t) {
        t.traverse(function(e) {
            if (e.isDirectionalLight || e.isSpotLight) {
                let i = e.target, s = t.getObjectByProperty("uuid", i);
                s !== void 0 ? e.target = s : e.target = new G;
            }
        });
    }
}, wd = {
    UVMapping: Lo,
    CubeReflectionMapping: Uo,
    CubeRefractionMapping: Hl,
    EquirectangularReflectionMapping: ql,
    EquirectangularRefractionMapping: Gl,
    CubeUVReflectionMapping: Xl
}, Ah = {
    RepeatWrapping: pr,
    ClampToEdgeWrapping: Ht,
    MirroredRepeatWrapping: fr
}, Sh = {
    NearestFilter: Ut,
    NearestMipmapNearestFilter: Jl,
    NearestMipmapLinearFilter: Zl,
    LinearFilter: Et,
    LinearMipmapNearestFilter: Yl,
    LinearMipmapLinearFilter: vn
}, Th = class extends wt {
    constructor(t){
        super(t), this.isImageBitmapLoader = !0, typeof createImageBitmap > "u" && console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported."), typeof fetch > "u" && console.warn("THREE.ImageBitmapLoader: fetch() not supported."), this.options = {
            premultiplyAlpha: "none"
        };
    }
    setOptions(t) {
        return this.options = t, this;
    }
    load(t, e, i, s) {
        t === void 0 && (t = ""), this.path !== void 0 && (t = this.path + t), t = this.manager.resolveURL(t);
        let n = this, r = we.get(t);
        if (r !== void 0) {
            if (n.manager.itemStart(t), r.then) {
                r.then((l)=>{
                    e && e(l), n.manager.itemEnd(t);
                }).catch((l)=>{
                    s && s(l);
                });
                return;
            }
            return setTimeout(function() {
                e && e(r), n.manager.itemEnd(t);
            }, 0), r;
        }
        let o = {};
        o.credentials = this.crossOrigin === "anonymous" ? "same-origin" : "include", o.headers = this.requestHeader;
        let a = fetch(t, o).then(function(l) {
            return l.blob();
        }).then(function(l) {
            return createImageBitmap(l, Object.assign(n.options, {
                colorSpaceConversion: "none"
            }));
        }).then(function(l) {
            return we.add(t, l), e && e(l), n.manager.itemEnd(t), l;
        }).catch(function(l) {
            s && s(l), we.remove(t), n.manager.itemError(t), n.manager.itemEnd(t);
        });
        we.add(t, a), n.manager.itemStart(t);
    }
}, Vs, _n = class {
    static getContext() {
        return Vs === void 0 && (Vs = new (window.AudioContext || window.webkitAudioContext)), Vs;
    }
    static setContext(t) {
        Vs = t;
    }
}, Ih = class extends wt {
    constructor(t){
        super(t);
    }
    load(t, e, i, s) {
        let n = this, r = new Jt(this.manager);
        r.setResponseType("arraybuffer"), r.setPath(this.path), r.setRequestHeader(this.requestHeader), r.setWithCredentials(this.withCredentials), r.load(t, function(a) {
            try {
                let l = a.slice(0);
                _n.getContext().decodeAudioData(l, function(u) {
                    e(u);
                }).catch(o);
            } catch (l) {
                o(l);
            }
        }, i, s);
        function o(a) {
            s ? s(a) : console.error(a), n.manager.itemError(t);
        }
    }
}, Ch = new D, zh = new D, Ee = new D, Fh = class {
    constructor(){
        this.type = "StereoCamera", this.aspect = 1, this.eyeSep = .064, this.cameraL = new vt, this.cameraL.layers.enable(1), this.cameraL.matrixAutoUpdate = !1, this.cameraR = new vt, this.cameraR.layers.enable(2), this.cameraR.matrixAutoUpdate = !1, this._cache = {
            focus: null,
            fov: null,
            aspect: null,
            near: null,
            far: null,
            zoom: null,
            eyeSep: null
        };
    }
    update(t) {
        let e = this._cache;
        if (e.focus !== t.focus || e.fov !== t.fov || e.aspect !== t.aspect * this.aspect || e.near !== t.near || e.far !== t.far || e.zoom !== t.zoom || e.eyeSep !== this.eyeSep) {
            e.focus = t.focus, e.fov = t.fov, e.aspect = t.aspect * this.aspect, e.near = t.near, e.far = t.far, e.zoom = t.zoom, e.eyeSep = this.eyeSep, Ee.copy(t.projectionMatrix);
            let s = e.eyeSep / 2, n = s * e.near / e.focus, r = e.near * Math.tan(De * e.fov * .5) / e.zoom, o, a;
            zh.elements[12] = -s, Ch.elements[12] = s, o = -r * e.aspect + n, a = r * e.aspect + n, Ee.elements[0] = 2 * e.near / (a - o), Ee.elements[8] = (a + o) / (a - o), this.cameraL.projectionMatrix.copy(Ee), o = -r * e.aspect - n, a = r * e.aspect - n, Ee.elements[0] = 2 * e.near / (a - o), Ee.elements[8] = (a + o) / (a - o), this.cameraR.projectionMatrix.copy(Ee);
        }
        this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(zh), this.cameraR.matrixWorld.copy(t.matrixWorld).multiply(Ch);
    }
}, Bh = class extends vt {
    constructor(t = []){
        super(), this.isArrayCamera = !0, this.cameras = t, this.index = 0;
    }
}, Ro = class {
    constructor(t = !0){
        this.autoStart = t, this.startTime = 0, this.oldTime = 0, this.elapsedTime = 0, this.running = !1;
    }
    start() {
        this.startTime = Eh(), this.oldTime = this.startTime, this.elapsedTime = 0, this.running = !0;
    }
    stop() {
        this.getElapsedTime(), this.running = !1, this.autoStart = !1;
    }
    getElapsedTime() {
        return this.getDelta(), this.elapsedTime;
    }
    getDelta() {
        let t = 0;
        if (this.autoStart && !this.running) return this.start(), 0;
        if (this.running) {
            let e = Eh();
            t = (e - this.oldTime) / 1e3, this.oldTime = e, this.elapsedTime += t;
        }
        return t;
    }
};
function Eh() {
    return performance.now();
}
var Re = new w, Rh = new bt, Md = new w, ke = new w, kh = class extends G {
    constructor(){
        super(), this.type = "AudioListener", this.context = _n.getContext(), this.gain = this.context.createGain(), this.gain.connect(this.context.destination), this.filter = null, this.timeDelta = 0, this._clock = new Ro;
    }
    getInput() {
        return this.gain;
    }
    removeFilter() {
        return this.filter !== null && (this.gain.disconnect(this.filter), this.filter.disconnect(this.context.destination), this.gain.connect(this.context.destination), this.filter = null), this;
    }
    getFilter() {
        return this.filter;
    }
    setFilter(t) {
        return this.filter !== null ? (this.gain.disconnect(this.filter), this.filter.disconnect(this.context.destination)) : this.gain.disconnect(this.context.destination), this.filter = t, this.gain.connect(this.filter), this.filter.connect(this.context.destination), this;
    }
    getMasterVolume() {
        return this.gain.gain.value;
    }
    setMasterVolume(t) {
        return this.gain.gain.setTargetAtTime(t, this.context.currentTime, .01), this;
    }
    updateMatrixWorld(t) {
        super.updateMatrixWorld(t);
        let e = this.context.listener, i = this.up;
        if (this.timeDelta = this._clock.getDelta(), this.matrixWorld.decompose(Re, Rh, Md), ke.set(0, 0, -1).applyQuaternion(Rh), e.positionX) {
            let s = this.context.currentTime + this.timeDelta;
            e.positionX.linearRampToValueAtTime(Re.x, s), e.positionY.linearRampToValueAtTime(Re.y, s), e.positionZ.linearRampToValueAtTime(Re.z, s), e.forwardX.linearRampToValueAtTime(ke.x, s), e.forwardY.linearRampToValueAtTime(ke.y, s), e.forwardZ.linearRampToValueAtTime(ke.z, s), e.upX.linearRampToValueAtTime(i.x, s), e.upY.linearRampToValueAtTime(i.y, s), e.upZ.linearRampToValueAtTime(i.z, s);
        } else e.setPosition(Re.x, Re.y, Re.z), e.setOrientation(ke.x, ke.y, ke.z, i.x, i.y, i.z);
    }
}, ko = class extends G {
    constructor(t){
        super(), this.type = "Audio", this.listener = t, this.context = t.context, this.gain = this.context.createGain(), this.gain.connect(t.getInput()), this.autoplay = !1, this.buffer = null, this.detune = 0, this.loop = !1, this.loopStart = 0, this.loopEnd = 0, this.offset = 0, this.duration = void 0, this.playbackRate = 1, this.isPlaying = !1, this.hasPlaybackControl = !0, this.source = null, this.sourceType = "empty", this._startedAt = 0, this._progress = 0, this._connected = !1, this.filters = [];
    }
    getOutput() {
        return this.gain;
    }
    setNodeSource(t) {
        return this.hasPlaybackControl = !1, this.sourceType = "audioNode", this.source = t, this.connect(), this;
    }
    setMediaElementSource(t) {
        return this.hasPlaybackControl = !1, this.sourceType = "mediaNode", this.source = this.context.createMediaElementSource(t), this.connect(), this;
    }
    setMediaStreamSource(t) {
        return this.hasPlaybackControl = !1, this.sourceType = "mediaStreamNode", this.source = this.context.createMediaStreamSource(t), this.connect(), this;
    }
    setBuffer(t) {
        return this.buffer = t, this.sourceType = "buffer", this.autoplay && this.play(), this;
    }
    play(t = 0) {
        if (this.isPlaying === !0) {
            console.warn("THREE.Audio: Audio is already playing.");
            return;
        }
        if (this.hasPlaybackControl === !1) {
            console.warn("THREE.Audio: this Audio has no playback control.");
            return;
        }
        this._startedAt = this.context.currentTime + t;
        let e = this.context.createBufferSource();
        return e.buffer = this.buffer, e.loop = this.loop, e.loopStart = this.loopStart, e.loopEnd = this.loopEnd, e.onended = this.onEnded.bind(this), e.start(this._startedAt, this._progress + this.offset, this.duration), this.isPlaying = !0, this.source = e, this.setDetune(this.detune), this.setPlaybackRate(this.playbackRate), this.connect();
    }
    pause() {
        if (this.hasPlaybackControl === !1) {
            console.warn("THREE.Audio: this Audio has no playback control.");
            return;
        }
        return this.isPlaying === !0 && (this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate, this.loop === !0 && (this._progress = this._progress % (this.duration || this.buffer.duration)), this.source.stop(), this.source.onended = null, this.isPlaying = !1), this;
    }
    stop(t = 0) {
        if (this.hasPlaybackControl === !1) {
            console.warn("THREE.Audio: this Audio has no playback control.");
            return;
        }
        return this._progress = 0, this.source !== null && (this.source.stop(this.context.currentTime + t), this.source.onended = null), this.isPlaying = !1, this;
    }
    connect() {
        if (this.filters.length > 0) {
            this.source.connect(this.filters[0]);
            for(let t = 1, e = this.filters.length; t < e; t++)this.filters[t - 1].connect(this.filters[t]);
            this.filters[this.filters.length - 1].connect(this.getOutput());
        } else this.source.connect(this.getOutput());
        return this._connected = !0, this;
    }
    disconnect() {
        if (this._connected !== !1) {
            if (this.filters.length > 0) {
                this.source.disconnect(this.filters[0]);
                for(let t = 1, e = this.filters.length; t < e; t++)this.filters[t - 1].disconnect(this.filters[t]);
                this.filters[this.filters.length - 1].disconnect(this.getOutput());
            } else this.source.disconnect(this.getOutput());
            return this._connected = !1, this;
        }
    }
    getFilters() {
        return this.filters;
    }
    setFilters(t) {
        return t || (t = []), this._connected === !0 ? (this.disconnect(), this.filters = t.slice(), this.connect()) : this.filters = t.slice(), this;
    }
    setDetune(t) {
        return this.detune = t, this.isPlaying === !0 && this.source.detune !== void 0 && this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, .01), this;
    }
    getDetune() {
        return this.detune;
    }
    getFilter() {
        return this.getFilters()[0];
    }
    setFilter(t) {
        return this.setFilters(t ? [
            t
        ] : []);
    }
    setPlaybackRate(t) {
        if (this.hasPlaybackControl === !1) {
            console.warn("THREE.Audio: this Audio has no playback control.");
            return;
        }
        return this.playbackRate = t, this.isPlaying === !0 && this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, .01), this;
    }
    getPlaybackRate() {
        return this.playbackRate;
    }
    onEnded() {
        this.isPlaying = !1, this._progress = 0;
    }
    getLoop() {
        return this.hasPlaybackControl === !1 ? (console.warn("THREE.Audio: this Audio has no playback control."), !1) : this.loop;
    }
    setLoop(t) {
        if (this.hasPlaybackControl === !1) {
            console.warn("THREE.Audio: this Audio has no playback control.");
            return;
        }
        return this.loop = t, this.isPlaying === !0 && (this.source.loop = this.loop), this;
    }
    setLoopStart(t) {
        return this.loopStart = t, this;
    }
    setLoopEnd(t) {
        return this.loopEnd = t, this;
    }
    getVolume() {
        return this.gain.gain.value;
    }
    setVolume(t) {
        return this.gain.gain.setTargetAtTime(t, this.context.currentTime, .01), this;
    }
    copy(t, e) {
        return super.copy(t, e), t.sourceType !== "buffer" ? (console.warn("THREE.Audio: Audio source type cannot be copied."), this) : (this.autoplay = t.autoplay, this.buffer = t.buffer, this.detune = t.detune, this.loop = t.loop, this.loopStart = t.loopStart, this.loopEnd = t.loopEnd, this.offset = t.offset, this.duration = t.duration, this.playbackRate = t.playbackRate, this.hasPlaybackControl = t.hasPlaybackControl, this.sourceType = t.sourceType, this.filters = t.filters.slice(), this);
    }
    clone(t) {
        return new this.constructor(this.listener).copy(this, t);
    }
}, Pe = new w, Ph = new bt, _d = new w, Oe = new w, Oh = class extends ko {
    constructor(t){
        super(t), this.panner = this.context.createPanner(), this.panner.panningModel = "HRTF", this.panner.connect(this.gain);
    }
    connect() {
        super.connect(), this.panner.connect(this.gain);
    }
    disconnect() {
        super.disconnect(), this.panner.disconnect(this.gain);
    }
    getOutput() {
        return this.panner;
    }
    getRefDistance() {
        return this.panner.refDistance;
    }
    setRefDistance(t) {
        return this.panner.refDistance = t, this;
    }
    getRolloffFactor() {
        return this.panner.rolloffFactor;
    }
    setRolloffFactor(t) {
        return this.panner.rolloffFactor = t, this;
    }
    getDistanceModel() {
        return this.panner.distanceModel;
    }
    setDistanceModel(t) {
        return this.panner.distanceModel = t, this;
    }
    getMaxDistance() {
        return this.panner.maxDistance;
    }
    setMaxDistance(t) {
        return this.panner.maxDistance = t, this;
    }
    setDirectionalCone(t, e, i) {
        return this.panner.coneInnerAngle = t, this.panner.coneOuterAngle = e, this.panner.coneOuterGain = i, this;
    }
    updateMatrixWorld(t) {
        if (super.updateMatrixWorld(t), this.hasPlaybackControl === !0 && this.isPlaying === !1) return;
        this.matrixWorld.decompose(Pe, Ph, _d), Oe.set(0, 0, 1).applyQuaternion(Ph);
        let e = this.panner;
        if (e.positionX) {
            let i = this.context.currentTime + this.listener.timeDelta;
            e.positionX.linearRampToValueAtTime(Pe.x, i), e.positionY.linearRampToValueAtTime(Pe.y, i), e.positionZ.linearRampToValueAtTime(Pe.z, i), e.orientationX.linearRampToValueAtTime(Oe.x, i), e.orientationY.linearRampToValueAtTime(Oe.y, i), e.orientationZ.linearRampToValueAtTime(Oe.z, i);
        } else e.setPosition(Pe.x, Pe.y, Pe.z), e.setOrientation(Oe.x, Oe.y, Oe.z);
    }
}, Nh = class {
    constructor(t, e = 2048){
        this.analyser = t.context.createAnalyser(), this.analyser.fftSize = e, this.data = new Uint8Array(this.analyser.frequencyBinCount), t.getOutput().connect(this.analyser);
    }
    getFrequencyData() {
        return this.analyser.getByteFrequencyData(this.data), this.data;
    }
    getAverageFrequency() {
        let t = 0, e = this.getFrequencyData();
        for(let i = 0; i < e.length; i++)t += e[i];
        return t / e.length;
    }
}, Po = class {
    constructor(t, e, i){
        this.binding = t, this.valueSize = i;
        let s, n, r;
        switch(e){
            case "quaternion":
                s = this._slerp, n = this._slerpAdditive, r = this._setAdditiveIdentityQuaternion, this.buffer = new Float64Array(i * 6), this._workIndex = 5;
                break;
            case "string":
            case "bool":
                s = this._select, n = this._select, r = this._setAdditiveIdentityOther, this.buffer = new Array(i * 5);
                break;
            default:
                s = this._lerp, n = this._lerpAdditive, r = this._setAdditiveIdentityNumeric, this.buffer = new Float64Array(i * 5);
        }
        this._mixBufferRegion = s, this._mixBufferRegionAdditive = n, this._setIdentity = r, this._origIndex = 3, this._addIndex = 4, this.cumulativeWeight = 0, this.cumulativeWeightAdditive = 0, this.useCount = 0, this.referenceCount = 0;
    }
    accumulate(t, e) {
        let i = this.buffer, s = this.valueSize, n = t * s + s, r = this.cumulativeWeight;
        if (r === 0) {
            for(let o = 0; o !== s; ++o)i[n + o] = i[o];
            r = e;
        } else {
            r += e;
            let o = e / r;
            this._mixBufferRegion(i, n, 0, o, s);
        }
        this.cumulativeWeight = r;
    }
    accumulateAdditive(t) {
        let e = this.buffer, i = this.valueSize, s = i * this._addIndex;
        this.cumulativeWeightAdditive === 0 && this._setIdentity(), this._mixBufferRegionAdditive(e, s, 0, t, i), this.cumulativeWeightAdditive += t;
    }
    apply(t) {
        let e = this.valueSize, i = this.buffer, s = t * e + e, n = this.cumulativeWeight, r = this.cumulativeWeightAdditive, o = this.binding;
        if (this.cumulativeWeight = 0, this.cumulativeWeightAdditive = 0, n < 1) {
            let a = e * this._origIndex;
            this._mixBufferRegion(i, s, a, 1 - n, e);
        }
        r > 0 && this._mixBufferRegionAdditive(i, s, this._addIndex * e, 1, e);
        for(let a = e, l = e + e; a !== l; ++a)if (i[a] !== i[a + e]) {
            o.setValue(i, s);
            break;
        }
    }
    saveOriginalState() {
        let t = this.binding, e = this.buffer, i = this.valueSize, s = i * this._origIndex;
        t.getValue(e, s);
        for(let n = i, r = s; n !== r; ++n)e[n] = e[s + n % i];
        this._setIdentity(), this.cumulativeWeight = 0, this.cumulativeWeightAdditive = 0;
    }
    restoreOriginalState() {
        let t = this.valueSize * 3;
        this.binding.setValue(this.buffer, t);
    }
    _setAdditiveIdentityNumeric() {
        let t = this._addIndex * this.valueSize, e = t + this.valueSize;
        for(let i = t; i < e; i++)this.buffer[i] = 0;
    }
    _setAdditiveIdentityQuaternion() {
        this._setAdditiveIdentityNumeric(), this.buffer[this._addIndex * this.valueSize + 3] = 1;
    }
    _setAdditiveIdentityOther() {
        let t = this._origIndex * this.valueSize, e = this._addIndex * this.valueSize;
        for(let i = 0; i < this.valueSize; i++)this.buffer[e + i] = this.buffer[t + i];
    }
    _select(t, e, i, s, n) {
        if (s >= .5) for(let r = 0; r !== n; ++r)t[e + r] = t[i + r];
    }
    _slerp(t, e, i, s) {
        bt.slerpFlat(t, e, t, e, t, i, s);
    }
    _slerpAdditive(t, e, i, s, n) {
        let r = this._workIndex * n;
        bt.multiplyQuaternionsFlat(t, r, t, e, t, i), bt.slerpFlat(t, e, t, e, t, r, s);
    }
    _lerp(t, e, i, s, n) {
        let r = 1 - s;
        for(let o = 0; o !== n; ++o){
            let a = e + o;
            t[a] = t[a] * r + t[i + o] * s;
        }
    }
    _lerpAdditive(t, e, i, s, n) {
        for(let r = 0; r !== n; ++r){
            let o = e + r;
            t[o] = t[o] + t[i + r] * s;
        }
    }
}, Jo = "\\[\\]\\.:\\/", vd = new RegExp("[" + Jo + "]", "g"), Zo = "[^" + Jo + "]", Ad = "[^" + Jo.replace("\\.", "") + "]", Sd = /((?:WC+[\/:])*)/.source.replace("WC", Zo), Td = /(WCOD+)?/.source.replace("WCOD", Ad), Id = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC", Zo), Cd = /\.(WC+)(?:\[(.+)\])?/.source.replace("WC", Zo), zd = new RegExp("^" + Sd + Td + Id + Cd + "$"), Fd = [
    "material",
    "materials",
    "bones",
    "map"
], Oo = class {
    constructor(t, e, i){
        let s = i || J.parseTrackName(e);
        this._targetGroup = t, this._bindings = t.subscribe_(e, s);
    }
    getValue(t, e) {
        this.bind();
        let i = this._targetGroup.nCachedObjects_, s = this._bindings[i];
        s !== void 0 && s.getValue(t, e);
    }
    setValue(t, e) {
        let i = this._bindings;
        for(let s = this._targetGroup.nCachedObjects_, n = i.length; s !== n; ++s)i[s].setValue(t, e);
    }
    bind() {
        let t = this._bindings;
        for(let e = this._targetGroup.nCachedObjects_, i = t.length; e !== i; ++e)t[e].bind();
    }
    unbind() {
        let t = this._bindings;
        for(let e = this._targetGroup.nCachedObjects_, i = t.length; e !== i; ++e)t[e].unbind();
    }
}, J = class h {
    constructor(t, e, i){
        this.path = e, this.parsedPath = i || h.parseTrackName(e), this.node = h.findNode(t, this.parsedPath.nodeName), this.rootNode = t, this.getValue = this._getValue_unbound, this.setValue = this._setValue_unbound;
    }
    static create(t, e, i) {
        return t && t.isAnimationObjectGroup ? new h.Composite(t, e, i) : new h(t, e, i);
    }
    static sanitizeNodeName(t) {
        return t.replace(/\s/g, "_").replace(vd, "");
    }
    static parseTrackName(t) {
        let e = zd.exec(t);
        if (e === null) throw new Error("PropertyBinding: Cannot parse trackName: " + t);
        let i = {
            nodeName: e[2],
            objectName: e[3],
            objectIndex: e[4],
            propertyName: e[5],
            propertyIndex: e[6]
        }, s = i.nodeName && i.nodeName.lastIndexOf(".");
        if (s !== void 0 && s !== -1) {
            let n = i.nodeName.substring(s + 1);
            Fd.indexOf(n) !== -1 && (i.nodeName = i.nodeName.substring(0, s), i.objectName = n);
        }
        if (i.propertyName === null || i.propertyName.length === 0) throw new Error("PropertyBinding: can not parse propertyName from trackName: " + t);
        return i;
    }
    static findNode(t, e) {
        if (e === void 0 || e === "" || e === "." || e === -1 || e === t.name || e === t.uuid) return t;
        if (t.skeleton) {
            let i = t.skeleton.getBoneByName(e);
            if (i !== void 0) return i;
        }
        if (t.children) {
            let i = function(n) {
                for(let r = 0; r < n.length; r++){
                    let o = n[r];
                    if (o.name === e || o.uuid === e) return o;
                    let a = i(o.children);
                    if (a) return a;
                }
                return null;
            }, s = i(t.children);
            if (s) return s;
        }
        return null;
    }
    _getValue_unavailable() {}
    _setValue_unavailable() {}
    _getValue_direct(t, e) {
        t[e] = this.targetObject[this.propertyName];
    }
    _getValue_array(t, e) {
        let i = this.resolvedProperty;
        for(let s = 0, n = i.length; s !== n; ++s)t[e++] = i[s];
    }
    _getValue_arrayElement(t, e) {
        t[e] = this.resolvedProperty[this.propertyIndex];
    }
    _getValue_toArray(t, e) {
        this.resolvedProperty.toArray(t, e);
    }
    _setValue_direct(t, e) {
        this.targetObject[this.propertyName] = t[e];
    }
    _setValue_direct_setNeedsUpdate(t, e) {
        this.targetObject[this.propertyName] = t[e], this.targetObject.needsUpdate = !0;
    }
    _setValue_direct_setMatrixWorldNeedsUpdate(t, e) {
        this.targetObject[this.propertyName] = t[e], this.targetObject.matrixWorldNeedsUpdate = !0;
    }
    _setValue_array(t, e) {
        let i = this.resolvedProperty;
        for(let s = 0, n = i.length; s !== n; ++s)i[s] = t[e++];
    }
    _setValue_array_setNeedsUpdate(t, e) {
        let i = this.resolvedProperty;
        for(let s = 0, n = i.length; s !== n; ++s)i[s] = t[e++];
        this.targetObject.needsUpdate = !0;
    }
    _setValue_array_setMatrixWorldNeedsUpdate(t, e) {
        let i = this.resolvedProperty;
        for(let s = 0, n = i.length; s !== n; ++s)i[s] = t[e++];
        this.targetObject.matrixWorldNeedsUpdate = !0;
    }
    _setValue_arrayElement(t, e) {
        this.resolvedProperty[this.propertyIndex] = t[e];
    }
    _setValue_arrayElement_setNeedsUpdate(t, e) {
        this.resolvedProperty[this.propertyIndex] = t[e], this.targetObject.needsUpdate = !0;
    }
    _setValue_arrayElement_setMatrixWorldNeedsUpdate(t, e) {
        this.resolvedProperty[this.propertyIndex] = t[e], this.targetObject.matrixWorldNeedsUpdate = !0;
    }
    _setValue_fromArray(t, e) {
        this.resolvedProperty.fromArray(t, e);
    }
    _setValue_fromArray_setNeedsUpdate(t, e) {
        this.resolvedProperty.fromArray(t, e), this.targetObject.needsUpdate = !0;
    }
    _setValue_fromArray_setMatrixWorldNeedsUpdate(t, e) {
        this.resolvedProperty.fromArray(t, e), this.targetObject.matrixWorldNeedsUpdate = !0;
    }
    _getValue_unbound(t, e) {
        this.bind(), this.getValue(t, e);
    }
    _setValue_unbound(t, e) {
        this.bind(), this.setValue(t, e);
    }
    bind() {
        let t = this.node, e = this.parsedPath, i = e.objectName, s = e.propertyName, n = e.propertyIndex;
        if (t || (t = h.findNode(this.rootNode, e.nodeName), this.node = t), this.getValue = this._getValue_unavailable, this.setValue = this._setValue_unavailable, !t) {
            console.warn("THREE.PropertyBinding: No target node found for track: " + this.path + ".");
            return;
        }
        if (i) {
            let l = e.objectIndex;
            switch(i){
                case "materials":
                    if (!t.material) {
                        console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.", this);
                        return;
                    }
                    if (!t.material.materials) {
                        console.error("THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.", this);
                        return;
                    }
                    t = t.material.materials;
                    break;
                case "bones":
                    if (!t.skeleton) {
                        console.error("THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.", this);
                        return;
                    }
                    t = t.skeleton.bones;
                    for(let c = 0; c < t.length; c++)if (t[c].name === l) {
                        l = c;
                        break;
                    }
                    break;
                case "map":
                    if ("map" in t) {
                        t = t.map;
                        break;
                    }
                    if (!t.material) {
                        console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.", this);
                        return;
                    }
                    if (!t.material.map) {
                        console.error("THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.", this);
                        return;
                    }
                    t = t.material.map;
                    break;
                default:
                    if (t[i] === void 0) {
                        console.error("THREE.PropertyBinding: Can not bind to objectName of node undefined.", this);
                        return;
                    }
                    t = t[i];
            }
            if (l !== void 0) {
                if (t[l] === void 0) {
                    console.error("THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.", this, t);
                    return;
                }
                t = t[l];
            }
        }
        let r = t[s];
        if (r === void 0) {
            let l = e.nodeName;
            console.error("THREE.PropertyBinding: Trying to update property for track: " + l + "." + s + " but it wasn't found.", t);
            return;
        }
        let o = this.Versioning.None;
        this.targetObject = t, t.isMaterial === !0 ? o = this.Versioning.NeedsUpdate : t.isObject3D === !0 && (o = this.Versioning.MatrixWorldNeedsUpdate);
        let a = this.BindingType.Direct;
        if (n !== void 0) {
            if (s === "morphTargetInfluences") {
                if (!t.geometry) {
                    console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.", this);
                    return;
                }
                if (!t.geometry.morphAttributes) {
                    console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.", this);
                    return;
                }
                t.morphTargetDictionary[n] !== void 0 && (n = t.morphTargetDictionary[n]);
            }
            a = this.BindingType.ArrayElement, this.resolvedProperty = r, this.propertyIndex = n;
        } else r.fromArray !== void 0 && r.toArray !== void 0 ? (a = this.BindingType.HasFromToArray, this.resolvedProperty = r) : Array.isArray(r) ? (a = this.BindingType.EntireArray, this.resolvedProperty = r) : this.propertyName = s;
        this.getValue = this.GetterByBindingType[a], this.setValue = this.SetterByBindingTypeAndVersioning[a][o];
    }
    unbind() {
        this.node = null, this.getValue = this._getValue_unbound, this.setValue = this._setValue_unbound;
    }
};
J.Composite = Oo;
J.prototype.BindingType = {
    Direct: 0,
    EntireArray: 1,
    ArrayElement: 2,
    HasFromToArray: 3
};
J.prototype.Versioning = {
    None: 0,
    NeedsUpdate: 1,
    MatrixWorldNeedsUpdate: 2
};
J.prototype.GetterByBindingType = [
    J.prototype._getValue_direct,
    J.prototype._getValue_array,
    J.prototype._getValue_arrayElement,
    J.prototype._getValue_toArray
];
J.prototype.SetterByBindingTypeAndVersioning = [
    [
        J.prototype._setValue_direct,
        J.prototype._setValue_direct_setNeedsUpdate,
        J.prototype._setValue_direct_setMatrixWorldNeedsUpdate
    ],
    [
        J.prototype._setValue_array,
        J.prototype._setValue_array_setNeedsUpdate,
        J.prototype._setValue_array_setMatrixWorldNeedsUpdate
    ],
    [
        J.prototype._setValue_arrayElement,
        J.prototype._setValue_arrayElement_setNeedsUpdate,
        J.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate
    ],
    [
        J.prototype._setValue_fromArray,
        J.prototype._setValue_fromArray_setNeedsUpdate,
        J.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate
    ]
];
var Vh = class {
    constructor(){
        this.isAnimationObjectGroup = !0, this.uuid = It(), this._objects = Array.prototype.slice.call(arguments), this.nCachedObjects_ = 0;
        let t = {};
        this._indicesByUUID = t;
        for(let i = 0, s = arguments.length; i !== s; ++i)t[arguments[i].uuid] = i;
        this._paths = [], this._parsedPaths = [], this._bindings = [], this._bindingsIndicesByPath = {};
        let e = this;
        this.stats = {
            objects: {
                get total () {
                    return e._objects.length;
                },
                get inUse () {
                    return this.total - e.nCachedObjects_;
                }
            },
            get bindingsPerObject () {
                return e._bindings.length;
            }
        };
    }
    add() {
        let t = this._objects, e = this._indicesByUUID, i = this._paths, s = this._parsedPaths, n = this._bindings, r = n.length, o, a = t.length, l = this.nCachedObjects_;
        for(let c = 0, u = arguments.length; c !== u; ++c){
            let d = arguments[c], p = d.uuid, f = e[p];
            if (f === void 0) {
                f = a++, e[p] = f, t.push(d);
                for(let m = 0, y1 = r; m !== y1; ++m)n[m].push(new J(d, i[m], s[m]));
            } else if (f < l) {
                o = t[f];
                let m = --l, y1 = t[m];
                e[y1.uuid] = f, t[f] = y1, e[p] = m, t[m] = d;
                for(let g = 0, x1 = r; g !== x1; ++g){
                    let b = n[g], M = b[m], _ = b[f];
                    b[f] = M, _ === void 0 && (_ = new J(d, i[g], s[g])), b[m] = _;
                }
            } else t[f] !== o && console.error("THREE.AnimationObjectGroup: Different objects with the same UUID detected. Clean the caches or recreate your infrastructure when reloading scenes.");
        }
        this.nCachedObjects_ = l;
    }
    remove() {
        let t = this._objects, e = this._indicesByUUID, i = this._bindings, s = i.length, n = this.nCachedObjects_;
        for(let r = 0, o = arguments.length; r !== o; ++r){
            let a = arguments[r], l = a.uuid, c = e[l];
            if (c !== void 0 && c >= n) {
                let u = n++, d = t[u];
                e[d.uuid] = c, t[c] = d, e[l] = u, t[u] = a;
                for(let p = 0, f = s; p !== f; ++p){
                    let m = i[p], y1 = m[u], g = m[c];
                    m[c] = y1, m[u] = g;
                }
            }
        }
        this.nCachedObjects_ = n;
    }
    uncache() {
        let t = this._objects, e = this._indicesByUUID, i = this._bindings, s = i.length, n = this.nCachedObjects_, r = t.length;
        for(let o = 0, a = arguments.length; o !== a; ++o){
            let l = arguments[o], c = l.uuid, u = e[c];
            if (u !== void 0) if (delete e[c], u < n) {
                let d = --n, p = t[d], f = --r, m = t[f];
                e[p.uuid] = u, t[u] = p, e[m.uuid] = d, t[d] = m, t.pop();
                for(let y1 = 0, g = s; y1 !== g; ++y1){
                    let x1 = i[y1], b = x1[d], M = x1[f];
                    x1[u] = b, x1[d] = M, x1.pop();
                }
            } else {
                let d = --r, p = t[d];
                d > 0 && (e[p.uuid] = u), t[u] = p, t.pop();
                for(let f = 0, m = s; f !== m; ++f){
                    let y1 = i[f];
                    y1[u] = y1[d], y1.pop();
                }
            }
        }
        this.nCachedObjects_ = n;
    }
    subscribe_(t, e) {
        let i = this._bindingsIndicesByPath, s = i[t], n = this._bindings;
        if (s !== void 0) return n[s];
        let r = this._paths, o = this._parsedPaths, a = this._objects, l = a.length, c = this.nCachedObjects_, u = new Array(l);
        s = n.length, i[t] = s, r.push(t), o.push(e), n.push(u);
        for(let d = c, p = a.length; d !== p; ++d){
            let f = a[d];
            u[d] = new J(f, t, e);
        }
        return u;
    }
    unsubscribe_(t) {
        let e = this._bindingsIndicesByPath, i = e[t];
        if (i !== void 0) {
            let s = this._paths, n = this._parsedPaths, r = this._bindings, o = r.length - 1, a = r[o], l = t[o];
            e[l] = i, r[i] = a, r.pop(), n[i] = n[o], n.pop(), s[i] = s[o], s.pop();
        }
    }
}, No = class {
    constructor(t, e, i = null, s = e.blendMode){
        this._mixer = t, this._clip = e, this._localRoot = i, this.blendMode = s;
        let n = e.tracks, r = n.length, o = new Array(r), a = {
            endingStart: hi,
            endingEnd: hi
        };
        for(let l = 0; l !== r; ++l){
            let c = n[l].createInterpolant(null);
            o[l] = c, c.settings = a;
        }
        this._interpolantSettings = a, this._interpolants = o, this._propertyBindings = new Array(r), this._cacheIndex = null, this._byClipCacheIndex = null, this._timeScaleInterpolant = null, this._weightInterpolant = null, this.loop = Gc, this._loopCount = -1, this._startTime = null, this.time = 0, this.timeScale = 1, this._effectiveTimeScale = 1, this.weight = 1, this._effectiveWeight = 1, this.repetitions = 1 / 0, this.paused = !1, this.enabled = !0, this.clampWhenFinished = !1, this.zeroSlopeAtStart = !0, this.zeroSlopeAtEnd = !0;
    }
    play() {
        return this._mixer._activateAction(this), this;
    }
    stop() {
        return this._mixer._deactivateAction(this), this.reset();
    }
    reset() {
        return this.paused = !1, this.enabled = !0, this.time = 0, this._loopCount = -1, this._startTime = null, this.stopFading().stopWarping();
    }
    isRunning() {
        return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
    }
    isScheduled() {
        return this._mixer._isActiveAction(this);
    }
    startAt(t) {
        return this._startTime = t, this;
    }
    setLoop(t, e) {
        return this.loop = t, this.repetitions = e, this;
    }
    setEffectiveWeight(t) {
        return this.weight = t, this._effectiveWeight = this.enabled ? t : 0, this.stopFading();
    }
    getEffectiveWeight() {
        return this._effectiveWeight;
    }
    fadeIn(t) {
        return this._scheduleFading(t, 0, 1);
    }
    fadeOut(t) {
        return this._scheduleFading(t, 1, 0);
    }
    crossFadeFrom(t, e, i) {
        if (t.fadeOut(e), this.fadeIn(e), i) {
            let s = this._clip.duration, n = t._clip.duration, r = n / s, o = s / n;
            t.warp(1, r, e), this.warp(o, 1, e);
        }
        return this;
    }
    crossFadeTo(t, e, i) {
        return t.crossFadeFrom(this, e, i);
    }
    stopFading() {
        let t = this._weightInterpolant;
        return t !== null && (this._weightInterpolant = null, this._mixer._takeBackControlInterpolant(t)), this;
    }
    setEffectiveTimeScale(t) {
        return this.timeScale = t, this._effectiveTimeScale = this.paused ? 0 : t, this.stopWarping();
    }
    getEffectiveTimeScale() {
        return this._effectiveTimeScale;
    }
    setDuration(t) {
        return this.timeScale = this._clip.duration / t, this.stopWarping();
    }
    syncWith(t) {
        return this.time = t.time, this.timeScale = t.timeScale, this.stopWarping();
    }
    halt(t) {
        return this.warp(this._effectiveTimeScale, 0, t);
    }
    warp(t, e, i) {
        let s = this._mixer, n = s.time, r = this.timeScale, o = this._timeScaleInterpolant;
        o === null && (o = s._lendControlInterpolant(), this._timeScaleInterpolant = o);
        let a = o.parameterPositions, l = o.sampleValues;
        return a[0] = n, a[1] = n + i, l[0] = t / r, l[1] = e / r, this;
    }
    stopWarping() {
        let t = this._timeScaleInterpolant;
        return t !== null && (this._timeScaleInterpolant = null, this._mixer._takeBackControlInterpolant(t)), this;
    }
    getMixer() {
        return this._mixer;
    }
    getClip() {
        return this._clip;
    }
    getRoot() {
        return this._localRoot || this._mixer._root;
    }
    _update(t, e, i, s) {
        if (!this.enabled) {
            this._updateWeight(t);
            return;
        }
        let n = this._startTime;
        if (n !== null) {
            let a = (t - n) * i;
            a < 0 || i === 0 ? e = 0 : (this._startTime = null, e = i * a);
        }
        e *= this._updateTimeScale(t);
        let r = this._updateTime(e), o = this._updateWeight(t);
        if (o > 0) {
            let a = this._interpolants, l = this._propertyBindings;
            switch(this.blendMode){
                case Cl:
                    for(let c = 0, u = a.length; c !== u; ++c)a[c].evaluate(r), l[c].accumulateAdditive(o);
                    break;
                case Ho:
                default:
                    for(let c = 0, u = a.length; c !== u; ++c)a[c].evaluate(r), l[c].accumulate(s, o);
            }
        }
    }
    _updateWeight(t) {
        let e = 0;
        if (this.enabled) {
            e = this.weight;
            let i = this._weightInterpolant;
            if (i !== null) {
                let s = i.evaluate(t)[0];
                e *= s, t > i.parameterPositions[1] && (this.stopFading(), s === 0 && (this.enabled = !1));
            }
        }
        return this._effectiveWeight = e, e;
    }
    _updateTimeScale(t) {
        let e = 0;
        if (!this.paused) {
            e = this.timeScale;
            let i = this._timeScaleInterpolant;
            if (i !== null) {
                let s = i.evaluate(t)[0];
                e *= s, t > i.parameterPositions[1] && (this.stopWarping(), e === 0 ? this.paused = !0 : this.timeScale = e);
            }
        }
        return this._effectiveTimeScale = e, e;
    }
    _updateTime(t) {
        let e = this._clip.duration, i = this.loop, s = this.time + t, n = this._loopCount, r = i === Xc;
        if (t === 0) return n === -1 ? s : r && (n & 1) === 1 ? e - s : s;
        if (i === qc) {
            n === -1 && (this._loopCount = 0, this._setEndings(!0, !0, !1));
            t: {
                if (s >= e) s = e;
                else if (s < 0) s = 0;
                else {
                    this.time = s;
                    break t;
                }
                this.clampWhenFinished ? this.paused = !0 : this.enabled = !1, this.time = s, this._mixer.dispatchEvent({
                    type: "finished",
                    action: this,
                    direction: t < 0 ? -1 : 1
                });
            }
        } else {
            if (n === -1 && (t >= 0 ? (n = 0, this._setEndings(!0, this.repetitions === 0, r)) : this._setEndings(this.repetitions === 0, !0, r)), s >= e || s < 0) {
                let o = Math.floor(s / e);
                s -= e * o, n += Math.abs(o);
                let a = this.repetitions - n;
                if (a <= 0) this.clampWhenFinished ? this.paused = !0 : this.enabled = !1, s = t > 0 ? e : 0, this.time = s, this._mixer.dispatchEvent({
                    type: "finished",
                    action: this,
                    direction: t > 0 ? 1 : -1
                });
                else {
                    if (a === 1) {
                        let l = t < 0;
                        this._setEndings(l, !l, r);
                    } else this._setEndings(!1, !1, r);
                    this._loopCount = n, this.time = s, this._mixer.dispatchEvent({
                        type: "loop",
                        action: this,
                        loopDelta: o
                    });
                }
            } else this.time = s;
            if (r && (n & 1) === 1) return e - s;
        }
        return s;
    }
    _setEndings(t, e, i) {
        let s = this._interpolantSettings;
        i ? (s.endingStart = li, s.endingEnd = li) : (t ? s.endingStart = this.zeroSlopeAtStart ? li : hi : s.endingStart = Xs, e ? s.endingEnd = this.zeroSlopeAtEnd ? li : hi : s.endingEnd = Xs);
    }
    _scheduleFading(t, e, i) {
        let s = this._mixer, n = s.time, r = this._weightInterpolant;
        r === null && (r = s._lendControlInterpolant(), this._weightInterpolant = r);
        let o = r.parameterPositions, a = r.sampleValues;
        return o[0] = n, a[0] = e, o[1] = n + t, a[1] = i, this;
    }
}, Bd = new Float32Array(1), Dh = class extends qt {
    constructor(t){
        super(), this._root = t, this._initMemoryManager(), this._accuIndex = 0, this.time = 0, this.timeScale = 1;
    }
    _bindAction(t, e) {
        let i = t._localRoot || this._root, s = t._clip.tracks, n = s.length, r = t._propertyBindings, o = t._interpolants, a = i.uuid, l = this._bindingsByRootAndName, c = l[a];
        c === void 0 && (c = {}, l[a] = c);
        for(let u = 0; u !== n; ++u){
            let d = s[u], p = d.name, f = c[p];
            if (f !== void 0) ++f.referenceCount, r[u] = f;
            else {
                if (f = r[u], f !== void 0) {
                    f._cacheIndex === null && (++f.referenceCount, this._addInactiveBinding(f, a, p));
                    continue;
                }
                let m = e && e._propertyBindings[u].binding.parsedPath;
                f = new Po(J.create(i, p, m), d.ValueTypeName, d.getValueSize()), ++f.referenceCount, this._addInactiveBinding(f, a, p), r[u] = f;
            }
            o[u].resultBuffer = f.buffer;
        }
    }
    _activateAction(t) {
        if (!this._isActiveAction(t)) {
            if (t._cacheIndex === null) {
                let i = (t._localRoot || this._root).uuid, s = t._clip.uuid, n = this._actionsByClip[s];
                this._bindAction(t, n && n.knownActions[0]), this._addInactiveAction(t, s, i);
            }
            let e = t._propertyBindings;
            for(let i = 0, s = e.length; i !== s; ++i){
                let n = e[i];
                n.useCount++ === 0 && (this._lendBinding(n), n.saveOriginalState());
            }
            this._lendAction(t);
        }
    }
    _deactivateAction(t) {
        if (this._isActiveAction(t)) {
            let e = t._propertyBindings;
            for(let i = 0, s = e.length; i !== s; ++i){
                let n = e[i];
                --n.useCount === 0 && (n.restoreOriginalState(), this._takeBackBinding(n));
            }
            this._takeBackAction(t);
        }
    }
    _initMemoryManager() {
        this._actions = [], this._nActiveActions = 0, this._actionsByClip = {}, this._bindings = [], this._nActiveBindings = 0, this._bindingsByRootAndName = {}, this._controlInterpolants = [], this._nActiveControlInterpolants = 0;
        let t = this;
        this.stats = {
            actions: {
                get total () {
                    return t._actions.length;
                },
                get inUse () {
                    return t._nActiveActions;
                }
            },
            bindings: {
                get total () {
                    return t._bindings.length;
                },
                get inUse () {
                    return t._nActiveBindings;
                }
            },
            controlInterpolants: {
                get total () {
                    return t._controlInterpolants.length;
                },
                get inUse () {
                    return t._nActiveControlInterpolants;
                }
            }
        };
    }
    _isActiveAction(t) {
        let e = t._cacheIndex;
        return e !== null && e < this._nActiveActions;
    }
    _addInactiveAction(t, e, i) {
        let s = this._actions, n = this._actionsByClip, r = n[e];
        if (r === void 0) r = {
            knownActions: [
                t
            ],
            actionByRoot: {}
        }, t._byClipCacheIndex = 0, n[e] = r;
        else {
            let o = r.knownActions;
            t._byClipCacheIndex = o.length, o.push(t);
        }
        t._cacheIndex = s.length, s.push(t), r.actionByRoot[i] = t;
    }
    _removeInactiveAction(t) {
        let e = this._actions, i = e[e.length - 1], s = t._cacheIndex;
        i._cacheIndex = s, e[s] = i, e.pop(), t._cacheIndex = null;
        let n = t._clip.uuid, r = this._actionsByClip, o = r[n], a = o.knownActions, l = a[a.length - 1], c = t._byClipCacheIndex;
        l._byClipCacheIndex = c, a[c] = l, a.pop(), t._byClipCacheIndex = null;
        let u = o.actionByRoot, d = (t._localRoot || this._root).uuid;
        delete u[d], a.length === 0 && delete r[n], this._removeInactiveBindingsForAction(t);
    }
    _removeInactiveBindingsForAction(t) {
        let e = t._propertyBindings;
        for(let i = 0, s = e.length; i !== s; ++i){
            let n = e[i];
            --n.referenceCount === 0 && this._removeInactiveBinding(n);
        }
    }
    _lendAction(t) {
        let e = this._actions, i = t._cacheIndex, s = this._nActiveActions++, n = e[s];
        t._cacheIndex = s, e[s] = t, n._cacheIndex = i, e[i] = n;
    }
    _takeBackAction(t) {
        let e = this._actions, i = t._cacheIndex, s = --this._nActiveActions, n = e[s];
        t._cacheIndex = s, e[s] = t, n._cacheIndex = i, e[i] = n;
    }
    _addInactiveBinding(t, e, i) {
        let s = this._bindingsByRootAndName, n = this._bindings, r = s[e];
        r === void 0 && (r = {}, s[e] = r), r[i] = t, t._cacheIndex = n.length, n.push(t);
    }
    _removeInactiveBinding(t) {
        let e = this._bindings, i = t.binding, s = i.rootNode.uuid, n = i.path, r = this._bindingsByRootAndName, o = r[s], a = e[e.length - 1], l = t._cacheIndex;
        a._cacheIndex = l, e[l] = a, e.pop(), delete o[n], Object.keys(o).length === 0 && delete r[s];
    }
    _lendBinding(t) {
        let e = this._bindings, i = t._cacheIndex, s = this._nActiveBindings++, n = e[s];
        t._cacheIndex = s, e[s] = t, n._cacheIndex = i, e[i] = n;
    }
    _takeBackBinding(t) {
        let e = this._bindings, i = t._cacheIndex, s = --this._nActiveBindings, n = e[s];
        t._cacheIndex = s, e[s] = t, n._cacheIndex = i, e[i] = n;
    }
    _lendControlInterpolant() {
        let t = this._controlInterpolants, e = this._nActiveControlInterpolants++, i = t[e];
        return i === void 0 && (i = new gn(new Float32Array(2), new Float32Array(2), 1, Bd), i.__cacheIndex = e, t[e] = i), i;
    }
    _takeBackControlInterpolant(t) {
        let e = this._controlInterpolants, i = t.__cacheIndex, s = --this._nActiveControlInterpolants, n = e[s];
        t.__cacheIndex = s, e[s] = t, n.__cacheIndex = i, e[i] = n;
    }
    clipAction(t, e, i) {
        let s = e || this._root, n = s.uuid, r = typeof t == "string" ? wi.findByName(s, t) : t, o = r !== null ? r.uuid : t, a = this._actionsByClip[o], l = null;
        if (i === void 0 && (r !== null ? i = r.blendMode : i = Ho), a !== void 0) {
            let u = a.actionByRoot[n];
            if (u !== void 0 && u.blendMode === i) return u;
            l = a.knownActions[0], r === null && (r = l._clip);
        }
        if (r === null) return null;
        let c = new No(this, r, e, i);
        return this._bindAction(c, l), this._addInactiveAction(c, o, n), c;
    }
    existingAction(t, e) {
        let i = e || this._root, s = i.uuid, n = typeof t == "string" ? wi.findByName(i, t) : t, r = n ? n.uuid : t, o = this._actionsByClip[r];
        return o !== void 0 && o.actionByRoot[s] || null;
    }
    stopAllAction() {
        let t = this._actions, e = this._nActiveActions;
        for(let i = e - 1; i >= 0; --i)t[i].stop();
        return this;
    }
    update(t) {
        t *= this.timeScale;
        let e = this._actions, i = this._nActiveActions, s = this.time += t, n = Math.sign(t), r = this._accuIndex ^= 1;
        for(let l = 0; l !== i; ++l)e[l]._update(s, t, n, r);
        let o = this._bindings, a = this._nActiveBindings;
        for(let l = 0; l !== a; ++l)o[l].apply(r);
        return this;
    }
    setTime(t) {
        this.time = 0;
        for(let e = 0; e < this._actions.length; e++)this._actions[e].time = 0;
        return this.update(t);
    }
    getRoot() {
        return this._root;
    }
    uncacheClip(t) {
        let e = this._actions, i = t.uuid, s = this._actionsByClip, n = s[i];
        if (n !== void 0) {
            let r = n.knownActions;
            for(let o = 0, a = r.length; o !== a; ++o){
                let l = r[o];
                this._deactivateAction(l);
                let c = l._cacheIndex, u = e[e.length - 1];
                l._cacheIndex = null, l._byClipCacheIndex = null, u._cacheIndex = c, e[c] = u, e.pop(), this._removeInactiveBindingsForAction(l);
            }
            delete s[i];
        }
    }
    uncacheRoot(t) {
        let e = t.uuid, i = this._actionsByClip;
        for(let r in i){
            let o = i[r].actionByRoot, a = o[e];
            a !== void 0 && (this._deactivateAction(a), this._removeInactiveAction(a));
        }
        let s = this._bindingsByRootAndName, n = s[e];
        if (n !== void 0) for(let r in n){
            let o = n[r];
            o.restoreOriginalState(), this._removeInactiveBinding(o);
        }
    }
    uncacheAction(t, e) {
        let i = this.existingAction(t, e);
        i !== null && (this._deactivateAction(i), this._removeInactiveAction(i));
    }
}, Lh = class extends Wi {
    constructor(t = 1, e = 1, i = 1, s = {}){
        super(t, e, s), this.isRenderTarget3D = !0, this.depth = i, this.texture = new Qs(null, t, e, i), this.texture.isRenderTargetTexture = !0;
    }
}, Uh = class extends Wi {
    constructor(t = 1, e = 1, i = 1, s = {}){
        super(t, e, s), this.isRenderTargetArray = !0, this.depth = i, this.texture = new $s(null, t, e, i), this.texture.isRenderTargetTexture = !0;
    }
}, Wh = class h {
    constructor(t){
        this.value = t;
    }
    clone() {
        return new h(this.value.clone === void 0 ? this.value : this.value.clone());
    }
}, Ed = 0, Hh = class extends qt {
    constructor(){
        super(), this.isUniformsGroup = !0, Object.defineProperty(this, "id", {
            value: Ed++
        }), this.name = "", this.usage = Js, this.uniforms = [];
    }
    add(t) {
        return this.uniforms.push(t), this;
    }
    remove(t) {
        let e = this.uniforms.indexOf(t);
        return e !== -1 && this.uniforms.splice(e, 1), this;
    }
    setName(t) {
        return this.name = t, this;
    }
    setUsage(t) {
        return this.usage = t, this;
    }
    dispose() {
        return this.dispatchEvent({
            type: "dispose"
        }), this;
    }
    copy(t) {
        this.name = t.name, this.usage = t.usage;
        let e = t.uniforms;
        this.uniforms.length = 0;
        for(let i = 0, s = e.length; i < s; i++){
            let n = Array.isArray(e[i]) ? e[i] : [
                e[i]
            ];
            for(let r = 0; r < n.length; r++)this.uniforms.push(n[r].clone());
        }
        return this;
    }
    clone() {
        return new this.constructor().copy(this);
    }
}, qh = class extends Ji {
    constructor(t, e, i = 1){
        super(t, e), this.isInstancedInterleavedBuffer = !0, this.meshPerAttribute = i;
    }
    copy(t) {
        return super.copy(t), this.meshPerAttribute = t.meshPerAttribute, this;
    }
    clone(t) {
        let e = super.clone(t);
        return e.meshPerAttribute = this.meshPerAttribute, e;
    }
    toJSON(t) {
        let e = super.toJSON(t);
        return e.isInstancedInterleavedBuffer = !0, e.meshPerAttribute = this.meshPerAttribute, e;
    }
}, Gh = class {
    constructor(t, e, i, s, n){
        this.isGLBufferAttribute = !0, this.name = "", this.buffer = t, this.type = e, this.itemSize = i, this.elementSize = s, this.count = n, this.version = 0;
    }
    set needsUpdate(t) {
        t === !0 && this.version++;
    }
    setBuffer(t) {
        return this.buffer = t, this;
    }
    setType(t, e) {
        return this.type = t, this.elementSize = e, this;
    }
    setItemSize(t) {
        return this.itemSize = t, this;
    }
    setCount(t) {
        return this.count = t, this;
    }
}, Xh = new D, Jh = class {
    constructor(t, e, i = 0, s = 1 / 0){
        this.ray = new Le(t, e), this.near = i, this.far = s, this.camera = null, this.layers = new js, this.params = {
            Mesh: {},
            Line: {
                threshold: 1
            },
            LOD: {},
            Points: {
                threshold: 1
            },
            Sprite: {}
        };
    }
    set(t, e) {
        this.ray.set(t, e);
    }
    setFromCamera(t, e) {
        e.isPerspectiveCamera ? (this.ray.origin.setFromMatrixPosition(e.matrixWorld), this.ray.direction.set(t.x, t.y, .5).unproject(e).sub(this.ray.origin).normalize(), this.camera = e) : e.isOrthographicCamera ? (this.ray.origin.set(t.x, t.y, (e.near + e.far) / (e.near - e.far)).unproject(e), this.ray.direction.set(0, 0, -1).transformDirection(e.matrixWorld), this.camera = e) : console.error("THREE.Raycaster: Unsupported camera type: " + e.type);
    }
    setFromXRController(t) {
        return Xh.identity().extractRotation(t.matrixWorld), this.ray.origin.setFromMatrixPosition(t.matrixWorld), this.ray.direction.set(0, 0, -1).applyMatrix4(Xh), this;
    }
    intersectObject(t, e = !0, i = []) {
        return Vo(t, this, i, e), i.sort(Zh), i;
    }
    intersectObjects(t, e = !0, i = []) {
        for(let s = 0, n = t.length; s < n; s++)Vo(t[s], this, i, e);
        return i.sort(Zh), i;
    }
};
function Zh(h, t) {
    return h.distance - t.distance;
}
function Vo(h, t, e, i) {
    let s = !0;
    if (h.layers.test(t.layers) && h.raycast(t, e) === !1 && (s = !1), s === !0 && i === !0) {
        let n = h.children;
        for(let r = 0, o = n.length; r < o; r++)Vo(n[r], t, e, !0);
    }
}
var Yh = class {
    constructor(t = 1, e = 0, i = 0){
        return this.radius = t, this.phi = e, this.theta = i, this;
    }
    set(t, e, i) {
        return this.radius = t, this.phi = e, this.theta = i, this;
    }
    copy(t) {
        return this.radius = t.radius, this.phi = t.phi, this.theta = t.theta, this;
    }
    makeSafe() {
        return this.phi = N(this.phi, 1e-6, Math.PI - 1e-6), this;
    }
    setFromVector3(t) {
        return this.setFromCartesianCoords(t.x, t.y, t.z);
    }
    setFromCartesianCoords(t, e, i) {
        return this.radius = Math.sqrt(t * t + e * e + i * i), this.radius === 0 ? (this.theta = 0, this.phi = 0) : (this.theta = Math.atan2(t, i), this.phi = Math.acos(N(e / this.radius, -1, 1))), this;
    }
    clone() {
        return new this.constructor().copy(this);
    }
}, $h = class {
    constructor(t = 1, e = 0, i = 0){
        return this.radius = t, this.theta = e, this.y = i, this;
    }
    set(t, e, i) {
        return this.radius = t, this.theta = e, this.y = i, this;
    }
    copy(t) {
        return this.radius = t.radius, this.theta = t.theta, this.y = t.y, this;
    }
    setFromVector3(t) {
        return this.setFromCartesianCoords(t.x, t.y, t.z);
    }
    setFromCartesianCoords(t, e, i) {
        return this.radius = Math.sqrt(t * t + i * i), this.theta = Math.atan2(t, i), this.y = e, this;
    }
    clone() {
        return new this.constructor().copy(this);
    }
}, Qh = class h {
    constructor(t, e, i, s){
        h.prototype.isMatrix2 = !0, this.elements = [
            1,
            0,
            0,
            1
        ], t !== void 0 && this.set(t, e, i, s);
    }
    identity() {
        return this.set(1, 0, 0, 1), this;
    }
    fromArray(t, e = 0) {
        for(let i = 0; i < 4; i++)this.elements[i] = t[i + e];
        return this;
    }
    set(t, e, i, s) {
        let n = this.elements;
        return n[0] = t, n[2] = e, n[1] = i, n[3] = s, this;
    }
}, jh = new T, Kh = class {
    constructor(t = new T(1 / 0, 1 / 0), e = new T(-1 / 0, -1 / 0)){
        this.isBox2 = !0, this.min = t, this.max = e;
    }
    set(t, e) {
        return this.min.copy(t), this.max.copy(e), this;
    }
    setFromPoints(t) {
        this.makeEmpty();
        for(let e = 0, i = t.length; e < i; e++)this.expandByPoint(t[e]);
        return this;
    }
    setFromCenterAndSize(t, e) {
        let i = jh.copy(e).multiplyScalar(.5);
        return this.min.copy(t).sub(i), this.max.copy(t).add(i), this;
    }
    clone() {
        return new this.constructor().copy(this);
    }
    copy(t) {
        return this.min.copy(t.min), this.max.copy(t.max), this;
    }
    makeEmpty() {
        return this.min.x = this.min.y = 1 / 0, this.max.x = this.max.y = -1 / 0, this;
    }
    isEmpty() {
        return this.max.x < this.min.x || this.max.y < this.min.y;
    }
    getCenter(t) {
        return this.isEmpty() ? t.set(0, 0) : t.addVectors(this.min, this.max).multiplyScalar(.5);
    }
    getSize(t) {
        return this.isEmpty() ? t.set(0, 0) : t.subVectors(this.max, this.min);
    }
    expandByPoint(t) {
        return this.min.min(t), this.max.max(t), this;
    }
    expandByVector(t) {
        return this.min.sub(t), this.max.add(t), this;
    }
    expandByScalar(t) {
        return this.min.addScalar(-t), this.max.addScalar(t), this;
    }
    containsPoint(t) {
        return t.x >= this.min.x && t.x <= this.max.x && t.y >= this.min.y && t.y <= this.max.y;
    }
    containsBox(t) {
        return this.min.x <= t.min.x && t.max.x <= this.max.x && this.min.y <= t.min.y && t.max.y <= this.max.y;
    }
    getParameter(t, e) {
        return e.set((t.x - this.min.x) / (this.max.x - this.min.x), (t.y - this.min.y) / (this.max.y - this.min.y));
    }
    intersectsBox(t) {
        return t.max.x >= this.min.x && t.min.x <= this.max.x && t.max.y >= this.min.y && t.min.y <= this.max.y;
    }
    clampPoint(t, e) {
        return e.copy(t).clamp(this.min, this.max);
    }
    distanceToPoint(t) {
        return this.clampPoint(t, jh).distanceTo(t);
    }
    intersect(t) {
        return this.min.max(t.min), this.max.min(t.max), this.isEmpty() && this.makeEmpty(), this;
    }
    union(t) {
        return this.min.min(t.min), this.max.max(t.max), this;
    }
    translate(t) {
        return this.min.add(t), this.max.add(t), this;
    }
    equals(t) {
        return t.min.equals(this.min) && t.max.equals(this.max);
    }
}, tl = new w, Ds = new w, el = class {
    constructor(t = new w, e = new w){
        this.start = t, this.end = e;
    }
    set(t, e) {
        return this.start.copy(t), this.end.copy(e), this;
    }
    copy(t) {
        return this.start.copy(t.start), this.end.copy(t.end), this;
    }
    getCenter(t) {
        return t.addVectors(this.start, this.end).multiplyScalar(.5);
    }
    delta(t) {
        return t.subVectors(this.end, this.start);
    }
    distanceSq() {
        return this.start.distanceToSquared(this.end);
    }
    distance() {
        return this.start.distanceTo(this.end);
    }
    at(t, e) {
        return this.delta(e).multiplyScalar(t).add(this.start);
    }
    closestPointToPointParameter(t, e) {
        tl.subVectors(t, this.start), Ds.subVectors(this.end, this.start);
        let i = Ds.dot(Ds), n = Ds.dot(tl) / i;
        return e && (n = N(n, 0, 1)), n;
    }
    closestPointToPoint(t, e, i) {
        let s = this.closestPointToPointParameter(t, e);
        return this.delta(i).multiplyScalar(s).add(this.start);
    }
    applyMatrix4(t) {
        return this.start.applyMatrix4(t), this.end.applyMatrix4(t), this;
    }
    equals(t) {
        return t.start.equals(this.start) && t.end.equals(this.end);
    }
    clone() {
        return new this.constructor().copy(this);
    }
}, il = new w, sl = class extends G {
    constructor(t, e){
        super(), this.light = t, this.matrixAutoUpdate = !1, this.color = e, this.type = "SpotLightHelper";
        let i = new L, s = [
            0,
            0,
            0,
            0,
            0,
            1,
            0,
            0,
            0,
            1,
            0,
            1,
            0,
            0,
            0,
            -1,
            0,
            1,
            0,
            0,
            0,
            0,
            1,
            1,
            0,
            0,
            0,
            0,
            -1,
            1
        ];
        for(let r = 0, o = 1, a = 32; r < a; r++, o++){
            let l = r / a * Math.PI * 2, c = o / a * Math.PI * 2;
            s.push(Math.cos(l), Math.sin(l), 1, Math.cos(c), Math.sin(c), 1);
        }
        i.setAttribute("position", new E(s, 3));
        let n = new mt({
            fog: !1,
            toneMapped: !1
        });
        this.cone = new Wt(i, n), this.add(this.cone), this.update();
    }
    dispose() {
        this.cone.geometry.dispose(), this.cone.material.dispose();
    }
    update() {
        this.light.updateWorldMatrix(!0, !1), this.light.target.updateWorldMatrix(!0, !1), this.parent ? (this.parent.updateWorldMatrix(!0), this.matrix.copy(this.parent.matrixWorld).invert().multiply(this.light.matrixWorld)) : this.matrix.copy(this.light.matrixWorld), this.matrixWorld.copy(this.light.matrixWorld);
        let t = this.light.distance ? this.light.distance : 1e3, e = t * Math.tan(this.light.angle);
        this.cone.scale.set(e, e, t), il.setFromMatrixPosition(this.light.target.matrixWorld), this.cone.lookAt(il), this.color !== void 0 ? this.cone.material.color.set(this.color) : this.cone.material.color.copy(this.light.color);
    }
}, ge = new w, Ls = new D, cr = new D, nl = class extends Wt {
    constructor(t){
        let e = Nl(t), i = new L, s = [], n = [], r = new P(0, 0, 1), o = new P(0, 1, 0);
        for(let l = 0; l < e.length; l++){
            let c = e[l];
            c.parent && c.parent.isBone && (s.push(0, 0, 0), s.push(0, 0, 0), n.push(r.r, r.g, r.b), n.push(o.r, o.g, o.b));
        }
        i.setAttribute("position", new E(s, 3)), i.setAttribute("color", new E(n, 3));
        let a = new mt({
            vertexColors: !0,
            depthTest: !1,
            depthWrite: !1,
            toneMapped: !1,
            transparent: !0
        });
        super(i, a), this.isSkeletonHelper = !0, this.type = "SkeletonHelper", this.root = t, this.bones = e, this.matrix = t.matrixWorld, this.matrixAutoUpdate = !1;
    }
    updateMatrixWorld(t) {
        let e = this.bones, i = this.geometry, s = i.getAttribute("position");
        cr.copy(this.root.matrixWorld).invert();
        for(let n = 0, r = 0; n < e.length; n++){
            let o = e[n];
            o.parent && o.parent.isBone && (Ls.multiplyMatrices(cr, o.matrixWorld), ge.setFromMatrixPosition(Ls), s.setXYZ(r, ge.x, ge.y, ge.z), Ls.multiplyMatrices(cr, o.parent.matrixWorld), ge.setFromMatrixPosition(Ls), s.setXYZ(r + 1, ge.x, ge.y, ge.z), r += 2);
        }
        i.getAttribute("position").needsUpdate = !0, super.updateMatrixWorld(t);
    }
    dispose() {
        this.geometry.dispose(), this.material.dispose();
    }
};
function Nl(h) {
    let t = [];
    h.isBone === !0 && t.push(h);
    for(let e = 0; e < h.children.length; e++)t.push.apply(t, Nl(h.children[e]));
    return t;
}
var rl = class extends Ct {
    constructor(t, e, i){
        let s = new mn(e, 4, 2), n = new _e({
            wireframe: !0,
            fog: !1,
            toneMapped: !1
        });
        super(s, n), this.light = t, this.color = i, this.type = "PointLightHelper", this.matrix = this.light.matrixWorld, this.matrixAutoUpdate = !1, this.update();
    }
    dispose() {
        this.geometry.dispose(), this.material.dispose();
    }
    update() {
        this.light.updateWorldMatrix(!0, !1), this.color !== void 0 ? this.material.color.set(this.color) : this.material.color.copy(this.light.color);
    }
}, Rd = new w, ol = new P, al = new P, hl = class extends G {
    constructor(t, e, i){
        super(), this.light = t, this.matrix = t.matrixWorld, this.matrixAutoUpdate = !1, this.color = i, this.type = "HemisphereLightHelper";
        let s = new fn(e);
        s.rotateY(Math.PI * .5), this.material = new _e({
            wireframe: !0,
            fog: !1,
            toneMapped: !1
        }), this.color === void 0 && (this.material.vertexColors = !0);
        let n = s.getAttribute("position"), r = new Float32Array(n.count * 3);
        s.setAttribute("color", new Z(r, 3)), this.add(new Ct(s, this.material)), this.update();
    }
    dispose() {
        this.children[0].geometry.dispose(), this.children[0].material.dispose();
    }
    update() {
        let t = this.children[0];
        if (this.color !== void 0) this.material.color.set(this.color);
        else {
            let e = t.geometry.getAttribute("color");
            ol.copy(this.light.color), al.copy(this.light.groundColor);
            for(let i = 0, s = e.count; i < s; i++){
                let n = i < s / 2 ? ol : al;
                e.setXYZ(i, n.r, n.g, n.b);
            }
            e.needsUpdate = !0;
        }
        this.light.updateWorldMatrix(!0, !1), t.lookAt(Rd.setFromMatrixPosition(this.light.matrixWorld).negate());
    }
}, ll = class extends Wt {
    constructor(t = 10, e = 10, i = 4473924, s = 8947848){
        i = new P(i), s = new P(s);
        let n = e / 2, r = t / e, o = t / 2, a = [], l = [];
        for(let d = 0, p = 0, f = -o; d <= e; d++, f += r){
            a.push(-o, 0, f, o, 0, f), a.push(f, 0, -o, f, 0, o);
            let m = d === n ? i : s;
            m.toArray(l, p), p += 3, m.toArray(l, p), p += 3, m.toArray(l, p), p += 3, m.toArray(l, p), p += 3;
        }
        let c = new L;
        c.setAttribute("position", new E(a, 3)), c.setAttribute("color", new E(l, 3));
        let u = new mt({
            vertexColors: !0,
            toneMapped: !1
        });
        super(c, u), this.type = "GridHelper";
    }
    dispose() {
        this.geometry.dispose(), this.material.dispose();
    }
}, cl = class extends Wt {
    constructor(t = 10, e = 16, i = 8, s = 64, n = 4473924, r = 8947848){
        n = new P(n), r = new P(r);
        let o = [], a = [];
        if (e > 1) for(let u = 0; u < e; u++){
            let d = u / e * (Math.PI * 2), p = Math.sin(d) * t, f = Math.cos(d) * t;
            o.push(0, 0, 0), o.push(p, 0, f);
            let m = u & 1 ? n : r;
            a.push(m.r, m.g, m.b), a.push(m.r, m.g, m.b);
        }
        for(let u = 0; u < i; u++){
            let d = u & 1 ? n : r, p = t - t / i * u;
            for(let f = 0; f < s; f++){
                let m = f / s * (Math.PI * 2), y1 = Math.sin(m) * p, g = Math.cos(m) * p;
                o.push(y1, 0, g), a.push(d.r, d.g, d.b), m = (f + 1) / s * (Math.PI * 2), y1 = Math.sin(m) * p, g = Math.cos(m) * p, o.push(y1, 0, g), a.push(d.r, d.g, d.b);
            }
        }
        let l = new L;
        l.setAttribute("position", new E(o, 3)), l.setAttribute("color", new E(a, 3));
        let c = new mt({
            vertexColors: !0,
            toneMapped: !1
        });
        super(l, c), this.type = "PolarGridHelper";
    }
    dispose() {
        this.geometry.dispose(), this.material.dispose();
    }
}, ul = new w, Us = new w, dl = new w, pl = class extends G {
    constructor(t, e, i){
        super(), this.light = t, this.matrix = t.matrixWorld, this.matrixAutoUpdate = !1, this.color = i, this.type = "DirectionalLightHelper", e === void 0 && (e = 1);
        let s = new L;
        s.setAttribute("position", new E([
            -e,
            e,
            0,
            e,
            e,
            0,
            e,
            -e,
            0,
            -e,
            -e,
            0,
            -e,
            e,
            0
        ], 3));
        let n = new mt({
            fog: !1,
            toneMapped: !1
        });
        this.lightPlane = new le(s, n), this.add(this.lightPlane), s = new L, s.setAttribute("position", new E([
            0,
            0,
            0,
            0,
            0,
            1
        ], 3)), this.targetLine = new le(s, n), this.add(this.targetLine), this.update();
    }
    dispose() {
        this.lightPlane.geometry.dispose(), this.lightPlane.material.dispose(), this.targetLine.geometry.dispose(), this.targetLine.material.dispose();
    }
    update() {
        this.light.updateWorldMatrix(!0, !1), this.light.target.updateWorldMatrix(!0, !1), ul.setFromMatrixPosition(this.light.matrixWorld), Us.setFromMatrixPosition(this.light.target.matrixWorld), dl.subVectors(Us, ul), this.lightPlane.lookAt(Us), this.color !== void 0 ? (this.lightPlane.material.color.set(this.color), this.targetLine.material.color.set(this.color)) : (this.lightPlane.material.color.copy(this.light.color), this.targetLine.material.color.copy(this.light.color)), this.targetLine.lookAt(Us), this.targetLine.scale.z = dl.length();
    }
}, Ws = new w, et = new Gi, fl = class extends Wt {
    constructor(t){
        let e = new L, i = new mt({
            color: 16777215,
            vertexColors: !0,
            toneMapped: !1
        }), s = [], n = [], r = {};
        o("n1", "n2"), o("n2", "n4"), o("n4", "n3"), o("n3", "n1"), o("f1", "f2"), o("f2", "f4"), o("f4", "f3"), o("f3", "f1"), o("n1", "f1"), o("n2", "f2"), o("n3", "f3"), o("n4", "f4"), o("p", "n1"), o("p", "n2"), o("p", "n3"), o("p", "n4"), o("u1", "u2"), o("u2", "u3"), o("u3", "u1"), o("c", "t"), o("p", "c"), o("cn1", "cn2"), o("cn3", "cn4"), o("cf1", "cf2"), o("cf3", "cf4");
        function o(f, m) {
            a(f), a(m);
        }
        function a(f) {
            s.push(0, 0, 0), n.push(0, 0, 0), r[f] === void 0 && (r[f] = []), r[f].push(s.length / 3 - 1);
        }
        e.setAttribute("position", new E(s, 3)), e.setAttribute("color", new E(n, 3)), super(e, i), this.type = "CameraHelper", this.camera = t, this.camera.updateProjectionMatrix && this.camera.updateProjectionMatrix(), this.matrix = t.matrixWorld, this.matrixAutoUpdate = !1, this.pointMap = r, this.update();
        let l = new P(16755200), c = new P(16711680), u = new P(43775), d = new P(16777215), p = new P(3355443);
        this.setColors(l, c, u, d, p);
    }
    setColors(t, e, i, s, n) {
        let o = this.geometry.getAttribute("color");
        o.setXYZ(0, t.r, t.g, t.b), o.setXYZ(1, t.r, t.g, t.b), o.setXYZ(2, t.r, t.g, t.b), o.setXYZ(3, t.r, t.g, t.b), o.setXYZ(4, t.r, t.g, t.b), o.setXYZ(5, t.r, t.g, t.b), o.setXYZ(6, t.r, t.g, t.b), o.setXYZ(7, t.r, t.g, t.b), o.setXYZ(8, t.r, t.g, t.b), o.setXYZ(9, t.r, t.g, t.b), o.setXYZ(10, t.r, t.g, t.b), o.setXYZ(11, t.r, t.g, t.b), o.setXYZ(12, t.r, t.g, t.b), o.setXYZ(13, t.r, t.g, t.b), o.setXYZ(14, t.r, t.g, t.b), o.setXYZ(15, t.r, t.g, t.b), o.setXYZ(16, t.r, t.g, t.b), o.setXYZ(17, t.r, t.g, t.b), o.setXYZ(18, t.r, t.g, t.b), o.setXYZ(19, t.r, t.g, t.b), o.setXYZ(20, t.r, t.g, t.b), o.setXYZ(21, t.r, t.g, t.b), o.setXYZ(22, t.r, t.g, t.b), o.setXYZ(23, t.r, t.g, t.b), o.setXYZ(24, e.r, e.g, e.b), o.setXYZ(25, e.r, e.g, e.b), o.setXYZ(26, e.r, e.g, e.b), o.setXYZ(27, e.r, e.g, e.b), o.setXYZ(28, e.r, e.g, e.b), o.setXYZ(29, e.r, e.g, e.b), o.setXYZ(30, e.r, e.g, e.b), o.setXYZ(31, e.r, e.g, e.b), o.setXYZ(32, i.r, i.g, i.b), o.setXYZ(33, i.r, i.g, i.b), o.setXYZ(34, i.r, i.g, i.b), o.setXYZ(35, i.r, i.g, i.b), o.setXYZ(36, i.r, i.g, i.b), o.setXYZ(37, i.r, i.g, i.b), o.setXYZ(38, s.r, s.g, s.b), o.setXYZ(39, s.r, s.g, s.b), o.setXYZ(40, n.r, n.g, n.b), o.setXYZ(41, n.r, n.g, n.b), o.setXYZ(42, n.r, n.g, n.b), o.setXYZ(43, n.r, n.g, n.b), o.setXYZ(44, n.r, n.g, n.b), o.setXYZ(45, n.r, n.g, n.b), o.setXYZ(46, n.r, n.g, n.b), o.setXYZ(47, n.r, n.g, n.b), o.setXYZ(48, n.r, n.g, n.b), o.setXYZ(49, n.r, n.g, n.b), o.needsUpdate = !0;
    }
    update() {
        let t = this.geometry, e = this.pointMap, i = 1, s = 1;
        et.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse);
        let n = this.camera.coordinateSystem === oe ? -1 : 0;
        it("c", e, t, et, 0, 0, n), it("t", e, t, et, 0, 0, 1), it("n1", e, t, et, -i, -s, n), it("n2", e, t, et, i, -s, n), it("n3", e, t, et, -i, s, n), it("n4", e, t, et, i, s, n), it("f1", e, t, et, -i, -s, 1), it("f2", e, t, et, i, -s, 1), it("f3", e, t, et, -i, s, 1), it("f4", e, t, et, i, s, 1), it("u1", e, t, et, i * .7, s * 1.1, n), it("u2", e, t, et, -i * .7, s * 1.1, n), it("u3", e, t, et, 0, s * 2, n), it("cf1", e, t, et, -i, 0, 1), it("cf2", e, t, et, i, 0, 1), it("cf3", e, t, et, 0, -s, 1), it("cf4", e, t, et, 0, s, 1), it("cn1", e, t, et, -i, 0, n), it("cn2", e, t, et, i, 0, n), it("cn3", e, t, et, 0, -s, n), it("cn4", e, t, et, 0, s, n), t.getAttribute("position").needsUpdate = !0;
    }
    dispose() {
        this.geometry.dispose(), this.material.dispose();
    }
};
function it(h, t, e, i, s, n, r) {
    Ws.set(s, n, r).unproject(i);
    let o = t[h];
    if (o !== void 0) {
        let a = e.getAttribute("position");
        for(let l = 0, c = o.length; l < c; l++)a.setXYZ(o[l], Ws.x, Ws.y, Ws.z);
    }
}
var Hs = new ft, ml = class extends Wt {
    constructor(t, e = 16776960){
        let i = new Uint16Array([
            0,
            1,
            1,
            2,
            2,
            3,
            3,
            0,
            4,
            5,
            5,
            6,
            6,
            7,
            7,
            4,
            0,
            4,
            1,
            5,
            2,
            6,
            3,
            7
        ]), s = new Float32Array(8 * 3), n = new L;
        n.setIndex(new Z(i, 1)), n.setAttribute("position", new Z(s, 3)), super(n, new mt({
            color: e,
            toneMapped: !1
        })), this.object = t, this.type = "BoxHelper", this.matrixAutoUpdate = !1, this.update();
    }
    update(t) {
        if (t !== void 0 && console.warn("THREE.BoxHelper: .update() has no longer arguments."), this.object !== void 0 && Hs.setFromObject(this.object), Hs.isEmpty()) return;
        let e = Hs.min, i = Hs.max, s = this.geometry.attributes.position, n = s.array;
        n[0] = i.x, n[1] = i.y, n[2] = i.z, n[3] = e.x, n[4] = i.y, n[5] = i.z, n[6] = e.x, n[7] = e.y, n[8] = i.z, n[9] = i.x, n[10] = e.y, n[11] = i.z, n[12] = i.x, n[13] = i.y, n[14] = e.z, n[15] = e.x, n[16] = i.y, n[17] = e.z, n[18] = e.x, n[19] = e.y, n[20] = e.z, n[21] = i.x, n[22] = e.y, n[23] = e.z, s.needsUpdate = !0, this.geometry.computeBoundingSphere();
    }
    setFromObject(t) {
        return this.object = t, this.update(), this;
    }
    copy(t, e) {
        return super.copy(t, e), this.object = t.object, this;
    }
    dispose() {
        this.geometry.dispose(), this.material.dispose();
    }
}, yl = class extends Wt {
    constructor(t, e = 16776960){
        let i = new Uint16Array([
            0,
            1,
            1,
            2,
            2,
            3,
            3,
            0,
            4,
            5,
            5,
            6,
            6,
            7,
            7,
            4,
            0,
            4,
            1,
            5,
            2,
            6,
            3,
            7
        ]), s = [
            1,
            1,
            1,
            -1,
            1,
            1,
            -1,
            -1,
            1,
            1,
            -1,
            1,
            1,
            1,
            -1,
            -1,
            1,
            -1,
            -1,
            -1,
            -1,
            1,
            -1,
            -1
        ], n = new L;
        n.setIndex(new Z(i, 1)), n.setAttribute("position", new E(s, 3)), super(n, new mt({
            color: e,
            toneMapped: !1
        })), this.box = t, this.type = "Box3Helper", this.geometry.computeBoundingSphere();
    }
    updateMatrixWorld(t) {
        let e = this.box;
        e.isEmpty() || (e.getCenter(this.position), e.getSize(this.scale), this.scale.multiplyScalar(.5), super.updateMatrixWorld(t));
    }
    dispose() {
        this.geometry.dispose(), this.material.dispose();
    }
}, gl = class extends le {
    constructor(t, e = 1, i = 16776960){
        let s = i, n = [
            1,
            -1,
            0,
            -1,
            1,
            0,
            -1,
            -1,
            0,
            1,
            1,
            0,
            -1,
            1,
            0,
            -1,
            -1,
            0,
            1,
            -1,
            0,
            1,
            1,
            0
        ], r = new L;
        r.setAttribute("position", new E(n, 3)), r.computeBoundingSphere(), super(r, new mt({
            color: s,
            toneMapped: !1
        })), this.type = "PlaneHelper", this.plane = t, this.size = e;
        let o = [
            1,
            1,
            0,
            -1,
            1,
            0,
            -1,
            -1,
            0,
            1,
            1,
            0,
            -1,
            -1,
            0,
            1,
            -1,
            0
        ], a = new L;
        a.setAttribute("position", new E(o, 3)), a.computeBoundingSphere(), this.add(new Ct(a, new _e({
            color: s,
            opacity: .2,
            transparent: !0,
            depthWrite: !1,
            toneMapped: !1
        })));
    }
    updateMatrixWorld(t) {
        this.position.set(0, 0, 0), this.scale.set(.5 * this.size, .5 * this.size, 1), this.lookAt(this.plane.normal), this.translateZ(-this.plane.constant), super.updateMatrixWorld(t);
    }
    dispose() {
        this.geometry.dispose(), this.material.dispose(), this.children[0].geometry.dispose(), this.children[0].material.dispose();
    }
}, xl = new w, qs, ur, bl = class extends G {
    constructor(t = new w(0, 0, 1), e = new w(0, 0, 0), i = 1, s = 16776960, n = i * .2, r = n * .2){
        super(), this.type = "ArrowHelper", qs === void 0 && (qs = new L, qs.setAttribute("position", new E([
            0,
            0,
            0,
            0,
            1,
            0
        ], 3)), ur = new $i(0, .5, 1, 5, 1), ur.translate(0, -.5, 0)), this.position.copy(e), this.line = new le(qs, new mt({
            color: s,
            toneMapped: !1
        })), this.line.matrixAutoUpdate = !1, this.add(this.line), this.cone = new Ct(ur, new _e({
            color: s,
            toneMapped: !1
        })), this.cone.matrixAutoUpdate = !1, this.add(this.cone), this.setDirection(t), this.setLength(i, n, r);
    }
    setDirection(t) {
        if (t.y > .99999) this.quaternion.set(0, 0, 0, 1);
        else if (t.y < -.99999) this.quaternion.set(1, 0, 0, 0);
        else {
            xl.set(t.z, 0, -t.x).normalize();
            let e = Math.acos(t.y);
            this.quaternion.setFromAxisAngle(xl, e);
        }
    }
    setLength(t, e = t * .2, i = e * .2) {
        this.line.scale.set(1, Math.max(1e-4, t - e), 1), this.line.updateMatrix(), this.cone.scale.set(i, e, i), this.cone.position.y = t, this.cone.updateMatrix();
    }
    setColor(t) {
        this.line.material.color.set(t), this.cone.material.color.set(t);
    }
    copy(t) {
        return super.copy(t, !1), this.line.copy(t.line), this.cone.copy(t.cone), this;
    }
    dispose() {
        this.line.geometry.dispose(), this.line.material.dispose(), this.cone.geometry.dispose(), this.cone.material.dispose();
    }
}, wl = class extends Wt {
    constructor(t = 1){
        let e = [
            0,
            0,
            0,
            t,
            0,
            0,
            0,
            0,
            0,
            0,
            t,
            0,
            0,
            0,
            0,
            0,
            0,
            t
        ], i = [
            1,
            0,
            0,
            1,
            .6,
            0,
            0,
            1,
            0,
            .6,
            1,
            0,
            0,
            0,
            1,
            0,
            .6,
            1
        ], s = new L;
        s.setAttribute("position", new E(e, 3)), s.setAttribute("color", new E(i, 3));
        let n = new mt({
            vertexColors: !0,
            toneMapped: !1
        });
        super(s, n), this.type = "AxesHelper";
    }
    setColors(t, e, i) {
        let s = new P, n = this.geometry.attributes.color.array;
        return s.set(t), s.toArray(n, 0), s.toArray(n, 3), s.set(e), s.toArray(n, 6), s.toArray(n, 9), s.set(i), s.toArray(n, 12), s.toArray(n, 15), this.geometry.attributes.color.needsUpdate = !0, this;
    }
    dispose() {
        this.geometry.dispose(), this.material.dispose();
    }
}, Ml = class {
    constructor(){
        this.type = "ShapePath", this.color = new P, this.subPaths = [], this.currentPath = null;
    }
    moveTo(t, e) {
        return this.currentPath = new mi, this.subPaths.push(this.currentPath), this.currentPath.moveTo(t, e), this;
    }
    lineTo(t, e) {
        return this.currentPath.lineTo(t, e), this;
    }
    quadraticCurveTo(t, e, i, s) {
        return this.currentPath.quadraticCurveTo(t, e, i, s), this;
    }
    bezierCurveTo(t, e, i, s, n, r) {
        return this.currentPath.bezierCurveTo(t, e, i, s, n, r), this;
    }
    splineThru(t) {
        return this.currentPath.splineThru(t), this;
    }
    toShapes(t) {
        function e(g) {
            let x1 = [];
            for(let b = 0, M = g.length; b < M; b++){
                let _ = g[b], v = new Me;
                v.curves = _.curves, x1.push(v);
            }
            return x1;
        }
        function i(g, x1) {
            let b = x1.length, M = !1;
            for(let _ = b - 1, v = 0; v < b; _ = v++){
                let S = x1[_], A = x1[v], I = A.x - S.x, C = A.y - S.y;
                if (Math.abs(C) > Number.EPSILON) {
                    if (C < 0 && (S = x1[v], I = -I, A = x1[_], C = -C), g.y < S.y || g.y > A.y) continue;
                    if (g.y === S.y) {
                        if (g.x === S.x) return !0;
                    } else {
                        let k = C * (g.x - S.x) - I * (g.y - S.y);
                        if (k === 0) return !0;
                        if (k < 0) continue;
                        M = !M;
                    }
                } else {
                    if (g.y !== S.y) continue;
                    if (A.x <= g.x && g.x <= S.x || S.x <= g.x && g.x <= A.x) return !0;
                }
            }
            return M;
        }
        let s = he.isClockWise, n = this.subPaths;
        if (n.length === 0) return [];
        let r, o, a, l = [];
        if (n.length === 1) return o = n[0], a = new Me, a.curves = o.curves, l.push(a), l;
        let c = !s(n[0].getPoints());
        c = t ? !c : c;
        let u = [], d = [], p = [], f = 0, m;
        d[f] = void 0, p[f] = [];
        for(let g = 0, x1 = n.length; g < x1; g++)o = n[g], m = o.getPoints(), r = s(m), r = t ? !r : r, r ? (!c && d[f] && f++, d[f] = {
            s: new Me,
            p: m
        }, d[f].s.curves = o.curves, c && f++, p[f] = []) : p[f].push({
            h: o,
            p: m[0]
        });
        if (!d[0]) return e(n);
        if (d.length > 1) {
            let g = !1, x1 = 0;
            for(let b = 0, M = d.length; b < M; b++)u[b] = [];
            for(let b = 0, M = d.length; b < M; b++){
                let _ = p[b];
                for(let v = 0; v < _.length; v++){
                    let S = _[v], A = !0;
                    for(let I = 0; I < d.length; I++)i(S.p, d[I].p) && (b !== I && x1++, A ? (A = !1, u[I].push(S)) : g = !0);
                    A && u[b].push(S);
                }
            }
            x1 > 0 && g === !1 && (p = u);
        }
        let y1;
        for(let g = 0, x1 = d.length; g < x1; g++){
            a = d[g].s, l.push(a), y1 = p[g];
            for(let b = 0, M = y1.length; b < M; b++)a.holes.push(y1[b].h);
        }
        return l;
    }
}, _l = class extends qt {
    constructor(t, e = null){
        super(), this.object = t, this.domElement = e, this.enabled = !0, this.state = -1, this.keys = {}, this.mouseButtons = {
            LEFT: null,
            MIDDLE: null,
            RIGHT: null
        }, this.touches = {
            ONE: null,
            TWO: null
        };
    }
    connect() {}
    disconnect() {}
    dispose() {}
    update() {}
};
function kd(h, t) {
    let e = h.image && h.image.width ? h.image.width / h.image.height : 1;
    return e > t ? (h.repeat.x = 1, h.repeat.y = e / t, h.offset.x = 0, h.offset.y = (1 - h.repeat.y) / 2) : (h.repeat.x = t / e, h.repeat.y = 1, h.offset.x = (1 - h.repeat.x) / 2, h.offset.y = 0), h;
}
function Pd(h, t) {
    let e = h.image && h.image.width ? h.image.width / h.image.height : 1;
    return e > t ? (h.repeat.x = t / e, h.repeat.y = 1, h.offset.x = (1 - h.repeat.x) / 2, h.offset.y = 0) : (h.repeat.x = 1, h.repeat.y = e / t, h.offset.x = 0, h.offset.y = (1 - h.repeat.y) / 2), h;
}
function Od(h) {
    return h.repeat.x = 1, h.repeat.y = 1, h.offset.x = 0, h.offset.y = 0, h;
}
function Nd(h, t, e, i) {
    let s = Vd(i);
    switch(e){
        case rc:
            return h * t;
        case ac:
            return h * t;
        case hc:
            return h * t * 2;
        case Tl:
            return h * t / s.components * s.byteLength;
        case Il:
            return h * t / s.components * s.byteLength;
        case lc:
            return h * t * 2 / s.components * s.byteLength;
        case cc:
            return h * t * 2 / s.components * s.byteLength;
        case oc:
            return h * t * 3 / s.components * s.byteLength;
        case Li:
            return h * t * 4 / s.components * s.byteLength;
        case uc:
            return h * t * 4 / s.components * s.byteLength;
        case dc:
        case pc:
            return Math.floor((h + 3) / 4) * Math.floor((t + 3) / 4) * 8;
        case fc:
        case mc:
            return Math.floor((h + 3) / 4) * Math.floor((t + 3) / 4) * 16;
        case gc:
        case bc:
            return Math.max(h, 16) * Math.max(t, 8) / 4;
        case yc:
        case xc:
            return Math.max(h, 8) * Math.max(t, 8) / 2;
        case wc:
        case Mc:
            return Math.floor((h + 3) / 4) * Math.floor((t + 3) / 4) * 8;
        case _c:
            return Math.floor((h + 3) / 4) * Math.floor((t + 3) / 4) * 16;
        case vc:
            return Math.floor((h + 3) / 4) * Math.floor((t + 3) / 4) * 16;
        case Ac:
            return Math.floor((h + 4) / 5) * Math.floor((t + 3) / 4) * 16;
        case Sc:
            return Math.floor((h + 4) / 5) * Math.floor((t + 4) / 5) * 16;
        case Tc:
            return Math.floor((h + 5) / 6) * Math.floor((t + 4) / 5) * 16;
        case Ic:
            return Math.floor((h + 5) / 6) * Math.floor((t + 5) / 6) * 16;
        case Cc:
            return Math.floor((h + 7) / 8) * Math.floor((t + 4) / 5) * 16;
        case zc:
            return Math.floor((h + 7) / 8) * Math.floor((t + 5) / 6) * 16;
        case Fc:
            return Math.floor((h + 7) / 8) * Math.floor((t + 7) / 8) * 16;
        case Bc:
            return Math.floor((h + 9) / 10) * Math.floor((t + 4) / 5) * 16;
        case Ec:
            return Math.floor((h + 9) / 10) * Math.floor((t + 5) / 6) * 16;
        case Rc:
            return Math.floor((h + 9) / 10) * Math.floor((t + 7) / 8) * 16;
        case kc:
            return Math.floor((h + 9) / 10) * Math.floor((t + 9) / 10) * 16;
        case Pc:
            return Math.floor((h + 11) / 12) * Math.floor((t + 9) / 10) * 16;
        case Oc:
            return Math.floor((h + 11) / 12) * Math.floor((t + 11) / 12) * 16;
        case Nc:
        case Vc:
        case Dc:
            return Math.ceil(h / 4) * Math.ceil(t / 4) * 16;
        case Lc:
        case Uc:
            return Math.ceil(h / 4) * Math.ceil(t / 4) * 8;
        case Wc:
        case Hc:
            return Math.ceil(h / 4) * Math.ceil(t / 4) * 16;
    }
    throw new Error(`Unable to determine texture byte length for ${e} format.`);
}
function Vd(h) {
    switch(h){
        case Sl:
        case $l:
            return {
                byteLength: 1,
                components: 1
            };
        case jl:
        case Ql:
        case tc:
            return {
                byteLength: 2,
                components: 1
            };
        case ec:
        case ic:
            return {
                byteLength: 2,
                components: 4
            };
        case Wo:
        case Kl:
        case pi:
            return {
                byteLength: 4,
                components: 1
            };
        case nc:
            return {
                byteLength: 4,
                components: 3
            };
    }
    throw new Error(`Unknown texture type ${h}.`);
}
var Of = {
    contain: kd,
    cover: Pd,
    fill: Od,
    getByteLength: Nd
};
typeof __THREE_DEVTOOLS__ < "u" && __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register", {
    detail: {
        revision: vl
    }
}));
typeof window < "u" && (window.__THREE__ ? console.warn("WARNING: Multiple instances of Three.js being imported.") : window.__THREE__ = vl);
function br1() {
    let e = null, n = !1, t = null, i = null;
    function c(s, h) {
        t(s, h), i = e.requestAnimationFrame(c);
    }
    return {
        start: function() {
            n !== !0 && t !== null && (i = e.requestAnimationFrame(c), n = !0);
        },
        stop: function() {
            e.cancelAnimationFrame(i), n = !1;
        },
        setAnimationLoop: function(s) {
            t = s;
        },
        setContext: function(s) {
            e = s;
        }
    };
}
function uo1(e) {
    let n = new WeakMap;
    function t(d, I) {
        let T = d.array, C = d.usage, R = T.byteLength, S = e.createBuffer();
        e.bindBuffer(I, S), e.bufferData(I, T, C), d.onUploadCallback();
        let x1;
        if (T instanceof Float32Array) x1 = e.FLOAT;
        else if (T instanceof Uint16Array) d.isFloat16BufferAttribute ? x1 = e.HALF_FLOAT : x1 = e.UNSIGNED_SHORT;
        else if (T instanceof Int16Array) x1 = e.SHORT;
        else if (T instanceof Uint32Array) x1 = e.UNSIGNED_INT;
        else if (T instanceof Int32Array) x1 = e.INT;
        else if (T instanceof Int8Array) x1 = e.BYTE;
        else if (T instanceof Uint8Array) x1 = e.UNSIGNED_BYTE;
        else if (T instanceof Uint8ClampedArray) x1 = e.UNSIGNED_BYTE;
        else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: " + T);
        return {
            buffer: S,
            type: x1,
            bytesPerElement: T.BYTES_PER_ELEMENT,
            version: d.version,
            size: R
        };
    }
    function i(d, I, T) {
        let C = I.array, R = I.updateRanges;
        if (e.bindBuffer(T, d), R.length === 0) e.bufferSubData(T, 0, C);
        else {
            R.sort((x1, O)=>x1.start - O.start);
            let S = 0;
            for(let x1 = 1; x1 < R.length; x1++){
                let O = R[S], L = R[x1];
                L.start <= O.start + O.count + 1 ? O.count = Math.max(O.count, L.start + L.count - O.start) : (++S, R[S] = L);
            }
            R.length = S + 1;
            for(let x1 = 0, O = R.length; x1 < O; x1++){
                let L = R[x1];
                e.bufferSubData(T, L.start * C.BYTES_PER_ELEMENT, C, L.start, L.count);
            }
            I.clearUpdateRanges();
        }
        I.onUploadCallback();
    }
    function c(d) {
        return d.isInterleavedBufferAttribute && (d = d.data), n.get(d);
    }
    function s(d) {
        d.isInterleavedBufferAttribute && (d = d.data);
        let I = n.get(d);
        I && (e.deleteBuffer(I.buffer), n.delete(d));
    }
    function h(d, I) {
        if (d.isInterleavedBufferAttribute && (d = d.data), d.isGLBufferAttribute) {
            let C = n.get(d);
            (!C || C.version < d.version) && n.set(d, {
                buffer: d.buffer,
                type: d.type,
                bytesPerElement: d.elementSize,
                version: d.version
            });
            return;
        }
        let T = n.get(d);
        if (T === void 0) n.set(d, t(d, I));
        else if (T.version < d.version) {
            if (T.size !== d.array.byteLength) throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");
            i(T.buffer, d, I), T.version = d.version;
        }
    }
    return {
        get: c,
        remove: s,
        update: h
    };
}
var po1 = `#ifdef USE_ALPHAHASH
	if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
#endif`, ho1 = `#ifdef USE_ALPHAHASH
	const float ALPHA_HASH_SCALE = 0.05;
	float hash2D( vec2 value ) {
		return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
	}
	float hash3D( vec3 value ) {
		return hash2D( vec2( hash2D( value.xy ), value.z ) );
	}
	float getAlphaHashThreshold( vec3 position ) {
		float maxDeriv = max(
			length( dFdx( position.xyz ) ),
			length( dFdy( position.xyz ) )
		);
		float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
		vec2 pixScales = vec2(
			exp2( floor( log2( pixScale ) ) ),
			exp2( ceil( log2( pixScale ) ) )
		);
		vec2 alpha = vec2(
			hash3D( floor( pixScales.x * position.xyz ) ),
			hash3D( floor( pixScales.y * position.xyz ) )
		);
		float lerpFactor = fract( log2( pixScale ) );
		float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;
		float a = min( lerpFactor, 1.0 - lerpFactor );
		vec3 cases = vec3(
			x * x / ( 2.0 * a * ( 1.0 - a ) ),
			( x - 0.5 * a ) / ( 1.0 - a ),
			1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
		);
		float threshold = ( x < ( 1.0 - a ) )
			? ( ( x < a ) ? cases.x : cases.y )
			: cases.z;
		return clamp( threshold , 1.0e-6, 1.0 );
	}
#endif`, mo1 = `#ifdef USE_ALPHAMAP
	diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
#endif`, _o1 = `#ifdef USE_ALPHAMAP
	uniform sampler2D alphaMap;
#endif`, vo1 = `#ifdef USE_ALPHATEST
	#ifdef ALPHA_TO_COVERAGE
	diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );
	if ( diffuseColor.a == 0.0 ) discard;
	#else
	if ( diffuseColor.a < alphaTest ) discard;
	#endif
#endif`, go1 = `#ifdef USE_ALPHATEST
	uniform float alphaTest;
#endif`, So1 = `#ifdef USE_AOMAP
	float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
	reflectedLight.indirectDiffuse *= ambientOcclusion;
	#if defined( USE_CLEARCOAT ) 
		clearcoatSpecularIndirect *= ambientOcclusion;
	#endif
	#if defined( USE_SHEEN ) 
		sheenSpecularIndirect *= ambientOcclusion;
	#endif
	#if defined( USE_ENVMAP ) && defined( STANDARD )
		float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
		reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
	#endif
#endif`, Eo1 = `#ifdef USE_AOMAP
	uniform sampler2D aoMap;
	uniform float aoMapIntensity;
#endif`, Mo1 = `#ifdef USE_BATCHING
	#if ! defined( GL_ANGLE_multi_draw )
	#define gl_DrawID _gl_DrawID
	uniform int _gl_DrawID;
	#endif
	uniform highp sampler2D batchingTexture;
	uniform highp usampler2D batchingIdTexture;
	mat4 getBatchingMatrix( const in float i ) {
		int size = textureSize( batchingTexture, 0 ).x;
		int j = int( i ) * 4;
		int x = j % size;
		int y = j / size;
		vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
		vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
		vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
		vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
		return mat4( v1, v2, v3, v4 );
	}
	float getIndirectIndex( const in int i ) {
		int size = textureSize( batchingIdTexture, 0 ).x;
		int x = i % size;
		int y = i / size;
		return float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );
	}
#endif
#ifdef USE_BATCHING_COLOR
	uniform sampler2D batchingColorTexture;
	vec3 getBatchingColor( const in float i ) {
		int size = textureSize( batchingColorTexture, 0 ).x;
		int j = int( i );
		int x = j % size;
		int y = j / size;
		return texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;
	}
#endif`, To1 = `#ifdef USE_BATCHING
	mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
#endif`, xo1 = `vec3 transformed = vec3( position );
#ifdef USE_ALPHAHASH
	vPosition = vec3( position );
#endif`, Ao1 = `vec3 objectNormal = vec3( normal );
#ifdef USE_TANGENT
	vec3 objectTangent = vec3( tangent.xyz );
#endif`, Ro1 = `float G_BlinnPhong_Implicit( ) {
	return 0.25;
}
float D_BlinnPhong( const in float shininess, const in float dotNH ) {
	return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
}
vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
	vec3 halfDir = normalize( lightDir + viewDir );
	float dotNH = saturate( dot( normal, halfDir ) );
	float dotVH = saturate( dot( viewDir, halfDir ) );
	vec3 F = F_Schlick( specularColor, 1.0, dotVH );
	float G = G_BlinnPhong_Implicit( );
	float D = D_BlinnPhong( shininess, dotNH );
	return F * ( G * D );
} // validated`, Co1 = `#ifdef USE_IRIDESCENCE
	const mat3 XYZ_TO_REC709 = mat3(
		 3.2404542, -0.9692660,  0.0556434,
		-1.5371385,  1.8760108, -0.2040259,
		-0.4985314,  0.0415560,  1.0572252
	);
	vec3 Fresnel0ToIor( vec3 fresnel0 ) {
		vec3 sqrtF0 = sqrt( fresnel0 );
		return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
	}
	vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {
		return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
	}
	float IorToFresnel0( float transmittedIor, float incidentIor ) {
		return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));
	}
	vec3 evalSensitivity( float OPD, vec3 shift ) {
		float phase = 2.0 * PI * OPD * 1.0e-9;
		vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
		vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
		vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
		vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );
		xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );
		xyz /= 1.0685e-7;
		vec3 rgb = XYZ_TO_REC709 * xyz;
		return rgb;
	}
	vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
		vec3 I;
		float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
		float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );
		float cosTheta2Sq = 1.0 - sinTheta2Sq;
		if ( cosTheta2Sq < 0.0 ) {
			return vec3( 1.0 );
		}
		float cosTheta2 = sqrt( cosTheta2Sq );
		float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
		float R12 = F_Schlick( R0, 1.0, cosTheta1 );
		float T121 = 1.0 - R12;
		float phi12 = 0.0;
		if ( iridescenceIOR < outsideIOR ) phi12 = PI;
		float phi21 = PI - phi12;
		vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) );		vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );
		vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );
		vec3 phi23 = vec3( 0.0 );
		if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;
		if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;
		if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;
		float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;
		vec3 phi = vec3( phi21 ) + phi23;
		vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
		vec3 r123 = sqrt( R123 );
		vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
		vec3 C0 = R12 + Rs;
		I = C0;
		vec3 Cm = Rs - T121;
		for ( int m = 1; m <= 2; ++ m ) {
			Cm *= r123;
			vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
			I += Cm * Sm;
		}
		return max( I, vec3( 0.0 ) );
	}
#endif`, bo1 = `#ifdef USE_BUMPMAP
	uniform sampler2D bumpMap;
	uniform float bumpScale;
	vec2 dHdxy_fwd() {
		vec2 dSTdx = dFdx( vBumpMapUv );
		vec2 dSTdy = dFdy( vBumpMapUv );
		float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;
		float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;
		float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;
		return vec2( dBx, dBy );
	}
	vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
		vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
		vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
		vec3 vN = surf_norm;
		vec3 R1 = cross( vSigmaY, vN );
		vec3 R2 = cross( vN, vSigmaX );
		float fDet = dot( vSigmaX, R1 ) * faceDirection;
		vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
		return normalize( abs( fDet ) * surf_norm - vGrad );
	}
#endif`, Po1 = `#if NUM_CLIPPING_PLANES > 0
	vec4 plane;
	#ifdef ALPHA_TO_COVERAGE
		float distanceToPlane, distanceGradient;
		float clipOpacity = 1.0;
		#pragma unroll_loop_start
		for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
			plane = clippingPlanes[ i ];
			distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
			distanceGradient = fwidth( distanceToPlane ) / 2.0;
			clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
			if ( clipOpacity == 0.0 ) discard;
		}
		#pragma unroll_loop_end
		#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
			float unionClipOpacity = 1.0;
			#pragma unroll_loop_start
			for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
				plane = clippingPlanes[ i ];
				distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
				distanceGradient = fwidth( distanceToPlane ) / 2.0;
				unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
			}
			#pragma unroll_loop_end
			clipOpacity *= 1.0 - unionClipOpacity;
		#endif
		diffuseColor.a *= clipOpacity;
		if ( diffuseColor.a == 0.0 ) discard;
	#else
		#pragma unroll_loop_start
		for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
			plane = clippingPlanes[ i ];
			if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
		}
		#pragma unroll_loop_end
		#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
			bool clipped = true;
			#pragma unroll_loop_start
			for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
				plane = clippingPlanes[ i ];
				clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
			}
			#pragma unroll_loop_end
			if ( clipped ) discard;
		#endif
	#endif
#endif`, Lo1 = `#if NUM_CLIPPING_PLANES > 0
	varying vec3 vClipPosition;
	uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
#endif`, Uo1 = `#if NUM_CLIPPING_PLANES > 0
	varying vec3 vClipPosition;
#endif`, Do1 = `#if NUM_CLIPPING_PLANES > 0
	vClipPosition = - mvPosition.xyz;
#endif`, wo1 = `#if defined( USE_COLOR_ALPHA )
	diffuseColor *= vColor;
#elif defined( USE_COLOR )
	diffuseColor.rgb *= vColor;
#endif`, Io1 = `#if defined( USE_COLOR_ALPHA )
	varying vec4 vColor;
#elif defined( USE_COLOR )
	varying vec3 vColor;
#endif`, yo1 = `#if defined( USE_COLOR_ALPHA )
	varying vec4 vColor;
#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
	varying vec3 vColor;
#endif`, No1 = `#if defined( USE_COLOR_ALPHA )
	vColor = vec4( 1.0 );
#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
	vColor = vec3( 1.0 );
#endif
#ifdef USE_COLOR
	vColor *= color;
#endif
#ifdef USE_INSTANCING_COLOR
	vColor.xyz *= instanceColor.xyz;
#endif
#ifdef USE_BATCHING_COLOR
	vec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );
	vColor.xyz *= batchingColor.xyz;
#endif`, Oo1 = `#define PI 3.141592653589793
#define PI2 6.283185307179586
#define PI_HALF 1.5707963267948966
#define RECIPROCAL_PI 0.3183098861837907
#define RECIPROCAL_PI2 0.15915494309189535
#define EPSILON 1e-6
#ifndef saturate
#define saturate( a ) clamp( a, 0.0, 1.0 )
#endif
#define whiteComplement( a ) ( 1.0 - saturate( a ) )
float pow2( const in float x ) { return x*x; }
vec3 pow2( const in vec3 x ) { return x*x; }
float pow3( const in float x ) { return x*x*x; }
float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
highp float rand( const in vec2 uv ) {
	const highp float a = 12.9898, b = 78.233, c = 43758.5453;
	highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
	return fract( sin( sn ) * c );
}
#ifdef HIGH_PRECISION
	float precisionSafeLength( vec3 v ) { return length( v ); }
#else
	float precisionSafeLength( vec3 v ) {
		float maxComponent = max3( abs( v ) );
		return length( v / maxComponent ) * maxComponent;
	}
#endif
struct IncidentLight {
	vec3 color;
	vec3 direction;
	bool visible;
};
struct ReflectedLight {
	vec3 directDiffuse;
	vec3 directSpecular;
	vec3 indirectDiffuse;
	vec3 indirectSpecular;
};
#ifdef USE_ALPHAHASH
	varying vec3 vPosition;
#endif
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
	return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
}
vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
	return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
}
mat3 transposeMat3( const in mat3 m ) {
	mat3 tmp;
	tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
	tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
	tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
	return tmp;
}
bool isPerspectiveMatrix( mat4 m ) {
	return m[ 2 ][ 3 ] == - 1.0;
}
vec2 equirectUv( in vec3 dir ) {
	float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
	float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
	return vec2( u, v );
}
vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
	return RECIPROCAL_PI * diffuseColor;
}
vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
	float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
	return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
}
float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
	float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
	return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
} // validated`, Fo1 = `#ifdef ENVMAP_TYPE_CUBE_UV
	#define cubeUV_minMipLevel 4.0
	#define cubeUV_minTileSize 16.0
	float getFace( vec3 direction ) {
		vec3 absDirection = abs( direction );
		float face = - 1.0;
		if ( absDirection.x > absDirection.z ) {
			if ( absDirection.x > absDirection.y )
				face = direction.x > 0.0 ? 0.0 : 3.0;
			else
				face = direction.y > 0.0 ? 1.0 : 4.0;
		} else {
			if ( absDirection.z > absDirection.y )
				face = direction.z > 0.0 ? 2.0 : 5.0;
			else
				face = direction.y > 0.0 ? 1.0 : 4.0;
		}
		return face;
	}
	vec2 getUV( vec3 direction, float face ) {
		vec2 uv;
		if ( face == 0.0 ) {
			uv = vec2( direction.z, direction.y ) / abs( direction.x );
		} else if ( face == 1.0 ) {
			uv = vec2( - direction.x, - direction.z ) / abs( direction.y );
		} else if ( face == 2.0 ) {
			uv = vec2( - direction.x, direction.y ) / abs( direction.z );
		} else if ( face == 3.0 ) {
			uv = vec2( - direction.z, direction.y ) / abs( direction.x );
		} else if ( face == 4.0 ) {
			uv = vec2( - direction.x, direction.z ) / abs( direction.y );
		} else {
			uv = vec2( direction.x, direction.y ) / abs( direction.z );
		}
		return 0.5 * ( uv + 1.0 );
	}
	vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {
		float face = getFace( direction );
		float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );
		mipInt = max( mipInt, cubeUV_minMipLevel );
		float faceSize = exp2( mipInt );
		highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;
		if ( face > 2.0 ) {
			uv.y += faceSize;
			face -= 3.0;
		}
		uv.x += face * faceSize;
		uv.x += filterInt * 3.0 * cubeUV_minTileSize;
		uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );
		uv.x *= CUBEUV_TEXEL_WIDTH;
		uv.y *= CUBEUV_TEXEL_HEIGHT;
		#ifdef texture2DGradEXT
			return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;
		#else
			return texture2D( envMap, uv ).rgb;
		#endif
	}
	#define cubeUV_r0 1.0
	#define cubeUV_m0 - 2.0
	#define cubeUV_r1 0.8
	#define cubeUV_m1 - 1.0
	#define cubeUV_r4 0.4
	#define cubeUV_m4 2.0
	#define cubeUV_r5 0.305
	#define cubeUV_m5 3.0
	#define cubeUV_r6 0.21
	#define cubeUV_m6 4.0
	float roughnessToMip( float roughness ) {
		float mip = 0.0;
		if ( roughness >= cubeUV_r1 ) {
			mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;
		} else if ( roughness >= cubeUV_r4 ) {
			mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;
		} else if ( roughness >= cubeUV_r5 ) {
			mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;
		} else if ( roughness >= cubeUV_r6 ) {
			mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;
		} else {
			mip = - 2.0 * log2( 1.16 * roughness );		}
		return mip;
	}
	vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {
		float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );
		float mipF = fract( mip );
		float mipInt = floor( mip );
		vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );
		if ( mipF == 0.0 ) {
			return vec4( color0, 1.0 );
		} else {
			vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );
			return vec4( mix( color0, color1, mipF ), 1.0 );
		}
	}
#endif`, Bo1 = `vec3 transformedNormal = objectNormal;
#ifdef USE_TANGENT
	vec3 transformedTangent = objectTangent;
#endif
#ifdef USE_BATCHING
	mat3 bm = mat3( batchingMatrix );
	transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );
	transformedNormal = bm * transformedNormal;
	#ifdef USE_TANGENT
		transformedTangent = bm * transformedTangent;
	#endif
#endif
#ifdef USE_INSTANCING
	mat3 im = mat3( instanceMatrix );
	transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );
	transformedNormal = im * transformedNormal;
	#ifdef USE_TANGENT
		transformedTangent = im * transformedTangent;
	#endif
#endif
transformedNormal = normalMatrix * transformedNormal;
#ifdef FLIP_SIDED
	transformedNormal = - transformedNormal;
#endif
#ifdef USE_TANGENT
	transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;
	#ifdef FLIP_SIDED
		transformedTangent = - transformedTangent;
	#endif
#endif`, Go1 = `#ifdef USE_DISPLACEMENTMAP
	uniform sampler2D displacementMap;
	uniform float displacementScale;
	uniform float displacementBias;
#endif`, Ho1 = `#ifdef USE_DISPLACEMENTMAP
	transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
#endif`, Vo1 = `#ifdef USE_EMISSIVEMAP
	vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
	#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
		emissiveColor = sRGBTransferEOTF( emissiveColor );
	#endif
	totalEmissiveRadiance *= emissiveColor.rgb;
#endif`, ko1 = `#ifdef USE_EMISSIVEMAP
	uniform sampler2D emissiveMap;
#endif`, zo1 = "gl_FragColor = linearToOutputTexel( gl_FragColor );", Wo1 = `vec4 LinearTransferOETF( in vec4 value ) {
	return value;
}
vec4 sRGBTransferEOTF( in vec4 value ) {
	return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
}
vec4 sRGBTransferOETF( in vec4 value ) {
	return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );
}`, Xo1 = `#ifdef USE_ENVMAP
	#ifdef ENV_WORLDPOS
		vec3 cameraToFrag;
		if ( isOrthographic ) {
			cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
		} else {
			cameraToFrag = normalize( vWorldPosition - cameraPosition );
		}
		vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
		#ifdef ENVMAP_MODE_REFLECTION
			vec3 reflectVec = reflect( cameraToFrag, worldNormal );
		#else
			vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
		#endif
	#else
		vec3 reflectVec = vReflect;
	#endif
	#ifdef ENVMAP_TYPE_CUBE
		vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
	#else
		vec4 envColor = vec4( 0.0 );
	#endif
	#ifdef ENVMAP_BLENDING_MULTIPLY
		outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
	#elif defined( ENVMAP_BLENDING_MIX )
		outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
	#elif defined( ENVMAP_BLENDING_ADD )
		outgoingLight += envColor.xyz * specularStrength * reflectivity;
	#endif
#endif`, Yo = `#ifdef USE_ENVMAP
	uniform float envMapIntensity;
	uniform float flipEnvMap;
	uniform mat3 envMapRotation;
	#ifdef ENVMAP_TYPE_CUBE
		uniform samplerCube envMap;
	#else
		uniform sampler2D envMap;
	#endif
	
#endif`, qo1 = `#ifdef USE_ENVMAP
	uniform float reflectivity;
	#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
		#define ENV_WORLDPOS
	#endif
	#ifdef ENV_WORLDPOS
		varying vec3 vWorldPosition;
		uniform float refractionRatio;
	#else
		varying vec3 vReflect;
	#endif
#endif`, Ko = `#ifdef USE_ENVMAP
	#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
		#define ENV_WORLDPOS
	#endif
	#ifdef ENV_WORLDPOS
		
		varying vec3 vWorldPosition;
	#else
		varying vec3 vReflect;
		uniform float refractionRatio;
	#endif
#endif`, $o = `#ifdef USE_ENVMAP
	#ifdef ENV_WORLDPOS
		vWorldPosition = worldPosition.xyz;
	#else
		vec3 cameraToVertex;
		if ( isOrthographic ) {
			cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
		} else {
			cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
		}
		vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
		#ifdef ENVMAP_MODE_REFLECTION
			vReflect = reflect( cameraToVertex, worldNormal );
		#else
			vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
		#endif
	#endif
#endif`, Zo1 = `#ifdef USE_FOG
	vFogDepth = - mvPosition.z;
#endif`, Qo = `#ifdef USE_FOG
	varying float vFogDepth;
#endif`, Jo1 = `#ifdef USE_FOG
	#ifdef FOG_EXP2
		float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
	#else
		float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
	#endif
	gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
#endif`, jo = `#ifdef USE_FOG
	uniform vec3 fogColor;
	varying float vFogDepth;
	#ifdef FOG_EXP2
		uniform float fogDensity;
	#else
		uniform float fogNear;
		uniform float fogFar;
	#endif
#endif`, es = `#ifdef USE_GRADIENTMAP
	uniform sampler2D gradientMap;
#endif
vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
	float dotNL = dot( normal, lightDirection );
	vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
	#ifdef USE_GRADIENTMAP
		return vec3( texture2D( gradientMap, coord ).r );
	#else
		vec2 fw = fwidth( coord ) * 0.5;
		return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
	#endif
}`, ts1 = `#ifdef USE_LIGHTMAP
	uniform sampler2D lightMap;
	uniform float lightMapIntensity;
#endif`, ns1 = `LambertMaterial material;
material.diffuseColor = diffuseColor.rgb;
material.specularStrength = specularStrength;`, is = `varying vec3 vViewPosition;
struct LambertMaterial {
	vec3 diffuseColor;
	float specularStrength;
};
void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
	float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
	vec3 irradiance = dotNL * directLight.color;
	reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
	reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
#define RE_Direct				RE_Direct_Lambert
#define RE_IndirectDiffuse		RE_IndirectDiffuse_Lambert`, rs1 = `uniform bool receiveShadow;
uniform vec3 ambientLightColor;
#if defined( USE_LIGHT_PROBES )
	uniform vec3 lightProbe[ 9 ];
#endif
vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
	float x = normal.x, y = normal.y, z = normal.z;
	vec3 result = shCoefficients[ 0 ] * 0.886227;
	result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
	result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
	result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
	result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
	result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
	result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
	result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
	result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
	return result;
}
vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
	vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
	vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
	return irradiance;
}
vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
	vec3 irradiance = ambientLightColor;
	return irradiance;
}
float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
	float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
	if ( cutoffDistance > 0.0 ) {
		distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
	}
	return distanceFalloff;
}
float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
	return smoothstep( coneCosine, penumbraCosine, angleCosine );
}
#if NUM_DIR_LIGHTS > 0
	struct DirectionalLight {
		vec3 direction;
		vec3 color;
	};
	uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
	void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {
		light.color = directionalLight.color;
		light.direction = directionalLight.direction;
		light.visible = true;
	}
#endif
#if NUM_POINT_LIGHTS > 0
	struct PointLight {
		vec3 position;
		vec3 color;
		float distance;
		float decay;
	};
	uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
	void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {
		vec3 lVector = pointLight.position - geometryPosition;
		light.direction = normalize( lVector );
		float lightDistance = length( lVector );
		light.color = pointLight.color;
		light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
		light.visible = ( light.color != vec3( 0.0 ) );
	}
#endif
#if NUM_SPOT_LIGHTS > 0
	struct SpotLight {
		vec3 position;
		vec3 direction;
		vec3 color;
		float distance;
		float decay;
		float coneCos;
		float penumbraCos;
	};
	uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
	void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {
		vec3 lVector = spotLight.position - geometryPosition;
		light.direction = normalize( lVector );
		float angleCos = dot( light.direction, spotLight.direction );
		float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
		if ( spotAttenuation > 0.0 ) {
			float lightDistance = length( lVector );
			light.color = spotLight.color * spotAttenuation;
			light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
			light.visible = ( light.color != vec3( 0.0 ) );
		} else {
			light.color = vec3( 0.0 );
			light.visible = false;
		}
	}
#endif
#if NUM_RECT_AREA_LIGHTS > 0
	struct RectAreaLight {
		vec3 color;
		vec3 position;
		vec3 halfWidth;
		vec3 halfHeight;
	};
	uniform sampler2D ltc_1;	uniform sampler2D ltc_2;
	uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
#endif
#if NUM_HEMI_LIGHTS > 0
	struct HemisphereLight {
		vec3 direction;
		vec3 skyColor;
		vec3 groundColor;
	};
	uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
	vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {
		float dotNL = dot( normal, hemiLight.direction );
		float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
		vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
		return irradiance;
	}
#endif`, as1 = `#ifdef USE_ENVMAP
	vec3 getIBLIrradiance( const in vec3 normal ) {
		#ifdef ENVMAP_TYPE_CUBE_UV
			vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
			vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );
			return PI * envMapColor.rgb * envMapIntensity;
		#else
			return vec3( 0.0 );
		#endif
	}
	vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
		#ifdef ENVMAP_TYPE_CUBE_UV
			vec3 reflectVec = reflect( - viewDir, normal );
			reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
			reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
			vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );
			return envMapColor.rgb * envMapIntensity;
		#else
			return vec3( 0.0 );
		#endif
	}
	#ifdef USE_ANISOTROPY
		vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
			#ifdef ENVMAP_TYPE_CUBE_UV
				vec3 bentNormal = cross( bitangent, viewDir );
				bentNormal = normalize( cross( bentNormal, bitangent ) );
				bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
				return getIBLRadiance( viewDir, bentNormal, roughness );
			#else
				return vec3( 0.0 );
			#endif
		}
	#endif
#endif`, os1 = `ToonMaterial material;
material.diffuseColor = diffuseColor.rgb;`, ss1 = `varying vec3 vViewPosition;
struct ToonMaterial {
	vec3 diffuseColor;
};
void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
	vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;
	reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
	reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
#define RE_Direct				RE_Direct_Toon
#define RE_IndirectDiffuse		RE_IndirectDiffuse_Toon`, cs1 = `BlinnPhongMaterial material;
material.diffuseColor = diffuseColor.rgb;
material.specularColor = specular;
material.specularShininess = shininess;
material.specularStrength = specularStrength;`, ls1 = `varying vec3 vViewPosition;
struct BlinnPhongMaterial {
	vec3 diffuseColor;
	vec3 specularColor;
	float specularShininess;
	float specularStrength;
};
void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
	float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
	vec3 irradiance = dotNL * directLight.color;
	reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
	reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;
}
void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
	reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
#define RE_Direct				RE_Direct_BlinnPhong
#define RE_IndirectDiffuse		RE_IndirectDiffuse_BlinnPhong`, fs1 = `PhysicalMaterial material;
material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;
material.roughness = min( material.roughness, 1.0 );
#ifdef IOR
	material.ior = ior;
	#ifdef USE_SPECULAR
		float specularIntensityFactor = specularIntensity;
		vec3 specularColorFactor = specularColor;
		#ifdef USE_SPECULAR_COLORMAP
			specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;
		#endif
		#ifdef USE_SPECULAR_INTENSITYMAP
			specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;
		#endif
		material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
	#else
		float specularIntensityFactor = 1.0;
		vec3 specularColorFactor = vec3( 1.0 );
		material.specularF90 = 1.0;
	#endif
	material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );
#else
	material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
	material.specularF90 = 1.0;
#endif
#ifdef USE_CLEARCOAT
	material.clearcoat = clearcoat;
	material.clearcoatRoughness = clearcoatRoughness;
	material.clearcoatF0 = vec3( 0.04 );
	material.clearcoatF90 = 1.0;
	#ifdef USE_CLEARCOATMAP
		material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;
	#endif
	#ifdef USE_CLEARCOAT_ROUGHNESSMAP
		material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;
	#endif
	material.clearcoat = saturate( material.clearcoat );	material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
	material.clearcoatRoughness += geometryRoughness;
	material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
#endif
#ifdef USE_DISPERSION
	material.dispersion = dispersion;
#endif
#ifdef USE_IRIDESCENCE
	material.iridescence = iridescence;
	material.iridescenceIOR = iridescenceIOR;
	#ifdef USE_IRIDESCENCEMAP
		material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;
	#endif
	#ifdef USE_IRIDESCENCE_THICKNESSMAP
		material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;
	#else
		material.iridescenceThickness = iridescenceThicknessMaximum;
	#endif
#endif
#ifdef USE_SHEEN
	material.sheenColor = sheenColor;
	#ifdef USE_SHEEN_COLORMAP
		material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;
	#endif
	material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );
	#ifdef USE_SHEEN_ROUGHNESSMAP
		material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;
	#endif
#endif
#ifdef USE_ANISOTROPY
	#ifdef USE_ANISOTROPYMAP
		mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );
		vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;
		vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;
	#else
		vec2 anisotropyV = anisotropyVector;
	#endif
	material.anisotropy = length( anisotropyV );
	if( material.anisotropy == 0.0 ) {
		anisotropyV = vec2( 1.0, 0.0 );
	} else {
		anisotropyV /= material.anisotropy;
		material.anisotropy = saturate( material.anisotropy );
	}
	material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
	material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
	material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
#endif`, ds1 = `struct PhysicalMaterial {
	vec3 diffuseColor;
	float roughness;
	vec3 specularColor;
	float specularF90;
	float dispersion;
	#ifdef USE_CLEARCOAT
		float clearcoat;
		float clearcoatRoughness;
		vec3 clearcoatF0;
		float clearcoatF90;
	#endif
	#ifdef USE_IRIDESCENCE
		float iridescence;
		float iridescenceIOR;
		float iridescenceThickness;
		vec3 iridescenceFresnel;
		vec3 iridescenceF0;
	#endif
	#ifdef USE_SHEEN
		vec3 sheenColor;
		float sheenRoughness;
	#endif
	#ifdef IOR
		float ior;
	#endif
	#ifdef USE_TRANSMISSION
		float transmission;
		float transmissionAlpha;
		float thickness;
		float attenuationDistance;
		vec3 attenuationColor;
	#endif
	#ifdef USE_ANISOTROPY
		float anisotropy;
		float alphaT;
		vec3 anisotropyT;
		vec3 anisotropyB;
	#endif
};
vec3 clearcoatSpecularDirect = vec3( 0.0 );
vec3 clearcoatSpecularIndirect = vec3( 0.0 );
vec3 sheenSpecularDirect = vec3( 0.0 );
vec3 sheenSpecularIndirect = vec3(0.0 );
vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {
    float x = clamp( 1.0 - dotVH, 0.0, 1.0 );
    float x2 = x * x;
    float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );
    return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
}
float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
	float a2 = pow2( alpha );
	float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
	float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
	return 0.5 / max( gv + gl, EPSILON );
}
float D_GGX( const in float alpha, const in float dotNH ) {
	float a2 = pow2( alpha );
	float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
	return RECIPROCAL_PI * a2 / pow2( denom );
}
#ifdef USE_ANISOTROPY
	float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {
		float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );
		float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
		float v = 0.5 / ( gv + gl );
		return saturate(v);
	}
	float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {
		float a2 = alphaT * alphaB;
		highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );
		highp float v2 = dot( v, v );
		float w2 = a2 / v2;
		return RECIPROCAL_PI * a2 * pow2 ( w2 );
	}
#endif
#ifdef USE_CLEARCOAT
	vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {
		vec3 f0 = material.clearcoatF0;
		float f90 = material.clearcoatF90;
		float roughness = material.clearcoatRoughness;
		float alpha = pow2( roughness );
		vec3 halfDir = normalize( lightDir + viewDir );
		float dotNL = saturate( dot( normal, lightDir ) );
		float dotNV = saturate( dot( normal, viewDir ) );
		float dotNH = saturate( dot( normal, halfDir ) );
		float dotVH = saturate( dot( viewDir, halfDir ) );
		vec3 F = F_Schlick( f0, f90, dotVH );
		float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
		float D = D_GGX( alpha, dotNH );
		return F * ( V * D );
	}
#endif
vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
	vec3 f0 = material.specularColor;
	float f90 = material.specularF90;
	float roughness = material.roughness;
	float alpha = pow2( roughness );
	vec3 halfDir = normalize( lightDir + viewDir );
	float dotNL = saturate( dot( normal, lightDir ) );
	float dotNV = saturate( dot( normal, viewDir ) );
	float dotNH = saturate( dot( normal, halfDir ) );
	float dotVH = saturate( dot( viewDir, halfDir ) );
	vec3 F = F_Schlick( f0, f90, dotVH );
	#ifdef USE_IRIDESCENCE
		F = mix( F, material.iridescenceFresnel, material.iridescence );
	#endif
	#ifdef USE_ANISOTROPY
		float dotTL = dot( material.anisotropyT, lightDir );
		float dotTV = dot( material.anisotropyT, viewDir );
		float dotTH = dot( material.anisotropyT, halfDir );
		float dotBL = dot( material.anisotropyB, lightDir );
		float dotBV = dot( material.anisotropyB, viewDir );
		float dotBH = dot( material.anisotropyB, halfDir );
		float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
		float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );
	#else
		float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
		float D = D_GGX( alpha, dotNH );
	#endif
	return F * ( V * D );
}
vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
	const float LUT_SIZE = 64.0;
	const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
	const float LUT_BIAS = 0.5 / LUT_SIZE;
	float dotNV = saturate( dot( N, V ) );
	vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
	uv = uv * LUT_SCALE + LUT_BIAS;
	return uv;
}
float LTC_ClippedSphereFormFactor( const in vec3 f ) {
	float l = length( f );
	return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
}
vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
	float x = dot( v1, v2 );
	float y = abs( x );
	float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
	float b = 3.4175940 + ( 4.1616724 + y ) * y;
	float v = a / b;
	float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
	return cross( v1, v2 ) * theta_sintheta;
}
vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
	vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
	vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
	vec3 lightNormal = cross( v1, v2 );
	if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
	vec3 T1, T2;
	T1 = normalize( V - N * dot( V, N ) );
	T2 = - cross( N, T1 );
	mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );
	vec3 coords[ 4 ];
	coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
	coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
	coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
	coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
	coords[ 0 ] = normalize( coords[ 0 ] );
	coords[ 1 ] = normalize( coords[ 1 ] );
	coords[ 2 ] = normalize( coords[ 2 ] );
	coords[ 3 ] = normalize( coords[ 3 ] );
	vec3 vectorFormFactor = vec3( 0.0 );
	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
	float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
	return vec3( result );
}
#if defined( USE_SHEEN )
float D_Charlie( float roughness, float dotNH ) {
	float alpha = pow2( roughness );
	float invAlpha = 1.0 / alpha;
	float cos2h = dotNH * dotNH;
	float sin2h = max( 1.0 - cos2h, 0.0078125 );
	return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
}
float V_Neubelt( float dotNV, float dotNL ) {
	return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
}
vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
	vec3 halfDir = normalize( lightDir + viewDir );
	float dotNL = saturate( dot( normal, lightDir ) );
	float dotNV = saturate( dot( normal, viewDir ) );
	float dotNH = saturate( dot( normal, halfDir ) );
	float D = D_Charlie( sheenRoughness, dotNH );
	float V = V_Neubelt( dotNV, dotNL );
	return sheenColor * ( D * V );
}
#endif
float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
	float dotNV = saturate( dot( normal, viewDir ) );
	float r2 = roughness * roughness;
	float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;
	float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;
	float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );
	return saturate( DG * RECIPROCAL_PI );
}
vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
	float dotNV = saturate( dot( normal, viewDir ) );
	const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
	const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
	vec4 r = roughness * c0 + c1;
	float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
	vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;
	return fab;
}
vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
	vec2 fab = DFGApprox( normal, viewDir, roughness );
	return specularColor * fab.x + specularF90 * fab.y;
}
#ifdef USE_IRIDESCENCE
void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
#else
void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
#endif
	vec2 fab = DFGApprox( normal, viewDir, roughness );
	#ifdef USE_IRIDESCENCE
		vec3 Fr = mix( specularColor, iridescenceF0, iridescence );
	#else
		vec3 Fr = specularColor;
	#endif
	vec3 FssEss = Fr * fab.x + specularF90 * fab.y;
	float Ess = fab.x + fab.y;
	float Ems = 1.0 - Ess;
	vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;	vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
	singleScatter += FssEss;
	multiScatter += Fms * Ems;
}
#if NUM_RECT_AREA_LIGHTS > 0
	void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
		vec3 normal = geometryNormal;
		vec3 viewDir = geometryViewDir;
		vec3 position = geometryPosition;
		vec3 lightPos = rectAreaLight.position;
		vec3 halfWidth = rectAreaLight.halfWidth;
		vec3 halfHeight = rectAreaLight.halfHeight;
		vec3 lightColor = rectAreaLight.color;
		float roughness = material.roughness;
		vec3 rectCoords[ 4 ];
		rectCoords[ 0 ] = lightPos + halfWidth - halfHeight;		rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
		rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
		rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
		vec2 uv = LTC_Uv( normal, viewDir, roughness );
		vec4 t1 = texture2D( ltc_1, uv );
		vec4 t2 = texture2D( ltc_2, uv );
		mat3 mInv = mat3(
			vec3( t1.x, 0, t1.y ),
			vec3(    0, 1,    0 ),
			vec3( t1.z, 0, t1.w )
		);
		vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );
		reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
		reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
	}
#endif
void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
	float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
	vec3 irradiance = dotNL * directLight.color;
	#ifdef USE_CLEARCOAT
		float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );
		vec3 ccIrradiance = dotNLcc * directLight.color;
		clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );
	#endif
	#ifdef USE_SHEEN
		sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );
	#endif
	reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );
	reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
	reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
}
void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
	#ifdef USE_CLEARCOAT
		clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
	#endif
	#ifdef USE_SHEEN
		sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
	#endif
	vec3 singleScattering = vec3( 0.0 );
	vec3 multiScattering = vec3( 0.0 );
	vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
	#ifdef USE_IRIDESCENCE
		computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );
	#else
		computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );
	#endif
	vec3 totalScattering = singleScattering + multiScattering;
	vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
	reflectedLight.indirectSpecular += radiance * singleScattering;
	reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;
	reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;
}
#define RE_Direct				RE_Direct_Physical
#define RE_Direct_RectArea		RE_Direct_RectArea_Physical
#define RE_IndirectDiffuse		RE_IndirectDiffuse_Physical
#define RE_IndirectSpecular		RE_IndirectSpecular_Physical
float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
	return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
}`, us1 = `
vec3 geometryPosition = - vViewPosition;
vec3 geometryNormal = normal;
vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
vec3 geometryClearcoatNormal = vec3( 0.0 );
#ifdef USE_CLEARCOAT
	geometryClearcoatNormal = clearcoatNormal;
#endif
#ifdef USE_IRIDESCENCE
	float dotNVi = saturate( dot( normal, geometryViewDir ) );
	if ( material.iridescenceThickness == 0.0 ) {
		material.iridescence = 0.0;
	} else {
		material.iridescence = saturate( material.iridescence );
	}
	if ( material.iridescence > 0.0 ) {
		material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
		material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );
	}
#endif
IncidentLight directLight;
#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
	PointLight pointLight;
	#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
	PointLightShadow pointLightShadow;
	#endif
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
		pointLight = pointLights[ i ];
		getPointLightInfo( pointLight, geometryPosition, directLight );
		#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
		pointLightShadow = pointLightShadows[ i ];
		directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
		#endif
		RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
	}
	#pragma unroll_loop_end
#endif
#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
	SpotLight spotLight;
	vec4 spotColor;
	vec3 spotLightCoord;
	bool inSpotLightMap;
	#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
	SpotLightShadow spotLightShadow;
	#endif
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
		spotLight = spotLights[ i ];
		getSpotLightInfo( spotLight, geometryPosition, directLight );
		#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
		#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX
		#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
		#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS
		#else
		#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
		#endif
		#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )
			spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;
			inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );
			spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );
			directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;
		#endif
		#undef SPOT_LIGHT_MAP_INDEX
		#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
		spotLightShadow = spotLightShadows[ i ];
		directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
		#endif
		RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
	}
	#pragma unroll_loop_end
#endif
#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
	DirectionalLight directionalLight;
	#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
	DirectionalLightShadow directionalLightShadow;
	#endif
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
		directionalLight = directionalLights[ i ];
		getDirectionalLightInfo( directionalLight, directLight );
		#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
		directionalLightShadow = directionalLightShadows[ i ];
		directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
		#endif
		RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
	}
	#pragma unroll_loop_end
#endif
#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
	RectAreaLight rectAreaLight;
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
		rectAreaLight = rectAreaLights[ i ];
		RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
	}
	#pragma unroll_loop_end
#endif
#if defined( RE_IndirectDiffuse )
	vec3 iblIrradiance = vec3( 0.0 );
	vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
	#if defined( USE_LIGHT_PROBES )
		irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
	#endif
	#if ( NUM_HEMI_LIGHTS > 0 )
		#pragma unroll_loop_start
		for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
			irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
		}
		#pragma unroll_loop_end
	#endif
#endif
#if defined( RE_IndirectSpecular )
	vec3 radiance = vec3( 0.0 );
	vec3 clearcoatRadiance = vec3( 0.0 );
#endif`, ps1 = `#if defined( RE_IndirectDiffuse )
	#ifdef USE_LIGHTMAP
		vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
		vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
		irradiance += lightMapIrradiance;
	#endif
	#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
		iblIrradiance += getIBLIrradiance( geometryNormal );
	#endif
#endif
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
	#ifdef USE_ANISOTROPY
		radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
	#else
		radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
	#endif
	#ifdef USE_CLEARCOAT
		clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
	#endif
#endif`, hs1 = `#if defined( RE_IndirectDiffuse )
	RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
#endif
#if defined( RE_IndirectSpecular )
	RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
#endif`, ms1 = `#if defined( USE_LOGDEPTHBUF )
	gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
#endif`, _s1 = `#if defined( USE_LOGDEPTHBUF )
	uniform float logDepthBufFC;
	varying float vFragDepth;
	varying float vIsPerspective;
#endif`, vs1 = `#ifdef USE_LOGDEPTHBUF
	varying float vFragDepth;
	varying float vIsPerspective;
#endif`, gs1 = `#ifdef USE_LOGDEPTHBUF
	vFragDepth = 1.0 + gl_Position.w;
	vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
#endif`, Ss1 = `#ifdef USE_MAP
	vec4 sampledDiffuseColor = texture2D( map, vMapUv );
	#ifdef DECODE_VIDEO_TEXTURE
		sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
	#endif
	diffuseColor *= sampledDiffuseColor;
#endif`, Es1 = `#ifdef USE_MAP
	uniform sampler2D map;
#endif`, Ms1 = `#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
	#if defined( USE_POINTS_UV )
		vec2 uv = vUv;
	#else
		vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
	#endif
#endif
#ifdef USE_MAP
	diffuseColor *= texture2D( map, uv );
#endif
#ifdef USE_ALPHAMAP
	diffuseColor.a *= texture2D( alphaMap, uv ).g;
#endif`, Ts1 = `#if defined( USE_POINTS_UV )
	varying vec2 vUv;
#else
	#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
		uniform mat3 uvTransform;
	#endif
#endif
#ifdef USE_MAP
	uniform sampler2D map;
#endif
#ifdef USE_ALPHAMAP
	uniform sampler2D alphaMap;
#endif`, xs1 = `float metalnessFactor = metalness;
#ifdef USE_METALNESSMAP
	vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
	metalnessFactor *= texelMetalness.b;
#endif`, As1 = `#ifdef USE_METALNESSMAP
	uniform sampler2D metalnessMap;
#endif`, Rs1 = `#ifdef USE_INSTANCING_MORPH
	float morphTargetInfluences[ MORPHTARGETS_COUNT ];
	float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;
	for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
		morphTargetInfluences[i] =  texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;
	}
#endif`, Cs1 = `#if defined( USE_MORPHCOLORS )
	vColor *= morphTargetBaseInfluence;
	for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
		#if defined( USE_COLOR_ALPHA )
			if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
		#elif defined( USE_COLOR )
			if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
		#endif
	}
#endif`, bs1 = `#ifdef USE_MORPHNORMALS
	objectNormal *= morphTargetBaseInfluence;
	for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
		if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
	}
#endif`, Ps1 = `#ifdef USE_MORPHTARGETS
	#ifndef USE_INSTANCING_MORPH
		uniform float morphTargetBaseInfluence;
		uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
	#endif
	uniform sampler2DArray morphTargetsTexture;
	uniform ivec2 morphTargetsTextureSize;
	vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {
		int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;
		int y = texelIndex / morphTargetsTextureSize.x;
		int x = texelIndex - y * morphTargetsTextureSize.x;
		ivec3 morphUV = ivec3( x, y, morphTargetIndex );
		return texelFetch( morphTargetsTexture, morphUV, 0 );
	}
#endif`, Ls1 = `#ifdef USE_MORPHTARGETS
	transformed *= morphTargetBaseInfluence;
	for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
		if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
	}
#endif`, Us1 = `float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
#ifdef FLAT_SHADED
	vec3 fdx = dFdx( vViewPosition );
	vec3 fdy = dFdy( vViewPosition );
	vec3 normal = normalize( cross( fdx, fdy ) );
#else
	vec3 normal = normalize( vNormal );
	#ifdef DOUBLE_SIDED
		normal *= faceDirection;
	#endif
#endif
#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )
	#ifdef USE_TANGENT
		mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
	#else
		mat3 tbn = getTangentFrame( - vViewPosition, normal,
		#if defined( USE_NORMALMAP )
			vNormalMapUv
		#elif defined( USE_CLEARCOAT_NORMALMAP )
			vClearcoatNormalMapUv
		#else
			vUv
		#endif
		);
	#endif
	#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
		tbn[0] *= faceDirection;
		tbn[1] *= faceDirection;
	#endif
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	#ifdef USE_TANGENT
		mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
	#else
		mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
	#endif
	#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
		tbn2[0] *= faceDirection;
		tbn2[1] *= faceDirection;
	#endif
#endif
vec3 nonPerturbedNormal = normal;`, Ds1 = `#ifdef USE_NORMALMAP_OBJECTSPACE
	normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
	#ifdef FLIP_SIDED
		normal = - normal;
	#endif
	#ifdef DOUBLE_SIDED
		normal = normal * faceDirection;
	#endif
	normal = normalize( normalMatrix * normal );
#elif defined( USE_NORMALMAP_TANGENTSPACE )
	vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
	mapN.xy *= normalScale;
	normal = normalize( tbn * mapN );
#elif defined( USE_BUMPMAP )
	normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
#endif`, ws1 = `#ifndef FLAT_SHADED
	varying vec3 vNormal;
	#ifdef USE_TANGENT
		varying vec3 vTangent;
		varying vec3 vBitangent;
	#endif
#endif`, Is1 = `#ifndef FLAT_SHADED
	varying vec3 vNormal;
	#ifdef USE_TANGENT
		varying vec3 vTangent;
		varying vec3 vBitangent;
	#endif
#endif`, ys1 = `#ifndef FLAT_SHADED
	vNormal = normalize( transformedNormal );
	#ifdef USE_TANGENT
		vTangent = normalize( transformedTangent );
		vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
	#endif
#endif`, Ns1 = `#ifdef USE_NORMALMAP
	uniform sampler2D normalMap;
	uniform vec2 normalScale;
#endif
#ifdef USE_NORMALMAP_OBJECTSPACE
	uniform mat3 normalMatrix;
#endif
#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )
	mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {
		vec3 q0 = dFdx( eye_pos.xyz );
		vec3 q1 = dFdy( eye_pos.xyz );
		vec2 st0 = dFdx( uv.st );
		vec2 st1 = dFdy( uv.st );
		vec3 N = surf_norm;
		vec3 q1perp = cross( q1, N );
		vec3 q0perp = cross( N, q0 );
		vec3 T = q1perp * st0.x + q0perp * st1.x;
		vec3 B = q1perp * st0.y + q0perp * st1.y;
		float det = max( dot( T, T ), dot( B, B ) );
		float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
		return mat3( T * scale, B * scale, N );
	}
#endif`, Os1 = `#ifdef USE_CLEARCOAT
	vec3 clearcoatNormal = nonPerturbedNormal;
#endif`, Fs1 = `#ifdef USE_CLEARCOAT_NORMALMAP
	vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
	clearcoatMapN.xy *= clearcoatNormalScale;
	clearcoatNormal = normalize( tbn2 * clearcoatMapN );
#endif`, Bs1 = `#ifdef USE_CLEARCOATMAP
	uniform sampler2D clearcoatMap;
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	uniform sampler2D clearcoatNormalMap;
	uniform vec2 clearcoatNormalScale;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
	uniform sampler2D clearcoatRoughnessMap;
#endif`, Gs1 = `#ifdef USE_IRIDESCENCEMAP
	uniform sampler2D iridescenceMap;
#endif
#ifdef USE_IRIDESCENCE_THICKNESSMAP
	uniform sampler2D iridescenceThicknessMap;
#endif`, Hs1 = `#ifdef OPAQUE
diffuseColor.a = 1.0;
#endif
#ifdef USE_TRANSMISSION
diffuseColor.a *= material.transmissionAlpha;
#endif
gl_FragColor = vec4( outgoingLight, diffuseColor.a );`, Vs1 = `vec3 packNormalToRGB( const in vec3 normal ) {
	return normalize( normal ) * 0.5 + 0.5;
}
vec3 unpackRGBToNormal( const in vec3 rgb ) {
	return 2.0 * rgb.xyz - 1.0;
}
const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;
const float Inv255 = 1. / 255.;
const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );
const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );
const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );
const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );
vec4 packDepthToRGBA( const in float v ) {
	if( v <= 0.0 )
		return vec4( 0., 0., 0., 0. );
	if( v >= 1.0 )
		return vec4( 1., 1., 1., 1. );
	float vuf;
	float af = modf( v * PackFactors.a, vuf );
	float bf = modf( vuf * ShiftRight8, vuf );
	float gf = modf( vuf * ShiftRight8, vuf );
	return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );
}
vec3 packDepthToRGB( const in float v ) {
	if( v <= 0.0 )
		return vec3( 0., 0., 0. );
	if( v >= 1.0 )
		return vec3( 1., 1., 1. );
	float vuf;
	float bf = modf( v * PackFactors.b, vuf );
	float gf = modf( vuf * ShiftRight8, vuf );
	return vec3( vuf * Inv255, gf * PackUpscale, bf );
}
vec2 packDepthToRG( const in float v ) {
	if( v <= 0.0 )
		return vec2( 0., 0. );
	if( v >= 1.0 )
		return vec2( 1., 1. );
	float vuf;
	float gf = modf( v * 256., vuf );
	return vec2( vuf * Inv255, gf );
}
float unpackRGBAToDepth( const in vec4 v ) {
	return dot( v, UnpackFactors4 );
}
float unpackRGBToDepth( const in vec3 v ) {
	return dot( v, UnpackFactors3 );
}
float unpackRGToDepth( const in vec2 v ) {
	return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;
}
vec4 pack2HalfToRGBA( const in vec2 v ) {
	vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
	return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
}
vec2 unpackRGBATo2Half( const in vec4 v ) {
	return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
}
float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
	return ( viewZ + near ) / ( near - far );
}
float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {
	return depth * ( near - far ) - near;
}
float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
	return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
}
float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
	return ( near * far ) / ( ( far - near ) * depth - far );
}`, ks1 = `#ifdef PREMULTIPLIED_ALPHA
	gl_FragColor.rgb *= gl_FragColor.a;
#endif`, zs1 = `vec4 mvPosition = vec4( transformed, 1.0 );
#ifdef USE_BATCHING
	mvPosition = batchingMatrix * mvPosition;
#endif
#ifdef USE_INSTANCING
	mvPosition = instanceMatrix * mvPosition;
#endif
mvPosition = modelViewMatrix * mvPosition;
gl_Position = projectionMatrix * mvPosition;`, Ws1 = `#ifdef DITHERING
	gl_FragColor.rgb = dithering( gl_FragColor.rgb );
#endif`, Xs1 = `#ifdef DITHERING
	vec3 dithering( vec3 color ) {
		float grid_position = rand( gl_FragCoord.xy );
		vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
		dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
		return color + dither_shift_RGB;
	}
#endif`, Ys1 = `float roughnessFactor = roughness;
#ifdef USE_ROUGHNESSMAP
	vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
	roughnessFactor *= texelRoughness.g;
#endif`, qs1 = `#ifdef USE_ROUGHNESSMAP
	uniform sampler2D roughnessMap;
#endif`, Ks1 = `#if NUM_SPOT_LIGHT_COORDS > 0
	varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
#endif
#if NUM_SPOT_LIGHT_MAPS > 0
	uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];
#endif
#ifdef USE_SHADOWMAP
	#if NUM_DIR_LIGHT_SHADOWS > 0
		uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
		varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
		struct DirectionalLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
		};
		uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
	#endif
	#if NUM_SPOT_LIGHT_SHADOWS > 0
		uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
		struct SpotLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
		};
		uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
	#endif
	#if NUM_POINT_LIGHT_SHADOWS > 0
		uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
		varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
		struct PointLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
			float shadowCameraNear;
			float shadowCameraFar;
		};
		uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
	#endif
	float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
		return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
	}
	vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
		return unpackRGBATo2Half( texture2D( shadow, uv ) );
	}
	float VSMShadow (sampler2D shadow, vec2 uv, float compare ){
		float occlusion = 1.0;
		vec2 distribution = texture2DDistribution( shadow, uv );
		float hard_shadow = step( compare , distribution.x );
		if (hard_shadow != 1.0 ) {
			float distance = compare - distribution.x ;
			float variance = max( 0.00000, distribution.y * distribution.y );
			float softness_probability = variance / (variance + distance * distance );			softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );			occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );
		}
		return occlusion;
	}
	float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
		float shadow = 1.0;
		shadowCoord.xyz /= shadowCoord.w;
		shadowCoord.z += shadowBias;
		bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
		bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
		if ( frustumTest ) {
		#if defined( SHADOWMAP_TYPE_PCF )
			vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
			float dx0 = - texelSize.x * shadowRadius;
			float dy0 = - texelSize.y * shadowRadius;
			float dx1 = + texelSize.x * shadowRadius;
			float dy1 = + texelSize.y * shadowRadius;
			float dx2 = dx0 / 2.0;
			float dy2 = dy0 / 2.0;
			float dx3 = dx1 / 2.0;
			float dy3 = dy1 / 2.0;
			shadow = (
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
			) * ( 1.0 / 17.0 );
		#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
			vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
			float dx = texelSize.x;
			float dy = texelSize.y;
			vec2 uv = shadowCoord.xy;
			vec2 f = fract( uv * shadowMapSize + 0.5 );
			uv -= f * texelSize;
			shadow = (
				texture2DCompare( shadowMap, uv, shadowCoord.z ) +
				texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
				texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
				texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
				mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
					 texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
					 f.x ) +
				mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
					 texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
					 f.x ) +
				mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
					 texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
					 f.y ) +
				mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
					 texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
					 f.y ) +
				mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
						  texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
						  f.x ),
					 mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
						  texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
						  f.x ),
					 f.y )
			) * ( 1.0 / 9.0 );
		#elif defined( SHADOWMAP_TYPE_VSM )
			shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
		#else
			shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );
		#endif
		}
		return mix( 1.0, shadow, shadowIntensity );
	}
	vec2 cubeToUV( vec3 v, float texelSizeY ) {
		vec3 absV = abs( v );
		float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );
		absV *= scaleToCube;
		v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );
		vec2 planar = v.xy;
		float almostATexel = 1.5 * texelSizeY;
		float almostOne = 1.0 - almostATexel;
		if ( absV.z >= almostOne ) {
			if ( v.z > 0.0 )
				planar.x = 4.0 - v.x;
		} else if ( absV.x >= almostOne ) {
			float signX = sign( v.x );
			planar.x = v.z * signX + 2.0 * signX;
		} else if ( absV.y >= almostOne ) {
			float signY = sign( v.y );
			planar.x = v.x + 2.0 * signY + 2.0;
			planar.y = v.z * signY - 2.0;
		}
		return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );
	}
	float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
		float shadow = 1.0;
		vec3 lightToPosition = shadowCoord.xyz;
		
		float lightToPositionLength = length( lightToPosition );
		if ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {
			float dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );			dp += shadowBias;
			vec3 bd3D = normalize( lightToPosition );
			vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
			#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
				vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
				shadow = (
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
					texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
				) * ( 1.0 / 9.0 );
			#else
				shadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
			#endif
		}
		return mix( 1.0, shadow, shadowIntensity );
	}
#endif`, $s1 = `#if NUM_SPOT_LIGHT_COORDS > 0
	uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
	varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
#endif
#ifdef USE_SHADOWMAP
	#if NUM_DIR_LIGHT_SHADOWS > 0
		uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
		varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
		struct DirectionalLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
		};
		uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
	#endif
	#if NUM_SPOT_LIGHT_SHADOWS > 0
		struct SpotLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
		};
		uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
	#endif
	#if NUM_POINT_LIGHT_SHADOWS > 0
		uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
		varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
		struct PointLightShadow {
			float shadowIntensity;
			float shadowBias;
			float shadowNormalBias;
			float shadowRadius;
			vec2 shadowMapSize;
			float shadowCameraNear;
			float shadowCameraFar;
		};
		uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
	#endif
#endif`, Zs1 = `#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
	vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
	vec4 shadowWorldPosition;
#endif
#if defined( USE_SHADOWMAP )
	#if NUM_DIR_LIGHT_SHADOWS > 0
		#pragma unroll_loop_start
		for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
			shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
			vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
		}
		#pragma unroll_loop_end
	#endif
	#if NUM_POINT_LIGHT_SHADOWS > 0
		#pragma unroll_loop_start
		for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
			shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
			vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
		}
		#pragma unroll_loop_end
	#endif
#endif
#if NUM_SPOT_LIGHT_COORDS > 0
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {
		shadowWorldPosition = worldPosition;
		#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
			shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;
		#endif
		vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
	}
	#pragma unroll_loop_end
#endif`, Qs1 = `float getShadowMask() {
	float shadow = 1.0;
	#ifdef USE_SHADOWMAP
	#if NUM_DIR_LIGHT_SHADOWS > 0
	DirectionalLightShadow directionalLight;
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
		directionalLight = directionalLightShadows[ i ];
		shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
	}
	#pragma unroll_loop_end
	#endif
	#if NUM_SPOT_LIGHT_SHADOWS > 0
	SpotLightShadow spotLight;
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
		spotLight = spotLightShadows[ i ];
		shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
	}
	#pragma unroll_loop_end
	#endif
	#if NUM_POINT_LIGHT_SHADOWS > 0
	PointLightShadow pointLight;
	#pragma unroll_loop_start
	for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
		pointLight = pointLightShadows[ i ];
		shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
	}
	#pragma unroll_loop_end
	#endif
	#endif
	return shadow;
}`, Js1 = `#ifdef USE_SKINNING
	mat4 boneMatX = getBoneMatrix( skinIndex.x );
	mat4 boneMatY = getBoneMatrix( skinIndex.y );
	mat4 boneMatZ = getBoneMatrix( skinIndex.z );
	mat4 boneMatW = getBoneMatrix( skinIndex.w );
#endif`, js1 = `#ifdef USE_SKINNING
	uniform mat4 bindMatrix;
	uniform mat4 bindMatrixInverse;
	uniform highp sampler2D boneTexture;
	mat4 getBoneMatrix( const in float i ) {
		int size = textureSize( boneTexture, 0 ).x;
		int j = int( i ) * 4;
		int x = j % size;
		int y = j / size;
		vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );
		vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );
		vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );
		vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
		return mat4( v1, v2, v3, v4 );
	}
#endif`, ec1 = `#ifdef USE_SKINNING
	vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
	vec4 skinned = vec4( 0.0 );
	skinned += boneMatX * skinVertex * skinWeight.x;
	skinned += boneMatY * skinVertex * skinWeight.y;
	skinned += boneMatZ * skinVertex * skinWeight.z;
	skinned += boneMatW * skinVertex * skinWeight.w;
	transformed = ( bindMatrixInverse * skinned ).xyz;
#endif`, tc1 = `#ifdef USE_SKINNING
	mat4 skinMatrix = mat4( 0.0 );
	skinMatrix += skinWeight.x * boneMatX;
	skinMatrix += skinWeight.y * boneMatY;
	skinMatrix += skinWeight.z * boneMatZ;
	skinMatrix += skinWeight.w * boneMatW;
	skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
	objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
	#ifdef USE_TANGENT
		objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
	#endif
#endif`, nc1 = `float specularStrength;
#ifdef USE_SPECULARMAP
	vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
	specularStrength = texelSpecular.r;
#else
	specularStrength = 1.0;
#endif`, ic1 = `#ifdef USE_SPECULARMAP
	uniform sampler2D specularMap;
#endif`, rc1 = `#if defined( TONE_MAPPING )
	gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
#endif`, ac1 = `#ifndef saturate
#define saturate( a ) clamp( a, 0.0, 1.0 )
#endif
uniform float toneMappingExposure;
vec3 LinearToneMapping( vec3 color ) {
	return saturate( toneMappingExposure * color );
}
vec3 ReinhardToneMapping( vec3 color ) {
	color *= toneMappingExposure;
	return saturate( color / ( vec3( 1.0 ) + color ) );
}
vec3 CineonToneMapping( vec3 color ) {
	color *= toneMappingExposure;
	color = max( vec3( 0.0 ), color - 0.004 );
	return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
}
vec3 RRTAndODTFit( vec3 v ) {
	vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
	vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
	return a / b;
}
vec3 ACESFilmicToneMapping( vec3 color ) {
	const mat3 ACESInputMat = mat3(
		vec3( 0.59719, 0.07600, 0.02840 ),		vec3( 0.35458, 0.90834, 0.13383 ),
		vec3( 0.04823, 0.01566, 0.83777 )
	);
	const mat3 ACESOutputMat = mat3(
		vec3(  1.60475, -0.10208, -0.00327 ),		vec3( -0.53108,  1.10813, -0.07276 ),
		vec3( -0.07367, -0.00605,  1.07602 )
	);
	color *= toneMappingExposure / 0.6;
	color = ACESInputMat * color;
	color = RRTAndODTFit( color );
	color = ACESOutputMat * color;
	return saturate( color );
}
const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
	vec3( 1.6605, - 0.1246, - 0.0182 ),
	vec3( - 0.5876, 1.1329, - 0.1006 ),
	vec3( - 0.0728, - 0.0083, 1.1187 )
);
const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
	vec3( 0.6274, 0.0691, 0.0164 ),
	vec3( 0.3293, 0.9195, 0.0880 ),
	vec3( 0.0433, 0.0113, 0.8956 )
);
vec3 agxDefaultContrastApprox( vec3 x ) {
	vec3 x2 = x * x;
	vec3 x4 = x2 * x2;
	return + 15.5 * x4 * x2
		- 40.14 * x4 * x
		+ 31.96 * x4
		- 6.868 * x2 * x
		+ 0.4298 * x2
		+ 0.1191 * x
		- 0.00232;
}
vec3 AgXToneMapping( vec3 color ) {
	const mat3 AgXInsetMatrix = mat3(
		vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),
		vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),
		vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )
	);
	const mat3 AgXOutsetMatrix = mat3(
		vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),
		vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),
		vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
	);
	const float AgxMinEv = - 12.47393;	const float AgxMaxEv = 4.026069;
	color *= toneMappingExposure;
	color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
	color = AgXInsetMatrix * color;
	color = max( color, 1e-10 );	color = log2( color );
	color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );
	color = clamp( color, 0.0, 1.0 );
	color = agxDefaultContrastApprox( color );
	color = AgXOutsetMatrix * color;
	color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );
	color = LINEAR_REC2020_TO_LINEAR_SRGB * color;
	color = clamp( color, 0.0, 1.0 );
	return color;
}
vec3 NeutralToneMapping( vec3 color ) {
	const float StartCompression = 0.8 - 0.04;
	const float Desaturation = 0.15;
	color *= toneMappingExposure;
	float x = min( color.r, min( color.g, color.b ) );
	float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
	color -= offset;
	float peak = max( color.r, max( color.g, color.b ) );
	if ( peak < StartCompression ) return color;
	float d = 1. - StartCompression;
	float newPeak = 1. - d * d / ( peak + d - StartCompression );
	color *= newPeak / peak;
	float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
	return mix( color, vec3( newPeak ), g );
}
vec3 CustomToneMapping( vec3 color ) { return color; }`, oc1 = `#ifdef USE_TRANSMISSION
	material.transmission = transmission;
	material.transmissionAlpha = 1.0;
	material.thickness = thickness;
	material.attenuationDistance = attenuationDistance;
	material.attenuationColor = attenuationColor;
	#ifdef USE_TRANSMISSIONMAP
		material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;
	#endif
	#ifdef USE_THICKNESSMAP
		material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;
	#endif
	vec3 pos = vWorldPosition;
	vec3 v = normalize( cameraPosition - pos );
	vec3 n = inverseTransformDirection( normal, viewMatrix );
	vec4 transmitted = getIBLVolumeRefraction(
		n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
		pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,
		material.attenuationColor, material.attenuationDistance );
	material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
	totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
#endif`, sc1 = `#ifdef USE_TRANSMISSION
	uniform float transmission;
	uniform float thickness;
	uniform float attenuationDistance;
	uniform vec3 attenuationColor;
	#ifdef USE_TRANSMISSIONMAP
		uniform sampler2D transmissionMap;
	#endif
	#ifdef USE_THICKNESSMAP
		uniform sampler2D thicknessMap;
	#endif
	uniform vec2 transmissionSamplerSize;
	uniform sampler2D transmissionSamplerMap;
	uniform mat4 modelMatrix;
	uniform mat4 projectionMatrix;
	varying vec3 vWorldPosition;
	float w0( float a ) {
		return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
	}
	float w1( float a ) {
		return ( 1.0 / 6.0 ) * ( a *  a * ( 3.0 * a - 6.0 ) + 4.0 );
	}
	float w2( float a ){
		return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );
	}
	float w3( float a ) {
		return ( 1.0 / 6.0 ) * ( a * a * a );
	}
	float g0( float a ) {
		return w0( a ) + w1( a );
	}
	float g1( float a ) {
		return w2( a ) + w3( a );
	}
	float h0( float a ) {
		return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );
	}
	float h1( float a ) {
		return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );
	}
	vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {
		uv = uv * texelSize.zw + 0.5;
		vec2 iuv = floor( uv );
		vec2 fuv = fract( uv );
		float g0x = g0( fuv.x );
		float g1x = g1( fuv.x );
		float h0x = h0( fuv.x );
		float h1x = h1( fuv.x );
		float h0y = h0( fuv.y );
		float h1y = h1( fuv.y );
		vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
		vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
		vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
		vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
		return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +
			g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );
	}
	vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {
		vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );
		vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );
		vec2 fLodSizeInv = 1.0 / fLodSize;
		vec2 cLodSizeInv = 1.0 / cLodSize;
		vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
		vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
		return mix( fSample, cSample, fract( lod ) );
	}
	vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
		vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
		vec3 modelScale;
		modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
		modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
		modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
		return normalize( refractionVector ) * thickness * modelScale;
	}
	float applyIorToRoughness( const in float roughness, const in float ior ) {
		return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
	}
	vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
		float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
		return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );
	}
	vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
		if ( isinf( attenuationDistance ) ) {
			return vec3( 1.0 );
		} else {
			vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
			vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );			return transmittance;
		}
	}
	vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
		const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
		const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,
		const in vec3 attenuationColor, const in float attenuationDistance ) {
		vec4 transmittedLight;
		vec3 transmittance;
		#ifdef USE_DISPERSION
			float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;
			vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );
			for ( int i = 0; i < 3; i ++ ) {
				vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );
				vec3 refractedRayExit = position + transmissionRay;
				vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
				vec2 refractionCoords = ndcPos.xy / ndcPos.w;
				refractionCoords += 1.0;
				refractionCoords /= 2.0;
				vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );
				transmittedLight[ i ] = transmissionSample[ i ];
				transmittedLight.a += transmissionSample.a;
				transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];
			}
			transmittedLight.a /= 3.0;
		#else
			vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
			vec3 refractedRayExit = position + transmissionRay;
			vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
			vec2 refractionCoords = ndcPos.xy / ndcPos.w;
			refractionCoords += 1.0;
			refractionCoords /= 2.0;
			transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
			transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
		#endif
		vec3 attenuatedColor = transmittance * transmittedLight.rgb;
		vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
		float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
		return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
	}
#endif`, cc1 = `#if defined( USE_UV ) || defined( USE_ANISOTROPY )
	varying vec2 vUv;
#endif
#ifdef USE_MAP
	varying vec2 vMapUv;
#endif
#ifdef USE_ALPHAMAP
	varying vec2 vAlphaMapUv;
#endif
#ifdef USE_LIGHTMAP
	varying vec2 vLightMapUv;
#endif
#ifdef USE_AOMAP
	varying vec2 vAoMapUv;
#endif
#ifdef USE_BUMPMAP
	varying vec2 vBumpMapUv;
#endif
#ifdef USE_NORMALMAP
	varying vec2 vNormalMapUv;
#endif
#ifdef USE_EMISSIVEMAP
	varying vec2 vEmissiveMapUv;
#endif
#ifdef USE_METALNESSMAP
	varying vec2 vMetalnessMapUv;
#endif
#ifdef USE_ROUGHNESSMAP
	varying vec2 vRoughnessMapUv;
#endif
#ifdef USE_ANISOTROPYMAP
	varying vec2 vAnisotropyMapUv;
#endif
#ifdef USE_CLEARCOATMAP
	varying vec2 vClearcoatMapUv;
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	varying vec2 vClearcoatNormalMapUv;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
	varying vec2 vClearcoatRoughnessMapUv;
#endif
#ifdef USE_IRIDESCENCEMAP
	varying vec2 vIridescenceMapUv;
#endif
#ifdef USE_IRIDESCENCE_THICKNESSMAP
	varying vec2 vIridescenceThicknessMapUv;
#endif
#ifdef USE_SHEEN_COLORMAP
	varying vec2 vSheenColorMapUv;
#endif
#ifdef USE_SHEEN_ROUGHNESSMAP
	varying vec2 vSheenRoughnessMapUv;
#endif
#ifdef USE_SPECULARMAP
	varying vec2 vSpecularMapUv;
#endif
#ifdef USE_SPECULAR_COLORMAP
	varying vec2 vSpecularColorMapUv;
#endif
#ifdef USE_SPECULAR_INTENSITYMAP
	varying vec2 vSpecularIntensityMapUv;
#endif
#ifdef USE_TRANSMISSIONMAP
	uniform mat3 transmissionMapTransform;
	varying vec2 vTransmissionMapUv;
#endif
#ifdef USE_THICKNESSMAP
	uniform mat3 thicknessMapTransform;
	varying vec2 vThicknessMapUv;
#endif`, lc1 = `#if defined( USE_UV ) || defined( USE_ANISOTROPY )
	varying vec2 vUv;
#endif
#ifdef USE_MAP
	uniform mat3 mapTransform;
	varying vec2 vMapUv;
#endif
#ifdef USE_ALPHAMAP
	uniform mat3 alphaMapTransform;
	varying vec2 vAlphaMapUv;
#endif
#ifdef USE_LIGHTMAP
	uniform mat3 lightMapTransform;
	varying vec2 vLightMapUv;
#endif
#ifdef USE_AOMAP
	uniform mat3 aoMapTransform;
	varying vec2 vAoMapUv;
#endif
#ifdef USE_BUMPMAP
	uniform mat3 bumpMapTransform;
	varying vec2 vBumpMapUv;
#endif
#ifdef USE_NORMALMAP
	uniform mat3 normalMapTransform;
	varying vec2 vNormalMapUv;
#endif
#ifdef USE_DISPLACEMENTMAP
	uniform mat3 displacementMapTransform;
	varying vec2 vDisplacementMapUv;
#endif
#ifdef USE_EMISSIVEMAP
	uniform mat3 emissiveMapTransform;
	varying vec2 vEmissiveMapUv;
#endif
#ifdef USE_METALNESSMAP
	uniform mat3 metalnessMapTransform;
	varying vec2 vMetalnessMapUv;
#endif
#ifdef USE_ROUGHNESSMAP
	uniform mat3 roughnessMapTransform;
	varying vec2 vRoughnessMapUv;
#endif
#ifdef USE_ANISOTROPYMAP
	uniform mat3 anisotropyMapTransform;
	varying vec2 vAnisotropyMapUv;
#endif
#ifdef USE_CLEARCOATMAP
	uniform mat3 clearcoatMapTransform;
	varying vec2 vClearcoatMapUv;
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	uniform mat3 clearcoatNormalMapTransform;
	varying vec2 vClearcoatNormalMapUv;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
	uniform mat3 clearcoatRoughnessMapTransform;
	varying vec2 vClearcoatRoughnessMapUv;
#endif
#ifdef USE_SHEEN_COLORMAP
	uniform mat3 sheenColorMapTransform;
	varying vec2 vSheenColorMapUv;
#endif
#ifdef USE_SHEEN_ROUGHNESSMAP
	uniform mat3 sheenRoughnessMapTransform;
	varying vec2 vSheenRoughnessMapUv;
#endif
#ifdef USE_IRIDESCENCEMAP
	uniform mat3 iridescenceMapTransform;
	varying vec2 vIridescenceMapUv;
#endif
#ifdef USE_IRIDESCENCE_THICKNESSMAP
	uniform mat3 iridescenceThicknessMapTransform;
	varying vec2 vIridescenceThicknessMapUv;
#endif
#ifdef USE_SPECULARMAP
	uniform mat3 specularMapTransform;
	varying vec2 vSpecularMapUv;
#endif
#ifdef USE_SPECULAR_COLORMAP
	uniform mat3 specularColorMapTransform;
	varying vec2 vSpecularColorMapUv;
#endif
#ifdef USE_SPECULAR_INTENSITYMAP
	uniform mat3 specularIntensityMapTransform;
	varying vec2 vSpecularIntensityMapUv;
#endif
#ifdef USE_TRANSMISSIONMAP
	uniform mat3 transmissionMapTransform;
	varying vec2 vTransmissionMapUv;
#endif
#ifdef USE_THICKNESSMAP
	uniform mat3 thicknessMapTransform;
	varying vec2 vThicknessMapUv;
#endif`, fc1 = `#if defined( USE_UV ) || defined( USE_ANISOTROPY )
	vUv = vec3( uv, 1 ).xy;
#endif
#ifdef USE_MAP
	vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;
#endif
#ifdef USE_ALPHAMAP
	vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_LIGHTMAP
	vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_AOMAP
	vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_BUMPMAP
	vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_NORMALMAP
	vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_DISPLACEMENTMAP
	vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_EMISSIVEMAP
	vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_METALNESSMAP
	vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_ROUGHNESSMAP
	vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_ANISOTROPYMAP
	vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_CLEARCOATMAP
	vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_CLEARCOAT_NORMALMAP
	vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
	vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_IRIDESCENCEMAP
	vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_IRIDESCENCE_THICKNESSMAP
	vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SHEEN_COLORMAP
	vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SHEEN_ROUGHNESSMAP
	vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SPECULARMAP
	vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SPECULAR_COLORMAP
	vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_SPECULAR_INTENSITYMAP
	vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_TRANSMISSIONMAP
	vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;
#endif
#ifdef USE_THICKNESSMAP
	vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
#endif`, dc1 = `#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
	vec4 worldPosition = vec4( transformed, 1.0 );
	#ifdef USE_BATCHING
		worldPosition = batchingMatrix * worldPosition;
	#endif
	#ifdef USE_INSTANCING
		worldPosition = instanceMatrix * worldPosition;
	#endif
	worldPosition = modelMatrix * worldPosition;
#endif`, uc1 = `varying vec2 vUv;
uniform mat3 uvTransform;
void main() {
	vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
	gl_Position = vec4( position.xy, 1.0, 1.0 );
}`, pc1 = `uniform sampler2D t2D;
uniform float backgroundIntensity;
varying vec2 vUv;
void main() {
	vec4 texColor = texture2D( t2D, vUv );
	#ifdef DECODE_VIDEO_TEXTURE
		texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
	#endif
	texColor.rgb *= backgroundIntensity;
	gl_FragColor = texColor;
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
}`, hc1 = `varying vec3 vWorldDirection;
#include <common>
void main() {
	vWorldDirection = transformDirection( position, modelMatrix );
	#include <begin_vertex>
	#include <project_vertex>
	gl_Position.z = gl_Position.w;
}`, mc1 = `#ifdef ENVMAP_TYPE_CUBE
	uniform samplerCube envMap;
#elif defined( ENVMAP_TYPE_CUBE_UV )
	uniform sampler2D envMap;
#endif
uniform float flipEnvMap;
uniform float backgroundBlurriness;
uniform float backgroundIntensity;
uniform mat3 backgroundRotation;
varying vec3 vWorldDirection;
#include <cube_uv_reflection_fragment>
void main() {
	#ifdef ENVMAP_TYPE_CUBE
		vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );
	#elif defined( ENVMAP_TYPE_CUBE_UV )
		vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );
	#else
		vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );
	#endif
	texColor.rgb *= backgroundIntensity;
	gl_FragColor = texColor;
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
}`, _c1 = `varying vec3 vWorldDirection;
#include <common>
void main() {
	vWorldDirection = transformDirection( position, modelMatrix );
	#include <begin_vertex>
	#include <project_vertex>
	gl_Position.z = gl_Position.w;
}`, vc1 = `uniform samplerCube tCube;
uniform float tFlip;
uniform float opacity;
varying vec3 vWorldDirection;
void main() {
	vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
	gl_FragColor = texColor;
	gl_FragColor.a *= opacity;
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
}`, gc1 = `#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
varying vec2 vHighPrecisionZW;
void main() {
	#include <uv_vertex>
	#include <batching_vertex>
	#include <skinbase_vertex>
	#include <morphinstance_vertex>
	#ifdef USE_DISPLACEMENTMAP
		#include <beginnormal_vertex>
		#include <morphnormal_vertex>
		#include <skinnormal_vertex>
	#endif
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vHighPrecisionZW = gl_Position.zw;
}`, Sc1 = `#if DEPTH_PACKING == 3200
	uniform float opacity;
#endif
#include <common>
#include <packing>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
varying vec2 vHighPrecisionZW;
void main() {
	vec4 diffuseColor = vec4( 1.0 );
	#include <clipping_planes_fragment>
	#if DEPTH_PACKING == 3200
		diffuseColor.a = opacity;
	#endif
	#include <map_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <logdepthbuf_fragment>
	float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
	#if DEPTH_PACKING == 3200
		gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
	#elif DEPTH_PACKING == 3201
		gl_FragColor = packDepthToRGBA( fragCoordZ );
	#elif DEPTH_PACKING == 3202
		gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );
	#elif DEPTH_PACKING == 3203
		gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
	#endif
}`, Ec1 = `#define DISTANCE
varying vec3 vWorldPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <batching_vertex>
	#include <skinbase_vertex>
	#include <morphinstance_vertex>
	#ifdef USE_DISPLACEMENTMAP
		#include <beginnormal_vertex>
		#include <morphnormal_vertex>
		#include <skinnormal_vertex>
	#endif
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <worldpos_vertex>
	#include <clipping_planes_vertex>
	vWorldPosition = worldPosition.xyz;
}`, Mc1 = `#define DISTANCE
uniform vec3 referencePosition;
uniform float nearDistance;
uniform float farDistance;
varying vec3 vWorldPosition;
#include <common>
#include <packing>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <clipping_planes_pars_fragment>
void main () {
	vec4 diffuseColor = vec4( 1.0 );
	#include <clipping_planes_fragment>
	#include <map_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	float dist = length( vWorldPosition - referencePosition );
	dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
	dist = saturate( dist );
	gl_FragColor = packDepthToRGBA( dist );
}`, Tc1 = `varying vec3 vWorldDirection;
#include <common>
void main() {
	vWorldDirection = transformDirection( position, modelMatrix );
	#include <begin_vertex>
	#include <project_vertex>
}`, xc1 = `uniform sampler2D tEquirect;
varying vec3 vWorldDirection;
#include <common>
void main() {
	vec3 direction = normalize( vWorldDirection );
	vec2 sampleUV = equirectUv( direction );
	gl_FragColor = texture2D( tEquirect, sampleUV );
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
}`, Ac1 = `uniform float scale;
attribute float lineDistance;
varying float vLineDistance;
#include <common>
#include <uv_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	vLineDistance = scale * lineDistance;
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <fog_vertex>
}`, Rc1 = `uniform vec3 diffuse;
uniform float opacity;
uniform float dashSize;
uniform float totalSize;
varying float vLineDistance;
#include <common>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	if ( mod( vLineDistance, totalSize ) > dashSize ) {
		discard;
	}
	vec3 outgoingLight = vec3( 0.0 );
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	outgoingLight = diffuseColor.rgb;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
}`, Cc1 = `#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <envmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
		#include <beginnormal_vertex>
		#include <morphnormal_vertex>
		#include <skinbase_vertex>
		#include <skinnormal_vertex>
		#include <defaultnormal_vertex>
	#endif
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <worldpos_vertex>
	#include <envmap_vertex>
	#include <fog_vertex>
}`, bc1 = `uniform vec3 diffuse;
uniform float opacity;
#ifndef FLAT_SHADED
	varying vec3 vNormal;
#endif
#include <common>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <fog_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <specularmap_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	#ifdef USE_LIGHTMAP
		vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
		reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
	#else
		reflectedLight.indirectDiffuse += vec3( 1.0 );
	#endif
	#include <aomap_fragment>
	reflectedLight.indirectDiffuse *= diffuseColor.rgb;
	vec3 outgoingLight = reflectedLight.indirectDiffuse;
	#include <envmap_fragment>
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, Pc1 = `#define LAMBERT
varying vec3 vViewPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <envmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vViewPosition = - mvPosition.xyz;
	#include <worldpos_vertex>
	#include <envmap_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
}`, Lc1 = `#define LAMBERT
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float opacity;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_lambert_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	vec3 totalEmissiveRadiance = emissive;
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <specularmap_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	#include <emissivemap_fragment>
	#include <lights_lambert_fragment>
	#include <lights_fragment_begin>
	#include <lights_fragment_maps>
	#include <lights_fragment_end>
	#include <aomap_fragment>
	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
	#include <envmap_fragment>
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, Uc1 = `#define MATCAP
varying vec3 vViewPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <color_pars_vertex>
#include <displacementmap_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <fog_vertex>
	vViewPosition = - mvPosition.xyz;
}`, Dc1 = `#define MATCAP
uniform vec3 diffuse;
uniform float opacity;
uniform sampler2D matcap;
varying vec3 vViewPosition;
#include <common>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <fog_pars_fragment>
#include <normal_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	vec3 viewDir = normalize( vViewPosition );
	vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );
	vec3 y = cross( viewDir, x );
	vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;
	#ifdef USE_MATCAP
		vec4 matcapColor = texture2D( matcap, uv );
	#else
		vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );
	#endif
	vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, wc1 = `#define NORMAL
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
	varying vec3 vViewPosition;
#endif
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphinstance_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
	vViewPosition = - mvPosition.xyz;
#endif
}`, Ic1 = `#define NORMAL
uniform float opacity;
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
	varying vec3 vViewPosition;
#endif
#include <packing>
#include <uv_pars_fragment>
#include <normal_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );
	#include <clipping_planes_fragment>
	#include <logdepthbuf_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	gl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );
	#ifdef OPAQUE
		gl_FragColor.a = 1.0;
	#endif
}`, yc1 = `#define PHONG
varying vec3 vViewPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <envmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphinstance_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vViewPosition = - mvPosition.xyz;
	#include <worldpos_vertex>
	#include <envmap_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
}`, Nc1 = `#define PHONG
uniform vec3 diffuse;
uniform vec3 emissive;
uniform vec3 specular;
uniform float shininess;
uniform float opacity;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_phong_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	vec3 totalEmissiveRadiance = emissive;
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <specularmap_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	#include <emissivemap_fragment>
	#include <lights_phong_fragment>
	#include <lights_fragment_begin>
	#include <lights_fragment_maps>
	#include <lights_fragment_end>
	#include <aomap_fragment>
	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
	#include <envmap_fragment>
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, Oc1 = `#define STANDARD
varying vec3 vViewPosition;
#ifdef USE_TRANSMISSION
	varying vec3 vWorldPosition;
#endif
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vViewPosition = - mvPosition.xyz;
	#include <worldpos_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
#ifdef USE_TRANSMISSION
	vWorldPosition = worldPosition.xyz;
#endif
}`, Fc1 = `#define STANDARD
#ifdef PHYSICAL
	#define IOR
	#define USE_SPECULAR
#endif
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float roughness;
uniform float metalness;
uniform float opacity;
#ifdef IOR
	uniform float ior;
#endif
#ifdef USE_SPECULAR
	uniform float specularIntensity;
	uniform vec3 specularColor;
	#ifdef USE_SPECULAR_COLORMAP
		uniform sampler2D specularColorMap;
	#endif
	#ifdef USE_SPECULAR_INTENSITYMAP
		uniform sampler2D specularIntensityMap;
	#endif
#endif
#ifdef USE_CLEARCOAT
	uniform float clearcoat;
	uniform float clearcoatRoughness;
#endif
#ifdef USE_DISPERSION
	uniform float dispersion;
#endif
#ifdef USE_IRIDESCENCE
	uniform float iridescence;
	uniform float iridescenceIOR;
	uniform float iridescenceThicknessMinimum;
	uniform float iridescenceThicknessMaximum;
#endif
#ifdef USE_SHEEN
	uniform vec3 sheenColor;
	uniform float sheenRoughness;
	#ifdef USE_SHEEN_COLORMAP
		uniform sampler2D sheenColorMap;
	#endif
	#ifdef USE_SHEEN_ROUGHNESSMAP
		uniform sampler2D sheenRoughnessMap;
	#endif
#endif
#ifdef USE_ANISOTROPY
	uniform vec2 anisotropyVector;
	#ifdef USE_ANISOTROPYMAP
		uniform sampler2D anisotropyMap;
	#endif
#endif
varying vec3 vViewPosition;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <iridescence_fragment>
#include <cube_uv_reflection_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_physical_pars_fragment>
#include <fog_pars_fragment>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_physical_pars_fragment>
#include <transmission_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <clearcoat_pars_fragment>
#include <iridescence_pars_fragment>
#include <roughnessmap_pars_fragment>
#include <metalnessmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	vec3 totalEmissiveRadiance = emissive;
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <roughnessmap_fragment>
	#include <metalnessmap_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	#include <clearcoat_normal_fragment_begin>
	#include <clearcoat_normal_fragment_maps>
	#include <emissivemap_fragment>
	#include <lights_physical_fragment>
	#include <lights_fragment_begin>
	#include <lights_fragment_maps>
	#include <lights_fragment_end>
	#include <aomap_fragment>
	vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
	vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
	#include <transmission_fragment>
	vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
	#ifdef USE_SHEEN
		float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
		outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;
	#endif
	#ifdef USE_CLEARCOAT
		float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
		vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
		outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
	#endif
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, Bc1 = `#define TOON
varying vec3 vViewPosition;
#include <common>
#include <batching_pars_vertex>
#include <uv_pars_vertex>
#include <displacementmap_pars_vertex>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <normal_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <shadowmap_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <normal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <displacementmap_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	vViewPosition = - mvPosition.xyz;
	#include <worldpos_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
}`, Gc1 = `#define TOON
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float opacity;
#include <common>
#include <packing>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <emissivemap_pars_fragment>
#include <gradientmap_pars_fragment>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <normal_pars_fragment>
#include <lights_toon_pars_fragment>
#include <shadowmap_pars_fragment>
#include <bumpmap_pars_fragment>
#include <normalmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
	vec3 totalEmissiveRadiance = emissive;
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <color_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	#include <normal_fragment_begin>
	#include <normal_fragment_maps>
	#include <emissivemap_fragment>
	#include <lights_toon_fragment>
	#include <lights_fragment_begin>
	#include <lights_fragment_maps>
	#include <lights_fragment_end>
	#include <aomap_fragment>
	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
	#include <dithering_fragment>
}`, Hc1 = `uniform float size;
uniform float scale;
#include <common>
#include <color_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
#ifdef USE_POINTS_UV
	varying vec2 vUv;
	uniform mat3 uvTransform;
#endif
void main() {
	#ifdef USE_POINTS_UV
		vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
	#endif
	#include <color_vertex>
	#include <morphinstance_vertex>
	#include <morphcolor_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <project_vertex>
	gl_PointSize = size;
	#ifdef USE_SIZEATTENUATION
		bool isPerspective = isPerspectiveMatrix( projectionMatrix );
		if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
	#endif
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <worldpos_vertex>
	#include <fog_vertex>
}`, Vc1 = `uniform vec3 diffuse;
uniform float opacity;
#include <common>
#include <color_pars_fragment>
#include <map_particle_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	vec3 outgoingLight = vec3( 0.0 );
	#include <logdepthbuf_fragment>
	#include <map_particle_fragment>
	#include <color_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	outgoingLight = diffuseColor.rgb;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
	#include <premultiplied_alpha_fragment>
}`, kc1 = `#include <common>
#include <batching_pars_vertex>
#include <fog_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <shadowmap_pars_vertex>
void main() {
	#include <batching_vertex>
	#include <beginnormal_vertex>
	#include <morphinstance_vertex>
	#include <morphnormal_vertex>
	#include <skinbase_vertex>
	#include <skinnormal_vertex>
	#include <defaultnormal_vertex>
	#include <begin_vertex>
	#include <morphtarget_vertex>
	#include <skinning_vertex>
	#include <project_vertex>
	#include <logdepthbuf_vertex>
	#include <worldpos_vertex>
	#include <shadowmap_vertex>
	#include <fog_vertex>
}`, zc1 = `uniform vec3 color;
uniform float opacity;
#include <common>
#include <packing>
#include <fog_pars_fragment>
#include <bsdfs>
#include <lights_pars_begin>
#include <logdepthbuf_pars_fragment>
#include <shadowmap_pars_fragment>
#include <shadowmask_pars_fragment>
void main() {
	#include <logdepthbuf_fragment>
	gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
}`, Wc1 = `uniform float rotation;
uniform vec2 center;
#include <common>
#include <uv_pars_vertex>
#include <fog_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
	#include <uv_vertex>
	vec4 mvPosition = modelViewMatrix[ 3 ];
	vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );
	#ifndef USE_SIZEATTENUATION
		bool isPerspective = isPerspectiveMatrix( projectionMatrix );
		if ( isPerspective ) scale *= - mvPosition.z;
	#endif
	vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;
	vec2 rotatedPosition;
	rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
	rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
	mvPosition.xy += rotatedPosition;
	gl_Position = projectionMatrix * mvPosition;
	#include <logdepthbuf_vertex>
	#include <clipping_planes_vertex>
	#include <fog_vertex>
}`, Xc1 = `uniform vec3 diffuse;
uniform float opacity;
#include <common>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main() {
	vec4 diffuseColor = vec4( diffuse, opacity );
	#include <clipping_planes_fragment>
	vec3 outgoingLight = vec3( 0.0 );
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <alphamap_fragment>
	#include <alphatest_fragment>
	#include <alphahash_fragment>
	outgoingLight = diffuseColor.rgb;
	#include <opaque_fragment>
	#include <tonemapping_fragment>
	#include <colorspace_fragment>
	#include <fog_fragment>
}`, Pe1 = {
    alphahash_fragment: po1,
    alphahash_pars_fragment: ho1,
    alphamap_fragment: mo1,
    alphamap_pars_fragment: _o1,
    alphatest_fragment: vo1,
    alphatest_pars_fragment: go1,
    aomap_fragment: So1,
    aomap_pars_fragment: Eo1,
    batching_pars_vertex: Mo1,
    batching_vertex: To1,
    begin_vertex: xo1,
    beginnormal_vertex: Ao1,
    bsdfs: Ro1,
    iridescence_fragment: Co1,
    bumpmap_pars_fragment: bo1,
    clipping_planes_fragment: Po1,
    clipping_planes_pars_fragment: Lo1,
    clipping_planes_pars_vertex: Uo1,
    clipping_planes_vertex: Do1,
    color_fragment: wo1,
    color_pars_fragment: Io1,
    color_pars_vertex: yo1,
    color_vertex: No1,
    common: Oo1,
    cube_uv_reflection_fragment: Fo1,
    defaultnormal_vertex: Bo1,
    displacementmap_pars_vertex: Go1,
    displacementmap_vertex: Ho1,
    emissivemap_fragment: Vo1,
    emissivemap_pars_fragment: ko1,
    colorspace_fragment: zo1,
    colorspace_pars_fragment: Wo1,
    envmap_fragment: Xo1,
    envmap_common_pars_fragment: Yo,
    envmap_pars_fragment: qo1,
    envmap_pars_vertex: Ko,
    envmap_physical_pars_fragment: as1,
    envmap_vertex: $o,
    fog_vertex: Zo1,
    fog_pars_vertex: Qo,
    fog_fragment: Jo1,
    fog_pars_fragment: jo,
    gradientmap_pars_fragment: es,
    lightmap_pars_fragment: ts1,
    lights_lambert_fragment: ns1,
    lights_lambert_pars_fragment: is,
    lights_pars_begin: rs1,
    lights_toon_fragment: os1,
    lights_toon_pars_fragment: ss1,
    lights_phong_fragment: cs1,
    lights_phong_pars_fragment: ls1,
    lights_physical_fragment: fs1,
    lights_physical_pars_fragment: ds1,
    lights_fragment_begin: us1,
    lights_fragment_maps: ps1,
    lights_fragment_end: hs1,
    logdepthbuf_fragment: ms1,
    logdepthbuf_pars_fragment: _s1,
    logdepthbuf_pars_vertex: vs1,
    logdepthbuf_vertex: gs1,
    map_fragment: Ss1,
    map_pars_fragment: Es1,
    map_particle_fragment: Ms1,
    map_particle_pars_fragment: Ts1,
    metalnessmap_fragment: xs1,
    metalnessmap_pars_fragment: As1,
    morphinstance_vertex: Rs1,
    morphcolor_vertex: Cs1,
    morphnormal_vertex: bs1,
    morphtarget_pars_vertex: Ps1,
    morphtarget_vertex: Ls1,
    normal_fragment_begin: Us1,
    normal_fragment_maps: Ds1,
    normal_pars_fragment: ws1,
    normal_pars_vertex: Is1,
    normal_vertex: ys1,
    normalmap_pars_fragment: Ns1,
    clearcoat_normal_fragment_begin: Os1,
    clearcoat_normal_fragment_maps: Fs1,
    clearcoat_pars_fragment: Bs1,
    iridescence_pars_fragment: Gs1,
    opaque_fragment: Hs1,
    packing: Vs1,
    premultiplied_alpha_fragment: ks1,
    project_vertex: zs1,
    dithering_fragment: Ws1,
    dithering_pars_fragment: Xs1,
    roughnessmap_fragment: Ys1,
    roughnessmap_pars_fragment: qs1,
    shadowmap_pars_fragment: Ks1,
    shadowmap_pars_vertex: $s1,
    shadowmap_vertex: Zs1,
    shadowmask_pars_fragment: Qs1,
    skinbase_vertex: Js1,
    skinning_pars_vertex: js1,
    skinning_vertex: ec1,
    skinnormal_vertex: tc1,
    specularmap_fragment: nc1,
    specularmap_pars_fragment: ic1,
    tonemapping_fragment: rc1,
    tonemapping_pars_fragment: ac1,
    transmission_fragment: oc1,
    transmission_pars_fragment: sc1,
    uv_pars_fragment: cc1,
    uv_pars_vertex: lc1,
    uv_vertex: fc1,
    worldpos_vertex: dc1,
    background_vert: uc1,
    background_frag: pc1,
    backgroundCube_vert: hc1,
    backgroundCube_frag: mc1,
    cube_vert: _c1,
    cube_frag: vc1,
    depth_vert: gc1,
    depth_frag: Sc1,
    distanceRGBA_vert: Ec1,
    distanceRGBA_frag: Mc1,
    equirect_vert: Tc1,
    equirect_frag: xc1,
    linedashed_vert: Ac1,
    linedashed_frag: Rc1,
    meshbasic_vert: Cc1,
    meshbasic_frag: bc1,
    meshlambert_vert: Pc1,
    meshlambert_frag: Lc1,
    meshmatcap_vert: Uc1,
    meshmatcap_frag: Dc1,
    meshnormal_vert: wc1,
    meshnormal_frag: Ic1,
    meshphong_vert: yc1,
    meshphong_frag: Nc1,
    meshphysical_vert: Oc1,
    meshphysical_frag: Fc1,
    meshtoon_vert: Bc1,
    meshtoon_frag: Gc1,
    points_vert: Hc1,
    points_frag: Vc1,
    shadow_vert: kc1,
    shadow_frag: zc1,
    sprite_vert: Wc1,
    sprite_frag: Xc1
}, ee1 = {
    common: {
        diffuse: {
            value: new P(16777215)
        },
        opacity: {
            value: 1
        },
        map: {
            value: null
        },
        mapTransform: {
            value: new Gt
        },
        alphaMap: {
            value: null
        },
        alphaMapTransform: {
            value: new Gt
        },
        alphaTest: {
            value: 0
        }
    },
    specularmap: {
        specularMap: {
            value: null
        },
        specularMapTransform: {
            value: new Gt
        }
    },
    envmap: {
        envMap: {
            value: null
        },
        envMapRotation: {
            value: new Gt
        },
        flipEnvMap: {
            value: -1
        },
        reflectivity: {
            value: 1
        },
        ior: {
            value: 1.5
        },
        refractionRatio: {
            value: .98
        }
    },
    aomap: {
        aoMap: {
            value: null
        },
        aoMapIntensity: {
            value: 1
        },
        aoMapTransform: {
            value: new Gt
        }
    },
    lightmap: {
        lightMap: {
            value: null
        },
        lightMapIntensity: {
            value: 1
        },
        lightMapTransform: {
            value: new Gt
        }
    },
    bumpmap: {
        bumpMap: {
            value: null
        },
        bumpMapTransform: {
            value: new Gt
        },
        bumpScale: {
            value: 1
        }
    },
    normalmap: {
        normalMap: {
            value: null
        },
        normalMapTransform: {
            value: new Gt
        },
        normalScale: {
            value: new T(1, 1)
        }
    },
    displacementmap: {
        displacementMap: {
            value: null
        },
        displacementMapTransform: {
            value: new Gt
        },
        displacementScale: {
            value: 1
        },
        displacementBias: {
            value: 0
        }
    },
    emissivemap: {
        emissiveMap: {
            value: null
        },
        emissiveMapTransform: {
            value: new Gt
        }
    },
    metalnessmap: {
        metalnessMap: {
            value: null
        },
        metalnessMapTransform: {
            value: new Gt
        }
    },
    roughnessmap: {
        roughnessMap: {
            value: null
        },
        roughnessMapTransform: {
            value: new Gt
        }
    },
    gradientmap: {
        gradientMap: {
            value: null
        }
    },
    fog: {
        fogDensity: {
            value: 25e-5
        },
        fogNear: {
            value: 1
        },
        fogFar: {
            value: 2e3
        },
        fogColor: {
            value: new P(16777215)
        }
    },
    lights: {
        ambientLightColor: {
            value: []
        },
        lightProbe: {
            value: []
        },
        directionalLights: {
            value: [],
            properties: {
                direction: {},
                color: {}
            }
        },
        directionalLightShadows: {
            value: [],
            properties: {
                shadowIntensity: 1,
                shadowBias: {},
                shadowNormalBias: {},
                shadowRadius: {},
                shadowMapSize: {}
            }
        },
        directionalShadowMap: {
            value: []
        },
        directionalShadowMatrix: {
            value: []
        },
        spotLights: {
            value: [],
            properties: {
                color: {},
                position: {},
                direction: {},
                distance: {},
                coneCos: {},
                penumbraCos: {},
                decay: {}
            }
        },
        spotLightShadows: {
            value: [],
            properties: {
                shadowIntensity: 1,
                shadowBias: {},
                shadowNormalBias: {},
                shadowRadius: {},
                shadowMapSize: {}
            }
        },
        spotLightMap: {
            value: []
        },
        spotShadowMap: {
            value: []
        },
        spotLightMatrix: {
            value: []
        },
        pointLights: {
            value: [],
            properties: {
                color: {},
                position: {},
                decay: {},
                distance: {}
            }
        },
        pointLightShadows: {
            value: [],
            properties: {
                shadowIntensity: 1,
                shadowBias: {},
                shadowNormalBias: {},
                shadowRadius: {},
                shadowMapSize: {},
                shadowCameraNear: {},
                shadowCameraFar: {}
            }
        },
        pointShadowMap: {
            value: []
        },
        pointShadowMatrix: {
            value: []
        },
        hemisphereLights: {
            value: [],
            properties: {
                direction: {},
                skyColor: {},
                groundColor: {}
            }
        },
        rectAreaLights: {
            value: [],
            properties: {
                color: {},
                position: {},
                width: {},
                height: {}
            }
        },
        ltc_1: {
            value: null
        },
        ltc_2: {
            value: null
        }
    },
    points: {
        diffuse: {
            value: new P(16777215)
        },
        opacity: {
            value: 1
        },
        size: {
            value: 1
        },
        scale: {
            value: 1
        },
        map: {
            value: null
        },
        alphaMap: {
            value: null
        },
        alphaMapTransform: {
            value: new Gt
        },
        alphaTest: {
            value: 0
        },
        uvTransform: {
            value: new Gt
        }
    },
    sprite: {
        diffuse: {
            value: new P(16777215)
        },
        opacity: {
            value: 1
        },
        center: {
            value: new T(.5, .5)
        },
        rotation: {
            value: 0
        },
        map: {
            value: null
        },
        mapTransform: {
            value: new Gt
        },
        alphaMap: {
            value: null
        },
        alphaMapTransform: {
            value: new Gt
        },
        alphaTest: {
            value: 0
        }
    }
}, gt1 = {
    basic: {
        uniforms: Iu([
            ee1.common,
            ee1.specularmap,
            ee1.envmap,
            ee1.aomap,
            ee1.lightmap,
            ee1.fog
        ]),
        vertexShader: Pe1.meshbasic_vert,
        fragmentShader: Pe1.meshbasic_frag
    },
    lambert: {
        uniforms: Iu([
            ee1.common,
            ee1.specularmap,
            ee1.envmap,
            ee1.aomap,
            ee1.lightmap,
            ee1.emissivemap,
            ee1.bumpmap,
            ee1.normalmap,
            ee1.displacementmap,
            ee1.fog,
            ee1.lights,
            {
                emissive: {
                    value: new P(0)
                }
            }
        ]),
        vertexShader: Pe1.meshlambert_vert,
        fragmentShader: Pe1.meshlambert_frag
    },
    phong: {
        uniforms: Iu([
            ee1.common,
            ee1.specularmap,
            ee1.envmap,
            ee1.aomap,
            ee1.lightmap,
            ee1.emissivemap,
            ee1.bumpmap,
            ee1.normalmap,
            ee1.displacementmap,
            ee1.fog,
            ee1.lights,
            {
                emissive: {
                    value: new P(0)
                },
                specular: {
                    value: new P(1118481)
                },
                shininess: {
                    value: 30
                }
            }
        ]),
        vertexShader: Pe1.meshphong_vert,
        fragmentShader: Pe1.meshphong_frag
    },
    standard: {
        uniforms: Iu([
            ee1.common,
            ee1.envmap,
            ee1.aomap,
            ee1.lightmap,
            ee1.emissivemap,
            ee1.bumpmap,
            ee1.normalmap,
            ee1.displacementmap,
            ee1.roughnessmap,
            ee1.metalnessmap,
            ee1.fog,
            ee1.lights,
            {
                emissive: {
                    value: new P(0)
                },
                roughness: {
                    value: 1
                },
                metalness: {
                    value: 0
                },
                envMapIntensity: {
                    value: 1
                }
            }
        ]),
        vertexShader: Pe1.meshphysical_vert,
        fragmentShader: Pe1.meshphysical_frag
    },
    toon: {
        uniforms: Iu([
            ee1.common,
            ee1.aomap,
            ee1.lightmap,
            ee1.emissivemap,
            ee1.bumpmap,
            ee1.normalmap,
            ee1.displacementmap,
            ee1.gradientmap,
            ee1.fog,
            ee1.lights,
            {
                emissive: {
                    value: new P(0)
                }
            }
        ]),
        vertexShader: Pe1.meshtoon_vert,
        fragmentShader: Pe1.meshtoon_frag
    },
    matcap: {
        uniforms: Iu([
            ee1.common,
            ee1.bumpmap,
            ee1.normalmap,
            ee1.displacementmap,
            ee1.fog,
            {
                matcap: {
                    value: null
                }
            }
        ]),
        vertexShader: Pe1.meshmatcap_vert,
        fragmentShader: Pe1.meshmatcap_frag
    },
    points: {
        uniforms: Iu([
            ee1.points,
            ee1.fog
        ]),
        vertexShader: Pe1.points_vert,
        fragmentShader: Pe1.points_frag
    },
    dashed: {
        uniforms: Iu([
            ee1.common,
            ee1.fog,
            {
                scale: {
                    value: 1
                },
                dashSize: {
                    value: 1
                },
                totalSize: {
                    value: 2
                }
            }
        ]),
        vertexShader: Pe1.linedashed_vert,
        fragmentShader: Pe1.linedashed_frag
    },
    depth: {
        uniforms: Iu([
            ee1.common,
            ee1.displacementmap
        ]),
        vertexShader: Pe1.depth_vert,
        fragmentShader: Pe1.depth_frag
    },
    normal: {
        uniforms: Iu([
            ee1.common,
            ee1.bumpmap,
            ee1.normalmap,
            ee1.displacementmap,
            {
                opacity: {
                    value: 1
                }
            }
        ]),
        vertexShader: Pe1.meshnormal_vert,
        fragmentShader: Pe1.meshnormal_frag
    },
    sprite: {
        uniforms: Iu([
            ee1.sprite,
            ee1.fog
        ]),
        vertexShader: Pe1.sprite_vert,
        fragmentShader: Pe1.sprite_frag
    },
    background: {
        uniforms: {
            uvTransform: {
                value: new Gt
            },
            t2D: {
                value: null
            },
            backgroundIntensity: {
                value: 1
            }
        },
        vertexShader: Pe1.background_vert,
        fragmentShader: Pe1.background_frag
    },
    backgroundCube: {
        uniforms: {
            envMap: {
                value: null
            },
            flipEnvMap: {
                value: -1
            },
            backgroundBlurriness: {
                value: 0
            },
            backgroundIntensity: {
                value: 1
            },
            backgroundRotation: {
                value: new Gt
            }
        },
        vertexShader: Pe1.backgroundCube_vert,
        fragmentShader: Pe1.backgroundCube_frag
    },
    cube: {
        uniforms: {
            tCube: {
                value: null
            },
            tFlip: {
                value: -1
            },
            opacity: {
                value: 1
            }
        },
        vertexShader: Pe1.cube_vert,
        fragmentShader: Pe1.cube_frag
    },
    equirect: {
        uniforms: {
            tEquirect: {
                value: null
            }
        },
        vertexShader: Pe1.equirect_vert,
        fragmentShader: Pe1.equirect_frag
    },
    distanceRGBA: {
        uniforms: Iu([
            ee1.common,
            ee1.displacementmap,
            {
                referencePosition: {
                    value: new w
                },
                nearDistance: {
                    value: 1
                },
                farDistance: {
                    value: 1e3
                }
            }
        ]),
        vertexShader: Pe1.distanceRGBA_vert,
        fragmentShader: Pe1.distanceRGBA_frag
    },
    shadow: {
        uniforms: Iu([
            ee1.lights,
            ee1.fog,
            {
                color: {
                    value: new P(0)
                },
                opacity: {
                    value: 1
                }
            }
        ]),
        vertexShader: Pe1.shadow_vert,
        fragmentShader: Pe1.shadow_frag
    }
};
gt1.physical = {
    uniforms: Iu([
        gt1.standard.uniforms,
        {
            clearcoat: {
                value: 0
            },
            clearcoatMap: {
                value: null
            },
            clearcoatMapTransform: {
                value: new Gt
            },
            clearcoatNormalMap: {
                value: null
            },
            clearcoatNormalMapTransform: {
                value: new Gt
            },
            clearcoatNormalScale: {
                value: new T(1, 1)
            },
            clearcoatRoughness: {
                value: 0
            },
            clearcoatRoughnessMap: {
                value: null
            },
            clearcoatRoughnessMapTransform: {
                value: new Gt
            },
            dispersion: {
                value: 0
            },
            iridescence: {
                value: 0
            },
            iridescenceMap: {
                value: null
            },
            iridescenceMapTransform: {
                value: new Gt
            },
            iridescenceIOR: {
                value: 1.3
            },
            iridescenceThicknessMinimum: {
                value: 100
            },
            iridescenceThicknessMaximum: {
                value: 400
            },
            iridescenceThicknessMap: {
                value: null
            },
            iridescenceThicknessMapTransform: {
                value: new Gt
            },
            sheen: {
                value: 0
            },
            sheenColor: {
                value: new P(0)
            },
            sheenColorMap: {
                value: null
            },
            sheenColorMapTransform: {
                value: new Gt
            },
            sheenRoughness: {
                value: 1
            },
            sheenRoughnessMap: {
                value: null
            },
            sheenRoughnessMapTransform: {
                value: new Gt
            },
            transmission: {
                value: 0
            },
            transmissionMap: {
                value: null
            },
            transmissionMapTransform: {
                value: new Gt
            },
            transmissionSamplerSize: {
                value: new T
            },
            transmissionSamplerMap: {
                value: null
            },
            thickness: {
                value: 0
            },
            thicknessMap: {
                value: null
            },
            thicknessMapTransform: {
                value: new Gt
            },
            attenuationDistance: {
                value: 0
            },
            attenuationColor: {
                value: new P(0)
            },
            specularColor: {
                value: new P(1, 1, 1)
            },
            specularColorMap: {
                value: null
            },
            specularColorMapTransform: {
                value: new Gt
            },
            specularIntensity: {
                value: 1
            },
            specularIntensityMap: {
                value: null
            },
            specularIntensityMapTransform: {
                value: new Gt
            },
            anisotropyVector: {
                value: new T
            },
            anisotropyMap: {
                value: null
            },
            anisotropyMapTransform: {
                value: new Gt
            }
        }
    ]),
    vertexShader: Pe1.meshphysical_vert,
    fragmentShader: Pe1.meshphysical_frag
};
var an1 = {
    r: 0,
    b: 0,
    g: 0
}, bt1 = new Xt, Yc1 = new D;
function qc1(e, n, t, i, c, s, h) {
    let d = new P(0), I = s === !0 ? 0 : 1, T, C, R = null, S = 0, x1 = null;
    function O(M) {
        let _ = M.isScene === !0 ? M.background : null;
        return _ && _.isTexture && (_ = (M.backgroundBlurriness > 0 ? t : n).get(_)), _;
    }
    function L(M) {
        let _ = !1, H = O(M);
        H === null ? r(d, I) : H && H.isColor && (r(H, 1), _ = !0);
        let P = e.xr.getEnvironmentBlendMode();
        P === "additive" ? i.buffers.color.setClear(0, 0, 0, 1, h) : P === "alpha-blend" && i.buffers.color.setClear(0, 0, 0, 0, h), (e.autoClear || _) && (i.buffers.depth.setTest(!0), i.buffers.depth.setMask(!0), i.buffers.color.setMask(!0), e.clear(e.autoClearColor, e.autoClearDepth, e.autoClearStencil));
    }
    function l(M, _) {
        let H = O(_);
        H && (H.isCubeTexture || H.mapping === Xl) ? (C === void 0 && (C = new Ct(new Ks(1, 1, 1), new qi({
            name: "BackgroundCubeMaterial",
            uniforms: An(gt1.backgroundCube.uniforms),
            vertexShader: gt1.backgroundCube.vertexShader,
            fragmentShader: gt1.backgroundCube.fragmentShader,
            side: Al,
            depthTest: !1,
            depthWrite: !1,
            fog: !1
        })), C.geometry.deleteAttribute("normal"), C.geometry.deleteAttribute("uv"), C.onBeforeRender = function(P, y1, B) {
            this.matrixWorld.copyPosition(B.matrixWorld);
        }, Object.defineProperty(C.material, "envMap", {
            get: function() {
                return this.uniforms.envMap.value;
            }
        }), c.update(C)), bt1.copy(_.backgroundRotation), bt1.x *= -1, bt1.y *= -1, bt1.z *= -1, H.isCubeTexture && H.isRenderTargetTexture === !1 && (bt1.y *= -1, bt1.z *= -1), C.material.uniforms.envMap.value = H, C.material.uniforms.flipEnvMap.value = H.isCubeTexture && H.isRenderTargetTexture === !1 ? -1 : 1, C.material.uniforms.backgroundBlurriness.value = _.backgroundBlurriness, C.material.uniforms.backgroundIntensity.value = _.backgroundIntensity, C.material.uniforms.backgroundRotation.value.setFromMatrix4(Yc1.makeRotationFromEuler(bt1)), C.material.toneMapped = Tt.getTransfer(H.colorSpace) !== Fn, (R !== H || S !== H.version || x1 !== e.toneMapping) && (C.material.needsUpdate = !0, R = H, S = H.version, x1 = e.toneMapping), C.layers.enableAll(), M.unshift(C, C.geometry, C.material, 0, 0, null)) : H && H.isTexture && (T === void 0 && (T = new Ct(new Zr(2, 2), new qi({
            name: "BackgroundMaterial",
            uniforms: An(gt1.background.uniforms),
            vertexShader: gt1.background.vertexShader,
            fragmentShader: gt1.background.fragmentShader,
            side: dr,
            depthTest: !1,
            depthWrite: !1,
            fog: !1
        })), T.geometry.deleteAttribute("normal"), Object.defineProperty(T.material, "map", {
            get: function() {
                return this.uniforms.t2D.value;
            }
        }), c.update(T)), T.material.uniforms.t2D.value = H, T.material.uniforms.backgroundIntensity.value = _.backgroundIntensity, T.material.toneMapped = Tt.getTransfer(H.colorSpace) !== Fn, H.matrixAutoUpdate === !0 && H.updateMatrix(), T.material.uniforms.uvTransform.value.copy(H.matrix), (R !== H || S !== H.version || x1 !== e.toneMapping) && (T.material.needsUpdate = !0, R = H, S = H.version, x1 = e.toneMapping), T.layers.enableAll(), M.unshift(T, T.geometry, T.material, 0, 0, null));
    }
    function r(M, _) {
        M.getRGB(an1, Rf(e)), i.buffers.color.setClear(an1.r, an1.g, an1.b, _, h);
    }
    function w() {
        C !== void 0 && (C.geometry.dispose(), C.material.dispose(), C = void 0), T !== void 0 && (T.geometry.dispose(), T.material.dispose(), T = void 0);
    }
    return {
        getClearColor: function() {
            return d;
        },
        setClearColor: function(M, _ = 1) {
            d.set(M), I = _, r(d, I);
        },
        getClearAlpha: function() {
            return I;
        },
        setClearAlpha: function(M) {
            I = M, r(d, I);
        },
        render: L,
        addToRenderList: l,
        dispose: w
    };
}
function Kc1(e, n) {
    let t = e.getParameter(e.MAX_VERTEX_ATTRIBS), i = {}, c = S(null), s = c, h = !1;
    function d(f, A, q, V, Y) {
        let Q = !1, z = R(V, q, A);
        s !== z && (s = z, T(s.object)), Q = x1(f, V, q, Y), Q && O(f, V, q, Y), Y !== null && n.update(Y, e.ELEMENT_ARRAY_BUFFER), (Q || h) && (h = !1, _(f, A, q, V), Y !== null && e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, n.get(Y).buffer));
    }
    function I() {
        return e.createVertexArray();
    }
    function T(f) {
        return e.bindVertexArray(f);
    }
    function C(f) {
        return e.deleteVertexArray(f);
    }
    function R(f, A, q) {
        let V = q.wireframe === !0, Y = i[f.id];
        Y === void 0 && (Y = {}, i[f.id] = Y);
        let Q = Y[A.id];
        Q === void 0 && (Q = {}, Y[A.id] = Q);
        let z = Q[V];
        return z === void 0 && (z = S(I()), Q[V] = z), z;
    }
    function S(f) {
        let A = [], q = [], V = [];
        for(let Y = 0; Y < t; Y++)A[Y] = 0, q[Y] = 0, V[Y] = 0;
        return {
            geometry: null,
            program: null,
            wireframe: !1,
            newAttributes: A,
            enabledAttributes: q,
            attributeDivisors: V,
            object: f,
            attributes: {},
            index: null
        };
    }
    function x1(f, A, q, V) {
        let Y = s.attributes, Q = A.attributes, z = 0, j = q.getAttributes();
        for(let F in j)if (j[F].location >= 0) {
            let Me = Y[F], Le = Q[F];
            if (Le === void 0 && (F === "instanceMatrix" && f.instanceMatrix && (Le = f.instanceMatrix), F === "instanceColor" && f.instanceColor && (Le = f.instanceColor)), Me === void 0 || Me.attribute !== Le || Le && Me.data !== Le.data) return !0;
            z++;
        }
        return s.attributesNum !== z || s.index !== V;
    }
    function O(f, A, q, V) {
        let Y = {}, Q = A.attributes, z = 0, j = q.getAttributes();
        for(let F in j)if (j[F].location >= 0) {
            let Me = Q[F];
            Me === void 0 && (F === "instanceMatrix" && f.instanceMatrix && (Me = f.instanceMatrix), F === "instanceColor" && f.instanceColor && (Me = f.instanceColor));
            let Le = {};
            Le.attribute = Me, Me && Me.data && (Le.data = Me.data), Y[F] = Le, z++;
        }
        s.attributes = Y, s.attributesNum = z, s.index = V;
    }
    function L() {
        let f = s.newAttributes;
        for(let A = 0, q = f.length; A < q; A++)f[A] = 0;
    }
    function l(f) {
        r(f, 0);
    }
    function r(f, A) {
        let q = s.newAttributes, V = s.enabledAttributes, Y = s.attributeDivisors;
        q[f] = 1, V[f] === 0 && (e.enableVertexAttribArray(f), V[f] = 1), Y[f] !== A && (e.vertexAttribDivisor(f, A), Y[f] = A);
    }
    function w() {
        let f = s.newAttributes, A = s.enabledAttributes;
        for(let q = 0, V = A.length; q < V; q++)A[q] !== f[q] && (e.disableVertexAttribArray(q), A[q] = 0);
    }
    function M(f, A, q, V, Y, Q, z) {
        z === !0 ? e.vertexAttribIPointer(f, A, q, Y, Q) : e.vertexAttribPointer(f, A, q, V, Y, Q);
    }
    function _(f, A, q, V) {
        L();
        let Y = V.attributes, Q = q.getAttributes(), z = A.defaultAttributeValues;
        for(let j in Q){
            let F = Q[j];
            if (F.location >= 0) {
                let me = Y[j];
                if (me === void 0 && (j === "instanceMatrix" && f.instanceMatrix && (me = f.instanceMatrix), j === "instanceColor" && f.instanceColor && (me = f.instanceColor)), me !== void 0) {
                    let Me = me.normalized, Le = me.itemSize, Ge = n.get(me);
                    if (Ge === void 0) continue;
                    let Ze = Ge.buffer, k = Ge.type, J = Ge.bytesPerElement, ue = k === e.INT || k === e.UNSIGNED_INT || me.gpuType === Kl;
                    if (me.isInterleavedBufferAttribute) {
                        let ie = me.data, Ee = ie.stride, Be = me.offset;
                        if (ie.isInstancedInterleavedBuffer) {
                            for(let Te = 0; Te < F.locationSize; Te++)r(F.location + Te, ie.meshPerAttribute);
                            f.isInstancedMesh !== !0 && V._maxInstanceCount === void 0 && (V._maxInstanceCount = ie.meshPerAttribute * ie.count);
                        } else for(let Te = 0; Te < F.locationSize; Te++)l(F.location + Te);
                        e.bindBuffer(e.ARRAY_BUFFER, Ze);
                        for(let Te = 0; Te < F.locationSize; Te++)M(F.location + Te, Le / F.locationSize, k, Me, Ee * J, (Be + Le / F.locationSize * Te) * J, ue);
                    } else {
                        if (me.isInstancedBufferAttribute) {
                            for(let ie = 0; ie < F.locationSize; ie++)r(F.location + ie, me.meshPerAttribute);
                            f.isInstancedMesh !== !0 && V._maxInstanceCount === void 0 && (V._maxInstanceCount = me.meshPerAttribute * me.count);
                        } else for(let ie = 0; ie < F.locationSize; ie++)l(F.location + ie);
                        e.bindBuffer(e.ARRAY_BUFFER, Ze);
                        for(let ie = 0; ie < F.locationSize; ie++)M(F.location + ie, Le / F.locationSize, k, Me, Le * J, Le / F.locationSize * ie * J, ue);
                    }
                } else if (z !== void 0) {
                    let Me = z[j];
                    if (Me !== void 0) switch(Me.length){
                        case 2:
                            e.vertexAttrib2fv(F.location, Me);
                            break;
                        case 3:
                            e.vertexAttrib3fv(F.location, Me);
                            break;
                        case 4:
                            e.vertexAttrib4fv(F.location, Me);
                            break;
                        default:
                            e.vertexAttrib1fv(F.location, Me);
                    }
                }
            }
        }
        w();
    }
    function H() {
        B();
        for(let f in i){
            let A = i[f];
            for(let q in A){
                let V = A[q];
                for(let Y in V)C(V[Y].object), delete V[Y];
                delete A[q];
            }
            delete i[f];
        }
    }
    function P(f) {
        if (i[f.id] === void 0) return;
        let A = i[f.id];
        for(let q in A){
            let V = A[q];
            for(let Y in V)C(V[Y].object), delete V[Y];
            delete A[q];
        }
        delete i[f.id];
    }
    function y1(f) {
        for(let A in i){
            let q = i[A];
            if (q[f.id] === void 0) continue;
            let V = q[f.id];
            for(let Y in V)C(V[Y].object), delete V[Y];
            delete q[f.id];
        }
    }
    function B() {
        p(), h = !0, s !== c && (s = c, T(s.object));
    }
    function p() {
        c.geometry = null, c.program = null, c.wireframe = !1;
    }
    return {
        setup: d,
        reset: B,
        resetDefaultState: p,
        dispose: H,
        releaseStatesOfGeometry: P,
        releaseStatesOfProgram: y1,
        initAttributes: L,
        enableAttribute: l,
        disableUnusedAttributes: w
    };
}
function $c1(e, n, t) {
    let i;
    function c(T) {
        i = T;
    }
    function s(T, C) {
        e.drawArrays(i, T, C), t.update(C, i, 1);
    }
    function h(T, C, R) {
        R !== 0 && (e.drawArraysInstanced(i, T, C, R), t.update(C, i, R));
    }
    function d(T, C, R) {
        if (R === 0) return;
        n.get("WEBGL_multi_draw").multiDrawArraysWEBGL(i, T, 0, C, 0, R);
        let x1 = 0;
        for(let O = 0; O < R; O++)x1 += C[O];
        t.update(x1, i, 1);
    }
    function I(T, C, R, S) {
        if (R === 0) return;
        let x1 = n.get("WEBGL_multi_draw");
        if (x1 === null) for(let O = 0; O < T.length; O++)h(T[O], C[O], S[O]);
        else {
            x1.multiDrawArraysInstancedWEBGL(i, T, 0, C, 0, S, 0, R);
            let O = 0;
            for(let L = 0; L < R; L++)O += C[L] * S[L];
            t.update(O, i, 1);
        }
    }
    this.setMode = c, this.render = s, this.renderInstances = h, this.renderMultiDraw = d, this.renderMultiDrawInstances = I;
}
function Zc1(e, n, t, i) {
    let c;
    function s() {
        if (c !== void 0) return c;
        if (n.has("EXT_texture_filter_anisotropic") === !0) {
            let y1 = n.get("EXT_texture_filter_anisotropic");
            c = e.getParameter(y1.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
        } else c = 0;
        return c;
    }
    function h(y1) {
        return !(y1 !== Li && i.convert(y1) !== e.getParameter(e.IMPLEMENTATION_COLOR_READ_FORMAT));
    }
    function d(y1) {
        let B = y1 === tc && (n.has("EXT_color_buffer_half_float") || n.has("EXT_color_buffer_float"));
        return !(y1 !== Sl && i.convert(y1) !== e.getParameter(e.IMPLEMENTATION_COLOR_READ_TYPE) && y1 !== pi && !B);
    }
    function I(y1) {
        if (y1 === "highp") {
            if (e.getShaderPrecisionFormat(e.VERTEX_SHADER, e.HIGH_FLOAT).precision > 0 && e.getShaderPrecisionFormat(e.FRAGMENT_SHADER, e.HIGH_FLOAT).precision > 0) return "highp";
            y1 = "mediump";
        }
        return y1 === "mediump" && e.getShaderPrecisionFormat(e.VERTEX_SHADER, e.MEDIUM_FLOAT).precision > 0 && e.getShaderPrecisionFormat(e.FRAGMENT_SHADER, e.MEDIUM_FLOAT).precision > 0 ? "mediump" : "lowp";
    }
    let T = t.precision !== void 0 ? t.precision : "highp", C = I(T);
    C !== T && (console.warn("THREE.WebGLRenderer:", T, "not supported, using", C, "instead."), T = C);
    let R = t.logarithmicDepthBuffer === !0, S = t.reverseDepthBuffer === !0 && n.has("EXT_clip_control"), x1 = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), O = e.getParameter(e.MAX_VERTEX_TEXTURE_IMAGE_UNITS), L = e.getParameter(e.MAX_TEXTURE_SIZE), l = e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE), r = e.getParameter(e.MAX_VERTEX_ATTRIBS), w = e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS), M = e.getParameter(e.MAX_VARYING_VECTORS), _ = e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS), H = O > 0, P = e.getParameter(e.MAX_SAMPLES);
    return {
        isWebGL2: !0,
        getMaxAnisotropy: s,
        getMaxPrecision: I,
        textureFormatReadable: h,
        textureTypeReadable: d,
        precision: T,
        logarithmicDepthBuffer: R,
        reverseDepthBuffer: S,
        maxTextures: x1,
        maxVertexTextures: O,
        maxTextureSize: L,
        maxCubemapSize: l,
        maxAttributes: r,
        maxVertexUniforms: w,
        maxVaryings: M,
        maxFragmentUniforms: _,
        vertexTextures: H,
        maxSamples: P
    };
}
function Qc1(e) {
    let n = this, t = null, i = 0, c = !1, s = !1, h = new xe, d = new Gt, I = {
        value: null,
        needsUpdate: !1
    };
    this.uniform = I, this.numPlanes = 0, this.numIntersection = 0, this.init = function(R, S) {
        let x1 = R.length !== 0 || S || i !== 0 || c;
        return c = S, i = R.length, x1;
    }, this.beginShadows = function() {
        s = !0, C(null);
    }, this.endShadows = function() {
        s = !1;
    }, this.setGlobalState = function(R, S) {
        t = C(R, S, 0);
    }, this.setState = function(R, S, x1) {
        let O = R.clippingPlanes, L = R.clipIntersection, l = R.clipShadows, r = e.get(R);
        if (!c || O === null || O.length === 0 || s && !l) s ? C(null) : T();
        else {
            let w = s ? 0 : i, M = w * 4, _ = r.clippingState || null;
            I.value = _, _ = C(O, S, M, x1);
            for(let H = 0; H !== M; ++H)_[H] = t[H];
            r.clippingState = _, this.numIntersection = L ? this.numPlanes : 0, this.numPlanes += w;
        }
    };
    function T() {
        I.value !== t && (I.value = t, I.needsUpdate = i > 0), n.numPlanes = i, n.numIntersection = 0;
    }
    function C(R, S, x1, O) {
        let L = R !== null ? R.length : 0, l = null;
        if (L !== 0) {
            if (l = I.value, O !== !0 || l === null) {
                let r = x1 + L * 4, w = S.matrixWorldInverse;
                d.getNormalMatrix(w), (l === null || l.length < r) && (l = new Float32Array(r));
                for(let M = 0, _ = x1; M !== L; ++M, _ += 4)h.copy(R[M]).applyMatrix4(w, d), h.normal.toArray(l, _), l[_ + 3] = h.constant;
            }
            I.value = l, I.needsUpdate = !0;
        }
        return n.numPlanes = L, n.numIntersection = 0, l;
    }
}
function Jc1(e) {
    let n = new WeakMap;
    function t(h, d) {
        return d === ql ? h.mapping = Uo : d === Gl && (h.mapping = Hl), h;
    }
    function i(h) {
        if (h && h.isTexture) {
            let d = h.mapping;
            if (d === ql || d === Gl) if (n.has(h)) {
                let I = n.get(h).texture;
                return t(I, h.mapping);
            } else {
                let I = h.image;
                if (I && I.height > 0) {
                    let T = new Na(I.height);
                    return T.fromEquirectangularTexture(e, h), n.set(h, T), h.addEventListener("dispose", c), t(T.texture, h.mapping);
                } else return null;
            }
        }
        return h;
    }
    function c(h) {
        let d = h.target;
        d.removeEventListener("dispose", c);
        let I = n.get(d);
        I !== void 0 && (n.delete(d), I.dispose());
    }
    function s() {
        n = new WeakMap;
    }
    return {
        get: i,
        dispose: s
    };
}
var Ht1 = 4, Gi1 = [
    .125,
    .215,
    .35,
    .446,
    .526,
    .582
], Ut1 = 20, Pn1 = new wn, Hi1 = new P, Ln1 = null, Un1 = 0, Dn1 = 0, wn1 = !1, Lt1 = (1 + Math.sqrt(5)) / 2, Ot = 1 / Lt1, Vi1 = [
    new w(-Lt1, Ot, 0),
    new w(Lt1, Ot, 0),
    new w(-Ot, 0, Lt1),
    new w(Ot, 0, Lt1),
    new w(0, Lt1, -Ot),
    new w(0, Lt1, Ot),
    new w(-1, 1, -1),
    new w(1, 1, -1),
    new w(-1, 1, 1),
    new w(1, 1, 1)
], hn1 = class {
    constructor(n){
        this._renderer = n, this._pingPongRenderTarget = null, this._lodMax = 0, this._cubeSize = 0, this._lodPlanes = [], this._sizeLods = [], this._sigmas = [], this._blurMaterial = null, this._cubemapMaterial = null, this._equirectMaterial = null, this._compileMaterial(this._blurMaterial);
    }
    fromScene(n, t = 0, i = .1, c = 100) {
        Ln1 = this._renderer.getRenderTarget(), Un1 = this._renderer.getActiveCubeFace(), Dn1 = this._renderer.getActiveMipmapLevel(), wn1 = this._renderer.xr.enabled, this._renderer.xr.enabled = !1, this._setSize(256);
        let s = this._allocateTargets();
        return s.depthBuffer = !0, this._sceneToCubeUV(n, i, c, s), t > 0 && this._blur(s, 0, 0, t), this._applyPMREM(s), this._cleanup(s), s;
    }
    fromEquirectangular(n, t = null) {
        return this._fromTexture(n, t);
    }
    fromCubemap(n, t = null) {
        return this._fromTexture(n, t);
    }
    compileCubemapShader() {
        this._cubemapMaterial === null && (this._cubemapMaterial = Wi1(), this._compileMaterial(this._cubemapMaterial));
    }
    compileEquirectangularShader() {
        this._equirectMaterial === null && (this._equirectMaterial = zi1(), this._compileMaterial(this._equirectMaterial));
    }
    dispose() {
        this._dispose(), this._cubemapMaterial !== null && this._cubemapMaterial.dispose(), this._equirectMaterial !== null && this._equirectMaterial.dispose();
    }
    _setSize(n) {
        this._lodMax = Math.floor(Math.log2(n)), this._cubeSize = Math.pow(2, this._lodMax);
    }
    _dispose() {
        this._blurMaterial !== null && this._blurMaterial.dispose(), this._pingPongRenderTarget !== null && this._pingPongRenderTarget.dispose();
        for(let n = 0; n < this._lodPlanes.length; n++)this._lodPlanes[n].dispose();
    }
    _cleanup(n) {
        this._renderer.setRenderTarget(Ln1, Un1, Dn1), this._renderer.xr.enabled = wn1, n.scissorTest = !1, on1(n, 0, 0, n.width, n.height);
    }
    _fromTexture(n, t) {
        n.mapping === Uo || n.mapping === Hl ? this._setSize(n.image.length === 0 ? 16 : n.image[0].width || n.image[0].image.width) : this._setSize(n.image.width / 4), Ln1 = this._renderer.getRenderTarget(), Un1 = this._renderer.getActiveCubeFace(), Dn1 = this._renderer.getActiveMipmapLevel(), wn1 = this._renderer.xr.enabled, this._renderer.xr.enabled = !1;
        let i = t || this._allocateTargets();
        return this._textureToCubeUV(n, i), this._applyPMREM(i), this._cleanup(i), i;
    }
    _allocateTargets() {
        let n = 3 * Math.max(this._cubeSize, 112), t = 4 * this._cubeSize, i = {
            magFilter: Et,
            minFilter: Et,
            generateMipmaps: !1,
            type: tc,
            format: Li,
            colorSpace: ha,
            depthBuffer: !1
        }, c = ki1(n, t, i);
        if (this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== n || this._pingPongRenderTarget.height !== t) {
            this._pingPongRenderTarget !== null && this._dispose(), this._pingPongRenderTarget = ki1(n, t, i);
            let { _lodMax: s  } = this;
            ({ sizeLods: this._sizeLods , lodPlanes: this._lodPlanes , sigmas: this._sigmas  } = jc1(s)), this._blurMaterial = el1(s, n, t);
        }
        return c;
    }
    _compileMaterial(n) {
        let t = new Ct(this._lodPlanes[0], n);
        this._renderer.compile(t, Pn1);
    }
    _sceneToCubeUV(n, t, i, c) {
        let d = new vt(90, 1, t, i), I = [
            1,
            -1,
            1,
            1,
            1,
            1
        ], T = [
            1,
            1,
            1,
            -1,
            -1,
            -1
        ], C = this._renderer, R = C.autoClear, S = C.toneMapping;
        C.getClearColor(Hi1), C.toneMapping = Tp, C.autoClear = !1;
        let x1 = new _e({
            name: "PMREM.Background",
            side: Al,
            depthWrite: !1,
            depthTest: !1
        }), O = new Ct(new Ks, x1), L = !1, l = n.background;
        l ? l.isColor && (x1.color.copy(l), n.background = null, L = !0) : (x1.color.copy(Hi1), L = !0);
        for(let r = 0; r < 6; r++){
            let w = r % 3;
            w === 0 ? (d.up.set(0, I[r], 0), d.lookAt(T[r], 0, 0)) : w === 1 ? (d.up.set(0, 0, I[r]), d.lookAt(0, T[r], 0)) : (d.up.set(0, I[r], 0), d.lookAt(0, 0, T[r]));
            let M = this._cubeSize;
            on1(c, w * M, r > 2 ? M : 0, M, M), C.setRenderTarget(c), L && C.render(O, d), C.render(n, d);
        }
        O.geometry.dispose(), O.material.dispose(), C.toneMapping = S, C.autoClear = R, n.background = l;
    }
    _textureToCubeUV(n, t) {
        let i = this._renderer, c = n.mapping === Uo || n.mapping === Hl;
        c ? (this._cubemapMaterial === null && (this._cubemapMaterial = Wi1()), this._cubemapMaterial.uniforms.flipEnvMap.value = n.isRenderTargetTexture === !1 ? -1 : 1) : this._equirectMaterial === null && (this._equirectMaterial = zi1());
        let s = c ? this._cubemapMaterial : this._equirectMaterial, h = new Ct(this._lodPlanes[0], s), d = s.uniforms;
        d.envMap.value = n;
        let I = this._cubeSize;
        on1(t, 0, 0, 3 * I, 2 * I), i.setRenderTarget(t), i.render(h, Pn1);
    }
    _applyPMREM(n) {
        let t = this._renderer, i = t.autoClear;
        t.autoClear = !1;
        let c = this._lodPlanes.length;
        for(let s = 1; s < c; s++){
            let h = Math.sqrt(this._sigmas[s] * this._sigmas[s] - this._sigmas[s - 1] * this._sigmas[s - 1]), d = Vi1[(c - s - 1) % Vi1.length];
            this._blur(n, s - 1, s, h, d);
        }
        t.autoClear = i;
    }
    _blur(n, t, i, c, s) {
        let h = this._pingPongRenderTarget;
        this._halfBlur(n, h, t, i, c, "latitudinal", s), this._halfBlur(h, n, i, i, c, "longitudinal", s);
    }
    _halfBlur(n, t, i, c, s, h, d) {
        let I = this._renderer, T = this._blurMaterial;
        h !== "latitudinal" && h !== "longitudinal" && console.error("blur direction must be either latitudinal or longitudinal!");
        let C = 3, R = new Ct(this._lodPlanes[c], T), S = T.uniforms, x1 = this._sizeLods[i] - 1, O = isFinite(s) ? Math.PI / (2 * x1) : 2 * Math.PI / (2 * Ut1 - 1), L = s / O, l = isFinite(s) ? 1 + Math.floor(C * L) : Ut1;
        l > Ut1 && console.warn(`sigmaRadians, ${s}, is too large and will clip, as it requested ${l} samples when the maximum is set to ${Ut1}`);
        let r = [], w = 0;
        for(let y1 = 0; y1 < Ut1; ++y1){
            let B = y1 / L, p = Math.exp(-B * B / 2);
            r.push(p), y1 === 0 ? w += p : y1 < l && (w += 2 * p);
        }
        for(let y1 = 0; y1 < r.length; y1++)r[y1] = r[y1] / w;
        S.envMap.value = n.texture, S.samples.value = l, S.weights.value = r, S.latitudinal.value = h === "latitudinal", d && (S.poleAxis.value = d);
        let { _lodMax: M  } = this;
        S.dTheta.value = O, S.mipInt.value = M - i;
        let _ = this._sizeLods[c], H = 3 * _ * (c > M - Ht1 ? c - M + Ht1 : 0), P = 4 * (this._cubeSize - _);
        on1(t, H, P, 3 * _, 2 * _), I.setRenderTarget(t), I.render(R, Pn1);
    }
};
function jc1(e) {
    let n = [], t = [], i = [], c = e, s = e - Ht1 + 1 + Gi1.length;
    for(let h = 0; h < s; h++){
        let d = Math.pow(2, c);
        t.push(d);
        let I = 1 / d;
        h > e - Ht1 ? I = Gi1[h - e + Ht1 - 1] : h === 0 && (I = 0), i.push(I);
        let T = 1 / (d - 2), C = -T, R = 1 + T, S = [
            C,
            C,
            R,
            C,
            R,
            R,
            C,
            C,
            R,
            R,
            C,
            R
        ], x1 = 6, O = 6, L1 = 3, l = 2, r = 1, w = new Float32Array(L1 * O * x1), M = new Float32Array(l * O * x1), _ = new Float32Array(r * O * x1);
        for(let P = 0; P < x1; P++){
            let y1 = P % 3 * 2 / 3 - 1, B = P > 2 ? 0 : -1, p = [
                y1,
                B,
                0,
                y1 + 2 / 3,
                B,
                0,
                y1 + 2 / 3,
                B + 1,
                0,
                y1,
                B,
                0,
                y1 + 2 / 3,
                B + 1,
                0,
                y1,
                B + 1,
                0
            ];
            w.set(p, L1 * O * P), M.set(S, l * O * P);
            let f = [
                P,
                P,
                P,
                P,
                P,
                P
            ];
            _.set(f, r * O * P);
        }
        let H = new L;
        H.setAttribute("position", new Z(w, L1)), H.setAttribute("uv", new Z(M, l)), H.setAttribute("faceIndex", new Z(_, r)), n.push(H), c > Ht1 && c--;
    }
    return {
        lodPlanes: n,
        sizeLods: t,
        sigmas: i
    };
}
function ki1(e, n, t) {
    let i = new Hi(e, n, t);
    return i.texture.mapping = Xl, i.texture.name = "PMREM.cubeUv", i.scissorTest = !0, i;
}
function on1(e, n, t, i, c) {
    e.viewport.set(n, t, i, c), e.scissor.set(n, t, i, c);
}
function el1(e, n, t) {
    let i = new Float32Array(Ut1), c = new w(0, 1, 0);
    return new qi({
        name: "SphericalGaussianBlur",
        defines: {
            n: Ut1,
            CUBEUV_TEXEL_WIDTH: 1 / n,
            CUBEUV_TEXEL_HEIGHT: 1 / t,
            CUBEUV_MAX_MIP: `${e}.0`
        },
        uniforms: {
            envMap: {
                value: null
            },
            samples: {
                value: 1
            },
            weights: {
                value: i
            },
            latitudinal: {
                value: !1
            },
            dTheta: {
                value: 0
            },
            mipInt: {
                value: 0
            },
            poleAxis: {
                value: c
            }
        },
        vertexShader: Jn1(),
        fragmentShader: `

			precision mediump float;
			precision mediump int;

			varying vec3 vOutputDirection;

			uniform sampler2D envMap;
			uniform int samples;
			uniform float weights[ n ];
			uniform bool latitudinal;
			uniform float dTheta;
			uniform float mipInt;
			uniform vec3 poleAxis;

			#define ENVMAP_TYPE_CUBE_UV
			#include <cube_uv_reflection_fragment>

			vec3 getSample( float theta, vec3 axis ) {

				float cosTheta = cos( theta );
				// Rodrigues' axis-angle rotation
				vec3 sampleDirection = vOutputDirection * cosTheta
					+ cross( axis, vOutputDirection ) * sin( theta )
					+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );

				return bilinearCubeUV( envMap, sampleDirection, mipInt );

			}

			void main() {

				vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );

				if ( all( equal( axis, vec3( 0.0 ) ) ) ) {

					axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );

				}

				axis = normalize( axis );

				gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
				gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );

				for ( int i = 1; i < n; i++ ) {

					if ( i >= samples ) {

						break;

					}

					float theta = dTheta * float( i );
					gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
					gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );

				}

			}
		`,
        blending: Ul,
        depthTest: !1,
        depthWrite: !1
    });
}
function zi1() {
    return new qi({
        name: "EquirectangularToCubeUV",
        uniforms: {
            envMap: {
                value: null
            }
        },
        vertexShader: Jn1(),
        fragmentShader: `

			precision mediump float;
			precision mediump int;

			varying vec3 vOutputDirection;

			uniform sampler2D envMap;

			#include <common>

			void main() {

				vec3 outputDirection = normalize( vOutputDirection );
				vec2 uv = equirectUv( outputDirection );

				gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );

			}
		`,
        blending: Ul,
        depthTest: !1,
        depthWrite: !1
    });
}
function Wi1() {
    return new qi({
        name: "CubemapToCubeUV",
        uniforms: {
            envMap: {
                value: null
            },
            flipEnvMap: {
                value: -1
            }
        },
        vertexShader: Jn1(),
        fragmentShader: `

			precision mediump float;
			precision mediump int;

			uniform float flipEnvMap;

			varying vec3 vOutputDirection;

			uniform samplerCube envMap;

			void main() {

				gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );

			}
		`,
        blending: Ul,
        depthTest: !1,
        depthWrite: !1
    });
}
function Jn1() {
    return `

		precision mediump float;
		precision mediump int;

		attribute float faceIndex;

		varying vec3 vOutputDirection;

		// RH coordinate system; PMREM face-indexing convention
		vec3 getDirection( vec2 uv, float face ) {

			uv = 2.0 * uv - 1.0;

			vec3 direction = vec3( uv, 1.0 );

			if ( face == 0.0 ) {

				direction = direction.zyx; // ( 1, v, u ) pos x

			} else if ( face == 1.0 ) {

				direction = direction.xzy;
				direction.xz *= -1.0; // ( -u, 1, -v ) pos y

			} else if ( face == 2.0 ) {

				direction.x *= -1.0; // ( -u, v, 1 ) pos z

			} else if ( face == 3.0 ) {

				direction = direction.zyx;
				direction.xz *= -1.0; // ( -1, v, -u ) neg x

			} else if ( face == 4.0 ) {

				direction = direction.xzy;
				direction.xy *= -1.0; // ( -u, -1, v ) neg y

			} else if ( face == 5.0 ) {

				direction.z *= -1.0; // ( u, v, -1 ) neg z

			}

			return direction;

		}

		void main() {

			vOutputDirection = getDirection( uv, faceIndex );
			gl_Position = vec4( position, 1.0 );

		}
	`;
}
function tl1(e) {
    let n = new WeakMap, t = null;
    function i(d) {
        if (d && d.isTexture) {
            let I = d.mapping, T = I === ql || I === Gl, C = I === Uo || I === Hl;
            if (T || C) {
                let R = n.get(d), S = R !== void 0 ? R.texture.pmremVersion : 0;
                if (d.isRenderTargetTexture && d.pmremVersion !== S) return t === null && (t = new hn1(e)), R = T ? t.fromEquirectangular(d, R) : t.fromCubemap(d, R), R.texture.pmremVersion = d.pmremVersion, n.set(d, R), R.texture;
                if (R !== void 0) return R.texture;
                {
                    let x1 = d.image;
                    return T && x1 && x1.height > 0 || C && x1 && c(x1) ? (t === null && (t = new hn1(e)), R = T ? t.fromEquirectangular(d) : t.fromCubemap(d), R.texture.pmremVersion = d.pmremVersion, n.set(d, R), d.addEventListener("dispose", s), R.texture) : null;
                }
            }
        }
        return d;
    }
    function c(d) {
        let I = 0, T = 6;
        for(let C = 0; C < T; C++)d[C] !== void 0 && I++;
        return I === T;
    }
    function s(d) {
        let I = d.target;
        I.removeEventListener("dispose", s);
        let T = n.get(I);
        T !== void 0 && (n.delete(I), T.dispose());
    }
    function h() {
        n = new WeakMap, t !== null && (t.dispose(), t = null);
    }
    return {
        get: i,
        dispose: h
    };
}
function nl1(e) {
    let n = {};
    function t(i) {
        if (n[i] !== void 0) return n[i];
        let c;
        switch(i){
            case "WEBGL_depth_texture":
                c = e.getExtension("WEBGL_depth_texture") || e.getExtension("MOZ_WEBGL_depth_texture") || e.getExtension("WEBKIT_WEBGL_depth_texture");
                break;
            case "EXT_texture_filter_anisotropic":
                c = e.getExtension("EXT_texture_filter_anisotropic") || e.getExtension("MOZ_EXT_texture_filter_anisotropic") || e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");
                break;
            case "WEBGL_compressed_texture_s3tc":
                c = e.getExtension("WEBGL_compressed_texture_s3tc") || e.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");
                break;
            case "WEBGL_compressed_texture_pvrtc":
                c = e.getExtension("WEBGL_compressed_texture_pvrtc") || e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");
                break;
            default:
                c = e.getExtension(i);
        }
        return n[i] = c, c;
    }
    return {
        has: function(i) {
            return t(i) !== null;
        },
        init: function() {
            t("EXT_color_buffer_float"), t("WEBGL_clip_cull_distance"), t("OES_texture_float_linear"), t("EXT_color_buffer_half_float"), t("WEBGL_multisampled_render_to_texture"), t("WEBGL_render_shared_exponent");
        },
        get: function(i) {
            let c = t(i);
            return c === null && Cf("THREE.WebGLRenderer: " + i + " extension not supported."), c;
        }
    };
}
function il1(e, n, t, i) {
    let c = {}, s = new WeakMap;
    function h(R) {
        let S = R.target;
        S.index !== null && n.remove(S.index);
        for(let O in S.attributes)n.remove(S.attributes[O]);
        S.removeEventListener("dispose", h), delete c[S.id];
        let x1 = s.get(S);
        x1 && (n.remove(x1), s.delete(S)), i.releaseStatesOfGeometry(S), S.isInstancedBufferGeometry === !0 && delete S._maxInstanceCount, t.memory.geometries--;
    }
    function d(R, S) {
        return c[S.id] === !0 || (S.addEventListener("dispose", h), c[S.id] = !0, t.memory.geometries++), S;
    }
    function I(R) {
        let S = R.attributes;
        for(let x1 in S)n.update(S[x1], e.ARRAY_BUFFER);
    }
    function T(R) {
        let S = [], x1 = R.index, O = R.attributes.position, L = 0;
        if (x1 !== null) {
            let w = x1.array;
            L = x1.version;
            for(let M = 0, _ = w.length; M < _; M += 3){
                let H = w[M + 0], P = w[M + 1], y1 = w[M + 2];
                S.push(H, P, P, y1, y1, H);
            }
        } else if (O !== void 0) {
            let w = O.array;
            L = O.version;
            for(let M = 0, _ = w.length / 3 - 1; M < _; M += 3){
                let H = M + 0, P = M + 1, y1 = M + 2;
                S.push(H, P, P, y1, y1, H);
            }
        } else return;
        let l = new (cu(S) ? xr : gr)(S, 1);
        l.version = L;
        let r = s.get(R);
        r && n.remove(r), s.set(R, l);
    }
    function C(R) {
        let S = s.get(R);
        if (S) {
            let x1 = R.index;
            x1 !== null && S.version < x1.version && T(R);
        } else T(R);
        return s.get(R);
    }
    return {
        get: d,
        update: I,
        getWireframeAttribute: C
    };
}
function rl1(e, n, t) {
    let i;
    function c(S) {
        i = S;
    }
    let s, h;
    function d(S) {
        s = S.type, h = S.bytesPerElement;
    }
    function I(S, x1) {
        e.drawElements(i, x1, s, S * h), t.update(x1, i, 1);
    }
    function T(S, x1, O) {
        O !== 0 && (e.drawElementsInstanced(i, x1, s, S * h, O), t.update(x1, i, O));
    }
    function C(S, x1, O) {
        if (O === 0) return;
        n.get("WEBGL_multi_draw").multiDrawElementsWEBGL(i, x1, 0, s, S, 0, O);
        let l = 0;
        for(let r = 0; r < O; r++)l += x1[r];
        t.update(l, i, 1);
    }
    function R(S, x1, O, L) {
        if (O === 0) return;
        let l = n.get("WEBGL_multi_draw");
        if (l === null) for(let r = 0; r < S.length; r++)T(S[r] / h, x1[r], L[r]);
        else {
            l.multiDrawElementsInstancedWEBGL(i, x1, 0, s, S, 0, L, 0, O);
            let r = 0;
            for(let w = 0; w < O; w++)r += x1[w] * L[w];
            t.update(r, i, 1);
        }
    }
    this.setMode = c, this.setIndex = d, this.render = I, this.renderInstances = T, this.renderMultiDraw = C, this.renderMultiDrawInstances = R;
}
function al1(e) {
    let n = {
        geometries: 0,
        textures: 0
    }, t = {
        frame: 0,
        calls: 0,
        triangles: 0,
        points: 0,
        lines: 0
    };
    function i(s, h, d) {
        switch(t.calls++, h){
            case e.TRIANGLES:
                t.triangles += d * (s / 3);
                break;
            case e.LINES:
                t.lines += d * (s / 2);
                break;
            case e.LINE_STRIP:
                t.lines += d * (s - 1);
                break;
            case e.LINE_LOOP:
                t.lines += d * s;
                break;
            case e.POINTS:
                t.points += d * s;
                break;
            default:
                console.error("THREE.WebGLInfo: Unknown draw mode:", h);
                break;
        }
    }
    function c() {
        t.calls = 0, t.triangles = 0, t.points = 0, t.lines = 0;
    }
    return {
        memory: n,
        render: t,
        programs: null,
        autoReset: !0,
        reset: c,
        update: i
    };
}
function ol1(e, n, t) {
    let i = new WeakMap, c = new ot;
    function s(h, d, I) {
        let T1 = h.morphTargetInfluences, C = d.morphAttributes.position || d.morphAttributes.normal || d.morphAttributes.color, R = C !== void 0 ? C.length : 0, S = i.get(d);
        if (S === void 0 || S.count !== R) {
            let p = function() {
                y1.dispose(), i.delete(d), d.removeEventListener("dispose", p);
            };
            S !== void 0 && S.texture.dispose();
            let x1 = d.morphAttributes.position !== void 0, O = d.morphAttributes.normal !== void 0, L = d.morphAttributes.color !== void 0, l = d.morphAttributes.position || [], r = d.morphAttributes.normal || [], w = d.morphAttributes.color || [], M = 0;
            x1 === !0 && (M = 1), O === !0 && (M = 2), L === !0 && (M = 3);
            let _ = d.attributes.position.count * M, H = 1;
            _ > n.maxTextureSize && (H = Math.ceil(_ / n.maxTextureSize), _ = n.maxTextureSize);
            let P = new Float32Array(_ * H * 4 * R), y1 = new $s(P, _, H, R);
            y1.type = pi, y1.needsUpdate = !0;
            let B = M * 4;
            for(let f = 0; f < R; f++){
                let A = l[f], q = r[f], V = w[f], Y = _ * H * 4 * f;
                for(let Q = 0; Q < A.count; Q++){
                    let z = Q * B;
                    x1 === !0 && (c.fromBufferAttribute(A, Q), P[Y + z + 0] = c.x, P[Y + z + 1] = c.y, P[Y + z + 2] = c.z, P[Y + z + 3] = 0), O === !0 && (c.fromBufferAttribute(q, Q), P[Y + z + 4] = c.x, P[Y + z + 5] = c.y, P[Y + z + 6] = c.z, P[Y + z + 7] = 0), L === !0 && (c.fromBufferAttribute(V, Q), P[Y + z + 8] = c.x, P[Y + z + 9] = c.y, P[Y + z + 10] = c.z, P[Y + z + 11] = V.itemSize === 4 ? c.w : 1);
                }
            }
            S = {
                count: R,
                texture: y1,
                size: new T(_, H)
            }, i.set(d, S), d.addEventListener("dispose", p);
        }
        if (h.isInstancedMesh === !0 && h.morphTexture !== null) I.getUniforms().setValue(e, "morphTexture", h.morphTexture, t);
        else {
            let x1 = 0;
            for(let L = 0; L < T1.length; L++)x1 += T1[L];
            let O = d.morphTargetsRelative ? 1 : 1 - x1;
            I.getUniforms().setValue(e, "morphTargetBaseInfluence", O), I.getUniforms().setValue(e, "morphTargetInfluences", T1);
        }
        I.getUniforms().setValue(e, "morphTargetsTexture", S.texture, t), I.getUniforms().setValue(e, "morphTargetsTextureSize", S.size);
    }
    return {
        update: s
    };
}
function sl1(e, n, t, i) {
    let c = new WeakMap;
    function s(I) {
        let T = i.render.frame, C = I.geometry, R = n.get(I, C);
        if (c.get(R) !== T && (n.update(R), c.set(R, T)), I.isInstancedMesh && (I.hasEventListener("dispose", d) === !1 && I.addEventListener("dispose", d), c.get(I) !== T && (t.update(I.instanceMatrix, e.ARRAY_BUFFER), I.instanceColor !== null && t.update(I.instanceColor, e.ARRAY_BUFFER), c.set(I, T))), I.isSkinnedMesh) {
            let S = I.skeleton;
            c.get(S) !== T && (S.update(), c.set(S, T));
        }
        return R;
    }
    function h() {
        c = new WeakMap;
    }
    function d(I) {
        let T = I.target;
        T.removeEventListener("dispose", d), t.remove(T.instanceMatrix), T.instanceColor !== null && t.remove(T.instanceColor);
    }
    return {
        update: s,
        dispose: h
    };
}
var Pr1 = new lt, Xi1 = new hh(1, 1), Lr1 = new $s, Ur1 = new Qs, Dr1 = new Xi, Yi1 = [], qi1 = [], Ki1 = new Float32Array(16), $i1 = new Float32Array(9), Zi1 = new Float32Array(4);
function Xt1(e, n, t) {
    let i = e[0];
    if (i <= 0 || i > 0) return e;
    let c = n * t, s = Yi1[c];
    if (s === void 0 && (s = new Float32Array(c), Yi1[c] = s), n !== 0) {
        i.toArray(s, 0);
        for(let h = 1, d = 0; h !== n; ++h)d += t, e[h].toArray(s, d);
    }
    return s;
}
function nt1(e, n) {
    if (e.length !== n.length) return !1;
    for(let t = 0, i = e.length; t < i; t++)if (e[t] !== n[t]) return !1;
    return !0;
}
function it1(e, n) {
    for(let t = 0, i = n.length; t < i; t++)e[t] = n[t];
}
function gn1(e, n) {
    let t = qi1[n];
    t === void 0 && (t = new Int32Array(n), qi1[n] = t);
    for(let i = 0; i !== n; ++i)t[i] = e.allocateTextureUnit();
    return t;
}
function cl1(e, n) {
    let t = this.cache;
    t[0] !== n && (e.uniform1f(this.addr, n), t[0] = n);
}
function ll1(e, n) {
    let t = this.cache;
    if (n.x !== void 0) (t[0] !== n.x || t[1] !== n.y) && (e.uniform2f(this.addr, n.x, n.y), t[0] = n.x, t[1] = n.y);
    else {
        if (nt1(t, n)) return;
        e.uniform2fv(this.addr, n), it1(t, n);
    }
}
function fl1(e, n) {
    let t = this.cache;
    if (n.x !== void 0) (t[0] !== n.x || t[1] !== n.y || t[2] !== n.z) && (e.uniform3f(this.addr, n.x, n.y, n.z), t[0] = n.x, t[1] = n.y, t[2] = n.z);
    else if (n.r !== void 0) (t[0] !== n.r || t[1] !== n.g || t[2] !== n.b) && (e.uniform3f(this.addr, n.r, n.g, n.b), t[0] = n.r, t[1] = n.g, t[2] = n.b);
    else {
        if (nt1(t, n)) return;
        e.uniform3fv(this.addr, n), it1(t, n);
    }
}
function dl1(e, n) {
    let t = this.cache;
    if (n.x !== void 0) (t[0] !== n.x || t[1] !== n.y || t[2] !== n.z || t[3] !== n.w) && (e.uniform4f(this.addr, n.x, n.y, n.z, n.w), t[0] = n.x, t[1] = n.y, t[2] = n.z, t[3] = n.w);
    else {
        if (nt1(t, n)) return;
        e.uniform4fv(this.addr, n), it1(t, n);
    }
}
function ul1(e, n) {
    let t = this.cache, i = n.elements;
    if (i === void 0) {
        if (nt1(t, n)) return;
        e.uniformMatrix2fv(this.addr, !1, n), it1(t, n);
    } else {
        if (nt1(t, i)) return;
        Zi1.set(i), e.uniformMatrix2fv(this.addr, !1, Zi1), it1(t, i);
    }
}
function pl1(e, n) {
    let t = this.cache, i = n.elements;
    if (i === void 0) {
        if (nt1(t, n)) return;
        e.uniformMatrix3fv(this.addr, !1, n), it1(t, n);
    } else {
        if (nt1(t, i)) return;
        $i1.set(i), e.uniformMatrix3fv(this.addr, !1, $i1), it1(t, i);
    }
}
function hl1(e, n) {
    let t = this.cache, i = n.elements;
    if (i === void 0) {
        if (nt1(t, n)) return;
        e.uniformMatrix4fv(this.addr, !1, n), it1(t, n);
    } else {
        if (nt1(t, i)) return;
        Ki1.set(i), e.uniformMatrix4fv(this.addr, !1, Ki1), it1(t, i);
    }
}
function ml1(e, n) {
    let t = this.cache;
    t[0] !== n && (e.uniform1i(this.addr, n), t[0] = n);
}
function _l1(e, n) {
    let t = this.cache;
    if (n.x !== void 0) (t[0] !== n.x || t[1] !== n.y) && (e.uniform2i(this.addr, n.x, n.y), t[0] = n.x, t[1] = n.y);
    else {
        if (nt1(t, n)) return;
        e.uniform2iv(this.addr, n), it1(t, n);
    }
}
function vl1(e, n) {
    let t = this.cache;
    if (n.x !== void 0) (t[0] !== n.x || t[1] !== n.y || t[2] !== n.z) && (e.uniform3i(this.addr, n.x, n.y, n.z), t[0] = n.x, t[1] = n.y, t[2] = n.z);
    else {
        if (nt1(t, n)) return;
        e.uniform3iv(this.addr, n), it1(t, n);
    }
}
function gl1(e, n) {
    let t = this.cache;
    if (n.x !== void 0) (t[0] !== n.x || t[1] !== n.y || t[2] !== n.z || t[3] !== n.w) && (e.uniform4i(this.addr, n.x, n.y, n.z, n.w), t[0] = n.x, t[1] = n.y, t[2] = n.z, t[3] = n.w);
    else {
        if (nt1(t, n)) return;
        e.uniform4iv(this.addr, n), it1(t, n);
    }
}
function Sl1(e, n) {
    let t = this.cache;
    t[0] !== n && (e.uniform1ui(this.addr, n), t[0] = n);
}
function El1(e, n) {
    let t = this.cache;
    if (n.x !== void 0) (t[0] !== n.x || t[1] !== n.y) && (e.uniform2ui(this.addr, n.x, n.y), t[0] = n.x, t[1] = n.y);
    else {
        if (nt1(t, n)) return;
        e.uniform2uiv(this.addr, n), it1(t, n);
    }
}
function Ml1(e, n) {
    let t = this.cache;
    if (n.x !== void 0) (t[0] !== n.x || t[1] !== n.y || t[2] !== n.z) && (e.uniform3ui(this.addr, n.x, n.y, n.z), t[0] = n.x, t[1] = n.y, t[2] = n.z);
    else {
        if (nt1(t, n)) return;
        e.uniform3uiv(this.addr, n), it1(t, n);
    }
}
function Tl1(e, n) {
    let t = this.cache;
    if (n.x !== void 0) (t[0] !== n.x || t[1] !== n.y || t[2] !== n.z || t[3] !== n.w) && (e.uniform4ui(this.addr, n.x, n.y, n.z, n.w), t[0] = n.x, t[1] = n.y, t[2] = n.z, t[3] = n.w);
    else {
        if (nt1(t, n)) return;
        e.uniform4uiv(this.addr, n), it1(t, n);
    }
}
function xl1(e, n, t) {
    let i = this.cache, c = t.allocateTextureUnit();
    i[0] !== c && (e.uniform1i(this.addr, c), i[0] = c);
    let s;
    this.type === e.SAMPLER_2D_SHADOW ? (Xi1.compareFunction = cf, s = Xi1) : s = Pr1, t.setTexture2D(n || s, c);
}
function Al1(e, n, t) {
    let i = this.cache, c = t.allocateTextureUnit();
    i[0] !== c && (e.uniform1i(this.addr, c), i[0] = c), t.setTexture3D(n || Ur1, c);
}
function Rl1(e, n, t) {
    let i = this.cache, c = t.allocateTextureUnit();
    i[0] !== c && (e.uniform1i(this.addr, c), i[0] = c), t.setTextureCube(n || Dr1, c);
}
function Cl1(e, n, t) {
    let i = this.cache, c = t.allocateTextureUnit();
    i[0] !== c && (e.uniform1i(this.addr, c), i[0] = c), t.setTexture2DArray(n || Lr1, c);
}
function bl1(e) {
    switch(e){
        case 5126:
            return cl1;
        case 35664:
            return ll1;
        case 35665:
            return fl1;
        case 35666:
            return dl1;
        case 35674:
            return ul1;
        case 35675:
            return pl1;
        case 35676:
            return hl1;
        case 5124:
        case 35670:
            return ml1;
        case 35667:
        case 35671:
            return _l1;
        case 35668:
        case 35672:
            return vl1;
        case 35669:
        case 35673:
            return gl1;
        case 5125:
            return Sl1;
        case 36294:
            return El1;
        case 36295:
            return Ml1;
        case 36296:
            return Tl1;
        case 35678:
        case 36198:
        case 36298:
        case 36306:
        case 35682:
            return xl1;
        case 35679:
        case 36299:
        case 36307:
            return Al1;
        case 35680:
        case 36300:
        case 36308:
        case 36293:
            return Rl1;
        case 36289:
        case 36303:
        case 36311:
        case 36292:
            return Cl1;
    }
}
function Pl1(e, n) {
    e.uniform1fv(this.addr, n);
}
function Ll(e, n) {
    let t = Xt1(n, this.size, 2);
    e.uniform2fv(this.addr, t);
}
function Ul1(e, n) {
    let t = Xt1(n, this.size, 3);
    e.uniform3fv(this.addr, t);
}
function Dl(e, n) {
    let t = Xt1(n, this.size, 4);
    e.uniform4fv(this.addr, t);
}
function wl1(e, n) {
    let t = Xt1(n, this.size, 4);
    e.uniformMatrix2fv(this.addr, !1, t);
}
function Il1(e, n) {
    let t = Xt1(n, this.size, 9);
    e.uniformMatrix3fv(this.addr, !1, t);
}
function yl1(e, n) {
    let t = Xt1(n, this.size, 16);
    e.uniformMatrix4fv(this.addr, !1, t);
}
function Nl1(e, n) {
    e.uniform1iv(this.addr, n);
}
function Ol1(e, n) {
    e.uniform2iv(this.addr, n);
}
function Fl1(e, n) {
    e.uniform3iv(this.addr, n);
}
function Bl1(e, n) {
    e.uniform4iv(this.addr, n);
}
function Gl1(e, n) {
    e.uniform1uiv(this.addr, n);
}
function Hl1(e, n) {
    e.uniform2uiv(this.addr, n);
}
function Vl(e, n) {
    e.uniform3uiv(this.addr, n);
}
function kl1(e, n) {
    e.uniform4uiv(this.addr, n);
}
function zl1(e, n, t) {
    let i = this.cache, c = n.length, s = gn1(t, c);
    nt1(i, s) || (e.uniform1iv(this.addr, s), it1(i, s));
    for(let h = 0; h !== c; ++h)t.setTexture2D(n[h] || Pr1, s[h]);
}
function Wl1(e, n, t) {
    let i = this.cache, c = n.length, s = gn1(t, c);
    nt1(i, s) || (e.uniform1iv(this.addr, s), it1(i, s));
    for(let h = 0; h !== c; ++h)t.setTexture3D(n[h] || Ur1, s[h]);
}
function Xl1(e, n, t) {
    let i = this.cache, c = n.length, s = gn1(t, c);
    nt1(i, s) || (e.uniform1iv(this.addr, s), it1(i, s));
    for(let h = 0; h !== c; ++h)t.setTextureCube(n[h] || Dr1, s[h]);
}
function Yl1(e, n, t) {
    let i = this.cache, c = n.length, s = gn1(t, c);
    nt1(i, s) || (e.uniform1iv(this.addr, s), it1(i, s));
    for(let h = 0; h !== c; ++h)t.setTexture2DArray(n[h] || Lr1, s[h]);
}
function ql1(e) {
    switch(e){
        case 5126:
            return Pl1;
        case 35664:
            return Ll;
        case 35665:
            return Ul1;
        case 35666:
            return Dl;
        case 35674:
            return wl1;
        case 35675:
            return Il1;
        case 35676:
            return yl1;
        case 5124:
        case 35670:
            return Nl1;
        case 35667:
        case 35671:
            return Ol1;
        case 35668:
        case 35672:
            return Fl1;
        case 35669:
        case 35673:
            return Bl1;
        case 5125:
            return Gl1;
        case 36294:
            return Hl1;
        case 36295:
            return Vl;
        case 36296:
            return kl1;
        case 35678:
        case 36198:
        case 36298:
        case 36306:
        case 35682:
            return zl1;
        case 35679:
        case 36299:
        case 36307:
            return Wl1;
        case 35680:
        case 36300:
        case 36308:
        case 36293:
            return Xl1;
        case 36289:
        case 36303:
        case 36311:
        case 36292:
            return Yl1;
    }
}
var zn1 = class {
    constructor(n, t, i){
        this.id = n, this.addr = i, this.cache = [], this.type = t.type, this.setValue = bl1(t.type);
    }
}, Wn1 = class {
    constructor(n, t, i){
        this.id = n, this.addr = i, this.cache = [], this.type = t.type, this.size = t.size, this.setValue = ql1(t.type);
    }
}, Xn1 = class {
    constructor(n){
        this.id = n, this.seq = [], this.map = {};
    }
    setValue(n, t, i) {
        let c = this.seq;
        for(let s = 0, h = c.length; s !== h; ++s){
            let d = c[s];
            d.setValue(n, t[d.id], i);
        }
    }
}, In = /(\w+)(\])?(\[|\.)?/g;
function Qi1(e, n) {
    e.seq.push(n), e.map[n.id] = n;
}
function Kl1(e, n, t) {
    let i = e.name, c = i.length;
    for(In.lastIndex = 0;;){
        let s = In.exec(i), h = In.lastIndex, d = s[1], I = s[2] === "]", T = s[3];
        if (I && (d = d | 0), T === void 0 || T === "[" && h + 2 === c) {
            Qi1(t, T === void 0 ? new zn1(d, e, n) : new Wn1(d, e, n));
            break;
        } else {
            let R = t.map[d];
            R === void 0 && (R = new Xn1(d), Qi1(t, R)), t = R;
        }
    }
}
var Vt1 = class {
    constructor(n, t){
        this.seq = [], this.map = {};
        let i = n.getProgramParameter(t, n.ACTIVE_UNIFORMS);
        for(let c = 0; c < i; ++c){
            let s = n.getActiveUniform(t, c), h = n.getUniformLocation(t, s.name);
            Kl1(s, h, this);
        }
    }
    setValue(n, t, i, c) {
        let s = this.map[t];
        s !== void 0 && s.setValue(n, i, c);
    }
    setOptional(n, t, i) {
        let c = t[i];
        c !== void 0 && this.setValue(n, i, c);
    }
    static upload(n, t, i, c) {
        for(let s = 0, h = t.length; s !== h; ++s){
            let d = t[s], I = i[d.id];
            I.needsUpdate !== !1 && d.setValue(n, I.value, c);
        }
    }
    static seqWithValue(n, t) {
        let i = [];
        for(let c = 0, s = n.length; c !== s; ++c){
            let h = n[c];
            h.id in t && i.push(h);
        }
        return i;
    }
};
function Ji1(e, n, t) {
    let i = e.createShader(n);
    return e.shaderSource(i, t), e.compileShader(i), i;
}
var $l1 = 37297, Zl1 = 0;
function Ql1(e, n) {
    let t = e.split(`
`), i = [], c = Math.max(n - 6, 0), s = Math.min(n + 6, t.length);
    for(let h = c; h < s; h++){
        let d = h + 1;
        i.push(`${d === n ? ">" : " "} ${d}: ${t[h]}`);
    }
    return i.join(`
`);
}
var ji1 = new Gt;
function Jl1(e) {
    Tt._getMatrix(ji1, Tt.workingColorSpace, e);
    let n = `mat3( ${ji1.elements.map((t)=>t.toFixed(4))} )`;
    switch(Tt.getTransfer(e)){
        case la:
            return [
                n,
                "LinearTransferOETF"
            ];
        case Fn:
            return [
                n,
                "sRGBTransferOETF"
            ];
        default:
            return console.warn("THREE.WebGLProgram: Unsupported color space: ", e), [
                n,
                "LinearTransferOETF"
            ];
    }
}
function er1(e, n, t) {
    let i = e.getShaderParameter(n, e.COMPILE_STATUS), c = e.getShaderInfoLog(n).trim();
    if (i && c === "") return "";
    let s = /ERROR: 0:(\d+)/.exec(c);
    if (s) {
        let h = parseInt(s[1]);
        return t.toUpperCase() + `

` + c + `

` + Ql1(e.getShaderSource(n), h);
    } else return c;
}
function jl1(e, n) {
    let t = Jl1(n);
    return [
        `vec4 ${e}( vec4 value ) {`,
        `	return ${t[1]}( vec4( value.rgb * ${t[0]}, value.a ) );`,
        "}"
    ].join(`
`);
}
function ef1(e, n) {
    let t;
    switch(n){
        case Ip:
            t = "Linear";
            break;
        case Cp:
            t = "Reinhard";
            break;
        case zp:
            t = "Cineon";
            break;
        case Fp:
            t = "ACESFilmic";
            break;
        case Ep:
            t = "AgX";
            break;
        case Rp:
            t = "Neutral";
            break;
        case Bp:
            t = "Custom";
            break;
        default:
            console.warn("THREE.WebGLProgram: Unsupported toneMapping:", n), t = "Linear";
    }
    return "vec3 " + e + "( vec3 color ) { return " + t + "ToneMapping( color ); }";
}
var sn1 = new w;
function tf1() {
    Tt.getLuminanceCoefficients(sn1);
    let e = sn1.x.toFixed(4), n = sn1.y.toFixed(4), t = sn1.z.toFixed(4);
    return [
        "float luminance( const in vec3 rgb ) {",
        `	const vec3 weights = vec3( ${e}, ${n}, ${t} );`,
        "	return dot( weights, rgb );",
        "}"
    ].join(`
`);
}
function nf1(e) {
    return [
        e.extensionClipCullDistance ? "#extension GL_ANGLE_clip_cull_distance : require" : "",
        e.extensionMultiDraw ? "#extension GL_ANGLE_multi_draw : require" : ""
    ].filter($t).join(`
`);
}
function rf1(e) {
    let n = [];
    for(let t in e){
        let i = e[t];
        i !== !1 && n.push("#define " + t + " " + i);
    }
    return n.join(`
`);
}
function af1(e, n) {
    let t = {}, i = e.getProgramParameter(n, e.ACTIVE_ATTRIBUTES);
    for(let c = 0; c < i; c++){
        let s = e.getActiveAttrib(n, c), h = s.name, d = 1;
        s.type === e.FLOAT_MAT2 && (d = 2), s.type === e.FLOAT_MAT3 && (d = 3), s.type === e.FLOAT_MAT4 && (d = 4), t[h] = {
            type: s.type,
            location: e.getAttribLocation(n, h),
            locationSize: d
        };
    }
    return t;
}
function $t(e) {
    return e !== "";
}
function tr1(e, n) {
    let t = n.numSpotLightShadows + n.numSpotLightMaps - n.numSpotLightShadowsWithMaps;
    return e.replace(/NUM_DIR_LIGHTS/g, n.numDirLights).replace(/NUM_SPOT_LIGHTS/g, n.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g, n.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g, t).replace(/NUM_RECT_AREA_LIGHTS/g, n.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g, n.numPointLights).replace(/NUM_HEMI_LIGHTS/g, n.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g, n.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g, n.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g, n.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g, n.numPointLightShadows);
}
function nr1(e, n) {
    return e.replace(/NUM_CLIPPING_PLANES/g, n.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, n.numClippingPlanes - n.numClipIntersection);
}
var of1 = /^[ \t]*#include +<([\w\d./]+)>/gm;
function Yn1(e) {
    return e.replace(of1, cf1);
}
var sf1 = new Map;
function cf1(e, n) {
    let t = Pe1[n];
    if (t === void 0) {
        let i = sf1.get(n);
        if (i !== void 0) t = Pe1[i], console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.', n, i);
        else throw new Error("Can not resolve #include <" + n + ">");
    }
    return Yn1(t);
}
var lf1 = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;
function ir1(e) {
    return e.replace(lf1, ff1);
}
function ff1(e, n, t, i) {
    let c = "";
    for(let s = parseInt(n); s < parseInt(t); s++)c += i.replace(/\[\s*i\s*\]/g, "[ " + s + " ]").replace(/UNROLLED_LOOP_INDEX/g, s);
    return c;
}
function rr1(e) {
    let n = `precision ${e.precision} float;
	precision ${e.precision} int;
	precision ${e.precision} sampler2D;
	precision ${e.precision} samplerCube;
	precision ${e.precision} sampler3D;
	precision ${e.precision} sampler2DArray;
	precision ${e.precision} sampler2DShadow;
	precision ${e.precision} samplerCubeShadow;
	precision ${e.precision} sampler2DArrayShadow;
	precision ${e.precision} isampler2D;
	precision ${e.precision} isampler3D;
	precision ${e.precision} isamplerCube;
	precision ${e.precision} isampler2DArray;
	precision ${e.precision} usampler2D;
	precision ${e.precision} usampler3D;
	precision ${e.precision} usamplerCube;
	precision ${e.precision} usampler2DArray;
	`;
    return e.precision === "highp" ? n += `
#define HIGH_PRECISION` : e.precision === "mediump" ? n += `
#define MEDIUM_PRECISION` : e.precision === "lowp" && (n += `
#define LOW_PRECISION`), n;
}
function df1(e) {
    let n = "SHADOWMAP_TYPE_BASIC";
    return e.shadowMapType === Xd ? n = "SHADOWMAP_TYPE_PCF" : e.shadowMapType === Jd ? n = "SHADOWMAP_TYPE_PCF_SOFT" : e.shadowMapType === Zd && (n = "SHADOWMAP_TYPE_VSM"), n;
}
function uf1(e) {
    let n = "ENVMAP_TYPE_CUBE";
    if (e.envMap) switch(e.envMapMode){
        case Uo:
        case Hl:
            n = "ENVMAP_TYPE_CUBE";
            break;
        case Xl:
            n = "ENVMAP_TYPE_CUBE_UV";
            break;
    }
    return n;
}
function pf1(e) {
    let n = "ENVMAP_MODE_REFLECTION";
    if (e.envMap) switch(e.envMapMode){
        case Hl:
            n = "ENVMAP_MODE_REFRACTION";
            break;
    }
    return n;
}
function hf1(e) {
    let n = "ENVMAP_BLENDING_NONE";
    if (e.envMap) switch(e.combine){
        case Do:
            n = "ENVMAP_BLENDING_MULTIPLY";
            break;
        case Ap:
            n = "ENVMAP_BLENDING_MIX";
            break;
        case Sp:
            n = "ENVMAP_BLENDING_ADD";
            break;
    }
    return n;
}
function mf1(e) {
    let n = e.envMapCubeUVHeight;
    if (n === null) return null;
    let t = Math.log2(n) - 2, i = 1 / n;
    return {
        texelWidth: 1 / (3 * Math.max(Math.pow(2, t), 7 * 16)),
        texelHeight: i,
        maxMip: t
    };
}
function _f1(e, n, t, i) {
    let c = e.getContext(), s = t.defines, h = t.vertexShader, d = t.fragmentShader, I = df1(t), T = uf1(t), C = pf1(t), R = hf1(t), S = mf1(t), x1 = nf1(t), O = rf1(s), L = c.createProgram(), l, r, w = t.glslVersion ? "#version " + t.glslVersion + `
` : "";
    t.isRawShaderMaterial ? (l = [
        "#define SHADER_TYPE " + t.shaderType,
        "#define SHADER_NAME " + t.shaderName,
        O
    ].filter($t).join(`
`), l.length > 0 && (l += `
`), r = [
        "#define SHADER_TYPE " + t.shaderType,
        "#define SHADER_NAME " + t.shaderName,
        O
    ].filter($t).join(`
`), r.length > 0 && (r += `
`)) : (l = [
        rr1(t),
        "#define SHADER_TYPE " + t.shaderType,
        "#define SHADER_NAME " + t.shaderName,
        O,
        t.extensionClipCullDistance ? "#define USE_CLIP_DISTANCE" : "",
        t.batching ? "#define USE_BATCHING" : "",
        t.batchingColor ? "#define USE_BATCHING_COLOR" : "",
        t.instancing ? "#define USE_INSTANCING" : "",
        t.instancingColor ? "#define USE_INSTANCING_COLOR" : "",
        t.instancingMorph ? "#define USE_INSTANCING_MORPH" : "",
        t.useFog && t.fog ? "#define USE_FOG" : "",
        t.useFog && t.fogExp2 ? "#define FOG_EXP2" : "",
        t.map ? "#define USE_MAP" : "",
        t.envMap ? "#define USE_ENVMAP" : "",
        t.envMap ? "#define " + C : "",
        t.lightMap ? "#define USE_LIGHTMAP" : "",
        t.aoMap ? "#define USE_AOMAP" : "",
        t.bumpMap ? "#define USE_BUMPMAP" : "",
        t.normalMap ? "#define USE_NORMALMAP" : "",
        t.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "",
        t.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "",
        t.displacementMap ? "#define USE_DISPLACEMENTMAP" : "",
        t.emissiveMap ? "#define USE_EMISSIVEMAP" : "",
        t.anisotropy ? "#define USE_ANISOTROPY" : "",
        t.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "",
        t.clearcoatMap ? "#define USE_CLEARCOATMAP" : "",
        t.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "",
        t.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "",
        t.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "",
        t.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "",
        t.specularMap ? "#define USE_SPECULARMAP" : "",
        t.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "",
        t.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "",
        t.roughnessMap ? "#define USE_ROUGHNESSMAP" : "",
        t.metalnessMap ? "#define USE_METALNESSMAP" : "",
        t.alphaMap ? "#define USE_ALPHAMAP" : "",
        t.alphaHash ? "#define USE_ALPHAHASH" : "",
        t.transmission ? "#define USE_TRANSMISSION" : "",
        t.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "",
        t.thicknessMap ? "#define USE_THICKNESSMAP" : "",
        t.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "",
        t.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "",
        t.mapUv ? "#define MAP_UV " + t.mapUv : "",
        t.alphaMapUv ? "#define ALPHAMAP_UV " + t.alphaMapUv : "",
        t.lightMapUv ? "#define LIGHTMAP_UV " + t.lightMapUv : "",
        t.aoMapUv ? "#define AOMAP_UV " + t.aoMapUv : "",
        t.emissiveMapUv ? "#define EMISSIVEMAP_UV " + t.emissiveMapUv : "",
        t.bumpMapUv ? "#define BUMPMAP_UV " + t.bumpMapUv : "",
        t.normalMapUv ? "#define NORMALMAP_UV " + t.normalMapUv : "",
        t.displacementMapUv ? "#define DISPLACEMENTMAP_UV " + t.displacementMapUv : "",
        t.metalnessMapUv ? "#define METALNESSMAP_UV " + t.metalnessMapUv : "",
        t.roughnessMapUv ? "#define ROUGHNESSMAP_UV " + t.roughnessMapUv : "",
        t.anisotropyMapUv ? "#define ANISOTROPYMAP_UV " + t.anisotropyMapUv : "",
        t.clearcoatMapUv ? "#define CLEARCOATMAP_UV " + t.clearcoatMapUv : "",
        t.clearcoatNormalMapUv ? "#define CLEARCOAT_NORMALMAP_UV " + t.clearcoatNormalMapUv : "",
        t.clearcoatRoughnessMapUv ? "#define CLEARCOAT_ROUGHNESSMAP_UV " + t.clearcoatRoughnessMapUv : "",
        t.iridescenceMapUv ? "#define IRIDESCENCEMAP_UV " + t.iridescenceMapUv : "",
        t.iridescenceThicknessMapUv ? "#define IRIDESCENCE_THICKNESSMAP_UV " + t.iridescenceThicknessMapUv : "",
        t.sheenColorMapUv ? "#define SHEEN_COLORMAP_UV " + t.sheenColorMapUv : "",
        t.sheenRoughnessMapUv ? "#define SHEEN_ROUGHNESSMAP_UV " + t.sheenRoughnessMapUv : "",
        t.specularMapUv ? "#define SPECULARMAP_UV " + t.specularMapUv : "",
        t.specularColorMapUv ? "#define SPECULAR_COLORMAP_UV " + t.specularColorMapUv : "",
        t.specularIntensityMapUv ? "#define SPECULAR_INTENSITYMAP_UV " + t.specularIntensityMapUv : "",
        t.transmissionMapUv ? "#define TRANSMISSIONMAP_UV " + t.transmissionMapUv : "",
        t.thicknessMapUv ? "#define THICKNESSMAP_UV " + t.thicknessMapUv : "",
        t.vertexTangents && t.flatShading === !1 ? "#define USE_TANGENT" : "",
        t.vertexColors ? "#define USE_COLOR" : "",
        t.vertexAlphas ? "#define USE_COLOR_ALPHA" : "",
        t.vertexUv1s ? "#define USE_UV1" : "",
        t.vertexUv2s ? "#define USE_UV2" : "",
        t.vertexUv3s ? "#define USE_UV3" : "",
        t.pointsUvs ? "#define USE_POINTS_UV" : "",
        t.flatShading ? "#define FLAT_SHADED" : "",
        t.skinning ? "#define USE_SKINNING" : "",
        t.morphTargets ? "#define USE_MORPHTARGETS" : "",
        t.morphNormals && t.flatShading === !1 ? "#define USE_MORPHNORMALS" : "",
        t.morphColors ? "#define USE_MORPHCOLORS" : "",
        t.morphTargetsCount > 0 ? "#define MORPHTARGETS_TEXTURE_STRIDE " + t.morphTextureStride : "",
        t.morphTargetsCount > 0 ? "#define MORPHTARGETS_COUNT " + t.morphTargetsCount : "",
        t.doubleSided ? "#define DOUBLE_SIDED" : "",
        t.flipSided ? "#define FLIP_SIDED" : "",
        t.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
        t.shadowMapEnabled ? "#define " + I : "",
        t.sizeAttenuation ? "#define USE_SIZEATTENUATION" : "",
        t.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "",
        t.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
        t.reverseDepthBuffer ? "#define USE_REVERSEDEPTHBUF" : "",
        "uniform mat4 modelMatrix;",
        "uniform mat4 modelViewMatrix;",
        "uniform mat4 projectionMatrix;",
        "uniform mat4 viewMatrix;",
        "uniform mat3 normalMatrix;",
        "uniform vec3 cameraPosition;",
        "uniform bool isOrthographic;",
        "#ifdef USE_INSTANCING",
        "	attribute mat4 instanceMatrix;",
        "#endif",
        "#ifdef USE_INSTANCING_COLOR",
        "	attribute vec3 instanceColor;",
        "#endif",
        "#ifdef USE_INSTANCING_MORPH",
        "	uniform sampler2D morphTexture;",
        "#endif",
        "attribute vec3 position;",
        "attribute vec3 normal;",
        "attribute vec2 uv;",
        "#ifdef USE_UV1",
        "	attribute vec2 uv1;",
        "#endif",
        "#ifdef USE_UV2",
        "	attribute vec2 uv2;",
        "#endif",
        "#ifdef USE_UV3",
        "	attribute vec2 uv3;",
        "#endif",
        "#ifdef USE_TANGENT",
        "	attribute vec4 tangent;",
        "#endif",
        "#if defined( USE_COLOR_ALPHA )",
        "	attribute vec4 color;",
        "#elif defined( USE_COLOR )",
        "	attribute vec3 color;",
        "#endif",
        "#ifdef USE_SKINNING",
        "	attribute vec4 skinIndex;",
        "	attribute vec4 skinWeight;",
        "#endif",
        `
`
    ].filter($t).join(`
`), r = [
        rr1(t),
        "#define SHADER_TYPE " + t.shaderType,
        "#define SHADER_NAME " + t.shaderName,
        O,
        t.useFog && t.fog ? "#define USE_FOG" : "",
        t.useFog && t.fogExp2 ? "#define FOG_EXP2" : "",
        t.alphaToCoverage ? "#define ALPHA_TO_COVERAGE" : "",
        t.map ? "#define USE_MAP" : "",
        t.matcap ? "#define USE_MATCAP" : "",
        t.envMap ? "#define USE_ENVMAP" : "",
        t.envMap ? "#define " + T : "",
        t.envMap ? "#define " + C : "",
        t.envMap ? "#define " + R : "",
        S ? "#define CUBEUV_TEXEL_WIDTH " + S.texelWidth : "",
        S ? "#define CUBEUV_TEXEL_HEIGHT " + S.texelHeight : "",
        S ? "#define CUBEUV_MAX_MIP " + S.maxMip + ".0" : "",
        t.lightMap ? "#define USE_LIGHTMAP" : "",
        t.aoMap ? "#define USE_AOMAP" : "",
        t.bumpMap ? "#define USE_BUMPMAP" : "",
        t.normalMap ? "#define USE_NORMALMAP" : "",
        t.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "",
        t.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "",
        t.emissiveMap ? "#define USE_EMISSIVEMAP" : "",
        t.anisotropy ? "#define USE_ANISOTROPY" : "",
        t.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "",
        t.clearcoat ? "#define USE_CLEARCOAT" : "",
        t.clearcoatMap ? "#define USE_CLEARCOATMAP" : "",
        t.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "",
        t.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "",
        t.dispersion ? "#define USE_DISPERSION" : "",
        t.iridescence ? "#define USE_IRIDESCENCE" : "",
        t.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "",
        t.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "",
        t.specularMap ? "#define USE_SPECULARMAP" : "",
        t.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "",
        t.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "",
        t.roughnessMap ? "#define USE_ROUGHNESSMAP" : "",
        t.metalnessMap ? "#define USE_METALNESSMAP" : "",
        t.alphaMap ? "#define USE_ALPHAMAP" : "",
        t.alphaTest ? "#define USE_ALPHATEST" : "",
        t.alphaHash ? "#define USE_ALPHAHASH" : "",
        t.sheen ? "#define USE_SHEEN" : "",
        t.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "",
        t.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "",
        t.transmission ? "#define USE_TRANSMISSION" : "",
        t.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "",
        t.thicknessMap ? "#define USE_THICKNESSMAP" : "",
        t.vertexTangents && t.flatShading === !1 ? "#define USE_TANGENT" : "",
        t.vertexColors || t.instancingColor || t.batchingColor ? "#define USE_COLOR" : "",
        t.vertexAlphas ? "#define USE_COLOR_ALPHA" : "",
        t.vertexUv1s ? "#define USE_UV1" : "",
        t.vertexUv2s ? "#define USE_UV2" : "",
        t.vertexUv3s ? "#define USE_UV3" : "",
        t.pointsUvs ? "#define USE_POINTS_UV" : "",
        t.gradientMap ? "#define USE_GRADIENTMAP" : "",
        t.flatShading ? "#define FLAT_SHADED" : "",
        t.doubleSided ? "#define DOUBLE_SIDED" : "",
        t.flipSided ? "#define FLIP_SIDED" : "",
        t.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
        t.shadowMapEnabled ? "#define " + I : "",
        t.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : "",
        t.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "",
        t.decodeVideoTexture ? "#define DECODE_VIDEO_TEXTURE" : "",
        t.decodeVideoTextureEmissive ? "#define DECODE_VIDEO_TEXTURE_EMISSIVE" : "",
        t.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
        t.reverseDepthBuffer ? "#define USE_REVERSEDEPTHBUF" : "",
        "uniform mat4 viewMatrix;",
        "uniform vec3 cameraPosition;",
        "uniform bool isOrthographic;",
        t.toneMapping !== Tp ? "#define TONE_MAPPING" : "",
        t.toneMapping !== Tp ? Pe1.tonemapping_pars_fragment : "",
        t.toneMapping !== Tp ? ef1("toneMapping", t.toneMapping) : "",
        t.dithering ? "#define DITHERING" : "",
        t.opaque ? "#define OPAQUE" : "",
        Pe1.colorspace_pars_fragment,
        jl1("linearToOutputTexel", t.outputColorSpace),
        tf1(),
        t.useDepthPacking ? "#define DEPTH_PACKING " + t.depthPacking : "",
        `
`
    ].filter($t).join(`
`)), h = Yn1(h), h = tr1(h, t), h = nr1(h, t), d = Yn1(d), d = tr1(d, t), d = nr1(d, t), h = ir1(h), d = ir1(d), t.isRawShaderMaterial !== !0 && (w = `#version 300 es
`, l = [
        x1,
        "#define attribute in",
        "#define varying out",
        "#define texture2D texture"
    ].join(`
`) + `
` + l, r = [
        "#define varying in",
        t.glslVersion === Af ? "" : "layout(location = 0) out highp vec4 pc_fragColor;",
        t.glslVersion === Af ? "" : "#define gl_FragColor pc_fragColor",
        "#define gl_FragDepthEXT gl_FragDepth",
        "#define texture2D texture",
        "#define textureCube texture",
        "#define texture2DProj textureProj",
        "#define texture2DLodEXT textureLod",
        "#define texture2DProjLodEXT textureProjLod",
        "#define textureCubeLodEXT textureLod",
        "#define texture2DGradEXT textureGrad",
        "#define texture2DProjGradEXT textureProjGrad",
        "#define textureCubeGradEXT textureGrad"
    ].join(`
`) + `
` + r);
    let M = w + l + h, _ = w + r + d, H = Ji1(c, c.VERTEX_SHADER, M), P = Ji1(c, c.FRAGMENT_SHADER, _);
    c.attachShader(L, H), c.attachShader(L, P), t.index0AttributeName !== void 0 ? c.bindAttribLocation(L, 0, t.index0AttributeName) : t.morphTargets === !0 && c.bindAttribLocation(L, 0, "position"), c.linkProgram(L);
    function y1(A) {
        if (e.debug.checkShaderErrors) {
            let q = c.getProgramInfoLog(L).trim(), V = c.getShaderInfoLog(H).trim(), Y = c.getShaderInfoLog(P).trim(), Q = !0, z = !0;
            if (c.getProgramParameter(L, c.LINK_STATUS) === !1) if (Q = !1, typeof e.debug.onShaderError == "function") e.debug.onShaderError(c, L, H, P);
            else {
                let j = er1(c, H, "vertex"), F = er1(c, P, "fragment");
                console.error("THREE.WebGLProgram: Shader Error " + c.getError() + " - VALIDATE_STATUS " + c.getProgramParameter(L, c.VALIDATE_STATUS) + `

Material Name: ` + A.name + `
Material Type: ` + A.type + `

Program Info Log: ` + q + `
` + j + `
` + F);
            }
            else q !== "" ? console.warn("THREE.WebGLProgram: Program Info Log:", q) : (V === "" || Y === "") && (z = !1);
            z && (A.diagnostics = {
                runnable: Q,
                programLog: q,
                vertexShader: {
                    log: V,
                    prefix: l
                },
                fragmentShader: {
                    log: Y,
                    prefix: r
                }
            });
        }
        c.deleteShader(H), c.deleteShader(P), B = new Vt1(c, L), p = af1(c, L);
    }
    let B;
    this.getUniforms = function() {
        return B === void 0 && y1(this), B;
    };
    let p;
    this.getAttributes = function() {
        return p === void 0 && y1(this), p;
    };
    let f = t.rendererExtensionParallelShaderCompile === !1;
    return this.isReady = function() {
        return f === !1 && (f = c.getProgramParameter(L, $l1)), f;
    }, this.destroy = function() {
        i.releaseStatesOfProgram(this), c.deleteProgram(L), this.program = void 0;
    }, this.type = t.shaderType, this.name = t.shaderName, this.id = Zl1++, this.cacheKey = n, this.usedTimes = 1, this.program = L, this.vertexShader = H, this.fragmentShader = P, this;
}
var vf1 = 0, qn1 = class {
    constructor(){
        this.shaderCache = new Map, this.materialCache = new Map;
    }
    update(n) {
        let t = n.vertexShader, i = n.fragmentShader, c = this._getShaderStage(t), s = this._getShaderStage(i), h = this._getShaderCacheForMaterial(n);
        return h.has(c) === !1 && (h.add(c), c.usedTimes++), h.has(s) === !1 && (h.add(s), s.usedTimes++), this;
    }
    remove(n) {
        let t = this.materialCache.get(n);
        for (let i of t)i.usedTimes--, i.usedTimes === 0 && this.shaderCache.delete(i.code);
        return this.materialCache.delete(n), this;
    }
    getVertexShaderID(n) {
        return this._getShaderStage(n.vertexShader).id;
    }
    getFragmentShaderID(n) {
        return this._getShaderStage(n.fragmentShader).id;
    }
    dispose() {
        this.shaderCache.clear(), this.materialCache.clear();
    }
    _getShaderCacheForMaterial(n) {
        let t = this.materialCache, i = t.get(n);
        return i === void 0 && (i = new Set, t.set(n, i)), i;
    }
    _getShaderStage(n) {
        let t = this.shaderCache, i = t.get(n);
        return i === void 0 && (i = new Kn1(n), t.set(n, i)), i;
    }
}, Kn1 = class {
    constructor(n){
        this.id = vf1++, this.code = n, this.usedTimes = 0;
    }
};
function gf1(e, n, t, i, c, s, h) {
    let d = new js, I = new qn1, T = new Set, C = [], R = c.logarithmicDepthBuffer, S = c.vertexTextures, x1 = c.precision, O = {
        MeshDepthMaterial: "depth",
        MeshDistanceMaterial: "distanceRGBA",
        MeshNormalMaterial: "normal",
        MeshBasicMaterial: "basic",
        MeshLambertMaterial: "lambert",
        MeshPhongMaterial: "phong",
        MeshToonMaterial: "toon",
        MeshStandardMaterial: "physical",
        MeshPhysicalMaterial: "physical",
        MeshMatcapMaterial: "matcap",
        LineBasicMaterial: "basic",
        LineDashedMaterial: "dashed",
        PointsMaterial: "points",
        ShadowMaterial: "shadow",
        SpriteMaterial: "sprite"
    };
    function L(p) {
        return T.add(p), p === 0 ? "uv" : `uv${p}`;
    }
    function l(p, f, A, q, V) {
        let Y = q.fog, Q = V.geometry, z = p.isMeshStandardMaterial ? q.environment : null, j = (p.isMeshStandardMaterial ? t : n).get(p.envMap || z), F = j && j.mapping === Xl ? j.image.height : null, me = O[p.type];
        p.precision !== null && (x1 = c.getMaxPrecision(p.precision), x1 !== p.precision && console.warn("THREE.WebGLProgram.getParameters:", p.precision, "not supported, using", x1, "instead."));
        let Me = Q.morphAttributes.position || Q.morphAttributes.normal || Q.morphAttributes.color, Le = Me !== void 0 ? Me.length : 0, Ge = 0;
        Q.morphAttributes.position !== void 0 && (Ge = 1), Q.morphAttributes.normal !== void 0 && (Ge = 2), Q.morphAttributes.color !== void 0 && (Ge = 3);
        let Ze, k, J, ue;
        if (me) {
            let ke = gt1[me];
            Ze = ke.vertexShader, k = ke.fragmentShader;
        } else Ze = p.vertexShader, k = p.fragmentShader, I.update(p), J = I.getVertexShaderID(p), ue = I.getFragmentShaderID(p);
        let ie = e.getRenderTarget(), Ee = e.state.buffers.depth.getReversed(), Be = V.isInstancedMesh === !0, Te = V.isBatchedMesh === !0, je = !!p.map, $e = !!p.matcap, Ue = !!j, m = !!p.aoMap, ut = !!p.lightMap, De = !!p.bumpMap, we = !!p.normalMap, _e = !!p.displacementMap, Xe = !!p.emissiveMap, he = !!p.metalnessMap, u = !!p.roughnessMap, a = p.anisotropy > 0, b = p.clearcoat > 0, W = p.dispersion > 0, K = p.iridescence > 0, G = p.sheen > 0, pe = p.transmission > 0, re = a && !!p.anisotropyMap, ce = b && !!p.clearcoatMap, ye = b && !!p.clearcoatNormalMap, Z = b && !!p.clearcoatRoughnessMap, le = K && !!p.iridescenceMap, Se = K && !!p.iridescenceThicknessMap, xe = G && !!p.sheenColorMap, fe = G && !!p.sheenRoughnessMap, Ie = !!p.specularMap, be = !!p.specularColorMap, ze = !!p.specularIntensityMap, v = pe && !!p.transmissionMap, te = pe && !!p.thicknessMap, N = !!p.gradientMap, X = !!p.alphaMap, oe = p.alphaTest > 0, ae = !!p.alphaHash, Ce = !!p.extensions, Qe = Tp;
        p.toneMapped && (ie === null || ie.isXRRenderTarget === !0) && (Qe = e.toneMapping);
        let at = {
            shaderID: me,
            shaderType: p.type,
            shaderName: p.name,
            vertexShader: Ze,
            fragmentShader: k,
            defines: p.defines,
            customVertexShaderID: J,
            customFragmentShaderID: ue,
            isRawShaderMaterial: p.isRawShaderMaterial === !0,
            glslVersion: p.glslVersion,
            precision: x1,
            batching: Te,
            batchingColor: Te && V._colorsTexture !== null,
            instancing: Be,
            instancingColor: Be && V.instanceColor !== null,
            instancingMorph: Be && V.morphTexture !== null,
            supportsVertexTextures: S,
            outputColorSpace: ie === null ? e.outputColorSpace : ie.isXRRenderTarget === !0 ? ie.texture.colorSpace : ha,
            alphaToCoverage: !!p.alphaToCoverage,
            map: je,
            matcap: $e,
            envMap: Ue,
            envMapMode: Ue && j.mapping,
            envMapCubeUVHeight: F,
            aoMap: m,
            lightMap: ut,
            bumpMap: De,
            normalMap: we,
            displacementMap: S && _e,
            emissiveMap: Xe,
            normalMapObjectSpace: we && p.normalMapType === Gp,
            normalMapTangentSpace: we && p.normalMapType === _i,
            metalnessMap: he,
            roughnessMap: u,
            anisotropy: a,
            anisotropyMap: re,
            clearcoat: b,
            clearcoatMap: ce,
            clearcoatNormalMap: ye,
            clearcoatRoughnessMap: Z,
            dispersion: W,
            iridescence: K,
            iridescenceMap: le,
            iridescenceThicknessMap: Se,
            sheen: G,
            sheenColorMap: xe,
            sheenRoughnessMap: fe,
            specularMap: Ie,
            specularColorMap: be,
            specularIntensityMap: ze,
            transmission: pe,
            transmissionMap: v,
            thicknessMap: te,
            gradientMap: N,
            opaque: p.transparent === !1 && p.blending === ea && p.alphaToCoverage === !1,
            alphaMap: X,
            alphaTest: oe,
            alphaHash: ae,
            combine: p.combine,
            mapUv: je && L(p.map.channel),
            aoMapUv: m && L(p.aoMap.channel),
            lightMapUv: ut && L(p.lightMap.channel),
            bumpMapUv: De && L(p.bumpMap.channel),
            normalMapUv: we && L(p.normalMap.channel),
            displacementMapUv: _e && L(p.displacementMap.channel),
            emissiveMapUv: Xe && L(p.emissiveMap.channel),
            metalnessMapUv: he && L(p.metalnessMap.channel),
            roughnessMapUv: u && L(p.roughnessMap.channel),
            anisotropyMapUv: re && L(p.anisotropyMap.channel),
            clearcoatMapUv: ce && L(p.clearcoatMap.channel),
            clearcoatNormalMapUv: ye && L(p.clearcoatNormalMap.channel),
            clearcoatRoughnessMapUv: Z && L(p.clearcoatRoughnessMap.channel),
            iridescenceMapUv: le && L(p.iridescenceMap.channel),
            iridescenceThicknessMapUv: Se && L(p.iridescenceThicknessMap.channel),
            sheenColorMapUv: xe && L(p.sheenColorMap.channel),
            sheenRoughnessMapUv: fe && L(p.sheenRoughnessMap.channel),
            specularMapUv: Ie && L(p.specularMap.channel),
            specularColorMapUv: be && L(p.specularColorMap.channel),
            specularIntensityMapUv: ze && L(p.specularIntensityMap.channel),
            transmissionMapUv: v && L(p.transmissionMap.channel),
            thicknessMapUv: te && L(p.thicknessMap.channel),
            alphaMapUv: X && L(p.alphaMap.channel),
            vertexTangents: !!Q.attributes.tangent && (we || a),
            vertexColors: p.vertexColors,
            vertexAlphas: p.vertexColors === !0 && !!Q.attributes.color && Q.attributes.color.itemSize === 4,
            pointsUvs: V.isPoints === !0 && !!Q.attributes.uv && (je || X),
            fog: !!Y,
            useFog: p.fog === !0,
            fogExp2: !!Y && Y.isFogExp2,
            flatShading: p.flatShading === !0,
            sizeAttenuation: p.sizeAttenuation === !0,
            logarithmicDepthBuffer: R,
            reverseDepthBuffer: Ee,
            skinning: V.isSkinnedMesh === !0,
            morphTargets: Q.morphAttributes.position !== void 0,
            morphNormals: Q.morphAttributes.normal !== void 0,
            morphColors: Q.morphAttributes.color !== void 0,
            morphTargetsCount: Le,
            morphTextureStride: Ge,
            numDirLights: f.directional.length,
            numPointLights: f.point.length,
            numSpotLights: f.spot.length,
            numSpotLightMaps: f.spotLightMap.length,
            numRectAreaLights: f.rectArea.length,
            numHemiLights: f.hemi.length,
            numDirLightShadows: f.directionalShadowMap.length,
            numPointLightShadows: f.pointShadowMap.length,
            numSpotLightShadows: f.spotShadowMap.length,
            numSpotLightShadowsWithMaps: f.numSpotLightShadowsWithMaps,
            numLightProbes: f.numLightProbes,
            numClippingPlanes: h.numPlanes,
            numClipIntersection: h.numIntersection,
            dithering: p.dithering,
            shadowMapEnabled: e.shadowMap.enabled && A.length > 0,
            shadowMapType: e.shadowMap.type,
            toneMapping: Qe,
            decodeVideoTexture: je && p.map.isVideoTexture === !0 && Tt.getTransfer(p.map.colorSpace) === Fn,
            decodeVideoTextureEmissive: Xe && p.emissiveMap.isVideoTexture === !0 && Tt.getTransfer(p.emissiveMap.colorSpace) === Fn,
            premultipliedAlpha: p.premultipliedAlpha,
            doubleSided: p.side === Yd,
            flipSided: p.side === Al,
            useDepthPacking: p.depthPacking >= 0,
            depthPacking: p.depthPacking || 0,
            index0AttributeName: p.index0AttributeName,
            extensionClipCullDistance: Ce && p.extensions.clipCullDistance === !0 && i.has("WEBGL_clip_cull_distance"),
            extensionMultiDraw: (Ce && p.extensions.multiDraw === !0 || Te) && i.has("WEBGL_multi_draw"),
            rendererExtensionParallelShaderCompile: i.has("KHR_parallel_shader_compile"),
            customProgramCacheKey: p.customProgramCacheKey()
        };
        return at.vertexUv1s = T.has(1), at.vertexUv2s = T.has(2), at.vertexUv3s = T.has(3), T.clear(), at;
    }
    function r(p) {
        let f = [];
        if (p.shaderID ? f.push(p.shaderID) : (f.push(p.customVertexShaderID), f.push(p.customFragmentShaderID)), p.defines !== void 0) for(let A in p.defines)f.push(A), f.push(p.defines[A]);
        return p.isRawShaderMaterial === !1 && (w(f, p), M(f, p), f.push(e.outputColorSpace)), f.push(p.customProgramCacheKey), f.join();
    }
    function w(p, f) {
        p.push(f.precision), p.push(f.outputColorSpace), p.push(f.envMapMode), p.push(f.envMapCubeUVHeight), p.push(f.mapUv), p.push(f.alphaMapUv), p.push(f.lightMapUv), p.push(f.aoMapUv), p.push(f.bumpMapUv), p.push(f.normalMapUv), p.push(f.displacementMapUv), p.push(f.emissiveMapUv), p.push(f.metalnessMapUv), p.push(f.roughnessMapUv), p.push(f.anisotropyMapUv), p.push(f.clearcoatMapUv), p.push(f.clearcoatNormalMapUv), p.push(f.clearcoatRoughnessMapUv), p.push(f.iridescenceMapUv), p.push(f.iridescenceThicknessMapUv), p.push(f.sheenColorMapUv), p.push(f.sheenRoughnessMapUv), p.push(f.specularMapUv), p.push(f.specularColorMapUv), p.push(f.specularIntensityMapUv), p.push(f.transmissionMapUv), p.push(f.thicknessMapUv), p.push(f.combine), p.push(f.fogExp2), p.push(f.sizeAttenuation), p.push(f.morphTargetsCount), p.push(f.morphAttributeCount), p.push(f.numDirLights), p.push(f.numPointLights), p.push(f.numSpotLights), p.push(f.numSpotLightMaps), p.push(f.numHemiLights), p.push(f.numRectAreaLights), p.push(f.numDirLightShadows), p.push(f.numPointLightShadows), p.push(f.numSpotLightShadows), p.push(f.numSpotLightShadowsWithMaps), p.push(f.numLightProbes), p.push(f.shadowMapType), p.push(f.toneMapping), p.push(f.numClippingPlanes), p.push(f.numClipIntersection), p.push(f.depthPacking);
    }
    function M(p, f) {
        d.disableAll(), f.supportsVertexTextures && d.enable(0), f.instancing && d.enable(1), f.instancingColor && d.enable(2), f.instancingMorph && d.enable(3), f.matcap && d.enable(4), f.envMap && d.enable(5), f.normalMapObjectSpace && d.enable(6), f.normalMapTangentSpace && d.enable(7), f.clearcoat && d.enable(8), f.iridescence && d.enable(9), f.alphaTest && d.enable(10), f.vertexColors && d.enable(11), f.vertexAlphas && d.enable(12), f.vertexUv1s && d.enable(13), f.vertexUv2s && d.enable(14), f.vertexUv3s && d.enable(15), f.vertexTangents && d.enable(16), f.anisotropy && d.enable(17), f.alphaHash && d.enable(18), f.batching && d.enable(19), f.dispersion && d.enable(20), f.batchingColor && d.enable(21), p.push(d.mask), d.disableAll(), f.fog && d.enable(0), f.useFog && d.enable(1), f.flatShading && d.enable(2), f.logarithmicDepthBuffer && d.enable(3), f.reverseDepthBuffer && d.enable(4), f.skinning && d.enable(5), f.morphTargets && d.enable(6), f.morphNormals && d.enable(7), f.morphColors && d.enable(8), f.premultipliedAlpha && d.enable(9), f.shadowMapEnabled && d.enable(10), f.doubleSided && d.enable(11), f.flipSided && d.enable(12), f.useDepthPacking && d.enable(13), f.dithering && d.enable(14), f.transmission && d.enable(15), f.sheen && d.enable(16), f.opaque && d.enable(17), f.pointsUvs && d.enable(18), f.decodeVideoTexture && d.enable(19), f.decodeVideoTextureEmissive && d.enable(20), f.alphaToCoverage && d.enable(21), p.push(d.mask);
    }
    function _(p) {
        let f = O[p.type], A;
        if (f) {
            let q = gt1[f];
            A = kf.clone(q.uniforms);
        } else A = p.uniforms;
        return A;
    }
    function H(p, f) {
        let A;
        for(let q = 0, V = C.length; q < V; q++){
            let Y = C[q];
            if (Y.cacheKey === f) {
                A = Y, ++A.usedTimes;
                break;
            }
        }
        return A === void 0 && (A = new _f1(e, f, p, s), C.push(A)), A;
    }
    function P(p) {
        if (--p.usedTimes === 0) {
            let f = C.indexOf(p);
            C[f] = C[C.length - 1], C.pop(), p.destroy();
        }
    }
    function y1(p) {
        I.remove(p);
    }
    function B() {
        I.dispose();
    }
    return {
        getParameters: l,
        getProgramCacheKey: r,
        getUniforms: _,
        acquireProgram: H,
        releaseProgram: P,
        releaseShaderCache: y1,
        programs: C,
        dispose: B
    };
}
function Sf1() {
    let e = new WeakMap;
    function n(h) {
        return e.has(h);
    }
    function t(h) {
        let d = e.get(h);
        return d === void 0 && (d = {}, e.set(h, d)), d;
    }
    function i(h) {
        e.delete(h);
    }
    function c(h, d, I) {
        e.get(h)[d] = I;
    }
    function s() {
        e = new WeakMap;
    }
    return {
        has: n,
        get: t,
        remove: i,
        update: c,
        dispose: s
    };
}
function Ef1(e, n) {
    return e.groupOrder !== n.groupOrder ? e.groupOrder - n.groupOrder : e.renderOrder !== n.renderOrder ? e.renderOrder - n.renderOrder : e.material.id !== n.material.id ? e.material.id - n.material.id : e.z !== n.z ? e.z - n.z : e.id - n.id;
}
function ar1(e, n) {
    return e.groupOrder !== n.groupOrder ? e.groupOrder - n.groupOrder : e.renderOrder !== n.renderOrder ? e.renderOrder - n.renderOrder : e.z !== n.z ? n.z - e.z : e.id - n.id;
}
function or1() {
    let e = [], n = 0, t = [], i = [], c = [];
    function s() {
        n = 0, t.length = 0, i.length = 0, c.length = 0;
    }
    function h(R, S, x1, O, L, l) {
        let r = e[n];
        return r === void 0 ? (r = {
            id: R.id,
            object: R,
            geometry: S,
            material: x1,
            groupOrder: O,
            renderOrder: R.renderOrder,
            z: L,
            group: l
        }, e[n] = r) : (r.id = R.id, r.object = R, r.geometry = S, r.material = x1, r.groupOrder = O, r.renderOrder = R.renderOrder, r.z = L, r.group = l), n++, r;
    }
    function d(R, S, x1, O, L, l) {
        let r = h(R, S, x1, O, L, l);
        x1.transmission > 0 ? i.push(r) : x1.transparent === !0 ? c.push(r) : t.push(r);
    }
    function I(R, S, x1, O, L, l) {
        let r = h(R, S, x1, O, L, l);
        x1.transmission > 0 ? i.unshift(r) : x1.transparent === !0 ? c.unshift(r) : t.unshift(r);
    }
    function T(R, S) {
        t.length > 1 && t.sort(R || Ef1), i.length > 1 && i.sort(S || ar1), c.length > 1 && c.sort(S || ar1);
    }
    function C() {
        for(let R = n, S = e.length; R < S; R++){
            let x1 = e[R];
            if (x1.id === null) break;
            x1.id = null, x1.object = null, x1.geometry = null, x1.material = null, x1.group = null;
        }
    }
    return {
        opaque: t,
        transmissive: i,
        transparent: c,
        init: s,
        push: d,
        unshift: I,
        finish: C,
        sort: T
    };
}
function Mf1() {
    let e = new WeakMap;
    function n(i, c) {
        let s = e.get(i), h;
        return s === void 0 ? (h = new or1, e.set(i, [
            h
        ])) : c >= s.length ? (h = new or1, s.push(h)) : h = s[c], h;
    }
    function t() {
        e = new WeakMap;
    }
    return {
        get: n,
        dispose: t
    };
}
function Tf1() {
    let e = {};
    return {
        get: function(n) {
            if (e[n.id] !== void 0) return e[n.id];
            let t;
            switch(n.type){
                case "DirectionalLight":
                    t = {
                        direction: new w,
                        color: new P
                    };
                    break;
                case "SpotLight":
                    t = {
                        position: new w,
                        direction: new w,
                        color: new P,
                        distance: 0,
                        coneCos: 0,
                        penumbraCos: 0,
                        decay: 0
                    };
                    break;
                case "PointLight":
                    t = {
                        position: new w,
                        color: new P,
                        distance: 0,
                        decay: 0
                    };
                    break;
                case "HemisphereLight":
                    t = {
                        direction: new w,
                        skyColor: new P,
                        groundColor: new P
                    };
                    break;
                case "RectAreaLight":
                    t = {
                        color: new P,
                        position: new w,
                        halfWidth: new w,
                        halfHeight: new w
                    };
                    break;
            }
            return e[n.id] = t, t;
        }
    };
}
function xf1() {
    let e = {};
    return {
        get: function(n) {
            if (e[n.id] !== void 0) return e[n.id];
            let t;
            switch(n.type){
                case "DirectionalLight":
                    t = {
                        shadowIntensity: 1,
                        shadowBias: 0,
                        shadowNormalBias: 0,
                        shadowRadius: 1,
                        shadowMapSize: new T
                    };
                    break;
                case "SpotLight":
                    t = {
                        shadowIntensity: 1,
                        shadowBias: 0,
                        shadowNormalBias: 0,
                        shadowRadius: 1,
                        shadowMapSize: new T
                    };
                    break;
                case "PointLight":
                    t = {
                        shadowIntensity: 1,
                        shadowBias: 0,
                        shadowNormalBias: 0,
                        shadowRadius: 1,
                        shadowMapSize: new T,
                        shadowCameraNear: 1,
                        shadowCameraFar: 1e3
                    };
                    break;
            }
            return e[n.id] = t, t;
        }
    };
}
var Af1 = 0;
function Rf1(e, n) {
    return (n.castShadow ? 2 : 0) - (e.castShadow ? 2 : 0) + (n.map ? 1 : 0) - (e.map ? 1 : 0);
}
function Cf1(e) {
    let n = new Tf1, t = xf1(), i = {
        version: 0,
        hash: {
            directionalLength: -1,
            pointLength: -1,
            spotLength: -1,
            rectAreaLength: -1,
            hemiLength: -1,
            numDirectionalShadows: -1,
            numPointShadows: -1,
            numSpotShadows: -1,
            numSpotMaps: -1,
            numLightProbes: -1
        },
        ambient: [
            0,
            0,
            0
        ],
        probe: [],
        directional: [],
        directionalShadow: [],
        directionalShadowMap: [],
        directionalShadowMatrix: [],
        spot: [],
        spotLightMap: [],
        spotShadow: [],
        spotShadowMap: [],
        spotLightMatrix: [],
        rectArea: [],
        rectAreaLTC1: null,
        rectAreaLTC2: null,
        point: [],
        pointShadow: [],
        pointShadowMap: [],
        pointShadowMatrix: [],
        hemi: [],
        numSpotLightShadowsWithMaps: 0,
        numLightProbes: 0
    };
    for(let T = 0; T < 9; T++)i.probe.push(new w);
    let c = new w, s = new D, h = new D;
    function d(T) {
        let C = 0, R = 0, S = 0;
        for(let p = 0; p < 9; p++)i.probe[p].set(0, 0, 0);
        let x1 = 0, O = 0, L = 0, l = 0, r = 0, w = 0, M = 0, _ = 0, H = 0, P = 0, y1 = 0;
        T.sort(Rf1);
        for(let p = 0, f = T.length; p < f; p++){
            let A = T[p], q = A.color, V = A.intensity, Y = A.distance, Q = A.shadow && A.shadow.map ? A.shadow.map.texture : null;
            if (A.isAmbientLight) C += q.r * V, R += q.g * V, S += q.b * V;
            else if (A.isLightProbe) {
                for(let z = 0; z < 9; z++)i.probe[z].addScaledVector(A.sh.coefficients[z], V);
                y1++;
            } else if (A.isDirectionalLight) {
                let z = n.get(A);
                if (z.color.copy(A.color).multiplyScalar(A.intensity), A.castShadow) {
                    let j = A.shadow, F = t.get(A);
                    F.shadowIntensity = j.intensity, F.shadowBias = j.bias, F.shadowNormalBias = j.normalBias, F.shadowRadius = j.radius, F.shadowMapSize = j.mapSize, i.directionalShadow[x1] = F, i.directionalShadowMap[x1] = Q, i.directionalShadowMatrix[x1] = A.shadow.matrix, w++;
                }
                i.directional[x1] = z, x1++;
            } else if (A.isSpotLight) {
                let z = n.get(A);
                z.position.setFromMatrixPosition(A.matrixWorld), z.color.copy(q).multiplyScalar(V), z.distance = Y, z.coneCos = Math.cos(A.angle), z.penumbraCos = Math.cos(A.angle * (1 - A.penumbra)), z.decay = A.decay, i.spot[L] = z;
                let j = A.shadow;
                if (A.map && (i.spotLightMap[H] = A.map, H++, j.updateMatrices(A), A.castShadow && P++), i.spotLightMatrix[L] = j.matrix, A.castShadow) {
                    let F = t.get(A);
                    F.shadowIntensity = j.intensity, F.shadowBias = j.bias, F.shadowNormalBias = j.normalBias, F.shadowRadius = j.radius, F.shadowMapSize = j.mapSize, i.spotShadow[L] = F, i.spotShadowMap[L] = Q, _++;
                }
                L++;
            } else if (A.isRectAreaLight) {
                let z = n.get(A);
                z.color.copy(q).multiplyScalar(V), z.halfWidth.set(A.width * .5, 0, 0), z.halfHeight.set(0, A.height * .5, 0), i.rectArea[l] = z, l++;
            } else if (A.isPointLight) {
                let z = n.get(A);
                if (z.color.copy(A.color).multiplyScalar(A.intensity), z.distance = A.distance, z.decay = A.decay, A.castShadow) {
                    let j = A.shadow, F = t.get(A);
                    F.shadowIntensity = j.intensity, F.shadowBias = j.bias, F.shadowNormalBias = j.normalBias, F.shadowRadius = j.radius, F.shadowMapSize = j.mapSize, F.shadowCameraNear = j.camera.near, F.shadowCameraFar = j.camera.far, i.pointShadow[O] = F, i.pointShadowMap[O] = Q, i.pointShadowMatrix[O] = A.shadow.matrix, M++;
                }
                i.point[O] = z, O++;
            } else if (A.isHemisphereLight) {
                let z = n.get(A);
                z.skyColor.copy(A.color).multiplyScalar(V), z.groundColor.copy(A.groundColor).multiplyScalar(V), i.hemi[r] = z, r++;
            }
        }
        l > 0 && (e.has("OES_texture_float_linear") === !0 ? (i.rectAreaLTC1 = ee1.LTC_FLOAT_1, i.rectAreaLTC2 = ee1.LTC_FLOAT_2) : (i.rectAreaLTC1 = ee1.LTC_HALF_1, i.rectAreaLTC2 = ee1.LTC_HALF_2)), i.ambient[0] = C, i.ambient[1] = R, i.ambient[2] = S;
        let B = i.hash;
        (B.directionalLength !== x1 || B.pointLength !== O || B.spotLength !== L || B.rectAreaLength !== l || B.hemiLength !== r || B.numDirectionalShadows !== w || B.numPointShadows !== M || B.numSpotShadows !== _ || B.numSpotMaps !== H || B.numLightProbes !== y1) && (i.directional.length = x1, i.spot.length = L, i.rectArea.length = l, i.point.length = O, i.hemi.length = r, i.directionalShadow.length = w, i.directionalShadowMap.length = w, i.pointShadow.length = M, i.pointShadowMap.length = M, i.spotShadow.length = _, i.spotShadowMap.length = _, i.directionalShadowMatrix.length = w, i.pointShadowMatrix.length = M, i.spotLightMatrix.length = _ + H - P, i.spotLightMap.length = H, i.numSpotLightShadowsWithMaps = P, i.numLightProbes = y1, B.directionalLength = x1, B.pointLength = O, B.spotLength = L, B.rectAreaLength = l, B.hemiLength = r, B.numDirectionalShadows = w, B.numPointShadows = M, B.numSpotShadows = _, B.numSpotMaps = H, B.numLightProbes = y1, i.version = Af1++);
    }
    function I(T, C) {
        let R = 0, S = 0, x1 = 0, O = 0, L = 0, l = C.matrixWorldInverse;
        for(let r = 0, w = T.length; r < w; r++){
            let M = T[r];
            if (M.isDirectionalLight) {
                let _ = i.directional[R];
                _.direction.setFromMatrixPosition(M.matrixWorld), c.setFromMatrixPosition(M.target.matrixWorld), _.direction.sub(c), _.direction.transformDirection(l), R++;
            } else if (M.isSpotLight) {
                let _ = i.spot[x1];
                _.position.setFromMatrixPosition(M.matrixWorld), _.position.applyMatrix4(l), _.direction.setFromMatrixPosition(M.matrixWorld), c.setFromMatrixPosition(M.target.matrixWorld), _.direction.sub(c), _.direction.transformDirection(l), x1++;
            } else if (M.isRectAreaLight) {
                let _ = i.rectArea[O];
                _.position.setFromMatrixPosition(M.matrixWorld), _.position.applyMatrix4(l), h.identity(), s.copy(M.matrixWorld), s.premultiply(l), h.extractRotation(s), _.halfWidth.set(M.width * .5, 0, 0), _.halfHeight.set(0, M.height * .5, 0), _.halfWidth.applyMatrix4(h), _.halfHeight.applyMatrix4(h), O++;
            } else if (M.isPointLight) {
                let _ = i.point[S];
                _.position.setFromMatrixPosition(M.matrixWorld), _.position.applyMatrix4(l), S++;
            } else if (M.isHemisphereLight) {
                let _ = i.hemi[L];
                _.direction.setFromMatrixPosition(M.matrixWorld), _.direction.transformDirection(l), L++;
            }
        }
    }
    return {
        setup: d,
        setupView: I,
        state: i
    };
}
function sr1(e) {
    let n = new Cf1(e), t = [], i = [];
    function c(C) {
        T.camera = C, t.length = 0, i.length = 0;
    }
    function s(C) {
        t.push(C);
    }
    function h(C) {
        i.push(C);
    }
    function d() {
        n.setup(t);
    }
    function I(C) {
        n.setupView(t, C);
    }
    let T = {
        lightsArray: t,
        shadowsArray: i,
        camera: null,
        lights: n,
        transmissionRenderTarget: {}
    };
    return {
        init: c,
        state: T,
        setupLights: d,
        setupLightsView: I,
        pushLight: s,
        pushShadow: h
    };
}
function bf1(e) {
    let n = new WeakMap;
    function t(c, s = 0) {
        let h = n.get(c), d;
        return h === void 0 ? (d = new sr1(e), n.set(c, [
            d
        ])) : s >= h.length ? (d = new sr1(e), h.push(d)) : d = h[s], d;
    }
    function i() {
        n = new WeakMap;
    }
    return {
        get: t,
        dispose: i
    };
}
var Pf1 = `void main() {
	gl_Position = vec4( position, 1.0 );
}`, Lf = `uniform sampler2D shadow_pass;
uniform vec2 resolution;
uniform float radius;
#include <packing>
void main() {
	const float samples = float( VSM_SAMPLES );
	float mean = 0.0;
	float squared_mean = 0.0;
	float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );
	float uvStart = samples <= 1.0 ? 0.0 : - 1.0;
	for ( float i = 0.0; i < samples; i ++ ) {
		float uvOffset = uvStart + i * uvStride;
		#ifdef HORIZONTAL_PASS
			vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );
			mean += distribution.x;
			squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
		#else
			float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );
			mean += depth;
			squared_mean += depth * depth;
		#endif
	}
	mean = mean / samples;
	squared_mean = squared_mean / samples;
	float std_dev = sqrt( squared_mean - mean * mean );
	gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );
}`;
function Uf(e, n, t) {
    let i = new sn, c = new T, s = new T, h = new ot, d = new lo({
        depthPacking: Wp
    }), I = new co, T1 = {}, C = t.maxTextureSize, R = {
        [dr]: Al,
        [Al]: dr,
        [Yd]: Yd
    }, S = new qi({
        defines: {
            VSM_SAMPLES: 8
        },
        uniforms: {
            shadow_pass: {
                value: null
            },
            resolution: {
                value: new T
            },
            radius: {
                value: 4
            }
        },
        vertexShader: Pf1,
        fragmentShader: Lf
    }), x1 = S.clone();
    x1.defines.HORIZONTAL_PASS = 1;
    let O = new L;
    O.setAttribute("position", new Z(new Float32Array([
        -1,
        -1,
        .5,
        3,
        -1,
        .5,
        -1,
        3,
        .5
    ]), 3));
    let L1 = new Ct(O, S), l = this;
    this.enabled = !1, this.autoUpdate = !0, this.needsUpdate = !1, this.type = Xd;
    let r = this.type;
    this.render = function(P, y1, B) {
        if (l.enabled === !1 || l.autoUpdate === !1 && l.needsUpdate === !1 || P.length === 0) return;
        let p = e.getRenderTarget(), f = e.getActiveCubeFace(), A = e.getActiveMipmapLevel(), q = e.state;
        q.setBlending(Ul), q.buffers.color.setClear(1, 1, 1, 1), q.buffers.depth.setTest(!0), q.setScissorTest(!1);
        let V = r !== Zd && this.type === Zd, Y = r === Zd && this.type !== Zd;
        for(let Q = 0, z = P.length; Q < z; Q++){
            let j = P[Q], F = j.shadow;
            if (F === void 0) {
                console.warn("THREE.WebGLShadowMap:", j, "has no shadow.");
                continue;
            }
            if (F.autoUpdate === !1 && F.needsUpdate === !1) continue;
            c.copy(F.mapSize);
            let me = F.getFrameExtents();
            if (c.multiply(me), s.copy(F.mapSize), (c.x > C || c.y > C) && (c.x > C && (s.x = Math.floor(C / me.x), c.x = s.x * me.x, F.mapSize.x = s.x), c.y > C && (s.y = Math.floor(C / me.y), c.y = s.y * me.y, F.mapSize.y = s.y)), F.map === null || V === !0 || Y === !0) {
                let Le = this.type !== Zd ? {
                    minFilter: Ut,
                    magFilter: Ut
                } : {};
                F.map !== null && F.map.dispose(), F.map = new Hi(c.x, c.y, Le), F.map.texture.name = j.name + ".shadowMap", F.camera.updateProjectionMatrix();
            }
            e.setRenderTarget(F.map), e.clear();
            let Me = F.getViewportCount();
            for(let Le = 0; Le < Me; Le++){
                let Ge = F.getViewport(Le);
                h.set(s.x * Ge.x, s.y * Ge.y, s.x * Ge.z, s.y * Ge.w), q.viewport(h), F.updateMatrices(j, Le), i = F.getFrustum(), _(y1, B, F.camera, j, this.type);
            }
            F.isPointLightShadow !== !0 && this.type === Zd && w(F, B), F.needsUpdate = !1;
        }
        r = this.type, l.needsUpdate = !1, e.setRenderTarget(p, f, A);
    };
    function w(P, y1) {
        let B = n.update(L1);
        S.defines.VSM_SAMPLES !== P.blurSamples && (S.defines.VSM_SAMPLES = P.blurSamples, x1.defines.VSM_SAMPLES = P.blurSamples, S.needsUpdate = !0, x1.needsUpdate = !0), P.mapPass === null && (P.mapPass = new Hi(c.x, c.y)), S.uniforms.shadow_pass.value = P.map.texture, S.uniforms.resolution.value = P.mapSize, S.uniforms.radius.value = P.radius, e.setRenderTarget(P.mapPass), e.clear(), e.renderBufferDirect(y1, null, B, S, L1, null), x1.uniforms.shadow_pass.value = P.mapPass.texture, x1.uniforms.resolution.value = P.mapSize, x1.uniforms.radius.value = P.radius, e.setRenderTarget(P.map), e.clear(), e.renderBufferDirect(y1, null, B, x1, L1, null);
    }
    function M(P, y1, B, p) {
        let f = null, A = B.isPointLight === !0 ? P.customDistanceMaterial : P.customDepthMaterial;
        if (A !== void 0) f = A;
        else if (f = B.isPointLight === !0 ? I : d, e.localClippingEnabled && y1.clipShadows === !0 && Array.isArray(y1.clippingPlanes) && y1.clippingPlanes.length !== 0 || y1.displacementMap && y1.displacementScale !== 0 || y1.alphaMap && y1.alphaTest > 0 || y1.map && y1.alphaTest > 0) {
            let q = f.uuid, V = y1.uuid, Y = T1[q];
            Y === void 0 && (Y = {}, T1[q] = Y);
            let Q = Y[V];
            Q === void 0 && (Q = f.clone(), Y[V] = Q, y1.addEventListener("dispose", H)), f = Q;
        }
        if (f.visible = y1.visible, f.wireframe = y1.wireframe, p === Zd ? f.side = y1.shadowSide !== null ? y1.shadowSide : y1.side : f.side = y1.shadowSide !== null ? y1.shadowSide : R[y1.side], f.alphaMap = y1.alphaMap, f.alphaTest = y1.alphaTest, f.map = y1.map, f.clipShadows = y1.clipShadows, f.clippingPlanes = y1.clippingPlanes, f.clipIntersection = y1.clipIntersection, f.displacementMap = y1.displacementMap, f.displacementScale = y1.displacementScale, f.displacementBias = y1.displacementBias, f.wireframeLinewidth = y1.wireframeLinewidth, f.linewidth = y1.linewidth, B.isPointLight === !0 && f.isMeshDistanceMaterial === !0) {
            let q = e.properties.get(f);
            q.light = B;
        }
        return f;
    }
    function _(P, y1, B, p, f) {
        if (P.visible === !1) return;
        if (P.layers.test(y1.layers) && (P.isMesh || P.isLine || P.isPoints) && (P.castShadow || P.receiveShadow && f === Zd) && (!P.frustumCulled || i.intersectsObject(P))) {
            P.modelViewMatrix.multiplyMatrices(B.matrixWorldInverse, P.matrixWorld);
            let V = n.update(P), Y = P.material;
            if (Array.isArray(Y)) {
                let Q = V.groups;
                for(let z = 0, j = Q.length; z < j; z++){
                    let F = Q[z], me = Y[F.materialIndex];
                    if (me && me.visible) {
                        let Me = M(P, me, p, f);
                        P.onBeforeShadow(e, P, y1, B, V, Me, F), e.renderBufferDirect(B, null, V, Me, P, F), P.onAfterShadow(e, P, y1, B, V, Me, F);
                    }
                }
            } else if (Y.visible) {
                let Q = M(P, Y, p, f);
                P.onBeforeShadow(e, P, y1, B, V, Q, null), e.renderBufferDirect(B, null, V, Q, P, null), P.onAfterShadow(e, P, y1, B, V, Q, null);
            }
        }
        let q = P.children;
        for(let V = 0, Y = q.length; V < Y; V++)_(q[V], y1, B, p, f);
    }
    function H(P) {
        P.target.removeEventListener("dispose", H);
        for(let B in T1){
            let p = T1[B], f = P.target.uuid;
            f in p && (p[f].dispose(), delete p[f]);
        }
    }
}
var Df = {
    [gp]: xp,
    [bp]: _p,
    [wp]: vp,
    [ra]: Mp,
    [xp]: gp,
    [_p]: bp,
    [vp]: wp,
    [Mp]: ra
};
function wf1(e, n) {
    function t() {
        let v = !1, te = new ot, N = null, X = new ot(0, 0, 0, 0);
        return {
            setMask: function(oe) {
                N !== oe && !v && (e.colorMask(oe, oe, oe, oe), N = oe);
            },
            setLocked: function(oe) {
                v = oe;
            },
            setClear: function(oe, ae, Ce, Qe, at) {
                at === !0 && (oe *= Qe, ae *= Qe, Ce *= Qe), te.set(oe, ae, Ce, Qe), X.equals(te) === !1 && (e.clearColor(oe, ae, Ce, Qe), X.copy(te));
            },
            reset: function() {
                v = !1, N = null, X.set(-1, 0, 0, 0);
            }
        };
    }
    function i() {
        let v = !1, te = !1, N = null, X = null, oe = null;
        return {
            setReversed: function(ae) {
                if (te !== ae) {
                    let Ce = n.get("EXT_clip_control");
                    te ? Ce.clipControlEXT(Ce.LOWER_LEFT_EXT, Ce.ZERO_TO_ONE_EXT) : Ce.clipControlEXT(Ce.LOWER_LEFT_EXT, Ce.NEGATIVE_ONE_TO_ONE_EXT);
                    let Qe = oe;
                    oe = null, this.setClear(Qe);
                }
                te = ae;
            },
            getReversed: function() {
                return te;
            },
            setTest: function(ae) {
                ae ? ie(e.DEPTH_TEST) : Ee(e.DEPTH_TEST);
            },
            setMask: function(ae) {
                N !== ae && !v && (e.depthMask(ae), N = ae);
            },
            setFunc: function(ae) {
                if (te && (ae = Df[ae]), X !== ae) {
                    switch(ae){
                        case gp:
                            e.depthFunc(e.NEVER);
                            break;
                        case xp:
                            e.depthFunc(e.ALWAYS);
                            break;
                        case bp:
                            e.depthFunc(e.LESS);
                            break;
                        case ra:
                            e.depthFunc(e.LEQUAL);
                            break;
                        case wp:
                            e.depthFunc(e.EQUAL);
                            break;
                        case Mp:
                            e.depthFunc(e.GEQUAL);
                            break;
                        case _p:
                            e.depthFunc(e.GREATER);
                            break;
                        case vp:
                            e.depthFunc(e.NOTEQUAL);
                            break;
                        default:
                            e.depthFunc(e.LEQUAL);
                    }
                    X = ae;
                }
            },
            setLocked: function(ae) {
                v = ae;
            },
            setClear: function(ae) {
                oe !== ae && (te && (ae = 1 - ae), e.clearDepth(ae), oe = ae);
            },
            reset: function() {
                v = !1, N = null, X = null, oe = null, te = !1;
            }
        };
    }
    function c() {
        let v = !1, te = null, N = null, X = null, oe = null, ae = null, Ce = null, Qe = null, at = null;
        return {
            setTest: function(ke) {
                v || (ke ? ie(e.STENCIL_TEST) : Ee(e.STENCIL_TEST));
            },
            setMask: function(ke) {
                te !== ke && !v && (e.stencilMask(ke), te = ke);
            },
            setFunc: function(ke, _t, St) {
                (N !== ke || X !== _t || oe !== St) && (e.stencilFunc(ke, _t, St), N = ke, X = _t, oe = St);
            },
            setOp: function(ke, _t, St) {
                (ae !== ke || Ce !== _t || Qe !== St) && (e.stencilOp(ke, _t, St), ae = ke, Ce = _t, Qe = St);
            },
            setLocked: function(ke) {
                v = ke;
            },
            setClear: function(ke) {
                at !== ke && (e.clearStencil(ke), at = ke);
            },
            reset: function() {
                v = !1, te = null, N = null, X = null, oe = null, ae = null, Ce = null, Qe = null, at = null;
            }
        };
    }
    let s = new t, h = new i, d = new c, I = new WeakMap, T = new WeakMap, C = {}, R = {}, S = new WeakMap, x1 = [], O = null, L = !1, l = null, r = null, w = null, M = null, _ = null, H = null, P1 = null, y1 = new P(0, 0, 0), B = 0, p = !1, f = null, A = null, q = null, V = null, Y = null, Q = e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS), z = !1, j = 0, F = e.getParameter(e.VERSION);
    F.indexOf("WebGL") !== -1 ? (j = parseFloat(/^WebGL (\d)/.exec(F)[1]), z = j >= 1) : F.indexOf("OpenGL ES") !== -1 && (j = parseFloat(/^OpenGL ES (\d)/.exec(F)[1]), z = j >= 2);
    let me = null, Me = {}, Le = e.getParameter(e.SCISSOR_BOX), Ge = e.getParameter(e.VIEWPORT), Ze = new ot().fromArray(Le), k = new ot().fromArray(Ge);
    function J(v, te, N, X) {
        let oe = new Uint8Array(4), ae = e.createTexture();
        e.bindTexture(v, ae), e.texParameteri(v, e.TEXTURE_MIN_FILTER, e.NEAREST), e.texParameteri(v, e.TEXTURE_MAG_FILTER, e.NEAREST);
        for(let Ce = 0; Ce < N; Ce++)v === e.TEXTURE_3D || v === e.TEXTURE_2D_ARRAY ? e.texImage3D(te, 0, e.RGBA, 1, 1, X, 0, e.RGBA, e.UNSIGNED_BYTE, oe) : e.texImage2D(te + Ce, 0, e.RGBA, 1, 1, 0, e.RGBA, e.UNSIGNED_BYTE, oe);
        return ae;
    }
    let ue = {};
    ue[e.TEXTURE_2D] = J(e.TEXTURE_2D, e.TEXTURE_2D, 1), ue[e.TEXTURE_CUBE_MAP] = J(e.TEXTURE_CUBE_MAP, e.TEXTURE_CUBE_MAP_POSITIVE_X, 6), ue[e.TEXTURE_2D_ARRAY] = J(e.TEXTURE_2D_ARRAY, e.TEXTURE_2D_ARRAY, 1, 1), ue[e.TEXTURE_3D] = J(e.TEXTURE_3D, e.TEXTURE_3D, 1, 1), s.setClear(0, 0, 0, 1), h.setClear(1), d.setClear(0), ie(e.DEPTH_TEST), h.setFunc(ra), De(!1), we(Wd), ie(e.CULL_FACE), m(Ul);
    function ie(v) {
        C[v] !== !0 && (e.enable(v), C[v] = !0);
    }
    function Ee(v) {
        C[v] !== !1 && (e.disable(v), C[v] = !1);
    }
    function Be(v, te) {
        return R[v] !== te ? (e.bindFramebuffer(v, te), R[v] = te, v === e.DRAW_FRAMEBUFFER && (R[e.FRAMEBUFFER] = te), v === e.FRAMEBUFFER && (R[e.DRAW_FRAMEBUFFER] = te), !0) : !1;
    }
    function Te(v, te) {
        let N = x1, X = !1;
        if (v) {
            N = S.get(te), N === void 0 && (N = [], S.set(te, N));
            let oe = v.textures;
            if (N.length !== oe.length || N[0] !== e.COLOR_ATTACHMENT0) {
                for(let ae = 0, Ce = oe.length; ae < Ce; ae++)N[ae] = e.COLOR_ATTACHMENT0 + ae;
                N.length = oe.length, X = !0;
            }
        } else N[0] !== e.BACK && (N[0] = e.BACK, X = !0);
        X && e.drawBuffers(N);
    }
    function je(v) {
        return O !== v ? (e.useProgram(v), O = v, !0) : !1;
    }
    let $e = {
        [ia]: e.FUNC_ADD,
        [tp]: e.FUNC_SUBTRACT,
        [ep]: e.FUNC_REVERSE_SUBTRACT
    };
    $e[ip] = e.MIN, $e[sp] = e.MAX;
    let Ue = {
        [np]: e.ZERO,
        [rp]: e.ONE,
        [op]: e.SRC_COLOR,
        [sa]: e.SRC_ALPHA,
        [dp]: e.SRC_ALPHA_SATURATE,
        [cp]: e.DST_COLOR,
        [hp]: e.DST_ALPHA,
        [ap]: e.ONE_MINUS_SRC_COLOR,
        [na]: e.ONE_MINUS_SRC_ALPHA,
        [up]: e.ONE_MINUS_DST_COLOR,
        [lp]: e.ONE_MINUS_DST_ALPHA,
        [pp]: e.CONSTANT_COLOR,
        [fp]: e.ONE_MINUS_CONSTANT_COLOR,
        [mp]: e.CONSTANT_ALPHA,
        [yp]: e.ONE_MINUS_CONSTANT_ALPHA
    };
    function m(v, te, N, X, oe, ae, Ce, Qe, at, ke) {
        if (v === Ul) {
            L === !0 && (Ee(e.BLEND), L = !1);
            return;
        }
        if (L === !1 && (ie(e.BLEND), L = !0), v !== Kd) {
            if (v !== l || ke !== p) {
                if ((r !== ia || _ !== ia) && (e.blendEquation(e.FUNC_ADD), r = ia, _ = ia), ke) switch(v){
                    case ea:
                        e.blendFuncSeparate(e.ONE, e.ONE_MINUS_SRC_ALPHA, e.ONE, e.ONE_MINUS_SRC_ALPHA);
                        break;
                    case $d:
                        e.blendFunc(e.ONE, e.ONE);
                        break;
                    case Qd:
                        e.blendFuncSeparate(e.ZERO, e.ONE_MINUS_SRC_COLOR, e.ZERO, e.ONE);
                        break;
                    case jd:
                        e.blendFuncSeparate(e.ZERO, e.SRC_COLOR, e.ZERO, e.SRC_ALPHA);
                        break;
                    default:
                        console.error("THREE.WebGLState: Invalid blending: ", v);
                        break;
                }
                else switch(v){
                    case ea:
                        e.blendFuncSeparate(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA, e.ONE, e.ONE_MINUS_SRC_ALPHA);
                        break;
                    case $d:
                        e.blendFunc(e.SRC_ALPHA, e.ONE);
                        break;
                    case Qd:
                        e.blendFuncSeparate(e.ZERO, e.ONE_MINUS_SRC_COLOR, e.ZERO, e.ONE);
                        break;
                    case jd:
                        e.blendFunc(e.ZERO, e.SRC_COLOR);
                        break;
                    default:
                        console.error("THREE.WebGLState: Invalid blending: ", v);
                        break;
                }
                w = null, M = null, H = null, P1 = null, y1.set(0, 0, 0), B = 0, l = v, p = ke;
            }
            return;
        }
        oe = oe || te, ae = ae || N, Ce = Ce || X, (te !== r || oe !== _) && (e.blendEquationSeparate($e[te], $e[oe]), r = te, _ = oe), (N !== w || X !== M || ae !== H || Ce !== P1) && (e.blendFuncSeparate(Ue[N], Ue[X], Ue[ae], Ue[Ce]), w = N, M = X, H = ae, P1 = Ce), (Qe.equals(y1) === !1 || at !== B) && (e.blendColor(Qe.r, Qe.g, Qe.b, at), y1.copy(Qe), B = at), l = v, p = !1;
    }
    function ut(v, te) {
        v.side === Yd ? Ee(e.CULL_FACE) : ie(e.CULL_FACE);
        let N = v.side === Al;
        te && (N = !N), De(N), v.blending === ea && v.transparent === !1 ? m(Ul) : m(v.blending, v.blendEquation, v.blendSrc, v.blendDst, v.blendEquationAlpha, v.blendSrcAlpha, v.blendDstAlpha, v.blendColor, v.blendAlpha, v.premultipliedAlpha), h.setFunc(v.depthFunc), h.setTest(v.depthTest), h.setMask(v.depthWrite), s.setMask(v.colorWrite);
        let X = v.stencilWrite;
        d.setTest(X), X && (d.setMask(v.stencilWriteMask), d.setFunc(v.stencilFunc, v.stencilRef, v.stencilFuncMask), d.setOp(v.stencilFail, v.stencilZFail, v.stencilZPass)), Xe(v.polygonOffset, v.polygonOffsetFactor, v.polygonOffsetUnits), v.alphaToCoverage === !0 ? ie(e.SAMPLE_ALPHA_TO_COVERAGE) : Ee(e.SAMPLE_ALPHA_TO_COVERAGE);
    }
    function De(v) {
        f !== v && (v ? e.frontFace(e.CW) : e.frontFace(e.CCW), f = v);
    }
    function we(v) {
        v !== Ud ? (ie(e.CULL_FACE), v !== A && (v === Wd ? e.cullFace(e.BACK) : v === Hd ? e.cullFace(e.FRONT) : e.cullFace(e.FRONT_AND_BACK))) : Ee(e.CULL_FACE), A = v;
    }
    function _e(v) {
        v !== q && (z && e.lineWidth(v), q = v);
    }
    function Xe(v, te, N) {
        v ? (ie(e.POLYGON_OFFSET_FILL), (V !== te || Y !== N) && (e.polygonOffset(te, N), V = te, Y = N)) : Ee(e.POLYGON_OFFSET_FILL);
    }
    function he(v) {
        v ? ie(e.SCISSOR_TEST) : Ee(e.SCISSOR_TEST);
    }
    function u(v) {
        v === void 0 && (v = e.TEXTURE0 + Q - 1), me !== v && (e.activeTexture(v), me = v);
    }
    function a(v, te, N) {
        N === void 0 && (me === null ? N = e.TEXTURE0 + Q - 1 : N = me);
        let X = Me[N];
        X === void 0 && (X = {
            type: void 0,
            texture: void 0
        }, Me[N] = X), (X.type !== v || X.texture !== te) && (me !== N && (e.activeTexture(N), me = N), e.bindTexture(v, te || ue[v]), X.type = v, X.texture = te);
    }
    function b() {
        let v = Me[me];
        v !== void 0 && v.type !== void 0 && (e.bindTexture(v.type, null), v.type = void 0, v.texture = void 0);
    }
    function W() {
        try {
            e.compressedTexImage2D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function K() {
        try {
            e.compressedTexImage3D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function G() {
        try {
            e.texSubImage2D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function pe() {
        try {
            e.texSubImage3D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function re() {
        try {
            e.compressedTexSubImage2D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function ce() {
        try {
            e.compressedTexSubImage3D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function ye() {
        try {
            e.texStorage2D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function Z() {
        try {
            e.texStorage3D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function le() {
        try {
            e.texImage2D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function Se() {
        try {
            e.texImage3D.apply(e, arguments);
        } catch (v) {
            console.error("THREE.WebGLState:", v);
        }
    }
    function xe(v) {
        Ze.equals(v) === !1 && (e.scissor(v.x, v.y, v.z, v.w), Ze.copy(v));
    }
    function fe(v) {
        k.equals(v) === !1 && (e.viewport(v.x, v.y, v.z, v.w), k.copy(v));
    }
    function Ie(v, te) {
        let N = T.get(te);
        N === void 0 && (N = new WeakMap, T.set(te, N));
        let X = N.get(v);
        X === void 0 && (X = e.getUniformBlockIndex(te, v.name), N.set(v, X));
    }
    function be(v, te) {
        let X = T.get(te).get(v);
        I.get(te) !== X && (e.uniformBlockBinding(te, X, v.__bindingPointIndex), I.set(te, X));
    }
    function ze() {
        e.disable(e.BLEND), e.disable(e.CULL_FACE), e.disable(e.DEPTH_TEST), e.disable(e.POLYGON_OFFSET_FILL), e.disable(e.SCISSOR_TEST), e.disable(e.STENCIL_TEST), e.disable(e.SAMPLE_ALPHA_TO_COVERAGE), e.blendEquation(e.FUNC_ADD), e.blendFunc(e.ONE, e.ZERO), e.blendFuncSeparate(e.ONE, e.ZERO, e.ONE, e.ZERO), e.blendColor(0, 0, 0, 0), e.colorMask(!0, !0, !0, !0), e.clearColor(0, 0, 0, 0), e.depthMask(!0), e.depthFunc(e.LESS), h.setReversed(!1), e.clearDepth(1), e.stencilMask(4294967295), e.stencilFunc(e.ALWAYS, 0, 4294967295), e.stencilOp(e.KEEP, e.KEEP, e.KEEP), e.clearStencil(0), e.cullFace(e.BACK), e.frontFace(e.CCW), e.polygonOffset(0, 0), e.activeTexture(e.TEXTURE0), e.bindFramebuffer(e.FRAMEBUFFER, null), e.bindFramebuffer(e.DRAW_FRAMEBUFFER, null), e.bindFramebuffer(e.READ_FRAMEBUFFER, null), e.useProgram(null), e.lineWidth(1), e.scissor(0, 0, e.canvas.width, e.canvas.height), e.viewport(0, 0, e.canvas.width, e.canvas.height), C = {}, me = null, Me = {}, R = {}, S = new WeakMap, x1 = [], O = null, L = !1, l = null, r = null, w = null, M = null, _ = null, H = null, P1 = null, y1 = new P(0, 0, 0), B = 0, p = !1, f = null, A = null, q = null, V = null, Y = null, Ze.set(0, 0, e.canvas.width, e.canvas.height), k.set(0, 0, e.canvas.width, e.canvas.height), s.reset(), h.reset(), d.reset();
    }
    return {
        buffers: {
            color: s,
            depth: h,
            stencil: d
        },
        enable: ie,
        disable: Ee,
        bindFramebuffer: Be,
        drawBuffers: Te,
        useProgram: je,
        setBlending: m,
        setMaterial: ut,
        setFlipSided: De,
        setCullFace: we,
        setLineWidth: _e,
        setPolygonOffset: Xe,
        setScissorTest: he,
        activeTexture: u,
        bindTexture: a,
        unbindTexture: b,
        compressedTexImage2D: W,
        compressedTexImage3D: K,
        texImage2D: le,
        texImage3D: Se,
        updateUBOMapping: Ie,
        uniformBlockBinding: be,
        texStorage2D: ye,
        texStorage3D: Z,
        texSubImage2D: G,
        texSubImage3D: pe,
        compressedTexSubImage2D: re,
        compressedTexSubImage3D: ce,
        scissor: xe,
        viewport: fe,
        reset: ze
    };
}
function If1(e, n, t, i, c, s, h) {
    let d = n.has("WEBGL_multisampled_render_to_texture") ? n.get("WEBGL_multisampled_render_to_texture") : null, I = typeof navigator > "u" ? !1 : /OculusBrowser/g.test(navigator.userAgent), T1 = new T, C = new WeakMap, R, S = new WeakMap, x1 = !1;
    try {
        x1 = typeof OffscreenCanvas < "u" && new OffscreenCanvas(1, 1).getContext("2d") !== null;
    } catch  {}
    function O(u, a) {
        return x1 ? new OffscreenCanvas(u, a) : Ys("canvas");
    }
    function L(u, a, b) {
        let W = 1, K = he(u);
        if ((K.width > b || K.height > b) && (W = b / Math.max(K.width, K.height)), W < 1) if (typeof HTMLImageElement < "u" && u instanceof HTMLImageElement || typeof HTMLCanvasElement < "u" && u instanceof HTMLCanvasElement || typeof ImageBitmap < "u" && u instanceof ImageBitmap || typeof VideoFrame < "u" && u instanceof VideoFrame) {
            let G = Math.floor(W * K.width), pe = Math.floor(W * K.height);
            R === void 0 && (R = O(G, pe));
            let re = a ? O(G, pe) : R;
            return re.width = G, re.height = pe, re.getContext("2d").drawImage(u, 0, 0, G, pe), console.warn("THREE.WebGLRenderer: Texture has been resized from (" + K.width + "x" + K.height + ") to (" + G + "x" + pe + ")."), re;
        } else return "data" in u && console.warn("THREE.WebGLRenderer: Image in DataTexture is too big (" + K.width + "x" + K.height + ")."), u;
        return u;
    }
    function l(u) {
        return u.generateMipmaps;
    }
    function r(u) {
        e.generateMipmap(u);
    }
    function w(u) {
        return u.isWebGLCubeRenderTarget ? e.TEXTURE_CUBE_MAP : u.isWebGL3DRenderTarget ? e.TEXTURE_3D : u.isWebGLArrayRenderTarget || u.isCompressedArrayTexture ? e.TEXTURE_2D_ARRAY : e.TEXTURE_2D;
    }
    function M(u, a, b, W, K = !1) {
        if (u !== null) {
            if (e[u] !== void 0) return e[u];
            console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '" + u + "'");
        }
        let G = a;
        if (a === e.RED && (b === e.FLOAT && (G = e.R32F), b === e.HALF_FLOAT && (G = e.R16F), b === e.UNSIGNED_BYTE && (G = e.R8)), a === e.RED_INTEGER && (b === e.UNSIGNED_BYTE && (G = e.R8UI), b === e.UNSIGNED_SHORT && (G = e.R16UI), b === e.UNSIGNED_INT && (G = e.R32UI), b === e.BYTE && (G = e.R8I), b === e.SHORT && (G = e.R16I), b === e.INT && (G = e.R32I)), a === e.RG && (b === e.FLOAT && (G = e.RG32F), b === e.HALF_FLOAT && (G = e.RG16F), b === e.UNSIGNED_BYTE && (G = e.RG8)), a === e.RG_INTEGER && (b === e.UNSIGNED_BYTE && (G = e.RG8UI), b === e.UNSIGNED_SHORT && (G = e.RG16UI), b === e.UNSIGNED_INT && (G = e.RG32UI), b === e.BYTE && (G = e.RG8I), b === e.SHORT && (G = e.RG16I), b === e.INT && (G = e.RG32I)), a === e.RGB_INTEGER && (b === e.UNSIGNED_BYTE && (G = e.RGB8UI), b === e.UNSIGNED_SHORT && (G = e.RGB16UI), b === e.UNSIGNED_INT && (G = e.RGB32UI), b === e.BYTE && (G = e.RGB8I), b === e.SHORT && (G = e.RGB16I), b === e.INT && (G = e.RGB32I)), a === e.RGBA_INTEGER && (b === e.UNSIGNED_BYTE && (G = e.RGBA8UI), b === e.UNSIGNED_SHORT && (G = e.RGBA16UI), b === e.UNSIGNED_INT && (G = e.RGBA32UI), b === e.BYTE && (G = e.RGBA8I), b === e.SHORT && (G = e.RGBA16I), b === e.INT && (G = e.RGBA32I)), a === e.RGB && b === e.UNSIGNED_INT_5_9_9_9_REV && (G = e.RGB9_E5), a === e.RGBA) {
            let pe = K ? la : Tt.getTransfer(W);
            b === e.FLOAT && (G = e.RGBA32F), b === e.HALF_FLOAT && (G = e.RGBA16F), b === e.UNSIGNED_BYTE && (G = pe === Fn ? e.SRGB8_ALPHA8 : e.RGBA8), b === e.UNSIGNED_SHORT_4_4_4_4 && (G = e.RGBA4), b === e.UNSIGNED_SHORT_5_5_5_1 && (G = e.RGB5_A1);
        }
        return (G === e.R16F || G === e.R32F || G === e.RG16F || G === e.RG32F || G === e.RGBA16F || G === e.RGBA32F) && n.get("EXT_color_buffer_float"), G;
    }
    function _(u, a) {
        let b;
        return u ? a === null || a === Wo || a === sc ? b = e.DEPTH24_STENCIL8 : a === pi ? b = e.DEPTH32F_STENCIL8 : a === jl && (b = e.DEPTH24_STENCIL8, console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")) : a === null || a === Wo || a === sc ? b = e.DEPTH_COMPONENT24 : a === pi ? b = e.DEPTH_COMPONENT32F : a === jl && (b = e.DEPTH_COMPONENT16), b;
    }
    function H(u, a) {
        return l(u) === !0 || u.isFramebufferTexture && u.minFilter !== Ut && u.minFilter !== Et ? Math.log2(Math.max(a.width, a.height)) + 1 : u.mipmaps !== void 0 && u.mipmaps.length > 0 ? u.mipmaps.length : u.isCompressedTexture && Array.isArray(u.image) ? a.mipmaps.length : 1;
    }
    function P(u) {
        let a = u.target;
        a.removeEventListener("dispose", P), B(a), a.isVideoTexture && C.delete(a);
    }
    function y1(u) {
        let a = u.target;
        a.removeEventListener("dispose", y1), f(a);
    }
    function B(u) {
        let a = i.get(u);
        if (a.__webglInit === void 0) return;
        let b = u.source, W = S.get(b);
        if (W) {
            let K = W[a.__cacheKey];
            K.usedTimes--, K.usedTimes === 0 && p(u), Object.keys(W).length === 0 && S.delete(b);
        }
        i.remove(u);
    }
    function p(u) {
        let a = i.get(u);
        e.deleteTexture(a.__webglTexture);
        let b = u.source, W = S.get(b);
        delete W[a.__cacheKey], h.memory.textures--;
    }
    function f(u) {
        let a = i.get(u);
        if (u.depthTexture && (u.depthTexture.dispose(), i.remove(u.depthTexture)), u.isWebGLCubeRenderTarget) for(let W = 0; W < 6; W++){
            if (Array.isArray(a.__webglFramebuffer[W])) for(let K = 0; K < a.__webglFramebuffer[W].length; K++)e.deleteFramebuffer(a.__webglFramebuffer[W][K]);
            else e.deleteFramebuffer(a.__webglFramebuffer[W]);
            a.__webglDepthbuffer && e.deleteRenderbuffer(a.__webglDepthbuffer[W]);
        }
        else {
            if (Array.isArray(a.__webglFramebuffer)) for(let W = 0; W < a.__webglFramebuffer.length; W++)e.deleteFramebuffer(a.__webglFramebuffer[W]);
            else e.deleteFramebuffer(a.__webglFramebuffer);
            if (a.__webglDepthbuffer && e.deleteRenderbuffer(a.__webglDepthbuffer), a.__webglMultisampledFramebuffer && e.deleteFramebuffer(a.__webglMultisampledFramebuffer), a.__webglColorRenderbuffer) for(let W = 0; W < a.__webglColorRenderbuffer.length; W++)a.__webglColorRenderbuffer[W] && e.deleteRenderbuffer(a.__webglColorRenderbuffer[W]);
            a.__webglDepthRenderbuffer && e.deleteRenderbuffer(a.__webglDepthRenderbuffer);
        }
        let b = u.textures;
        for(let W = 0, K = b.length; W < K; W++){
            let G = i.get(b[W]);
            G.__webglTexture && (e.deleteTexture(G.__webglTexture), h.memory.textures--), i.remove(b[W]);
        }
        i.remove(u);
    }
    let A = 0;
    function q() {
        A = 0;
    }
    function V() {
        let u = A;
        return u >= c.maxTextures && console.warn("THREE.WebGLTextures: Trying to use " + u + " texture units while this GPU supports only " + c.maxTextures), A += 1, u;
    }
    function Y(u) {
        let a = [];
        return a.push(u.wrapS), a.push(u.wrapT), a.push(u.wrapR || 0), a.push(u.magFilter), a.push(u.minFilter), a.push(u.anisotropy), a.push(u.internalFormat), a.push(u.format), a.push(u.type), a.push(u.generateMipmaps), a.push(u.premultiplyAlpha), a.push(u.flipY), a.push(u.unpackAlignment), a.push(u.colorSpace), a.join();
    }
    function Q(u, a) {
        let b = i.get(u);
        if (u.isVideoTexture && _e(u), u.isRenderTargetTexture === !1 && u.version > 0 && b.__version !== u.version) {
            let W = u.image;
            if (W === null) console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");
            else if (W.complete === !1) console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");
            else {
                k(b, u, a);
                return;
            }
        }
        t.bindTexture(e.TEXTURE_2D, b.__webglTexture, e.TEXTURE0 + a);
    }
    function z(u, a) {
        let b = i.get(u);
        if (u.version > 0 && b.__version !== u.version) {
            k(b, u, a);
            return;
        }
        t.bindTexture(e.TEXTURE_2D_ARRAY, b.__webglTexture, e.TEXTURE0 + a);
    }
    function j(u, a) {
        let b = i.get(u);
        if (u.version > 0 && b.__version !== u.version) {
            k(b, u, a);
            return;
        }
        t.bindTexture(e.TEXTURE_3D, b.__webglTexture, e.TEXTURE0 + a);
    }
    function F(u, a) {
        let b = i.get(u);
        if (u.version > 0 && b.__version !== u.version) {
            J(b, u, a);
            return;
        }
        t.bindTexture(e.TEXTURE_CUBE_MAP, b.__webglTexture, e.TEXTURE0 + a);
    }
    let me = {
        [pr]: e.REPEAT,
        [Ht]: e.CLAMP_TO_EDGE,
        [fr]: e.MIRRORED_REPEAT
    }, Me = {
        [Ut]: e.NEAREST,
        [Jl]: e.NEAREST_MIPMAP_NEAREST,
        [Zl]: e.NEAREST_MIPMAP_LINEAR,
        [Et]: e.LINEAR,
        [Yl]: e.LINEAR_MIPMAP_NEAREST,
        [vn]: e.LINEAR_MIPMAP_LINEAR
    }, Le = {
        [af]: e.NEVER,
        [ff]: e.ALWAYS,
        [hf]: e.LESS,
        [cf]: e.LEQUAL,
        [lf]: e.EQUAL,
        [pf]: e.GEQUAL,
        [uf]: e.GREATER,
        [df]: e.NOTEQUAL
    };
    function Ge(u, a) {
        if (a.type === pi && n.has("OES_texture_float_linear") === !1 && (a.magFilter === Et || a.magFilter === Yl || a.magFilter === Zl || a.magFilter === vn || a.minFilter === Et || a.minFilter === Yl || a.minFilter === Zl || a.minFilter === vn) && console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."), e.texParameteri(u, e.TEXTURE_WRAP_S, me[a.wrapS]), e.texParameteri(u, e.TEXTURE_WRAP_T, me[a.wrapT]), (u === e.TEXTURE_3D || u === e.TEXTURE_2D_ARRAY) && e.texParameteri(u, e.TEXTURE_WRAP_R, me[a.wrapR]), e.texParameteri(u, e.TEXTURE_MAG_FILTER, Me[a.magFilter]), e.texParameteri(u, e.TEXTURE_MIN_FILTER, Me[a.minFilter]), a.compareFunction && (e.texParameteri(u, e.TEXTURE_COMPARE_MODE, e.COMPARE_REF_TO_TEXTURE), e.texParameteri(u, e.TEXTURE_COMPARE_FUNC, Le[a.compareFunction])), n.has("EXT_texture_filter_anisotropic") === !0) {
            if (a.magFilter === Ut || a.minFilter !== Zl && a.minFilter !== vn || a.type === pi && n.has("OES_texture_float_linear") === !1) return;
            if (a.anisotropy > 1 || i.get(a).__currentAnisotropy) {
                let b = n.get("EXT_texture_filter_anisotropic");
                e.texParameterf(u, b.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(a.anisotropy, c.getMaxAnisotropy())), i.get(a).__currentAnisotropy = a.anisotropy;
            }
        }
    }
    function Ze(u, a) {
        let b = !1;
        u.__webglInit === void 0 && (u.__webglInit = !0, a.addEventListener("dispose", P));
        let W = a.source, K = S.get(W);
        K === void 0 && (K = {}, S.set(W, K));
        let G = Y(a);
        if (G !== u.__cacheKey) {
            K[G] === void 0 && (K[G] = {
                texture: e.createTexture(),
                usedTimes: 0
            }, h.memory.textures++, b = !0), K[G].usedTimes++;
            let pe = K[u.__cacheKey];
            pe !== void 0 && (K[u.__cacheKey].usedTimes--, pe.usedTimes === 0 && p(a)), u.__cacheKey = G, u.__webglTexture = K[G].texture;
        }
        return b;
    }
    function k(u, a, b) {
        let W = e.TEXTURE_2D;
        (a.isDataArrayTexture || a.isCompressedArrayTexture) && (W = e.TEXTURE_2D_ARRAY), a.isData3DTexture && (W = e.TEXTURE_3D);
        let K = Ze(u, a), G = a.source;
        t.bindTexture(W, u.__webglTexture, e.TEXTURE0 + b);
        let pe = i.get(G);
        if (G.version !== pe.__version || K === !0) {
            t.activeTexture(e.TEXTURE0 + b);
            let re = Tt.getPrimaries(Tt.workingColorSpace), ce = a.colorSpace === zl ? null : Tt.getPrimaries(a.colorSpace), ye = a.colorSpace === zl || re === ce ? e.NONE : e.BROWSER_DEFAULT_WEBGL;
            e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL, a.flipY), e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL, a.premultiplyAlpha), e.pixelStorei(e.UNPACK_ALIGNMENT, a.unpackAlignment), e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL, ye);
            let Z = L(a.image, !1, c.maxTextureSize);
            Z = Xe(a, Z);
            let le = s.convert(a.format, a.colorSpace), Se = s.convert(a.type), xe = M(a.internalFormat, le, Se, a.colorSpace, a.isVideoTexture);
            Ge(W, a);
            let fe, Ie = a.mipmaps, be = a.isVideoTexture !== !0, ze = pe.__version === void 0 || K === !0, v = G.dataReady, te = H(a, Z);
            if (a.isDepthTexture) xe = _(a.format === aa, a.type), ze && (be ? t.texStorage2D(e.TEXTURE_2D, 1, xe, Z.width, Z.height) : t.texImage2D(e.TEXTURE_2D, 0, xe, Z.width, Z.height, 0, le, Se, null));
            else if (a.isDataTexture) if (Ie.length > 0) {
                be && ze && t.texStorage2D(e.TEXTURE_2D, te, xe, Ie[0].width, Ie[0].height);
                for(let N = 0, X = Ie.length; N < X; N++)fe = Ie[N], be ? v && t.texSubImage2D(e.TEXTURE_2D, N, 0, 0, fe.width, fe.height, le, Se, fe.data) : t.texImage2D(e.TEXTURE_2D, N, xe, fe.width, fe.height, 0, le, Se, fe.data);
                a.generateMipmaps = !1;
            } else be ? (ze && t.texStorage2D(e.TEXTURE_2D, te, xe, Z.width, Z.height), v && t.texSubImage2D(e.TEXTURE_2D, 0, 0, 0, Z.width, Z.height, le, Se, Z.data)) : t.texImage2D(e.TEXTURE_2D, 0, xe, Z.width, Z.height, 0, le, Se, Z.data);
            else if (a.isCompressedTexture) if (a.isCompressedArrayTexture) {
                be && ze && t.texStorage3D(e.TEXTURE_2D_ARRAY, te, xe, Ie[0].width, Ie[0].height, Z.depth);
                for(let N = 0, X = Ie.length; N < X; N++)if (fe = Ie[N], a.format !== Li) if (le !== null) if (be) {
                    if (v) if (a.layerUpdates.size > 0) {
                        let oe = Nd(fe.width, fe.height, a.format, a.type);
                        for (let ae of a.layerUpdates){
                            let Ce = fe.data.subarray(ae * oe / fe.data.BYTES_PER_ELEMENT, (ae + 1) * oe / fe.data.BYTES_PER_ELEMENT);
                            t.compressedTexSubImage3D(e.TEXTURE_2D_ARRAY, N, 0, 0, ae, fe.width, fe.height, 1, le, Ce);
                        }
                        a.clearLayerUpdates();
                    } else t.compressedTexSubImage3D(e.TEXTURE_2D_ARRAY, N, 0, 0, 0, fe.width, fe.height, Z.depth, le, fe.data);
                } else t.compressedTexImage3D(e.TEXTURE_2D_ARRAY, N, xe, fe.width, fe.height, Z.depth, 0, fe.data, 0, 0);
                else console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");
                else be ? v && t.texSubImage3D(e.TEXTURE_2D_ARRAY, N, 0, 0, 0, fe.width, fe.height, Z.depth, le, Se, fe.data) : t.texImage3D(e.TEXTURE_2D_ARRAY, N, xe, fe.width, fe.height, Z.depth, 0, le, Se, fe.data);
            } else {
                be && ze && t.texStorage2D(e.TEXTURE_2D, te, xe, Ie[0].width, Ie[0].height);
                for(let N = 0, X = Ie.length; N < X; N++)fe = Ie[N], a.format !== Li ? le !== null ? be ? v && t.compressedTexSubImage2D(e.TEXTURE_2D, N, 0, 0, fe.width, fe.height, le, fe.data) : t.compressedTexImage2D(e.TEXTURE_2D, N, xe, fe.width, fe.height, 0, fe.data) : console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()") : be ? v && t.texSubImage2D(e.TEXTURE_2D, N, 0, 0, fe.width, fe.height, le, Se, fe.data) : t.texImage2D(e.TEXTURE_2D, N, xe, fe.width, fe.height, 0, le, Se, fe.data);
            }
            else if (a.isDataArrayTexture) if (be) {
                if (ze && t.texStorage3D(e.TEXTURE_2D_ARRAY, te, xe, Z.width, Z.height, Z.depth), v) if (a.layerUpdates.size > 0) {
                    let N = Nd(Z.width, Z.height, a.format, a.type);
                    for (let X of a.layerUpdates){
                        let oe = Z.data.subarray(X * N / Z.data.BYTES_PER_ELEMENT, (X + 1) * N / Z.data.BYTES_PER_ELEMENT);
                        t.texSubImage3D(e.TEXTURE_2D_ARRAY, 0, 0, 0, X, Z.width, Z.height, 1, le, Se, oe);
                    }
                    a.clearLayerUpdates();
                } else t.texSubImage3D(e.TEXTURE_2D_ARRAY, 0, 0, 0, 0, Z.width, Z.height, Z.depth, le, Se, Z.data);
            } else t.texImage3D(e.TEXTURE_2D_ARRAY, 0, xe, Z.width, Z.height, Z.depth, 0, le, Se, Z.data);
            else if (a.isData3DTexture) be ? (ze && t.texStorage3D(e.TEXTURE_3D, te, xe, Z.width, Z.height, Z.depth), v && t.texSubImage3D(e.TEXTURE_3D, 0, 0, 0, 0, Z.width, Z.height, Z.depth, le, Se, Z.data)) : t.texImage3D(e.TEXTURE_3D, 0, xe, Z.width, Z.height, Z.depth, 0, le, Se, Z.data);
            else if (a.isFramebufferTexture) {
                if (ze) if (be) t.texStorage2D(e.TEXTURE_2D, te, xe, Z.width, Z.height);
                else {
                    let N = Z.width, X = Z.height;
                    for(let oe = 0; oe < te; oe++)t.texImage2D(e.TEXTURE_2D, oe, xe, N, X, 0, le, Se, null), N >>= 1, X >>= 1;
                }
            } else if (Ie.length > 0) {
                if (be && ze) {
                    let N = he(Ie[0]);
                    t.texStorage2D(e.TEXTURE_2D, te, xe, N.width, N.height);
                }
                for(let N = 0, X = Ie.length; N < X; N++)fe = Ie[N], be ? v && t.texSubImage2D(e.TEXTURE_2D, N, 0, 0, le, Se, fe) : t.texImage2D(e.TEXTURE_2D, N, xe, le, Se, fe);
                a.generateMipmaps = !1;
            } else if (be) {
                if (ze) {
                    let N = he(Z);
                    t.texStorage2D(e.TEXTURE_2D, te, xe, N.width, N.height);
                }
                v && t.texSubImage2D(e.TEXTURE_2D, 0, 0, 0, le, Se, Z);
            } else t.texImage2D(e.TEXTURE_2D, 0, xe, le, Se, Z);
            l(a) && r(W), pe.__version = G.version, a.onUpdate && a.onUpdate(a);
        }
        u.__version = a.version;
    }
    function J(u, a, b) {
        if (a.image.length !== 6) return;
        let W = Ze(u, a), K = a.source;
        t.bindTexture(e.TEXTURE_CUBE_MAP, u.__webglTexture, e.TEXTURE0 + b);
        let G = i.get(K);
        if (K.version !== G.__version || W === !0) {
            t.activeTexture(e.TEXTURE0 + b);
            let pe = Tt.getPrimaries(Tt.workingColorSpace), re = a.colorSpace === zl ? null : Tt.getPrimaries(a.colorSpace), ce = a.colorSpace === zl || pe === re ? e.NONE : e.BROWSER_DEFAULT_WEBGL;
            e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL, a.flipY), e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL, a.premultiplyAlpha), e.pixelStorei(e.UNPACK_ALIGNMENT, a.unpackAlignment), e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL, ce);
            let ye = a.isCompressedTexture || a.image[0].isCompressedTexture, Z = a.image[0] && a.image[0].isDataTexture, le = [];
            for(let X = 0; X < 6; X++)!ye && !Z ? le[X] = L(a.image[X], !0, c.maxCubemapSize) : le[X] = Z ? a.image[X].image : a.image[X], le[X] = Xe(a, le[X]);
            let Se = le[0], xe = s.convert(a.format, a.colorSpace), fe = s.convert(a.type), Ie = M(a.internalFormat, xe, fe, a.colorSpace), be = a.isVideoTexture !== !0, ze = G.__version === void 0 || W === !0, v = K.dataReady, te = H(a, Se);
            Ge(e.TEXTURE_CUBE_MAP, a);
            let N;
            if (ye) {
                be && ze && t.texStorage2D(e.TEXTURE_CUBE_MAP, te, Ie, Se.width, Se.height);
                for(let X = 0; X < 6; X++){
                    N = le[X].mipmaps;
                    for(let oe = 0; oe < N.length; oe++){
                        let ae = N[oe];
                        a.format !== Li ? xe !== null ? be ? v && t.compressedTexSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, oe, 0, 0, ae.width, ae.height, xe, ae.data) : t.compressedTexImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, oe, Ie, ae.width, ae.height, 0, ae.data) : console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()") : be ? v && t.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, oe, 0, 0, ae.width, ae.height, xe, fe, ae.data) : t.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, oe, Ie, ae.width, ae.height, 0, xe, fe, ae.data);
                    }
                }
            } else {
                if (N = a.mipmaps, be && ze) {
                    N.length > 0 && te++;
                    let X = he(le[0]);
                    t.texStorage2D(e.TEXTURE_CUBE_MAP, te, Ie, X.width, X.height);
                }
                for(let X = 0; X < 6; X++)if (Z) {
                    be ? v && t.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, 0, 0, 0, le[X].width, le[X].height, xe, fe, le[X].data) : t.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, 0, Ie, le[X].width, le[X].height, 0, xe, fe, le[X].data);
                    for(let oe = 0; oe < N.length; oe++){
                        let Ce = N[oe].image[X].image;
                        be ? v && t.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, oe + 1, 0, 0, Ce.width, Ce.height, xe, fe, Ce.data) : t.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, oe + 1, Ie, Ce.width, Ce.height, 0, xe, fe, Ce.data);
                    }
                } else {
                    be ? v && t.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, 0, 0, 0, xe, fe, le[X]) : t.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, 0, Ie, xe, fe, le[X]);
                    for(let oe = 0; oe < N.length; oe++){
                        let ae = N[oe];
                        be ? v && t.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, oe + 1, 0, 0, xe, fe, ae.image[X]) : t.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X + X, oe + 1, Ie, xe, fe, ae.image[X]);
                    }
                }
            }
            l(a) && r(e.TEXTURE_CUBE_MAP), G.__version = K.version, a.onUpdate && a.onUpdate(a);
        }
        u.__version = a.version;
    }
    function ue(u, a, b, W, K, G) {
        let pe = s.convert(b.format, b.colorSpace), re = s.convert(b.type), ce = M(b.internalFormat, pe, re, b.colorSpace), ye = i.get(a), Z = i.get(b);
        if (Z.__renderTarget = a, !ye.__hasExternalTextures) {
            let le = Math.max(1, a.width >> G), Se = Math.max(1, a.height >> G);
            K === e.TEXTURE_3D || K === e.TEXTURE_2D_ARRAY ? t.texImage3D(K, G, ce, le, Se, a.depth, 0, pe, re, null) : t.texImage2D(K, G, ce, le, Se, 0, pe, re, null);
        }
        t.bindFramebuffer(e.FRAMEBUFFER, u), we(a) ? d.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER, W, K, Z.__webglTexture, 0, De(a)) : (K === e.TEXTURE_2D || K >= e.TEXTURE_CUBE_MAP_POSITIVE_X && K <= e.TEXTURE_CUBE_MAP_NEGATIVE_Z) && e.framebufferTexture2D(e.FRAMEBUFFER, W, K, Z.__webglTexture, G), t.bindFramebuffer(e.FRAMEBUFFER, null);
    }
    function ie(u, a, b) {
        if (e.bindRenderbuffer(e.RENDERBUFFER, u), a.depthBuffer) {
            let W = a.depthTexture, K = W && W.isDepthTexture ? W.type : null, G = _(a.stencilBuffer, K), pe = a.stencilBuffer ? e.DEPTH_STENCIL_ATTACHMENT : e.DEPTH_ATTACHMENT, re = De(a);
            we(a) ? d.renderbufferStorageMultisampleEXT(e.RENDERBUFFER, re, G, a.width, a.height) : b ? e.renderbufferStorageMultisample(e.RENDERBUFFER, re, G, a.width, a.height) : e.renderbufferStorage(e.RENDERBUFFER, G, a.width, a.height), e.framebufferRenderbuffer(e.FRAMEBUFFER, pe, e.RENDERBUFFER, u);
        } else {
            let W = a.textures;
            for(let K = 0; K < W.length; K++){
                let G = W[K], pe = s.convert(G.format, G.colorSpace), re = s.convert(G.type), ce = M(G.internalFormat, pe, re, G.colorSpace), ye = De(a);
                b && we(a) === !1 ? e.renderbufferStorageMultisample(e.RENDERBUFFER, ye, ce, a.width, a.height) : we(a) ? d.renderbufferStorageMultisampleEXT(e.RENDERBUFFER, ye, ce, a.width, a.height) : e.renderbufferStorage(e.RENDERBUFFER, ce, a.width, a.height);
            }
        }
        e.bindRenderbuffer(e.RENDERBUFFER, null);
    }
    function Ee(u, a) {
        if (a && a.isWebGLCubeRenderTarget) throw new Error("Depth Texture with cube render targets is not supported");
        if (t.bindFramebuffer(e.FRAMEBUFFER, u), !(a.depthTexture && a.depthTexture.isDepthTexture)) throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");
        let W = i.get(a.depthTexture);
        W.__renderTarget = a, (!W.__webglTexture || a.depthTexture.image.width !== a.width || a.depthTexture.image.height !== a.height) && (a.depthTexture.image.width = a.width, a.depthTexture.image.height = a.height, a.depthTexture.needsUpdate = !0), Q(a.depthTexture, 0);
        let K = W.__webglTexture, G = De(a);
        if (a.depthTexture.format === Cn) we(a) ? d.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER, e.DEPTH_ATTACHMENT, e.TEXTURE_2D, K, 0, G) : e.framebufferTexture2D(e.FRAMEBUFFER, e.DEPTH_ATTACHMENT, e.TEXTURE_2D, K, 0);
        else if (a.depthTexture.format === aa) we(a) ? d.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER, e.DEPTH_STENCIL_ATTACHMENT, e.TEXTURE_2D, K, 0, G) : e.framebufferTexture2D(e.FRAMEBUFFER, e.DEPTH_STENCIL_ATTACHMENT, e.TEXTURE_2D, K, 0);
        else throw new Error("Unknown depthTexture format");
    }
    function Be(u) {
        let a = i.get(u), b = u.isWebGLCubeRenderTarget === !0;
        if (a.__boundDepthTexture !== u.depthTexture) {
            let W = u.depthTexture;
            if (a.__depthDisposeCallback && a.__depthDisposeCallback(), W) {
                let K = ()=>{
                    delete a.__boundDepthTexture, delete a.__depthDisposeCallback, W.removeEventListener("dispose", K);
                };
                W.addEventListener("dispose", K), a.__depthDisposeCallback = K;
            }
            a.__boundDepthTexture = W;
        }
        if (u.depthTexture && !a.__autoAllocateDepthBuffer) {
            if (b) throw new Error("target.depthTexture not supported in Cube render targets");
            Ee(a.__webglFramebuffer, u);
        } else if (b) {
            a.__webglDepthbuffer = [];
            for(let W = 0; W < 6; W++)if (t.bindFramebuffer(e.FRAMEBUFFER, a.__webglFramebuffer[W]), a.__webglDepthbuffer[W] === void 0) a.__webglDepthbuffer[W] = e.createRenderbuffer(), ie(a.__webglDepthbuffer[W], u, !1);
            else {
                let K = u.stencilBuffer ? e.DEPTH_STENCIL_ATTACHMENT : e.DEPTH_ATTACHMENT, G = a.__webglDepthbuffer[W];
                e.bindRenderbuffer(e.RENDERBUFFER, G), e.framebufferRenderbuffer(e.FRAMEBUFFER, K, e.RENDERBUFFER, G);
            }
        } else if (t.bindFramebuffer(e.FRAMEBUFFER, a.__webglFramebuffer), a.__webglDepthbuffer === void 0) a.__webglDepthbuffer = e.createRenderbuffer(), ie(a.__webglDepthbuffer, u, !1);
        else {
            let W = u.stencilBuffer ? e.DEPTH_STENCIL_ATTACHMENT : e.DEPTH_ATTACHMENT, K = a.__webglDepthbuffer;
            e.bindRenderbuffer(e.RENDERBUFFER, K), e.framebufferRenderbuffer(e.FRAMEBUFFER, W, e.RENDERBUFFER, K);
        }
        t.bindFramebuffer(e.FRAMEBUFFER, null);
    }
    function Te(u, a, b) {
        let W = i.get(u);
        a !== void 0 && ue(W.__webglFramebuffer, u, u.texture, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, 0), b !== void 0 && Be(u);
    }
    function je(u) {
        let a = u.texture, b = i.get(u), W = i.get(a);
        u.addEventListener("dispose", y1);
        let K = u.textures, G = u.isWebGLCubeRenderTarget === !0, pe = K.length > 1;
        if (pe || (W.__webglTexture === void 0 && (W.__webglTexture = e.createTexture()), W.__version = a.version, h.memory.textures++), G) {
            b.__webglFramebuffer = [];
            for(let re = 0; re < 6; re++)if (a.mipmaps && a.mipmaps.length > 0) {
                b.__webglFramebuffer[re] = [];
                for(let ce = 0; ce < a.mipmaps.length; ce++)b.__webglFramebuffer[re][ce] = e.createFramebuffer();
            } else b.__webglFramebuffer[re] = e.createFramebuffer();
        } else {
            if (a.mipmaps && a.mipmaps.length > 0) {
                b.__webglFramebuffer = [];
                for(let re = 0; re < a.mipmaps.length; re++)b.__webglFramebuffer[re] = e.createFramebuffer();
            } else b.__webglFramebuffer = e.createFramebuffer();
            if (pe) for(let re = 0, ce = K.length; re < ce; re++){
                let ye = i.get(K[re]);
                ye.__webglTexture === void 0 && (ye.__webglTexture = e.createTexture(), h.memory.textures++);
            }
            if (u.samples > 0 && we(u) === !1) {
                b.__webglMultisampledFramebuffer = e.createFramebuffer(), b.__webglColorRenderbuffer = [], t.bindFramebuffer(e.FRAMEBUFFER, b.__webglMultisampledFramebuffer);
                for(let re = 0; re < K.length; re++){
                    let ce = K[re];
                    b.__webglColorRenderbuffer[re] = e.createRenderbuffer(), e.bindRenderbuffer(e.RENDERBUFFER, b.__webglColorRenderbuffer[re]);
                    let ye = s.convert(ce.format, ce.colorSpace), Z = s.convert(ce.type), le = M(ce.internalFormat, ye, Z, ce.colorSpace, u.isXRRenderTarget === !0), Se = De(u);
                    e.renderbufferStorageMultisample(e.RENDERBUFFER, Se, le, u.width, u.height), e.framebufferRenderbuffer(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0 + re, e.RENDERBUFFER, b.__webglColorRenderbuffer[re]);
                }
                e.bindRenderbuffer(e.RENDERBUFFER, null), u.depthBuffer && (b.__webglDepthRenderbuffer = e.createRenderbuffer(), ie(b.__webglDepthRenderbuffer, u, !0)), t.bindFramebuffer(e.FRAMEBUFFER, null);
            }
        }
        if (G) {
            t.bindTexture(e.TEXTURE_CUBE_MAP, W.__webglTexture), Ge(e.TEXTURE_CUBE_MAP, a);
            for(let re = 0; re < 6; re++)if (a.mipmaps && a.mipmaps.length > 0) for(let ce = 0; ce < a.mipmaps.length; ce++)ue(b.__webglFramebuffer[re][ce], u, a, e.COLOR_ATTACHMENT0, e.TEXTURE_CUBE_MAP_POSITIVE_X + re, ce);
            else ue(b.__webglFramebuffer[re], u, a, e.COLOR_ATTACHMENT0, e.TEXTURE_CUBE_MAP_POSITIVE_X + re, 0);
            l(a) && r(e.TEXTURE_CUBE_MAP), t.unbindTexture();
        } else if (pe) {
            for(let re = 0, ce = K.length; re < ce; re++){
                let ye = K[re], Z = i.get(ye);
                t.bindTexture(e.TEXTURE_2D, Z.__webglTexture), Ge(e.TEXTURE_2D, ye), ue(b.__webglFramebuffer, u, ye, e.COLOR_ATTACHMENT0 + re, e.TEXTURE_2D, 0), l(ye) && r(e.TEXTURE_2D);
            }
            t.unbindTexture();
        } else {
            let re = e.TEXTURE_2D;
            if ((u.isWebGL3DRenderTarget || u.isWebGLArrayRenderTarget) && (re = u.isWebGL3DRenderTarget ? e.TEXTURE_3D : e.TEXTURE_2D_ARRAY), t.bindTexture(re, W.__webglTexture), Ge(re, a), a.mipmaps && a.mipmaps.length > 0) for(let ce = 0; ce < a.mipmaps.length; ce++)ue(b.__webglFramebuffer[ce], u, a, e.COLOR_ATTACHMENT0, re, ce);
            else ue(b.__webglFramebuffer, u, a, e.COLOR_ATTACHMENT0, re, 0);
            l(a) && r(re), t.unbindTexture();
        }
        u.depthBuffer && Be(u);
    }
    function $e(u) {
        let a = u.textures;
        for(let b = 0, W = a.length; b < W; b++){
            let K = a[b];
            if (l(K)) {
                let G = w(u), pe = i.get(K).__webglTexture;
                t.bindTexture(G, pe), r(G), t.unbindTexture();
            }
        }
    }
    let Ue = [], m = [];
    function ut(u) {
        if (u.samples > 0) {
            if (we(u) === !1) {
                let a = u.textures, b = u.width, W = u.height, K = e.COLOR_BUFFER_BIT, G = u.stencilBuffer ? e.DEPTH_STENCIL_ATTACHMENT : e.DEPTH_ATTACHMENT, pe = i.get(u), re = a.length > 1;
                if (re) for(let ce = 0; ce < a.length; ce++)t.bindFramebuffer(e.FRAMEBUFFER, pe.__webglMultisampledFramebuffer), e.framebufferRenderbuffer(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0 + ce, e.RENDERBUFFER, null), t.bindFramebuffer(e.FRAMEBUFFER, pe.__webglFramebuffer), e.framebufferTexture2D(e.DRAW_FRAMEBUFFER, e.COLOR_ATTACHMENT0 + ce, e.TEXTURE_2D, null, 0);
                t.bindFramebuffer(e.READ_FRAMEBUFFER, pe.__webglMultisampledFramebuffer), t.bindFramebuffer(e.DRAW_FRAMEBUFFER, pe.__webglFramebuffer);
                for(let ce = 0; ce < a.length; ce++){
                    if (u.resolveDepthBuffer && (u.depthBuffer && (K |= e.DEPTH_BUFFER_BIT), u.stencilBuffer && u.resolveStencilBuffer && (K |= e.STENCIL_BUFFER_BIT)), re) {
                        e.framebufferRenderbuffer(e.READ_FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.RENDERBUFFER, pe.__webglColorRenderbuffer[ce]);
                        let ye = i.get(a[ce]).__webglTexture;
                        e.framebufferTexture2D(e.DRAW_FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, ye, 0);
                    }
                    e.blitFramebuffer(0, 0, b, W, 0, 0, b, W, K, e.NEAREST), I === !0 && (Ue.length = 0, m.length = 0, Ue.push(e.COLOR_ATTACHMENT0 + ce), u.depthBuffer && u.resolveDepthBuffer === !1 && (Ue.push(G), m.push(G), e.invalidateFramebuffer(e.DRAW_FRAMEBUFFER, m)), e.invalidateFramebuffer(e.READ_FRAMEBUFFER, Ue));
                }
                if (t.bindFramebuffer(e.READ_FRAMEBUFFER, null), t.bindFramebuffer(e.DRAW_FRAMEBUFFER, null), re) for(let ce = 0; ce < a.length; ce++){
                    t.bindFramebuffer(e.FRAMEBUFFER, pe.__webglMultisampledFramebuffer), e.framebufferRenderbuffer(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0 + ce, e.RENDERBUFFER, pe.__webglColorRenderbuffer[ce]);
                    let ye = i.get(a[ce]).__webglTexture;
                    t.bindFramebuffer(e.FRAMEBUFFER, pe.__webglFramebuffer), e.framebufferTexture2D(e.DRAW_FRAMEBUFFER, e.COLOR_ATTACHMENT0 + ce, e.TEXTURE_2D, ye, 0);
                }
                t.bindFramebuffer(e.DRAW_FRAMEBUFFER, pe.__webglMultisampledFramebuffer);
            } else if (u.depthBuffer && u.resolveDepthBuffer === !1 && I) {
                let a = u.stencilBuffer ? e.DEPTH_STENCIL_ATTACHMENT : e.DEPTH_ATTACHMENT;
                e.invalidateFramebuffer(e.DRAW_FRAMEBUFFER, [
                    a
                ]);
            }
        }
    }
    function De(u) {
        return Math.min(c.maxSamples, u.samples);
    }
    function we(u) {
        let a = i.get(u);
        return u.samples > 0 && n.has("WEBGL_multisampled_render_to_texture") === !0 && a.__useRenderToTexture !== !1;
    }
    function _e(u) {
        let a = h.render.frame;
        C.get(u) !== a && (C.set(u, a), u.update());
    }
    function Xe(u, a) {
        let b = u.colorSpace, W = u.format, K = u.type;
        return u.isCompressedTexture === !0 || u.isVideoTexture === !0 || b !== ha && b !== zl && (Tt.getTransfer(b) === Fn ? (W !== Li || K !== Sl) && console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.") : console.error("THREE.WebGLTextures: Unsupported texture color space:", b)), a;
    }
    function he(u) {
        return typeof HTMLImageElement < "u" && u instanceof HTMLImageElement ? (T1.width = u.naturalWidth || u.width, T1.height = u.naturalHeight || u.height) : typeof VideoFrame < "u" && u instanceof VideoFrame ? (T1.width = u.displayWidth, T1.height = u.displayHeight) : (T1.width = u.width, T1.height = u.height), T1;
    }
    this.allocateTextureUnit = V, this.resetTextureUnits = q, this.setTexture2D = Q, this.setTexture2DArray = z, this.setTexture3D = j, this.setTextureCube = F, this.rebindTextures = Te, this.setupRenderTarget = je, this.updateRenderTargetMipmap = $e, this.updateMultisampleRenderTarget = ut, this.setupDepthRenderbuffer = Be, this.setupFrameBufferTexture = ue, this.useMultisampledRTT = we;
}
function yf1(e, n) {
    function t(i, c = zl) {
        let s, h = Tt.getTransfer(c);
        if (i === Sl) return e.UNSIGNED_BYTE;
        if (i === ec) return e.UNSIGNED_SHORT_4_4_4_4;
        if (i === ic) return e.UNSIGNED_SHORT_5_5_5_1;
        if (i === nc) return e.UNSIGNED_INT_5_9_9_9_REV;
        if (i === $l) return e.BYTE;
        if (i === Ql) return e.SHORT;
        if (i === jl) return e.UNSIGNED_SHORT;
        if (i === Kl) return e.INT;
        if (i === Wo) return e.UNSIGNED_INT;
        if (i === pi) return e.FLOAT;
        if (i === tc) return e.HALF_FLOAT;
        if (i === rc) return e.ALPHA;
        if (i === oc) return e.RGB;
        if (i === Li) return e.RGBA;
        if (i === ac) return e.LUMINANCE;
        if (i === hc) return e.LUMINANCE_ALPHA;
        if (i === Cn) return e.DEPTH_COMPONENT;
        if (i === aa) return e.DEPTH_STENCIL;
        if (i === Tl) return e.RED;
        if (i === Il) return e.RED_INTEGER;
        if (i === lc) return e.RG;
        if (i === cc) return e.RG_INTEGER;
        if (i === uc) return e.RGBA_INTEGER;
        if (i === dc || i === pc || i === fc || i === mc) if (h === Fn) if (s = n.get("WEBGL_compressed_texture_s3tc_srgb"), s !== null) {
            if (i === dc) return s.COMPRESSED_SRGB_S3TC_DXT1_EXT;
            if (i === pc) return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
            if (i === fc) return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
            if (i === mc) return s.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
        } else return null;
        else if (s = n.get("WEBGL_compressed_texture_s3tc"), s !== null) {
            if (i === dc) return s.COMPRESSED_RGB_S3TC_DXT1_EXT;
            if (i === pc) return s.COMPRESSED_RGBA_S3TC_DXT1_EXT;
            if (i === fc) return s.COMPRESSED_RGBA_S3TC_DXT3_EXT;
            if (i === mc) return s.COMPRESSED_RGBA_S3TC_DXT5_EXT;
        } else return null;
        if (i === yc || i === gc || i === xc || i === bc) if (s = n.get("WEBGL_compressed_texture_pvrtc"), s !== null) {
            if (i === yc) return s.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
            if (i === gc) return s.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
            if (i === xc) return s.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
            if (i === bc) return s.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
        } else return null;
        if (i === wc || i === Mc || i === _c) if (s = n.get("WEBGL_compressed_texture_etc"), s !== null) {
            if (i === wc || i === Mc) return h === Fn ? s.COMPRESSED_SRGB8_ETC2 : s.COMPRESSED_RGB8_ETC2;
            if (i === _c) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : s.COMPRESSED_RGBA8_ETC2_EAC;
        } else return null;
        if (i === vc || i === Ac || i === Sc || i === Tc || i === Ic || i === Cc || i === zc || i === Fc || i === Bc || i === Ec || i === Rc || i === kc || i === Pc || i === Oc) if (s = n.get("WEBGL_compressed_texture_astc"), s !== null) {
            if (i === vc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : s.COMPRESSED_RGBA_ASTC_4x4_KHR;
            if (i === Ac) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : s.COMPRESSED_RGBA_ASTC_5x4_KHR;
            if (i === Sc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : s.COMPRESSED_RGBA_ASTC_5x5_KHR;
            if (i === Tc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : s.COMPRESSED_RGBA_ASTC_6x5_KHR;
            if (i === Ic) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : s.COMPRESSED_RGBA_ASTC_6x6_KHR;
            if (i === Cc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : s.COMPRESSED_RGBA_ASTC_8x5_KHR;
            if (i === zc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : s.COMPRESSED_RGBA_ASTC_8x6_KHR;
            if (i === Fc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : s.COMPRESSED_RGBA_ASTC_8x8_KHR;
            if (i === Bc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : s.COMPRESSED_RGBA_ASTC_10x5_KHR;
            if (i === Ec) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : s.COMPRESSED_RGBA_ASTC_10x6_KHR;
            if (i === Rc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : s.COMPRESSED_RGBA_ASTC_10x8_KHR;
            if (i === kc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : s.COMPRESSED_RGBA_ASTC_10x10_KHR;
            if (i === Pc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : s.COMPRESSED_RGBA_ASTC_12x10_KHR;
            if (i === Oc) return h === Fn ? s.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : s.COMPRESSED_RGBA_ASTC_12x12_KHR;
        } else return null;
        if (i === Nc || i === Vc || i === Dc) if (s = n.get("EXT_texture_compression_bptc"), s !== null) {
            if (i === Nc) return h === Fn ? s.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : s.COMPRESSED_RGBA_BPTC_UNORM_EXT;
            if (i === Vc) return s.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;
            if (i === Dc) return s.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT;
        } else return null;
        if (i === Lc || i === Uc || i === Wc || i === Hc) if (s = n.get("EXT_texture_compression_rgtc"), s !== null) {
            if (i === Nc) return s.COMPRESSED_RED_RGTC1_EXT;
            if (i === Uc) return s.COMPRESSED_SIGNED_RED_RGTC1_EXT;
            if (i === Wc) return s.COMPRESSED_RED_GREEN_RGTC2_EXT;
            if (i === Hc) return s.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT;
        } else return null;
        return i === sc ? e.UNSIGNED_INT_24_8 : e[i] !== void 0 ? e[i] : null;
    }
    return {
        convert: t
    };
}
var Nf = `
void main() {

	gl_Position = vec4( position, 1.0 );

}`, Of1 = `
uniform sampler2DArray depthColor;
uniform float depthWidth;
uniform float depthHeight;

void main() {

	vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );

	if ( coord.x >= 1.0 ) {

		gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;

	} else {

		gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;

	}

}`, $n1 = class {
    constructor(){
        this.texture = null, this.mesh = null, this.depthNear = 0, this.depthFar = 0;
    }
    init(n, t, i) {
        if (this.texture === null) {
            let c = new lt, s = n.properties.get(c);
            s.__webglTexture = t.texture, (t.depthNear !== i.depthNear || t.depthFar !== i.depthFar) && (this.depthNear = t.depthNear, this.depthFar = t.depthFar), this.texture = c;
        }
    }
    getMesh(n) {
        if (this.texture !== null && this.mesh === null) {
            let t = n.cameras[0].viewport, i = new qi({
                vertexShader: Nf,
                fragmentShader: Of1,
                uniforms: {
                    depthColor: {
                        value: this.texture
                    },
                    depthWidth: {
                        value: t.z
                    },
                    depthHeight: {
                        value: t.w
                    }
                }
            });
            this.mesh = new Ct(new Zr(20, 20), i);
        }
        return this.mesh;
    }
    reset() {
        this.texture = null, this.mesh = null;
    }
    getDepthTexture() {
        return this.texture;
    }
}, Zn1 = class extends qt {
    constructor(n, t){
        super();
        let i = this, c = null, s = 1, h = null, d = "local-floor", I = 1, T1 = null, C = null, R = null, S = null, x1 = null, O = null, L = new $n1, l = t.getContextAttributes(), r = null, w1 = null, M = [], _ = [], H = new T, P = null, y1 = new vt;
        y1.viewport = new ot;
        let B = new vt;
        B.viewport = new ot;
        let p = [
            y1,
            B
        ], f = new Bh, A = null, q = null;
        this.cameraAutoUpdate = !0, this.enabled = !1, this.isPresenting = !1, this.getController = function(k) {
            let J = M[k];
            return J === void 0 && (J = new Va, M[k] = J), J.getTargetRaySpace();
        }, this.getControllerGrip = function(k) {
            let J = M[k];
            return J === void 0 && (J = new Va, M[k] = J), J.getGripSpace();
        }, this.getHand = function(k) {
            let J = M[k];
            return J === void 0 && (J = new Va, M[k] = J), J.getHandSpace();
        };
        function V(k) {
            let J = _.indexOf(k.inputSource);
            if (J === -1) return;
            let ue = M[J];
            ue !== void 0 && (ue.update(k.inputSource, k.frame, T1 || h), ue.dispatchEvent({
                type: k.type,
                data: k.inputSource
            }));
        }
        function Y() {
            c.removeEventListener("select", V), c.removeEventListener("selectstart", V), c.removeEventListener("selectend", V), c.removeEventListener("squeeze", V), c.removeEventListener("squeezestart", V), c.removeEventListener("squeezeend", V), c.removeEventListener("end", Y), c.removeEventListener("inputsourceschange", Q);
            for(let k = 0; k < M.length; k++){
                let J = _[k];
                J !== null && (_[k] = null, M[k].disconnect(J));
            }
            A = null, q = null, L.reset(), n.setRenderTarget(r), x1 = null, S = null, R = null, c = null, w1 = null, Ze.stop(), i.isPresenting = !1, n.setPixelRatio(P), n.setSize(H.width, H.height, !1), i.dispatchEvent({
                type: "sessionend"
            });
        }
        this.setFramebufferScaleFactor = function(k) {
            s = k, i.isPresenting === !0 && console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting.");
        }, this.setReferenceSpaceType = function(k) {
            d = k, i.isPresenting === !0 && console.warn("THREE.WebXRManager: Cannot change reference space type while presenting.");
        }, this.getReferenceSpace = function() {
            return T1 || h;
        }, this.setReferenceSpace = function(k) {
            T1 = k;
        }, this.getBaseLayer = function() {
            return S !== null ? S : x1;
        }, this.getBinding = function() {
            return R;
        }, this.getFrame = function() {
            return O;
        }, this.getSession = function() {
            return c;
        }, this.setSession = async function(k) {
            if (c = k, c !== null) {
                if (r = n.getRenderTarget(), c.addEventListener("select", V), c.addEventListener("selectstart", V), c.addEventListener("selectend", V), c.addEventListener("squeeze", V), c.addEventListener("squeezestart", V), c.addEventListener("squeezeend", V), c.addEventListener("end", Y), c.addEventListener("inputsourceschange", Q), l.xrCompatible !== !0 && await t.makeXRCompatible(), P = n.getPixelRatio(), n.getSize(H), typeof XRWebGLBinding < "u" && "createProjectionLayer" in XRWebGLBinding.prototype) {
                    let ue = null, ie = null, Ee = null;
                    l.depth && (Ee = l.stencil ? t.DEPTH24_STENCIL8 : t.DEPTH_COMPONENT24, ue = l.stencil ? aa : Cn, ie = l.stencil ? sc : Wo);
                    let Be = {
                        colorFormat: t.RGBA8,
                        depthFormat: Ee,
                        scaleFactor: s
                    };
                    R = new XRWebGLBinding(c, t), S = R.createProjectionLayer(Be), c.updateRenderState({
                        layers: [
                            S
                        ]
                    }), n.setPixelRatio(1), n.setSize(S.textureWidth, S.textureHeight, !1), w1 = new Hi(S.textureWidth, S.textureHeight, {
                        format: Li,
                        type: Sl,
                        depthTexture: new hh(S.textureWidth, S.textureHeight, ie, void 0, void 0, void 0, void 0, void 0, void 0, ue),
                        stencilBuffer: l.stencil,
                        colorSpace: n.outputColorSpace,
                        samples: l.antialias ? 4 : 0,
                        resolveDepthBuffer: S.ignoreDepthValues === !1
                    });
                } else {
                    let ue = {
                        antialias: l.antialias,
                        alpha: !0,
                        depth: l.depth,
                        stencil: l.stencil,
                        framebufferScaleFactor: s
                    };
                    x1 = new XRWebGLLayer(c, t, ue), c.updateRenderState({
                        baseLayer: x1
                    }), n.setPixelRatio(1), n.setSize(x1.framebufferWidth, x1.framebufferHeight, !1), w1 = new Hi(x1.framebufferWidth, x1.framebufferHeight, {
                        format: Li,
                        type: Sl,
                        colorSpace: n.outputColorSpace,
                        stencilBuffer: l.stencil
                    });
                }
                w1.isXRRenderTarget = !0, this.setFoveation(I), T1 = null, h = await c.requestReferenceSpace(d), Ze.setContext(c), Ze.start(), i.isPresenting = !0, i.dispatchEvent({
                    type: "sessionstart"
                });
            }
        }, this.getEnvironmentBlendMode = function() {
            if (c !== null) return c.environmentBlendMode;
        }, this.getDepthTexture = function() {
            return L.getDepthTexture();
        };
        function Q(k) {
            for(let J = 0; J < k.removed.length; J++){
                let ue = k.removed[J], ie = _.indexOf(ue);
                ie >= 0 && (_[ie] = null, M[ie].disconnect(ue));
            }
            for(let J = 0; J < k.added.length; J++){
                let ue = k.added[J], ie = _.indexOf(ue);
                if (ie === -1) {
                    for(let Be = 0; Be < M.length; Be++)if (Be >= _.length) {
                        _.push(ue), ie = Be;
                        break;
                    } else if (_[Be] === null) {
                        _[Be] = ue, ie = Be;
                        break;
                    }
                    if (ie === -1) break;
                }
                let Ee = M[ie];
                Ee && Ee.connect(ue);
            }
        }
        let z = new w, j = new w;
        function F(k, J, ue) {
            z.setFromMatrixPosition(J.matrixWorld), j.setFromMatrixPosition(ue.matrixWorld);
            let ie = z.distanceTo(j), Ee = J.projectionMatrix.elements, Be = ue.projectionMatrix.elements, Te = Ee[14] / (Ee[10] - 1), je = Ee[14] / (Ee[10] + 1), $e = (Ee[9] + 1) / Ee[5], Ue = (Ee[9] - 1) / Ee[5], m = (Ee[8] - 1) / Ee[0], ut = (Be[8] + 1) / Be[0], De = Te * m, we = Te * ut, _e = ie / (-m + ut), Xe = _e * -m;
            if (J.matrixWorld.decompose(k.position, k.quaternion, k.scale), k.translateX(Xe), k.translateZ(_e), k.matrixWorld.compose(k.position, k.quaternion, k.scale), k.matrixWorldInverse.copy(k.matrixWorld).invert(), Ee[10] === -1) k.projectionMatrix.copy(J.projectionMatrix), k.projectionMatrixInverse.copy(J.projectionMatrixInverse);
            else {
                let he = Te + _e, u = je + _e, a = De - Xe, b = we + (ie - Xe), W = $e * je / u * he, K = Ue * je / u * he;
                k.projectionMatrix.makePerspective(a, b, W, K, he, u), k.projectionMatrixInverse.copy(k.projectionMatrix).invert();
            }
        }
        function me(k, J) {
            J === null ? k.matrixWorld.copy(k.matrix) : k.matrixWorld.multiplyMatrices(J.matrixWorld, k.matrix), k.matrixWorldInverse.copy(k.matrixWorld).invert();
        }
        this.updateCamera = function(k) {
            if (c === null) return;
            let J = k.near, ue = k.far;
            L.texture !== null && (L.depthNear > 0 && (J = L.depthNear), L.depthFar > 0 && (ue = L.depthFar)), f.near = B.near = y1.near = J, f.far = B.far = y1.far = ue, (A !== f.near || q !== f.far) && (c.updateRenderState({
                depthNear: f.near,
                depthFar: f.far
            }), A = f.near, q = f.far), y1.layers.mask = k.layers.mask | 2, B.layers.mask = k.layers.mask | 4, f.layers.mask = y1.layers.mask | B.layers.mask;
            let ie = k.parent, Ee = f.cameras;
            me(f, ie);
            for(let Be = 0; Be < Ee.length; Be++)me(Ee[Be], ie);
            Ee.length === 2 ? F(f, y1, B) : f.projectionMatrix.copy(y1.projectionMatrix), Me(k, f, ie);
        };
        function Me(k, J, ue) {
            ue === null ? k.matrix.copy(J.matrixWorld) : (k.matrix.copy(ue.matrixWorld), k.matrix.invert(), k.matrix.multiply(J.matrixWorld)), k.matrix.decompose(k.position, k.quaternion, k.scale), k.updateMatrixWorld(!0), k.projectionMatrix.copy(J.projectionMatrix), k.projectionMatrixInverse.copy(J.projectionMatrixInverse), k.isPerspectiveCamera && (k.fov = Ui * 2 * Math.atan(1 / k.projectionMatrix.elements[5]), k.zoom = 1);
        }
        this.getCamera = function() {
            return f;
        }, this.getFoveation = function() {
            if (!(S === null && x1 === null)) return I;
        }, this.setFoveation = function(k) {
            I = k, S !== null && (S.fixedFoveation = k), x1 !== null && x1.fixedFoveation !== void 0 && (x1.fixedFoveation = k);
        }, this.hasDepthSensing = function() {
            return L.texture !== null;
        }, this.getDepthSensingMesh = function() {
            return L.getMesh(f);
        };
        let Le = null;
        function Ge(k, J) {
            if (C = J.getViewerPose(T1 || h), O = J, C !== null) {
                let ue = C.views;
                x1 !== null && (n.setRenderTargetFramebuffer(w1, x1.framebuffer), n.setRenderTarget(w1));
                let ie = !1;
                ue.length !== f.cameras.length && (f.cameras.length = 0, ie = !0);
                for(let Te = 0; Te < ue.length; Te++){
                    let je = ue[Te], $e = null;
                    if (x1 !== null) $e = x1.getViewport(je);
                    else {
                        let m = R.getViewSubImage(S, je);
                        $e = m.viewport, Te === 0 && (n.setRenderTargetTextures(w1, m.colorTexture, S.ignoreDepthValues ? void 0 : m.depthStencilTexture), n.setRenderTarget(w1));
                    }
                    let Ue = p[Te];
                    Ue === void 0 && (Ue = new vt, Ue.layers.enable(Te), Ue.viewport = new ot, p[Te] = Ue), Ue.matrix.fromArray(je.transform.matrix), Ue.matrix.decompose(Ue.position, Ue.quaternion, Ue.scale), Ue.projectionMatrix.fromArray(je.projectionMatrix), Ue.projectionMatrixInverse.copy(Ue.projectionMatrix).invert(), Ue.viewport.set($e.x, $e.y, $e.width, $e.height), Te === 0 && (f.matrix.copy(Ue.matrix), f.matrix.decompose(f.position, f.quaternion, f.scale)), ie === !0 && f.cameras.push(Ue);
                }
                let Ee = c.enabledFeatures;
                if (Ee && Ee.includes("depth-sensing") && c.depthUsage == "gpu-optimized" && R) {
                    let Te = R.getDepthInformation(ue[0]);
                    Te && Te.isValid && Te.texture && L.init(n, Te, c.renderState);
                }
            }
            for(let ue = 0; ue < M.length; ue++){
                let ie = _[ue], Ee = M[ue];
                ie !== null && Ee !== void 0 && Ee.update(ie, J, T1 || h);
            }
            Le && Le(k, J), J.detectedPlanes && i.dispatchEvent({
                type: "planesdetected",
                data: J
            }), O = null;
        }
        let Ze = new br1;
        Ze.setAnimationLoop(Ge), this.setAnimationLoop = function(k) {
            Le = k;
        }, this.dispose = function() {};
    }
}, Pt = new Xt, Ff1 = new D;
function Bf1(e, n) {
    function t(l, r) {
        l.matrixAutoUpdate === !0 && l.updateMatrix(), r.value.copy(l.matrix);
    }
    function i(l, r) {
        r.color.getRGB(l.fogColor.value, Rf(e)), r.isFog ? (l.fogNear.value = r.near, l.fogFar.value = r.far) : r.isFogExp2 && (l.fogDensity.value = r.density);
    }
    function c(l, r, w, M, _) {
        r.isMeshBasicMaterial || r.isMeshLambertMaterial ? s(l, r) : r.isMeshToonMaterial ? (s(l, r), R(l, r)) : r.isMeshPhongMaterial ? (s(l, r), C(l, r)) : r.isMeshStandardMaterial ? (s(l, r), S(l, r), r.isMeshPhysicalMaterial && x1(l, r, _)) : r.isMeshMatcapMaterial ? (s(l, r), O(l, r)) : r.isMeshDepthMaterial ? s(l, r) : r.isMeshDistanceMaterial ? (s(l, r), L(l, r)) : r.isMeshNormalMaterial ? s(l, r) : r.isLineBasicMaterial ? (h(l, r), r.isLineDashedMaterial && d(l, r)) : r.isPointsMaterial ? I(l, r, w, M) : r.isSpriteMaterial ? T(l, r) : r.isShadowMaterial ? (l.color.value.copy(r.color), l.opacity.value = r.opacity) : r.isShaderMaterial && (r.uniformsNeedUpdate = !1);
    }
    function s(l, r) {
        l.opacity.value = r.opacity, r.color && l.diffuse.value.copy(r.color), r.emissive && l.emissive.value.copy(r.emissive).multiplyScalar(r.emissiveIntensity), r.map && (l.map.value = r.map, t(r.map, l.mapTransform)), r.alphaMap && (l.alphaMap.value = r.alphaMap, t(r.alphaMap, l.alphaMapTransform)), r.bumpMap && (l.bumpMap.value = r.bumpMap, t(r.bumpMap, l.bumpMapTransform), l.bumpScale.value = r.bumpScale, r.side === Al && (l.bumpScale.value *= -1)), r.normalMap && (l.normalMap.value = r.normalMap, t(r.normalMap, l.normalMapTransform), l.normalScale.value.copy(r.normalScale), r.side === Al && l.normalScale.value.negate()), r.displacementMap && (l.displacementMap.value = r.displacementMap, t(r.displacementMap, l.displacementMapTransform), l.displacementScale.value = r.displacementScale, l.displacementBias.value = r.displacementBias), r.emissiveMap && (l.emissiveMap.value = r.emissiveMap, t(r.emissiveMap, l.emissiveMapTransform)), r.specularMap && (l.specularMap.value = r.specularMap, t(r.specularMap, l.specularMapTransform)), r.alphaTest > 0 && (l.alphaTest.value = r.alphaTest);
        let w = n.get(r), M = w.envMap, _ = w.envMapRotation;
        M && (l.envMap.value = M, Pt.copy(_), Pt.x *= -1, Pt.y *= -1, Pt.z *= -1, M.isCubeTexture && M.isRenderTargetTexture === !1 && (Pt.y *= -1, Pt.z *= -1), l.envMapRotation.value.setFromMatrix4(Ff1.makeRotationFromEuler(Pt)), l.flipEnvMap.value = M.isCubeTexture && M.isRenderTargetTexture === !1 ? -1 : 1, l.reflectivity.value = r.reflectivity, l.ior.value = r.ior, l.refractionRatio.value = r.refractionRatio), r.lightMap && (l.lightMap.value = r.lightMap, l.lightMapIntensity.value = r.lightMapIntensity, t(r.lightMap, l.lightMapTransform)), r.aoMap && (l.aoMap.value = r.aoMap, l.aoMapIntensity.value = r.aoMapIntensity, t(r.aoMap, l.aoMapTransform));
    }
    function h(l, r) {
        l.diffuse.value.copy(r.color), l.opacity.value = r.opacity, r.map && (l.map.value = r.map, t(r.map, l.mapTransform));
    }
    function d(l, r) {
        l.dashSize.value = r.dashSize, l.totalSize.value = r.dashSize + r.gapSize, l.scale.value = r.scale;
    }
    function I(l, r, w, M) {
        l.diffuse.value.copy(r.color), l.opacity.value = r.opacity, l.size.value = r.size * w, l.scale.value = M * .5, r.map && (l.map.value = r.map, t(r.map, l.uvTransform)), r.alphaMap && (l.alphaMap.value = r.alphaMap, t(r.alphaMap, l.alphaMapTransform)), r.alphaTest > 0 && (l.alphaTest.value = r.alphaTest);
    }
    function T(l, r) {
        l.diffuse.value.copy(r.color), l.opacity.value = r.opacity, l.rotation.value = r.rotation, r.map && (l.map.value = r.map, t(r.map, l.mapTransform)), r.alphaMap && (l.alphaMap.value = r.alphaMap, t(r.alphaMap, l.alphaMapTransform)), r.alphaTest > 0 && (l.alphaTest.value = r.alphaTest);
    }
    function C(l, r) {
        l.specular.value.copy(r.specular), l.shininess.value = Math.max(r.shininess, 1e-4);
    }
    function R(l, r) {
        r.gradientMap && (l.gradientMap.value = r.gradientMap);
    }
    function S(l, r) {
        l.metalness.value = r.metalness, r.metalnessMap && (l.metalnessMap.value = r.metalnessMap, t(r.metalnessMap, l.metalnessMapTransform)), l.roughness.value = r.roughness, r.roughnessMap && (l.roughnessMap.value = r.roughnessMap, t(r.roughnessMap, l.roughnessMapTransform)), r.envMap && (l.envMapIntensity.value = r.envMapIntensity);
    }
    function x1(l, r, w) {
        l.ior.value = r.ior, r.sheen > 0 && (l.sheenColor.value.copy(r.sheenColor).multiplyScalar(r.sheen), l.sheenRoughness.value = r.sheenRoughness, r.sheenColorMap && (l.sheenColorMap.value = r.sheenColorMap, t(r.sheenColorMap, l.sheenColorMapTransform)), r.sheenRoughnessMap && (l.sheenRoughnessMap.value = r.sheenRoughnessMap, t(r.sheenRoughnessMap, l.sheenRoughnessMapTransform))), r.clearcoat > 0 && (l.clearcoat.value = r.clearcoat, l.clearcoatRoughness.value = r.clearcoatRoughness, r.clearcoatMap && (l.clearcoatMap.value = r.clearcoatMap, t(r.clearcoatMap, l.clearcoatMapTransform)), r.clearcoatRoughnessMap && (l.clearcoatRoughnessMap.value = r.clearcoatRoughnessMap, t(r.clearcoatRoughnessMap, l.clearcoatRoughnessMapTransform)), r.clearcoatNormalMap && (l.clearcoatNormalMap.value = r.clearcoatNormalMap, t(r.clearcoatNormalMap, l.clearcoatNormalMapTransform), l.clearcoatNormalScale.value.copy(r.clearcoatNormalScale), r.side === Al && l.clearcoatNormalScale.value.negate())), r.dispersion > 0 && (l.dispersion.value = r.dispersion), r.iridescence > 0 && (l.iridescence.value = r.iridescence, l.iridescenceIOR.value = r.iridescenceIOR, l.iridescenceThicknessMinimum.value = r.iridescenceThicknessRange[0], l.iridescenceThicknessMaximum.value = r.iridescenceThicknessRange[1], r.iridescenceMap && (l.iridescenceMap.value = r.iridescenceMap, t(r.iridescenceMap, l.iridescenceMapTransform)), r.iridescenceThicknessMap && (l.iridescenceThicknessMap.value = r.iridescenceThicknessMap, t(r.iridescenceThicknessMap, l.iridescenceThicknessMapTransform))), r.transmission > 0 && (l.transmission.value = r.transmission, l.transmissionSamplerMap.value = w.texture, l.transmissionSamplerSize.value.set(w.width, w.height), r.transmissionMap && (l.transmissionMap.value = r.transmissionMap, t(r.transmissionMap, l.transmissionMapTransform)), l.thickness.value = r.thickness, r.thicknessMap && (l.thicknessMap.value = r.thicknessMap, t(r.thicknessMap, l.thicknessMapTransform)), l.attenuationDistance.value = r.attenuationDistance, l.attenuationColor.value.copy(r.attenuationColor)), r.anisotropy > 0 && (l.anisotropyVector.value.set(r.anisotropy * Math.cos(r.anisotropyRotation), r.anisotropy * Math.sin(r.anisotropyRotation)), r.anisotropyMap && (l.anisotropyMap.value = r.anisotropyMap, t(r.anisotropyMap, l.anisotropyMapTransform))), l.specularIntensity.value = r.specularIntensity, l.specularColor.value.copy(r.specularColor), r.specularColorMap && (l.specularColorMap.value = r.specularColorMap, t(r.specularColorMap, l.specularColorMapTransform)), r.specularIntensityMap && (l.specularIntensityMap.value = r.specularIntensityMap, t(r.specularIntensityMap, l.specularIntensityMapTransform));
    }
    function O(l, r) {
        r.matcap && (l.matcap.value = r.matcap);
    }
    function L(l, r) {
        let w = n.get(r).light;
        l.referencePosition.value.setFromMatrixPosition(w.matrixWorld), l.nearDistance.value = w.shadow.camera.near, l.farDistance.value = w.shadow.camera.far;
    }
    return {
        refreshFogUniforms: i,
        refreshMaterialUniforms: c
    };
}
function Gf(e, n, t, i) {
    let c = {}, s = {}, h = [], d = e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS);
    function I(w, M) {
        let _ = M.program;
        i.uniformBlockBinding(w, _);
    }
    function T(w, M) {
        let _ = c[w.id];
        _ === void 0 && (O(w), _ = C(w), c[w.id] = _, w.addEventListener("dispose", l));
        let H = M.program;
        i.updateUBOMapping(w, H);
        let P = n.render.frame;
        s[w.id] !== P && (S(w), s[w.id] = P);
    }
    function C(w) {
        let M = R();
        w.__bindingPointIndex = M;
        let _ = e.createBuffer(), H = w.__size, P = w.usage;
        return e.bindBuffer(e.UNIFORM_BUFFER, _), e.bufferData(e.UNIFORM_BUFFER, H, P), e.bindBuffer(e.UNIFORM_BUFFER, null), e.bindBufferBase(e.UNIFORM_BUFFER, M, _), _;
    }
    function R() {
        for(let w = 0; w < d; w++)if (h.indexOf(w) === -1) return h.push(w), w;
        return console.error("THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."), 0;
    }
    function S(w) {
        let M = c[w.id], _ = w.uniforms, H = w.__cache;
        e.bindBuffer(e.UNIFORM_BUFFER, M);
        for(let P = 0, y1 = _.length; P < y1; P++){
            let B = Array.isArray(_[P]) ? _[P] : [
                _[P]
            ];
            for(let p = 0, f = B.length; p < f; p++){
                let A = B[p];
                if (x1(A, P, p, H) === !0) {
                    let q = A.__offset, V = Array.isArray(A.value) ? A.value : [
                        A.value
                    ], Y = 0;
                    for(let Q = 0; Q < V.length; Q++){
                        let z = V[Q], j = L(z);
                        typeof z == "number" || typeof z == "boolean" ? (A.__data[0] = z, e.bufferSubData(e.UNIFORM_BUFFER, q + Y, A.__data)) : z.isMatrix3 ? (A.__data[0] = z.elements[0], A.__data[1] = z.elements[1], A.__data[2] = z.elements[2], A.__data[3] = 0, A.__data[4] = z.elements[3], A.__data[5] = z.elements[4], A.__data[6] = z.elements[5], A.__data[7] = 0, A.__data[8] = z.elements[6], A.__data[9] = z.elements[7], A.__data[10] = z.elements[8], A.__data[11] = 0) : (z.toArray(A.__data, Y), Y += j.storage / Float32Array.BYTES_PER_ELEMENT);
                    }
                    e.bufferSubData(e.UNIFORM_BUFFER, q, A.__data);
                }
            }
        }
        e.bindBuffer(e.UNIFORM_BUFFER, null);
    }
    function x1(w, M, _, H) {
        let P = w.value, y1 = M + "_" + _;
        if (H[y1] === void 0) return typeof P == "number" || typeof P == "boolean" ? H[y1] = P : H[y1] = P.clone(), !0;
        {
            let B = H[y1];
            if (typeof P == "number" || typeof P == "boolean") {
                if (B !== P) return H[y1] = P, !0;
            } else if (B.equals(P) === !1) return B.copy(P), !0;
        }
        return !1;
    }
    function O(w) {
        let M = w.uniforms, _ = 0, H = 16;
        for(let y1 = 0, B = M.length; y1 < B; y1++){
            let p = Array.isArray(M[y1]) ? M[y1] : [
                M[y1]
            ];
            for(let f = 0, A = p.length; f < A; f++){
                let q = p[f], V = Array.isArray(q.value) ? q.value : [
                    q.value
                ];
                for(let Y = 0, Q = V.length; Y < Q; Y++){
                    let z = V[Y], j = L(z), F = _ % H, me = F % j.boundary, Me = F + me;
                    _ += me, Me !== 0 && H - Me < j.storage && (_ += H - Me), q.__data = new Float32Array(j.storage / Float32Array.BYTES_PER_ELEMENT), q.__offset = _, _ += j.storage;
                }
            }
        }
        let P = _ % H;
        return P > 0 && (_ += H - P), w.__size = _, w.__cache = {}, this;
    }
    function L(w) {
        let M = {
            boundary: 0,
            storage: 0
        };
        return typeof w == "number" || typeof w == "boolean" ? (M.boundary = 4, M.storage = 4) : w.isVector2 ? (M.boundary = 8, M.storage = 8) : w.isVector3 || w.isColor ? (M.boundary = 16, M.storage = 12) : w.isVector4 ? (M.boundary = 16, M.storage = 16) : w.isMatrix3 ? (M.boundary = 48, M.storage = 48) : w.isMatrix4 ? (M.boundary = 64, M.storage = 64) : w.isTexture ? console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group.") : console.warn("THREE.WebGLRenderer: Unsupported uniform value type.", w), M;
    }
    function l(w) {
        let M = w.target;
        M.removeEventListener("dispose", l);
        let _ = h.indexOf(M.__bindingPointIndex);
        h.splice(_, 1), e.deleteBuffer(c[M.id]), delete c[M.id], delete s[M.id];
    }
    function r() {
        for(let w in c)e.deleteBuffer(c[w]);
        h = [], c = {}, s = {};
    }
    return {
        bind: I,
        update: T,
        dispose: r
    };
}
var cr1 = class {
    constructor(n = {}){
        let { canvas: t = If() , context: i = null , depth: c = !0 , stencil: s = !1 , alpha: h = !1 , antialias: d = !1 , premultipliedAlpha: I = !0 , preserveDrawingBuffer: T = !1 , powerPreference: C = "default" , failIfMajorPerformanceCaveat: R = !1 , reverseDepthBuffer: S = !1  } = n;
        this.isWebGLRenderer = !0;
        let x1;
        if (i !== null) {
            if (typeof WebGLRenderingContext < "u" && i instanceof WebGLRenderingContext) throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");
            x1 = i.getContextAttributes().alpha;
        } else x1 = h;
        let O = new Uint32Array(4), L = new Int32Array(4), l = null, r = null, w1 = [], M = [];
        this.domElement = t, this.debug = {
            checkShaderErrors: !0,
            onShaderError: null
        }, this.autoClear = !0, this.autoClearColor = !0, this.autoClearDepth = !0, this.autoClearStencil = !0, this.sortObjects = !0, this.clippingPlanes = [], this.localClippingEnabled = !1, this._outputColorSpace = Bt, this.toneMapping = Tp, this.toneMappingExposure = 1;
        let _ = this, H = !1, P1 = 0, y1 = 0, B = null, p = -1, f = null, A = new ot, q = new ot, V = null, Y = new P(0), Q = 0, z = t.width, j = t.height, F = 1, me = null, Me = null, Le = new ot(0, 0, z, j), Ge = new ot(0, 0, z, j), Ze = !1, k = new sn, J = !1, ue = !1;
        this.transmissionResolutionScale = 1;
        let ie = new D, Ee = new D, Be = new w, Te = new ot, je = {
            background: null,
            fog: null,
            environment: null,
            overrideMaterial: null,
            isScene: !0
        }, $e = !1;
        function Ue() {
            return B === null ? F : 1;
        }
        let m = i;
        function ut(o, g) {
            return t.getContext(o, g);
        }
        try {
            let o = {
                alpha: !0,
                depth: c,
                stencil: s,
                antialias: d,
                premultipliedAlpha: I,
                preserveDrawingBuffer: T,
                powerPreference: C,
                failIfMajorPerformanceCaveat: R
            };
            if ("setAttribute" in t && t.setAttribute("data-engine", `three.js r${vl}`), t.addEventListener("webglcontextlost", X, !1), t.addEventListener("webglcontextrestored", oe, !1), t.addEventListener("webglcontextcreationerror", ae, !1), m === null) {
                let g = "webgl2";
                if (m = ut(g, o), m === null) throw ut(g) ? new Error("Error creating WebGL context with your selected attributes.") : new Error("Error creating WebGL context.");
            }
        } catch (o) {
            throw console.error("THREE.WebGLRenderer: " + o.message), o;
        }
        let De, we, _e, Xe, he, u, a, b, W, K, G, pe, re, ce, ye, Z, le, Se, xe, fe, Ie, be, ze, v;
        function te() {
            De = new nl1(m), De.init(), be = new yf1(m, De), we = new Zc1(m, De, n, be), _e = new wf1(m, De), we.reverseDepthBuffer && S && _e.buffers.depth.setReversed(!0), Xe = new al1(m), he = new Sf1, u = new If1(m, De, _e, he, we, be, Xe), a = new Jc1(_), b = new tl1(_), W = new uo1(m), ze = new Kc1(m, W), K = new il1(m, W, Xe, ze), G = new sl1(m, K, W, Xe), xe = new ol1(m, we, u), Z = new Qc1(he), pe = new gf1(_, a, b, De, we, ze, Z), re = new Bf1(_, he), ce = new Mf1, ye = new bf1(De), Se = new qc1(_, a, b, _e, G, x1, I), le = new Uf(_, G, we), v = new Gf(m, Xe, we, _e), fe = new $c1(m, De, Xe), Ie = new rl1(m, De, Xe), Xe.programs = pe.programs, _.capabilities = we, _.extensions = De, _.properties = he, _.renderLists = ce, _.shadowMap = le, _.state = _e, _.info = Xe;
        }
        te();
        let N = new Zn1(_, m);
        this.xr = N, this.getContext = function() {
            return m;
        }, this.getContextAttributes = function() {
            return m.getContextAttributes();
        }, this.forceContextLoss = function() {
            let o = De.get("WEBGL_lose_context");
            o && o.loseContext();
        }, this.forceContextRestore = function() {
            let o = De.get("WEBGL_lose_context");
            o && o.restoreContext();
        }, this.getPixelRatio = function() {
            return F;
        }, this.setPixelRatio = function(o) {
            o !== void 0 && (F = o, this.setSize(z, j, !1));
        }, this.getSize = function(o) {
            return o.set(z, j);
        }, this.setSize = function(o, g, U = !0) {
            if (N.isPresenting) {
                console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting.");
                return;
            }
            z = o, j = g, t.width = Math.floor(o * F), t.height = Math.floor(g * F), U === !0 && (t.style.width = o + "px", t.style.height = g + "px"), this.setViewport(0, 0, o, g);
        }, this.getDrawingBufferSize = function(o) {
            return o.set(z * F, j * F).floor();
        }, this.setDrawingBufferSize = function(o, g, U) {
            z = o, j = g, F = U, t.width = Math.floor(o * U), t.height = Math.floor(g * U), this.setViewport(0, 0, o, g);
        }, this.getCurrentViewport = function(o) {
            return o.copy(A);
        }, this.getViewport = function(o) {
            return o.copy(Le);
        }, this.setViewport = function(o, g, U, D) {
            o.isVector4 ? Le.set(o.x, o.y, o.z, o.w) : Le.set(o, g, U, D), _e.viewport(A.copy(Le).multiplyScalar(F).round());
        }, this.getScissor = function(o) {
            return o.copy(Ge);
        }, this.setScissor = function(o, g, U, D) {
            o.isVector4 ? Ge.set(o.x, o.y, o.z, o.w) : Ge.set(o, g, U, D), _e.scissor(q.copy(Ge).multiplyScalar(F).round());
        }, this.getScissorTest = function() {
            return Ze;
        }, this.setScissorTest = function(o) {
            _e.setScissorTest(Ze = o);
        }, this.setOpaqueSort = function(o) {
            me = o;
        }, this.setTransparentSort = function(o) {
            Me = o;
        }, this.getClearColor = function(o) {
            return o.copy(Se.getClearColor());
        }, this.setClearColor = function() {
            Se.setClearColor.apply(Se, arguments);
        }, this.getClearAlpha = function() {
            return Se.getClearAlpha();
        }, this.setClearAlpha = function() {
            Se.setClearAlpha.apply(Se, arguments);
        }, this.clear = function(o = !0, g = !0, U = !0) {
            let D = 0;
            if (o) {
                let E = !1;
                if (B !== null) {
                    let $ = B.texture.format;
                    E = $ === uc || $ === cc || $ === Il;
                }
                if (E) {
                    let $ = B.texture.type, ne = $ === Sl || $ === Wo || $ === jl || $ === sc || $ === ec || $ === ic, se = Se.getClearColor(), de = Se.getClearAlpha(), Ae = se.r, Re = se.g, ve = se.b;
                    ne ? (O[0] = Ae, O[1] = Re, O[2] = ve, O[3] = de, m.clearBufferuiv(m.COLOR, 0, O)) : (L[0] = Ae, L[1] = Re, L[2] = ve, L[3] = de, m.clearBufferiv(m.COLOR, 0, L));
                } else D |= m.COLOR_BUFFER_BIT;
            }
            g && (D |= m.DEPTH_BUFFER_BIT), U && (D |= m.STENCIL_BUFFER_BIT, this.state.buffers.stencil.setMask(4294967295)), m.clear(D);
        }, this.clearColor = function() {
            this.clear(!0, !1, !1);
        }, this.clearDepth = function() {
            this.clear(!1, !0, !1);
        }, this.clearStencil = function() {
            this.clear(!1, !1, !0);
        }, this.dispose = function() {
            t.removeEventListener("webglcontextlost", X, !1), t.removeEventListener("webglcontextrestored", oe, !1), t.removeEventListener("webglcontextcreationerror", ae, !1), Se.dispose(), ce.dispose(), ye.dispose(), he.dispose(), a.dispose(), b.dispose(), G.dispose(), ze.dispose(), v.dispose(), pe.dispose(), N.dispose(), N.removeEventListener("sessionstart", jn), N.removeEventListener("sessionend", ei), Rt.stop();
        };
        function X(o) {
            o.preventDefault(), console.log("THREE.WebGLRenderer: Context Lost."), H = !0;
        }
        function oe() {
            console.log("THREE.WebGLRenderer: Context Restored."), H = !1;
            let o = Xe.autoReset, g = le.enabled, U = le.autoUpdate, D = le.needsUpdate, E = le.type;
            te(), Xe.autoReset = o, le.enabled = g, le.autoUpdate = U, le.needsUpdate = D, le.type = E;
        }
        function ae(o) {
            console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ", o.statusMessage);
        }
        function Ce(o) {
            let g = o.target;
            g.removeEventListener("dispose", Ce), Qe(g);
        }
        function Qe(o) {
            at(o), he.remove(o);
        }
        function at(o) {
            let g = he.get(o).programs;
            g !== void 0 && (g.forEach(function(U) {
                pe.releaseProgram(U);
            }), o.isShaderMaterial && pe.releaseShaderCache(o));
        }
        this.renderBufferDirect = function(o, g, U, D, E, $) {
            g === null && (g = je);
            let ne = E.isMesh && E.matrixWorld.determinant() < 0, se = wr(o, g, U, D, E);
            _e.setMaterial(D, ne);
            let de = U.index, Ae = 1;
            if (D.wireframe === !0) {
                if (de = K.getWireframeAttribute(U), de === void 0) return;
                Ae = 2;
            }
            let Re = U.drawRange, ve = U.attributes.position, Ne = Re.start * Ae, He = (Re.start + Re.count) * Ae;
            $ !== null && (Ne = Math.max(Ne, $.start * Ae), He = Math.min(He, ($.start + $.count) * Ae)), de !== null ? (Ne = Math.max(Ne, 0), He = Math.min(He, de.count)) : ve != null && (Ne = Math.max(Ne, 0), He = Math.min(He, ve.count));
            let et = He - Ne;
            if (et < 0 || et === 1 / 0) return;
            ze.setup(E, D, se, U, de);
            let Je, Oe = fe;
            if (de !== null && (Je = W.get(de), Oe = Ie, Oe.setIndex(Je)), E.isMesh) D.wireframe === !0 ? (_e.setLineWidth(D.wireframeLinewidth * Ue()), Oe.setMode(m.LINES)) : Oe.setMode(m.TRIANGLES);
            else if (E.isLine) {
                let ge = D.linewidth;
                ge === void 0 && (ge = 1), _e.setLineWidth(ge * Ue()), E.isLineSegments ? Oe.setMode(m.LINES) : E.isLineLoop ? Oe.setMode(m.LINE_LOOP) : Oe.setMode(m.LINE_STRIP);
            } else E.isPoints ? Oe.setMode(m.POINTS) : E.isSprite && Oe.setMode(m.TRIANGLES);
            if (E.isBatchedMesh) if (E._multiDrawInstances !== null) Oe.renderMultiDrawInstances(E._multiDrawStarts, E._multiDrawCounts, E._multiDrawCount, E._multiDrawInstances);
            else if (De.get("WEBGL_multi_draw")) Oe.renderMultiDraw(E._multiDrawStarts, E._multiDrawCounts, E._multiDrawCount);
            else {
                let ge = E._multiDrawStarts, rt = E._multiDrawCounts, Ve = E._multiDrawCount, vt = de ? W.get(de).bytesPerElement : 1, Nt = he.get(D).currentProgram.getUniforms();
                for(let dt = 0; dt < Ve; dt++)Nt.setValue(m, "_gl_DrawID", dt), Oe.render(ge[dt] / vt, rt[dt]);
            }
            else if (E.isInstancedMesh) Oe.renderInstances(Ne, et, E.count);
            else if (U.isInstancedBufferGeometry) {
                let ge = U._maxInstanceCount !== void 0 ? U._maxInstanceCount : 1 / 0, rt = Math.min(U.instanceCount, ge);
                Oe.renderInstances(Ne, et, rt);
            } else Oe.render(Ne, et);
        };
        function ke(o, g, U) {
            o.transparent === !0 && o.side === Yd && o.forceSinglePass === !1 ? (o.side = Al, o.needsUpdate = !0, nn(o, g, U), o.side = dr, o.needsUpdate = !0, nn(o, g, U), o.side = Yd) : nn(o, g, U);
        }
        this.compile = function(o, g, U = null) {
            U === null && (U = o), r = ye.get(U), r.init(g), M.push(r), U.traverseVisible(function(E) {
                E.isLight && E.layers.test(g.layers) && (r.pushLight(E), E.castShadow && r.pushShadow(E));
            }), o !== U && o.traverseVisible(function(E) {
                E.isLight && E.layers.test(g.layers) && (r.pushLight(E), E.castShadow && r.pushShadow(E));
            }), r.setupLights();
            let D = new Set;
            return o.traverse(function(E) {
                if (!(E.isMesh || E.isPoints || E.isLine || E.isSprite)) return;
                let $ = E.material;
                if ($) if (Array.isArray($)) for(let ne = 0; ne < $.length; ne++){
                    let se = $[ne];
                    ke(se, U, E), D.add(se);
                }
                else ke($, U, E), D.add($);
            }), M.pop(), r = null, D;
        }, this.compileAsync = function(o, g, U = null) {
            let D = this.compile(o, g, U);
            return new Promise((E)=>{
                function $() {
                    if (D.forEach(function(ne) {
                        he.get(ne).currentProgram.isReady() && D.delete(ne);
                    }), D.size === 0) {
                        E(o);
                        return;
                    }
                    setTimeout($, 10);
                }
                De.get("KHR_parallel_shader_compile") !== null ? $() : setTimeout($, 10);
            });
        };
        let _t = null;
        function St(o) {
            _t && _t(o);
        }
        function jn() {
            Rt.stop();
        }
        function ei() {
            Rt.start();
        }
        let Rt = new br1;
        Rt.setAnimationLoop(St), typeof self < "u" && Rt.setContext(self), this.setAnimationLoop = function(o) {
            _t = o, N.setAnimationLoop(o), o === null ? Rt.stop() : Rt.start();
        }, N.addEventListener("sessionstart", jn), N.addEventListener("sessionend", ei), this.render = function(o, g) {
            if (g !== void 0 && g.isCamera !== !0) {
                console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");
                return;
            }
            if (H === !0) return;
            if (o.matrixWorldAutoUpdate === !0 && o.updateMatrixWorld(), g.parent === null && g.matrixWorldAutoUpdate === !0 && g.updateMatrixWorld(), N.enabled === !0 && N.isPresenting === !0 && (N.cameraAutoUpdate === !0 && N.updateCamera(g), g = N.getCamera()), o.isScene === !0 && o.onBeforeRender(_, o, g, B), r = ye.get(o, M.length), r.init(g), M.push(r), Ee.multiplyMatrices(g.projectionMatrix, g.matrixWorldInverse), k.setFromProjectionMatrix(Ee), ue = this.localClippingEnabled, J = Z.init(this.clippingPlanes, ue), l = ce.get(o, w1.length), l.init(), w1.push(l), N.enabled === !0 && N.isPresenting === !0) {
                let $ = _.xr.getDepthSensingMesh();
                $ !== null && Sn($, g, -1 / 0, _.sortObjects);
            }
            Sn(o, g, 0, _.sortObjects), l.finish(), _.sortObjects === !0 && l.sort(me, Me), $e = N.enabled === !1 || N.isPresenting === !1 || N.hasDepthSensing() === !1, $e && Se.addToRenderList(l, o), this.info.render.frame++, J === !0 && Z.beginShadows();
            let U = r.state.shadowsArray;
            le.render(U, o, g), J === !0 && Z.endShadows(), this.info.autoReset === !0 && this.info.reset();
            let D = l.opaque, E = l.transmissive;
            if (r.setupLights(), g.isArrayCamera) {
                let $ = g.cameras;
                if (E.length > 0) for(let ne = 0, se = $.length; ne < se; ne++){
                    let de = $[ne];
                    ni(D, E, o, de);
                }
                $e && Se.render(o);
                for(let ne = 0, se = $.length; ne < se; ne++){
                    let de = $[ne];
                    ti(l, o, de, de.viewport);
                }
            } else E.length > 0 && ni(D, E, o, g), $e && Se.render(o), ti(l, o, g);
            B !== null && y1 === 0 && (u.updateMultisampleRenderTarget(B), u.updateRenderTargetMipmap(B)), o.isScene === !0 && o.onAfterRender(_, o, g), ze.resetDefaultState(), p = -1, f = null, M.pop(), M.length > 0 ? (r = M[M.length - 1], J === !0 && Z.setGlobalState(_.clippingPlanes, r.state.camera)) : r = null, w1.pop(), w1.length > 0 ? l = w1[w1.length - 1] : l = null;
        };
        function Sn(o, g, U, D) {
            if (o.visible === !1) return;
            if (o.layers.test(g.layers)) {
                if (o.isGroup) U = o.renderOrder;
                else if (o.isLOD) o.autoUpdate === !0 && o.update(g);
                else if (o.isLight) r.pushLight(o), o.castShadow && r.pushShadow(o);
                else if (o.isSprite) {
                    if (!o.frustumCulled || k.intersectsSprite(o)) {
                        D && Te.setFromMatrixPosition(o.matrixWorld).applyMatrix4(Ee);
                        let ne = G.update(o), se = o.material;
                        se.visible && l.push(o, ne, se, U, Te.z, null);
                    }
                } else if ((o.isMesh || o.isLine || o.isPoints) && (!o.frustumCulled || k.intersectsObject(o))) {
                    let ne = G.update(o), se = o.material;
                    if (D && (o.boundingSphere !== void 0 ? (o.boundingSphere === null && o.computeBoundingSphere(), Te.copy(o.boundingSphere.center)) : (ne.boundingSphere === null && ne.computeBoundingSphere(), Te.copy(ne.boundingSphere.center)), Te.applyMatrix4(o.matrixWorld).applyMatrix4(Ee)), Array.isArray(se)) {
                        let de = ne.groups;
                        for(let Ae = 0, Re = de.length; Ae < Re; Ae++){
                            let ve = de[Ae], Ne = se[ve.materialIndex];
                            Ne && Ne.visible && l.push(o, ne, Ne, U, Te.z, ve);
                        }
                    } else se.visible && l.push(o, ne, se, U, Te.z, null);
                }
            }
            let $ = o.children;
            for(let ne = 0, se = $.length; ne < se; ne++)Sn($[ne], g, U, D);
        }
        function ti(o, g, U, D) {
            let E = o.opaque, $ = o.transmissive, ne = o.transparent;
            r.setupLightsView(U), J === !0 && Z.setGlobalState(_.clippingPlanes, U), D && _e.viewport(A.copy(D)), E.length > 0 && tn(E, g, U), $.length > 0 && tn($, g, U), ne.length > 0 && tn(ne, g, U), _e.buffers.depth.setTest(!0), _e.buffers.depth.setMask(!0), _e.buffers.color.setMask(!0), _e.setPolygonOffset(!1);
        }
        function ni(o, g, U, D) {
            if ((U.isScene === !0 ? U.overrideMaterial : null) !== null) return;
            r.state.transmissionRenderTarget[D.id] === void 0 && (r.state.transmissionRenderTarget[D.id] = new Hi(1, 1, {
                generateMipmaps: !0,
                type: De.has("EXT_color_buffer_half_float") || De.has("EXT_color_buffer_float") ? tc : Sl,
                minFilter: vn,
                samples: 4,
                stencilBuffer: s,
                resolveDepthBuffer: !1,
                resolveStencilBuffer: !1,
                colorSpace: Tt.workingColorSpace
            }));
            let $ = r.state.transmissionRenderTarget[D.id], ne = D.viewport || A;
            $.setSize(ne.z * _.transmissionResolutionScale, ne.w * _.transmissionResolutionScale);
            let se = _.getRenderTarget();
            _.setRenderTarget($), _.getClearColor(Y), Q = _.getClearAlpha(), Q < 1 && _.setClearColor(16777215, .5), _.clear(), $e && Se.render(U);
            let de = _.toneMapping;
            _.toneMapping = Tp;
            let Ae = D.viewport;
            if (D.viewport !== void 0 && (D.viewport = void 0), r.setupLightsView(D), J === !0 && Z.setGlobalState(_.clippingPlanes, D), tn(o, U, D), u.updateMultisampleRenderTarget($), u.updateRenderTargetMipmap($), De.has("WEBGL_multisampled_render_to_texture") === !1) {
                let Re = !1;
                for(let ve = 0, Ne = g.length; ve < Ne; ve++){
                    let He = g[ve], et = He.object, Je = He.geometry, Oe = He.material, ge = He.group;
                    if (Oe.side === Yd && et.layers.test(D.layers)) {
                        let rt = Oe.side;
                        Oe.side = Al, Oe.needsUpdate = !0, ii(et, U, D, Je, Oe, ge), Oe.side = rt, Oe.needsUpdate = !0, Re = !0;
                    }
                }
                Re === !0 && (u.updateMultisampleRenderTarget($), u.updateRenderTargetMipmap($));
            }
            _.setRenderTarget(se), _.setClearColor(Y, Q), Ae !== void 0 && (D.viewport = Ae), _.toneMapping = de;
        }
        function tn(o, g, U) {
            let D = g.isScene === !0 ? g.overrideMaterial : null;
            for(let E = 0, $ = o.length; E < $; E++){
                let ne = o[E], se = ne.object, de = ne.geometry, Ae = D === null ? ne.material : D, Re = ne.group;
                se.layers.test(U.layers) && ii(se, g, U, de, Ae, Re);
            }
        }
        function ii(o, g, U, D, E, $) {
            o.onBeforeRender(_, g, U, D, E, $), o.modelViewMatrix.multiplyMatrices(U.matrixWorldInverse, o.matrixWorld), o.normalMatrix.getNormalMatrix(o.modelViewMatrix), E.onBeforeRender(_, g, U, D, o, $), E.transparent === !0 && E.side === Yd && E.forceSinglePass === !1 ? (E.side = Al, E.needsUpdate = !0, _.renderBufferDirect(U, g, D, E, o, $), E.side = dr, E.needsUpdate = !0, _.renderBufferDirect(U, g, D, E, o, $), E.side = Yd) : _.renderBufferDirect(U, g, D, E, o, $), o.onAfterRender(_, g, U, D, E, $);
        }
        function nn(o, g, U) {
            g.isScene !== !0 && (g = je);
            let D = he.get(o), E = r.state.lights, $ = r.state.shadowsArray, ne = E.state.version, se = pe.getParameters(o, E.state, $, g, U), de = pe.getProgramCacheKey(se), Ae = D.programs;
            D.environment = o.isMeshStandardMaterial ? g.environment : null, D.fog = g.fog, D.envMap = (o.isMeshStandardMaterial ? b : a).get(o.envMap || D.environment), D.envMapRotation = D.environment !== null && o.envMap === null ? g.environmentRotation : o.envMapRotation, Ae === void 0 && (o.addEventListener("dispose", Ce), Ae = new Map, D.programs = Ae);
            let Re = Ae.get(de);
            if (Re !== void 0) {
                if (D.currentProgram === Re && D.lightsStateVersion === ne) return ai(o, se), Re;
            } else se.uniforms = pe.getUniforms(o), o.onBeforeCompile(se, _), Re = pe.acquireProgram(se, de), Ae.set(de, Re), D.uniforms = se.uniforms;
            let ve = D.uniforms;
            return (!o.isShaderMaterial && !o.isRawShaderMaterial || o.clipping === !0) && (ve.clippingPlanes = Z.uniform), ai(o, se), D.needsLights = yr(o), D.lightsStateVersion = ne, D.needsLights && (ve.ambientLightColor.value = E.state.ambient, ve.lightProbe.value = E.state.probe, ve.directionalLights.value = E.state.directional, ve.directionalLightShadows.value = E.state.directionalShadow, ve.spotLights.value = E.state.spot, ve.spotLightShadows.value = E.state.spotShadow, ve.rectAreaLights.value = E.state.rectArea, ve.ltc_1.value = E.state.rectAreaLTC1, ve.ltc_2.value = E.state.rectAreaLTC2, ve.pointLights.value = E.state.point, ve.pointLightShadows.value = E.state.pointShadow, ve.hemisphereLights.value = E.state.hemi, ve.directionalShadowMap.value = E.state.directionalShadowMap, ve.directionalShadowMatrix.value = E.state.directionalShadowMatrix, ve.spotShadowMap.value = E.state.spotShadowMap, ve.spotLightMatrix.value = E.state.spotLightMatrix, ve.spotLightMap.value = E.state.spotLightMap, ve.pointShadowMap.value = E.state.pointShadowMap, ve.pointShadowMatrix.value = E.state.pointShadowMatrix), D.currentProgram = Re, D.uniformsList = null, Re;
        }
        function ri(o) {
            if (o.uniformsList === null) {
                let g = o.currentProgram.getUniforms();
                o.uniformsList = Vt1.seqWithValue(g.seq, o.uniforms);
            }
            return o.uniformsList;
        }
        function ai(o, g) {
            let U = he.get(o);
            U.outputColorSpace = g.outputColorSpace, U.batching = g.batching, U.batchingColor = g.batchingColor, U.instancing = g.instancing, U.instancingColor = g.instancingColor, U.instancingMorph = g.instancingMorph, U.skinning = g.skinning, U.morphTargets = g.morphTargets, U.morphNormals = g.morphNormals, U.morphColors = g.morphColors, U.morphTargetsCount = g.morphTargetsCount, U.numClippingPlanes = g.numClippingPlanes, U.numIntersection = g.numClipIntersection, U.vertexAlphas = g.vertexAlphas, U.vertexTangents = g.vertexTangents, U.toneMapping = g.toneMapping;
        }
        function wr(o, g, U, D, E) {
            g.isScene !== !0 && (g = je), u.resetTextureUnits();
            let $ = g.fog, ne = D.isMeshStandardMaterial ? g.environment : null, se = B === null ? _.outputColorSpace : B.isXRRenderTarget === !0 ? B.texture.colorSpace : ha, de = (D.isMeshStandardMaterial ? b : a).get(D.envMap || ne), Ae = D.vertexColors === !0 && !!U.attributes.color && U.attributes.color.itemSize === 4, Re = !!U.attributes.tangent && (!!D.normalMap || D.anisotropy > 0), ve = !!U.morphAttributes.position, Ne = !!U.morphAttributes.normal, He = !!U.morphAttributes.color, et = Tp;
            D.toneMapped && (B === null || B.isXRRenderTarget === !0) && (et = _.toneMapping);
            let Je = U.morphAttributes.position || U.morphAttributes.normal || U.morphAttributes.color, Oe = Je !== void 0 ? Je.length : 0, ge = he.get(D), rt = r.state.lights;
            if (J === !0 && (ue === !0 || o !== f)) {
                let ot = o === f && D.id === p;
                Z.setState(D, o, ot);
            }
            let Ve = !1;
            D.version === ge.__version ? (ge.needsLights && ge.lightsStateVersion !== rt.state.version || ge.outputColorSpace !== se || E.isBatchedMesh && ge.batching === !1 || !E.isBatchedMesh && ge.batching === !0 || E.isBatchedMesh && ge.batchingColor === !0 && E.colorTexture === null || E.isBatchedMesh && ge.batchingColor === !1 && E.colorTexture !== null || E.isInstancedMesh && ge.instancing === !1 || !E.isInstancedMesh && ge.instancing === !0 || E.isSkinnedMesh && ge.skinning === !1 || !E.isSkinnedMesh && ge.skinning === !0 || E.isInstancedMesh && ge.instancingColor === !0 && E.instanceColor === null || E.isInstancedMesh && ge.instancingColor === !1 && E.instanceColor !== null || E.isInstancedMesh && ge.instancingMorph === !0 && E.morphTexture === null || E.isInstancedMesh && ge.instancingMorph === !1 && E.morphTexture !== null || ge.envMap !== de || D.fog === !0 && ge.fog !== $ || ge.numClippingPlanes !== void 0 && (ge.numClippingPlanes !== Z.numPlanes || ge.numIntersection !== Z.numIntersection) || ge.vertexAlphas !== Ae || ge.vertexTangents !== Re || ge.morphTargets !== ve || ge.morphNormals !== Ne || ge.morphColors !== He || ge.toneMapping !== et || ge.morphTargetsCount !== Oe) && (Ve = !0) : (Ve = !0, ge.__version = D.version);
            let vt = ge.currentProgram;
            Ve === !0 && (vt = nn(D, g, E));
            let Nt = !1, dt = !1, Yt = !1, qe = vt.getUniforms(), pt = ge.uniforms;
            if (_e.useProgram(vt.program) && (Nt = !0, dt = !0, Yt = !0), D.id !== p && (p = D.id, dt = !0), Nt || f !== o) {
                _e.buffers.depth.getReversed() ? (ie.copy(o.projectionMatrix), Ff(ie), Bf(ie), qe.setValue(m, "projectionMatrix", ie)) : qe.setValue(m, "projectionMatrix", o.projectionMatrix), qe.setValue(m, "viewMatrix", o.matrixWorldInverse);
                let st = qe.map.cameraPosition;
                st !== void 0 && st.setValue(m, Be.setFromMatrixPosition(o.matrixWorld)), we.logarithmicDepthBuffer && qe.setValue(m, "logDepthBufFC", 2 / (Math.log(o.far + 1) / Math.LN2)), (D.isMeshPhongMaterial || D.isMeshToonMaterial || D.isMeshLambertMaterial || D.isMeshBasicMaterial || D.isMeshStandardMaterial || D.isShaderMaterial) && qe.setValue(m, "isOrthographic", o.isOrthographicCamera === !0), f !== o && (f = o, dt = !0, Yt = !0);
            }
            if (E.isSkinnedMesh) {
                qe.setOptional(m, E, "bindMatrix"), qe.setOptional(m, E, "bindMatrixInverse");
                let ot = E.skeleton;
                ot && (ot.boneTexture === null && ot.computeBoneTexture(), qe.setValue(m, "boneTexture", ot.boneTexture, u));
            }
            E.isBatchedMesh && (qe.setOptional(m, E, "batchingTexture"), qe.setValue(m, "batchingTexture", E._matricesTexture, u), qe.setOptional(m, E, "batchingIdTexture"), qe.setValue(m, "batchingIdTexture", E._indirectTexture, u), qe.setOptional(m, E, "batchingColorTexture"), E._colorsTexture !== null && qe.setValue(m, "batchingColorTexture", E._colorsTexture, u));
            let ht = U.morphAttributes;
            if ((ht.position !== void 0 || ht.normal !== void 0 || ht.color !== void 0) && xe.update(E, U, vt), (dt || ge.receiveShadow !== E.receiveShadow) && (ge.receiveShadow = E.receiveShadow, qe.setValue(m, "receiveShadow", E.receiveShadow)), D.isMeshGouraudMaterial && D.envMap !== null && (pt.envMap.value = de, pt.flipEnvMap.value = de.isCubeTexture && de.isRenderTargetTexture === !1 ? -1 : 1), D.isMeshStandardMaterial && D.envMap === null && g.environment !== null && (pt.envMapIntensity.value = g.environmentIntensity), dt && (qe.setValue(m, "toneMappingExposure", _.toneMappingExposure), ge.needsLights && Ir(pt, Yt), $ && D.fog === !0 && re.refreshFogUniforms(pt, $), re.refreshMaterialUniforms(pt, D, F, j, r.state.transmissionRenderTarget[o.id]), Vt1.upload(m, ri(ge), pt, u)), D.isShaderMaterial && D.uniformsNeedUpdate === !0 && (Vt1.upload(m, ri(ge), pt, u), D.uniformsNeedUpdate = !1), D.isSpriteMaterial && qe.setValue(m, "center", E.center), qe.setValue(m, "modelViewMatrix", E.modelViewMatrix), qe.setValue(m, "normalMatrix", E.normalMatrix), qe.setValue(m, "modelMatrix", E.matrixWorld), D.isShaderMaterial || D.isRawShaderMaterial) {
                let ot = D.uniformsGroups;
                for(let st = 0, En = ot.length; st < En; st++){
                    let Ct = ot[st];
                    v.update(Ct, vt), v.bind(Ct, vt);
                }
            }
            return vt;
        }
        function Ir(o, g) {
            o.ambientLightColor.needsUpdate = g, o.lightProbe.needsUpdate = g, o.directionalLights.needsUpdate = g, o.directionalLightShadows.needsUpdate = g, o.pointLights.needsUpdate = g, o.pointLightShadows.needsUpdate = g, o.spotLights.needsUpdate = g, o.spotLightShadows.needsUpdate = g, o.rectAreaLights.needsUpdate = g, o.hemisphereLights.needsUpdate = g;
        }
        function yr(o) {
            return o.isMeshLambertMaterial || o.isMeshToonMaterial || o.isMeshPhongMaterial || o.isMeshStandardMaterial || o.isShadowMaterial || o.isShaderMaterial && o.lights === !0;
        }
        this.getActiveCubeFace = function() {
            return P1;
        }, this.getActiveMipmapLevel = function() {
            return y1;
        }, this.getRenderTarget = function() {
            return B;
        }, this.setRenderTargetTextures = function(o, g, U) {
            he.get(o.texture).__webglTexture = g, he.get(o.depthTexture).__webglTexture = U;
            let D = he.get(o);
            D.__hasExternalTextures = !0, D.__autoAllocateDepthBuffer = U === void 0, D.__autoAllocateDepthBuffer || De.has("WEBGL_multisampled_render_to_texture") === !0 && (console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"), D.__useRenderToTexture = !1);
        }, this.setRenderTargetFramebuffer = function(o, g) {
            let U = he.get(o);
            U.__webglFramebuffer = g, U.__useDefaultFramebuffer = g === void 0;
        };
        let Nr = m.createFramebuffer();
        this.setRenderTarget = function(o, g = 0, U = 0) {
            B = o, P1 = g, y1 = U;
            let D = !0, E = null, $ = !1, ne = !1;
            if (o) {
                let de = he.get(o);
                if (de.__useDefaultFramebuffer !== void 0) _e.bindFramebuffer(m.FRAMEBUFFER, null), D = !1;
                else if (de.__webglFramebuffer === void 0) u.setupRenderTarget(o);
                else if (de.__hasExternalTextures) u.rebindTextures(o, he.get(o.texture).__webglTexture, he.get(o.depthTexture).__webglTexture);
                else if (o.depthBuffer) {
                    let ve = o.depthTexture;
                    if (de.__boundDepthTexture !== ve) {
                        if (ve !== null && he.has(ve) && (o.width !== ve.image.width || o.height !== ve.image.height)) throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");
                        u.setupDepthRenderbuffer(o);
                    }
                }
                let Ae = o.texture;
                (Ae.isData3DTexture || Ae.isDataArrayTexture || Ae.isCompressedArrayTexture) && (ne = !0);
                let Re = he.get(o).__webglFramebuffer;
                o.isWebGLCubeRenderTarget ? (Array.isArray(Re[g]) ? E = Re[g][U] : E = Re[g], $ = !0) : o.samples > 0 && u.useMultisampledRTT(o) === !1 ? E = he.get(o).__webglMultisampledFramebuffer : Array.isArray(Re) ? E = Re[U] : E = Re, A.copy(o.viewport), q.copy(o.scissor), V = o.scissorTest;
            } else A.copy(Le).multiplyScalar(F).floor(), q.copy(Ge).multiplyScalar(F).floor(), V = Ze;
            if (U !== 0 && (E = Nr), _e.bindFramebuffer(m.FRAMEBUFFER, E) && D && _e.drawBuffers(o, E), _e.viewport(A), _e.scissor(q), _e.setScissorTest(V), $) {
                let de = he.get(o.texture);
                m.framebufferTexture2D(m.FRAMEBUFFER, m.COLOR_ATTACHMENT0, m.TEXTURE_CUBE_MAP_POSITIVE_X + g, de.__webglTexture, U);
            } else if (ne) {
                let de = he.get(o.texture), Ae = g;
                m.framebufferTextureLayer(m.FRAMEBUFFER, m.COLOR_ATTACHMENT0, de.__webglTexture, U, Ae);
            } else if (o !== null && U !== 0) {
                let de = he.get(o.texture);
                m.framebufferTexture2D(m.FRAMEBUFFER, m.COLOR_ATTACHMENT0, m.TEXTURE_2D, de.__webglTexture, U);
            }
            p = -1;
        }, this.readRenderTargetPixels = function(o, g, U, D, E, $, ne) {
            if (!(o && o.isWebGLRenderTarget)) {
                console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");
                return;
            }
            let se = he.get(o).__webglFramebuffer;
            if (o.isWebGLCubeRenderTarget && ne !== void 0 && (se = se[ne]), se) {
                _e.bindFramebuffer(m.FRAMEBUFFER, se);
                try {
                    let de = o.texture, Ae = de.format, Re = de.type;
                    if (!we.textureFormatReadable(Ae)) {
                        console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");
                        return;
                    }
                    if (!we.textureTypeReadable(Re)) {
                        console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");
                        return;
                    }
                    g >= 0 && g <= o.width - D && U >= 0 && U <= o.height - E && m.readPixels(g, U, D, E, be.convert(Ae), be.convert(Re), $);
                } finally{
                    let de = B !== null ? he.get(B).__webglFramebuffer : null;
                    _e.bindFramebuffer(m.FRAMEBUFFER, de);
                }
            }
        }, this.readRenderTargetPixelsAsync = async function(o, g, U, D, E, $, ne) {
            if (!(o && o.isWebGLRenderTarget)) throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");
            let se = he.get(o).__webglFramebuffer;
            if (o.isWebGLCubeRenderTarget && ne !== void 0 && (se = se[ne]), se) {
                let de = o.texture, Ae = de.format, Re = de.type;
                if (!we.textureFormatReadable(Ae)) throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");
                if (!we.textureTypeReadable(Re)) throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");
                if (g >= 0 && g <= o.width - D && U >= 0 && U <= o.height - E) {
                    _e.bindFramebuffer(m.FRAMEBUFFER, se);
                    let ve = m.createBuffer();
                    m.bindBuffer(m.PIXEL_PACK_BUFFER, ve), m.bufferData(m.PIXEL_PACK_BUFFER, $.byteLength, m.STREAM_READ), m.readPixels(g, U, D, E, be.convert(Ae), be.convert(Re), 0);
                    let Ne = B !== null ? he.get(B).__webglFramebuffer : null;
                    _e.bindFramebuffer(m.FRAMEBUFFER, Ne);
                    let He = m.fenceSync(m.SYNC_GPU_COMMANDS_COMPLETE, 0);
                    return m.flush(), await zf(m, He, 4), m.bindBuffer(m.PIXEL_PACK_BUFFER, ve), m.getBufferSubData(m.PIXEL_PACK_BUFFER, 0, $), m.deleteBuffer(ve), m.deleteSync(He), $;
                } else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.");
            }
        }, this.copyFramebufferToTexture = function(o, g = null, U = 0) {
            o.isTexture !== !0 && (Cf("WebGLRenderer: copyFramebufferToTexture function signature has changed."), g = arguments[0] || null, o = arguments[1]);
            let D = Math.pow(2, -U), E = Math.floor(o.image.width * D), $ = Math.floor(o.image.height * D), ne = g !== null ? g.x : 0, se = g !== null ? g.y : 0;
            u.setTexture2D(o, 0), m.copyTexSubImage2D(m.TEXTURE_2D, U, 0, 0, ne, se, E, $), _e.unbindTexture();
        };
        let Or = m.createFramebuffer(), Fr = m.createFramebuffer();
        this.copyTextureToTexture = function(o, g, U = null, D = null, E = 0, $ = null) {
            o.isTexture !== !0 && (Cf("WebGLRenderer: copyTextureToTexture function signature has changed."), D = arguments[0] || null, o = arguments[1], g = arguments[2], $ = arguments[3] || 0, U = null), $ === null && (E !== 0 ? (Cf("WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels."), $ = E, E = 0) : $ = 0);
            let ne, se, de, Ae, Re, ve, Ne, He, et, Je = o.isCompressedTexture ? o.mipmaps[$] : o.image;
            if (U !== null) ne = U.max.x - U.min.x, se = U.max.y - U.min.y, de = U.isBox3 ? U.max.z - U.min.z : 1, Ae = U.min.x, Re = U.min.y, ve = U.isBox3 ? U.min.z : 0;
            else {
                let ht = Math.pow(2, -E);
                ne = Math.floor(Je.width * ht), se = Math.floor(Je.height * ht), o.isDataArrayTexture ? de = Je.depth : o.isData3DTexture ? de = Math.floor(Je.depth * ht) : de = 1, Ae = 0, Re = 0, ve = 0;
            }
            D !== null ? (Ne = D.x, He = D.y, et = D.z) : (Ne = 0, He = 0, et = 0);
            let Oe = be.convert(g.format), ge = be.convert(g.type), rt;
            g.isData3DTexture ? (u.setTexture3D(g, 0), rt = m.TEXTURE_3D) : g.isDataArrayTexture || g.isCompressedArrayTexture ? (u.setTexture2DArray(g, 0), rt = m.TEXTURE_2D_ARRAY) : (u.setTexture2D(g, 0), rt = m.TEXTURE_2D), m.pixelStorei(m.UNPACK_FLIP_Y_WEBGL, g.flipY), m.pixelStorei(m.UNPACK_PREMULTIPLY_ALPHA_WEBGL, g.premultiplyAlpha), m.pixelStorei(m.UNPACK_ALIGNMENT, g.unpackAlignment);
            let Ve = m.getParameter(m.UNPACK_ROW_LENGTH), vt = m.getParameter(m.UNPACK_IMAGE_HEIGHT), Nt = m.getParameter(m.UNPACK_SKIP_PIXELS), dt = m.getParameter(m.UNPACK_SKIP_ROWS), Yt = m.getParameter(m.UNPACK_SKIP_IMAGES);
            m.pixelStorei(m.UNPACK_ROW_LENGTH, Je.width), m.pixelStorei(m.UNPACK_IMAGE_HEIGHT, Je.height), m.pixelStorei(m.UNPACK_SKIP_PIXELS, Ae), m.pixelStorei(m.UNPACK_SKIP_ROWS, Re), m.pixelStorei(m.UNPACK_SKIP_IMAGES, ve);
            let qe = o.isDataArrayTexture || o.isData3DTexture, pt = g.isDataArrayTexture || g.isData3DTexture;
            if (o.isDepthTexture) {
                let ht = he.get(o), ot = he.get(g), st = he.get(ht.__renderTarget), En = he.get(ot.__renderTarget);
                _e.bindFramebuffer(m.READ_FRAMEBUFFER, st.__webglFramebuffer), _e.bindFramebuffer(m.DRAW_FRAMEBUFFER, En.__webglFramebuffer);
                for(let Ct = 0; Ct < de; Ct++)qe && (m.framebufferTextureLayer(m.READ_FRAMEBUFFER, m.COLOR_ATTACHMENT0, he.get(o).__webglTexture, E, ve + Ct), m.framebufferTextureLayer(m.DRAW_FRAMEBUFFER, m.COLOR_ATTACHMENT0, he.get(g).__webglTexture, $, et + Ct)), m.blitFramebuffer(Ae, Re, ne, se, Ne, He, ne, se, m.DEPTH_BUFFER_BIT, m.NEAREST);
                _e.bindFramebuffer(m.READ_FRAMEBUFFER, null), _e.bindFramebuffer(m.DRAW_FRAMEBUFFER, null);
            } else if (E !== 0 || o.isRenderTargetTexture || he.has(o)) {
                let ht = he.get(o), ot = he.get(g);
                _e.bindFramebuffer(m.READ_FRAMEBUFFER, Or), _e.bindFramebuffer(m.DRAW_FRAMEBUFFER, Fr);
                for(let st = 0; st < de; st++)qe ? m.framebufferTextureLayer(m.READ_FRAMEBUFFER, m.COLOR_ATTACHMENT0, ht.__webglTexture, E, ve + st) : m.framebufferTexture2D(m.READ_FRAMEBUFFER, m.COLOR_ATTACHMENT0, m.TEXTURE_2D, ht.__webglTexture, E), pt ? m.framebufferTextureLayer(m.DRAW_FRAMEBUFFER, m.COLOR_ATTACHMENT0, ot.__webglTexture, $, et + st) : m.framebufferTexture2D(m.DRAW_FRAMEBUFFER, m.COLOR_ATTACHMENT0, m.TEXTURE_2D, ot.__webglTexture, $), E !== 0 ? m.blitFramebuffer(Ae, Re, ne, se, Ne, He, ne, se, m.COLOR_BUFFER_BIT, m.NEAREST) : pt ? m.copyTexSubImage3D(rt, $, Ne, He, et + st, Ae, Re, ne, se) : m.copyTexSubImage2D(rt, $, Ne, He, Ae, Re, ne, se);
                _e.bindFramebuffer(m.READ_FRAMEBUFFER, null), _e.bindFramebuffer(m.DRAW_FRAMEBUFFER, null);
            } else pt ? o.isDataTexture || o.isData3DTexture ? m.texSubImage3D(rt, $, Ne, He, et, ne, se, de, Oe, ge, Je.data) : g.isCompressedArrayTexture ? m.compressedTexSubImage3D(rt, $, Ne, He, et, ne, se, de, Oe, Je.data) : m.texSubImage3D(rt, $, Ne, He, et, ne, se, de, Oe, ge, Je) : o.isDataTexture ? m.texSubImage2D(m.TEXTURE_2D, $, Ne, He, ne, se, Oe, ge, Je.data) : o.isCompressedTexture ? m.compressedTexSubImage2D(m.TEXTURE_2D, $, Ne, He, Je.width, Je.height, Oe, Je.data) : m.texSubImage2D(m.TEXTURE_2D, $, Ne, He, ne, se, Oe, ge, Je);
            m.pixelStorei(m.UNPACK_ROW_LENGTH, Ve), m.pixelStorei(m.UNPACK_IMAGE_HEIGHT, vt), m.pixelStorei(m.UNPACK_SKIP_PIXELS, Nt), m.pixelStorei(m.UNPACK_SKIP_ROWS, dt), m.pixelStorei(m.UNPACK_SKIP_IMAGES, Yt), $ === 0 && g.generateMipmaps && m.generateMipmap(rt), _e.unbindTexture();
        }, this.copyTextureToTexture3D = function(o, g, U = null, D = null, E = 0) {
            return o.isTexture !== !0 && (Cf("WebGLRenderer: copyTextureToTexture3D function signature has changed."), U = arguments[0] || null, D = arguments[1] || null, o = arguments[2], g = arguments[3], E = arguments[4] || 0), Cf('WebGLRenderer: copyTextureToTexture3D function has been deprecated. Use "copyTextureToTexture" instead.'), this.copyTextureToTexture(o, g, U, D, E);
        }, this.initRenderTarget = function(o) {
            he.get(o).__webglFramebuffer === void 0 && u.setupRenderTarget(o);
        }, this.initTexture = function(o) {
            o.isCubeTexture ? u.setTextureCube(o, 0) : o.isData3DTexture ? u.setTexture3D(o, 0) : o.isDataArrayTexture || o.isCompressedArrayTexture ? u.setTexture2DArray(o, 0) : u.setTexture2D(o, 0), _e.unbindTexture();
        }, this.resetState = function() {
            P1 = 0, y1 = 0, B = null, _e.reset(), ze.reset();
        }, typeof __THREE_DEVTOOLS__ < "u" && __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe", {
            detail: this
        }));
    }
    get coordinateSystem() {
        return oe;
    }
    get outputColorSpace() {
        return this._outputColorSpace;
    }
    set outputColorSpace(n) {
        this._outputColorSpace = n;
        let t = this.getContext();
        t.drawingBufferColorspace = Tt._getDrawingBufferColorSpace(n), t.unpackColorSpace = Tt._getUnpackColorSpace();
    }
};
const mod = {
    ACESFilmicToneMapping: Fp,
    AddEquation: ia,
    AddOperation: Sp,
    AdditiveAnimationBlendMode: Cl,
    AdditiveBlending: $d,
    AgXToneMapping: Ep,
    AlphaFormat: rc,
    AlwaysCompare: ff,
    AlwaysDepth: xp,
    AlwaysStencilFunc: ca,
    AmbientLight: To,
    AnimationAction: No,
    AnimationClip: wi,
    AnimationLoader: mh,
    AnimationMixer: Dh,
    AnimationObjectGroup: Vh,
    AnimationUtils: Pf,
    ArcCurve: kr,
    ArrayCamera: Bh,
    ArrowHelper: bl,
    AttachedBindMode: oa,
    Audio: ko,
    AudioAnalyser: Nh,
    AudioContext: _n,
    AudioListener: kh,
    AudioLoader: Ih,
    AxesHelper: wl,
    BackSide: Al,
    BasicDepthPacking: Jc,
    BasicShadowMap: Gd,
    BatchedMesh: zr,
    Bone: en,
    BooleanKeyframeTrack: ve,
    Box2: Kh,
    Box3: ft,
    Box3Helper: yl,
    BoxGeometry: Ks,
    BoxHelper: ml,
    BufferAttribute: Z,
    BufferGeometry: L,
    BufferGeometryLoader: Eo,
    ByteType: $l,
    Cache: we,
    Camera: Gi,
    CameraHelper: fl,
    CanvasTexture: ah,
    CapsuleGeometry: Dr,
    CatmullRomCurve3: Pr,
    CineonToneMapping: zp,
    CircleGeometry: Lr,
    ClampToEdgeWrapping: Ht,
    Clock: Ro,
    Color: P,
    ColorKeyframeTrack: xn,
    ColorManagement: Tt,
    CompressedArrayTexture: rh,
    CompressedCubeTexture: oh,
    CompressedTexture: Zi,
    CompressedTextureLoader: yh,
    ConeGeometry: Ur,
    ConstantAlphaFactor: mp,
    ConstantColorFactor: pp,
    Controls: _l,
    CubeCamera: br,
    CubeReflectionMapping: Uo,
    CubeRefractionMapping: Hl,
    CubeTexture: Xi,
    CubeTextureLoader: gh,
    CubeUVReflectionMapping: Xl,
    CubicBezierCurve: an,
    CubicBezierCurve3: Or,
    CubicInterpolant: mo,
    CullFaceBack: Wd,
    CullFaceFront: Hd,
    CullFaceFrontBack: qd,
    CullFaceNone: Ud,
    Curve: Rt,
    CurvePath: Vr,
    CustomBlending: Kd,
    CustomToneMapping: Bp,
    CylinderGeometry: $i,
    Cylindrical: $h,
    Data3DTexture: Qs,
    DataArrayTexture: $s,
    DataTexture: Lt,
    DataTextureLoader: xh,
    DataUtils: Ef,
    DecrementStencilOp: Yp,
    DecrementWrapStencilOp: Qp,
    DefaultLoadingManager: bd,
    DepthFormat: Cn,
    DepthStencilFormat: aa,
    DepthTexture: hh,
    DetachedBindMode: Wl,
    DirectionalLight: So,
    DirectionalLightHelper: pl,
    DiscreteInterpolant: yo,
    DodecahedronGeometry: Wr,
    DoubleSide: Yd,
    DstAlphaFactor: hp,
    DstColorFactor: cp,
    DynamicCopyUsage: Mf,
    DynamicDrawUsage: mf,
    DynamicReadUsage: xf,
    EdgesGeometry: Hr,
    EllipseCurve: Yi,
    EqualCompare: lf,
    EqualDepth: wp,
    EqualStencilFunc: ef,
    EquirectangularReflectionMapping: ql,
    EquirectangularRefractionMapping: Gl,
    Euler: Xt,
    EventDispatcher: qt,
    ExtrudeGeometry: Xr,
    FileLoader: Jt,
    Float16BufferAttribute: Ba,
    Float32BufferAttribute: E,
    FloatType: pi,
    Fog: Mr,
    FogExp2: wr,
    FramebufferTexture: nh,
    FrontSide: dr,
    Frustum: sn,
    GLBufferAttribute: Gh,
    GLSL1: vf,
    GLSL3: Af,
    GreaterCompare: uf,
    GreaterDepth: _p,
    GreaterEqualCompare: pf,
    GreaterEqualDepth: Mp,
    GreaterEqualStencilFunc: of,
    GreaterStencilFunc: nf,
    GridHelper: ll,
    Group: Ne,
    HalfFloatType: tc,
    HemisphereLight: bo,
    HemisphereLightHelper: hl,
    IcosahedronGeometry: Jr,
    ImageBitmapLoader: Th,
    ImageLoader: Mi,
    ImageUtils: yr,
    IncrementStencilOp: Zp,
    IncrementWrapStencilOp: $p,
    InstancedBufferAttribute: Ue,
    InstancedBufferGeometry: Bo,
    InstancedInterleavedBuffer: qh,
    InstancedMesh: Ir,
    Int16BufferAttribute: za,
    Int32BufferAttribute: Fa,
    Int8BufferAttribute: Ta,
    IntType: Kl,
    InterleavedBuffer: Ji,
    InterleavedBufferAttribute: fi,
    Interpolant: yi,
    InterpolateDiscrete: Gs,
    InterpolateLinear: mr,
    InterpolateSmooth: zn,
    InvertStencilOp: jp,
    KeepStencilOp: qe,
    KeyframeTrack: kt,
    LOD: Ar,
    LatheGeometry: pn,
    Layers: js,
    LessCompare: hf,
    LessDepth: bp,
    LessEqualCompare: cf,
    LessEqualDepth: ra,
    LessEqualStencilFunc: sf,
    LessStencilFunc: tf,
    Light: ce,
    LightProbe: zo,
    Line: le,
    Line3: el,
    LineBasicMaterial: mt,
    LineCurve: hn,
    LineCurve3: Nr,
    LineDashedMaterial: po,
    LineLoop: Fr,
    LineSegments: Wt,
    LinearFilter: Et,
    LinearInterpolant: gn,
    LinearMipMapLinearFilter: Np,
    LinearMipMapNearestFilter: Op,
    LinearMipmapLinearFilter: vn,
    LinearMipmapNearestFilter: Yl,
    LinearSRGBColorSpace: ha,
    LinearToneMapping: Ip,
    LinearTransfer: la,
    Loader: wt,
    LoaderUtils: Mn,
    LoadingManager: bn,
    LoopOnce: qc,
    LoopPingPong: Xc,
    LoopRepeat: Gc,
    LuminanceAlphaFormat: hc,
    LuminanceFormat: ac,
    MOUSE: Dd,
    Material: ct,
    MaterialLoader: Fo,
    MathUtils: Tf,
    Matrix2: Qh,
    Matrix3: Gt,
    Matrix4: D,
    MaxEquation: sp,
    Mesh: Ct,
    MeshBasicMaterial: _e,
    MeshDepthMaterial: lo,
    MeshDistanceMaterial: co,
    MeshLambertMaterial: ho,
    MeshMatcapMaterial: uo,
    MeshNormalMaterial: ao,
    MeshPhongMaterial: ro,
    MeshPhysicalMaterial: no,
    MeshStandardMaterial: yn,
    MeshToonMaterial: oo,
    MinEquation: ip,
    MirroredRepeatWrapping: fr,
    MixOperation: Ap,
    MultiplyBlending: jd,
    MultiplyOperation: Do,
    NearestFilter: Ut,
    NearestMipMapLinearFilter: Pp,
    NearestMipMapNearestFilter: kp,
    NearestMipmapLinearFilter: Zl,
    NearestMipmapNearestFilter: Jl,
    NeutralToneMapping: Rp,
    NeverCompare: af,
    NeverDepth: gp,
    NeverStencilFunc: Kp,
    NoBlending: Ul,
    NoColorSpace: zl,
    NoToneMapping: Tp,
    NormalAnimationBlendMode: Ho,
    NormalBlending: ea,
    NotEqualCompare: df,
    NotEqualDepth: vp,
    NotEqualStencilFunc: rf,
    NumberKeyframeTrack: gi,
    Object3D: G,
    ObjectLoader: vh,
    ObjectSpaceNormalMap: Gp,
    OctahedronGeometry: fn,
    OneFactor: rp,
    OneMinusConstantAlphaFactor: yp,
    OneMinusConstantColorFactor: fp,
    OneMinusDstAlphaFactor: lp,
    OneMinusDstColorFactor: up,
    OneMinusSrcAlphaFactor: na,
    OneMinusSrcColorFactor: ap,
    OrthographicCamera: wn,
    PCFShadowMap: Xd,
    PCFSoftShadowMap: Jd,
    PMREMGenerator: hn1,
    Path: mi,
    PerspectiveCamera: vt,
    Plane: xe,
    PlaneGeometry: Zr,
    PlaneHelper: gl,
    PointLight: vo,
    PointLightHelper: rl,
    Points: Er,
    PointsMaterial: on,
    PolarGridHelper: cl,
    PolyhedronGeometry: We,
    PositionalAudio: Oh,
    PropertyBinding: J,
    PropertyMixer: Po,
    QuadraticBezierCurve: ln,
    QuadraticBezierCurve3: cn,
    Quaternion: bt,
    QuaternionKeyframeTrack: xi,
    QuaternionLinearInterpolant: go,
    RED_GREEN_RGTC2_Format: Wc,
    RED_RGTC1_Format: Lc,
    REVISION: vl,
    RGBADepthPacking: Wp,
    RGBAFormat: Li,
    RGBAIntegerFormat: uc,
    RGBA_ASTC_10x10_Format: kc,
    RGBA_ASTC_10x5_Format: Bc,
    RGBA_ASTC_10x6_Format: Ec,
    RGBA_ASTC_10x8_Format: Rc,
    RGBA_ASTC_12x10_Format: Pc,
    RGBA_ASTC_12x12_Format: Oc,
    RGBA_ASTC_4x4_Format: vc,
    RGBA_ASTC_5x4_Format: Ac,
    RGBA_ASTC_5x5_Format: Sc,
    RGBA_ASTC_6x5_Format: Tc,
    RGBA_ASTC_6x6_Format: Ic,
    RGBA_ASTC_8x5_Format: Cc,
    RGBA_ASTC_8x6_Format: zc,
    RGBA_ASTC_8x8_Format: Fc,
    RGBA_BPTC_Format: Nc,
    RGBA_ETC2_EAC_Format: _c,
    RGBA_PVRTC_2BPPV1_Format: bc,
    RGBA_PVRTC_4BPPV1_Format: xc,
    RGBA_S3TC_DXT1_Format: pc,
    RGBA_S3TC_DXT3_Format: fc,
    RGBA_S3TC_DXT5_Format: mc,
    RGBDepthPacking: Hp,
    RGBFormat: oc,
    RGBIntegerFormat: Vp,
    RGB_BPTC_SIGNED_Format: Vc,
    RGB_BPTC_UNSIGNED_Format: Dc,
    RGB_ETC1_Format: wc,
    RGB_ETC2_Format: Mc,
    RGB_PVRTC_2BPPV1_Format: gc,
    RGB_PVRTC_4BPPV1_Format: yc,
    RGB_S3TC_DXT1_Format: dc,
    RGDepthPacking: qp,
    RGFormat: lc,
    RGIntegerFormat: cc,
    RawShaderMaterial: so,
    Ray: Le,
    Raycaster: Jh,
    RectAreaLight: Io,
    RedFormat: Tl,
    RedIntegerFormat: Il,
    ReinhardToneMapping: Cp,
    RenderTarget: Wi,
    RenderTarget3D: Lh,
    RenderTargetArray: Uh,
    RepeatWrapping: pr,
    ReplaceStencilOp: Jp,
    ReverseSubtractEquation: ep,
    RingGeometry: Yr,
    SIGNED_RED_GREEN_RGTC2_Format: Hc,
    SIGNED_RED_RGTC1_Format: Uc,
    SRGBColorSpace: Bt,
    SRGBTransfer: Fn,
    Scene: _r,
    ShaderChunk: Pe1,
    ShaderLib: gt1,
    ShaderMaterial: qi,
    ShadowMaterial: io,
    Shape: Me,
    ShapeGeometry: $r,
    ShapePath: Ml,
    ShapeUtils: he,
    ShortType: Ql,
    Skeleton: Tr,
    SkeletonHelper: nl,
    SkinnedMesh: Sr,
    Source: be,
    Sphere: ht,
    SphereGeometry: mn,
    Spherical: Yh,
    SphericalHarmonics3: Co,
    SplineCurve: un,
    SpotLight: Mo,
    SpotLightHelper: sl,
    Sprite: vr,
    SpriteMaterial: tn,
    SrcAlphaFactor: sa,
    SrcAlphaSaturateFactor: dp,
    SrcColorFactor: op,
    StaticCopyUsage: wf,
    StaticDrawUsage: Js,
    StaticReadUsage: gf,
    StereoCamera: Fh,
    StreamCopyUsage: _f,
    StreamDrawUsage: yf,
    StreamReadUsage: bf,
    StringKeyframeTrack: Ae,
    SubtractEquation: tp,
    SubtractiveBlending: Qd,
    TOUCH: Ld,
    TangentSpaceNormalMap: _i,
    TetrahedronGeometry: Qr,
    Texture: lt,
    TextureLoader: bh,
    TextureUtils: Of,
    TimestampQuery: Sf,
    TorusGeometry: jr,
    TorusKnotGeometry: Kr,
    Triangle: ne,
    TriangleFanDrawMode: Up,
    TriangleStripDrawMode: Lp,
    TrianglesDrawMode: Dp,
    TubeGeometry: to,
    UVMapping: Lo,
    Uint16BufferAttribute: gr,
    Uint32BufferAttribute: xr,
    Uint8BufferAttribute: Ia,
    Uint8ClampedBufferAttribute: Ca,
    Uniform: Wh,
    UniformsGroup: Hh,
    UniformsLib: ee1,
    UniformsUtils: kf,
    UnsignedByteType: Sl,
    UnsignedInt248Type: sc,
    UnsignedInt5999Type: nc,
    UnsignedIntType: Wo,
    UnsignedShort4444Type: ec,
    UnsignedShort5551Type: ic,
    UnsignedShortType: jl,
    VSMShadowMap: Zd,
    Vector2: T,
    Vector3: w,
    Vector4: ot,
    VectorKeyframeTrack: bi,
    VideoFrameTexture: sh,
    VideoTexture: Rr,
    WebGL3DRenderTarget: ya,
    WebGLArrayRenderTarget: ma,
    WebGLCoordinateSystem: oe,
    WebGLCubeRenderTarget: Na,
    WebGLRenderTarget: Hi,
    WebGLRenderer: cr1,
    WebGLUtils: yf1,
    WebGPUCoordinateSystem: Zs,
    WebXRController: Va,
    WireframeGeometry: eo,
    WrapAroundEnding: Xs,
    ZeroCurvatureEnding: hi,
    ZeroFactor: np,
    ZeroSlopeEnding: li,
    ZeroStencilOp: Xp,
    createCanvasElement: If
};
function getWebGLErrorMessage() {
    return getErrorMessage(1);
}
function getErrorMessage(version) {
    var names = {
        1: "WebGL",
        2: "WebGL 2"
    };
    var contexts = {
        1: window.WebGLRenderingContext,
        2: window.WebGL2RenderingContext
    };
    var message = 'Your $0 does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">$1</a>';
    var element = document.createElement("div");
    element.id = "webglmessage";
    element.style.fontFamily = "monospace";
    element.style.fontSize = "13px";
    element.style.fontWeight = "normal";
    element.style.textAlign = "center";
    element.style.background = "#fff";
    element.style.color = "#000";
    element.style.padding = "1.5em";
    element.style.width = "400px";
    element.style.margin = "5em auto 0";
    if (contexts[version]) {
        message = message.replace("$0", "graphics card");
    } else {
        message = message.replace("$0", "browser");
    }
    message = message.replace("$1", names[version]);
    element.innerHTML = message;
    return element;
}
function uv_to_pixel_bounds(uv, tex_width, tex_height) {
    const tex_size = new T(tex_width, tex_height);
    const uv_left_bottom = new T(uv.x, uv.y);
    const uv_right_top = new T(uv.z, uv.w);
    const px_left_bottom = uv_left_bottom.clone().multiply(tex_size).floor();
    const px_right_top = uv_right_top.clone().multiply(tex_size).ceil();
    const wx = Math.abs(px_right_top.x - px_left_bottom.x);
    const wy = Math.abs(px_right_top.y - px_left_bottom.y);
    return [
        px_left_bottom,
        new T(wx, wy)
    ];
}
function is_three_fixed_array(value) {
    return value instanceof mod.Vector2 || value instanceof mod.Vector3 || value instanceof mod.Vector4 || value instanceof mod.Matrix4;
}
function to_three_vector(data) {
    if (data.length == 2) {
        return new mod.Vector2().fromArray(data);
    }
    if (data.length == 3) {
        return new mod.Vector3().fromArray(data);
    }
    if (data.length == 4) {
        return new mod.Vector4().fromArray(data);
    }
    if (data.length == 16) {
        const mat = new mod.Matrix4();
        mat.fromArray(data);
        return mat;
    }
    return data;
}
function typedarray_to_vectype(typedArray, ndim) {
    if (typedArray instanceof Float32Array) {
        if (ndim === 1) {
            return "float";
        } else {
            return "vec" + ndim;
        }
    } else if (typedArray instanceof Int32Array) {
        if (ndim === 1) {
            return "int";
        } else {
            return "ivec" + ndim;
        }
    } else if (typedArray instanceof Uint32Array) {
        if (ndim === 1) {
            return "uint";
        } else {
            return "uvec" + ndim;
        }
    } else {
        return;
    }
}
function attribute_type(attribute) {
    if (attribute) {
        return typedarray_to_vectype(attribute.array, attribute.itemSize);
    } else {
        return;
    }
}
function uniform_type(obj) {
    if (obj instanceof mod.Uniform) {
        return uniform_type(obj.value);
    } else if (typeof obj === "number") {
        return "float";
    } else if (typeof obj === "boolean") {
        return "bool";
    } else if (obj instanceof mod.Vector2) {
        return "vec2";
    } else if (obj instanceof mod.Vector3) {
        return "vec3";
    } else if (obj instanceof mod.Vector4) {
        return "vec4";
    } else if (obj instanceof mod.Color) {
        return "vec4";
    } else if (obj instanceof mod.Matrix3) {
        return "mat3";
    } else if (obj instanceof mod.Matrix4) {
        return "mat4";
    } else if (obj instanceof mod.Texture) {
        return "sampler2D";
    } else {
        return "invalid";
    }
}
function uniforms_to_type_declaration(uniform_dict) {
    let result = "";
    for(const name in uniform_dict){
        const uniform = uniform_dict[name];
        const type = uniform_type(uniform);
        if (type != "invalid") result += `uniform ${type} ${name};\n`;
    }
    return result;
}
function attributes_to_type_declaration(attributes_dict) {
    let result = "";
    for(const name in attributes_dict){
        const attribute = attributes_dict[name];
        const type = attribute_type(attribute);
        result += `in ${type} ${name};\n`;
    }
    return result;
}
function update_uniform(uniform, new_value) {
    if (uniform.value.isTexture) {
        const im_data = uniform.value.image;
        const [size, tex_data] = new_value;
        if (tex_data.length == im_data.data.length) {
            im_data.data.set(tex_data);
        } else {
            const old_texture = uniform.value;
            uniform.value = re_create_texture(old_texture, tex_data, size);
            old_texture.dispose();
        }
        uniform.value.needsUpdate = true;
    } else {
        if (is_three_fixed_array(uniform.value)) {
            uniform.value.fromArray(new_value);
        } else {
            uniform.value = new_value;
        }
    }
}
function re_create_buffer(buffer, is_segments) {
    if (buffer instanceof mod.InterleavedBufferAttribute) {
        return new mod.InterleavedBufferAttribute(buffer.data, buffer.itemSize, buffer.offset);
    }
    let { new_data  } = buffer;
    if (!new_data) {
        new_data = buffer.array;
    }
    let new_buffer;
    if (buffer instanceof mod.InstancedInterleavedBuffer) {
        new_buffer = new mod.InstancedInterleavedBuffer(new_data, buffer.stride, buffer.meshPerAttribute);
        new_buffer.count = Math.max(0, is_segments ? Math.floor(new_buffer.count - 1) : new_buffer.count - 3);
    } else if (buffer instanceof mod.InstancedBufferAttribute) {
        new_buffer = new mod.InstancedBufferAttribute(new_data, buffer.itemSize, buffer.normalized, buffer.meshPerAttribute);
    } else if (buffer instanceof mod.BufferAttribute) {
        new_buffer = new mod.BufferAttribute(new_data, buffer.itemSize, buffer.normalized);
    } else {
        throw new Error("Unsupported buffer type. Must be THREE.BufferAttribute, THREE.InstancedBufferAttribute, or THREE.InstancedInterleavedBuffer.");
    }
    if (buffer.usage) {
        new_buffer.usage = buffer.usage;
    }
    if (buffer.updateRange) {
        new_buffer.updateRange = {
            offset: buffer.updateRange.offset,
            count: buffer.updateRange.count
        };
    }
    return new_buffer;
}
function re_create_geometry(geometry, is_segments) {
    let new_geometry;
    if (geometry instanceof mod.InstancedBufferGeometry) {
        new_geometry = new mod.InstancedBufferGeometry();
    } else {
        new_geometry = new mod.BufferGeometry();
    }
    new_geometry.boundingSphere = new mod.Sphere();
    new_geometry.boundingSphere.radius = 10000000000000;
    new_geometry.frustumCulled = false;
    const interleaved_attributes = new Map();
    let instance_count = geometry.instanceCount;
    for (const [name, attribute] of Object.entries(geometry.attributes)){
        let new_attribute;
        if (attribute.isInterleavedBufferAttribute) {
            const old_buffer = attribute.data;
            let new_buffer;
            if (!interleaved_attributes.has(old_buffer)) {
                new_buffer = re_create_buffer(old_buffer, is_segments);
                interleaved_attributes.set(old_buffer, new_buffer);
            } else {
                new_buffer = interleaved_attributes.get(old_buffer);
            }
            attribute.data = new_buffer;
            new_attribute = re_create_buffer(attribute, is_segments);
            instance_count = new_attribute.count;
        } else {
            new_attribute = re_create_buffer(attribute, is_segments);
        }
        new_geometry.setAttribute(name, new_attribute);
        if (new_attribute instanceof mod.InstancedBufferAttribute) {
            instance_count = new_attribute.count;
        }
    }
    if (geometry.interleaved_attributes) {
        new_geometry.interleaved_attributes = {};
        Object.keys(geometry.interleaved_attributes).forEach((name)=>{
            const old = geometry.interleaved_attributes[name];
            new_geometry.interleaved_attributes[name] = interleaved_attributes.get(old);
        });
    }
    if (geometry instanceof mod.InstancedBufferGeometry) {
        geometry.instanceCount = instance_count;
    }
    if (geometry.index) {
        new_geometry.index = re_create_buffer(geometry.index, is_segments);
    }
    return new_geometry;
}
function find_interleaved_attribute(geometry, buffer) {
    for (const [name, attribute] of Object.entries(geometry.attributes)){
        if (attribute.data === buffer) {
            return attribute;
        }
    }
    return null;
}
function convert_RGB_to_RGBA(rgbArray) {
    const length = rgbArray.length;
    const rgbaArray = new rgbArray.constructor(length / 3 * 4);
    const a = rgbArray instanceof Uint8Array ? 255 : 1.0;
    for(let i = 0, j = 0; i < length; i += 3, j += 4){
        rgbaArray[j] = rgbArray[i];
        rgbaArray[j + 1] = rgbArray[i + 1];
        rgbaArray[j + 2] = rgbArray[i + 2];
        rgbaArray[j + 3] = a;
    }
    return rgbaArray;
}
function create_texture_from_data(data) {
    let buffer = data.data;
    if (data.size.length == 3) {
        const tex = new mod.Data3DTexture(buffer, data.size[0], data.size[1], data.size[2]);
        tex.format = mod[data.three_format];
        tex.type = mod[data.three_type];
        return tex;
    } else {
        let format = mod[data.three_format];
        if (data.three_format == "RGBFormat") {
            buffer = convert_RGB_to_RGBA(buffer);
            format = mod.RGBAFormat;
        }
        return new mod.DataTexture(buffer, data.size[0], data.size[1], format, mod[data.three_type]);
    }
}
class TextureAtlas {
    constructor(width, pix_per_glyph, glyph_padding){
        this.pix_per_glyph = pix_per_glyph;
        this.glyph_padding = glyph_padding;
        this.width = width;
        this.height = width;
        this.data = new Float32Array(width * width);
        for(let i = 0; i < this.data.length; i++){
            this.data[i] = 0.0;
        }
        this.glyph_data = new Map();
        this.textures = new Map();
    }
    insert_glyph(hash, glyph_data, uv_pos, width, minimum) {
        this.glyph_data.set(hash, [
            uv_pos,
            width,
            minimum
        ]);
        const [px_start, px_width] = uv_to_pixel_bounds(uv_pos, this.width, this.height);
        for(let col = 0; col < px_width.y; col++){
            for(let row = 0; row < px_width.x; row++){
                const glyph_index = col * px_width.x + row;
                const atlas_index = (px_start.y + col) * this.height + (px_start.x + row);
                this.data[atlas_index] = glyph_data.array[glyph_index];
            }
        }
    }
    insert_glyphs(glyph_data) {
        let written = false;
        Object.keys(glyph_data).forEach((hash)=>{
            if (this.glyph_data.has(hash)) {
                return;
            }
            const [uv, sdf, width, minimum] = glyph_data[hash];
            this.insert_glyph(hash, sdf, to_three_vector(uv), to_three_vector(width), to_three_vector(minimum));
            written = true;
            return;
        });
        if (written) {
            this.upload_tex_data();
        }
    }
    get_glyph_data(hash, scale) {
        const data = this.glyph_data.get(hash.toString());
        if (!data) {
            console.warn(`Glyph with hash ${hash} not found in the atlas.`);
            return null;
        }
        const [uv_offset_width, width, mini] = data;
        const w_scaled = width.clone().multiply(scale);
        const mini_scaled = mini.clone().multiply(scale);
        const pad = this.glyph_padding / this.pix_per_glyph;
        const scaled_pad = scale.clone().multiplyScalar(2 * pad);
        const scales = w_scaled.clone().add(scaled_pad);
        const quad_offsets = mini_scaled.clone().sub(scale.clone().multiplyScalar(pad));
        return [
            uv_offset_width,
            scales,
            quad_offsets
        ];
    }
    get_texture(renderer) {
        if (this.textures.has(renderer)) {
            return this.textures.get(renderer);
        }
        const texture = new Lt(this.data, this.width, this.height, Tl, pi);
        texture.magFilter = Ut;
        texture.minFilter = Ut;
        texture.wrapS = Ht;
        texture.wrapT = Ht;
        this.textures.set(renderer, texture);
        return texture;
    }
    upload_tex_data() {
        for (const [renderer, texture] of this.textures.entries()){
            if (!texture.image) {
                this.textures.delete(renderer);
                continue;
            }
            texture.image.data.set(this.data);
            texture.needsUpdate = true;
        }
    }
}
const TEXTURE_ATLAS = [];
function get_texture_atlas() {
    if (TEXTURE_ATLAS.length === 0) {
        const atlas = new TextureAtlas(2048, 64, 12);
        TEXTURE_ATLAS.push(atlas);
    }
    return TEXTURE_ATLAS[0];
}
function create_texture(scene, data) {
    const buffer = data.data;
    if (buffer === "texture_atlas") {
        const { texture_atlas , renderer  } = scene.screen;
        if (!texture_atlas) {
            const atlas = get_texture_atlas();
            scene.screen.texture_atlas = atlas.get_texture(renderer);
        }
        return scene.screen.texture_atlas;
    } else {
        return create_texture_from_data(data);
    }
}
function re_create_texture(old_texture, buffer, size) {
    let tex;
    if (size.length == 3) {
        tex = new mod.Data3DTexture(buffer, size[0], size[1], size[2]);
        tex.format = old_texture.format;
        tex.type = old_texture.type;
    } else {
        tex = new mod.DataTexture(buffer, size[0], size[1] ? size[1] : 1, old_texture.format, old_texture.type);
    }
    tex.minFilter = old_texture.minFilter;
    tex.magFilter = old_texture.magFilter;
    tex.anisotropy = old_texture.anisotropy;
    tex.wrapS = old_texture.wrapS;
    if (size.length > 1) {
        tex.wrapT = old_texture.wrapT;
    }
    if (size.length > 2) {
        tex.wrapR = old_texture.wrapR;
    }
    return tex;
}
function BufferAttribute(buffer) {
    const jsbuff = new mod.BufferAttribute(buffer.flat, buffer.type_length);
    jsbuff.setUsage(mod.DynamicDrawUsage);
    return jsbuff;
}
function InstanceBufferAttribute(buffer) {
    const jsbuff = new mod.InstancedBufferAttribute(buffer.flat, buffer.type_length);
    jsbuff.setUsage(mod.DynamicDrawUsage);
    return jsbuff;
}
function attach_geometry(buffer_geometry, vertexarrays, faces) {
    for(const name in vertexarrays){
        const buff = vertexarrays[name];
        let buffer;
        if (buff.to_update) {
            buffer = new mod.BufferAttribute(buff.to_update, buff.itemSize);
        } else {
            buffer = BufferAttribute(buff);
        }
        buffer_geometry.setAttribute(name, buffer);
    }
    buffer_geometry.setIndex(faces);
    buffer_geometry.boundingSphere = new mod.Sphere();
    buffer_geometry.boundingSphere.radius = 10000000000000;
    buffer_geometry.frustumCulled = false;
    return buffer_geometry;
}
function attach_instanced_geometry(buffer_geometry, instance_attributes) {
    for(const name in instance_attributes){
        const buffer = InstanceBufferAttribute(instance_attributes[name]);
        buffer_geometry.setAttribute(name, buffer);
    }
}
function create_material(plot) {
    const is_volume = "isovalue" in plot.deserialized_uniforms;
    return new mod.RawShaderMaterial({
        uniforms: plot.deserialized_uniforms,
        vertexShader: plot.plot_data.vertex_source,
        fragmentShader: plot.plot_data.fragment_source,
        side: is_volume ? mod.BackSide : mod.DoubleSide,
        transparent: true,
        glslVersion: mod.GLSL3,
        depthTest: !plot.plot_data.overdraw,
        depthWrite: !plot.plot_data.transparency
    });
}
function create_mesh(plot) {
    const buffer_geometry = new mod.BufferGeometry();
    const { plot_data  } = plot;
    const faces = new mod.BufferAttribute(plot_data.faces, 1);
    attach_geometry(buffer_geometry, plot_data.vertexarrays, faces);
    const material = create_material(plot);
    const mesh = new mod.Mesh(buffer_geometry, material);
    return mesh;
}
function create_instanced_mesh(plot) {
    const { plot_data  } = plot;
    const buffer_geometry = new mod.InstancedBufferGeometry();
    const faces = new mod.BufferAttribute(plot_data.faces, 1);
    attach_geometry(buffer_geometry, plot_data.vertexarrays, faces);
    attach_instanced_geometry(buffer_geometry, plot_data.instance_attributes);
    const material = create_material(plot);
    const mesh = new mod.Mesh(buffer_geometry, material);
    return mesh;
}
const _changeEvent = {
    type: "change"
};
const _startEvent = {
    type: "start"
};
const _endEvent = {
    type: "end"
};
const _ray = new Le();
const _plane = new xe();
const TILT_LIMIT = Math.cos(70 * Tf.DEG2RAD);
class OrbitControls extends qt {
    constructor(object, domElement, allow_update, is_in_scene){
        super();
        this.object = object;
        this.domElement = domElement;
        this.domElement.style.touchAction = "none";
        this.enabled = true;
        this.target = new w();
        this.cursor = new w();
        this.minDistance = 0;
        this.maxDistance = Infinity;
        this.minZoom = 0;
        this.maxZoom = Infinity;
        this.minTargetRadius = 0;
        this.maxTargetRadius = Infinity;
        this.minPolarAngle = 0;
        this.maxPolarAngle = Math.PI;
        this.minAzimuthAngle = -Infinity;
        this.maxAzimuthAngle = Infinity;
        this.enableDamping = false;
        this.dampingFactor = 0.05;
        this.enableZoom = true;
        this.zoomSpeed = 1.0;
        this.enableRotate = true;
        this.rotateSpeed = 1.0;
        this.enablePan = true;
        this.panSpeed = 1.0;
        this.screenSpacePanning = true;
        this.keyPanSpeed = 7.0;
        this.zoomToCursor = false;
        this.autoRotate = false;
        this.autoRotateSpeed = 2.0;
        this.keys = {
            LEFT: "ArrowLeft",
            UP: "ArrowUp",
            RIGHT: "ArrowRight",
            BOTTOM: "ArrowDown"
        };
        this.mouseButtons = {
            LEFT: Dd.ROTATE,
            MIDDLE: Dd.DOLLY,
            RIGHT: Dd.PAN
        };
        this.touches = {
            ONE: Ld.ROTATE,
            TWO: Ld.DOLLY_PAN
        };
        this.target0 = this.target.clone();
        this.position0 = this.object.position.clone();
        this.zoom0 = this.object.zoom;
        this._domElementKeyEvents = null;
        this.getPolarAngle = function() {
            return spherical.phi;
        };
        this.getAzimuthalAngle = function() {
            return spherical.theta;
        };
        this.getDistance = function() {
            return this.object.position.distanceTo(this.target);
        };
        this.listenToKeyEvents = function(domElement) {
            domElement.addEventListener("keydown", onKeyDown);
            this._domElementKeyEvents = domElement;
        };
        this.stopListenToKeyEvents = function() {
            this._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
            this._domElementKeyEvents = null;
        };
        this.saveState = function() {
            scope.target0.copy(scope.target);
            scope.position0.copy(scope.object.position);
            scope.zoom0 = scope.object.zoom;
        };
        this.reset = function() {
            scope.target.copy(scope.target0);
            scope.object.position.copy(scope.position0);
            scope.object.zoom = scope.zoom0;
            scope.object.updateProjectionMatrix();
            scope.dispatchEvent(_changeEvent);
            scope.update();
            state = STATE.NONE;
        };
        this.update = function() {
            const offset = new w();
            const quat = new bt().setFromUnitVectors(object.up, new w(0, 1, 0));
            const quatInverse = quat.clone().invert();
            const lastPosition = new w();
            const lastQuaternion = new bt();
            const lastTargetPosition = new w();
            const twoPI = 2 * Math.PI;
            return function update(deltaTime = null) {
                if (!allow_update()) {
                    return;
                }
                const position = scope.object.position;
                offset.copy(position).sub(scope.target);
                offset.applyQuaternion(quat);
                spherical.setFromVector3(offset);
                if (scope.autoRotate && state === STATE.NONE) {
                    rotateLeft(getAutoRotationAngle(deltaTime));
                }
                if (scope.enableDamping) {
                    spherical.theta += sphericalDelta.theta * scope.dampingFactor;
                    spherical.phi += sphericalDelta.phi * scope.dampingFactor;
                } else {
                    spherical.theta += sphericalDelta.theta;
                    spherical.phi += sphericalDelta.phi;
                }
                let min = scope.minAzimuthAngle;
                let max = scope.maxAzimuthAngle;
                if (isFinite(min) && isFinite(max)) {
                    if (min < -Math.PI) min += twoPI;
                    else if (min > Math.PI) min -= twoPI;
                    if (max < -Math.PI) max += twoPI;
                    else if (max > Math.PI) max -= twoPI;
                    if (min <= max) {
                        spherical.theta = Math.max(min, Math.min(max, spherical.theta));
                    } else {
                        spherical.theta = spherical.theta > (min + max) / 2 ? Math.max(min, spherical.theta) : Math.min(max, spherical.theta);
                    }
                }
                spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
                spherical.makeSafe();
                if (scope.enableDamping === true) {
                    scope.target.addScaledVector(panOffset, scope.dampingFactor);
                } else {
                    scope.target.add(panOffset);
                }
                scope.target.sub(scope.cursor);
                scope.target.clampLength(scope.minTargetRadius, scope.maxTargetRadius);
                scope.target.add(scope.cursor);
                if (scope.zoomToCursor && performCursorZoom || scope.object.isOrthographicCamera) {
                    spherical.radius = clampDistance(spherical.radius);
                } else {
                    spherical.radius = clampDistance(spherical.radius * scale);
                }
                offset.setFromSpherical(spherical);
                offset.applyQuaternion(quatInverse);
                position.copy(scope.target).add(offset);
                scope.object.lookAt(scope.target);
                if (scope.enableDamping === true) {
                    sphericalDelta.theta *= 1 - scope.dampingFactor;
                    sphericalDelta.phi *= 1 - scope.dampingFactor;
                    panOffset.multiplyScalar(1 - scope.dampingFactor);
                } else {
                    sphericalDelta.set(0, 0, 0);
                    panOffset.set(0, 0, 0);
                }
                let zoomChanged = false;
                if (scope.zoomToCursor && performCursorZoom) {
                    let newRadius = null;
                    if (scope.object.isPerspectiveCamera) {
                        const prevRadius = offset.length();
                        newRadius = clampDistance(prevRadius * scale);
                        const radiusDelta = prevRadius - newRadius;
                        scope.object.position.addScaledVector(dollyDirection, radiusDelta);
                        scope.object.updateMatrixWorld();
                    } else if (scope.object.isOrthographicCamera) {
                        const mouseBefore = new w(mouse.x, mouse.y, 0);
                        mouseBefore.unproject(scope.object);
                        scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
                        scope.object.updateProjectionMatrix();
                        zoomChanged = true;
                        const mouseAfter = new w(mouse.x, mouse.y, 0);
                        mouseAfter.unproject(scope.object);
                        scope.object.position.sub(mouseAfter).add(mouseBefore);
                        scope.object.updateMatrixWorld();
                        newRadius = offset.length();
                    } else {
                        console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.");
                        scope.zoomToCursor = false;
                    }
                    if (newRadius !== null) {
                        if (this.screenSpacePanning) {
                            scope.target.set(0, 0, -1).transformDirection(scope.object.matrix).multiplyScalar(newRadius).add(scope.object.position);
                        } else {
                            _ray.origin.copy(scope.object.position);
                            _ray.direction.set(0, 0, -1).transformDirection(scope.object.matrix);
                            if (Math.abs(scope.object.up.dot(_ray.direction)) < TILT_LIMIT) {
                                object.lookAt(scope.target);
                            } else {
                                _plane.setFromNormalAndCoplanarPoint(scope.object.up, scope.target);
                                _ray.intersectPlane(_plane, scope.target);
                            }
                        }
                    }
                } else if (scope.object.isOrthographicCamera) {
                    scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
                    scope.object.updateProjectionMatrix();
                    zoomChanged = true;
                }
                scale = 1;
                performCursorZoom = false;
                if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS || lastTargetPosition.distanceToSquared(scope.target) > 0) {
                    scope.dispatchEvent(_changeEvent);
                    lastPosition.copy(scope.object.position);
                    lastQuaternion.copy(scope.object.quaternion);
                    lastTargetPosition.copy(scope.target);
                    zoomChanged = false;
                    return true;
                }
                return false;
            };
        }();
        this.dispose = function() {
            scope.domElement.removeEventListener("contextmenu", onContextMenu);
            scope.domElement.removeEventListener("pointerdown", onPointerDown);
            scope.domElement.removeEventListener("pointercancel", onPointerUp);
            scope.domElement.removeEventListener("wheel", onMouseWheel);
            scope.domElement.removeEventListener("pointermove", onPointerMove);
            scope.domElement.removeEventListener("pointerup", onPointerUp);
            if (scope._domElementKeyEvents !== null) {
                scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
                scope._domElementKeyEvents = null;
            }
        };
        const scope = this;
        const STATE = {
            NONE: -1,
            ROTATE: 0,
            DOLLY: 1,
            PAN: 2,
            TOUCH_ROTATE: 3,
            TOUCH_PAN: 4,
            TOUCH_DOLLY_PAN: 5,
            TOUCH_DOLLY_ROTATE: 6
        };
        let state = STATE.NONE;
        const EPS = 0.000001;
        const spherical = new Yh();
        const sphericalDelta = new Yh();
        let scale = 1;
        const panOffset = new w();
        const rotateStart = new T();
        const rotateEnd = new T();
        const rotateDelta = new T();
        const panStart = new T();
        const panEnd = new T();
        const panDelta = new T();
        const dollyStart = new T();
        const dollyEnd = new T();
        const dollyDelta = new T();
        const dollyDirection = new w();
        const mouse = new T();
        let performCursorZoom = false;
        const pointers = [];
        const pointerPositions = {};
        function getAutoRotationAngle(deltaTime) {
            if (deltaTime !== null) {
                return 2 * Math.PI / 60 * scope.autoRotateSpeed * deltaTime;
            } else {
                return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
            }
        }
        function getZoomScale() {
            return Math.pow(0.95, scope.zoomSpeed);
        }
        function rotateLeft(angle) {
            sphericalDelta.theta -= angle;
        }
        function rotateUp(angle) {
            sphericalDelta.phi -= angle;
        }
        const panLeft = function() {
            const v = new w();
            return function panLeft(distance, objectMatrix) {
                v.setFromMatrixColumn(objectMatrix, 0);
                v.multiplyScalar(-distance);
                panOffset.add(v);
            };
        }();
        const panUp = function() {
            const v = new w();
            return function panUp(distance, objectMatrix) {
                if (scope.screenSpacePanning === true) {
                    v.setFromMatrixColumn(objectMatrix, 1);
                } else {
                    v.setFromMatrixColumn(objectMatrix, 0);
                    v.crossVectors(scope.object.up, v);
                }
                v.multiplyScalar(distance);
                panOffset.add(v);
            };
        }();
        const pan = function() {
            const offset = new w();
            return function pan(deltaX, deltaY) {
                const element = scope.domElement;
                if (scope.object.isPerspectiveCamera) {
                    const position = scope.object.position;
                    offset.copy(position).sub(scope.target);
                    let targetDistance = offset.length();
                    targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180.0);
                    panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
                    panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
                } else if (scope.object.isOrthographicCamera) {
                    panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix);
                    panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix);
                } else {
                    console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
                    scope.enablePan = false;
                }
            };
        }();
        function dollyOut(dollyScale) {
            if (scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera) {
                scale /= dollyScale;
            } else {
                console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
                scope.enableZoom = false;
            }
        }
        function dollyIn(dollyScale) {
            if (scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera) {
                scale *= dollyScale;
            } else {
                console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
                scope.enableZoom = false;
            }
        }
        function updateMouseParameters(event) {
            if (!scope.zoomToCursor) {
                return;
            }
            performCursorZoom = true;
            const rect = scope.domElement.getBoundingClientRect();
            const x1 = event.clientX - rect.left;
            const y1 = event.clientY - rect.top;
            const w = rect.width;
            const h = rect.height;
            mouse.x = x1 / w * 2 - 1;
            mouse.y = -(y1 / h) * 2 + 1;
            dollyDirection.set(mouse.x, mouse.y, 1).unproject(scope.object).sub(scope.object.position).normalize();
        }
        function clampDistance(dist) {
            return Math.max(scope.minDistance, Math.min(scope.maxDistance, dist));
        }
        function handleMouseDownRotate(event) {
            rotateStart.set(event.clientX, event.clientY);
        }
        function handleMouseDownDolly(event) {
            updateMouseParameters(event);
            dollyStart.set(event.clientX, event.clientY);
        }
        function handleMouseDownPan(event) {
            panStart.set(event.clientX, event.clientY);
        }
        function handleMouseMoveRotate(event) {
            rotateEnd.set(event.clientX, event.clientY);
            rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
            const element = scope.domElement;
            rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
            rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
            rotateStart.copy(rotateEnd);
            scope.update();
        }
        function handleMouseMoveDolly(event) {
            dollyEnd.set(event.clientX, event.clientY);
            dollyDelta.subVectors(dollyEnd, dollyStart);
            if (dollyDelta.y > 0) {
                dollyOut(getZoomScale());
            } else if (dollyDelta.y < 0) {
                dollyIn(getZoomScale());
            }
            dollyStart.copy(dollyEnd);
            scope.update();
        }
        function handleMouseMovePan(event) {
            panEnd.set(event.clientX, event.clientY);
            panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
            pan(panDelta.x, panDelta.y);
            panStart.copy(panEnd);
            scope.update();
        }
        function handleMouseWheel(event) {
            updateMouseParameters(event);
            if (event.deltaY < 0) {
                dollyIn(getZoomScale());
            } else if (event.deltaY > 0) {
                dollyOut(getZoomScale());
            }
            scope.update();
        }
        function handleKeyDown(event) {
            let needsUpdate = false;
            switch(event.code){
                case scope.keys.UP:
                    if (event.ctrlKey || event.metaKey || event.shiftKey) {
                        rotateUp(2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight);
                    } else {
                        pan(0, scope.keyPanSpeed);
                    }
                    needsUpdate = true;
                    break;
                case scope.keys.BOTTOM:
                    if (event.ctrlKey || event.metaKey || event.shiftKey) {
                        rotateUp(-2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight);
                    } else {
                        pan(0, -scope.keyPanSpeed);
                    }
                    needsUpdate = true;
                    break;
                case scope.keys.LEFT:
                    if (event.ctrlKey || event.metaKey || event.shiftKey) {
                        rotateLeft(2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight);
                    } else {
                        pan(scope.keyPanSpeed, 0);
                    }
                    needsUpdate = true;
                    break;
                case scope.keys.RIGHT:
                    if (event.ctrlKey || event.metaKey || event.shiftKey) {
                        rotateLeft(-2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight);
                    } else {
                        pan(-scope.keyPanSpeed, 0);
                    }
                    needsUpdate = true;
                    break;
            }
            if (needsUpdate) {
                event.preventDefault();
                scope.update();
            }
        }
        function handleTouchStartRotate() {
            if (pointers.length === 1) {
                rotateStart.set(pointers[0].pageX, pointers[0].pageY);
            } else {
                const x1 = 0.5 * (pointers[0].pageX + pointers[1].pageX);
                const y1 = 0.5 * (pointers[0].pageY + pointers[1].pageY);
                rotateStart.set(x1, y1);
            }
        }
        function handleTouchStartPan() {
            if (pointers.length === 1) {
                panStart.set(pointers[0].pageX, pointers[0].pageY);
            } else {
                const x1 = 0.5 * (pointers[0].pageX + pointers[1].pageX);
                const y1 = 0.5 * (pointers[0].pageY + pointers[1].pageY);
                panStart.set(x1, y1);
            }
        }
        function handleTouchStartDolly() {
            const dx = pointers[0].pageX - pointers[1].pageX;
            const dy = pointers[0].pageY - pointers[1].pageY;
            const distance = Math.sqrt(dx * dx + dy * dy);
            dollyStart.set(0, distance);
        }
        function handleTouchStartDollyPan() {
            if (scope.enableZoom) handleTouchStartDolly();
            if (scope.enablePan) handleTouchStartPan();
        }
        function handleTouchStartDollyRotate() {
            if (scope.enableZoom) handleTouchStartDolly();
            if (scope.enableRotate) handleTouchStartRotate();
        }
        function handleTouchMoveRotate(event) {
            if (pointers.length == 1) {
                rotateEnd.set(event.pageX, event.pageY);
            } else {
                const position = getSecondPointerPosition(event);
                const x1 = 0.5 * (event.pageX + position.x);
                const y1 = 0.5 * (event.pageY + position.y);
                rotateEnd.set(x1, y1);
            }
            rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
            const element = scope.domElement;
            rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
            rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
            rotateStart.copy(rotateEnd);
        }
        function handleTouchMovePan(event) {
            if (pointers.length === 1) {
                panEnd.set(event.pageX, event.pageY);
            } else {
                const position = getSecondPointerPosition(event);
                const x1 = 0.5 * (event.pageX + position.x);
                const y1 = 0.5 * (event.pageY + position.y);
                panEnd.set(x1, y1);
            }
            panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
            pan(panDelta.x, panDelta.y);
            panStart.copy(panEnd);
        }
        function handleTouchMoveDolly(event) {
            const position = getSecondPointerPosition(event);
            const dx = event.pageX - position.x;
            const dy = event.pageY - position.y;
            const distance = Math.sqrt(dx * dx + dy * dy);
            dollyEnd.set(0, distance);
            dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
            dollyOut(dollyDelta.y);
            dollyStart.copy(dollyEnd);
        }
        function handleTouchMoveDollyPan(event) {
            if (scope.enableZoom) handleTouchMoveDolly(event);
            if (scope.enablePan) handleTouchMovePan(event);
        }
        function handleTouchMoveDollyRotate(event) {
            if (scope.enableZoom) handleTouchMoveDolly(event);
            if (scope.enableRotate) handleTouchMoveRotate(event);
        }
        function onPointerDown(event) {
            if (scope.enabled === false) return;
            if (pointers.length === 0) {
                scope.domElement.setPointerCapture(event.pointerId);
                scope.domElement.addEventListener("pointermove", onPointerMove);
                scope.domElement.addEventListener("pointerup", onPointerUp);
            }
            addPointer(event);
            if (event.pointerType === "touch") {
                onTouchStart(event);
            } else {
                onMouseDown(event);
            }
        }
        function onPointerMove(event) {
            if (scope.enabled === false) return;
            if (!is_in_scene(event)) return;
            if (event.pointerType === "touch") {
                onTouchMove(event);
            } else {
                onMouseMove(event);
            }
        }
        function onPointerUp(event) {
            removePointer(event);
            if (pointers.length === 0) {
                scope.domElement.releasePointerCapture(event.pointerId);
                scope.domElement.removeEventListener("pointermove", onPointerMove);
                scope.domElement.removeEventListener("pointerup", onPointerUp);
            }
            scope.dispatchEvent(_endEvent);
            state = STATE.NONE;
        }
        function onMouseDown(event) {
            let mouseAction;
            switch(event.button){
                case 0:
                    mouseAction = scope.mouseButtons.LEFT;
                    break;
                case 1:
                    mouseAction = scope.mouseButtons.MIDDLE;
                    break;
                case 2:
                    mouseAction = scope.mouseButtons.RIGHT;
                    break;
                default:
                    mouseAction = -1;
            }
            switch(mouseAction){
                case Dd.DOLLY:
                    if (scope.enableZoom === false) return;
                    handleMouseDownDolly(event);
                    state = STATE.DOLLY;
                    break;
                case Dd.ROTATE:
                    if (event.ctrlKey || event.metaKey || event.shiftKey) {
                        if (scope.enablePan === false) return;
                        handleMouseDownPan(event);
                        state = STATE.PAN;
                    } else {
                        if (scope.enableRotate === false) return;
                        handleMouseDownRotate(event);
                        state = STATE.ROTATE;
                    }
                    break;
                case Dd.PAN:
                    if (event.ctrlKey || event.metaKey || event.shiftKey) {
                        if (scope.enableRotate === false) return;
                        handleMouseDownRotate(event);
                        state = STATE.ROTATE;
                    } else {
                        if (scope.enablePan === false) return;
                        handleMouseDownPan(event);
                        state = STATE.PAN;
                    }
                    break;
                default:
                    state = STATE.NONE;
            }
            if (state !== STATE.NONE) {
                scope.dispatchEvent(_startEvent);
            }
        }
        function onMouseMove(event) {
            switch(state){
                case STATE.ROTATE:
                    if (scope.enableRotate === false) return;
                    handleMouseMoveRotate(event);
                    break;
                case STATE.DOLLY:
                    if (scope.enableZoom === false) return;
                    handleMouseMoveDolly(event);
                    break;
                case STATE.PAN:
                    if (scope.enablePan === false) return;
                    handleMouseMovePan(event);
                    break;
            }
        }
        function onMouseWheel(event) {
            if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE || !is_in_scene(event)) return;
            event.preventDefault();
            scope.dispatchEvent(_startEvent);
            handleMouseWheel(event);
            scope.dispatchEvent(_endEvent);
        }
        function onKeyDown(event) {
            if (scope.enabled === false || scope.enablePan === false) return;
            handleKeyDown(event);
        }
        function onTouchStart(event) {
            trackPointer(event);
            switch(pointers.length){
                case 1:
                    switch(scope.touches.ONE){
                        case Ld.ROTATE:
                            if (scope.enableRotate === false) return;
                            handleTouchStartRotate();
                            state = STATE.TOUCH_ROTATE;
                            break;
                        case Ld.PAN:
                            if (scope.enablePan === false) return;
                            handleTouchStartPan();
                            state = STATE.TOUCH_PAN;
                            break;
                        default:
                            state = STATE.NONE;
                    }
                    break;
                case 2:
                    switch(scope.touches.TWO){
                        case Ld.DOLLY_PAN:
                            if (scope.enableZoom === false && scope.enablePan === false) return;
                            handleTouchStartDollyPan();
                            state = STATE.TOUCH_DOLLY_PAN;
                            break;
                        case Ld.DOLLY_ROTATE:
                            if (scope.enableZoom === false && scope.enableRotate === false) return;
                            handleTouchStartDollyRotate();
                            state = STATE.TOUCH_DOLLY_ROTATE;
                            break;
                        default:
                            state = STATE.NONE;
                    }
                    break;
                default:
                    state = STATE.NONE;
            }
            if (state !== STATE.NONE) {
                scope.dispatchEvent(_startEvent);
            }
        }
        function onTouchMove(event) {
            trackPointer(event);
            switch(state){
                case STATE.TOUCH_ROTATE:
                    if (scope.enableRotate === false) return;
                    handleTouchMoveRotate(event);
                    scope.update();
                    break;
                case STATE.TOUCH_PAN:
                    if (scope.enablePan === false) return;
                    handleTouchMovePan(event);
                    scope.update();
                    break;
                case STATE.TOUCH_DOLLY_PAN:
                    if (scope.enableZoom === false && scope.enablePan === false) return;
                    handleTouchMoveDollyPan(event);
                    scope.update();
                    break;
                case STATE.TOUCH_DOLLY_ROTATE:
                    if (scope.enableZoom === false && scope.enableRotate === false) return;
                    handleTouchMoveDollyRotate(event);
                    scope.update();
                    break;
                default:
                    state = STATE.NONE;
            }
        }
        function onContextMenu(event) {
            if (scope.enabled === false) return;
            event.preventDefault();
        }
        function addPointer(event) {
            pointers.push(event);
        }
        function removePointer(event) {
            delete pointerPositions[event.pointerId];
            for(let i = 0; i < pointers.length; i++){
                if (pointers[i].pointerId == event.pointerId) {
                    pointers.splice(i, 1);
                    return;
                }
            }
        }
        function trackPointer(event) {
            let position = pointerPositions[event.pointerId];
            if (position === undefined) {
                position = new T();
                pointerPositions[event.pointerId] = position;
            }
            position.set(event.pageX, event.pageY);
        }
        function getSecondPointerPosition(event) {
            const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
            return pointerPositions[pointer.pointerId];
        }
        scope.domElement.addEventListener("contextmenu", onContextMenu);
        scope.domElement.addEventListener("pointerdown", onPointerDown);
        scope.domElement.addEventListener("pointercancel", onPointerUp);
        scope.domElement.addEventListener("wheel", onMouseWheel, {
            passive: false
        });
        this.update();
    }
}
function events2unitless(screen, event) {
    const { canvas , winscale , renderer  } = screen;
    const rect = canvas.getBoundingClientRect();
    const x1 = (event.clientX - rect.left) / winscale;
    const y1 = (event.clientY - rect.top) / winscale;
    return [
        x1,
        renderer._height - y1
    ];
}
function Identity4x4() {
    return new D();
}
function in_scene(scene, mouse_event) {
    const [x1, y1] = events2unitless(scene.screen, mouse_event);
    const [sx, sy, sw, sh] = scene.viewport.value;
    return x1 >= sx && x1 < sx + sw && y1 >= sy && y1 < sy + sh;
}
function attach_3d_camera(canvas, makie_camera, cam3d, light_dir, scene) {
    if (cam3d === undefined) {
        return;
    }
    const [w1, h] = makie_camera.resolution.value;
    const camera = new vt(cam3d.fov.value, w1 / h, 0.01, 100.0);
    const center = new w(...cam3d.lookat.value);
    camera.up = new w(0, 0, 1);
    camera.position.set(...cam3d.eyeposition.value);
    camera.lookAt(center);
    const use_orbit_cam = ()=>!(Bonito.can_send_to_julia && Bonito.can_send_to_julia());
    const controls = new OrbitControls(camera, canvas, use_orbit_cam, (e)=>in_scene(scene, e));
    controls.target = center.clone();
    controls.target0 = center.clone();
    scene.orbitcontrols = controls;
    controls.addEventListener("change", (e)=>{
        const [width, height] = cam3d.resolution.value;
        const position = camera.position;
        const lookat = controls.target;
        const [x1, y1, z] = position;
        const dist = position.distanceTo(lookat);
        camera.aspect = width / height;
        camera.near = dist * 0.1;
        camera.far = dist * 5;
        camera.updateProjectionMatrix();
        camera.updateWorldMatrix();
        const view = camera.matrixWorldInverse;
        const projection = camera.projectionMatrix;
        makie_camera.update_matrices(view.elements, projection.elements, [
            width,
            height
        ], [
            x1,
            y1,
            z
        ]);
        makie_camera.update_light_dir(light_dir.value);
    });
}
function mul(a, b) {
    return b.clone().multiply(a);
}
function orthographicprojection(left, right, bottom, top, znear, zfar) {
    return [
        2 / (right - left),
        0,
        0,
        0,
        0,
        2 / (top - bottom),
        0,
        0,
        0,
        0,
        -2 / (zfar - znear),
        0,
        -(right + left) / (right - left),
        -(top + bottom) / (top - bottom),
        -(zfar + znear) / (zfar - znear),
        1
    ];
}
function pixel_space_inverse(w, h, near) {
    return [
        0.5 * w,
        0,
        0,
        0,
        0,
        0.5 * h,
        0,
        0,
        0,
        0,
        near,
        0,
        0.5 * w,
        0.5 * h,
        0,
        1
    ];
}
function relative_space() {
    const relative = Identity4x4();
    relative.fromArray([
        2,
        0,
        0,
        0,
        0,
        2,
        0,
        0,
        0,
        0,
        1,
        0,
        -1,
        -1,
        0,
        1
    ]);
    return relative;
}
class MakieCamera {
    constructor(){
        this.view = new Wh(Identity4x4());
        this.projection = new Wh(Identity4x4());
        this.projectionview = new Wh(Identity4x4());
        this.pixel_space = new Wh(Identity4x4());
        this.pixel_space_inverse = new Wh(Identity4x4());
        this.projectionview_inverse = new Wh(Identity4x4());
        this.relative_space = new Wh(relative_space());
        this.relative_inverse = new Wh(relative_space().invert());
        this.clip_space = new Wh(Identity4x4());
        this.resolution = new Wh(new T());
        this.eyeposition = new Wh(new w());
        this.preprojections = {};
        this.original_light_direction = [
            -1,
            -1,
            -1
        ];
        this.light_direction = new Wh(new w(-1, -1, -1).normalize());
        this.on_update = new Map();
    }
    calculate_matrices() {
        const [w, h] = this.resolution.value;
        const nearclip = -10_000;
        this.pixel_space.value.fromArray(orthographicprojection(0, w, 0, h, nearclip, 10_000));
        this.pixel_space_inverse.value.fromArray(pixel_space_inverse(w, h, nearclip));
        const proj_view = mul(this.view.value, this.projection.value);
        this.projectionview.value = proj_view;
        this.projectionview_inverse.value = proj_view.clone().invert();
        Object.keys(this.preprojections).forEach((key)=>{
            const [space, markerspace] = key.split(",");
            this.preprojections[key].value = this.calculate_preprojection_matrix(space, markerspace);
        });
    }
    update_matrices(view, projection, resolution, eyepos) {
        this.view.value.fromArray(view);
        this.projection.value.fromArray(projection);
        this.resolution.value.fromArray(resolution);
        this.eyeposition.value.fromArray(eyepos);
        this.calculate_matrices();
        this.recalculate_light_dir();
        for (const func of this.on_update.values()){
            try {
                func(this);
            } catch (e) {
                console.error("Error during camera update callback:", e);
            }
        }
    }
    recalculate_light_dir() {
        const light_dir = this.original_light_direction;
        this.update_light_dir(light_dir);
    }
    update_light_dir(light_dir) {
        this.original_light_direction = light_dir;
        const T = new Gt().setFromMatrix4(this.view.value).invert();
        const new_dir = new w().fromArray(light_dir);
        new_dir.applyMatrix3(T).normalize();
        this.light_direction.value = new_dir;
    }
    clip_to_space(space) {
        if (space === "data") {
            return this.projectionview_inverse.value;
        } else if (space === "pixel") {
            return this.pixel_space_inverse.value;
        } else if (space === "relative") {
            return this.relative_inverse.value;
        } else if (space === "clip") {
            return this.clip_space.value;
        } else {
            throw new Error(`Space ${space} not recognized`);
        }
    }
    space_to_clip(space) {
        if (space === "data") {
            return this.projectionview.value;
        } else if (space === "pixel") {
            return this.pixel_space.value;
        } else if (space === "relative") {
            return this.relative_space.value;
        } else if (space === "clip") {
            return this.clip_space.value;
        } else {
            throw new Error(`Space ${space} not recognized`);
        }
    }
    calculate_preprojection_matrix(space, markerspace) {
        const cp = this.clip_to_space(markerspace);
        const sc = this.space_to_clip(space);
        return mul(sc, cp);
    }
    preprojection_matrix(space, markerspace) {
        const key = [
            space,
            markerspace
        ];
        const matrix_uniform = this.preprojections[key];
        if (matrix_uniform) {
            return matrix_uniform;
        } else {
            const matrix = this.calculate_preprojection_matrix(space, markerspace);
            const uniform = new Wh(matrix);
            this.preprojections[key] = uniform;
            return uniform;
        }
    }
}
function create_plot(scene, data) {
    const PlotClass = mod1[data.plot_type];
    if (typeof PlotClass !== "function") {
        throw new Error(`Unknown plot type: ${data.plot_type}`);
    }
    return new PlotClass(scene, data);
}
function connect_plot(scene, plot) {
    const cam = scene.wgl_camera;
    const identity = new Wh(new D());
    const uniforms = plot.mesh ? plot.mesh.material.uniforms : plot.plot_data.uniforms;
    const space = plot.plot_data.cam_space;
    if (space == "data") {
        uniforms.view = cam.view;
        uniforms.projection = cam.projection;
        uniforms.projectionview = cam.projectionview;
        uniforms.eyeposition = cam.eyeposition;
    } else if (space == "pixel") {
        uniforms.view = identity;
        uniforms.projection = cam.pixel_space;
        uniforms.projectionview = cam.pixel_space;
    } else if (space == "relative") {
        uniforms.view = identity;
        uniforms.projection = cam.relative_space;
        uniforms.projectionview = cam.relative_space;
    } else if (space == "clip") {
        uniforms.view = identity;
        uniforms.projection = identity;
        uniforms.projectionview = identity;
    } else {
        throw new Error(`Space ${space} not supported!`);
    }
    const { px_per_unit  } = scene.screen;
    uniforms.resolution = cam.resolution;
    uniforms.px_per_unit = new Wh(px_per_unit);
    if (plot.plot_data.uniforms.preprojection) {
        const { space , markerspace  } = plot.plot_data;
        uniforms.preprojection = cam.preprojection_matrix(space, markerspace);
    }
    uniforms.light_direction = scene.light_direction;
    uniforms.ambient = scene.ambient;
    uniforms.light_color = scene.light_color;
}
function filter_by_key(dict, keys, default_value = false) {
    const result = {};
    keys.forEach((key)=>{
        const val = dict[key];
        if (val) {
            result[key] = val;
        } else {
            result[key] = default_value;
        }
    });
    return result;
}
const scene_cache = {};
const plot_cache = {};
function add_plot(scene, plot_data) {
    const p = create_plot(scene, plot_data);
    plot_cache[p.uuid] = p.mesh;
    scene.add(p.mesh);
    const next_insert = new Set(ON_NEXT_INSERT);
    next_insert.forEach((f)=>f());
}
function add_scene(scene_id, three_scene) {
    scene_cache[scene_id] = three_scene;
}
function find_scene(scene_id) {
    return scene_cache[scene_id];
}
function delete_scene(scene_id) {
    const scene = scene_cache[scene_id];
    if (!scene) {
        return;
    }
    delete_three_scene(scene);
    while(scene.children.length > 0){
        scene.remove(scene.children[0]);
    }
    delete scene_cache[scene_id];
}
function find_plots(plot_uuids) {
    const plots = [];
    plot_uuids.forEach((id)=>{
        const plot = plot_cache[id];
        if (plot) {
            plots.push(plot);
        }
    });
    return plots;
}
function delete_scenes(scene_uuids, plot_uuids) {
    plot_uuids.forEach((plot_id)=>{
        const plot = plot_cache[plot_id];
        if (plot) {
            delete_plot(plot);
        }
    });
    scene_uuids.forEach((scene_id)=>{
        delete_scene(scene_id);
    });
}
function insert_plot(scene_id, plot_data) {
    const scene = find_scene(scene_id);
    plot_data.forEach((plot)=>{
        add_plot(scene, plot);
    });
}
function delete_plots(plot_uuids) {
    const plots = find_plots(plot_uuids);
    plots.forEach(delete_plot);
}
function convert_texture(scene, data) {
    const tex = create_texture(scene, data);
    tex.needsUpdate = true;
    tex.generateMipmaps = data.mipmap;
    tex.minFilter = mod[data.minFilter];
    tex.magFilter = mod[data.magFilter];
    tex.anisotropy = data.anisotropy;
    tex.wrapS = mod[data.wrapS];
    if (data.size.length > 1) {
        tex.wrapT = mod[data.wrapT];
    }
    if (data.size.length > 2) {
        tex.wrapR = mod[data.wrapR];
    }
    return tex;
}
function is_typed_array(data) {
    return data instanceof Float32Array || data instanceof Int32Array || data instanceof Uint32Array;
}
function to_uniform(scene, data) {
    if (data.type !== undefined) {
        if (data.type == "Sampler") {
            return convert_texture(scene, data);
        }
        throw new Error(`Type ${data.type} not known`);
    }
    if (Array.isArray(data) || ArrayBuffer.isView(data)) {
        if (!data.every((x1)=>typeof x1 === "number")) {
            return data;
        }
        return to_three_vector(data);
    }
    return data;
}
function deserialize_uniforms(scene, data) {
    const result = {};
    for(const name in data){
        const value = data[name];
        if (value instanceof mod.Uniform) {
            result[name] = value;
        } else {
            const ser = to_uniform(scene, value);
            result[name] = new mod.Uniform(ser);
        }
    }
    return result;
}
const ON_NEXT_INSERT = new Set();
function on_next_insert(f) {
    ON_NEXT_INSERT.add(f);
}
function add_glyphs_from_plots(scene_data) {
    const atlas = get_texture_atlas();
    scene_data.plots.forEach((plot_data)=>{
        if (plot_data.glyph_data) {
            const glyph_data = plot_data.glyph_data;
            const { atlas_updates  } = glyph_data;
            if (atlas_updates) {
                atlas.insert_glyphs(atlas_updates);
            }
        }
    });
    scene_data.children.forEach((child)=>{
        add_glyphs_from_plots(child);
    });
}
function deserialize_scene(data, screen) {
    add_glyphs_from_plots(data);
    return deserialize_scene_recursive(data, screen);
}
function deserialize_scene_recursive(data, screen) {
    const scene = new mod.Scene();
    scene.screen = screen;
    const { canvas  } = screen;
    add_scene(data.uuid, scene);
    scene.scene_uuid = data.uuid;
    scene.frustumCulled = false;
    scene.viewport = data.viewport;
    scene.backgroundcolor = data.backgroundcolor;
    scene.backgroundcolor_alpha = data.backgroundcolor_alpha;
    scene.clearscene = data.clearscene;
    scene.visible = data.visible;
    const camera = new MakieCamera();
    scene.wgl_camera = camera;
    function update_cam(camera_matrices, force) {
        if (!force) {
            if (!(Bonito.can_send_to_julia && Bonito.can_send_to_julia())) {
                return;
            }
        }
        const [view, projection, resolution, eyepos] = camera_matrices;
        camera.update_matrices(view, projection, resolution, eyepos);
    }
    if (data.cam3d_state) {
        attach_3d_camera(canvas, camera, data.cam3d_state, data.light_direction, scene);
    }
    update_cam(data.camera.value, true);
    data.camera.on(update_cam);
    if (data.camera_relative_light.value) {
        camera.update_light_dir(data.light_direction.value);
        scene.light_direction = camera.light_direction;
        data.light_direction.on((value)=>{
            camera.update_light_dir(value);
        });
    } else {
        const light_dir = new mod.Vector3().fromArray(data.light_direction.value);
        scene.light_direction = new mod.Uniform(light_dir);
        data.light_direction.on((value)=>{
            scene.light_direction.value.fromArray(value);
        });
    }
    const ambient = new mod.Vector3().fromArray(data.ambient.value);
    scene.ambient = new mod.Uniform(ambient);
    data.ambient.on((value)=>{
        scene.ambient.value.fromArray(value);
    });
    const light_color = new mod.Vector3().fromArray(data.light_color.value);
    scene.light_color = new mod.Uniform(light_color);
    data.light_color.on((value)=>{
        scene.light_color.value.fromArray(value);
    });
    data.plots.forEach((plot_data)=>{
        add_plot(scene, plot_data);
    });
    scene.scene_children = data.children.map((child)=>{
        const childscene = deserialize_scene_recursive(child, screen);
        return childscene;
    });
    return scene;
}
function delete_plot(plot) {
    plot.plot_object.dispose();
}
function delete_three_scene(scene) {
    delete scene_cache[scene.scene_uuid];
    scene.scene_children.forEach(delete_three_scene);
    while(scene.children.length > 0){
        delete_plot(scene.children[0]);
    }
}
function expand_compressed(new_data) {
    if (new_data && typeof new_data === "object" && "value" in new_data && "length" in new_data) {
        const value = new_data.value;
        if (value instanceof Float32Array || Array.isArray(value)) {
            const element_size = value.length;
            const total_size = new_data.length * element_size;
            const expanded_array = new Float32Array(total_size);
            for(let i = 0; i < new_data.length; i++){
                expanded_array.set(value, i * element_size);
            }
            return expanded_array;
        } else {
            return new Float32Array(new_data.length).fill(value);
        }
    }
    return new_data;
}
class Plot {
    mesh = undefined;
    parent = undefined;
    uuid = "";
    name = "";
    is_instanced = false;
    geometry_needs_recreation = false;
    plot_data = {};
    deserialized_uniforms = {};
    type = "";
    constructor(scene, data){
        this.plot_data = data;
        connect_plot(scene, this);
        this.deserialized_uniforms = deserialize_uniforms(scene, data.uniforms);
        this.name = data.name;
        this.uuid = data.uuid;
        this.parent = scene;
        data.updater.on((data)=>{
            this.update(data);
        });
    }
    init_mesh() {
        this.mesh.plot_uuid = this.plot_data.uuid;
        this.mesh.frustumCulled = false;
        this.mesh.matrixAutoUpdate = false;
        this.mesh.renderOrder = this.plot_data.zvalue;
        this.mesh.plot_object = this;
        this.mesh.visible = this.plot_data.visible;
    }
    dispose() {
        delete plot_cache[this.uuid];
        this.parent.remove(this.mesh);
        this.mesh.geometry.dispose();
        this.mesh.material.dispose();
        this.mesh = undefined;
        this.parent = undefined;
        this.is_instanced = false;
        this.geometry_needs_recreation = false;
        this.plot_data = {};
    }
    move_to(scene) {
        if (scene === this.parent) {
            return;
        }
        this.parent.remove(this.mesh);
        connect_plot(scene, this);
        scene.add(this.mesh);
        this.parent = scene;
        return;
    }
    update(data) {
        const { mesh  } = this;
        if (!mesh) {
            return;
        }
        const { geometry  } = mesh;
        const { attributes , interleaved_attributes  } = geometry;
        const { uniforms  } = mesh.material;
        data.forEach(([key, value])=>{
            if (key in uniforms) {
                this.update_uniform(key, value);
            } else if (key in attributes || interleaved_attributes && key in interleaved_attributes) {
                this.update_buffer(key, value);
            } else if (key === "faces") {
                this.update_faces(value);
            } else if (key === "visible") {
                this.mesh.visible = value;
            } else {
                console.warn(`Unknown key ${key} in Plot: ${this.name}`);
            }
        });
        this.apply_updates();
    }
    update_uniform(name, new_data) {
        const uniform = this.mesh.material.uniforms[name];
        if (!uniform) {
            throw new Error(`Uniform ${name} doesn't exist in Plot: ${this.name}`);
        }
        update_uniform(uniform, new_data);
    }
    update_buffer(name, input_data) {
        const new_data = expand_compressed(input_data);
        const { geometry  } = this.mesh;
        let buffer = geometry.attributes[name];
        if (!buffer) {
            buffer = geometry.interleaved_attributes[name];
            if (!buffer) {
                throw new Error(`Buffer ${name} doesn't exist in Plot: ${this.name}`);
            }
        }
        const old_length = buffer.array.length;
        const is_interleaved = buffer instanceof qh;
        const attribute = is_interleaved ? find_interleaved_attribute(geometry, buffer) : buffer;
        if (attribute == null) {
            console.log(name);
            console.log(geometry.interleaved_attributes);
            console.log(geometry.attributes);
        }
        const new_count = new_data.length / attribute.itemSize;
        if (new_data.length <= old_length) {
            buffer.set(new_data);
            buffer.count = new_count;
            if (this instanceof Lines) {
                const is_segments = this.is_segments === true;
                const skipped = new_count / (buffer.stride / attribute.itemSize);
                buffer.count = Math.max(0, is_segments ? Math.floor(skipped - 1) : skipped - 3);
            }
            buffer.needsUpdate = true;
        } else {
            buffer.new_data = new_data;
            this.geometry_needs_recreation = true;
        }
        if (this.is_instanced) {
            this.mesh.geometry.instanceCount = attribute.count;
        }
    }
    apply_updates() {
        if (this.geometry_needs_recreation) {
            const { geometry  } = this.mesh;
            const new_geometry = re_create_geometry(geometry, this.is_segments === true);
            geometry.dispose();
            this.mesh.geometry = new_geometry;
            this.mesh.needsUpdate = true;
        }
        this.geometry_needs_recreation = false;
    }
    update_faces(face_data) {
        this.mesh.geometry.setIndex(new Z(face_data, 1));
    }
}
function lines_vertex_shader(uniforms, attributes, is_linesegments) {
    const attribute_decl = attributes_to_type_declaration(attributes);
    const uniform_decl = uniforms_to_type_declaration(uniforms);
    const color = attribute_type(attributes.line_color_start) || uniform_type(uniforms.line_color_start);
    if (is_linesegments) {
        return `precision highp float;
            precision highp int;
            precision highp sampler2D;
            precision highp sampler3D;

            ${attribute_decl}

            out vec3 f_quad_sdf;
            out vec2 f_truncation;              // invalid / not needed
            out float f_linestart;              // constant
            out float f_linelength;

            flat out vec2 f_extrusion;          // invalid / not needed
            flat out float f_linewidth;
            flat out vec4 f_pattern_overwrite;  // invalid / not needed
            flat out uint f_instance_id;
            flat out ${color} f_color1;
            flat out ${color} f_color2;
            flat out float f_alpha_weight;
            flat out float f_cumulative_length;
            flat out ivec2 f_capmode;
            flat out vec4 f_linepoints;         // invalid / not needed
            flat out vec4 f_miter_vecs;         // invalid / not needed

            ${uniform_decl}
            uniform vec4 uniform_clip_planes[8];

            // Constants
            const float AA_RADIUS = 0.8;
            const float AA_THICKNESS = 2.0 * AA_RADIUS;


            ////////////////////////////////////////////////////////////////////////
            // Geometry/Position Utils
            ////////////////////////////////////////////////////////////////////////

            vec4 clip_space(vec3 point) {
                return projectionview * model_f32c * vec4(point, 1);
            }
            vec4 clip_space(vec2 point) { return clip_space(vec3(point, 0)); }

            vec3 screen_space(vec4 vertex) {
                return vec3(
                    (0.5 * vertex.xy / vertex.w + 0.5) * px_per_unit * resolution,
                    vertex.z / vertex.w + depth_shift
                );
            }

            vec2 normal_vector(in vec2 v) { return vec2(-v.y, v.x); }
            vec2 normal_vector(in vec3 v) { return vec2(-v.y, v.x); }

            void process_clip_planes(inout vec4 p1, inout vec4 p2)
            {
                float d1, d2;
                for (int i = 0; i < int(uniform_num_clip_planes); i++) {
                    // distance from clip planes with negative clipped
                    d1 = dot(p1.xyz, uniform_clip_planes[i].xyz) - uniform_clip_planes[i].w * p1.w;
                    d2 = dot(p2.xyz, uniform_clip_planes[i].xyz) - uniform_clip_planes[i].w * p2.w;

                    // both outside - clip everything
                    if (d1 < 0.0 && d2 < 0.0) {
                        p2 = p1;
                        return;
                    }

                    // one outside - shorten segment
                    else if (d1 < 0.0)
                    {
                        // solve 0 = m * t + b = (d2 - d1) * t + d1 with t in (0, 1)
                        p1       = p1       - d1 * (p2 - p1)             / (d2 - d1);
                        f_color1 = f_color1 - d1 * (f_color2 - f_color1) / (d2 - d1);
                    }
                    else if (d2 < 0.0)
                    {
                        p2       = p2       - d2 * (p1 - p2)             / (d1 - d2);
                        f_color2 = f_color2 - d2 * (f_color1 - f_color2) / (d1 - d2);
                    }
                }

                return;
            }


            ////////////////////////////////////////////////////////////////////////
            // Main
            ////////////////////////////////////////////////////////////////////////


            void main() {
                bool is_end = position.x == 1.0;

                ////////////////////////////////////////////////////////////////////
                // Handle line geometry (position, directions)
                ////////////////////////////////////////////////////////////////////


                float width = px_per_unit * (is_end ? uniform_linewidth_end : uniform_linewidth_start);
                float halfwidth = 0.5 * max(AA_RADIUS, width);

                // color at line start/end for interpolation
                f_color1 = line_color_start;
                f_color2 = line_color_end;

                // restrict to visible area (see other shader)
                vec3 p1, p2;
                {
                    vec4 _p1 = clip_space(positions_transformed_f32c_start), _p2 = clip_space(positions_transformed_f32c_end);

                    vec4 v1 = _p2 - _p1;

                    if (_p1.w < 0.0) {
                        _p1 = _p1 + (-_p1.w - _p1.z) / (v1.z + v1.w) * v1;
                        f_color1 = f_color1 + (-_p1.w - _p1.z) / (v1.z + v1.w) * (f_color2 - f_color1);
                    }
                    if (_p2.w < 0.0) {
                        _p2 = _p2 + (-_p2.w - _p2.z) / (v1.z + v1.w) * v1;
                        f_color2 = f_color2 + (-_p2.w - _p2.z) / (v1.z + v1.w) * (f_color2 - f_color1);
                    }

                    // Shorten segments to fit clip planes
                    // returns true if segments are fully clipped
                    process_clip_planes(_p1, _p2);

                    p1 = screen_space(_p1);
                    p2 = screen_space(_p2);
                }

                // line vector (xy-normalized vectors in line direction)
                // Need z component for correct depth order
                vec3 v1 = p2 - p1;
                float segment_length = length(v1);
                v1 /= segment_length;

                // line normal (i.e. in uniform_linewidth direction)
                vec2 n1 = normal_vector(v1);


                ////////////////////////////////////////////////////////////////////
                // Static vertex data
                ////////////////////////////////////////////////////////////////////


                // invalid - no joints requiring uniform_pattern adjustments
                f_pattern_overwrite = vec4(-1e12, 1.0, 1e12, 1.0);

                // invalid - no joints requiring line sdfs to be extruded
                f_extrusion = vec2(0.0);

                // used to compute width sdf
                f_linewidth = halfwidth;

                f_instance_id = lineindex_start + uint(1); // NOTE: this is correct, no need to multiple by 2

                // we restart patterns for each segment
                f_cumulative_length = 0.0;

                // no joints means these should be set to a "never discard" state
                f_linepoints = vec4(-1e12);
                f_miter_vecs = vec4(-1);


                ////////////////////////////////////////////////////////////////////
                // Varying vertex data
                ////////////////////////////////////////////////////////////////////

                // linecaps
                f_capmode = ivec2(linecap);

                // Vertex position (padded for joint & anti-aliasing)
                float v_offset = position.x * (0.5 * segment_length + halfwidth + AA_THICKNESS);
                float n_offset = (halfwidth + AA_THICKNESS) * position.y;
                vec3 point = 0.5 * (p1 + p2) + v_offset * v1 + n_offset * vec3(n1, 0);

                // SDF's
                vec2 VP1 = point.xy - p1.xy;
                vec2 VP2 = point.xy - p2.xy;

                // sdf of this segment
                f_quad_sdf.x = dot(VP1, -v1.xy);
                f_quad_sdf.y = dot(VP2,  v1.xy);
                f_quad_sdf.z = dot(VP1,  n1);

                // invalid - no joint to truncate
                f_truncation = vec2(-1e12);

                // simplified - no extrusion or joints means we just have:
                f_linestart = 0.0;
                f_linelength = segment_length;

                // for thin lines
                f_alpha_weight = min(1.0, width / AA_RADIUS);

                // clip space position
                gl_Position = vec4(2.0 * point.xy / (px_per_unit * resolution) - 1.0, point.z, 1.0);
            }
        `;
    } else {
        return `precision highp float;
            precision highp int;
            precision highp sampler2D;
            precision highp sampler3D;

            ${attribute_decl}

            out vec3 f_quad_sdf;
            out vec2 f_truncation;
            out float f_linestart;
            out float f_linelength;

            flat out vec2 f_extrusion;
            flat out float f_linewidth;
            flat out vec4 f_pattern_overwrite;
            flat out uint f_instance_id;
            flat out ${color} f_color1;
            flat out ${color} f_color2;
            flat out float f_alpha_weight;
            flat out float f_cumulative_length;
            flat out ivec2 f_capmode;
            flat out vec4 f_linepoints;
            flat out vec4 f_miter_vecs;

            ${uniform_decl}
            uniform vec4 uniform_clip_planes[8];

            // Constants
            const float AA_RADIUS = 0.8;
            const float AA_THICKNESS = 2.0 * AA_RADIUS;
            const int BUTT   = 0;
            const int SQUARE = 1;
            const int ROUND  = 2;
            const int MITER  = 0;
            const int BEVEL  = 3;


            ////////////////////////////////////////////////////////////////////////
            // Pattern handling
            ////////////////////////////////////////////////////////////////////////


            vec2 process_pattern(bool uniform_pattern, bool[4] isvalid, vec2 extrusion, float segment_length, float halfwidth) {
                // do not adjust stuff
                f_pattern_overwrite = vec4(-1e12, 1.0, 1e12, 1.0);
                return vec2(0);
            }

            vec2 process_pattern(sampler2D uniform_pattern, bool[4] isvalid, vec2 extrusion, float segment_length, float halfwidth) {
                // samples:
                //   -ext1  p1 ext1    -ext2 p2 ext2
                //      1   2   3        4   5   6
                // prev | joint |  this  | joint | next

                // default to no overwrite
                f_pattern_overwrite.x = -1e12;
                f_pattern_overwrite.z = +1e12;
                vec2 adjust = vec2(0);
                float width = 2.0 * halfwidth;
                float uv_scale = 1.0 / (width * uniform_pattern_length);
                float left, center, right;

                if (isvalid[0]) {
                    float offset = abs(extrusion[0]);
                    left   = width * texture(uniform_pattern, vec2(uv_scale * (px_per_unit * lastlen_start - offset), 0.0)).x;
                    center = width * texture(uniform_pattern, vec2(uv_scale * (px_per_unit * lastlen_start         ), 0.0)).x;
                    right  = width * texture(uniform_pattern, vec2(uv_scale * (px_per_unit * lastlen_start + offset), 0.0)).x;

                    // cases:
                    // ++-, +--, +-+ => elongate backwards
                    // -++, --+      => shrink forward
                    // +++, ---, -+- => freeze around joint

                    if ((left > 0.0 && center > 0.0 && right > 0.0) || (left < 0.0 && right < 0.0)) {
                        // default/freeze
                        // overwrite until one AA gap past the corner/joint
                        f_pattern_overwrite.x = uv_scale * (px_per_unit * lastlen_start + abs(extrusion[0]) + AA_RADIUS);
                        // using the sign of the center to decide between drawing or not drawing
                        f_pattern_overwrite.y = sign(center);
                    } else if (left > 0.0) {
                        // elongate backwards
                        adjust.x = -1.0;
                    } else if (right > 0.0) {
                        // shorten forward
                        adjust.x = 1.0;
                    } else {
                        // default - see above
                        f_pattern_overwrite.x = uv_scale * (px_per_unit * lastlen_start + abs(extrusion[0]) + AA_RADIUS);
                        f_pattern_overwrite.y = sign(center);
                    }

                } // else there is no left segment, no left join, so no overwrite

                if (isvalid[3]) {
                    float offset = abs(extrusion[1]);
                    left   = width * texture(uniform_pattern, vec2(uv_scale * (px_per_unit * lastlen_start + segment_length - offset), 0.0)).x;
                    center = width * texture(uniform_pattern, vec2(uv_scale * (px_per_unit * lastlen_start + segment_length         ), 0.0)).x;
                    right  = width * texture(uniform_pattern, vec2(uv_scale * (px_per_unit * lastlen_start + segment_length + offset), 0.0)).x;

                    if ((left > 0.0 && center > 0.0 && right > 0.0) || (left < 0.0 && right < 0.0)) {
                        // default/freeze
                        f_pattern_overwrite.z = uv_scale * (px_per_unit * lastlen_start + segment_length - abs(extrusion[1]) - AA_RADIUS);
                        f_pattern_overwrite.w = sign(center);
                    } else if (left > 0.0) {
                        // shrink backwards
                        adjust.y = -1.0;
                    } else if (right > 0.0) {
                        // elongate forward
                        adjust.y = 1.0;
                    } else {
                        // default - see above
                        f_pattern_overwrite.z = uv_scale * (px_per_unit * lastlen_start + segment_length - abs(extrusion[1]) - AA_RADIUS);
                        f_pattern_overwrite.w = sign(center);
                    }
                }

                return adjust;
            }


            ////////////////////////////////////////////////////////////////////////
            // Geometry/Position Utils
            ////////////////////////////////////////////////////////////////////////

            vec4 clip_space(vec3 point) {
                return projectionview * model_f32c * vec4(point, 1);
            }
            vec4 clip_space(vec2 point) { return clip_space(vec3(point, 0)); }

            vec3 screen_space(vec4 vertex) {
                return vec3(
                    (0.5 * vertex.xy / vertex.w + 0.5) * px_per_unit * resolution,
                    vertex.z / vertex.w + depth_shift
                );
            }

            vec2 normal_vector(in vec2 v) { return vec2(-v.y, v.x); }
            vec2 normal_vector(in vec3 v) { return vec2(-v.y, v.x); }
            float sign_no_zero(float value) { return value >= 0.0 ? 1.0 : -1.0; }

            void process_clip_planes(inout vec4 p1, inout vec4 p2, inout bool[4] isvalid)
            {
                float d1, d2;
                for(int i = 0; i < int(uniform_num_clip_planes); i++)
                {
                    // distance from clip planes with negative clipped
                    d1 = dot(p1.xyz, uniform_clip_planes[i].xyz) - uniform_clip_planes[i].w * p1.w;
                    d2 = dot(p2.xyz, uniform_clip_planes[i].xyz) - uniform_clip_planes[i].w * p2.w;

                    // both outside - clip everything
                    if (d1 < 0.0 && d2 < 0.0) {
                        p2 = p1;
                        isvalid[1] = false;
                        isvalid[2] = false;
                        return;
                    // one outside - shorten segment
                    } else if (d1 < 0.0) {
                        // solve 0 = m * t + b = (d2 - d1) * t + d1 with t in (0, 1)
                        p1       = p1       - d1 * (p2 - p1)             / (d2 - d1);
                        f_color1 = f_color1 - d1 * (f_color2 - f_color1) / (d2 - d1);
                        isvalid[0] = false;
                    } else if (d2 < 0.0) {
                        p2       = p2       - d2 * (p1 - p2)             / (d1 - d2);
                        f_color2 = f_color2 - d2 * (f_color1 - f_color2) / (d1 - d2);
                        isvalid[3] = false;
                    }
                }

                return;
            }

            ////////////////////////////////////////////////////////////////////////
            // Main
            ////////////////////////////////////////////////////////////////////////

            void main() {
                bool is_end = position.x == 1.0;


                ////////////////////////////////////////////////////////////////////
                // Handle line geometry (position, directions)
                ////////////////////////////////////////////////////////////////////


                float width = px_per_unit * (is_end ? uniform_linewidth_end : uniform_linewidth_start);
                float halfwidth = 0.5 * max(AA_RADIUS, width);

                bool[4] isvalid = bool[4](true, true, true, true);

                // color at start/end of segment
                f_color1 = line_color_start;
                f_color2 = line_color_end;

                // To apply pixel space linewidths we transform line vertices to pixel space
                // here. This is dangerous with perspective projection as p.xyz / p.w sends
                // points from behind the camera to beyond far (clip z > 1), causing lines
                // to invert. To avoid this we translate points along the line direction,
                // moving them to the edge of the visible area.
                vec3 p0, p1, p2, p3;
                {
                    // All in clip space
                    vec4 clip_p0 = clip_space(positions_transformed_f32c_prev);
                    vec4 clip_p1 = clip_space(positions_transformed_f32c_start);
                    vec4 clip_p2 = clip_space(positions_transformed_f32c_end);
                    vec4 clip_p3 = clip_space(positions_transformed_f32c_next);

                    vec4 v1 = clip_p2 - clip_p1;

                    // With our perspective projection matrix clip.w = -view.z with
                    // clip.w < 0.0 being behind the camera.
                    // Note that if the signs in the projectionmatrix change, this may become wrong.
                    if (clip_p1.w < 0.0) {
                        // the line connects outside the visible area so we may consider it disconnected
                        isvalid[0] = false;
                        // A clip position is visible if -w <= z <= w. To move the line along
                        // the line direction v to the start of the visible area, we solve:
                        //   p.z + t * v.z = +-(p.w + t * v.w)
                        // where (-) gives us the result for the near clipping plane as p.z
                        // and p.w share the same sign and p.z/p.w = -1.0 is the near plane.
                        clip_p1 = clip_p1 + (-clip_p1.w - clip_p1.z) / (v1.z + v1.w) * v1;
                        f_color1 = f_color1 + (-clip_p1.w - clip_p1.z) / (v1.z + v1.w) * (f_color2 - f_color1);
                    }
                    if (clip_p2.w < 0.0) {
                        isvalid[3] = false;
                        clip_p2 = clip_p2 + (-clip_p2.w - clip_p2.z) / (v1.z + v1.w) * v1;
                        f_color2 = f_color2 + (-clip_p2.w - clip_p2.z) / (v1.z + v1.w) * (f_color2 - f_color1);
                    }

                    // Shorten segments to fit clip planes
                    // returns true if segments are fully clipped
                    process_clip_planes(clip_p1, clip_p2, isvalid);

                    // transform clip -> screen space, applying xyz / w normalization (which
                    // is now save as all vertices are in front of the camera)
                    p0 = screen_space(clip_p0); // start of previous segment
                    p1 = screen_space(clip_p1); // end of previous segment, start of current segment
                    p2 = screen_space(clip_p2); // end of current segment, start of next segment
                    p3 = screen_space(clip_p3); // end of next segment
                }

                // doesn't work correctly with linepoint_x...
                isvalid[0] = p0 != p1;
                isvalid[3] = p2 != p3;

                // line vectors (xy-normalized vectors in line direction)
                // Need z component here for correct depth order
                vec3 v1 = p2 - p1;
                float segment_length = length(v1);
                v1 /= segment_length;

                // We don't need the z component for these
                vec2 v0 = v1.xy, v2 = v1.xy;
                bool[2] skip_joint;
                if (isvalid[0])
                    v0 = normalize(p1.xy - p0.xy);
                if (isvalid[3])
                    v2 = normalize(p3.xy - p2.xy);

                // line normals (i.e. in uniform_linewidth direction)
                vec2 n0 = normal_vector(v0);
                vec2 n1 = normal_vector(v1);
                vec2 n2 = normal_vector(v2);


                ////////////////////////////////////////////////////////////////////
                // Handle joint geometry
                ////////////////////////////////////////////////////////////////////


                // joint information

                // Miter normals (normal of truncated edge / vector to sharp corner)
                // Note: n0 + n1 = vec(0) for a 180° change in direction. +-(v0 - v1) is the
                //       same direction, but becomes vec(0) at 0°, so we can use it instead
                vec2 miter = vec2(dot(v0, v1.xy), dot(v1.xy, v2));
                vec2 miter_n1 = miter.x < -0.0 ?
                    sign_no_zero(dot(v0.xy, n1)) * normalize(v0.xy - v1.xy) : normalize(n0 + n1);
                vec2 miter_n2 = miter.y < -0.0 ?
                    sign_no_zero(dot(v1.xy, n2)) * normalize(v1.xy - v2.xy) : normalize(n1 + n2);

                // Are we truncating the joint based on miter limit or joinstyle?
                // bevel / always truncate doesn't work with v1 == v2 (v0) so we use allow
                // miter joints a when v1 ≈ v2 (v0)
                bool[2] is_truncated = bool[2](
                    (int(joinstyle) == BEVEL) ? miter.x < 0.99 : miter.x < miter_limit,
                    (int(joinstyle) == BEVEL) ? miter.y < 0.99 : miter.y < miter_limit
                );

                // miter vectors (line vector matching miter normal)
                vec2 miter_v1 = -normal_vector(miter_n1);
                vec2 miter_v2 = -normal_vector(miter_n2);

                // distance between p1/2 and respective sharp corner
                float miter_offset1 = dot(miter_n1, n1); // = dot(miter_v1, v1)
                float miter_offset2 = dot(miter_n2, n1); // = dot(miter_v2, v1)

                // How far the line needs to extend to accomodate the joint.
                // These are calculated as prefactors to v1 so that the line quad
                // is given by:
                //      p1 + w * extrusion[0] * v1  -----  p2 + w * extrusion[1] * v1
                //                |                                 |
                //      p1 + w * extrusion[0] * v1  -----  p2 + w * extrusion[1] * v1
                // with w = halfwidth for drawn corners and w = halfwidth + AA_THICKNESS
                // for the corners of quad. The sign difference due to miter joints
                // is included based on the current vertex position (position.y).
                // (truncated miter joints do not differ here)
                vec2 extrusion;

                if (is_truncated[0]) {
                    // need to extend segment to include previous segments corners for truncated join
                    extrusion[0] = -abs(miter_offset1 / dot(miter_v1, n1));
                } else {
                    // shallow/spike join needs to include point where miter normal meets outer line edge
                    extrusion[0] = position.y * dot(miter_n1, v1.xy) / miter_offset1;
                }

                if (is_truncated[1]) {
                    extrusion[1] = abs(miter_offset2 / dot(miter_n2, v1.xy));
                } else {
                    extrusion[1] = position.y * dot(miter_n2, v1.xy) / miter_offset2;
                }


                ////////////////////////////////////////////////////////////////////
                // Joint adjustments
                ////////////////////////////////////////////////////////////////////


                // Miter joints can cause vertices to move past each other, e.g.
                //  _______
                //  '.   .'
                //     x
                //   '---'
                // To avoid drawing the "inverted" section we move the relevant
                // vertices to the crossing point (x) using this scaling factor.
                // TODO: skipping this for linestart/end avoid round and square
                //       being cut off but causes overlap...
                float shape_factor = 1.0;
                if ((isvalid[0] && isvalid[3]) || (int(linecap) == BUTT))
                    shape_factor = segment_length / max(segment_length,
                        (halfwidth + AA_THICKNESS) * (extrusion[0] - extrusion[1]));

                // If a uniform_pattern starts or stops drawing in a joint it will get
                // fractured across the joint. To avoid this we either:
                // - adjust the involved line segments so that the patterns ends
                //   on straight line quad (adjustment becomes +1.0 or -1.0)
                // - or adjust the uniform_pattern to start/stop outside of the joint
                //   (f_pattern_overwrite is set, adjustment is 0.0)
                vec2 adjustment = process_pattern(
                    uniform_pattern, isvalid, halfwidth * extrusion, segment_length, halfwidth
                );

                // If adjustment != 0.0 we replace a joint by an extruded line,
                // so we no longer need to shrink the line for the joint to fit.
                if (adjustment[0] != 0.0 || adjustment[1] != 0.0)
                    shape_factor = 1.0;

                ////////////////////////////////////////////////////////////////////
                // Static vertex data
                ////////////////////////////////////////////////////////////////////

                // For truncated miter joints we discard overlapping sections of the two
                // involved line segments. To identify which sections overlap we calculate
                // the signed distance in +- miter vector direction from the shared line
                // point in fragment shader. We pass the necessary data here. If we do not
                // have a truncated joint we adjust the data here to never discard.
                // Why not calculate the sdf here?
                // If we calculate the sdf here and pass it as an interpolated vertex output
                // the values we get between the two line segments will differ since the
                // the vertices each segment interpolates from differ. This causes the
                // discard check to rarely be true or false for both segments, resulting in
                // duplicated or missing pixel/fragment draw.
                // Passing the line point and miter vector instead should fix this issue,
                // because both of these values come from the same calculation between the
                // two segments. I.e. (previous segment).p2 == (next segment).p1 and
                // (previous segment).miter_v2 == (next segment).miter_v1 should be the case.
                if (isvalid[0] && is_truncated[0] && (adjustment[0] == 0.0)) {
                    f_linepoints.xy = p1.xy + px_per_unit * scene_origin;   // FragCoords are relative to the window
                    f_miter_vecs.xy = -miter_v1.xy;                         // but p1/p2 is relative to the scene origin
                } else {
                    f_linepoints.xy = vec2(-1e12);          // FragCoord > 0
                    f_miter_vecs.xy = normalize(vec2(-1));
                }
                if (isvalid[3] && is_truncated[1] && (adjustment[1] == 0.0)) {
                    f_linepoints.zw = p2.xy + px_per_unit * scene_origin;
                    f_miter_vecs.zw = miter_v2.xy;
                } else {
                    f_linepoints.zw = vec2(-1e12);
                    f_miter_vecs.zw = normalize(vec2(-1));
                }

                // Used to elongate sdf to include joints
                // if start/end         no elongation
                // if joint skipped     elongate to new length
                // if normal joint      elongate a lot to let shape/truncation handle joint
                f_extrusion = vec2(
                    !isvalid[0] ? 0.0 : (adjustment[0] == 0.0 ? 1e12 : halfwidth * abs(extrusion[0])),
                    !isvalid[3] ? 0.0 : (adjustment[1] == 0.0 ? 1e12 : halfwidth * abs(extrusion[1]))
                );

                // used to compute width sdf
                f_linewidth = halfwidth;

                f_instance_id = lineindex_start + uint(1);

                f_cumulative_length = px_per_unit * lastlen_start;

                // linecap + joinstyle
                f_capmode = ivec2(
                    isvalid[0] ? joinstyle : linecap,
                    isvalid[3] ? joinstyle : linecap
                );


                ////////////////////////////////////////////////////////////////////
                // Varying vertex data
                ////////////////////////////////////////////////////////////////////

                vec3 offset;
                int x = int(is_end);
                if (adjustment[x] == 0.0) {
                    if (is_truncated[x] || !isvalid[3 * x]) {
                        // handle overlap in fragment shader via SDF comparison
                        offset = shape_factor * (
                            position.x * (halfwidth * max(1.0, abs(extrusion[x])) + AA_THICKNESS) * v1 +
                            vec3(position.y * (halfwidth + AA_THICKNESS) * n1, 0)
                        );
                    } else {
                        // handle overlap by adjusting geometry
                        // TODO: should this include z in miter_n?
                        offset = position.y * shape_factor *
                            (halfwidth + AA_THICKNESS) /
                            float[2](miter_offset1, miter_offset2)[x] *
                            vec3(vec2[2](miter_n1, miter_n2)[x], 0);
                    }
                } else {
                    // discard joint for cleaner uniform_pattern handling
                    offset =
                        adjustment[x] * (halfwidth * abs(extrusion[x]) + AA_THICKNESS) * v1 +
                        vec3(position.y * (halfwidth + AA_THICKNESS) * n1, 0);
                }

                // Vertex position (padded for joint & anti-aliasing)
                vec3 point = vec3[2](p1, p2)[x] + offset;

                // SDF's
                vec2 VP1 = point.xy - p1.xy;
                vec2 VP2 = point.xy - p2.xy;

                // sdf of this segment
                f_quad_sdf.x = dot(VP1, -v1.xy);
                f_quad_sdf.y = dot(VP2,  v1.xy);
                f_quad_sdf.z = dot(VP1,  n1);

                // sdf for creating a flat cap on truncated joints
                // (sign(dot(...)) detects if line bends left or right)
                f_truncation.x = !is_truncated[0] ? -1.0 :
                    dot(VP1, sign(dot(miter_n1, -v1.xy)) * miter_n1) - halfwidth * abs(miter_offset1)
                    - abs(adjustment[0]) * 1e12;
                f_truncation.y = !is_truncated[1] ? -1.0 :
                    dot(VP2, sign(dot(miter_n2, +v1.xy)) * miter_n2) - halfwidth * abs(miter_offset2)
                    - abs(adjustment[1]) * 1e12;

                // Colors should be sampled based on the normalized distance from the
                // extruded edge (varies with offset in n direction)
                // - correcting for this with per-vertex colors results visible face border
                // - calculating normalized distance here will cause div 0/negative
                //   issues as (linelength +- (extrusion[0] + extrusion[1])) <= 0 is possible
                // So defer color interpolation to fragment shader
                f_linestart = shape_factor * halfwidth * extrusion[0];
                f_linelength = max(1.0, segment_length - shape_factor * halfwidth * (extrusion[0] - extrusion[1]));

                // for thin lines
                f_alpha_weight = min(1.0, width / AA_RADIUS);

                // clip space position
                gl_Position = vec4(2.0 * point.xy / (px_per_unit * resolution) - 1.0, point.z, 1.0);
            }
        `;
    }
}
function lines_fragment_shader(uniforms, attributes) {
    const color_uniforms = filter_by_key(uniforms, [
        "picking",
        "uniform_pattern",
        "uniform_pattern_length",
        "uniform_colorrange",
        "uniform_colormap",
        "nan_color",
        "highclip_color",
        "lowclip_color"
    ]);
    const uniform_decl = uniforms_to_type_declaration(color_uniforms);
    const color = attribute_type(attributes.line_color_start) || uniform_type(uniforms.line_color_start);
    return `
    // uncomment for debug rendering
    // #define DEBUG

    precision highp int;
    precision highp float;
    precision highp sampler2D;
    precision highp sampler3D;

    in highp vec3 f_quad_sdf;
    in vec2 f_truncation;
    in float f_linestart;
    in float f_linelength;

    flat in float f_linewidth;
    flat in vec4 f_pattern_overwrite;
    flat in vec2 f_extrusion;
    flat in ${color} f_color1;
    flat in ${color} f_color2;
    flat in float f_alpha_weight;
    flat in uint f_instance_id;
    flat in float f_cumulative_length;
    flat in ivec2 f_capmode;
    flat in vec4 f_linepoints;
    flat in vec4 f_miter_vecs;

    uniform uint object_id;
    ${uniform_decl}

    out vec4 fragment_color;

    // Half width of antialiasing smoothstep
    const float AA_RADIUS = 0.8;
    // space allocated for AA
    const float AA_THICKNESS = 2.0 * AA_RADIUS;
    const int BUTT   = 0;
    const int SQUARE = 1;
    const int ROUND  = 2;
    const int MITER  = 0;
    const int BEVEL  = 3;

    float aastep(float threshold, float value) {
        return smoothstep(threshold-AA_RADIUS, threshold+AA_RADIUS, value);
    }


    ////////////////////////////////////////////////////////////////////////
    // Color handling
    ////////////////////////////////////////////////////////////////////////


    vec4 get_color_from_cmap(float value, sampler2D colormap, vec2 colorrange) {
        float cmin = colorrange.x;
        float cmax = colorrange.y;
        if (value <= cmax && value >= cmin) {
            // in value range, continue!
        } else if (value < cmin) {
            return lowclip_color;
        } else if (value > cmax) {
            return highclip_color;
        } else {
            // isnan CAN be broken (of course) -.-
            // so if outside value range and not smaller/bigger min/max we assume NaN
            return nan_color;
        }
        float i01 = clamp((value - cmin) / (cmax - cmin), 0.0, 1.0);
        // 1/0 corresponds to the corner of the colormap, so to properly interpolate
        // between the colors, we need to scale it, so that the ends are at 1 - (stepsize/2) and 0+(stepsize/2).
        float stepsize = 1.0 / float(textureSize(colormap, 0));
        i01 = (1.0 - stepsize) * i01 + 0.5 * stepsize;
        return texture(colormap, vec2(i01, 0.0));
    }

    vec4 get_color(float color, sampler2D colormap, vec2 colorrange) {
        return get_color_from_cmap(color, colormap, colorrange);
    }

    vec4 get_color(vec4 color, bool colormap, bool colorrange) {
        return color;
    }
    vec4 get_color(vec3 color, bool colormap, bool colorrange) {
        return vec4(color, 1.0);
    }


    ////////////////////////////////////////////////////////////////////////
    // Pattern sampling
    ////////////////////////////////////////////////////////////////////////


    float get_pattern_sdf(sampler2D uniform_pattern, vec2 uv){

        // f_pattern_overwrite.x
        //      v           joint
        //    ----------------
        //      |          |
        //    ----------------
        // joint           ^
        //      f_pattern_overwrite.z

        float w = 2.0 * f_linewidth;
        if (uv.x <= f_pattern_overwrite.x) {
            // overwrite for uniform_pattern with "ON" to the right (positive uv.x)
            float sdf_overwrite = w * uniform_pattern_length * (f_pattern_overwrite.x - uv.x);
            // uniform_pattern value where we start overwriting
            float edge_sample = w * texture(uniform_pattern, vec2(f_pattern_overwrite.x, 0.5)).x;
            // offset for overwrite to smoothly connect between sampling and edge
            float sdf_offset = max(f_pattern_overwrite.y * edge_sample, -AA_RADIUS);
            // add offset and apply direction ("ON" to left or right) to overwrite
            return f_pattern_overwrite.y * (sdf_overwrite + sdf_offset);
        } else if (uv.x >= f_pattern_overwrite.z) {
            // same as above (other than mirroring overwrite direction)
            float sdf_overwrite = w * uniform_pattern_length * (uv.x - f_pattern_overwrite.z);
            float edge_sample = w * texture(uniform_pattern, vec2(f_pattern_overwrite.z, 0.5)).x;
            float sdf_offset = max(f_pattern_overwrite.w * edge_sample, -AA_RADIUS);
            return f_pattern_overwrite.w * (sdf_overwrite + sdf_offset);
        } else
            // in allowed range
            return w * texture(uniform_pattern, uv).x;
    }

    float get_pattern_sdf(bool _, vec2 uv){
        return -10.0;
    }

    vec2 encode_uint_to_float(uint value) {
        float lower = float(value & 0xFFFFu) / 65535.0;
        float upper = float(value >> 16u) / 65535.0;
        return vec2(lower, upper);
    }

    vec4 pack_int(uint id, uint index) {
        vec4 unpack;
        unpack.rg = encode_uint_to_float(id);
        unpack.ba = encode_uint_to_float(index);
        return unpack;
    }


    void main(){
        vec4 color;

        // f_quad_sdf.x is the distance from p1, negative in v1 direction.
        vec2 uv = vec2(
            (f_cumulative_length - f_quad_sdf.x) / (2.0 * f_linewidth * uniform_pattern_length),
            0.5 + 0.5 * f_quad_sdf.z / f_linewidth
        );

    #ifndef DEBUG
        // discard fragments that are other side of the truncated joint
        float discard_sdf1 = dot(gl_FragCoord.xy - f_linepoints.xy, f_miter_vecs.xy);
        float discard_sdf2 = dot(gl_FragCoord.xy - f_linepoints.zw, f_miter_vecs.zw);
        if ((f_quad_sdf.x > 0.0 && discard_sdf1 > 0.0) ||
            (f_quad_sdf.y > 0.0 && discard_sdf2 >= 0.0))
            discard;

        float sdf;

        // f_quad_sdf.x includes everything from p1 in p2-p1 direction, i.e. >
        // f_quad_sdf.y includes everything from p2 in p1-p2 direction, i.e. <
        // <   < | >    < >    < | >   >
        // <   < 1->----<->----<-2 >   >
        // <   < | >    < >    < | >   >
        if (f_capmode.x == ROUND) {
            // in circle(p1, halfwidth) || is beyond p1 in p2-p1 direction
            sdf = min(sqrt(f_quad_sdf.x * f_quad_sdf.x + f_quad_sdf.z * f_quad_sdf.z) - f_linewidth, f_quad_sdf.x);
        } else if (f_capmode.x == SQUARE) {
            // everything in p2-p1 direction shifted by halfwidth in p1-p2 direction (i.e. include more)
            sdf = f_quad_sdf.x - f_linewidth;
        } else { // miter or bevel joint or :butt cap
            // variable shift in -(p2-p1) direction to make space for joints
            sdf = f_quad_sdf.x - f_extrusion.x;
            // do truncate joints
            sdf = max(sdf, f_truncation.x);
        }

        // Same as above but for p2
        if (f_capmode.y == ROUND) {
            sdf = max(sdf,
                min(sqrt(f_quad_sdf.y * f_quad_sdf.y + f_quad_sdf.z * f_quad_sdf.z) - f_linewidth, f_quad_sdf.y)
            );
        } else if (f_capmode.y == SQUARE) {
            sdf = max(sdf, f_quad_sdf.y - f_linewidth);
        } else { // miter or bevel joint or :butt cap
            sdf = max(sdf, f_quad_sdf.y - f_extrusion.y);
            sdf = max(sdf, f_truncation.y);
        }

        // distance in uniform_linewidth direction
        // f_quad_sdf.z is 0 along the line connecting p1 and p2 and increases along line-normal direction
        //  ^  |  ^      ^  | ^
        //     1------------2
        //  ^  |  ^      ^  | ^
        sdf = max(sdf, abs(f_quad_sdf.z) - f_linewidth);

        // inner truncation (AA for overlapping parts)
        // min(a, b) keeps what is inside a and b
        // where a is the smoothly cut of part just before discard triggers (i.e. visible)
        // and b is the (smoothly) cut of part where the discard triggers
        // 100.0x sdf makes the sdf much more sharply, avoiding overdraw in the center
        sdf = max(sdf, min(f_quad_sdf.x + 1.0, 100.0 * discard_sdf1 - 1.0));
        sdf = max(sdf, min(f_quad_sdf.y + 1.0, 100.0 * discard_sdf2 - 1.0));

        // uniform_pattern application
        sdf = max(sdf, get_pattern_sdf(uniform_pattern, uv));

        // draw

        //  v- edge
        //   .---------------
        //    '.
        //      p1      v1
        //        '.   --->
        //          '----------
        // -f_quad_sdf.x is the distance from p1, positive in v1 direction
        // f_linestart is the distance between p1 and the left edge along v1 direction
        // f_start_length.y is the distance between the edges of this segment, in v1 direction
        // so this is 0 at the left edge and 1 at the right edge (with extrusion considered)
        float factor = (-f_quad_sdf.x - f_linestart) / f_linelength;
        color = get_color(f_color1 + factor * (f_color2 - f_color1), uniform_colormap, uniform_colorrange);

        color.a *= aastep(0.0, -sdf) * f_alpha_weight;
    #endif

    #ifdef DEBUG
        // base color
        color = vec4(0.5, 0.5, 0.5, 0.2);
        color.rgb += (2.0 * mod(float(f_instance_id), 2.0) - 1.0) * 0.1;

        // show color interpolation as brightness gradient
        // float factor = (-f_quad_sdf.x - f_linestart) / f_linelength;
        // color.rgb += (2.0 * factor - 1.0) * 0.2;

        // mark "outside" define by quad_sdf in black
        float sdf = max(f_quad_sdf.x - f_extrusion.x, f_quad_sdf.y - f_extrusion.y);
        sdf = max(sdf, abs(f_quad_sdf.z) - f_linewidth);
        color.rgb -= vec3(0.4) * step(0.0, sdf);

        // Mark discarded space in red/blue
        float discard_sdf1 = dot(gl_FragCoord.xy - f_linepoints.xy, f_miter_vecs.xy);
        float discard_sdf2 = dot(gl_FragCoord.xy - f_linepoints.zw, f_miter_vecs.zw);
        if (f_quad_sdf.x > 0.0 && discard_sdf1 > 0.0)
            color.r += 0.5;
        if (f_quad_sdf.y > 0.0 && discard_sdf2 >= 0.0)
            color.b += 0.5;

        // remaining overlap as softer red/blue
        if (discard_sdf1 - 1.0 > 0.0)
            color.r += 0.2;
            color.r += 0.2;
        if (discard_sdf2 - 1.0 > 0.0)
            color.b += 0.2;

        // Mark regions excluded via truncation in green
        color.g += 0.5 * step(0.0, max(f_truncation.x, f_truncation.y));

        // and inner truncation as softer green
        if (min(f_quad_sdf.x + 1.0, 100.0 * discard_sdf1 - 1.0) > 0.0)
            color.g += 0.2;
        if (min(f_quad_sdf.y + 1.0, 100.0 * discard_sdf2 - 1.0) > 0.0)
            color.g += 0.2;

        // mark uniform_pattern in white
        color.rgb += vec3(0.3) * step(0.0, get_pattern_sdf(uniform_pattern, uv));
    #endif

        if (color.a <= 0.0)
            discard;

        if (picking) {
            if (color.a > 0.1) {
                fragment_color = pack_int(object_id, f_instance_id);
            }
            return;
        }
        fragment_color = vec4(color.rgb, color.a);
    }
    `;
}
function create_line_material(uniforms_des, attributes, is_linesegments) {
    const mat = new THREE.RawShaderMaterial({
        uniforms: uniforms_des,
        glslVersion: THREE.GLSL3,
        vertexShader: lines_vertex_shader(uniforms_des, attributes, is_linesegments),
        fragmentShader: lines_fragment_shader(uniforms_des, attributes),
        transparent: true,
        blending: THREE.CustomBlending,
        blendSrc: THREE.SrcAlphaFactor,
        blendDst: THREE.OneMinusSrcAlphaFactor,
        blendSrcAlpha: THREE.ZeroFactor,
        blendDstAlpha: THREE.OneFactor,
        blendEquation: THREE.AddEquation
    });
    mat.uniforms.object_id = {
        value: 1
    };
    return mat;
}
function attach_interleaved_line_buffer(attr_name, geometry, data, ndim, is_segments, is_position) {
    const skip_elems = is_segments ? 2 * ndim : ndim;
    const buffer = new THREE.InstancedInterleavedBuffer(data, skip_elems, 1);
    buffer.count = Math.max(0, is_segments ? Math.floor(buffer.count - 1) : buffer.count - 3);
    geometry.setAttribute(attr_name + "_start", new THREE.InterleavedBufferAttribute(buffer, ndim, ndim));
    geometry.setAttribute(attr_name + "_end", new THREE.InterleavedBufferAttribute(buffer, ndim, 2 * ndim));
    if (is_position) {
        geometry.setAttribute(attr_name + "_prev", new THREE.InterleavedBufferAttribute(buffer, ndim, 0));
        geometry.setAttribute(attr_name + "_next", new THREE.InterleavedBufferAttribute(buffer, ndim, 3 * ndim));
    }
    geometry.interleaved_attributes[attr_name] = buffer;
    return buffer;
}
function create_line_instance_geometry() {
    const geometry = new THREE.InstancedBufferGeometry();
    geometry.interleaved_attributes = {};
    const instance_positions = [
        -1,
        -1,
        1,
        -1,
        1,
        1,
        -1,
        -1,
        1,
        1,
        -1,
        1
    ];
    geometry.setAttribute("position", new THREE.Float32BufferAttribute(instance_positions, 2));
    geometry.boundingSphere = new THREE.Sphere();
    geometry.boundingSphere.radius = 10000000000000;
    geometry.frustumCulled = false;
    return geometry;
}
function create_line_buffer(geometry, buffers, name, attr, is_segments, is_position) {
    const flat_buffer = attr.flat;
    const ndims = attr.type_length;
    const linebuffer = attach_interleaved_line_buffer(name, geometry, flat_buffer, ndims, is_segments, is_position);
    buffers[name] = linebuffer;
    return flat_buffer;
}
function create_line_buffers(geometry, buffers, attributes, is_segments) {
    for(let name in attributes){
        const attr = attributes[name];
        create_line_buffer(geometry, buffers, name, attr, is_segments, name == "positions_transformed_f32c");
    }
}
function get_points_view(points, indices, ndim) {
    let view = new Float32Array(indices.length * ndim);
    for(let i = 0; i < indices.length; i++){
        let index = indices[i];
        for(let j = 0; j < ndim; j++){
            view[i * ndim + j] = points[index * ndim + j];
        }
    }
    return view;
}
function pack_array(array, data, type_length = 0) {
    if (array.flat) {
        const tl = type_length === 0 ? array.type_length : type_length;
        return {
            flat: data,
            type_length: tl
        };
    }
    return data;
}
function unpack_array(array) {
    if (array.flat) {
        return array.flat;
    }
    return array;
}
function compute_lastlen(points, point_ndim, pvm, res, is_lines_with_linestyle) {
    if (!is_lines_with_linestyle) return new Float32Array(points.length / point_ndim).fill(0);
    if (points.length === 0) return new Float32Array(0);
    const num_points = points.length / point_ndim;
    const output = new Float32Array(num_points);
    const scale = new THREE.Vector2(0.5 * res.x, 0.5 * res.y);
    const second_point_idx = 1 * point_ndim;
    let clip = new THREE.Vector4(points[second_point_idx], points[second_point_idx + 1], point_ndim === 3 ? points[second_point_idx + 2] : 0, 1).applyMatrix4(pvm);
    let prev = new THREE.Vector2(clip.x, clip.y).multiply(scale).divideScalar(clip.w);
    output[0] = 0.0;
    output[1] = 0.0;
    output[output.length - 1] = 0.0;
    let point_i = 2;
    while(point_i < num_points){
        const array_idx = point_i * point_ndim;
        const x1 = points[array_idx];
        const y1 = points[array_idx + 1];
        const z = point_ndim === 3 ? points[array_idx + 2] : 0;
        if (Number.isFinite(x1) && Number.isFinite(y1) && (point_ndim === 2 || Number.isFinite(z))) {
            clip = new THREE.Vector4(x1, y1, z, 1).applyMatrix4(pvm);
            const current = new THREE.Vector2(clip.x, clip.y).multiply(scale).divideScalar(clip.w);
            const length = current.distanceTo(prev);
            output[point_i] = output[point_i - 1] + length;
            prev = current;
            point_i += 1;
        } else {
            output[point_i] = 0.0;
            output[point_i + 1] = 0.0;
            if (point_i + 2 < num_points) {
                output[Math.min(output.length - 1, point_i + 2)] = 0.0;
                const next_point_idx = (point_i + 2) * point_ndim;
                clip = new THREE.Vector4(points[next_point_idx], points[next_point_idx + 1], point_ndim === 3 ? points[next_point_idx + 2] : 0, 1).applyMatrix4(pvm);
                prev = new THREE.Vector2(clip.x, clip.y).multiply(scale).divideScalar(clip.w);
            }
            point_i += 3;
        }
    }
    return output;
}
function get_projectionview(cam, plot) {
    const space = plot.plot_data.cam_space;
    const identity = new THREE.Uniform(new THREE.Matrix4());
    if (space == "data") {
        return cam.projectionview;
    } else if (space == "pixel") {
        return cam.pixel_space;
    } else if (space == "relative") {
        return cam.relative_space;
    } else if (space == "clip") {
        return identity;
    } else {
        throw new Error(`Space ${space} not supported!`);
    }
}
function get_last_len(plot, points) {
    const cam = plot.scene.wgl_camera;
    const is_lines_with_linestyle = !plot.is_segments && plot.plot_data.pattern != false;
    const pvm = get_projectionview(cam, plot);
    const res = cam.resolution;
    const point_ndim = plot.ndims["positions_transformed_f32c"] || 2;
    const space = plot.plot_data.cam_space;
    const static_space = space === "clip" || space === "relative";
    if (!cam.on_update.has(plot.uuid) && !static_space) {
        cam.on_update[plot.uuid] = (x1)=>{
            const geom = plot.mesh.geometry;
            const ia = geom.interleaved_attributes;
            const new_points = ia.positions_transformed_f32c.array;
            compute_lastlen(new_points, point_ndim, pvm.value, res.value, is_lines_with_linestyle);
        };
    }
    return compute_lastlen(points, point_ndim, pvm.value, res.value, is_lines_with_linestyle);
}
function add_line_attributes(plot, attributes) {
    const new_data = {};
    let { lineindex  } = plot;
    if (attributes.positions_transformed_f32c) {
        const { positions_transformed_f32c  } = attributes;
        const val = unpack_array(positions_transformed_f32c);
        if (positions_transformed_f32c.type_length) {
            plot.ndims["positions_transformed_f32c"] = positions_transformed_f32c.type_length;
        }
        lineindex = nan_free_points_indices(val, plot.ndims["positions_transformed_f32c"]);
        plot.lineindex = lineindex;
        const points = get_points_view(val, lineindex, plot.ndims["positions_transformed_f32c"]);
        new_data["positions_transformed_f32c"] = pack_array(positions_transformed_f32c, points);
        new_data["lineindex"] = pack_array(positions_transformed_f32c, lineindex, 1);
        new_data["lastlen"] = pack_array(positions_transformed_f32c, get_last_len(plot, points), 1);
    }
    function is_uniform(key) {
        return key in plot.deserialized_uniforms;
    }
    for (const [key, value] of Object.entries(attributes)){
        const val = unpack_array(value);
        if (key === "positions_transformed_f32c") {
            continue;
        }
        if ((key === "line_color" || key === "uniform_linewidth") && is_uniform(key)) {
            new_data[key + "_start"] = value;
            new_data[key + "_end"] = value;
        } else if (is_typed_array(val) && (key === "line_color" || key === "uniform_linewidth")) {
            if (value.type_length) {
                plot.ndims[key] = value.type_length;
            }
            new_data[key] = pack_array(value, get_points_view(val, lineindex, plot.ndims[key]));
        } else {
            new_data[key] = value;
        }
    }
    return new_data;
}
function create_line(plot_object) {
    const geometry = create_line_instance_geometry();
    const buffers = {};
    const { plot_data  } = plot_object;
    create_line_buffers(geometry, buffers, add_line_attributes(plot_object, plot_data.attributes), plot_object.is_segments);
    const material = create_line_material(add_line_attributes(plot_object, plot_object.deserialized_uniforms), geometry.attributes, plot_object.is_segments);
    material.depthTest = !plot_data.overdraw;
    material.depthWrite = !plot_data.transparency;
    material.uniforms.is_linesegments = {
        value: plot_object.is_segments
    };
    const mesh = new THREE.Mesh(geometry, material);
    mesh.geometry.instanceCount = geometry.attributes.positions_transformed_f32c_start.count;
    return mesh;
}
class Lines extends Plot {
    constructor(scene, data){
        super(scene, data);
        if (data.plot_type !== "Lines") {
            throw new Error(`Lines class must be initialized with plot_type 'Lines' found ${data.plot_type}`);
        }
        this.is_segments = data.is_segments === true;
        this.is_instanced = true;
        this.ndims = {};
        this.scene = scene;
        this.mesh = create_line(this);
        this.init_mesh();
    }
    update(data_key_value_array) {
        const dict = Object.fromEntries(data_key_value_array.map(([k, v])=>[
                k,
                expand_compressed(v)
            ]));
        const line_attr = Object.entries(add_line_attributes(this, dict));
        super.update(line_attr);
    }
    dispose() {
        this.scene.wgl_camera.on_update.delete(this.uuid);
        super.dispose();
    }
}
class Mesh extends Plot {
    constructor(scene, data){
        super(scene, data);
        if ("instance_attributes" in data) {
            this.is_instanced = true;
            this.mesh = create_instanced_mesh(this);
        } else {
            this.mesh = create_mesh(this);
        }
        this.init_mesh();
    }
}
function broadcast_getindex(a, x1, i) {
    if (a.length == x1.length / 2) {
        return new T(x1[i * 2], x1[i * 2 + 1]);
    } else if (x1.length == 2) {
        return new T(x1[0], x1[1]);
    } else {
        throw new Error(`broadcast_getindex: x has length ${x1.length}, but a has length ${a.length}`);
    }
}
function per_glyph_data(glyph_hashes, scales) {
    const atlas = get_texture_atlas();
    const uv_offset_width = new Float32Array(glyph_hashes.length * 4);
    const markersize = new Float32Array(glyph_hashes.length * 2);
    const quad_offsets = new Float32Array(glyph_hashes.length * 2);
    for(let i = 0; i < glyph_hashes.length; i++){
        const hash = glyph_hashes[i];
        const data = atlas.get_glyph_data(hash, broadcast_getindex(glyph_hashes, scales, i));
        const [uv, c_width, q_offset] = data ?? [
            new ot(0, 0, 0, 0),
            new T(0, 0),
            new T(0, 0)
        ];
        uv_offset_width.set(uv.toArray(), i * 4);
        markersize.set(c_width.toArray(), i * 2);
        quad_offsets.set(q_offset.toArray(), i * 2);
    }
    return [
        uv_offset_width,
        markersize,
        quad_offsets
    ];
}
function get_glyph_data_attributes(atlas, glyph_data) {
    if (glyph_data == null) {
        return {};
    }
    const { glyph_hashes , atlas_updates , scales  } = glyph_data;
    atlas.insert_glyphs(atlas_updates);
    if (glyph_hashes) {
        const [sdf_uv, quad_scale, quad_offset] = per_glyph_data(glyph_hashes, scales);
        return {
            sdf_uv,
            quad_scale,
            quad_offset
        };
    }
    return {};
}
class Scatter extends Plot {
    constructor(scene, data){
        const atlas = get_texture_atlas();
        const lengths = {
            sdf_uv: 4
        };
        if ("glyph_data" in data) {
            const gdata = get_glyph_data_attributes(atlas, data.glyph_data);
            delete data.glyph_data;
            for(const name in gdata){
                const buff = gdata[name];
                const len = lengths[name] || 2;
                data.instance_attributes[name] = {
                    flat: buff,
                    type_length: len
                };
            }
        }
        super(scene, data);
        this.is_instanced = true;
        this.atlas = atlas;
        this.mesh = create_instanced_mesh(this);
        this.init_mesh();
    }
    update(data_key_value_array) {
        const dict = Object.fromEntries(data_key_value_array);
        if ("glyph_data" in dict) {
            const data = get_glyph_data_attributes(this.atlas, dict.glyph_data);
            delete dict.glyph_data;
            for (const [key, value] of Object.entries(data)){
                dict[key] = value;
            }
        }
        super.update(Object.entries(dict));
    }
}
function nan_free_points_indices(points, ndim) {
    const indices = [];
    const npoints = points.length / ndim;
    let was_nan = true;
    let loop_start_idx = -1;
    for(let i = 0; i < npoints; i++){
        const p = get_point(points, i, ndim);
        if (point_isnan(p)) {
            if (!was_nan) {
                if (loop_start_idx !== -1 && loop_start_idx + 2 < indices.length && points_approx_equal(get_point(points, indices[loop_start_idx], ndim), get_point(points, i - 1, ndim))) {
                    indices.push(indices[loop_start_idx + 1]);
                    indices[loop_start_idx - 1] = i - 2;
                } else {
                    indices.push(i - 1);
                }
            }
            loop_start_idx = -1;
            was_nan = true;
        } else {
            if (was_nan) {
                indices.push(i);
                loop_start_idx = indices.length;
            }
            was_nan = false;
        }
        indices.push(i);
    }
    if (!was_nan) {
        if (loop_start_idx !== -1 && loop_start_idx + 2 < indices.length && points_approx_equal(get_point(points, indices[loop_start_idx], ndim), get_point(points, npoints - 1, ndim))) {
            indices.push(indices[loop_start_idx + 1]);
            indices[loop_start_idx - 1] = npoints - 2;
        } else {
            indices.push(npoints - 1);
        }
    }
    return new Uint32Array(indices);
}
function get_point(points, index, ndim) {
    return points.slice(index * ndim, (index + 1) * ndim);
}
function point_isnan(p) {
    return p.some((p)=>isNaN(p));
}
function points_approx_equal(p1, p2) {
    return p1.every((p, i)=>approx_equal(p, p2[i]));
}
function approx_equal(a, b) {
    return Math.abs(a - b) < Number.EPSILON;
}
const mod1 = {
    expand_compressed: expand_compressed,
    Plot: Plot,
    Lines: Lines,
    Mesh: Mesh,
    Scatter: Scatter
};
window.THREE = mod;
const orderedExecutor = {
    tasks: new Map(),
    nextExpected: 1,
    insert (f, order) {
        if (this.tasks.has(order)) {
            throw new Error(`Duplicate task for order ${order}`);
        }
        this.tasks.set(order, f);
        this.flush();
    },
    flush () {
        while(this.tasks.has(this.nextExpected)){
            const f = this.tasks.get(this.nextExpected);
            f();
            this.tasks.delete(this.nextExpected);
            this.nextExpected += 1;
        }
    }
};
function execute_in_order(order, f) {
    if (order < 1 || !Number.isInteger(order)) {
        throw new Error(`Invalid order: ${order}`);
    }
    orderedExecutor.insert(f, order);
}
function dispose_screen(screen) {
    if (Object.keys(screen).length === 0) {
        return;
    }
    const { renderer , picking_target , root_scene , comm  } = screen;
    comm.notify({
        window_open: false
    });
    if (renderer) {
        const canvas = renderer.domElement;
        if (canvas.parentNode) {
            canvas.parentNode.removeChild(canvas);
        }
        renderer.state.reset();
        renderer.forceContextLoss();
        renderer.dispose();
    }
    if (screen.texture_atlas) {
        screen.texture_atlas.dispose();
        screen.texture_atlas.image = null;
        screen.texture_atlas = undefined;
    }
    if (root_scene) {
        delete_three_scene(root_scene);
    }
    if (picking_target) {
        picking_target.dispose();
    }
    if (screen.resizeObserver) {
        screen.resizeObserver.disconnect();
        screen.resizeObserver = undefined;
    }
    Object.keys(screen).forEach((key)=>delete screen[key]);
    return;
}
function check_screen(screen) {
    if (!screen || !screen.renderer) {
        dispose_screen(screen);
        return false;
    }
    const canvas = screen.renderer.domElement;
    if (!document.body.contains(canvas)) {
        console.log("removing WGL context, canvas is not in the DOM anymore!");
        dispose_screen(screen);
        return false;
    }
    return true;
}
function render_scene(scene, picking = false) {
    const { renderer , camera , px_per_unit  } = scene.screen;
    if (!check_screen(scene.screen)) {
        return false;
    }
    if (!scene.visible.value) {
        return true;
    }
    renderer.autoClear = scene.clearscene.value;
    const area = scene.viewport.value;
    if (area) {
        const [x1, y1, w, h] = area.map((x1)=>x1 * px_per_unit);
        renderer.setViewport(x1, y1, w, h);
        renderer.setScissor(x1, y1, w, h);
        renderer.setScissorTest(true);
        if (picking) {
            renderer.setClearAlpha(0);
            renderer.setClearColor(new mod.Color(0), 0.0);
        } else {
            const alpha = scene.backgroundcolor_alpha.value;
            renderer.setClearColor(scene.backgroundcolor.value, alpha);
        }
        renderer.render(scene, camera);
    }
    return scene.scene_children.every((x1)=>render_scene(x1, picking));
}
function start_renderloop(three_scene) {
    const { fps  } = three_scene.screen;
    const time_per_frame = 1 / fps * 1000;
    let last_time_stamp = performance.now();
    function renderloop(timestamp) {
        if (!check_screen(three_scene.screen)) {
            return false;
        }
        if (timestamp - last_time_stamp > time_per_frame) {
            const all_rendered = render_scene(three_scene);
            if (!all_rendered) {
                return;
            }
            last_time_stamp = performance.now();
        }
        requestAnimationFrame(renderloop);
    }
    function _check_screen() {
        if (!check_screen(three_scene.screen)) {
            return;
        }
        setTimeout(_check_screen, 1000);
    }
    render_scene(three_scene);
    _check_screen();
    renderloop();
}
function get_element_size(element) {
    if (!element) {
        throw new Error("Element is null or undefined");
    }
    const style = window.getComputedStyle(element);
    const paddingLeft = parseFloat(style.paddingLeft) || 0;
    const paddingRight = parseFloat(style.paddingRight) || 0;
    const paddingTop = parseFloat(style.paddingTop) || 0;
    const paddingBottom = parseFloat(style.paddingBottom) || 0;
    let width, height;
    if (element === document.body) {
        const marginLeft = parseFloat(style.marginLeft) || 0;
        const marginRight = parseFloat(style.marginRight) || 0;
        const marginTop = parseFloat(style.marginTop) || 0;
        const marginBottom = parseFloat(style.marginBottom) || 0;
        width = window.innerWidth - paddingLeft - paddingRight - marginLeft - marginRight;
        height = window.innerHeight - paddingTop - paddingBottom - marginTop - marginBottom;
    } else {
        const rect = element.getBoundingClientRect();
        width = rect.width - paddingLeft - paddingRight;
        height = rect.height - paddingTop - paddingBottom;
    }
    return [
        width,
        height
    ];
}
function get_resize_element(canvas, resize_to) {
    if (!resize_to) {
        return null;
    }
    if (resize_to == "body") {
        return document.body;
    } else if (resize_to == "parent" || Array.isArray(resize_to) && resize_to.length == 2) {
        const wrapper = canvas.parentElement;
        if (!wrapper) {
            console.error("Canvas has no parent wrapper");
            return null;
        }
        const real_parent = wrapper.parentElement;
        if (!real_parent) {
            console.error("Canvas wrapper has no parent");
            return null;
        }
        return real_parent;
    }
    return null;
}
function convert_to_makie_size(element_width, element_height, fixed_width, fixed_height, resize_to, winscale) {
    let makie_width = fixed_width;
    let makie_height = fixed_height;
    if (resize_to == "body" || resize_to == "parent") {
        makie_width = element_width;
        makie_height = element_height;
    } else if (Array.isArray(resize_to) && resize_to.length == 2) {
        const [width_mode, height_mode] = resize_to;
        makie_width = width_mode == "parent" ? element_width : fixed_width;
        makie_height = height_mode == "parent" ? element_height : fixed_height;
    }
    return [
        makie_width / winscale,
        makie_height / winscale
    ];
}
function get_parent_size(canvas) {
    const wrapper = canvas.parentElement;
    if (!wrapper) {
        console.error("Canvas has no parent wrapper - this should not happen!");
        return [
            canvas.width,
            canvas.height
        ];
    }
    const real_parent = wrapper.parentElement;
    if (!real_parent) {
        console.error("Canvas wrapper has no parent - this should not happen!");
        return [
            canvas.width,
            canvas.height
        ];
    }
    return get_element_size(real_parent);
}
function wglerror(gl, error) {
    switch(error){
        case gl.NO_ERROR:
            return "No error";
        case gl.INVALID_ENUM:
            return "Invalid enum";
        case gl.INVALID_VALUE:
            return "Invalid value";
        case gl.INVALID_OPERATION:
            return "Invalid operation";
        case gl.OUT_OF_MEMORY:
            return "Out of memory";
        case gl.CONTEXT_LOST_WEBGL:
            return "Context lost";
        default:
            return "Unknown error";
    }
}
function getShaderErrors(gl, shader, type) {
    const status = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
    const errors = gl.getShaderInfoLog(shader).trim();
    if (status && errors === "") return "";
    const errorMatches = /ERROR: 0:(\d+)/.exec(errors);
    if (errorMatches) {
        const errorLine = parseInt(errorMatches[1]);
        return type.toUpperCase() + "\n\n" + errors + "\n\n" + "In line: " + errorLine + "\n\n" + "Source:\n" + gl.getShaderSource(shader);
    } else {
        return errors;
    }
}
function on_shader_error(gl, program, glVertexShader, glFragmentShader) {
    const programLog = gl.getProgramInfoLog(program).trim();
    const vertexErrors = getShaderErrors(gl, glVertexShader, "vertex");
    const fragmentErrors = getShaderErrors(gl, glFragmentShader, "fragment");
    const vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
    const fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
    const err = "THREE.WebGLProgram: Shader Error " + wglerror(gl, gl.getError()) + " - " + "VALIDATE_STATUS " + gl.getProgramParameter(program, gl.VALIDATE_STATUS) + "\n\n" + "Program Info Log:\n" + programLog + "\n" + vertexErrors + "\n" + fragmentErrors + "\n" + "Fragment log:\n" + fragmentLog + "Vertex log:\n" + vertexLog;
    Bonito.Connection.send_warning(err);
}
function add_canvas_events(screen, comm, resize_to) {
    const { canvas , winscale  } = screen;
    canvas.addEventListener("webglcontextlost", (event)=>{
        dispose_screen(screen);
    });
    function mouse_callback(event) {
        const [x1, y1] = events2unitless(screen, event);
        comm.notify({
            mouseposition: [
                x1,
                y1
            ]
        });
    }
    const notify_mouse_throttled = Bonito.throttle_function(mouse_callback, 40);
    function mousemove(event) {
        notify_mouse_throttled(event);
        return false;
    }
    canvas.addEventListener("mousemove", mousemove);
    function mousedown(event) {
        comm.notify({
            mousedown: event.buttons
        });
        return false;
    }
    canvas.addEventListener("mousedown", mousedown);
    function mouseup(event) {
        comm.notify({
            mouseup: event.buttons
        });
        return false;
    }
    canvas.addEventListener("mouseup", mouseup);
    function wheel(event) {
        comm.notify({
            scroll: [
                event.deltaX,
                -event.deltaY
            ]
        });
        event.preventDefault();
        return false;
    }
    canvas.addEventListener("wheel", wheel);
    function keydown(event) {
        event.preventDefault();
        comm.notify({
            keydown: [
                event.code,
                event.key
            ]
        });
        return false;
    }
    canvas.addEventListener("keydown", keydown);
    function keyup(event) {
        event.preventDefault();
        comm.notify({
            keyup: event.code
        });
        return false;
    }
    canvas.addEventListener("keyup", keyup);
    function contextmenu(event) {
        comm.notify({
            keyup: "delete_keys"
        });
        return false;
    }
    canvas.addEventListener("contextmenu", (e)=>e.preventDefault());
    canvas.addEventListener("focusout", contextmenu);
    if (resize_to) {
        const resize_element = get_resize_element(canvas, resize_to);
        if (resize_element) {
            function resize_callback() {
                const [element_width, element_height] = get_element_size(resize_element);
                const [f_width, f_height] = [
                    screen.renderer._width,
                    screen.renderer._height
                ];
                const [width, height] = convert_to_makie_size(element_width, element_height, f_width, f_height, resize_to, winscale);
                if (height > 0 && width > 0) {
                    comm.notify({
                        resize: [
                            width,
                            height
                        ]
                    });
                }
            }
            const resize_callback_throttled = Bonito.throttle_function(resize_callback, 100);
            const resizeObserver = new ResizeObserver((entries)=>{
                resize_callback_throttled();
            });
            resizeObserver.observe(resize_element);
            screen.resizeObserver = resizeObserver;
        } else {
            console.warn("Could not find element to observe for resize_to:", resize_to);
        }
    }
}
function threejs_module(canvas) {
    const context_options = {
        preserveDrawingBuffer: true,
        failIfMajorPerformanceCaveat: false
    };
    let context = canvas.getContext("webgl2", context_options);
    if (!context) {
        console.warn("WebGL 2.0 not supported by browser, falling back to WebGL 1.0 (Volume plots will not work)");
        context = canvas.getContext("webgl", context_options);
    }
    if (!context) {
        return;
    }
    const renderer = new mod.WebGLRenderer({
        antialias: true,
        canvas: canvas,
        context: context,
        powerPreference: "high-performance",
        precision: "highp",
        alpha: true,
        logarithmicDepthBuffer: true
    });
    renderer.debug.onShaderError = on_shader_error;
    renderer.setClearColor("#ffffff");
    return renderer;
}
function set_render_size(screen, width, height) {
    const { renderer , canvas , scalefactor , winscale , px_per_unit  } = screen;
    const [swidth, sheight] = [
        winscale * width,
        winscale * height
    ];
    const real_pixel_width = Math.ceil(width * px_per_unit);
    const real_pixel_height = Math.ceil(height * px_per_unit);
    renderer._width = width;
    renderer._height = height;
    canvas.width = real_pixel_width;
    canvas.height = real_pixel_height;
    canvas.style.width = swidth + "px";
    canvas.style.height = sheight + "px";
    renderer.setViewport(0, 0, real_pixel_width, real_pixel_height);
    add_picking_target(screen);
    return;
}
function initialize_canvas_size(canvas, resize_to, width, height, px_per_unit, scalefactor) {
    if (!scalefactor) {
        scalefactor = window.devicePixelRatio || 1.0;
    }
    if (!px_per_unit) {
        px_per_unit = scalefactor;
    }
    const pixel_ratio = window.devicePixelRatio || 1.0;
    const winscale = scalefactor / pixel_ratio;
    let initial_width = width;
    let initial_height = height;
    if (resize_to) {
        const resize_element = get_resize_element(canvas, resize_to);
        if (resize_element) {
            const [element_width, element_height] = get_element_size(resize_element);
            [initial_width, initial_height] = convert_to_makie_size(element_width, element_height, width, height, resize_to, 1.0);
        }
    }
    const swidth = winscale * initial_width;
    const sheight = winscale * initial_height;
    canvas.style.width = swidth + "px";
    canvas.style.height = sheight + "px";
    return [
        initial_width,
        initial_height
    ];
}
function setup_scene_init(wrapper, canvas, width, height, resize_to, px_per_unit, scalefactor, real_size, canvas_width, scene_serialized, comm, framerate, done_init) {
    const spinner = wrapper.querySelector('.wglmakie-spinner');
    try {
        let final_width = width;
        let final_height = height;
        if (resize_to) {
            const sizes = initialize_canvas_size(canvas, resize_to, width, height, px_per_unit, scalefactor);
            final_width = sizes[0];
            final_height = sizes[1];
        }
        real_size.notify([
            final_width,
            final_height
        ]);
        const init_scene = (scene_data)=>{
            try {
                create_scene(wrapper, canvas, canvas_width, scene_data, comm, final_width, final_height, framerate, resize_to, px_per_unit, scalefactor);
                spinner?.remove();
                requestAnimationFrame(()=>requestAnimationFrame(()=>done_init.notify(true)));
            } catch (e) {
                Bonito.Connection.send_error("error initializing scene", e);
                done_init.notify(e);
                spinner?.remove();
                return;
            }
            return false;
        };
        if (scene_serialized.value) {
            init_scene(scene_serialized.value);
        } else {
            scene_serialized.on(init_scene);
        }
    } catch (e) {
        Bonito.Connection.send_error("error setting up scene", e);
        done_init.notify(e);
        spinner?.remove();
        return;
    }
}
function add_picking_target(screen) {
    const { picking_target , canvas  } = screen;
    const [w, h] = [
        canvas.width,
        canvas.height
    ];
    if (picking_target) {
        if (picking_target.width == w && picking_target.height == h) {
            return;
        } else {
            picking_target.dispose();
        }
    }
    screen.picking_target = new mod.WebGLRenderTarget(w, h, {
        type: mod.FloatType,
        minFilter: mod.NearestFilter,
        magFilter: mod.NearestFilter
    });
    return;
}
function create_scene(wrapper, canvas, canvas_width, scenes, comm, width, height, fps, resize_to, px_per_unit, scalefactor) {
    if (!scalefactor) {
        scalefactor = window.devicePixelRatio || 1.0;
    }
    if (!px_per_unit) {
        px_per_unit = scalefactor;
    }
    const renderer = threejs_module(canvas);
    if (!renderer) {
        const warning = getWebGLErrorMessage();
        wrapper.appendChild(warning);
        return;
    }
    const camera = new mod.PerspectiveCamera(45, 1, 0, 100);
    camera.updateProjectionMatrix();
    const pixel_ratio = window.devicePixelRatio || 1.0;
    const winscale = scalefactor / pixel_ratio;
    const screen = {
        renderer,
        camera,
        fps,
        canvas,
        px_per_unit,
        scalefactor,
        winscale,
        comm,
        texture_atlas: undefined
    };
    canvas.wglmakie_screen = screen;
    add_canvas_events(screen, comm, resize_to);
    set_render_size(screen, width, height);
    const three_scene = deserialize_scene(scenes, screen);
    console.log(three_scene);
    screen.root_scene = three_scene;
    start_renderloop(three_scene);
    canvas_width.on((w_h)=>{
        set_render_size(screen, ...w_h);
        queueMicrotask(()=>{
            if (screen.root_scene) {
                render_scene(screen.root_scene);
            }
        });
    });
    const gl = renderer.getContext();
    const err = gl.getError();
    if (err != gl.NO_ERROR) {
        throw new Error("WebGL error: " + wglerror(gl, err));
    }
    return renderer;
}
function set_picking_uniforms(scene, last_id, picking, picked_plots, plots, id_to_plot) {
    scene.children.forEach((plot, index)=>{
        const { material  } = plot;
        const { uniforms  } = material;
        if (picking) {
            uniforms.object_id.value = last_id + index;
            uniforms.picking.value = true;
            material.blending = mod.NoBlending;
        } else {
            uniforms.picking.value = false;
            material.blending = mod.NormalBlending;
            const id = uniforms.object_id.value;
            if (id in picked_plots) {
                picked_plots[id].forEach((index)=>{
                    plots.push([
                        plot,
                        index
                    ]);
                });
                id_to_plot[id] = plot;
            }
        }
    });
    let next_id = last_id + scene.children.length;
    scene.scene_children.forEach((scene)=>{
        next_id = set_picking_uniforms(scene, next_id, picking, picked_plots, plots, id_to_plot);
    });
    return next_id;
}
function decode_float_to_uint(r, g) {
    const lower = Math.round(r * 65535);
    const upper = Math.round(g * 65535);
    return upper << 16 | lower;
}
function read_pixels(renderer, picking_target, x1, y1, w, h) {
    const nbytes = w * h * 4;
    const pixel_bytes = new Float32Array(nbytes);
    renderer.readRenderTargetPixels(picking_target, x1, y1, w, h, pixel_bytes);
    const result = [];
    for(let i = 0; i < pixel_bytes.length; i += 4){
        const r = pixel_bytes[i];
        const g = pixel_bytes[i + 1];
        const b = pixel_bytes[i + 2];
        const a = pixel_bytes[i + 3];
        const id = decode_float_to_uint(r, g);
        const index = decode_float_to_uint(b, a);
        result.push([
            id,
            index
        ]);
    }
    return result;
}
function pick_native(scene, _x, _y, _w, _h, apply_ppu = true) {
    const { renderer , picking_target , px_per_unit  } = scene.screen;
    if (apply_ppu) {
        [_x, _y, _w, _h] = [
            _x,
            _y,
            _w,
            _h
        ].map((x1)=>Math.round(x1 * px_per_unit));
    }
    const [x1, y1, w, h] = [
        _x,
        _y,
        _w,
        _h
    ];
    renderer.setRenderTarget(picking_target);
    set_picking_uniforms(scene, 1, true);
    const rendered = render_scene(scene, true);
    if (!rendered) {
        return;
    }
    renderer.setRenderTarget(null);
    const picked_plots_array = read_pixels(renderer, picking_target, x1, y1, w, h);
    const picked_plots = {};
    picked_plots_array.forEach(([id, index])=>{
        if (!picked_plots[id]) {
            picked_plots[id] = [];
        }
        if (!picked_plots[id].includes(index)) {
            picked_plots[id].push(index);
        }
    });
    const plots = [];
    const id_to_plot = {};
    set_picking_uniforms(scene, 0, false, picked_plots, plots, id_to_plot);
    const picked_plots_matrix = picked_plots_array.map(([id, index])=>{
        const p = id_to_plot[id];
        return [
            p ? p.plot_uuid : null,
            index
        ];
    });
    const plot_matrix = {
        data: picked_plots_matrix,
        size: [
            w,
            h
        ]
    };
    return [
        plot_matrix,
        plots
    ];
}
function get_picking_buffer(scene) {
    const { renderer , picking_target  } = scene.screen;
    const [w, h] = [
        picking_target.width,
        picking_target.height
    ];
    renderer.setRenderTarget(picking_target);
    set_picking_uniforms(scene, 1, true);
    const rendered = render_scene(scene, true);
    if (!rendered) {
        return;
    }
    renderer.setRenderTarget(null);
    const picked_plots_array = read_pixels(renderer, picking_target, x, y, w, h);
    return {
        picked_plots_array,
        w,
        h
    };
}
function pick_closest(scene, xy, range) {
    const { canvas , px_per_unit , renderer  } = scene.screen;
    const [width, height] = [
        renderer._width,
        renderer._height
    ];
    if (!(1.0 <= xy[0] <= width && 1.0 <= xy[1] <= height)) {
        return [
            null,
            0
        ];
    }
    const x0 = Math.max(1, Math.floor(px_per_unit * (xy[0] - range)));
    const y0 = Math.max(1, Math.floor(px_per_unit * (xy[1] - range)));
    const x1 = Math.min(canvas.width, Math.ceil(px_per_unit * (xy[0] + range)));
    const y1 = Math.min(canvas.height, Math.ceil(px_per_unit * (xy[1] + range)));
    const dx = x1 - x0;
    const dy = y1 - y0;
    const [plot_data, _] = pick_native(scene, x0, y0, dx, dy, false);
    const plot_matrix = plot_data.data;
    let min_dist = px_per_unit * px_per_unit * range * range;
    let selection = [
        null,
        0
    ];
    const x2 = xy[0] * px_per_unit + 1 - x0;
    const y2 = xy[1] * px_per_unit + 1 - y0;
    let pindex = 0;
    for(let i = 1; i <= dx; i++){
        for(let j = 1; j <= dy; j++){
            const d = Math.pow(x2 - i, 2) + Math.pow(y2 - j, 2);
            const [plot_uuid, index] = plot_matrix[pindex];
            pindex = pindex + 1;
            if (d < min_dist && plot_uuid) {
                min_dist = d;
                selection = [
                    plot_uuid,
                    index
                ];
            }
        }
    }
    return selection;
}
function pick_sorted(scene, xy, range) {
    const { canvas , px_per_unit , renderer  } = scene.screen;
    const [width, height] = [
        renderer._width,
        renderer._height
    ];
    if (!(1.0 <= xy[0] <= width && 1.0 <= xy[1] <= height)) {
        return null;
    }
    const x0 = Math.max(1, Math.floor(px_per_unit * (xy[0] - range)));
    const y0 = Math.max(1, Math.floor(px_per_unit * (xy[1] - range)));
    const x1 = Math.min(canvas.width, Math.ceil(px_per_unit * (xy[0] + range)));
    const y1 = Math.min(canvas.height, Math.ceil(px_per_unit * (xy[1] + range)));
    const dx = x1 - x0;
    const dy = y1 - y0;
    const picked = pick_native(scene, x0, y0, dx, dy, false);
    if (!picked) {
        return null;
    }
    const [plot_data, selected] = picked;
    if (selected.length == 0) {
        return null;
    }
    const plot_matrix = plot_data.data;
    const distances = selected.map((x1)=>1e30);
    const x2 = xy[0] * px_per_unit + 1 - x0;
    const y2 = xy[1] * px_per_unit + 1 - y0;
    let pindex = 0;
    for(let i = 1; i <= dx; i++){
        for(let j = 1; j <= dy; j++){
            const d = Math.pow(x2 - i, 2) + Math.pow(y2 - j, 2);
            const [plot_uuid, index] = plot_matrix[pindex];
            pindex = pindex + 1;
            const plot_index = selected.findIndex((x1)=>x1[0].plot_uuid == plot_uuid && x1[1] == index);
            if (plot_index >= 0 && d < distances[plot_index]) {
                distances[plot_index] = d;
            }
        }
    }
    const sorted_indices = Array.from(Array(distances.length).keys()).sort((a, b)=>distances[a] < distances[b] ? -1 : distances[b] < distances[a] | 0);
    return sorted_indices.map((idx)=>{
        const [plot, index] = selected[idx];
        return [
            plot.plot_uuid,
            index
        ];
    });
}
function pick_native_uuid(scene, x1, y1, w, h) {
    const picked = pick_native(scene, x1, y1, w, h);
    if (!picked) {
        return [];
    }
    const [_, picked_plots] = picked;
    return picked_plots.map(([p, index])=>[
            p.plot_uuid,
            index
        ]);
}
function pick_native_matrix(scene, x1, y1, w, h) {
    const picked = pick_native(scene, x1, y1, w, h);
    if (!picked) {
        return {
            data: [],
            size: [
                0,
                0
            ]
        };
    }
    return picked[0];
}
function register_popup(popup, scene, plots_to_pick, callback) {
    if (!scene || !scene.screen) {
        return;
    }
    const { canvas  } = scene.screen;
    canvas.addEventListener("mousedown", (event)=>{
        const [x1, y1] = events2unitless(scene.screen, event);
        const picked = pick_native(scene, x1, y1, 1, 1);
        if (!picked) {
            return;
        }
        const [_, picks] = picked;
        if (picks.length == 1) {
            const [plot, index] = picks[0];
            if (plots_to_pick.has(plot.plot_uuid)) {
                const result = callback(plot, index);
                if (!popup.classList.contains("show")) {
                    popup.classList.add("show");
                }
                popup.style.left = event.pageX + "px";
                popup.style.top = event.pageY + "px";
                if (typeof result === "string" || result instanceof String) {
                    popup.innerText = result;
                } else {
                    popup.innerHTML = result;
                }
            }
        } else {
            popup.classList.remove("show");
        }
    });
    canvas.addEventListener("keyup", (event)=>{
        if (event.key === "Escape") {
            popup.classList.remove("show");
        }
    });
}
window.WGL = {
    deserialize_scene,
    threejs_module,
    start_renderloop,
    delete_plots,
    insert_plot,
    find_plots,
    delete_scene,
    find_scene,
    scene_cache,
    plot_cache,
    dispose_screen,
    delete_scenes,
    create_scene,
    events2unitless,
    on_next_insert,
    register_popup,
    render_scene,
    get_texture_atlas,
    get_parent_size,
    get_element_size,
    get_resize_element,
    convert_to_makie_size,
    initialize_canvas_size,
    setup_scene_init,
    execute_in_order
};
export { deserialize_scene as deserialize_scene, threejs_module as threejs_module, start_renderloop as start_renderloop, delete_plots as delete_plots, insert_plot as insert_plot, find_plots as find_plots, delete_scene as delete_scene, find_scene as find_scene, scene_cache as scene_cache, plot_cache as plot_cache, delete_scenes as delete_scenes, create_scene as create_scene, events2unitless as events2unitless, on_next_insert as on_next_insert, get_texture_atlas as get_texture_atlas, get_parent_size as get_parent_size, get_element_size as get_element_size, get_resize_element as get_resize_element, convert_to_makie_size as convert_to_makie_size };
export { execute_in_order as execute_in_order };
export { dispose_screen as dispose_screen };
export { render_scene as render_scene };
export { wglerror as wglerror };
export { initialize_canvas_size as initialize_canvas_size };
export { setup_scene_init as setup_scene_init };
export { pick_native as pick_native };
export { get_picking_buffer as get_picking_buffer };
export { pick_closest as pick_closest };
export { pick_sorted as pick_sorted };
export { pick_native_uuid as pick_native_uuid };
export { pick_native_matrix as pick_native_matrix };
export { register_popup as register_popup };

