UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

2 lines • 262 kB
import{Mesh as B,SphereGeometry as Wn,Vector3 as U,MeshBasicMaterial as ht,NodeFrame as Vr,PerspectiveCamera as Mn,ShaderLib as ut,ExtrudeGeometry as Yr,Loader as kt,FileLoader as Kt,ShapePath as Wr,TrianglesDrawMode as Kr,TriangleFanDrawMode as Kn,TriangleStripDrawMode as Zs,LoaderUtils as Ut,MeshPhysicalMaterial as dt,Vector2 as Ne,Color as we,LinearSRGBColorSpace as nt,SRGBColorSpace as ue,SpotLight as qs,PointLight as Zn,DirectionalLight as Qs,Matrix4 as oe,InstancedMesh as Zr,Quaternion as ve,InstancedBufferAttribute as qr,Object3D as pt,TextureLoader as qn,ImageBitmapLoader as Qr,BufferAttribute as rt,InterleavedBuffer as $r,LinearMipmapLinearFilter as Qn,NearestMipmapLinearFilter as $s,LinearMipmapNearestFilter as Js,NearestMipmapNearestFilter as ei,LinearFilter as xt,NearestFilter as ti,RepeatWrapping as Ft,MirroredRepeatWrapping as ni,ClampToEdgeWrapping as _n,PointsMaterial as on,Material as an,LineBasicMaterial as bt,MeshStandardMaterial as $n,DoubleSide as Jn,PropertyBinding as Tt,BufferGeometry as ot,SkinnedMesh as si,LineSegments as In,Line as at,LineLoop as Jr,Points as Rn,Group as zt,MathUtils as ge,OrthographicCamera as ii,Skeleton as ri,AnimationClip as oi,Bone as es,InterpolateDiscrete as ai,InterpolateLinear as ts,InterleavedBufferAttribute as jt,Texture as ns,VectorKeyframeTrack as ss,NumberKeyframeTrack as is,QuaternionKeyframeTrack as rs,ColorManagement as $e,FrontSide as li,Interpolant as eo,Box3 as Pn,Sphere as os,CylinderGeometry as Ke,BoxGeometry as Ve,Float32BufferAttribute as _e,OctahedronGeometry as Ln,TorusGeometry as ln,Euler as Rt,Controls as ci,Raycaster as as,PlaneGeometry as ls,DataTextureLoader as hi,HalfFloatType as Pt,FloatType as Zt,RGBAFormat as ui,RedFormat as to,NoColorSpace as di,DataUtils as qt,Vector4 as At,Curve as no,MeshPhongMaterial as cn,MeshLambertMaterial as so,EquirectangularReflectionMapping as io,AmbientLight as ro,Uint16BufferAttribute as oo,Matrix3 as pi,ShapeUtils as ao,DefaultLoadingManager as lo,MOUSE as Qt,TOUCH as $t,Spherical as fi,Ray as co,Plane as ho,ShaderMaterial as mi,Uniform$1 as uo,Scene as cs,WebGLRenderer as po,CanvasTexture as gi,REVISION as fo,CompressedTexture as hs,Source as mo,InstancedBufferGeometry as go,InstancedInterleavedBuffer as us,WireframeGeometry as yo,UniformsUtils as yi,UniformsLib as Nn,Line3 as vo}from"./three.min.js";class wo extends B{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 Wn(s,2*n,n);i.scale(1,1,-1);const r=i.getAttribute("position"),a=new U;for(let l=0;l<r.count;++l)if(a.fromBufferAttribute(r,l),a.y<0){const c=-t*3/2,h=a.y<c?-t/a.y:1-a.y*a.y/(3*c*c);a.multiplyScalar(h),a.toArray(r.array,3*l)}r.needsUpdate=!0,super(i,new ht({map:e,depthWrite:!1}))}}const vi=new Vr;vi.camera=new Mn,ut.basic,ut.basic,ut.points,ut.standard,ut.physical,ut.phong;var hn=function(){var o=0,e=document.createElement("div");e.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",e.addEventListener("click",function(h){h.preventDefault(),s(++o%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";o=h}var n=(performance||Date).now(),i=n,r=0,a=t(new hn.Panel("FPS","#0ff","#002")),l=t(new hn.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var c=t(new hn.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 h=(performance||Date).now();if(l.update(h-n,200),h>=i+1e3&&(a.update(r*1e3/(h-i),100),i=h,r=0,c)){var u=performance.memory;c.update(u.usedJSHeapSize/1048576,u.jsHeapSizeLimit/1048576)}return h},update:function(){n=this.end()},domElement:e,setMode:s}};hn.Panel=function(o,e,t){var s=1/0,n=0,i=Math.round,r=i(window.devicePixelRatio||1),a=80*r,l=48*r,c=3*r,h=2*r,u=3*r,p=15*r,f=74*r,y=30*r,v=document.createElement("canvas");v.width=a,v.height=l,v.style.cssText="width:80px;height:48px";var g=v.getContext("2d");return g.font="bold "+9*r+"px Helvetica,Arial,sans-serif",g.textBaseline="top",g.fillStyle=t,g.fillRect(0,0,a,l),g.fillStyle=e,g.fillText(o,c,h),g.fillRect(u,p,f,y),g.fillStyle=t,g.globalAlpha=.9,g.fillRect(u,p,f,y),{dom:v,update:function(x,T){s=Math.min(s,x),n=Math.max(n,x),g.fillStyle=t,g.globalAlpha=1,g.fillRect(0,0,a,p),g.fillStyle=e,g.fillText(i(x)+" "+o+" ("+i(s)+"-"+i(n)+")",c,h),g.drawImage(v,u+r,p,f-r,y,u,p,f-r,y),g.fillRect(u+f-r,p,r,y),g.fillStyle=t,g.globalAlpha=.9,g.fillRect(u+f-r,p,r,i((1-x/T)*y))}}};class xo extends Yr{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 bo extends kt{constructor(e){super(e)}load(e,t,s,n){const i=this,r=new Kt(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(e,function(a){const l=i.parse(JSON.parse(a));t&&t(l)},s,n)}parse(e){return new wi(e)}}class wi{constructor(e){this.isFont=!0,this.type="Font",this.data=e}generateShapes(e,t=100){const s=[],n=To(e,t,this.data);for(let i=0,r=n.length;i<r;i++)s.push(...n[i].toShapes());return s}}function To(o,e,t){const s=Array.from(o),n=e/t.resolution,i=(t.boundingBox.yMax-t.boundingBox.yMin+t.underlineThickness)*n,r=[];let a=0,l=0;for(let c=0;c<s.length;c++){const h=s[c];if(h===` `)a=0,l-=i;else{const u=Ao(h,n,a,l,t);a+=u.offsetX,r.push(u.path)}}return r}function Ao(o,e,t,s,n){const i=n.glyphs[o]||n.glyphs["?"];if(!i){console.error('THREE.Font: character "'+o+'" does not exists in font family '+n.familyName+".");return}const r=new Wr;let a,l,c,h,u,p,f,y;if(i.o){const v=i._cachedOutline||(i._cachedOutline=i.o.split(" "));for(let g=0,x=v.length;g<x;)switch(v[g++]){case"m":a=v[g++]*e+t,l=v[g++]*e+s,r.moveTo(a,l);break;case"l":a=v[g++]*e+t,l=v[g++]*e+s,r.lineTo(a,l);break;case"q":c=v[g++]*e+t,h=v[g++]*e+s,u=v[g++]*e+t,p=v[g++]*e+s,r.quadraticCurveTo(u,p,c,h);break;case"b":c=v[g++]*e+t,h=v[g++]*e+s,u=v[g++]*e+t,p=v[g++]*e+s,f=v[g++]*e+t,y=v[g++]*e+s,r.bezierCurveTo(u,p,f,y,c,h);break}}return{offsetX:i.ha*e,path:r}}function Eo(o,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},s=o.getIndex(),n=o.getAttribute("position"),i=s?s.count:n.count;let r=0;const a=Object.keys(o.attributes),l={},c={},h=[],u=["getX","getY","getZ","getW"],p=["setX","setY","setZ","setW"];for(let T=0,b=a.length;T<b;T++){const _=a[T],S=o.attributes[_];l[_]=new S.constructor(new S.array.constructor(S.count*S.itemSize),S.itemSize,S.normalized);const I=o.morphAttributes[_];I&&(c[_]||(c[_]=[]),I.forEach((P,M)=>{const D=new P.array.constructor(P.count*P.itemSize);c[_][M]=new P.constructor(D,P.itemSize,P.normalized)}))}const f=e*.5,y=Math.log10(1/e),v=Math.pow(10,y),g=f*v;for(let T=0;T<i;T++){const b=s?s.getX(T):T;let _="";for(let S=0,I=a.length;S<I;S++){const P=a[S],M=o.getAttribute(P),D=M.itemSize;for(let K=0;K<D;K++)_+=`${~~(M[u[K]](b)*v+g)},`}if(_ in t)h.push(t[_]);else{for(let S=0,I=a.length;S<I;S++){const P=a[S],M=o.getAttribute(P),D=o.morphAttributes[P],K=M.itemSize,q=l[P],W=c[P];for(let Q=0;Q<K;Q++){const V=u[Q],J=p[Q];if(q[J](r,M[V](b)),D)for(let Y=0,te=D.length;Y<te;Y++)W[Y][J](r,D[Y][V](b))}}t[_]=r,h.push(r),r++}}const x=o.clone();for(const T in o.attributes){const b=l[T];if(x.setAttribute(T,new b.constructor(b.array.slice(0,r*b.itemSize),b.itemSize,b.normalized)),T in c)for(let _=0;_<c[T].length;_++){const S=c[T][_];x.morphAttributes[T][_]=new S.constructor(S.array.slice(0,r*S.itemSize),S.itemSize,S.normalized)}}return x.setIndex(h),x}function xi(o,e){if(e===Kr)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),o;if(e===Kn||e===Zs){let t=o.getIndex();if(t===null){const r=[],a=o.getAttribute("position");if(a!==void 0){for(let l=0;l<a.count;l++)r.push(l);o.setIndex(r),t=o.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),o}const s=t.count-2,n=[];if(e===Kn)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=o.clone();return i.setIndex(n),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),o}class ds extends kt{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Ro(t)}),this.register(function(t){return new Po(t)}),this.register(function(t){return new zo(t)}),this.register(function(t){return new jo(t)}),this.register(function(t){return new Bo(t)}),this.register(function(t){return new No(t)}),this.register(function(t){return new Co(t)}),this.register(function(t){return new Oo(t)}),this.register(function(t){return new Do(t)}),this.register(function(t){return new Io(t)}),this.register(function(t){return new ko(t)}),this.register(function(t){return new Lo(t)}),this.register(function(t){return new Fo(t)}),this.register(function(t){return new Uo(t)}),this.register(function(t){return new Mo(t)}),this.register(function(t){return new Ho(t)}),this.register(function(t){return new Go(t)})}load(e,t,s,n){const i=this;let r;if(this.resourcePath!=="")r=this.resourcePath;else if(this.path!==""){const c=Ut.extractUrlBase(e);r=Ut.resolveURL(c,this.path)}else r=Ut.extractUrlBase(e);this.manager.itemStart(e);const a=function(c){n?n(c):console.error(c),i.manager.itemError(e),i.manager.itemEnd(e)},l=new Kt(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(e,function(c){try{i.parse(c,r,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,r;const a={},l={},c=new TextDecoder;if(typeof e=="string")try{i=JSON.parse(e)}catch(u){r=e,n&&n(u);return}else if(e instanceof ArrayBuffer)if(c.decode(new Uint8Array(e,0,4))===bi){try{a[se.KHR_BINARY_GLTF]=new Xo(e)}catch(u){n&&n(u);return}try{i=JSON.parse(a[se.KHR_BINARY_GLTF].content)}catch(u){r=a[se.KHR_BINARY_GLTF].content,n&&n(u);return}}else try{i=JSON.parse(c.decode(e))}catch(u){r=c.decode(e),n&&n(u);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 h=new sa(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"),l[p.name]=p,a[p.name]=!0}if(i.extensionsUsed)for(let u=0;u<i.extensionsUsed.length;++u){const p=i.extensionsUsed[u],f=i.extensionsRequired||[];switch(p){case se.KHR_MATERIALS_UNLIT:a[p]=new _o;break;case se.KHR_DRACO_MESH_COMPRESSION:a[p]=new Vo(i,this.dracoLoader);break;case se.KHR_TEXTURE_TRANSFORM:a[p]=new Yo;break;case se.KHR_MESH_QUANTIZATION:a[p]=new Wo;break;default:f.indexOf(p)>=0&&l[p]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+p+'".')}}h.setExtensions(a),h.setPlugins(l),h.parse(s,n)}parseAsync(e,t){const s=this;return new Promise(function(n,i){s.parse(e,t,n,i)})}}function So(){let o={};return{get:function(e){return o[e]},add:function(e,t){o[e]=t},remove:function(e){delete o[e]},removeAll:function(){o={}}}}const se={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 Mo{constructor(e){this.parser=e,this.name=se.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,r=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let a;const l=new we(16777215);r.color!==void 0&&l.setRGB(r.color[0],r.color[1],r.color[2],nt);const c=r.range!==void 0?r.range:0;switch(r.type){case"directional":a=new Qs(l),a.target.position.set(0,0,-1),a.add(a.target);break;case"point":a=new Zn(l),a.distance=c;break;case"spot":a=new qs(l),a.distance=c,r.spot=r.spot||{},r.spot.innerConeAngle=r.spot.innerConeAngle!==void 0?r.spot.innerConeAngle:0,r.spot.outerConeAngle=r.spot.outerConeAngle!==void 0?r.spot.outerConeAngle:Math.PI/4,a.angle=r.spot.outerConeAngle,a.penumbra=1-r.spot.innerConeAngle/r.spot.outerConeAngle,a.target.position.set(0,0,-1),a.add(a.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+r.type)}return a.position.set(0,0,0),a.decay=2,Et(a,r),r.intensity!==void 0&&(a.intensity=r.intensity),a.name=t.createUniqueName(r.name||"light_"+e),n=Promise.resolve(a),t.cache.add(s,n),n}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,n=s.json.nodes[e],i=(n.extensions&&n.extensions[this.name]||{}).light;return i===void 0?null:this._loadLight(i).then(function(r){return s._getNodeRef(t.cache,i,r)})}}let _o=class{constructor(){this.name=se.KHR_MATERIALS_UNLIT}getMaterialType(){return ht}extendParams(o,e,t){const s=[];o.color=new we(1,1,1),o.opacity=1;const n=e.pbrMetallicRoughness;if(n){if(Array.isArray(n.baseColorFactor)){const i=n.baseColorFactor;o.color.setRGB(i[0],i[1],i[2],nt),o.opacity=i[3]}n.baseColorTexture!==void 0&&s.push(t.assignTexture(o,"map",n.baseColorTexture,ue))}return Promise.all(s)}},Io=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(o,e){const t=this.parser.json.materials[o];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const s=t.extensions[this.name].emissiveStrength;return s!==void 0&&(e.emissiveIntensity=s),Promise.resolve()}},Ro=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_CLEARCOAT}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser,s=t.json.materials[o];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=[],i=s.extensions[this.name];if(i.clearcoatFactor!==void 0&&(e.clearcoat=i.clearcoatFactor),i.clearcoatTexture!==void 0&&n.push(t.assignTexture(e,"clearcoatMap",i.clearcoatTexture)),i.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=i.clearcoatRoughnessFactor),i.clearcoatRoughnessTexture!==void 0&&n.push(t.assignTexture(e,"clearcoatRoughnessMap",i.clearcoatRoughnessTexture)),i.clearcoatNormalTexture!==void 0&&(n.push(t.assignTexture(e,"clearcoatNormalMap",i.clearcoatNormalTexture)),i.clearcoatNormalTexture.scale!==void 0)){const r=i.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new Ne(r,r)}return Promise.all(n)}},Po=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_DISPERSION}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser.json.materials[o];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const s=t.extensions[this.name];return e.dispersion=s.dispersion!==void 0?s.dispersion:0,Promise.resolve()}},Lo=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_IRIDESCENCE}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser,s=t.json.materials[o];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=[],i=s.extensions[this.name];return i.iridescenceFactor!==void 0&&(e.iridescence=i.iridescenceFactor),i.iridescenceTexture!==void 0&&n.push(t.assignTexture(e,"iridescenceMap",i.iridescenceTexture)),i.iridescenceIor!==void 0&&(e.iridescenceIOR=i.iridescenceIor),e.iridescenceThicknessRange===void 0&&(e.iridescenceThicknessRange=[100,400]),i.iridescenceThicknessMinimum!==void 0&&(e.iridescenceThicknessRange[0]=i.iridescenceThicknessMinimum),i.iridescenceThicknessMaximum!==void 0&&(e.iridescenceThicknessRange[1]=i.iridescenceThicknessMaximum),i.iridescenceThicknessTexture!==void 0&&n.push(t.assignTexture(e,"iridescenceThicknessMap",i.iridescenceThicknessTexture)),Promise.all(n)}},No=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_SHEEN}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser,s=t.json.materials[o];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=[];e.sheenColor=new we(0,0,0),e.sheenRoughness=0,e.sheen=1;const i=s.extensions[this.name];if(i.sheenColorFactor!==void 0){const r=i.sheenColorFactor;e.sheenColor.setRGB(r[0],r[1],r[2],nt)}return i.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=i.sheenRoughnessFactor),i.sheenColorTexture!==void 0&&n.push(t.assignTexture(e,"sheenColorMap",i.sheenColorTexture,ue)),i.sheenRoughnessTexture!==void 0&&n.push(t.assignTexture(e,"sheenRoughnessMap",i.sheenRoughnessTexture)),Promise.all(n)}},Co=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_TRANSMISSION}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser,s=t.json.materials[o];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=[],i=s.extensions[this.name];return i.transmissionFactor!==void 0&&(e.transmission=i.transmissionFactor),i.transmissionTexture!==void 0&&n.push(t.assignTexture(e,"transmissionMap",i.transmissionTexture)),Promise.all(n)}},Oo=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_VOLUME}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser,s=t.json.materials[o];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=[],i=s.extensions[this.name];e.thickness=i.thicknessFactor!==void 0?i.thicknessFactor:0,i.thicknessTexture!==void 0&&n.push(t.assignTexture(e,"thicknessMap",i.thicknessTexture)),e.attenuationDistance=i.attenuationDistance||1/0;const r=i.attenuationColor||[1,1,1];return e.attenuationColor=new we().setRGB(r[0],r[1],r[2],nt),Promise.all(n)}},Do=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_IOR}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser.json.materials[o];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const s=t.extensions[this.name];return e.ior=s.ior!==void 0?s.ior:1.5,Promise.resolve()}},ko=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_SPECULAR}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser,s=t.json.materials[o];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=[],i=s.extensions[this.name];e.specularIntensity=i.specularFactor!==void 0?i.specularFactor:1,i.specularTexture!==void 0&&n.push(t.assignTexture(e,"specularIntensityMap",i.specularTexture));const r=i.specularColorFactor||[1,1,1];return e.specularColor=new we().setRGB(r[0],r[1],r[2],nt),i.specularColorTexture!==void 0&&n.push(t.assignTexture(e,"specularColorMap",i.specularColorTexture,ue)),Promise.all(n)}},Uo=class{constructor(o){this.parser=o,this.name=se.EXT_MATERIALS_BUMP}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser,s=t.json.materials[o];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=[],i=s.extensions[this.name];return e.bumpScale=i.bumpFactor!==void 0?i.bumpFactor:1,i.bumpTexture!==void 0&&n.push(t.assignTexture(e,"bumpMap",i.bumpTexture)),Promise.all(n)}},Fo=class{constructor(o){this.parser=o,this.name=se.KHR_MATERIALS_ANISOTROPY}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:dt}extendMaterialParams(o,e){const t=this.parser,s=t.json.materials[o];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=[],i=s.extensions[this.name];return i.anisotropyStrength!==void 0&&(e.anisotropy=i.anisotropyStrength),i.anisotropyRotation!==void 0&&(e.anisotropyRotation=i.anisotropyRotation),i.anisotropyTexture!==void 0&&n.push(t.assignTexture(e,"anisotropyMap",i.anisotropyTexture)),Promise.all(n)}};class zo{constructor(e){this.parser=e,this.name=se.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 jo{constructor(e){this.parser=e,this.name=se.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],a=n.images[r.source];let l=s.textureLoader;if(a.uri){const c=s.options.manager.getHandler(a.uri);c!==null&&(l=c)}return this.detectSupport().then(function(c){if(c)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 Bo{constructor(e){this.parser=e,this.name=se.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],a=n.images[r.source];let l=s.textureLoader;if(a.uri){const c=s.options.manager.getHandler(a.uri);c!==null&&(l=c)}return this.detectSupport().then(function(c){if(c)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 Ho{constructor(e){this.name=se.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(a){const l=n.byteOffset||0,c=n.byteLength||0,h=n.count,u=n.byteStride,p=new Uint8Array(a,l,c);return r.decodeGltfBufferAsync?r.decodeGltfBufferAsync(h,u,p,n.mode,n.filter).then(function(f){return f.buffer}):r.ready.then(function(){const f=new ArrayBuffer(h*u);return r.decodeGltfBuffer(new Uint8Array(f),h,u,p,n.mode,n.filter),f})})}else return null}}let Go=class{constructor(o){this.name=se.EXT_MESH_GPU_INSTANCING,this.parser=o}createNodeMesh(o){const e=this.parser.json,t=e.nodes[o];if(!t.extensions||!t.extensions[this.name]||t.mesh===void 0)return null;const s=e.meshes[t.mesh];for(const a of s.primitives)if(a.mode!==st.TRIANGLES&&a.mode!==st.TRIANGLE_STRIP&&a.mode!==st.TRIANGLE_FAN&&a.mode!==void 0)return null;const n=t.extensions[this.name].attributes,i=[],r={};for(const a in n)i.push(this.parser.getDependency("accessor",n[a]).then(l=>(r[a]=l,r[a])));return i.length<1?null:(i.push(this.parser.createNodeMesh(o)),Promise.all(i).then(a=>{const l=a.pop(),c=l.isGroup?l.children:[l],h=a[0].count,u=[];for(const p of c){const f=new oe,y=new U,v=new ve,g=new U(1,1,1),x=new Zr(p.geometry,p.material,h);for(let T=0;T<h;T++)r.TRANSLATION&&y.fromBufferAttribute(r.TRANSLATION,T),r.ROTATION&&v.fromBufferAttribute(r.ROTATION,T),r.SCALE&&g.fromBufferAttribute(r.SCALE,T),x.setMatrixAt(T,f.compose(y,v,g));for(const T in r)if(T==="_COLOR_0"){const b=r[T];x.instanceColor=new qr(b.array,b.itemSize,b.normalized)}else T!=="TRANSLATION"&&T!=="ROTATION"&&T!=="SCALE"&&p.geometry.setAttribute(T,r[T]);pt.prototype.copy.call(x,p),this.parser.assignFinalMaterial(x),u.push(x)}return l.isGroup?(l.clear(),l.add(...u),l):u[0]}))}};const bi="glTF",un=12,Ti={JSON:1313821514,BIN:5130562};class Xo{constructor(e){this.name=se.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,un),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!==bi)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-un,i=new DataView(e,un);let r=0;for(;r<n;){const a=i.getUint32(r,!0);r+=4;const l=i.getUint32(r,!0);if(r+=4,l===Ti.JSON){const c=new Uint8Array(e,un+r,a);this.content=s.decode(c)}else if(l===Ti.BIN){const c=un+r;this.body=e.slice(c,c+a)}r+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Vo{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=se.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,a={},l={},c={};for(const h in r){const u=fs[h]||h.toLowerCase();a[u]=r[h]}for(const h in e.attributes){const u=fs[h]||h.toLowerCase();if(r[h]!==void 0){const p=s.accessors[e.attributes[h]],f=Jt[p.componentType];c[u]=f.name,l[u]=p.normalized===!0}}return t.getDependency("bufferView",i).then(function(h){return new Promise(function(u,p){n.decodeDracoFile(h,function(f){for(const y in f.attributes){const v=f.attributes[y],g=l[y];g!==void 0&&(v.normalized=g)}u(f)},a,c,nt,p)})})}}class Yo{constructor(){this.name=se.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=se.KHR_MESH_QUANTIZATION}}class Ai extends eo{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,a=this.valueSize,l=a*2,c=a*3,h=n-t,u=(s-t)/h,p=u*u,f=p*u,y=e*c,v=y-c,g=-2*f+3*p,x=f-p,T=1-g,b=x-p+u;for(let _=0;_!==a;_++){const S=r[v+_+a],I=r[v+_+l]*h,P=r[y+_+a],M=r[y+_]*h;i[_]=T*S+b*I+g*P+x*M}return i}}const Ko=new ve;class Zo extends Ai{interpolate_(e,t,s,n){const i=super.interpolate_(e,t,s,n);return Ko.fromArray(i).normalize().toArray(i),i}}const st={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Jt={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Ei={9728:ti,9729:xt,9984:ei,9985:Js,9986:$s,9987:Qn},Si={33071:_n,33648:ni,10497:Ft},ps={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},fs={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"},Lt={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},qo={CUBICSPLINE:void 0,LINEAR:ts,STEP:ai},ms={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function Qo(o){return o.DefaultMaterial===void 0&&(o.DefaultMaterial=new $n({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:li})),o.DefaultMaterial}function Bt(o,e,t){for(const s in t.extensions)o[s]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[s]=t.extensions[s])}function Et(o,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(o.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function $o(o,e,t){let s=!1,n=!1,i=!1;for(let c=0,h=e.length;c<h;c++){const u=e[c];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(o);const r=[],a=[],l=[];for(let c=0,h=e.length;c<h;c++){const u=e[c];if(s){const p=u.POSITION!==void 0?t.getDependency("accessor",u.POSITION):o.attributes.position;r.push(p)}if(n){const p=u.NORMAL!==void 0?t.getDependency("accessor",u.NORMAL):o.attributes.normal;a.push(p)}if(i){const p=u.COLOR_0!==void 0?t.getDependency("accessor",u.COLOR_0):o.attributes.color;l.push(p)}}return Promise.all([Promise.all(r),Promise.all(a),Promise.all(l)]).then(function(c){const h=c[0],u=c[1],p=c[2];return s&&(o.morphAttributes.position=h),n&&(o.morphAttributes.normal=u),i&&(o.morphAttributes.color=p),o.morphTargetsRelative=!0,o})}function Jo(o,e){if(o.updateMorphTargets(),e.weights!==void 0)for(let t=0,s=e.weights.length;t<s;t++)o.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(o.morphTargetInfluences.length===t.length){o.morphTargetDictionary={};for(let s=0,n=t.length;s<n;s++)o.morphTargetDictionary[t[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function ea(o){let e;const t=o.extensions&&o.extensions[se.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+gs(t.attributes):e=o.indices+":"+gs(o.attributes)+":"+o.mode,o.targets!==void 0)for(let s=0,n=o.targets.length;s<n;s++)e+=":"+gs(o.targets[s]);return e}function gs(o){let e="";const t=Object.keys(o).sort();for(let s=0,n=t.length;s<n;s++)e+=t[s]+":"+o[t[s]]+";";return e}function ys(o){switch(o){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function ta(o){return o.search(/\.jpe?g($|\?)/i)>0||o.search(/^data\:image\/jpeg/)===0?"image/jpeg":o.search(/\.webp($|\?)/i)>0||o.search(/^data\:image\/webp/)===0?"image/webp":"image/png"}const na=new oe;class sa{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new So,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 a=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(a)===!0;const l=a.match(/Version\/(\d+)/);n=s&&l?parseInt(l[1],10):-1,i=a.indexOf("Firefox")>-1,r=i?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||i&&r<98?this.textureLoader=new qn(this.options.manager):this.textureLoader=new Qr(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new Kt(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 a={scene:r[0][n.scene||0],scenes:r[0],animations:r[1],cameras:r[2],asset:n.asset,parser:s,userData:{}};return Bt(i,a,n),Et(a,n),Promise.all(s._invokeAll(function(l){return l.afterRoot&&l.afterRoot(a)})).then(function(){for(const l of a.scenes)l.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 r=t[n].joints;for(let a=0,l=r.length;a<l;a++)e[r[a]].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,a)=>{const l=this.associations.get(r);l!=null&&this.associations.set(a,l);for(const[c,h]of r.children.entries())i(h,a.children[c])};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[se.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(i,r){s.load(Ut.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=ps[n.type],a=Jt[n.componentType],l=n.normalized===!0,c=new a(n.count*r);return Promise.resolve(new rt(c,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 a=r[0],l=ps[n.type],c=Jt[n.componentType],h=c.BYTES_PER_ELEMENT,u=h*l,p=n.byteOffset||0,f=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,y=n.normalized===!0;let v,g;if(f&&f!==u){const x=Math.floor(p/f),T="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+x+":"+n.count;let b=t.cache.get(T);b||(v=new c(a,x*f,n.count*f/h),b=new $r(v,f/h),t.cache.add(T,b)),g=new jt(b,l,p%f/h,y)}else a===null?v=new c(n.count*l):v=new c(a,p,n.count*l),g=new rt(v,l,y);if(n.sparse!==void 0){const x=ps.SCALAR,T=Jt[n.sparse.indices.componentType],b=n.sparse.indices.byteOffset||0,_=n.sparse.values.byteOffset||0,S=new T(r[1],b,n.sparse.count*x),I=new c(r[2],_,n.sparse.count*l);a!==null&&(g=new rt(g.array.slice(),g.itemSize,g.normalized)),g.normalized=!1;for(let P=0,M=S.length;P<M;P++){const D=S[P];if(g.setX(D,I[P*l]),l>=2&&g.setY(D,I[P*l+1]),l>=3&&g.setZ(D,I[P*l+2]),l>=4&&g.setW(D,I[P*l+3]),l>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}g.normalized=y}return g})}loadTexture(e){const t=this.json,s=this.options,n=t.textures[e].source,i=t.images[n];let r=this.textureLoader;if(i.uri){const a=s.manager.getHandler(i.uri);a!==null&&(r=a)}return this.loadTextureImage(e,n,r)}loadTextureImage(e,t,s){const n=this,i=this.json,r=i.textures[e],a=i.images[t],l=(a.uri||a.bufferView)+":"+r.sampler;if(this.textureCache[l])return this.textureCache[l];const c=this.loadImageSource(t,s).then(function(h){h.flipY=!1,h.name=r.name||a.name||"",h.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(h.name=a.uri);const u=(i.samplers||{})[r.sampler]||{};return h.magFilter=Ei[u.magFilter]||xt,h.minFilter=Ei[u.minFilter]||Qn,h.wrapS=Si[u.wrapS]||Ft,h.wrapT=Si[u.wrapT]||Ft,h.anisotropy=4,n.associations.set(h,{textures:e}),h}).catch(function(){return null});return this.textureCache[l]=c,c}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 r=n.images[e],a=self.URL||self.webkitURL;let l=r.uri||"",c=!1;if(r.bufferView!==void 0)l=s.getDependency("bufferView",r.bufferView).then(function(u){c=!0;const p=new Blob([u],{type:r.mimeType});return l=a.createObjectURL(p),l});else if(r.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const h=Promise.resolve(l).then(function(u){return new Promise(function(p,f){let y=p;t.isImageBitmapLoader===!0&&(y=function(v){const g=new ns(v);g.needsUpdate=!0,p(g)}),t.load(Ut.resolveURL(u,i.path),y,void 0,f)})}).then(function(u){return c===!0&&a.revokeObjectURL(l),Et(u,r),u.userData.mimeType=r.mimeType||ta(r.uri),u}).catch(function(u){throw console.error("THREE.GLTFLoader: Couldn't load texture",l),u});return this.sourceCache[e]=h,h}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[se.KHR_TEXTURE_TRANSFORM]){const a=s.extensions!==void 0?s.extensions[se.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const l=i.associations.get(r);r=i.extensions[se.KHR_TEXTURE_TRANSFORM].extendTexture(r,a),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 a="PointsMaterial:"+s.uuid;let l=this.cache.get(a);l||(l=new on,an.prototype.copy.call(l,s),l.color.copy(s.color),l.map=s.map,l.sizeAttenuation=!1,this.cache.add(a,l)),s=l}else if(e.isLine){const a="LineBasicMaterial:"+s.uuid;let l=this.cache.get(a);l||(l=new bt,an.prototype.copy.call(l,s),l.color.copy(s.color),l.map=s.map,this.cache.add(a,l)),s=l}if(n||i||r){let a="ClonedMaterial:"+s.uuid+":";n&&(a+="derivative-tangents:"),i&&(a+="vertex-colors:"),r&&(a+="flat-shading:");let l=this.cache.get(a);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(a,l),this.associations.set(l,this.associations.get(s))),s=l}e.material=s}getMaterialType(){return $n}loadMaterial(e){const t=this,s=this.json,n=this.extensions,i=s.materials[e];let r;const a={},l=i.extensions||{},c=[];if(l[se.KHR_MATERIALS_UNLIT]){const u=n[se.KHR_MATERIALS_UNLIT];r=u.getMaterialType(),c.push(u.extendParams(a,i,t))}else{const u=i.pbrMetallicRoughness||{};if(a.color=new we(1,1,1),a.opacity=1,Array.isArray(u.baseColorFactor)){const p=u.baseColorFactor;a.color.setRGB(p[0],p[1],p[2],nt),a.opacity=p[3]}u.baseColorTexture!==void 0&&c.push(t.assignTexture(a,"map",u.baseColorTexture,ue)),a.metalness=u.metallicFactor!==void 0?u.metallicFactor:1,a.roughness=u.roughnessFactor!==void 0?u.roughnessFactor:1,u.metallicRoughnessTexture!==void 0&&(c.push(t.assignTexture(a,"metalnessMap",u.metallicRoughnessTexture)),c.push(t.assignTexture(a,"roughnessMap",u.metallicRoughnessTexture))),r=this._invokeOne(function(p){return p.getMaterialType&&p.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(p){return p.extendMaterialParams&&p.extendMaterialParams(e,a)})))}i.doubleSided===!0&&(a.side=Jn);const h=i.alphaMode||ms.OPAQUE;if(h===ms.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,h===ms.MASK&&(a.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&r!==ht&&(c.push(t.assignTexture(a,"normalMap",i.normalTexture)),a.normalScale=new Ne(1,1),i.normalTexture.scale!==void 0)){const u=i.normalTexture.scale;a.normalScale.set(u,u)}if(i.occlusionTexture!==void 0&&r!==ht&&(c.push(t.assignTexture(a,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&r!==ht){const u=i.emissiveFactor;a.emissive=new we().setRGB(u[0],u[1],u[2],nt)}return i.emissiveTexture!==void 0&&r!==ht&&c.push(t.assignTexture(a,"emissiveMap",i.emissiveTexture,ue)),Promise.all(c).then(function(){const u=new r(a);return i.name&&(u.name=i.name),Et(u,i),t.associations.set(u,{materials:e}),i.extensions&&Bt(n,u,i),u})}createUniqueName(e){const t=Tt.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(a){return s[se.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(l){return Mi(l,a,t)})}const r=[];for(let a=0,l=e.length;a<l;a++){const c=e[a],h=ea(c),u=n[h];if(u)r.push(u.promise);else{let p;c.extensions&&c.extensions[se.KHR_DRACO_MESH_COMPRESSION]?p=i(c):p=Mi(new ot,c,t),n[h]={primitive:c,promise:p},r.push(p)}}return Promise.all(r)}loadMesh(e){const t=this,s=this.json,n=this.extensions,i=s.meshes[e],r=i.primitives,a=[];for(let l=0,c=r.length;l<c;l++){const h=r[l].material===void 0?Qo(this.cache):this.getDependency("material",r[l].material);a.push(h)}return a.push(t.loadGeometries(r)),Promise.all(a).then(function(l){const c=l.slice(0,l.length-1),h=l[l.length-1],u=[];for(let f=0,y=h.length;f<y;f++){const v=h[f],g=r[f];let x;const T=c[f];if(g.mode===st.TRIANGLES||g.mode===st.TRIANGLE_STRIP||g.mode===st.TRIANGLE_FAN||g.mode===void 0)x=i.isSkinnedMesh===!0?new si(v,T):new B(v,T),x.isSkinnedMesh===!0&&x.normalizeSkinWeights(),g.mode===st.TRIANGLE_STRIP?x.geometry=xi(x.geometry,Zs):g.mode===st.TRIANGLE_FAN&&(x.geometry=xi(x.geometry,Kn));else if(g.mode===st.LINES)x=new In(v,T);else if(g.mode===st.LINE_STRIP)x=new at(v,T);else if(g.mode===st.LINE_LOOP)x=new Jr(v,T);else if(g.mode===st.POINTS)x=new Rn(v,T);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+g.mode);Object.keys(x.geometry.morphAttributes).length>0&&Jo(x,i),x.name=t.createUniqueName(i.name||"mesh_"+e),Et(x,i),g.extensions&&Bt(n,x,g),t.assignFinalMaterial(x),u.push(x)}for(let f=0,y=u.length;f<y;f++)t.associations.set(u[f],{meshes:e,primitives:f});if(u.length===1)return i.extensions&&Bt(n,u[0],i),u[0];const p=new zt;i.extensions&&Bt(n,p,i),t.associations.set(p,{meshes:e});for(let f=0,y=u.length;f<y;f++)p.add(u[f]);return p})}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 Mn(ge.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(t=new ii(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(t.name=this.createUniqueName(s.name)),Et(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,a=[],l=[];for(let c=0,h=r.length;c<h;c++){const u=r[c];if(u){a.push(u);const p=new oe;i!==null&&p.fromArray(i.array,c*16),l.push(p)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[c])}return new ri(a,l)})}loadAnimation(e){const t=this.json,s=this,n=t.animations[e],i=n.name?n.name:"animation_"+e,r=[],a=[],l=[],c=[],h=[];let u=0,p=n.channels.length;for(u=0,p=n.channels.length;u<p;u++){const f=n.channels[u],y=n.samplers[f.sampler],v=f.target,g=v.node,x=n.parameters!==void 0?n.parameters[y.input]:y.input,T=n.parameters!==void 0?n.parameters[y.output]:y.output;v.node!==void 0&&(r.push(this.getDependency("node",g)),a.push(this.getDependency("accessor",x)),l.push(this.getDependency("accessor",T)),c.push(y),h.push(v))}return Promise.all([Promise.all(r),Promise.all(a),Promise.all(l),Promise.all(c),Promise.all(h)]).then(function(f){const y=f[0],v=f[1],g=f[2],x=f[3],T=f[4],b=[];for(u=0,p=y.length;u<p;u++){const _=y[u],S=v[u],I=g[u],P=x[u],M=T[u];if(_===void 0)continue;_.updateMatrix&&_.updateMatrix();const D=s._createAnimationTracks(_,S,I,P,M);if(D)for(let K=0;K<D.length;K++)b.push(D[K])}return new oi(i,void 0,b)})}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(a){if(a.isMesh)for(let l=0,c=n.weights.length;l<c;l++)a.morphTargetInfluences[l]=n.weights[l]}),r})}loadNode(e){const t=this.json,s=this,n=t.nodes[e],i=s._loadNodeShallow(e),r=[],a=n.children||[];for(let c=0,h=a.length;c<h;c++)r.push(s.getDependency("node",a[c]));const l=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([i,Promise.all(r),l]).then(function(c){const h=c[0],u=c[1],p=c[2];p!==null&&h.traverse(function(f){f.isSkinnedMesh&&f.bind(p,na)});for(let f=0,y=u.length;f<y;f++)h.add(u[f]);return h})}_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):"",a=[],l=n._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(e)});return l&&a.push(l),i.camera!==void 0&&a.push(n.getDependency("camera",i.camera).then(function(c){return n._getNodeRef(n.cameraCache,i.camera,c)})),n._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(e)}).forEach(function(c){a.push(c)}),this.nodeCache[e]=Promise.all(a).then(function(c){let h;if(i.isBone===!0?h=new es:c.length>1?h=new zt:c.length===1?h=c[0]:h=new pt,h!==c[0])for(let u=0,p=c.length;u<p;u++)h.add(c[u]);if(i.name&&(h.userData.name=i.name,h