var Ee = Object.defineProperty;
var _e = (f, t, e) => t in f ? Ee(f, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : f[t] = e;
var M = (f, t, e) => (_e(f, typeof t != "symbol" ? t + "" : t, e), e);
import { t as Le, u as Q, v as le, r as Me, w as G, F as fe, C as F, x as w, y as Se, P as we, z as ye, g as H, H as B, J as y, d as he, a as U, V as D, K as be, W as Ne, O as de, X as Ie, Y as Oe, f as K, Z as Ce, _ as pe, $ as me, a0 as Z, a1 as Fe, a2 as V, L as De, a3 as ge, D as Pe, a4 as ve, e as ke, o as He, h as Ge, i as Be, n as Ue, a5 as je, a6 as Ke, G as X, a7 as Ve, M as Xe, a8 as ze, S as We, A as qe, s as Ye, a9 as Ae, aa as ee, Q as Te, ab as Qe, ac as Ze, ad as Je, ae as $e, af as et, ag as tt, ah as nt, ai as st, aj as it, ak as te, c as ne, N as se, b as ie, al as rt, am as ot, an as at, ao as ct, ap as ut } from "../three.module-BPupfU8l.js";
import { c as lt, d as z } from "../three-vrm.module-BuztCP2r.js";
import { loadAnimation as ft } from "../utils/model.js";
import { bindToVRM as ht, convert as dt } from "../utils/vendors/models/loaders/vmdtovrmbinding.js";
import pt from "../utils/vendors/models/vrm-ik-handler.js";
import mt from "../utils/vendors/models/vrm-model-noise.js";
import { d as gt } from "../delay-DxExMFCS.js";
function re(f, t) {
  if (t === Le)
    return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), f;
  if (t === Q || t === le) {
    let e = f.getIndex();
    if (e === null) {
      const r = [], a = f.getAttribute("position");
      if (a !== void 0) {
        for (let o = 0; o < a.count; o++)
          r.push(o);
        f.setIndex(r), e = f.getIndex();
      } else
        return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), f;
    }
    const s = e.count - 2, n = [];
    if (t === Q)
      for (let r = 1; r <= s; r++)
        n.push(e.getX(0)), n.push(e.getX(r)), n.push(e.getX(r + 1));
    else
      for (let r = 0; r < s; r++)
        r % 2 === 0 ? (n.push(e.getX(r)), n.push(e.getX(r + 1)), n.push(e.getX(r + 2))) : (n.push(e.getX(r + 2)), n.push(e.getX(r + 1)), n.push(e.getX(r)));
    n.length / 3 !== s && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
    const i = f.clone();
    return i.setIndex(n), i.clearGroups(), i;
  } else
    return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", t), f;
}
class At extends Me {
  constructor(t) {
    super(t), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(e) {
      return new _t(e);
    }), this.register(function(e) {
      return new Ot(e);
    }), this.register(function(e) {
      return new Ct(e);
    }), this.register(function(e) {
      return new Ft(e);
    }), this.register(function(e) {
      return new Mt(e);
    }), this.register(function(e) {
      return new St(e);
    }), this.register(function(e) {
      return new wt(e);
    }), this.register(function(e) {
      return new yt(e);
    }), this.register(function(e) {
      return new Et(e);
    }), this.register(function(e) {
      return new bt(e);
    }), this.register(function(e) {
      return new Lt(e);
    }), this.register(function(e) {
      return new It(e);
    }), this.register(function(e) {
      return new Nt(e);
    }), this.register(function(e) {
      return new Rt(e);
    }), this.register(function(e) {
      return new Dt(e);
    }), this.register(function(e) {
      return new Pt(e);
    });
  }
  load(t, e, s, n) {
    const i = this;
    let r;
    if (this.resourcePath !== "")
      r = this.resourcePath;
    else if (this.path !== "") {
      const c = G.extractUrlBase(t);
      r = G.resolveURL(c, this.path);
    } else
      r = G.extractUrlBase(t);
    this.manager.itemStart(t);
    const a = function(c) {
      n ? n(c) : console.error(c), i.manager.itemError(t), i.manager.itemEnd(t);
    }, o = new fe(this.manager);
    o.setPath(this.path), o.setResponseType("arraybuffer"), o.setRequestHeader(this.requestHeader), o.setWithCredentials(this.withCredentials), o.load(t, function(c) {
      try {
        i.parse(c, r, function(u) {
          e(u), i.manager.itemEnd(t);
        }, a);
      } catch (u) {
        a(u);
      }
    }, s, a);
  }
  setDRACOLoader(t) {
    return this.dracoLoader = t, this;
  }
  setDDSLoader() {
    throw new Error(
      'THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".'
    );
  }
  setKTX2Loader(t) {
    return this.ktx2Loader = t, this;
  }
  setMeshoptDecoder(t) {
    return this.meshoptDecoder = t, this;
  }
  register(t) {
    return this.pluginCallbacks.indexOf(t) === -1 && this.pluginCallbacks.push(t), this;
  }
  unregister(t) {
    return this.pluginCallbacks.indexOf(t) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(t), 1), this;
  }
  parse(t, e, s, n) {
    let i;
    const r = {}, a = {}, o = new TextDecoder();
    if (typeof t == "string")
      i = JSON.parse(t);
    else if (t instanceof ArrayBuffer)
      if (o.decode(new Uint8Array(t, 0, 4)) === Re) {
        try {
          r[g.KHR_BINARY_GLTF] = new vt(t);
        } catch (l) {
          n && n(l);
          return;
        }
        i = JSON.parse(r[g.KHR_BINARY_GLTF].content);
      } else
        i = JSON.parse(o.decode(t));
    else
      i = t;
    if (i.asset === void 0 || i.asset.version[0] < 2) {
      n && n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
      return;
    }
    const c = new Yt(i, {
      path: e || this.resourcePath || "",
      crossOrigin: this.crossOrigin,
      requestHeader: this.requestHeader,
      manager: this.manager,
      ktx2Loader: this.ktx2Loader,
      meshoptDecoder: this.meshoptDecoder
    });
    c.fileLoader.setRequestHeader(this.requestHeader);
    for (let u = 0; u < this.pluginCallbacks.length; u++) {
      const l = this.pluginCallbacks[u](c);
      l.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[l.name] = l, r[l.name] = !0;
    }
    if (i.extensionsUsed)
      for (let u = 0; u < i.extensionsUsed.length; ++u) {
        const l = i.extensionsUsed[u], h = i.extensionsRequired || [];
        switch (l) {
          case g.KHR_MATERIALS_UNLIT:
            r[l] = new xt();
            break;
          case g.KHR_DRACO_MESH_COMPRESSION:
            r[l] = new kt(i, this.dracoLoader);
            break;
          case g.KHR_TEXTURE_TRANSFORM:
            r[l] = new Ht();
            break;
          case g.KHR_MESH_QUANTIZATION:
            r[l] = new Gt();
            break;
          default:
            h.indexOf(l) >= 0 && a[l] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + l + '".');
        }
      }
    c.setExtensions(r), c.setPlugins(a), c.parse(s, n);
  }
  parseAsync(t, e) {
    const s = this;
    return new Promise(function(n, i) {
      s.parse(t, e, n, i);
    });
  }
}
function Tt() {
  let f = {};
  return {
    get: function(t) {
      return f[t];
    },
    add: function(t, e) {
      f[t] = e;
    },
    remove: function(t) {
      delete f[t];
    },
    removeAll: function() {
      f = {};
    }
  };
}
const g = {
  KHR_BINARY_GLTF: "KHR_binary_glTF",
  KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
  KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
  KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
  KHR_MATERIALS_IOR: "KHR_materials_ior",
  KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
  KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
  KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
  KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
  KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
  KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
  KHR_MATERIALS_VOLUME: "KHR_materials_volume",
  KHR_TEXTURE_BASISU: "KHR_texture_basisu",
  KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
  KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
  KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength",
  EXT_MATERIALS_BUMP: "EXT_materials_bump",
  EXT_TEXTURE_WEBP: "EXT_texture_webp",
  EXT_TEXTURE_AVIF: "EXT_texture_avif",
  EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression",
  EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing"
};
class Rt {
  constructor(t) {
    this.parser = t, this.name = g.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} };
  }
  _markDefs() {
    const t = this.parser, e = this.parser.json.nodes || [];
    for (let s = 0, n = e.length; s < n; s++) {
      const i = e[s];
      i.extensions && i.extensions[this.name] && i.extensions[this.name].light !== void 0 && t._addNodeRef(this.cache, i.extensions[this.name].light);
    }
  }
  _loadLight(t) {
    const e = this.parser, s = "light:" + t;
    let n = e.cache.get(s);
    if (n)
      return n;
    const i = e.json, o = ((i.extensions && i.extensions[this.name] || {}).lights || [])[t];
    let c;
    const u = new F(16777215);
    o.color !== void 0 && u.setRGB(o.color[0], o.color[1], o.color[2], w);
    const l = o.range !== void 0 ? o.range : 0;
    switch (o.type) {
      case "directional":
        c = new ye(u), c.target.position.set(0, 0, -1), c.add(c.target);
        break;
      case "point":
        c = new we(u), c.distance = l;
        break;
      case "spot":
        c = new Se(u), c.distance = l, o.spot = o.spot || {}, o.spot.innerConeAngle = o.spot.innerConeAngle !== void 0 ? o.spot.innerConeAngle : 0, o.spot.outerConeAngle = o.spot.outerConeAngle !== void 0 ? o.spot.outerConeAngle : Math.PI / 4, c.angle = o.spot.outerConeAngle, c.penumbra = 1 - o.spot.innerConeAngle / o.spot.outerConeAngle, c.target.position.set(0, 0, -1), c.add(c.target);
        break;
      default:
        throw new Error("THREE.GLTFLoader: Unexpected light type: " + o.type);
    }
    return c.position.set(0, 0, 0), c.decay = 2, O(c, o), o.intensity !== void 0 && (c.intensity = o.intensity), c.name = e.createUniqueName(o.name || "light_" + t), n = Promise.resolve(c), e.cache.add(s, n), n;
  }
  getDependency(t, e) {
    if (t === "light")
      return this._loadLight(e);
  }
  createNodeAttachment(t) {
    const e = this, s = this.parser, i = s.json.nodes[t], a = (i.extensions && i.extensions[this.name] || {}).light;
    return a === void 0 ? null : this._loadLight(a).then(function(o) {
      return s._getNodeRef(e.cache, a, o);
    });
  }
}
class xt {
  constructor() {
    this.name = g.KHR_MATERIALS_UNLIT;
  }
  getMaterialType() {
    return H;
  }
  extendParams(t, e, s) {
    const n = [];
    t.color = new F(1, 1, 1), t.opacity = 1;
    const i = e.pbrMetallicRoughness;
    if (i) {
      if (Array.isArray(i.baseColorFactor)) {
        const r = i.baseColorFactor;
        t.color.setRGB(r[0], r[1], r[2], w), t.opacity = r[3];
      }
      i.baseColorTexture !== void 0 && n.push(s.assignTexture(t, "map", i.baseColorTexture, B));
    }
    return Promise.all(n);
  }
}
class Et {
  constructor(t) {
    this.parser = t, this.name = g.KHR_MATERIALS_EMISSIVE_STRENGTH;
  }
  extendMaterialParams(t, e) {
    const n = this.parser.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = n.extensions[this.name].emissiveStrength;
    return i !== void 0 && (e.emissiveIntensity = i), Promise.resolve();
  }
}
class _t {
  constructor(t) {
    this.parser = t, this.name = g.KHR_MATERIALS_CLEARCOAT;
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return !s.extensions || !s.extensions[this.name] ? null : y;
  }
  extendMaterialParams(t, e) {
    const s = this.parser, n = s.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = [], r = n.extensions[this.name];
    if (r.clearcoatFactor !== void 0 && (e.clearcoat = r.clearcoatFactor), r.clearcoatTexture !== void 0 && i.push(s.assignTexture(e, "clearcoatMap", r.clearcoatTexture)), r.clearcoatRoughnessFactor !== void 0 && (e.clearcoatRoughness = r.clearcoatRoughnessFactor), r.clearcoatRoughnessTexture !== void 0 && i.push(s.assignTexture(e, "clearcoatRoughnessMap", r.clearcoatRoughnessTexture)), r.clearcoatNormalTexture !== void 0 && (i.push(s.assignTexture(e, "clearcoatNormalMap", r.clearcoatNormalTexture)), r.clearcoatNormalTexture.scale !== void 0)) {
      const a = r.clearcoatNormalTexture.scale;
      e.clearcoatNormalScale = new he(a, a);
    }
    return Promise.all(i);
  }
}
class Lt {
  constructor(t) {
    this.parser = t, this.name = g.KHR_MATERIALS_IRIDESCENCE;
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return !s.extensions || !s.extensions[this.name] ? null : y;
  }
  extendMaterialParams(t, e) {
    const s = this.parser, n = s.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = [], r = n.extensions[this.name];
    return r.iridescenceFactor !== void 0 && (e.iridescence = r.iridescenceFactor), r.iridescenceTexture !== void 0 && i.push(s.assignTexture(e, "iridescenceMap", r.iridescenceTexture)), r.iridescenceIor !== void 0 && (e.iridescenceIOR = r.iridescenceIor), e.iridescenceThicknessRange === void 0 && (e.iridescenceThicknessRange = [100, 400]), r.iridescenceThicknessMinimum !== void 0 && (e.iridescenceThicknessRange[0] = r.iridescenceThicknessMinimum), r.iridescenceThicknessMaximum !== void 0 && (e.iridescenceThicknessRange[1] = r.iridescenceThicknessMaximum), r.iridescenceThicknessTexture !== void 0 && i.push(s.assignTexture(e, "iridescenceThicknessMap", r.iridescenceThicknessTexture)), Promise.all(i);
  }
}
class Mt {
  constructor(t) {
    this.parser = t, this.name = g.KHR_MATERIALS_SHEEN;
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return !s.extensions || !s.extensions[this.name] ? null : y;
  }
  extendMaterialParams(t, e) {
    const s = this.parser, n = s.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = [];
    e.sheenColor = new F(0, 0, 0), e.sheenRoughness = 0, e.sheen = 1;
    const r = n.extensions[this.name];
    if (r.sheenColorFactor !== void 0) {
      const a = r.sheenColorFactor;
      e.sheenColor.setRGB(a[0], a[1], a[2], w);
    }
    return r.sheenRoughnessFactor !== void 0 && (e.sheenRoughness = r.sheenRoughnessFactor), r.sheenColorTexture !== void 0 && i.push(s.assignTexture(e, "sheenColorMap", r.sheenColorTexture, B)), r.sheenRoughnessTexture !== void 0 && i.push(s.assignTexture(e, "sheenRoughnessMap", r.sheenRoughnessTexture)), Promise.all(i);
  }
}
class St {
  constructor(t) {
    this.parser = t, this.name = g.KHR_MATERIALS_TRANSMISSION;
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return !s.extensions || !s.extensions[this.name] ? null : y;
  }
  extendMaterialParams(t, e) {
    const s = this.parser, n = s.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = [], r = n.extensions[this.name];
    return r.transmissionFactor !== void 0 && (e.transmission = r.transmissionFactor), r.transmissionTexture !== void 0 && i.push(s.assignTexture(e, "transmissionMap", r.transmissionTexture)), Promise.all(i);
  }
}
class wt {
  constructor(t) {
    this.parser = t, this.name = g.KHR_MATERIALS_VOLUME;
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return !s.extensions || !s.extensions[this.name] ? null : y;
  }
  extendMaterialParams(t, e) {
    const s = this.parser, n = s.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = [], r = n.extensions[this.name];
    e.thickness = r.thicknessFactor !== void 0 ? r.thicknessFactor : 0, r.thicknessTexture !== void 0 && i.push(s.assignTexture(e, "thicknessMap", r.thicknessTexture)), e.attenuationDistance = r.attenuationDistance || 1 / 0;
    const a = r.attenuationColor || [1, 1, 1];
    return e.attenuationColor = new F().setRGB(a[0], a[1], a[2], w), Promise.all(i);
  }
}
class yt {
  constructor(t) {
    this.parser = t, this.name = g.KHR_MATERIALS_IOR;
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return !s.extensions || !s.extensions[this.name] ? null : y;
  }
  extendMaterialParams(t, e) {
    const n = this.parser.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = n.extensions[this.name];
    return e.ior = i.ior !== void 0 ? i.ior : 1.5, Promise.resolve();
  }
}
class bt {
  constructor(t) {
    this.parser = t, this.name = g.KHR_MATERIALS_SPECULAR;
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return !s.extensions || !s.extensions[this.name] ? null : y;
  }
  extendMaterialParams(t, e) {
    const s = this.parser, n = s.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = [], r = n.extensions[this.name];
    e.specularIntensity = r.specularFactor !== void 0 ? r.specularFactor : 1, r.specularTexture !== void 0 && i.push(s.assignTexture(e, "specularIntensityMap", r.specularTexture));
    const a = r.specularColorFactor || [1, 1, 1];
    return e.specularColor = new F().setRGB(a[0], a[1], a[2], w), r.specularColorTexture !== void 0 && i.push(s.assignTexture(e, "specularColorMap", r.specularColorTexture, B)), Promise.all(i);
  }
}
class Nt {
  constructor(t) {
    this.parser = t, this.name = g.EXT_MATERIALS_BUMP;
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return !s.extensions || !s.extensions[this.name] ? null : y;
  }
  extendMaterialParams(t, e) {
    const s = this.parser, n = s.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = [], r = n.extensions[this.name];
    return e.bumpScale = r.bumpFactor !== void 0 ? r.bumpFactor : 1, r.bumpTexture !== void 0 && i.push(s.assignTexture(e, "bumpMap", r.bumpTexture)), Promise.all(i);
  }
}
class It {
  constructor(t) {
    this.parser = t, this.name = g.KHR_MATERIALS_ANISOTROPY;
  }
  getMaterialType(t) {
    const s = this.parser.json.materials[t];
    return !s.extensions || !s.extensions[this.name] ? null : y;
  }
  extendMaterialParams(t, e) {
    const s = this.parser, n = s.json.materials[t];
    if (!n.extensions || !n.extensions[this.name])
      return Promise.resolve();
    const i = [], r = n.extensions[this.name];
    return r.anisotropyStrength !== void 0 && (e.anisotropy = r.anisotropyStrength), r.anisotropyRotation !== void 0 && (e.anisotropyRotation = r.anisotropyRotation), r.anisotropyTexture !== void 0 && i.push(s.assignTexture(e, "anisotropyMap", r.anisotropyTexture)), Promise.all(i);
  }
}
class Ot {
  constructor(t) {
    this.parser = t, this.name = g.KHR_TEXTURE_BASISU;
  }
  loadTexture(t) {
    const e = this.parser, s = e.json, n = s.textures[t];
    if (!n.extensions || !n.extensions[this.name])
      return null;
    const i = n.extensions[this.name], r = e.options.ktx2Loader;
    if (!r) {
      if (s.extensionsRequired && s.extensionsRequired.indexOf(this.name) >= 0)
        throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
      return null;
    }
    return e.loadTextureImage(t, i.source, r);
  }
}
class Ct {
  constructor(t) {
    this.parser = t, this.name = g.EXT_TEXTURE_WEBP, this.isSupported = null;
  }
  loadTexture(t) {
    const e = this.name, s = this.parser, n = s.json, i = n.textures[t];
    if (!i.extensions || !i.extensions[e])
      return null;
    const r = i.extensions[e], a = n.images[r.source];
    let o = s.textureLoader;
    if (a.uri) {
      const c = s.options.manager.getHandler(a.uri);
      c !== null && (o = c);
    }
    return this.detectSupport().then(function(c) {
      if (c)
        return s.loadTextureImage(t, r.source, o);
      if (n.extensionsRequired && n.extensionsRequired.indexOf(e) >= 0)
        throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
      return s.loadTexture(t);
    });
  }
  detectSupport() {
    return this.isSupported || (this.isSupported = new Promise(function(t) {
      const e = new Image();
      e.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA", e.onload = e.onerror = function() {
        t(e.height === 1);
      };
    })), this.isSupported;
  }
}
class Ft {
  constructor(t) {
    this.parser = t, this.name = g.EXT_TEXTURE_AVIF, this.isSupported = null;
  }
  loadTexture(t) {
    const e = this.name, s = this.parser, n = s.json, i = n.textures[t];
    if (!i.extensions || !i.extensions[e])
      return null;
    const r = i.extensions[e], a = n.images[r.source];
    let o = s.textureLoader;
    if (a.uri) {
      const c = s.options.manager.getHandler(a.uri);
      c !== null && (o = c);
    }
    return this.detectSupport().then(function(c) {
      if (c)
        return s.loadTextureImage(t, r.source, o);
      if (n.extensionsRequired && n.extensionsRequired.indexOf(e) >= 0)
        throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");
      return s.loadTexture(t);
    });
  }
  detectSupport() {
    return this.isSupported || (this.isSupported = new Promise(function(t) {
      const e = new Image();
      e.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=", e.onload = e.onerror = function() {
        t(e.height === 1);
      };
    })), this.isSupported;
  }
}
class Dt {
  constructor(t) {
    this.name = g.EXT_MESHOPT_COMPRESSION, this.parser = t;
  }
  loadBufferView(t) {
    const e = this.parser.json, s = e.bufferViews[t];
    if (s.extensions && s.extensions[this.name]) {
      const n = s.extensions[this.name], i = this.parser.getDependency("buffer", n.buffer), r = this.parser.options.meshoptDecoder;
      if (!r || !r.supported) {
        if (e.extensionsRequired && e.extensionsRequired.indexOf(this.name) >= 0)
          throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
        return null;
      }
      return i.then(function(a) {
        const o = n.byteOffset || 0, c = n.byteLength || 0, u = n.count, l = n.byteStride, h = new Uint8Array(a, o, c);
        return r.decodeGltfBufferAsync ? r.decodeGltfBufferAsync(u, l, h, n.mode, n.filter).then(function(d) {
          return d.buffer;
        }) : r.ready.then(function() {
          const d = new ArrayBuffer(u * l);
          return r.decodeGltfBuffer(new Uint8Array(d), u, l, h, n.mode, n.filter), d;
        });
      });
    } else
      return null;
  }
}
class Pt {
  constructor(t) {
    this.name = g.EXT_MESH_GPU_INSTANCING, this.parser = t;
  }
  createNodeMesh(t) {
    const e = this.parser.json, s = e.nodes[t];
    if (!s.extensions || !s.extensions[this.name] || s.mesh === void 0)
      return null;
    const n = e.meshes[s.mesh];
    for (const c of n.primitives)
      if (c.mode !== _.TRIANGLES && c.mode !== _.TRIANGLE_STRIP && c.mode !== _.TRIANGLE_FAN && c.mode !== void 0)
        return null;
    const r = s.extensions[this.name].attributes, a = [], o = {};
    for (const c in r)
      a.push(this.parser.getDependency("accessor", r[c]).then((u) => (o[c] = u, o[c])));
    return a.length < 1 ? null : (a.push(this.parser.createNodeMesh(t)), Promise.all(a).then((c) => {
      const u = c.pop(), l = u.isGroup ? u.children : [u], h = c[0].count, d = [];
      for (const p of l) {
        const T = new U(), m = new D(), A = new Te(), x = new D(1, 1, 1), E = new be(p.geometry, p.material, h);
        for (let R = 0; R < h; R++)
          o.TRANSLATION && m.fromBufferAttribute(o.TRANSLATION, R), o.ROTATION && A.fromBufferAttribute(o.ROTATION, R), o.SCALE && x.fromBufferAttribute(o.SCALE, R), E.setMatrixAt(R, T.compose(m, A, x));
        for (const R in o)
          if (R === "_COLOR_0") {
            const S = o[R];
            E.instanceColor = new Ne(S.array, S.itemSize, S.normalized);
          } else
            R !== "TRANSLATION" && R !== "ROTATION" && R !== "SCALE" && p.geometry.setAttribute(R, o[R]);
        de.prototype.copy.call(E, p), this.parser.assignFinalMaterial(E), d.push(E);
      }
      return u.isGroup ? (u.clear(), u.add(...d), u) : d[0];
    }));
  }
}
const Re = "glTF", k = 12, oe = { JSON: 1313821514, BIN: 5130562 };
class vt {
  constructor(t) {
    this.name = g.KHR_BINARY_GLTF, this.content = null, this.body = null;
    const e = new DataView(t, 0, k), s = new TextDecoder();
    if (this.header = {
      magic: s.decode(new Uint8Array(t.slice(0, 4))),
      version: e.getUint32(4, !0),
      length: e.getUint32(8, !0)
    }, this.header.magic !== Re)
      throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
    if (this.header.version < 2)
      throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
    const n = this.header.length - k, i = new DataView(t, k);
    let r = 0;
    for (; r < n; ) {
      const a = i.getUint32(r, !0);
      r += 4;
      const o = i.getUint32(r, !0);
      if (r += 4, o === oe.JSON) {
        const c = new Uint8Array(t, k + r, a);
        this.content = s.decode(c);
      } else if (o === oe.BIN) {
        const c = k + r;
        this.body = t.slice(c, c + a);
      }
      r += a;
    }
    if (this.content === null)
      throw new Error("THREE.GLTFLoader: JSON content not found.");
  }
}
class kt {
  constructor(t, e) {
    if (!e)
      throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
    this.name = g.KHR_DRACO_MESH_COMPRESSION, this.json = t, this.dracoLoader = e, this.dracoLoader.preload();
  }
  decodePrimitive(t, e) {
    const s = this.json, n = this.dracoLoader, i = t.extensions[this.name].bufferView, r = t.extensions[this.name].attributes, a = {}, o = {}, c = {};
    for (const u in r) {
      const l = J[u] || u.toLowerCase();
      a[l] = r[u];
    }
    for (const u in t.attributes) {
      const l = J[u] || u.toLowerCase();
      if (r[u] !== void 0) {
        const h = s.accessors[t.attributes[u]], d = P[h.componentType];
        c[l] = d.name, o[l] = h.normalized === !0;
      }
    }
    return e.getDependency("bufferView", i).then(function(u) {
      return new Promise(function(l, h) {
        n.decodeDracoFile(u, function(d) {
          for (const p in d.attributes) {
            const T = d.attributes[p], m = o[p];
            m !== void 0 && (T.normalized = m);
          }
          l(d);
        }, a, c, w, h);
      });
    });
  }
}
class Ht {
  constructor() {
    this.name = g.KHR_TEXTURE_TRANSFORM;
  }
  extendTexture(t, e) {
    return (e.texCoord === void 0 || e.texCoord === t.channel) && e.offset === void 0 && e.rotation === void 0 && e.scale === void 0 || (t = t.clone(), e.texCoord !== void 0 && (t.channel = e.texCoord), e.offset !== void 0 && t.offset.fromArray(e.offset), e.rotation !== void 0 && (t.rotation = e.rotation), e.scale !== void 0 && t.repeat.fromArray(e.scale), t.needsUpdate = !0), t;
  }
}
class Gt {
  constructor() {
    this.name = g.KHR_MESH_QUANTIZATION;
  }
}
class xe extends at {
  constructor(t, e, s, n) {
    super(t, e, s, n);
  }
  copySampleValue_(t) {
    const e = this.resultBuffer, s = this.sampleValues, n = this.valueSize, i = t * n * 3 + n;
    for (let r = 0; r !== n; r++)
      e[r] = s[i + r];
    return e;
  }
  interpolate_(t, e, s, n) {
    const i = this.resultBuffer, r = this.sampleValues, a = this.valueSize, o = a * 2, c = a * 3, u = n - e, l = (s - e) / u, h = l * l, d = h * l, p = t * c, T = p - c, m = -2 * d + 3 * h, A = d - h, x = 1 - m, E = A - h + l;
    for (let R = 0; R !== a; R++) {
      const S = r[T + R + a], b = r[T + R + o] * u, L = r[p + R + a], v = r[p + R] * u;
      i[R] = x * S + E * b + m * L + A * v;
    }
    return i;
  }
}
const Bt = new Te();
class Ut extends xe {
  interpolate_(t, e, s, n) {
    const i = super.interpolate_(t, e, s, n);
    return Bt.fromArray(i).normalize().toArray(i), i;
  }
}
const _ = {
  FLOAT: 5126,
  //FLOAT_MAT2: 35674,
  FLOAT_MAT3: 35675,
  FLOAT_MAT4: 35676,
  FLOAT_VEC2: 35664,
  FLOAT_VEC3: 35665,
  FLOAT_VEC4: 35666,
  LINEAR: 9729,
  REPEAT: 10497,
  SAMPLER_2D: 35678,
  POINTS: 0,
  LINES: 1,
  LINE_LOOP: 2,
  LINE_STRIP: 3,
  TRIANGLES: 4,
  TRIANGLE_STRIP: 5,
  TRIANGLE_FAN: 6,
  UNSIGNED_BYTE: 5121,
  UNSIGNED_SHORT: 5123
}, P = {
  5120: Int8Array,
  5121: Uint8Array,
  5122: Int16Array,
  5123: Uint16Array,
  5125: Uint32Array,
  5126: Float32Array
}, ae = {
  9728: Qe,
  9729: pe,
  9984: Ze,
  9985: Je,
  9986: $e,
  9987: me
}, ce = {
  33071: et,
  33648: tt,
  10497: Z
}, W = {
  SCALAR: 1,
  VEC2: 2,
  VEC3: 3,
  VEC4: 4,
  MAT2: 4,
  MAT3: 9,
  MAT4: 16
}, J = {
  POSITION: "position",
  NORMAL: "normal",
  TANGENT: "tangent",
  TEXCOORD_0: "uv",
  TEXCOORD_1: "uv1",
  TEXCOORD_2: "uv2",
  TEXCOORD_3: "uv3",
  COLOR_0: "color",
  WEIGHTS_0: "skinWeight",
  JOINTS_0: "skinIndex"
}, I = {
  scale: "scale",
  translation: "position",
  rotation: "quaternion",
  weights: "morphTargetInfluences"
}, jt = {
  CUBICSPLINE: void 0,
  // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
  // keyframe track will be initialized with a default interpolation type, then modified.
  LINEAR: Ae,
  STEP: nt
}, q = {
  OPAQUE: "OPAQUE",
  MASK: "MASK",
  BLEND: "BLEND"
};
function Kt(f) {
  return f.DefaultMaterial === void 0 && (f.DefaultMaterial = new ge({
    color: 16777215,
    emissive: 0,
    metalness: 1,
    roughness: 1,
    transparent: !1,
    depthTest: !0,
    side: st
  })), f.DefaultMaterial;
}
function C(f, t, e) {
  for (const s in e.extensions)
    f[s] === void 0 && (t.userData.gltfExtensions = t.userData.gltfExtensions || {}, t.userData.gltfExtensions[s] = e.extensions[s]);
}
function O(f, t) {
  t.extras !== void 0 && (typeof t.extras == "object" ? Object.assign(f.userData, t.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + t.extras));
}
function Vt(f, t, e) {
  let s = !1, n = !1, i = !1;
  for (let c = 0, u = t.length; c < u; c++) {
    const l = t[c];
    if (l.POSITION !== void 0 && (s = !0), l.NORMAL !== void 0 && (n = !0), l.COLOR_0 !== void 0 && (i = !0), s && n && i)
      break;
  }
  if (!s && !n && !i)
    return Promise.resolve(f);
  const r = [], a = [], o = [];
  for (let c = 0, u = t.length; c < u; c++) {
    const l = t[c];
    if (s) {
      const h = l.POSITION !== void 0 ? e.getDependency("accessor", l.POSITION) : f.attributes.position;
      r.push(h);
    }
    if (n) {
      const h = l.NORMAL !== void 0 ? e.getDependency("accessor", l.NORMAL) : f.attributes.normal;
      a.push(h);
    }
    if (i) {
      const h = l.COLOR_0 !== void 0 ? e.getDependency("accessor", l.COLOR_0) : f.attributes.color;
      o.push(h);
    }
  }
  return Promise.all([
    Promise.all(r),
    Promise.all(a),
    Promise.all(o)
  ]).then(function(c) {
    const u = c[0], l = c[1], h = c[2];
    return s && (f.morphAttributes.position = u), n && (f.morphAttributes.normal = l), i && (f.morphAttributes.color = h), f.morphTargetsRelative = !0, f;
  });
}
function Xt(f, t) {
  if (f.updateMorphTargets(), t.weights !== void 0)
    for (let e = 0, s = t.weights.length; e < s; e++)
      f.morphTargetInfluences[e] = t.weights[e];
  if (t.extras && Array.isArray(t.extras.targetNames)) {
    const e = t.extras.targetNames;
    if (f.morphTargetInfluences.length === e.length) {
      f.morphTargetDictionary = {};
      for (let s = 0, n = e.length; s < n; s++)
        f.morphTargetDictionary[e[s]] = s;
    } else
      console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
  }
}
function zt(f) {
  let t;
  const e = f.extensions && f.extensions[g.KHR_DRACO_MESH_COMPRESSION];
  if (e ? t = "draco:" + e.bufferView + ":" + e.indices + ":" + Y(e.attributes) : t = f.indices + ":" + Y(f.attributes) + ":" + f.mode, f.targets !== void 0)
    for (let s = 0, n = f.targets.length; s < n; s++)
      t += ":" + Y(f.targets[s]);
  return t;
}
function Y(f) {
  let t = "";
  const e = Object.keys(f).sort();
  for (let s = 0, n = e.length; s < n; s++)
    t += e[s] + ":" + f[e[s]] + ";";
  return t;
}
function $(f) {
  switch (f) {
    case Int8Array:
      return 1 / 127;
    case Uint8Array:
      return 1 / 255;
    case Int16Array:
      return 1 / 32767;
    case Uint16Array:
      return 1 / 65535;
    default:
      throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
  }
}
function Wt(f) {
  return f.search(/\.jpe?g($|\?)/i) > 0 || f.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : f.search(/\.webp($|\?)/i) > 0 || f.search(/^data\:image\/webp/) === 0 ? "image/webp" : "image/png";
}
const qt = new U();
class Yt {
  constructor(t = {}, e = {}) {
    this.json = t, this.extensions = {}, this.plugins = {}, this.options = e, this.cache = new Tt(), this.associations = /* @__PURE__ */ new Map(), this.primitiveCache = {}, this.nodeCache = {}, this.meshCache = { refs: {}, uses: {} }, this.cameraCache = { refs: {}, uses: {} }, this.lightCache = { refs: {}, uses: {} }, this.sourceCache = {}, this.textureCache = {}, this.nodeNamesUsed = {};
    let s = !1, n = !1, i = -1;
    typeof navigator < "u" && (s = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) === !0, n = navigator.userAgent.indexOf("Firefox") > -1, i = n ? navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1] : -1), typeof createImageBitmap > "u" || s || n && i < 98 ? this.textureLoader = new Ie(this.options.manager) : this.textureLoader = new Oe(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new fe(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(!0);
  }
  setExtensions(t) {
    this.extensions = t;
  }
  setPlugins(t) {
    this.plugins = t;
  }
  parse(t, e) {
    const s = this, n = this.json, i = this.extensions;
    this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(r) {
      return r._markDefs && r._markDefs();
    }), Promise.all(this._invokeAll(function(r) {
      return r.beforeRoot && r.beforeRoot();
    })).then(function() {
      return Promise.all([
        s.getDependencies("scene"),
        s.getDependencies("animation"),
        s.getDependencies("camera")
      ]);
    }).then(function(r) {
      const a = {
        scene: r[0][n.scene || 0],
        scenes: r[0],
        animations: r[1],
        cameras: r[2],
        asset: n.asset,
        parser: s,
        userData: {}
      };
      return C(i, a, n), O(a, n), Promise.all(s._invokeAll(function(o) {
        return o.afterRoot && o.afterRoot(a);
      })).then(function() {
        t(a);
      });
    }).catch(e);
  }
  /**
   * Marks the special nodes/meshes in json for efficient parse.
   */
  _markDefs() {
    const t = this.json.nodes || [], e = this.json.skins || [], s = this.json.meshes || [];
    for (let n = 0, i = e.length; n < i; n++) {
      const r = e[n].joints;
      for (let a = 0, o = r.length; a < o; a++)
        t[r[a]].isBone = !0;
    }
    for (let n = 0, i = t.length; n < i; n++) {
      const r = t[n];
      r.mesh !== void 0 && (this._addNodeRef(this.meshCache, r.mesh), r.skin !== void 0 && (s[r.mesh].isSkinnedMesh = !0)), r.camera !== void 0 && this._addNodeRef(this.cameraCache, r.camera);
    }
  }
  /**
   * Counts references to shared node / Object3D resources. These resources
   * can be reused, or "instantiated", at multiple nodes in the scene
   * hierarchy. Mesh, Camera, and Light instances are instantiated and must
   * be marked. Non-scenegraph resources (like Materials, Geometries, and
   * Textures) can be reused directly and are not marked here.
   *
   * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
   */
  _addNodeRef(t, e) {
    e !== void 0 && (t.refs[e] === void 0 && (t.refs[e] = t.uses[e] = 0), t.refs[e]++);
  }
  /** Returns a reference to a shared resource, cloning it if necessary. */
  _getNodeRef(t, e, s) {
    if (t.refs[e] <= 1)
      return s;
    const n = s.clone(), i = (r, a) => {
      const o = this.associations.get(r);
      o != null && this.associations.set(a, o);
      for (const [c, u] of r.children.entries())
        i(u, a.children[c]);
    };
    return i(s, n), n.name += "_instance_" + t.uses[e]++, n;
  }
  _invokeOne(t) {
    const e = Object.values(this.plugins);
    e.push(this);
    for (let s = 0; s < e.length; s++) {
      const n = t(e[s]);
      if (n)
        return n;
    }
    return null;
  }
  _invokeAll(t) {
    const e = Object.values(this.plugins);
    e.unshift(this);
    const s = [];
    for (let n = 0; n < e.length; n++) {
      const i = t(e[n]);
      i && s.push(i);
    }
    return s;
  }
  /**
   * Requests the specified dependency asynchronously, with caching.
   * @param {string} type
   * @param {number} index
   * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
   */
  getDependency(t, e) {
    const s = t + ":" + e;
    let n = this.cache.get(s);
    if (!n) {
      switch (t) {
        case "scene":
          n = this.loadScene(e);
          break;
        case "node":
          n = this._invokeOne(function(i) {
            return i.loadNode && i.loadNode(e);
          });
          break;
        case "mesh":
          n = this._invokeOne(function(i) {
            return i.loadMesh && i.loadMesh(e);
          });
          break;
        case "accessor":
          n = this.loadAccessor(e);
          break;
        case "bufferView":
          n = this._invokeOne(function(i) {
            return i.loadBufferView && i.loadBufferView(e);
          });
          break;
        case "buffer":
          n = this.loadBuffer(e);
          break;
        case "material":
          n = this._invokeOne(function(i) {
            return i.loadMaterial && i.loadMaterial(e);
          });
          break;
        case "texture":
          n = this._invokeOne(function(i) {
            return i.loadTexture && i.loadTexture(e);
          });
          break;
        case "skin":
          n = this.loadSkin(e);
          break;
        case "animation":
          n = this._invokeOne(function(i) {
            return i.loadAnimation && i.loadAnimation(e);
          });
          break;
        case "camera":
          n = this.loadCamera(e);
          break;
        default:
          if (n = this._invokeOne(function(i) {
            return i != this && i.getDependency && i.getDependency(t, e);
          }), !n)
            throw new Error("Unknown type: " + t);
          break;
      }
      this.cache.add(s, n);
    }
    return n;
  }
  /**
   * Requests all dependencies of the specified type asynchronously, with caching.
   * @param {string} type
   * @return {Promise<Array<Object>>}
   */
  getDependencies(t) {
    let e = this.cache.get(t);
    if (!e) {
      const s = this, n = this.json[t + (t === "mesh" ? "es" : "s")] || [];
      e = Promise.all(n.map(function(i, r) {
        return s.getDependency(t, r);
      })), this.cache.add(t, e);
    }
    return e;
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
   * @param {number} bufferIndex
   * @return {Promise<ArrayBuffer>}
   */
  loadBuffer(t) {
    const e = this.json.buffers[t], s = this.fileLoader;
    if (e.type && e.type !== "arraybuffer")
      throw new Error("THREE.GLTFLoader: " + e.type + " buffer type is not supported.");
    if (e.uri === void 0 && t === 0)
      return Promise.resolve(this.extensions[g.KHR_BINARY_GLTF].body);
    const n = this.options;
    return new Promise(function(i, r) {
      s.load(G.resolveURL(e.uri, n.path), i, void 0, function() {
        r(new Error('THREE.GLTFLoader: Failed to load buffer "' + e.uri + '".'));
      });
    });
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
   * @param {number} bufferViewIndex
   * @return {Promise<ArrayBuffer>}
   */
  loadBufferView(t) {
    const e = this.json.bufferViews[t];
    return this.getDependency("buffer", e.buffer).then(function(s) {
      const n = e.byteLength || 0, i = e.byteOffset || 0;
      return s.slice(i, i + n);
    });
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
   * @param {number} accessorIndex
   * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
   */
  loadAccessor(t) {
    const e = this, s = this.json, n = this.json.accessors[t];
    if (n.bufferView === void 0 && n.sparse === void 0) {
      const r = W[n.type], a = P[n.componentType], o = n.normalized === !0, c = new a(n.count * r);
      return Promise.resolve(new K(c, r, o));
    }
    const i = [];
    return n.bufferView !== void 0 ? i.push(this.getDependency("bufferView", n.bufferView)) : i.push(null), n.sparse !== void 0 && (i.push(this.getDependency("bufferView", n.sparse.indices.bufferView)), i.push(this.getDependency("bufferView", n.sparse.values.bufferView))), Promise.all(i).then(function(r) {
      const a = r[0], o = W[n.type], c = P[n.componentType], u = c.BYTES_PER_ELEMENT, l = u * o, h = n.byteOffset || 0, d = n.bufferView !== void 0 ? s.bufferViews[n.bufferView].byteStride : void 0, p = n.normalized === !0;
      let T, m;
      if (d && d !== l) {
        const A = Math.floor(h / d), x = "InterleavedBuffer:" + n.bufferView + ":" + n.componentType + ":" + A + ":" + n.count;
        let E = e.cache.get(x);
        E || (T = new c(a, A * d, n.count * d / u), E = new Ce(T, d / u), e.cache.add(x, E)), m = new it(E, o, h % d / u, p);
      } else
        a === null ? T = new c(n.count * o) : T = new c(a, h, n.count * o), m = new K(T, o, p);
      if (n.sparse !== void 0) {
        const A = W.SCALAR, x = P[n.sparse.indices.componentType], E = n.sparse.indices.byteOffset || 0, R = n.sparse.values.byteOffset || 0, S = new x(r[1], E, n.sparse.count * A), b = new c(r[2], R, n.sparse.count * o);
        a !== null && (m = new K(m.array.slice(), m.itemSize, m.normalized));
        for (let L = 0, v = S.length; L < v; L++) {
          const N = S[L];
          if (m.setX(N, b[L * o]), o >= 2 && m.setY(N, b[L * o + 1]), o >= 3 && m.setZ(N, b[L * o + 2]), o >= 4 && m.setW(N, b[L * o + 3]), o >= 5)
            throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
        }
      }
      return m;
    });
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
   * @param {number} textureIndex
   * @return {Promise<THREE.Texture|null>}
   */
  loadTexture(t) {
    const e = this.json, s = this.options, i = e.textures[t].source, r = e.images[i];
    let a = this.textureLoader;
    if (r.uri) {
      const o = s.manager.getHandler(r.uri);
      o !== null && (a = o);
    }
    return this.loadTextureImage(t, i, a);
  }
  loadTextureImage(t, e, s) {
    const n = this, i = this.json, r = i.textures[t], a = i.images[e], o = (a.uri || a.bufferView) + ":" + r.sampler;
    if (this.textureCache[o])
      return this.textureCache[o];
    const c = this.loadImageSource(e, s).then(function(u) {
      u.flipY = !1, u.name = r.name || a.name || "", u.name === "" && typeof a.uri == "string" && a.uri.startsWith("data:image/") === !1 && (u.name = a.uri);
      const h = (i.samplers || {})[r.sampler] || {};
      return u.magFilter = ae[h.magFilter] || pe, u.minFilter = ae[h.minFilter] || me, u.wrapS = ce[h.wrapS] || Z, u.wrapT = ce[h.wrapT] || Z, n.associations.set(u, { textures: t }), u;
    }).catch(function() {
      return null;
    });
    return this.textureCache[o] = c, c;
  }
  loadImageSource(t, e) {
    const s = this, n = this.json, i = this.options;
    if (this.sourceCache[t] !== void 0)
      return this.sourceCache[t].then((l) => l.clone());
    const r = n.images[t], a = self.URL || self.webkitURL;
    let o = r.uri || "", c = !1;
    if (r.bufferView !== void 0)
      o = s.getDependency("bufferView", r.bufferView).then(function(l) {
        c = !0;
        const h = new Blob([l], { type: r.mimeType });
        return o = a.createObjectURL(h), o;
      });
    else if (r.uri === void 0)
      throw new Error("THREE.GLTFLoader: Image " + t + " is missing URI and bufferView");
    const u = Promise.resolve(o).then(function(l) {
      return new Promise(function(h, d) {
        let p = h;
        e.isImageBitmapLoader === !0 && (p = function(T) {
          const m = new te(T);
          m.needsUpdate = !0, h(m);
        }), e.load(G.resolveURL(l, i.path), p, void 0, d);
      });
    }).then(function(l) {
      return c === !0 && a.revokeObjectURL(o), l.userData.mimeType = r.mimeType || Wt(r.uri), l;
    }).catch(function(l) {
      throw console.error("THREE.GLTFLoader: Couldn't load texture", o), l;
    });
    return this.sourceCache[t] = u, u;
  }
  /**
   * Asynchronously assigns a texture to the given material parameters.
   * @param {Object} materialParams
   * @param {string} mapName
   * @param {Object} mapDef
   * @return {Promise<Texture>}
   */
  assignTexture(t, e, s, n) {
    const i = this;
    return this.getDependency("texture", s.index).then(function(r) {
      if (!r)
        return null;
      if (s.texCoord !== void 0 && s.texCoord > 0 && (r = r.clone(), r.channel = s.texCoord), i.extensions[g.KHR_TEXTURE_TRANSFORM]) {
        const a = s.extensions !== void 0 ? s.extensions[g.KHR_TEXTURE_TRANSFORM] : void 0;
        if (a) {
          const o = i.associations.get(r);
          r = i.extensions[g.KHR_TEXTURE_TRANSFORM].extendTexture(r, a), i.associations.set(r, o);
        }
      }
      return n !== void 0 && (r.colorSpace = n), t[e] = r, r;
    });
  }
  /**
   * Assigns final material to a Mesh, Line, or Points instance. The instance
   * already has a material (generated from the glTF material options alone)
   * but reuse of the same glTF material may require multiple threejs materials
   * to accommodate different primitive types, defines, etc. New materials will
   * be created if necessary, and reused from a cache.
   * @param  {Object3D} mesh Mesh, Line, or Points instance.
   */
  assignFinalMaterial(t) {
    const e = t.geometry;
    let s = t.material;
    const n = e.attributes.tangent === void 0, i = e.attributes.color !== void 0, r = e.attributes.normal === void 0;
    if (t.isPoints) {
      const a = "PointsMaterial:" + s.uuid;
      let o = this.cache.get(a);
      o || (o = new Fe(), V.prototype.copy.call(o, s), o.color.copy(s.color), o.map = s.map, o.sizeAttenuation = !1, this.cache.add(a, o)), s = o;
    } else if (t.isLine) {
      const a = "LineBasicMaterial:" + s.uuid;
      let o = this.cache.get(a);
      o || (o = new De(), V.prototype.copy.call(o, s), o.color.copy(s.color), o.map = s.map, this.cache.add(a, o)), s = o;
    }
    if (n || i || r) {
      let a = "ClonedMaterial:" + s.uuid + ":";
      n && (a += "derivative-tangents:"), i && (a += "vertex-colors:"), r && (a += "flat-shading:");
      let o = this.cache.get(a);
      o || (o = s.clone(), i && (o.vertexColors = !0), r && (o.flatShading = !0), n && (o.normalScale && (o.normalScale.y *= -1), o.clearcoatNormalScale && (o.clearcoatNormalScale.y *= -1)), this.cache.add(a, o), this.associations.set(o, this.associations.get(s))), s = o;
    }
    t.material = s;
  }
  getMaterialType() {
    return ge;
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
   * @param {number} materialIndex
   * @return {Promise<Material>}
   */
  loadMaterial(t) {
    const e = this, s = this.json, n = this.extensions, i = s.materials[t];
    let r;
    const a = {}, o = i.extensions || {}, c = [];
    if (o[g.KHR_MATERIALS_UNLIT]) {
      const l = n[g.KHR_MATERIALS_UNLIT];
      r = l.getMaterialType(), c.push(l.extendParams(a, i, e));
    } else {
      const l = i.pbrMetallicRoughness || {};
      if (a.color = new F(1, 1, 1), a.opacity = 1, Array.isArray(l.baseColorFactor)) {
        const h = l.baseColorFactor;
        a.color.setRGB(h[0], h[1], h[2], w), a.opacity = h[3];
      }
      l.baseColorTexture !== void 0 && c.push(e.assignTexture(a, "map", l.baseColorTexture, B)), a.metalness = l.metallicFactor !== void 0 ? l.metallicFactor : 1, a.roughness = l.roughnessFactor !== void 0 ? l.roughnessFactor : 1, l.metallicRoughnessTexture !== void 0 && (c.push(e.assignTexture(a, "metalnessMap", l.metallicRoughnessTexture)), c.push(e.assignTexture(a, "roughnessMap", l.metallicRoughnessTexture))), r = this._invokeOne(function(h) {
        return h.getMaterialType && h.getMaterialType(t);
      }), c.push(Promise.all(this._invokeAll(function(h) {
        return h.extendMaterialParams && h.extendMaterialParams(t, a);
      })));
    }
    i.doubleSided === !0 && (a.side = Pe);
    const u = i.alphaMode || q.OPAQUE;
    if (u === q.BLEND ? (a.transparent = !0, a.depthWrite = !1) : (a.transparent = !1, u === q.MASK && (a.alphaTest = i.alphaCutoff !== void 0 ? i.alphaCutoff : 0.5)), i.normalTexture !== void 0 && r !== H && (c.push(e.assignTexture(a, "normalMap", i.normalTexture)), a.normalScale = new he(1, 1), i.normalTexture.scale !== void 0)) {
      const l = i.normalTexture.scale;
      a.normalScale.set(l, l);
    }
    if (i.occlusionTexture !== void 0 && r !== H && (c.push(e.assignTexture(a, "aoMap", i.occlusionTexture)), i.occlusionTexture.strength !== void 0 && (a.aoMapIntensity = i.occlusionTexture.strength)), i.emissiveFactor !== void 0 && r !== H) {
      const l = i.emissiveFactor;
      a.emissive = new F().setRGB(l[0], l[1], l[2], w);
    }
    return i.emissiveTexture !== void 0 && r !== H && c.push(e.assignTexture(a, "emissiveMap", i.emissiveTexture, B)), Promise.all(c).then(function() {
      const l = new r(a);
      return i.name && (l.name = i.name), O(l, i), e.associations.set(l, { materials: t }), i.extensions && C(n, l, i), l;
    });
  }
  /** When Object3D instances are targeted by animation, they need unique names. */
  createUniqueName(t) {
    const e = ve.sanitizeNodeName(t || "");
    return e in this.nodeNamesUsed ? e + "_" + ++this.nodeNamesUsed[e] : (this.nodeNamesUsed[e] = 0, e);
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
   *
   * Creates BufferGeometries from primitives.
   *
   * @param {Array<GLTF.Primitive>} primitives
   * @return {Promise<Array<BufferGeometry>>}
   */
  loadGeometries(t) {
    const e = this, s = this.extensions, n = this.primitiveCache;
    function i(a) {
      return s[g.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a, e).then(function(o) {
        return ue(o, a, e);
      });
    }
    const r = [];
    for (let a = 0, o = t.length; a < o; a++) {
      const c = t[a], u = zt(c), l = n[u];
      if (l)
        r.push(l.promise);
      else {
        let h;
        c.extensions && c.extensions[g.KHR_DRACO_MESH_COMPRESSION] ? h = i(c) : h = ue(new ke(), c, e), n[u] = { primitive: c, promise: h }, r.push(h);
      }
    }
    return Promise.all(r);
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
   * @param {number} meshIndex
   * @return {Promise<Group|Mesh|SkinnedMesh>}
   */
  loadMesh(t) {
    const e = this, s = this.json, n = this.extensions, i = s.meshes[t], r = i.primitives, a = [];
    for (let o = 0, c = r.length; o < c; o++) {
      const u = r[o].material === void 0 ? Kt(this.cache) : this.getDependency("material", r[o].material);
      a.push(u);
    }
    return a.push(e.loadGeometries(r)), Promise.all(a).then(function(o) {
      const c = o.slice(0, o.length - 1), u = o[o.length - 1], l = [];
      for (let d = 0, p = u.length; d < p; d++) {
        const T = u[d], m = r[d];
        let A;
        const x = c[d];
        if (m.mode === _.TRIANGLES || m.mode === _.TRIANGLE_STRIP || m.mode === _.TRIANGLE_FAN || m.mode === void 0)
          A = i.isSkinnedMesh === !0 ? new He(T, x) : new Ge(T, x), A.isSkinnedMesh === !0 && A.normalizeSkinWeights(), m.mode === _.TRIANGLE_STRIP ? A.geometry = re(A.geometry, le) : m.mode === _.TRIANGLE_FAN && (A.geometry = re(A.geometry, Q));
        else if (m.mode === _.LINES)
          A = new Be(T, x);
        else if (m.mode === _.LINE_STRIP)
          A = new Ue(T, x);
        else if (m.mode === _.LINE_LOOP)
          A = new je(T, x);
        else if (m.mode === _.POINTS)
          A = new Ke(T, x);
        else
          throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + m.mode);
        Object.keys(A.geometry.morphAttributes).length > 0 && Xt(A, i), A.name = e.createUniqueName(i.name || "mesh_" + t), O(A, i), m.extensions && C(n, A, m), e.assignFinalMaterial(A), l.push(A);
      }
      for (let d = 0, p = l.length; d < p; d++)
        e.associations.set(l[d], {
          meshes: t,
          primitives: d
        });
      if (l.length === 1)
        return i.extensions && C(n, l[0], i), l[0];
      const h = new X();
      i.extensions && C(n, h, i), e.associations.set(h, { meshes: t });
      for (let d = 0, p = l.length; d < p; d++)
        h.add(l[d]);
      return h;
    });
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
   * @param {number} cameraIndex
   * @return {Promise<THREE.Camera>}
   */
  loadCamera(t) {
    let e;
    const s = this.json.cameras[t], n = s[s.type];
    if (!n) {
      console.warn("THREE.GLTFLoader: Missing camera parameters.");
      return;
    }
    return s.type === "perspective" ? e = new Ve(Xe.radToDeg(n.yfov), n.aspectRatio || 1, n.znear || 1, n.zfar || 2e6) : s.type === "orthographic" && (e = new ze(-n.xmag, n.xmag, n.ymag, -n.ymag, n.znear, n.zfar)), s.name && (e.name = this.createUniqueName(s.name)), O(e, s), Promise.resolve(e);
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
   * @param {number} skinIndex
   * @return {Promise<Skeleton>}
   */
  loadSkin(t) {
    const e = this.json.skins[t], s = [];
    for (let n = 0, i = e.joints.length; n < i; n++)
      s.push(this._loadNodeShallow(e.joints[n]));
    return e.inverseBindMatrices !== void 0 ? s.push(this.getDependency("accessor", e.inverseBindMatrices)) : s.push(null), Promise.all(s).then(function(n) {
      const i = n.pop(), r = n, a = [], o = [];
      for (let c = 0, u = r.length; c < u; c++) {
        const l = r[c];
        if (l) {
          a.push(l);
          const h = new U();
          i !== null && h.fromArray(i.array, c * 16), o.push(h);
        } else
          console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', e.joints[c]);
      }
      return new We(a, o);
    });
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
   * @param {number} animationIndex
   * @return {Promise<AnimationClip>}
   */
  loadAnimation(t) {
    const e = this.json, s = this, n = e.animations[t], i = n.name ? n.name : "animation_" + t, r = [], a = [], o = [], c = [], u = [];
    for (let l = 0, h = n.channels.length; l < h; l++) {
      const d = n.channels[l], p = n.samplers[d.sampler], T = d.target, m = T.node, A = n.parameters !== void 0 ? n.parameters[p.input] : p.input, x = n.parameters !== void 0 ? n.parameters[p.output] : p.output;
      T.node !== void 0 && (r.push(this.getDependency("node", m)), a.push(this.getDependency("accessor", A)), o.push(this.getDependency("accessor", x)), c.push(p), u.push(T));
    }
    return Promise.all([
      Promise.all(r),
      Promise.all(a),
      Promise.all(o),
      Promise.all(c),
      Promise.all(u)
    ]).then(function(l) {
      const h = l[0], d = l[1], p = l[2], T = l[3], m = l[4], A = [];
      for (let x = 0, E = h.length; x < E; x++) {
        const R = h[x], S = d[x], b = p[x], L = T[x], v = m[x];
        if (R === void 0)
          continue;
        R.updateMatrix && R.updateMatrix();
        const N = s._createAnimationTracks(R, S, b, L, v);
        if (N)
          for (let j = 0; j < N.length; j++)
            A.push(N[j]);
      }
      return new qe(i, void 0, A);
    });
  }
  createNodeMesh(t) {
    const e = this.json, s = this, n = e.nodes[t];
    return n.mesh === void 0 ? null : s.getDependency("mesh", n.mesh).then(function(i) {
      const r = s._getNodeRef(s.meshCache, n.mesh, i);
      return n.weights !== void 0 && r.traverse(function(a) {
        if (a.isMesh)
          for (let o = 0, c = n.weights.length; o < c; o++)
            a.morphTargetInfluences[o] = n.weights[o];
      }), r;
    });
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
   * @param {number} nodeIndex
   * @return {Promise<Object3D>}
   */
  loadNode(t) {
    const e = this.json, s = this, n = e.nodes[t], i = s._loadNodeShallow(t), r = [], a = n.children || [];
    for (let c = 0, u = a.length; c < u; c++)
      r.push(s.getDependency("node", a[c]));
    const o = n.skin === void 0 ? Promise.resolve(null) : s.getDependency("skin", n.skin);
    return Promise.all([
      i,
      Promise.all(r),
      o
    ]).then(function(c) {
      const u = c[0], l = c[1], h = c[2];
      h !== null && u.traverse(function(d) {
        d.isSkinnedMesh && d.bind(h, qt);
      });
      for (let d = 0, p = l.length; d < p; d++)
        u.add(l[d]);
      return u;
    });
  }
  // ._loadNodeShallow() parses a single node.
  // skin and child nodes are created and added in .loadNode() (no '_' prefix).
  _loadNodeShallow(t) {
    const e = this.json, s = this.extensions, n = this;
    if (this.nodeCache[t] !== void 0)
      return this.nodeCache[t];
    const i = e.nodes[t], r = i.name ? n.createUniqueName(i.name) : "", a = [], o = n._invokeOne(function(c) {
      return c.createNodeMesh && c.createNodeMesh(t);
    });
    return o && a.push(o), i.camera !== void 0 && a.push(n.getDependency("camera", i.camera).then(function(c) {
      return n._getNodeRef(n.cameraCache, i.camera, c);
    })), n._invokeAll(function(c) {
      return c.createNodeAttachment && c.createNodeAttachment(t);
    }).forEach(function(c) {
      a.push(c);
    }), this.nodeCache[t] = Promise.all(a).then(function(c) {
      let u;
      if (i.isBone === !0 ? u = new Ye() : c.length > 1 ? u = new X() : c.length === 1 ? u = c[0] : u = new de(), u !== c[0])
        for (let l = 0, h = c.length; l < h; l++)
          u.add(c[l]);
      if (i.name && (u.userData.name = i.name, u.name = r), O(u, i), i.extensions && C(s, u, i), i.matrix !== void 0) {
        const l = new U();
        l.fromArray(i.matrix), u.applyMatrix4(l);
      } else
        i.translation !== void 0 && u.position.fromArray(i.translation), i.rotation !== void 0 && u.quaternion.fromArray(i.rotation), i.scale !== void 0 && u.scale.fromArray(i.scale);
      return n.associations.has(u) || n.associations.set(u, {}), n.associations.get(u).nodes = t, u;
    }), this.nodeCache[t];
  }
  /**
   * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
   * @param {number} sceneIndex
   * @return {Promise<Group>}
   */
  loadScene(t) {
    const e = this.extensions, s = this.json.scenes[t], n = this, i = new X();
    s.name && (i.name = n.createUniqueName(s.name)), O(i, s), s.extensions && C(e, i, s);
    const r = s.nodes || [], a = [];
    for (let o = 0, c = r.length; o < c; o++)
      a.push(n.getDependency("node", r[o]));
    return Promise.all(a).then(function(o) {
      for (let u = 0, l = o.length; u < l; u++)
        i.add(o[u]);
      const c = (u) => {
        const l = /* @__PURE__ */ new Map();
        for (const [h, d] of n.associations)
          (h instanceof V || h instanceof te) && l.set(h, d);
        return u.traverse((h) => {
          const d = n.associations.get(h);
          d != null && l.set(h, d);
        }), l;
      };
      return n.associations = c(i), i;
    });
  }
  _createAnimationTracks(t, e, s, n, i) {
    const r = [], a = t.name ? t.name : t.uuid, o = [];
    I[i.path] === I.weights ? t.traverse(function(h) {
      h.morphTargetInfluences && o.push(h.name ? h.name : h.uuid);
    }) : o.push(a);
    let c;
    switch (I[i.path]) {
      case I.weights:
        c = se;
        break;
      case I.rotation:
        c = ie;
        break;
      case I.position:
      case I.scale:
        c = ne;
        break;
      default:
        switch (s.itemSize) {
          case 1:
            c = se;
            break;
          case 2:
          case 3:
          default:
            c = ne;
            break;
        }
        break;
    }
    const u = n.interpolation !== void 0 ? jt[n.interpolation] : Ae, l = this._getArrayFromAccessor(s);
    for (let h = 0, d = o.length; h < d; h++) {
      const p = new c(
        o[h] + "." + I[i.path],
        e.array,
        l,
        u
      );
      n.interpolation === "CUBICSPLINE" && this._createCubicSplineTrackInterpolant(p), r.push(p);
    }
    return r;
  }
  _getArrayFromAccessor(t) {
    let e = t.array;
    if (t.normalized) {
      const s = $(e.constructor), n = new Float32Array(e.length);
      for (let i = 0, r = e.length; i < r; i++)
        n[i] = e[i] * s;
      e = n;
    }
    return e;
  }
  _createCubicSplineTrackInterpolant(t) {
    t.createInterpolant = function(s) {
      const n = this instanceof ie ? Ut : xe;
      return new n(this.times, this.values, this.getValueSize() / 3, s);
    }, t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = !0;
  }
}
function Qt(f, t, e) {
  const s = t.attributes, n = new rt();
  if (s.POSITION !== void 0) {
    const a = e.json.accessors[s.POSITION], o = a.min, c = a.max;
    if (o !== void 0 && c !== void 0) {
      if (n.set(
        new D(o[0], o[1], o[2]),
        new D(c[0], c[1], c[2])
      ), a.normalized) {
        const u = $(P[a.componentType]);
        n.min.multiplyScalar(u), n.max.multiplyScalar(u);
      }
    } else {
      console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
      return;
    }
  } else
    return;
  const i = t.targets;
  if (i !== void 0) {
    const a = new D(), o = new D();
    for (let c = 0, u = i.length; c < u; c++) {
      const l = i[c];
      if (l.POSITION !== void 0) {
        const h = e.json.accessors[l.POSITION], d = h.min, p = h.max;
        if (d !== void 0 && p !== void 0) {
          if (o.setX(Math.max(Math.abs(d[0]), Math.abs(p[0]))), o.setY(Math.max(Math.abs(d[1]), Math.abs(p[1]))), o.setZ(Math.max(Math.abs(d[2]), Math.abs(p[2]))), h.normalized) {
            const T = $(P[h.componentType]);
            o.multiplyScalar(T);
          }
          a.max(o);
        } else
          console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
      }
    }
    n.expandByVector(a);
  }
  f.boundingBox = n;
  const r = new ot();
  n.getCenter(r.center), r.radius = n.min.distanceTo(n.max) / 2, f.boundingSphere = r;
}
function ue(f, t, e) {
  const s = t.attributes, n = [];
  function i(r, a) {
    return e.getDependency("accessor", r).then(function(o) {
      f.setAttribute(a, o);
    });
  }
  for (const r in s) {
    const a = J[r] || r.toLowerCase();
    a in f.attributes || n.push(i(s[r], a));
  }
  if (t.indices !== void 0 && !f.index) {
    const r = e.getDependency("accessor", t.indices).then(function(a) {
      f.setIndex(a);
    });
    n.push(r);
  }
  return ee.workingColorSpace !== w && "COLOR_0" in s && console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ee.workingColorSpace}" not supported.`), O(f, t), Qt(f, t, e), Promise.all(n).then(function() {
    return t.targets !== void 0 ? Vt(f, t.targets, e) : f;
  });
}
class on {
  constructor(t) {
    M(this, "previousAction");
    M(this, "activeAction");
    M(this, "isAnimating", !1);
    M(this, "lastCloseTime", /* @__PURE__ */ new Date());
    M(this, "configs");
    M(this, "loader");
    M(this, "currentVrm");
    M(this, "mixer");
    M(this, "ik");
    M(this, "noise");
    this.configs = t;
    const e = new At();
    e.register((s) => new lt(s)), this.loader = e;
  }
  updateModelConfigs(t) {
    var e;
    this.currentVrm && ((e = this.currentVrm.springBoneManager) == null || e.joints.forEach((s) => {
      const n = t == null ? void 0 : t[s.bone.name];
      n != null && n.stiffness && (s.settings.stiffness = n.stiffness), n != null && n.dragForce && (s.settings.dragForce = n.dragForce), n != null && n.hitRadius && (s.settings.hitRadius = n.hitRadius);
    }));
  }
  /**
   * Load VRM model
   */
  loadModel() {
    this.currentVrm = void 0, this.loader.load(
      // URL of the VRM you want to load
      this.configs.vrmUrl,
      // called when the resource is loaded
      (t) => {
        var r, a, o;
        const e = t.userData.vrm;
        if (!e)
          return;
        e == null || e.scene.traverse((c) => {
          c.frustumCulled = !1;
        }), e.humanoid.resetNormalizedPose(), z.rotateVRM0(e), z.removeUnnecessaryJoints(e.scene), z.removeUnnecessaryVertices(e.scene), e.lookAt && (e.lookAt.target = this.configs.camera, e.lookAt.autoUpdate = !0), this.currentVrm = e;
        const s = pt.get(this.currentVrm);
        this.ik = s;
        const n = mt.get(this.currentVrm);
        this.noise = n, (r = e.springBoneManager) == null || r.joints.forEach((c) => {
          var l;
          const u = (l = this.configs.modelConfigs) == null ? void 0 : l[c.bone.name];
          u != null && u.stiffness && (c.settings.stiffness = u.stiffness), u != null && u.dragForce && (c.settings.dragForce = u.dragForce), u != null && u.hitRadius && (c.settings.hitRadius = u.hitRadius);
        }), (a = this.configs) != null && a.onLoad && ((o = this.configs) == null || o.onLoad(e));
        const i = new ct(e.scene);
        this.mixer = i, i.addEventListener("finished", () => {
          setTimeout(() => {
            this.isAnimating = !1;
          }, 1e3), this.fadeToAnimationUrl(
            "https://react-virtual-ai.s3.ap-southeast-1.amazonaws.com/idle.vmd",
            !0
          );
        }), this.fadeToAnimationUrl(
          "https://react-virtual-ai.s3.ap-southeast-1.amazonaws.com/idle.vmd",
          !0
        ), setTimeout(() => {
          var c, u;
          (u = (c = this.configs).onLoadProgress) == null || u.call(c, 100);
        }, 1e3);
      },
      // called while loading is progressing
      (t) => {
        var s, n;
        let e = 100 * (t.loaded / t.total);
        e >= 100 && (e = 99), (n = (s = this.configs).onLoadProgress) == null || n.call(s, e);
      },
      // called when loading has errors
      (t) => {
        var e, s, n, i;
        console.error(t), (s = (e = this.configs).onLoadErr) == null || s.call(e, t), (i = (n = this.configs).onLoadProgress) == null || i.call(n, 0);
      }
    );
  }
  /**
   * Fade to target animation URL
   * @param url VMD / Mixamo FBX Animation. Other formats are not supported at the moment
   * @param loop Whether to loop the selected animation or not
   * @returns
   */
  async fadeToAnimationUrl(t, e) {
    var r, a, o;
    if (!this.mixer || !this.currentVrm || !((r = this.configs) != null && r.vrmUrl))
      return;
    let s;
    if (t.includes(".fbx"))
      s = await ft(t, this.currentVrm);
    else {
      const c = await fetch(t);
      s = ht(
        dt(await c.arrayBuffer(), this.currentVrm),
        this.currentVrm
      );
    }
    const n = `${t}_${this.configs.vrmUrl}`;
    if (s.name = n, !s || this.activeAction && this.activeAction.getClip().name === n)
      return;
    if (this.previousAction && this.previousAction.getClip().name !== n) {
      this.previousAction.fadeOut(1), this.previousAction = void 0, gt(() => {
        this.fadeToAnimationUrl(t, e);
      }, 0);
      return;
    }
    const i = this.mixer.clipAction(s);
    i && (this.activeAction = i, this.activeAction.clampWhenFinished = !0, e ? (this.isAnimating = !1, (a = this.activeAction) == null || a.reset().setEffectiveTimeScale(1).setEffectiveWeight(1).fadeIn(1).play()) : (this.isAnimating = !0, (o = this.activeAction) == null || o.reset().setEffectiveTimeScale(1).setEffectiveWeight(1).fadeIn(1).setLoop(ut, 1).play()), this.previousAction = this.activeAction);
  }
}
export {
  on as VrmService
};
