UNPKG

assistant-robot

Version:

An assistant widget, have a 3D robot which can interact with user, have a simple LLM which can chat with user.

1,225 lines 391 kB
var hA = Object.defineProperty; var ZA = (n, P, A) => P in n ? hA(n, P, { enumerable: !0, configurable: !0, writable: !0, value: A }) : n[P] = A; var j = (n, P, A) => (ZA(n, typeof P != "symbol" ? P + "" : P, A), A); import { TrianglesDrawMode as yA, TriangleFanDrawMode as $, TriangleStripDrawMode as lA, Loader as RA, LoaderUtils as AA, FileLoader as zA, Color as O, LinearSRGBColorSpace as U, SpotLight as FA, PointLight as NA, DirectionalLight as aA, MeshBasicMaterial as V, SRGBColorSpace as W, MeshPhysicalMaterial as J, Vector2 as LA, Matrix4 as S, Vector3 as Z, Quaternion as TA, InstancedMesh as VA, InstancedBufferAttribute as WA, Object3D as uA, TextureLoader as kA, ImageBitmapLoader as SA, BufferAttribute as p, InterleavedBuffer as xA, InterleavedBufferAttribute as pA, LinearFilter as mA, LinearMipmapLinearFilter as bA, RepeatWrapping as PA, PointsMaterial as HA, Material as H, LineBasicMaterial as XA, MeshStandardMaterial as dA, DoubleSide as KA, PropertyBinding as qA, BufferGeometry as _A, SkinnedMesh as $A, Mesh as AP, LineSegments as PP, Line as wP, LineLoop as sP, Points as DP, Group as X, PerspectiveCamera as GA, MathUtils as iP, OrthographicCamera as eP, Skeleton as gP, AnimationClip as wA, Bone as IP, InterpolateLinear as fA, ColorManagement as iA, NearestFilter as BP, NearestMipmapNearestFilter as CP, LinearMipmapNearestFilter as nP, NearestMipmapLinearFilter as QP, ClampToEdgeWrapping as oP, MirroredRepeatWrapping as tP, InterpolateDiscrete as rP, FrontSide as vP, Texture as eA, VectorKeyframeTrack as gA, NumberKeyframeTrack as IA, QuaternionKeyframeTrack as BA, Box3 as cP, Sphere as jP, Interpolant as EP, Clock as MP, Scene as lP, AmbientLight as zP, WebGL1Renderer as aP, AnimationMixer as LP, LoopRepeat as CA, LoopOnce as TP } from "three"; import { A as uP, M as u, a as h, O as mP, R as bP, E as OA, b as G, i as nA, V as k, T as dP, c as QA, d as oA, e as GP, p as UA, f as fP, g as OP, h as UP, j as JP, C as YP, k as hP, r as ZP, l as yP, U as RP, m as F, n as FP, t as tA, o as NP } from "./utils-FAxjgnse.mjs"; import * as VP from "@mediapipe/face_detection"; import * as rA from "@tensorflow-models/face-detection"; function vA(n, P) { if (P === yA) return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), n; if (P === $ || P === lA) { let A = n.getIndex(); if (A === null) { const i = [], g = n.getAttribute("position"); if (g !== void 0) { for (let e = 0; e < g.count; e++) i.push(e); n.setIndex(i), A = n.getIndex(); } else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), n; } const s = A.count - 2, w = []; if (P === $) for (let i = 1; i <= s; i++) w.push(A.getX(0)), w.push(A.getX(i)), w.push(A.getX(i + 1)); else for (let i = 0; i < s; i++) i % 2 === 0 ? (w.push(A.getX(i)), w.push(A.getX(i + 1)), w.push(A.getX(i + 2))) : (w.push(A.getX(i + 2)), w.push(A.getX(i + 1)), w.push(A.getX(i))); w.length / 3 !== s && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles."); const D = n.clone(); return D.setIndex(w), D.clearGroups(), D; } else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", P), n; } class WP extends RA { constructor(P) { super(P), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(A) { return new HP(A); }), this.register(function(A) { return new ww(A); }), this.register(function(A) { return new sw(A); }), this.register(function(A) { return new Dw(A); }), this.register(function(A) { return new KP(A); }), this.register(function(A) { return new qP(A); }), this.register(function(A) { return new _P(A); }), this.register(function(A) { return new $P(A); }), this.register(function(A) { return new pP(A); }), this.register(function(A) { return new Aw(A); }), this.register(function(A) { return new XP(A); }), this.register(function(A) { return new Pw(A); }), this.register(function(A) { return new SP(A); }), this.register(function(A) { return new iw(A); }), this.register(function(A) { return new ew(A); }); } load(P, A, s, w) { const D = this; let i; this.resourcePath !== "" ? i = this.resourcePath : this.path !== "" ? i = this.path : i = AA.extractUrlBase(P), this.manager.itemStart(P); const g = function(I) { w ? w(I) : console.error(I), D.manager.itemError(P), D.manager.itemEnd(P); }, e = new zA(this.manager); e.setPath(this.path), e.setResponseType("arraybuffer"), e.setRequestHeader(this.requestHeader), e.setWithCredentials(this.withCredentials), e.load(P, function(I) { try { D.parse(I, i, function(C) { A(C), D.manager.itemEnd(P); }, g); } catch (C) { g(C); } }, s, g); } setDRACOLoader(P) { return this.dracoLoader = P, this; } setDDSLoader() { throw new Error( 'THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".' ); } setKTX2Loader(P) { return this.ktx2Loader = P, this; } setMeshoptDecoder(P) { return this.meshoptDecoder = P, this; } register(P) { return this.pluginCallbacks.indexOf(P) === -1 && this.pluginCallbacks.push(P), this; } unregister(P) { return this.pluginCallbacks.indexOf(P) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(P), 1), this; } parse(P, A, s, w) { let D; const i = {}, g = {}, e = new TextDecoder(); if (typeof P == "string") D = JSON.parse(P); else if (P instanceof ArrayBuffer) if (e.decode(new Uint8Array(P, 0, 4)) === JA) { try { i[v.KHR_BINARY_GLTF] = new gw(P); } catch (B) { w && w(B); return; } D = JSON.parse(i[v.KHR_BINARY_GLTF].content); } else D = JSON.parse(e.decode(P)); else D = P; if (D.asset === void 0 || D.asset.version[0] < 2) { w && w(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")); return; } const I = new Mw(D, { path: A || this.resourcePath || "", crossOrigin: this.crossOrigin, requestHeader: this.requestHeader, manager: this.manager, ktx2Loader: this.ktx2Loader, meshoptDecoder: this.meshoptDecoder }); I.fileLoader.setRequestHeader(this.requestHeader); for (let C = 0; C < this.pluginCallbacks.length; C++) { const B = this.pluginCallbacks[C](I); B.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), g[B.name] = B, i[B.name] = !0; } if (D.extensionsUsed) for (let C = 0; C < D.extensionsUsed.length; ++C) { const B = D.extensionsUsed[C], Q = D.extensionsRequired || []; switch (B) { case v.KHR_MATERIALS_UNLIT: i[B] = new xP(); break; case v.KHR_DRACO_MESH_COMPRESSION: i[B] = new Iw(D, this.dracoLoader); break; case v.KHR_TEXTURE_TRANSFORM: i[B] = new Bw(); break; case v.KHR_MESH_QUANTIZATION: i[B] = new Cw(); break; default: Q.indexOf(B) >= 0 && g[B] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + B + '".'); } } I.setExtensions(i), I.setPlugins(g), I.parse(s, w); } parseAsync(P, A) { const s = this; return new Promise(function(w, D) { s.parse(P, A, w, D); }); } } function kP() { let n = {}; return { get: function(P) { return n[P]; }, add: function(P, A) { n[P] = A; }, remove: function(P) { delete n[P]; }, removeAll: function() { n = {}; } }; } const v = { KHR_BINARY_GLTF: "KHR_binary_glTF", KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression", KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual", KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat", KHR_MATERIALS_IOR: "KHR_materials_ior", KHR_MATERIALS_SHEEN: "KHR_materials_sheen", KHR_MATERIALS_SPECULAR: "KHR_materials_specular", KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission", KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence", KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy", KHR_MATERIALS_UNLIT: "KHR_materials_unlit", KHR_MATERIALS_VOLUME: "KHR_materials_volume", KHR_TEXTURE_BASISU: "KHR_texture_basisu", KHR_TEXTURE_TRANSFORM: "KHR_texture_transform", KHR_MESH_QUANTIZATION: "KHR_mesh_quantization", KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength", EXT_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 SP { constructor(P) { this.parser = P, this.name = v.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} }; } _markDefs() { const P = this.parser, A = this.parser.json.nodes || []; for (let s = 0, w = A.length; s < w; s++) { const D = A[s]; D.extensions && D.extensions[this.name] && D.extensions[this.name].light !== void 0 && P._addNodeRef(this.cache, D.extensions[this.name].light); } } _loadLight(P) { const A = this.parser, s = "light:" + P; let w = A.cache.get(s); if (w) return w; const D = A.json, e = ((D.extensions && D.extensions[this.name] || {}).lights || [])[P]; let I; const C = new O(16777215); e.color !== void 0 && C.setRGB(e.color[0], e.color[1], e.color[2], U); const B = e.range !== void 0 ? e.range : 0; switch (e.type) { case "directional": I = new aA(C), I.target.position.set(0, 0, -1), I.add(I.target); break; case "point": I = new NA(C), I.distance = B; break; case "spot": I = new FA(C), I.distance = B, e.spot = e.spot || {}, e.spot.innerConeAngle = e.spot.innerConeAngle !== void 0 ? e.spot.innerConeAngle : 0, e.spot.outerConeAngle = e.spot.outerConeAngle !== void 0 ? e.spot.outerConeAngle : Math.PI / 4, I.angle = e.spot.outerConeAngle, I.penumbra = 1 - e.spot.innerConeAngle / e.spot.outerConeAngle, I.target.position.set(0, 0, -1), I.add(I.target); break; default: throw new Error("THREE.GLTFLoader: Unexpected light type: " + e.type); } return I.position.set(0, 0, 0), I.decay = 2, f(I, e), e.intensity !== void 0 && (I.intensity = e.intensity), I.name = A.createUniqueName(e.name || "light_" + P), w = Promise.resolve(I), A.cache.add(s, w), w; } getDependency(P, A) { if (P === "light") return this._loadLight(A); } createNodeAttachment(P) { const A = this, s = this.parser, D = s.json.nodes[P], g = (D.extensions && D.extensions[this.name] || {}).light; return g === void 0 ? null : this._loadLight(g).then(function(e) { return s._getNodeRef(A.cache, g, e); }); } } class xP { constructor() { this.name = v.KHR_MATERIALS_UNLIT; } getMaterialType() { return V; } extendParams(P, A, s) { const w = []; P.color = new O(1, 1, 1), P.opacity = 1; const D = A.pbrMetallicRoughness; if (D) { if (Array.isArray(D.baseColorFactor)) { const i = D.baseColorFactor; P.color.setRGB(i[0], i[1], i[2], U), P.opacity = i[3]; } D.baseColorTexture !== void 0 && w.push(s.assignTexture(P, "map", D.baseColorTexture, W)); } return Promise.all(w); } } class pP { constructor(P) { this.parser = P, this.name = v.KHR_MATERIALS_EMISSIVE_STRENGTH; } extendMaterialParams(P, A) { const w = this.parser.json.materials[P]; if (!w.extensions || !w.extensions[this.name]) return Promise.resolve(); const D = w.extensions[this.name].emissiveStrength; return D !== void 0 && (A.emissiveIntensity = D), Promise.resolve(); } } class HP { constructor(P) { this.parser = P, this.name = v.KHR_MATERIALS_CLEARCOAT; } getMaterialType(P) { const s = this.parser.json.materials[P]; return !s.extensions || !s.extensions[this.name] ? null : J; } extendMaterialParams(P, A) { const s = this.parser, w = s.json.materials[P]; if (!w.extensions || !w.extensions[this.name]) return Promise.resolve(); const D = [], i = w.extensions[this.name]; if (i.clearcoatFactor !== void 0 && (A.clearcoat = i.clearcoatFactor), i.clearcoatTexture !== void 0 && D.push(s.assignTexture(A, "clearcoatMap", i.clearcoatTexture)), i.clearcoatRoughnessFactor !== void 0 && (A.clearcoatRoughness = i.clearcoatRoughnessFactor), i.clearcoatRoughnessTexture !== void 0 && D.push(s.assignTexture(A, "clearcoatRoughnessMap", i.clearcoatRoughnessTexture)), i.clearcoatNormalTexture !== void 0 && (D.push(s.assignTexture(A, "clearcoatNormalMap", i.clearcoatNormalTexture)), i.clearcoatNormalTexture.scale !== void 0)) { const g = i.clearcoatNormalTexture.scale; A.clearcoatNormalScale = new LA(g, g); } return Promise.all(D); } } class XP { constructor(P) { this.parser = P, this.name = v.KHR_MATERIALS_IRIDESCENCE; } getMaterialType(P) { const s = this.parser.json.materials[P]; return !s.extensions || !s.extensions[this.name] ? null : J; } extendMaterialParams(P, A) { const s = this.parser, w = s.json.materials[P]; if (!w.extensions || !w.extensions[this.name]) return Promise.resolve(); const D = [], i = w.extensions[this.name]; return i.iridescenceFactor !== void 0 && (A.iridescence = i.iridescenceFactor), i.iridescenceTexture !== void 0 && D.push(s.assignTexture(A, "iridescenceMap", i.iridescenceTexture)), i.iridescenceIor !== void 0 && (A.iridescenceIOR = i.iridescenceIor), A.iridescenceThicknessRange === void 0 && (A.iridescenceThicknessRange = [100, 400]), i.iridescenceThicknessMinimum !== void 0 && (A.iridescenceThicknessRange[0] = i.iridescenceThicknessMinimum), i.iridescenceThicknessMaximum !== void 0 && (A.iridescenceThicknessRange[1] = i.iridescenceThicknessMaximum), i.iridescenceThicknessTexture !== void 0 && D.push(s.assignTexture(A, "iridescenceThicknessMap", i.iridescenceThicknessTexture)), Promise.all(D); } } class KP { constructor(P) { this.parser = P, this.name = v.KHR_MATERIALS_SHEEN; } getMaterialType(P) { const s = this.parser.json.materials[P]; return !s.extensions || !s.extensions[this.name] ? null : J; } extendMaterialParams(P, A) { const s = this.parser, w = s.json.materials[P]; if (!w.extensions || !w.extensions[this.name]) return Promise.resolve(); const D = []; A.sheenColor = new O(0, 0, 0), A.sheenRoughness = 0, A.sheen = 1; const i = w.extensions[this.name]; if (i.sheenColorFactor !== void 0) { const g = i.sheenColorFactor; A.sheenColor.setRGB(g[0], g[1], g[2], U); } return i.sheenRoughnessFactor !== void 0 && (A.sheenRoughness = i.sheenRoughnessFactor), i.sheenColorTexture !== void 0 && D.push(s.assignTexture(A, "sheenColorMap", i.sheenColorTexture, W)), i.sheenRoughnessTexture !== void 0 && D.push(s.assignTexture(A, "sheenRoughnessMap", i.sheenRoughnessTexture)), Promise.all(D); } } class qP { constructor(P) { this.parser = P, this.name = v.KHR_MATERIALS_TRANSMISSION; } getMaterialType(P) { const s = this.parser.json.materials[P]; return !s.extensions || !s.extensions[this.name] ? null : J; } extendMaterialParams(P, A) { const s = this.parser, w = s.json.materials[P]; if (!w.extensions || !w.extensions[this.name]) return Promise.resolve(); const D = [], i = w.extensions[this.name]; return i.transmissionFactor !== void 0 && (A.transmission = i.transmissionFactor), i.transmissionTexture !== void 0 && D.push(s.assignTexture(A, "transmissionMap", i.transmissionTexture)), Promise.all(D); } } class _P { constructor(P) { this.parser = P, this.name = v.KHR_MATERIALS_VOLUME; } getMaterialType(P) { const s = this.parser.json.materials[P]; return !s.extensions || !s.extensions[this.name] ? null : J; } extendMaterialParams(P, A) { const s = this.parser, w = s.json.materials[P]; if (!w.extensions || !w.extensions[this.name]) return Promise.resolve(); const D = [], i = w.extensions[this.name]; A.thickness = i.thicknessFactor !== void 0 ? i.thicknessFactor : 0, i.thicknessTexture !== void 0 && D.push(s.assignTexture(A, "thicknessMap", i.thicknessTexture)), A.attenuationDistance = i.attenuationDistance || 1 / 0; const g = i.attenuationColor || [1, 1, 1]; return A.attenuationColor = new O().setRGB(g[0], g[1], g[2], U), Promise.all(D); } } class $P { constructor(P) { this.parser = P, this.name = v.KHR_MATERIALS_IOR; } getMaterialType(P) { const s = this.parser.json.materials[P]; return !s.extensions || !s.extensions[this.name] ? null : J; } extendMaterialParams(P, A) { const w = this.parser.json.materials[P]; if (!w.extensions || !w.extensions[this.name]) return Promise.resolve(); const D = w.extensions[this.name]; return A.ior = D.ior !== void 0 ? D.ior : 1.5, Promise.resolve(); } } class Aw { constructor(P) { this.parser = P, this.name = v.KHR_MATERIALS_SPECULAR; } getMaterialType(P) { const s = this.parser.json.materials[P]; return !s.extensions || !s.extensions[this.name] ? null : J; } extendMaterialParams(P, A) { const s = this.parser, w = s.json.materials[P]; if (!w.extensions || !w.extensions[this.name]) return Promise.resolve(); const D = [], i = w.extensions[this.name]; A.specularIntensity = i.specularFactor !== void 0 ? i.specularFactor : 1, i.specularTexture !== void 0 && D.push(s.assignTexture(A, "specularIntensityMap", i.specularTexture)); const g = i.specularColorFactor || [1, 1, 1]; return A.specularColor = new O().setRGB(g[0], g[1], g[2], U), i.specularColorTexture !== void 0 && D.push(s.assignTexture(A, "specularColorMap", i.specularColorTexture, W)), Promise.all(D); } } class Pw { constructor(P) { this.parser = P, this.name = v.KHR_MATERIALS_ANISOTROPY; } getMaterialType(P) { const s = this.parser.json.materials[P]; return !s.extensions || !s.extensions[this.name] ? null : J; } extendMaterialParams(P, A) { const s = this.parser, w = s.json.materials[P]; if (!w.extensions || !w.extensions[this.name]) return Promise.resolve(); const D = [], i = w.extensions[this.name]; return i.anisotropyStrength !== void 0 && (A.anisotropy = i.anisotropyStrength), i.anisotropyRotation !== void 0 && (A.anisotropyRotation = i.anisotropyRotation), i.anisotropyTexture !== void 0 && D.push(s.assignTexture(A, "anisotropyMap", i.anisotropyTexture)), Promise.all(D); } } class ww { constructor(P) { this.parser = P, this.name = v.KHR_TEXTURE_BASISU; } loadTexture(P) { const A = this.parser, s = A.json, w = s.textures[P]; if (!w.extensions || !w.extensions[this.name]) return null; const D = w.extensions[this.name], i = A.options.ktx2Loader; if (!i) { if (s.extensionsRequired && s.extensionsRequired.indexOf(this.name) >= 0) throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures"); return null; } return A.loadTextureImage(P, D.source, i); } } class sw { constructor(P) { this.parser = P, this.name = v.EXT_TEXTURE_WEBP, this.isSupported = null; } loadTexture(P) { const A = this.name, s = this.parser, w = s.json, D = w.textures[P]; if (!D.extensions || !D.extensions[A]) return null; const i = D.extensions[A], g = w.images[i.source]; let e = s.textureLoader; if (g.uri) { const I = s.options.manager.getHandler(g.uri); I !== null && (e = I); } return this.detectSupport().then(function(I) { if (I) return s.loadTextureImage(P, i.source, e); if (w.extensionsRequired && w.extensionsRequired.indexOf(A) >= 0) throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported."); return s.loadTexture(P); }); } detectSupport() { return this.isSupported || (this.isSupported = new Promise(function(P) { const A = new Image(); A.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA", A.onload = A.onerror = function() { P(A.height === 1); }; })), this.isSupported; } } class Dw { constructor(P) { this.parser = P, this.name = v.EXT_TEXTURE_AVIF, this.isSupported = null; } loadTexture(P) { const A = this.name, s = this.parser, w = s.json, D = w.textures[P]; if (!D.extensions || !D.extensions[A]) return null; const i = D.extensions[A], g = w.images[i.source]; let e = s.textureLoader; if (g.uri) { const I = s.options.manager.getHandler(g.uri); I !== null && (e = I); } return this.detectSupport().then(function(I) { if (I) return s.loadTextureImage(P, i.source, e); if (w.extensionsRequired && w.extensionsRequired.indexOf(A) >= 0) throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported."); return s.loadTexture(P); }); } detectSupport() { return this.isSupported || (this.isSupported = new Promise(function(P) { const A = new Image(); A.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=", A.onload = A.onerror = function() { P(A.height === 1); }; })), this.isSupported; } } class iw { constructor(P) { this.name = v.EXT_MESHOPT_COMPRESSION, this.parser = P; } loadBufferView(P) { const A = this.parser.json, s = A.bufferViews[P]; if (s.extensions && s.extensions[this.name]) { const w = s.extensions[this.name], D = this.parser.getDependency("buffer", w.buffer), i = this.parser.options.meshoptDecoder; if (!i || !i.supported) { if (A.extensionsRequired && A.extensionsRequired.indexOf(this.name) >= 0) throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files"); return null; } return D.then(function(g) { const e = w.byteOffset || 0, I = w.byteLength || 0, C = w.count, B = w.byteStride, Q = new Uint8Array(g, e, I); return i.decodeGltfBufferAsync ? i.decodeGltfBufferAsync(C, B, Q, w.mode, w.filter).then(function(o) { return o.buffer; }) : i.ready.then(function() { const o = new ArrayBuffer(C * B); return i.decodeGltfBuffer(new Uint8Array(o), C, B, Q, w.mode, w.filter), o; }); }); } else return null; } } class ew { constructor(P) { this.name = v.EXT_MESH_GPU_INSTANCING, this.parser = P; } createNodeMesh(P) { const A = this.parser.json, s = A.nodes[P]; if (!s.extensions || !s.extensions[this.name] || s.mesh === void 0) return null; const w = A.meshes[s.mesh]; for (const I of w.primitives) if (I.mode !== a.TRIANGLES && I.mode !== a.TRIANGLE_STRIP && I.mode !== a.TRIANGLE_FAN && I.mode !== void 0) return null; const i = s.extensions[this.name].attributes, g = [], e = {}; for (const I in i) g.push(this.parser.getDependency("accessor", i[I]).then((C) => (e[I] = C, e[I]))); return g.length < 1 ? null : (g.push(this.parser.createNodeMesh(P)), Promise.all(g).then((I) => { const C = I.pop(), B = C.isGroup ? C.children : [C], Q = I[0].count, o = []; for (const t of B) { const E = new S(), r = new Z(), c = new TA(), l = new Z(1, 1, 1), z = new VA(t.geometry, t.material, Q); for (let M = 0; M < Q; M++) e.TRANSLATION && r.fromBufferAttribute(e.TRANSLATION, M), e.ROTATION && c.fromBufferAttribute(e.ROTATION, M), e.SCALE && l.fromBufferAttribute(e.SCALE, M), z.setMatrixAt(M, E.compose(r, c, l)); for (const M in e) if (M === "_COLOR_0") { const T = e[M]; z.instanceColor = new WA(T.array, T.itemSize, T.normalized); } else M !== "TRANSLATION" && M !== "ROTATION" && M !== "SCALE" && t.geometry.setAttribute(M, e[M]); uA.prototype.copy.call(z, t), this.parser.assignFinalMaterial(z), o.push(z); } return C.isGroup ? (C.clear(), C.add(...o), C) : o[0]; })); } } const JA = "glTF", N = 12, cA = { JSON: 1313821514, BIN: 5130562 }; class gw { constructor(P) { this.name = v.KHR_BINARY_GLTF, this.content = null, this.body = null; const A = new DataView(P, 0, N), s = new TextDecoder(); if (this.header = { magic: s.decode(new Uint8Array(P.slice(0, 4))), version: A.getUint32(4, !0), length: A.getUint32(8, !0) }, this.header.magic !== JA) throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header."); if (this.header.version < 2) throw new Error("THREE.GLTFLoader: Legacy binary file detected."); const w = this.header.length - N, D = new DataView(P, N); let i = 0; for (; i < w; ) { const g = D.getUint32(i, !0); i += 4; const e = D.getUint32(i, !0); if (i += 4, e === cA.JSON) { const I = new Uint8Array(P, N + i, g); this.content = s.decode(I); } else if (e === cA.BIN) { const I = N + i; this.body = P.slice(I, I + g); } i += g; } if (this.content === null) throw new Error("THREE.GLTFLoader: JSON content not found."); } } class Iw { constructor(P, A) { if (!A) throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided."); this.name = v.KHR_DRACO_MESH_COMPRESSION, this.json = P, this.dracoLoader = A, this.dracoLoader.preload(); } decodePrimitive(P, A) { const s = this.json, w = this.dracoLoader, D = P.extensions[this.name].bufferView, i = P.extensions[this.name].attributes, g = {}, e = {}, I = {}; for (const C in i) { const B = sA[C] || C.toLowerCase(); g[B] = i[C]; } for (const C in P.attributes) { const B = sA[C] || C.toLowerCase(); if (i[C] !== void 0) { const Q = s.accessors[P.attributes[C]], o = y[Q.componentType]; I[B] = o.name, e[B] = Q.normalized === !0; } } return A.getDependency("bufferView", D).then(function(C) { return new Promise(function(B) { w.decodeDracoFile(C, function(Q) { for (const o in Q.attributes) { const t = Q.attributes[o], E = e[o]; E !== void 0 && (t.normalized = E); } B(Q); }, g, I); }); }); } } class Bw { constructor() { this.name = v.KHR_TEXTURE_TRANSFORM; } extendTexture(P, A) { return (A.texCoord === void 0 || A.texCoord === P.channel) && A.offset === void 0 && A.rotation === void 0 && A.scale === void 0 || (P = P.clone(), A.texCoord !== void 0 && (P.channel = A.texCoord), A.offset !== void 0 && P.offset.fromArray(A.offset), A.rotation !== void 0 && (P.rotation = A.rotation), A.scale !== void 0 && P.repeat.fromArray(A.scale), P.needsUpdate = !0), P; } } class Cw { constructor() { this.name = v.KHR_MESH_QUANTIZATION; } } class YA extends EP { constructor(P, A, s, w) { super(P, A, s, w); } copySampleValue_(P) { const A = this.resultBuffer, s = this.sampleValues, w = this.valueSize, D = P * w * 3 + w; for (let i = 0; i !== w; i++) A[i] = s[D + i]; return A; } interpolate_(P, A, s, w) { const D = this.resultBuffer, i = this.sampleValues, g = this.valueSize, e = g * 2, I = g * 3, C = w - A, B = (s - A) / C, Q = B * B, o = Q * B, t = P * I, E = t - I, r = -2 * o + 3 * Q, c = o - Q, l = 1 - r, z = c - Q + B; for (let M = 0; M !== g; M++) { const T = i[E + M + g], m = i[E + M + e] * C, L = i[t + M + g], R = i[t + M] * C; D[M] = l * T + z * m + r * L + c * R; } return D; } } const nw = new TA(); class Qw extends YA { interpolate_(P, A, s, w) { const D = super.interpolate_(P, A, s, w); return nw.fromArray(D).normalize().toArray(D), D; } } const a = { 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 }, y = { 5120: Int8Array, 5121: Uint8Array, 5122: Int16Array, 5123: Uint16Array, 5125: Uint32Array, 5126: Float32Array }, jA = { 9728: BP, 9729: mA, 9984: CP, 9985: nP, 9986: QP, 9987: bA }, EA = { 33071: oP, 33648: tP, 10497: PA }, K = { SCALAR: 1, VEC2: 2, VEC3: 3, VEC4: 4, MAT2: 4, MAT3: 9, MAT4: 16 }, sA = { 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" }, d = { scale: "scale", translation: "position", rotation: "quaternion", weights: "morphTargetInfluences" }, ow = { 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: fA, STEP: rP }, q = { OPAQUE: "OPAQUE", MASK: "MASK", BLEND: "BLEND" }; function tw(n) { return n.DefaultMaterial === void 0 && (n.DefaultMaterial = new dA({ color: 16777215, emissive: 0, metalness: 1, roughness: 1, transparent: !1, depthTest: !0, side: vP })), n.DefaultMaterial; } function Y(n, P, A) { for (const s in A.extensions) n[s] === void 0 && (P.userData.gltfExtensions = P.userData.gltfExtensions || {}, P.userData.gltfExtensions[s] = A.extensions[s]); } function f(n, P) { P.extras !== void 0 && (typeof P.extras == "object" ? Object.assign(n.userData, P.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + P.extras)); } function rw(n, P, A) { let s = !1, w = !1, D = !1; for (let I = 0, C = P.length; I < C; I++) { const B = P[I]; if (B.POSITION !== void 0 && (s = !0), B.NORMAL !== void 0 && (w = !0), B.COLOR_0 !== void 0 && (D = !0), s && w && D) break; } if (!s && !w && !D) return Promise.resolve(n); const i = [], g = [], e = []; for (let I = 0, C = P.length; I < C; I++) { const B = P[I]; if (s) { const Q = B.POSITION !== void 0 ? A.getDependency("accessor", B.POSITION) : n.attributes.position; i.push(Q); } if (w) { const Q = B.NORMAL !== void 0 ? A.getDependency("accessor", B.NORMAL) : n.attributes.normal; g.push(Q); } if (D) { const Q = B.COLOR_0 !== void 0 ? A.getDependency("accessor", B.COLOR_0) : n.attributes.color; e.push(Q); } } return Promise.all([ Promise.all(i), Promise.all(g), Promise.all(e) ]).then(function(I) { const C = I[0], B = I[1], Q = I[2]; return s && (n.morphAttributes.position = C), w && (n.morphAttributes.normal = B), D && (n.morphAttributes.color = Q), n.morphTargetsRelative = !0, n; }); } function vw(n, P) { if (n.updateMorphTargets(), P.weights !== void 0) for (let A = 0, s = P.weights.length; A < s; A++) n.morphTargetInfluences[A] = P.weights[A]; if (P.extras && Array.isArray(P.extras.targetNames)) { const A = P.extras.targetNames; if (n.morphTargetInfluences.length === A.length) { n.morphTargetDictionary = {}; for (let s = 0, w = A.length; s < w; s++) n.morphTargetDictionary[A[s]] = s; } else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names."); } } function cw(n) { let P; const A = n.extensions && n.extensions[v.KHR_DRACO_MESH_COMPRESSION]; if (A ? P = "draco:" + A.bufferView + ":" + A.indices + ":" + _(A.attributes) : P = n.indices + ":" + _(n.attributes) + ":" + n.mode, n.targets !== void 0) for (let s = 0, w = n.targets.length; s < w; s++) P += ":" + _(n.targets[s]); return P; } function _(n) { let P = ""; const A = Object.keys(n).sort(); for (let s = 0, w = A.length; s < w; s++) P += A[s] + ":" + n[A[s]] + ";"; return P; } function DA(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 jw(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 Ew = new S(); class Mw { constructor(P = {}, A = {}) { this.json = P, this.extensions = {}, this.plugins = {}, this.options = A, this.cache = new kP(), 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, w = !1, D = -1; typeof navigator < "u" && (s = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) === !0, w = navigator.userAgent.indexOf("Firefox") > -1, D = w ? navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1] : -1), typeof createImageBitmap > "u" || s || w && D < 98 ? this.textureLoader = new kA(this.options.manager) : this.textureLoader = new SA(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new zA(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(!0); } setExtensions(P) { this.extensions = P; } setPlugins(P) { this.plugins = P; } parse(P, A) { const s = this, w = this.json, D = this.extensions; this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(i) { return i._markDefs && i._markDefs(); }), Promise.all(this._invokeAll(function(i) { return i.beforeRoot && i.beforeRoot(); })).then(function() { return Promise.all([ s.getDependencies("scene"), s.getDependencies("animation"), s.getDependencies("camera") ]); }).then(function(i) { const g = { scene: i[0][w.scene || 0], scenes: i[0], animations: i[1], cameras: i[2], asset: w.asset, parser: s, userData: {} }; return Y(D, g, w), f(g, w), Promise.all(s._invokeAll(function(e) { return e.afterRoot && e.afterRoot(g); })).then(function() { P(g); }); }).catch(A); } /** * Marks the special nodes/meshes in json for efficient parse. */ _markDefs() { const P = this.json.nodes || [], A = this.json.skins || [], s = this.json.meshes || []; for (let w = 0, D = A.length; w < D; w++) { const i = A[w].joints; for (let g = 0, e = i.length; g < e; g++) P[i[g]].isBone = !0; } for (let w = 0, D = P.length; w < D; w++) { const i = P[w]; i.mesh !== void 0 && (this._addNodeRef(this.meshCache, i.mesh), i.skin !== void 0 && (s[i.mesh].isSkinnedMesh = !0)), i.camera !== void 0 && this._addNodeRef(this.cameraCache, i.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(P, A) { A !== void 0 && (P.refs[A] === void 0 && (P.refs[A] = P.uses[A] = 0), P.refs[A]++); } /** Returns a reference to a shared resource, cloning it if necessary. */ _getNodeRef(P, A, s) { if (P.refs[A] <= 1) return s; const w = s.clone(), D = (i, g) => { const e = this.associations.get(i); e != null && this.associations.set(g, e); for (const [I, C] of i.children.entries()) D(C, g.children[I]); }; return D(s, w), w.name += "_instance_" + P.uses[A]++, w; } _invokeOne(P) { const A = Object.values(this.plugins); A.push(this); for (let s = 0; s < A.length; s++) { const w = P(A[s]); if (w) return w; } return null; } _invokeAll(P) { const A = Object.values(this.plugins); A.unshift(this); const s = []; for (let w = 0; w < A.length; w++) { const D = P(A[w]); D && s.push(D); } 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(P, A) { const s = P + ":" + A; let w = this.cache.get(s); if (!w) { switch (P) { case "scene": w = this.loadScene(A); break; case "node": w = this._invokeOne(function(D) { return D.loadNode && D.loadNode(A); }); break; case "mesh": w = this._invokeOne(function(D) { return D.loadMesh && D.loadMesh(A); }); break; case "accessor": w = this.loadAccessor(A); break; case "bufferView": w = this._invokeOne(function(D) { return D.loadBufferView && D.loadBufferView(A); }); break; case "buffer": w = this.loadBuffer(A); break; case "material": w = this._invokeOne(function(D) { return D.loadMaterial && D.loadMaterial(A); }); break; case "texture": w = this._invokeOne(function(D) { return D.loadTexture && D.loadTexture(A); }); break; case "skin": w = this.loadSkin(A); break; case "animation": w = this._invokeOne(function(D) { return D.loadAnimation && D.loadAnimation(A); }); break; case "camera": w = this.loadCamera(A); break; default: if (w = this._invokeOne(function(D) { return D != this && D.getDependency && D.getDependency(P, A); }), !w) throw new Error("Unknown type: " + P); break; } this.cache.add(s, w); } return w; } /** * Requests all dependencies of the specified type asynchronously, with caching. * @param {string} type * @return {Promise<Array<Object>>} */ getDependencies(P) { let A = this.cache.get(P); if (!A) { const s = this, w = this.json[P + (P === "mesh" ? "es" : "s")] || []; A = Promise.all(w.map(function(D, i) { return s.getDependency(P, i); })), this.cache.add(P, A); } return A; } /** * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views * @param {number} bufferIndex * @return {Promise<ArrayBuffer>} */ loadBuffer(P) { const A = this.json.buffers[P], s = this.fileLoader; if (A.type && A.type !== "arraybuffer") throw new Error("THREE.GLTFLoader: " + A.type + " buffer type is not supported."); if (A.uri === void 0 && P === 0) return Promise.resolve(this.extensions[v.KHR_BINARY_GLTF].body); const w = this.options; return new Promise(function(D, i) { s.load(AA.resolveURL(A.uri, w.path), D, void 0, function() { i(new Error('THREE.GLTFLoader: Failed to load buffer "' + A.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(P) { const A = this.json.bufferViews[P]; return this.getDependency("buffer", A.buffer).then(function(s) { const w = A.byteLength || 0, D = A.byteOffset || 0; return s.slice(D, D + w); }); } /** * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors * @param {number} accessorIndex * @return {Promise<BufferAttribute|InterleavedBufferAttribute>} */ loadAccessor(P) { const A = this, s = this.json, w = this.json.accessors[P]; if (w.bufferView === void 0 && w.sparse === void 0) { const i = K[w.type], g = y[w.componentType], e = w.normalized === !0, I = new g(w.count * i); return Promise.resolve(new p(I, i, e)); } const D = []; return w.bufferView !== void 0 ? D.push(this.getDependency("bufferView", w.bufferView)) : D.push(null), w.sparse !== void 0 && (D.push(this.getDependency("bufferView", w.sparse.indices.bufferView)), D.push(this.getDependency("bufferView", w.sparse.values.bufferView))), Promise.all(D).then(function(i) { const g = i[0], e = K[w.type], I = y[w.componentType], C = I.BYTES_PER_ELEMENT, B = C * e, Q = w.byteOffset || 0, o = w.bufferView !== void 0 ? s.bufferViews[w.bufferView].byteStride : void 0, t = w.normalized === !0; let E, r; if (o && o !== B) { const c = Math.floor(Q / o), l = "InterleavedBuffer:" + w.bufferView + ":" + w.componentType + ":" + c + ":" + w.count; let z = A.cache.get(l); z || (E = new I(g, c * o, w.count * o / C), z = new xA(E, o / C), A.cache.add(l, z)), r = new pA(z, e, Q % o / C, t); } else g === null ? E = new I(w.count * e) : E = new I(g, Q, w.count * e), r = new p(E, e, t); if (w.sparse !== void 0) { const c = K.SCALAR, l = y[w.sparse.indices.componentType], z = w.sparse.indices.byteOffset || 0, M = w.sparse.values.byteOffset || 0, T = new l(i[1], z, w.sparse.count * c), m = new I(i[2], M, w.sparse.count * e); g !== null && (r = new p(r.array.slice(), r.itemSize, r.normalized)); for (let L = 0, R = T.length; L < R; L++) { const b = T[L]; if (r.setX(b, m[L * e]), e >= 2 && r.setY(b, m[L * e + 1]), e >= 3 && r.setZ(b, m[L * e + 2]), e >= 4 && r.setW(b, m[L * e + 3]), e >= 5) throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute."); } } return r; }); } /** * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures * @param {number} textureIndex * @return {Promise<THREE.Texture|null>} */ loadTexture(P) { const A = this.json, s = this.options, D = A.textures[P].source, i = A.images[D]; let g = this.textureLoader; if (i.uri) { const e = s.manager.getHandler(i.uri); e !== null && (g = e); } return this.loadTextureImage(P, D, g); } loadTextureImage(P, A, s) { const w = this, D = this.json, i = D.textures[P], g = D.images[A], e = (g.uri || g.bufferView) + ":" + i.sampler; if (this.textureCache[e]) return this.textureCache[e]; const I = this.loadImageSource(A, s).then(function(C) { C.flipY = !1, C.name = i.name || g.name || "", C.name === "" && typeof g.uri == "string" && g.uri.startsWith("data:image/") === !1 && (C.name = g.uri); const Q = (D.samplers || {})[i.sampler] || {}; return C.magFilter = jA[Q.magFilter] || mA, C.minFilter = jA[Q.minFilter] || bA, C.wrapS = EA[Q.wrapS] || PA, C.wrapT = EA[Q.wrapT] || PA, w.associations.set(C, { textures: P }), C; }).catch(function() { return null; }); return this.textureCache[e] = I, I; } loadImageSource(P, A) { const s = this, w = this.json, D = this.options; if (this.sourceCache[P] !== void 0) return this.sourceCache[P].then((B) => B.clone()); const i = w.images[P], g = self.URL || self.webkitURL; let e = i.uri || "", I = !1; if (i.bufferView !== void 0) e = s.getDependency("bufferView", i.bufferView).then(function(B) { I = !0; const Q = new Blob([B], { type: i.mimeType }); return e = g.createObjectURL(Q), e; }); else if (i.uri === void 0) throw new Error("THREE.GLTFLoader: Image " + P + " is missing URI and bufferView"); const C = Promise.resolve(e).then(function(B) { return new Promise(function(Q, o) { let t = Q; A.isImageBitmapLoader === !0 && (t = function(E) { const r = new eA(E); r.needsUpdate = !0, Q(r); }), A.load(AA.resolveURL(B, D.path), t, void 0, o); }); }).then(function(B) { return I === !0 && g.revokeObjectURL(e), B.userData.mimeType = i.mimeType || jw(i.uri), B; }).catch(function(B) { throw console.error("THREE.GLTFLoader: Couldn't load texture", e), B; }); return this.sourceCache[P] = C, C; } /** * Asynchronously assigns a texture to the given material parameters. * @param {Object} materialParams * @param {string} mapName * @param {Object} mapDef * @return {Promise<Texture>} */ assignTexture(P, A, s, w) { const D = this; return this.getDependency("texture", s.index).then(function(i) { if (!i) return null; if (s.texCoord !== void 0 && s.texCoord > 0 && (i = i.clone(), i.channel = s.texCoord), D.extensions[v.KHR_TEXTURE_TRANSFORM]) { const g = s.extensions !== void 0 ? s.extensions[v.KHR_TEXTURE_TRANSFORM] : void 0; if (g) { const e = D.associations.get(i); i = D.extensions[v.KHR_TEXTURE_TRANSFORM].extendTexture(i, g), D.associations.set(i, e); } } return w !== void 0 && (i.colorSpace = w), P[A] = i, i; }); } /** * 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(P) { const A = P.geometry; let s = P.material; const w = A.attributes.tangent === void 0, D = A.attributes.color !== void 0, i = A.attributes.normal === void 0; if (P.isPoints) { const g = "PointsMaterial:" + s.uuid; let e = this.cache.get(g); e || (e = new HA(), H.prototype.copy.call(e, s), e.color.copy(s.color), e.map = s.map, e.sizeAttenuation = !1, this.cache.add(g, e)), s = e; } else if (P.isLine) { const g = "LineBasicMaterial:" + s.uuid; let e = this.cache.get(g); e || (e = new XA(), H.prototype.copy.call(e, s), e.color.copy(s.color), e.map = s.map, this.cache.add(g, e)), s = e; } if (w || D || i) { let g = "ClonedMaterial:" + s.uuid + ":"; w && (g += "derivative-tangents:"), D && (g += "vertex-colors:"), i && (g += "flat-shading:"); let e = this.cache.get(g); e || (e = s.clone(), D && (e.vertexColors = !0), i && (e.flatShading = !0), w && (e.normalScale && (e.normalScale.y *= -1), e.clearcoatNormalScale && (e.clearcoatNormalScale.y *= -1)), this.cache.add(g, e), this.associations.set(e, this.associations.get(s))), s = e; } P.material = s; } getMaterialType() { return dA; } /** * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials * @param {number} materialIndex * @return {Promise<Material>} */ loadMaterial(P) { const A = this, s = this.json, w = this.extensions, D = s.materials[P]; let i; const g = {}, e = D.extensions || {}, I = []; if (e[v.KHR_MATERIALS_UNLIT]) { const B = w[v.KHR_MATERIALS_UNLIT]; i = B.getMaterialType(), I.push(B.extendParams(g, D, A)); } else { const B = D.pbrMetallicRoughness || {}; if (g.color = new O(1, 1, 1), g.opacity = 1, Array.isArray(B.baseColorFactor)) { const Q = B.baseColorFactor; g.color.setRGB(Q[0], Q[1], Q[2], U), g.opacity = Q[3]; } B.baseColorTexture !== void 0 && I.push(A.assignTexture(g, "map", B.baseColorTexture, W)), g.metalness = B.metallicFactor !== void 0 ? B.metallicFactor : 1, g.roughness = B.roughnessFactor !== void 0 ? B.roughnessFactor : 1, B.metallicRoughnessTexture !== void 0 && (I.push(A.assignTexture(g, "metalnessMap", B.metallicRoughnessTexture)), I.push(A.assignTexture(g, "roughnessMap", B.metallicRoughnessTexture))), i = this._invokeOne(function(Q) { return Q.getMaterialType && Q.getMaterialType(P); }), I.push(Promise.all(this._invokeAll(function(Q) { return Q.extendMaterialParams && Q.extendMaterialParams(P, g); }))); } D.doubleSided === !0 && (g.side = KA); const C = D.alphaMode || q.OPAQUE; if (C === q.BLEND ? (g.transparent = !0, g.depthWrite = !1) : (g.transparent = !1, C === q.MASK && (g.alphaTest = D.alphaCutoff !== void 0 ? D.alphaCutoff : 0.5)), D.normalTexture !== void 0 && i !== V && (I.push(A.assignTexture(g, "normalMap", D.normalTexture)), g.normalScale =