Files
cad-Integration/text-to-cad-main/skills/cad-viewer/scripts/viewer/dist/assets/GLTFLoader-B3ztFMBW.js
T
2026-07-22 13:48:46 +08:00

3 lines
45 KiB
JavaScript

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