@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
1,274 lines (1,273 loc) • 368 kB
JavaScript
import { Mesh as X, SphereGeometry as Fs, Vector3 as U, MeshBasicMaterial as gt, NodeFrame as ur, PerspectiveCamera as Zn, ShaderLib as dt, ExtrudeGeometry as pr, Loader as Yt, FileLoader as an, ShapePath as fr, TrianglesDrawMode as dr, TriangleFanDrawMode as xs, TriangleStripDrawMode as ji, LoaderUtils as jt, MeshPhysicalMaterial as xt, Vector2 as Ne, Color as Ie, LinearSRGBColorSpace as ot, SRGBColorSpace as ye, SpotLight as Xi, PointLight as vs, DirectionalLight as Vi, Matrix4 as le, InstancedMesh as mr, Quaternion as Se, InstancedBufferAttribute as gr, Object3D as yt, TextureLoader as Us, ImageBitmapLoader as yr, BufferAttribute as ct, InterleavedBuffer as wr, LinearMipmapLinearFilter as ks, NearestMipmapLinearFilter as Yi, LinearMipmapNearestFilter as Wi, NearestMipmapNearestFilter as Zi, LinearFilter as bt, NearestFilter as Ki, RepeatWrapping as Wt, MirroredRepeatWrapping as qi, ClampToEdgeWrapping as Yn, PointsMaterial as xn, Material as An, LineBasicMaterial as At, MeshStandardMaterial as Bs, DoubleSide as Hs, PropertyBinding as St, BufferGeometry as lt, SkinnedMesh as Qi, LineSegments as Wn, Line as at, LineLoop as xr, Points as zn, Group as Xt, MathUtils as Ee, OrthographicCamera as $i, Skeleton as Ji, AnimationClip as eo, Bone as Ts, InterpolateDiscrete as to, InterpolateLinear as zs, InterleavedBufferAttribute as Gt, Texture as Es, VectorKeyframeTrack as _s, NumberKeyframeTrack as As, QuaternionKeyframeTrack as bs, ColorManagement as Qe, FrontSide as no, Interpolant as vr, Box3 as Kn, Sphere as Gs, CylinderGeometry as Xe, BoxGeometry as Ge, Float32BufferAttribute as De, OctahedronGeometry as Ln, TorusGeometry as hn, Euler as Dt, Controls as so, Raycaster as js, PlaneGeometry as Xs, DataTextureLoader as io, HalfFloatType as Ot, FloatType as sn, RGBAFormat as oo, RedFormat as Tr, NoColorSpace as ro, DataUtils as tn, Vector4 as Mt, Curve as Er, MeshPhongMaterial as bn, MeshLambertMaterial as _r, EquirectangularReflectionMapping as Ar, AmbientLight as br, Uint16BufferAttribute as Sr, Matrix3 as ao, ShapeUtils as Mr, DefaultLoadingManager as Ir, MOUSE as on, TOUCH as nn, Spherical as ti, Ray as Rr, Plane as Lr, ShaderMaterial as co, Uniform$1 as Pr, Scene as Ss, WebGLRenderer as Cr, CanvasTexture as lo, REVISION as Dr, CompressedTexture as es, Source as Or, InstancedBufferGeometry as Nr, InstancedInterleavedBuffer as Ms, WireframeGeometry as Fr, UniformsUtils as ho, UniformsLib as Gn, Line3 as Ur } from "./three.js";
class El extends X {
constructor(e, t, s, n = 128) {
if (t <= 0 || s <= 0 || n <= 0)
throw new Error("GroundedSkybox height, radius, and resolution must be positive.");
const i = new Fs(s, 2 * n, n);
i.scale(1, 1, -1);
const o = i.getAttribute("position"), r = new U();
for (let a = 0; a < o.count; ++a)
if (r.fromBufferAttribute(o, a), r.y < 0) {
const l = -t * 3 / 2, h = r.y < l ? -t / r.y : 1 - r.y * r.y / (3 * l * l);
r.multiplyScalar(h), r.toArray(o.array, 3 * a);
}
o.needsUpdate = !0, super(i, new gt({ map: e, depthWrite: !1 }));
}
}
const kr = new ur();
kr.camera = new Zn();
dt.basic, dt.basic, dt.points, dt.standard, dt.physical, dt.phong;
var jn = function() {
var c = 0, e = document.createElement("div");
e.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", e.addEventListener("click", function(h) {
h.preventDefault(), s(++c % e.children.length);
}, !1);
function t(h) {
return e.appendChild(h.dom), h;
}
function s(h) {
for (var u = 0; u < e.children.length; u++)
e.children[u].style.display = u === h ? "block" : "none";
c = h;
}
var n = (performance || Date).now(), i = n, o = 0, r = t(new jn.Panel("FPS", "#0ff", "#002")), a = t(new jn.Panel("MS", "#0f0", "#020"));
if (self.performance && self.performance.memory)
var l = t(new jn.Panel("MB", "#f08", "#201"));
return s(0), {
REVISION: 16,
dom: e,
addPanel: t,
showPanel: s,
begin: function() {
n = (performance || Date).now();
},
end: function() {
o++;
var h = (performance || Date).now();
if (a.update(h - n, 200), h >= i + 1e3 && (r.update(o * 1e3 / (h - i), 100), i = h, o = 0, l)) {
var u = performance.memory;
l.update(u.usedJSHeapSize / 1048576, u.jsHeapSizeLimit / 1048576);
}
return h;
},
update: function() {
n = this.end();
},
// Backwards Compatibility
domElement: e,
setMode: s
};
};
jn.Panel = function(c, e, t) {
var s = 1 / 0, n = 0, i = Math.round, o = i(window.devicePixelRatio || 1), r = 80 * o, a = 48 * o, l = 3 * o, h = 2 * o, u = 3 * o, f = 15 * o, d = 74 * o, g = 30 * o, w = document.createElement("canvas");
w.width = r, w.height = a, w.style.cssText = "width:80px;height:48px";
var y = w.getContext("2d");
return y.font = "bold " + 9 * o + "px Helvetica,Arial,sans-serif", y.textBaseline = "top", y.fillStyle = t, y.fillRect(0, 0, r, a), y.fillStyle = e, y.fillText(c, l, h), y.fillRect(u, f, d, g), y.fillStyle = t, y.globalAlpha = 0.9, y.fillRect(u, f, d, g), {
dom: w,
update: function(v, I) {
s = Math.min(s, v), n = Math.max(n, v), y.fillStyle = t, y.globalAlpha = 1, y.fillRect(0, 0, r, f), y.fillStyle = e, y.fillText(i(v) + " " + c + " (" + i(s) + "-" + i(n) + ")", l, h), y.drawImage(w, u + o, f, d - o, g, u, f, d - o, g), y.fillRect(u + d - o, f, o, g), y.fillStyle = t, y.globalAlpha = 0.9, y.fillRect(u + d - o, f, o, i((1 - v / I) * g));
}
};
};
class _l extends pr {
constructor(e, t = {}) {
const s = t.font;
if (s === void 0)
super();
else {
const n = s.generateShapes(e, t.size);
t.depth === void 0 && t.height !== void 0 && console.warn("THREE.TextGeometry: .height is now depreciated. Please use .depth instead"), t.depth = t.depth !== void 0 ? t.depth : t.height !== void 0 ? t.height : 50, t.bevelThickness === void 0 && (t.bevelThickness = 10), t.bevelSize === void 0 && (t.bevelSize = 8), t.bevelEnabled === void 0 && (t.bevelEnabled = !1), super(n, t);
}
this.type = "TextGeometry";
}
}
class Al extends Yt {
constructor(e) {
super(e);
}
load(e, t, s, n) {
const i = this, o = new an(this.manager);
o.setPath(this.path), o.setRequestHeader(this.requestHeader), o.setWithCredentials(this.withCredentials), o.load(e, function(r) {
const a = i.parse(JSON.parse(r));
t && t(a);
}, s, n);
}
parse(e) {
return new Br(e);
}
}
class Br {
constructor(e) {
this.isFont = !0, this.type = "Font", this.data = e;
}
generateShapes(e, t = 100) {
const s = [], n = Hr(e, t, this.data);
for (let i = 0, o = n.length; i < o; i++)
s.push(...n[i].toShapes());
return s;
}
}
function Hr(c, e, t) {
const s = Array.from(c), n = e / t.resolution, i = (t.boundingBox.yMax - t.boundingBox.yMin + t.underlineThickness) * n, o = [];
let r = 0, a = 0;
for (let l = 0; l < s.length; l++) {
const h = s[l];
if (h === `
`)
r = 0, a -= i;
else {
const u = zr(h, n, r, a, t);
r += u.offsetX, o.push(u.path);
}
}
return o;
}
function zr(c, e, t, s, n) {
const i = n.glyphs[c] || n.glyphs["?"];
if (!i) {
console.error('THREE.Font: character "' + c + '" does not exists in font family ' + n.familyName + ".");
return;
}
const o = new fr();
let r, a, l, h, u, f, d, g;
if (i.o) {
const w = i._cachedOutline || (i._cachedOutline = i.o.split(" "));
for (let y = 0, v = w.length; y < v; )
switch (w[y++]) {
case "m":
r = w[y++] * e + t, a = w[y++] * e + s, o.moveTo(r, a);
break;
case "l":
r = w[y++] * e + t, a = w[y++] * e + s, o.lineTo(r, a);
break;
case "q":
l = w[y++] * e + t, h = w[y++] * e + s, u = w[y++] * e + t, f = w[y++] * e + s, o.quadraticCurveTo(u, f, l, h);
break;
case "b":
l = w[y++] * e + t, h = w[y++] * e + s, u = w[y++] * e + t, f = w[y++] * e + s, d = w[y++] * e + t, g = w[y++] * e + s, o.bezierCurveTo(u, f, d, g, l, h);
break;
}
}
return { offsetX: i.ha * e, path: o };
}
function bl(c, e = 1e-4) {
e = Math.max(e, Number.EPSILON);
const t = {}, s = c.getIndex(), n = c.getAttribute("position"), i = s ? s.count : n.count;
let o = 0;
const r = Object.keys(c.attributes), a = {}, l = {}, h = [], u = ["getX", "getY", "getZ", "getW"], f = ["setX", "setY", "setZ", "setW"];
for (let I = 0, T = r.length; I < T; I++) {
const b = r[I], S = c.attributes[b];
a[b] = new S.constructor(
new S.array.constructor(S.count * S.itemSize),
S.itemSize,
S.normalized
);
const N = c.morphAttributes[b];
N && (l[b] || (l[b] = []), N.forEach((O, A) => {
const R = new O.array.constructor(O.count * O.itemSize);
l[b][A] = new O.constructor(R, O.itemSize, O.normalized);
}));
}
const d = e * 0.5, g = Math.log10(1 / e), w = Math.pow(10, g), y = d * w;
for (let I = 0; I < i; I++) {
const T = s ? s.getX(I) : I;
let b = "";
for (let S = 0, N = r.length; S < N; S++) {
const O = r[S], A = c.getAttribute(O), R = A.itemSize;
for (let z = 0; z < R; z++)
b += `${~~(A[u[z]](T) * w + y)},`;
}
if (b in t)
h.push(t[b]);
else {
for (let S = 0, N = r.length; S < N; S++) {
const O = r[S], A = c.getAttribute(O), R = c.morphAttributes[O], z = A.itemSize, B = a[O], j = l[O];
for (let J = 0; J < z; J++) {
const k = u[J], K = f[J];
if (B[K](o, A[k](T)), R)
for (let G = 0, $ = R.length; G < $; G++)
j[G][K](o, R[G][k](T));
}
}
t[b] = o, h.push(o), o++;
}
}
const v = c.clone();
for (const I in c.attributes) {
const T = a[I];
if (v.setAttribute(I, new T.constructor(
T.array.slice(0, o * T.itemSize),
T.itemSize,
T.normalized
)), I in l)
for (let b = 0; b < l[I].length; b++) {
const S = l[I][b];
v.morphAttributes[I][b] = new S.constructor(
S.array.slice(0, o * S.itemSize),
S.itemSize,
S.normalized
);
}
}
return v.setIndex(h), v;
}
function ni(c, e) {
if (e === dr)
return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), c;
if (e === xs || e === ji) {
let t = c.getIndex();
if (t === null) {
const o = [], r = c.getAttribute("position");
if (r !== void 0) {
for (let a = 0; a < r.count; a++)
o.push(a);
c.setIndex(o), t = c.getIndex();
} else
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), c;
}
const s = t.count - 2, n = [];
if (e === xs)
for (let o = 1; o <= s; o++)
n.push(t.getX(0)), n.push(t.getX(o)), n.push(t.getX(o + 1));
else
for (let o = 0; o < s; o++)
o % 2 === 0 ? (n.push(t.getX(o)), n.push(t.getX(o + 1)), n.push(t.getX(o + 2))) : (n.push(t.getX(o + 2)), n.push(t.getX(o + 1)), n.push(t.getX(o)));
n.length / 3 !== s && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
const i = c.clone();
return i.setIndex(n), i.clearGroups(), i;
} else
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", e), c;
}
class uo extends Yt {
constructor(e) {
super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(t) {
return new Yr(t);
}), this.register(function(t) {
return new Wr(t);
}), this.register(function(t) {
return new na(t);
}), this.register(function(t) {
return new sa(t);
}), this.register(function(t) {
return new ia(t);
}), this.register(function(t) {
return new Kr(t);
}), this.register(function(t) {
return new qr(t);
}), this.register(function(t) {
return new Qr(t);
}), this.register(function(t) {
return new $r(t);
}), this.register(function(t) {
return new Vr(t);
}), this.register(function(t) {
return new Jr(t);
}), this.register(function(t) {
return new Zr(t);
}), this.register(function(t) {
return new ta(t);
}), this.register(function(t) {
return new ea(t);
}), this.register(function(t) {
return new jr(t);
}), this.register(function(t) {
return new oa(t);
}), this.register(function(t) {
return new ra(t);
});
}
load(e, t, s, n) {
const i = this;
let o;
if (this.resourcePath !== "")
o = this.resourcePath;
else if (this.path !== "") {
const l = jt.extractUrlBase(e);
o = jt.resolveURL(l, this.path);
} else
o = jt.extractUrlBase(e);
this.manager.itemStart(e);
const r = function(l) {
n ? n(l) : console.error(l), i.manager.itemError(e), i.manager.itemEnd(e);
}, a = new an(this.manager);
a.setPath(this.path), a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setWithCredentials(this.withCredentials), a.load(e, function(l) {
try {
i.parse(l, o, function(h) {
t(h), i.manager.itemEnd(e);
}, r);
} catch (h) {
r(h);
}
}, s, r);
}
setDRACOLoader(e) {
return this.dracoLoader = e, this;
}
setKTX2Loader(e) {
return this.ktx2Loader = e, this;
}
setMeshoptDecoder(e) {
return this.meshoptDecoder = e, this;
}
register(e) {
return this.pluginCallbacks.indexOf(e) === -1 && this.pluginCallbacks.push(e), this;
}
unregister(e) {
return this.pluginCallbacks.indexOf(e) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this;
}
parse(e, t, s, n) {
let i, o;
const r = {}, a = {}, l = new TextDecoder();
if (typeof e == "string")
try {
i = JSON.parse(e);
} catch (u) {
o = e, n && n(u);
return;
}
else if (e instanceof ArrayBuffer)
if (l.decode(new Uint8Array(e, 0, 4)) === po) {
try {
r[se.KHR_BINARY_GLTF] = new aa(e);
} catch (f) {
n && n(f);
return;
}
try {
i = JSON.parse(r[se.KHR_BINARY_GLTF].content);
} catch (f) {
o = r[se.KHR_BINARY_GLTF].content, n && n(f);
return;
}
} else
try {
i = JSON.parse(l.decode(e));
} catch (f) {
o = l.decode(e), n && n(f);
return;
}
else
i = e;
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;
}
this.json = i, this.jsonErrorData = o;
const h = new va(i, {
path: t || this.resourcePath || "",
crossOrigin: this.crossOrigin,
requestHeader: this.requestHeader,
manager: this.manager,
ktx2Loader: this.ktx2Loader,
meshoptDecoder: this.meshoptDecoder
});
h.fileLoader.setRequestHeader(this.requestHeader);
for (let u = 0; u < this.pluginCallbacks.length; u++) {
const f = this.pluginCallbacks[u](h);
f.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[f.name] = f, r[f.name] = !0;
}
if (i.extensionsUsed)
for (let u = 0; u < i.extensionsUsed.length; ++u) {
const f = i.extensionsUsed[u], d = i.extensionsRequired || [];
switch (f) {
case se.KHR_MATERIALS_UNLIT:
r[f] = new Xr();
break;
case se.KHR_DRACO_MESH_COMPRESSION:
r[f] = new ca(i, this.dracoLoader);
break;
case se.KHR_TEXTURE_TRANSFORM:
r[f] = new la();
break;
case se.KHR_MESH_QUANTIZATION:
r[f] = new ha();
break;
default:
d.indexOf(f) >= 0 && a[f] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + f + '".');
}
}
h.setExtensions(r), h.setPlugins(a), h.parse(s, n);
}
parseAsync(e, t) {
const s = this;
return new Promise(function(n, i) {
s.parse(e, t, n, i);
});
}
}
function Gr() {
let c = {};
return {
get: function(e) {
return c[e];
},
add: function(e, t) {
c[e] = t;
},
remove: function(e) {
delete c[e];
},
removeAll: function() {
c = {};
}
};
}
const se = {
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_DISPERSION: "KHR_materials_dispersion",
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 jr {
constructor(e) {
this.parser = e, this.name = se.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} };
}
_markDefs() {
const e = this.parser, t = this.parser.json.nodes || [];
for (let s = 0, n = t.length; s < n; s++) {
const i = t[s];
i.extensions && i.extensions[this.name] && i.extensions[this.name].light !== void 0 && e._addNodeRef(this.cache, i.extensions[this.name].light);
}
}
_loadLight(e) {
const t = this.parser, s = "light:" + e;
let n = t.cache.get(s);
if (n) return n;
const i = t.json, a = ((i.extensions && i.extensions[this.name] || {}).lights || [])[e];
let l;
const h = new Ie(16777215);
a.color !== void 0 && h.setRGB(a.color[0], a.color[1], a.color[2], ot);
const u = a.range !== void 0 ? a.range : 0;
switch (a.type) {
case "directional":
l = new Vi(h), l.target.position.set(0, 0, -1), l.add(l.target);
break;
case "point":
l = new vs(h), l.distance = u;
break;
case "spot":
l = new Xi(h), l.distance = u, a.spot = a.spot || {}, a.spot.innerConeAngle = a.spot.innerConeAngle !== void 0 ? a.spot.innerConeAngle : 0, a.spot.outerConeAngle = a.spot.outerConeAngle !== void 0 ? a.spot.outerConeAngle : Math.PI / 4, l.angle = a.spot.outerConeAngle, l.penumbra = 1 - a.spot.innerConeAngle / a.spot.outerConeAngle, l.target.position.set(0, 0, -1), l.add(l.target);
break;
default:
throw new Error("THREE.GLTFLoader: Unexpected light type: " + a.type);
}
return l.position.set(0, 0, 0), l.decay = 2, _t(l, a), a.intensity !== void 0 && (l.intensity = a.intensity), l.name = t.createUniqueName(a.name || "light_" + e), n = Promise.resolve(l), t.cache.add(s, n), n;
}
getDependency(e, t) {
if (e === "light")
return this._loadLight(t);
}
createNodeAttachment(e) {
const t = this, s = this.parser, i = s.json.nodes[e], r = (i.extensions && i.extensions[this.name] || {}).light;
return r === void 0 ? null : this._loadLight(r).then(function(a) {
return s._getNodeRef(t.cache, r, a);
});
}
}
let Xr = class {
constructor() {
this.name = se.KHR_MATERIALS_UNLIT;
}
getMaterialType() {
return gt;
}
extendParams(e, t, s) {
const n = [];
e.color = new Ie(1, 1, 1), e.opacity = 1;
const i = t.pbrMetallicRoughness;
if (i) {
if (Array.isArray(i.baseColorFactor)) {
const o = i.baseColorFactor;
e.color.setRGB(o[0], o[1], o[2], ot), e.opacity = o[3];
}
i.baseColorTexture !== void 0 && n.push(s.assignTexture(e, "map", i.baseColorTexture, ye));
}
return Promise.all(n);
}
}, Vr = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_EMISSIVE_STRENGTH;
}
extendMaterialParams(e, t) {
const n = this.parser.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = n.extensions[this.name].emissiveStrength;
return i !== void 0 && (t.emissiveIntensity = i), Promise.resolve();
}
}, Yr = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_CLEARCOAT;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
if (o.clearcoatFactor !== void 0 && (t.clearcoat = o.clearcoatFactor), o.clearcoatTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatMap", o.clearcoatTexture)), o.clearcoatRoughnessFactor !== void 0 && (t.clearcoatRoughness = o.clearcoatRoughnessFactor), o.clearcoatRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatRoughnessMap", o.clearcoatRoughnessTexture)), o.clearcoatNormalTexture !== void 0 && (i.push(s.assignTexture(t, "clearcoatNormalMap", o.clearcoatNormalTexture)), o.clearcoatNormalTexture.scale !== void 0)) {
const r = o.clearcoatNormalTexture.scale;
t.clearcoatNormalScale = new Ne(r, r);
}
return Promise.all(i);
}
}, Wr = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_DISPERSION;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const n = this.parser.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = n.extensions[this.name];
return t.dispersion = i.dispersion !== void 0 ? i.dispersion : 0, Promise.resolve();
}
}, Zr = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_IRIDESCENCE;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
return o.iridescenceFactor !== void 0 && (t.iridescence = o.iridescenceFactor), o.iridescenceTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceMap", o.iridescenceTexture)), o.iridescenceIor !== void 0 && (t.iridescenceIOR = o.iridescenceIor), t.iridescenceThicknessRange === void 0 && (t.iridescenceThicknessRange = [100, 400]), o.iridescenceThicknessMinimum !== void 0 && (t.iridescenceThicknessRange[0] = o.iridescenceThicknessMinimum), o.iridescenceThicknessMaximum !== void 0 && (t.iridescenceThicknessRange[1] = o.iridescenceThicknessMaximum), o.iridescenceThicknessTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceThicknessMap", o.iridescenceThicknessTexture)), Promise.all(i);
}
}, Kr = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_SHEEN;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [];
t.sheenColor = new Ie(0, 0, 0), t.sheenRoughness = 0, t.sheen = 1;
const o = n.extensions[this.name];
if (o.sheenColorFactor !== void 0) {
const r = o.sheenColorFactor;
t.sheenColor.setRGB(r[0], r[1], r[2], ot);
}
return o.sheenRoughnessFactor !== void 0 && (t.sheenRoughness = o.sheenRoughnessFactor), o.sheenColorTexture !== void 0 && i.push(s.assignTexture(t, "sheenColorMap", o.sheenColorTexture, ye)), o.sheenRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "sheenRoughnessMap", o.sheenRoughnessTexture)), Promise.all(i);
}
}, qr = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_TRANSMISSION;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
return o.transmissionFactor !== void 0 && (t.transmission = o.transmissionFactor), o.transmissionTexture !== void 0 && i.push(s.assignTexture(t, "transmissionMap", o.transmissionTexture)), Promise.all(i);
}
}, Qr = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_VOLUME;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
t.thickness = o.thicknessFactor !== void 0 ? o.thicknessFactor : 0, o.thicknessTexture !== void 0 && i.push(s.assignTexture(t, "thicknessMap", o.thicknessTexture)), t.attenuationDistance = o.attenuationDistance || 1 / 0;
const r = o.attenuationColor || [1, 1, 1];
return t.attenuationColor = new Ie().setRGB(r[0], r[1], r[2], ot), Promise.all(i);
}
}, $r = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_IOR;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const n = this.parser.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = n.extensions[this.name];
return t.ior = i.ior !== void 0 ? i.ior : 1.5, Promise.resolve();
}
}, Jr = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_SPECULAR;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
t.specularIntensity = o.specularFactor !== void 0 ? o.specularFactor : 1, o.specularTexture !== void 0 && i.push(s.assignTexture(t, "specularIntensityMap", o.specularTexture));
const r = o.specularColorFactor || [1, 1, 1];
return t.specularColor = new Ie().setRGB(r[0], r[1], r[2], ot), o.specularColorTexture !== void 0 && i.push(s.assignTexture(t, "specularColorMap", o.specularColorTexture, ye)), Promise.all(i);
}
}, ea = class {
constructor(e) {
this.parser = e, this.name = se.EXT_MATERIALS_BUMP;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
return t.bumpScale = o.bumpFactor !== void 0 ? o.bumpFactor : 1, o.bumpTexture !== void 0 && i.push(s.assignTexture(t, "bumpMap", o.bumpTexture)), Promise.all(i);
}
}, ta = class {
constructor(e) {
this.parser = e, this.name = se.KHR_MATERIALS_ANISOTROPY;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : xt;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], o = n.extensions[this.name];
return o.anisotropyStrength !== void 0 && (t.anisotropy = o.anisotropyStrength), o.anisotropyRotation !== void 0 && (t.anisotropyRotation = o.anisotropyRotation), o.anisotropyTexture !== void 0 && i.push(s.assignTexture(t, "anisotropyMap", o.anisotropyTexture)), Promise.all(i);
}
};
class na {
constructor(e) {
this.parser = e, this.name = se.KHR_TEXTURE_BASISU;
}
loadTexture(e) {
const t = this.parser, s = t.json, n = s.textures[e];
if (!n.extensions || !n.extensions[this.name])
return null;
const i = n.extensions[this.name], o = t.options.ktx2Loader;
if (!o) {
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 t.loadTextureImage(e, i.source, o);
}
}
class sa {
constructor(e) {
this.parser = e, this.name = se.EXT_TEXTURE_WEBP, this.isSupported = null;
}
loadTexture(e) {
const t = this.name, s = this.parser, n = s.json, i = n.textures[e];
if (!i.extensions || !i.extensions[t])
return null;
const o = i.extensions[t], r = n.images[o.source];
let a = s.textureLoader;
if (r.uri) {
const l = s.options.manager.getHandler(r.uri);
l !== null && (a = l);
}
return this.detectSupport().then(function(l) {
if (l) return s.loadTextureImage(e, o.source, a);
if (n.extensionsRequired && n.extensionsRequired.indexOf(t) >= 0)
throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
return s.loadTexture(e);
});
}
detectSupport() {
return this.isSupported || (this.isSupported = new Promise(function(e) {
const t = new Image();
t.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA", t.onload = t.onerror = function() {
e(t.height === 1);
};
})), this.isSupported;
}
}
class ia {
constructor(e) {
this.parser = e, this.name = se.EXT_TEXTURE_AVIF, this.isSupported = null;
}
loadTexture(e) {
const t = this.name, s = this.parser, n = s.json, i = n.textures[e];
if (!i.extensions || !i.extensions[t])
return null;
const o = i.extensions[t], r = n.images[o.source];
let a = s.textureLoader;
if (r.uri) {
const l = s.options.manager.getHandler(r.uri);
l !== null && (a = l);
}
return this.detectSupport().then(function(l) {
if (l) return s.loadTextureImage(e, o.source, a);
if (n.extensionsRequired && n.extensionsRequired.indexOf(t) >= 0)
throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");
return s.loadTexture(e);
});
}
detectSupport() {
return this.isSupported || (this.isSupported = new Promise(function(e) {
const t = new Image();
t.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=", t.onload = t.onerror = function() {
e(t.height === 1);
};
})), this.isSupported;
}
}
class oa {
constructor(e) {
this.name = se.EXT_MESHOPT_COMPRESSION, this.parser = e;
}
loadBufferView(e) {
const t = this.parser.json, s = t.bufferViews[e];
if (s.extensions && s.extensions[this.name]) {
const n = s.extensions[this.name], i = this.parser.getDependency("buffer", n.buffer), o = this.parser.options.meshoptDecoder;
if (!o || !o.supported) {
if (t.extensionsRequired && t.extensionsRequired.indexOf(this.name) >= 0)
throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
return null;
}
return i.then(function(r) {
const a = n.byteOffset || 0, l = n.byteLength || 0, h = n.count, u = n.byteStride, f = new Uint8Array(r, a, l);
return o.decodeGltfBufferAsync ? o.decodeGltfBufferAsync(h, u, f, n.mode, n.filter).then(function(d) {
return d.buffer;
}) : o.ready.then(function() {
const d = new ArrayBuffer(h * u);
return o.decodeGltfBuffer(new Uint8Array(d), h, u, f, n.mode, n.filter), d;
});
});
} else
return null;
}
}
let ra = class {
constructor(e) {
this.name = se.EXT_MESH_GPU_INSTANCING, this.parser = e;
}
createNodeMesh(e) {
const t = this.parser.json, s = t.nodes[e];
if (!s.extensions || !s.extensions[this.name] || s.mesh === void 0)
return null;
const n = t.meshes[s.mesh];
for (const l of n.primitives)
if (l.mode !== it.TRIANGLES && l.mode !== it.TRIANGLE_STRIP && l.mode !== it.TRIANGLE_FAN && l.mode !== void 0)
return null;
const o = s.extensions[this.name].attributes, r = [], a = {};
for (const l in o)
r.push(this.parser.getDependency("accessor", o[l]).then((h) => (a[l] = h, a[l])));
return r.length < 1 ? null : (r.push(this.parser.createNodeMesh(e)), Promise.all(r).then((l) => {
const h = l.pop(), u = h.isGroup ? h.children : [h], f = l[0].count, d = [];
for (const g of u) {
const w = new le(), y = new U(), v = new Se(), I = new U(1, 1, 1), T = new mr(g.geometry, g.material, f);
for (let b = 0; b < f; b++)
a.TRANSLATION && y.fromBufferAttribute(a.TRANSLATION, b), a.ROTATION && v.fromBufferAttribute(a.ROTATION, b), a.SCALE && I.fromBufferAttribute(a.SCALE, b), T.setMatrixAt(b, w.compose(y, v, I));
for (const b in a)
if (b === "_COLOR_0") {
const S = a[b];
T.instanceColor = new gr(S.array, S.itemSize, S.normalized);
} else b !== "TRANSLATION" && b !== "ROTATION" && b !== "SCALE" && g.geometry.setAttribute(b, a[b]);
yt.prototype.copy.call(T, g), this.parser.assignFinalMaterial(T), d.push(T);
}
return h.isGroup ? (h.clear(), h.add(...d), h) : d[0];
}));
}
};
const po = "glTF", un = 12, si = { JSON: 1313821514, BIN: 5130562 };
class aa {
constructor(e) {
this.name = se.KHR_BINARY_GLTF, this.content = null, this.body = null;
const t = new DataView(e, 0, un), s = new TextDecoder();
if (this.header = {
magic: s.decode(new Uint8Array(e.slice(0, 4))),
version: t.getUint32(4, !0),
length: t.getUint32(8, !0)
}, this.header.magic !== po)
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 - un, i = new DataView(e, un);
let o = 0;
for (; o < n; ) {
const r = i.getUint32(o, !0);
o += 4;
const a = i.getUint32(o, !0);
if (o += 4, a === si.JSON) {
const l = new Uint8Array(e, un + o, r);
this.content = s.decode(l);
} else if (a === si.BIN) {
const l = un + o;
this.body = e.slice(l, l + r);
}
o += r;
}
if (this.content === null)
throw new Error("THREE.GLTFLoader: JSON content not found.");
}
}
class ca {
constructor(e, t) {
if (!t)
throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
this.name = se.KHR_DRACO_MESH_COMPRESSION, this.json = e, this.dracoLoader = t, this.dracoLoader.preload();
}
decodePrimitive(e, t) {
const s = this.json, n = this.dracoLoader, i = e.extensions[this.name].bufferView, o = e.extensions[this.name].attributes, r = {}, a = {}, l = {};
for (const h in o) {
const u = Is[h] || h.toLowerCase();
r[u] = o[h];
}
for (const h in e.attributes) {
const u = Is[h] || h.toLowerCase();
if (o[h] !== void 0) {
const f = s.accessors[e.attributes[h]], d = rn[f.componentType];
l[u] = d.name, a[u] = f.normalized === !0;
}
}
return t.getDependency("bufferView", i).then(function(h) {
return new Promise(function(u, f) {
n.decodeDracoFile(h, function(d) {
for (const g in d.attributes) {
const w = d.attributes[g], y = a[g];
y !== void 0 && (w.normalized = y);
}
u(d);
}, r, l, ot, f);
});
});
}
}
class la {
constructor() {
this.name = se.KHR_TEXTURE_TRANSFORM;
}
extendTexture(e, t) {
return (t.texCoord === void 0 || t.texCoord === e.channel) && t.offset === void 0 && t.rotation === void 0 && t.scale === void 0 || (e = e.clone(), t.texCoord !== void 0 && (e.channel = t.texCoord), t.offset !== void 0 && e.offset.fromArray(t.offset), t.rotation !== void 0 && (e.rotation = t.rotation), t.scale !== void 0 && e.repeat.fromArray(t.scale), e.needsUpdate = !0), e;
}
}
class ha {
constructor() {
this.name = se.KHR_MESH_QUANTIZATION;
}
}
class fo extends vr {
constructor(e, t, s, n) {
super(e, t, s, n);
}
copySampleValue_(e) {
const t = this.resultBuffer, s = this.sampleValues, n = this.valueSize, i = e * n * 3 + n;
for (let o = 0; o !== n; o++)
t[o] = s[i + o];
return t;
}
interpolate_(e, t, s, n) {
const i = this.resultBuffer, o = this.sampleValues, r = this.valueSize, a = r * 2, l = r * 3, h = n - t, u = (s - t) / h, f = u * u, d = f * u, g = e * l, w = g - l, y = -2 * d + 3 * f, v = d - f, I = 1 - y, T = v - f + u;
for (let b = 0; b !== r; b++) {
const S = o[w + b + r], N = o[w + b + a] * h, O = o[g + b + r], A = o[g + b] * h;
i[b] = I * S + T * N + y * O + v * A;
}
return i;
}
}
const ua = new Se();
class pa extends fo {
interpolate_(e, t, s, n) {
const i = super.interpolate_(e, t, s, n);
return ua.fromArray(i).normalize().toArray(i), i;
}
}
const it = {
POINTS: 0,
LINES: 1,
LINE_LOOP: 2,
LINE_STRIP: 3,
TRIANGLES: 4,
TRIANGLE_STRIP: 5,
TRIANGLE_FAN: 6
}, rn = {
5120: Int8Array,
5121: Uint8Array,
5122: Int16Array,
5123: Uint16Array,
5125: Uint32Array,
5126: Float32Array
}, ii = {
9728: Ki,
9729: bt,
9984: Zi,
9985: Wi,
9986: Yi,
9987: ks
}, oi = {
33071: Yn,
33648: qi,
10497: Wt
}, ts = {
SCALAR: 1,
VEC2: 2,
VEC3: 3,
VEC4: 4,
MAT2: 4,
MAT3: 9,
MAT4: 16
}, Is = {
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"
}, Lt = {
scale: "scale",
translation: "position",
rotation: "quaternion",
weights: "morphTargetInfluences"
}, fa = {
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: zs,
STEP: to
}, ns = {
OPAQUE: "OPAQUE",
MASK: "MASK",
BLEND: "BLEND"
};
function da(c) {
return c.DefaultMaterial === void 0 && (c.DefaultMaterial = new Bs({
color: 16777215,
emissive: 0,
metalness: 1,
roughness: 1,
transparent: !1,
depthTest: !0,
side: no
})), c.DefaultMaterial;
}
function kt(c, e, t) {
for (const s in t.extensions)
c[s] === void 0 && (e.userData.gltfExtensions = e.userData.gltfExtensions || {}, e.userData.gltfExtensions[s] = t.extensions[s]);
}
function _t(c, e) {
e.extras !== void 0 && (typeof e.extras == "object" ? Object.assign(c.userData, e.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + e.extras));
}
function ma(c, e, t) {
let s = !1, n = !1, i = !1;
for (let l = 0, h = e.length; l < h; l++) {
const u = e[l];
if (u.POSITION !== void 0 && (s = !0), u.NORMAL !== void 0 && (n = !0), u.COLOR_0 !== void 0 && (i = !0), s && n && i) break;
}
if (!s && !n && !i) return Promise.resolve(c);
const o = [], r = [], a = [];
for (let l = 0, h = e.length; l < h; l++) {
const u = e[l];
if (s) {
const f = u.POSITION !== void 0 ? t.getDependency("accessor", u.POSITION) : c.attributes.position;
o.push(f);
}
if (n) {
const f = u.NORMAL !== void 0 ? t.getDependency("accessor", u.NORMAL) : c.attributes.normal;
r.push(f);
}
if (i) {
const f = u.COLOR_0 !== void 0 ? t.getDependency("accessor", u.COLOR_0) : c.attributes.color;
a.push(f);
}
}
return Promise.all([
Promise.all(o),
Promise.all(r),
Promise.all(a)
]).then(function(l) {
const h = l[0], u = l[1], f = l[2];
return s && (c.morphAttributes.position = h), n && (c.morphAttributes.normal = u), i && (c.morphAttributes.color = f), c.morphTargetsRelative = !0, c;
});
}
function ga(c, e) {
if (c.updateMorphTargets(), e.weights !== void 0)
for (let t = 0, s = e.weights.length; t < s; t++)
c.morphTargetInfluences[t] = e.weights[t];
if (e.extras && Array.isArray(e.extras.targetNames)) {
const t = e.extras.targetNames;
if (c.morphTargetInfluences.length === t.length) {
c.morphTargetDictionary = {};
for (let s = 0, n = t.length; s < n; s++)
c.morphTargetDictionary[t[s]] = s;
} else
console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
}
}
function ya(c) {
let e;
const t = c.extensions && c.extensions[se.KHR_DRACO_MESH_COMPRESSION];
if (t ? e = "draco:" + t.bufferView + ":" + t.indices + ":" + ss(t.attributes) : e = c.indices + ":" + ss(c.attributes) + ":" + c.mode, c.targets !== void 0)
for (let s = 0, n = c.targets.length; s < n; s++)
e += ":" + ss(c.targets[s]);
return e;
}
function ss(c) {
let e = "";
const t = Object.keys(c).sort();
for (let s = 0, n = t.length; s < n; s++)
e += t[s] + ":" + c[t[s]] + ";";
return e;
}
function Rs(c) {
switch (c) {
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 wa(c) {
return c.search(/\.jpe?g($|\?)/i) > 0 || c.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : c.search(/\.webp($|\?)/i) > 0 || c.search(/^data\:image\/webp/) === 0 ? "image/webp" : "image/png";
}
const xa = new le();
class va {
constructor(e = {}, t = {}) {
this.json = e, this.extensions = {}, this.plugins = {}, this.options = t, this.cache = new Gr(), 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, o = -1;
if (typeof navigator < "u") {
const r = navigator.userAgent;
s = /^((?!chrome|android).)*safari/i.test(r) === !0;
const a = r.match(/Version\/(\d+)/);
n = s && a ? parseInt(a[1], 10) : -1, i = r.indexOf("Firefox") > -1, o = i ? r.match(/Firefox\/([0-9]+)\./)[1] : -1;
}
typeof createImageBitmap > "u" || s && n < 17 || i && o < 98 ? this.textureLoader = new Us(this.options.manager) : this.textureLoader = new yr(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new an(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(!0);
}
setExtensions(e) {
this.extensions = e;
}
setPlugins(e) {
this.plugins = e;
}
parse(e, t) {
const s = this, n = this.json, i = this.extensions;
this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(o) {
return o._markDefs && o._markDefs();
}), Promise.all(this._invokeAll(function(o) {
return o.beforeRoot && o.beforeRoot();
})).then(function() {
return Promise.all([
s.getDependencies("scene"),
s.getDependencies("animation"),
s.getDependencies("camera")
]);
}).then(function(o) {
const r = {
scene: o[0][n.scene || 0],
scenes: o[0],
animations: o[1],
cameras: o[2],
asset: n.asset,
parser: s,
userData: {}
};
return kt(i, r, n), _t(r, n), Promise.all(s._invokeAll(function(a) {
return a.afterRoot && a.afterRoot(r);
})).then(function() {
for (const a of r.scenes)
a.updateMatrixWorld();
e(r);
});
}).catch(t);
}
/**
* Marks the special nodes/meshes in json for efficient parse.
*/
_markDefs() {
const e = this.json.nodes || [], t = this.json.skins || [], s = this.json.meshes || [];
for (let n = 0, i = t.length; n < i; n++) {
const o = t[n].joints;
for (let r = 0, a = o.length; r < a; r++)
e[o[r]].isBone = !0;
}
for (let n = 0, i = e.length; n < i; n++) {
const o = e[n];
o.mesh !== void 0 && (this._addNodeRef(this.meshCache, o.mesh), o.skin !== void 0 && (s[o.mesh].isSkinnedMesh = !0)), o.camera !== void 0 && this._addNodeRef(this.cameraCache, o.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(e, t) {
t !== void 0 && (e.refs[t] === void 0 && (e.refs[t] = e.uses[t] = 0), e.refs[t]++);
}
/** Returns a reference to a shared resource, cloning it if necessary. */
_getNodeRef(e, t, s) {
if (e.refs[t] <= 1) return s;
const n = s.clone(), i = (o, r) => {
const a = this.associations.get(o);
a != null && this.associations.set(r, a);
for (const [l, h] of o.children.entries())
i(h, r.children[l]);
};
return i(s, n), n.name += "_instance_" + e.uses[t]++, n;
}
_invokeOne(e) {
const t = Object.values(this.plugins);
t.push(this);
for (let s = 0; s < t.length; s++) {
const n = e(t[s]);
if (n) return n;
}
return null;
}
_invokeAll(e) {
const t = Object.values(this.plugins);
t.unshift(this);
const s = [];
for (let n = 0; n < t.length; n++) {
const i = e(t[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(e, t) {
const s = e + ":" + t;
let n = this.cache.get(s);
if (!n) {
switch (e) {
case "scene":
n = this.loadScene(t);
break;
case "node":
n = this._invokeOne(function(i) {
return i.loadNode && i.loadNode(t);
});
break;
case "mesh":
n = this._invokeOne(function(i) {
return i.loadMesh && i.loadMesh(t);
});
break;
case "accessor":
n = this.loadAccessor(t);
break;
case "bufferView":
n = this._invokeOne(function(i) {
return i.loadBufferView && i.loadBufferView(t);
});
break;
case "buffer":
n = this.loadBuffer(t);
break;
case "material":
n = this._invokeOne(function(i) {
return i.loadMaterial && i.loadMaterial(t);
});
break;
case "texture":
n = this._invokeOne(function(i) {
return i.loadTexture && i.loadTexture(t);
});
break;
case "skin":
n = this.loadSkin(t);
break;
case "animation":
n = this._invokeOne(function(i) {
return i.loadAnimation && i.loadAnimation(t);
});
break;
case "camera":
n = this.loadCamera(t);
break;
default:
if (n = this._invokeOne(function(i) {
return i != this && i.getDependency && i.getDependency(e, t);
}), !n)
throw new Error("Unknown type: " + e);
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(e) {
let t = this.cache.get(e);
if (!t) {
const s = this, n = this.json[e + (e === "mesh" ? "es" : "s")] || [];
t = Promise.all(n.map(function(i, o) {
return s.getDependency(e, o);
})), this.cache.add(e, t);
}
return t;
}
/**
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
* @param {number} bufferIndex
* @return {Promise<ArrayBuffer>}
*/
loadBuffer(e) {
const t = this.json.buffers[e], s = this.fileLoader;
if (t.type && t.type !== "arraybuffer")
throw new Error("THREE.GLTFLoader: " + t.type + " buffer type is not supported.");