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.

33 lines (23 loc) • 366 kB
import{Mesh as H,SphereGeometry as pn,Vector3 as N,MeshBasicMaterial as It,Node as Ho,PerspectiveCamera as Os,NodeFrame as jo,NodeBuilder as qo,GLSLNodeParser as zo,ShaderLib as Et,UniformsUtils as un,UniformsLib as fs,normalView as Ko,defaultShaderStages as Hs,ShaderChunk as Yo,Material as Jt,TrianglesDrawMode as Jo,TriangleFanDrawMode as fn,TriangleStripDrawMode as yi,Matrix4 as oe,Loader as Dt,LoaderUtils as Vt,FileLoader as gt,MeshPhysicalMaterial as Ct,Vector2 as Fe,Color as Be,LinearSRGBColorSpace as We,SRGBColorSpace as re,SpotLight as Qi,PointLight as mn,DirectionalLight as vi,InstancedMesh as Vo,Quaternion as we,InstancedBufferAttribute as Wo,Object3D as Bt,TextureLoader as bn,ImageBitmapLoader as Xo,BufferAttribute as nt,InterleavedBuffer as Zo,LinearMipmapLinearFilter as js,NearestMipmapLinearFilter as xi,LinearMipmapNearestFilter as Si,NearestMipmapNearestFilter as Ti,LinearFilter as dt,NearestFilter as Ri,RepeatWrapping as Wt,MirroredRepeatWrapping as Di,ClampToEdgeWrapping as qs,PointsMaterial as ms,LineBasicMaterial as kt,MeshStandardMaterial as In,DoubleSide as En,PropertyBinding as pt,BufferGeometry as At,SkinnedMesh as Cn,LineSegments as zs,Line as ut,LineLoop as $o,Points as Ks,Group as Xt,MathUtils as Ee,OrthographicCamera as ki,Skeleton as Mi,AnimationClip as Bn,Bone as wn,InterpolateDiscrete as yn,InterpolateLinear as bs,InterleavedBufferAttribute as Zt,Texture as Qn,VectorKeyframeTrack as Ys,NumberKeyframeTrack as Js,QuaternionKeyframeTrack as Vs,ColorManagement as Xe,FrontSide as _i,Interpolant as er,Box3 as Ws,Sphere as vn,RGBA_S3TC_DXT1_Format as tr,RGB_PVRTC_4BPPV1_Format as sr,RGB_ETC2_Format as nr,RGB_ETC1_Format as ir,RGBA_S3TC_DXT5_Format as ar,RGBA_PVRTC_4BPPV1_Format as or,RGBA_ETC2_EAC_Format as rr,RGBA_BPTC_Format as Ar,RGBA_ASTC_4x4_Format as Fi,RGBAFormat as Pt,CompressedCubeTexture as cr,UnsignedByteType as ft,CompressedArrayTexture as lr,CompressedTexture as Is,DisplayP3ColorSpace as hr,LinearDisplayP3ColorSpace as gr,NoColorSpace as Xs,RGBA_ASTC_6x6_Format as Li,RedFormat as os,RGFormat as Es,HalfFloatType as it,FloatType as wt,DataTexture as dr,Data3DTexture as pr,ExtrudeGeometry as ur,ShapePath as fr,Raycaster as xn,CylinderGeometry as Ze,BoxGeometry as Ye,Float32BufferAttribute as Te,OctahedronGeometry as Zs,TorusGeometry as Cs,Euler as Ot,Controls as Ni,PlaneGeometry as Sn,DataTextureLoader as Ui,DataUtils as rs,Vector4 as Mt,Curve as mr,MeshPhongMaterial as Bs,MeshLambertMaterial as br,EquirectangularReflectionMapping as Ir,AmbientLight as Er,Uint16BufferAttribute as Cr,Matrix3 as Gi,ShapeUtils as Br,DefaultLoadingManager as wr,Ray as yr,Plane as Qr,MOUSE as As,TOUCH as cs,Spherical as Pi,ShaderMaterial as Oi,Uniform$1 as vr,Scene as Tn,WebGLRenderer as xr,CanvasTexture as Hi,REVISION as Sr,Source as Tr,InstancedBufferGeometry as Rr,InstancedInterleavedBuffer as Rn,WireframeGeometry as Dr,Line3 as kr,ColorKeyframeTrack as Mr}from"./three-Boa-jOq-.min.js";class _r extends H{constructor(e,t,n,s=128){if(t<=0||n<=0||s<=0)throw new Error("GroundedSkybox height, radius, and resolution must be positive.");const i=new pn(n,2*s,s);i.scale(1,1,-1);const a=i.getAttribute("position"),r=new N;for(let A=0;A<a.count;++A)if(r.fromBufferAttribute(a,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(a.array,3*A)}a.needsUpdate=!0,super(i,new It({map:e,depthWrite:!1}))}}class fe extends Ho{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 $e=new jo;$e.camera=new Os;const ji={LineBasicNodeMaterial:Et.basic,MeshBasicNodeMaterial:Et.basic,PointsNodeMaterial:Et.points,MeshStandardNodeMaterial:Et.standard,MeshPhysicalNodeMaterial:Et.physical,MeshPhongNodeMaterial:Et.phong},Fr={atan2:"atan"},Lr={low:"lowp",medium:"mediump",high:"highp"};function Ht(o){return`#include <${o}>`}function ws(o){return`${o}Shader`}class Nr extends qo{constructor(e,t,n,s=null){super(e,t,new zo,null,s),this.shader=n,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 Fr[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"),ji[t]!==void 0){const n=ji[t],s=this.shader;s.vertexShader=n.vertexShader,s.fragmentShader=n.fragmentShader,s.uniforms=un.merge([n.uniforms,fs.lights])}}_parseObject(){const{material:e,renderer:t}=this;this.addSlot("fragment",new fe({node:Ko,nodeType:"vec3",source:"void main() {",target:"vec3 TransformedNormalView = %RESULT%;",inclusionType:"append"})),t.toneMappingNode&&t.toneMappingNode.isNode===!0&&this.addSlot("fragment",new fe({node:e.colorNode,nodeType:"vec4",source:Ht("tonemapping_fragment"),target:""})),e.colorNode&&e.colorNode.isNode&&this.addSlot("fragment",new fe({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 fe({node:e.opacityNode,nodeType:"float",source:Ht("alphatest_fragment"),target:"diffuseColor.a = %RESULT%;",inclusionType:"append"})),e.normalNode&&e.normalNode.isNode&&this.addSlot("fragment",new fe({node:e.normalNode,nodeType:"vec3",source:Ht("normal_fragment_begin"),target:"normal = %RESULT%;",inclusionType:"append"})),e.emissiveNode&&e.emissiveNode.isNode&&this.addSlot("fragment",new fe({node:e.emissiveNode,nodeType:"vec3",source:Ht("emissivemap_fragment"),target:"totalEmissiveRadiance = %RESULT%;",inclusionType:"append"})),e.isMeshStandardNodeMaterial&&(e.metalnessNode&&e.metalnessNode.isNode&&this.addSlot("fragment",new fe({node:e.metalnessNode,nodeType:"float",source:Ht("metalnessmap_fragment"),target:"metalnessFactor = %RESULT%;",inclusionType:"append"})),e.roughnessNode&&e.roughnessNode.isNode&&this.addSlot("fragment",new fe({node:e.roughnessNode,nodeType:"float",source:Ht("roughnessmap_fragment"),target:"roughnessFactor = %RESULT%;",inclusionType:"append"})),e.isMeshPhysicalNodeMaterial&&(e.clearcoatNode&&e.clearcoatNode.isNode?(this.addSlot("fragment",new fe({node:e.clearcoatNode,nodeType:"float",source:"material.clearcoat = clearcoat;",target:"material.clearcoat = %RESULT%;"})),e.clearcoatRoughnessNode&&e.clearcoatRoughnessNode.isNode&&this.addSlot("fragment",new fe({node:e.clearcoatRoughnessNode,nodeType:"float",source:"material.clearcoatRoughness = clearcoatRoughness;",target:"material.clearcoatRoughness = %RESULT%;"})),e.clearcoatNormalNode&&e.clearcoatNormalNode.isNode&&this.addSlot("fragment",new fe({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 fe({node:e.sheenNode,nodeType:"vec3",source:"material.sheenColor = sheenColor;",target:"material.sheenColor = %RESULT%;"})),e.sheenRoughnessNode&&e.sheenRoughnessNode.isNode&&this.addSlot("fragment",new fe({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 fe({node:e.iridescenceNode,nodeType:"float",source:"material.iridescence = iridescence;",target:"material.iridescence = %RESULT%;"})),e.iridescenceIORNode&&e.iridescenceIORNode.isNode&&this.addSlot("fragment",new fe({node:e.iridescenceIORNode,nodeType:"float",source:"material.iridescenceIOR = iridescenceIOR;",target:"material.iridescenceIOR = %RESULT%;"})),e.iridescenceThicknessNode&&e.iridescenceThicknessNode.isNode&&this.addSlot("fragment",new fe({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 fe({node:e.iorNode,nodeType:"float",source:"material.ior = ior;",target:"material.ior = %RESULT%;"})),e.specularColorNode&&e.specularColorNode.isNode&&this.addSlot("fragment",new fe({node:e.specularColorNode,nodeType:"vec3",source:"vec3 specularColorFactor = specularColor;",target:"vec3 specularColorFactor = %RESULT%;"})),e.specularIntensityNode&&e.specularIntensityNode.isNode&&this.addSlot("fragment",new fe({node:e.specularIntensityNode,nodeType:"float",source:"float specularIntensityFactor = specularIntensity;",target:"float specularIntensityFactor = %RESULT%;"})),e.transmissionNode&&e.transmissionNode.isNode?(this.addSlot("fragment",new fe({node:e.transmissionNode,nodeType:"float",source:"material.transmission = transmission;",target:"material.transmission = %RESULT%;"})),e.thicknessNode&&e.thicknessNode.isNode&&this.addSlot("fragment",new fe({node:e.thicknessNode,nodeType:"float",source:"material.thickness = thickness;",target:"material.thickness = %RESULT%;"})),e.attenuationDistanceNode&&e.attenuationDistanceNode.isNode&&this.addSlot("fragment",new fe({node:e.attenuationDistanceNode,nodeType:"float",source:"material.attenuationDistance = attenuationDistance;",target:"material.attenuationDistance = %RESULT%;"})),e.attenuationColorNode&&e.attenuationColorNode.isNode&&this.addSlot("fragment",new fe({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 fe({node:e.positionNode,nodeType:"vec3",source:Ht("begin_vertex"),target:"transformed = %RESULT%;",inclusionType:"append"})),e.sizeNode&&e.sizeNode.isNode&&this.addSlot("vertex",new fe({node:e.sizeNode,nodeType:"float",source:"gl_PointSize = size;",target:"gl_PointSize = %RESULT%;"}))}generateTexture(e,t,n){return e.isTextureCube?`textureCube( ${t}, ${n} )`:`texture2D( ${t}, ${n} )`}generateTextureLevel(e,t,n,s){return`textureLod( ${t}, ${n}, ${s} )`}buildFunctionCode(e){const t=e.layout,n=this.flowShaderNode(e),s=[];for(const i of t.inputs)s.push(this.getType(i.type)+" "+i.name);return`${this.getType(t.type)} ${t.name}( ${s.join(", ")} ) { ${n.vars} ${n.code} return ${n.result}; }`}getUniforms(e){const t=this.uniforms[e];let n="";for(const s of t){if(/^(modelViewMatrix|projectionMatrix)$/.test(s.name))continue;let i=null;s.type==="texture"?i=`sampler2D ${s.name}; `:s.type==="cubeTexture"?i=`samplerCube ${s.name}; `:i=`${this.getVectorType(s.type)} ${s.name}; `;const a=s.node.precision;a!==null?i="uniform "+Lr[a]+" "+i:i="uniform "+i,n+=i}return n}getAttributes(e){let t="";if(e==="vertex"){const n=this.attributes;for(const s of n)/^(position|normal|uv[1-3]?)$/.test(s.name)||(t+=`attribute ${s.type} ${s.name}; `)}return t}getVaryings(e){let t="";const n=this.varyings;if(e==="vertex")for(const s of n)t+=`${s.needsInterpolation?"varying":"/*varying*/"} ${s.type} ${s.name}; `;else if(e==="fragment")for(const s of n)s.needsInterpolation&&(t+=`varying ${s.type} ${s.name}; `);return t}addCode(e,t,n,s=this){const i=ws(e);let a=s[i];const r=a.indexOf(t);if(r!==-1){const A=a.substring(0,r+t.length),c=a.substring(r+t.length);a=`${A} ${n} ${c}`}s[i]=a}replaceCode(e,t,n,s=this){const i=ws(e);s[i]=s[i].replaceAll(t,n)}getVertexIndex(){return"gl_VertexID"}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord"}isFlipY(){return!0}buildCode(){const e={};for(const t of Hs){const n=this.getUniforms(t),s=this.getAttributes(t),i=this.getVaryings(t),a=this.getVars(t),r=this.getCodes(t);e[t]=`${this.getSignature()} // <node_builder> // uniforms ${n} // attributes ${s} // varyings ${i} // vars ${a} // codes ${r} // </node_builder> ${this.shader[ws(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 n of t){const s=Ht(n),i=Yo[n],a=ws(e);this.shader[a]=this.shader[a].replaceAll(s,i)}}_sortSlotsToFlow(){for(const e of Hs){const t=this.shader[ws(e)],n=this.slots[e].sort((s,i)=>t.indexOf(s.source)>t.indexOf(i.source)?1:-1);for(const s of n)this.addFlow(e,s)}}_addSnippets(){for(const e of Hs){for(const t of this.slots[e]){const n=this.getFlowData(t),s=t.inclusionType,i=t.source,a=n.code+` `+t.target.replace("%RESULT%",n.result);s==="append"?this.addCode(e,i,a):s==="replace"?this.replaceCode(e,i,a):console.warn(`Inclusion type "${s}" not compatible.`)}this.addCode(e,"main() {",` `+this.flowCode[e])}}_addUniforms(){for(const e of Hs)for(const t of this.uniforms[e])this.shader.uniforms[t.name]=t}_updateUniforms(){$e.object=this.object,$e.renderer=this.renderer,$e.material=this.material,$e.scene=this.scene;for(const e of this.updateNodes)$e.updateNode(e)}}const qi=new WeakMap;Jt.prototype.onBuild=function(o,e,t){const n=this;if(n.isNodeMaterial===!0){let s;try{s=new Nr(o,t,e,n).build(),qi.set(n,s)}catch(i){console.error("Material.prototype.onBuild: ",i)}}},Jt.prototype.onBeforeRender=function(o,e,t,n,s){const i=qi.get(this);if(i!==void 0){$e.material=this,$e.camera=t,$e.object=s,$e.renderer=o,$e.scene=e,$e.geometry=n;const a=i.updateNodes;if(a.length>0){o.state.useProgram(null);for(const r of a)$e.updateNode(r)}}};var ys=function(){var o=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(),n(++o%e.children.length)},!1);function t(l){return e.appendChild(l.dom),l}function n(l){for(var h=0;h<e.children.length;h++)e.children[h].style.display=h===l?"block":"none";o=l}var s=(performance||Date).now(),i=s,a=0,r=t(new ys.Panel("FPS","#0ff","#002")),A=t(new ys.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var c=t(new ys.Panel("MB","#f08","#201"));return n(0),{REVISION:16,dom:e,addPanel:t,showPanel:n,begin:function(){s=(performance||Date).now()},end:function(){a++;var l=(performance||Date).now();if(A.update(l-s,200),l>=i+1e3&&(r.update(a*1e3/(l-i),100),i=l,a=0,c)){var h=performance.memory;c.update(h.usedJSHeapSize/1048576,h.jsHeapSizeLimit/1048576)}return l},update:function(){s=this.end()},domElement:e,setMode:n}};ys.Panel=function(o,e,t){var n=1/0,s=0,i=Math.round,a=i(window.devicePixelRatio||1),r=80*a,A=48*a,c=3*a,l=2*a,h=3*a,d=15*a,p=74*a,u=30*a,m=document.createElement("canvas");m.width=r,m.height=A,m.style.cssText="width:80px;height:48px";var b=m.getContext("2d");return b.font="bold "+9*a+"px Helvetica,Arial,sans-serif",b.textBaseline="top",b.fillStyle=t,b.fillRect(0,0,r,A),b.fillStyle=e,b.fillText(o,c,l),b.fillRect(h,d,p,u),b.fillStyle=t,b.globalAlpha=.9,b.fillRect(h,d,p,u),{dom:m,update:function(I,E){n=Math.min(n,I),s=Math.max(s,I),b.fillStyle=t,b.globalAlpha=1,b.fillRect(0,0,r,d),b.fillStyle=e,b.fillText(i(I)+" "+o+" ("+i(n)+"-"+i(s)+")",c,l),b.drawImage(m,h+a,d,p-a,u,h,d,p-a,u),b.fillRect(h+p-a,d,a,u),b.fillStyle=t,b.globalAlpha=.9,b.fillRect(h+p-a,d,a,i((1-I/E)*u))}}};function Ur(o,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},n=o.getIndex(),s=o.getAttribute("position"),i=n?n.count:s.count;let a=0;const r=Object.keys(o.attributes),A={},c={},l=[],h=["getX","getY","getZ","getW"],d=["setX","setY","setZ","setW"];for(let E=0,C=r.length;E<C;E++){const w=r[E],y=o.attributes[w];A[w]=new y.constructor(new y.array.constructor(y.count*y.itemSize),y.itemSize,y.normalized);const S=o.morphAttributes[w];S&&(c[w]||(c[w]=[]),S.forEach((T,x)=>{const D=new T.array.constructor(T.count*T.itemSize);c[w][x]=new T.constructor(D,T.itemSize,T.normalized)}))}const p=e*.5,u=Math.log10(1/e),m=Math.pow(10,u),b=p*m;for(let E=0;E<i;E++){const C=n?n.getX(E):E;let w="";for(let y=0,S=r.length;y<S;y++){const T=r[y],x=o.getAttribute(T),D=x.itemSize;for(let G=0;G<D;G++)w+=`${~~(x[h[G]](C)*m+b)},`}if(w in t)l.push(t[w]);else{for(let y=0,S=r.length;y<S;y++){const T=r[y],x=o.getAttribute(T),D=o.morphAttributes[T],G=x.itemSize,V=A[T],W=c[T];for(let J=0;J<G;J++){const Z=h[J],$=d[J];if(V[$](a,x[Z](C)),D)for(let z=0,K=D.length;z<K;z++)W[z][$](a,D[z][Z](C))}}t[w]=a,l.push(a),a++}}const I=o.clone();for(const E in o.attributes){const C=A[E];if(I.setAttribute(E,new C.constructor(C.array.slice(0,a*C.itemSize),C.itemSize,C.normalized)),E in c)for(let w=0;w<c[E].length;w++){const y=c[E][w];I.morphAttributes[E][w]=new y.constructor(y.array.slice(0,a*y.itemSize),y.itemSize,y.normalized)}}return I.setIndex(l),I}function zi(o,e){if(e===Jo)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),o;if(e===fn||e===yi){let t=o.getIndex();if(t===null){const a=[],r=o.getAttribute("position");if(r!==void 0){for(let A=0;A<r.count;A++)a.push(A);o.setIndex(a),t=o.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),o}const n=t.count-2,s=[];if(e===fn)for(let a=1;a<=n;a++)s.push(t.getX(0)),s.push(t.getX(a)),s.push(t.getX(a+1));else for(let a=0;a<n;a++)a%2===0?(s.push(t.getX(a)),s.push(t.getX(a+1)),s.push(t.getX(a+2))):(s.push(t.getX(a+2)),s.push(t.getX(a+1)),s.push(t.getX(a)));s.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=o.clone();return i.setIndex(s),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),o}class Dn extends Dt{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new jr(t)}),this.register(function(t){return new qr(t)}),this.register(function(t){return new $r(t)}),this.register(function(t){return new eA(t)}),this.register(function(t){return new tA(t)}),this.register(function(t){return new Kr(t)}),this.register(function(t){return new Yr(t)}),this.register(function(t){return new Jr(t)}),this.register(function(t){return new Vr(t)}),this.register(function(t){return new Hr(t)}),this.register(function(t){return new Wr(t)}),this.register(function(t){return new zr(t)}),this.register(function(t){return new Zr(t)}),this.register(function(t){return new Xr(t)}),this.register(function(t){return new Pr(t)}),this.register(function(t){return new sA(t)}),this.register(function(t){return new nA(t)})}load(e,t,n,s){const i=this;let a;if(this.resourcePath!=="")a=this.resourcePath;else if(this.path!==""){const c=Vt.extractUrlBase(e);a=Vt.resolveURL(c,this.path)}else a=Vt.extractUrlBase(e);this.manager.itemStart(e);const r=function(c){s?s(c):console.error(c),i.manager.itemError(e),i.manager.itemEnd(e)},A=new gt(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,a,function(l){t(l),i.manager.itemEnd(e)},r)}catch(l){r(l)}},n,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,n,s){let i,a;const r={},A={},c=new TextDecoder;if(typeof e=="string")try{i=JSON.parse(e)}catch(h){a=e,s&&s(h);return}else if(e instanceof ArrayBuffer)if(c.decode(new Uint8Array(e,0,4))===Ki){try{r[ne.KHR_BINARY_GLTF]=new iA(e)}catch(h){s&&s(h);return}try{i=JSON.parse(r[ne.KHR_BINARY_GLTF].content)}catch(h){a=r[ne.KHR_BINARY_GLTF].content,s&&s(h);return}}else try{i=JSON.parse(c.decode(e))}catch(h){a=c.decode(e),s&&s(h);return}else i=e;if(i.asset===void 0||i.asset.version[0]<2){s&&s(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}this.json=i,this.jsonErrorData=a;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 d=this.pluginCallbacks[h](l);d.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),A[d.name]=d,r[d.name]=!0}if(i.extensionsUsed)for(let h=0;h<i.extensionsUsed.length;++h){const d=i.extensionsUsed[h],p=i.extensionsRequired||[];switch(d){case ne.KHR_MATERIALS_UNLIT:r[d]=new Or;break;case ne.KHR_DRACO_MESH_COMPRESSION:r[d]=new aA(i,this.dracoLoader);break;case ne.KHR_TEXTURE_TRANSFORM:r[d]=new oA;break;case ne.KHR_MESH_QUANTIZATION:r[d]=new rA;break;default:p.indexOf(d)>=0&&A[d]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+d+'".')}}l.setExtensions(r),l.setPlugins(A),l.parse(n,s)}parseAsync(e,t){const n=this;return new Promise(function(s,i){n.parse(e,t,s,i)})}}function Gr(){let o={};return{get:function(e){return o[e]},add:function(e,t){o[e]=t},remove:function(e){delete o[e]},removeAll:function(){o={}}}}const ne={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 Pr{constructor(e){this.parser=e,this.name=ne.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let n=0,s=t.length;n<s;n++){const i=t[n];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,n="light:"+e;let s=t.cache.get(n);if(s)return s;const i=t.json,a=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let r;const A=new Be(16777215);a.color!==void 0&&A.setRGB(a.color[0],a.color[1],a.color[2],We);const c=a.range!==void 0?a.range:0;switch(a.type){case"directional":r=new vi(A),r.target.position.set(0,0,-1),r.add(r.target);break;case"point":r=new mn(A),r.distance=c;break;case"spot":r=new Qi(A),r.distance=c,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,r.angle=a.spot.outerConeAngle,r.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,r.target.position.set(0,0,-1),r.add(r.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+a.type)}return r.position.set(0,0,0),r.decay=2,_t(r,a),a.intensity!==void 0&&(r.intensity=a.intensity),r.name=t.createUniqueName(a.name||"light_"+e),s=Promise.resolve(r),t.cache.add(n,s),s}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,n=this.parser,s=n.json.nodes[e],i=(s.extensions&&s.extensions[this.name]||{}).light;return i===void 0?null:this._loadLight(i).then(function(a){return n._getNodeRef(t.cache,i,a)})}}let Or=class{constructor(){this.name=ne.KHR_MATERIALS_UNLIT}getMaterialType(){return It}extendParams(o,e,t){const n=[];o.color=new Be(1,1,1),o.opacity=1;const s=e.pbrMetallicRoughness;if(s){if(Array.isArray(s.baseColorFactor)){const i=s.baseColorFactor;o.color.setRGB(i[0],i[1],i[2],We),o.opacity=i[3]}s.baseColorTexture!==void 0&&n.push(t.assignTexture(o,"map",s.baseColorTexture,re))}return Promise.all(n)}},Hr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(o,e){const t=this.parser.json.materials[o];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const n=t.extensions[this.name].emissiveStrength;return n!==void 0&&(e.emissiveIntensity=n),Promise.resolve()}},jr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_CLEARCOAT}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser,n=t.json.materials[o];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const s=[],i=n.extensions[this.name];if(i.clearcoatFactor!==void 0&&(e.clearcoat=i.clearcoatFactor),i.clearcoatTexture!==void 0&&s.push(t.assignTexture(e,"clearcoatMap",i.clearcoatTexture)),i.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=i.clearcoatRoughnessFactor),i.clearcoatRoughnessTexture!==void 0&&s.push(t.assignTexture(e,"clearcoatRoughnessMap",i.clearcoatRoughnessTexture)),i.clearcoatNormalTexture!==void 0&&(s.push(t.assignTexture(e,"clearcoatNormalMap",i.clearcoatNormalTexture)),i.clearcoatNormalTexture.scale!==void 0)){const a=i.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new Fe(a,a)}return Promise.all(s)}},qr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_DISPERSION}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser.json.materials[o];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const n=t.extensions[this.name];return e.dispersion=n.dispersion!==void 0?n.dispersion:0,Promise.resolve()}},zr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_IRIDESCENCE}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser,n=t.json.materials[o];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const s=[],i=n.extensions[this.name];return i.iridescenceFactor!==void 0&&(e.iridescence=i.iridescenceFactor),i.iridescenceTexture!==void 0&&s.push(t.assignTexture(e,"iridescenceMap",i.iridescenceTexture)),i.iridescenceIor!==void 0&&(e.iridescenceIOR=i.iridescenceIor),e.iridescenceThicknessRange===void 0&&(e.iridescenceThicknessRange=[100,400]),i.iridescenceThicknessMinimum!==void 0&&(e.iridescenceThicknessRange[0]=i.iridescenceThicknessMinimum),i.iridescenceThicknessMaximum!==void 0&&(e.iridescenceThicknessRange[1]=i.iridescenceThicknessMaximum),i.iridescenceThicknessTexture!==void 0&&s.push(t.assignTexture(e,"iridescenceThicknessMap",i.iridescenceThicknessTexture)),Promise.all(s)}},Kr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_SHEEN}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser,n=t.json.materials[o];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const s=[];e.sheenColor=new Be(0,0,0),e.sheenRoughness=0,e.sheen=1;const i=n.extensions[this.name];if(i.sheenColorFactor!==void 0){const a=i.sheenColorFactor;e.sheenColor.setRGB(a[0],a[1],a[2],We)}return i.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=i.sheenRoughnessFactor),i.sheenColorTexture!==void 0&&s.push(t.assignTexture(e,"sheenColorMap",i.sheenColorTexture,re)),i.sheenRoughnessTexture!==void 0&&s.push(t.assignTexture(e,"sheenRoughnessMap",i.sheenRoughnessTexture)),Promise.all(s)}},Yr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_TRANSMISSION}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser,n=t.json.materials[o];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const s=[],i=n.extensions[this.name];return i.transmissionFactor!==void 0&&(e.transmission=i.transmissionFactor),i.transmissionTexture!==void 0&&s.push(t.assignTexture(e,"transmissionMap",i.transmissionTexture)),Promise.all(s)}},Jr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_VOLUME}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser,n=t.json.materials[o];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const s=[],i=n.extensions[this.name];e.thickness=i.thicknessFactor!==void 0?i.thicknessFactor:0,i.thicknessTexture!==void 0&&s.push(t.assignTexture(e,"thicknessMap",i.thicknessTexture)),e.attenuationDistance=i.attenuationDistance||1/0;const a=i.attenuationColor||[1,1,1];return e.attenuationColor=new Be().setRGB(a[0],a[1],a[2],We),Promise.all(s)}},Vr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_IOR}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser.json.materials[o];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const n=t.extensions[this.name];return e.ior=n.ior!==void 0?n.ior:1.5,Promise.resolve()}},Wr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_SPECULAR}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser,n=t.json.materials[o];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const s=[],i=n.extensions[this.name];e.specularIntensity=i.specularFactor!==void 0?i.specularFactor:1,i.specularTexture!==void 0&&s.push(t.assignTexture(e,"specularIntensityMap",i.specularTexture));const a=i.specularColorFactor||[1,1,1];return e.specularColor=new Be().setRGB(a[0],a[1],a[2],We),i.specularColorTexture!==void 0&&s.push(t.assignTexture(e,"specularColorMap",i.specularColorTexture,re)),Promise.all(s)}},Xr=class{constructor(o){this.parser=o,this.name=ne.EXT_MATERIALS_BUMP}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser,n=t.json.materials[o];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const s=[],i=n.extensions[this.name];return e.bumpScale=i.bumpFactor!==void 0?i.bumpFactor:1,i.bumpTexture!==void 0&&s.push(t.assignTexture(e,"bumpMap",i.bumpTexture)),Promise.all(s)}},Zr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_ANISOTROPY}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:Ct}extendMaterialParams(o,e){const t=this.parser,n=t.json.materials[o];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const s=[],i=n.extensions[this.name];return i.anisotropyStrength!==void 0&&(e.anisotropy=i.anisotropyStrength),i.anisotropyRotation!==void 0&&(e.anisotropyRotation=i.anisotropyRotation),i.anisotropyTexture!==void 0&&s.push(t.assignTexture(e,"anisotropyMap",i.anisotropyTexture)),Promise.all(s)}};class $r{constructor(e){this.parser=e,this.name=ne.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,n=t.json,s=n.textures[e];if(!s.extensions||!s.extensions[this.name])return null;const i=s.extensions[this.name],a=t.options.ktx2Loader;if(!a){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,a)}}class eA{constructor(e){this.parser=e,this.name=ne.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,n=this.parser,s=n.json,i=s.textures[e];if(!i.extensions||!i.extensions[t])return null;const a=i.extensions[t],r=s.images[a.source];let A=n.textureLoader;if(r.uri){const c=n.options.manager.getHandler(r.uri);c!==null&&(A=c)}return this.detectSupport().then(function(c){if(c)return n.loadTextureImage(e,a.source,A);if(s.extensionsRequired&&s.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return n.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 tA{constructor(e){this.parser=e,this.name=ne.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,n=this.parser,s=n.json,i=s.textures[e];if(!i.extensions||!i.extensions[t])return null;const a=i.extensions[t],r=s.images[a.source];let A=n.textureLoader;if(r.uri){const c=n.options.manager.getHandler(r.uri);c!==null&&(A=c)}return this.detectSupport().then(function(c){if(c)return n.loadTextureImage(e,a.source,A);if(s.extensionsRequired&&s.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return n.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 sA{constructor(e){this.name=ne.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){const s=n.extensions[this.name],i=this.parser.getDependency("buffer",s.buffer),a=this.parser.options.meshoptDecoder;if(!a||!a.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=s.byteOffset||0,c=s.byteLength||0,l=s.count,h=s.byteStride,d=new Uint8Array(r,A,c);return a.decodeGltfBufferAsync?a.decodeGltfBufferAsync(l,h,d,s.mode,s.filter).then(function(p){return p.buffer}):a.ready.then(function(){const p=new ArrayBuffer(l*h);return a.decodeGltfBuffer(new Uint8Array(p),l,h,d,s.mode,s.filter),p})})}else return null}}let nA=class{constructor(o){this.name=ne.EXT_MESH_GPU_INSTANCING,this.parser=o}createNodeMesh(o){const e=this.parser.json,t=e.nodes[o];if(!t.extensions||!t.extensions[this.name]||t.mesh===void 0)return null;const n=e.meshes[t.mesh];for(const r of n.primitives)if(r.mode!==ct.TRIANGLES&&r.mode!==ct.TRIANGLE_STRIP&&r.mode!==ct.TRIANGLE_FAN&&r.mode!==void 0)return null;const s=t.extensions[this.name].attributes,i=[],a={};for(const r in s)i.push(this.parser.getDependency("accessor",s[r]).then(A=>(a[r]=A,a[r])));return i.length<1?null:(i.push(this.parser.createNodeMesh(o)),Promise.all(i).then(r=>{const A=r.pop(),c=A.isGroup?A.children:[A],l=r[0].count,h=[];for(const d of c){const p=new oe,u=new N,m=new we,b=new N(1,1,1),I=new Vo(d.geometry,d.material,l);for(let E=0;E<l;E++)a.TRANSLATION&&u.fromBufferAttribute(a.TRANSLATION,E),a.ROTATION&&m.fromBufferAttribute(a.ROTATION,E),a.SCALE&&b.fromBufferAttribute(a.SCALE,E),I.setMatrixAt(E,p.compose(u,m,b));for(const E in a)if(E==="_COLOR_0"){const C=a[E];I.instanceColor=new Wo(C.array,C.itemSize,C.normalized)}else E!=="TRANSLATION"&&E!=="ROTATION"&&E!=="SCALE"&&d.geometry.setAttribute(E,a[E]);Bt.prototype.copy.call(I,d),this.parser.assignFinalMaterial(I),h.push(I)}return A.isGroup?(A.clear(),A.add(...h),A):h[0]}))}};const Ki="glTF",Qs=12,Yi={JSON:1313821514,BIN:5130562};class iA{constructor(e){this.name=ne.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,Qs),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==Ki)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const s=this.header.length-Qs,i=new DataView(e,Qs);let a=0;for(;a<s;){const r=i.getUint32(a,!0);a+=4;const A=i.getUint32(a,!0);if(a+=4,A===Yi.JSON){const c=new Uint8Array(e,Qs+a,r);this.content=n.decode(c)}else if(A===Yi.BIN){const c=Qs+a;this.body=e.slice(c,c+r)}a+=r}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class aA{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=ne.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const n=this.json,s=this.dracoLoader,i=e.extensions[this.name].bufferView,a=e.extensions[this.name].attributes,r={},A={},c={};for(const l in a){const h=Mn[l]||l.toLowerCase();r[h]=a[l]}for(const l in e.attributes){const h=Mn[l]||l.toLowerCase();if(a[l]!==void 0){const d=n.accessors[e.attributes[l]],p=ls[d.componentType];c[h]=p.name,A[h]=d.normalized===!0}}return t.getDependency("bufferView",i).then(function(l){return new Promise(function(h,d){s.decodeDracoFile(l,function(p){for(const u in p.attributes){const m=p.attributes[u],b=A[u];b!==void 0&&(m.normalized=b)}h(p)},r,c,We,d)})})}}class oA{constructor(){this.name=ne.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 rA{constructor(){this.name=ne.KHR_MESH_QUANTIZATION}}class Ji extends er{constructor(e,t,n,s){super(e,t,n,s)}copySampleValue_(e){const t=this.resultBuffer,n=this.sampleValues,s=this.valueSize,i=e*s*3+s;for(let a=0;a!==s;a++)t[a]=n[i+a];return t}interpolate_(e,t,n,s){const i=this.resultBuffer,a=this.sampleValues,r=this.valueSize,A=r*2,c=r*3,l=s-t,h=(n-t)/l,d=h*h,p=d*h,u=e*c,m=u-c,b=-2*p+3*d,I=p-d,E=1-b,C=I-d+h;for(let w=0;w!==r;w++){const y=a[m+w+r],S=a[m+w+A]*l,T=a[u+w+r],x=a[u+w]*l;i[w]=E*y+C*S+b*T+I*x}return i}}const AA=new we;class cA extends Ji{interpolate_(e,t,n,s){const i=super.interpolate_(e,t,n,s);return AA.fromArray(i).normalize().toArray(i),i}}const ct={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},ls={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Vi={9728:Ri,9729:dt,9984:Ti,9985:Si,9986:xi,9987:js},Wi={33071:qs,33648:Di,10497:Wt},kn={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Mn={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"},jt={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},lA={CUBICSPLINE:void 0,LINEAR:bs,STEP:yn},_n={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function hA(o){return o.DefaultMaterial===void 0&&(o.DefaultMaterial=new In({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:_i})),o.DefaultMaterial}function $t(o,e,t){for(const n in t.extensions)o[n]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[n]=t.extensions[n])}function _t(o,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(o.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function gA(o,e,t){let n=!1,s=!1,i=!1;for(let c=0,l=e.length;c<l;c++){const h=e[c];if(h.POSITION!==void 0&&(n=!0),h.NORMAL!==void 0&&(s=!0),h.COLOR_0!==void 0&&(i=!0),n&&s&&i)break}if(!n&&!s&&!i)return Promise.resolve(o);const a=[],r=[],A=[];for(let c=0,l=e.length;c<l;c++){const h=e[c];if(n){const d=h.POSITION!==void 0?t.getDependency("accessor",h.POSITION):o.attributes.position;a.push(d)}if(s){const d=h.NORMAL!==void 0?t.getDependency("accessor",h.NORMAL):o.attributes.normal;r.push(d)}if(i){const d=h.COLOR_0!==void 0?t.getDependency("accessor",h.COLOR_0):o.attributes.color;A.push(d)}}return Promise.all([Promise.all(a),Promise.all(r),Promise.all(A)]).then(function(c){const l=c[0],h=c[1],d=c[2];return n&&(o.morphAttributes.position=l),s&&(o.morphAttributes.normal=h),i&&(o.morphAttributes.color=d),o.morphTargetsRelative=!0,o})}function dA(o,e){if(o.updateMorphTargets(),e.weights!==void 0)for(let t=0,n=e.weights.length;t<n;t++)o.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(o.morphTargetInfluences.length===t.length){o.morphTargetDictionary={};for(let n=0,s=t.length;n<s;n++)o.morphTargetDictionary[t[n]]=n}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function pA(o){let e;const t=o.extensions&&o.extensions[ne.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Fn(t.attributes):e=o.indices+":"+Fn(o.attributes)+":"+o.mode,o.targets!==void 0)for(let n=0,s=o.targets.length;n<s;n++)e+=":"+Fn(o.targets[n]);return e}function Fn(o){let e="";const t=Object.keys(o).sort();for(let n=0,s=t.length;n<s;n++)e+=t[n]+":"+o[t[n]]+";";return e}function Ln(o){switch(o){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 uA(o){return o.search(/\.jpe?g($|\?)/i)>0||o.search(/^data\:image\/jpeg/)===0?"image/jpeg":o.search(/\.webp($|\?)/i)>0||o.search(/^data\:image\/webp/)===0?"image/webp":"image/png"}const fA=new oe;class mA{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Gr,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,s=-1,i=!1,a=-1;if(typeof navigator<"u"){const r=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(r)===!0;const A=r.match(/Version\/(\d+)/);s=n&&A?parseInt(A[1],10):-1,i=r.indexOf("Firefox")>-1,a=i?r.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||n&&s<17||i&&a<98?this.textureLoader=new bn(this.options.manager):this.textureLoader=new Xo(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new gt(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const n=this,s=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(a){return a._markDefs&&a._markDefs()}),Promise.all(this._invokeAll(function(a){return a.beforeRoot&&a.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(a){const r={scene:a[0][s.scene||0],scenes:a[0],animations:a[1],cameras:a[2],asset:s.asset,parser:n,userData:{}};return $t(i,r,s),_t(r,s),Promise.all(n._invokeAll(function(A){return A.afterRoot&&A.afterRoot(r)})).then(function(){for(const A of r.scenes)A.updateMatrixWorld();e(r)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let s=0,i=t.length;s<i;s++){const a=t[s].joints;for(let r=0,A=a.length;r<A;r++)e[a[r]].isBone=!0}for(let s=0,i=e.length;s<i;s++){const a=e[s];a.mesh!==void 0&&(this._addNodeRef(this.meshCache,a.mesh),a.skin!==void 0&&(n[a.mesh].isSkinnedMesh=!0)),a.camera!==void 0&&this._addNodeRef(this.cameraCache,a.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;const s=n.clone(),i=(a,r)=>{const A=this.associations.get(a);A!=null&&this.associations.set(r,A);for(const[c,l]of a.children.entries())i(l,r.children[c])};return i(n,s),s.name+="_instance_"+e.uses[t]++,s}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){const s=e(t[n]);if(s)return s}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const n=[];for(let s=0;s<t.length;s++){const i=e(t[s]);i&&n.push(i)}return n}getDependency(e,t){const n=e+":"+t;let s=this.cache.get(n);if(!s){switch(e){case"scene":s=this.loadScene(t);break;case"node":s=this._invokeOne(function(i){return i.loadNode&&i.loadNode(t)});break;case"mesh":s=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(t)});break;case"accessor":s=this.loadAccessor(t);break;case"bufferView":s=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(t)});break;case"buffer":s=this.loadBuffer(t);break;case"material":s=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(t)});break;case"texture":s=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(t)});break;case"skin":s=this.loadSkin(t);break;case"animation":s=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(t)});break;case"camera":s=this.loadCamera(t);break;default:if(s=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(e,t)}),!s)throw new Error("Unknown type: "+e);break}this.cache.add(n,s)}return s}getDependencies(e){let t=this.cache.get(e);if(!t){const n=this,s=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(s.map(function(i,a){return n.getDependency(e,a)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[ne.KHR_BINARY_GLTF].body);const s=this.options;return new Promise(function(i,a){n.load(Vt.resolveURL(t.uri,s.path),i,void 0,function(){a(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(n){const s=t.byteLength||0,i=t.byteOffset||0;return n.slice(i,i+s)})}loadAccessor(e){const t=this,n=this.json,s=this.json.accessors[e];if(s.bufferView===void 0&&s.sparse===void 0){const a=kn[s.type],r=ls[s.componentType],A=s.normalized===!0,c=new r(s.count*a);return Promise.resolve(new nt(c,a,A))}const i=[];return s.bufferView!==void 0?i.push(this.getDependency("bufferView",s.bufferView)):i.push(null),s.sparse!==void 0&&(i.push(this.getDependency("bufferView",s.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",s.sparse.values.bufferView))),Promise.all(i).then(function(a){const r=a[0],A=kn[s.type],c=ls[s.componentType],l=c.BYTES_PER_ELEMENT,h=l*A,d=s.byteOffset||0,p=s.bufferView!==void 0?n.bufferViews[s.bufferView].byteStride:void 0,u=s.normalized===!0;let m,b;if(p&&p!==h){const I=Math.floor(d/p),E="InterleavedBuffer:"+s.bufferView+":"+s.componentType+":"+I+":"+s.count;let C=t.cache.get(E);C||(m=new c(r,I*p,s.count*p/l),C=new Zo(m,p/l),t.cache.add(E,C)),b=new Zt(C,A,d%p/l,u)}else r===null?m=new c(s.count*A):m=new c(r,d,s.count*A),b=new nt(m,A,u);if(s.sparse!==void 0){const I=kn.SCALAR,E=ls[s.sparse.indices.componentType],C=s.sparse.indices.byteOffset||0,w=s.sparse.values.byteOffset||0,y=new E(a[1],C,s.sparse.count*I),S=new c(a[2],w,s.sparse.count*A);r!==null&&(b=new nt(b.array.slice(),b.itemSize,b.normalized)),b.normalized=!1;for(let T=0,x=y.length;T<x;T++){const D=y[T];if(b.setX(D,S[T*A]),A>=2&&b.setY(D,S[T*A+1]),A>=3&&b.setZ(D,S[T*A+2]),A>=4&&b.setW(D,S[T*A+3]),A>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}b.normalized=u}return b})}loadTexture(e){const t=this.json,n=this.options,s=t.textures[e].source,i=t.images[s];let a=this.textureLoader;if(i.uri){const r=n.manager.getHandler(i.uri);r!==null&&(a=r)}return this.loadTextureImage(e,s,a)}loadTextureImage(e,t,n){const s=this,i=this.json,a=i.textures[e],r=i.images[t],A=(r.uri||r.bufferView)+":"+a.sampler;if(this.textureCache[A])return this.textureCache[A];const c=this.loadImageSource(t,n).then(function(l){l.flipY=!1,l.name=a.name||r.name||"",l.name===""&&typeof r.uri=="string"&&r.uri.startsWith("data:image/")===!1&&(l.name=r.uri);const h=(i.samplers||{})[a.sampler]||{};return l.magFilter=Vi[h.magFilter]||dt,l.minFilter=Vi[h.minFilter]||js,l.wrapS=Wi[h.wrapS]||Wt,l.wrapT=Wi[h.wrapT]||Wt,l.anisotropy=4,s.associations.set(l,{textures:e}),l}).catch(function(){return null});return this.textureCache[A]=c,c}loadImageSource(e,t){const n=this,s=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(h=>h.clone());const a=s.images[e],r=self.URL||self.webkitURL;let A=a.uri||"",c=!1;if(a.bufferView!==void 0)A=n.getDependency("bufferView",a.bufferView).then(fun