UNPKG

@j-kyoda/vue-three-vrm

Version:

A Vue 3 component designed to render and display VRM models on your web pages.

2 lines 92.6 kB
(function(R,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("vue"),require("three"),require("@pixiv/three-vrm")):typeof define=="function"&&define.amd?define(["exports","vue","three","@pixiv/three-vrm"],w):(R=typeof globalThis<"u"?globalThis:R||self,w(R.VueThreeVrm={},R.Vue,R.THREE,R.THREE_VRM))})(this,(function(R,w,u,D){"use strict";var ae=document.createElement("style");ae.textContent=`.box[data-v-0b88fd37]{display:block;width:100%;height:100%} /*$vite$:1*/`,document.head.appendChild(ae);function Ue(l){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const t in l)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(l,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>l[t]})}}return e.default=l,Object.freeze(e)}const _=Ue(u);class z{constructor(){}async fetchJSON(e){const t=await fetch(e);return t.ok?await t.json():null}normalizePose(e){return e==null?null:"pose"in e?e.pose:e}async fetchPose(e){const t=await this.fetchJSON(e);return this.normalizePose(t)}async fetchExpression(e){const t=await this.fetchJSON(e);return t==null?null:"expressions"in t?t.expressions:t}}class le{constructor(){this.gltf=null}get scene(){return this.gltf.scene}setModel(e){this.gltf=e}setPosition(e){this.gltf&&this.gltf.scene.position.set(e.x,e.y,e.z)}getPosition(){return this.gltf?{x:this.gltf.scene.position.x,y:this.gltf.scene.position.y,z:this.gltf.scene.position.z}:null}setRotation(e){this.gltf&&this.gltf.scene.rotation.set(e.x,e.y,e.z)}getRotation(){return this.gltf?{x:this.gltf.scene.rotation.x,y:this.gltf.scene.rotation.y,z:this.gltf.scene.rotation.z}:null}}class ce{constructor(){this.vrm=null,this.vrma=null,this.mixer=null}get scene(){return this.vrm?this.vrm.scene:null}setModel(e){this.vrm=e}setVrma(e){this.vrma=e}setMixer(e){this.mixer=e}setPosition(e){this.vrm.scene.position.x=e.x,this.vrm.scene.position.y=e.y,this.vrm.scene.position.z=e.z}getPosition(){return{x:this.vrm.scene.position.x,y:this.vrm.scene.position.y,z:this.vrm.scene.position.z}}setPose(e){this.vrm&&this.vrm.humanoid.setNormalizedPose(e)}getPose(){return this.vrm?this.vrm.humanoid.getNormalizedPose():null}updatePose(){this.vrm&&this.vrm.humanoid.update()}resetPose(){this.vrm&&this.vrm.humanoid.resetNormalizedPose()}getBoneNode(e){return this.vrm?this.vrm.humanoid.getNormalizedBoneNode(e):null}isValid(){return!!this.vrm}getBoneRotate(e){const t=this.getBoneNode(e);return t?{x:t.rotation.x,y:t.rotation.y,z:t.rotation.z}:null}setBoneRotate(e,t,n,s){const i=this.getBoneNode(e);i&&(i.rotation.x=t,i.rotation.y=n,i.rotation.z=s)}getBonePosition(e){const t=this.getBoneNode(e);return t?{x:t.position.x,y:t.position.y,z:t.position.z}:null}setBonePosition(e,t,n,s){const i=this.getBoneNode(e);i&&(i.position.x=t,i.position.y=n,i.position.z=s)}getMetaVersion(){return this.vrm?this.vrm.meta.metaVersion:null}setExpression(e,t){this.vrm&&this.vrm.expressionManager.setValue(e,t)}getExpression(e){return this.vrm?this.vrm.expressionManager.getValue(e):null}updateExpression(){return this.vrm?this.vrm.expressionManager.update():null}resetExpression(){return this.vrm?this.vrm.expressionManager.resetValues():null}getExpressionNames(){if(this.vrm){let e=[];for(const t in this.vrm.expressionManager.expressionMap)e.push(t);return e}return null}importExpression(e){if(this.vrm)for(const t in e)this.vrm.expressionManager.setValue(t,e[t])}exportExpression(){if(this.vrm){let e={};const t=this.getExpressionNames();for(const n in t)e[n]=this.getExpression(n);return e}return null}updateAnimation(e){this.mixer&&this.mixer.update(e),this.vrm&&this.vrm.update(e)}}class he{static isWebGL2Available(){try{const e=document.createElement("canvas");return!!(window.WebGL2RenderingContext&&e.getContext("webgl2"))}catch{return!1}}static isColorSpaceAvailable(e){try{const t=document.createElement("canvas"),n=window.WebGL2RenderingContext&&t.getContext("webgl2");return n.drawingBufferColorSpace=e,n.drawingBufferColorSpace===e}catch{return!1}}static getWebGL2ErrorMessage(){return this._getErrorMessage(2)}static _getErrorMessage(e){const t={1:"WebGL",2:"WebGL 2"},n={1:window.WebGLRenderingContext,2:window.WebGL2RenderingContext};let s='Your $0 does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">$1</a>';const i=document.createElement("div");return i.id="webglmessage",i.style.fontFamily="monospace",i.style.fontSize="13px",i.style.fontWeight="normal",i.style.textAlign="center",i.style.background="#fff",i.style.color="#000",i.style.padding="1.5em",i.style.width="400px",i.style.margin="5em auto 0",n[e]?s=s.replace("$0","graphics card"):s=s.replace("$0","browser"),s=s.replace("$1",t[e]),i.innerHTML=s,i}}function ue(l,e){if(e===u.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),l;if(e===u.TriangleFanDrawMode||e===u.TriangleStripDrawMode){let t=l.getIndex();if(t===null){const o=[],a=l.getAttribute("position");if(a!==void 0){for(let r=0;r<a.count;r++)o.push(r);l.setIndex(o),t=l.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),l}const n=t.count-2,s=[];if(e===u.TriangleFanDrawMode)for(let o=1;o<=n;o++)s.push(t.getX(0)),s.push(t.getX(o)),s.push(t.getX(o+1));else for(let o=0;o<n;o++)o%2===0?(s.push(t.getX(o)),s.push(t.getX(o+1)),s.push(t.getX(o+2))):(s.push(t.getX(o+2)),s.push(t.getX(o+1)),s.push(t.getX(o)));s.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=l.clone();return i.setIndex(s),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),l}function Ee(l){const e=new Map,t=new Map,n=l.clone();return de(l,n,function(s,i){e.set(i,s),t.set(s,i)}),n.traverse(function(s){if(!s.isSkinnedMesh)return;const i=s,o=e.get(s),a=o.skeleton.bones;i.skeleton=o.skeleton.clone(),i.bindMatrix.copy(o.bindMatrix),i.skeleton.bones=a.map(function(r){return t.get(r)}),i.bind(i.skeleton,i.bindMatrix)}),n}function de(l,e,t){t(l,e);for(let n=0;n<l.children.length;n++)de(l.children[n],e.children[n],t)}class j extends u.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new ze(t)}),this.register(function(t){return new We(t)}),this.register(function(t){return new et(t)}),this.register(function(t){return new tt(t)}),this.register(function(t){return new nt(t)}),this.register(function(t){return new Ye(t)}),this.register(function(t){return new Qe(t)}),this.register(function(t){return new qe(t)}),this.register(function(t){return new Ze(t)}),this.register(function(t){return new Ke(t)}),this.register(function(t){return new He(t)}),this.register(function(t){return new Xe(t)}),this.register(function(t){return new Je(t)}),this.register(function(t){return new $e(t)}),this.register(function(t){return new Be(t)}),this.register(function(t){return new pe(t,b.EXT_MESHOPT_COMPRESSION)}),this.register(function(t){return new pe(t,b.KHR_MESHOPT_COMPRESSION)}),this.register(function(t){return new st(t)})}load(e,t,n,s){const i=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const c=u.LoaderUtils.extractUrlBase(e);o=u.LoaderUtils.resolveURL(c,this.path)}else o=u.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=function(c){s?s(c):console.error(c),i.manager.itemError(e),i.manager.itemEnd(e)},r=new u.FileLoader(this.manager);r.setPath(this.path),r.setResponseType("arraybuffer"),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(e,function(c){try{i.parse(c,o,function(h){t(h),i.manager.itemEnd(e)},a)}catch(h){a(h)}},n,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,s){let i;const o={},a={},r=new TextDecoder;if(typeof e=="string")i=JSON.parse(e);else if(e instanceof ArrayBuffer)if(r.decode(new Uint8Array(e,0,4))===fe){try{o[b.KHR_BINARY_GLTF]=new it(e)}catch(d){s&&s(d);return}i=JSON.parse(o[b.KHR_BINARY_GLTF].content)}else i=JSON.parse(r.decode(e));else i=e;if(i.asset===void 0||i.asset.version[0]<2){s&&s(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const c=new _t(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let h=0;h<this.pluginCallbacks.length;h++){const d=this.pluginCallbacks[h](c);d.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[d.name]=d,o[d.name]=!0}if(i.extensionsUsed)for(let h=0;h<i.extensionsUsed.length;++h){const d=i.extensionsUsed[h],p=i.extensionsRequired||[];switch(d){case b.KHR_MATERIALS_UNLIT:o[d]=new Ge;break;case b.KHR_DRACO_MESH_COMPRESSION:o[d]=new ot(i,this.dracoLoader);break;case b.KHR_TEXTURE_TRANSFORM:o[d]=new rt;break;case b.KHR_MESH_QUANTIZATION:o[d]=new at;break;default:p.indexOf(d)>=0&&a[d]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+d+'".')}}c.setExtensions(o),c.setPlugins(a),c.parse(n,s)}parseAsync(e,t){const n=this;return new Promise(function(s,i){n.parse(e,t,s,i)})}}function je(){let l={};return{get:function(e){return l[e]},add:function(e,t){l[e]=t},remove:function(e){delete l[e]},removeAll:function(){l={}}}}function L(l,e,t){const n=l.json.materials[e];return n.extensions&&n.extensions[t]?n.extensions[t]:null}const b={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class Be{constructor(e){this.parser=e,this.name=b.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let n=0,s=t.length;n<s;n++){const i=t[n];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(e){const t=this.parser,n="light:"+e;let s=t.cache.get(n);if(s)return s;const i=t.json,r=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let c;const h=new u.Color(16777215);r.color!==void 0&&h.setRGB(r.color[0],r.color[1],r.color[2],u.LinearSRGBColorSpace);const d=r.range!==void 0?r.range:0;switch(r.type){case"directional":c=new u.DirectionalLight(h),c.target.position.set(0,0,-1),c.add(c.target);break;case"point":c=new u.PointLight(h),c.distance=d;break;case"spot":c=new u.SpotLight(h),c.distance=d,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),I(c,r),r.intensity!==void 0&&(c.intensity=r.intensity),c.name=t.createUniqueName(r.name||"light_"+e),s=Promise.resolve(c),t.cache.add(n,s),s}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,n=this.parser,i=n.json.nodes[e],a=(i.extensions&&i.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(r){return n._getNodeRef(t.cache,a,r)})}}class Ge{constructor(){this.name=b.KHR_MATERIALS_UNLIT}getMaterialType(){return u.MeshBasicMaterial}extendParams(e,t,n){const s=[];e.color=new u.Color(1,1,1),e.opacity=1;const i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const o=i.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],u.LinearSRGBColorSpace),e.opacity=o[3]}i.baseColorTexture!==void 0&&s.push(n.assignTexture(e,"map",i.baseColorTexture,u.SRGBColorSpace))}return Promise.all(s)}}class Ke{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);return n===null||n.emissiveStrength!==void 0&&(t.emissiveIntensity=n.emissiveStrength),Promise.resolve()}}class ze{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&s.push(this.parser.assignTexture(t,"clearcoatMap",n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&s.push(this.parser.assignTexture(t,"clearcoatRoughnessMap",n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(s.push(this.parser.assignTexture(t,"clearcoatNormalMap",n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){const i=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new u.Vector2(i,i)}return Promise.all(s)}}class We{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_DISPERSION}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);return n===null||(t.dispersion=n.dispersion!==void 0?n.dispersion:0),Promise.resolve()}}class Xe{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&s.push(this.parser.assignTexture(t,"iridescenceMap",n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&s.push(this.parser.assignTexture(t,"iridescenceThicknessMap",n.iridescenceThicknessTexture)),Promise.all(s)}}class Ye{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_SHEEN}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];if(t.sheenColor=new u.Color(0,0,0),t.sheenRoughness=0,t.sheen=1,n.sheenColorFactor!==void 0){const i=n.sheenColorFactor;t.sheenColor.setRGB(i[0],i[1],i[2],u.LinearSRGBColorSpace)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&s.push(this.parser.assignTexture(t,"sheenColorMap",n.sheenColorTexture,u.SRGBColorSpace)),n.sheenRoughnessTexture!==void 0&&s.push(this.parser.assignTexture(t,"sheenRoughnessMap",n.sheenRoughnessTexture)),Promise.all(s)}}class Qe{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&s.push(this.parser.assignTexture(t,"transmissionMap",n.transmissionTexture)),Promise.all(s)}}class qe{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_VOLUME}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];t.thickness=n.thicknessFactor!==void 0?n.thicknessFactor:0,n.thicknessTexture!==void 0&&s.push(this.parser.assignTexture(t,"thicknessMap",n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;const i=n.attenuationColor||[1,1,1];return t.attenuationColor=new u.Color().setRGB(i[0],i[1],i[2],u.LinearSRGBColorSpace),Promise.all(s)}}class Ze{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_IOR}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);return n===null||(t.ior=n.ior!==void 0?n.ior:1.5,t.ior===0&&(t.ior=1e3)),Promise.resolve()}}class He{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_SPECULAR}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];t.specularIntensity=n.specularFactor!==void 0?n.specularFactor:1,n.specularTexture!==void 0&&s.push(this.parser.assignTexture(t,"specularIntensityMap",n.specularTexture));const i=n.specularColorFactor||[1,1,1];return t.specularColor=new u.Color().setRGB(i[0],i[1],i[2],u.LinearSRGBColorSpace),n.specularColorTexture!==void 0&&s.push(this.parser.assignTexture(t,"specularColorMap",n.specularColorTexture,u.SRGBColorSpace)),Promise.all(s)}}class $e{constructor(e){this.parser=e,this.name=b.EXT_MATERIALS_BUMP}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];return t.bumpScale=n.bumpFactor!==void 0?n.bumpFactor:1,n.bumpTexture!==void 0&&s.push(this.parser.assignTexture(t,"bumpMap",n.bumpTexture)),Promise.all(s)}}class Je{constructor(e){this.parser=e,this.name=b.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return L(this.parser,e,this.name)!==null?u.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=L(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&s.push(this.parser.assignTexture(t,"anisotropyMap",n.anisotropyTexture)),Promise.all(s)}}class et{constructor(e){this.parser=e,this.name=b.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,n=t.json,s=n.textures[e];if(!s.extensions||!s.extensions[this.name])return null;const i=s.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,i.source,o)}}class tt{constructor(e){this.parser=e,this.name=b.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,n=this.parser,s=n.json,i=s.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],a=s.images[o.source];let r=n.textureLoader;if(a.uri){const c=n.options.manager.getHandler(a.uri);c!==null&&(r=c)}return n.loadTextureImage(e,o.source,r)}}class nt{constructor(e){this.parser=e,this.name=b.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,n=this.parser,s=n.json,i=s.textures[e];if(!i.extensions||!i.extensions[t])return null;const o=i.extensions[t],a=s.images[o.source];let r=n.textureLoader;if(a.uri){const c=n.options.manager.getHandler(a.uri);c!==null&&(r=c)}return n.loadTextureImage(e,o.source,r)}}class pe{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){const t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){const s=n.extensions[this.name],i=this.parser.getDependency("buffer",s.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(a){const r=s.byteOffset||0,c=s.byteLength||0,h=s.count,d=s.byteStride,p=new Uint8Array(a,r,c);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(h,d,p,s.mode,s.filter).then(function(f){return f.buffer}):o.ready.then(function(){const f=new ArrayBuffer(h*d);return o.decodeGltfBuffer(new Uint8Array(f),h,d,p,s.mode,s.filter),f})})}else return null}}class st{constructor(e){this.name=b.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;const s=t.meshes[n.mesh];for(const c of s.primitives)if(c.mode!==C.TRIANGLES&&c.mode!==C.TRIANGLE_STRIP&&c.mode!==C.TRIANGLE_FAN&&c.mode!==void 0)return null;const o=n.extensions[this.name].attributes,a=[],r={};for(const c in o)a.push(this.parser.getDependency("accessor",o[c]).then(h=>(r[c]=h,r[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(c=>{const h=c.pop(),d=h.isGroup?h.children:[h],p=c[0].count,f=[];for(const m of d){const x=new u.Matrix4,y=new u.Vector3,g=new u.Quaternion,M=new u.Vector3(1,1,1),T=new u.InstancedMesh(m.geometry,m.material,p);for(let A=0;A<p;A++)r.TRANSLATION&&y.fromBufferAttribute(r.TRANSLATION,A),r.ROTATION&&g.fromBufferAttribute(r.ROTATION,A),r.SCALE&&M.fromBufferAttribute(r.SCALE,A),T.setMatrixAt(A,x.compose(y,g,M));for(const A in r)if(A==="_COLOR_0"){const P=r[A];T.instanceColor=new u.InstancedBufferAttribute(P.array,P.itemSize,P.normalized)}else A!=="TRANSLATION"&&A!=="ROTATION"&&A!=="SCALE"&&m.geometry.setAttribute(A,r[A]);u.Object3D.prototype.copy.call(T,m),this.parser.assignFinalMaterial(T),f.push(T)}return h.isGroup?(h.clear(),h.add(...f),h):f[0]}))}}const fe="glTF",B=12,me={JSON:1313821514,BIN:5130562};class it{constructor(e){this.name=b.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,B),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==fe)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-B,i=new DataView(e,B);let o=0;for(;o<s;){const a=i.getUint32(o,!0);o+=4;const r=i.getUint32(o,!0);if(o+=4,r===me.JSON){const c=new Uint8Array(e,B+o,a);this.content=n.decode(c)}else if(r===me.BIN){const c=B+o;this.body=e.slice(c,c+a)}o+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class ot{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=b.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const n=this.json,s=this.dracoLoader,i=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},r={},c={};for(const h in o){const d=Y[h]||h.toLowerCase();a[d]=o[h]}for(const h in e.attributes){const d=Y[h]||h.toLowerCase();if(o[h]!==void 0){const p=n.accessors[e.attributes[h]],f=U[p.componentType];c[d]=f.name,r[d]=p.normalized===!0}}return t.getDependency("bufferView",i).then(function(h){return new Promise(function(d,p){s.decodeDracoFile(h,function(f){for(const m in f.attributes){const x=f.attributes[m],y=r[m];y!==void 0&&(x.normalized=y)}d(f)},a,c,u.LinearSRGBColorSpace,p)})})}}class rt{constructor(){this.name=b.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class at{constructor(){this.name=b.KHR_MESH_QUANTIZATION}}class ge extends u.Interpolant{constructor(e,t,n,s){super(e,t,n,s)}copySampleValue_(e){const t=this.resultBuffer,n=this.sampleValues,s=this.valueSize,i=e*s*3+s;for(let o=0;o!==s;o++)t[o]=n[i+o];return t}interpolate_(e,t,n,s){const i=this.resultBuffer,o=this.sampleValues,a=this.valueSize,r=a*2,c=a*3,h=s-t,d=(n-t)/h,p=d*d,f=p*d,m=e*c,x=m-c,y=-2*f+3*p,g=f-p,M=1-y,T=g-p+d;for(let A=0;A!==a;A++){const P=o[x+A+a],v=o[x+A+r]*h,O=o[m+A+a],K=o[m+A]*h;i[A]=M*P+T*v+y*O+g*K}return i}}const lt=new u.Quaternion;class ct extends ge{interpolate_(e,t,n,s){const i=super.interpolate_(e,t,n,s);return lt.fromArray(i).normalize().toArray(i),i}}const C={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},U={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},_e={9728:u.NearestFilter,9729:u.LinearFilter,9984:u.NearestMipmapNearestFilter,9985:u.LinearMipmapNearestFilter,9986:u.NearestMipmapLinearFilter,9987:u.LinearMipmapLinearFilter},ye={33071:u.ClampToEdgeWrapping,33648:u.MirroredRepeatWrapping,10497:u.RepeatWrapping},X={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Y={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"},F={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},ht={CUBICSPLINE:void 0,LINEAR:u.InterpolateLinear,STEP:u.InterpolateDiscrete},Q={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function ut(l){return l.DefaultMaterial===void 0&&(l.DefaultMaterial=new u.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:u.FrontSide})),l.DefaultMaterial}function V(l,e,t){for(const n in t.extensions)l[n]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[n]=t.extensions[n])}function I(l,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(l.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function dt(l,e,t){let n=!1,s=!1,i=!1;for(let c=0,h=e.length;c<h;c++){const d=e[c];if(d.POSITION!==void 0&&(n=!0),d.NORMAL!==void 0&&(s=!0),d.COLOR_0!==void 0&&(i=!0),n&&s&&i)break}if(!n&&!s&&!i)return Promise.resolve(l);const o=[],a=[],r=[];for(let c=0,h=e.length;c<h;c++){const d=e[c];if(n){const p=d.POSITION!==void 0?t.getDependency("accessor",d.POSITION):l.attributes.position;o.push(p)}if(s){const p=d.NORMAL!==void 0?t.getDependency("accessor",d.NORMAL):l.attributes.normal;a.push(p)}if(i){const p=d.COLOR_0!==void 0?t.getDependency("accessor",d.COLOR_0):l.attributes.color;r.push(p)}}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(r)]).then(function(c){const h=c[0],d=c[1],p=c[2];return n&&(l.morphAttributes.position=h),s&&(l.morphAttributes.normal=d),i&&(l.morphAttributes.color=p),l.morphTargetsRelative=!0,l})}function pt(l,e){if(l.updateMorphTargets(),e.weights!==void 0)for(let t=0,n=e.weights.length;t<n;t++)l.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(l.morphTargetInfluences.length===t.length){l.morphTargetDictionary={};for(let n=0,s=t.length;n<s;n++)l.morphTargetDictionary[t[n]]=n}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function ft(l){let e;const t=l.extensions&&l.extensions[b.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+q(t.attributes):e=l.indices+":"+q(l.attributes)+":"+l.mode,l.targets!==void 0)for(let n=0,s=l.targets.length;n<s;n++)e+=":"+q(l.targets[n]);return e}function q(l){let e="";const t=Object.keys(l).sort();for(let n=0,s=t.length;n<s;n++)e+=t[n]+":"+l[t[n]]+";";return e}function Z(l){switch(l){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 mt(l){return l.search(/\.jpe?g($|\?)/i)>0||l.search(/^data\:image\/jpeg/)===0?"image/jpeg":l.search(/\.webp($|\?)/i)>0||l.search(/^data\:image\/webp/)===0?"image/webp":l.search(/\.ktx2($|\?)/i)>0||l.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const gt=new u.Matrix4;class _t{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new je,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 n=!1,s=-1,i=!1,o=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){const a=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(a)===!0;const r=a.match(/Version\/(\d+)/);s=n&&r?parseInt(r[1],10):-1,i=a.indexOf("Firefox")>-1,o=i?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||n&&s<17||i&&o<98?this.textureLoader=new u.TextureLoader(this.options.manager):this.textureLoader=new u.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new u.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const n=this,s=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(o){const a={scene:o[0][s.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:s.asset,parser:n,userData:{}};return V(i,a,s),I(a,s),Promise.all(n._invokeAll(function(r){return r.afterRoot&&r.afterRoot(a)})).then(function(){for(const r of a.scenes)r.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let s=0,i=t.length;s<i;s++){const o=t[s].joints;for(let a=0,r=o.length;a<r;a++)e[o[a]].isBone=!0}for(let s=0,i=e.length;s<i;s++){const o=e[s];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(n[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;const s=n.clone(),i=(o,a)=>{const r=this.associations.get(o);r!=null&&this.associations.set(a,r);for(const[c,h]of o.children.entries())i(h,a.children[c])};return i(n,s),s.name+="_instance_"+e.uses[t]++,s}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){const s=e(t[n]);if(s)return s}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const n=[];for(let s=0;s<t.length;s++){const i=e(t[s]);i&&n.push(i)}return n}getDependency(e,t){const n=e+":"+t;let s=this.cache.get(n);if(!s){switch(e){case"scene":s=this.loadScene(t);break;case"node":s=this._invokeOne(function(i){return i.loadNode&&i.loadNode(t)});break;case"mesh":s=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(t)});break;case"accessor":s=this.loadAccessor(t);break;case"bufferView":s=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(t)});break;case"buffer":s=this.loadBuffer(t);break;case"material":s=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(t)});break;case"texture":s=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(t)});break;case"skin":s=this.loadSkin(t);break;case"animation":s=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(t)});break;case"camera":s=this.loadCamera(t);break;default:if(s=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(e,t)}),!s)throw new Error("Unknown type: "+e);break}this.cache.add(n,s)}return s}getDependencies(e){let t=this.cache.get(e);if(!t){const n=this,s=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(s.map(function(i,o){return n.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[b.KHR_BINARY_GLTF].body);const s=this.options;return new Promise(function(i,o){n.load(u.LoaderUtils.resolveURL(t.uri,s.path),i,void 0,function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(n){const s=t.byteLength||0,i=t.byteOffset||0;return n.slice(i,i+s)})}loadAccessor(e){const t=this,n=this.json,s=this.json.accessors[e];if(s.bufferView===void 0&&s.sparse===void 0){const o=X[s.type],a=U[s.componentType],r=s.normalized===!0,c=new a(s.count*o);return Promise.resolve(new u.BufferAttribute(c,o,r))}const i=[];return s.bufferView!==void 0?i.push(this.getDependency("bufferView",s.bufferView)):i.push(null),s.sparse!==void 0&&(i.push(this.getDependency("bufferView",s.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",s.sparse.values.bufferView))),Promise.all(i).then(function(o){const a=o[0],r=X[s.type],c=U[s.componentType],h=c.BYTES_PER_ELEMENT,d=h*r,p=s.byteOffset||0,f=s.bufferView!==void 0?n.bufferViews[s.bufferView].byteStride:void 0,m=s.normalized===!0;let x,y;if(f&&f!==d){const g=Math.floor(p/f),M="InterleavedBuffer:"+s.bufferView+":"+s.componentType+":"+g+":"+s.count;let T=t.cache.get(M);T||(x=new c(a,g*f,s.count*f/h),T=new u.InterleavedBuffer(x,f/h),t.cache.add(M,T)),y=new u.InterleavedBufferAttribute(T,r,p%f/h,m)}else a===null?x=new c(s.count*r):x=new c(a,p,s.count*r),y=new u.BufferAttribute(x,r,m);if(s.sparse!==void 0){const g=X.SCALAR,M=U[s.sparse.indices.componentType],T=s.sparse.indices.byteOffset||0,A=s.sparse.values.byteOffset||0,P=new M(o[1],T,s.sparse.count*g),v=new c(o[2],A,s.sparse.count*r);a!==null&&(y=new u.BufferAttribute(y.array.slice(),y.itemSize,y.normalized)),y.normalized=!1;for(let O=0,K=P.length;O<K;O++){const E=P[O];if(y.setX(E,v[O*r]),r>=2&&y.setY(E,v[O*r+1]),r>=3&&y.setZ(E,v[O*r+2]),r>=4&&y.setW(E,v[O*r+3]),r>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}y.normalized=m}return y})}loadTexture(e){const t=this.json,n=this.options,i=t.textures[e].source,o=t.images[i];let a=this.textureLoader;if(o.uri){const r=n.manager.getHandler(o.uri);r!==null&&(a=r)}return this.loadTextureImage(e,i,a)}loadTextureImage(e,t,n){const s=this,i=this.json,o=i.textures[e],a=i.images[t],r=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[r])return this.textureCache[r];const c=this.loadImageSource(t,n).then(function(h){h.flipY=!1,h.name=o.name||a.name||"",h.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(h.name=a.uri);const p=(i.samplers||{})[o.sampler]||{};return h.magFilter=_e[p.magFilter]||u.LinearFilter,h.minFilter=_e[p.minFilter]||u.LinearMipmapLinearFilter,h.wrapS=ye[p.wrapS]||u.RepeatWrapping,h.wrapT=ye[p.wrapT]||u.RepeatWrapping,h.generateMipmaps=!h.isCompressedTexture&&h.minFilter!==u.NearestFilter&&h.minFilter!==u.LinearFilter,s.associations.set(h,{textures:e}),h}).catch(function(){return null});return this.textureCache[r]=c,c}loadImageSource(e,t){const n=this,s=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(d=>d.clone());const o=s.images[e],a=self.URL||self.webkitURL;let r=o.uri||"",c=!1;if(o.bufferView!==void 0)r=n.getDependency("bufferView",o.bufferView).then(function(d){c=!0;const p=new Blob([d],{type:o.mimeType});return r=a.createObjectURL(p),r});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const h=Promise.resolve(r).then(function(d){return new Promise(function(p,f){let m=p;t.isImageBitmapLoader===!0&&(m=function(x){const y=new u.Texture(x);y.needsUpdate=!0,p(y)}),t.load(u.LoaderUtils.resolveURL(d,i.path),m,void 0,f)})}).then(function(d){return c===!0&&a.revokeObjectURL(r),I(d,o),d.userData.mimeType=o.mimeType||mt(o.uri),d}).catch(function(d){throw console.error("THREE.GLTFLoader: Couldn't load texture",r),d});return this.sourceCache[e]=h,h}assignTexture(e,t,n,s){const i=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(o=o.clone(),o.channel=n.texCoord),i.extensions[b.KHR_TEXTURE_TRANSFORM]){const a=n.extensions!==void 0?n.extensions[b.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const r=i.associations.get(o);o=i.extensions[b.KHR_TEXTURE_TRANSFORM].extendTexture(o,a),i.associations.set(o,r)}}return s!==void 0&&(o.colorSpace=s),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let n=e.material;const s=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){const a="PointsMaterial:"+n.uuid;let r=this.cache.get(a);r||(r=new u.PointsMaterial,u.Material.prototype.copy.call(r,n),r.color.copy(n.color),r.map=n.map,r.sizeAttenuation=!1,this.cache.add(a,r)),n=r}else if(e.isLine){const a="LineBasicMaterial:"+n.uuid;let r=this.cache.get(a);r||(r=new u.LineBasicMaterial,u.Material.prototype.copy.call(r,n),r.color.copy(n.color),r.map=n.map,this.cache.add(a,r)),n=r}if(s||i||o){let a="ClonedMaterial:"+n.uuid+":";s&&(a+="derivative-tangents:"),i&&(a+="vertex-colors:"),o&&(a+="flat-shading:");let r=this.cache.get(a);r||(r=n.clone(),i&&(r.vertexColors=!0),o&&(r.flatShading=!0),s&&(r.normalScale&&(r.normalScale.y*=-1),r.clearcoatNormalScale&&(r.clearcoatNormalScale.y*=-1)),this.cache.add(a,r),this.associations.set(r,this.associations.get(n))),n=r}e.material=n}getMaterialType(){return u.MeshStandardMaterial}loadMaterial(e){const t=this,n=this.json,s=this.extensions,i=n.materials[e];let o;const a={},r=i.extensions||{},c=[];if(r[b.KHR_MATERIALS_UNLIT]){const d=s[b.KHR_MATERIALS_UNLIT];o=d.getMaterialType(),c.push(d.extendParams(a,i,t))}else{const d=i.pbrMetallicRoughness||{};if(a.color=new u.Color(1,1,1),a.opacity=1,Array.isArray(d.baseColorFactor)){const p=d.baseColorFactor;a.color.setRGB(p[0],p[1],p[2],u.LinearSRGBColorSpace),a.opacity=p[3]}d.baseColorTexture!==void 0&&c.push(t.assignTexture(a,"map",d.baseColorTexture,u.SRGBColorSpace)),a.metalness=d.metallicFactor!==void 0?d.metallicFactor:1,a.roughness=d.roughnessFactor!==void 0?d.roughnessFactor:1,d.metallicRoughnessTexture!==void 0&&(c.push(t.assignTexture(a,"metalnessMap",d.metallicRoughnessTexture)),c.push(t.assignTexture(a,"roughnessMap",d.metallicRoughnessTexture))),o=this._invokeOne(function(p){return p.getMaterialType&&p.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(p){return p.extendMaterialParams&&p.extendMaterialParams(e,a)})))}i.doubleSided===!0&&(a.side=u.DoubleSide);const h=i.alphaMode||Q.OPAQUE;if(h===Q.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,h===Q.MASK&&(a.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&o!==u.MeshBasicMaterial&&(c.push(t.assignTexture(a,"normalMap",i.normalTexture)),a.normalScale=new u.Vector2(1,1),i.normalTexture.scale!==void 0)){const d=i.normalTexture.scale;a.normalScale.set(d,d)}if(i.occlusionTexture!==void 0&&o!==u.MeshBasicMaterial&&(c.push(t.assignTexture(a,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&o!==u.MeshBasicMaterial){const d=i.emissiveFactor;a.emissive=new u.Color().setRGB(d[0],d[1],d[2],u.LinearSRGBColorSpace)}return i.emissiveTexture!==void 0&&o!==u.MeshBasicMaterial&&c.push(t.assignTexture(a,"emissiveMap",i.emissiveTexture,u.SRGBColorSpace)),Promise.all(c).then(function(){const d=new o(a);return i.name&&(d.name=i.name),I(d,i),t.associations.set(d,{materials:e}),i.extensions&&V(s,d,i),d})}createUniqueName(e){const t=u.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,n=this.extensions,s=this.primitiveCache;function i(a){return n[b.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(r){return xe(r,a,t)})}const o=[];for(let a=0,r=e.length;a<r;a++){const c=e[a],h=ft(c),d=s[h];if(d)o.push(d.promise);else{let p;c.extensions&&c.extensions[b.KHR_DRACO_MESH_COMPRESSION]?p=i(c):p=xe(new u.BufferGeometry,c,t),s[h]={primitive:c,promise:p},o.push(p)}}return Promise.all(o)}loadMesh(e){const t=this,n=this.json,s=this.extensions,i=n.meshes[e],o=i.primitives,a=[];for(let r=0,c=o.length;r<c;r++){const h=o[r].material===void 0?ut(this.cache):this.getDependency("material",o[r].material);a.push(h)}return a.push(t.loadGeometries(o)),Promise.all(a).then(function(r){const c=r.slice(0,r.length-1),h=r[r.length-1],d=[];for(let f=0,m=h.length;f<m;f++){const x=h[f],y=o[f];let g;const M=c[f];if(y.mode===C.TRIANGLES||y.mode===C.TRIANGLE_STRIP||y.mode===C.TRIANGLE_FAN||y.mode===void 0)g=i.isSkinnedMesh===!0?new u.SkinnedMesh(x,M):new u.Mesh(x,M),g.isSkinnedMesh===!0&&g.normalizeSkinWeights(),y.mode===C.TRIANGLE_STRIP?g.geometry=ue(g.geometry,u.TriangleStripDrawMode):y.mode===C.TRIANGLE_FAN&&(g.geometry=ue(g.geometry,u.TriangleFanDrawMode));else if(y.mode===C.LINES)g=new u.LineSegments(x,M);else if(y.mode===C.LINE_STRIP)g=new u.Line(x,M);else if(y.mode===C.LINE_LOOP)g=new u.LineLoop(x,M);else if(y.mode===C.POINTS)g=new u.Points(x,M);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+y.mode);Object.keys(g.geometry.morphAttributes).length>0&&pt(g,i),g.name=t.createUniqueName(i.name||"mesh_"+e),I(g,i),y.extensions&&V(s,g,y),t.assignFinalMaterial(g),d.push(g)}for(let f=0,m=d.length;f<m;f++)t.associations.set(d[f],{meshes:e,primitives:f});if(d.length===1)return i.extensions&&V(s,d[0],i),d[0];const p=new u.Group;i.extensions&&V(s,p,i),t.associations.set(p,{meshes:e});for(let f=0,m=d.length;f<m;f++)p.add(d[f]);return p})}loadCamera(e){let t;const n=this.json.cameras[e],s=n[n.type];if(!s){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return n.type==="perspective"?t=new u.PerspectiveCamera(u.MathUtils.radToDeg(s.yfov),s.aspectRatio||1,s.znear||1,s.zfar||2e6):n.type==="orthographic"&&(t=new u.OrthographicCamera(-s.xmag,s.xmag,s.ymag,-s.ymag,s.znear,s.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),I(t,n),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],n=[];for(let s=0,i=t.joints.length;s<i;s++)n.push(this._loadNodeShallow(t.joints[s]));return t.inverseBindMatrices!==void 0?n.push(this.getDependency("accessor",t.inverseBindMatrices)):n.push(null),Promise.all(n).then(function(s){const i=s.pop(),o=s,a=[],r=[];for(let c=0,h=o.length;c<h;c++){const d=o[c];if(d){a.push(d);const p=new u.Matrix4;i!==null&&p.fromArray(i.array,c*16),r.push(p)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[c])}return new u.Skeleton(a,r)})}loadAnimation(e){const t=this.json,n=this,s=t.animations[e],i=s.name?s.name:"animation_"+e,o=[],a=[],r=[],c=[],h=[];for(let d=0,p=s.channels.length;d<p;d++){const f=s.channels[d],m=s.samplers[f.sampler],x=f.target,y=x.node,g=s.parameters!==void 0?s.parameters[m.input]:m.input,M=s.parameters!==void 0?s.parameters[m.output]:m.output;x.node!==void 0&&(o.push(this.getDependency("node",y)),a.push(this.getDependency("accessor",g)),r.push(this.getDependency("accessor",M)),c.push(m),h.push(x))}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(r),Promise.all(c),Promise.all(h)]).then(function(d){const p=d[0],f=d[1],m=d[2],x=d[3],y=d[4],g=[];for(let T=0,A=p.length;T<A;T++){const P=p[T],v=f[T],O=m[T],K=x[T],E=y[T];if(P===void 0)continue;P.updateMatrix&&P.updateMatrix();const oe=n._createAnimationTracks(P,v,O,K,E);if(oe)for(let re=0;re<oe.length;re++)g.push(oe[re])}const M=new u.AnimationClip(i,void 0,g);return I(M,s),M})}createNodeMesh(e){const t=this.json,n=this,s=t.nodes[e];return s.mesh===void 0?null:n.getDependency("mesh",s.mesh).then(function(i){const o=n._getNodeRef(n.meshCache,s.mesh,i);return s.weights!==void 0&&o.traverse(function(a){if(a.isMesh)for(let r=0,c=s.weights.length;r<c;r++)a.morphTargetInfluences[r]=s.weights[r]}),o})}loadNode(e){const t=this.json,n=this,s=t.nodes[e],i=n._loadNodeShallow(e),o=[],a=s.children||[];for(let c=0,h=a.length;c<h;c++)o.push(n.getDependency("node",a[c]));const r=s.skin===void 0?Promise.resolve(null):n.getDependency("skin",s.skin);return Promise.all([i,Promise.all(o),r]).then(function(c){const h=c[0],d=c[1],p=c[2];p!==null&&h.traverse(function(f){f.isSkinnedMesh&&f.bind(p,gt)});for(let f=0,m=d.length;f<m;f++)h.add(d[f]);if(h.userData.pivot!==void 0&&d.length>0){const f=h.userData.pivot,m=d[0];h.pivot=new u.Vector3().fromArray(f),h.position.x-=f[0],h.position.y-=f[1],h.position.z-=f[2],m.position.set(0,0,0),delete h.userData.pivot}return h})}_loadNodeShallow(e){const t=this.json,n=this.extensions,s=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const i=t.nodes[e],o=i.name?s.createUniqueName(i.name):"",a=[],r=s._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(e)});return r&&a.push(r),i.camera!==void 0&&a.push(s.getDependency("camera",i.camera).then(function(c){return s._getNodeRef(s.cameraCache,i.camera,c)})),s._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(e)}).forEach(function(c){a.push(c)}),this.nodeCache[e]=Promise.all(a).then(function(c){let h;if(i.isBone===!0?h=new u.Bone:c.length>1?h=new u.Group:c.length===1?h=c[0]:h=new u.Object3D,h!==c[0])for(let d=0,p=c.length;d<p;d++)h.add(c[d]);if(i.name&&(h.userData.name=i.name,h.name=o),I(h,i),i.extensions&&V(n,h,i),i.matrix!==void 0){const d=new u.Matrix4;d.fromArray(i.matrix),h.applyMatrix4(d)}else i.translation!==void 0&&h.position.fromArray(i.translation),i.rotation!==void 0&&h.quaternion.fromArray(i.rotation),i.scale!==void 0&&h.scale.fromArray(i.scale);if(!s.associations.has(h))s.associations.set(h,{});else if(i.mesh!==void 0&&s.meshCache.refs[i.mesh]>1){const d=s.associations.get(h);s.associations.set(h,{...d})}return s.associations.get(h).nodes=e,h}),this.nodeCache[e]}loadScene(e){const t=this.extensions,n=this.json.scenes[e],s=this,i=new u.Group;n.name&&(i.name=s.createUniqueName(n.name)),I(i,n),n.extensions&&V(t,i,n);const o=n.nodes||[],a=[];for(let r=0,c=o.length;r<c;r++)a.push(s.getDependency("node",o[r]));return Promise.all(a).then(function(r){for(let h=0,d=r.length;h<d;h++){const p=r[h];p.parent!==null?i.add(Ee(p)):i.add(p)}const c=h=>{const d=new Map;for(const[p,f]of s.associations)(p instanceof u.Material||p instanceof u.Texture)&&d.set(p,f);return h.traverse(p=>{const f=s.associations.get(p);f!=null&&d.set(p,f)}),d};return s.associations=c(i),i})}_createAnimationTracks(e,t,n,s,i){const o=[],a=e.name?e.name:e.uuid,r=[];function c(f){f.morphTargetInfluences&&r.push(f.name?f.name:f.uuid)}F[i.path]===F.weights?(c(e),e.isGroup&&e.children.forEach(c)):r.push(a);let h;switch(F[i.path]){case F.weights:h=u.NumberKeyframeTrack;break;case F.rotation:h=u.QuaternionKeyframeTrack;break;case F.translation:case F.scale:h=u.VectorKeyframeTrack;break;default:n.itemSize===1?h=u.NumberKeyframeTrack:h=u.VectorKeyframeTrack;break}const d=s.interpolation!==void 0?ht[s.interpolation]:u.InterpolateLinear,p=this._getArrayFromAccessor(n);for(let f=0,m=r.length;f<m;f++){const x=new h(r[f]+"."+F[i.path],t.array,p,d);s.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(x),o.push(x)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const n=Z(t.constructor),s=new Float32Array(t.length);for(let i=0,o=t.length;i<o;i++)s[i]=t[i]*n;t=s}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(n){const s=this instanceof u.QuaternionKeyframeTrack?ct:ge;return new s(this.times,this.values,this.getValueSize()/3,n)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function yt(l,e,t){const n=e.attributes,s=new u.Box3;if(n.POSITION!==void 0){const a=t.json.accessors[n.POSITION],r=a.min,c=a.max;if(r!==void 0&&c!==void 0){if(s.set(new u.Vector3(r[0],r[1],r[2]),new u.Vector3(c[0],c[1],c[2])),a.normalized){const h=Z(U[a.componentType]);s.min.multiplyScalar(h),s.max.multiplyScalar(h)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=e.targets;if(i!==void 0){const a=new u.Vector3,r=new u.Vector3;for(let c=0,h=i.length;c<h;c++){const d=i[c];if(d.POSITION!==void 0){const p=t.json.accessors[d.POSITION],f=p.min,m=p.max;if(f!==void 0&&m!==void 0){if(r.setX(Math.max(Math.abs(f[0]),Math.abs(m[0]))),r.setY(Math.max(Math.abs(f[1]),Math.abs(m[1]))),r.setZ(Math.max(Math.abs(f[2]),Math.abs(m[2]))),p.normalized){const x=Z(U[p.componentType]);r.multiplyScalar(x)}a.max(r)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}s.expan