lingo3d-react
Version:
Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor
1,263 lines (1,262 loc) • 68.6 kB
JavaScript
import { h as V, L as pe, b as Z, F as X, e as I, S as Ie, k as Ce, D as Oe, M as te, f as v, I as O, J as me, a as P, K as ke, O as Ae, T as De, W as Pe, X as B, Y as Fe, Z as ge, _ as Te, R as J, $ as Ue, a0 as z, o as Ge, a1 as Be, a2 as K, P as ve, r as xe, m as He, n as je, a3 as se, a4 as Ke, p as Ve, a5 as Xe, a6 as ze, G as W, j as We, l as qe, i as Ye, q as Qe, a7 as _e, u as Ze, B as Je, y as Le, z as ye, Q as Re, a8 as $e, a9 as et, aa as tt, ab as nt, c as st, ac as rt, ad as it, ae as ot, af as at, d as re, ag as ct, ah as ut, v as lt, w as ie, N as dt, ai as ft, aj as ht, ak as pt, al as oe, am as mt, x as At, H as gt, an as Tt, ao as xt } from "./index-895cfa2f.mjs";
import { p as _t, c as Lt } from "./processChildren-cb5144fc.mjs";
import "react";
import "react-dom";
let ae = !1;
const yt = () => {
ae || (ae = !0, Le());
};
let ce = !1;
const Rt = () => {
ce || (ce = !0, ye());
};
class wt extends pe {
constructor(e) {
super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(t) {
return new Nt(t);
}), this.register(function(t) {
return new Ft(t);
}), this.register(function(t) {
return new Ut(t);
}), this.register(function(t) {
return new Gt(t);
}), this.register(function(t) {
return new Ct(t);
}), this.register(function(t) {
return new Ot(t);
}), this.register(function(t) {
return new kt(t);
}), this.register(function(t) {
return new Dt(t);
}), this.register(function(t) {
return new Mt(t);
}), this.register(function(t) {
return new Pt(t);
}), this.register(function(t) {
return new It(t);
}), this.register(function(t) {
return new St(t);
}), this.register(function(t) {
return new Bt(t);
}), this.register(function(t) {
return new vt(t);
});
}
load(e, t, s, n) {
const i = this;
let r;
this.resourcePath !== "" ? r = this.resourcePath : this.path !== "" ? r = this.path : r = Z.extractUrlBase(e), this.manager.itemStart(e);
const a = function(c) {
n ? n(c) : console.error(c), i.manager.itemError(e), i.manager.itemEnd(e);
}, o = new X(this.manager);
o.setPath(this.path), o.setResponseType("arraybuffer"), o.setRequestHeader(this.requestHeader), o.setWithCredentials(this.withCredentials), o.load(e, function(c) {
try {
i.parse(c, r, function(u) {
t(u), i.manager.itemEnd(e);
}, a);
} catch (u) {
a(u);
}
}, s, a);
}
setDRACOLoader(e) {
return this.dracoLoader = e, this;
}
setDDSLoader() {
throw new Error('GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".');
}
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;
const r = {}, a = {}, o = new TextDecoder();
if (typeof e == "string")
i = JSON.parse(e);
else if (e instanceof ArrayBuffer)
if (o.decode(new Uint8Array(e, 0, 4)) === we) {
try {
r[T.KHR_BINARY_GLTF] = new Ht(e);
} catch (l) {
n && n(l);
return;
}
i = JSON.parse(r[T.KHR_BINARY_GLTF].content);
} else
i = JSON.parse(o.decode(e));
else
i = e;
if (i.asset === void 0 || i.asset.version[0] < 2) {
n && n(new Error("GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
return;
}
const c = new en(i, {
path: t || 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);
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], d = i.extensionsRequired || [];
switch (l) {
case T.KHR_MATERIALS_UNLIT:
r[l] = new Et();
break;
case T.KHR_DRACO_MESH_COMPRESSION:
r[l] = new jt(i, this.dracoLoader);
break;
case T.KHR_TEXTURE_TRANSFORM:
r[l] = new Kt();
break;
case T.KHR_MESH_QUANTIZATION:
r[l] = new Vt();
break;
default:
d.indexOf(l) >= 0 && a[l] === void 0 && console.warn('GLTFLoader: Unknown extension "' + l + '".');
}
}
c.setExtensions(r), c.setPlugins(a), c.parse(s, n);
}
parseAsync(e, t) {
const s = this;
return new Promise(function(n, i) {
s.parse(e, t, n, i);
});
}
}
function bt() {
let f = {};
return {
get: function(e) {
return f[e];
},
add: function(e, t) {
f[e] = t;
},
remove: function(e) {
delete f[e];
},
removeAll: function() {
f = {};
}
};
}
const T = {
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_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_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 St {
constructor(e) {
this.parser = e, this.name = T.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, o = ((i.extensions && i.extensions[this.name] || {}).lights || [])[e];
let c;
const u = new I(16777215);
o.color !== void 0 && u.fromArray(o.color);
const l = o.range !== void 0 ? o.range : 0;
switch (o.type) {
case "directional":
c = new Oe(u), c.target.position.set(0, 0, -1), c.add(c.target);
break;
case "point":
c = new Ce(u), c.distance = l;
break;
case "spot":
c = new Ie(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("GLTFLoader: Unexpected light type: " + o.type);
}
return c.position.set(0, 0, 0), c.decay = 2, N(c, o), o.intensity !== void 0 && (c.intensity = o.intensity), c.name = t.createUniqueName(o.name || "light_" + e), n = Promise.resolve(c), 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], a = (i.extensions && i.extensions[this.name] || {}).light;
return a === void 0 ? null : this._loadLight(a).then(function(o) {
return s._getNodeRef(t.cache, a, o);
});
}
}
class Et {
constructor() {
this.name = T.KHR_MATERIALS_UNLIT;
}
getMaterialType() {
return te;
}
extendParams(e, t, s) {
const n = [];
e.color = new I(1, 1, 1), e.opacity = 1;
const i = t.pbrMetallicRoughness;
if (i) {
if (Array.isArray(i.baseColorFactor)) {
const r = i.baseColorFactor;
e.color.fromArray(r), e.opacity = r[3];
}
i.baseColorTexture !== void 0 && n.push(s.assignTexture(e, "map", i.baseColorTexture, v));
}
return Promise.all(n);
}
}
class Mt {
constructor(e) {
this.parser = e, this.name = T.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();
}
}
class Nt {
constructor(e) {
this.parser = e, this.name = T.KHR_MATERIALS_CLEARCOAT;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : O;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], r = n.extensions[this.name];
if (r.clearcoatFactor !== void 0 && (t.clearcoat = r.clearcoatFactor), r.clearcoatTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatMap", r.clearcoatTexture)), r.clearcoatRoughnessFactor !== void 0 && (t.clearcoatRoughness = r.clearcoatRoughnessFactor), r.clearcoatRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatRoughnessMap", r.clearcoatRoughnessTexture)), r.clearcoatNormalTexture !== void 0 && (i.push(s.assignTexture(t, "clearcoatNormalMap", r.clearcoatNormalTexture)), r.clearcoatNormalTexture.scale !== void 0)) {
const a = r.clearcoatNormalTexture.scale;
t.clearcoatNormalScale = new me(a, a);
}
return Promise.all(i);
}
}
class It {
constructor(e) {
this.parser = e, this.name = T.KHR_MATERIALS_IRIDESCENCE;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : O;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], r = n.extensions[this.name];
return r.iridescenceFactor !== void 0 && (t.iridescence = r.iridescenceFactor), r.iridescenceTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceMap", r.iridescenceTexture)), r.iridescenceIor !== void 0 && (t.iridescenceIOR = r.iridescenceIor), t.iridescenceThicknessRange === void 0 && (t.iridescenceThicknessRange = [100, 400]), r.iridescenceThicknessMinimum !== void 0 && (t.iridescenceThicknessRange[0] = r.iridescenceThicknessMinimum), r.iridescenceThicknessMaximum !== void 0 && (t.iridescenceThicknessRange[1] = r.iridescenceThicknessMaximum), r.iridescenceThicknessTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceThicknessMap", r.iridescenceThicknessTexture)), Promise.all(i);
}
}
class Ct {
constructor(e) {
this.parser = e, this.name = T.KHR_MATERIALS_SHEEN;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : O;
}
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 I(0, 0, 0), t.sheenRoughness = 0, t.sheen = 1;
const r = n.extensions[this.name];
return r.sheenColorFactor !== void 0 && t.sheenColor.fromArray(r.sheenColorFactor), r.sheenRoughnessFactor !== void 0 && (t.sheenRoughness = r.sheenRoughnessFactor), r.sheenColorTexture !== void 0 && i.push(s.assignTexture(t, "sheenColorMap", r.sheenColorTexture, v)), r.sheenRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "sheenRoughnessMap", r.sheenRoughnessTexture)), Promise.all(i);
}
}
class Ot {
constructor(e) {
this.parser = e, this.name = T.KHR_MATERIALS_TRANSMISSION;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : O;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], r = n.extensions[this.name];
return r.transmissionFactor !== void 0 && (t.transmission = r.transmissionFactor), r.transmissionTexture !== void 0 && i.push(s.assignTexture(t, "transmissionMap", r.transmissionTexture)), Promise.all(i);
}
}
class kt {
constructor(e) {
this.parser = e, this.name = T.KHR_MATERIALS_VOLUME;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : O;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], r = n.extensions[this.name];
t.thickness = r.thicknessFactor !== void 0 ? r.thicknessFactor : 0, r.thicknessTexture !== void 0 && i.push(s.assignTexture(t, "thicknessMap", r.thicknessTexture)), t.attenuationDistance = r.attenuationDistance || 1 / 0;
const a = r.attenuationColor || [1, 1, 1];
return t.attenuationColor = new I(a[0], a[1], a[2]), Promise.all(i);
}
}
class Dt {
constructor(e) {
this.parser = e, this.name = T.KHR_MATERIALS_IOR;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : O;
}
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();
}
}
class Pt {
constructor(e) {
this.parser = e, this.name = T.KHR_MATERIALS_SPECULAR;
}
getMaterialType(e) {
const s = this.parser.json.materials[e];
return !s.extensions || !s.extensions[this.name] ? null : O;
}
extendMaterialParams(e, t) {
const s = this.parser, n = s.json.materials[e];
if (!n.extensions || !n.extensions[this.name])
return Promise.resolve();
const i = [], r = n.extensions[this.name];
t.specularIntensity = r.specularFactor !== void 0 ? r.specularFactor : 1, r.specularTexture !== void 0 && i.push(s.assignTexture(t, "specularIntensityMap", r.specularTexture));
const a = r.specularColorFactor || [1, 1, 1];
return t.specularColor = new I(a[0], a[1], a[2]), r.specularColorTexture !== void 0 && i.push(s.assignTexture(t, "specularColorMap", r.specularColorTexture, v)), Promise.all(i);
}
}
class Ft {
constructor(e) {
this.parser = e, this.name = T.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], r = t.options.ktx2Loader;
if (!r) {
if (s.extensionsRequired && s.extensionsRequired.indexOf(this.name) >= 0)
throw new Error("GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
return null;
}
return t.loadTextureImage(e, i.source, r);
}
}
class Ut {
constructor(e) {
this.parser = e, this.name = T.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 r = i.extensions[t], 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(e, r.source, o);
if (n.extensionsRequired && n.extensionsRequired.indexOf(t) >= 0)
throw new Error("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 Gt {
constructor(e) {
this.parser = e, this.name = T.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 r = i.extensions[t], 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(e, r.source, o);
if (n.extensionsRequired && n.extensionsRequired.indexOf(t) >= 0)
throw new Error("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 Bt {
constructor(e) {
this.name = T.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), r = this.parser.options.meshoptDecoder;
if (!r || !r.supported) {
if (t.extensionsRequired && t.extensionsRequired.indexOf(this.name) >= 0)
throw new Error("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, d = new Uint8Array(a, o, c);
return r.decodeGltfBufferAsync ? r.decodeGltfBufferAsync(u, l, d, n.mode, n.filter).then(function(h) {
return h.buffer;
}) : r.ready.then(function() {
const h = new ArrayBuffer(u * l);
return r.decodeGltfBuffer(new Uint8Array(h), u, l, d, n.mode, n.filter), h;
});
});
} else
return null;
}
}
class vt {
constructor(e) {
this.name = T.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 c of n.primitives)
if (c.mode !== R.TRIANGLES && c.mode !== R.TRIANGLE_STRIP && c.mode !== R.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(e)), Promise.all(a).then((c) => {
const u = c.pop(), l = u.isGroup ? u.children : [u], d = c[0].count, h = [];
for (const m of l) {
const g = new V(), p = new P(), A = new Re(), L = new P(1, 1, 1), x = new ke(m.geometry, m.material, d);
for (let _ = 0; _ < d; _++)
o.TRANSLATION && p.fromBufferAttribute(o.TRANSLATION, _), o.ROTATION && A.fromBufferAttribute(o.ROTATION, _), o.SCALE && L.fromBufferAttribute(o.SCALE, _), x.setMatrixAt(_, g.compose(p, A, L));
for (const _ in o)
_ !== "TRANSLATION" && _ !== "ROTATION" && _ !== "SCALE" && m.geometry.setAttribute(_, o[_]);
Ae.prototype.copy.call(x, m), x.frustumCulled = !1, this.parser.assignFinalMaterial(x), h.push(x);
}
return u.isGroup ? (u.clear(), u.add(...h), u) : h[0];
}));
}
}
const we = "glTF", U = 12, ue = { JSON: 1313821514, BIN: 5130562 };
class Ht {
constructor(e) {
this.name = T.KHR_BINARY_GLTF, this.content = null, this.body = null;
const t = new DataView(e, 0, U), 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 !== we)
throw new Error("GLTFLoader: Unsupported glTF-Binary header.");
if (this.header.version < 2)
throw new Error("GLTFLoader: Legacy binary file detected.");
const n = this.header.length - U, i = new DataView(e, U);
let r = 0;
for (; r < n; ) {
const a = i.getUint32(r, !0);
r += 4;
const o = i.getUint32(r, !0);
if (r += 4, o === ue.JSON) {
const c = new Uint8Array(e, U + r, a);
this.content = s.decode(c);
} else if (o === ue.BIN) {
const c = U + r;
this.body = e.slice(c, c + a);
}
r += a;
}
if (this.content === null)
throw new Error("GLTFLoader: JSON content not found.");
}
}
class jt {
constructor(e, t) {
if (!t)
throw new Error("GLTFLoader: No DRACOLoader instance provided.");
this.name = T.KHR_DRACO_MESH_COMPRESSION, this.json = e, this.dracoLoader = t, this.dracoLoader.preload(), yt();
}
decodePrimitive(e, t) {
const s = this.json, n = this.dracoLoader, i = e.extensions[this.name].bufferView, r = e.extensions[this.name].attributes, a = {}, o = {}, c = {};
for (const u in r) {
const l = $[u] || u.toLowerCase();
a[l] = r[u];
}
for (const u in e.attributes) {
const l = $[u] || u.toLowerCase();
if (r[u] !== void 0) {
const d = s.accessors[e.attributes[u]], h = F[d.componentType];
c[l] = h.name, o[l] = d.normalized === !0;
}
}
return t.getDependency("bufferView", i).then(function(u) {
return new Promise(function(l) {
n.decodeDracoFile(u, function(d) {
for (const h in d.attributes) {
const m = d.attributes[h], g = o[h];
g !== void 0 && (m.normalized = g);
}
Rt(), l(d);
}, a, c);
});
});
}
}
class Kt {
constructor() {
this.name = T.KHR_TEXTURE_TRANSFORM;
}
extendTexture(e, t) {
return t.texCoord !== void 0 && console.warn('GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.'), t.offset === void 0 && t.rotation === void 0 && t.scale === void 0 || (e = e.clone(), 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 Vt {
constructor() {
this.name = T.KHR_MESH_QUANTIZATION;
}
}
class be extends pt {
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 r = 0; r !== n; r++)
t[r] = s[i + r];
return t;
}
interpolate_(e, t, s, n) {
const i = this.resultBuffer, r = this.sampleValues, a = this.valueSize, o = a * 2, c = a * 3, u = n - t, l = (s - t) / u, d = l * l, h = d * l, m = e * c, g = m - c, p = -2 * h + 3 * d, A = h - d, L = 1 - p, x = A - d + l;
for (let _ = 0; _ !== a; _++) {
const C = r[g + _ + a], w = r[g + _ + o] * u, y = r[m + _ + a], S = r[m + _] * u;
i[_] = L * C + x * w + p * y + A * S;
}
return i;
}
}
const Xt = new Re();
class zt extends be {
interpolate_(e, t, s, n) {
const i = super.interpolate_(e, t, s, n);
return Xt.fromArray(i).normalize().toArray(i), i;
}
}
const R = {
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
}, F = {
5120: Int8Array,
5121: Uint8Array,
5122: Int16Array,
5123: Uint16Array,
5125: Uint32Array,
5126: Float32Array
}, le = {
9728: $e,
9729: ge,
9984: et,
9985: tt,
9986: nt,
9987: Te
}, de = {
33071: st,
33648: rt,
10497: J
}, q = {
SCALAR: 1,
VEC2: 2,
VEC3: 3,
VEC4: 4,
MAT2: 4,
MAT3: 9,
MAT4: 16
}, $ = {
POSITION: "position",
NORMAL: "normal",
TANGENT: "tangent",
TEXCOORD_0: "uv",
TEXCOORD_1: "uv2",
COLOR_0: "color",
WEIGHTS_0: "skinWeight",
JOINTS_0: "skinIndex"
}, M = {
scale: "scale",
translation: "position",
rotation: "quaternion",
weights: "morphTargetInfluences"
}, Wt = {
CUBICSPLINE: void 0,
// keyframe track will be initialized with a default interpolation type, then modified.
LINEAR: _e,
STEP: it
}, Y = {
OPAQUE: "OPAQUE",
MASK: "MASK",
BLEND: "BLEND"
};
function qt(f) {
return f.DefaultMaterial === void 0 && (f.DefaultMaterial = new te({
color: 16777215,
emissive: 0,
metalness: 1,
roughness: 1,
transparent: !1,
depthTest: !0,
side: ot
})), f.DefaultMaterial;
}
function G(f, e, t) {
for (const s in t.extensions)
f[s] === void 0 && (e.userData.gltfExtensions = e.userData.gltfExtensions || {}, e.userData.gltfExtensions[s] = t.extensions[s]);
}
function N(f, e) {
e.extras !== void 0 && (typeof e.extras == "object" ? Object.assign(f.userData, e.extras) : console.warn("GLTFLoader: Ignoring primitive type .extras, " + e.extras));
}
function Yt(f, e, t) {
let s = !1, n = !1, i = !1;
for (let c = 0, u = e.length; c < u; c++) {
const l = e[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 = e.length; c < u; c++) {
const l = e[c];
if (s) {
const d = l.POSITION !== void 0 ? t.getDependency("accessor", l.POSITION) : f.attributes.position;
r.push(d);
}
if (n) {
const d = l.NORMAL !== void 0 ? t.getDependency("accessor", l.NORMAL) : f.attributes.normal;
a.push(d);
}
if (i) {
const d = l.COLOR_0 !== void 0 ? t.getDependency("accessor", l.COLOR_0) : f.attributes.color;
o.push(d);
}
}
return Promise.all([
Promise.all(r),
Promise.all(a),
Promise.all(o)
]).then(function(c) {
const u = c[0], l = c[1], d = c[2];
return s && (f.morphAttributes.position = u), n && (f.morphAttributes.normal = l), i && (f.morphAttributes.color = d), f.morphTargetsRelative = !0, f;
});
}
function Qt(f, e) {
if (f.updateMorphTargets(), e.weights !== void 0)
for (let t = 0, s = e.weights.length; t < s; t++)
f.morphTargetInfluences[t] = e.weights[t];
if (e.extras && Array.isArray(e.extras.targetNames)) {
const t = e.extras.targetNames;
if (f.morphTargetInfluences.length === t.length) {
f.morphTargetDictionary = {};
for (let s = 0, n = t.length; s < n; s++)
f.morphTargetDictionary[t[s]] = s;
} else
console.warn("GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
}
}
function Zt(f) {
const e = f.extensions && f.extensions[T.KHR_DRACO_MESH_COMPRESSION];
let t;
return e ? t = "draco:" + e.bufferView + ":" + e.indices + ":" + fe(e.attributes) : t = f.indices + ":" + fe(f.attributes) + ":" + f.mode, t;
}
function fe(f) {
let e = "";
const t = Object.keys(f).sort();
for (let s = 0, n = t.length; s < n; s++)
e += t[s] + ":" + f[t[s]] + ";";
return e;
}
function ee(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("GLTFLoader: Unsupported normalized accessor component type.");
}
}
function Jt(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 $t = new V();
class en {
constructor(e = {}, t = {}) {
this.json = e, this.extensions = {}, this.plugins = {}, this.options = t, this.cache = new bt(), 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 De(this.options.manager) : this.textureLoader = new Pe(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new X(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(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: {}
};
G(i, a, n), N(a, n), Promise.all(s._invokeAll(function(o) {
return o.afterRoot && o.afterRoot(a);
})).then(function() {
e(a);
});
}).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 r = t[n].joints;
for (let a = 0, o = r.length; a < o; a++)
e[r[a]].isBone = !0;
}
for (let n = 0, i = e.length; n < i; n++) {
const r = e[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(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 = (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_" + 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, r) {
return s.getDependency(e, r);
})), 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("GLTFLoader: " + t.type + " buffer type is not supported.");
if (t.uri === void 0 && e === 0)
return Promise.resolve(this.extensions[T.KHR_BINARY_GLTF].body);
const n = this.options;
return new Promise(function(i, r) {
s.load(Z.resolveURL(t.uri, n.path), i, void 0, function() {
r(new Error('GLTFLoader: Failed to load buffer "' + t.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(e) {
const t = this.json.bufferViews[e];
return this.getDependency("buffer", t.buffer).then(function(s) {
const n = t.byteLength || 0, i = t.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(e) {
const t = this, s = this.json, n = this.json.accessors[e];
if (n.bufferView === void 0 && n.sparse === void 0) {
const r = q[n.type], a = F[n.componentType], o = n.normalized === !0, c = new a(n.count * r);
return Promise.resolve(new B(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 = q[n.type], c = F[n.componentType], u = c.BYTES_PER_ELEMENT, l = u * o, d = n.byteOffset || 0, h = n.bufferView !== void 0 ? s.bufferViews[n.bufferView].byteStride : void 0, m = n.normalized === !0;
let g, p;
if (h && h !== l) {
const A = Math.floor(d / h), L = "InterleavedBuffer:" + n.bufferView + ":" + n.componentType + ":" + A + ":" + n.count;
let x = t.cache.get(L);
x || (g = new c(a, A * h, n.count * h / u), x = new Fe(g, h / u), t.cache.add(L, x)), p = new at(x, o, d % h / u, m);
} else
a === null ? g = new c(n.count * o) : g = new c(a, d, n.count * o), p = new B(g, o, m);
if (n.sparse !== void 0) {
const A = q.SCALAR, L = F[n.sparse.indices.componentType], x = n.sparse.indices.byteOffset || 0, _ = n.sparse.values.byteOffset || 0, C = new L(r[1], x, n.sparse.count * A), w = new c(r[2], _, n.sparse.count * o);
a !== null && (p = new B(p.array.slice(), p.itemSize, p.normalized));
for (let y = 0, S = C.length; y < S; y++) {
const k = C[y];
if (p.setX(k, w[y * o]), o >= 2 && p.setY(k, w[y * o + 1]), o >= 3 && p.setZ(k, w[y * o + 2]), o >= 4 && p.setW(k, w[y * o + 3]), o >= 5)
throw new Error("GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
}
}
return p;
});
}
/**
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
* @param {number} textureIndex
* @return {Promise<THREE.Texture|null>}
*/
loadTexture(e) {
const t = this.json, s = this.options, i = t.textures[e].source, r = t.images[i];
let a = this.textureLoader;
if (r.uri) {
const o = s.manager.getHandler(r.uri);
o !== null && (a = o);
}
return this.loadTextureImage(e, i, a);
}
loadTextureImage(e, t, s) {
const n = this, i = this.json, r = i.textures[e], a = i.images[t], o = (a.uri || a.bufferView) + ":" + r.sampler;
if (this.textureCache[o])
return this.textureCache[o];
const c = this.loadImageSource(t, s).then(function(u) {
u.flipY = !1, u.name = r.name || a.name || "";
const d = (i.samplers || {})[r.sampler] || {};
return u.magFilter = le[d.magFilter] || ge, u.minFilter = le[d.minFilter] || Te, u.wrapS = de[d.wrapS] || J, u.wrapT = de[d.wrapT] || J, n.associations.set(u, { textures: e }), u;
}).catch(function() {
return null;
});
return this.textureCache[o] = c, c;
}
loadImageSource(e, t) {
const s = this, n = this.json, i = this.options;
if (this.sourceCache[e] !== void 0)
return this.sourceCache[e].then((l) => l.clone());
const r = n.images[e], 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 d = new Blob([l], {
type: r.mimeType
});
return o = a.createObjectURL(d), o;
});
else if (r.uri === void 0)
throw new Error("GLTFLoader: Image " + e + " is missing URI and bufferView");
const u = Promise.resolve(o).then(function(l) {
return new Promise(function(d, h) {
let m = d;
t.isImageBitmapLoader === !0 && (m = function(g) {
const p = new re(g);
p.needsUpdate = !0, d(p);
}), t.load(Z.resolveURL(l, i.path), m, void 0, h);
});
}).then(function(l) {
return c === !0 && a.revokeObjectURL(o), l.userData.mimeType = r.mimeType || Jt(r.uri), l;
}).catch(function(l) {
throw console.error("GLTFLoader: Couldn't load texture", o), l;
});
return this.sourceCache[e] = u, u;
}
/**
* Asynchronously assigns a texture to the given material parameters.
* @param {Object} materialParams
* @param {string} mapName
* @param {Object} mapDef
* @return {Promise<Texture>}
*/
assignTexture(e, t, 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 && !(t === "aoMap" && s.texCoord == 1) && console.warn("GLTFLoader: Custom UV set " + s.texCoord + " for texture " + t + " not yet supported."), i.extensions[T.KHR_TEXTURE_TRANSFORM]) {
const a = s.extensions !== void 0 ? s.extensions[T.KHR_TEXTURE_TRANSFORM] : void 0;
if (a) {
const o = i.associations.get(r);
r = i.extensions[T.KHR_TEXTURE_TRANSFORM].extendTexture(r, a), i.associations.set(r, o);
}
}
return n !== void 0 && (r.encoding = n), e[t] = 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(e) {
const t = e.geometry;
let s = e.material;
const n = t.attributes.tangent === void 0, i = t.attributes.color !== void 0, r = t.attributes.normal === void 0;
if (e.isPoints) {
const a = "PointsMaterial:" + s.uuid;
let o = this.cache.get(a);
o || (o = new Ue(), z.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 (e.isLine) {
const a = "LineBasicMaterial:" + s.uuid;
let o = this.cache.get(a);
o || (o = new Ge(), z.prototype.copy.call(o, s), o.color.copy(s.color), 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;
}
s.aoMap && t.attributes.uv2 === void 0 && t.attributes.uv !== void 0 && t.setAttribute("uv2", t.attributes.uv), e.material = s;
}
getMaterialType() {
return te;
}
/**
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
* @param {number} materialIndex
* @return {Promise<Material>}
*/
loadMaterial(e) {
const t = this, s = this.json, n = this.extensions, i = s.materials[e];
let r;
const a = {}, o = i.extensions || {}, c = [];
if (o[T.KHR_MATERIALS_UNLIT]) {
const l = n[T.KHR_MATERIALS_UNLIT];
r = l.getMaterialType(), c.push(l.extendParams(a, i, t));
} else {
const l = i.pbrMetallicRoughness || {};
if (a.color = new I(1, 1, 1), a.opacity = 1, Array.isArray(l.baseColorFactor)) {
const d = l.baseColorFactor;
a.color.fromArray(d), a.opacity = d[3];
}
l.baseColorTexture !== void 0 && c.push(t.assignTexture(a, "map", l.baseColorTexture, v)), a.metalness = l.metallicFactor !== void 0 ? l.metallicFactor : 1, a.roughness = l.roughnessFactor !== void 0 ? l.roughnessFactor : 1, l.metallicRoughnessTexture !== void 0 && (c.push(t.assignTexture(a, "metalnessMap", l.metallicRoughnessTexture)), c.push(t.assignTexture(a, "roughnessMap", l.metallicRoughnessTexture))), r = this._invokeOne(function(d) {
return d.getMaterialType && d.getMaterialType(e);
}), c.push(Promise.all(this._invokeAll(function(d) {
return d.extendMaterialParams && d.extendMaterialParams(e, a);
})));
}
i.doubleSided === !0 && (a.side = Be);
const u = i.alphaMode || Y.OPAQUE;
if (u === Y.BLEND ? (a.transparent = !0, a.depthWrite = !1) : (a.transparent = !1, u === Y.MASK && (a.alphaTest = i.alphaCutoff !== void 0 ? i.alphaCutoff : 0.5)), i.normalTexture !== void 0 && r !== K && (c.push(t.assignTexture(a, "normalMap", i.normalTexture)), a.normalScale = new me(1, 1), i.normalTexture.scale !== void 0)) {
const l = i.normalTexture.scale;
a.normalScale.set(l, l);
}
return i.occlusionTexture !== void 0 && r !== K && (c.push(t.assignTexture(a, "aoMap", i.occlusionTexture)), i.occlusionTexture.strength !== void 0 && (a.aoMapIntensity = i.occlusionTexture.strength)), i.emissiveFactor !== void 0 && r !== K && (a.emissive = new I().fromArray(i.emissiveFactor)), i.emissiveTexture !== void 0 && r !== K && c.push(t.assignTexture(a, "emissiveMap", i.emissiveTexture, v)), Promise.all(c).then(function() {
const l = new r(a);
return i.name && (l.name = i.name), N(l, i), t.associations.set(l, { materials: e }), i.extensions && G(n, l, i), l;
});
}
/** When Object3D instances are targeted by animation, they need unique names. */
createUniqueName(e) {
const t = ve.sanitizeNodeName(e || "");
let s = t;
for (let n = 1; this.nodeNamesUsed[s]; ++n)
s = t + "_" + n;
return this.nodeNamesUsed[s] = !0, s;
}
/**
* 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(e) {
const t = this, s = this.extensions, n = this.primitiveCache;
function i(a) {
return s[T.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a, t).then(function(o) {
return he(o, a, t);
});
}
const r = [];
for (let a = 0, o = e.length; a < o; a++) {
const c = e[a], u = Zt(c), l = n[u];
if (l)
r.push(l.promise);
else {
let d;
c.extensions && c.extensions[T.KHR_DRACO_MESH_COMPRESSION] ? d = i(c) : d = he(new xe(), c, t), n[u] = {
primitive: c,
promise: d
}, r.push(d);
}
}
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(e) {
const t = this, s = this.json, n = this.extensions, i = s.meshes[e], r = i.primitives, a = [];
for (let o = 0, c = r.length; o < c; o++) {
const u = r[o].material === void 0 ? qt(this.cache) : this.getDependency("material", r[o].material);
a.push(u);
}
return a.push(t.loadGeometries(r)), Promise.all(a).then(function(o) {
const c = o.slice(0, o.length - 1), u = o[o.length - 1], l = [];
for (let h = 0, m = u.length; h < m; h++) {
const g = u[h], p = r[h];
let A;
const L = c[h];
if (p.mode === R.TRIANGLES || p.mode === R.TRIANGLE_STRIP || p.mode === R.TRIANGLE_FAN || p.mode === void 0)
A = i.isSkinnedMesh === !0 ? new He(g, L) : new je(g, L), A.isSkinnedMesh === !0 && A.normalizeSkinWeights(), p.mode === R.TRIANGLE_STRIP ? A.geometry = se(A.geometry, ct) : p.mode === R.TRIANGLE_FAN && (A.geometry = se(A.geometry, ut));
else if (p.mode === R.LINES)
A = new Ke(g, L);
else if (p.mode === R.LINE_STRIP)
A = new Ve(g, L);
else if (p.mode === R.LINE_LOOP)
A = new Xe(g, L);
else if (p.mode === R.POINTS)
A = new ze(g, L);
else
throw new Error("GLTFLoader: Primitive mode unsupported: " + p.mode);
Object.keys(A.geometry.morphAttributes).length > 0 && Qt(A, i), A.name = t.createUniqueName(i.name || "mesh_" + e), N(A, i), p.extensions && G(n, A, p), t.assignFinalMaterial(A), l.push(A);
}
for (let h = 0, m = l.length; h < m; h++)
t.associations.set(l[h], {
meshes: e,
primitives: h
});
if (l.length === 1)
return l[0];
const d = new W();
t.associations.set(d, { meshes: e });
for (let h = 0, m = l.length; h < m; h++)
d.add(l[h]);
return d;
});
}
/**