@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) • 368 kB
JavaScript
"use strict";const r=require("./three.umd.cjs");class yo extends r.Mesh{constructor(e,t,s,n=128){if(t<=0||s<=0||n<=0)throw new Error("GroundedSkybox height, radius, and resolution must be positive.");const i=new r.SphereGeometry(s,2*n,n);i.scale(1,1,-1);const o=i.getAttribute("position"),a=new r.Vector3;for(let A=0;A<o.count;++A)if(a.fromBufferAttribute(o,A),a.y<0){const l=-t*3/2,h=a.y<l?-t/a.y:1-a.y*a.y/(3*l*l);a.multiplyScalar(h),a.toArray(o.array,3*A)}o.needsUpdate=!0,super(i,new r.MeshBasicMaterial({map:e,depthWrite:!1}))}}class be extends r.Node{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 Ue=new r.NodeFrame;Ue.camera=new r.PerspectiveCamera;const us={LineBasicNodeMaterial:r.ShaderLib.basic,MeshBasicNodeMaterial:r.ShaderLib.basic,PointsNodeMaterial:r.ShaderLib.points,MeshStandardNodeMaterial:r.ShaderLib.standard,MeshPhysicalNodeMaterial:r.ShaderLib.physical,MeshPhongNodeMaterial:r.ShaderLib.phong},wo={atan2:"atan"},Qo={low:"lowp",medium:"mediump",high:"highp"};function ut(c){return`#include <${c}>`}function Ft(c){return`${c}Shader`}class xo extends r.NodeBuilder{constructor(e,t,s,n=null){super(e,t,new r.GLSLNodeParser,null,n),this.shader=s,this.slots={vertex:[],fragment:[]},this._parseShaderLib(),this._parseInclude("fragment","lights_physical_fragment","clearcoat_normal_fragment_begin","transmission_fragment"),this._parseObject(),this._sortSlotsToFlow(),this.useComparisonMethod=!0}getMethod(e){return wo[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"),us[t]!==void 0){const s=us[t],n=this.shader;n.vertexShader=s.vertexShader,n.fragmentShader=s.fragmentShader,n.uniforms=r.UniformsUtils.merge([s.uniforms,r.UniformsLib.lights])}}_parseObject(){const{material:e,renderer:t}=this;this.addSlot("fragment",new be({node:r.normalView,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:ut("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:ut("alphatest_fragment"),target:"diffuseColor.a = %RESULT%;",inclusionType:"append"})),e.normalNode&&e.normalNode.isNode&&this.addSlot("fragment",new be({node:e.normalNode,nodeType:"vec3",source:ut("normal_fragment_begin"),target:"normal = %RESULT%;",inclusionType:"append"})),e.emissiveNode&&e.emissiveNode.isNode&&this.addSlot("fragment",new be({node:e.emissiveNode,nodeType:"vec3",source:ut("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:ut("metalnessmap_fragment"),target:"metalnessFactor = %RESULT%;",inclusionType:"append"})),e.roughnessNode&&e.roughnessNode.isNode&&this.addSlot("fragment",new be({node:e.roughnessNode,nodeType:"float",source:ut("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:ut("begin_vertex"),target:"transformed = %RESULT%;",inclusionType:"append"})),e.sizeNode&&e.sizeNode.isNode&&this.addSlot("vertex",new be({node:e.sizeNode,nodeType:"float",source:"gl_PointSize = size;",target:"gl_PointSize = %RESULT%;"}))}generateTexture(e,t,s){return e.isTextureCube?`textureCube( ${t}, ${s} )`:`texture2D( ${t}, ${s} )`}generateTextureLevel(e,t,s,n){return`textureLod( ${t}, ${s}, ${n} )`}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),n=[];for(const o of t.inputs)n.push(this.getType(o.type)+" "+o.name);return`${this.getType(t.type)} ${t.name}( ${n.join(", ")} ) {
${s.vars}
${s.code}
return ${s.result};
}`}getUniforms(e){const t=this.uniforms[e];let s="";for(const n of t){if(/^(modelViewMatrix|projectionMatrix)$/.test(n.name))continue;let i=null;n.type==="texture"?i=`sampler2D ${n.name}; `:n.type==="cubeTexture"?i=`samplerCube ${n.name}; `:i=`${this.getVectorType(n.type)} ${n.name}; `;const o=n.node.precision;o!==null?i="uniform "+Qo[o]+" "+i:i="uniform "+i,s+=i}return s}getAttributes(e){let t="";if(e==="vertex"){const s=this.attributes;for(const n of s)/^(position|normal|uv[1-3]?)$/.test(n.name)||(t+=`attribute ${n.type} ${n.name}; `)}return t}getVaryings(e){let t="";const s=this.varyings;if(e==="vertex")for(const n of s)t+=`${n.needsInterpolation?"varying":"/*varying*/"} ${n.type} ${n.name}; `;else if(e==="fragment")for(const n of s)n.needsInterpolation&&(t+=`varying ${n.type} ${n.name}; `);return t}addCode(e,t,s,n=this){const i=Ft(e);let o=n[i];const a=o.indexOf(t);if(a!==-1){const A=o.substring(0,a+t.length),l=o.substring(a+t.length);o=`${A}
${s}
${l}`}n[i]=o}replaceCode(e,t,s,n=this){const i=Ft(e);n[i]=n[i].replaceAll(t,s)}getVertexIndex(){return"gl_VertexID"}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord"}isFlipY(){return!0}buildCode(){const e={};for(const t of r.defaultShaderStages){const s=this.getUniforms(t),n=this.getAttributes(t),i=this.getVaryings(t);let o=this.getVars(t);o=o.replace("mat4 modelViewMatrix;","");const a=this.getCodes(t);e[t]=`${this.getSignature()}
// <node_builder>
// uniforms
${s}
// attributes
${n}
// varyings
${i}
// vars
${o}
// codes
${a}
// </node_builder>
${this.shader[Ft(t)]}
`}this.vertexShader=e.vertex,this.fragmentShader=e.fragment}build(){return super.build(!1),this._addSnippets(),this._addUniforms(),this._updateUniforms(),this.shader.vertexShader=this.vertexShader,this.shader.fragmentShader=this.fragmentShader,this}_parseInclude(e,...t){for(const s of t){const n=ut(s),i=r.ShaderChunk[s],o=Ft(e);this.shader[o]=this.shader[o].replaceAll(n,i)}}_sortSlotsToFlow(){for(const e of r.defaultShaderStages){const t=this.shader[Ft(e)],s=this.slots[e].sort((n,i)=>t.indexOf(n.source)>t.indexOf(i.source)?1:-1);for(const n of s)this.addFlow(e,n)}}_addSnippets(){for(const e of r.defaultShaderStages){for(const t of this.slots[e]){const s=this.getFlowData(t),n=t.inclusionType,i=t.source,o=s.code+`
`+t.target.replace("%RESULT%",s.result);n==="append"?this.addCode(e,i,o):n==="replace"?this.replaceCode(e,i,o):console.warn(`Inclusion type "${n}" not compatible.`)}this.addCode(e,"main() {",`
`+this.flowCode[e])}}_addUniforms(){for(const e of r.defaultShaderStages)for(const t of this.uniforms[e])this.shader.uniforms[t.name]=t}_updateUniforms(){Ue.object=this.object,Ue.renderer=this.renderer,Ue.material=this.material,Ue.scene=this.scene;for(const e of this.updateNodes)Ue.updateNode(e)}}const si=new WeakMap;r.Material.prototype.onBuild=function(c,e,t){const s=this;if(s.isNodeMaterial===!0){let n;try{n=new xo(c,t,e,s).build(),si.set(s,n)}catch(i){console.error("Material.prototype.onBuild: ",i)}}};r.Material.prototype.onBeforeRender=function(c,e,t,s,n){const i=si.get(this);if(i!==void 0){Ue.material=this,Ue.camera=t,Ue.object=n,Ue.renderer=c,Ue.scene=e,Ue.geometry=s;const o=i.updateNodes;if(o.length>0){c.state.useProgram(null);for(const a of o)Ue.updateNode(a)}}};var Jt=function(){var c=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(h){h.preventDefault(),s(++c%e.children.length)},!1);function t(h){return e.appendChild(h.dom),h}function s(h){for(var u=0;u<e.children.length;u++)e.children[u].style.display=u===h?"block":"none";c=h}var n=(performance||Date).now(),i=n,o=0,a=t(new Jt.Panel("FPS","#0ff","#002")),A=t(new Jt.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var l=t(new Jt.Panel("MB","#f08","#201"));return s(0),{REVISION:16,dom:e,addPanel:t,showPanel:s,begin:function(){n=(performance||Date).now()},end:function(){o++;var h=(performance||Date).now();if(A.update(h-n,200),h>=i+1e3&&(a.update(o*1e3/(h-i),100),i=h,o=0,l)){var u=performance.memory;l.update(u.usedJSHeapSize/1048576,u.jsHeapSizeLimit/1048576)}return h},update:function(){n=this.end()},domElement:e,setMode:s}};Jt.Panel=function(c,e,t){var s=1/0,n=0,i=Math.round,o=i(window.devicePixelRatio||1),a=80*o,A=48*o,l=3*o,h=2*o,u=3*o,p=15*o,g=74*o,m=30*o,I=document.createElement("canvas");I.width=a,I.height=A,I.style.cssText="width:80px;height:48px";var b=I.getContext("2d");return b.font="bold "+9*o+"px Helvetica,Arial,sans-serif",b.textBaseline="top",b.fillStyle=t,b.fillRect(0,0,a,A),b.fillStyle=e,b.fillText(c,l,h),b.fillRect(u,p,g,m),b.fillStyle=t,b.globalAlpha=.9,b.fillRect(u,p,g,m),{dom:I,update:function(B,w){s=Math.min(s,B),n=Math.max(n,B),b.fillStyle=t,b.globalAlpha=1,b.fillRect(0,0,a,p),b.fillStyle=e,b.fillText(i(B)+" "+c+" ("+i(s)+"-"+i(n)+")",l,h),b.drawImage(I,u+o,p,g-o,m,u,p,g-o,m),b.fillRect(u+g-o,p,o,m),b.fillStyle=t,b.globalAlpha=.9,b.fillRect(u+g-o,p,o,i((1-B/w)*m))}}};function So(c,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},s=c.getIndex(),n=c.getAttribute("position"),i=s?s.count:n.count;let o=0;const a=Object.keys(c.attributes),A={},l={},h=[],u=["getX","getY","getZ","getW"],p=["setX","setY","setZ","setW"];for(let w=0,C=a.length;w<C;w++){const y=a[w],x=c.attributes[y];A[y]=new x.constructor(new x.array.constructor(x.count*x.itemSize),x.itemSize,x.normalized);const R=c.morphAttributes[y];R&&(l[y]||(l[y]=[]),R.forEach((D,S)=>{const v=new D.array.constructor(D.count*D.itemSize);l[y][S]=new D.constructor(v,D.itemSize,D.normalized)}))}const g=e*.5,m=Math.log10(1/e),I=Math.pow(10,m),b=g*I;for(let w=0;w<i;w++){const C=s?s.getX(w):w;let y="";for(let x=0,R=a.length;x<R;x++){const D=a[x],S=c.getAttribute(D),v=S.itemSize;for(let U=0;U<v;U++)y+=`${~~(S[u[U]](C)*I+b)},`}if(y in t)h.push(t[y]);else{for(let x=0,R=a.length;x<R;x++){const D=a[x],S=c.getAttribute(D),v=c.morphAttributes[D],U=S.itemSize,G=A[D],H=l[D];for(let X=0;X<U;X++){const N=u[X],Y=p[X];if(G[Y](o,S[N](C)),v)for(let O=0,Z=v.length;O<Z;O++)H[O][Y](o,v[O][N](C))}}t[y]=o,h.push(o),o++}}const B=c.clone();for(const w in c.attributes){const C=A[w];if(B.setAttribute(w,new C.constructor(C.array.slice(0,o*C.itemSize),C.itemSize,C.normalized)),w in l)for(let y=0;y<l[w].length;y++){const x=l[w][y];B.morphAttributes[w][y]=new x.constructor(x.array.slice(0,o*x.itemSize),x.itemSize,x.normalized)}}return B.setIndex(h),B}function ds(c,e){if(e===r.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),c;if(e===r.TriangleFanDrawMode||e===r.TriangleStripDrawMode){let t=c.getIndex();if(t===null){const o=[],a=c.getAttribute("position");if(a!==void 0){for(let A=0;A<a.count;A++)o.push(A);c.setIndex(o),t=c.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),c}const s=t.count-2,n=[];if(e===r.TriangleFanDrawMode)for(let o=1;o<=s;o++)n.push(t.getX(0)),n.push(t.getX(o)),n.push(t.getX(o+1));else for(let o=0;o<s;o++)o%2===0?(n.push(t.getX(o)),n.push(t.getX(o+1)),n.push(t.getX(o+2))):(n.push(t.getX(o+2)),n.push(t.getX(o+1)),n.push(t.getX(o)));n.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=c.clone();return i.setIndex(n),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),c}class Zn extends r.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Do(t)}),this.register(function(t){return new _o(t)}),this.register(function(t){return new Ho(t)}),this.register(function(t){return new jo(t)}),this.register(function(t){return new qo(t)}),this.register(function(t){return new Lo(t)}),this.register(function(t){return new ko(t)}),this.register(function(t){return new Go(t)}),this.register(function(t){return new No(t)}),this.register(function(t){return new Ro(t)}),this.register(function(t){return new Uo(t)}),this.register(function(t){return new Fo(t)}),this.register(function(t){return new Oo(t)}),this.register(function(t){return new Po(t)}),this.register(function(t){return new vo(t)}),this.register(function(t){return new zo(t)}),this.register(function(t){return new Yo(t)})}load(e,t,s,n){const i=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const l=r.LoaderUtils.extractUrlBase(e);o=r.LoaderUtils.resolveURL(l,this.path)}else o=r.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=function(l){n?n(l):console.error(l),i.manager.itemError(e),i.manager.itemEnd(e)},A=new r.FileLoader(this.manager);A.setPath(this.path),A.setResponseType("arraybuffer"),A.setRequestHeader(this.requestHeader),A.setWithCredentials(this.withCredentials),A.load(e,function(l){try{i.parse(l,o,function(h){t(h),i.manager.itemEnd(e)},a)}catch(h){a(h)}},s,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,s,n){let i,o;const a={},A={},l=new TextDecoder;if(typeof e=="string")try{i=JSON.parse(e)}catch(u){o=e,n&&n(u);return}else if(e instanceof ArrayBuffer)if(l.decode(new Uint8Array(e,0,4))===ii){try{a[re.KHR_BINARY_GLTF]=new Vo(e)}catch(p){n&&n(p);return}try{i=JSON.parse(a[re.KHR_BINARY_GLTF].content)}catch(p){o=a[re.KHR_BINARY_GLTF].content,n&&n(p);return}}else try{i=JSON.parse(l.decode(e))}catch(p){o=l.decode(e),n&&n(p);return}else i=e;if(i.asset===void 0||i.asset.version[0]<2){n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}this.json=i,this.jsonErrorData=o;const h=new rr(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});h.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){const p=this.pluginCallbacks[u](h);p.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),A[p.name]=p,a[p.name]=!0}if(i.extensionsUsed)for(let u=0;u<i.extensionsUsed.length;++u){const p=i.extensionsUsed[u],g=i.extensionsRequired||[];switch(p){case re.KHR_MATERIALS_UNLIT:a[p]=new Mo;break;case re.KHR_DRACO_MESH_COMPRESSION:a[p]=new Ko(i,this.dracoLoader);break;case re.KHR_TEXTURE_TRANSFORM:a[p]=new Jo;break;case re.KHR_MESH_QUANTIZATION:a[p]=new Wo;break;default:g.indexOf(p)>=0&&A[p]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+p+'".')}}h.setExtensions(a),h.setPlugins(A),h.parse(s,n)}parseAsync(e,t){const s=this;return new Promise(function(n,i){s.parse(e,t,n,i)})}}function To(){let c={};return{get:function(e){return c[e]},add:function(e,t){c[e]=t},remove:function(e){delete c[e]},removeAll:function(){c={}}}}const re={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 vo{constructor(e){this.parser=e,this.name=re.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const i=t[s];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,s="light:"+e;let n=t.cache.get(s);if(n)return n;const i=t.json,A=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let l;const h=new r.Color(16777215);A.color!==void 0&&h.setRGB(A.color[0],A.color[1],A.color[2],r.LinearSRGBColorSpace);const u=A.range!==void 0?A.range:0;switch(A.type){case"directional":l=new r.DirectionalLight(h),l.target.position.set(0,0,-1),l.add(l.target);break;case"point":l=new r.PointLight(h),l.distance=u;break;case"spot":l=new r.SpotLight(h),l.distance=u,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,l.angle=A.spot.outerConeAngle,l.penumbra=1-A.spot.innerConeAngle/A.spot.outerConeAngle,l.target.position.set(0,0,-1),l.add(l.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+A.type)}return l.position.set(0,0,0),l.decay=2,ct(l,A),A.intensity!==void 0&&(l.intensity=A.intensity),l.name=t.createUniqueName(A.name||"light_"+e),n=Promise.resolve(l),t.cache.add(s,n),n}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,i=s.json.nodes[e],a=(i.extensions&&i.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(A){return s._getNodeRef(t.cache,a,A)})}}let Mo=class{constructor(){this.name=re.KHR_MATERIALS_UNLIT}getMaterialType(){return r.MeshBasicMaterial}extendParams(e,t,s){const n=[];e.color=new r.Color(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const o=i.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],r.LinearSRGBColorSpace),e.opacity=o[3]}i.baseColorTexture!==void 0&&n.push(s.assignTexture(e,"map",i.baseColorTexture,r.SRGBColorSpace))}return Promise.all(n)}},Ro=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name].emissiveStrength;return i!==void 0&&(t.emissiveIntensity=i),Promise.resolve()}},Do=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];if(o.clearcoatFactor!==void 0&&(t.clearcoat=o.clearcoatFactor),o.clearcoatTexture!==void 0&&i.push(s.assignTexture(t,"clearcoatMap",o.clearcoatTexture)),o.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=o.clearcoatRoughnessFactor),o.clearcoatRoughnessTexture!==void 0&&i.push(s.assignTexture(t,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),o.clearcoatNormalTexture!==void 0&&(i.push(s.assignTexture(t,"clearcoatNormalMap",o.clearcoatNormalTexture)),o.clearcoatNormalTexture.scale!==void 0)){const a=o.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new r.Vector2(a,a)}return Promise.all(i)}},_o=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_DISPERSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name];return t.dispersion=i.dispersion!==void 0?i.dispersion:0,Promise.resolve()}},Fo=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return o.iridescenceFactor!==void 0&&(t.iridescence=o.iridescenceFactor),o.iridescenceTexture!==void 0&&i.push(s.assignTexture(t,"iridescenceMap",o.iridescenceTexture)),o.iridescenceIor!==void 0&&(t.iridescenceIOR=o.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),o.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=o.iridescenceThicknessMinimum),o.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=o.iridescenceThicknessMaximum),o.iridescenceThicknessTexture!==void 0&&i.push(s.assignTexture(t,"iridescenceThicknessMap",o.iridescenceThicknessTexture)),Promise.all(i)}},Lo=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_SHEEN}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[];t.sheenColor=new r.Color(0,0,0),t.sheenRoughness=0,t.sheen=1;const o=n.extensions[this.name];if(o.sheenColorFactor!==void 0){const a=o.sheenColorFactor;t.sheenColor.setRGB(a[0],a[1],a[2],r.LinearSRGBColorSpace)}return o.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=o.sheenRoughnessFactor),o.sheenColorTexture!==void 0&&i.push(s.assignTexture(t,"sheenColorMap",o.sheenColorTexture,r.SRGBColorSpace)),o.sheenRoughnessTexture!==void 0&&i.push(s.assignTexture(t,"sheenRoughnessMap",o.sheenRoughnessTexture)),Promise.all(i)}},ko=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return o.transmissionFactor!==void 0&&(t.transmission=o.transmissionFactor),o.transmissionTexture!==void 0&&i.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(i)}},Go=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_VOLUME}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];t.thickness=o.thicknessFactor!==void 0?o.thicknessFactor:0,o.thicknessTexture!==void 0&&i.push(s.assignTexture(t,"thicknessMap",o.thicknessTexture)),t.attenuationDistance=o.attenuationDistance||1/0;const a=o.attenuationColor||[1,1,1];return t.attenuationColor=new r.Color().setRGB(a[0],a[1],a[2],r.LinearSRGBColorSpace),Promise.all(i)}},No=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_IOR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name];return t.ior=i.ior!==void 0?i.ior:1.5,Promise.resolve()}},Uo=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_SPECULAR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];t.specularIntensity=o.specularFactor!==void 0?o.specularFactor:1,o.specularTexture!==void 0&&i.push(s.assignTexture(t,"specularIntensityMap",o.specularTexture));const a=o.specularColorFactor||[1,1,1];return t.specularColor=new r.Color().setRGB(a[0],a[1],a[2],r.LinearSRGBColorSpace),o.specularColorTexture!==void 0&&i.push(s.assignTexture(t,"specularColorMap",o.specularColorTexture,r.SRGBColorSpace)),Promise.all(i)}},Po=class{constructor(e){this.parser=e,this.name=re.EXT_MATERIALS_BUMP}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return t.bumpScale=o.bumpFactor!==void 0?o.bumpFactor:1,o.bumpTexture!==void 0&&i.push(s.assignTexture(t,"bumpMap",o.bumpTexture)),Promise.all(i)}},Oo=class{constructor(e){this.parser=e,this.name=re.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:r.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return o.anisotropyStrength!==void 0&&(t.anisotropy=o.anisotropyStrength),o.anisotropyRotation!==void 0&&(t.anisotropyRotation=o.anisotropyRotation),o.anisotropyTexture!==void 0&&i.push(s.assignTexture(t,"anisotropyMap",o.anisotropyTexture)),Promise.all(i)}};class Ho{constructor(e){this.parser=e,this.name=re.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const i=n.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,o)}}class jo{constructor(e){this.parser=e,this.name=re.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],a=n.images[o.source];let A=s.textureLoader;if(a.uri){const l=s.options.manager.getHandler(a.uri);l!==null&&(A=l)}return this.detectSupport().then(function(l){if(l)return s.loadTextureImage(e,o.source,A);if(n.extensionsRequired&&n.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return s.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(t.height===1)}})),this.isSupported}}class qo{constructor(e){this.parser=e,this.name=re.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,i=n.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],a=n.images[o.source];let A=s.textureLoader;if(a.uri){const l=s.options.manager.getHandler(a.uri);l!==null&&(A=l)}return this.detectSupport().then(function(l){if(l)return s.loadTextureImage(e,o.source,A);if(n.extensionsRequired&&n.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return s.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(t.height===1)}})),this.isSupported}}class zo{constructor(e){this.name=re.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const n=s.extensions[this.name],i=this.parser.getDependency("buffer",n.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(a){const A=n.byteOffset||0,l=n.byteLength||0,h=n.count,u=n.byteStride,p=new Uint8Array(a,A,l);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(h,u,p,n.mode,n.filter).then(function(g){return g.buffer}):o.ready.then(function(){const g=new ArrayBuffer(h*u);return o.decodeGltfBuffer(new Uint8Array(g),h,u,p,n.mode,n.filter),g})})}else return null}}let Yo=class{constructor(e){this.name=re.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,s=t.nodes[e];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;const n=t.meshes[s.mesh];for(const l of n.primitives)if(l.mode!==We.TRIANGLES&&l.mode!==We.TRIANGLE_STRIP&&l.mode!==We.TRIANGLE_FAN&&l.mode!==void 0)return null;const o=s.extensions[this.name].attributes,a=[],A={};for(const l in o)a.push(this.parser.getDependency("accessor",o[l]).then(h=>(A[l]=h,A[l])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(l=>{const h=l.pop(),u=h.isGroup?h.children:[h],p=l[0].count,g=[];for(const m of u){const I=new r.Matrix4,b=new r.Vector3,B=new r.Quaternion,w=new r.Vector3(1,1,1),C=new r.InstancedMesh(m.geometry,m.material,p);for(let y=0;y<p;y++)A.TRANSLATION&&b.fromBufferAttribute(A.TRANSLATION,y),A.ROTATION&&B.fromBufferAttribute(A.ROTATION,y),A.SCALE&&w.fromBufferAttribute(A.SCALE,y),C.setMatrixAt(y,I.compose(b,B,w));for(const y in A)if(y==="_COLOR_0"){const x=A[y];C.instanceColor=new r.InstancedBufferAttribute(x.array,x.itemSize,x.normalized)}else y!=="TRANSLATION"&&y!=="ROTATION"&&y!=="SCALE"&&m.geometry.setAttribute(y,A[y]);r.Object3D.prototype.copy.call(C,m),this.parser.assignFinalMaterial(C),g.push(C)}return h.isGroup?(h.clear(),h.add(...g),h):g[0]}))}};const ii="glTF",Lt=12,ps={JSON:1313821514,BIN:5130562};class Vo{constructor(e){this.name=re.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,Lt),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==ii)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const n=this.header.length-Lt,i=new DataView(e,Lt);let o=0;for(;o<n;){const a=i.getUint32(o,!0);o+=4;const A=i.getUint32(o,!0);if(o+=4,A===ps.JSON){const l=new Uint8Array(e,Lt+o,a);this.content=s.decode(l)}else if(A===ps.BIN){const l=Lt+o;this.body=e.slice(l,l+a)}o+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Ko{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=re.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,i=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},A={},l={};for(const h in o){const u=Hn[h]||h.toLowerCase();a[u]=o[h]}for(const h in e.attributes){const u=Hn[h]||h.toLowerCase();if(o[h]!==void 0){const p=s.accessors[e.attributes[h]],g=Rt[p.componentType];l[u]=g.name,A[u]=p.normalized===!0}}return t.getDependency("bufferView",i).then(function(h){return new Promise(function(u,p){n.decodeDracoFile(h,function(g){for(const m in g.attributes){const I=g.attributes[m],b=A[m];b!==void 0&&(I.normalized=b)}u(g)},a,l,r.LinearSRGBColorSpace,p)})})}}class Jo{constructor(){this.name=re.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 Wo{constructor(){this.name=re.KHR_MESH_QUANTIZATION}}class oi extends r.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,i=e*n*3+n;for(let o=0;o!==n;o++)t[o]=s[i+o];return t}interpolate_(e,t,s,n){const i=this.resultBuffer,o=this.sampleValues,a=this.valueSize,A=a*2,l=a*3,h=n-t,u=(s-t)/h,p=u*u,g=p*u,m=e*l,I=m-l,b=-2*g+3*p,B=g-p,w=1-b,C=B-p+u;for(let y=0;y!==a;y++){const x=o[I+y+a],R=o[I+y+A]*h,D=o[m+y+a],S=o[m+y]*h;i[y]=w*x+C*R+b*D+B*S}return i}}const Xo=new r.Quaternion;class Zo extends oi{interpolate_(e,t,s,n){const i=super.interpolate_(e,t,s,n);return Xo.fromArray(i).normalize().toArray(i),i}}const We={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Rt={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},gs={9728:r.NearestFilter,9729:r.LinearFilter,9984:r.NearestMipmapNearestFilter,9985:r.LinearMipmapNearestFilter,9986:r.NearestMipmapLinearFilter,9987:r.LinearMipmapLinearFilter},fs={33071:r.ClampToEdgeWrapping,33648:r.MirroredRepeatWrapping,10497:r.RepeatWrapping},mn={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"},dt={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},$o={CUBICSPLINE:void 0,LINEAR:r.InterpolateLinear,STEP:r.InterpolateDiscrete},In={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function er(c){return c.DefaultMaterial===void 0&&(c.DefaultMaterial=new r.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:r.FrontSide})),c.DefaultMaterial}function bt(c,e,t){for(const s in t.extensions)c[s]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[s]=t.extensions[s])}function ct(c,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(c.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function tr(c,e,t){let s=!1,n=!1,i=!1;for(let l=0,h=e.length;l<h;l++){const u=e[l];if(u.POSITION!==void 0&&(s=!0),u.NORMAL!==void 0&&(n=!0),u.COLOR_0!==void 0&&(i=!0),s&&n&&i)break}if(!s&&!n&&!i)return Promise.resolve(c);const o=[],a=[],A=[];for(let l=0,h=e.length;l<h;l++){const u=e[l];if(s){const p=u.POSITION!==void 0?t.getDependency("accessor",u.POSITION):c.attributes.position;o.push(p)}if(n){const p=u.NORMAL!==void 0?t.getDependency("accessor",u.NORMAL):c.attributes.normal;a.push(p)}if(i){const p=u.COLOR_0!==void 0?t.getDependency("accessor",u.COLOR_0):c.attributes.color;A.push(p)}}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(A)]).then(function(l){const h=l[0],u=l[1],p=l[2];return s&&(c.morphAttributes.position=h),n&&(c.morphAttributes.normal=u),i&&(c.morphAttributes.color=p),c.morphTargetsRelative=!0,c})}function nr(c,e){if(c.updateMorphTargets(),e.weights!==void 0)for(let t=0,s=e.weights.length;t<s;t++)c.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(c.morphTargetInfluences.length===t.length){c.morphTargetDictionary={};for(let s=0,n=t.length;s<n;s++)c.morphTargetDictionary[t[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function sr(c){let e;const t=c.extensions&&c.extensions[re.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+bn(t.attributes):e=c.indices+":"+bn(c.attributes)+":"+c.mode,c.targets!==void 0)for(let s=0,n=c.targets.length;s<n;s++)e+=":"+bn(c.targets[s]);return e}function bn(c){let e="";const t=Object.keys(c).sort();for(let s=0,n=t.length;s<n;s++)e+=t[s]+":"+c[t[s]]+";";return e}function jn(c){switch(c){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 ir(c){return c.search(/\.jpe?g($|\?)/i)>0||c.search(/^data\:image\/jpeg/)===0?"image/jpeg":c.search(/\.webp($|\?)/i)>0||c.search(/^data\:image\/webp/)===0?"image/webp":"image/png"}const or=new r.Matrix4;class rr{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new To,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 s=!1,n=-1,i=!1,o=-1;if(typeof navigator<"u"){const a=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(a)===!0;const A=a.match(/Version\/(\d+)/);n=s&&A?parseInt(A[1],10):-1,i=a.indexOf("Firefox")>-1,o=i?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||i&&o<98?this.textureLoader=new r.TextureLoader(this.options.manager):this.textureLoader=new r.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new r.FileLoader(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 s=this,n=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(o){const a={scene:o[0][n.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:n.asset,parser:s,userData:{}};return bt(i,a,n),ct(a,n),Promise.all(s._invokeAll(function(A){return A.afterRoot&&A.afterRoot(a)})).then(function(){for(const A of a.scenes)A.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let n=0,i=t.length;n<i;n++){const o=t[n].joints;for(let a=0,A=o.length;a<A;a++)e[o[a]].isBone=!0}for(let n=0,i=e.length;n<i;n++){const o=e[n];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(s[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.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,s){if(e.refs[t]<=1)return s;const n=s.clone(),i=(o,a)=>{const A=this.associations.get(o);A!=null&&this.associations.set(a,A);for(const[l,h]of o.children.entries())i(h,a.children[l])};return i(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const i=e(t[n]);i&&s.push(i)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this._invokeOne(function(i){return i.loadNode&&i.loadNode(t)});break;case"mesh":n=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(t)});break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(t)});break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(t)});break;case"texture":n=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(t)});break;case"skin":n=this.loadSkin(t);break;case"animation":n=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(t)});break;case"camera":n=this.loadCamera(t);break;default:if(n=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(e,t)}),!n)throw new Error("Unknown type: "+e);break}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(n.map(function(i,o){return s.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],s=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[re.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(i,o){s.load(r.LoaderUtils.resolveURL(t.uri,n.path),i,void 0,function(){o(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(s){const n=t.byteLength||0,i=t.byteOffset||0;return s.slice(i,i+n)})}loadAccessor(e){const t=this,s=this.json,n=this.json.accessors[e];if(n.bufferView===void 0&&n.sparse===void 0){const o=mn[n.type],a=Rt[n.componentType],A=n.normalized===!0,l=new a(n.count*o);return Promise.resolve(new r.BufferAttribute(l,o,A))}const i=[];return n.bufferView!==void 0?i.push(this.getDependency("bufferView",n.bufferView)):i.push(null),n.sparse!==void 0&&(i.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(i).then(function(o){const a=o[0],A=mn[n.type],l=Rt[n.componentType],h=l.BYTES_PER_ELEMENT,u=h*A,p=n.byteOffset||0,g=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,m=n.normalized===!0;let I,b;if(g&&g!==u){const B=Math.floor(p/g),w="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+B+":"+n.count;let C=t.cache.get(w);C||(I=new l(a,B*g,n.count*g/h),C=new r.InterleavedBuffer(I,g/h),t.cache.add(w,C)),b=new r.InterleavedBufferAttribute(C,A,p%g/h,m)}else a===null?I=new l(n.count*A):I=new l(a,p,n.count*A),b=new r.BufferAttribute(I,A,m);if(n.sparse!==void 0){const B=mn.SCALAR,w=Rt[n.sparse.indices.componentType],C=n.sparse.indices.byteOffset||0,y=n.sparse.values.byteOffset||0,x=new w(o[1],C,n.sparse.count*B),R=new l(o[2],y,n.sparse.count*A);a!==null&&(b=new r.BufferAttribute(b.array.slice(),b.itemSize,b.normalized)),b.normalized=!1;for(let D=0,S=x.length;D<S;D++){const v=x[D];if(b.setX(v,R[D*A]),A>=2&&b.setY(v,R[D*A+1]),A>=3&&b.setZ(v,R[D*A+2]),A>=4&&b.setW(v,R[D*A+3]),A>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}b.normalized=m}return b})}loadTexture(e){const t=this.json,s=this.options,i=t.textures[e].source,o=t.images[i];let a=this.textureLoader;if(o.uri){const A=s.manager.getHandler(o.uri);A!==null&&(a=A)}return this.loadTextureImage(e,i,a)}loadTextureImage(e,t,s){const n=this,i=this.json,o=i.textures[e],a=i.images[t],A=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[A])return this.textureCache[A];const l=this.loadImageSource(t,s).then(function(h){h.flipY=!1,h.name=o.name||a.name||"",h.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(h.name=a.uri);const p=(i.samplers||{})[o.sampler]||{};return h.magFilter=gs[p.magFilter]||r.LinearFilter,h.minFilter=gs[p.minFilter]||r.LinearMipmapLinearFilter,h.wrapS=fs[p.wrapS]||r.RepeatWrapping,h.wrapT=fs[p.wrapT]||r.RepeatWrapping,h.anisotropy=4,n.associations.set(h,{textures:e}),h}).catch(function(){return null});return this.textureCache[A]=l,l}loadImageSource(e,t){const s=this,n=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(u=>u.clone());const o=n.images[e],a=self.URL||self.webkitURL;let A=o.uri||"",l=!1;if(o.bufferView!==void 0)A=s.getDependency("bufferView",o.bufferView).then(function(u){l=!0;const p=new Blob([u],{type:o.mimeType});return A=a.createObjectURL(p),A});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const h=Promise.resolve(A).then(function(u){return new Promise(function(p,g){let m=p;t.isImageBitmapLoader===!0&&(m=function(I){const b=new r.Texture(I);b.needsUpdate=!0,p(b)}),t.load(r.LoaderUtils.resolveURL(u,i.path),m,void 0,g)})}).then(function(u){return l===!0&&a.revokeObjectURL(A),ct(u,o),u.userData.mimeType=o.mimeType||ir(o.uri),u}).catch(function(u){throw console.error("THREE.GLTFLoader: Couldn't load texture",A),u});return this.sourceCache[e]=h,h}assignTexture(e,t,s,n){const i=this;return this.getDependency("texture",s.index).then(function(o){if(!o)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(o=o.clone(),o.channel=s.texCoord),i.extensions[re.KHR_TEXTURE_TRANSFORM]){const a=s.extensions!==void 0?s.extensions[re.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const A=i.associations.get(o);o=i.extensions[re.KHR_TEXTURE_TRANSFORM].extendTexture(o,a),i.associations.set(o,A)}}return n!==void 0&&(o.colorSpace=n),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let s=e.material;const n=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){const a="PointsMaterial:"+s.uuid;let A=this.cache.get(a);A||(A=new r.PointsMaterial,r.Material.prototype.copy.call(A,s),A.color.copy(s.color),A