WolfDavid's picture
feat(01-10): vendor the 3D runtime and take the CDN out of the render path
c23e6ce
Raw History Blame
45.8 kB
/* esm.sh - three@0.185.1/examples/jsm/loaders/GLTFLoader */
import{AnimationClip as Ze,Bone as Qe,Box3 as Je,BufferAttribute as q,BufferGeometry as $e,ClampToEdgeWrapping as et,Color as v,ColorManagement as Ne,DirectionalLight as tt,DoubleSide as nt,FileLoader as Fe,FrontSide as st,Group as W,ImageBitmapLoader as rt,InstancedMesh as it,InterleavedBuffer as ot,InterleavedBufferAttribute as at,Interpolant as ct,InterpolateDiscrete as ut,InterpolateLinear as Ue,Line as lt,LineBasicMaterial as ft,LineLoop as dt,LineSegments as ht,LinearFilter as $,LinearMipmapLinearFilter as ze,LinearMipmapNearestFilter as pt,LinearSRGBColorSpace as I,Loader as mt,LoaderUtils as F,Material as Y,MathUtils as gt,Matrix4 as z,Mesh as Tt,MeshBasicMaterial as D,MeshPhysicalMaterial as S,MeshStandardMaterial as Ge,MirroredRepeatWrapping as At,NearestFilter as Ke,NearestMipmapLinearFilter as Rt,NearestMipmapNearestFilter as xt,NumberKeyframeTrack as Le,Object3D as je,OrthographicCamera as yt,PerspectiveCamera as bt,PointLight as wt,Points as Et,PointsMaterial as _t,PropertyBinding as Mt,Quaternion as Ve,QuaternionKeyframeTrack as Oe,RepeatWrapping as ee,Skeleton as St,SkinnedMesh as It,Sphere as Nt,SpotLight as Lt,Texture as Ce,TextureLoader as Ot,TriangleFanDrawMode as Ct,TriangleStripDrawMode as vt,Vector2 as Xe,Vector3 as C,VectorKeyframeTrack as ve,SRGBColorSpace as U,InstancedBufferAttribute as kt}from"./three.mjs";import{BufferAttribute as Xt,BufferGeometry as qt,Float32BufferAttribute as Wt,InstancedBufferAttribute as Yt,InterleavedBuffer as Zt,InterleavedBufferAttribute as Qt,TriangleFanDrawMode as Me,TriangleStripDrawMode as We,TrianglesDrawMode as Ye,Vector3 as Jt}from"./three.mjs";function X(f,t){if(t===Ye)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),f;if(t===Me||t===We){let e=f.getIndex();if(e===null){let i=[],a=f.getAttribute("position");if(a!==void 0){for(let o=0;o<a.count;o++)i.push(o);f.setIndex(i),e=f.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),f}let s=e.count-2,n=[];if(t===Me)for(let i=1;i<=s;i++)n.push(e.getX(0)),n.push(e.getX(i)),n.push(e.getX(i+1));else for(let i=0;i<s;i++)i%2===0?(n.push(e.getX(i)),n.push(e.getX(i+1)),n.push(e.getX(i+2))):(n.push(e.getX(i+2)),n.push(e.getX(i+1)),n.push(e.getX(i)));n.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");let r=f.clone();return r.setIndex(n),r.clearGroups(),r}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),f}import{AnimationClip as tn,AnimationMixer as nn,Matrix4 as sn,Quaternion as rn,QuaternionKeyframeTrack as on,SkeletonHelper as an,Vector3 as cn,VectorKeyframeTrack as un}from"./three.mjs";function Se(f){let t=new Map,e=new Map,s=f.clone();return Ie(f,s,function(n,r){t.set(r,n),e.set(n,r)}),s.traverse(function(n){if(!n.isSkinnedMesh)return;let r=n,i=t.get(n),a=i.skeleton.bones;r.skeleton=i.skeleton.clone(),r.bindMatrix.copy(i.bindMatrix),r.skeleton.bones=a.map(function(o){return e.get(o)}),r.bind(r.skeleton,r.bindMatrix)}),s}function Ie(f,t,e){e(f,t);for(let s=0;s<f.children.length;s++)Ie(f.children[s],t.children[s],e)}var ke=class extends mt{constructor(t){super(t),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new re(e)}),this.register(function(e){return new ie(e)}),this.register(function(e){return new pe(e)}),this.register(function(e){return new me(e)}),this.register(function(e){return new ge(e)}),this.register(function(e){return new ae(e)}),this.register(function(e){return new ce(e)}),this.register(function(e){return new ue(e)}),this.register(function(e){return new le(e)}),this.register(function(e){return new se(e)}),this.register(function(e){return new fe(e)}),this.register(function(e){return new oe(e)}),this.register(function(e){return new he(e)}),this.register(function(e){return new de(e)}),this.register(function(e){return new te(e)}),this.register(function(e){return new G(e,g.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new G(e,g.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new Te(e)})}load(t,e,s,n){let r=this,i;if(this.resourcePath!=="")i=this.resourcePath;else if(this.path!==""){let c=F.extractUrlBase(t);i=F.resolveURL(c,this.path)}else i=F.extractUrlBase(t);this.manager.itemStart(t);let a=function(c){n?n(c):console.error(c),r.manager.itemError(t),r.manager.itemEnd(t)},o=new Fe(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(t,function(c){try{r.parse(c,i,function(u){e(u),r.manager.itemEnd(t)},a)}catch(u){a(u)}},s,a)}setDRACOLoader(t){return this.dracoLoader=t,this}setKTX2Loader(t){return this.ktx2Loader=t,this}setMeshoptDecoder(t){return this.meshoptDecoder=t,this}register(t){return this.pluginCallbacks.indexOf(t)===-1&&this.pluginCallbacks.push(t),this}unregister(t){return this.pluginCallbacks.indexOf(t)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(t),1),this}parse(t,e,s,n){let r,i={},a={},o=new TextDecoder;if(typeof t=="string")r=JSON.parse(t);else if(t instanceof ArrayBuffer)if(o.decode(new Uint8Array(t,0,4))===qe){try{i[g.KHR_BINARY_GLTF]=new Ae(t)}catch(l){n&&n(l);return}r=JSON.parse(i[g.KHR_BINARY_GLTF].content)}else r=JSON.parse(o.decode(t));else r=t;if(r.asset===void 0||r.asset.version[0]<2){n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}let c=new _e(r,{path:e||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){let l=this.pluginCallbacks[u](c);l.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[l.name]=l,i[l.name]=!0}if(r.extensionsUsed)for(let u=0;u<r.extensionsUsed.length;++u){let l=r.extensionsUsed[u],d=r.extensionsRequired||[];switch(l){case g.KHR_MATERIALS_UNLIT:i[l]=new ne;break;case g.KHR_DRACO_MESH_COMPRESSION:i[l]=new Re(r,this.dracoLoader);break;case g.KHR_TEXTURE_TRANSFORM:i[l]=new xe;break;case g.KHR_MESH_QUANTIZATION:i[l]=new ye;break;default:d.indexOf(l)>=0&&a[l]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+l+'".')}}c.setExtensions(i),c.setPlugins(a),c.parse(s,n)}parseAsync(t,e){let s=this;return new Promise(function(n,r){s.parse(t,e,n,r)})}};function Pt(){let f={};return{get:function(t){return f[t]},add:function(t,e){f[t]=e},remove:function(t){delete f[t]},removeAll:function(){f={}}}}function b(f,t,e){let s=f.json.materials[t];return s.extensions&&s.extensions[e]?s.extensions[e]:null}var g={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",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"},te=class{constructor(t){this.parser=t,this.name=g.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let t=this.parser,e=this.parser.json.nodes||[];for(let s=0,n=e.length;s<n;s++){let r=e[s];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&t._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(t){let e=this.parser,s="light:"+t,n=e.cache.get(s);if(n)return n;let r=e.json,o=((r.extensions&&r.extensions[this.name]||{}).lights||[])[t],c,u=new v(16777215);o.color!==void 0&&u.setRGB(o.color[0],o.color[1],o.color[2],I);let l=o.range!==void 0?o.range:0;switch(o.type){case"directional":c=new tt(u),c.target.position.set(0,0,-1),c.add(c.target);break;case"point":c=new wt(u),c.distance=l;break;case"spot":c=new Lt(u),c.distance=l,o.spot=o.spot||{},o.spot.innerConeAngle=o.spot.innerConeAngle!==void 0?o.spot.innerConeAngle:0,o.spot.outerConeAngle=o.spot.outerConeAngle!==void 0?o.spot.outerConeAngle:Math.PI/4,c.angle=o.spot.outerConeAngle,c.penumbra=1-o.spot.innerConeAngle/o.spot.outerConeAngle,c.target.position.set(0,0,-1),c.add(c.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+o.type)}return c.position.set(0,0,0),M(c,o),o.intensity!==void 0&&(c.intensity=o.intensity),c.name=e.createUniqueName(o.name||"light_"+t),n=Promise.resolve(c),e.cache.add(s,n),n}getDependency(t,e){if(t==="light")return this._loadLight(e)}createNodeAttachment(t){let e=this,s=this.parser,r=s.json.nodes[t],a=(r.extensions&&r.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(o){return s._getNodeRef(e.cache,a,o)})}},ne=class{constructor(){this.name=g.KHR_MATERIALS_UNLIT}getMaterialType(){return D}extendParams(t,e,s){let n=[];t.color=new v(1,1,1),t.opacity=1;let r=e.pbrMetallicRoughness;if(r){if(Array.isArray(r.baseColorFactor)){let i=r.baseColorFactor;t.color.setRGB(i[0],i[1],i[2],I),t.opacity=i[3]}r.baseColorTexture!==void 0&&n.push(s.assignTexture(t,"map",r.baseColorTexture,U))}return Promise.all(n)}},se=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);return s===null||s.emissiveStrength!==void 0&&(e.emissiveIntensity=s.emissiveStrength),Promise.resolve()}},re=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];if(s.clearcoatFactor!==void 0&&(e.clearcoat=s.clearcoatFactor),s.clearcoatTexture!==void 0&&n.push(this.parser.assignTexture(e,"clearcoatMap",s.clearcoatTexture)),s.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=s.clearcoatRoughnessFactor),s.clearcoatRoughnessTexture!==void 0&&n.push(this.parser.assignTexture(e,"clearcoatRoughnessMap",s.clearcoatRoughnessTexture)),s.clearcoatNormalTexture!==void 0&&(n.push(this.parser.assignTexture(e,"clearcoatNormalMap",s.clearcoatNormalTexture)),s.clearcoatNormalTexture.scale!==void 0)){let r=s.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new Xe(r,r)}return Promise.all(n)}},ie=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_DISPERSION}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);return s===null||(e.dispersion=s.dispersion!==void 0?s.dispersion:0),Promise.resolve()}},oe=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_IRIDESCENCE}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];return s.iridescenceFactor!==void 0&&(e.iridescence=s.iridescenceFactor),s.iridescenceTexture!==void 0&&n.push(this.parser.assignTexture(e,"iridescenceMap",s.iridescenceTexture)),s.iridescenceIor!==void 0&&(e.iridescenceIOR=s.iridescenceIor),e.iridescenceThicknessRange===void 0&&(e.iridescenceThicknessRange=[100,400]),s.iridescenceThicknessMinimum!==void 0&&(e.iridescenceThicknessRange[0]=s.iridescenceThicknessMinimum),s.iridescenceThicknessMaximum!==void 0&&(e.iridescenceThicknessRange[1]=s.iridescenceThicknessMaximum),s.iridescenceThicknessTexture!==void 0&&n.push(this.parser.assignTexture(e,"iridescenceThicknessMap",s.iridescenceThicknessTexture)),Promise.all(n)}},ae=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_SHEEN}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];if(e.sheenColor=new v(0,0,0),e.sheenRoughness=0,e.sheen=1,s.sheenColorFactor!==void 0){let r=s.sheenColorFactor;e.sheenColor.setRGB(r[0],r[1],r[2],I)}return s.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=s.sheenRoughnessFactor),s.sheenColorTexture!==void 0&&n.push(this.parser.assignTexture(e,"sheenColorMap",s.sheenColorTexture,U)),s.sheenRoughnessTexture!==void 0&&n.push(this.parser.assignTexture(e,"sheenRoughnessMap",s.sheenRoughnessTexture)),Promise.all(n)}},ce=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];return s.transmissionFactor!==void 0&&(e.transmission=s.transmissionFactor),s.transmissionTexture!==void 0&&n.push(this.parser.assignTexture(e,"transmissionMap",s.transmissionTexture)),Promise.all(n)}},ue=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_VOLUME}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];e.thickness=s.thicknessFactor!==void 0?s.thicknessFactor:0,s.thicknessTexture!==void 0&&n.push(this.parser.assignTexture(e,"thicknessMap",s.thicknessTexture)),e.attenuationDistance=s.attenuationDistance||1/0;let r=s.attenuationColor||[1,1,1];return e.attenuationColor=new v().setRGB(r[0],r[1],r[2],I),Promise.all(n)}},le=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_IOR}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);return s===null||(e.ior=s.ior!==void 0?s.ior:1.5,e.ior===0&&(e.ior=1e3)),Promise.resolve()}},fe=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_SPECULAR}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];e.specularIntensity=s.specularFactor!==void 0?s.specularFactor:1,s.specularTexture!==void 0&&n.push(this.parser.assignTexture(e,"specularIntensityMap",s.specularTexture));let r=s.specularColorFactor||[1,1,1];return e.specularColor=new v().setRGB(r[0],r[1],r[2],I),s.specularColorTexture!==void 0&&n.push(this.parser.assignTexture(e,"specularColorMap",s.specularColorTexture,U)),Promise.all(n)}},de=class{constructor(t){this.parser=t,this.name=g.EXT_MATERIALS_BUMP}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];return e.bumpScale=s.bumpFactor!==void 0?s.bumpFactor:1,s.bumpTexture!==void 0&&n.push(this.parser.assignTexture(e,"bumpMap",s.bumpTexture)),Promise.all(n)}},he=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_ANISOTROPY}getMaterialType(t){return b(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=b(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];return s.anisotropyStrength!==void 0&&(e.anisotropy=s.anisotropyStrength),s.anisotropyRotation!==void 0&&(e.anisotropyRotation=s.anisotropyRotation),s.anisotropyTexture!==void 0&&n.push(this.parser.assignTexture(e,"anisotropyMap",s.anisotropyTexture)),Promise.all(n)}},pe=class{constructor(t){this.parser=t,this.name=g.KHR_TEXTURE_BASISU}loadTexture(t){let e=this.parser,s=e.json,n=s.textures[t];if(!n.extensions||!n.extensions[this.name])return null;let r=n.extensions[this.name],i=e.options.ktx2Loader;if(!i){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 e.loadTextureImage(t,r.source,i)}},me=class{constructor(t){this.parser=t,this.name=g.EXT_TEXTURE_WEBP}loadTexture(t){let e=this.name,s=this.parser,n=s.json,r=n.textures[t];if(!r.extensions||!r.extensions[e])return null;let i=r.extensions[e],a=n.images[i.source],o=s.textureLoader;if(a.uri){let c=s.options.manager.getHandler(a.uri);c!==null&&(o=c)}return s.loadTextureImage(t,i.source,o)}},ge=class{constructor(t){this.parser=t,this.name=g.EXT_TEXTURE_AVIF}loadTexture(t){let e=this.name,s=this.parser,n=s.json,r=n.textures[t];if(!r.extensions||!r.extensions[e])return null;let i=r.extensions[e],a=n.images[i.source],o=s.textureLoader;if(a.uri){let c=s.options.manager.getHandler(a.uri);c!==null&&(o=c)}return s.loadTextureImage(t,i.source,o)}},G=class{constructor(t,e){this.name=e,this.parser=t}loadBufferView(t){let e=this.parser.json,s=e.bufferViews[t];if(s.extensions&&s.extensions[this.name]){let n=s.extensions[this.name],r=this.parser.getDependency("buffer",n.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(e.extensionsRequired&&e.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return r.then(function(a){let o=n.byteOffset||0,c=n.byteLength||0,u=n.count,l=n.byteStride,d=new Uint8Array(a,o,c);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(u,l,d,n.mode,n.filter).then(function(h){return h.buffer}):i.ready.then(function(){let h=new ArrayBuffer(u*l);return i.decodeGltfBuffer(new Uint8Array(h),u,l,d,n.mode,n.filter),h})})}else return null}},Te=class{constructor(t){this.name=g.EXT_MESH_GPU_INSTANCING,this.parser=t}createNodeMesh(t){let e=this.parser.json,s=e.nodes[t];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;let n=e.meshes[s.mesh];for(let c of n.primitives)if(c.mode!==E.TRIANGLES&&c.mode!==E.TRIANGLE_STRIP&&c.mode!==E.TRIANGLE_FAN&&c.mode!==void 0)return null;let i=s.extensions[this.name].attributes,a=[],o={};for(let c in i)a.push(this.parser.getDependency("accessor",i[c]).then(u=>(o[c]=u,o[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(t)),Promise.all(a).then(c=>{let u=c.pop(),l=u.isGroup?u.children:[u],d=c[0].count,h=[];for(let p of l){let A=new z,m=new C,T=new Ve,y=new C(1,1,1),x=new it(p.geometry,p.material,d);for(let R=0;R<d;R++)o.TRANSLATION&&m.fromBufferAttribute(o.TRANSLATION,R),o.ROTATION&&T.fromBufferAttribute(o.ROTATION,R),o.SCALE&&y.fromBufferAttribute(o.SCALE,R),x.setMatrixAt(R,A.compose(m,T,y));for(let R in o)if(R==="_COLOR_0"){let w=o[R];x.instanceColor=new kt(w.array,w.itemSize,w.normalized)}else R!=="TRANSLATION"&&R!=="ROTATION"&&R!=="SCALE"&&p.geometry.setAttribute(R,o[R]);je.prototype.copy.call(x,p),this.parser.assignFinalMaterial(x),h.push(x)}return u.isGroup?(u.clear(),u.add(...h),u):h[0]}))}},qe="glTF",H=12,Pe={JSON:1313821514,BIN:5130562},Ae=class{constructor(t){this.name=g.KHR_BINARY_GLTF,this.content=null,this.body=null;let e=new DataView(t,0,H),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(t.slice(0,4))),version:e.getUint32(4,!0),length:e.getUint32(8,!0)},this.header.magic!==qe)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");let n=this.header.length-H,r=new DataView(t,H),i=0;for(;i<n;){let a=r.getUint32(i,!0);i+=4;let o=r.getUint32(i,!0);if(i+=4,o===Pe.JSON){let c=new Uint8Array(t,H+i,a);this.content=s.decode(c)}else if(o===Pe.BIN){let c=H+i;this.body=t.slice(c,c+a)}i+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}},Re=class{constructor(t,e){if(!e)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=g.KHR_DRACO_MESH_COMPRESSION,this.json=t,this.dracoLoader=e,this.dracoLoader.preload()}decodePrimitive(t,e){let s=this.json,n=this.dracoLoader,r=t.extensions[this.name].bufferView,i=t.extensions[this.name].attributes,a={},o={},c={};for(let u in i){let l=we[u]||u.toLowerCase();a[l]=i[u]}for(let u in t.attributes){let l=we[u]||u.toLowerCase();if(i[u]!==void 0){let d=s.accessors[t.attributes[u]],h=P[d.componentType];c[l]=h.name,o[l]=d.normalized===!0}}return e.getDependency("bufferView",r).then(function(u){return new Promise(function(l,d){n.decodeDracoFile(u,function(h){for(let p in h.attributes){let A=h.attributes[p],m=o[p];m!==void 0&&(A.normalized=m)}l(h)},a,c,I,d)})})}},xe=class{constructor(){this.name=g.KHR_TEXTURE_TRANSFORM}extendTexture(t,e){return(e.texCoord===void 0||e.texCoord===t.channel)&&e.offset===void 0&&e.rotation===void 0&&e.scale===void 0||(t=t.clone(),e.texCoord!==void 0&&(t.channel=e.texCoord),e.offset!==void 0&&t.offset.fromArray(e.offset),e.rotation!==void 0&&(t.rotation=e.rotation),e.scale!==void 0&&t.repeat.fromArray(e.scale),t.needsUpdate=!0),t}},ye=class{constructor(){this.name=g.KHR_MESH_QUANTIZATION}},K=class extends ct{constructor(t,e,s,n){super(t,e,s,n)}copySampleValue_(t){let e=this.resultBuffer,s=this.sampleValues,n=this.valueSize,r=t*n*3+n;for(let i=0;i!==n;i++)e[i]=s[r+i];return e}interpolate_(t,e,s,n){let r=this.resultBuffer,i=this.sampleValues,a=this.valueSize,o=a*2,c=a*3,u=n-e,l=(s-e)/u,d=l*l,h=d*l,p=t*c,A=p-c,m=-2*h+3*d,T=h-d,y=1-m,x=T-d+l;for(let R=0;R!==a;R++){let w=i[A+R+a],N=i[A+R+o]*u,_=i[p+R+a],B=i[p+R]*u;r[R]=y*w+x*N+m*_+T*B}return r}},Bt=new Ve,be=class extends K{interpolate_(t,e,s,n){let r=super.interpolate_(t,e,s,n);return Bt.fromArray(r).normalize().toArray(r),r}},E={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},P={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Be={9728:Ke,9729:$,9984:xt,9985:pt,9986:Rt,9987:ze},He={33071:et,33648:At,10497:ee},Z={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},we={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"},L={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Ht={CUBICSPLINE:void 0,LINEAR:Ue,STEP:ut},Q={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function Dt(f){return f.DefaultMaterial===void 0&&(f.DefaultMaterial=new Ge({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:st})),f.DefaultMaterial}function O(f,t,e){for(let s in e.extensions)f[s]===void 0&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[s]=e.extensions[s])}function M(f,t){t.extras!==void 0&&(typeof t.extras=="object"?Object.assign(f.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function Ft(f,t,e){let s=!1,n=!1,r=!1;for(let c=0,u=t.length;c<u;c++){let l=t[c];if(l.POSITION!==void 0&&(s=!0),l.NORMAL!==void 0&&(n=!0),l.COLOR_0!==void 0&&(r=!0),s&&n&&r)break}if(!s&&!n&&!r)return Promise.resolve(f);let i=[],a=[],o=[];for(let c=0,u=t.length;c<u;c++){let l=t[c];if(s){let d=l.POSITION!==void 0?e.getDependency("accessor",l.POSITION):f.attributes.position;i.push(d)}if(n){let d=l.NORMAL!==void 0?e.getDependency("accessor",l.NORMAL):f.attributes.normal;a.push(d)}if(r){let d=l.COLOR_0!==void 0?e.getDependency("accessor",l.COLOR_0):f.attributes.color;o.push(d)}}return Promise.all([Promise.all(i),Promise.all(a),Promise.all(o)]).then(function(c){let u=c[0],l=c[1],d=c[2];return s&&(f.morphAttributes.position=u),n&&(f.morphAttributes.normal=l),r&&(f.morphAttributes.color=d),f.morphTargetsRelative=!0,f})}function Ut(f,t){if(f.updateMorphTargets(),t.weights!==void 0)for(let e=0,s=t.weights.length;e<s;e++)f.morphTargetInfluences[e]=t.weights[e];if(t.extras&&Array.isArray(t.extras.targetNames)){let e=t.extras.targetNames;if(f.morphTargetInfluences.length===e.length){f.morphTargetDictionary={};for(let s=0,n=e.length;s<n;s++)f.morphTargetDictionary[e[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function zt(f){let t,e=f.extensions&&f.extensions[g.KHR_DRACO_MESH_COMPRESSION];if(e?t="draco:"+e.bufferView+":"+e.indices+":"+J(e.attributes):t=f.indices+":"+J(f.attributes)+":"+f.mode,f.targets!==void 0)for(let s=0,n=f.targets.length;s<n;s++)t+=":"+J(f.targets[s]);return t}function J(f){let t="",e=Object.keys(f).sort();for(let s=0,n=e.length;s<n;s++)t+=e[s]+":"+f[e[s]]+";";return t}function Ee(f){switch(f){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 Gt(f){return f.search(/\.jpe?g($|\?)/i)>0||f.search(/^data\:image\/jpeg/)===0?"image/jpeg":f.search(/\.webp($|\?)/i)>0||f.search(/^data\:image\/webp/)===0?"image/webp":f.search(/\.ktx2($|\?)/i)>0||f.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}var Kt=new z,_e=class{constructor(t={},e={}){this.json=t,this.extensions={},this.plugins={},this.options=e,this.cache=new Pt,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,r=!1,i=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){let a=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(a)===!0;let o=a.match(/Version\/(\d+)/);n=s&&o?parseInt(o[1],10):-1,r=a.indexOf("Firefox")>-1,i=r?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||r&&i<98?this.textureLoader=new Ot(this.options.manager):this.textureLoader=new rt(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new Fe(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(t){this.extensions=t}setPlugins(t){this.plugins=t}parse(t,e){let s=this,n=this.json,r=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(i){return i._markDefs&&i._markDefs()}),Promise.all(this._invokeAll(function(i){return i.beforeRoot&&i.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(i){let a={scene:i[0][n.scene||0],scenes:i[0],animations:i[1],cameras:i[2],asset:n.asset,parser:s,userData:{}};return O(r,a,n),M(a,n),Promise.all(s._invokeAll(function(o){return o.afterRoot&&o.afterRoot(a)})).then(function(){for(let o of a.scenes)o.updateMatrixWorld();t(a)})}).catch(e)}_markDefs(){let t=this.json.nodes||[],e=this.json.skins||[],s=this.json.meshes||[];for(let n=0,r=e.length;n<r;n++){let i=e[n].joints;for(let a=0,o=i.length;a<o;a++)t[i[a]].isBone=!0}for(let n=0,r=t.length;n<r;n++){let i=t[n];i.mesh!==void 0&&(this._addNodeRef(this.meshCache,i.mesh),i.skin!==void 0&&(s[i.mesh].isSkinnedMesh=!0)),i.camera!==void 0&&this._addNodeRef(this.cameraCache,i.camera)}}_addNodeRef(t,e){e!==void 0&&(t.refs[e]===void 0&&(t.refs[e]=t.uses[e]=0),t.refs[e]++)}_getNodeRef(t,e,s){if(t.refs[e]<=1)return s;let n=s.clone(),r=(i,a)=>{let o=this.associations.get(i);o!=null&&this.associations.set(a,o);for(let[c,u]of i.children.entries())r(u,a.children[c])};return r(s,n),n.name+="_instance_"+t.uses[e]++,n}_invokeOne(t){let e=Object.values(this.plugins);e.push(this);for(let s=0;s<e.length;s++){let n=t(e[s]);if(n)return n}return null}_invokeAll(t){let e=Object.values(this.plugins);e.unshift(this);let s=[];for(let n=0;n<e.length;n++){let r=t(e[n]);r&&s.push(r)}return s}getDependency(t,e){let s=t+":"+e,n=this.cache.get(s);if(!n){switch(t){case"scene":n=this.loadScene(e);break;case"node":n=this._invokeOne(function(r){return r.loadNode&&r.loadNode(e)});break;case"mesh":n=this._invokeOne(function(r){return r.loadMesh&&r.loadMesh(e)});break;case"accessor":n=this.loadAccessor(e);break;case"bufferView":n=this._invokeOne(function(r){return r.loadBufferView&&r.loadBufferView(e)});break;case"buffer":n=this.loadBuffer(e);break;case"material":n=this._invokeOne(function(r){return r.loadMaterial&&r.loadMaterial(e)});break;case"texture":n=this._invokeOne(function(r){return r.loadTexture&&r.loadTexture(e)});break;case"skin":n=this.loadSkin(e);break;case"animation":n=this._invokeOne(function(r){return r.loadAnimation&&r.loadAnimation(e)});break;case"camera":n=this.loadCamera(e);break;default:if(n=this._invokeOne(function(r){return r!=this&&r.getDependency&&r.getDependency(t,e)}),!n)throw new Error("Unknown type: "+t);break}this.cache.add(s,n)}return n}getDependencies(t){let e=this.cache.get(t);if(!e){let s=this,n=this.json[t+(t==="mesh"?"es":"s")]||[];e=Promise.all(n.map(function(r,i){return s.getDependency(t,i)})),this.cache.add(t,e)}return e}loadBuffer(t){let e=this.json.buffers[t],s=this.fileLoader;if(e.type&&e.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+e.type+" buffer type is not supported.");if(e.uri===void 0&&t===0)return Promise.resolve(this.extensions[g.KHR_BINARY_GLTF].body);let n=this.options;return new Promise(function(r,i){s.load(F.resolveURL(e.uri,n.path),r,void 0,function(){i(new Error('THREE.GLTFLoader: Failed to load buffer "'+e.uri+'".'))})})}loadBufferView(t){let e=this.json.bufferViews[t];return this.getDependency("buffer",e.buffer).then(function(s){let n=e.byteLength||0,r=e.byteOffset||0;return s.slice(r,r+n)})}loadAccessor(t){let e=this,s=this.json,n=this.json.accessors[t];if(n.bufferView===void 0&&n.sparse===void 0){let i=Z[n.type],a=P[n.componentType],o=n.normalized===!0,c=new a(n.count*i);return Promise.resolve(new q(c,i,o))}let r=[];return n.bufferView!==void 0?r.push(this.getDependency("bufferView",n.bufferView)):r.push(null),n.sparse!==void 0&&(r.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),r.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(r).then(function(i){let a=i[0],o=Z[n.type],c=P[n.componentType],u=c.BYTES_PER_ELEMENT,l=u*o,d=n.byteOffset||0,h=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,p=n.normalized===!0,A,m;if(h&&h!==l){let T=Math.floor(d/h),y="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+T+":"+n.count,x=e.cache.get(y);x||(A=new c(a,T*h,n.count*h/u),x=new ot(A,h/u),e.cache.add(y,x)),m=new at(x,o,d%h/u,p)}else a===null?A=new c(n.count*o):A=new c(a,d,n.count*o),m=new q(A,o,p);if(n.sparse!==void 0){let T=Z.SCALAR,y=P[n.sparse.indices.componentType],x=n.sparse.indices.byteOffset||0,R=n.sparse.values.byteOffset||0,w=new y(i[1],x,n.sparse.count*T),N=new c(i[2],R,n.sparse.count*o);a!==null&&(m=new q(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let _=0,B=w.length;_<B;_++){let k=w[_];if(m.setX(k,N[_*o]),o>=2&&m.setY(k,N[_*o+1]),o>=3&&m.setZ(k,N[_*o+2]),o>=4&&m.setW(k,N[_*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=p}return m})}loadTexture(t){let e=this.json,s=this.options,r=e.textures[t].source,i=e.images[r],a=this.textureLoader;if(i.uri){let o=s.manager.getHandler(i.uri);o!==null&&(a=o)}return this.loadTextureImage(t,r,a)}loadTextureImage(t,e,s){let n=this,r=this.json,i=r.textures[t],a=r.images[e],o=(a.uri||a.bufferView)+":"+i.sampler;if(this.textureCache[o])return this.textureCache[o];let c=this.loadImageSource(e,s).then(function(u){u.flipY=!1,u.name=i.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);let d=(r.samplers||{})[i.sampler]||{};return u.magFilter=Be[d.magFilter]||$,u.minFilter=Be[d.minFilter]||ze,u.wrapS=He[d.wrapS]||ee,u.wrapT=He[d.wrapT]||ee,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==Ke&&u.minFilter!==$,n.associations.set(u,{textures:t}),u}).catch(function(){return null});return this.textureCache[o]=c,c}loadImageSource(t,e){let s=this,n=this.json,r=this.options;if(this.sourceCache[t]!==void 0)return this.sourceCache[t].then(l=>l.clone());let i=n.images[t],a=self.URL||self.webkitURL,o=i.uri||"",c=!1;if(i.bufferView!==void 0)o=s.getDependency("bufferView",i.bufferView).then(function(l){c=!0;let d=new Blob([l],{type:i.mimeType});return o=a.createObjectURL(d),o});else if(i.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");let u=Promise.resolve(o).then(function(l){return new Promise(function(d,h){let p=d;e.isImageBitmapLoader===!0&&(p=function(A){let m=new Ce(A);m.needsUpdate=!0,d(m)}),e.load(F.resolveURL(l,r.path),p,void 0,h)})}).then(function(l){return c===!0&&a.revokeObjectURL(o),M(l,i),l.userData.mimeType=i.mimeType||Gt(i.uri),l}).catch(function(l){throw console.error("THREE.GLTFLoader: Couldn't load texture",o),l});return this.sourceCache[t]=u,u}assignTexture(t,e,s,n){let r=this;return this.getDependency("texture",s.index).then(function(i){if(!i)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(i=i.clone(),i.channel=s.texCoord),r.extensions[g.KHR_TEXTURE_TRANSFORM]){let a=s.extensions!==void 0?s.extensions[g.KHR_TEXTURE_TRANSFORM]:void 0;if(a){let o=r.associations.get(i);i=r.extensions[g.KHR_TEXTURE_TRANSFORM].extendTexture(i,a),r.associations.set(i,o)}}return n!==void 0&&(i.colorSpace=n),t[e]=i,i})}assignFinalMaterial(t){let e=t.geometry,s=t.material,n=e.attributes.tangent===void 0,r=e.attributes.color!==void 0,i=e.attributes.normal===void 0;if(t.isPoints){let a="PointsMaterial:"+s.uuid,o=this.cache.get(a);o||(o=new _t,Y.prototype.copy.call(o,s),o.color.copy(s.color),o.map=s.map,o.sizeAttenuation=!1,this.cache.add(a,o)),s=o}else if(t.isLine){let a="LineBasicMaterial:"+s.uuid,o=this.cache.get(a);o||(o=new ft,Y.prototype.copy.call(o,s),o.color.copy(s.color),o.map=s.map,this.cache.add(a,o)),s=o}if(n||r||i){let a="ClonedMaterial:"+s.uuid+":";n&&(a+="derivative-tangents:"),r&&(a+="vertex-colors:"),i&&(a+="flat-shading:");let o=this.cache.get(a);o||(o=s.clone(),r&&(o.vertexColors=!0),i&&(o.flatShading=!0),n&&(o.normalScale&&(o.normalScale.y*=-1),o.clearcoatNormalScale&&(o.clearcoatNormalScale.y*=-1)),this.cache.add(a,o),this.associations.set(o,this.associations.get(s))),s=o}t.material=s}getMaterialType(){return Ge}loadMaterial(t){let e=this,s=this.json,n=this.extensions,r=s.materials[t],i,a={},o=r.extensions||{},c=[];if(o[g.KHR_MATERIALS_UNLIT]){let l=n[g.KHR_MATERIALS_UNLIT];i=l.getMaterialType(),c.push(l.extendParams(a,r,e))}else{let l=r.pbrMetallicRoughness||{};if(a.color=new v(1,1,1),a.opacity=1,Array.isArray(l.baseColorFactor)){let d=l.baseColorFactor;a.color.setRGB(d[0],d[1],d[2],I),a.opacity=d[3]}l.baseColorTexture!==void 0&&c.push(e.assignTexture(a,"map",l.baseColorTexture,U)),a.metalness=l.metallicFactor!==void 0?l.metallicFactor:1,a.roughness=l.roughnessFactor!==void 0?l.roughnessFactor:1,l.metallicRoughnessTexture!==void 0&&(c.push(e.assignTexture(a,"metalnessMap",l.metallicRoughnessTexture)),c.push(e.assignTexture(a,"roughnessMap",l.metallicRoughnessTexture))),i=this._invokeOne(function(d){return d.getMaterialType&&d.getMaterialType(t)}),c.push(Promise.all(this._invokeAll(function(d){return d.extendMaterialParams&&d.extendMaterialParams(t,a)})))}r.doubleSided===!0&&(a.side=nt);let u=r.alphaMode||Q.OPAQUE;if(u===Q.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===Q.MASK&&(a.alphaTest=r.alphaCutoff!==void 0?r.alphaCutoff:.5)),r.normalTexture!==void 0&&i!==D&&(c.push(e.assignTexture(a,"normalMap",r.normalTexture)),a.normalScale=new Xe(1,1),r.normalTexture.scale!==void 0)){let l=r.normalTexture.scale;a.normalScale.set(l,l)}if(r.occlusionTexture!==void 0&&i!==D&&(c.push(e.assignTexture(a,"aoMap",r.occlusionTexture)),r.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=r.occlusionTexture.strength)),r.emissiveFactor!==void 0&&i!==D){let l=r.emissiveFactor;a.emissive=new v().setRGB(l[0],l[1],l[2],I)}return r.emissiveTexture!==void 0&&i!==D&&c.push(e.assignTexture(a,"emissiveMap",r.emissiveTexture,U)),Promise.all(c).then(function(){let l=new i(a);return r.name&&(l.name=r.name),M(l,r),e.associations.set(l,{materials:t}),r.extensions&&O(n,l,r),l})}createUniqueName(t){let e=Mt.sanitizeNodeName(t||"");return e in this.nodeNamesUsed?e+"_"+ ++this.nodeNamesUsed[e]:(this.nodeNamesUsed[e]=0,e)}loadGeometries(t){let e=this,s=this.extensions,n=this.primitiveCache;function r(a){return s[g.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,e).then(function(o){return De(o,a,e)})}let i=[];for(let a=0,o=t.length;a<o;a++){let c=t[a],u=zt(c),l=n[u];if(l)i.push(l.promise);else{let d;c.extensions&&c.extensions[g.KHR_DRACO_MESH_COMPRESSION]?d=r(c):d=De(new $e,c,e),n[u]={primitive:c,promise:d},i.push(d)}}return Promise.all(i)}loadMesh(t){let e=this,s=this.json,n=this.extensions,r=s.meshes[t],i=r.primitives,a=[];for(let o=0,c=i.length;o<c;o++){let u=i[o].material===void 0?Dt(this.cache):this.getDependency("material",i[o].material);a.push(u)}return a.push(e.loadGeometries(i)),Promise.all(a).then(function(o){let c=o.slice(0,o.length-1),u=o[o.length-1],l=[];for(let h=0,p=u.length;h<p;h++){let A=u[h],m=i[h],T,y=c[h];if(m.mode===E.TRIANGLES||m.mode===E.TRIANGLE_STRIP||m.mode===E.TRIANGLE_FAN||m.mode===void 0)T=r.isSkinnedMesh===!0?new It(A,y):new Tt(A,y),T.isSkinnedMesh===!0&&T.normalizeSkinWeights(),m.mode===E.TRIANGLE_STRIP?T.geometry=X(T.geometry,vt):m.mode===E.TRIANGLE_FAN&&(T.geometry=X(T.geometry,Ct));else if(m.mode===E.LINES)T=new ht(A,y);else if(m.mode===E.LINE_STRIP)T=new lt(A,y);else if(m.mode===E.LINE_LOOP)T=new dt(A,y);else if(m.mode===E.POINTS)T=new Et(A,y);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+m.mode);Object.keys(T.geometry.morphAttributes).length>0&&Ut(T,r),T.name=e.createUniqueName(r.name||"mesh_"+t),M(T,r),m.extensions&&O(n,T,m),e.assignFinalMaterial(T),l.push(T)}for(let h=0,p=l.length;h<p;h++)e.associations.set(l[h],{meshes:t,primitives:h});if(l.length===1)return r.extensions&&O(n,l[0],r),l[0];let d=new W;r.extensions&&O(n,d,r),e.associations.set(d,{meshes:t});for(let h=0,p=l.length;h<p;h++)d.add(l[h]);return d})}loadCamera(t){let e,s=this.json.cameras[t],n=s[s.type];if(!n){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?e=new bt(gt.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(e=new yt(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(e.name=this.createUniqueName(s.name)),M(e,s),Promise.resolve(e)}loadSkin(t){let e=this.json.skins[t],s=[];for(let n=0,r=e.joints.length;n<r;n++)s.push(this._loadNodeShallow(e.joints[n]));return e.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",e.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(n){let r=n.pop(),i=n,a=[],o=[];for(let c=0,u=i.length;c<u;c++){let l=i[c];if(l){a.push(l);let d=new z;r!==null&&d.fromArray(r.array,c*16),o.push(d)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',e.joints[c])}return new St(a,o)})}loadAnimation(t){let e=this.json,s=this,n=e.animations[t],r=n.name?n.name:"animation_"+t,i=[],a=[],o=[],c=[],u=[];for(let l=0,d=n.channels.length;l<d;l++){let h=n.channels[l],p=n.samplers[h.sampler],A=h.target,m=A.node,T=n.parameters!==void 0?n.parameters[p.input]:p.input,y=n.parameters!==void 0?n.parameters[p.output]:p.output;A.node!==void 0&&(i.push(this.getDependency("node",m)),a.push(this.getDependency("accessor",T)),o.push(this.getDependency("accessor",y)),c.push(p),u.push(A))}return Promise.all([Promise.all(i),Promise.all(a),Promise.all(o),Promise.all(c),Promise.all(u)]).then(function(l){let d=l[0],h=l[1],p=l[2],A=l[3],m=l[4],T=[];for(let x=0,R=d.length;x<R;x++){let w=d[x],N=h[x],_=p[x],B=A[x],k=m[x];if(w===void 0)continue;w.updateMatrix&&w.updateMatrix();let j=s._createAnimationTracks(w,N,_,B,k);if(j)for(let V=0;V<j.length;V++)T.push(j[V])}let y=new Ze(r,void 0,T);return M(y,n),y})}createNodeMesh(t){let e=this.json,s=this,n=e.nodes[t];return n.mesh===void 0?null:s.getDependency("mesh",n.mesh).then(function(r){let i=s._getNodeRef(s.meshCache,n.mesh,r);return n.weights!==void 0&&i.traverse(function(a){if(a.isMesh)for(let o=0,c=n.weights.length;o<c;o++)a.morphTargetInfluences[o]=n.weights[o]}),i})}loadNode(t){let e=this.json,s=this,n=e.nodes[t],r=s._loadNodeShallow(t),i=[],a=n.children||[];for(let c=0,u=a.length;c<u;c++)i.push(s.getDependency("node",a[c]));let o=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([r,Promise.all(i),o]).then(function(c){let u=c[0],l=c[1],d=c[2];d!==null&&u.traverse(function(h){h.isSkinnedMesh&&h.bind(d,Kt)});for(let h=0,p=l.length;h<p;h++)u.add(l[h]);if(u.userData.pivot!==void 0&&l.length>0){let h=u.userData.pivot,p=l[0];u.pivot=new C().fromArray(h),u.position.x-=h[0],u.position.y-=h[1],u.position.z-=h[2],p.position.set(0,0,0),delete u.userData.pivot}return u})}_loadNodeShallow(t){let e=this.json,s=this.extensions,n=this;if(this.nodeCache[t]!==void 0)return this.nodeCache[t];let r=e.nodes[t],i=r.name?n.createUniqueName(r.name):"",a=[],o=n._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(t)});return o&&a.push(o),r.camera!==void 0&&a.push(n.getDependency("camera",r.camera).then(function(c){return n._getNodeRef(n.cameraCache,r.camera,c)})),n._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(t)}).forEach(function(c){a.push(c)}),this.nodeCache[t]=Promise.all(a).then(function(c){let u;if(r.isBone===!0?u=new Qe:c.length>1?u=new W:c.length===1?u=c[0]:u=new je,u!==c[0])for(let l=0,d=c.length;l<d;l++)u.add(c[l]);if(r.name&&(u.userData.name=r.name,u.name=i),M(u,r),r.extensions&&O(s,u,r),r.matrix!==void 0){let l=new z;l.fromArray(r.matrix),u.applyMatrix4(l)}else r.translation!==void 0&&u.position.fromArray(r.translation),r.rotation!==void 0&&u.quaternion.fromArray(r.rotation),r.scale!==void 0&&u.scale.fromArray(r.scale);if(!n.associations.has(u))n.associations.set(u,{});else if(r.mesh!==void 0&&n.meshCache.refs[r.mesh]>1){let l=n.associations.get(u);n.associations.set(u,{...l})}return n.associations.get(u).nodes=t,u}),this.nodeCache[t]}loadScene(t){let e=this.extensions,s=this.json.scenes[t],n=this,r=new W;s.name&&(r.name=n.createUniqueName(s.name)),M(r,s),s.extensions&&O(e,r,s);let i=s.nodes||[],a=[];for(let o=0,c=i.length;o<c;o++)a.push(n.getDependency("node",i[o]));return Promise.all(a).then(function(o){for(let u=0,l=o.length;u<l;u++){let d=o[u];d.parent!==null?r.add(Se(d)):r.add(d)}let c=u=>{let l=new Map;for(let[d,h]of n.associations)(d instanceof Y||d instanceof Ce)&&l.set(d,h);return u.traverse(d=>{let h=n.associations.get(d);h!=null&&l.set(d,h)}),l};return n.associations=c(r),r})}_createAnimationTracks(t,e,s,n,r){let i=[],a=t.name?t.name:t.uuid,o=[];function c(h){h.morphTargetInfluences&&o.push(h.name?h.name:h.uuid)}L[r.path]===L.weights?(c(t),t.isGroup&&t.children.forEach(c)):o.push(a);let u;switch(L[r.path]){case L.weights:u=Le;break;case L.rotation:u=Oe;break;case L.translation:case L.scale:u=ve;break;default:s.itemSize===1?u=Le:u=ve;break}let l=n.interpolation!==void 0?Ht[n.interpolation]:Ue,d=this._getArrayFromAccessor(s);for(let h=0,p=o.length;h<p;h++){let A=new u(o[h]+"."+L[r.path],e.array,d,l);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(A),i.push(A)}return i}_getArrayFromAccessor(t){let e=t.array;if(t.normalized){let s=Ee(e.constructor),n=new Float32Array(e.length);for(let r=0,i=e.length;r<i;r++)n[r]=e[r]*s;e=n}return e}_createCubicSplineTrackInterpolant(t){t.createInterpolant=function(s){let n=this instanceof Oe?be:K;return new n(this.times,this.values,this.getValueSize()/3,s)},t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}};function jt(f,t,e){let s=t.attributes,n=new Je;if(s.POSITION!==void 0){let a=e.json.accessors[s.POSITION],o=a.min,c=a.max;if(o!==void 0&&c!==void 0){if(n.set(new C(o[0],o[1],o[2]),new C(c[0],c[1],c[2])),a.normalized){let u=Ee(P[a.componentType]);n.min.multiplyScalar(u),n.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;let r=t.targets;if(r!==void 0){let a=new C,o=new C;for(let c=0,u=r.length;c<u;c++){let l=r[c];if(l.POSITION!==void 0){let d=e.json.accessors[l.POSITION],h=d.min,p=d.max;if(h!==void 0&&p!==void 0){if(o.setX(Math.max(Math.abs(h[0]),Math.abs(p[0]))),o.setY(Math.max(Math.abs(h[1]),Math.abs(p[1]))),o.setZ(Math.max(Math.abs(h[2]),Math.abs(p[2]))),d.normalized){let A=Ee(P[d.componentType]);o.multiplyScalar(A)}a.max(o)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}n.expandByVector(a)}f.boundingBox=n;let i=new Nt;n.getCenter(i.center),i.radius=n.min.distanceTo(n.max)/2,f.boundingSphere=i}function De(f,t,e){let s=t.attributes,n=[];function r(i,a){return e.getDependency("accessor",i).then(function(o){f.setAttribute(a,o)})}for(let i in s){let a=we[i]||i.toLowerCase();a in f.attributes||n.push(r(s[i],a))}if(t.indices!==void 0&&!f.index){let i=e.getDependency("accessor",t.indices).then(function(a){f.setIndex(a)});n.push(i)}return Ne.workingColorSpace!==I&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Ne.workingColorSpace}" not supported.`),M(f,t),jt(f,t,e),Promise.all(n).then(function(){return t.targets!==void 0?Ft(f,t.targets,e):f})}export{ke as GLTFLoader};
//# sourceMappingURL=GLTFLoader.mjs.map