UNPKG

@j-kyoda/vue-three-vrm

Version:

A Vue 3 component designed to render and display VRM models on your web pages.

1,371 lines (1,370 loc) 131 kB
import { getCurrentInstance as ft, useTemplateRef as mt, watch as N, onMounted as z, onUnmounted as gt, openBlock as Me, createElementBlock as Je, ref as j, Fragment as _t, createVNode as J, createBlock as Tt } from "vue"; import * as g from "three"; import { TrianglesDrawMode as yt, TriangleFanDrawMode as _e, TriangleStripDrawMode as et, Loader as xt, LoaderUtils as q, FileLoader as tt, MeshPhysicalMaterial as C, Vector2 as k, Color as U, LinearSRGBColorSpace as D, SRGBColorSpace as Z, SpotLight as Et, PointLight as wt, DirectionalLight as Rt, Matrix4 as te, Vector3 as S, Quaternion as ne, InstancedMesh as bt, InstancedBufferAttribute as Mt, Object3D as nt, TextureLoader as At, ImageBitmapLoader as Lt, BufferAttribute as oe, InterleavedBuffer as St, InterleavedBufferAttribute as Pt, LinearMipmapLinearFilter as st, NearestMipmapLinearFilter as vt, LinearMipmapNearestFilter as kt, NearestMipmapNearestFilter as Nt, LinearFilter as Te, NearestFilter as it, RepeatWrapping as ye, MirroredRepeatWrapping as Ot, ClampToEdgeWrapping as It, PointsMaterial as Ct, Material as re, LineBasicMaterial as Dt, MeshStandardMaterial as ot, DoubleSide as Ht, MeshBasicMaterial as Q, PropertyBinding as Ft, BufferGeometry as Ut, SkinnedMesh as Vt, Mesh as jt, LineSegments as Gt, Line as Bt, LineLoop as Kt, Points as zt, Group as ae, PerspectiveCamera as Xt, MathUtils as rt, OrthographicCamera as Wt, Skeleton as Yt, AnimationClip as Qt, Bone as qt, InterpolateDiscrete as Zt, InterpolateLinear as at, Texture as Le, VectorKeyframeTrack as Se, NumberKeyframeTrack as Pe, QuaternionKeyframeTrack as ve, ColorManagement as ke, FrontSide as $t, Interpolant as Jt, Box3 as en, Sphere as tn, Controls as nn, MOUSE as B, TOUCH as G, Spherical as Ne, Ray as sn, Plane as on } from "three"; import { VRMUtils as xe, VRMHumanBoneName as Oe, VRMExpressionPresetName as Ie, VRMLoaderPlugin as rn } from "@pixiv/three-vrm"; class Ee { constructor() { } async fetchJSON(e) { const t = await fetch(e); return t.ok ? await t.json() : null; } normalizePose(e) { return e == null ? null : "pose" in e ? e.pose : e; } async fetchPose(e) { const t = await this.fetchJSON(e); return this.normalizePose(t); } async fetchExpression(e) { const t = await this.fetchJSON(e); return t == null ? null : "expressions" in t ? t.expressions : t; } } class an { constructor() { this.gltf = null; } // getter get scene() { return this.gltf.scene; } // methods setModel(e) { this.gltf = e; } setPosition(e) { this.gltf && this.gltf.scene.position.set(e.x, e.y, e.z); } getPosition() { return this.gltf ? { x: this.gltf.scene.position.x, y: this.gltf.scene.position.y, z: this.gltf.scene.position.z } : null; } setRotation(e) { this.gltf && this.gltf.scene.rotation.set(e.x, e.y, e.z); } getRotation() { return this.gltf ? { x: this.gltf.scene.rotation.x, y: this.gltf.scene.rotation.y, z: this.gltf.scene.rotation.z } : null; } } class ln { constructor() { this.vrm = null, this.vrma = null, this.mixer = null; } // getter get scene() { return this.vrm ? this.vrm.scene : null; } // methods setModel(e) { this.vrm = e; } setVrma(e) { this.vrma = e; } setMixer(e) { this.mixer = e; } setPosition(e) { this.vrm.scene.position.x = e.x, this.vrm.scene.position.y = e.y, this.vrm.scene.position.z = e.z; } getPosition() { return { x: this.vrm.scene.position.x, y: this.vrm.scene.position.y, z: this.vrm.scene.position.z }; } setPose(e) { this.vrm && this.vrm.humanoid.setNormalizedPose(e); } getPose() { return this.vrm ? this.vrm.humanoid.getNormalizedPose() : null; } updatePose() { this.vrm && this.vrm.humanoid.update(); } resetPose() { this.vrm && this.vrm.humanoid.resetNormalizedPose(); } getBoneNode(e) { return this.vrm ? this.vrm.humanoid.getNormalizedBoneNode(e) : null; } isValid() { return !!this.vrm; } getBoneRotate(e) { const t = this.getBoneNode(e); return t ? { x: t.rotation.x, y: t.rotation.y, z: t.rotation.z } : null; } setBoneRotate(e, t, n, s) { const i = this.getBoneNode(e); i && (i.rotation.x = t, i.rotation.y = n, i.rotation.z = s); } getBonePosition(e) { const t = this.getBoneNode(e); return t ? { x: t.position.x, y: t.position.y, z: t.position.z } : null; } setBonePosition(e, t, n, s) { const i = this.getBoneNode(e); i && (i.position.x = t, i.position.y = n, i.position.z = s); } getMetaVersion() { return this.vrm ? this.vrm.meta.metaVersion : null; } setExpression(e, t) { this.vrm && this.vrm.expressionManager.setValue(e, t); } getExpression(e) { return this.vrm ? this.vrm.expressionManager.getValue(e) : null; } updateExpression() { return this.vrm ? this.vrm.expressionManager.update() : null; } resetExpression() { return this.vrm ? this.vrm.expressionManager.resetValues() : null; } getExpressionNames() { if (this.vrm) { let e = []; for (const t in this.vrm.expressionManager.expressionMap) e.push(t); return e; } return null; } importExpression(e) { if (this.vrm) for (const t in e) this.vrm.expressionManager.setValue(t, e[t]); } exportExpression() { if (this.vrm) { let e = {}; const t = this.getExpressionNames(); for (const n in t) e[n] = this.getExpression(n); return e; } return null; } updateAnimation(e) { this.mixer && this.mixer.update(e), this.vrm && this.vrm.update(e); } } class Ce { /** * Returns `true` if WebGL 2 is available. * * @return {boolean} Whether WebGL 2 is available or not. */ static isWebGL2Available() { try { const e = document.createElement("canvas"); return !!(window.WebGL2RenderingContext && e.getContext("webgl2")); } catch { return !1; } } /** * Returns `true` if the given color space is available. This method can only be used * if WebGL 2 is supported. * * @param {string} colorSpace - The color space to test. * @return {boolean} Whether the given color space is available or not. */ static isColorSpaceAvailable(e) { try { const t = document.createElement("canvas"), n = window.WebGL2RenderingContext && t.getContext("webgl2"); return n.drawingBufferColorSpace = e, n.drawingBufferColorSpace === e; } catch { return !1; } } /** * Returns a `div` element representing a formatted error message that can be appended in * web sites if WebGL 2 isn't supported. * * @return {HTMLDivElement} A `div` element representing a formatted error message that WebGL 2 isn't supported. */ static getWebGL2ErrorMessage() { return this._getErrorMessage(2); } // private static _getErrorMessage(e) { const t = { 1: "WebGL", 2: "WebGL 2" }, n = { 1: window.WebGLRenderingContext, 2: window.WebGL2RenderingContext }; let s = 'Your $0 does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">$1</a>'; const i = document.createElement("div"); return i.id = "webglmessage", i.style.fontFamily = "monospace", i.style.fontSize = "13px", i.style.fontWeight = "normal", i.style.textAlign = "center", i.style.background = "#fff", i.style.color = "#000", i.style.padding = "1.5em", i.style.width = "400px", i.style.margin = "5em auto 0", n[e] ? s = s.replace("$0", "graphics card") : s = s.replace("$0", "browser"), s = s.replace("$1", t[e]), i.innerHTML = s, i; } } function De(l, e) { if (e === yt) return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), l; if (e === _e || e === et) { let t = l.getIndex(); if (t === null) { const o = [], a = l.getAttribute("position"); if (a !== void 0) { for (let r = 0; r < a.count; r++) o.push(r); l.setIndex(o), t = l.getIndex(); } else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), l; } const n = t.count - 2, s = []; if (e === _e) for (let o = 1; o <= n; o++) s.push(t.getX(0)), s.push(t.getX(o)), s.push(t.getX(o + 1)); else for (let o = 0; o < n; o++) o % 2 === 0 ? (s.push(t.getX(o)), s.push(t.getX(o + 1)), s.push(t.getX(o + 2))) : (s.push(t.getX(o + 2)), s.push(t.getX(o + 1)), s.push(t.getX(o))); s.length / 3 !== n && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles."); const i = l.clone(); return i.setIndex(s), i.clearGroups(), i; } else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", e), l; } function cn(l) { const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = l.clone(); return lt(l, n, function(s, i) { e.set(i, s), t.set(s, i); }), n.traverse(function(s) { if (!s.isSkinnedMesh) return; const i = s, o = e.get(s), a = o.skeleton.bones; i.skeleton = o.skeleton.clone(), i.bindMatrix.copy(o.bindMatrix), i.skeleton.bones = a.map(function(r) { return t.get(r); }), i.bind(i.skeleton, i.bindMatrix); }), n; } function lt(l, e, t) { t(l, e); for (let n = 0; n < l.children.length; n++) lt(l.children[n], e.children[n], t); } class $ extends xt { /** * Constructs a new glTF loader. * * @param {LoadingManager} [manager] - The loading manager. */ constructor(e) { super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(t) { return new fn(t); }), this.register(function(t) { return new mn(t); }), this.register(function(t) { return new bn(t); }), this.register(function(t) { return new Mn(t); }), this.register(function(t) { return new An(t); }), this.register(function(t) { return new _n(t); }), this.register(function(t) { return new Tn(t); }), this.register(function(t) { return new yn(t); }), this.register(function(t) { return new xn(t); }), this.register(function(t) { return new pn(t); }), this.register(function(t) { return new En(t); }), this.register(function(t) { return new gn(t); }), this.register(function(t) { return new Rn(t); }), this.register(function(t) { return new wn(t); }), this.register(function(t) { return new un(t); }), this.register(function(t) { return new He(t, x.EXT_MESHOPT_COMPRESSION); }), this.register(function(t) { return new He(t, x.KHR_MESHOPT_COMPRESSION); }), this.register(function(t) { return new Ln(t); }); } /** * Starts loading from the given URL and passes the loaded glTF asset * to the `onLoad()` callback. * * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI. * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished. * @param {onProgressCallback} onProgress - Executed while the loading is in progress. * @param {onErrorCallback} onError - Executed when errors occur. */ load(e, t, n, s) { const i = this; let o; if (this.resourcePath !== "") o = this.resourcePath; else if (this.path !== "") { const c = q.extractUrlBase(e); o = q.resolveURL(c, this.path); } else o = q.extractUrlBase(e); this.manager.itemStart(e); const a = function(c) { s ? s(c) : console.error(c), i.manager.itemError(e), i.manager.itemEnd(e); }, r = new tt(this.manager); r.setPath(this.path), r.setResponseType("arraybuffer"), r.setRequestHeader(this.requestHeader), r.setWithCredentials(this.withCredentials), r.load(e, function(c) { try { i.parse(c, o, function(h) { t(h), i.manager.itemEnd(e); }, a); } catch (h) { a(h); } }, n, a); } /** * Sets the given Draco loader to this loader. Required for decoding assets * compressed with the `KHR_draco_mesh_compression` extension. * * @param {DRACOLoader} dracoLoader - The Draco loader to set. * @return {GLTFLoader} A reference to this loader. */ setDRACOLoader(e) { return this.dracoLoader = e, this; } /** * Sets the given KTX2 loader to this loader. Required for loading KTX2 * compressed textures. * * @param {KTX2Loader} ktx2Loader - The KTX2 loader to set. * @return {GLTFLoader} A reference to this loader. */ setKTX2Loader(e) { return this.ktx2Loader = e, this; } /** * Sets the given meshopt decoder. Required for decoding assets * compressed with the `EXT_meshopt_compression` extension. * * @param {Object} meshoptDecoder - The meshopt decoder to set. * @return {GLTFLoader} A reference to this loader. */ setMeshoptDecoder(e) { return this.meshoptDecoder = e, this; } /** * Registers a plugin callback. This API is internally used to implement the various * glTF extensions but can also used by third-party code to add additional logic * to the loader. * * @param {function(parser:GLTFParser)} callback - The callback function to register. * @return {GLTFLoader} A reference to this loader. */ register(e) { return this.pluginCallbacks.indexOf(e) === -1 && this.pluginCallbacks.push(e), this; } /** * Unregisters a plugin callback. * * @param {Function} callback - The callback function to unregister. * @return {GLTFLoader} A reference to this loader. */ unregister(e) { return this.pluginCallbacks.indexOf(e) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this; } /** * Parses the given glTF data and returns the resulting group. * * @param {string|ArrayBuffer} data - The raw glTF data. * @param {string} path - The URL base path. * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished. * @param {onErrorCallback} onError - Executed when errors occur. */ parse(e, t, n, s) { let i; const o = {}, a = {}, r = new TextDecoder(); if (typeof e == "string") i = JSON.parse(e); else if (e instanceof ArrayBuffer) if (r.decode(new Uint8Array(e, 0, 4)) === ct) { try { o[x.KHR_BINARY_GLTF] = new Sn(e); } catch (u) { s && s(u); return; } i = JSON.parse(o[x.KHR_BINARY_GLTF].content); } else i = JSON.parse(r.decode(e)); else i = e; if (i.asset === void 0 || i.asset.version[0] < 2) { s && s(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")); return; } const c = new jn(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 h = 0; h < this.pluginCallbacks.length; h++) { const u = this.pluginCallbacks[h](c); u.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[u.name] = u, o[u.name] = !0; } if (i.extensionsUsed) for (let h = 0; h < i.extensionsUsed.length; ++h) { const u = i.extensionsUsed[h], d = i.extensionsRequired || []; switch (u) { case x.KHR_MATERIALS_UNLIT: o[u] = new dn(); break; case x.KHR_DRACO_MESH_COMPRESSION: o[u] = new Pn(i, this.dracoLoader); break; case x.KHR_TEXTURE_TRANSFORM: o[u] = new vn(); break; case x.KHR_MESH_QUANTIZATION: o[u] = new kn(); break; default: d.indexOf(u) >= 0 && a[u] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + u + '".'); } } c.setExtensions(o), c.setPlugins(a), c.parse(n, s); } /** * Async version of {@link GLTFLoader#parse}. * * @async * @param {string|ArrayBuffer} data - The raw glTF data. * @param {string} path - The URL base path. * @return {Promise<GLTFLoader~LoadObject>} A Promise that resolves with the loaded glTF when the parsing has been finished. */ parseAsync(e, t) { const n = this; return new Promise(function(s, i) { n.parse(e, t, s, i); }); } } function hn() { let l = {}; return { get: function(e) { return l[e]; }, add: function(e, t) { l[e] = t; }, remove: function(e) { delete l[e]; }, removeAll: function() { l = {}; } }; } function b(l, e, t) { const n = l.json.materials[e]; return n.extensions && n.extensions[t] ? n.extensions[t] : null; } const x = { 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", KHR_MESHOPT_COMPRESSION: "KHR_meshopt_compression", EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing" }; class un { constructor(e) { this.parser = e, this.name = x.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} }; } _markDefs() { const e = this.parser, t = this.parser.json.nodes || []; for (let n = 0, s = t.length; n < s; n++) { const i = t[n]; 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, n = "light:" + e; let s = t.cache.get(n); if (s) return s; const i = t.json, r = ((i.extensions && i.extensions[this.name] || {}).lights || [])[e]; let c; const h = new U(16777215); r.color !== void 0 && h.setRGB(r.color[0], r.color[1], r.color[2], D); const u = r.range !== void 0 ? r.range : 0; switch (r.type) { case "directional": c = new Rt(h), c.target.position.set(0, 0, -1), c.add(c.target); break; case "point": c = new wt(h), c.distance = u; break; case "spot": c = new Et(h), c.distance = u, 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), I(c, r), r.intensity !== void 0 && (c.intensity = r.intensity), c.name = t.createUniqueName(r.name || "light_" + e), s = Promise.resolve(c), t.cache.add(n, s), s; } getDependency(e, t) { if (e === "light") return this._loadLight(t); } createNodeAttachment(e) { const t = this, n = this.parser, i = n.json.nodes[e], a = (i.extensions && i.extensions[this.name] || {}).light; return a === void 0 ? null : this._loadLight(a).then(function(r) { return n._getNodeRef(t.cache, a, r); }); } } class dn { constructor() { this.name = x.KHR_MATERIALS_UNLIT; } getMaterialType() { return Q; } extendParams(e, t, n) { const s = []; e.color = new U(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], D), e.opacity = o[3]; } i.baseColorTexture !== void 0 && s.push(n.assignTexture(e, "map", i.baseColorTexture, Z)); } return Promise.all(s); } } class pn { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_EMISSIVE_STRENGTH; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); return n === null || n.emissiveStrength !== void 0 && (t.emissiveIntensity = n.emissiveStrength), Promise.resolve(); } } class fn { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_CLEARCOAT; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); if (n === null) return Promise.resolve(); const s = []; if (n.clearcoatFactor !== void 0 && (t.clearcoat = n.clearcoatFactor), n.clearcoatTexture !== void 0 && s.push(this.parser.assignTexture(t, "clearcoatMap", n.clearcoatTexture)), n.clearcoatRoughnessFactor !== void 0 && (t.clearcoatRoughness = n.clearcoatRoughnessFactor), n.clearcoatRoughnessTexture !== void 0 && s.push(this.parser.assignTexture(t, "clearcoatRoughnessMap", n.clearcoatRoughnessTexture)), n.clearcoatNormalTexture !== void 0 && (s.push(this.parser.assignTexture(t, "clearcoatNormalMap", n.clearcoatNormalTexture)), n.clearcoatNormalTexture.scale !== void 0)) { const i = n.clearcoatNormalTexture.scale; t.clearcoatNormalScale = new k(i, i); } return Promise.all(s); } } class mn { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_DISPERSION; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); return n === null || (t.dispersion = n.dispersion !== void 0 ? n.dispersion : 0), Promise.resolve(); } } class gn { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_IRIDESCENCE; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); if (n === null) return Promise.resolve(); const s = []; return n.iridescenceFactor !== void 0 && (t.iridescence = n.iridescenceFactor), n.iridescenceTexture !== void 0 && s.push(this.parser.assignTexture(t, "iridescenceMap", n.iridescenceTexture)), n.iridescenceIor !== void 0 && (t.iridescenceIOR = n.iridescenceIor), t.iridescenceThicknessRange === void 0 && (t.iridescenceThicknessRange = [100, 400]), n.iridescenceThicknessMinimum !== void 0 && (t.iridescenceThicknessRange[0] = n.iridescenceThicknessMinimum), n.iridescenceThicknessMaximum !== void 0 && (t.iridescenceThicknessRange[1] = n.iridescenceThicknessMaximum), n.iridescenceThicknessTexture !== void 0 && s.push(this.parser.assignTexture(t, "iridescenceThicknessMap", n.iridescenceThicknessTexture)), Promise.all(s); } } class _n { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_SHEEN; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); if (n === null) return Promise.resolve(); const s = []; if (t.sheenColor = new U(0, 0, 0), t.sheenRoughness = 0, t.sheen = 1, n.sheenColorFactor !== void 0) { const i = n.sheenColorFactor; t.sheenColor.setRGB(i[0], i[1], i[2], D); } return n.sheenRoughnessFactor !== void 0 && (t.sheenRoughness = n.sheenRoughnessFactor), n.sheenColorTexture !== void 0 && s.push(this.parser.assignTexture(t, "sheenColorMap", n.sheenColorTexture, Z)), n.sheenRoughnessTexture !== void 0 && s.push(this.parser.assignTexture(t, "sheenRoughnessMap", n.sheenRoughnessTexture)), Promise.all(s); } } class Tn { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_TRANSMISSION; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); if (n === null) return Promise.resolve(); const s = []; return n.transmissionFactor !== void 0 && (t.transmission = n.transmissionFactor), n.transmissionTexture !== void 0 && s.push(this.parser.assignTexture(t, "transmissionMap", n.transmissionTexture)), Promise.all(s); } } class yn { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_VOLUME; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); if (n === null) return Promise.resolve(); const s = []; t.thickness = n.thicknessFactor !== void 0 ? n.thicknessFactor : 0, n.thicknessTexture !== void 0 && s.push(this.parser.assignTexture(t, "thicknessMap", n.thicknessTexture)), t.attenuationDistance = n.attenuationDistance || 1 / 0; const i = n.attenuationColor || [1, 1, 1]; return t.attenuationColor = new U().setRGB(i[0], i[1], i[2], D), Promise.all(s); } } class xn { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_IOR; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); return n === null || (t.ior = n.ior !== void 0 ? n.ior : 1.5, t.ior === 0 && (t.ior = 1e3)), Promise.resolve(); } } class En { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_SPECULAR; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); if (n === null) return Promise.resolve(); const s = []; t.specularIntensity = n.specularFactor !== void 0 ? n.specularFactor : 1, n.specularTexture !== void 0 && s.push(this.parser.assignTexture(t, "specularIntensityMap", n.specularTexture)); const i = n.specularColorFactor || [1, 1, 1]; return t.specularColor = new U().setRGB(i[0], i[1], i[2], D), n.specularColorTexture !== void 0 && s.push(this.parser.assignTexture(t, "specularColorMap", n.specularColorTexture, Z)), Promise.all(s); } } class wn { constructor(e) { this.parser = e, this.name = x.EXT_MATERIALS_BUMP; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); if (n === null) return Promise.resolve(); const s = []; return t.bumpScale = n.bumpFactor !== void 0 ? n.bumpFactor : 1, n.bumpTexture !== void 0 && s.push(this.parser.assignTexture(t, "bumpMap", n.bumpTexture)), Promise.all(s); } } class Rn { constructor(e) { this.parser = e, this.name = x.KHR_MATERIALS_ANISOTROPY; } getMaterialType(e) { return b(this.parser, e, this.name) !== null ? C : null; } extendMaterialParams(e, t) { const n = b(this.parser, e, this.name); if (n === null) return Promise.resolve(); const s = []; return n.anisotropyStrength !== void 0 && (t.anisotropy = n.anisotropyStrength), n.anisotropyRotation !== void 0 && (t.anisotropyRotation = n.anisotropyRotation), n.anisotropyTexture !== void 0 && s.push(this.parser.assignTexture(t, "anisotropyMap", n.anisotropyTexture)), Promise.all(s); } } class bn { constructor(e) { this.parser = e, this.name = x.KHR_TEXTURE_BASISU; } loadTexture(e) { const t = this.parser, n = t.json, s = n.textures[e]; if (!s.extensions || !s.extensions[this.name]) return null; const i = s.extensions[this.name], o = t.options.ktx2Loader; if (!o) { if (n.extensionsRequired && n.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 Mn { constructor(e) { this.parser = e, this.name = x.EXT_TEXTURE_WEBP; } loadTexture(e) { const t = this.name, n = this.parser, s = n.json, i = s.textures[e]; if (!i.extensions || !i.extensions[t]) return null; const o = i.extensions[t], a = s.images[o.source]; let r = n.textureLoader; if (a.uri) { const c = n.options.manager.getHandler(a.uri); c !== null && (r = c); } return n.loadTextureImage(e, o.source, r); } } class An { constructor(e) { this.parser = e, this.name = x.EXT_TEXTURE_AVIF; } loadTexture(e) { const t = this.name, n = this.parser, s = n.json, i = s.textures[e]; if (!i.extensions || !i.extensions[t]) return null; const o = i.extensions[t], a = s.images[o.source]; let r = n.textureLoader; if (a.uri) { const c = n.options.manager.getHandler(a.uri); c !== null && (r = c); } return n.loadTextureImage(e, o.source, r); } } class He { constructor(e, t) { this.name = t, this.parser = e; } loadBufferView(e) { const t = this.parser.json, n = t.bufferViews[e]; if (n.extensions && n.extensions[this.name]) { const s = n.extensions[this.name], i = this.parser.getDependency("buffer", s.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(a) { const r = s.byteOffset || 0, c = s.byteLength || 0, h = s.count, u = s.byteStride, d = new Uint8Array(a, r, c); return o.decodeGltfBufferAsync ? o.decodeGltfBufferAsync(h, u, d, s.mode, s.filter).then(function(p) { return p.buffer; }) : o.ready.then(function() { const p = new ArrayBuffer(h * u); return o.decodeGltfBuffer(new Uint8Array(p), h, u, d, s.mode, s.filter), p; }); }); } else return null; } } class Ln { constructor(e) { this.name = x.EXT_MESH_GPU_INSTANCING, this.parser = e; } createNodeMesh(e) { const t = this.parser.json, n = t.nodes[e]; if (!n.extensions || !n.extensions[this.name] || n.mesh === void 0) return null; const s = t.meshes[n.mesh]; for (const c of s.primitives) if (c.mode !== O.TRIANGLES && c.mode !== O.TRIANGLE_STRIP && c.mode !== O.TRIANGLE_FAN && c.mode !== void 0) return null; const o = n.extensions[this.name].attributes, a = [], r = {}; for (const c in o) a.push(this.parser.getDependency("accessor", o[c]).then((h) => (r[c] = h, r[c]))); return a.length < 1 ? null : (a.push(this.parser.createNodeMesh(e)), Promise.all(a).then((c) => { const h = c.pop(), u = h.isGroup ? h.children : [h], d = c[0].count, p = []; for (const f of u) { const T = new te(), _ = new S(), m = new ne(), y = new S(1, 1, 1), E = new bt(f.geometry, f.material, d); for (let w = 0; w < d; w++) r.TRANSLATION && _.fromBufferAttribute(r.TRANSLATION, w), r.ROTATION && m.fromBufferAttribute(r.ROTATION, w), r.SCALE && y.fromBufferAttribute(r.SCALE, w), E.setMatrixAt(w, T.compose(_, m, y)); for (const w in r) if (w === "_COLOR_0") { const M = r[w]; E.instanceColor = new Mt(M.array, M.itemSize, M.normalized); } else w !== "TRANSLATION" && w !== "ROTATION" && w !== "SCALE" && f.geometry.setAttribute(w, r[w]); nt.prototype.copy.call(E, f), this.parser.assignFinalMaterial(E), p.push(E); } return h.isGroup ? (h.clear(), h.add(...p), h) : p[0]; })); } } const ct = "glTF", W = 12, Fe = { JSON: 1313821514, BIN: 5130562 }; class Sn { constructor(e) { this.name = x.KHR_BINARY_GLTF, this.content = null, this.body = null; const t = new DataView(e, 0, W), n = new TextDecoder(); if (this.header = { magic: n.decode(new Uint8Array(e.slice(0, 4))), version: t.getUint32(4, !0), length: t.getUint32(8, !0) }, this.header.magic !== ct) throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header."); if (this.header.version < 2) throw new Error("THREE.GLTFLoader: Legacy binary file detected."); const s = this.header.length - W, i = new DataView(e, W); let o = 0; for (; o < s; ) { const a = i.getUint32(o, !0); o += 4; const r = i.getUint32(o, !0); if (o += 4, r === Fe.JSON) { const c = new Uint8Array(e, W + o, a); this.content = n.decode(c); } else if (r === Fe.BIN) { const c = W + o; this.body = e.slice(c, c + a); } o += a; } if (this.content === null) throw new Error("THREE.GLTFLoader: JSON content not found."); } } class Pn { constructor(e, t) { if (!t) throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided."); this.name = x.KHR_DRACO_MESH_COMPRESSION, this.json = e, this.dracoLoader = t, this.dracoLoader.preload(); } decodePrimitive(e, t) { const n = this.json, s = this.dracoLoader, i = e.extensions[this.name].bufferView, o = e.extensions[this.name].attributes, a = {}, r = {}, c = {}; for (const h in o) { const u = we[h] || h.toLowerCase(); a[u] = o[h]; } for (const h in e.attributes) { const u = we[h] || h.toLowerCase(); if (o[h] !== void 0) { const d = n.accessors[e.attributes[h]], p = K[d.componentType]; c[u] = p.name, r[u] = d.normalized === !0; } } return t.getDependency("bufferView", i).then(function(h) { return new Promise(function(u, d) { s.decodeDracoFile(h, function(p) { for (const f in p.attributes) { const T = p.attributes[f], _ = r[f]; _ !== void 0 && (T.normalized = _); } u(p); }, a, c, D, d); }); }); } } class vn { constructor() { this.name = x.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 kn { constructor() { this.name = x.KHR_MESH_QUANTIZATION; } } class ht extends Jt { constructor(e, t, n, s) { super(e, t, n, s); } copySampleValue_(e) { const t = this.resultBuffer, n = this.sampleValues, s = this.valueSize, i = e * s * 3 + s; for (let o = 0; o !== s; o++) t[o] = n[i + o]; return t; } interpolate_(e, t, n, s) { const i = this.resultBuffer, o = this.sampleValues, a = this.valueSize, r = a * 2, c = a * 3, h = s - t, u = (n - t) / h, d = u * u, p = d * u, f = e * c, T = f - c, _ = -2 * p + 3 * d, m = p - d, y = 1 - _, E = m - d + u; for (let w = 0; w !== a; w++) { const M = o[T + w + a], L = o[T + w + r] * h, v = o[f + w + a], X = o[f + w] * h; i[w] = y * M + E * L + _ * v + m * X; } return i; } } const Nn = new ne(); class On extends ht { interpolate_(e, t, n, s) { const i = super.interpolate_(e, t, n, s); return Nn.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 }, K = { 5120: Int8Array, 5121: Uint8Array, 5122: Int16Array, 5123: Uint16Array, 5125: Uint32Array, 5126: Float32Array }, Ue = { 9728: it, 9729: Te, 9984: Nt, 9985: kt, 9986: vt, 9987: st }, Ve = { 33071: It, 33648: Ot, 10497: ye }, le = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16 }, we = { 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" }, H = { scale: "scale", translation: "position", rotation: "quaternion", weights: "morphTargetInfluences" }, In = { 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: at, STEP: Zt }, ce = { OPAQUE: "OPAQUE", MASK: "MASK", BLEND: "BLEND" }; function Cn(l) { return l.DefaultMaterial === void 0 && (l.DefaultMaterial = new ot({ color: 16777215, emissive: 0, metalness: 1, roughness: 1, transparent: !1, depthTest: !0, side: $t })), l.DefaultMaterial; } function F(l, e, t) { for (const n in t.extensions) l[n] === void 0 && (e.userData.gltfExtensions = e.userData.gltfExtensions || {}, e.userData.gltfExtensions[n] = t.extensions[n]); } function I(l, e) { e.extras !== void 0 && (typeof e.extras == "object" ? Object.assign(l.userData, e.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + e.extras)); } function Dn(l, e, t) { let n = !1, s = !1, i = !1; for (let c = 0, h = e.length; c < h; c++) { const u = e[c]; if (u.POSITION !== void 0 && (n = !0), u.NORMAL !== void 0 && (s = !0), u.COLOR_0 !== void 0 && (i = !0), n && s && i) break; } if (!n && !s && !i) return Promise.resolve(l); const o = [], a = [], r = []; for (let c = 0, h = e.length; c < h; c++) { const u = e[c]; if (n) { const d = u.POSITION !== void 0 ? t.getDependency("accessor", u.POSITION) : l.attributes.position; o.push(d); } if (s) { const d = u.NORMAL !== void 0 ? t.getDependency("accessor", u.NORMAL) : l.attributes.normal; a.push(d); } if (i) { const d = u.COLOR_0 !== void 0 ? t.getDependency("accessor", u.COLOR_0) : l.attributes.color; r.push(d); } } return Promise.all([ Promise.all(o), Promise.all(a), Promise.all(r) ]).then(function(c) { const h = c[0], u = c[1], d = c[2]; return n && (l.morphAttributes.position = h), s && (l.morphAttributes.normal = u), i && (l.morphAttributes.color = d), l.morphTargetsRelative = !0, l; }); } function Hn(l, e) { if (l.updateMorphTargets(), e.weights !== void 0) for (let t = 0, n = e.weights.length; t < n; t++) l.morphTargetInfluences[t] = e.weights[t]; if (e.extras && Array.isArray(e.extras.targetNames)) { const t = e.extras.targetNames; if (l.morphTargetInfluences.length === t.length) { l.morphTargetDictionary = {}; for (let n = 0, s = t.length; n < s; n++) l.morphTargetDictionary[t[n]] = n; } else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names."); } } function Fn(l) { let e; const t = l.extensions && l.extensions[x.KHR_DRACO_MESH_COMPRESSION]; if (t ? e = "draco:" + t.bufferView + ":" + t.indices + ":" + he(t.attributes) : e = l.indices + ":" + he(l.attributes) + ":" + l.mode, l.targets !== void 0) for (let n = 0, s = l.targets.length; n < s; n++) e += ":" + he(l.targets[n]); return e; } function he(l) { let e = ""; const t = Object.keys(l).sort(); for (let n = 0, s = t.length; n < s; n++) e += t[n] + ":" + l[t[n]] + ";"; return e; } function Re(l) { switch (l) { 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 Un(l) { return l.search(/\.jpe?g($|\?)/i) > 0 || l.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : l.search(/\.webp($|\?)/i) > 0 || l.search(/^data\:image\/webp/) === 0 ? "image/webp" : l.search(/\.ktx2($|\?)/i) > 0 || l.search(/^data\:image\/ktx2/) === 0 ? "image/ktx2" : "image/png"; } const Vn = new te(); class jn { constructor(e = {}, t = {}) { this.json = e, this.extensions = {}, this.plugins = {}, this.options = t, this.cache = new hn(), 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 n = !1, s = -1, i = !1, o = -1; if (typeof navigator < "u" && typeof navigator.userAgent < "u") { const a = navigator.userAgent; n = /^((?!chrome|android).)*safari/i.test(a) === !0; const r = a.match(/Version\/(\d+)/); s = n && r ? parseInt(r[1], 10) : -1, i = a.indexOf("Firefox") > -1, o = i ? a.match(/Firefox\/([0-9]+)\./)[1] : -1; } typeof createImageBitmap > "u" || n && s < 17 || i && o < 98 ? this.textureLoader = new At(this.options.manager) : this.textureLoader = new Lt(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new tt(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 n = this, s = 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([ n.getDependencies("scene"), n.getDependencies("animation"), n.getDependencies("camera") ]); }).then(function(o) { const a = { scene: o[0][s.scene || 0], scenes: o[0], animations: o[1], cameras: o[2], asset: s.asset, parser: n, userData: {} }; return F(i, a, s), I(a, s), Promise.all(n._invokeAll(function(r) { return r.afterRoot && r.afterRoot(a); })).then(function() { for (const r of a.scenes) r.updateMatrixWorld(); e(a); }); }).catch(t); } /** * Marks the special nodes/meshes in json for efficient parse. * * @private */ _markDefs() { const e = this.json.nodes || [], t = this.json.skins || [], n = this.json.meshes || []; for (let s = 0, i = t.length; s < i; s++) { const o = t[s].joints; for (let a = 0, r = o.length; a < r; a++) e[o[a]].isBone = !0; } for (let s = 0, i = e.length; s < i; s++) { const o = e[s]; o.mesh !== void 0 && (this._addNodeRef(this.meshCache, o.mesh), o.skin !== void 0 && (n[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. * * @private * @param {Object} cache * @param {Object3D} index */ _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. * * @private * @param {Object} cache * @param {number} index * @param {Object} object * @return {Object} */ _getNodeRef(e, t, n) { if (e.refs[t] <= 1) return n; const s = n.clone(), i = (o, a) => { const r = this.associations.get(o); r != null && this.associations.set(a, r); for (const [c, h] of o.children.entries()) i(h, a.children[c]); }; return i(n, s), s.name += "_instance_" + e.uses[t]++, s; } _invokeOne(e) { const t = Object.values(this.plugins); t.push(this); for (let n = 0; n < t.length; n++) { const s = e(t[n]); if (s) return s; } return null; } _invokeAll(e) { const t = Object.values(this.plugins); t.unshift(this); const n = []; for (let s = 0; s < t.length; s++) { const i = e(t[s]); i && n.push(i); } return n; } /** * Requests the specified dependency asynchronously, with caching. * * @private * @param {string} type * @param {number} index * @return {Promise<Object3D|Material|Texture|AnimationClip|ArrayBuffer|Object>} */ getDependency(e, t) { const n = e + ":" + t; let s = this.cache.get(n); if (!s) { switch (e) { case "scene": s = this.loadScene(t); break; case "node": s = this._invokeOne(function(i) { return i.loadNode && i.loadNode(t); }); break; case "mesh": s = this._invokeOne(function(i) { return i.loadMesh && i.loadMesh(t); }); break; case "accessor": s = this.loadAccessor(t); break; case "bufferView": s = this._invokeOne(function(i) { return i.loadBufferView && i.loadBufferView(t); }); break; case "buffer": s = this.loadBuffer(t); break; case "material": s = this._invokeOne(function(i) { return i.loadMaterial && i.loadMaterial(t); }); break; case "texture": s = this._invokeOne(function(i) { return i.loadTexture && i.loadTexture(t); }); break; case "skin": s = this.loadSkin(t); break; case "animation": s = this._invokeOne(function(i) { return i.loadAnimation && i.loadAnimation(t); }); break; case "camera": s = this.loadCamera(t); break; default: if (s = this._invokeOne(function(i) { return i != this && i.getDependency && i.getDependency(e, t); }), !s) throw new Error("Unknown type: " + e); break; } this.cache.add(n, s); } return s; } /** * Requests all dependencies of the specified type asynchronously, with caching. * * @private * @param {string} type * @return {Promise<Array<Object>>} */ getDependencies(e) { let t = this.cache.get(e); if (!t) { const n = this, s = this.json[e + (e === "mesh" ? "es" : "s")] || []; t = Promise.all(s.map(function(i, o) { return n.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 * * @private * @param {number} bufferIndex * @return {Promise<ArrayBuffer>} */ loadBuffer(e) { const t = this.json.buffers[e], n = this.fileLoader; if (t.type && t.type !== "arraybuffer") throw new Error("THREE.GLTFLoader: " + t.type + " buffer type is not supported."); if (t.uri === void 0 && e === 0) return Promise.resolve(this.extensions[x.KHR_BINARY_GLTF].body); const s = this.options; return new Promise(function(i, o) { n.load(q.resolveURL(t.uri, s.path), i, void 0, function() { o(new Error('THREE.GLTFLoader: Failed to load buffer "' + t.uri + '".')); }); }); } /** * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views * * @private * @param {number} bufferViewIndex * @return {Promise<ArrayBuffer>} */ loadBufferView(e) { const t = this.json.bufferViews[e]; return this.getDependency("buffer", t.buffer).then(function(n) { const s = t.byteLength || 0, i = t.byteOffset || 0; return n.slice(i, i + s); }); } /** * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors * * @private * @param {number} accessorIndex * @return {Promise<BufferAttribute|InterleavedBufferAttribute>} */ loadAccessor(e) { const t = this, n = this.json, s = this.json.accessors[e]; if (s.bufferView === void 0 && s.sparse === void 0) { const o = le[s.type], a = K[s.componentType], r = s.normalized === !0, c = new a(s.count * o); return Promise.resolve(new oe(c, o, r)); } const i = []; return s.bufferView !== void 0 ? i.push(this.getDependency("bufferView", s.bufferView)) : i.push(null), s.sparse !== void 0 && (i.push(this.getDependency("bufferView", s.sparse.indices.bufferView)), i.push(this.getDependency("bufferView", s.sparse.values.bufferView))), Promise.all(i).then(function(o) { const a = o[0], r = le[s.type], c = K[s.componentType], h = c.BYTES_PER_ELEMENT, u = h * r, d = s.byteOffset || 0, p = s.bufferView !== void 0 ? n.bufferViews[s.bufferView].byteStride : void 0, f = s.normalized === !0; let T, _;