@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.
2 lines • 268 kB
JavaScript
"use strict";const a=require("./three.umd.cjs");class Oi extends a.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 a.SphereGeometry(s,2*n,n);i.scale(1,1,-1);const r=i.getAttribute("position"),o=new a.Vector3;for(let l=0;l<r.count;++l)if(o.fromBufferAttribute(r,l),o.y<0){const h=-t*3/2,u=o.y<h?-t/o.y:1-o.y*o.y/(3*h*h);o.multiplyScalar(u),o.toArray(r.array,3*l)}r.needsUpdate=!0,super(i,new a.MeshBasicMaterial({map:e,depthWrite:!1}))}}const Os=new a.NodeFrame;Os.camera=new a.PerspectiveCamera;a.ShaderLib.basic,a.ShaderLib.basic,a.ShaderLib.points,a.ShaderLib.standard,a.ShaderLib.physical,a.ShaderLib.phong;var Gt=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(u){u.preventDefault(),s(++c%e.children.length)},!1);function t(u){return e.appendChild(u.dom),u}function s(u){for(var p=0;p<e.children.length;p++)e.children[p].style.display=p===u?"block":"none";c=u}var n=(performance||Date).now(),i=n,r=0,o=t(new Gt.Panel("FPS","#0ff","#002")),l=t(new Gt.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var h=t(new Gt.Panel("MB","#f08","#201"));return s(0),{REVISION:16,dom:e,addPanel:t,showPanel:s,begin:function(){n=(performance||Date).now()},end:function(){r++;var u=(performance||Date).now();if(l.update(u-n,200),u>=i+1e3&&(o.update(r*1e3/(u-i),100),i=u,r=0,h)){var p=performance.memory;h.update(p.usedJSHeapSize/1048576,p.jsHeapSizeLimit/1048576)}return u},update:function(){n=this.end()},domElement:e,setMode:s}};Gt.Panel=function(c,e,t){var s=1/0,n=0,i=Math.round,r=i(window.devicePixelRatio||1),o=80*r,l=48*r,h=3*r,u=2*r,p=3*r,d=15*r,m=74*r,y=30*r,x=document.createElement("canvas");x.width=o,x.height=l,x.style.cssText="width:80px;height:48px";var w=x.getContext("2d");return w.font="bold "+9*r+"px Helvetica,Arial,sans-serif",w.textBaseline="top",w.fillStyle=t,w.fillRect(0,0,o,l),w.fillStyle=e,w.fillText(c,h,u),w.fillRect(p,d,m,y),w.fillStyle=t,w.globalAlpha=.9,w.fillRect(p,d,m,y),{dom:x,update:function(T,R){s=Math.min(s,T),n=Math.max(n,T),w.fillStyle=t,w.globalAlpha=1,w.fillRect(0,0,o,d),w.fillStyle=e,w.fillText(i(T)+" "+c+" ("+i(s)+"-"+i(n)+")",h,u),w.drawImage(x,p+r,d,m-r,y,p,d,m-r,y),w.fillRect(p+m-r,d,r,y),w.fillStyle=t,w.globalAlpha=.9,w.fillRect(p+m-r,d,r,i((1-T/R)*y))}}};class Fi extends a.ExtrudeGeometry{constructor(e,t={}){const s=t.font;if(s===void 0)super();else{const n=s.generateShapes(e,t.size);t.depth===void 0&&t.height!==void 0&&console.warn("THREE.TextGeometry: .height is now depreciated. Please use .depth instead"),t.depth=t.depth!==void 0?t.depth:t.height!==void 0?t.height:50,t.bevelThickness===void 0&&(t.bevelThickness=10),t.bevelSize===void 0&&(t.bevelSize=8),t.bevelEnabled===void 0&&(t.bevelEnabled=!1),super(n,t)}this.type="TextGeometry"}}class Ni extends a.Loader{constructor(e){super(e)}load(e,t,s,n){const i=this,r=new a.FileLoader(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(e,function(o){const l=i.parse(JSON.parse(o));t&&t(l)},s,n)}parse(e){return new Fs(e)}}class Fs{constructor(e){this.isFont=!0,this.type="Font",this.data=e}generateShapes(e,t=100){const s=[],n=Ui(e,t,this.data);for(let i=0,r=n.length;i<r;i++)s.push(...n[i].toShapes());return s}}function Ui(c,e,t){const s=Array.from(c),n=e/t.resolution,i=(t.boundingBox.yMax-t.boundingBox.yMin+t.underlineThickness)*n,r=[];let o=0,l=0;for(let h=0;h<s.length;h++){const u=s[h];if(u===`
`)o=0,l-=i;else{const p=Bi(u,n,o,l,t);o+=p.offsetX,r.push(p.path)}}return r}function Bi(c,e,t,s,n){const i=n.glyphs[c]||n.glyphs["?"];if(!i){console.error('THREE.Font: character "'+c+'" does not exists in font family '+n.familyName+".");return}const r=new a.ShapePath;let o,l,h,u,p,d,m,y;if(i.o){const x=i._cachedOutline||(i._cachedOutline=i.o.split(" "));for(let w=0,T=x.length;w<T;)switch(x[w++]){case"m":o=x[w++]*e+t,l=x[w++]*e+s,r.moveTo(o,l);break;case"l":o=x[w++]*e+t,l=x[w++]*e+s,r.lineTo(o,l);break;case"q":h=x[w++]*e+t,u=x[w++]*e+s,p=x[w++]*e+t,d=x[w++]*e+s,r.quadraticCurveTo(p,d,h,u);break;case"b":h=x[w++]*e+t,u=x[w++]*e+s,p=x[w++]*e+t,d=x[w++]*e+s,m=x[w++]*e+t,y=x[w++]*e+s,r.bezierCurveTo(p,d,m,y,h,u);break}}return{offsetX:i.ha*e,path:r}}function ki(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 r=0;const o=Object.keys(c.attributes),l={},h={},u=[],p=["getX","getY","getZ","getW"],d=["setX","setY","setZ","setW"];for(let R=0,E=o.length;R<E;R++){const _=o[R],A=c.attributes[_];l[_]=new A.constructor(new A.array.constructor(A.count*A.itemSize),A.itemSize,A.normalized);const N=c.morphAttributes[_];N&&(h[_]||(h[_]=[]),N.forEach((F,b)=>{const L=new F.array.constructor(F.count*F.itemSize);h[_][b]=new F.constructor(L,F.itemSize,F.normalized)}))}const m=e*.5,y=Math.log10(1/e),x=Math.pow(10,y),w=m*x;for(let R=0;R<i;R++){const E=s?s.getX(R):R;let _="";for(let A=0,N=o.length;A<N;A++){const F=o[A],b=c.getAttribute(F),L=b.itemSize;for(let H=0;H<L;H++)_+=`${~~(b[p[H]](E)*x+w)},`}if(_ in t)u.push(t[_]);else{for(let A=0,N=o.length;A<N;A++){const F=o[A],b=c.getAttribute(F),L=c.morphAttributes[F],H=b.itemSize,k=l[F],j=h[F];for(let $=0;$<H;$++){const B=p[$],Z=d[$];if(k[Z](r,b[B](E)),L)for(let z=0,q=L.length;z<q;z++)j[z][Z](r,L[z][B](E))}}t[_]=r,u.push(r),r++}}const T=c.clone();for(const R in c.attributes){const E=l[R];if(T.setAttribute(R,new E.constructor(E.array.slice(0,r*E.itemSize),E.itemSize,E.normalized)),R in h)for(let _=0;_<h[R].length;_++){const A=h[R][_];T.morphAttributes[R][_]=new A.constructor(A.array.slice(0,r*A.itemSize),A.itemSize,A.normalized)}}return T.setIndex(u),T}function Zn(c,e){if(e===a.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),c;if(e===a.TriangleFanDrawMode||e===a.TriangleStripDrawMode){let t=c.getIndex();if(t===null){const r=[],o=c.getAttribute("position");if(o!==void 0){for(let l=0;l<o.count;l++)r.push(l);c.setIndex(r),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===a.TriangleFanDrawMode)for(let r=1;r<=s;r++)n.push(t.getX(0)),n.push(t.getX(r)),n.push(t.getX(r+1));else for(let r=0;r<s;r++)r%2===0?(n.push(t.getX(r)),n.push(t.getX(r+1)),n.push(t.getX(r+2))):(n.push(t.getX(r+2)),n.push(t.getX(r+1)),n.push(t.getX(r)));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 Fn extends a.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Vi(t)}),this.register(function(t){return new Xi(t)}),this.register(function(t){return new er(t)}),this.register(function(t){return new tr(t)}),this.register(function(t){return new nr(t)}),this.register(function(t){return new Yi(t)}),this.register(function(t){return new Zi(t)}),this.register(function(t){return new Ki(t)}),this.register(function(t){return new Qi(t)}),this.register(function(t){return new ji(t)}),this.register(function(t){return new qi(t)}),this.register(function(t){return new Wi(t)}),this.register(function(t){return new Ji(t)}),this.register(function(t){return new $i(t)}),this.register(function(t){return new Hi(t)}),this.register(function(t){return new sr(t)}),this.register(function(t){return new ir(t)})}load(e,t,s,n){const i=this;let r;if(this.resourcePath!=="")r=this.resourcePath;else if(this.path!==""){const h=a.LoaderUtils.extractUrlBase(e);r=a.LoaderUtils.resolveURL(h,this.path)}else r=a.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const o=function(h){n?n(h):console.error(h),i.manager.itemError(e),i.manager.itemEnd(e)},l=new a.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(e,function(h){try{i.parse(h,r,function(u){t(u),i.manager.itemEnd(e)},o)}catch(u){o(u)}},s,o)}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,r;const o={},l={},h=new TextDecoder;if(typeof e=="string")try{i=JSON.parse(e)}catch(p){r=e,n&&n(p);return}else if(e instanceof ArrayBuffer)if(h.decode(new Uint8Array(e,0,4))===Ns){try{o[ne.KHR_BINARY_GLTF]=new rr(e)}catch(d){n&&n(d);return}try{i=JSON.parse(o[ne.KHR_BINARY_GLTF].content)}catch(d){r=o[ne.KHR_BINARY_GLTF].content,n&&n(d);return}}else try{i=JSON.parse(h.decode(e))}catch(d){r=h.decode(e),n&&n(d);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=r;const u=new wr(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});u.fileLoader.setRequestHeader(this.requestHeader);for(let p=0;p<this.pluginCallbacks.length;p++){const d=this.pluginCallbacks[p](u);d.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),l[d.name]=d,o[d.name]=!0}if(i.extensionsUsed)for(let p=0;p<i.extensionsUsed.length;++p){const d=i.extensionsUsed[p],m=i.extensionsRequired||[];switch(d){case ne.KHR_MATERIALS_UNLIT:o[d]=new zi;break;case ne.KHR_DRACO_MESH_COMPRESSION:o[d]=new or(i,this.dracoLoader);break;case ne.KHR_TEXTURE_TRANSFORM:o[d]=new ar;break;case ne.KHR_MESH_QUANTIZATION:o[d]=new lr;break;default:m.indexOf(d)>=0&&l[d]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+d+'".')}}u.setExtensions(o),u.setPlugins(l),u.parse(s,n)}parseAsync(e,t){const s=this;return new Promise(function(n,i){s.parse(e,t,n,i)})}}function Gi(){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 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 Hi{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 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,l=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let h;const u=new a.Color(16777215);l.color!==void 0&&u.setRGB(l.color[0],l.color[1],l.color[2],a.LinearSRGBColorSpace);const p=l.range!==void 0?l.range:0;switch(l.type){case"directional":h=new a.DirectionalLight(u),h.target.position.set(0,0,-1),h.add(h.target);break;case"point":h=new a.PointLight(u),h.distance=p;break;case"spot":h=new a.SpotLight(u),h.distance=p,l.spot=l.spot||{},l.spot.innerConeAngle=l.spot.innerConeAngle!==void 0?l.spot.innerConeAngle:0,l.spot.outerConeAngle=l.spot.outerConeAngle!==void 0?l.spot.outerConeAngle:Math.PI/4,h.angle=l.spot.outerConeAngle,h.penumbra=1-l.spot.innerConeAngle/l.spot.outerConeAngle,h.target.position.set(0,0,-1),h.add(h.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+l.type)}return h.position.set(0,0,0),h.decay=2,it(h,l),l.intensity!==void 0&&(h.intensity=l.intensity),h.name=t.createUniqueName(l.name||"light_"+e),n=Promise.resolve(h),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],o=(i.extensions&&i.extensions[this.name]||{}).light;return o===void 0?null:this._loadLight(o).then(function(l){return s._getNodeRef(t.cache,o,l)})}}let zi=class{constructor(){this.name=ne.KHR_MATERIALS_UNLIT}getMaterialType(){return a.MeshBasicMaterial}extendParams(e,t,s){const n=[];e.color=new a.Color(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const r=i.baseColorFactor;e.color.setRGB(r[0],r[1],r[2],a.LinearSRGBColorSpace),e.opacity=r[3]}i.baseColorTexture!==void 0&&n.push(s.assignTexture(e,"map",i.baseColorTexture,a.SRGBColorSpace))}return Promise.all(n)}},ji=class{constructor(e){this.parser=e,this.name=ne.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()}},Vi=class{constructor(e){this.parser=e,this.name=ne.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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=[],r=n.extensions[this.name];if(r.clearcoatFactor!==void 0&&(t.clearcoat=r.clearcoatFactor),r.clearcoatTexture!==void 0&&i.push(s.assignTexture(t,"clearcoatMap",r.clearcoatTexture)),r.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=r.clearcoatRoughnessFactor),r.clearcoatRoughnessTexture!==void 0&&i.push(s.assignTexture(t,"clearcoatRoughnessMap",r.clearcoatRoughnessTexture)),r.clearcoatNormalTexture!==void 0&&(i.push(s.assignTexture(t,"clearcoatNormalMap",r.clearcoatNormalTexture)),r.clearcoatNormalTexture.scale!==void 0)){const o=r.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new a.Vector2(o,o)}return Promise.all(i)}},Xi=class{constructor(e){this.parser=e,this.name=ne.KHR_MATERIALS_DISPERSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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()}},Wi=class{constructor(e){this.parser=e,this.name=ne.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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=[],r=n.extensions[this.name];return r.iridescenceFactor!==void 0&&(t.iridescence=r.iridescenceFactor),r.iridescenceTexture!==void 0&&i.push(s.assignTexture(t,"iridescenceMap",r.iridescenceTexture)),r.iridescenceIor!==void 0&&(t.iridescenceIOR=r.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),r.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=r.iridescenceThicknessMinimum),r.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=r.iridescenceThicknessMaximum),r.iridescenceThicknessTexture!==void 0&&i.push(s.assignTexture(t,"iridescenceThicknessMap",r.iridescenceThicknessTexture)),Promise.all(i)}},Yi=class{constructor(e){this.parser=e,this.name=ne.KHR_MATERIALS_SHEEN}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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 a.Color(0,0,0),t.sheenRoughness=0,t.sheen=1;const r=n.extensions[this.name];if(r.sheenColorFactor!==void 0){const o=r.sheenColorFactor;t.sheenColor.setRGB(o[0],o[1],o[2],a.LinearSRGBColorSpace)}return r.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=r.sheenRoughnessFactor),r.sheenColorTexture!==void 0&&i.push(s.assignTexture(t,"sheenColorMap",r.sheenColorTexture,a.SRGBColorSpace)),r.sheenRoughnessTexture!==void 0&&i.push(s.assignTexture(t,"sheenRoughnessMap",r.sheenRoughnessTexture)),Promise.all(i)}},Zi=class{constructor(e){this.parser=e,this.name=ne.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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=[],r=n.extensions[this.name];return r.transmissionFactor!==void 0&&(t.transmission=r.transmissionFactor),r.transmissionTexture!==void 0&&i.push(s.assignTexture(t,"transmissionMap",r.transmissionTexture)),Promise.all(i)}},Ki=class{constructor(e){this.parser=e,this.name=ne.KHR_MATERIALS_VOLUME}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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=[],r=n.extensions[this.name];t.thickness=r.thicknessFactor!==void 0?r.thicknessFactor:0,r.thicknessTexture!==void 0&&i.push(s.assignTexture(t,"thicknessMap",r.thicknessTexture)),t.attenuationDistance=r.attenuationDistance||1/0;const o=r.attenuationColor||[1,1,1];return t.attenuationColor=new a.Color().setRGB(o[0],o[1],o[2],a.LinearSRGBColorSpace),Promise.all(i)}},Qi=class{constructor(e){this.parser=e,this.name=ne.KHR_MATERIALS_IOR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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()}},qi=class{constructor(e){this.parser=e,this.name=ne.KHR_MATERIALS_SPECULAR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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=[],r=n.extensions[this.name];t.specularIntensity=r.specularFactor!==void 0?r.specularFactor:1,r.specularTexture!==void 0&&i.push(s.assignTexture(t,"specularIntensityMap",r.specularTexture));const o=r.specularColorFactor||[1,1,1];return t.specularColor=new a.Color().setRGB(o[0],o[1],o[2],a.LinearSRGBColorSpace),r.specularColorTexture!==void 0&&i.push(s.assignTexture(t,"specularColorMap",r.specularColorTexture,a.SRGBColorSpace)),Promise.all(i)}},$i=class{constructor(e){this.parser=e,this.name=ne.EXT_MATERIALS_BUMP}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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=[],r=n.extensions[this.name];return t.bumpScale=r.bumpFactor!==void 0?r.bumpFactor:1,r.bumpTexture!==void 0&&i.push(s.assignTexture(t,"bumpMap",r.bumpTexture)),Promise.all(i)}},Ji=class{constructor(e){this.parser=e,this.name=ne.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:a.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=[],r=n.extensions[this.name];return r.anisotropyStrength!==void 0&&(t.anisotropy=r.anisotropyStrength),r.anisotropyRotation!==void 0&&(t.anisotropyRotation=r.anisotropyRotation),r.anisotropyTexture!==void 0&&i.push(s.assignTexture(t,"anisotropyMap",r.anisotropyTexture)),Promise.all(i)}};class er{constructor(e){this.parser=e,this.name=ne.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],r=t.options.ktx2Loader;if(!r){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,r)}}class tr{constructor(e){this.parser=e,this.name=ne.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 r=i.extensions[t],o=n.images[r.source];let l=s.textureLoader;if(o.uri){const h=s.options.manager.getHandler(o.uri);h!==null&&(l=h)}return this.detectSupport().then(function(h){if(h)return s.loadTextureImage(e,r.source,l);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 nr{constructor(e){this.parser=e,this.name=ne.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 r=i.extensions[t],o=n.images[r.source];let l=s.textureLoader;if(o.uri){const h=s.options.manager.getHandler(o.uri);h!==null&&(l=h)}return this.detectSupport().then(function(h){if(h)return s.loadTextureImage(e,r.source,l);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 sr{constructor(e){this.name=ne.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),r=this.parser.options.meshoptDecoder;if(!r||!r.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(o){const l=n.byteOffset||0,h=n.byteLength||0,u=n.count,p=n.byteStride,d=new Uint8Array(o,l,h);return r.decodeGltfBufferAsync?r.decodeGltfBufferAsync(u,p,d,n.mode,n.filter).then(function(m){return m.buffer}):r.ready.then(function(){const m=new ArrayBuffer(u*p);return r.decodeGltfBuffer(new Uint8Array(m),u,p,d,n.mode,n.filter),m})})}else return null}}let ir=class{constructor(e){this.name=ne.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 h of n.primitives)if(h.mode!==Ye.TRIANGLES&&h.mode!==Ye.TRIANGLE_STRIP&&h.mode!==Ye.TRIANGLE_FAN&&h.mode!==void 0)return null;const r=s.extensions[this.name].attributes,o=[],l={};for(const h in r)o.push(this.parser.getDependency("accessor",r[h]).then(u=>(l[h]=u,l[h])));return o.length<1?null:(o.push(this.parser.createNodeMesh(e)),Promise.all(o).then(h=>{const u=h.pop(),p=u.isGroup?u.children:[u],d=h[0].count,m=[];for(const y of p){const x=new a.Matrix4,w=new a.Vector3,T=new a.Quaternion,R=new a.Vector3(1,1,1),E=new a.InstancedMesh(y.geometry,y.material,d);for(let _=0;_<d;_++)l.TRANSLATION&&w.fromBufferAttribute(l.TRANSLATION,_),l.ROTATION&&T.fromBufferAttribute(l.ROTATION,_),l.SCALE&&R.fromBufferAttribute(l.SCALE,_),E.setMatrixAt(_,x.compose(w,T,R));for(const _ in l)if(_==="_COLOR_0"){const A=l[_];E.instanceColor=new a.InstancedBufferAttribute(A.array,A.itemSize,A.normalized)}else _!=="TRANSLATION"&&_!=="ROTATION"&&_!=="SCALE"&&y.geometry.setAttribute(_,l[_]);a.Object3D.prototype.copy.call(E,y),this.parser.assignFinalMaterial(E),m.push(E)}return u.isGroup?(u.clear(),u.add(...m),u):m[0]}))}};const Ns="glTF",It=12,Kn={JSON:1313821514,BIN:5130562};class rr{constructor(e){this.name=ne.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,It),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!==Ns)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-It,i=new DataView(e,It);let r=0;for(;r<n;){const o=i.getUint32(r,!0);r+=4;const l=i.getUint32(r,!0);if(r+=4,l===Kn.JSON){const h=new Uint8Array(e,It+r,o);this.content=s.decode(h)}else if(l===Kn.BIN){const h=It+r;this.body=e.slice(h,h+o)}r+=o}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class or{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 s=this.json,n=this.dracoLoader,i=e.extensions[this.name].bufferView,r=e.extensions[this.name].attributes,o={},l={},h={};for(const u in r){const p=_n[u]||u.toLowerCase();o[p]=r[u]}for(const u in e.attributes){const p=_n[u]||u.toLowerCase();if(r[u]!==void 0){const d=s.accessors[e.attributes[u]],m=bt[d.componentType];h[p]=m.name,l[p]=d.normalized===!0}}return t.getDependency("bufferView",i).then(function(u){return new Promise(function(p,d){n.decodeDracoFile(u,function(m){for(const y in m.attributes){const x=m.attributes[y],w=l[y];w!==void 0&&(x.normalized=w)}p(m)},o,h,a.LinearSRGBColorSpace,d)})})}}class ar{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 lr{constructor(){this.name=ne.KHR_MESH_QUANTIZATION}}class Us extends a.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 r=0;r!==n;r++)t[r]=s[i+r];return t}interpolate_(e,t,s,n){const i=this.resultBuffer,r=this.sampleValues,o=this.valueSize,l=o*2,h=o*3,u=n-t,p=(s-t)/u,d=p*p,m=d*p,y=e*h,x=y-h,w=-2*m+3*d,T=m-d,R=1-w,E=T-d+p;for(let _=0;_!==o;_++){const A=r[x+_+o],N=r[x+_+l]*u,F=r[y+_+o],b=r[y+_]*u;i[_]=R*A+E*N+w*F+T*b}return i}}const cr=new a.Quaternion;class hr extends Us{interpolate_(e,t,s,n){const i=super.interpolate_(e,t,s,n);return cr.fromArray(i).normalize().toArray(i),i}}const Ye={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},bt={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Qn={9728:a.NearestFilter,9729:a.LinearFilter,9984:a.NearestMipmapNearestFilter,9985:a.LinearMipmapNearestFilter,9986:a.NearestMipmapLinearFilter,9987:a.LinearMipmapLinearFilter},qn={33071:a.ClampToEdgeWrapping,33648:a.MirroredRepeatWrapping,10497:a.RepeatWrapping},ln={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},_n={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"},at={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},ur={CUBICSPLINE:void 0,LINEAR:a.InterpolateLinear,STEP:a.InterpolateDiscrete},cn={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function pr(c){return c.DefaultMaterial===void 0&&(c.DefaultMaterial=new a.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:a.FrontSide})),c.DefaultMaterial}function ft(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 it(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 fr(c,e,t){let s=!1,n=!1,i=!1;for(let h=0,u=e.length;h<u;h++){const p=e[h];if(p.POSITION!==void 0&&(s=!0),p.NORMAL!==void 0&&(n=!0),p.COLOR_0!==void 0&&(i=!0),s&&n&&i)break}if(!s&&!n&&!i)return Promise.resolve(c);const r=[],o=[],l=[];for(let h=0,u=e.length;h<u;h++){const p=e[h];if(s){const d=p.POSITION!==void 0?t.getDependency("accessor",p.POSITION):c.attributes.position;r.push(d)}if(n){const d=p.NORMAL!==void 0?t.getDependency("accessor",p.NORMAL):c.attributes.normal;o.push(d)}if(i){const d=p.COLOR_0!==void 0?t.getDependency("accessor",p.COLOR_0):c.attributes.color;l.push(d)}}return Promise.all([Promise.all(r),Promise.all(o),Promise.all(l)]).then(function(h){const u=h[0],p=h[1],d=h[2];return s&&(c.morphAttributes.position=u),n&&(c.morphAttributes.normal=p),i&&(c.morphAttributes.color=d),c.morphTargetsRelative=!0,c})}function dr(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 mr(c){let e;const t=c.extensions&&c.extensions[ne.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+hn(t.attributes):e=c.indices+":"+hn(c.attributes)+":"+c.mode,c.targets!==void 0)for(let s=0,n=c.targets.length;s<n;s++)e+=":"+hn(c.targets[s]);return e}function hn(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 An(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 gr(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 yr=new a.Matrix4;class wr{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Gi,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,r=-1;if(typeof navigator<"u"){const o=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(o)===!0;const l=o.match(/Version\/(\d+)/);n=s&&l?parseInt(l[1],10):-1,i=o.indexOf("Firefox")>-1,r=i?o.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||i&&r<98?this.textureLoader=new a.TextureLoader(this.options.manager):this.textureLoader=new a.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new a.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(r){return r._markDefs&&r._markDefs()}),Promise.all(this._invokeAll(function(r){return r.beforeRoot&&r.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(r){const o={scene:r[0][n.scene||0],scenes:r[0],animations:r[1],cameras:r[2],asset:n.asset,parser:s,userData:{}};return ft(i,o,n),it(o,n),Promise.all(s._invokeAll(function(l){return l.afterRoot&&l.afterRoot(o)})).then(function(){for(const l of o.scenes)l.updateMatrixWorld();e(o)})}).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 r=t[n].joints;for(let o=0,l=r.length;o<l;o++)e[r[o]].isBone=!0}for(let n=0,i=e.length;n<i;n++){const r=e[n];r.mesh!==void 0&&(this._addNodeRef(this.meshCache,r.mesh),r.skin!==void 0&&(s[r.mesh].isSkinnedMesh=!0)),r.camera!==void 0&&this._addNodeRef(this.cameraCache,r.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=(r,o)=>{const l=this.associations.get(r);l!=null&&this.associations.set(o,l);for(const[h,u]of r.children.entries())i(u,o.children[h])};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,r){return s.getDependency(e,r)})),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[ne.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(i,r){s.load(a.LoaderUtils.resolveURL(t.uri,n.path),i,void 0,function(){r(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 r=ln[n.type],o=bt[n.componentType],l=n.normalized===!0,h=new o(n.count*r);return Promise.resolve(new a.BufferAttribute(h,r,l))}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(r){const o=r[0],l=ln[n.type],h=bt[n.componentType],u=h.BYTES_PER_ELEMENT,p=u*l,d=n.byteOffset||0,m=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,y=n.normalized===!0;let x,w;if(m&&m!==p){const T=Math.floor(d/m),R="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+T+":"+n.count;let E=t.cache.get(R);E||(x=new h(o,T*m,n.count*m/u),E=new a.InterleavedBuffer(x,m/u),t.cache.add(R,E)),w=new a.InterleavedBufferAttribute(E,l,d%m/u,y)}else o===null?x=new h(n.count*l):x=new h(o,d,n.count*l),w=new a.BufferAttribute(x,l,y);if(n.sparse!==void 0){const T=ln.SCALAR,R=bt[n.sparse.indices.componentType],E=n.sparse.indices.byteOffset||0,_=n.sparse.values.byteOffset||0,A=new R(r[1],E,n.sparse.count*T),N=new h(r[2],_,n.sparse.count*l);o!==null&&(w=new a.BufferAttribute(w.array.slice(),w.itemSize,w.normalized)),w.normalized=!1;for(let F=0,b=A.length;F<b;F++){const L=A[F];if(w.setX(L,N[F*l]),l>=2&&w.setY(L,N[F*l+1]),l>=3&&w.setZ(L,N[F*l+2]),l>=4&&w.setW(L,N[F*l+3]),l>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}w.normalized=y}return w})}loadTexture(e){const t=this.json,s=this.options,i=t.textures[e].source,r=t.images[i];let o=this.textureLoader;if(r.uri){const l=s.manager.getHandler(r.uri);l!==null&&(o=l)}return this.loadTextureImage(e,i,o)}loadTextureImage(e,t,s){const n=this,i=this.json,r=i.textures[e],o=i.images[t],l=(o.uri||o.bufferView)+":"+r.sampler;if(this.textureCache[l])return this.textureCache[l];const h=this.loadImageSource(t,s).then(function(u){u.flipY=!1,u.name=r.name||o.name||"",u.name===""&&typeof o.uri=="string"&&o.uri.startsWith("data:image/")===!1&&(u.name=o.uri);const d=(i.samplers||{})[r.sampler]||{};return u.magFilter=Qn[d.magFilter]||a.LinearFilter,u.minFilter=Qn[d.minFilter]||a.LinearMipmapLinearFilter,u.wrapS=qn[d.wrapS]||a.RepeatWrapping,u.wrapT=qn[d.wrapT]||a.RepeatWrapping,u.anisotropy=4,n.associations.set(u,{textures:e}),u}).catch(function(){return null});return this.textureCache[l]=h,h}loadImageSource(e,t){const s=this,n=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(p=>p.clone());const r=n.images[e],o=self.URL||self.webkitURL;let l=r.uri||"",h=!1;if(r.bufferView!==void 0)l=s.getDependency("bufferView",r.bufferView).then(function(p){h=!0;const d=new Blob([p],{type:r.mimeType});return l=o.createObjectURL(d),l});else if(r.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const u=Promise.resolve(l).then(function(p){return new Promise(function(d,m){let y=d;t.isImageBitmapLoader===!0&&(y=function(x){const w=new a.Texture(x);w.needsUpdate=!0,d(w)}),t.load(a.LoaderUtils.resolveURL(p,i.path),y,void 0,m)})}).then(function(p){return h===!0&&o.revokeObjectURL(l),it(p,r),p.userData.mimeType=r.mimeType||gr(r.uri),p}).catch(function(p){throw console.error("THREE.GLTFLoader: Couldn't load texture",l),p});return this.sourceCache[e]=u,u}assignTexture(e,t,s,n){const i=this;return this.getDependency("texture",s.index).then(function(r){if(!r)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(r=r.clone(),r.channel=s.texCoord),i.extensions[ne.KHR_TEXTURE_TRANSFORM]){const o=s.extensions!==void 0?s.extensions[ne.KHR_TEXTURE_TRANSFORM]:void 0;if(o){const l=i.associations.get(r);r=i.extensions[ne.KHR_TEXTURE_TRANSFORM].extendTexture(r,o),i.associations.set(r,l)}}return n!==void 0&&(r.colorSpace=n),e[t]=r,r})}assignFinalMaterial(e){const t=e.geometry;let s=e.material;const n=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,r=t.attributes.normal===void 0;if(e.isPoints){const o="PointsMaterial:"+s.uuid;let l=this.cache.get(o);l||(l=new a.PointsMaterial,a.Material.prototype.copy.call(l,s),l.color.copy(s.color),l.map=s.map,l.sizeAttenuation=!1,this.cache.add(o,l)),s=l}else if(e.isLine){const o="LineBasicMaterial:"+s.uuid;let l=this.cache.get(o);l||(l=new a.LineBasicMaterial,a.Material.prototype.copy.call(l,s),l.color.copy(s.color),l.map=s.map,this.cache.add(o,l)),s=l}if(n||i||r){let o="ClonedMaterial:"+s.uuid+":";n&&(o+="derivative-tangents:"),i&&(o+="vertex-colors:"),r&&(o+="flat-shading:");let l=this.cache.get(o);l||(l=s.clone(),i&&(l.vertexColors=!0),r&&(l.flatShading=!0),n&&(l.normalScale&&(l.normalScale.y*=-1),l.clearcoatNormalScale&&(l.clearcoatNormalScale.y*=-1)),this.cache.add(o,l),this.associations.set(l,this.associations.get(s))),s=l}e.material=s}getMaterialType(){return a.MeshStandardMaterial}loadMaterial(e){const t=this,s=this.json,n=this.extensions,i=s.materials[e];let r;const o={},l=i.extensions||{},h=[];if(l[ne.KHR_MATERIALS_UNLIT]){const p=n[ne.KHR_MATERIALS_UNLIT];r=p.getMaterialType(),h.push(p.extendParams(o,i,t))}else{const p=i.pbrMetallicRoughness||{};if(o.color=new a.Color(1,1,1),o.opacity=1,Array.isArray(p.baseColorFactor)){const d=p.baseColorFactor;o.color.setRGB(d[0],d[1],d[2],a.LinearSRGBColorSpace),o.opacity=d[3]}p.baseColorTexture!==void 0&&h.push(t.assignTexture(o,"map",p.baseColorTexture,a.SRGBColorSpace)),o.metalness=p.metallicFactor!==void 0?p.metallicFactor:1,o.roughness=p.roughnessFactor!==void 0?p.roughnessFactor:1,p.metallicRoughnessTexture!==void 0&&(h.push(t.assignTexture(o,"metalnessMap",p.metallicRoughnessTexture)),h.push(t.assignTexture(o,"roughnessMap",p.metallicRoughnessTexture))),r=this._invokeOne(function(d){return d.getMaterialType&&d.getMaterialType(e)}),h.push(Promise.all(this._invokeAll(function(d){return d.extendMaterialParams&&d.extendMaterialParams(e,o)})))}i.doubleSided===!0&&(o.side=a.DoubleSide);const u=i.alphaMode||cn.OPAQUE;if(u===cn.BLEND?(o.transparent=!0,o.depthWrite=!1):(o.transparent=!1,u===cn.MASK&&(o.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&r!==a.MeshBasicMaterial&&(h.push(t.assignTexture(o,"normalMap",i.normalTexture)),o.normalScale=new a.Vector2(1,1),i.normalTexture.scale!==void 0)){const p=i.normalTexture.scale;o.normalScale.set(p,p)}if(i.occlusionTexture!==void 0&&r!==a.MeshBasicMaterial&&(h.push(t.assignTexture(o,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(o.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&r!==a.MeshBasicMaterial){const p=i.emissiveFactor;o.emissive=new a.Color().setRGB(p[0],p[1],p[2],a.LinearSRGBColorSpace)}return i.emissiveTexture!==void 0&&r!==a.MeshBasicMaterial&&h.push(t.assignTexture(o,"emissiveMap",i.emissiveTexture,a.SRGBColorSpace)),Promise.all(h).then(function(){const p=new r(o);return i.name&&(p.name=i.name),it(p,i),t.associations.set(p,{materials:e}),i.extensions&&ft(n,p,i),p})}createUniqueName(e){const t=a.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,s=this.extensions,n=this.primitiveCache;function i(o){return s[ne.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(o,t).then(function(l){return $n(l,o,t)})}const r=[];for(let o=0,l=e.length;o<l;o++){const h=e[o],u=mr(h),p=n[u];if(p)r.push(p.promise);else{let d;h.extensions&&h.extensions[ne.KHR_DRACO_MESH_COMPRESSION]?d=i(h):d=$n(new a.BufferGeometry,h,t),n[u]={primitive:h,promise:d},r.push(d)}}return Promise.all(r)}loadMesh(e){const t=this,s=this.json,n=this.extensions,i=s.meshes[e],r=i.primitives,o=[];for(let l=0,h=r.length;l<h;l++){const u=r[l].material===void 0?pr(this.cache):this.getDependency("material",r[l].material);o.push(u)}return o.push(t.loadGeometries(r)),Promise.all(o).then(function(l){const h=l.slice(0,l.length-1),u=l[l.length-1],p=[];for(let m=0,y=u.length;m<y;m++){const x=u[m],w=r[m];let T;const R=h[m];if(w.mode===Ye.TRIANGLES||w.mode===Ye.TRIANGLE_STRIP||w.mode===Ye.TRIANGLE_FAN||w.mode===void 0)T=i.isSkinnedMesh===!0?new a.SkinnedMesh(x,R):new a.Mesh(x,R),T.isSkinnedMesh===!0&&T.normalizeSkinWeights(),w.mode===Ye.TRIANGLE_STRIP?T.geometry=Zn(T.geometry,a.TriangleStripDrawMode):w.mode===Ye.TRIANGLE_FAN&&(T.geometry=Zn(T.geometry,a.TriangleFanDrawMode));else if(w.mode===Ye.LINES)T=new a.LineSegments(x,R);else if(w.mode===Ye.LINE_STRIP)T=new a.Line(x,R);else if(w.mode===Ye.LINE_LOOP)T=new a.LineLoop(x,R);else if(w.mode===Ye.POINTS)T=new a.Points(x,R);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+w.mode);Object.keys(T.geometry.morphAttributes).length>0&&dr(T,i),T.name=t.createUniqueName(i.name||"mesh_"+e),it(T,i),w.extensions&&ft(n,T,w),t.assignFinalMaterial(T),p.push(T)}for(let m=0,y=p.length;m<y;m++)t.associations.set(p[m],{meshes:e,primitives:m});if(p.length===1)return i.extensions&&ft(n,p[0],i),p[0];const d=new a.Group;i.extensions&&ft(n,d,i),t.associations.set(d,{meshes:e});for(let m=0,y=p.length;m<y;m++)d.add(p[m]);return d})}loadCamera(e){let t;const s=this.json.cameras[e],n=s[s.type];if(!n){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?t=new a.PerspectiveCamera(a.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(t=new a.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(t.name=this.createUniqueName(s.name)),it(t,s),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],s=[];for(let n=0,i=t.joints.length;n<i;n++)s.push(this._loadNodeShallow(t.joints[n]));return t.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",t.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(n){const i=n.pop(),r=n,o=[],l=[];for(let h=0,u=r.length;h<u;h++){const p=r[h];if(p){o.push(p);const d=new a.Matrix4;i!==null&&d.fromArray(i.array,h*16),l.push(d)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[h])}return new a.Skeleton(o,l)})}loadAnimation(e){const t=this.json,s=this,n=t.animations[e],i=n.name?n.name:"animation_"+e,r=[],o=[],l=[],h=[],u=[];let p=0,d=n.channels.length;for(p=0,d=n.channels.length;p<d;p++){const m=n.channels[p],y=n.samplers[m.sampler],x=m.target,w=x.node,T=n.parameters!==void 0?n.parameters[y.input]:y.input,R=n.parameters!==void 0?n.parameters[y.output]:y.output;x.node!==void 0&&(r.push(this.getDependency("node",w)),o.push(this.getDependency("accessor",T)),l.push(this.getDependency("accessor",R)),h.push(y),u.push(x))}return Promise.all([Promise.all(r),Promise.all(o),Promise.all(l),Promise.all(h),Promise.all(u)]).then(function(m){const y=m[0],x=m[1],w=m[2],T=m[3],R=m[4],E=[];for(p=0,d=y.length;p<d;p++){const _=y[p],A=x[p],N=w[p],F=T[p],b=R[p];if(_===void 0)continue;_.updateMatrix&&_.updateMatrix();const L=s._createAnimationTracks(_,A,N,F,b);if(L)for(let H=0;H<L.length;H++)E.push(L[H])}return new a.AnimationClip(i,void 0,E)})}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return n.mesh===void 0?null:s.getDependency("mesh",n.mesh).then(function(i){const r=s._getNodeRef(s.meshCache,n.mesh,i);return n.weights!==void 0&&r.traverse(function(o){if(o.isMesh)for(let l=0,h=n.weights.length;l<h;l++)o.morphTargetInfluences[l]=n.weights[l]}),r})}loadNode(e){const t=this.json,s=this,n=t.nodes[e],i=s._loadNodeShallow(e),r=[],o=n.children||[];for(let h=0,u=o.length;h<u;h++)r.push(s.getDependency("node",o[h]));const l=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([i,Promise.all(r),l]).then(function(h){const u=h[0],p=h[1],d=h[2];d!==null&&u.traverse(function(m){m.isSkinnedMesh&&m.bind(d,yr)});for(let m=0,y=p.length;m<y;m++)u.add(p[m]);return u})}_loadNodeShallow(e){const t=this.json,s=this.extensions,n=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const i=t.nodes[e],r=i.name?n.createUniqueName(i.name):"",o=[],l=n._invokeOne(function(h){return h.createNodeMesh&&h.createNodeMesh(e)});return l&&o.push(l),i.camera!==void 0&&o.push(n.getDependency("camera",i.camera).then(function(h){return n._getNodeRef(n.cameraCache,i.camera,h)})),n._invokeAll(function(h){return h.createNodeAttachment&&h.createNodeAttachment(e)}).forEach(function(h){o.push(h)}),this.nodeCache[e]=Promise.all(o).then(function(h){let u;if(i.isBone===!0?u=new a.Bone:h.length>1?u=new a.Group:h.length===1?u=h[0]:u=new a.Object3D,u!==h[0])for(let p=0,d=h.length;p<d;p++)u.add(h[p]);if(i.name&&(u.userData.name=i.name,u.name=r),it(u,i),i.extensions&&ft(s,u,i),i.matrix!==void 0){const p=new a.Matrix4;p.fromArray(i.matrix),u.applyMatrix4(p)}else i.translation!==void 0&&u.position.fromArray(i.translation),i.rotation!==void 0&&u.quaternion.fromArray(i.rotation),i.scale!==void 0&&u.scale.fromArray(i.scale);return n.associations.has(u)||n.associations.set(u,{}),n.associations.get(u).nodes=e,u}),this.nodeCache[e]}loadScene(e){const t=this.extensions,s=this.json.scenes[e],n=this,i=new a.Group;s.name&&(i.name=n.createUniqueName(s.name)),it(i,s),s.extensions&&ft(t,i,s);const r=