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) • 369 kB
import{Mesh as O,SphereGeometry as bn,Vector3 as N,MeshBasicMaterial as Ct,Node as sr,PerspectiveCamera as qs,NodeFrame as nr,NodeBuilder as ir,GLSLNodeParser as ar,ShaderLib as Bt,UniformsUtils as In,UniformsLib as ms,normalView as or,defaultShaderStages as zs,ShaderChunk as rr,Material as Jt,TrianglesDrawMode as Ar,TriangleFanDrawMode as En,TriangleStripDrawMode as ki,Matrix4 as ce,Loader as Dt,LoaderUtils as Wt,FileLoader as gt,MeshPhysicalMaterial as wt,Vector2 as Le,Color as we,LinearSRGBColorSpace as Ve,SRGBColorSpace as le,SpotLight as Mi,PointLight as Cn,DirectionalLight as _i,InstancedMesh as cr,Quaternion as ye,InstancedBufferAttribute as lr,Object3D as yt,TextureLoader as Bn,ImageBitmapLoader as hr,BufferAttribute as it,InterleavedBuffer as dr,LinearMipmapLinearFilter as bs,NearestMipmapLinearFilter as Fi,LinearMipmapNearestFilter as Li,NearestMipmapNearestFilter as wn,LinearFilter as at,NearestFilter as Ks,RepeatWrapping as Vt,MirroredRepeatWrapping as Ni,ClampToEdgeWrapping as Ys,PointsMaterial as Is,LineBasicMaterial as kt,MeshStandardMaterial as yn,DoubleSide as Qn,PropertyBinding as ut,BufferGeometry as ct,SkinnedMesh as vn,LineSegments as Js,Line as ft,LineLoop as pr,Points as Ws,Group as Xt,MathUtils as Ce,OrthographicCamera as Ui,Skeleton as Gi,AnimationClip as xn,Bone as Sn,InterpolateDiscrete as Tn,InterpolateLinear as Es,InterleavedBufferAttribute as Zt,Texture as Rn,VectorKeyframeTrack as Vs,NumberKeyframeTrack as Xs,QuaternionKeyframeTrack as Zs,ColorManagement as Xe,FrontSide as Pi,Interpolant as gr,Box3 as $s,Sphere as Dn,RGBA_S3TC_DXT1_Format as kn,RGB_PVRTC_4BPPV1_Format as ur,RGB_ETC2_Format as Oi,RGB_ETC1_Format as fr,RGBA_S3TC_DXT5_Format as Mn,RGBA_PVRTC_4BPPV1_Format as mr,RGBA_ETC2_EAC_Format as Hi,RGBA_BPTC_Format as _n,RGB_BPTC_UNSIGNED_Format as br,RGBA_ASTC_4x4_Format as en,RGBAFormat as Pt,FloatType as mt,HalfFloatType as Ze,UnsignedByteType as bt,CompressedCubeTexture as Ir,CompressedArrayTexture as Er,CompressedTexture as Cs,NoColorSpace as tn,RGBA_S3TC_DXT3_Format as ji,RGB_S3TC_DXT1_Format as qi,RGBA_ASTC_6x6_Format as zi,RGBFormat as Fn,RedFormat as rs,RGFormat as Bs,UnsignedInt101111Type as Ki,UnsignedInt5999Type as Yi,DataTexture as Cr,Data3DTexture as Br,ExtrudeGeometry as wr,ShapePath as yr,Raycaster as Ln,CylinderGeometry as $e,BoxGeometry as Ye,Float32BufferAttribute as ke,OctahedronGeometry as sn,TorusGeometry as ws,Euler as Ot,Controls as Ji,PlaneGeometry as Nn,DataTextureLoader as Wi,DataUtils as As,Vector4 as Mt,Curve as Qr,MeshPhongMaterial as ys,MeshLambertMaterial as vr,EquirectangularReflectionMapping as xr,AmbientLight as Sr,Uint16BufferAttribute as Tr,Matrix3 as Vi,ShapeUtils as Rr,DefaultLoadingManager as Dr,Ray as kr,Plane as Mr,MOUSE as cs,TOUCH as ls,Spherical as Xi,ShaderMaterial as Zi,Uniform$1 as _r,Scene as Un,WebGLRenderer as Fr,CanvasTexture as $i,REVISION as Lr,Source as Nr,InstancedBufferGeometry as Ur,InstancedInterleavedBuffer as Gn,WireframeGeometry as Gr,Line3 as Pr,ColorKeyframeTrack as Or}from"./three-CsmWHVn7.min.js";class Hr extends O{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 bn(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 Ct({map:e,depthWrite:!1}))}}class be extends sr{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 et=new nr;et.camera=new qs;const ea={LineBasicNodeMaterial:Bt.basic,MeshBasicNodeMaterial:Bt.basic,PointsNodeMaterial:Bt.points,MeshStandardNodeMaterial:Bt.standard,MeshPhysicalNodeMaterial:Bt.physical,MeshPhongNodeMaterial:Bt.phong},jr={atan2:"atan"},qr={low:"lowp",medium:"mediump",high:"highp"};function Ht(o){return`#include <${o}>`}function Qs(o){return`${o}Shader`}class zr extends ir{constructor(e,t,n,s=null){super(e,t,new ar,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 jr[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"),ea[t]!==void 0){const n=ea[t],s=this.shader;s.vertexShader=n.vertexShader,s.fragmentShader=n.fragmentShader,s.uniforms=In.merge([n.uniforms,ms.lights])}}_parseObject(){const{material:e,renderer:t}=this;this.addSlot("fragment",new be({node:or,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:Ht("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:Ht("alphatest_fragment"),target:"diffuseColor.a = %RESULT%;",inclusionType:"append"})),e.normalNode&&e.normalNode.isNode&&this.addSlot("fragment",new be({node:e.normalNode,nodeType:"vec3",source:Ht("normal_fragment_begin"),target:"normal = %RESULT%;",inclusionType:"append"})),e.emissiveNode&&e.emissiveNode.isNode&&this.addSlot("fragment",new be({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 be({node:e.metalnessNode,nodeType:"float",source:Ht("metalnessmap_fragment"),target:"metalnessFactor = %RESULT%;",inclusionType:"append"})),e.roughnessNode&&e.roughnessNode.isNode&&this.addSlot("fragment",new be({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 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:Ht("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,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 "+qr[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=Qs(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=Qs(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 zs){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[Qs(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=rr[n],a=Qs(e);this.shader[a]=this.shader[a].replaceAll(s,i)}}_sortSlotsToFlow(){for(const e of zs){const t=this.shader[Qs(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 zs){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 zs)for(const t of this.uniforms[e])this.shader.uniforms[t.name]=t}_updateUniforms(){et.object=this.object,et.renderer=this.renderer,et.material=this.material,et.scene=this.scene;for(const e of this.updateNodes)et.updateNode(e)}}const ta=new WeakMap;Jt.prototype.onBuild=function(o,e,t){const n=this;if(n.isNodeMaterial===!0){let s;try{s=new zr(o,t,e,n).build(),ta.set(n,s)}catch(i){console.error("Material.prototype.onBuild: ",i)}}},Jt.prototype.onBeforeRender=function(o,e,t,n,s){const i=ta.get(this);if(i!==void 0){et.material=this,et.camera=t,et.object=s,et.renderer=o,et.scene=e,et.geometry=n;const a=i.updateNodes;if(a.length>0){o.state.useProgram(null);for(const r of a)et.updateNode(r)}}};var vs=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 vs.Panel("FPS","#0ff","#002")),A=t(new vs.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var c=t(new vs.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}};vs.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,p=15*a,g=74*a,u=30*a,b=document.createElement("canvas");b.width=r,b.height=A,b.style.cssText="width:80px;height:48px";var f=b.getContext("2d");return f.font="bold "+9*a+"px Helvetica,Arial,sans-serif",f.textBaseline="top",f.fillStyle=t,f.fillRect(0,0,r,A),f.fillStyle=e,f.fillText(o,c,l),f.fillRect(h,p,g,u),f.fillStyle=t,f.globalAlpha=.9,f.fillRect(h,p,g,u),{dom:b,update:function(E,C){n=Math.min(n,E),s=Math.max(s,E),f.fillStyle=t,f.globalAlpha=1,f.fillRect(0,0,r,p),f.fillStyle=e,f.fillText(i(E)+" "+o+" ("+i(n)+"-"+i(s)+")",c,l),f.drawImage(b,h+a,p,g-a,u,h,p,g-a,u),f.fillRect(h+g-a,p,a,u),f.fillStyle=t,f.globalAlpha=.9,f.fillRect(h+g-a,p,a,i((1-E/C)*u))}}};function Kr(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"],p=["setX","setY","setZ","setW"];for(let C=0,I=r.length;C<I;C++){const y=r[C],w=o.attributes[y];A[y]=new w.constructor(new w.array.constructor(w.count*w.itemSize),w.itemSize,w.normalized);const x=o.morphAttributes[y];x&&(c[y]||(c[y]=[]),x.forEach((T,S)=>{const M=new T.array.constructor(T.count*T.itemSize);c[y][S]=new T.constructor(M,T.itemSize,T.normalized)}))}const g=e*.5,u=Math.log10(1/e),b=Math.pow(10,u),f=g*b;for(let C=0;C<i;C++){const I=n?n.getX(C):C;let y="";for(let w=0,x=r.length;w<x;w++){const T=r[w],S=o.getAttribute(T),M=S.itemSize;for(let j=0;j<M;j++)y+=`${~~(S[h[j]](I)*b+f)},`}if(y in t)l.push(t[y]);else{for(let w=0,x=r.length;w<x;w++){const T=r[w],S=o.getAttribute(T),M=o.morphAttributes[T],j=S.itemSize,K=A[T],J=c[T];for(let V=0;V<j;V++){const q=h[V],X=p[V];if(K[X](a,S[q](I)),M)for(let W=0,ee=M.length;W<ee;W++)J[W][X](a,M[W][q](I))}}t[y]=a,l.push(a),a++}}const E=o.clone();for(const C in o.attributes){const I=A[C];if(E.setAttribute(C,new I.constructor(I.array.slice(0,a*I.itemSize),I.itemSize,I.normalized)),C in c)for(let y=0;y<c[C].length;y++){const w=c[C][y];E.morphAttributes[C][y]=new w.constructor(w.array.slice(0,a*w.itemSize),w.itemSize,w.normalized)}}return E.setIndex(l),E}function sa(o,e){if(e===Ar)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),o;if(e===En||e===ki){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===En)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 Pn extends Dt{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Xr(t)}),this.register(function(t){return new Zr(t)}),this.register(function(t){return new rA(t)}),this.register(function(t){return new AA(t)}),this.register(function(t){return new cA(t)}),this.register(function(t){return new eA(t)}),this.register(function(t){return new tA(t)}),this.register(function(t){return new sA(t)}),this.register(function(t){return new nA(t)}),this.register(function(t){return new Vr(t)}),this.register(function(t){return new iA(t)}),this.register(function(t){return new $r(t)}),this.register(function(t){return new oA(t)}),this.register(function(t){return new aA(t)}),this.register(function(t){return new Jr(t)}),this.register(function(t){return new lA(t)}),this.register(function(t){return new hA(t)})}load(e,t,n,s){const i=this;let a;if(this.resourcePath!=="")a=this.resourcePath;else if(this.path!==""){const c=Wt.extractUrlBase(e);a=Wt.resolveURL(c,this.path)}else a=Wt.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))===na){try{r[ie.KHR_BINARY_GLTF]=new dA(e)}catch(h){s&&s(h);return}try{i=JSON.parse(r[ie.KHR_BINARY_GLTF].content)}catch(h){a=r[ie.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 QA(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 p=this.pluginCallbacks[h](l);p.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),A[p.name]=p,r[p.name]=!0}if(i.extensionsUsed)for(let h=0;h<i.extensionsUsed.length;++h){const p=i.extensionsUsed[h],g=i.extensionsRequired||[];switch(p){case ie.KHR_MATERIALS_UNLIT:r[p]=new Wr;break;case ie.KHR_DRACO_MESH_COMPRESSION:r[p]=new pA(i,this.dracoLoader);break;case ie.KHR_TEXTURE_TRANSFORM:r[p]=new gA;break;case ie.KHR_MESH_QUANTIZATION:r[p]=new uA;break;default:g.indexOf(p)>=0&&A[p]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+p+'".')}}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 Yr(){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 ie={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 Jr{constructor(e){this.parser=e,this.name=ie.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 we(16777215);a.color!==void 0&&A.setRGB(a.color[0],a.color[1],a.color[2],Ve);const c=a.range!==void 0?a.range:0;switch(a.type){case"directional":r=new _i(A),r.target.position.set(0,0,-1),r.add(r.target);break;case"point":r=new Cn(A),r.distance=c;break;case"spot":r=new Mi(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 Wr=class{constructor(){this.name=ie.KHR_MATERIALS_UNLIT}getMaterialType(){return Ct}extendParams(o,e,t){const n=[];o.color=new we(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],Ve),o.opacity=i[3]}s.baseColorTexture!==void 0&&n.push(t.assignTexture(o,"map",s.baseColorTexture,le))}return Promise.all(n)}},Vr=class{constructor(o){this.parser=o,this.name=ie.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()}},Xr=class{constructor(o){this.parser=o,this.name=ie.KHR_MATERIALS_CLEARCOAT}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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 Le(a,a)}return Promise.all(s)}},Zr=class{constructor(o){this.parser=o,this.name=ie.KHR_MATERIALS_DISPERSION}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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()}},$r=class{constructor(o){this.parser=o,this.name=ie.KHR_MATERIALS_IRIDESCENCE}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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)}},eA=class{constructor(o){this.parser=o,this.name=ie.KHR_MATERIALS_SHEEN}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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 we(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],Ve)}return i.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=i.sheenRoughnessFactor),i.sheenColorTexture!==void 0&&s.push(t.assignTexture(e,"sheenColorMap",i.sheenColorTexture,le)),i.sheenRoughnessTexture!==void 0&&s.push(t.assignTexture(e,"sheenRoughnessMap",i.sheenRoughnessTexture)),Promise.all(s)}},tA=class{constructor(o){this.parser=o,this.name=ie.KHR_MATERIALS_TRANSMISSION}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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)}},sA=class{constructor(o){this.parser=o,this.name=ie.KHR_MATERIALS_VOLUME}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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 we().setRGB(a[0],a[1],a[2],Ve),Promise.all(s)}},nA=class{constructor(o){this.parser=o,this.name=ie.KHR_MATERIALS_IOR}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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()}},iA=class{constructor(o){this.parser=o,this.name=ie.KHR_MATERIALS_SPECULAR}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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 we().setRGB(a[0],a[1],a[2],Ve),i.specularColorTexture!==void 0&&s.push(t.assignTexture(e,"specularColorMap",i.specularColorTexture,le)),Promise.all(s)}},aA=class{constructor(o){this.parser=o,this.name=ie.EXT_MATERIALS_BUMP}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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)}},oA=class{constructor(o){this.parser=o,this.name=ie.KHR_MATERIALS_ANISOTROPY}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:wt}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 rA{constructor(e){this.parser=e,this.name=ie.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 AA{constructor(e){this.parser=e,this.name=ie.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 cA{constructor(e){this.parser=e,this.name=ie.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 lA{constructor(e){this.name=ie.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,p=new Uint8Array(r,A,c);return a.decodeGltfBufferAsync?a.decodeGltfBufferAsync(l,h,p,s.mode,s.filter).then(function(g){return g.buffer}):a.ready.then(function(){const g=new ArrayBuffer(l*h);return a.decodeGltfBuffer(new Uint8Array(g),l,h,p,s.mode,s.filter),g})})}else return null}}let hA=class{constructor(o){this.name=ie.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!==lt.TRIANGLES&&r.mode!==lt.TRIANGLE_STRIP&&r.mode!==lt.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 p of c){const g=new ce,u=new N,b=new ye,f=new N(1,1,1),E=new cr(p.geometry,p.material,l);for(let C=0;C<l;C++)a.TRANSLATION&&u.fromBufferAttribute(a.TRANSLATION,C),a.ROTATION&&b.fromBufferAttribute(a.ROTATION,C),a.SCALE&&f.fromBufferAttribute(a.SCALE,C),E.setMatrixAt(C,g.compose(u,b,f));for(const C in a)if(C==="_COLOR_0"){const I=a[C];E.instanceColor=new lr(I.array,I.itemSize,I.normalized)}else C!=="TRANSLATION"&&C!=="ROTATION"&&C!=="SCALE"&&p.geometry.setAttribute(C,a[C]);yt.prototype.copy.call(E,p),this.parser.assignFinalMaterial(E),h.push(E)}return A.isGroup?(A.clear(),A.add(...h),A):h[0]}))}};const na="glTF",xs=12,ia={JSON:1313821514,BIN:5130562};class dA{constructor(e){this.name=ie.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,xs),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!==na)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-xs,i=new DataView(e,xs);let a=0;for(;a<s;){const r=i.getUint32(a,!0);a+=4;const A=i.getUint32(a,!0);if(a+=4,A===ia.JSON){const c=new Uint8Array(e,xs+a,r);this.content=n.decode(c)}else if(A===ia.BIN){const c=xs+a;this.body=e.slice(c,c+r)}a+=r}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class pA{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=ie.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=Hn[l]||l.toLowerCase();r[h]=a[l]}for(const l in e.attributes){const h=Hn[l]||l.toLowerCase();if(a[l]!==void 0){const p=n.accessors[e.attributes[l]],g=hs[p.componentType];c[h]=g.name,A[h]=p.normalized===!0}}return t.getDependency("bufferView",i).then(function(l){return new Promise(function(h,p){s.decodeDracoFile(l,function(g){for(const u in g.attributes){const b=g.attributes[u],f=A[u];f!==void 0&&(b.normalized=f)}h(g)},r,c,Ve,p)})})}}class gA{constructor(){this.name=ie.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 uA{constructor(){this.name=ie.KHR_MESH_QUANTIZATION}}class aa extends gr{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,p=h*h,g=p*h,u=e*c,b=u-c,f=-2*g+3*p,E=g-p,C=1-f,I=E-p+h;for(let y=0;y!==r;y++){const w=a[b+y+r],x=a[b+y+A]*l,T=a[u+y+r],S=a[u+y]*l;i[y]=C*w+I*x+f*T+E*S}return i}}const fA=new ye;class mA extends aa{interpolate_(e,t,n,s){const i=super.interpolate_(e,t,n,s);return fA.fromArray(i).normalize().toArray(i),i}}const lt={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},hs={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},oa={9728:Ks,9729:at,9984:wn,9985:Li,9986:Fi,9987:bs},ra={33071:Ys,33648:Ni,10497:Vt},On={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Hn={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"},bA={CUBICSPLINE:void 0,LINEAR:Es,STEP:Tn},jn={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function IA(o){return o.DefaultMaterial===void 0&&(o.DefaultMaterial=new yn({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:Pi})),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 EA(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 p=h.POSITION!==void 0?t.getDependency("accessor",h.POSITION):o.attributes.position;a.push(p)}if(s){const p=h.NORMAL!==void 0?t.getDependency("accessor",h.NORMAL):o.attributes.normal;r.push(p)}if(i){const p=h.COLOR_0!==void 0?t.getDependency("accessor",h.COLOR_0):o.attributes.color;A.push(p)}}return Promise.all([Promise.all(a),Promise.all(r),Promise.all(A)]).then(function(c){const l=c[0],h=c[1],p=c[2];return n&&(o.morphAttributes.position=l),s&&(o.morphAttributes.normal=h),i&&(o.morphAttributes.color=p),o.morphTargetsRelative=!0,o})}function CA(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 BA(o){let e;const t=o.extensions&&o.extensions[ie.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+qn(t.attributes):e=o.indices+":"+qn(o.attributes)+":"+o.mode,o.targets!==void 0)for(let n=0,s=o.targets.length;n<s;n++)e+=":"+qn(o.targets[n]);return e}function qn(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 zn(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 wA(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 yA=new ce;class QA{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Yr,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 hr(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[ie.KHR_BINARY_GLTF].body);const s=this.options;return new Promise(function(i,a){n.load(Wt.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=On[s.type],r=hs[s.componentType],A=s.normalized===!0,c=new r(s.count*a);return Promise.resolve(new it(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=On[s.type],c=hs[s.componentType],l=c.BYTES_PER_ELEMENT,h=l*A,p=s.byteOffset||0,g=s.bufferView!==void 0?n.bufferViews[s.bufferView].byteStride:void 0,u=s.normalized===!0;let b,f;if(g&&g!==h){const E=Math.floor(p/g),C="InterleavedBuffer:"+s.bufferView+":"+s.componentType+":"+E+":"+s.count;let I=t.cache.get(C);I||(b=new c(r,E*g,s.count*g/l),I=new dr(b,g/l),t.cache.add(C,I)),f=new Zt(I,A,p%g/l,u)}else r===null?b=new c(s.count*A):b=new c(r,p,s.count*A),f=new it(b,A,u);if(s.sparse!==void 0){const E=On.SCALAR,C=hs[s.sparse.indices.componentType],I=s.sparse.indices.byteOffset||0,y=s.sparse.values.byteOffset||0,w=new C(a[1],I,s.sparse.count*E),x=new c(a[2],y,s.sparse.count*A);r!==null&&(f=new it(f.array.slice(),f.itemSize,f.normalized)),f.normalized=!1;for(let T=0,S=w.length;T<S;T++){const M=w[T];if(f.setX(M,x[T*A]),A>=2&&f.setY(M,x[T*A+1]),A>=3&&f.setZ(M,x[T*A+2]),A>=4&&f.setW(M,x[T*A+3]),A>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}f.normalized=u}return f})}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=oa[h.magFilter]||at,l.minFilter=oa[h.minFilter]||bs,l.wrapS=ra[h.wrapS]||Vt,l.wrapT=ra[h.wrapT]||Vt,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