UNPKG

@vctrl/hooks

Version:

vctrl/hooks is a React hooks package designed to simplify 3D model loading and management within React applications. It's part of the vectreal-core ecosystem and is primarily used in the vctrl/viewer React component and the official website application.

1 lines 153 kB
"use strict";const Re=require("react/jsx-runtime"),q=require("react"),g=require("three"),sA={},W={emit(n,A){const e=sA[n];e&&e.forEach(a=>a(A))},on(n,A){sA[n]||(sA[n]=[]),sA[n].push(A)},off(n,A){const e=sA[n];e&&(sA[n]=e.filter(a=>a!==A))}};var O=(n=>(n.gltf="gltf",n.glb="glb",n.usdz="usdz",n))(O||{});const Ae={file:null,isFileLoading:!1,progress:0,supportedFileTypes:Object.values(O)};function Fe(n,A){switch(A.type){case"set-file":return{...n,file:A.payload};case"set-file-loading":return{...n,isFileLoading:A.payload};case"set-progress":return{...n,progress:A.payload};case"reset-state":return{...Ae};default:return n}}async function KA(n){const A=new Blob([n]),e=new FileReader;return new Promise((a,t)=>{e.onloadend=()=>{if(!(e!=null&&e.result))return;const i=(e==null?void 0:e.result).split(",")[1];a(i)},e.onerror=t,e.readAsDataURL(A)})}async function ke(n){const A=[];async function*e(a){for await(const[,t]of a)t.kind==="file"?yield await t.getFile():t.kind==="directory"&&(yield*e(t))}for await(const a of e(n))A.push(a);return A}function PA(n,A){if(A===g.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),n;if(A===g.TriangleFanDrawMode||A===g.TriangleStripDrawMode){let e=n.getIndex();if(e===null){const s=[],o=n.getAttribute("position");if(o!==void 0){for(let r=0;r<o.count;r++)s.push(r);n.setIndex(s),e=n.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),n}const a=e.count-2,t=[];if(A===g.TriangleFanDrawMode)for(let s=1;s<=a;s++)t.push(e.getX(0)),t.push(e.getX(s)),t.push(e.getX(s+1));else for(let s=0;s<a;s++)s%2===0?(t.push(e.getX(s)),t.push(e.getX(s+1)),t.push(e.getX(s+2))):(t.push(e.getX(s+2)),t.push(e.getX(s+1)),t.push(e.getX(s)));t.length/3!==a&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=n.clone();return i.setIndex(t),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",A),n}class Se extends g.Loader{constructor(A){super(A),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new Te(e)}),this.register(function(e){return new Me(e)}),this.register(function(e){return new Ke(e)}),this.register(function(e){return new Pe(e)}),this.register(function(e){return new Je(e)}),this.register(function(e){return new Ne(e)}),this.register(function(e){return new _e(e)}),this.register(function(e){return new qe(e)}),this.register(function(e){return new He(e)}),this.register(function(e){return new Le(e)}),this.register(function(e){return new Oe(e)}),this.register(function(e){return new Ue(e)}),this.register(function(e){return new je(e)}),this.register(function(e){return new ve(e)}),this.register(function(e){return new Ge(e)}),this.register(function(e){return new Ye(e)}),this.register(function(e){return new We(e)})}load(A,e,a,t){const i=this;let s;if(this.resourcePath!=="")s=this.resourcePath;else if(this.path!==""){const c=g.LoaderUtils.extractUrlBase(A);s=g.LoaderUtils.resolveURL(c,this.path)}else s=g.LoaderUtils.extractUrlBase(A);this.manager.itemStart(A);const o=function(c){t?t(c):console.error(c),i.manager.itemError(A),i.manager.itemEnd(A)},r=new g.FileLoader(this.manager);r.setPath(this.path),r.setResponseType("arraybuffer"),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(A,function(c){try{i.parse(c,s,function(B){e(B),i.manager.itemEnd(A)},o)}catch(B){o(B)}},a,o)}setDRACOLoader(A){return this.dracoLoader=A,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(A){return this.ktx2Loader=A,this}setMeshoptDecoder(A){return this.meshoptDecoder=A,this}register(A){return this.pluginCallbacks.indexOf(A)===-1&&this.pluginCallbacks.push(A),this}unregister(A){return this.pluginCallbacks.indexOf(A)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(A),1),this}parse(A,e,a,t){let i;const s={},o={},r=new TextDecoder;if(typeof A=="string")i=JSON.parse(A);else if(A instanceof ArrayBuffer)if(r.decode(new Uint8Array(A,0,4))===ee){try{s[G.KHR_BINARY_GLTF]=new Ve(A)}catch(I){t&&t(I);return}i=JSON.parse(s[G.KHR_BINARY_GLTF].content)}else i=JSON.parse(r.decode(A));else i=A;if(i.asset===void 0||i.asset.version[0]<2){t&&t(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const c=new rt(i,{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 B=0;B<this.pluginCallbacks.length;B++){const I=this.pluginCallbacks[B](c);I.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),o[I.name]=I,s[I.name]=!0}if(i.extensionsUsed)for(let B=0;B<i.extensionsUsed.length;++B){const I=i.extensionsUsed[B],l=i.extensionsRequired||[];switch(I){case G.KHR_MATERIALS_UNLIT:s[I]=new xe;break;case G.KHR_DRACO_MESH_COMPRESSION:s[I]=new ze(i,this.dracoLoader);break;case G.KHR_TEXTURE_TRANSFORM:s[I]=new Xe;break;case G.KHR_MESH_QUANTIZATION:s[I]=new Ze;break;default:l.indexOf(I)>=0&&o[I]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+I+'".')}}c.setExtensions(s),c.setPlugins(o),c.parse(a,t)}parseAsync(A,e){const a=this;return new Promise(function(t,i){a.parse(A,e,t,i)})}}function ye(){let n={};return{get:function(A){return n[A]},add:function(A,e){n[A]=e},remove:function(A){delete n[A]},removeAll:function(){n={}}}}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_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class Ge{constructor(A){this.parser=A,this.name=G.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const A=this.parser,e=this.parser.json.nodes||[];for(let a=0,t=e.length;a<t;a++){const i=e[a];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&A._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(A){const e=this.parser,a="light:"+A;let t=e.cache.get(a);if(t)return t;const i=e.json,r=((i.extensions&&i.extensions[this.name]||{}).lights||[])[A];let c;const B=new g.Color(16777215);r.color!==void 0&&B.setRGB(r.color[0],r.color[1],r.color[2],g.LinearSRGBColorSpace);const I=r.range!==void 0?r.range:0;switch(r.type){case"directional":c=new g.DirectionalLight(B),c.target.position.set(0,0,-1),c.add(c.target);break;case"point":c=new g.PointLight(B),c.distance=I;break;case"spot":c=new g.SpotLight(B),c.distance=I,r.spot=r.spot||{},r.spot.innerConeAngle=r.spot.innerConeAngle!==void 0?r.spot.innerConeAngle:0,r.spot.outerConeAngle=r.spot.outerConeAngle!==void 0?r.spot.outerConeAngle:Math.PI/4,c.angle=r.spot.outerConeAngle,c.penumbra=1-r.spot.innerConeAngle/r.spot.outerConeAngle,c.target.position.set(0,0,-1),c.add(c.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+r.type)}return c.position.set(0,0,0),c.decay=2,Z(c,r),r.intensity!==void 0&&(c.intensity=r.intensity),c.name=e.createUniqueName(r.name||"light_"+A),t=Promise.resolve(c),e.cache.add(a,t),t}getDependency(A,e){if(A==="light")return this._loadLight(e)}createNodeAttachment(A){const e=this,a=this.parser,i=a.json.nodes[A],o=(i.extensions&&i.extensions[this.name]||{}).light;return o===void 0?null:this._loadLight(o).then(function(r){return a._getNodeRef(e.cache,o,r)})}}class xe{constructor(){this.name=G.KHR_MATERIALS_UNLIT}getMaterialType(){return g.MeshBasicMaterial}extendParams(A,e,a){const t=[];A.color=new g.Color(1,1,1),A.opacity=1;const i=e.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const s=i.baseColorFactor;A.color.setRGB(s[0],s[1],s[2],g.LinearSRGBColorSpace),A.opacity=s[3]}i.baseColorTexture!==void 0&&t.push(a.assignTexture(A,"map",i.baseColorTexture,g.SRGBColorSpace))}return Promise.all(t)}}class Le{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(A,e){const t=this.parser.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=t.extensions[this.name].emissiveStrength;return i!==void 0&&(e.emissiveIntensity=i),Promise.resolve()}}class Te{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_CLEARCOAT}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const a=this.parser,t=a.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=[],s=t.extensions[this.name];if(s.clearcoatFactor!==void 0&&(e.clearcoat=s.clearcoatFactor),s.clearcoatTexture!==void 0&&i.push(a.assignTexture(e,"clearcoatMap",s.clearcoatTexture)),s.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=s.clearcoatRoughnessFactor),s.clearcoatRoughnessTexture!==void 0&&i.push(a.assignTexture(e,"clearcoatRoughnessMap",s.clearcoatRoughnessTexture)),s.clearcoatNormalTexture!==void 0&&(i.push(a.assignTexture(e,"clearcoatNormalMap",s.clearcoatNormalTexture)),s.clearcoatNormalTexture.scale!==void 0)){const o=s.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new g.Vector2(o,o)}return Promise.all(i)}}class Me{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_DISPERSION}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const t=this.parser.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=t.extensions[this.name];return e.dispersion=i.dispersion!==void 0?i.dispersion:0,Promise.resolve()}}class Ue{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_IRIDESCENCE}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const a=this.parser,t=a.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=[],s=t.extensions[this.name];return s.iridescenceFactor!==void 0&&(e.iridescence=s.iridescenceFactor),s.iridescenceTexture!==void 0&&i.push(a.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&&i.push(a.assignTexture(e,"iridescenceThicknessMap",s.iridescenceThicknessTexture)),Promise.all(i)}}class Ne{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_SHEEN}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const a=this.parser,t=a.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=[];e.sheenColor=new g.Color(0,0,0),e.sheenRoughness=0,e.sheen=1;const s=t.extensions[this.name];if(s.sheenColorFactor!==void 0){const o=s.sheenColorFactor;e.sheenColor.setRGB(o[0],o[1],o[2],g.LinearSRGBColorSpace)}return s.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=s.sheenRoughnessFactor),s.sheenColorTexture!==void 0&&i.push(a.assignTexture(e,"sheenColorMap",s.sheenColorTexture,g.SRGBColorSpace)),s.sheenRoughnessTexture!==void 0&&i.push(a.assignTexture(e,"sheenRoughnessMap",s.sheenRoughnessTexture)),Promise.all(i)}}class _e{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_TRANSMISSION}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const a=this.parser,t=a.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=[],s=t.extensions[this.name];return s.transmissionFactor!==void 0&&(e.transmission=s.transmissionFactor),s.transmissionTexture!==void 0&&i.push(a.assignTexture(e,"transmissionMap",s.transmissionTexture)),Promise.all(i)}}class qe{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_VOLUME}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const a=this.parser,t=a.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=[],s=t.extensions[this.name];e.thickness=s.thicknessFactor!==void 0?s.thicknessFactor:0,s.thicknessTexture!==void 0&&i.push(a.assignTexture(e,"thicknessMap",s.thicknessTexture)),e.attenuationDistance=s.attenuationDistance||1/0;const o=s.attenuationColor||[1,1,1];return e.attenuationColor=new g.Color().setRGB(o[0],o[1],o[2],g.LinearSRGBColorSpace),Promise.all(i)}}class He{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_IOR}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const t=this.parser.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=t.extensions[this.name];return e.ior=i.ior!==void 0?i.ior:1.5,Promise.resolve()}}class Oe{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_SPECULAR}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const a=this.parser,t=a.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=[],s=t.extensions[this.name];e.specularIntensity=s.specularFactor!==void 0?s.specularFactor:1,s.specularTexture!==void 0&&i.push(a.assignTexture(e,"specularIntensityMap",s.specularTexture));const o=s.specularColorFactor||[1,1,1];return e.specularColor=new g.Color().setRGB(o[0],o[1],o[2],g.LinearSRGBColorSpace),s.specularColorTexture!==void 0&&i.push(a.assignTexture(e,"specularColorMap",s.specularColorTexture,g.SRGBColorSpace)),Promise.all(i)}}class ve{constructor(A){this.parser=A,this.name=G.EXT_MATERIALS_BUMP}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const a=this.parser,t=a.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=[],s=t.extensions[this.name];return e.bumpScale=s.bumpFactor!==void 0?s.bumpFactor:1,s.bumpTexture!==void 0&&i.push(a.assignTexture(e,"bumpMap",s.bumpTexture)),Promise.all(i)}}class je{constructor(A){this.parser=A,this.name=G.KHR_MATERIALS_ANISOTROPY}getMaterialType(A){const a=this.parser.json.materials[A];return!a.extensions||!a.extensions[this.name]?null:g.MeshPhysicalMaterial}extendMaterialParams(A,e){const a=this.parser,t=a.json.materials[A];if(!t.extensions||!t.extensions[this.name])return Promise.resolve();const i=[],s=t.extensions[this.name];return s.anisotropyStrength!==void 0&&(e.anisotropy=s.anisotropyStrength),s.anisotropyRotation!==void 0&&(e.anisotropyRotation=s.anisotropyRotation),s.anisotropyTexture!==void 0&&i.push(a.assignTexture(e,"anisotropyMap",s.anisotropyTexture)),Promise.all(i)}}class Ke{constructor(A){this.parser=A,this.name=G.KHR_TEXTURE_BASISU}loadTexture(A){const e=this.parser,a=e.json,t=a.textures[A];if(!t.extensions||!t.extensions[this.name])return null;const i=t.extensions[this.name],s=e.options.ktx2Loader;if(!s){if(a.extensionsRequired&&a.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return e.loadTextureImage(A,i.source,s)}}class Pe{constructor(A){this.parser=A,this.name=G.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(A){const e=this.name,a=this.parser,t=a.json,i=t.textures[A];if(!i.extensions||!i.extensions[e])return null;const s=i.extensions[e],o=t.images[s.source];let r=a.textureLoader;if(o.uri){const c=a.options.manager.getHandler(o.uri);c!==null&&(r=c)}return this.detectSupport().then(function(c){if(c)return a.loadTextureImage(A,s.source,r);if(t.extensionsRequired&&t.extensionsRequired.indexOf(e)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return a.loadTexture(A)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(A){const e=new Image;e.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",e.onload=e.onerror=function(){A(e.height===1)}})),this.isSupported}}class Je{constructor(A){this.parser=A,this.name=G.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(A){const e=this.name,a=this.parser,t=a.json,i=t.textures[A];if(!i.extensions||!i.extensions[e])return null;const s=i.extensions[e],o=t.images[s.source];let r=a.textureLoader;if(o.uri){const c=a.options.manager.getHandler(o.uri);c!==null&&(r=c)}return this.detectSupport().then(function(c){if(c)return a.loadTextureImage(A,s.source,r);if(t.extensionsRequired&&t.extensionsRequired.indexOf(e)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return a.loadTexture(A)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(A){const e=new Image;e.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",e.onload=e.onerror=function(){A(e.height===1)}})),this.isSupported}}class Ye{constructor(A){this.name=G.EXT_MESHOPT_COMPRESSION,this.parser=A}loadBufferView(A){const e=this.parser.json,a=e.bufferViews[A];if(a.extensions&&a.extensions[this.name]){const t=a.extensions[this.name],i=this.parser.getDependency("buffer",t.buffer),s=this.parser.options.meshoptDecoder;if(!s||!s.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 i.then(function(o){const r=t.byteOffset||0,c=t.byteLength||0,B=t.count,I=t.byteStride,l=new Uint8Array(o,r,c);return s.decodeGltfBufferAsync?s.decodeGltfBufferAsync(B,I,l,t.mode,t.filter).then(function(C){return C.buffer}):s.ready.then(function(){const C=new ArrayBuffer(B*I);return s.decodeGltfBuffer(new Uint8Array(C),B,I,l,t.mode,t.filter),C})})}else return null}}class We{constructor(A){this.name=G.EXT_MESH_GPU_INSTANCING,this.parser=A}createNodeMesh(A){const e=this.parser.json,a=e.nodes[A];if(!a.extensions||!a.extensions[this.name]||a.mesh===void 0)return null;const t=e.meshes[a.mesh];for(const c of t.primitives)if(c.mode!==j.TRIANGLES&&c.mode!==j.TRIANGLE_STRIP&&c.mode!==j.TRIANGLE_FAN&&c.mode!==void 0)return null;const s=a.extensions[this.name].attributes,o=[],r={};for(const c in s)o.push(this.parser.getDependency("accessor",s[c]).then(B=>(r[c]=B,r[c])));return o.length<1?null:(o.push(this.parser.createNodeMesh(A)),Promise.all(o).then(c=>{const B=c.pop(),I=B.isGroup?B.children:[B],l=c[0].count,C=[];for(const E of I){const h=new g.Matrix4,u=new g.Vector3,Q=new g.Quaternion,f=new g.Vector3(1,1,1),p=new g.InstancedMesh(E.geometry,E.material,l);for(let m=0;m<l;m++)r.TRANSLATION&&u.fromBufferAttribute(r.TRANSLATION,m),r.ROTATION&&Q.fromBufferAttribute(r.ROTATION,m),r.SCALE&&f.fromBufferAttribute(r.SCALE,m),p.setMatrixAt(m,h.compose(u,Q,f));for(const m in r)if(m==="_COLOR_0"){const F=r[m];p.instanceColor=new g.InstancedBufferAttribute(F.array,F.itemSize,F.normalized)}else m!=="TRANSLATION"&&m!=="ROTATION"&&m!=="SCALE"&&E.geometry.setAttribute(m,r[m]);g.Object3D.prototype.copy.call(p,E),this.parser.assignFinalMaterial(p),C.push(p)}return B.isGroup?(B.clear(),B.add(...C),B):C[0]}))}}const ee="glTF",cA=12,JA={JSON:1313821514,BIN:5130562};class Ve{constructor(A){this.name=G.KHR_BINARY_GLTF,this.content=null,this.body=null;const e=new DataView(A,0,cA),a=new TextDecoder;if(this.header={magic:a.decode(new Uint8Array(A.slice(0,4))),version:e.getUint32(4,!0),length:e.getUint32(8,!0)},this.header.magic!==ee)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const t=this.header.length-cA,i=new DataView(A,cA);let s=0;for(;s<t;){const o=i.getUint32(s,!0);s+=4;const r=i.getUint32(s,!0);if(s+=4,r===JA.JSON){const c=new Uint8Array(A,cA+s,o);this.content=a.decode(c)}else if(r===JA.BIN){const c=cA+s;this.body=A.slice(c,c+o)}s+=o}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class ze{constructor(A,e){if(!e)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=G.KHR_DRACO_MESH_COMPRESSION,this.json=A,this.dracoLoader=e,this.dracoLoader.preload()}decodePrimitive(A,e){const a=this.json,t=this.dracoLoader,i=A.extensions[this.name].bufferView,s=A.extensions[this.name].attributes,o={},r={},c={};for(const B in s){const I=SA[B]||B.toLowerCase();o[I]=s[B]}for(const B in A.attributes){const I=SA[B]||B.toLowerCase();if(s[B]!==void 0){const l=a.accessors[A.attributes[B]],C=oA[l.componentType];c[I]=C.name,r[I]=l.normalized===!0}}return e.getDependency("bufferView",i).then(function(B){return new Promise(function(I,l){t.decodeDracoFile(B,function(C){for(const E in C.attributes){const h=C.attributes[E],u=r[E];u!==void 0&&(h.normalized=u)}I(C)},o,c,g.LinearSRGBColorSpace,l)})})}}class Xe{constructor(){this.name=G.KHR_TEXTURE_TRANSFORM}extendTexture(A,e){return(e.texCoord===void 0||e.texCoord===A.channel)&&e.offset===void 0&&e.rotation===void 0&&e.scale===void 0||(A=A.clone(),e.texCoord!==void 0&&(A.channel=e.texCoord),e.offset!==void 0&&A.offset.fromArray(e.offset),e.rotation!==void 0&&(A.rotation=e.rotation),e.scale!==void 0&&A.repeat.fromArray(e.scale),A.needsUpdate=!0),A}}class Ze{constructor(){this.name=G.KHR_MESH_QUANTIZATION}}class te extends g.Interpolant{constructor(A,e,a,t){super(A,e,a,t)}copySampleValue_(A){const e=this.resultBuffer,a=this.sampleValues,t=this.valueSize,i=A*t*3+t;for(let s=0;s!==t;s++)e[s]=a[i+s];return e}interpolate_(A,e,a,t){const i=this.resultBuffer,s=this.sampleValues,o=this.valueSize,r=o*2,c=o*3,B=t-e,I=(a-e)/B,l=I*I,C=l*I,E=A*c,h=E-c,u=-2*C+3*l,Q=C-l,f=1-u,p=Q-l+I;for(let m=0;m!==o;m++){const F=s[h+m+o],S=s[h+m+r]*B,x=s[E+m+o],U=s[E+m]*B;i[m]=f*F+p*S+u*x+Q*U}return i}}const $e=new g.Quaternion;class At extends te{interpolate_(A,e,a,t){const i=super.interpolate_(A,e,a,t);return $e.fromArray(i).normalize().toArray(i),i}}const j={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},oA={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},YA={9728:g.NearestFilter,9729:g.LinearFilter,9984:g.NearestMipmapNearestFilter,9985:g.LinearMipmapNearestFilter,9986:g.NearestMipmapLinearFilter,9987:g.LinearMipmapLinearFilter},WA={33071:g.ClampToEdgeWrapping,33648:g.MirroredRepeatWrapping,10497:g.RepeatWrapping},bA={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},SA={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"},AA={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},et={CUBICSPLINE:void 0,LINEAR:g.InterpolateLinear,STEP:g.InterpolateDiscrete},fA={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function tt(n){return n.DefaultMaterial===void 0&&(n.DefaultMaterial=new g.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:g.FrontSide})),n.DefaultMaterial}function aA(n,A,e){for(const a in e.extensions)n[a]===void 0&&(A.userData.gltfExtensions=A.userData.gltfExtensions||{},A.userData.gltfExtensions[a]=e.extensions[a])}function Z(n,A){A.extras!==void 0&&(typeof A.extras=="object"?Object.assign(n.userData,A.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+A.extras))}function at(n,A,e){let a=!1,t=!1,i=!1;for(let c=0,B=A.length;c<B;c++){const I=A[c];if(I.POSITION!==void 0&&(a=!0),I.NORMAL!==void 0&&(t=!0),I.COLOR_0!==void 0&&(i=!0),a&&t&&i)break}if(!a&&!t&&!i)return Promise.resolve(n);const s=[],o=[],r=[];for(let c=0,B=A.length;c<B;c++){const I=A[c];if(a){const l=I.POSITION!==void 0?e.getDependency("accessor",I.POSITION):n.attributes.position;s.push(l)}if(t){const l=I.NORMAL!==void 0?e.getDependency("accessor",I.NORMAL):n.attributes.normal;o.push(l)}if(i){const l=I.COLOR_0!==void 0?e.getDependency("accessor",I.COLOR_0):n.attributes.color;r.push(l)}}return Promise.all([Promise.all(s),Promise.all(o),Promise.all(r)]).then(function(c){const B=c[0],I=c[1],l=c[2];return a&&(n.morphAttributes.position=B),t&&(n.morphAttributes.normal=I),i&&(n.morphAttributes.color=l),n.morphTargetsRelative=!0,n})}function it(n,A){if(n.updateMorphTargets(),A.weights!==void 0)for(let e=0,a=A.weights.length;e<a;e++)n.morphTargetInfluences[e]=A.weights[e];if(A.extras&&Array.isArray(A.extras.targetNames)){const e=A.extras.targetNames;if(n.morphTargetInfluences.length===e.length){n.morphTargetDictionary={};for(let a=0,t=e.length;a<t;a++)n.morphTargetDictionary[e[a]]=a}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function st(n){let A;const e=n.extensions&&n.extensions[G.KHR_DRACO_MESH_COMPRESSION];if(e?A="draco:"+e.bufferView+":"+e.indices+":"+EA(e.attributes):A=n.indices+":"+EA(n.attributes)+":"+n.mode,n.targets!==void 0)for(let a=0,t=n.targets.length;a<t;a++)A+=":"+EA(n.targets[a]);return A}function EA(n){let A="";const e=Object.keys(n).sort();for(let a=0,t=e.length;a<t;a++)A+=e[a]+":"+n[e[a]]+";";return A}function yA(n){switch(n){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 nt(n){return n.search(/\.jpe?g($|\?)/i)>0||n.search(/^data\:image\/jpeg/)===0?"image/jpeg":n.search(/\.webp($|\?)/i)>0||n.search(/^data\:image\/webp/)===0?"image/webp":"image/png"}const ot=new g.Matrix4;class rt{constructor(A={},e={}){this.json=A,this.extensions={},this.plugins={},this.options=e,this.cache=new ye,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 a=!1,t=-1,i=!1,s=-1;if(typeof navigator<"u"){const o=navigator.userAgent;a=/^((?!chrome|android).)*safari/i.test(o)===!0;const r=o.match(/Version\/(\d+)/);t=a&&r?parseInt(r[1],10):-1,i=o.indexOf("Firefox")>-1,s=i?o.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||a&&t<17||i&&s<98?this.textureLoader=new g.TextureLoader(this.options.manager):this.textureLoader=new g.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new g.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(A){this.extensions=A}setPlugins(A){this.plugins=A}parse(A,e){const a=this,t=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(s){return s._markDefs&&s._markDefs()}),Promise.all(this._invokeAll(function(s){return s.beforeRoot&&s.beforeRoot()})).then(function(){return Promise.all([a.getDependencies("scene"),a.getDependencies("animation"),a.getDependencies("camera")])}).then(function(s){const o={scene:s[0][t.scene||0],scenes:s[0],animations:s[1],cameras:s[2],asset:t.asset,parser:a,userData:{}};return aA(i,o,t),Z(o,t),Promise.all(a._invokeAll(function(r){return r.afterRoot&&r.afterRoot(o)})).then(function(){for(const r of o.scenes)r.updateMatrixWorld();A(o)})}).catch(e)}_markDefs(){const A=this.json.nodes||[],e=this.json.skins||[],a=this.json.meshes||[];for(let t=0,i=e.length;t<i;t++){const s=e[t].joints;for(let o=0,r=s.length;o<r;o++)A[s[o]].isBone=!0}for(let t=0,i=A.length;t<i;t++){const s=A[t];s.mesh!==void 0&&(this._addNodeRef(this.meshCache,s.mesh),s.skin!==void 0&&(a[s.mesh].isSkinnedMesh=!0)),s.camera!==void 0&&this._addNodeRef(this.cameraCache,s.camera)}}_addNodeRef(A,e){e!==void 0&&(A.refs[e]===void 0&&(A.refs[e]=A.uses[e]=0),A.refs[e]++)}_getNodeRef(A,e,a){if(A.refs[e]<=1)return a;const t=a.clone(),i=(s,o)=>{const r=this.associations.get(s);r!=null&&this.associations.set(o,r);for(const[c,B]of s.children.entries())i(B,o.children[c])};return i(a,t),t.name+="_instance_"+A.uses[e]++,t}_invokeOne(A){const e=Object.values(this.plugins);e.push(this);for(let a=0;a<e.length;a++){const t=A(e[a]);if(t)return t}return null}_invokeAll(A){const e=Object.values(this.plugins);e.unshift(this);const a=[];for(let t=0;t<e.length;t++){const i=A(e[t]);i&&a.push(i)}return a}getDependency(A,e){const a=A+":"+e;let t=this.cache.get(a);if(!t){switch(A){case"scene":t=this.loadScene(e);break;case"node":t=this._invokeOne(function(i){return i.loadNode&&i.loadNode(e)});break;case"mesh":t=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(e)});break;case"accessor":t=this.loadAccessor(e);break;case"bufferView":t=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(e)});break;case"buffer":t=this.loadBuffer(e);break;case"material":t=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(e)});break;case"texture":t=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(e)});break;case"skin":t=this.loadSkin(e);break;case"animation":t=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(e)});break;case"camera":t=this.loadCamera(e);break;default:if(t=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(A,e)}),!t)throw new Error("Unknown type: "+A);break}this.cache.add(a,t)}return t}getDependencies(A){let e=this.cache.get(A);if(!e){const a=this,t=this.json[A+(A==="mesh"?"es":"s")]||[];e=Promise.all(t.map(function(i,s){return a.getDependency(A,s)})),this.cache.add(A,e)}return e}loadBuffer(A){const e=this.json.buffers[A],a=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&&A===0)return Promise.resolve(this.extensions[G.KHR_BINARY_GLTF].body);const t=this.options;return new Promise(function(i,s){a.load(g.LoaderUtils.resolveURL(e.uri,t.path),i,void 0,function(){s(new Error('THREE.GLTFLoader: Failed to load buffer "'+e.uri+'".'))})})}loadBufferView(A){const e=this.json.bufferViews[A];return this.getDependency("buffer",e.buffer).then(function(a){const t=e.byteLength||0,i=e.byteOffset||0;return a.slice(i,i+t)})}loadAccessor(A){const e=this,a=this.json,t=this.json.accessors[A];if(t.bufferView===void 0&&t.sparse===void 0){const s=bA[t.type],o=oA[t.componentType],r=t.normalized===!0,c=new o(t.count*s);return Promise.resolve(new g.BufferAttribute(c,s,r))}const i=[];return t.bufferView!==void 0?i.push(this.getDependency("bufferView",t.bufferView)):i.push(null),t.sparse!==void 0&&(i.push(this.getDependency("bufferView",t.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",t.sparse.values.bufferView))),Promise.all(i).then(function(s){const o=s[0],r=bA[t.type],c=oA[t.componentType],B=c.BYTES_PER_ELEMENT,I=B*r,l=t.byteOffset||0,C=t.bufferView!==void 0?a.bufferViews[t.bufferView].byteStride:void 0,E=t.normalized===!0;let h,u;if(C&&C!==I){const Q=Math.floor(l/C),f="InterleavedBuffer:"+t.bufferView+":"+t.componentType+":"+Q+":"+t.count;let p=e.cache.get(f);p||(h=new c(o,Q*C,t.count*C/B),p=new g.InterleavedBuffer(h,C/B),e.cache.add(f,p)),u=new g.InterleavedBufferAttribute(p,r,l%C/B,E)}else o===null?h=new c(t.count*r):h=new c(o,l,t.count*r),u=new g.BufferAttribute(h,r,E);if(t.sparse!==void 0){const Q=bA.SCALAR,f=oA[t.sparse.indices.componentType],p=t.sparse.indices.byteOffset||0,m=t.sparse.values.byteOffset||0,F=new f(s[1],p,t.sparse.count*Q),S=new c(s[2],m,t.sparse.count*r);o!==null&&(u=new g.BufferAttribute(u.array.slice(),u.itemSize,u.normalized));for(let x=0,U=F.length;x<U;x++){const b=F[x];if(u.setX(b,S[x*r]),r>=2&&u.setY(b,S[x*r+1]),r>=3&&u.setZ(b,S[x*r+2]),r>=4&&u.setW(b,S[x*r+3]),r>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return u})}loadTexture(A){const e=this.json,a=this.options,i=e.textures[A].source,s=e.images[i];let o=this.textureLoader;if(s.uri){const r=a.manager.getHandler(s.uri);r!==null&&(o=r)}return this.loadTextureImage(A,i,o)}loadTextureImage(A,e,a){const t=this,i=this.json,s=i.textures[A],o=i.images[e],r=(o.uri||o.bufferView)+":"+s.sampler;if(this.textureCache[r])return this.textureCache[r];const c=this.loadImageSource(e,a).then(function(B){B.flipY=!1,B.name=s.name||o.name||"",B.name===""&&typeof o.uri=="string"&&o.uri.startsWith("data:image/")===!1&&(B.name=o.uri);const l=(i.samplers||{})[s.sampler]||{};return B.magFilter=YA[l.magFilter]||g.LinearFilter,B.minFilter=YA[l.minFilter]||g.LinearMipmapLinearFilter,B.wrapS=WA[l.wrapS]||g.RepeatWrapping,B.wrapT=WA[l.wrapT]||g.RepeatWrapping,t.associations.set(B,{textures:A}),B}).catch(function(){return null});return this.textureCache[r]=c,c}loadImageSource(A,e){const a=this,t=this.json,i=this.options;if(this.sourceCache[A]!==void 0)return this.sourceCache[A].then(I=>I.clone());const s=t.images[A],o=self.URL||self.webkitURL;let r=s.uri||"",c=!1;if(s.bufferView!==void 0)r=a.getDependency("bufferView",s.bufferView).then(function(I){c=!0;const l=new Blob([I],{type:s.mimeType});return r=o.createObjectURL(l),r});else if(s.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+A+" is missing URI and bufferView");const B=Promise.resolve(r).then(function(I){return new Promise(function(l,C){let E=l;e.isImageBitmapLoader===!0&&(E=function(h){const u=new g.Texture(h);u.needsUpdate=!0,l(u)}),e.load(g.LoaderUtils.resolveURL(I,i.path),E,void 0,C)})}).then(function(I){return c===!0&&o.revokeObjectURL(r),Z(I,s),I.userData.mimeType=s.mimeType||nt(s.uri),I}).catch(function(I){throw console.error("THREE.GLTFLoader: Couldn't load texture",r),I});return this.sourceCache[A]=B,B}assignTexture(A,e,a,t){const i=this;return this.getDependency("texture",a.index).then(function(s){if(!s)return null;if(a.texCoord!==void 0&&a.texCoord>0&&(s=s.clone(),s.channel=a.texCoord),i.extensions[G.KHR_TEXTURE_TRANSFORM]){const o=a.extensions!==void 0?a.extensions[G.KHR_TEXTURE_TRANSFORM]:void 0;if(o){const r=i.associations.get(s);s=i.extensions[G.KHR_TEXTURE_TRANSFORM].extendTexture(s,o),i.associations.set(s,r)}}return t!==void 0&&(s.colorSpace=t),A[e]=s,s})}assignFinalMaterial(A){const e=A.geometry;let a=A.material;const t=e.attributes.tangent===void 0,i=e.attributes.color!==void 0,s=e.attributes.normal===void 0;if(A.isPoints){const o="PointsMaterial:"+a.uuid;let r=this.cache.get(o);r||(r=new g.PointsMaterial,g.Material.prototype.copy.call(r,a),r.color.copy(a.color),r.map=a.map,r.sizeAttenuation=!1,this.cache.add(o,r)),a=r}else if(A.isLine){const o="LineBasicMaterial:"+a.uuid;let r=this.cache.get(o);r||(r=new g.LineBasicMaterial,g.Material.prototype.copy.call(r,a),r.color.copy(a.color),r.map=a.map,this.cache.add(o,r)),a=r}if(t||i||s){let o="ClonedMaterial:"+a.uuid+":";t&&(o+="derivative-tangents:"),i&&(o+="vertex-colors:"),s&&(o+="flat-shading:");let r=this.cache.get(o);r||(r=a.clone(),i&&(r.vertexColors=!0),s&&(r.flatShading=!0),t&&(r.normalScale&&(r.normalScale.y*=-1),r.clearcoatNormalScale&&(r.clearcoatNormalScale.y*=-1)),this.cache.add(o,r),this.associations.set(r,this.associations.get(a))),a=r}A.material=a}getMaterialType(){return g.MeshStandardMaterial}loadMaterial(A){const e=this,a=this.json,t=this.extensions,i=a.materials[A];let s;const o={},r=i.extensions||{},c=[];if(r[G.KHR_MATERIALS_UNLIT]){const I=t[G.KHR_MATERIALS_UNLIT];s=I.getMaterialType(),c.push(I.extendParams(o,i,e))}else{const I=i.pbrMetallicRoughness||{};if(o.color=new g.Color(1,1,1),o.opacity=1,Array.isArray(I.baseColorFactor)){const l=I.baseColorFactor;o.color.setRGB(l[0],l[1],l[2],g.LinearSRGBColorSpace),o.opacity=l[3]}I.baseColorTexture!==void 0&&c.push(e.assignTexture(o,"map",I.baseColorTexture,g.SRGBColorSpace)),o.metalness=I.metallicFactor!==void 0?I.metallicFactor:1,o.roughness=I.roughnessFactor!==void 0?I.roughnessFactor:1,I.metallicRoughnessTexture!==void 0&&(c.push(e.assignTexture(o,"metalnessMap",I.metallicRoughnessTexture)),c.push(e.assignTexture(o,"roughnessMap",I.metallicRoughnessTexture))),s=this._invokeOne(function(l){return l.getMaterialType&&l.getMaterialType(A)}),c.push(Promise.all(this._invokeAll(function(l){return l.extendMaterialParams&&l.extendMaterialParams(A,o)})))}i.doubleSided===!0&&(o.side=g.DoubleSide);const B=i.alphaMode||fA.OPAQUE;if(B===fA.BLEND?(o.transparent=!0,o.depthWrite=!1):(o.transparent=!1,B===fA.MASK&&(o.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&s!==g.MeshBasicMaterial&&(c.push(e.assignTexture(o,"normalMap",i.normalTexture)),o.normalScale=new g.Vector2(1,1),i.normalTexture.scale!==void 0)){const I=i.normalTexture.scale;o.normalScale.set(I,I)}if(i.occlusionTexture!==void 0&&s!==g.MeshBasicMaterial&&(c.push(e.assignTexture(o,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(o.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&s!==g.MeshBasicMaterial){const I=i.emissiveFactor;o.emissive=new g.Color().setRGB(I[0],I[1],I[2],g.LinearSRGBColorSpace)}return i.emissiveTexture!==void 0&&s!==g.MeshBasicMaterial&&c.push(e.assignTexture(o,"emissiveMap",i.emissiveTexture,g.SRGBColorSpace)),Promise.all(c).then(function(){const I=new s(o);return i.name&&(I.name=i.name),Z(I,i),e.associations.set(I,{materials:A}),i.extensions&&aA(t,I,i),I})}createUniqueName(A){const e=g.PropertyBinding.sanitizeNodeName(A||"");return e in this.nodeNamesUsed?e+"_"+ ++this.nodeNamesUsed[e]:(this.nodeNamesUsed[e]=0,e)}loadGeometries(A){const e=this,a=this.extensions,t=this.primitiveCache;function i(o){return a[G.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(o,e).then(function(r){return VA(r,o,e)})}const s=[];for(let o=0,r=A.length;o<r;o++){const c=A[o],B=st(c),I=t[B];if(I)s.push(I.promise);else{let l;c.extensions&&c.extensions[G.KHR_DRACO_MESH_COMPRESSION]?l=i(c):l=VA(new g.BufferGeometry,c,e),t[B]={primitive:c,promise:l},s.push(l)}}return Promise.all(s)}loadMesh(A){const e=this,a=this.json,t=this.extensions,i=a.meshes[A],s=i.primitives,o=[];for(let r=0,c=s.length;r<c;r++){const B=s[r].material===void 0?tt(this.cache):this.getDependency("material",s[r].material);o.push(B)}return o.push(e.loadGeometries(s)),Promise.all(o).then(function(r){const c=r.slice(0,r.length-1),B=r[r.length-1],I=[];for(let C=0,E=B.length;C<E;C++){const h=B[C],u=s[C];let Q;const f=c[C];if(u.mode===j.TRIANGLES||u.mode===j.TRIANGLE_STRIP||u.mode===j.TRIANGLE_FAN||u.mode===void 0)Q=i.isSkinnedMesh===!0?new g.SkinnedMesh(h,f):new g.Mesh(h,f),Q.isSkinnedMesh===!0&&Q.normalizeSkinWeights(),u.mode===j.TRIANGLE_STRIP?Q.geometry=PA(Q.geometry,g.TriangleStripDrawMode):u.mode===j.TRIANGLE_FAN&&(Q.geometry=PA(Q.geometry,g.TriangleFanDrawMode));else if(u.mode===j.LINES)Q=new g.LineSegments(h,f);else if(u.mode===j.LINE_STRIP)Q=new g.Line(h,f);else if(u.mode===j.LINE_LOOP)Q=new g.LineLoop(h,f);else if(u.mode===j.POINTS)Q=new g.Points(h,f);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+u.mode);Object.keys(Q.geometry.morphAttributes).length>0&&it(Q,i),Q.name=e.createUniqueName(i.name||"mesh_"+A),Z(Q,i),u.extensions&&aA(t,Q,u),e.assignFinalMaterial(Q),I.push(Q)}for(let C=0,E=I.length;C<E;C++)e.associations.set(I[C],{meshes:A,primitives:C});if(I.length===1)return i.extensions&&aA(t,I[0],i),I[0];const l=new g.Group;i.extensions&&aA(t,l,i),e.associations.set(l,{meshes:A});for(let C=0,E=I.length;C<E;C++)l.add(I[C]);return l})}loadCamera(A){let e;const a=this.json.cameras[A],t=a[a.type];if(!t){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return a.type==="perspective"?e=new g.PerspectiveCamera(g.MathUtils.radToDeg(t.yfov),t.aspectRatio||1,t.znear||1,t.zfar||2e6):a.type==="orthographic"&&(e=new g.OrthographicCamera(-t.xmag,t.xmag,t.ymag,-t.ymag,t.znear,t.zfar)),a.name&&(e.name=this.createUniqueName(a.name)),Z(e,a),Promise.resolve(e)}loadSkin(A){const e=this.json.skins[A],a=[];for(let t=0,i=e.joints.length;t<i;t++)a.push(this._loadNodeShallow(e.joints[t]));return e.inverseBindMatrices!==void 0?a.push(this.getDependency("accessor",e.inverseBindMatrices)):a.push(null),Promise.all(a).then(function(t){const i=t.pop(),s=t,o=[],r=[];for(let c=0,B=s.length;c<B;c++){const I=s[c];if(I){o.push(I);const l=new g.Matrix4;i!==null&&l.fromArray(i.array,c*16),r.push(l)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',e.joints[c])}return new g.Skeleton(o,r)})}loadAnimation(A){const e=this.json,a=this,t=e.animations[A],i=t.name?t.name:"animation_"+A,s=[],o=[],r=[],c=[],B=[];for(let I=0,l=t.channels.length;I<l;I++){const C=t.channels[I],E=t.samplers[C.sampler],h=C.target,u=h.node,Q=t.parameters!==void 0?t.parameters[E.input]:E.input,f=t.parameters!==void 0?t.parameters[E.output]:E.output;h.node!==void 0&&(s.push(this.getDependency("node",u)),o.push(this.getDependency("accessor",Q)),r.push(this.getDependency("accessor",f)),c.push(E),B.push(h))}return Promise.all([Promise.all(s),Promise.all(o),Promise.all(r),Promise.all(c),Promise.all(B)]).then(function(I){const l=I[0],C=I[1],E=I[2],h=I[3],u=I[4],Q=[];for(let f=0,p=l.length;f<p;f++){const m=l[f],F=C[f],S=E[f],x=h[f],U=u[f];if(m===void 0)continue;m.updateMatrix&&m.updateMatrix();const b=a._createAnimationTracks(m,F,S,x,U);if(b)for(let d=0;d<b.length;d++)Q.push(b[d])}return new g.AnimationClip(i,void 0,Q)})}createNodeMesh(A){const e=this.json,a=this,t=e.nodes[A];return t.mesh===void 0?null:a.getDependency("mesh",t.mesh).then(function(i){const s=a._getNodeRef(a.meshCache,t.mesh,i);return t.weights!==void 0&&s.traverse(function(o){if(o.isMesh)for(let r=0,c=t.weights.length;r<c;r++)o.morphTargetInfluences[r]=t.weights[r]}),s})}loadNode(A){const e=this.json,a=this,t=e.nodes[A],i=a._loadNodeShallow(A),s=[],o=t.children||[];for(let c=0,B=o.length;c<B;c++)s.push(a.getDependency("node",o[c]));const r=t.skin===void 0?Promise.resolve(null):a.getDependency("skin",t.skin);return Promise.all([i,Promise.all(s),r]).then(function(c){const B=c[0],I=c[1],l=c[2];l!==null&&B.traverse(function(C){C.isSkinnedMesh&&C.bind(l,ot)});for(let C=0,E=I.length;C<E;C++)B.add(I[C]);return B})}_loadNodeShallow(A){const e=this.json,a=this.extensions,t=this;if(this.nodeCache[A]!==void 0)return this.nodeCache[A];const i=e.nodes[A],s=i.name?t.createUniqueName(i.name):"",o=[],r=t._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(A)});return r&&o.push(r),i.camera!==void 0&&o.push(t.getDependency("camera",i.camera).then(function(c){return t._getNodeRef(t.cameraCache,i.camera,c)})),t._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(A)}).forEach(function(c){o.push(c)}),this.nodeCache[A]=Promise.all(o).then(function(c){let B;if(i.isBone===!0?B=new g.Bone:c.length>1?B=new g.Group:c.length===1?B=c[0]:B=new g.Object3D,B!==c[0])for(let I=0,l=c.length;I<l;I++)B.add(c[I]);if(i.name&&(B.userData.name=i.name,B.name=s),Z(B,i),i.extensions&&aA(a,B,i),i.matrix!==void 0){const I=new g.Matrix4;I.fromArray(i.matrix),B.applyMatrix4(I)}else i.translation!==void 0&&B.position.fromArray(i.translation),i.rotation!==void 0&&B.quaternion.fromArray(i.rotation),i.scale!==void 0&&B.scale.fromArray(i.scale);return t.associations.has(B)||t.associations.set(B,{}),t.associations.get(B).nodes=A,B}),this.nodeCache[A]}loadScene(A){const e=this.extensions,a=this.json.scenes[A],t=this,i=new g.Group;a.name&&(i.name=t.createUniqueName(a.name)),Z(i,a),a.extensions&&aA(e,i,a);const s=a.nodes||[],o=[];for(let r=0,c=s.length;r<c;r++)o.push(t.getDependency("node",s[r]));return Promise.all(o).then(function(r){for(let B=0,I=r.length;B<I;B++)i.add(r[B]);const c=B=>{const I=new Map;for(const[l,C]of t.associations)(l instanceof g.Material||l instanceof g.Texture)&&I.set(l,C);return B.traverse(l=>{const C=t.associations.get(l);C!=null&&I.set(l,C)}),I};return t.associations=c(i),i})}_createAnimationTracks(A,e,a,t,i){const s=[],o=A.name?A.name:A.uuid,r=[];AA[i.path]===AA.weights?A.traverse(function(l){l.morphTargetInfluences&&r.push(l.name?l.name:l.uuid)}):r.push(o);let c;switch(AA[i.path]){case AA.weights:c=g.NumberKeyframeTrack;break;case AA.rotation:c=g.QuaternionKeyframeTrack;break;case AA.position:case AA.scale:c=g.VectorKeyframeTrack;break;default:switch(a.itemSize){case 1:c=g.NumberKeyframeTrack;break;case 2:case 3:default:c=g.VectorKeyframeTrack;break}break}const B=t.interpolation!==void 0?et[t.interpolation]:g.InterpolateLinear,I=this._getArrayFromAccessor(a);for(let l=0,C=r.length;l<C;l++){const E=new c(r[l]+"."+AA[i.path],e.array,I,B);t.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(E),s.push(E)}return s}_getArrayFromAccessor(A){let e=A.array;if(A.normalized){const a=yA(e.constructor),t=new Float32Array(e.length);for(let i=0,s=e.length;i<s;i++)t[i]=e[i]*a;e=t}return e}_createCubicSplineTrackInterpolant(A){A.createInterpolant=function(a){const t=this instanceof g.QuaternionKeyframeTrack?At:te;return new t(this.times,this.values,this.getValueSize()/3,a)},A.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function ct(n,A,e){const a=A.attributes,t=new g.Box3;if(a.POSITION!==void 0){const o=e.json.accessors[a.POSITION],r=o.min,c=o.max;if(r!==void 0&&c!==void 0){if(t.set(new g.Vector3(r[0],r[1],r[2]),new g.Vector3(c[0],c[1],c[2])),o.normalized){const B=yA(oA[o.componentType]);t.min.multiplyScalar(B),t.max.multiplyScalar(B)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=A.targets;if(i!==void 0){const o=new g.Vector3,r=new g.Vector3;for(let c=0,B=i.length;c<B;c++){const I=i[c];if(I.POSITION!==void 0){const l=e.json.accessors[I.POSITION],C=l.min,E=l.max;if(C!==void 0&&E!==void 0){if(r.setX(Math.max(Math.abs(C[0]),Math.abs(E[0]))),r.setY(Math.max(Math.abs(C[1]),Math.abs(E[1]))),r.setZ(Math.max(Math.abs(C[2]),Math.abs(E[2]))),l.normalized){const h=yA(oA[l.componentType]);r.multiplyScalar(h)}o.max(r)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}t.expandByVector(o)}n.boundingBox=t;const s=new g.Sphere;t.getCenter(s.center),s.radius=t.min.distanceTo(t.max)/2,n.boundingSphere=s}function VA(n,A,e){const a=A.attributes,t=[];function i(s,o){return e.getDependency("accessor",s).then(function(r){n.setAttribute(o,r)})}for(const s in a){const o=SA[s]||s.toLowerCase();o in n.attributes||t.push(i(a[s],o))}if(A.indices!==void 0&&!n.index){const s=e.getDependency("accessor",A.indices).then(function(o){n.setIndex(o)});t.push(s)}return g.ColorManagement.workingColorSpace!==g.LinearSRGBColorSpace&&"COLOR_0"in a&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${g.ColorManagement.workingColorSpace}" not supported.`),Z(n,A),ct(n,A,e),Promise.all(t).then(function(){return A.targets!==void 0?at(n,A.targets,e):n})}const QA=new WeakMap;class gt extends g.Loader{constructor(A){super(A),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(A){return this.decoderPath=A,this}setDecoderConfig(A){return this.decoderConfig=A,this}setWorkerLimit(A){return this.workerLimit=A,this}load(A,e,a,t){const i=new g.FileLoader(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(A,s=>{this.parse(s,e,t)},a,t)}parse(A,e,a=()=>{}){this.decodeDracoFile(A,e,null,null,g.SRGBColorSpace,a).catch(a)}decodeDracoFile(A,e,a,t,i=g.LinearSRGBColorSpace,s=()=>{}){const o={attributeIDs:a||this.defaultAttributeIDs,attributeTypes:t||this.defaultAttributeTypes,useUniqueIDs:!!a,vertexColorSpace:i};return this.decodeGeometry(A,o).then(e).catch(s)}decodeGeometry(A,e){const a=JSON.stringify(e);if(QA.has(A)){const r=QA.get(A);if(r.key===a)return r.promise;if(A.byteLength===0)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let t;const i=this.workerNextTaskID++,s=A.byteLength,o=this._getWorker(i,s).then(r=>(t=r,new Promise((c,B)=>{t._callbacks[i]={resolve:c,reject:B},t.postMessage({type:"decode",id:i