123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
import { cY as Z, cZ as tt, c_ as et, bQ as j, ag as nt, cH as st, H as ot, cW as rt, a3 as at, az as N, V as G, F as it, c$ as ct, c0 as lt } from "./chunk-CrnJfeNw.js";
import { S as $ } from "./chunk-DfdFCrVY.js";
const ht = 32768, H = 0.28209479177387814;
let Q = null, Y = null;
function ft(s, i, h) {
  const e = new Uint8Array(s), w = new Uint32Array(s.slice(0, 12)), r = w[2], p = e[12], d = e[13], g = e[14], M = e[15], C = w[1];
  if (M || w[0] != 1347635022 || C < 2 || C > 4)
    return new Promise((t) => {
      t({ mode: 3, data: new ArrayBuffer(0), hasVertexColors: !1 });
    });
  const O = 3 * 4 + 3 * 4 + 4 + 4, A = new ArrayBuffer(O * r), l = 1 / (1 << d), a = new Int32Array(1), c = new Uint8Array(a.buffer), v = function(t, o) {
    return c[0] = t[o + 0], c[1] = t[o + 1], c[2] = t[o + 2], c[3] = t[o + 2] & 128 ? 255 : 0, a[0] * l;
  };
  let n = 16;
  const b = new Float32Array(A), u = new Float32Array(A), I = new Uint8ClampedArray(A), x = new Uint8ClampedArray(A);
  for (let t = 0; t < r; t++)
    b[t * 8 + 0] = v(e, n + 0), b[t * 8 + 1] = v(e, n + 3), b[t * 8 + 2] = v(e, n + 6), n += 9;
  for (let t = 0; t < r; t++) {
    for (let o = 0; o < 3; o++) {
      const _ = (e[n + r + t * 3 + o] - 127.5) / (0.15 * 255);
      I[t * 32 + 24 + o] = j.Clamp((0.5 + H * _) * 255, 0, 255);
    }
    I[t * 32 + 24 + 3] = e[n + t];
  }
  n += r * 4;
  for (let t = 0; t < r; t++)
    u[t * 8 + 3 + 0] = Math.exp(e[n + 0] / 16 - 10), u[t * 8 + 3 + 1] = Math.exp(e[n + 1] / 16 - 10), u[t * 8 + 3 + 2] = Math.exp(e[n + 2] / 16 - 10), n += 3;
  if (C >= 3) {
    const t = Math.SQRT1_2;
    for (let o = 0; o < r; o++) {
      const f = [e[n + 0], e[n + 1], e[n + 2], e[n + 3]], _ = f[0] + (f[1] << 8) + (f[2] << 16) + (f[3] << 24), E = 511, y = [], m = _ >>> 30;
      let U = _, V = 0;
      for (let S = 3; S >= 0; --S)
        if (S !== m) {
          const P = U & E, R = U >>> 9 & 1;
          U = U >>> 10, y[S] = t * (P / E), R === 1 && (y[S] = -y[S]), V += y[S] * y[S];
        }
      const k = 1 - V;
      y[m] = Math.sqrt(Math.max(k, 0));
      const z = [3, 0, 1, 2];
      for (let S = 0; S < 4; S++)
        x[o * 32 + 28 + S] = Math.round(127.5 + y[z[S]] * 127.5);
      n += 4;
    }
  } else
    for (let t = 0; t < r; t++) {
      const o = e[n + 0], f = e[n + 1], _ = e[n + 2], E = o / 127.5 - 1, y = f / 127.5 - 1, m = _ / 127.5 - 1;
      x[t * 32 + 28 + 1] = o, x[t * 32 + 28 + 2] = f, x[t * 32 + 28 + 3] = _;
      const U = 1 - (E * E + y * y + m * m);
      x[t * 32 + 28 + 0] = 127.5 + Math.sqrt(U < 0 ? 0 : U) * 127.5, n += 3;
    }
  if (p) {
    const o = ((p + 1) * (p + 1) - 1) * 3, f = Math.ceil(o / 16);
    let _ = n;
    const E = [], m = i.getEngine().getCaps().maxTextureSize, U = Math.ceil(r / m);
    for (let V = 0; V < f; V++) {
      const k = new Uint8Array(U * m * 4 * 4);
      E.push(k);
    }
    for (let V = 0; V < r; V++)
      for (let k = 0; k < o; k++) {
        const z = e[_++], S = Math.floor(k / 16), P = E[S], R = k % 16, B = V * 16;
        P[R + B] = z;
      }
    return new Promise((V) => {
      V({ mode: 0, data: A, hasVertexColors: !1, sh: E, shDegree: p, trainedWithAntialiasing: !!g });
    });
  }
  return new Promise((t) => {
    t({ mode: 0, data: A, hasVertexColors: !1, trainedWithAntialiasing: !!g });
  });
}
async function ut(s) {
  if (Q && Y === s)
    return await Q;
  const i = Z(`import createSpzModule from '${s}';
         const module = await createSpzModule();
         const returnedValue = module;`);
  return Y = s, Q = i, await i;
}
function* pt(s, i, h = !1) {
  const e = s.numPoints, w = 3 * 4 + 3 * 4 + 4 + 4, r = new ArrayBuffer(w * e), p = new Float32Array(r), d = new Uint8Array(r), g = s.positions, M = s.scales, C = s.colors, O = s.alphas, A = s.rotations;
  let l = null;
  const a = s.shDegree;
  let c = null, v = 0, n = null, b = null, u = null;
  if (a > 0 && s.sh.length > 0) {
    v = ((a + 1) * (a + 1) - 1) * 3;
    const o = Math.ceil(v / 16), _ = i.getEngine().getCaps().maxTextureSize, E = Math.ceil(e / _);
    l = [];
    for (let y = 0; y < o; y++)
      l.push(new Uint8Array(E * _ * 4 * 4));
    n = new Int32Array(o), b = new Int32Array(o);
    for (let y = 0; y < o; y++)
      n[y] = y * 16, b[y] = Math.min((y + 1) * 16, v);
    u = l, c = s.sh;
  }
  for (let t = 0; t < e; t++) {
    const o = t * 8, f = t * 32, _ = t * 3, E = t * 4;
    p[o + 0] = g[_ + 0], p[o + 1] = g[_ + 1], p[o + 2] = g[_ + 2], p[o + 3] = Math.exp(M[_ + 0]), p[o + 4] = Math.exp(M[_ + 1]), p[o + 5] = Math.exp(M[_ + 2]);
    const y = (0.5 + H * C[_ + 0]) * 255, m = (0.5 + H * C[_ + 1]) * 255, U = (0.5 + H * C[_ + 2]) * 255;
    d[f + 24] = y <= 0 ? 0 : y >= 255 ? 255 : y + 0.5 | 0, d[f + 25] = m <= 0 ? 0 : m >= 255 ? 255 : m + 0.5 | 0, d[f + 26] = U <= 0 ? 0 : U >= 255 ? 255 : U + 0.5 | 0, d[f + 27] = 1 / (1 + Math.exp(-O[t])) * 255 + 0.5 | 0;
    const V = A[E + 3] * 127.5 + 127.5, k = A[E + 0] * 127.5 + 127.5, z = A[E + 1] * 127.5 + 127.5, S = A[E + 2] * 127.5 + 127.5;
    if (d[f + 28] = V <= 0 ? 0 : V >= 255 ? 255 : V + 0.5 | 0, d[f + 29] = k <= 0 ? 0 : k >= 255 ? 255 : k + 0.5 | 0, d[f + 30] = z <= 0 ? 0 : z >= 255 ? 255 : z + 0.5 | 0, d[f + 31] = S <= 0 ? 0 : S >= 255 ? 255 : S + 0.5 | 0, c && u && n && b) {
      const P = t * v, R = t * 16;
      for (let B = 0; B < u.length; B++) {
        const T = u[B], L = n[B], W = b[B];
        for (let D = L; D < W; D++) {
          const q = c[P + D] * 128 + 128;
          T[R + D - L] = q <= 0 ? 0 : q >= 255 ? 255 : q + 0.5 | 0;
        }
      }
    }
    t % ht === 0 && h && (yield);
  }
  let I, x;
  if (s.extensions)
    for (const t of s.extensions) {
      const o = t;
      if (o.safeOrbitRadiusMin !== void 0) {
        I = o.safeOrbitRadiusMin, x = [o.safeOrbitElevationMin, o.safeOrbitElevationMax];
        break;
      }
    }
  return {
    mode: 0,
    data: r,
    hasVertexColors: !1,
    sh: l !== null ? l : void 0,
    shDegree: a > 0 ? a : void 0,
    trainedWithAntialiasing: !!s.antialiased,
    safeOrbitCameraRadiusMin: I,
    safeOrbitCameraElevationMinMax: x
  };
}
async function dt(s, i) {
  return await tt(pt(s, i, !0), et());
}
const J = 0.28209479177387814;
async function X(s, i, h) {
  return await new Promise((w, r) => {
    const p = h.createCanvasImage();
    if (!p)
      throw new Error("Failed to create ImageBitmap");
    p.onload = () => {
      try {
        const g = h.createCanvas(p.width, p.height);
        if (!g)
          throw new Error("Failed to create canvas");
        const M = g.getContext("2d");
        if (!M)
          throw new Error("Failed to get 2D context");
        M.drawImage(p, 0, 0);
        const C = M.getImageData(0, 0, g.width, g.height);
        w({ bits: new Uint8Array(C.data.buffer), width: C.width });
      } catch (g) {
        r(`Error loading image ${p.src} with exception: ${g}`);
      }
    }, p.onerror = (g) => {
      r(`Error loading image ${p.src} with exception: ${g}`);
    }, p.crossOrigin = "anonymous";
    let d;
    if (typeof s == "string") {
      if (!i)
        throw new Error("filename is required when using a URL");
      p.src = s + i;
    } else {
      const g = new Blob([s], { type: "image/webp" });
      d = URL.createObjectURL(g), p.src = d;
    }
  });
}
async function mt(s, i, h) {
  const e = s.count ? s.count : s.means.shape[0], w = 3 * 4 + 3 * 4 + 4 + 4, r = new ArrayBuffer(w * e), p = new Float32Array(r), d = new Float32Array(r), g = new Uint8ClampedArray(r), M = new Uint8ClampedArray(r), C = (n) => Math.sign(n) * (Math.exp(Math.abs(n)) - 1), O = i[0].bits, A = i[1].bits;
  if (!Array.isArray(s.means.mins) || !Array.isArray(s.means.maxs))
    throw new Error("Missing arrays in SOG data.");
  for (let n = 0; n < e; n++) {
    const b = n * 4;
    for (let u = 0; u < 3; u++) {
      const I = s.means.mins[u], x = s.means.maxs[u], t = A[b + u], o = O[b + u], f = t << 8 | o, _ = j.Lerp(I, x, f / 65535);
      p[n * 8 + u] = C(_);
    }
  }
  const l = i[2].bits;
  if (s.version === 2) {
    if (!s.scales.codebook)
      throw new Error("Missing codebook in SOG version 2 scales data.");
    for (let n = 0; n < e; n++) {
      const b = n * 4;
      for (let u = 0; u < 3; u++) {
        const I = s.scales.codebook[l[b + u]], x = Math.exp(I);
        d[n * 8 + 3 + u] = x;
      }
    }
  } else {
    if (!Array.isArray(s.scales.mins) || !Array.isArray(s.scales.maxs))
      throw new Error("Missing arrays in SOG scales data.");
    for (let n = 0; n < e; n++) {
      const b = n * 4;
      for (let u = 0; u < 3; u++) {
        const I = l[b + u], x = j.Lerp(s.scales.mins[u], s.scales.maxs[u], I / 255), t = Math.exp(x);
        d[n * 8 + 3 + u] = t;
      }
    }
  }
  const a = i[4].bits;
  if (s.version === 2) {
    if (!s.sh0.codebook)
      throw new Error("Missing codebook in SOG version 2 sh0 data.");
    for (let n = 0; n < e; n++) {
      const b = n * 4;
      for (let u = 0; u < 3; u++) {
        const I = 0.5 + s.sh0.codebook[a[b + u]] * J;
        g[n * 32 + 24 + u] = Math.max(0, Math.min(255, Math.round(255 * I)));
      }
      g[n * 32 + 24 + 3] = a[b + 3];
    }
  } else {
    if (!Array.isArray(s.sh0.mins) || !Array.isArray(s.sh0.maxs))
      throw new Error("Missing arrays in SOG sh0 data.");
    for (let n = 0; n < e; n++) {
      const b = n * 4;
      for (let u = 0; u < 4; u++) {
        const I = s.sh0.mins[u], x = s.sh0.maxs[u], t = a[b + u], o = j.Lerp(I, x, t / 255);
        let f;
        u < 3 ? f = 0.5 + o * J : f = 1 / (1 + Math.exp(-o)), g[n * 32 + 24 + u] = Math.max(0, Math.min(255, Math.round(255 * f)));
      }
    }
  }
  const c = (n) => (n / 255 - 0.5) * 2 / Math.SQRT2, v = i[3].bits;
  for (let n = 0; n < e; n++) {
    const b = v[n * 4 + 0], u = v[n * 4 + 1], I = v[n * 4 + 2], x = v[n * 4 + 3], t = c(b), o = c(u), f = c(I), _ = x - 252, E = t * t + o * o + f * f, y = Math.sqrt(Math.max(0, 1 - E));
    let m;
    switch (_) {
      case 0:
        m = [y, t, o, f];
        break;
      case 1:
        m = [t, y, o, f];
        break;
      case 2:
        m = [t, o, y, f];
        break;
      case 3:
        m = [t, o, f, y];
        break;
      default:
        throw new Error("Invalid quaternion mode");
    }
    M[n * 32 + 28 + 0] = m[0] * 127.5 + 127.5, M[n * 32 + 28 + 1] = m[1] * 127.5 + 127.5, M[n * 32 + 28 + 2] = m[2] * 127.5 + 127.5, M[n * 32 + 28 + 3] = m[3] * 127.5 + 127.5;
  }
  if (s.shN) {
    const n = s.shN.bands ? (s.shN.bands + 1) ** 2 - 1 : s.shN.shape[1] / 3, b = s.shN.bands !== void 0 && s.shN.bands !== null ? s.shN.bands : Math.round(Math.sqrt(n + 1) - 1), u = i[5].bits, I = i[6].bits, x = i[5].width, t = n * 3, o = Math.ceil(t / 16), f = [], E = h.getEngine().getCaps().maxTextureSize, y = Math.ceil(e / E);
    for (let m = 0; m < o; m++) {
      const U = new Uint8Array(y * E * 4 * 4);
      f.push(U);
    }
    if (s.version === 2) {
      if (!s.shN.codebook)
        throw new Error("Missing codebook in SOG version 2 shN data.");
      for (let m = 0; m < e; m++) {
        const U = I[m * 4 + 0] + (I[m * 4 + 1] << 8), V = U % 64 * n, k = Math.floor(U / 64);
        for (let z = 0; z < n; z++)
          for (let S = 0; S < 3; S++) {
            const P = z * 3 + S, R = Math.floor(P / 16), B = f[R], T = P % 16, L = m * 16, W = s.shN.codebook[u[(V + z) * 4 + S + k * x * 4]] * 127.5 + 127.5;
            B[T + L] = Math.max(0, Math.min(255, W));
          }
      }
    } else
      for (let m = 0; m < e; m++) {
        const U = I[m * 4 + 0] + (I[m * 4 + 1] << 8), V = U % 64 * n, k = Math.floor(U / 64), z = s.shN.mins, S = s.shN.maxs;
        for (let P = 0; P < 3; P++)
          for (let R = 0; R < n / 3; R++) {
            const B = R * 3 + P, T = Math.floor(B / 16), L = f[T], W = B % 16, D = m * 16, q = j.Lerp(z, S, u[(V + R) * 4 + P + k * x * 4] / 255) * 127.5 + 127.5;
            L[W + D] = Math.max(0, Math.min(255, q));
          }
      }
    return await new Promise((m) => {
      m({ mode: 0, data: r, hasVertexColors: !1, sh: f, shDegree: b });
    });
  }
  return await new Promise((n) => {
    n({ mode: 0, data: r, hasVertexColors: !1 });
  });
}
async function K(s, i, h) {
  let e, w;
  if (s instanceof Map) {
    w = s;
    const d = w.get("meta.json");
    if (!d)
      throw new Error("meta.json not found in files Map");
    e = JSON.parse(new TextDecoder().decode(d));
  } else
    e = s;
  const r = [...e.means.files, ...e.scales.files, ...e.quats.files, ...e.sh0.files];
  e.shN && r.push(...e.shN.files);
  const p = await Promise.all(r.map(async (d) => {
    if (w && w.has(d)) {
      const g = w.get(d);
      return await X(g, d, h.getEngine());
    } else
      return await X(i, d, h.getEngine());
  }));
  return await mt(e, p, h);
}
class F {
  /**
   * Creates loader for gaussian splatting files
   * @param loadingOptions options for loading and parsing splat and PLY files.
   */
  constructor(i = F._DefaultLoadingOptions) {
    this.name = $.name, this._assetContainer = null, this.extensions = $.extensions, this._loadingOptions = i;
  }
  /** @internal */
  createPlugin(i) {
    return new F(i[$.name]);
  }
  /**
   * Imports  from the loaded gaussian splatting data and adds them to the scene
   * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
   * @param scene the scene the meshes should be added to
   * @param data the gaussian splatting data to load
   * @param rootUrl root url to load from
   * @param _onProgress callback called while file is loading
   * @param _fileName Defines the name of the file to load
   * @returns a promise containing the loaded meshes, particles, skeletons and animations
   */
  async importMeshAsync(i, h, e, w, r, p) {
    return await this._parseAsync(i, h, e, w).then((d) => ({
      meshes: d,
      particleSystems: [],
      skeletons: [],
      animationGroups: [],
      transformNodes: [],
      geometries: [],
      lights: [],
      spriteManagers: []
    }));
  }
  static _BuildPointCloud(i, h) {
    if (!h.byteLength)
      return !1;
    const e = new Uint8Array(h), w = new Float32Array(h), r = 3 * 4 + 3 * 4 + 4 + 4, p = e.length / r, d = function(g, M) {
      const C = w[8 * M + 0], O = w[8 * M + 1], A = w[8 * M + 2];
      g.position = new G(C, O, A);
      const l = e[r * M + 24 + 0] / 255, a = e[r * M + 24 + 1] / 255, c = e[r * M + 24 + 2] / 255;
      g.color = new it(l, a, c, 1);
    };
    return i.addPoints(p, d), !0;
  }
  static _BuildMesh(i, h) {
    const e = new nt("PLYMesh", i), w = new Uint8Array(h.data), r = new Float32Array(h.data), p = 3 * 4 + 3 * 4 + 4 + 4, d = w.length / p, g = [], M = new st();
    for (let C = 0; C < d; C++) {
      const O = r[8 * C + 0], A = r[8 * C + 1], l = r[8 * C + 2];
      g.push(O, A, l);
    }
    if (h.hasVertexColors) {
      const C = new Float32Array(d * 4);
      for (let O = 0; O < d; O++) {
        const A = w[p * O + 24 + 0] / 255, l = w[p * O + 24 + 1] / 255, a = w[p * O + 24 + 2] / 255;
        C[O * 4 + 0] = A, C[O * 4 + 1] = l, C[O * 4 + 2] = a, C[O * 4 + 3] = 1;
      }
      M.colors = C;
    }
    return M.positions = g, M.indices = h.faces, M.applyToMesh(e), e;
  }
  // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax, @typescript-eslint/naming-convention
  async _unzipWithFFlateAsync(i) {
    let h = this._loadingOptions.fflate;
    h || (typeof window.fflate > "u" && await ot.LoadScriptAsync(this._loadingOptions.deflateURL ?? "https://unpkg.com/fflate/umd/index.js"), h = window.fflate);
    const { unzipSync: e } = h, w = e(i), r = /* @__PURE__ */ new Map();
    for (const [p, d] of Object.entries(w))
      r.set(p, d);
    return r;
  }
  // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
  _parseAsync(i, h, e, w) {
    const r = [], p = (l) => {
      h._blockEntityCollection = !!this._assetContainer;
      const a = this._loadingOptions.gaussianSplattingMesh ?? new N("GaussianSplatting", null, h, this._loadingOptions.keepInRam, this._loadingOptions.needsRotationScaleTextures);
      a._parentContainer = this._assetContainer, r.push(a), a.updateData(l.data, l.sh, { flipY: !1 }, void 0, l.shDegree), a.scaling.y *= -1, a.computeWorldMatrix(!0), h._blockEntityCollection = !1;
    };
    if (typeof e == "string") {
      const l = JSON.parse(e);
      if (l && l.means && l.scales && l.quats && l.sh0)
        return new Promise((a) => {
          K(l, w, h).then((c) => {
            p(c), a(r);
          }).catch(() => {
            throw new Error("Failed to parse SOG data.");
          });
        });
    }
    const d = e instanceof ArrayBuffer ? new Uint8Array(e) : e;
    if (d[0] === 80 && d[1] === 75)
      return new Promise((l) => {
        this._unzipWithFFlateAsync(d).then((a) => {
          K(a, w, h).then((c) => {
            p(c), l(r);
          }).catch(() => {
            throw new Error("Failed to parse SOG zip data.");
          });
        });
      });
    const g = (l) => {
      F._ConvertPLYToSplat(e).then(async (a) => {
        switch (h._blockEntityCollection = !!this._assetContainer, a.mode) {
          case 0:
            {
              const c = this._loadingOptions.gaussianSplattingMesh ?? new N("GaussianSplatting", null, h, this._loadingOptions.keepInRam, this._loadingOptions.needsRotationScaleTextures);
              switch (c._parentContainer = this._assetContainer, r.push(c), c.updateData(a.data, a.sh, { flipY: !1 }, void 0, a.shDegree), c.scaling.y *= -1, a.chirality === "RightHanded" && (c.scaling.y *= -1), a.upAxis) {
                case "X":
                  c.rotation = new G(0, 0, Math.PI / 2);
                  break;
                case "Y":
                  c.rotation = new G(0, 0, Math.PI);
                  break;
                case "Z":
                  c.rotation = new G(-Math.PI / 2, Math.PI, 0);
                  break;
              }
              c.computeWorldMatrix(!0);
            }
            break;
          case 1:
            {
              const c = new ct("PointCloud", 1, h);
              F._BuildPointCloud(c, a.data) ? await c.buildMeshAsync().then((v) => {
                r.push(v);
              }) : c.dispose();
            }
            break;
          case 2:
            if (a.faces)
              r.push(F._BuildMesh(h, a));
            else
              throw new Error("PLY mesh doesn't contain face informations.");
            break;
          default:
            throw new Error("Unsupported Splat mode");
        }
        h._blockEntityCollection = !1, this.applyAutoCameraLimits(a, h), l(r);
      });
    };
    if (d[0] !== 31 || d[1] !== 139)
      return new Promise((l) => {
        g(l);
      });
    const M = (l, a) => {
      h._blockEntityCollection = !!this._assetContainer;
      const c = this._loadingOptions.gaussianSplattingMesh ?? new N("GaussianSplatting", null, h, this._loadingOptions.keepInRam, this._loadingOptions.needsRotationScaleTextures);
      if (l.trainedWithAntialiasing) {
        const v = c.material;
        v.kernelSize = 0.1, v.compensation = !0;
      }
      c._parentContainer = this._assetContainer, r.push(c), c.updateData(l.data, l.sh, { flipY: !1 }, void 0, l.shDegree), this._loadingOptions.flipY || (c.scaling.y *= -1, c.computeWorldMatrix(!0)), h._blockEntityCollection = !1, this.applyAutoCameraLimits(l, h), a(r);
    };
    if (this._loadingOptions.spzLibraryUrl)
      return ut(this._loadingOptions.spzLibraryUrl).then((l) => {
        const a = l.loadSpzFromBuffer(new Uint8Array(e), { to: l.CoordinateSystem.RUB });
        return dt(a, h).then((c) => new Promise((v) => {
          M(c, v);
        }));
      });
    const C = new ReadableStream({
      start(l) {
        l.enqueue(new Uint8Array(e)), l.close();
      }
    }), O = new DecompressionStream("gzip"), A = C.pipeThrough(O);
    return new Promise((l) => {
      new Response(A).arrayBuffer().then((a) => {
        ft(a, h, this._loadingOptions).then((c) => {
          M(c, l);
        });
      }).catch(() => {
        g(l);
      });
    });
  }
  /**
   * Applies camera limits based on parsed meta data
   * @param meta parsed splat meta data
   * @param scene
   */
  applyAutoCameraLimits(i, h) {
    if (!this._loadingOptions.disableAutoCameraLimits && (i.safeOrbitCameraRadiusMin !== void 0 || i.safeOrbitCameraElevationMinMax !== void 0) && h.activeCamera?.getClassName() === "ArcRotateCamera") {
      const e = h.activeCamera;
      i.safeOrbitCameraElevationMinMax && (e.lowerBetaLimit = Math.PI * 0.5 - i.safeOrbitCameraElevationMinMax[1], e.upperBetaLimit = Math.PI * 0.5 - i.safeOrbitCameraElevationMinMax[0]), i.safeOrbitCameraRadiusMin && (e.lowerRadiusLimit = i.safeOrbitCameraRadiusMin);
    }
  }
  /**
   * Load into an asset container.
   * @param scene The scene to load into
   * @param data The data to import
   * @param rootUrl The root url for scene and resources
   * @returns The loaded asset container
   */
  // eslint-disable-next-line no-restricted-syntax
  loadAssetContainerAsync(i, h, e) {
    const w = new rt(i);
    return this._assetContainer = w, this.importMeshAsync(null, i, h, e).then((r) => {
      for (const p of r.meshes)
        w.meshes.push(p);
      return this._assetContainer = null, w;
    }).catch((r) => {
      throw this._assetContainer = null, r;
    });
  }
  /**
   * Imports all objects from the loaded OBJ data and adds them to the scene
   * @param scene the scene the objects should be added to
   * @param data the OBJ data to load
   * @param rootUrl root url to load from
   * @returns a promise which completes when objects have been loaded to the scene
   */
  // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
  loadAsync(i, h, e) {
    return this.importMeshAsync(null, i, h, e).then(() => {
    });
  }
  /**
   * Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license
   * Converts a .ply data array buffer to splat
   * if data array buffer is not ply, returns the original buffer
   * @param data the .ply data to load
   * @returns the loaded splat buffer
   */
  static _ConvertPLYToSplat(i) {
    const h = new Uint8Array(i), e = new TextDecoder().decode(h.slice(0, 1024 * 10)), w = `end_header
`, r = e.indexOf(w);
    if (r < 0 || !e)
      return new Promise((x) => {
        x({ mode: 0, data: i, rawSplat: !0 });
      });
    const p = parseInt(/element vertex (\d+)\n/.exec(e)[1]), d = /element face (\d+)\n/.exec(e);
    let g = 0;
    d && (g = parseInt(d[1]));
    const M = /element chunk (\d+)\n/.exec(e);
    let C = 0;
    M && (C = parseInt(M[1]));
    let O = 0, A = 0;
    const l = {
      double: 8,
      int: 4,
      uint: 4,
      float: 4,
      short: 2,
      ushort: 2,
      uchar: 1,
      list: 0
    }, a = {
      Vertex: 0,
      Chunk: 1,
      SH: 2,
      Float_Tuple: 3,
      Float: 4,
      Uchar: 5
    };
    let c = a.Chunk;
    const v = [], n = e.slice(0, r).split(`
`), b = {};
    for (const x of n)
      if (x.startsWith("property ")) {
        const [, t, o] = x.split(" ");
        if (c == a.Chunk)
          A += l[t];
        else if (c == a.Vertex)
          v.push({ name: o, type: t, offset: O }), O += l[t];
        else if (c == a.SH)
          v.push({ name: o, type: t, offset: O });
        else if (c == a.Float_Tuple) {
          const f = new DataView(i, A, l.float * 2);
          b.safeOrbitCameraElevationMinMax = [f.getFloat32(0, !0), f.getFloat32(4, !0)];
        } else if (c == a.Float) {
          const f = new DataView(i, A, l.float);
          b.safeOrbitCameraRadiusMin = f.getFloat32(0, !0);
        } else if (c == a.Uchar) {
          const f = new DataView(i, A, l.uchar);
          o == "up_axis" ? b.upAxis = f.getUint8(0) == 0 ? "X" : f.getUint8(0) == 1 ? "Y" : "Z" : o == "chirality" && (b.chirality = f.getUint8(0) == 0 ? "LeftHanded" : "RightHanded");
        }
        l[t] || at.Warn(`Unsupported property type: ${t}.`);
      } else if (x.startsWith("element ")) {
        const [, t] = x.split(" ");
        t == "chunk" ? c = a.Chunk : t == "vertex" ? c = a.Vertex : t == "sh" ? c = a.SH : t == "safe_orbit_camera_elevation_min_max_radians" ? c = a.Float_Tuple : t == "safe_orbit_camera_radius_min" ? c = a.Float : (t == "up_axis" || t == "chirality") && (c = a.Uchar);
      }
    const u = O, I = A;
    return N.ConvertPLYWithSHToSplatAsync(i).then(async (x) => {
      const t = new DataView(i, r + w.length);
      let o = I * C + u * p;
      const f = [];
      if (g)
        for (let k = 0; k < g; k++) {
          const z = t.getUint8(o);
          if (z == 3) {
            o += 1;
            for (let S = 0; S < z; S++) {
              const P = t.getUint32(o + (2 - S) * 4, !0);
              f.push(P);
            }
            o += 12;
          }
        }
      if (C)
        return await new Promise((k) => {
          k({
            mode: 0,
            data: x.buffer,
            sh: x.sh,
            shDegree: x.shDegree,
            faces: f,
            hasVertexColors: !1,
            compressed: !0,
            rawSplat: !1
          });
        });
      let _ = 0, E = 0;
      const y = ["x", "y", "z", "scale_0", "scale_1", "scale_2", "opacity", "rot_0", "rot_1", "rot_2", "rot_3"], m = ["red", "green", "blue", "f_dc_0", "f_dc_1", "f_dc_2"];
      for (let k = 0; k < v.length; k++) {
        const z = v[k];
        y.includes(z.name) && _++, m.includes(z.name) && E++;
      }
      const U = _ == y.length && E == 3, V = g ? 2 : U ? 0 : 1;
      return await new Promise((k) => {
        k({
          ...b,
          mode: V,
          data: x.buffer,
          sh: x.sh,
          shDegree: x.shDegree,
          faces: f,
          hasVertexColors: !!E,
          compressed: !1,
          rawSplat: !1
        });
      });
    });
  }
}
F._DefaultLoadingOptions = {
  keepInRam: !1,
  flipY: !1,
  needsRotationScaleTextures: !1,
  spzLibraryUrl: typeof WebAssembly == "object" ? "https://unpkg.com/@adobe/[email protected]/dist/spz.js" : void 0
};
lt(new F());
export {
  F as SPLATFileLoader
};