@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) • 360 kB
JavaScript
import{Mesh as O,SphereGeometry as hi,Vector3 as N,MeshBasicMaterial as It,Node as Wo,PerspectiveCamera as Os,NodeFrame as Xo,NodeBuilder as Zo,GLSLNodeParser as $o,ShaderLib as Et,UniformsUtils as gi,UniformsLib as us,normalView as er,defaultShaderStages as Hs,ShaderChunk as tr,Material as Kt,TrianglesDrawMode as sr,TriangleFanDrawMode as di,TriangleStripDrawMode as xn,Matrix4 as ce,Loader as Tt,LoaderUtils as Jt,FileLoader as dt,MeshPhysicalMaterial as Ct,Vector2 as Le,Color as we,LinearSRGBColorSpace as We,SRGBColorSpace as le,SpotLight as Sn,PointLight as pi,DirectionalLight as Tn,InstancedMesh as ir,Quaternion as ye,InstancedBufferAttribute as nr,Object3D as Bt,TextureLoader as ui,ImageBitmapLoader as ar,BufferAttribute as nt,InterleavedBuffer as or,LinearMipmapLinearFilter as fs,NearestMipmapLinearFilter as Dn,LinearMipmapNearestFilter as Rn,NearestMipmapNearestFilter as fi,LinearFilter as at,NearestFilter as js,RepeatWrapping as Vt,MirroredRepeatWrapping as Mn,ClampToEdgeWrapping as qs,PointsMaterial as ms,LineBasicMaterial as Dt,MeshStandardMaterial as mi,DoubleSide as bi,PropertyBinding as Rt,BufferGeometry as ct,SkinnedMesh as kn,LineSegments as zs,Line as pt,LineLoop as rr,Points as Ys,Group as Wt,MathUtils as Ce,OrthographicCamera as _n,Skeleton as Fn,AnimationClip as Ln,Bone as Ii,InterpolateDiscrete as Nn,InterpolateLinear as Ei,InterleavedBufferAttribute as Xt,Texture as Ci,VectorKeyframeTrack as Bi,NumberKeyframeTrack as wi,QuaternionKeyframeTrack as yi,ColorManagement as Xe,FrontSide as Un,Interpolant as Ar,Box3 as Ks,Sphere as Qi,RGBA_S3TC_DXT1_Format as vi,RGB_PVRTC_4BPPV1_Format as cr,RGB_ETC2_Format as Gn,RGB_ETC1_Format as lr,RGBA_S3TC_DXT5_Format as xi,RGBA_PVRTC_4BPPV1_Format as hr,RGBA_ETC2_EAC_Format as Pn,RGBA_BPTC_Format as Si,RGB_BPTC_UNSIGNED_Format as gr,RGBA_ASTC_4x4_Format as Js,RGBAFormat as Gt,FloatType as ut,HalfFloatType as Ze,UnsignedByteType as ft,CompressedCubeTexture as dr,CompressedArrayTexture as pr,CompressedTexture as bs,NoColorSpace as Vs,RGBA_S3TC_DXT3_Format as On,RGB_S3TC_DXT1_Format as Hn,RGBA_ASTC_6x6_Format as jn,RGBFormat as Ti,RedFormat as as,RGFormat as Is,UnsignedInt101111Type as qn,UnsignedInt5999Type as zn,DataTexture as ur,Data3DTexture as fr,ExtrudeGeometry as mr,ShapePath as br,Raycaster as Di,CylinderGeometry as $e,BoxGeometry as Ke,Float32BufferAttribute as Me,OctahedronGeometry as Ws,TorusGeometry as Es,Euler as Pt,Controls as Yn,PlaneGeometry as Ri,DataTextureLoader as Kn,DataUtils as os,Vector4 as Mt,Curve as Ir,MeshPhongMaterial as Cs,MeshLambertMaterial as Er,EquirectangularReflectionMapping as Cr,AmbientLight as Br,Uint16BufferAttribute as wr,Matrix3 as Jn,ShapeUtils as yr,DefaultLoadingManager as Qr,Ray as vr,Plane as xr,MOUSE as rs,TOUCH as As,Spherical as Vn,ShaderMaterial as Wn,Uniform$1 as Sr,Scene as Mi,WebGLRenderer as Tr,CanvasTexture as Xn,REVISION as Dr,Source as Rr,InstancedBufferGeometry as Mr,InstancedInterleavedBuffer as ki,WireframeGeometry as kr,Line3 as _r}from"./three.min.js";class Fr extends O{constructor(e,t,i,s=128){if(t<=0||i<=0||s<=0)throw new Error("GroundedSkybox height, radius, and resolution must be positive.");const n=new hi(i,2*s,s);n.scale(1,1,-1);const a=n.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(n,new It({map:e,depthWrite:!1}))}}class be extends Wo{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 Xo;et.camera=new Os;const Zn={LineBasicNodeMaterial:Et.basic,MeshBasicNodeMaterial:Et.basic,PointsNodeMaterial:Et.points,MeshStandardNodeMaterial:Et.standard,MeshPhysicalNodeMaterial:Et.physical,MeshPhongNodeMaterial:Et.phong},Lr={atan2:"atan"},Nr={low:"lowp",medium:"mediump",high:"highp"};function Ot(o){return`#include <${o}>`}function Bs(o){return`${o}Shader`}class Ur extends Zo{constructor(e,t,i,s=null){super(e,t,new $o,null,s),this.shader=i,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 Lr[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"),Zn[t]!==void 0){const i=Zn[t],s=this.shader;s.vertexShader=i.vertexShader,s.fragmentShader=i.fragmentShader,s.uniforms=gi.merge([i.uniforms,us.lights])}}_parseObject(){const{material:e,renderer:t}=this;this.addSlot("fragment",new be({node:er,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:Ot("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:Ot("alphatest_fragment"),target:"diffuseColor.a = %RESULT%;",inclusionType:"append"})),e.normalNode&&e.normalNode.isNode&&this.addSlot("fragment",new be({node:e.normalNode,nodeType:"vec3",source:Ot("normal_fragment_begin"),target:"normal = %RESULT%;",inclusionType:"append"})),e.emissiveNode&&e.emissiveNode.isNode&&this.addSlot("fragment",new be({node:e.emissiveNode,nodeType:"vec3",source:Ot("emissivemap_fragment"),target:"totalEmissiveRadiance = %RESULT%;",inclusionType:"append"})),e.isMeshStandardNodeMaterial&&(e.metalnessNode&&e.metalnessNode.isNode&&this.addSlot("fragment",new be({node:e.metalnessNode,nodeType:"float",source:Ot("metalnessmap_fragment"),target:"metalnessFactor = %RESULT%;",inclusionType:"append"})),e.roughnessNode&&e.roughnessNode.isNode&&this.addSlot("fragment",new be({node:e.roughnessNode,nodeType:"float",source:Ot("roughnessmap_fragment"),target:"roughnessFactor = %RESULT%;",inclusionType:"append"})),e.isMeshPhysicalNodeMaterial&&(e.clearcoatNode&&e.clearcoatNode.isNode?(this.addSlot("fragment",new 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:Ot("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,i){return e.isTextureCube?`textureCube( ${t}, ${i} )`:`texture2D( ${t}, ${i} )`}generateTextureLevel(e,t,i,s){return`textureLod( ${t}, ${i}, ${s} )`}buildFunctionCode(e){const t=e.layout,i=this.flowShaderNode(e),s=[];for(const n of t.inputs)s.push(this.getType(n.type)+" "+n.name);return`${this.getType(t.type)} ${t.name}( ${s.join(", ")} ) {
${i.vars}
${i.code}
return ${i.result};
}`}getUniforms(e){const t=this.uniforms[e];let i="";for(const s of t){if(/^(modelViewMatrix|projectionMatrix)$/.test(s.name))continue;let n=null;s.type==="texture"?n=`sampler2D ${s.name}; `:s.type==="cubeTexture"?n=`samplerCube ${s.name}; `:n=`${this.getVectorType(s.type)} ${s.name}; `;const a=s.node.precision;a!==null?n="uniform "+Nr[a]+" "+n:n="uniform "+n,i+=n}return i}getAttributes(e){let t="";if(e==="vertex"){const i=this.attributes;for(const s of i)/^(position|normal|uv[1-3]?)$/.test(s.name)||(t+=`attribute ${s.type} ${s.name}; `)}return t}getVaryings(e){let t="";const i=this.varyings;if(e==="vertex")for(const s of i)t+=`${s.needsInterpolation?"varying":"/*varying*/"} ${s.type} ${s.name}; `;else if(e==="fragment")for(const s of i)s.needsInterpolation&&(t+=`varying ${s.type} ${s.name}; `);return t}addCode(e,t,i,s=this){const n=Bs(e);let a=s[n];const r=a.indexOf(t);if(r!==-1){const A=a.substring(0,r+t.length),c=a.substring(r+t.length);a=`${A}
${i}
${c}`}s[n]=a}replaceCode(e,t,i,s=this){const n=Bs(e);s[n]=s[n].replaceAll(t,i)}getVertexIndex(){return"gl_VertexID"}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord"}isFlipY(){return!0}buildCode(){const e={};for(const t of Hs){const i=this.getUniforms(t),s=this.getAttributes(t),n=this.getVaryings(t);let a=this.getVars(t);a=a.replace("mat4 modelViewMatrix;","");const r=this.getCodes(t);e[t]=`${this.getSignature()}
// <node_builder>
// uniforms
${i}
// attributes
${s}
// varyings
${n}
// vars
${a}
// codes
${r}
// </node_builder>
${this.shader[Bs(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 i of t){const s=Ot(i),n=tr[i],a=Bs(e);this.shader[a]=this.shader[a].replaceAll(s,n)}}_sortSlotsToFlow(){for(const e of Hs){const t=this.shader[Bs(e)],i=this.slots[e].sort((s,n)=>t.indexOf(s.source)>t.indexOf(n.source)?1:-1);for(const s of i)this.addFlow(e,s)}}_addSnippets(){for(const e of Hs){for(const t of this.slots[e]){const i=this.getFlowData(t),s=t.inclusionType,n=t.source,a=i.code+`
`+t.target.replace("%RESULT%",i.result);s==="append"?this.addCode(e,n,a):s==="replace"?this.replaceCode(e,n,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(){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 $n=new WeakMap;Kt.prototype.onBuild=function(o,e,t){const i=this;if(i.isNodeMaterial===!0){let s;try{s=new Ur(o,t,e,i).build(),$n.set(i,s)}catch(n){console.error("Material.prototype.onBuild: ",n)}}},Kt.prototype.onBeforeRender=function(o,e,t,i,s){const n=$n.get(this);if(n!==void 0){et.material=this,et.camera=t,et.object=s,et.renderer=o,et.scene=e,et.geometry=i;const a=n.updateNodes;if(a.length>0){o.state.useProgram(null);for(const r of a)et.updateNode(r)}}};var ws=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(),i(++o%e.children.length)},!1);function t(l){return e.appendChild(l.dom),l}function i(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(),n=s,a=0,r=t(new ws.Panel("FPS","#0ff","#002")),A=t(new ws.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var c=t(new ws.Panel("MB","#f08","#201"));return i(0),{REVISION:16,dom:e,addPanel:t,showPanel:i,begin:function(){s=(performance||Date).now()},end:function(){a++;var l=(performance||Date).now();if(A.update(l-s,200),l>=n+1e3&&(r.update(a*1e3/(l-n),100),n=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:i}};ws.Panel=function(o,e,t){var i=1/0,s=0,n=Math.round,a=n(window.devicePixelRatio||1),r=80*a,A=48*a,c=3*a,l=2*a,h=3*a,d=15*a,p=74*a,f=30*a,b=document.createElement("canvas");b.width=r,b.height=A,b.style.cssText="width:80px;height:48px";var m=b.getContext("2d");return m.font="bold "+9*a+"px Helvetica,Arial,sans-serif",m.textBaseline="top",m.fillStyle=t,m.fillRect(0,0,r,A),m.fillStyle=e,m.fillText(o,c,l),m.fillRect(h,d,p,f),m.fillStyle=t,m.globalAlpha=.9,m.fillRect(h,d,p,f),{dom:b,update:function(I,E){i=Math.min(i,I),s=Math.max(s,I),m.fillStyle=t,m.globalAlpha=1,m.fillRect(0,0,r,d),m.fillStyle=e,m.fillText(n(I)+" "+o+" ("+n(i)+"-"+n(s)+")",c,l),m.drawImage(b,h+a,d,p-a,f,h,d,p-a,f),m.fillRect(h+p-a,d,a,f),m.fillStyle=t,m.globalAlpha=.9,m.fillRect(h+p-a,d,a,n((1-I/E)*f))}}};function Gr(o,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},i=o.getIndex(),s=o.getAttribute("position"),n=i?i.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 y=r[E],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 _=new T.array.constructor(T.count*T.itemSize);c[y][S]=new T.constructor(_,T.itemSize,T.normalized)}))}const p=e*.5,f=Math.log10(1/e),b=Math.pow(10,f),m=p*b;for(let E=0;E<n;E++){const C=i?i.getX(E):E;let y="";for(let w=0,x=r.length;w<x;w++){const T=r[w],S=o.getAttribute(T),_=S.itemSize;for(let Y=0;Y<_;Y++)y+=`${~~(S[h[Y]](C)*b+m)},`}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),_=o.morphAttributes[T],Y=S.itemSize,V=A[T],K=c[T];for(let W=0;W<Y;W++){const j=h[W],X=d[W];if(V[X](a,S[j](C)),_)for(let J=0,ee=_.length;J<ee;J++)K[J][X](a,_[J][j](C))}}t[y]=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 y=0;y<c[E].length;y++){const w=c[E][y];I.morphAttributes[E][y]=new w.constructor(w.array.slice(0,a*w.itemSize),w.itemSize,w.normalized)}}return I.setIndex(l),I}function ea(o,e){if(e===sr)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),o;if(e===di||e===xn){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 i=t.count-2,s=[];if(e===di)for(let a=1;a<=i;a++)s.push(t.getX(0)),s.push(t.getX(a)),s.push(t.getX(a+1));else for(let a=0;a<i;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!==i&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const n=o.clone();return n.setIndex(s),n.clearGroups(),n}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),o}class _i extends Tt{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new qr(t)}),this.register(function(t){return new zr(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 Kr(t)}),this.register(function(t){return new Jr(t)}),this.register(function(t){return new Vr(t)}),this.register(function(t){return new Wr(t)}),this.register(function(t){return new jr(t)}),this.register(function(t){return new Xr(t)}),this.register(function(t){return new Yr(t)}),this.register(function(t){return new $r(t)}),this.register(function(t){return new Zr(t)}),this.register(function(t){return new Or(t)}),this.register(function(t){return new iA(t)}),this.register(function(t){return new nA(t)})}load(e,t,i,s){const n=this;let a;if(this.resourcePath!=="")a=this.resourcePath;else if(this.path!==""){const c=Jt.extractUrlBase(e);a=Jt.resolveURL(c,this.path)}else a=Jt.extractUrlBase(e);this.manager.itemStart(e);const r=function(c){s?s(c):console.error(c),n.manager.itemError(e),n.manager.itemEnd(e)},A=new dt(this.manager);A.setPath(this.path),A.setResponseType("arraybuffer"),A.setRequestHeader(this.requestHeader),A.setWithCredentials(this.withCredentials),A.load(e,function(c){try{n.parse(c,a,function(l){t(l),n.manager.itemEnd(e)},r)}catch(l){r(l)}},i,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,i,s){let n,a;const r={},A={},c=new TextDecoder;if(typeof e=="string")try{n=JSON.parse(e)}catch(h){a=e,s&&s(h);return}else if(e instanceof ArrayBuffer)if(c.decode(new Uint8Array(e,0,4))===ta){try{r[ne.KHR_BINARY_GLTF]=new aA(e)}catch(h){s&&s(h);return}try{n=JSON.parse(r[ne.KHR_BINARY_GLTF].content)}catch(h){a=r[ne.KHR_BINARY_GLTF].content,s&&s(h);return}}else try{n=JSON.parse(c.decode(e))}catch(h){a=c.decode(e),s&&s(h);return}else n=e;if(n.asset===void 0||n.asset.version[0]<2){s&&s(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}this.json=n,this.jsonErrorData=a;const l=new bA(n,{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(n.extensionsUsed)for(let h=0;h<n.extensionsUsed.length;++h){const d=n.extensionsUsed[h],p=n.extensionsRequired||[];switch(d){case ne.KHR_MATERIALS_UNLIT:r[d]=new Hr;break;case ne.KHR_DRACO_MESH_COMPRESSION:r[d]=new oA(n,this.dracoLoader);break;case ne.KHR_TEXTURE_TRANSFORM:r[d]=new rA;break;case ne.KHR_MESH_QUANTIZATION:r[d]=new AA;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(i,s)}parseAsync(e,t){const i=this;return new Promise(function(s,n){i.parse(e,t,s,n)})}}function Pr(){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 Or{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 i=0,s=t.length;i<s;i++){const n=t[i];n.extensions&&n.extensions[this.name]&&n.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(e){const t=this.parser,i="light:"+e;let s=t.cache.get(i);if(s)return s;const n=t.json,a=((n.extensions&&n.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],We);const c=a.range!==void 0?a.range:0;switch(a.type){case"directional":r=new Tn(A),r.target.position.set(0,0,-1),r.add(r.target);break;case"point":r=new pi(A),r.distance=c;break;case"spot":r=new Sn(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,kt(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(i,s),s}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,i=this.parser,s=i.json.nodes[e],n=(s.extensions&&s.extensions[this.name]||{}).light;return n===void 0?null:this._loadLight(n).then(function(a){return i._getNodeRef(t.cache,n,a)})}}let Hr=class{constructor(){this.name=ne.KHR_MATERIALS_UNLIT}getMaterialType(){return It}extendParams(o,e,t){const i=[];o.color=new we(1,1,1),o.opacity=1;const s=e.pbrMetallicRoughness;if(s){if(Array.isArray(s.baseColorFactor)){const n=s.baseColorFactor;o.color.setRGB(n[0],n[1],n[2],We),o.opacity=n[3]}s.baseColorTexture!==void 0&&i.push(t.assignTexture(o,"map",s.baseColorTexture,le))}return Promise.all(i)}},jr=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 i=t.extensions[this.name].emissiveStrength;return i!==void 0&&(e.emissiveIntensity=i),Promise.resolve()}},qr=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,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];if(n.clearcoatFactor!==void 0&&(e.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&s.push(t.assignTexture(e,"clearcoatMap",n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&s.push(t.assignTexture(e,"clearcoatRoughnessMap",n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(s.push(t.assignTexture(e,"clearcoatNormalMap",n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){const a=n.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new Le(a,a)}return Promise.all(s)}},zr=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 i=t.extensions[this.name];return e.dispersion=i.dispersion!==void 0?i.dispersion:0,Promise.resolve()}},Yr=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,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];return n.iridescenceFactor!==void 0&&(e.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&s.push(t.assignTexture(e,"iridescenceMap",n.iridescenceTexture)),n.iridescenceIor!==void 0&&(e.iridescenceIOR=n.iridescenceIor),e.iridescenceThicknessRange===void 0&&(e.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(e.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(e.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&s.push(t.assignTexture(e,"iridescenceThicknessMap",n.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,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[];e.sheenColor=new we(0,0,0),e.sheenRoughness=0,e.sheen=1;const n=i.extensions[this.name];if(n.sheenColorFactor!==void 0){const a=n.sheenColorFactor;e.sheenColor.setRGB(a[0],a[1],a[2],We)}return n.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&s.push(t.assignTexture(e,"sheenColorMap",n.sheenColorTexture,le)),n.sheenRoughnessTexture!==void 0&&s.push(t.assignTexture(e,"sheenRoughnessMap",n.sheenRoughnessTexture)),Promise.all(s)}},Jr=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,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];return n.transmissionFactor!==void 0&&(e.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&s.push(t.assignTexture(e,"transmissionMap",n.transmissionTexture)),Promise.all(s)}},Vr=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,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];e.thickness=n.thicknessFactor!==void 0?n.thicknessFactor:0,n.thicknessTexture!==void 0&&s.push(t.assignTexture(e,"thicknessMap",n.thicknessTexture)),e.attenuationDistance=n.attenuationDistance||1/0;const a=n.attenuationColor||[1,1,1];return e.attenuationColor=new we().setRGB(a[0],a[1],a[2],We),Promise.all(s)}},Wr=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 i=t.extensions[this.name];return e.ior=i.ior!==void 0?i.ior:1.5,Promise.resolve()}},Xr=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,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];e.specularIntensity=n.specularFactor!==void 0?n.specularFactor:1,n.specularTexture!==void 0&&s.push(t.assignTexture(e,"specularIntensityMap",n.specularTexture));const a=n.specularColorFactor||[1,1,1];return e.specularColor=new we().setRGB(a[0],a[1],a[2],We),n.specularColorTexture!==void 0&&s.push(t.assignTexture(e,"specularColorMap",n.specularColorTexture,le)),Promise.all(s)}},Zr=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,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];return e.bumpScale=n.bumpFactor!==void 0?n.bumpFactor:1,n.bumpTexture!==void 0&&s.push(t.assignTexture(e,"bumpMap",n.bumpTexture)),Promise.all(s)}},$r=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,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];return n.anisotropyStrength!==void 0&&(e.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(e.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&s.push(t.assignTexture(e,"anisotropyMap",n.anisotropyTexture)),Promise.all(s)}};class eA{constructor(e){this.parser=e,this.name=ne.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,i=t.json,s=i.textures[e];if(!s.extensions||!s.extensions[this.name])return null;const n=s.extensions[this.name],a=t.options.ktx2Loader;if(!a){if(i.extensionsRequired&&i.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,n.source,a)}}class tA{constructor(e){this.parser=e,this.name=ne.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,i=this.parser,s=i.json,n=s.textures[e];if(!n.extensions||!n.extensions[t])return null;const a=n.extensions[t],r=s.images[a.source];let A=i.textureLoader;if(r.uri){const c=i.options.manager.getHandler(r.uri);c!==null&&(A=c)}return this.detectSupport().then(function(c){if(c)return i.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 i.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 sA{constructor(e){this.parser=e,this.name=ne.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,i=this.parser,s=i.json,n=s.textures[e];if(!n.extensions||!n.extensions[t])return null;const a=n.extensions[t],r=s.images[a.source];let A=i.textureLoader;if(r.uri){const c=i.options.manager.getHandler(r.uri);c!==null&&(A=c)}return this.detectSupport().then(function(c){if(c)return i.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 i.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(t.height===1)}})),this.isSupported}}class iA{constructor(e){this.name=ne.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,i=t.bufferViews[e];if(i.extensions&&i.extensions[this.name]){const s=i.extensions[this.name],n=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 n.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 i=e.meshes[t.mesh];for(const r of i.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,n=[],a={};for(const r in s)n.push(this.parser.getDependency("accessor",s[r]).then(A=>(a[r]=A,a[r])));return n.length<1?null:(n.push(this.parser.createNodeMesh(o)),Promise.all(n).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 ce,f=new N,b=new ye,m=new N(1,1,1),I=new ir(d.geometry,d.material,l);for(let E=0;E<l;E++)a.TRANSLATION&&f.fromBufferAttribute(a.TRANSLATION,E),a.ROTATION&&b.fromBufferAttribute(a.ROTATION,E),a.SCALE&&m.fromBufferAttribute(a.SCALE,E),I.setMatrixAt(E,p.compose(f,b,m));for(const E in a)if(E==="_COLOR_0"){const C=a[E];I.instanceColor=new nr(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 ta="glTF",ys=12,sa={JSON:1313821514,BIN:5130562};class aA{constructor(e){this.name=ne.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,ys),i=new TextDecoder;if(this.header={magic:i.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==ta)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-ys,n=new DataView(e,ys);let a=0;for(;a<s;){const r=n.getUint32(a,!0);a+=4;const A=n.getUint32(a,!0);if(a+=4,A===sa.JSON){const c=new Uint8Array(e,ys+a,r);this.content=i.decode(c)}else if(A===sa.BIN){const c=ys+a;this.body=e.slice(c,c+r)}a+=r}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class oA{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 i=this.json,s=this.dracoLoader,n=e.extensions[this.name].bufferView,a=e.extensions[this.name].attributes,r={},A={},c={};for(const l in a){const h=Li[l]||l.toLowerCase();r[h]=a[l]}for(const l in e.attributes){const h=Li[l]||l.toLowerCase();if(a[l]!==void 0){const d=i.accessors[e.attributes[l]],p=cs[d.componentType];c[h]=p.name,A[h]=d.normalized===!0}}return t.getDependency("bufferView",n).then(function(l){return new Promise(function(h,d){s.decodeDracoFile(l,function(p){for(const f in p.attributes){const b=p.attributes[f],m=A[f];m!==void 0&&(b.normalized=m)}h(p)},r,c,We,d)})})}}class rA{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 AA{constructor(){this.name=ne.KHR_MESH_QUANTIZATION}}class ia extends Ar{constructor(e,t,i,s){super(e,t,i,s)}copySampleValue_(e){const t=this.resultBuffer,i=this.sampleValues,s=this.valueSize,n=e*s*3+s;for(let a=0;a!==s;a++)t[a]=i[n+a];return t}interpolate_(e,t,i,s){const n=this.resultBuffer,a=this.sampleValues,r=this.valueSize,A=r*2,c=r*3,l=s-t,h=(i-t)/l,d=h*h,p=d*h,f=e*c,b=f-c,m=-2*p+3*d,I=p-d,E=1-m,C=I-d+h;for(let y=0;y!==r;y++){const w=a[b+y+r],x=a[b+y+A]*l,T=a[f+y+r],S=a[f+y]*l;n[y]=E*w+C*x+m*T+I*S}return n}}const cA=new ye;class lA extends ia{interpolate_(e,t,i,s){const n=super.interpolate_(e,t,i,s);return cA.fromArray(n).normalize().toArray(n),n}}const lt={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},cs={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},na={9728:js,9729:at,9984:fi,9985:Rn,9986:Dn,9987:fs},aa={33071:qs,33648:Mn,10497:Vt},Fi={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Li={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"},Ht={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},hA={CUBICSPLINE:void 0,LINEAR:Ei,STEP:Nn},Ni={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function gA(o){return o.DefaultMaterial===void 0&&(o.DefaultMaterial=new mi({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:Un})),o.DefaultMaterial}function Zt(o,e,t){for(const i in t.extensions)o[i]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[i]=t.extensions[i])}function kt(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 dA(o,e,t){let i=!1,s=!1,n=!1;for(let c=0,l=e.length;c<l;c++){const h=e[c];if(h.POSITION!==void 0&&(i=!0),h.NORMAL!==void 0&&(s=!0),h.COLOR_0!==void 0&&(n=!0),i&&s&&n)break}if(!i&&!s&&!n)return Promise.resolve(o);const a=[],r=[],A=[];for(let c=0,l=e.length;c<l;c++){const h=e[c];if(i){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(n){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 i&&(o.morphAttributes.position=l),s&&(o.morphAttributes.normal=h),n&&(o.morphAttributes.color=d),o.morphTargetsRelative=!0,o})}function pA(o,e){if(o.updateMorphTargets(),e.weights!==void 0)for(let t=0,i=e.weights.length;t<i;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 i=0,s=t.length;i<s;i++)o.morphTargetDictionary[t[i]]=i}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function uA(o){let e;const t=o.extensions&&o.extensions[ne.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Ui(t.attributes):e=o.indices+":"+Ui(o.attributes)+":"+o.mode,o.targets!==void 0)for(let i=0,s=o.targets.length;i<s;i++)e+=":"+Ui(o.targets[i]);return e}function Ui(o){let e="";const t=Object.keys(o).sort();for(let i=0,s=t.length;i<s;i++)e+=t[i]+":"+o[t[i]]+";";return e}function Gi(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 fA(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 mA=new ce;class bA{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Pr,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 i=!1,s=-1,n=!1,a=-1;if(typeof navigator<"u"){const r=navigator.userAgent;i=/^((?!chrome|android).)*safari/i.test(r)===!0;const A=r.match(/Version\/(\d+)/);s=i&&A?parseInt(A[1],10):-1,n=r.indexOf("Firefox")>-1,a=n?r.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||i&&s<17||n&&a<98?this.textureLoader=new ui(this.options.manager):this.textureLoader=new ar(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new dt(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 i=this,s=this.json,n=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([i.getDependencies("scene"),i.getDependencies("animation"),i.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:i,userData:{}};return Zt(n,r,s),kt(r,s),Promise.all(i._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||[],i=this.json.meshes||[];for(let s=0,n=t.length;s<n;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,n=e.length;s<n;s++){const a=e[s];a.mesh!==void 0&&(this._addNodeRef(this.meshCache,a.mesh),a.skin!==void 0&&(i[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,i){if(e.refs[t]<=1)return i;const s=i.clone(),n=(a,r)=>{const A=this.associations.get(a);A!=null&&this.associations.set(r,A);for(const[c,l]of a.children.entries())n(l,r.children[c])};return n(i,s),s.name+="_instance_"+e.uses[t]++,s}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let i=0;i<t.length;i++){const s=e(t[i]);if(s)return s}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const i=[];for(let s=0;s<t.length;s++){const n=e(t[s]);n&&i.push(n)}return i}getDependency(e,t){const i=e+":"+t;let s=this.cache.get(i);if(!s){switch(e){case"scene":s=this.loadScene(t);break;case"node":s=this._invokeOne(function(n){return n.loadNode&&n.loadNode(t)});break;case"mesh":s=this._invokeOne(function(n){return n.loadMesh&&n.loadMesh(t)});break;case"accessor":s=this.loadAccessor(t);break;case"bufferView":s=this._invokeOne(function(n){return n.loadBufferView&&n.loadBufferView(t)});break;case"buffer":s=this.loadBuffer(t);break;case"material":s=this._invokeOne(function(n){return n.loadMaterial&&n.loadMaterial(t)});break;case"texture":s=this._invokeOne(function(n){return n.loadTexture&&n.loadTexture(t)});break;case"skin":s=this.loadSkin(t);break;case"animation":s=this._invokeOne(function(n){return n.loadAnimation&&n.loadAnimation(t)});break;case"camera":s=this.loadCamera(t);break;default:if(s=this._invokeOne(function(n){return n!=this&&n.getDependency&&n.getDependency(e,t)}),!s)throw new Error("Unknown type: "+e);break}this.cache.add(i,s)}return s}getDependencies(e){let t=this.cache.get(e);if(!t){const i=this,s=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(s.map(function(n,a){return i.getDependency(e,a)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],i=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(n,a){i.load(Jt.resolveURL(t.uri,s.path),n,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(i){const s=t.byteLength||0,n=t.byteOffset||0;return i.slice(n,n+s)})}loadAccessor(e){const t=this,i=this.json,s=this.json.accessors[e];if(s.bufferView===void 0&&s.sparse===void 0){const a=Fi[s.type],r=cs[s.componentType],A=s.normalized===!0,c=new r(s.count*a);return Promise.resolve(new nt(c,a,A))}const n=[];return s.bufferView!==void 0?n.push(this.getDependency("bufferView",s.bufferView)):n.push(null),s.sparse!==void 0&&(n.push(this.getDependency("bufferView",s.sparse.indices.bufferView)),n.push(this.getDependency("bufferView",s.sparse.values.bufferView))),Promise.all(n).then(function(a){const r=a[0],A=Fi[s.type],c=cs[s.componentType],l=c.BYTES_PER_ELEMENT,h=l*A,d=s.byteOffset||0,p=s.bufferView!==void 0?i.bufferViews[s.bufferView].byteStride:void 0,f=s.normalized===!0;let b,m;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||(b=new c(r,I*p,s.count*p/l),C=new or(b,p/l),t.cache.add(E,C)),m=new Xt(C,A,d%p/l,f)}else r===null?b=new c(s.count*A):b=new c(r,d,s.count*A),m=new nt(b,A,f);if(s.sparse!==void 0){const I=Fi.SCALAR,E=cs[s.sparse.indices.componentType],C=s.sparse.indices.byteOffset||0,y=s.sparse.values.byteOffset||0,w=new E(a[1],C,s.sparse.count*I),x=new c(a[2],y,s.sparse.count*A);r!==null&&(m=new nt(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let T=0,S=w.length;T<S;T++){const _=w[T];if(m.setX(_,x[T*A]),A>=2&&m.setY(_,x[T*A+1]),A>=3&&m.setZ(_,x[T*A+2]),A>=4&&m.setW(_,x[T*A+3]),A>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=f}return m})}loadTexture(e){const t=this.json,i=this.options,s=t.textures[e].source,n=t.images[s];let a=this.textureLoader;if(n.uri){const r=i.manager.getHandler(n.uri);r!==null&&(a=r)}return this.loadTextureImage(e,s,a)}loadTextureImage(e,t,i){const s=this,n=this.json,a=n.textures[e],r=n.images[t],A=(r.uri||r.bufferView)+":"+a.sampler;if(this.textureCache[A])return this.textureCache[A];const c=this.loadImageSource(t,i).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=(n.samplers||{})[a.sampler]||{};return l.magFilter=na[h.magFilter]||at,l.minFilter=na[h.minFilter]||fs,l.wrapS=aa[h.wrapS]||Vt,l.wrapT=aa[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 i=this,s=this.json,n=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(h=>h.clone());const a=s.images[e],r=self.URL