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,215 lines (1,205 loc) • 480 kB
import { Mesh as q, SphereGeometry as ui, Vector3 as P, MeshBasicMaterial as Qt, Node as fa, PerspectiveCamera as gs, NodeFrame as Ia, NodeBuilder as ma, GLSLNodeParser as Ea, ShaderLib as wt, UniformsUtils as gi, UniformsLib as Un, normalView as ba, defaultShaderStages as Yn, ShaderChunk as Ca, Material as en, TrianglesDrawMode as Ba, TriangleFanDrawMode as qs, TriangleStripDrawMode as Do, Matrix4 as ue, Loader as kt, LoaderUtils as tn, FileLoader as It, MeshPhysicalMaterial as Tt, Vector2 as Le, Color as Se, LinearSRGBColorSpace as Xe, SRGBColorSpace as ge, SpotLight as Ro, PointLight as zs, DirectionalLight as _o, InstancedMesh as wa, Quaternion as Te, InstancedBufferAttribute as ya, Object3D as xt, TextureLoader as di, ImageBitmapLoader as Qa, BufferAttribute as st, InterleavedBuffer as xa, LinearMipmapLinearFilter as jn, NearestMipmapLinearFilter as Mo, LinearMipmapNearestFilter as Fo, NearestMipmapNearestFilter as pi, LinearFilter as rt, NearestFilter as cs, RepeatWrapping as on, MirroredRepeatWrapping as ko, ClampToEdgeWrapping as ls, PointsMaterial as _n, LineBasicMaterial as Ft, MeshStandardMaterial as fi, DoubleSide as Ii, PropertyBinding as Lt, BufferGeometry as ut, SkinnedMesh as Lo, LineSegments as hs, Line as pt, LineLoop as Sa, Points as is, Group as nn, MathUtils as Qe, OrthographicCamera as No, Skeleton as Uo, AnimationClip as Go, Bone as Ys, InterpolateDiscrete as Po, InterpolateLinear as mi, InterleavedBufferAttribute as $t, Texture as Ks, VectorKeyframeTrack as Js, NumberKeyframeTrack as Vs, QuaternionKeyframeTrack as Ws, ColorManagement as Ve, FrontSide as Oo, Interpolant as Ta, Box3 as ds, Sphere as Ei, RGBA_S3TC_DXT1_Format as Xs, RGB_PVRTC_4BPPV1_Format as va, RGB_ETC2_Format as Ho, RGB_ETC1_Format as Da, RGBA_S3TC_DXT5_Format as Zs, RGBA_PVRTC_4BPPV1_Format as Ra, RGBA_ETC2_EAC_Format as jo, RGBA_BPTC_Format as $s, RGB_BPTC_UNSIGNED_Format as _a, RGBA_ASTC_4x4_Format as os, RGBAFormat as zt, FloatType as mt, HalfFloatType as We, UnsignedByteType as dt, CompressedCubeTexture as Ma, CompressedArrayTexture as Fa, CompressedTexture as Gn, NoColorSpace as us, RGBA_S3TC_DXT3_Format as Mi, RGB_S3TC_DXT1_Format as Fi, RGBA_ASTC_6x6_Format as ki, RGBFormat as ei, RedFormat as gn, RGFormat as Mn, UnsignedInt101111Type as qo, UnsignedInt5999Type as zo, DataTexture as ka, Data3DTexture as La, ExtrudeGeometry as Na, ShapePath as Ua, Raycaster as bi, CylinderGeometry as Ye, BoxGeometry as je, Float32BufferAttribute as Fe, OctahedronGeometry as Kn, TorusGeometry as bn, Euler as qt, Controls as Yo, PlaneGeometry as Ci, DataTextureLoader as Ko, DataUtils as dn, Vector4 as Nt, Curve as Ga, MeshPhongMaterial as Pn, MeshLambertMaterial as Pa, EquirectangularReflectionMapping as Oa, AmbientLight as Ha, Uint16BufferAttribute as ja, Matrix3 as Jo, ShapeUtils as qa, DefaultLoadingManager as za, Ray as Ya, Plane as Ka, MOUSE as fn, TOUCH as pn, Spherical as Li, ShaderMaterial as Vo, Uniform$1 as Ja, Scene as ti, WebGLRenderer as Va, CanvasTexture as Wo, REVISION as Wa, Source as Xa, InstancedBufferGeometry as Za, InstancedInterleavedBuffer as ni, WireframeGeometry as $a, Line3 as eA } from "./three.js"; class gh extends q { 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 ui(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 Be extends fa { 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 nt = new Ia(); nt.camera = new gs(); const Ni = { LineBasicNodeMaterial: wt.basic, MeshBasicNodeMaterial: wt.basic, PointsNodeMaterial: wt.points, MeshStandardNodeMaterial: wt.standard, MeshPhysicalNodeMaterial: wt.physical, MeshPhongNodeMaterial: wt.phong }, tA = { atan2: "atan" }, nA = { low: "lowp", medium: "mediump", high: "highp" }; function Pt(A) { return `#include <${A}>`; } function Cn(A) { return `${A}Shader`; } class sA extends ma { constructor(e, t, s, n = null) { super(e, t, new Ea(), 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 tA[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"), Ni[t] !== void 0) { const s = Ni[t], n = this.shader; n.vertexShader = s.vertexShader, n.fragmentShader = s.fragmentShader, n.uniforms = gi.merge([s.uniforms, Un.lights]); } } _parseObject() { const { material: e, renderer: t } = this; this.addSlot("fragment", new Be({ node: ba, nodeType: "vec3", source: "void main() {", target: "vec3 TransformedNormalView = %RESULT%;", inclusionType: "append" })), t.toneMappingNode && t.toneMappingNode.isNode === !0 && this.addSlot("fragment", new Be({ node: e.colorNode, nodeType: "vec4", source: Pt("tonemapping_fragment"), target: "" })), e.colorNode && e.colorNode.isNode && this.addSlot("fragment", new Be({ 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 Be({ node: e.opacityNode, nodeType: "float", source: Pt("alphatest_fragment"), target: "diffuseColor.a = %RESULT%;", inclusionType: "append" })), e.normalNode && e.normalNode.isNode && this.addSlot("fragment", new Be({ node: e.normalNode, nodeType: "vec3", source: Pt("normal_fragment_begin"), target: "normal = %RESULT%;", inclusionType: "append" })), e.emissiveNode && e.emissiveNode.isNode && this.addSlot("fragment", new Be({ node: e.emissiveNode, nodeType: "vec3", source: Pt("emissivemap_fragment"), target: "totalEmissiveRadiance = %RESULT%;", inclusionType: "append" })), e.isMeshStandardNodeMaterial && (e.metalnessNode && e.metalnessNode.isNode && this.addSlot("fragment", new Be({ node: e.metalnessNode, nodeType: "float", source: Pt("metalnessmap_fragment"), target: "metalnessFactor = %RESULT%;", inclusionType: "append" })), e.roughnessNode && e.roughnessNode.isNode && this.addSlot("fragment", new Be({ node: e.roughnessNode, nodeType: "float", source: Pt("roughnessmap_fragment"), target: "roughnessFactor = %RESULT%;", inclusionType: "append" })), e.isMeshPhysicalNodeMaterial && (e.clearcoatNode && e.clearcoatNode.isNode ? (this.addSlot("fragment", new Be({ node: e.clearcoatNode, nodeType: "float", source: "material.clearcoat = clearcoat;", target: "material.clearcoat = %RESULT%;" })), e.clearcoatRoughnessNode && e.clearcoatRoughnessNode.isNode && this.addSlot("fragment", new Be({ node: e.clearcoatRoughnessNode, nodeType: "float", source: "material.clearcoatRoughness = clearcoatRoughness;", target: "material.clearcoatRoughness = %RESULT%;" })), e.clearcoatNormalNode && e.clearcoatNormalNode.isNode && this.addSlot("fragment", new Be({ 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 Be({ node: e.sheenNode, nodeType: "vec3", source: "material.sheenColor = sheenColor;", target: "material.sheenColor = %RESULT%;" })), e.sheenRoughnessNode && e.sheenRoughnessNode.isNode && this.addSlot("fragment", new Be({ 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 Be({ node: e.iridescenceNode, nodeType: "float", source: "material.iridescence = iridescence;", target: "material.iridescence = %RESULT%;" })), e.iridescenceIORNode && e.iridescenceIORNode.isNode && this.addSlot("fragment", new Be({ node: e.iridescenceIORNode, nodeType: "float", source: "material.iridescenceIOR = iridescenceIOR;", target: "material.iridescenceIOR = %RESULT%;" })), e.iridescenceThicknessNode && e.iridescenceThicknessNode.isNode && this.addSlot("fragment", new Be({ 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 Be({ node: e.iorNode, nodeType: "float", source: "material.ior = ior;", target: "material.ior = %RESULT%;" })), e.specularColorNode && e.specularColorNode.isNode && this.addSlot("fragment", new Be({ node: e.specularColorNode, nodeType: "vec3", source: "vec3 specularColorFactor = specularColor;", target: "vec3 specularColorFactor = %RESULT%;" })), e.specularIntensityNode && e.specularIntensityNode.isNode && this.addSlot("fragment", new Be({ node: e.specularIntensityNode, nodeType: "float", source: "float specularIntensityFactor = specularIntensity;", target: "float specularIntensityFactor = %RESULT%;" })), e.transmissionNode && e.transmissionNode.isNode ? (this.addSlot("fragment", new Be({ node: e.transmissionNode, nodeType: "float", source: "material.transmission = transmission;", target: "material.transmission = %RESULT%;" })), e.thicknessNode && e.thicknessNode.isNode && this.addSlot("fragment", new Be({ node: e.thicknessNode, nodeType: "float", source: "material.thickness = thickness;", target: "material.thickness = %RESULT%;" })), e.attenuationDistanceNode && e.attenuationDistanceNode.isNode && this.addSlot("fragment", new Be({ node: e.attenuationDistanceNode, nodeType: "float", source: "material.attenuationDistance = attenuationDistance;", target: "material.attenuationDistance = %RESULT%;" })), e.attenuationColorNode && e.attenuationColorNode.isNode && this.addSlot("fragment", new Be({ 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 Be({ node: e.positionNode, nodeType: "vec3", source: Pt("begin_vertex"), target: "transformed = %RESULT%;", inclusionType: "append" })), e.sizeNode && e.sizeNode.isNode && this.addSlot("vertex", new Be({ 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 " + nA[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 = Cn(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 = Cn(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 Yn) { const s = this.getUniforms(t), n = this.getAttributes(t), i = this.getVaryings(t); let o = this.getVars(t); o = o.replace("mat4 modelViewMatrix;", ""); const r = this.getCodes(t); e[t] = `${this.getSignature()} // <node_builder> // uniforms ${s} // attributes ${n} // varyings ${i} // vars ${o} // codes ${r} // </node_builder> ${this.shader[Cn(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 = Pt(s), i = Ca[s], o = Cn(e); this.shader[o] = this.shader[o].replaceAll(n, i); } } _sortSlotsToFlow() { for (const e of Yn) { const t = this.shader[Cn(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 Yn) { 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 Yn) for (const t of this.uniforms[e]) this.shader.uniforms[t.name] = t; } _updateUniforms() { nt.object = this.object, nt.renderer = this.renderer, nt.material = this.material, nt.scene = this.scene; for (const e of this.updateNodes) nt.updateNode(e); } } const Xo = /* @__PURE__ */ new WeakMap(); en.prototype.onBuild = function(A, e, t) { const s = this; if (s.isNodeMaterial === !0) { let n; try { n = new sA(A, t, e, s).build(), Xo.set(s, n); } catch (i) { console.error("Material.prototype.onBuild: ", i); } } }; en.prototype.onBeforeRender = function(A, e, t, s, n) { const i = Xo.get(this); if (i !== void 0) { nt.material = this, nt.camera = t, nt.object = n, nt.renderer = A, nt.scene = e, nt.geometry = s; const o = i.updateNodes; if (o.length > 0) { A.state.useProgram(null); for (const r of o) nt.updateNode(r); } } }; var rs = 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 rs.Panel("FPS", "#0ff", "#002")), a = t(new rs.Panel("MS", "#0f0", "#020")); if (self.performance && self.performance.memory) var c = t(new rs.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 }; }; rs.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, f = 30 * o, I = document.createElement("canvas"); I.width = r, I.height = a, I.style.cssText = "width:80px;height:48px"; var m = I.getContext("2d"); return m.font = "bold " + 9 * o + "px Helvetica,Arial,sans-serif", m.textBaseline = "top", m.fillStyle = t, m.fillRect(0, 0, r, a), m.fillStyle = e, m.fillText(A, c, l), m.fillRect(h, g, d, f), m.fillStyle = t, m.globalAlpha = 0.9, m.fillRect(h, g, d, f), { dom: I, update: function(C, w) { s = Math.min(s, C), n = Math.max(n, C), m.fillStyle = t, m.globalAlpha = 1, m.fillRect(0, 0, r, g), m.fillStyle = e, m.fillText(i(C) + " " + A + " (" + i(s) + "-" + i(n) + ")", c, l), m.drawImage(I, h + o, g, d - o, f, h, g, d - o, f), m.fillRect(h + d - o, g, o, f), m.fillStyle = t, m.globalAlpha = 0.9, m.fillRect(h + d - o, g, o, i((1 - C / w) * f)); } }; }; function dh(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 w = 0, b = r.length; w < b; w++) { const B = r[w], Q = A.attributes[B]; a[B] = new Q.constructor( new Q.array.constructor(Q.count * Q.itemSize), Q.itemSize, Q.normalized ); const D = A.morphAttributes[B]; D && (c[B] || (c[B] = []), D.forEach((R, x) => { const T = new R.array.constructor(R.count * R.itemSize); c[B][x] = new R.constructor(T, R.itemSize, R.normalized); })); } const d = e * 0.5, f = Math.log10(1 / e), I = Math.pow(10, f), m = d * I; for (let w = 0; w < i; w++) { const b = s ? s.getX(w) : w; let B = ""; for (let Q = 0, D = r.length; Q < D; Q++) { const R = r[Q], x = A.getAttribute(R), T = x.itemSize; for (let U = 0; U < T; U++) B += `${~~(x[h[U]](b) * I + m)},`; } if (B in t) l.push(t[B]); else { for (let Q = 0, D = r.length; Q < D; Q++) { const R = r[Q], x = A.getAttribute(R), T = A.morphAttributes[R], U = x.itemSize, L = a[R], H = c[R]; for (let Z = 0; Z < U; Z++) { const N = h[Z], K = g[Z]; if (L[K](o, x[N](b)), T) for (let O = 0, $ = T.length; O < $; O++) H[O][K](o, T[O][N](b)); } } t[B] = o, l.push(o), o++; } } const C = A.clone(); for (const w in A.attributes) { const b = a[w]; if (C.setAttribute(w, new b.constructor( b.array.slice(0, o * b.itemSize), b.itemSize, b.normalized )), w in c) for (let B = 0; B < c[w].length; B++) { const Q = c[w][B]; C.morphAttributes[w][B] = new Q.constructor( Q.array.slice(0, o * Q.itemSize), Q.itemSize, Q.normalized ); } } return C.setIndex(l), C; } function Ui(A, e) { if (e === Ba) return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), A; if (e === qs || e === Do) { 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 === qs) 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 kt { constructor(e) { super(e), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(t) { return new AA(t); }), this.register(function(t) { return new cA(t); }), this.register(function(t) { return new mA(t); }), this.register(function(t) { return new EA(t); }), this.register(function(t) { return new bA(t); }), this.register(function(t) { return new hA(t); }), this.register(function(t) { return new uA(t); }), this.register(function(t) { return new gA(t); }), this.register(function(t) { return new dA(t); }), this.register(function(t) { return new aA(t); }), this.register(function(t) { return new pA(t); }), this.register(function(t) { return new lA(t); }), this.register(function(t) { return new IA(t); }), this.register(function(t) { return new fA(t); }), this.register(function(t) { return new oA(t); }), this.register(function(t) { return new CA(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 = tn.extractUrlBase(e); o = tn.resolveURL(c, this.path); } else o = tn.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 It(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)) === $o) { try { r[ae.KHR_BINARY_GLTF] = new wA(e); } catch (g) { n && n(g); return; } try { i = JSON.parse(r[ae.KHR_BINARY_GLTF].content); } catch (g) { o = r[ae.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 LA(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 ae.KHR_MATERIALS_UNLIT: r[g] = new rA(); break; case ae.KHR_DRACO_MESH_COMPRESSION: r[g] = new yA(i, this.dracoLoader); break; case ae.KHR_TEXTURE_TRANSFORM: r[g] = new QA(); break; case ae.KHR_MESH_QUANTIZATION: r[g] = new xA(); 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 iA() { 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 ae = { 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 oA { constructor(e) { this.parser = e, this.name = ae.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], Xe); const h = a.range !== void 0 ? a.range : 0; switch (a.type) { case "directional": c = new _o(l), c.target.position.set(0, 0, -1), c.add(c.target); break; case "point": c = new zs(l), c.distance = h; break; case "spot": c = new Ro(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, Mt(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 rA = class { constructor() { this.name = ae.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], Xe), e.opacity = o[3]; } i.baseColorTexture !== void 0 && n.push(s.assignTexture(e, "map", i.baseColorTexture, ge)); } return Promise.all(n); } }, aA = class { constructor(e) { this.parser = e, this.name = ae.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(); } }, AA = class { constructor(e) { this.parser = e, this.name = ae.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); } }, cA = class { constructor(e) { this.parser = e, this.name = ae.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(); } }, lA = class { constructor(e) { this.parser = e, this.name = ae.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); } }, hA = class { constructor(e) { this.parser = e, this.name = ae.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], Xe); } 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); } }, uA = class { constructor(e) { this.parser = e, this.name = ae.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); } }, gA = class { constructor(e) { this.parser = e, this.name = ae.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], Xe), Promise.all(i); } }, dA = class { constructor(e) { this.parser = e, this.name = ae.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(); } }, pA = class { constructor(e) { this.parser = e, this.name = ae.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], Xe), o.specularColorTexture !== void 0 && i.push(s.assignTexture(t, "specularColorMap", o.specularColorTexture, ge)), Promise.all(i); } }, fA = class { constructor(e) { this.parser = e, this.name = ae.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); } }, IA = class { constructor(e) { this.parser = e, this.name = ae.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 mA { constructor(e) { this.parser = e, this.name = ae.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 EA { constructor(e) { this.parser = e, this.name = ae.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 bA { constructor(e) { this.parser = e, this.name = ae.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 CA { constructor(e) { this.name = ae.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 = ae.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 f of h) { const I = new ue(), m = new P(), C = new Te(), w = new P(1, 1, 1), b = new wa(f.geometry, f.material, g); for (let B = 0; B < g; B++) a.TRANSLATION && m.fromBufferAttribute(a.TRANSLATION, B), a.ROTATION && C.fromBufferAttribute(a.ROTATION, B), a.SCALE && w.fromBufferAttribute(a.SCALE, B), b.setMatrixAt(B, I.compose(m, C, w)); for (const B in a) if (B === "_COLOR_0") { const Q = a[B]; b.instanceColor = new ya(Q.array, Q.itemSize, Q.normalized); } else B !== "TRANSLATION" && B !== "ROTATION" && B !== "SCALE" && f.geometry.setAttribute(B, a[B]); xt.prototype.copy.call(b, f), this.parser.assignFinalMaterial(b), d.push(b); } return l.isGroup ? (l.clear(), l.add(...d), l) : d[0]; })); } }; const $o = "glTF", Bn = 12, Gi = { JSON: 1313821514, BIN: 5130562 }; class wA { constructor(e) { this.name = ae.KHR_BINARY_GLTF, this.content = null, this.body = null; const t = new DataView(e, 0, Bn), 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 !== $o) 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 - Bn, i = new DataView(e, Bn); let o = 0; for (; o < n; ) { const r = i.getUint32(o, !0); o += 4; const a = i.getUint32(o, !0); if (o += 4, a === Gi.JSON) { const c = new Uint8Array(e, Bn + o, r); this.content = s.decode(c); } else if (a === Gi.BIN) { const c = Bn + o; this.body = e.slice(c, c + r); } o += r; } if (this.content === null) throw new Error("THREE.GLTFLoader: JSON content not found."); } } class yA { constructor(e, t) { if (!t) throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided."); this.name = ae.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 = si[l] || l.toLowerCase(); r[h] = o[l]; } for (const l in e.attributes) { const h = si[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 f in d.attributes) { const I = d.attributes[f], m = a[f]; m !== void 0 && (I.normalized = m); } h(d); }, r, c, Xe, g); }); }); } } class QA { constructor() { this.name = ae.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 xA { constructor() { this.name = ae.KHR_MESH_QUANTIZATION; } } class er extends Ta { 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, f = e * c, I = f - c, m = -2 * d + 3 * g, C = d - g, w = 1 - m, b = C - g + h; for (let B = 0; B !== r; B++) { const Q = o[I + B + r], D = o[I + B + a] * l, R = o[f + B + r], x = o[f + B] * l; i[B] = w * Q + b * D + m * R + C * x; } return i; } } const SA = new Te(); class TA extends er { interpolate_(e, t, s, n) { const i = super.interpolate_(e, t, s, n); return SA.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 },