@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.
1 lines • 350 kB
JavaScript
import{Mesh as O,SphereGeometry as oi,Vector3 as N,MeshBasicMaterial as mt,TrianglesDrawMode as qo,TriangleFanDrawMode as ri,TriangleStripDrawMode as Cn,Loader as xt,LoaderUtils as qt,FileLoader as ht,MeshPhysicalMaterial as bt,Vector2 as _e,Color as Be,LinearSRGBColorSpace as Ve,SRGBColorSpace as ce,SpotLight as Bn,PointLight as Ai,DirectionalLight as wn,Matrix4 as le,InstancedMesh as zo,Quaternion as we,InstancedBufferAttribute as Yo,Object3D as It,TextureLoader as ci,ImageBitmapLoader as Ko,BufferAttribute as st,InterleavedBuffer as Jo,LinearMipmapLinearFilter as hs,NearestMipmapLinearFilter as Qn,LinearMipmapNearestFilter as yn,NearestMipmapNearestFilter as li,LinearFilter as it,NearestFilter as Ls,RepeatWrapping as zt,MirroredRepeatWrapping as vn,ClampToEdgeWrapping as Ns,PointsMaterial as gs,Material as ds,LineBasicMaterial as St,MeshStandardMaterial as hi,DoubleSide as gi,PropertyBinding as Dt,BufferGeometry as rt,SkinnedMesh as xn,LineSegments as Us,Line as gt,LineLoop as Vo,Points as Gs,Group as Yt,PerspectiveCamera as Ps,MathUtils as Ee,OrthographicCamera as Sn,Skeleton as Dn,AnimationClip as Rn,Bone as di,InterpolateDiscrete as Tn,InterpolateLinear as pi,InterleavedBufferAttribute as Kt,Texture as ui,VectorKeyframeTrack as fi,NumberKeyframeTrack as mi,QuaternionKeyframeTrack as bi,ColorManagement as We,FrontSide as kn,Interpolant as Wo,Box3 as Os,Sphere as Ii,CompressedCubeTexture as Xo,CompressedArrayTexture as Zo,CompressedTexture as ps,NoColorSpace as Hs,RGBA_BPTC_Format as Ei,RGBA_S3TC_DXT5_Format as Ci,RGBA_S3TC_DXT3_Format as Mn,RGB_S3TC_DXT1_Format as Fn,RGBA_S3TC_DXT1_Format as Bi,RGBA_ASTC_6x6_Format as _n,RGBA_ASTC_4x4_Format as js,RGBA_ETC2_EAC_Format as Ln,RGB_ETC2_Format as Nn,RGBFormat as wi,RedFormat as ts,RGFormat as us,RGBAFormat as Nt,UnsignedByteType as dt,HalfFloatType as Xe,UnsignedInt101111Type as Un,UnsignedInt5999Type as Gn,FloatType as pt,DataTexture as $o,Data3DTexture as er,RGB_PVRTC_4BPPV1_Format as tr,RGB_ETC1_Format as sr,RGBA_PVRTC_4BPPV1_Format as ir,RGB_BPTC_UNSIGNED_Format as nr,NodeFrame as ar,ShaderLib as Et,ExtrudeGeometry as or,ShapePath as rr,DataTextureLoader as Pn,DataUtils as ss,CylinderGeometry as Ze,BoxGeometry as Ye,Float32BufferAttribute as Te,OctahedronGeometry as qs,TorusGeometry as fs,Euler as Ut,Controls as On,Raycaster as Qi,PlaneGeometry as yi,MOUSE as is,TOUCH as ns,Spherical as Hn,Ray as Ar,Plane as cr,ShaderMaterial as jn,Uniform$1 as lr,Scene as vi,WebGLRenderer as hr,CanvasTexture as qn,REVISION as gr,Source as dr,InstancedBufferGeometry as pr,InstancedInterleavedBuffer as xi,WireframeGeometry as ur,UniformsUtils as zn,UniformsLib as zs,Vector4 as Rt,Line3 as fr,Matrix3 as Yn,Curve as mr,MeshPhongMaterial as ms,MeshLambertMaterial as br,EquirectangularReflectionMapping as Ir,AmbientLight as Er,Uint16BufferAttribute as Cr,ShapeUtils as Br,DefaultLoadingManager as wr}from"./three.min.js";class Qr extends O{constructor(e,t,i,s=128){if(t<=0||i<=0||s<=0)throw new Error("GroundedSkybox height, radius, and resolution must be positive.");const n=new oi(i,2*s,s);n.scale(1,1,-1);const a=n.getAttribute("position"),r=new N;for(let A=0;A<a.count;++A)if(r.fromBufferAttribute(a,A),r.y<0){const c=-t*3/2,l=r.y<c?-t/r.y:1-r.y*r.y/(3*c*c);r.multiplyScalar(l),r.toArray(a.array,3*A)}a.needsUpdate=!0,super(n,new mt({map:e,depthWrite:!1}))}}function yr(o,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},i=o.getIndex(),s=o.getAttribute("position"),n=i?i.count:s.count;let a=0;const r=Object.keys(o.attributes),A={},c={},l=[],h=["getX","getY","getZ","getW"],d=["setX","setY","setZ","setW"];for(let E=0,C=r.length;E<C;E++){const Q=r[E],w=o.attributes[Q];A[Q]=new w.constructor(new w.array.constructor(w.count*w.itemSize),w.itemSize,w.normalized);const x=o.morphAttributes[Q];x&&(c[Q]||(c[Q]=[]),x.forEach((D,S)=>{const F=new D.array.constructor(D.count*D.itemSize);c[Q][S]=new D.constructor(F,D.itemSize,D.normalized)}))}const p=e*.5,f=Math.log10(1/e),b=Math.pow(10,f),m=p*b;for(let E=0;E<n;E++){const C=i?i.getX(E):E;let Q="";for(let w=0,x=r.length;w<x;w++){const D=r[w],S=o.getAttribute(D),F=S.itemSize;for(let Y=0;Y<F;Y++)Q+=`${~~(S[h[Y]](C)*b+m)},`}if(Q in t)l.push(t[Q]);else{for(let w=0,x=r.length;w<x;w++){const D=r[w],S=o.getAttribute(D),F=o.morphAttributes[D],Y=S.itemSize,V=A[D],K=c[D];for(let W=0;W<Y;W++){const j=h[W],X=d[W];if(V[X](a,S[j](C)),F)for(let J=0,ee=F.length;J<ee;J++)K[J][X](a,F[J][j](C))}}t[Q]=a,l.push(a),a++}}const I=o.clone();for(const E in o.attributes){const C=A[E];if(I.setAttribute(E,new C.constructor(C.array.slice(0,a*C.itemSize),C.itemSize,C.normalized)),E in c)for(let Q=0;Q<c[E].length;Q++){const w=c[E][Q];I.morphAttributes[E][Q]=new w.constructor(w.array.slice(0,a*w.itemSize),w.itemSize,w.normalized)}}return I.setIndex(l),I}function Kn(o,e){if(e===qo)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),o;if(e===ri||e===Cn){let t=o.getIndex();if(t===null){const a=[],r=o.getAttribute("position");if(r!==void 0){for(let A=0;A<r.count;A++)a.push(A);o.setIndex(a),t=o.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),o}const i=t.count-2,s=[];if(e===ri)for(let a=1;a<=i;a++)s.push(t.getX(0)),s.push(t.getX(a)),s.push(t.getX(a+1));else for(let a=0;a<i;a++)a%2===0?(s.push(t.getX(a)),s.push(t.getX(a+1)),s.push(t.getX(a+2))):(s.push(t.getX(a+2)),s.push(t.getX(a+1)),s.push(t.getX(a)));s.length/3!==i&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const n=o.clone();return n.setIndex(s),n.clearGroups(),n}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),o}class Si extends xt{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Rr(t)}),this.register(function(t){return new Tr(t)}),this.register(function(t){return new Pr(t)}),this.register(function(t){return new Or(t)}),this.register(function(t){return new Hr(t)}),this.register(function(t){return new Mr(t)}),this.register(function(t){return new Fr(t)}),this.register(function(t){return new _r(t)}),this.register(function(t){return new Lr(t)}),this.register(function(t){return new Dr(t)}),this.register(function(t){return new Nr(t)}),this.register(function(t){return new kr(t)}),this.register(function(t){return new Gr(t)}),this.register(function(t){return new Ur(t)}),this.register(function(t){return new xr(t)}),this.register(function(t){return new jr(t)}),this.register(function(t){return new qr(t)})}load(e,t,i,s){const n=this;let a;if(this.resourcePath!=="")a=this.resourcePath;else if(this.path!==""){const c=qt.extractUrlBase(e);a=qt.resolveURL(c,this.path)}else a=qt.extractUrlBase(e);this.manager.itemStart(e);const r=function(c){s?s(c):console.error(c),n.manager.itemError(e),n.manager.itemEnd(e)},A=new ht(this.manager);A.setPath(this.path),A.setResponseType("arraybuffer"),A.setRequestHeader(this.requestHeader),A.setWithCredentials(this.withCredentials),A.load(e,function(c){try{n.parse(c,a,function(l){t(l),n.manager.itemEnd(e)},r)}catch(l){r(l)}},i,r)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,i,s){let n,a;const r={},A={},c=new TextDecoder;if(typeof e=="string")try{n=JSON.parse(e)}catch(h){a=e,s&&s(h);return}else if(e instanceof ArrayBuffer)if(c.decode(new Uint8Array(e,0,4))===Jn){try{r[ne.KHR_BINARY_GLTF]=new zr(e)}catch(h){s&&s(h);return}try{n=JSON.parse(r[ne.KHR_BINARY_GLTF].content)}catch(h){a=r[ne.KHR_BINARY_GLTF].content,s&&s(h);return}}else try{n=JSON.parse(c.decode(e))}catch(h){a=c.decode(e),s&&s(h);return}else n=e;if(n.asset===void 0||n.asset.version[0]<2){s&&s(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}this.json=n,this.jsonErrorData=a;const l=new nA(n,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});l.fileLoader.setRequestHeader(this.requestHeader);for(let h=0;h<this.pluginCallbacks.length;h++){const d=this.pluginCallbacks[h](l);d.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),A[d.name]=d,r[d.name]=!0}if(n.extensionsUsed)for(let h=0;h<n.extensionsUsed.length;++h){const d=n.extensionsUsed[h],p=n.extensionsRequired||[];switch(d){case ne.KHR_MATERIALS_UNLIT:r[d]=new Sr;break;case ne.KHR_DRACO_MESH_COMPRESSION:r[d]=new Yr(n,this.dracoLoader);break;case ne.KHR_TEXTURE_TRANSFORM:r[d]=new Kr;break;case ne.KHR_MESH_QUANTIZATION:r[d]=new Jr;break;default:p.indexOf(d)>=0&&A[d]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+d+'".')}}l.setExtensions(r),l.setPlugins(A),l.parse(i,s)}parseAsync(e,t){const i=this;return new Promise(function(s,n){i.parse(e,t,s,n)})}}function vr(){let o={};return{get:function(e){return o[e]},add:function(e,t){o[e]=t},remove:function(e){delete o[e]},removeAll:function(){o={}}}}const ne={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class xr{constructor(e){this.parser=e,this.name=ne.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let i=0,s=t.length;i<s;i++){const n=t[i];n.extensions&&n.extensions[this.name]&&n.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(e){const t=this.parser,i="light:"+e;let s=t.cache.get(i);if(s)return s;const n=t.json,a=((n.extensions&&n.extensions[this.name]||{}).lights||[])[e];let r;const A=new Be(16777215);a.color!==void 0&&A.setRGB(a.color[0],a.color[1],a.color[2],Ve);const c=a.range!==void 0?a.range:0;switch(a.type){case"directional":r=new wn(A),r.target.position.set(0,0,-1),r.add(r.target);break;case"point":r=new Ai(A),r.distance=c;break;case"spot":r=new Bn(A),r.distance=c,a.spot=a.spot||{},a.spot.innerConeAngle=a.spot.innerConeAngle!==void 0?a.spot.innerConeAngle:0,a.spot.outerConeAngle=a.spot.outerConeAngle!==void 0?a.spot.outerConeAngle:Math.PI/4,r.angle=a.spot.outerConeAngle,r.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,r.target.position.set(0,0,-1),r.add(r.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+a.type)}return r.position.set(0,0,0),r.decay=2,Tt(r,a),a.intensity!==void 0&&(r.intensity=a.intensity),r.name=t.createUniqueName(a.name||"light_"+e),s=Promise.resolve(r),t.cache.add(i,s),s}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,i=this.parser,s=i.json.nodes[e],n=(s.extensions&&s.extensions[this.name]||{}).light;return n===void 0?null:this._loadLight(n).then(function(a){return i._getNodeRef(t.cache,n,a)})}}let Sr=class{constructor(){this.name=ne.KHR_MATERIALS_UNLIT}getMaterialType(){return mt}extendParams(o,e,t){const i=[];o.color=new Be(1,1,1),o.opacity=1;const s=e.pbrMetallicRoughness;if(s){if(Array.isArray(s.baseColorFactor)){const n=s.baseColorFactor;o.color.setRGB(n[0],n[1],n[2],Ve),o.opacity=n[3]}s.baseColorTexture!==void 0&&i.push(t.assignTexture(o,"map",s.baseColorTexture,ce))}return Promise.all(i)}},Dr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(o,e){const t=this.parser.json.materials[o];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=t.extensions[this.name].emissiveStrength;return i!==void 0&&(e.emissiveIntensity=i),Promise.resolve()}},Rr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_CLEARCOAT}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];if(n.clearcoatFactor!==void 0&&(e.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&s.push(t.assignTexture(e,"clearcoatMap",n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&s.push(t.assignTexture(e,"clearcoatRoughnessMap",n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(s.push(t.assignTexture(e,"clearcoatNormalMap",n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){const a=n.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new _e(a,a)}return Promise.all(s)}},Tr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_DISPERSION}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser.json.materials[o];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=t.extensions[this.name];return e.dispersion=i.dispersion!==void 0?i.dispersion:0,Promise.resolve()}},kr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_IRIDESCENCE}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];return n.iridescenceFactor!==void 0&&(e.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&s.push(t.assignTexture(e,"iridescenceMap",n.iridescenceTexture)),n.iridescenceIor!==void 0&&(e.iridescenceIOR=n.iridescenceIor),e.iridescenceThicknessRange===void 0&&(e.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(e.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(e.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&s.push(t.assignTexture(e,"iridescenceThicknessMap",n.iridescenceThicknessTexture)),Promise.all(s)}},Mr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_SHEEN}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[];e.sheenColor=new Be(0,0,0),e.sheenRoughness=0,e.sheen=1;const n=i.extensions[this.name];if(n.sheenColorFactor!==void 0){const a=n.sheenColorFactor;e.sheenColor.setRGB(a[0],a[1],a[2],Ve)}return n.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&s.push(t.assignTexture(e,"sheenColorMap",n.sheenColorTexture,ce)),n.sheenRoughnessTexture!==void 0&&s.push(t.assignTexture(e,"sheenRoughnessMap",n.sheenRoughnessTexture)),Promise.all(s)}},Fr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_TRANSMISSION}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];return n.transmissionFactor!==void 0&&(e.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&s.push(t.assignTexture(e,"transmissionMap",n.transmissionTexture)),Promise.all(s)}},_r=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_VOLUME}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];e.thickness=n.thicknessFactor!==void 0?n.thicknessFactor:0,n.thicknessTexture!==void 0&&s.push(t.assignTexture(e,"thicknessMap",n.thicknessTexture)),e.attenuationDistance=n.attenuationDistance||1/0;const a=n.attenuationColor||[1,1,1];return e.attenuationColor=new Be().setRGB(a[0],a[1],a[2],Ve),Promise.all(s)}},Lr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_IOR}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser.json.materials[o];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=t.extensions[this.name];return e.ior=i.ior!==void 0?i.ior:1.5,Promise.resolve()}},Nr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_SPECULAR}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];e.specularIntensity=n.specularFactor!==void 0?n.specularFactor:1,n.specularTexture!==void 0&&s.push(t.assignTexture(e,"specularIntensityMap",n.specularTexture));const a=n.specularColorFactor||[1,1,1];return e.specularColor=new Be().setRGB(a[0],a[1],a[2],Ve),n.specularColorTexture!==void 0&&s.push(t.assignTexture(e,"specularColorMap",n.specularColorTexture,ce)),Promise.all(s)}},Ur=class{constructor(o){this.parser=o,this.name=ne.EXT_MATERIALS_BUMP}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];return e.bumpScale=n.bumpFactor!==void 0?n.bumpFactor:1,n.bumpTexture!==void 0&&s.push(t.assignTexture(e,"bumpMap",n.bumpTexture)),Promise.all(s)}},Gr=class{constructor(o){this.parser=o,this.name=ne.KHR_MATERIALS_ANISOTROPY}getMaterialType(o){const e=this.parser.json.materials[o];return!e.extensions||!e.extensions[this.name]?null:bt}extendMaterialParams(o,e){const t=this.parser,i=t.json.materials[o];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],n=i.extensions[this.name];return n.anisotropyStrength!==void 0&&(e.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(e.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&s.push(t.assignTexture(e,"anisotropyMap",n.anisotropyTexture)),Promise.all(s)}};class Pr{constructor(e){this.parser=e,this.name=ne.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,i=t.json,s=i.textures[e];if(!s.extensions||!s.extensions[this.name])return null;const n=s.extensions[this.name],a=t.options.ktx2Loader;if(!a){if(i.extensionsRequired&&i.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,n.source,a)}}class Or{constructor(e){this.parser=e,this.name=ne.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,i=this.parser,s=i.json,n=s.textures[e];if(!n.extensions||!n.extensions[t])return null;const a=n.extensions[t],r=s.images[a.source];let A=i.textureLoader;if(r.uri){const c=i.options.manager.getHandler(r.uri);c!==null&&(A=c)}return this.detectSupport().then(function(c){if(c)return i.loadTextureImage(e,a.source,A);if(s.extensionsRequired&&s.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return i.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(t.height===1)}})),this.isSupported}}class Hr{constructor(e){this.parser=e,this.name=ne.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,i=this.parser,s=i.json,n=s.textures[e];if(!n.extensions||!n.extensions[t])return null;const a=n.extensions[t],r=s.images[a.source];let A=i.textureLoader;if(r.uri){const c=i.options.manager.getHandler(r.uri);c!==null&&(A=c)}return this.detectSupport().then(function(c){if(c)return i.loadTextureImage(e,a.source,A);if(s.extensionsRequired&&s.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return i.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(t.height===1)}})),this.isSupported}}class jr{constructor(e){this.name=ne.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,i=t.bufferViews[e];if(i.extensions&&i.extensions[this.name]){const s=i.extensions[this.name],n=this.parser.getDependency("buffer",s.buffer),a=this.parser.options.meshoptDecoder;if(!a||!a.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return n.then(function(r){const A=s.byteOffset||0,c=s.byteLength||0,l=s.count,h=s.byteStride,d=new Uint8Array(r,A,c);return a.decodeGltfBufferAsync?a.decodeGltfBufferAsync(l,h,d,s.mode,s.filter).then(function(p){return p.buffer}):a.ready.then(function(){const p=new ArrayBuffer(l*h);return a.decodeGltfBuffer(new Uint8Array(p),l,h,d,s.mode,s.filter),p})})}else return null}}let qr=class{constructor(o){this.name=ne.EXT_MESH_GPU_INSTANCING,this.parser=o}createNodeMesh(o){const e=this.parser.json,t=e.nodes[o];if(!t.extensions||!t.extensions[this.name]||t.mesh===void 0)return null;const i=e.meshes[t.mesh];for(const r of i.primitives)if(r.mode!==At.TRIANGLES&&r.mode!==At.TRIANGLE_STRIP&&r.mode!==At.TRIANGLE_FAN&&r.mode!==void 0)return null;const s=t.extensions[this.name].attributes,n=[],a={};for(const r in s)n.push(this.parser.getDependency("accessor",s[r]).then(A=>(a[r]=A,a[r])));return n.length<1?null:(n.push(this.parser.createNodeMesh(o)),Promise.all(n).then(r=>{const A=r.pop(),c=A.isGroup?A.children:[A],l=r[0].count,h=[];for(const d of c){const p=new le,f=new N,b=new we,m=new N(1,1,1),I=new zo(d.geometry,d.material,l);for(let E=0;E<l;E++)a.TRANSLATION&&f.fromBufferAttribute(a.TRANSLATION,E),a.ROTATION&&b.fromBufferAttribute(a.ROTATION,E),a.SCALE&&m.fromBufferAttribute(a.SCALE,E),I.setMatrixAt(E,p.compose(f,b,m));for(const E in a)if(E==="_COLOR_0"){const C=a[E];I.instanceColor=new Yo(C.array,C.itemSize,C.normalized)}else E!=="TRANSLATION"&&E!=="ROTATION"&&E!=="SCALE"&&d.geometry.setAttribute(E,a[E]);It.prototype.copy.call(I,d),this.parser.assignFinalMaterial(I),h.push(I)}return A.isGroup?(A.clear(),A.add(...h),A):h[0]}))}};const Jn="glTF",bs=12,Vn={JSON:1313821514,BIN:5130562};class zr{constructor(e){this.name=ne.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,bs),i=new TextDecoder;if(this.header={magic:i.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==Jn)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const s=this.header.length-bs,n=new DataView(e,bs);let a=0;for(;a<s;){const r=n.getUint32(a,!0);a+=4;const A=n.getUint32(a,!0);if(a+=4,A===Vn.JSON){const c=new Uint8Array(e,bs+a,r);this.content=i.decode(c)}else if(A===Vn.BIN){const c=bs+a;this.body=e.slice(c,c+r)}a+=r}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Yr{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=ne.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const i=this.json,s=this.dracoLoader,n=e.extensions[this.name].bufferView,a=e.extensions[this.name].attributes,r={},A={},c={};for(const l in a){const h=Ri[l]||l.toLowerCase();r[h]=a[l]}for(const l in e.attributes){const h=Ri[l]||l.toLowerCase();if(a[l]!==void 0){const d=i.accessors[e.attributes[l]],p=as[d.componentType];c[h]=p.name,A[h]=d.normalized===!0}}return t.getDependency("bufferView",n).then(function(l){return new Promise(function(h,d){s.decodeDracoFile(l,function(p){for(const f in p.attributes){const b=p.attributes[f],m=A[f];m!==void 0&&(b.normalized=m)}h(p)},r,c,Ve,d)})})}}class Kr{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 Jr{constructor(){this.name=ne.KHR_MESH_QUANTIZATION}}class Wn extends Wo{constructor(e,t,i,s){super(e,t,i,s)}copySampleValue_(e){const t=this.resultBuffer,i=this.sampleValues,s=this.valueSize,n=e*s*3+s;for(let a=0;a!==s;a++)t[a]=i[n+a];return t}interpolate_(e,t,i,s){const n=this.resultBuffer,a=this.sampleValues,r=this.valueSize,A=r*2,c=r*3,l=s-t,h=(i-t)/l,d=h*h,p=d*h,f=e*c,b=f-c,m=-2*p+3*d,I=p-d,E=1-m,C=I-d+h;for(let Q=0;Q!==r;Q++){const w=a[b+Q+r],x=a[b+Q+A]*l,D=a[f+Q+r],S=a[f+Q]*l;n[Q]=E*w+C*x+m*D+I*S}return n}}const Vr=new we;class Wr extends Wn{interpolate_(e,t,i,s){const n=super.interpolate_(e,t,i,s);return Vr.fromArray(n).normalize().toArray(n),n}}const At={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},as={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Xn={9728:Ls,9729:it,9984:li,9985:yn,9986:Qn,9987:hs},Zn={33071:Ns,33648:vn,10497:zt},Di={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ri={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"},Gt={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Xr={CUBICSPLINE:void 0,LINEAR:pi,STEP:Tn},Ti={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function Zr(o){return o.DefaultMaterial===void 0&&(o.DefaultMaterial=new hi({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:kn})),o.DefaultMaterial}function Jt(o,e,t){for(const i in t.extensions)o[i]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[i]=t.extensions[i])}function Tt(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 $r(o,e,t){let i=!1,s=!1,n=!1;for(let c=0,l=e.length;c<l;c++){const h=e[c];if(h.POSITION!==void 0&&(i=!0),h.NORMAL!==void 0&&(s=!0),h.COLOR_0!==void 0&&(n=!0),i&&s&&n)break}if(!i&&!s&&!n)return Promise.resolve(o);const a=[],r=[],A=[];for(let c=0,l=e.length;c<l;c++){const h=e[c];if(i){const d=h.POSITION!==void 0?t.getDependency("accessor",h.POSITION):o.attributes.position;a.push(d)}if(s){const d=h.NORMAL!==void 0?t.getDependency("accessor",h.NORMAL):o.attributes.normal;r.push(d)}if(n){const d=h.COLOR_0!==void 0?t.getDependency("accessor",h.COLOR_0):o.attributes.color;A.push(d)}}return Promise.all([Promise.all(a),Promise.all(r),Promise.all(A)]).then(function(c){const l=c[0],h=c[1],d=c[2];return i&&(o.morphAttributes.position=l),s&&(o.morphAttributes.normal=h),n&&(o.morphAttributes.color=d),o.morphTargetsRelative=!0,o})}function eA(o,e){if(o.updateMorphTargets(),e.weights!==void 0)for(let t=0,i=e.weights.length;t<i;t++)o.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(o.morphTargetInfluences.length===t.length){o.morphTargetDictionary={};for(let i=0,s=t.length;i<s;i++)o.morphTargetDictionary[t[i]]=i}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function tA(o){let e;const t=o.extensions&&o.extensions[ne.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+ki(t.attributes):e=o.indices+":"+ki(o.attributes)+":"+o.mode,o.targets!==void 0)for(let i=0,s=o.targets.length;i<s;i++)e+=":"+ki(o.targets[i]);return e}function ki(o){let e="";const t=Object.keys(o).sort();for(let i=0,s=t.length;i<s;i++)e+=t[i]+":"+o[t[i]]+";";return e}function Mi(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 sA(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 iA=new le;class nA{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new vr,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let i=!1,s=-1,n=!1,a=-1;if(typeof navigator<"u"){const r=navigator.userAgent;i=/^((?!chrome|android).)*safari/i.test(r)===!0;const A=r.match(/Version\/(\d+)/);s=i&&A?parseInt(A[1],10):-1,n=r.indexOf("Firefox")>-1,a=n?r.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||i&&s<17||n&&a<98?this.textureLoader=new ci(this.options.manager):this.textureLoader=new Ko(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new ht(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const i=this,s=this.json,n=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(a){return a._markDefs&&a._markDefs()}),Promise.all(this._invokeAll(function(a){return a.beforeRoot&&a.beforeRoot()})).then(function(){return Promise.all([i.getDependencies("scene"),i.getDependencies("animation"),i.getDependencies("camera")])}).then(function(a){const r={scene:a[0][s.scene||0],scenes:a[0],animations:a[1],cameras:a[2],asset:s.asset,parser:i,userData:{}};return Jt(n,r,s),Tt(r,s),Promise.all(i._invokeAll(function(A){return A.afterRoot&&A.afterRoot(r)})).then(function(){for(const A of r.scenes)A.updateMatrixWorld();e(r)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],i=this.json.meshes||[];for(let s=0,n=t.length;s<n;s++){const a=t[s].joints;for(let r=0,A=a.length;r<A;r++)e[a[r]].isBone=!0}for(let s=0,n=e.length;s<n;s++){const a=e[s];a.mesh!==void 0&&(this._addNodeRef(this.meshCache,a.mesh),a.skin!==void 0&&(i[a.mesh].isSkinnedMesh=!0)),a.camera!==void 0&&this._addNodeRef(this.cameraCache,a.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,i){if(e.refs[t]<=1)return i;const s=i.clone(),n=(a,r)=>{const A=this.associations.get(a);A!=null&&this.associations.set(r,A);for(const[c,l]of a.children.entries())n(l,r.children[c])};return n(i,s),s.name+="_instance_"+e.uses[t]++,s}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let i=0;i<t.length;i++){const s=e(t[i]);if(s)return s}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const i=[];for(let s=0;s<t.length;s++){const n=e(t[s]);n&&i.push(n)}return i}getDependency(e,t){const i=e+":"+t;let s=this.cache.get(i);if(!s){switch(e){case"scene":s=this.loadScene(t);break;case"node":s=this._invokeOne(function(n){return n.loadNode&&n.loadNode(t)});break;case"mesh":s=this._invokeOne(function(n){return n.loadMesh&&n.loadMesh(t)});break;case"accessor":s=this.loadAccessor(t);break;case"bufferView":s=this._invokeOne(function(n){return n.loadBufferView&&n.loadBufferView(t)});break;case"buffer":s=this.loadBuffer(t);break;case"material":s=this._invokeOne(function(n){return n.loadMaterial&&n.loadMaterial(t)});break;case"texture":s=this._invokeOne(function(n){return n.loadTexture&&n.loadTexture(t)});break;case"skin":s=this.loadSkin(t);break;case"animation":s=this._invokeOne(function(n){return n.loadAnimation&&n.loadAnimation(t)});break;case"camera":s=this.loadCamera(t);break;default:if(s=this._invokeOne(function(n){return n!=this&&n.getDependency&&n.getDependency(e,t)}),!s)throw new Error("Unknown type: "+e);break}this.cache.add(i,s)}return s}getDependencies(e){let t=this.cache.get(e);if(!t){const i=this,s=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(s.map(function(n,a){return i.getDependency(e,a)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],i=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[ne.KHR_BINARY_GLTF].body);const s=this.options;return new Promise(function(n,a){i.load(qt.resolveURL(t.uri,s.path),n,void 0,function(){a(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(i){const s=t.byteLength||0,n=t.byteOffset||0;return i.slice(n,n+s)})}loadAccessor(e){const t=this,i=this.json,s=this.json.accessors[e];if(s.bufferView===void 0&&s.sparse===void 0){const a=Di[s.type],r=as[s.componentType],A=s.normalized===!0,c=new r(s.count*a);return Promise.resolve(new st(c,a,A))}const n=[];return s.bufferView!==void 0?n.push(this.getDependency("bufferView",s.bufferView)):n.push(null),s.sparse!==void 0&&(n.push(this.getDependency("bufferView",s.sparse.indices.bufferView)),n.push(this.getDependency("bufferView",s.sparse.values.bufferView))),Promise.all(n).then(function(a){const r=a[0],A=Di[s.type],c=as[s.componentType],l=c.BYTES_PER_ELEMENT,h=l*A,d=s.byteOffset||0,p=s.bufferView!==void 0?i.bufferViews[s.bufferView].byteStride:void 0,f=s.normalized===!0;let b,m;if(p&&p!==h){const I=Math.floor(d/p),E="InterleavedBuffer:"+s.bufferView+":"+s.componentType+":"+I+":"+s.count;let C=t.cache.get(E);C||(b=new c(r,I*p,s.count*p/l),C=new Jo(b,p/l),t.cache.add(E,C)),m=new Kt(C,A,d%p/l,f)}else r===null?b=new c(s.count*A):b=new c(r,d,s.count*A),m=new st(b,A,f);if(s.sparse!==void 0){const I=Di.SCALAR,E=as[s.sparse.indices.componentType],C=s.sparse.indices.byteOffset||0,Q=s.sparse.values.byteOffset||0,w=new E(a[1],C,s.sparse.count*I),x=new c(a[2],Q,s.sparse.count*A);r!==null&&(m=new st(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let D=0,S=w.length;D<S;D++){const F=w[D];if(m.setX(F,x[D*A]),A>=2&&m.setY(F,x[D*A+1]),A>=3&&m.setZ(F,x[D*A+2]),A>=4&&m.setW(F,x[D*A+3]),A>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=f}return m})}loadTexture(e){const t=this.json,i=this.options,s=t.textures[e].source,n=t.images[s];let a=this.textureLoader;if(n.uri){const r=i.manager.getHandler(n.uri);r!==null&&(a=r)}return this.loadTextureImage(e,s,a)}loadTextureImage(e,t,i){const s=this,n=this.json,a=n.textures[e],r=n.images[t],A=(r.uri||r.bufferView)+":"+a.sampler;if(this.textureCache[A])return this.textureCache[A];const c=this.loadImageSource(t,i).then(function(l){l.flipY=!1,l.name=a.name||r.name||"",l.name===""&&typeof r.uri=="string"&&r.uri.startsWith("data:image/")===!1&&(l.name=r.uri);const h=(n.samplers||{})[a.sampler]||{};return l.magFilter=Xn[h.magFilter]||it,l.minFilter=Xn[h.minFilter]||hs,l.wrapS=Zn[h.wrapS]||zt,l.wrapT=Zn[h.wrapT]||zt,l.anisotropy=4,s.associations.set(l,{textures:e}),l}).catch(function(){return null});return this.textureCache[A]=c,c}loadImageSource(e,t){const i=this,s=this.json,n=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(h=>h.clone());const a=s.images[e],r=self.URL||self.webkitURL;let A=a.uri||"",c=!1;if(a.bufferView!==void 0)A=i.getDependency("bufferView",a.bufferView).then(function(h){c=!0;const d=new Blob([h],{type:a.mimeType});return A=r.createObjectURL(d),A});else if(a.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const l=Promise.resolve(A).then(function(h){return new Promise(function(d,p){let f=d;t.isImageBitmapLoader===!0&&(f=function(b){const m=new ui(b);m.needsUpdate=!0,d(m)}),t.load(qt.resolveURL(h,n.path),f,void 0,p)})}).then(function(h){return c===!0&&r.revokeObjectURL(A),Tt(h,a),h.userData.mimeType=a.mimeType||sA(a.uri),h}).catch(function(h){throw console.error("THREE.GLTFLoader: Couldn't load texture",A),h});return this.sourceCache[e]=l,l}assignTexture(e,t,i,s){const n=this;return this.getDependency("texture",i.index).then(function(a){if(!a)return null;if(i.texCoord!==void 0&&i.texCoord>0&&(a=a.clone(),a.channel=i.texCoord),n.extensions[ne.KHR_TEXTURE_TRANSFORM]){const r=i.extensions!==void 0?i.extensions[ne.KHR_TEXTURE_TRANSFORM]:void 0;if(r){const A=n.associations.get(a);a=n.extensions[ne.KHR_TEXTURE_TRANSFORM].extendTexture(a,r),n.associations.set(a,A)}}return s!==void 0&&(a.colorSpace=s),e[t]=a,a})}assignFinalMaterial(e){const t=e.geometry;let i=e.material;const s=t.attributes.tangent===void 0,n=t.attributes.color!==void 0,a=t.attributes.normal===void 0;if(e.isPoints){const r="PointsMaterial:"+i.uuid;let A=this.cache.get(r);A||(A=new gs,ds.prototype.copy.call(A,i),A.color.copy(i.color),A.map=i.map,A.sizeAttenuation=!1,this.cache.add(r,A)),i=A}else if(e.isLine){const r="LineBasicMaterial:"+i.uuid;let A=this.cache.get(r);A||(A=new St,ds.prototype.copy.call(A,i),A.color.copy(i.color),A.map=i.map,this.cache.add(r,A)),i=A}if(s||n||a){let r="ClonedMaterial:"+i.uuid+":";s&&(r+="derivative-tangents:"),n&&(r+="vertex-colors:"),a&&(r+="flat-shading:");let A=this.cache.get(r);A||(A=i.clone(),n&&(A.vertexColors=!0),a&&(A.flatShading=!0),s&&(A.normalScale&&(A.normalScale.y*=-1),A.clearcoatNormalScale&&(A.clearcoatNormalScale.y*=-1)),this.cache.add(r,A),this.associations.set(A,this.associations.get(i))),i=A}e.material=i}getMaterialType(){return hi}loadMaterial(e){const t=this,i=this.json,s=this.extensions,n=i.materials[e];let a;const r={},A=n.extensions||{},c=[];if(A[ne.KHR_MATERIALS_UNLIT]){const h=s[ne.KHR_MATERIALS_UNLIT];a=h.getMaterialType(),c.push(h.extendParams(r,n,t))}else{const h=n.pbrMetallicRoughness||{};if(r.color=new Be(1,1,1),r.opacity=1,Array.isArray(h.baseColorFactor)){const d=h.baseColorFactor;r.color.setRGB(d[0],d[1],d[2],Ve),r.opacity=d[3]}h.baseColorTexture!==void 0&&c.push(t.assignTexture(r,"map",h.baseColorTexture,ce)),r.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,r.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(c.push(t.assignTexture(r,"metalnessMap",h.metallicRoughnessTexture)),c.push(t.assignTexture(r,"roughnessMap",h.metallicRoughnessTexture))),a=this._invokeOne(function(d){return d.getMaterialType&&d.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(d){return d.extendMaterialParams&&d.extendMaterialParams(e,r)})))}n.doubleSided===!0&&(r.side=gi);const l=n.alphaMode||Ti.OPAQUE;if(l===Ti.BLEND?(r.transparent=!0,r.depthWrite=!1):(r.transparent=!1,l===Ti.MASK&&(r.alphaTest=n.alphaCutoff!==void 0?n.alphaCutoff:.5)),n.normalTexture!==void 0&&a!==mt&&(c.push(t.assignTexture(r,"normalMap",n.normalTexture)),r.normalScale=new _e(1,1),n.normalTexture.scale!==void 0)){const h=n.normalTexture.scale;r.normalScale.set(h,h)}if(n.occlusionTexture!==void 0&&a!==mt&&(c.push(t.assignTexture(r,"aoMap",n.occlusionTexture)),n.occlusionTexture.strength!==void 0&&(r.aoMapIntensity=n.occlusionTexture.strength)),n.emissiveFactor!==void 0&&a!==mt){const h=n.emissiveFactor;r.emissive=new Be().setRGB(h[0],h[1],h[2],Ve)}return n.emissiveTexture!==void 0&&a!==mt&&c.push(t.assignTexture(r,"emissiveMap",n.emissiveTexture,ce)),Promise.all(c).then(function(){const h=new a(r);return n.name&&(h.name=n.name),Tt(h,n),t.associations.set(h,{materials:e}),n.extensions&&Jt(s,h,n),h})}createUniqueName(e){const t=Dt.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,i=this.extensions,s=this.primitiveCache;function n(r){return i[ne.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(r,t).then(function(A){return $n(A,r,t)})}const a=[];for(let r=0,A=e.length;r<A;r++){const c=e[r],l=tA(c),h=s[l];if(h)a.push(h.promise);else{let d;c.extensions&&c.extensions[ne.KHR_DRACO_MESH_COMPRESSION]?d=n(c):d=$n(new rt,c,t),s[l]={primitive:c,promise:d},a.push(d)}}return Promise.all(a)}loadMesh(e){const t=this,i=this.json,s=this.extensions,n=i.meshes[e],a=n.primitives,r=[];for(let A=0,c=a.length;A<c;A++){const l=a[A].material===void 0?Zr(this.cache):this.getDependency("material",a[A].material);r.push(l)}return r.push(t.loadGeometries(a)),Promise.all(r).then(function(A){const c=A.slice(0,A.length-1),l=A[A.length-1],h=[];for(let p=0,f=l.length;p<f;p++){const b=l[p],m=a[p];let I;const E=c[p];if(m.mode===At.TRIANGLES||m.mode===At.TRIANGLE_STRIP||m.mode===At.TRIANGLE_FAN||m.mode===void 0)I=n.isSkinnedMesh===!0?new xn(b,E):new O(b,E),I.isSkinnedMesh===!0&&I.normalizeSkinWeights(),m.mode===At.TRIANGLE_STRIP?I.geometry=Kn(I.geometry,Cn):m.mode===At.TRIANGLE_FAN&&(I.geometry=Kn(I.geometry,ri));else if(m.mode===At.LINES)I=new Us(b,E);else if(m.mode===At.LINE_STRIP)I=new gt(b,E);else if(m.mode===At.LINE_LOOP)I=new Vo(b,E);else if(m.mode===At.POINTS)I=new Gs(b,E);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+m.mode);Object.keys(I.geometry.morphAttributes).length>0&&eA(I,n),I.name=t.createUniqueName(n.name||"mesh_"+e),Tt(I,n),m.extensions&&Jt(s,I,m),t.assignFinalMaterial(I),h.push(I)}for(let p=0,f=h.length;p<f;p++)t.associations.set(h[p],{meshes:e,primitives:p});if(h.length===1)return n.extensions&&Jt(s,h[0],n),h[0];const d=new Yt;n.extensions&&Jt(s,d,n),t.associations.set(d,{meshes:e});for(let p=0,f=h.length;p<f;p++)d.add(h[p]);return d})}loadCamera(e){let t;const i=this.json.cameras[e],s=i[i.type];if(!s){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return i.type==="perspective"?t=new Ps(Ee.radToDeg(s.yfov),s.aspectRatio||1,s.znear||1,s.zfar||2e6):i.type==="orthographic"&&(t=new Sn(-s.xmag,s.xmag,s.ymag,-s.ymag,s.znear,s.zfar)),i.name&&(t.name=this.createUniqueName(i.name)),Tt(t,i),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],i=[];for(let s=0,n=t.joints.length;s<n;s++)i.push(this._loadNodeShallow(t.joints[s]));return t.inverseBindMatrices!==void 0?i.push(this.getDependency("accessor",t.inverseBindMatrices)):i.push(null),Promise.all(i).then(function(s){const n=s.pop(),a=s,r=[],A=[];for(let c=0,l=a.length;c<l;c++){const h=a[c];if(h){r.push(h);const d=new le;n!==null&&d.fromArray(n.array,c*16),A.push(d)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[c])}return new Dn(r,A)})}loadAnimation(e){const t=this.json,i=this,s=t.animations[e],n=s.name?s.name:"animation_"+e,a=[],r=[],A=[],c=[],l=[];let h=0,d=s.channels.length;for(h=0,d=s.channels.length;h<d;h++){const p=s.channels[h],f=s.samplers[p.sampler],b=p.target,m=b.node,I=s.parameters!==void 0?s.parameters[f.input]:f.input,E=s.parameters!==void 0?s.parameters[f.output]:f.output;b.node!==void 0&&(a.push(this.getDependency("node",m)),r.push(this.getDependency("accessor",I)),A.push(this.getDependency("accessor",E)),c.push(f),l.push(b))}return Promise.all([Promise.all(a),Promise.all(r),Promise.all(A),Promise.all(c),Promise.all(l)]).then(function(p){const f=p[0],b=p[1],m=p[2],I=p[3],E=p[4],C=[];for(h=0,d=f.length;h<d;h++){const Q=f[h],w=b[h],x=m[h],D=I[h],S=E[h];if(Q===void 0)continue;Q.updateMatrix&&Q.updateMatrix();const F=i._createAnimationTracks(Q,w,x,D,S);if(F)for(let Y=0;Y<F.length;Y++)C.push(F[Y])}return new Rn(n,void 0,C)})}createNodeMesh(e){const t=this.json,i=this,s=t.nodes[e];return s.mesh===void 0?null:i.getDependency("mesh",s.mesh).then(function(n){const a=i._getNodeRef(i.meshCache,s.mesh,n);return s.weights!==void 0&&a.traverse(function(r){if(r.isMesh)for(let A=0,c=s.weights.length;A<c;A++)r.morphTargetInfluences[A]=s.weights[A]}),a})}loadNode(e){const t=this.json,i=this,s=t.nodes[e],n=i._loadNodeShallow(e),a=[],r=s.children||[];for(let c=0,l=r.length;c<l;c++)a.push(i.getDependency("node",r[c]));const A=s.skin===void 0?Promise.resolve(null):i.getDependency("skin",s.skin);return Promise.all([n,Promise.all(a),A]).then(function(c){const l=c[0],h=c[1],d=c[2];d!==null&&l.traverse(function(p){p.isSkinnedMesh&&p.bind(d,iA)});for(let p=0,f=h.length;p<f;p++)l.add(h[p]);return l})}_loadNodeShallow(e){const t=this.json,i=this.extensions,s=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const n=t.nodes[e],a=n.name?s.createUniqueName(n.name):"",r=[],A=s._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(e)});return A&&r.push(A),n.camera!==void 0&&r.push(s.getDependency("camera",n.camera).then(function(c){return s._getNodeRef(s.cameraCache,n.camera,c)})),s._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(e)}).forEach(function(c){r.push(c)}),this.nodeCache[e]=Promise.all(r).then(function(c){let l;if(n.isBone===!0?l=new di:c.length>1?l=new Yt:c.length===1?l=c[0]:l=new It,l!==c[0])for(let h=0,d=c.length;h<d;h++)l.add(c[h]);if(n.name&&(l.userData.name=n.name,l.name=a),Tt(l,n),n.extensions&&Jt(i,l,n),n.matrix!==void 0){const h=new le;h.fromArray(n.matrix),l.applyMatrix4(h)}else n.translation!==void 0&&l.position.fromArray(n.translation),n.rotation!==void 0&&l.quaternion.fromArray(n.rotation),n.scale!==void 0&&l.scale.fromArray(n.scale);return s.associations.has(l)||s.associations.set(l,{}),s.associations.get(l).nodes=e,l}),this.nodeCache[e]}loadScene(e){const t=this.extensions,i=this.json.scenes[e],s=this,n=new Yt;i.name&&(n.name=s.createUniqueName(i.name)),Tt(n,i),i.extensions&&Jt(t,n,i);const a=i.nodes||[],r=[];for(let A=0,c=a.length;A<c;A++)r.push(s.getDependency("node",a[A]));return Promise.all(r).then(function(A){for(let l=0,h=A.length;l<h;l++)n.add(A[l]);const c=l=>{const h=new Map;for(const[d,p]of s.associations)(d instanceof ds||d instanceof ui)&&h.set(d,p);return l.traverse(d=>{const p=s.associations.get(d);p!=null&&h.set(d,p)}),h};return s.associations=c(n),n})}_createAnimationTracks(e,t,i,s,n){const a=[],r=e.name?e.name:e.uuid,A=[];Gt[n.path]===Gt.weights?e.traverse(function(d){d.morphTargetInfluences&&A.push(d.name?d.name:d.uuid)}):A.push(r);let c;switch(Gt[n.path]){case Gt.weights:c=mi;break;case Gt.rotation:c=bi;break;case Gt.position:case Gt.scale:c=fi;break;default:i.itemSize===1?c=mi:c=fi;break}const l=s.interpolation!==void 0?Xr[s.interpolation]:pi,h=this._getArrayFromAccessor(i);for(let d=0,p=A.length;d<p;d++){const f=new c(A[d]+"."+Gt[n.path],t.array,h,l);s.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(f),a.push(f)}return a}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const i=Mi(t.constructor),s=new Float32Array(t.length);for(let n=0,a=t.length;n<a;n++)s[n]=t[n]*i;t=s}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(t){const i=this instanceof bi?Wr:Wn;return new i(this.times,this.values,this.getValueSize()/3,t)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function aA(o,e,t){const i=e.attributes,s=new Os;if(i.POSITION!==void 0){const r=t.json.accessors[i.POSITION],A=r.min,c=r.max;if(A!==void 0&&c!==void 0){if(s.set(new N(A[0],A[1],A[2]),new N(c[0],c[1],c[2])),r.normalized){const l=Mi(as[r.componentType]);s.min.multiplyScalar(l),s.max.multiplyScalar(l)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const n=e.targets;if(n!==void 0){const r=new N,A=new N;for(let c=0,l=n.length;c<l;c++){const h=n[c];if(h.POSITION!==void 0){const d=t.json.accessors[h.POSITION],p=d.min,f=d.max;if(p!==void 0&&f!==void 0){if(A.setX(Math.max(Math.abs(p[0]),Math.abs(f[0]))),A.setY(Math.max(Math.abs(p[1]),Math.abs(f[1]))),A.setZ(Math.max(Math.abs(p[2]),Math.abs(f[2]))),d.normalized){const b=Mi(as[d.componentType]);A.multiplyScalar(b)}r.max(A)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}s.expandByVector(r)}o.boundingBox=s;const a=new Ii;s.getCenter(a.center),a.radius=s.min.distanceTo(s.max)/2,o.boundingSphere=a}function $n(o,e,t){const i=e.attributes,s=[];function n(a,r){return t.getDependency("accessor",a).then(function(A){o.setAttribute(r,A)})}for(const a in i){const r=Ri[a]||a.toLowe