UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

1,224 lines (1,214 loc) • 489 kB
import { Mesh as z, SphereGeometry as ci, Vector3 as P, MeshBasicMaterial as Qt, Node as ra, PerspectiveCamera as ds, NodeFrame as aa, NodeBuilder as Aa, GLSLNodeParser as ca, ShaderLib as wt, UniformsUtils as li, UniformsLib as Un, normalView as la, defaultShaderStages as Kn, ShaderChunk as ha, Material as tn, TrianglesDrawMode as ua, TriangleFanDrawMode as Js, TriangleStripDrawMode as So, Matrix4 as ue, Loader as Nt, LoaderUtils as nn, FileLoader as ft, MeshPhysicalMaterial as Tt, Vector2 as Le, Color as Se, LinearSRGBColorSpace as Ve, SRGBColorSpace as ge, SpotLight as vo, PointLight as Ws, DirectionalLight as To, InstancedMesh as ga, Quaternion as ve, InstancedBufferAttribute as da, Object3D as xt, TextureLoader as hi, ImageBitmapLoader as pa, BufferAttribute as nt, InterleavedBuffer as fa, LinearMipmapLinearFilter as ps, NearestMipmapLinearFilter as Ro, LinearMipmapNearestFilter as _o, NearestMipmapNearestFilter as Do, LinearFilter as mt, NearestFilter as Mo, RepeatWrapping as rn, MirroredRepeatWrapping as ko, ClampToEdgeWrapping as As, PointsMaterial as Dn, LineBasicMaterial as Lt, MeshStandardMaterial as ui, DoubleSide as gi, PropertyBinding as It, BufferGeometry as ut, SkinnedMesh as di, LineSegments as cs, Line as dt, LineLoop as ma, Points as is, Group as sn, MathUtils as ye, OrthographicCamera as Fo, Skeleton as Lo, AnimationClip as pi, Bone as Vs, InterpolateDiscrete as fi, InterpolateLinear as jn, InterleavedBufferAttribute as en, Texture as Xs, VectorKeyframeTrack as ls, NumberKeyframeTrack as hs, QuaternionKeyframeTrack as us, ColorManagement as We, FrontSide as No, Interpolant as Ia, Box3 as fs, Sphere as mi, RGBA_S3TC_DXT1_Format as ba, RGB_PVRTC_4BPPV1_Format as Ea, RGB_ETC2_Format as Ca, RGB_ETC1_Format as Ba, RGBA_S3TC_DXT5_Format as wa, RGBA_PVRTC_4BPPV1_Format as ya, RGBA_ETC2_EAC_Format as Qa, RGBA_BPTC_Format as xa, RGBA_ASTC_4x4_Format as Uo, RGBAFormat as Kt, CompressedCubeTexture as Sa, UnsignedByteType as pt, CompressedArrayTexture as va, CompressedTexture as Gn, DisplayP3ColorSpace as Ta, LinearDisplayP3ColorSpace as Ra, NoColorSpace as gs, RGBA_ASTC_6x6_Format as Ri, RedFormat as dn, RGFormat as Mn, HalfFloatType as st, FloatType as St, DataTexture as _a, Data3DTexture as Da, ExtrudeGeometry as Ma, ShapePath as ka, Raycaster as Ii, CylinderGeometry as Ke, BoxGeometry as je, Float32BufferAttribute as ke, OctahedronGeometry as Yn, TorusGeometry as Cn, Euler as zt, Controls as Go, PlaneGeometry as bi, DataTextureLoader as Po, DataUtils as pn, Vector4 as Ut, Curve as Fa, MeshPhongMaterial as Pn, MeshLambertMaterial as La, EquirectangularReflectionMapping as Na, AmbientLight as Ua, Uint16BufferAttribute as Ga, Matrix3 as Oo, ShapeUtils as Pa, DefaultLoadingManager as Oa, Ray as Ha, Plane as ja, MOUSE as mn, TOUCH as fn, Spherical as _i, ShaderMaterial as Ho, Uniform$1 as qa, Scene as Zs, WebGLRenderer as za, CanvasTexture as jo, REVISION as Ka, Source as Ya, InstancedBufferGeometry as Ja, InstancedInterleavedBuffer as $s, WireframeGeometry as Wa, Line3 as Va, ColorKeyframeTrack as Xa } from "./three-Bz6X1mrw.js"; class eh extends z { constructor(e, t, s, n = 128) { if (t <= 0 || s <= 0 || n <= 0) throw new Error("GroundedSkybox height, radius, and resolution must be positive."); const i = new ci(s, 2 * n, n); i.scale(1, 1, -1); const o = i.getAttribute("position"), r = new P(); for (let a = 0; a < o.count; ++a) if (r.fromBufferAttribute(o, a), r.y < 0) { const c = -t * 3 / 2, l = r.y < c ? -t / r.y : 1 - r.y * r.y / (3 * c * c); r.multiplyScalar(l), r.toArray(o.array, 3 * a); } o.needsUpdate = !0, super(i, new Qt({ map: e, depthWrite: !1 })); } } class Ce extends ra { constructor(e) { super(e.nodeType), this.node = null, this.source = null, this.target = null, this.inclusionType = "replace", Object.assign(this, e); } generate(e) { return this.node.build(e, this.getNodeType(e)); } } const tt = new aa(); tt.camera = new ds(); const Di = { LineBasicNodeMaterial: wt.basic, MeshBasicNodeMaterial: wt.basic, PointsNodeMaterial: wt.points, MeshStandardNodeMaterial: wt.standard, MeshPhysicalNodeMaterial: wt.physical, MeshPhongNodeMaterial: wt.phong }, Za = { atan2: "atan" }, $a = { low: "lowp", medium: "mediump", high: "highp" }; function Ot(A) { return `#include <${A}>`; } function Bn(A) { return `${A}Shader`; } class eA extends Aa { constructor(e, t, s, n = null) { super(e, t, new ca(), null, n), this.shader = s, this.slots = { vertex: [], fragment: [] }, this._parseShaderLib(), this._parseInclude("fragment", "lights_physical_fragment", "clearcoat_normal_fragment_begin", "transmission_fragment"), this._parseObject(), this._sortSlotsToFlow(), this.useComparisonMethod = !0; } getMethod(e) { return Za[e] || e; } addSlot(e, t) { this.slots[e].push(t); } _parseShaderLib() { const e = this.material; let t = e.type; if (e.isMeshPhysicalNodeMaterial ? t = "MeshPhysicalNodeMaterial" : e.isMeshStandardNodeMaterial ? t = "MeshStandardNodeMaterial" : e.isMeshPhongNodeMaterial ? t = "MeshPhongNodeMaterial" : e.isMeshBasicNodeMaterial ? t = "MeshBasicNodeMaterial" : e.isPointsNodeMaterial ? t = "PointsNodeMaterial" : e.isLineBasicNodeMaterial && (t = "LineBasicNodeMaterial"), Di[t] !== void 0) { const s = Di[t], n = this.shader; n.vertexShader = s.vertexShader, n.fragmentShader = s.fragmentShader, n.uniforms = li.merge([s.uniforms, Un.lights]); } } _parseObject() { const { material: e, renderer: t } = this; this.addSlot("fragment", new Ce({ node: la, nodeType: "vec3", source: "void main() {", target: "vec3 TransformedNormalView = %RESULT%;", inclusionType: "append" })), t.toneMappingNode && t.toneMappingNode.isNode === !0 && this.addSlot("fragment", new Ce({ node: e.colorNode, nodeType: "vec4", source: Ot("tonemapping_fragment"), target: "" })), e.colorNode && e.colorNode.isNode && this.addSlot("fragment", new Ce({ node: e.colorNode, nodeType: "vec4", source: "vec4 diffuseColor = vec4( diffuse, opacity );", target: "vec4 diffuseColor = %RESULT%; diffuseColor.a *= opacity;" })), e.opacityNode && e.opacityNode.isNode && this.addSlot("fragment", new Ce({ node: e.opacityNode, nodeType: "float", source: Ot("alphatest_fragment"), target: "diffuseColor.a = %RESULT%;", inclusionType: "append" })), e.normalNode && e.normalNode.isNode && this.addSlot("fragment", new Ce({ node: e.normalNode, nodeType: "vec3", source: Ot("normal_fragment_begin"), target: "normal = %RESULT%;", inclusionType: "append" })), e.emissiveNode && e.emissiveNode.isNode && this.addSlot("fragment", new Ce({ node: e.emissiveNode, nodeType: "vec3", source: Ot("emissivemap_fragment"), target: "totalEmissiveRadiance = %RESULT%;", inclusionType: "append" })), e.isMeshStandardNodeMaterial && (e.metalnessNode && e.metalnessNode.isNode && this.addSlot("fragment", new Ce({ node: e.metalnessNode, nodeType: "float", source: Ot("metalnessmap_fragment"), target: "metalnessFactor = %RESULT%;", inclusionType: "append" })), e.roughnessNode && e.roughnessNode.isNode && this.addSlot("fragment", new Ce({ node: e.roughnessNode, nodeType: "float", source: Ot("roughnessmap_fragment"), target: "roughnessFactor = %RESULT%;", inclusionType: "append" })), e.isMeshPhysicalNodeMaterial && (e.clearcoatNode && e.clearcoatNode.isNode ? (this.addSlot("fragment", new Ce({ node: e.clearcoatNode, nodeType: "float", source: "material.clearcoat = clearcoat;", target: "material.clearcoat = %RESULT%;" })), e.clearcoatRoughnessNode && e.clearcoatRoughnessNode.isNode && this.addSlot("fragment", new Ce({ node: e.clearcoatRoughnessNode, nodeType: "float", source: "material.clearcoatRoughness = clearcoatRoughness;", target: "material.clearcoatRoughness = %RESULT%;" })), e.clearcoatNormalNode && e.clearcoatNormalNode.isNode && this.addSlot("fragment", new Ce({ node: e.clearcoatNormalNode, nodeType: "vec3", source: "vec3 clearcoatNormal = nonPerturbedNormal;", target: "vec3 clearcoatNormal = %RESULT%;" })), e.defines.USE_CLEARCOAT = "") : delete e.defines.USE_CLEARCOAT, e.sheenNode && e.sheenNode.isNode ? (this.addSlot("fragment", new Ce({ node: e.sheenNode, nodeType: "vec3", source: "material.sheenColor = sheenColor;", target: "material.sheenColor = %RESULT%;" })), e.sheenRoughnessNode && e.sheenRoughnessNode.isNode && this.addSlot("fragment", new Ce({ node: e.sheenRoughnessNode, nodeType: "float", source: "material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );", target: "material.sheenRoughness = clamp( %RESULT%, 0.07, 1.0 );" })), e.defines.USE_SHEEN = "") : delete e.defines.USE_SHEEN, e.iridescenceNode && e.iridescenceNode.isNode ? (this.addSlot("fragment", new Ce({ node: e.iridescenceNode, nodeType: "float", source: "material.iridescence = iridescence;", target: "material.iridescence = %RESULT%;" })), e.iridescenceIORNode && e.iridescenceIORNode.isNode && this.addSlot("fragment", new Ce({ node: e.iridescenceIORNode, nodeType: "float", source: "material.iridescenceIOR = iridescenceIOR;", target: "material.iridescenceIOR = %RESULT%;" })), e.iridescenceThicknessNode && e.iridescenceThicknessNode.isNode && this.addSlot("fragment", new Ce({ node: e.iridescenceThicknessNode, nodeType: "float", source: "material.iridescenceThickness = iridescenceThicknessMaximum;", target: "material.iridescenceThickness = %RESULT%;" })), e.defines.USE_IRIDESCENCE = "") : delete e.defines.USE_IRIDESCENCE, e.iorNode && e.iorNode.isNode && this.addSlot("fragment", new Ce({ node: e.iorNode, nodeType: "float", source: "material.ior = ior;", target: "material.ior = %RESULT%;" })), e.specularColorNode && e.specularColorNode.isNode && this.addSlot("fragment", new Ce({ node: e.specularColorNode, nodeType: "vec3", source: "vec3 specularColorFactor = specularColor;", target: "vec3 specularColorFactor = %RESULT%;" })), e.specularIntensityNode && e.specularIntensityNode.isNode && this.addSlot("fragment", new Ce({ node: e.specularIntensityNode, nodeType: "float", source: "float specularIntensityFactor = specularIntensity;", target: "float specularIntensityFactor = %RESULT%;" })), e.transmissionNode && e.transmissionNode.isNode ? (this.addSlot("fragment", new Ce({ node: e.transmissionNode, nodeType: "float", source: "material.transmission = transmission;", target: "material.transmission = %RESULT%;" })), e.thicknessNode && e.thicknessNode.isNode && this.addSlot("fragment", new Ce({ node: e.thicknessNode, nodeType: "float", source: "material.thickness = thickness;", target: "material.thickness = %RESULT%;" })), e.attenuationDistanceNode && e.attenuationDistanceNode.isNode && this.addSlot("fragment", new Ce({ node: e.attenuationDistanceNode, nodeType: "float", source: "material.attenuationDistance = attenuationDistance;", target: "material.attenuationDistance = %RESULT%;" })), e.attenuationColorNode && e.attenuationColorNode.isNode && this.addSlot("fragment", new Ce({ node: e.attenuationColorNode, nodeType: "vec3", source: "material.attenuationColor = attenuationColor;", target: "material.attenuationColor = %RESULT%;" })), e.transmission = 1, e.defines.USE_TRANSMISSION = "") : (e.transmission = 0, delete e.defines.USE_TRANSMISSION))), e.positionNode && e.positionNode.isNode && this.addSlot("vertex", new Ce({ node: e.positionNode, nodeType: "vec3", source: Ot("begin_vertex"), target: "transformed = %RESULT%;", inclusionType: "append" })), e.sizeNode && e.sizeNode.isNode && this.addSlot("vertex", new Ce({ node: e.sizeNode, nodeType: "float", source: "gl_PointSize = size;", target: "gl_PointSize = %RESULT%;" })); } generateTexture(e, t, s) { return e.isTextureCube ? `textureCube( ${t}, ${s} )` : `texture2D( ${t}, ${s} )`; } generateTextureLevel(e, t, s, n) { return `textureLod( ${t}, ${s}, ${n} )`; } buildFunctionCode(e) { const t = e.layout, s = this.flowShaderNode(e), n = []; for (const o of t.inputs) n.push(this.getType(o.type) + " " + o.name); return `${this.getType(t.type)} ${t.name}( ${n.join(", ")} ) { ${s.vars} ${s.code} return ${s.result}; }`; } getUniforms(e) { const t = this.uniforms[e]; let s = ""; for (const n of t) { if (/^(modelViewMatrix|projectionMatrix)$/.test(n.name)) continue; let i = null; n.type === "texture" ? i = `sampler2D ${n.name}; ` : n.type === "cubeTexture" ? i = `samplerCube ${n.name}; ` : i = `${this.getVectorType(n.type)} ${n.name}; `; const o = n.node.precision; o !== null ? i = "uniform " + $a[o] + " " + i : i = "uniform " + i, s += i; } return s; } getAttributes(e) { let t = ""; if (e === "vertex") { const s = this.attributes; for (const n of s) /^(position|normal|uv[1-3]?)$/.test(n.name) || (t += `attribute ${n.type} ${n.name}; `); } return t; } getVaryings(e) { let t = ""; const s = this.varyings; if (e === "vertex") for (const n of s) t += `${n.needsInterpolation ? "varying" : "/*varying*/"} ${n.type} ${n.name}; `; else if (e === "fragment") for (const n of s) n.needsInterpolation && (t += `varying ${n.type} ${n.name}; `); return t; } addCode(e, t, s, n = this) { const i = Bn(e); let o = n[i]; const r = o.indexOf(t); if (r !== -1) { const a = o.substring(0, r + t.length), c = o.substring(r + t.length); o = `${a} ${s} ${c}`; } n[i] = o; } replaceCode(e, t, s, n = this) { const i = Bn(e); n[i] = n[i].replaceAll(t, s); } getVertexIndex() { return "gl_VertexID"; } getFrontFacing() { return "gl_FrontFacing"; } getFragCoord() { return "gl_FragCoord"; } isFlipY() { return !0; } buildCode() { const e = {}; for (const t of Kn) { const s = this.getUniforms(t), n = this.getAttributes(t), i = this.getVaryings(t), o = this.getVars(t), r = this.getCodes(t); e[t] = `${this.getSignature()} // <node_builder> // uniforms ${s} // attributes ${n} // varyings ${i} // vars ${o} // codes ${r} // </node_builder> ${this.shader[Bn(t)]} `; } this.vertexShader = e.vertex, this.fragmentShader = e.fragment; } build() { return super.build(!1), this._addSnippets(), this._addUniforms(), this._updateUniforms(), this.shader.vertexShader = this.vertexShader, this.shader.fragmentShader = this.fragmentShader, this; } _parseInclude(e, ...t) { for (const s of t) { const n = Ot(s), i = ha[s], o = Bn(e); this.shader[o] = this.shader[o].replaceAll(n, i); } } _sortSlotsToFlow() { for (const e of Kn) { const t = this.shader[Bn(e)], s = this.slots[e].sort((n, i) => t.indexOf(n.source) > t.indexOf(i.source) ? 1 : -1); for (const n of s) this.addFlow(e, n); } } _addSnippets() { for (const e of Kn) { for (const t of this.slots[e]) { const s = this.getFlowData( t /*, shaderStage*/ ), n = t.inclusionType, i = t.source, o = s.code + ` ` + t.target.replace("%RESULT%", s.result); n === "append" ? this.addCode(e, i, o) : n === "replace" ? this.replaceCode(e, i, o) : console.warn(`Inclusion type "${n}" not compatible.`); } this.addCode( e, "main() {", ` ` + this.flowCode[e] ); } } _addUniforms() { for (const e of Kn) for (const t of this.uniforms[e]) this.shader.uniforms[t.name] = t; } _updateUniforms() { tt.object = this.object, tt.renderer = this.renderer, tt.material = this.material, tt.scene = this.scene; for (const e of this.updateNodes) tt.updateNode(e); } } const qo = /* @__PURE__ */ new WeakMap(); tn.prototype.onBuild = function(A, e, t) { const s = this; if (s.isNodeMaterial === !0) { let n; try { n = new eA(A, t, e, s).build(), qo.set(s, n); } catch (i) { console.error("Material.prototype.onBuild: ", i); } } }; tn.prototype.onBeforeRender = function(A, e, t, s, n) { const i = qo.get(this); if (i !== void 0) { tt.material = this, tt.camera = t, tt.object = n, tt.renderer = A, tt.scene = e, tt.geometry = s; const o = i.updateNodes; if (o.length > 0) { A.state.useProgram(null); for (const r of o) tt.updateNode(r); } } }; var os = function() { var A = 0, e = document.createElement("div"); e.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000", e.addEventListener("click", function(l) { l.preventDefault(), s(++A % e.children.length); }, !1); function t(l) { return e.appendChild(l.dom), l; } function s(l) { for (var h = 0; h < e.children.length; h++) e.children[h].style.display = h === l ? "block" : "none"; A = l; } var n = (performance || Date).now(), i = n, o = 0, r = t(new os.Panel("FPS", "#0ff", "#002")), a = t(new os.Panel("MS", "#0f0", "#020")); if (self.performance && self.performance.memory) var c = t(new os.Panel("MB", "#f08", "#201")); return s(0), { REVISION: 16, dom: e, addPanel: t, showPanel: s, begin: function() { n = (performance || Date).now(); }, end: function() { o++; var l = (performance || Date).now(); if (a.update(l - n, 200), l >= i + 1e3 && (r.update(o * 1e3 / (l - i), 100), i = l, o = 0, c)) { var h = performance.memory; c.update(h.usedJSHeapSize / 1048576, h.jsHeapSizeLimit / 1048576); } return l; }, update: function() { n = this.end(); }, // Backwards Compatibility domElement: e, setMode: s }; }; os.Panel = function(A, e, t) { var s = 1 / 0, n = 0, i = Math.round, o = i(window.devicePixelRatio || 1), r = 80 * o, a = 48 * o, c = 3 * o, l = 2 * o, h = 3 * o, g = 15 * o, d = 74 * o, p = 30 * o, m = document.createElement("canvas"); m.width = r, m.height = a, m.style.cssText = "width:80px;height:48px"; var I = m.getContext("2d"); return I.font = "bold " + 9 * o + "px Helvetica,Arial,sans-serif", I.textBaseline = "top", I.fillStyle = t, I.fillRect(0, 0, r, a), I.fillStyle = e, I.fillText(A, c, l), I.fillRect(h, g, d, p), I.fillStyle = t, I.globalAlpha = 0.9, I.fillRect(h, g, d, p), { dom: m, update: function(b, B) { s = Math.min(s, b), n = Math.max(n, b), I.fillStyle = t, I.globalAlpha = 1, I.fillRect(0, 0, r, g), I.fillStyle = e, I.fillText(i(b) + " " + A + " (" + i(s) + "-" + i(n) + ")", c, l), I.drawImage(m, h + o, g, d - o, p, h, g, d - o, p), I.fillRect(h + d - o, g, o, p), I.fillStyle = t, I.globalAlpha = 0.9, I.fillRect(h + d - o, g, o, i((1 - b / B) * p)); } }; }; function th(A, e = 1e-4) { e = Math.max(e, Number.EPSILON); const t = {}, s = A.getIndex(), n = A.getAttribute("position"), i = s ? s.count : n.count; let o = 0; const r = Object.keys(A.attributes), a = {}, c = {}, l = [], h = ["getX", "getY", "getZ", "getW"], g = ["setX", "setY", "setZ", "setW"]; for (let B = 0, E = r.length; B < E; B++) { const w = r[B], Q = A.attributes[w]; a[w] = new Q.constructor( new Q.array.constructor(Q.count * Q.itemSize), Q.itemSize, Q.normalized ); const R = A.morphAttributes[w]; R && (c[w] || (c[w] = []), R.forEach((_, x) => { const v = new _.array.constructor(_.count * _.itemSize); c[w][x] = new _.constructor(v, _.itemSize, _.normalized); })); } const d = e * 0.5, p = Math.log10(1 / e), m = Math.pow(10, p), I = d * m; for (let B = 0; B < i; B++) { const E = s ? s.getX(B) : B; let w = ""; for (let Q = 0, R = r.length; Q < R; Q++) { const _ = r[Q], x = A.getAttribute(_), v = x.itemSize; for (let L = 0; L < v; L++) w += `${~~(x[h[L]](E) * m + I)},`; } if (w in t) l.push(t[w]); else { for (let Q = 0, R = r.length; Q < R; Q++) { const _ = r[Q], x = A.getAttribute(_), v = A.morphAttributes[_], L = x.itemSize, N = a[_], O = c[_]; for (let Z = 0; Z < L; Z++) { const U = h[Z], q = g[Z]; if (N[q](o, x[U](E)), v) for (let H = 0, K = v.length; H < K; H++) O[H][q](o, v[H][U](E)); } } t[w] = o, l.push(o), o++; } } const b = A.clone(); for (const B in A.attributes) { const E = a[B]; if (b.setAttribute(B, new E.constructor( E.array.slice(0, o * E.itemSize), E.itemSize, E.normalized )), B in c) for (let w = 0; w < c[B].length; w++) { const Q = c[B][w]; b.morphAttributes[B][w] = new Q.constructor( Q.array.slice(0, o * Q.itemSize), Q.itemSize, Q.normalized ); } } return b.setIndex(l), b; } function Mi(A, e) { if (e === ua) return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), A; if (e === Js || e === So) { let t = A.getIndex(); if (t === null) { const o = [], r = A.getAttribute("position"); if (r !== void 0) { for (let a = 0; a < r.count; a++) o.push(a); A.setIndex(o), t = A.getIndex(); } else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), A; } const s = t.count - 2, n = []; if (e === Js) for (let o = 1; o <= s; o++) n.push(t.getX(0)), n.push(t.getX(o)), n.push(t.getX(o + 1)); else for (let o = 0; o < s; o++) o % 2 === 0 ? (n.push(t.getX(o)), n.push(t.getX(o + 1)), n.push(t.getX(o + 2))) : (n.push(t.getX(o + 2)), n.push(t.getX(o + 1)), n.push(t.getX(o))); n.length / 3 !== s && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles."); const i = A.clone(); return i.setIndex(n), i.clearGroups(), i; } else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", e), A; } class zo extends Nt { constructor(e) { super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(t) { return new oA(t); }), this.register(function(t) { return new rA(t); }), this.register(function(t) { return new pA(t); }), this.register(function(t) { return new fA(t); }), this.register(function(t) { return new mA(t); }), this.register(function(t) { return new AA(t); }), this.register(function(t) { return new cA(t); }), this.register(function(t) { return new lA(t); }), this.register(function(t) { return new hA(t); }), this.register(function(t) { return new iA(t); }), this.register(function(t) { return new uA(t); }), this.register(function(t) { return new aA(t); }), this.register(function(t) { return new dA(t); }), this.register(function(t) { return new gA(t); }), this.register(function(t) { return new nA(t); }), this.register(function(t) { return new IA(t); }), this.register(function(t) { return new bA(t); }); } load(e, t, s, n) { const i = this; let o; if (this.resourcePath !== "") o = this.resourcePath; else if (this.path !== "") { const c = nn.extractUrlBase(e); o = nn.resolveURL(c, this.path); } else o = nn.extractUrlBase(e); this.manager.itemStart(e); const r = function(c) { n ? n(c) : console.error(c), i.manager.itemError(e), i.manager.itemEnd(e); }, a = new ft(this.manager); a.setPath(this.path), a.setResponseType("arraybuffer"), a.setRequestHeader(this.requestHeader), a.setWithCredentials(this.withCredentials), a.load(e, function(c) { try { i.parse(c, o, function(l) { t(l), i.manager.itemEnd(e); }, r); } catch (l) { r(l); } }, s, r); } setDRACOLoader(e) { return this.dracoLoader = e, this; } setKTX2Loader(e) { return this.ktx2Loader = e, this; } setMeshoptDecoder(e) { return this.meshoptDecoder = e, this; } register(e) { return this.pluginCallbacks.indexOf(e) === -1 && this.pluginCallbacks.push(e), this; } unregister(e) { return this.pluginCallbacks.indexOf(e) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e), 1), this; } parse(e, t, s, n) { let i, o; const r = {}, a = {}, c = new TextDecoder(); if (typeof e == "string") try { i = JSON.parse(e); } catch (h) { o = e, n && n(h); return; } else if (e instanceof ArrayBuffer) if (c.decode(new Uint8Array(e, 0, 4)) === Ko) { try { r[oe.KHR_BINARY_GLTF] = new EA(e); } catch (g) { n && n(g); return; } try { i = JSON.parse(r[oe.KHR_BINARY_GLTF].content); } catch (g) { o = r[oe.KHR_BINARY_GLTF].content, n && n(g); return; } } else try { i = JSON.parse(c.decode(e)); } catch (g) { o = c.decode(e), n && n(g); return; } else i = e; if (i.asset === void 0 || i.asset.version[0] < 2) { n && n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")); return; } this.json = i, this.jsonErrorData = o; const l = new MA(i, { path: t || this.resourcePath || "", crossOrigin: this.crossOrigin, requestHeader: this.requestHeader, manager: this.manager, ktx2Loader: this.ktx2Loader, meshoptDecoder: this.meshoptDecoder }); l.fileLoader.setRequestHeader(this.requestHeader); for (let h = 0; h < this.pluginCallbacks.length; h++) { const g = this.pluginCallbacks[h](l); g.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[g.name] = g, r[g.name] = !0; } if (i.extensionsUsed) for (let h = 0; h < i.extensionsUsed.length; ++h) { const g = i.extensionsUsed[h], d = i.extensionsRequired || []; switch (g) { case oe.KHR_MATERIALS_UNLIT: r[g] = new sA(); break; case oe.KHR_DRACO_MESH_COMPRESSION: r[g] = new CA(i, this.dracoLoader); break; case oe.KHR_TEXTURE_TRANSFORM: r[g] = new BA(); break; case oe.KHR_MESH_QUANTIZATION: r[g] = new wA(); break; default: d.indexOf(g) >= 0 && a[g] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + g + '".'); } } l.setExtensions(r), l.setPlugins(a), l.parse(s, n); } parseAsync(e, t) { const s = this; return new Promise(function(n, i) { s.parse(e, t, n, i); }); } } function tA() { let A = {}; return { get: function(e) { return A[e]; }, add: function(e, t) { A[e] = t; }, remove: function(e) { delete A[e]; }, removeAll: function() { A = {}; } }; } const oe = { 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 nA { constructor(e) { this.parser = e, this.name = oe.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} }; } _markDefs() { const e = this.parser, t = this.parser.json.nodes || []; for (let s = 0, n = t.length; s < n; s++) { const i = t[s]; i.extensions && i.extensions[this.name] && i.extensions[this.name].light !== void 0 && e._addNodeRef(this.cache, i.extensions[this.name].light); } } _loadLight(e) { const t = this.parser, s = "light:" + e; let n = t.cache.get(s); if (n) return n; const i = t.json, a = ((i.extensions && i.extensions[this.name] || {}).lights || [])[e]; let c; const l = new Se(16777215); a.color !== void 0 && l.setRGB(a.color[0], a.color[1], a.color[2], Ve); const h = a.range !== void 0 ? a.range : 0; switch (a.type) { case "directional": c = new To(l), c.target.position.set(0, 0, -1), c.add(c.target); break; case "point": c = new Ws(l), c.distance = h; break; case "spot": c = new vo(l), c.distance = h, a.spot = a.spot || {}, a.spot.innerConeAngle = a.spot.innerConeAngle !== void 0 ? a.spot.innerConeAngle : 0, a.spot.outerConeAngle = a.spot.outerConeAngle !== void 0 ? a.spot.outerConeAngle : Math.PI / 4, c.angle = a.spot.outerConeAngle, c.penumbra = 1 - a.spot.innerConeAngle / a.spot.outerConeAngle, c.target.position.set(0, 0, -1), c.add(c.target); break; default: throw new Error("THREE.GLTFLoader: Unexpected light type: " + a.type); } return c.position.set(0, 0, 0), c.decay = 2, kt(c, a), a.intensity !== void 0 && (c.intensity = a.intensity), c.name = t.createUniqueName(a.name || "light_" + e), n = Promise.resolve(c), t.cache.add(s, n), n; } getDependency(e, t) { if (e === "light") return this._loadLight(t); } createNodeAttachment(e) { const t = this, s = this.parser, i = s.json.nodes[e], r = (i.extensions && i.extensions[this.name] || {}).light; return r === void 0 ? null : this._loadLight(r).then(function(a) { return s._getNodeRef(t.cache, r, a); }); } } let sA = class { constructor() { this.name = oe.KHR_MATERIALS_UNLIT; } getMaterialType() { return Qt; } extendParams(e, t, s) { const n = []; e.color = new Se(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], Ve), e.opacity = o[3]; } i.baseColorTexture !== void 0 && n.push(s.assignTexture(e, "map", i.baseColorTexture, ge)); } return Promise.all(n); } }, iA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_EMISSIVE_STRENGTH; } extendMaterialParams(e, t) { const n = this.parser.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = n.extensions[this.name].emissiveStrength; return i !== void 0 && (t.emissiveIntensity = i), Promise.resolve(); } }, oA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_CLEARCOAT; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const s = this.parser, n = s.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = [], o = n.extensions[this.name]; if (o.clearcoatFactor !== void 0 && (t.clearcoat = o.clearcoatFactor), o.clearcoatTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatMap", o.clearcoatTexture)), o.clearcoatRoughnessFactor !== void 0 && (t.clearcoatRoughness = o.clearcoatRoughnessFactor), o.clearcoatRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "clearcoatRoughnessMap", o.clearcoatRoughnessTexture)), o.clearcoatNormalTexture !== void 0 && (i.push(s.assignTexture(t, "clearcoatNormalMap", o.clearcoatNormalTexture)), o.clearcoatNormalTexture.scale !== void 0)) { const r = o.clearcoatNormalTexture.scale; t.clearcoatNormalScale = new Le(r, r); } return Promise.all(i); } }, rA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_DISPERSION; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const n = this.parser.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = n.extensions[this.name]; return t.dispersion = i.dispersion !== void 0 ? i.dispersion : 0, Promise.resolve(); } }, aA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_IRIDESCENCE; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const s = this.parser, n = s.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = [], o = n.extensions[this.name]; return o.iridescenceFactor !== void 0 && (t.iridescence = o.iridescenceFactor), o.iridescenceTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceMap", o.iridescenceTexture)), o.iridescenceIor !== void 0 && (t.iridescenceIOR = o.iridescenceIor), t.iridescenceThicknessRange === void 0 && (t.iridescenceThicknessRange = [100, 400]), o.iridescenceThicknessMinimum !== void 0 && (t.iridescenceThicknessRange[0] = o.iridescenceThicknessMinimum), o.iridescenceThicknessMaximum !== void 0 && (t.iridescenceThicknessRange[1] = o.iridescenceThicknessMaximum), o.iridescenceThicknessTexture !== void 0 && i.push(s.assignTexture(t, "iridescenceThicknessMap", o.iridescenceThicknessTexture)), Promise.all(i); } }, AA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_SHEEN; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const s = this.parser, n = s.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = []; t.sheenColor = new Se(0, 0, 0), t.sheenRoughness = 0, t.sheen = 1; const o = n.extensions[this.name]; if (o.sheenColorFactor !== void 0) { const r = o.sheenColorFactor; t.sheenColor.setRGB(r[0], r[1], r[2], Ve); } return o.sheenRoughnessFactor !== void 0 && (t.sheenRoughness = o.sheenRoughnessFactor), o.sheenColorTexture !== void 0 && i.push(s.assignTexture(t, "sheenColorMap", o.sheenColorTexture, ge)), o.sheenRoughnessTexture !== void 0 && i.push(s.assignTexture(t, "sheenRoughnessMap", o.sheenRoughnessTexture)), Promise.all(i); } }, cA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_TRANSMISSION; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const s = this.parser, n = s.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = [], o = n.extensions[this.name]; return o.transmissionFactor !== void 0 && (t.transmission = o.transmissionFactor), o.transmissionTexture !== void 0 && i.push(s.assignTexture(t, "transmissionMap", o.transmissionTexture)), Promise.all(i); } }, lA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_VOLUME; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const s = this.parser, n = s.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = [], o = n.extensions[this.name]; t.thickness = o.thicknessFactor !== void 0 ? o.thicknessFactor : 0, o.thicknessTexture !== void 0 && i.push(s.assignTexture(t, "thicknessMap", o.thicknessTexture)), t.attenuationDistance = o.attenuationDistance || 1 / 0; const r = o.attenuationColor || [1, 1, 1]; return t.attenuationColor = new Se().setRGB(r[0], r[1], r[2], Ve), Promise.all(i); } }, hA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_IOR; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const n = this.parser.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = n.extensions[this.name]; return t.ior = i.ior !== void 0 ? i.ior : 1.5, Promise.resolve(); } }, uA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_SPECULAR; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const s = this.parser, n = s.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = [], o = n.extensions[this.name]; t.specularIntensity = o.specularFactor !== void 0 ? o.specularFactor : 1, o.specularTexture !== void 0 && i.push(s.assignTexture(t, "specularIntensityMap", o.specularTexture)); const r = o.specularColorFactor || [1, 1, 1]; return t.specularColor = new Se().setRGB(r[0], r[1], r[2], Ve), o.specularColorTexture !== void 0 && i.push(s.assignTexture(t, "specularColorMap", o.specularColorTexture, ge)), Promise.all(i); } }, gA = class { constructor(e) { this.parser = e, this.name = oe.EXT_MATERIALS_BUMP; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const s = this.parser, n = s.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = [], o = n.extensions[this.name]; return t.bumpScale = o.bumpFactor !== void 0 ? o.bumpFactor : 1, o.bumpTexture !== void 0 && i.push(s.assignTexture(t, "bumpMap", o.bumpTexture)), Promise.all(i); } }, dA = class { constructor(e) { this.parser = e, this.name = oe.KHR_MATERIALS_ANISOTROPY; } getMaterialType(e) { const s = this.parser.json.materials[e]; return !s.extensions || !s.extensions[this.name] ? null : Tt; } extendMaterialParams(e, t) { const s = this.parser, n = s.json.materials[e]; if (!n.extensions || !n.extensions[this.name]) return Promise.resolve(); const i = [], o = n.extensions[this.name]; return o.anisotropyStrength !== void 0 && (t.anisotropy = o.anisotropyStrength), o.anisotropyRotation !== void 0 && (t.anisotropyRotation = o.anisotropyRotation), o.anisotropyTexture !== void 0 && i.push(s.assignTexture(t, "anisotropyMap", o.anisotropyTexture)), Promise.all(i); } }; class pA { constructor(e) { this.parser = e, this.name = oe.KHR_TEXTURE_BASISU; } loadTexture(e) { const t = this.parser, s = t.json, n = s.textures[e]; if (!n.extensions || !n.extensions[this.name]) return null; const i = n.extensions[this.name], o = t.options.ktx2Loader; if (!o) { if (s.extensionsRequired && s.extensionsRequired.indexOf(this.name) >= 0) throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures"); return null; } return t.loadTextureImage(e, i.source, o); } } class fA { constructor(e) { this.parser = e, this.name = oe.EXT_TEXTURE_WEBP, this.isSupported = null; } loadTexture(e) { const t = this.name, s = this.parser, n = s.json, i = n.textures[e]; if (!i.extensions || !i.extensions[t]) return null; const o = i.extensions[t], r = n.images[o.source]; let a = s.textureLoader; if (r.uri) { const c = s.options.manager.getHandler(r.uri); c !== null && (a = c); } return this.detectSupport().then(function(c) { if (c) return s.loadTextureImage(e, o.source, a); if (n.extensionsRequired && n.extensionsRequired.indexOf(t) >= 0) throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported."); return s.loadTexture(e); }); } detectSupport() { return this.isSupported || (this.isSupported = new Promise(function(e) { const t = new Image(); t.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA", t.onload = t.onerror = function() { e(t.height === 1); }; })), this.isSupported; } } class mA { constructor(e) { this.parser = e, this.name = oe.EXT_TEXTURE_AVIF, this.isSupported = null; } loadTexture(e) { const t = this.name, s = this.parser, n = s.json, i = n.textures[e]; if (!i.extensions || !i.extensions[t]) return null; const o = i.extensions[t], r = n.images[o.source]; let a = s.textureLoader; if (r.uri) { const c = s.options.manager.getHandler(r.uri); c !== null && (a = c); } return this.detectSupport().then(function(c) { if (c) return s.loadTextureImage(e, o.source, a); if (n.extensionsRequired && n.extensionsRequired.indexOf(t) >= 0) throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported."); return s.loadTexture(e); }); } detectSupport() { return this.isSupported || (this.isSupported = new Promise(function(e) { const t = new Image(); t.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=", t.onload = t.onerror = function() { e(t.height === 1); }; })), this.isSupported; } } class IA { constructor(e) { this.name = oe.EXT_MESHOPT_COMPRESSION, this.parser = e; } loadBufferView(e) { const t = this.parser.json, s = t.bufferViews[e]; if (s.extensions && s.extensions[this.name]) { const n = s.extensions[this.name], i = this.parser.getDependency("buffer", n.buffer), o = this.parser.options.meshoptDecoder; if (!o || !o.supported) { if (t.extensionsRequired && t.extensionsRequired.indexOf(this.name) >= 0) throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files"); return null; } return i.then(function(r) { const a = n.byteOffset || 0, c = n.byteLength || 0, l = n.count, h = n.byteStride, g = new Uint8Array(r, a, c); return o.decodeGltfBufferAsync ? o.decodeGltfBufferAsync(l, h, g, n.mode, n.filter).then(function(d) { return d.buffer; }) : o.ready.then(function() { const d = new ArrayBuffer(l * h); return o.decodeGltfBuffer(new Uint8Array(d), l, h, g, n.mode, n.filter), d; }); }); } else return null; } } let bA = class { constructor(e) { this.name = oe.EXT_MESH_GPU_INSTANCING, this.parser = e; } createNodeMesh(e) { const t = this.parser.json, s = t.nodes[e]; if (!s.extensions || !s.extensions[this.name] || s.mesh === void 0) return null; const n = t.meshes[s.mesh]; for (const c of n.primitives) if (c.mode !== ht.TRIANGLES && c.mode !== ht.TRIANGLE_STRIP && c.mode !== ht.TRIANGLE_FAN && c.mode !== void 0) return null; const o = s.extensions[this.name].attributes, r = [], a = {}; for (const c in o) r.push(this.parser.getDependency("accessor", o[c]).then((l) => (a[c] = l, a[c]))); return r.length < 1 ? null : (r.push(this.parser.createNodeMesh(e)), Promise.all(r).then((c) => { const l = c.pop(), h = l.isGroup ? l.children : [l], g = c[0].count, d = []; for (const p of h) { const m = new ue(), I = new P(), b = new ve(), B = new P(1, 1, 1), E = new ga(p.geometry, p.material, g); for (let w = 0; w < g; w++) a.TRANSLATION && I.fromBufferAttribute(a.TRANSLATION, w), a.ROTATION && b.fromBufferAttribute(a.ROTATION, w), a.SCALE && B.fromBufferAttribute(a.SCALE, w), E.setMatrixAt(w, m.compose(I, b, B)); for (const w in a) if (w === "_COLOR_0") { const Q = a[w]; E.instanceColor = new da(Q.array, Q.itemSize, Q.normalized); } else w !== "TRANSLATION" && w !== "ROTATION" && w !== "SCALE" && p.geometry.setAttribute(w, a[w]); xt.prototype.copy.call(E, p), this.parser.assignFinalMaterial(E), d.push(E); } return l.isGroup ? (l.clear(), l.add(...d), l) : d[0]; })); } }; const Ko = "glTF", wn = 12, ki = { JSON: 1313821514, BIN: 5130562 }; class EA { constructor(e) { this.name = oe.KHR_BINARY_GLTF, this.content = null, this.body = null; const t = new DataView(e, 0, wn), s = new TextDecoder(); if (this.header = { magic: s.decode(new Uint8Array(e.slice(0, 4))), version: t.getUint32(4, !0), length: t.getUint32(8, !0) }, this.header.magic !== Ko) throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header."); if (this.header.version < 2) throw new Error("THREE.GLTFLoader: Legacy binary file detected."); const n = this.header.length - wn, i = new DataView(e, wn); let o = 0; for (; o < n; ) { const r = i.getUint32(o, !0); o += 4; const a = i.getUint32(o, !0); if (o += 4, a === ki.JSON) { const c = new Uint8Array(e, wn + o, r); this.content = s.decode(c); } else if (a === ki.BIN) { const c = wn + o; this.body = e.slice(c, c + r); } o += r; } if (this.content === null) throw new Error("THREE.GLTFLoader: JSON content not found."); } } class CA { constructor(e, t) { if (!t) throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided."); this.name = oe.KHR_DRACO_MESH_COMPRESSION, this.json = e, this.dracoLoader = t, this.dracoLoader.preload(); } decodePrimitive(e, t) { const s = this.json, n = this.dracoLoader, i = e.extensions[this.name].bufferView, o = e.extensions[this.name].attributes, r = {}, a = {}, c = {}; for (const l in o) { const h = ei[l] || l.toLowerCase(); r[h] = o[l]; } for (const l in e.attributes) { const h = ei[l] || l.toLowerCase(); if (o[l] !== void 0) { const g = s.accessors[e.attributes[l]], d = In[g.componentType]; c[h] = d.name, a[h] = g.normalized === !0; } } return t.getDependency("bufferView", i).then(function(l) { return new Promise(function(h, g) { n.decodeDracoFile(l, function(d) { for (const p in d.attributes) { const m = d.attributes[p], I = a[p]; I !== void 0 && (m.normalized = I); } h(d); }, r, c, Ve, g); }); }); } } class BA { constructor() { this.name = oe.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 wA { constructor() { this.name = oe.KHR_MESH_QUANTIZATION; } } class Yo extends Ia { constructor(e, t, s, n) { super(e, t, s, n); } copySampleValue_(e) { const t = this.resultBuffer, s = this.sampleValues, n = this.valueSize, i = e * n * 3 + n; for (let o = 0; o !== n; o++) t[o] = s[i + o]; return t; } interpolate_(e, t, s, n) { const i = this.resultBuffer, o = this.sampleValues, r = this.valueSize, a = r * 2, c = r * 3, l = n - t, h = (s - t) / l, g = h * h, d = g * h, p = e * c, m = p - c, I = -2 * d + 3 * g, b = d - g, B = 1 - I, E = b - g + h; for (let w = 0; w !== r; w++) { const Q = o[m + w + r], R = o[m + w + a] * l, _ = o[p + w + r], x = o[p + w] * l; i[w] = B * Q + E * R + I * _ + b * x; } return i; } } const yA = new ve(); class QA extends Yo { interpolate_(e, t, s, n) { const i = super.interpolate_(e, t, s, n); return yA.fromArray(i).normalize().toArray(i), i; } } const ht = { POINTS: 0, LINES: 1, LINE_LOOP: 2, LINE_STRIP: 3, TRIANGLES: 4, TRIANGLE_STRIP: 5, TRIANGLE_FAN: 6 }, In = { 5120: Int8Array, 5121: Uint8Array, 5122: Int16Array, 5123: Uint16Array, 5125: Uint32Array, 5126: Float32Array }, Fi = { 9728: Mo, 9729: mt, 9984: Do, 9985: _o, 9986: Ro, 9987: ps }, Li = { 33071: As, 33648: ko, 10497: rn }, Cs = { S