@vctrl/hooks
Version:
vctrl/hooks is a React hooks package designed to simplify 3D model loading and management within React applications. It's part of the vectreal-core ecosystem and is primarily used in the vctrl/viewer React component and the official website application.
1,269 lines • 189 kB
JavaScript
import { jsx as Bt } from "react/jsx-runtime";
import { useCallback as z, useRef as Ct, useReducer as bt, useEffect as lt, createContext as ft, useContext as Et } from "react";
import { TrianglesDrawMode as Qt, TriangleFanDrawMode as XA, TriangleStripDrawMode as Ge, Loader as TA, LoaderUtils as mA, FileLoader as aA, MeshPhysicalMaterial as W, Vector2 as SA, Color as rA, LinearSRGBColorSpace as Y, SRGBColorSpace as AA, SpotLight as dt, PointLight as ht, DirectionalLight as pt, Matrix4 as yA, Vector3 as CA, Quaternion as xe, InstancedMesh as ut, InstancedBufferAttribute as mt, Object3D as ie, TextureLoader as Te, ImageBitmapLoader as wt, BufferAttribute as X, InterleavedBuffer as Dt, InterleavedBufferAttribute as kt, LinearMipmapLinearFilter as se, NearestMipmapLinearFilter as Rt, LinearMipmapNearestFilter as Ft, NearestMipmapNearestFilter as St, LinearFilter as GA, NearestFilter as yt, RepeatWrapping as xA, MirroredRepeatWrapping as Le, ClampToEdgeWrapping as Me, PointsMaterial as Gt, Material as UA, LineBasicMaterial as xt, MeshStandardMaterial as Ue, DoubleSide as Tt, MeshBasicMaterial as hA, PropertyBinding as Lt, BufferGeometry as ne, SkinnedMesh as Mt, Mesh as Ne, LineSegments as Ut, Line as Nt, LineLoop as _t, Points as qt, Group as kA, PerspectiveCamera as Ht, MathUtils as Ot, OrthographicCamera as vt, Skeleton as Jt, AnimationClip as jt, Bone as Kt, InterpolateDiscrete as Pt, InterpolateLinear as _e, Texture as le, VectorKeyframeTrack as fe, NumberKeyframeTrack as Ee, QuaternionKeyframeTrack as Qe, ColorManagement as de, FrontSide as Yt, Interpolant as Wt, Box3 as Vt, Sphere as zt, CompressedCubeTexture as Xt, UnsignedByteType as K, CompressedArrayTexture as Zt, CompressedTexture as qe, DisplayP3ColorSpace as $t, LinearDisplayP3ColorSpace as Aa, NoColorSpace as oA, RGBA_ASTC_6x6_Format as he, RedFormat as pA, RGFormat as uA, RGBAFormat as bA, HalfFloatType as RA, FloatType as FA, DataTexture as ea, Data3DTexture as ta, RGBA_S3TC_DXT1_Format as aa, RGB_PVRTC_4BPPV1_Format as ia, RGB_ETC2_Format as sa, RGB_ETC1_Format as na, RGBA_S3TC_DXT5_Format as oa, RGBA_PVRTC_4BPPV1_Format as ra, RGBA_ETC2_EAC_Format as ca, RGBA_BPTC_Format as ga, RGBA_ASTC_4x4_Format as Ia, WebGLRenderer as Ba } from "three";
const BA = {}, V = {
emit(n, A) {
const e = BA[n];
e && e.forEach((a) => a(A));
},
on(n, A) {
BA[n] || (BA[n] = []), BA[n].push(A);
},
off(n, A) {
const e = BA[n];
e && (BA[n] = e.filter(
(a) => a !== A
));
}
};
var q = /* @__PURE__ */ ((n) => (n.gltf = "gltf", n.glb = "glb", n.usdz = "usdz", n))(q || {});
const He = {
/**
* Currently loaded file
*/
file: null,
/**
* Flag indicating if a file is currently being loaded
*/
isFileLoading: !1,
/**
* Current loading progress (0-100)
*/
progress: 0,
/**
* List of supported file types
* @type {ModelFileTypes[]}
*/
supportedFileTypes: Object.values(q)
};
function Ca(n, A) {
switch (A.type) {
case "set-file":
return { ...n, file: A.payload };
case "set-file-loading":
return { ...n, isFileLoading: A.payload };
case "set-progress":
return { ...n, progress: A.payload };
case "reset-state":
return { ...He };
default:
return n;
}
}
async function pe(n) {
const A = new Blob([n]), e = new FileReader();
return new Promise((a, t) => {
e.onloadend = () => {
if (!(e != null && e.result)) return;
const i = (e == null ? void 0 : e.result).split(",")[1];
a(i);
}, e.onerror = t, e.readAsDataURL(A);
});
}
async function ba(n) {
const A = [];
async function* e(a) {
for await (const [, t] of a)
t.kind === "file" ? yield await t.getFile() : t.kind === "directory" && (yield* e(t));
}
for await (const a of e(n))
A.push(a);
return A;
}
function ue(n, A) {
if (A === Qt)
return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), n;
if (A === XA || A === Ge) {
let e = n.getIndex();
if (e === null) {
const s = [], o = n.getAttribute("position");
if (o !== void 0) {
for (let r = 0; r < o.count; r++)
s.push(r);
n.setIndex(s), e = n.getIndex();
} else
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), n;
}
const a = e.count - 2, t = [];
if (A === XA)
for (let s = 1; s <= a; s++)
t.push(e.getX(0)), t.push(e.getX(s)), t.push(e.getX(s + 1));
else
for (let s = 0; s < a; s++)
s % 2 === 0 ? (t.push(e.getX(s)), t.push(e.getX(s + 1)), t.push(e.getX(s + 2))) : (t.push(e.getX(s + 2)), t.push(e.getX(s + 1)), t.push(e.getX(s)));
t.length / 3 !== a && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
const i = n.clone();
return i.setIndex(t), i.clearGroups(), i;
} else
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", A), n;
}
class la extends TA {
constructor(A) {
super(A), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(e) {
return new ha(e);
}), this.register(function(e) {
return new pa(e);
}), this.register(function(e) {
return new ya(e);
}), this.register(function(e) {
return new Ga(e);
}), this.register(function(e) {
return new xa(e);
}), this.register(function(e) {
return new ma(e);
}), this.register(function(e) {
return new wa(e);
}), this.register(function(e) {
return new Da(e);
}), this.register(function(e) {
return new ka(e);
}), this.register(function(e) {
return new da(e);
}), this.register(function(e) {
return new Ra(e);
}), this.register(function(e) {
return new ua(e);
}), this.register(function(e) {
return new Sa(e);
}), this.register(function(e) {
return new Fa(e);
}), this.register(function(e) {
return new Ea(e);
}), this.register(function(e) {
return new Ta(e);
}), this.register(function(e) {
return new La(e);
});
}
load(A, e, a, t) {
const i = this;
let s;
if (this.resourcePath !== "")
s = this.resourcePath;
else if (this.path !== "") {
const c = mA.extractUrlBase(A);
s = mA.resolveURL(c, this.path);
} else
s = mA.extractUrlBase(A);
this.manager.itemStart(A);
const o = function(c) {
t ? t(c) : console.error(c), i.manager.itemError(A), i.manager.itemEnd(A);
}, r = new aA(this.manager);
r.setPath(this.path), r.setResponseType("arraybuffer"), r.setRequestHeader(this.requestHeader), r.setWithCredentials(this.withCredentials), r.load(A, function(c) {
try {
i.parse(c, s, function(I) {
e(I), i.manager.itemEnd(A);
}, o);
} catch (I) {
o(I);
}
}, a, o);
}
setDRACOLoader(A) {
return this.dracoLoader = A, this;
}
setDDSLoader() {
throw new Error(
'THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".'
);
}
setKTX2Loader(A) {
return this.ktx2Loader = A, this;
}
setMeshoptDecoder(A) {
return this.meshoptDecoder = A, this;
}
register(A) {
return this.pluginCallbacks.indexOf(A) === -1 && this.pluginCallbacks.push(A), this;
}
unregister(A) {
return this.pluginCallbacks.indexOf(A) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(A), 1), this;
}
parse(A, e, a, t) {
let i;
const s = {}, o = {}, r = new TextDecoder();
if (typeof A == "string")
i = JSON.parse(A);
else if (A instanceof ArrayBuffer)
if (r.decode(new Uint8Array(A, 0, 4)) === Oe) {
try {
s[y.KHR_BINARY_GLTF] = new Ma(A);
} catch (g) {
t && t(g);
return;
}
i = JSON.parse(s[y.KHR_BINARY_GLTF].content);
} else
i = JSON.parse(r.decode(A));
else
i = A;
if (i.asset === void 0 || i.asset.version[0] < 2) {
t && t(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
return;
}
const c = new Wa(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 I = 0; I < this.pluginCallbacks.length; I++) {
const g = this.pluginCallbacks[I](c);
g.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), o[g.name] = g, s[g.name] = !0;
}
if (i.extensionsUsed)
for (let I = 0; I < i.extensionsUsed.length; ++I) {
const g = i.extensionsUsed[I], B = i.extensionsRequired || [];
switch (g) {
case y.KHR_MATERIALS_UNLIT:
s[g] = new Qa();
break;
case y.KHR_DRACO_MESH_COMPRESSION:
s[g] = new Ua(i, this.dracoLoader);
break;
case y.KHR_TEXTURE_TRANSFORM:
s[g] = new Na();
break;
case y.KHR_MESH_QUANTIZATION:
s[g] = new _a();
break;
default:
B.indexOf(g) >= 0 && o[g] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + g + '".');
}
}
c.setExtensions(s), c.setPlugins(o), c.parse(a, t);
}
parseAsync(A, e) {
const a = this;
return new Promise(function(t, i) {
a.parse(A, e, t, i);
});
}
}
function fa() {
let n = {};
return {
get: function(A) {
return n[A];
},
add: function(A, e) {
n[A] = e;
},
remove: function(A) {
delete n[A];
},
removeAll: function() {
n = {};
}
};
}
const y = {
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 Ea {
constructor(A) {
this.parser = A, this.name = y.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} };
}
_markDefs() {
const A = this.parser, e = this.parser.json.nodes || [];
for (let a = 0, t = e.length; a < t; a++) {
const i = e[a];
i.extensions && i.extensions[this.name] && i.extensions[this.name].light !== void 0 && A._addNodeRef(this.cache, i.extensions[this.name].light);
}
}
_loadLight(A) {
const e = this.parser, a = "light:" + A;
let t = e.cache.get(a);
if (t) return t;
const i = e.json, r = ((i.extensions && i.extensions[this.name] || {}).lights || [])[A];
let c;
const I = new rA(16777215);
r.color !== void 0 && I.setRGB(r.color[0], r.color[1], r.color[2], Y);
const g = r.range !== void 0 ? r.range : 0;
switch (r.type) {
case "directional":
c = new pt(I), c.target.position.set(0, 0, -1), c.add(c.target);
break;
case "point":
c = new ht(I), c.distance = g;
break;
case "spot":
c = new dt(I), c.distance = g, r.spot = r.spot || {}, r.spot.innerConeAngle = r.spot.innerConeAngle !== void 0 ? r.spot.innerConeAngle : 0, r.spot.outerConeAngle = r.spot.outerConeAngle !== void 0 ? r.spot.outerConeAngle : Math.PI / 4, c.angle = r.spot.outerConeAngle, c.penumbra = 1 - r.spot.innerConeAngle / r.spot.outerConeAngle, c.target.position.set(0, 0, -1), c.add(c.target);
break;
default:
throw new Error("THREE.GLTFLoader: Unexpected light type: " + r.type);
}
return c.position.set(0, 0, 0), c.decay = 2, tA(c, r), r.intensity !== void 0 && (c.intensity = r.intensity), c.name = e.createUniqueName(r.name || "light_" + A), t = Promise.resolve(c), e.cache.add(a, t), t;
}
getDependency(A, e) {
if (A === "light")
return this._loadLight(e);
}
createNodeAttachment(A) {
const e = this, a = this.parser, i = a.json.nodes[A], o = (i.extensions && i.extensions[this.name] || {}).light;
return o === void 0 ? null : this._loadLight(o).then(function(r) {
return a._getNodeRef(e.cache, o, r);
});
}
}
class Qa {
constructor() {
this.name = y.KHR_MATERIALS_UNLIT;
}
getMaterialType() {
return hA;
}
extendParams(A, e, a) {
const t = [];
A.color = new rA(1, 1, 1), A.opacity = 1;
const i = e.pbrMetallicRoughness;
if (i) {
if (Array.isArray(i.baseColorFactor)) {
const s = i.baseColorFactor;
A.color.setRGB(s[0], s[1], s[2], Y), A.opacity = s[3];
}
i.baseColorTexture !== void 0 && t.push(a.assignTexture(A, "map", i.baseColorTexture, AA));
}
return Promise.all(t);
}
}
class da {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_EMISSIVE_STRENGTH;
}
extendMaterialParams(A, e) {
const t = this.parser.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = t.extensions[this.name].emissiveStrength;
return i !== void 0 && (e.emissiveIntensity = i), Promise.resolve();
}
}
class ha {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_CLEARCOAT;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const a = this.parser, t = a.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = [], s = t.extensions[this.name];
if (s.clearcoatFactor !== void 0 && (e.clearcoat = s.clearcoatFactor), s.clearcoatTexture !== void 0 && i.push(a.assignTexture(e, "clearcoatMap", s.clearcoatTexture)), s.clearcoatRoughnessFactor !== void 0 && (e.clearcoatRoughness = s.clearcoatRoughnessFactor), s.clearcoatRoughnessTexture !== void 0 && i.push(a.assignTexture(e, "clearcoatRoughnessMap", s.clearcoatRoughnessTexture)), s.clearcoatNormalTexture !== void 0 && (i.push(a.assignTexture(e, "clearcoatNormalMap", s.clearcoatNormalTexture)), s.clearcoatNormalTexture.scale !== void 0)) {
const o = s.clearcoatNormalTexture.scale;
e.clearcoatNormalScale = new SA(o, o);
}
return Promise.all(i);
}
}
class pa {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_DISPERSION;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const t = this.parser.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = t.extensions[this.name];
return e.dispersion = i.dispersion !== void 0 ? i.dispersion : 0, Promise.resolve();
}
}
class ua {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_IRIDESCENCE;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const a = this.parser, t = a.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = [], s = t.extensions[this.name];
return s.iridescenceFactor !== void 0 && (e.iridescence = s.iridescenceFactor), s.iridescenceTexture !== void 0 && i.push(a.assignTexture(e, "iridescenceMap", s.iridescenceTexture)), s.iridescenceIor !== void 0 && (e.iridescenceIOR = s.iridescenceIor), e.iridescenceThicknessRange === void 0 && (e.iridescenceThicknessRange = [100, 400]), s.iridescenceThicknessMinimum !== void 0 && (e.iridescenceThicknessRange[0] = s.iridescenceThicknessMinimum), s.iridescenceThicknessMaximum !== void 0 && (e.iridescenceThicknessRange[1] = s.iridescenceThicknessMaximum), s.iridescenceThicknessTexture !== void 0 && i.push(a.assignTexture(e, "iridescenceThicknessMap", s.iridescenceThicknessTexture)), Promise.all(i);
}
}
class ma {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_SHEEN;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const a = this.parser, t = a.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = [];
e.sheenColor = new rA(0, 0, 0), e.sheenRoughness = 0, e.sheen = 1;
const s = t.extensions[this.name];
if (s.sheenColorFactor !== void 0) {
const o = s.sheenColorFactor;
e.sheenColor.setRGB(o[0], o[1], o[2], Y);
}
return s.sheenRoughnessFactor !== void 0 && (e.sheenRoughness = s.sheenRoughnessFactor), s.sheenColorTexture !== void 0 && i.push(a.assignTexture(e, "sheenColorMap", s.sheenColorTexture, AA)), s.sheenRoughnessTexture !== void 0 && i.push(a.assignTexture(e, "sheenRoughnessMap", s.sheenRoughnessTexture)), Promise.all(i);
}
}
class wa {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_TRANSMISSION;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const a = this.parser, t = a.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = [], s = t.extensions[this.name];
return s.transmissionFactor !== void 0 && (e.transmission = s.transmissionFactor), s.transmissionTexture !== void 0 && i.push(a.assignTexture(e, "transmissionMap", s.transmissionTexture)), Promise.all(i);
}
}
class Da {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_VOLUME;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const a = this.parser, t = a.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = [], s = t.extensions[this.name];
e.thickness = s.thicknessFactor !== void 0 ? s.thicknessFactor : 0, s.thicknessTexture !== void 0 && i.push(a.assignTexture(e, "thicknessMap", s.thicknessTexture)), e.attenuationDistance = s.attenuationDistance || 1 / 0;
const o = s.attenuationColor || [1, 1, 1];
return e.attenuationColor = new rA().setRGB(o[0], o[1], o[2], Y), Promise.all(i);
}
}
class ka {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_IOR;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const t = this.parser.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = t.extensions[this.name];
return e.ior = i.ior !== void 0 ? i.ior : 1.5, Promise.resolve();
}
}
class Ra {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_SPECULAR;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const a = this.parser, t = a.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = [], s = t.extensions[this.name];
e.specularIntensity = s.specularFactor !== void 0 ? s.specularFactor : 1, s.specularTexture !== void 0 && i.push(a.assignTexture(e, "specularIntensityMap", s.specularTexture));
const o = s.specularColorFactor || [1, 1, 1];
return e.specularColor = new rA().setRGB(o[0], o[1], o[2], Y), s.specularColorTexture !== void 0 && i.push(a.assignTexture(e, "specularColorMap", s.specularColorTexture, AA)), Promise.all(i);
}
}
class Fa {
constructor(A) {
this.parser = A, this.name = y.EXT_MATERIALS_BUMP;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const a = this.parser, t = a.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = [], s = t.extensions[this.name];
return e.bumpScale = s.bumpFactor !== void 0 ? s.bumpFactor : 1, s.bumpTexture !== void 0 && i.push(a.assignTexture(e, "bumpMap", s.bumpTexture)), Promise.all(i);
}
}
class Sa {
constructor(A) {
this.parser = A, this.name = y.KHR_MATERIALS_ANISOTROPY;
}
getMaterialType(A) {
const a = this.parser.json.materials[A];
return !a.extensions || !a.extensions[this.name] ? null : W;
}
extendMaterialParams(A, e) {
const a = this.parser, t = a.json.materials[A];
if (!t.extensions || !t.extensions[this.name])
return Promise.resolve();
const i = [], s = t.extensions[this.name];
return s.anisotropyStrength !== void 0 && (e.anisotropy = s.anisotropyStrength), s.anisotropyRotation !== void 0 && (e.anisotropyRotation = s.anisotropyRotation), s.anisotropyTexture !== void 0 && i.push(a.assignTexture(e, "anisotropyMap", s.anisotropyTexture)), Promise.all(i);
}
}
class ya {
constructor(A) {
this.parser = A, this.name = y.KHR_TEXTURE_BASISU;
}
loadTexture(A) {
const e = this.parser, a = e.json, t = a.textures[A];
if (!t.extensions || !t.extensions[this.name])
return null;
const i = t.extensions[this.name], s = e.options.ktx2Loader;
if (!s) {
if (a.extensionsRequired && a.extensionsRequired.indexOf(this.name) >= 0)
throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
return null;
}
return e.loadTextureImage(A, i.source, s);
}
}
class Ga {
constructor(A) {
this.parser = A, this.name = y.EXT_TEXTURE_WEBP, this.isSupported = null;
}
loadTexture(A) {
const e = this.name, a = this.parser, t = a.json, i = t.textures[A];
if (!i.extensions || !i.extensions[e])
return null;
const s = i.extensions[e], o = t.images[s.source];
let r = a.textureLoader;
if (o.uri) {
const c = a.options.manager.getHandler(o.uri);
c !== null && (r = c);
}
return this.detectSupport().then(function(c) {
if (c) return a.loadTextureImage(A, s.source, r);
if (t.extensionsRequired && t.extensionsRequired.indexOf(e) >= 0)
throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
return a.loadTexture(A);
});
}
detectSupport() {
return this.isSupported || (this.isSupported = new Promise(function(A) {
const e = new Image();
e.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA", e.onload = e.onerror = function() {
A(e.height === 1);
};
})), this.isSupported;
}
}
class xa {
constructor(A) {
this.parser = A, this.name = y.EXT_TEXTURE_AVIF, this.isSupported = null;
}
loadTexture(A) {
const e = this.name, a = this.parser, t = a.json, i = t.textures[A];
if (!i.extensions || !i.extensions[e])
return null;
const s = i.extensions[e], o = t.images[s.source];
let r = a.textureLoader;
if (o.uri) {
const c = a.options.manager.getHandler(o.uri);
c !== null && (r = c);
}
return this.detectSupport().then(function(c) {
if (c) return a.loadTextureImage(A, s.source, r);
if (t.extensionsRequired && t.extensionsRequired.indexOf(e) >= 0)
throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");
return a.loadTexture(A);
});
}
detectSupport() {
return this.isSupported || (this.isSupported = new Promise(function(A) {
const e = new Image();
e.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=", e.onload = e.onerror = function() {
A(e.height === 1);
};
})), this.isSupported;
}
}
class Ta {
constructor(A) {
this.name = y.EXT_MESHOPT_COMPRESSION, this.parser = A;
}
loadBufferView(A) {
const e = this.parser.json, a = e.bufferViews[A];
if (a.extensions && a.extensions[this.name]) {
const t = a.extensions[this.name], i = this.parser.getDependency("buffer", t.buffer), s = this.parser.options.meshoptDecoder;
if (!s || !s.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(o) {
const r = t.byteOffset || 0, c = t.byteLength || 0, I = t.count, g = t.byteStride, B = new Uint8Array(o, r, c);
return s.decodeGltfBufferAsync ? s.decodeGltfBufferAsync(I, g, B, t.mode, t.filter).then(function(C) {
return C.buffer;
}) : s.ready.then(function() {
const C = new ArrayBuffer(I * g);
return s.decodeGltfBuffer(new Uint8Array(C), I, g, B, t.mode, t.filter), C;
});
});
} else
return null;
}
}
class La {
constructor(A) {
this.name = y.EXT_MESH_GPU_INSTANCING, this.parser = A;
}
createNodeMesh(A) {
const e = this.parser.json, a = e.nodes[A];
if (!a.extensions || !a.extensions[this.name] || a.mesh === void 0)
return null;
const t = e.meshes[a.mesh];
for (const c of t.primitives)
if (c.mode !== O.TRIANGLES && c.mode !== O.TRIANGLE_STRIP && c.mode !== O.TRIANGLE_FAN && c.mode !== void 0)
return null;
const s = a.extensions[this.name].attributes, o = [], r = {};
for (const c in s)
o.push(this.parser.getDependency("accessor", s[c]).then((I) => (r[c] = I, r[c])));
return o.length < 1 ? null : (o.push(this.parser.createNodeMesh(A)), Promise.all(o).then((c) => {
const I = c.pop(), g = I.isGroup ? I.children : [I], B = c[0].count, C = [];
for (const f of g) {
const d = new yA(), p = new CA(), E = new xe(), l = new CA(1, 1, 1), h = new ut(f.geometry, f.material, B);
for (let u = 0; u < B; u++)
r.TRANSLATION && p.fromBufferAttribute(r.TRANSLATION, u), r.ROTATION && E.fromBufferAttribute(r.ROTATION, u), r.SCALE && l.fromBufferAttribute(r.SCALE, u), h.setMatrixAt(u, d.compose(p, E, l));
for (const u in r)
if (u === "_COLOR_0") {
const k = r[u];
h.instanceColor = new mt(k.array, k.itemSize, k.normalized);
} else u !== "TRANSLATION" && u !== "ROTATION" && u !== "SCALE" && f.geometry.setAttribute(u, r[u]);
ie.prototype.copy.call(h, f), this.parser.assignFinalMaterial(h), C.push(h);
}
return I.isGroup ? (I.clear(), I.add(...C), I) : C[0];
}));
}
}
const Oe = "glTF", QA = 12, me = { JSON: 1313821514, BIN: 5130562 };
class Ma {
constructor(A) {
this.name = y.KHR_BINARY_GLTF, this.content = null, this.body = null;
const e = new DataView(A, 0, QA), a = new TextDecoder();
if (this.header = {
magic: a.decode(new Uint8Array(A.slice(0, 4))),
version: e.getUint32(4, !0),
length: e.getUint32(8, !0)
}, this.header.magic !== Oe)
throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
if (this.header.version < 2)
throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
const t = this.header.length - QA, i = new DataView(A, QA);
let s = 0;
for (; s < t; ) {
const o = i.getUint32(s, !0);
s += 4;
const r = i.getUint32(s, !0);
if (s += 4, r === me.JSON) {
const c = new Uint8Array(A, QA + s, o);
this.content = a.decode(c);
} else if (r === me.BIN) {
const c = QA + s;
this.body = A.slice(c, c + o);
}
s += o;
}
if (this.content === null)
throw new Error("THREE.GLTFLoader: JSON content not found.");
}
}
class Ua {
constructor(A, e) {
if (!e)
throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
this.name = y.KHR_DRACO_MESH_COMPRESSION, this.json = A, this.dracoLoader = e, this.dracoLoader.preload();
}
decodePrimitive(A, e) {
const a = this.json, t = this.dracoLoader, i = A.extensions[this.name].bufferView, s = A.extensions[this.name].attributes, o = {}, r = {}, c = {};
for (const I in s) {
const g = ZA[I] || I.toLowerCase();
o[g] = s[I];
}
for (const I in A.attributes) {
const g = ZA[I] || I.toLowerCase();
if (s[I] !== void 0) {
const B = a.accessors[A.attributes[I]], C = fA[B.componentType];
c[g] = C.name, r[g] = B.normalized === !0;
}
}
return e.getDependency("bufferView", i).then(function(I) {
return new Promise(function(g, B) {
t.decodeDracoFile(I, function(C) {
for (const f in C.attributes) {
const d = C.attributes[f], p = r[f];
p !== void 0 && (d.normalized = p);
}
g(C);
}, o, c, Y, B);
});
});
}
}
class Na {
constructor() {
this.name = y.KHR_TEXTURE_TRANSFORM;
}
extendTexture(A, e) {
return (e.texCoord === void 0 || e.texCoord === A.channel) && e.offset === void 0 && e.rotation === void 0 && e.scale === void 0 || (A = A.clone(), e.texCoord !== void 0 && (A.channel = e.texCoord), e.offset !== void 0 && A.offset.fromArray(e.offset), e.rotation !== void 0 && (A.rotation = e.rotation), e.scale !== void 0 && A.repeat.fromArray(e.scale), A.needsUpdate = !0), A;
}
}
class _a {
constructor() {
this.name = y.KHR_MESH_QUANTIZATION;
}
}
class ve extends Wt {
constructor(A, e, a, t) {
super(A, e, a, t);
}
copySampleValue_(A) {
const e = this.resultBuffer, a = this.sampleValues, t = this.valueSize, i = A * t * 3 + t;
for (let s = 0; s !== t; s++)
e[s] = a[i + s];
return e;
}
interpolate_(A, e, a, t) {
const i = this.resultBuffer, s = this.sampleValues, o = this.valueSize, r = o * 2, c = o * 3, I = t - e, g = (a - e) / I, B = g * g, C = B * g, f = A * c, d = f - c, p = -2 * C + 3 * B, E = C - B, l = 1 - p, h = E - B + g;
for (let u = 0; u !== o; u++) {
const k = s[d + u + o], F = s[d + u + r] * I, G = s[f + u + o], M = s[f + u] * I;
i[u] = l * k + h * F + p * G + E * M;
}
return i;
}
}
const qa = new xe();
class Ha extends ve {
interpolate_(A, e, a, t) {
const i = super.interpolate_(A, e, a, t);
return qa.fromArray(i).normalize().toArray(i), i;
}
}
const O = {
POINTS: 0,
LINES: 1,
LINE_LOOP: 2,
LINE_STRIP: 3,
TRIANGLES: 4,
TRIANGLE_STRIP: 5,
TRIANGLE_FAN: 6
}, fA = {
5120: Int8Array,
5121: Uint8Array,
5122: Int16Array,
5123: Uint16Array,
5125: Uint32Array,
5126: Float32Array
}, we = {
9728: yt,
9729: GA,
9984: St,
9985: Ft,
9986: Rt,
9987: se
}, De = {
33071: Me,
33648: Le,
10497: xA
}, NA = {
SCALAR: 1,
VEC2: 2,
VEC3: 3,
VEC4: 4,
MAT2: 4,
MAT3: 9,
MAT4: 16
}, ZA = {
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"
}, sA = {
scale: "scale",
translation: "position",
rotation: "quaternion",
weights: "morphTargetInfluences"
}, Oa = {
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: _e,
STEP: Pt
}, _A = {
OPAQUE: "OPAQUE",
MASK: "MASK",
BLEND: "BLEND"
};
function va(n) {
return n.DefaultMaterial === void 0 && (n.DefaultMaterial = new Ue({
color: 16777215,
emissive: 0,
metalness: 1,
roughness: 1,
transparent: !1,
depthTest: !0,
side: Yt
})), n.DefaultMaterial;
}
function gA(n, A, e) {
for (const a in e.extensions)
n[a] === void 0 && (A.userData.gltfExtensions = A.userData.gltfExtensions || {}, A.userData.gltfExtensions[a] = e.extensions[a]);
}
function tA(n, A) {
A.extras !== void 0 && (typeof A.extras == "object" ? Object.assign(n.userData, A.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + A.extras));
}
function Ja(n, A, e) {
let a = !1, t = !1, i = !1;
for (let c = 0, I = A.length; c < I; c++) {
const g = A[c];
if (g.POSITION !== void 0 && (a = !0), g.NORMAL !== void 0 && (t = !0), g.COLOR_0 !== void 0 && (i = !0), a && t && i) break;
}
if (!a && !t && !i) return Promise.resolve(n);
const s = [], o = [], r = [];
for (let c = 0, I = A.length; c < I; c++) {
const g = A[c];
if (a) {
const B = g.POSITION !== void 0 ? e.getDependency("accessor", g.POSITION) : n.attributes.position;
s.push(B);
}
if (t) {
const B = g.NORMAL !== void 0 ? e.getDependency("accessor", g.NORMAL) : n.attributes.normal;
o.push(B);
}
if (i) {
const B = g.COLOR_0 !== void 0 ? e.getDependency("accessor", g.COLOR_0) : n.attributes.color;
r.push(B);
}
}
return Promise.all([
Promise.all(s),
Promise.all(o),
Promise.all(r)
]).then(function(c) {
const I = c[0], g = c[1], B = c[2];
return a && (n.morphAttributes.position = I), t && (n.morphAttributes.normal = g), i && (n.morphAttributes.color = B), n.morphTargetsRelative = !0, n;
});
}
function ja(n, A) {
if (n.updateMorphTargets(), A.weights !== void 0)
for (let e = 0, a = A.weights.length; e < a; e++)
n.morphTargetInfluences[e] = A.weights[e];
if (A.extras && Array.isArray(A.extras.targetNames)) {
const e = A.extras.targetNames;
if (n.morphTargetInfluences.length === e.length) {
n.morphTargetDictionary = {};
for (let a = 0, t = e.length; a < t; a++)
n.morphTargetDictionary[e[a]] = a;
} else
console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
}
}
function Ka(n) {
let A;
const e = n.extensions && n.extensions[y.KHR_DRACO_MESH_COMPRESSION];
if (e ? A = "draco:" + e.bufferView + ":" + e.indices + ":" + qA(e.attributes) : A = n.indices + ":" + qA(n.attributes) + ":" + n.mode, n.targets !== void 0)
for (let a = 0, t = n.targets.length; a < t; a++)
A += ":" + qA(n.targets[a]);
return A;
}
function qA(n) {
let A = "";
const e = Object.keys(n).sort();
for (let a = 0, t = e.length; a < t; a++)
A += e[a] + ":" + n[e[a]] + ";";
return A;
}
function $A(n) {
switch (n) {
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 Pa(n) {
return n.search(/\.jpe?g($|\?)/i) > 0 || n.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : n.search(/\.webp($|\?)/i) > 0 || n.search(/^data\:image\/webp/) === 0 ? "image/webp" : "image/png";
}
const Ya = new yA();
class Wa {
constructor(A = {}, e = {}) {
this.json = A, this.extensions = {}, this.plugins = {}, this.options = e, this.cache = new fa(), 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 a = !1, t = -1, i = !1, s = -1;
if (typeof navigator < "u") {
const o = navigator.userAgent;
a = /^((?!chrome|android).)*safari/i.test(o) === !0;
const r = o.match(/Version\/(\d+)/);
t = a && r ? parseInt(r[1], 10) : -1, i = o.indexOf("Firefox") > -1, s = i ? o.match(/Firefox\/([0-9]+)\./)[1] : -1;
}
typeof createImageBitmap > "u" || a && t < 17 || i && s < 98 ? this.textureLoader = new Te(this.options.manager) : this.textureLoader = new wt(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new aA(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(!0);
}
setExtensions(A) {
this.extensions = A;
}
setPlugins(A) {
this.plugins = A;
}
parse(A, e) {
const a = this, t = this.json, i = this.extensions;
this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(s) {
return s._markDefs && s._markDefs();
}), Promise.all(this._invokeAll(function(s) {
return s.beforeRoot && s.beforeRoot();
})).then(function() {
return Promise.all([
a.getDependencies("scene"),
a.getDependencies("animation"),
a.getDependencies("camera")
]);
}).then(function(s) {
const o = {
scene: s[0][t.scene || 0],
scenes: s[0],
animations: s[1],
cameras: s[2],
asset: t.asset,
parser: a,
userData: {}
};
return gA(i, o, t), tA(o, t), Promise.all(a._invokeAll(function(r) {
return r.afterRoot && r.afterRoot(o);
})).then(function() {
for (const r of o.scenes)
r.updateMatrixWorld();
A(o);
});
}).catch(e);
}
/**
* Marks the special nodes/meshes in json for efficient parse.
*/
_markDefs() {
const A = this.json.nodes || [], e = this.json.skins || [], a = this.json.meshes || [];
for (let t = 0, i = e.length; t < i; t++) {
const s = e[t].joints;
for (let o = 0, r = s.length; o < r; o++)
A[s[o]].isBone = !0;
}
for (let t = 0, i = A.length; t < i; t++) {
const s = A[t];
s.mesh !== void 0 && (this._addNodeRef(this.meshCache, s.mesh), s.skin !== void 0 && (a[s.mesh].isSkinnedMesh = !0)), s.camera !== void 0 && this._addNodeRef(this.cameraCache, s.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(A, e) {
e !== void 0 && (A.refs[e] === void 0 && (A.refs[e] = A.uses[e] = 0), A.refs[e]++);
}
/** Returns a reference to a shared resource, cloning it if necessary. */
_getNodeRef(A, e, a) {
if (A.refs[e] <= 1) return a;
const t = a.clone(), i = (s, o) => {
const r = this.associations.get(s);
r != null && this.associations.set(o, r);
for (const [c, I] of s.children.entries())
i(I, o.children[c]);
};
return i(a, t), t.name += "_instance_" + A.uses[e]++, t;
}
_invokeOne(A) {
const e = Object.values(this.plugins);
e.push(this);
for (let a = 0; a < e.length; a++) {
const t = A(e[a]);
if (t) return t;
}
return null;
}
_invokeAll(A) {
const e = Object.values(this.plugins);
e.unshift(this);
const a = [];
for (let t = 0; t < e.length; t++) {
const i = A(e[t]);
i && a.push(i);
}
return a;
}
/**
* Requests the specified dependency asynchronously, with caching.
* @param {string} type
* @param {number} index
* @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
*/
getDependency(A, e) {
const a = A + ":" + e;
let t = this.cache.get(a);
if (!t) {
switch (A) {
case "scene":
t = this.loadScene(e);
break;
case "node":
t = this._invokeOne(function(i) {
return i.loadNode && i.loadNode(e);
});
break;
case "mesh":
t = this._invokeOne(function(i) {
return i.loadMesh && i.loadMesh(e);
});
break;
case "accessor":
t = this.loadAccessor(e);
break;
case "bufferView":
t = this._invokeOne(function(i) {
return i.loadBufferView && i.loadBufferView(e);
});
break;
case "buffer":
t = this.loadBuffer(e);
break;
case "material":
t = this._invokeOne(function(i) {
return i.loadMaterial && i.loadMaterial(e);
});
break;
case "texture":
t = this._invokeOne(function(i) {
return i.loadTexture && i.loadTexture(e);
});
break;
case "skin":
t = this.loadSkin(e);
break;
case "animation":
t = this._invokeOne(function(i) {
return i.loadAnimation && i.loadAnimation(e);
});
break;
case "camera":
t = this.loadCamera(e);
break;
default:
if (t = this._invokeOne(function(i) {
return i != this && i.getDependency && i.getDependency(A, e);
}), !t)
throw new Error("Unknown type: " + A);
break;
}
this.cache.add(a, t);
}
return t;
}
/**
* Requests all dependencies of the specified type asynchronously, with caching.
* @param {string} type
* @return {Promise<Array<Object>>}
*/
getDependencies(A) {
let e = this.cache.get(A);
if (!e) {
const a = this, t = this.json[A + (A === "mesh" ? "es" : "s")] || [];
e = Promise.all(t.map(function(i, s) {
return a.getDependency(A, s);
})), this.cache.add(A, 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(A) {
const e = this.json.buffers[A], a = 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 && A === 0)
return Promise.resolve(this.extensions[y.KHR_BINARY_GLTF].body);
const t = this.options;
return new Promise(function(i, s) {
a.load(mA.resolveURL(e.uri, t.path), i, void 0, function() {
s(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(A) {
const e = this.json.bufferViews[A];
return this.getDependency("buffer", e.buffer).then(function(a) {
const t = e.byteLength || 0, i = e.byteOffset || 0;
return a.slice(i, i + t);
});
}
/**
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
* @param {number} accessorIndex
* @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
*/
loadAccessor(A) {
const e = this, a = this.json, t = this.json.accessors[A];
if (t.bufferView === void 0 && t.sparse === void 0) {
const s = NA[t.type], o = fA[t.componentType], r = t.normalized === !0, c = new o(t.count * s);
return Promise.resolve(new X(c, s, r));
}
const i = [];
return t.bufferView !== void 0 ? i.push(this.getDependency("bufferView", t.bufferView)) : i.push(null), t.sparse !== void 0 && (i.push(this.getDependency("bufferView", t.sparse.indices.bufferView)), i.push(this.getDependency("bufferView", t.sparse.values.bufferView))), Promise.all(i).then(function(s) {
const o = s[0], r = NA[t.type], c = fA[t.componentType], I = c.BYTES_PER_ELEMENT, g = I * r, B = t.byteOffset || 0, C = t.bufferView !== void 0 ? a.bufferViews[t.bufferView].byteStride : void 0, f = t.normalized === !0;
let d, p;
if (C && C !== g) {
const E = Math.floor(B / C), l = "InterleavedBuffer:" + t.bufferView + ":" + t.componentType + ":" + E + ":" + t.count;
let h = e.cache.get(l);
h || (d = new c(o, E * C, t.count * C / I), h = new Dt(d, C / I), e.cache.add(l, h)), p = new kt(h, r, B % C / I, f);
} else
o === null ? d = new c(t.count * r) : d = new c(o, B, t.count * r), p = new X(d, r, f);
if (t.sparse !== void 0) {
const E = NA.SCALAR, l = fA[t.sparse.indices.componentType], h = t.sparse.indices.byteOffset || 0, u = t.sparse.values.byteOffset || 0, k = new l(s[1], h, t.sparse.count * E), F = new c(s[2], u, t.sparse.count * r);
o !== null && (p = new X(p.array.slice(), p.itemSize, p.normalized));
for (let G = 0, M = k.length; G < M; G++) {
const b = k[G];
if (p.setX(b, F[G * r]), r >= 2 && p.setY(b, F[G * r + 1]), r >= 3 && p.setZ(b, F[G * r + 2]), r >= 4 && p.setW(b, F[G * r + 3]), r >= 5) throw new Error("THREE.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(A) {
const e = this.json, a = this.options, i = e.textures[A].source, s = e.images[i];
let o = this.textureLoader;
if (s.uri) {
const r = a.manager.getHandler(s.uri);
r !== null && (o = r);
}
return this.loadTextureImage(A, i, o);
}
loadTextureImage(A, e, a) {
const t = this, i = this.json, s = i.textures[A], o = i.images[e], r = (o.uri || o.bufferView) + ":" + s.sampler;
if (this.textureCache[r])
return this.textureCache[r];
const c = this.loadImageSource(e, a).then(function(I) {
I.flipY = !1, I.name = s.name || o.name || "", I.name === "" && typeof o.uri == "string" && o.uri.startsWith("data:image/") === !1 && (I.name = o.uri);
const B = (i.samplers || {})[s.sampler] || {};
return I.magFilter = we[B.magFilter] || GA, I.minFilter = we[B.minFilter] || se, I.wrapS = De[B.wrapS] || xA, I.wrapT = De[B.wrapT] || xA, t.associations.set(I, { textures: A }), I;
}).catch(function() {
return null;
});
return this.textureCache[r] = c, c;
}
loadImageSource(A, e) {
const a = this, t = this.json, i = this.options;
if (this.sourceCache[A] !== void 0)
return this.sourceCache[A].then((g) => g.clone());
const s = t.images[A], o = self.URL || self.webkitURL;
let r = s.uri || "", c = !1;
if (s.bufferView !== void 0)
r = a.getDependency("bufferView", s.bufferView).then(function(g) {
c = !0;
const B = new Blob([g], { type: s.mimeType });
return r = o.createObjectURL(B), r;
});
else if (s.uri === void 0)
throw new Error("THREE.GLTFLoader: Image " + A + " is missing URI and bufferView");
const I = Promise.resolve(r).then(function(g) {
return new Promise(function(B, C) {
let f = B;
e.isImageBitmapLoader === !0 && (f = function(d) {
const p = new le(d);
p.needsUpdate = !0, B(p);
}), e.load(mA.resolveURL(g, i.path), f, void 0, C);
});
}).then(function(g) {
return c === !0 && o.revokeObjectURL(r), tA(g, s), g.userData.mimeType = s.mimeType || Pa(s.uri), g;
}).catch(function(g) {
throw console.error("THREE.GLTFLoader: Couldn't load texture", r), g;
});
return this.sourceCache[A] = I, I;
}
/**
* Asynchronously assigns a texture to the given material parameters.
* @param {Object} materialParams
* @param {string} mapName
* @param {Object} mapDef
* @return {Promise<Texture>}
*/
assignTexture(A, e, a, t) {
const i = this;
return this.getDependency("texture", a.index).then(function(s) {
if (!s) return null;
if (a.texCoord !== void 0 && a.texCoord > 0 && (s = s.clone(), s.channel = a.texCoord), i.extensions[y.KHR_TEXTURE_TRANSFORM]) {
const o = a.extensions !== void 0 ? a.extensions[y.KHR_TEXTURE_TRANSFORM] : void 0;
if (o) {
const r = i.associations.get(s);
s = i.extensions[y.KHR_TEXTURE_TRANSFORM].extendTexture(s, o), i.associations.set(s, r);
}
}
return t !== void 0 && (s.colorSpace = t), A[e] = s, s;
});
}
/**
* 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