Files
moon-gaming/games/New folder/pixi-renderers/ThreeAddons.js
T
2023-11-23 20:37:33 +00:00

3 lines
53 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("three")):"function"==typeof define&&define.amd?define(["exports","three"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).THREE_ADDONS={},e.THREE)}(this,(function(e,t){"use strict";function s(e,s){if(s===t.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(s===t.TriangleFanDrawMode||s===t.TriangleStripDrawMode){let r=e.getIndex();if(null===r){const t=[],s=e.getAttribute("position");if(void 0===s)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<s.count;e++)t.push(e);e.setIndex(t),r=e.getIndex()}const n=r.count-2,o=[];if(s===t.TriangleFanDrawMode)for(let e=1;e<=n;e++)o.push(r.getX(0)),o.push(r.getX(e)),o.push(r.getX(e+1));else for(let e=0;e<n;e++)e%2==0?(o.push(r.getX(e)),o.push(r.getX(e+1)),o.push(r.getX(e+2))):(o.push(r.getX(e+2)),o.push(r.getX(e+1)),o.push(r.getX(e)));o.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=e.clone();return i.setIndex(o),i.clearGroups(),i}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",s),e}class r extends t.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new l(e)})),this.register((function(e){return new A(e)})),this.register((function(e){return new g(e)})),this.register((function(e){return new T(e)})),this.register((function(e){return new h(e)})),this.register((function(e){return new d(e)})),this.register((function(e){return new p(e)})),this.register((function(e){return new m(e)})),this.register((function(e){return new c(e)})),this.register((function(e){return new f(e)})),this.register((function(e){return new u(e)})),this.register((function(e){return new i(e)})),this.register((function(e){return new x(e)})),this.register((function(e){return new R(e)}))}load(e,s,r,n){const o=this;let i;i=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:t.LoaderUtils.extractUrlBase(e),this.manager.itemStart(e);const a=function(t){n?n(t):console.error(t),o.manager.itemError(e),o.manager.itemEnd(e)},c=new t.FileLoader(this.manager);c.setPath(this.path),c.setResponseType("arraybuffer"),c.setRequestHeader(this.requestHeader),c.setWithCredentials(this.withCredentials),c.load(e,(function(t){try{o.parse(t,i,(function(t){s(t),o.manager.itemEnd(e)}),a)}catch(e){a(e)}}),r,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,s,r){let n;const i={},c={},l=new TextDecoder;if("string"==typeof e)n=JSON.parse(e);else if(e instanceof ArrayBuffer){if(l.decode(new Uint8Array(e,0,4))===y){try{i[o.KHR_BINARY_GLTF]=new v(e)}catch(e){return void(r&&r(e))}n=JSON.parse(i[o.KHR_BINARY_GLTF].content)}else n=JSON.parse(l.decode(e))}else n=e;if(void 0===n.asset||n.asset.version[0]<2)return void(r&&r(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const u=new Q(n,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});u.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](u);c[t.name]=t,i[t.name]=!0}if(n.extensionsUsed)for(let e=0;e<n.extensionsUsed.length;++e){const t=n.extensionsUsed[e],s=n.extensionsRequired||[];switch(t){case o.KHR_MATERIALS_UNLIT:i[t]=new a;break;case o.KHR_DRACO_MESH_COMPRESSION:i[t]=new E(n,this.dracoLoader);break;case o.KHR_TEXTURE_TRANSFORM:i[t]=new M;break;case o.KHR_MESH_QUANTIZATION:i[t]=new b;break;default:s.indexOf(t)>=0&&void 0===c[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}u.setExtensions(i),u.setPlugins(c),u.parse(s,r)}parseAsync(e,t){const s=this;return new Promise((function(r,n){s.parse(e,t,r,n)}))}}function n(){let e={};return{get:function(t){return e[t]},add:function(t,s){e[t]=s},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const o={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_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_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 i{constructor(e){this.parser=e,this.name=o.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,r=t.length;s<r;s++){const r=t[s];r.extensions&&r.extensions[this.name]&&void 0!==r.extensions[this.name].light&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){const s=this.parser,r="light:"+e;let n=s.cache.get(r);if(n)return n;const o=s.json,i=((o.extensions&&o.extensions[this.name]||{}).lights||[])[e];let a;const c=new t.Color(16777215);void 0!==i.color&&c.fromArray(i.color);const l=void 0!==i.range?i.range:0;switch(i.type){case"directional":a=new t.DirectionalLight(c),a.target.position.set(0,0,-1),a.add(a.target);break;case"point":a=new t.PointLight(c),a.distance=l;break;case"spot":a=new t.SpotLight(c),a.distance=l,i.spot=i.spot||{},i.spot.innerConeAngle=void 0!==i.spot.innerConeAngle?i.spot.innerConeAngle:0,i.spot.outerConeAngle=void 0!==i.spot.outerConeAngle?i.spot.outerConeAngle:Math.PI/4,a.angle=i.spot.outerConeAngle,a.penumbra=1-i.spot.innerConeAngle/i.spot.outerConeAngle,a.target.position.set(0,0,-1),a.add(a.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+i.type)}return a.position.set(0,0,0),a.decay=2,K(a,i),void 0!==i.intensity&&(a.intensity=i.intensity),a.name=s.createUniqueName(i.name||"light_"+e),n=Promise.resolve(a),s.cache.add(r,n),n}getDependency(e,t){if("light"===e)return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,r=s.json.nodes[e],n=(r.extensions&&r.extensions[this.name]||{}).light;return void 0===n?null:this._loadLight(n).then((function(e){return s._getNodeRef(t.cache,n,e)}))}}class a{constructor(){this.name=o.KHR_MATERIALS_UNLIT}getMaterialType(){return t.MeshBasicMaterial}extendParams(e,s,r){const n=[];e.color=new t.Color(1,1,1),e.opacity=1;const o=s.pbrMetallicRoughness;if(o){if(Array.isArray(o.baseColorFactor)){const t=o.baseColorFactor;e.color.fromArray(t),e.opacity=t[3]}void 0!==o.baseColorTexture&&n.push(r.assignTexture(e,"map",o.baseColorTexture,t.SRGBColorSpace))}return Promise.all(n)}}class c{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=s.extensions[this.name].emissiveStrength;return void 0!==r&&(t.emissiveIntensity=r),Promise.resolve()}}class l{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const r=this.parser,n=r.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const o=[],i=n.extensions[this.name];if(void 0!==i.clearcoatFactor&&(s.clearcoat=i.clearcoatFactor),void 0!==i.clearcoatTexture&&o.push(r.assignTexture(s,"clearcoatMap",i.clearcoatTexture)),void 0!==i.clearcoatRoughnessFactor&&(s.clearcoatRoughness=i.clearcoatRoughnessFactor),void 0!==i.clearcoatRoughnessTexture&&o.push(r.assignTexture(s,"clearcoatRoughnessMap",i.clearcoatRoughnessTexture)),void 0!==i.clearcoatNormalTexture&&(o.push(r.assignTexture(s,"clearcoatNormalMap",i.clearcoatNormalTexture)),void 0!==i.clearcoatNormalTexture.scale)){const e=i.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new t.Vector2(e,e)}return Promise.all(o)}}class u{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,r=s.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const n=[],o=r.extensions[this.name];return void 0!==o.iridescenceFactor&&(t.iridescence=o.iridescenceFactor),void 0!==o.iridescenceTexture&&n.push(s.assignTexture(t,"iridescenceMap",o.iridescenceTexture)),void 0!==o.iridescenceIor&&(t.iridescenceIOR=o.iridescenceIor),void 0===t.iridescenceThicknessRange&&(t.iridescenceThicknessRange=[100,400]),void 0!==o.iridescenceThicknessMinimum&&(t.iridescenceThicknessRange[0]=o.iridescenceThicknessMinimum),void 0!==o.iridescenceThicknessMaximum&&(t.iridescenceThicknessRange[1]=o.iridescenceThicknessMaximum),void 0!==o.iridescenceThicknessTexture&&n.push(s.assignTexture(t,"iridescenceThicknessMap",o.iridescenceThicknessTexture)),Promise.all(n)}}class h{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_SHEEN}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const r=this.parser,n=r.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const o=[];s.sheenColor=new t.Color(0,0,0),s.sheenRoughness=0,s.sheen=1;const i=n.extensions[this.name];return void 0!==i.sheenColorFactor&&s.sheenColor.fromArray(i.sheenColorFactor),void 0!==i.sheenRoughnessFactor&&(s.sheenRoughness=i.sheenRoughnessFactor),void 0!==i.sheenColorTexture&&o.push(r.assignTexture(s,"sheenColorMap",i.sheenColorTexture,t.SRGBColorSpace)),void 0!==i.sheenRoughnessTexture&&o.push(r.assignTexture(s,"sheenRoughnessMap",i.sheenRoughnessTexture)),Promise.all(o)}}class d{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,r=s.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const n=[],o=r.extensions[this.name];return void 0!==o.transmissionFactor&&(t.transmission=o.transmissionFactor),void 0!==o.transmissionTexture&&n.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(n)}}class p{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_VOLUME}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const r=this.parser,n=r.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const o=[],i=n.extensions[this.name];s.thickness=void 0!==i.thicknessFactor?i.thicknessFactor:0,void 0!==i.thicknessTexture&&o.push(r.assignTexture(s,"thicknessMap",i.thicknessTexture)),s.attenuationDistance=i.attenuationDistance||1/0;const a=i.attenuationColor||[1,1,1];return s.attenuationColor=new t.Color(a[0],a[1],a[2]),Promise.all(o)}}class m{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_IOR}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=s.extensions[this.name];return t.ior=void 0!==r.ior?r.ior:1.5,Promise.resolve()}}class f{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_SPECULAR}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const r=this.parser,n=r.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const o=[],i=n.extensions[this.name];s.specularIntensity=void 0!==i.specularFactor?i.specularFactor:1,void 0!==i.specularTexture&&o.push(r.assignTexture(s,"specularIntensityMap",i.specularTexture));const a=i.specularColorFactor||[1,1,1];return s.specularColor=new t.Color(a[0],a[1],a[2]),void 0!==i.specularColorTexture&&o.push(r.assignTexture(s,"specularColorMap",i.specularColorTexture,t.SRGBColorSpace)),Promise.all(o)}}class A{constructor(e){this.parser=e,this.name=o.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,r=s.textures[e];if(!r.extensions||!r.extensions[this.name])return null;const n=r.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,n.source,o)}}class g{constructor(e){this.parser=e,this.name=o.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,r=s.json,n=r.textures[e];if(!n.extensions||!n.extensions[t])return null;const o=n.extensions[t],i=r.images[o.source];let a=s.textureLoader;if(i.uri){const e=s.options.manager.getHandler(i.uri);null!==e&&(a=e)}return this.detectSupport().then((function(n){if(n)return s.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return s.loadTexture(e)}))}detectSupport(){return this.isSupported||(this.isSupported=new Promise((function(e){const t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}}))),this.isSupported}}class T{constructor(e){this.parser=e,this.name=o.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,r=s.json,n=r.textures[e];if(!n.extensions||!n.extensions[t])return null;const o=n.extensions[t],i=r.images[o.source];let a=s.textureLoader;if(i.uri){const e=s.options.manager.getHandler(i.uri);null!==e&&(a=e)}return this.detectSupport().then((function(n){if(n)return s.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return s.loadTexture(e)}))}detectSupport(){return this.isSupported||(this.isSupported=new Promise((function(e){const t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(1===t.height)}}))),this.isSupported}}class x{constructor(e){this.name=o.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const e=s.extensions[this.name],r=this.parser.getDependency("buffer",e.buffer),n=this.parser.options.meshoptDecoder;if(!n||!n.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 r.then((function(t){const s=e.byteOffset||0,r=e.byteLength||0,o=e.count,i=e.byteStride,a=new Uint8Array(t,s,r);return n.decodeGltfBufferAsync?n.decodeGltfBufferAsync(o,i,a,e.mode,e.filter).then((function(e){return e.buffer})):n.ready.then((function(){const t=new ArrayBuffer(o*i);return n.decodeGltfBuffer(new Uint8Array(t),o,i,a,e.mode,e.filter),t}))}))}return null}}class R{constructor(e){this.name=o.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const s=this.parser.json,r=s.nodes[e];if(!r.extensions||!r.extensions[this.name]||void 0===r.mesh)return null;const n=s.meshes[r.mesh];for(const e of n.primitives)if(e.mode!==C.TRIANGLES&&e.mode!==C.TRIANGLE_STRIP&&e.mode!==C.TRIANGLE_FAN&&void 0!==e.mode)return null;const o=r.extensions[this.name].attributes,i=[],a={};for(const e in o)i.push(this.parser.getDependency("accessor",o[e]).then((t=>(a[e]=t,a[e]))));return i.length<1?null:(i.push(this.parser.createNodeMesh(e)),Promise.all(i).then((e=>{const s=e.pop(),r=s.isGroup?s.children:[s],n=e[0].count,o=[];for(const e of r){const s=new t.Matrix4,r=new t.Vector3,i=new t.Quaternion,c=new t.Vector3(1,1,1),l=new t.InstancedMesh(e.geometry,e.material,n);for(let e=0;e<n;e++)a.TRANSLATION&&r.fromBufferAttribute(a.TRANSLATION,e),a.ROTATION&&i.fromBufferAttribute(a.ROTATION,e),a.SCALE&&c.fromBufferAttribute(a.SCALE,e),l.setMatrixAt(e,s.compose(r,i,c));for(const t in a)"TRANSLATION"!==t&&"ROTATION"!==t&&"SCALE"!==t&&e.geometry.setAttribute(t,a[t]);t.Object3D.prototype.copy.call(l,e),this.parser.assignFinalMaterial(l),o.push(l)}return s.isGroup?(s.clear(),s.add(...o),s):o[0]})))}}const y="glTF",w=1313821514,_=5130562;class v{constructor(e){this.name=o.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,12),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==y)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-12,n=new DataView(e,12);let i=0;for(;i<r;){const t=n.getUint32(i,!0);i+=4;const r=n.getUint32(i,!0);if(i+=4,r===w){const r=new Uint8Array(e,12+i,t);this.content=s.decode(r)}else if(r===_){const s=12+i;this.body=e.slice(s,s+t)}i+=t}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class E{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=o.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,r=this.dracoLoader,n=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,i={},a={},c={};for(const e in o){const t=D[e]||e.toLowerCase();i[t]=o[e]}for(const t in e.attributes){const r=D[t]||t.toLowerCase();if(void 0!==o[t]){const n=s.accessors[e.attributes[t]],o=P[n.componentType];c[r]=o.name,a[r]=!0===n.normalized}}return t.getDependency("bufferView",n).then((function(e){return new Promise((function(t){r.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],r=a[t];void 0!==r&&(s.normalized=r)}t(e)}),i,c)}))}))}}class M{constructor(){this.name=o.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&t.texCoord!==e.channel||void 0!==t.offset||void 0!==t.rotation||void 0!==t.scale?(e=e.clone(),void 0!==t.texCoord&&(e.channel=t.texCoord),void 0!==t.offset&&e.offset.fromArray(t.offset),void 0!==t.rotation&&(e.rotation=t.rotation),void 0!==t.scale&&e.repeat.fromArray(t.scale),e.needsUpdate=!0,e):e}}class b{constructor(){this.name=o.KHR_MESH_QUANTIZATION}}class L extends t.Interpolant{constructor(e,t,s,r){super(e,t,s,r)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,r=this.valueSize,n=e*r*3+r;for(let e=0;e!==r;e++)t[e]=s[n+e];return t}interpolate_(e,t,s,r){const n=this.resultBuffer,o=this.sampleValues,i=this.valueSize,a=2*i,c=3*i,l=r-t,u=(s-t)/l,h=u*u,d=h*u,p=e*c,m=p-c,f=-2*d+3*h,A=d-h,g=1-f,T=A-h+u;for(let e=0;e!==i;e++){const t=o[m+e+i],s=o[m+e+a]*l,r=o[p+e+i],c=o[p+e]*l;n[e]=g*t+T*s+f*r+A*c}return n}}const S=new t.Quaternion;class I extends L{interpolate_(e,t,s,r){const n=super.interpolate_(e,t,s,r);return S.fromArray(n).normalize().toArray(n),n}}const C={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},P={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},N={9728:t.NearestFilter,9729:t.LinearFilter,9984:t.NearestMipmapNearestFilter,9985:t.LinearMipmapNearestFilter,9986:t.NearestMipmapLinearFilter,9987:t.LinearMipmapLinearFilter},O={33071:t.ClampToEdgeWrapping,33648:t.MirroredRepeatWrapping,10497:t.RepeatWrapping},k={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},D={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"},H={CUBICSPLINE:void 0,LINEAR:t.InterpolateLinear,STEP:t.InterpolateDiscrete},U="OPAQUE",B="MASK",G="BLEND";function j(e,t,s){for(const r in s.extensions)void 0===e[r]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=s.extensions[r])}function K(e,t){void 0!==t.extras&&("object"==typeof t.extras?Object.assign(e.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function V(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let s=0,r=t.weights.length;s<r;s++)e.morphTargetInfluences[s]=t.weights[s];if(t.extras&&Array.isArray(t.extras.targetNames)){const s=t.extras.targetNames;if(e.morphTargetInfluences.length===s.length){e.morphTargetDictionary={};for(let t=0,r=s.length;t<r;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function X(e){const t=e.extensions&&e.extensions[o.KHR_DRACO_MESH_COMPRESSION];let s;return s=t?"draco:"+t.bufferView+":"+t.indices+":"+W(t.attributes):e.indices+":"+W(e.attributes)+":"+e.mode,s}function W(e){let t="";const s=Object.keys(e).sort();for(let r=0,n=s.length;r<n;r++)t+=s[r]+":"+e[s[r]]+";";return t}function q(e){switch(e){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.")}}const z=new t.Matrix4;class Q{constructor(e={},s={}){this.json=e,this.extensions={},this.plugins={},this.options=s,this.cache=new n,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 r=!1,o=!1,i=-1;"undefined"!=typeof navigator&&(r=!0===/^((?!chrome|android).)*safari/i.test(navigator.userAgent),o=navigator.userAgent.indexOf("Firefox")>-1,i=o?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1),"undefined"==typeof createImageBitmap||r||o&&i<98?this.textureLoader=new t.TextureLoader(this.options.manager):this.textureLoader=new t.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new t.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,r=this.json,n=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll((function(e){return e._markDefs&&e._markDefs()})),Promise.all(this._invokeAll((function(e){return e.beforeRoot&&e.beforeRoot()}))).then((function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])})).then((function(t){const o={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:s,userData:{}};j(n,o,r),K(o,r),Promise.all(s._invokeAll((function(e){return e.afterRoot&&e.afterRoot(o)}))).then((function(){e(o)}))})).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let s=0,r=t.length;s<r;s++){const r=t[s].joints;for(let t=0,s=r.length;t<s;t++)e[r[t]].isBone=!0}for(let t=0,r=e.length;t<r;t++){const r=e[t];void 0!==r.mesh&&(this._addNodeRef(this.meshCache,r.mesh),void 0!==r.skin&&(s[r.mesh].isSkinnedMesh=!0)),void 0!==r.camera&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){void 0!==t&&(void 0===e.refs[t]&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const r=s.clone(),n=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,r]of e.children.entries())n(r,t.children[s])};return n(s,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const r=e(t[s]);if(r)return r}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let r=0;r<t.length;r++){const n=e(t[r]);n&&s.push(n)}return s}getDependency(e,t){const s=e+":"+t;let r=this.cache.get(s);if(!r){switch(e){case"scene":r=this.loadScene(t);break;case"node":r=this._invokeOne((function(e){return e.loadNode&&e.loadNode(t)}));break;case"mesh":r=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":r=this.loadAccessor(t);break;case"bufferView":r=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":r=this.loadBuffer(t);break;case"material":r=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":r=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":r=this.loadSkin(t);break;case"animation":r=this._invokeOne((function(e){return e.loadAnimation&&e.loadAnimation(t)}));break;case"camera":r=this.loadCamera(t);break;default:if(r=this._invokeOne((function(s){return s!=this&&s.getDependency&&s.getDependency(e,t)})),!r)throw new Error("Unknown type: "+e)}this.cache.add(s,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,r=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(r.map((function(t,r){return s.getDependency(e,r)}))),this.cache.add(e,t)}return t}loadBuffer(e){const s=this.json.buffers[e],r=this.fileLoader;if(s.type&&"arraybuffer"!==s.type)throw new Error("THREE.GLTFLoader: "+s.type+" buffer type is not supported.");if(void 0===s.uri&&0===e)return Promise.resolve(this.extensions[o.KHR_BINARY_GLTF].body);const n=this.options;return new Promise((function(e,o){r.load(t.LoaderUtils.resolveURL(s.uri,n.path),e,void 0,(function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+s.uri+'".'))}))}))}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then((function(e){const s=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+s)}))}loadAccessor(e){const s=this,r=this.json,n=this.json.accessors[e];if(void 0===n.bufferView&&void 0===n.sparse){const e=k[n.type],s=P[n.componentType],r=!0===n.normalized,o=new s(n.count*e);return Promise.resolve(new t.BufferAttribute(o,e,r))}const o=[];return void 0!==n.bufferView?o.push(this.getDependency("bufferView",n.bufferView)):o.push(null),void 0!==n.sparse&&(o.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),o.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(o).then((function(e){const o=e[0],i=k[n.type],a=P[n.componentType],c=a.BYTES_PER_ELEMENT,l=c*i,u=n.byteOffset||0,h=void 0!==n.bufferView?r.bufferViews[n.bufferView].byteStride:void 0,d=!0===n.normalized;let p,m;if(h&&h!==l){const e=Math.floor(u/h),r="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+e+":"+n.count;let l=s.cache.get(r);l||(p=new a(o,e*h,n.count*h/c),l=new t.InterleavedBuffer(p,h/c),s.cache.add(r,l)),m=new t.InterleavedBufferAttribute(l,i,u%h/c,d)}else p=null===o?new a(n.count*i):new a(o,u,n.count*i),m=new t.BufferAttribute(p,i,d);if(void 0!==n.sparse){const s=k.SCALAR,r=P[n.sparse.indices.componentType],c=n.sparse.indices.byteOffset||0,l=n.sparse.values.byteOffset||0,u=new r(e[1],c,n.sparse.count*s),h=new a(e[2],l,n.sparse.count*i);null!==o&&(m=new t.BufferAttribute(m.array.slice(),m.itemSize,m.normalized));for(let e=0,t=u.length;e<t;e++){const t=u[e];if(m.setX(t,h[e*i]),i>=2&&m.setY(t,h[e*i+1]),i>=3&&m.setZ(t,h[e*i+2]),i>=4&&m.setW(t,h[e*i+3]),i>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return m}))}loadTexture(e){const t=this.json,s=this.options,r=t.textures[e].source,n=t.images[r];let o=this.textureLoader;if(n.uri){const e=s.manager.getHandler(n.uri);null!==e&&(o=e)}return this.loadTextureImage(e,r,o)}loadTextureImage(e,s,r){const n=this,o=this.json,i=o.textures[e],a=o.images[s],c=(a.uri||a.bufferView)+":"+i.sampler;if(this.textureCache[c])return this.textureCache[c];const l=this.loadImageSource(s,r).then((function(s){s.flipY=!1,s.name=i.name||a.name||"",""===s.name&&"string"==typeof a.uri&&!1===a.uri.startsWith("data:image/")&&(s.name=a.uri);const r=(o.samplers||{})[i.sampler]||{};return s.magFilter=N[r.magFilter]||t.LinearFilter,s.minFilter=N[r.minFilter]||t.LinearMipmapLinearFilter,s.wrapS=O[r.wrapS]||t.RepeatWrapping,s.wrapT=O[r.wrapT]||t.RepeatWrapping,n.associations.set(s,{textures:e}),s})).catch((function(){return null}));return this.textureCache[c]=l,l}loadImageSource(e,s){const r=this,n=this.json,o=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then((e=>e.clone()));const i=n.images[e],a=self.URL||self.webkitURL;let c=i.uri||"",l=!1;if(void 0!==i.bufferView)c=r.getDependency("bufferView",i.bufferView).then((function(e){l=!0;const t=new Blob([e],{type:i.mimeType});return c=a.createObjectURL(t),c}));else if(void 0===i.uri)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const u=Promise.resolve(c).then((function(e){return new Promise((function(r,n){let i=r;!0===s.isImageBitmapLoader&&(i=function(e){const s=new t.Texture(e);s.needsUpdate=!0,r(s)}),s.load(t.LoaderUtils.resolveURL(e,o.path),i,void 0,n)}))})).then((function(e){var t;return!0===l&&a.revokeObjectURL(c),e.userData.mimeType=i.mimeType||((t=i.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":"image/png"),e})).catch((function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",c),e}));return this.sourceCache[e]=u,u}assignTexture(e,t,s,r){const n=this;return this.getDependency("texture",s.index).then((function(i){if(!i)return null;if(void 0!==s.texCoord&&s.texCoord>0&&((i=i.clone()).channel=s.texCoord),n.extensions[o.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[o.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=n.associations.get(i);i=n.extensions[o.KHR_TEXTURE_TRANSFORM].extendTexture(i,e),n.associations.set(i,t)}}return void 0!==r&&(i.colorSpace=r),e[t]=i,i}))}assignFinalMaterial(e){const s=e.geometry;let r=e.material;const n=void 0===s.attributes.tangent,o=void 0!==s.attributes.color,i=void 0===s.attributes.normal;if(e.isPoints){const e="PointsMaterial:"+r.uuid;let s=this.cache.get(e);s||(s=new t.PointsMaterial,t.Material.prototype.copy.call(s,r),s.color.copy(r.color),s.map=r.map,s.sizeAttenuation=!1,this.cache.add(e,s)),r=s}else if(e.isLine){const e="LineBasicMaterial:"+r.uuid;let s=this.cache.get(e);s||(s=new t.LineBasicMaterial,t.Material.prototype.copy.call(s,r),s.color.copy(r.color),s.map=r.map,this.cache.add(e,s)),r=s}if(n||o||i){let e="ClonedMaterial:"+r.uuid+":";n&&(e+="derivative-tangents:"),o&&(e+="vertex-colors:"),i&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=r.clone(),o&&(t.vertexColors=!0),i&&(t.flatShading=!0),n&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(r))),r=t}e.material=r}getMaterialType(){return t.MeshStandardMaterial}loadMaterial(e){const s=this,r=this.json,n=this.extensions,i=r.materials[e];let a;const c={},l=[];if((i.extensions||{})[o.KHR_MATERIALS_UNLIT]){const e=n[o.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),l.push(e.extendParams(c,i,s))}else{const r=i.pbrMetallicRoughness||{};if(c.color=new t.Color(1,1,1),c.opacity=1,Array.isArray(r.baseColorFactor)){const e=r.baseColorFactor;c.color.fromArray(e),c.opacity=e[3]}void 0!==r.baseColorTexture&&l.push(s.assignTexture(c,"map",r.baseColorTexture,t.SRGBColorSpace)),c.metalness=void 0!==r.metallicFactor?r.metallicFactor:1,c.roughness=void 0!==r.roughnessFactor?r.roughnessFactor:1,void 0!==r.metallicRoughnessTexture&&(l.push(s.assignTexture(c,"metalnessMap",r.metallicRoughnessTexture)),l.push(s.assignTexture(c,"roughnessMap",r.metallicRoughnessTexture))),a=this._invokeOne((function(t){return t.getMaterialType&&t.getMaterialType(e)})),l.push(Promise.all(this._invokeAll((function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,c)}))))}!0===i.doubleSided&&(c.side=t.DoubleSide);const u=i.alphaMode||U;if(u===G?(c.transparent=!0,c.depthWrite=!1):(c.transparent=!1,u===B&&(c.alphaTest=void 0!==i.alphaCutoff?i.alphaCutoff:.5)),void 0!==i.normalTexture&&a!==t.MeshBasicMaterial&&(l.push(s.assignTexture(c,"normalMap",i.normalTexture)),c.normalScale=new t.Vector2(1,1),void 0!==i.normalTexture.scale)){const e=i.normalTexture.scale;c.normalScale.set(e,e)}return void 0!==i.occlusionTexture&&a!==t.MeshBasicMaterial&&(l.push(s.assignTexture(c,"aoMap",i.occlusionTexture)),void 0!==i.occlusionTexture.strength&&(c.aoMapIntensity=i.occlusionTexture.strength)),void 0!==i.emissiveFactor&&a!==t.MeshBasicMaterial&&(c.emissive=(new t.Color).fromArray(i.emissiveFactor)),void 0!==i.emissiveTexture&&a!==t.MeshBasicMaterial&&l.push(s.assignTexture(c,"emissiveMap",i.emissiveTexture,t.SRGBColorSpace)),Promise.all(l).then((function(){const t=new a(c);return i.name&&(t.name=i.name),K(t,i),s.associations.set(t,{materials:e}),i.extensions&&j(n,t,i),t}))}createUniqueName(e){const s=t.PropertyBinding.sanitizeNodeName(e||"");let r=s;for(let e=1;this.nodeNamesUsed[r];++e)r=s+"_"+e;return this.nodeNamesUsed[r]=!0,r}loadGeometries(e){const s=this,r=this.extensions,n=this.primitiveCache;function i(e){return r[o.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then((function(t){return Y(t,e,s)}))}const a=[];for(let r=0,c=e.length;r<c;r++){const c=e[r],l=X(c),u=n[l];if(u)a.push(u.promise);else{let e;e=c.extensions&&c.extensions[o.KHR_DRACO_MESH_COMPRESSION]?i(c):Y(new t.BufferGeometry,c,s),n[l]={primitive:c,promise:e},a.push(e)}}return Promise.all(a)}loadMesh(e){const r=this,n=this.json,o=this.extensions,i=n.meshes[e],a=i.primitives,c=[];for(let e=0,s=a.length;e<s;e++){const s=void 0===a[e].material?(void 0===(l=this.cache).DefaultMaterial&&(l.DefaultMaterial=new t.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:t.FrontSide})),l.DefaultMaterial):this.getDependency("material",a[e].material);c.push(s)}var l;return c.push(r.loadGeometries(a)),Promise.all(c).then((function(n){const c=n.slice(0,n.length-1),l=n[n.length-1],u=[];for(let n=0,h=l.length;n<h;n++){const h=l[n],d=a[n];let p;const m=c[n];if(d.mode===C.TRIANGLES||d.mode===C.TRIANGLE_STRIP||d.mode===C.TRIANGLE_FAN||void 0===d.mode)p=!0===i.isSkinnedMesh?new t.SkinnedMesh(h,m):new t.Mesh(h,m),!0===p.isSkinnedMesh&&p.normalizeSkinWeights(),d.mode===C.TRIANGLE_STRIP?p.geometry=s(p.geometry,t.TriangleStripDrawMode):d.mode===C.TRIANGLE_FAN&&(p.geometry=s(p.geometry,t.TriangleFanDrawMode));else if(d.mode===C.LINES)p=new t.LineSegments(h,m);else if(d.mode===C.LINE_STRIP)p=new t.Line(h,m);else if(d.mode===C.LINE_LOOP)p=new t.LineLoop(h,m);else{if(d.mode!==C.POINTS)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+d.mode);p=new t.Points(h,m)}Object.keys(p.geometry.morphAttributes).length>0&&V(p,i),p.name=r.createUniqueName(i.name||"mesh_"+e),K(p,i),d.extensions&&j(o,p,d),r.assignFinalMaterial(p),u.push(p)}for(let t=0,s=u.length;t<s;t++)r.associations.set(u[t],{meshes:e,primitives:t});if(1===u.length)return u[0];const h=new t.Group;r.associations.set(h,{meshes:e});for(let e=0,t=u.length;e<t;e++)h.add(u[e]);return h}))}loadCamera(e){let s;const r=this.json.cameras[e],n=r[r.type];if(n)return"perspective"===r.type?s=new t.PerspectiveCamera(t.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):"orthographic"===r.type&&(s=new t.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),r.name&&(s.name=this.createUniqueName(r.name)),K(s,r),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const s=this.json.skins[e],r=[];for(let e=0,t=s.joints.length;e<t;e++)r.push(this._loadNodeShallow(s.joints[e]));return void 0!==s.inverseBindMatrices?r.push(this.getDependency("accessor",s.inverseBindMatrices)):r.push(null),Promise.all(r).then((function(e){const r=e.pop(),n=e,o=[],i=[];for(let e=0,a=n.length;e<a;e++){const a=n[e];if(a){o.push(a);const s=new t.Matrix4;null!==r&&s.fromArray(r.array,16*e),i.push(s)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[e])}return new t.Skeleton(o,i)}))}loadAnimation(e){const s=this.json.animations[e],r=s.name?s.name:"animation_"+e,n=[],o=[],i=[],a=[],c=[];for(let e=0,t=s.channels.length;e<t;e++){const t=s.channels[e],r=s.samplers[t.sampler],l=t.target,u=l.node,h=void 0!==s.parameters?s.parameters[r.input]:r.input,d=void 0!==s.parameters?s.parameters[r.output]:r.output;void 0!==l.node&&(n.push(this.getDependency("node",u)),o.push(this.getDependency("accessor",h)),i.push(this.getDependency("accessor",d)),a.push(r),c.push(l))}return Promise.all([Promise.all(n),Promise.all(o),Promise.all(i),Promise.all(a),Promise.all(c)]).then((function(e){const s=e[0],n=e[1],o=e[2],i=e[3],a=e[4],c=[];for(let e=0,r=s.length;e<r;e++){const r=s[e],l=n[e],u=o[e],h=i[e],d=a[e];if(void 0===r)continue;let p;switch(r.updateMatrix(),F[d.path]){case F.weights:p=t.NumberKeyframeTrack;break;case F.rotation:p=t.QuaternionKeyframeTrack;break;default:p=t.VectorKeyframeTrack}const m=r.name?r.name:r.uuid,f=void 0!==h.interpolation?H[h.interpolation]:t.InterpolateLinear,A=[];F[d.path]===F.weights?r.traverse((function(e){e.morphTargetInfluences&&A.push(e.name?e.name:e.uuid)})):A.push(m);let g=u.array;if(u.normalized){const e=q(g.constructor),t=new Float32Array(g.length);for(let s=0,r=g.length;s<r;s++)t[s]=g[s]*e;g=t}for(let e=0,s=A.length;e<s;e++){const s=new p(A[e]+"."+F[d.path],l.array,g,f);"CUBICSPLINE"===h.interpolation&&(s.createInterpolant=function(e){return new(this instanceof t.QuaternionKeyframeTrack?I:L)(this.times,this.values,this.getValueSize()/3,e)},s.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),c.push(s)}}return new t.AnimationClip(r,void 0,c)}))}createNodeMesh(e){const t=this.json,s=this,r=t.nodes[e];return void 0===r.mesh?null:s.getDependency("mesh",r.mesh).then((function(e){const t=s._getNodeRef(s.meshCache,r.mesh,e);return void 0!==r.weights&&t.traverse((function(e){if(e.isMesh)for(let t=0,s=r.weights.length;t<s;t++)e.morphTargetInfluences[t]=r.weights[t]})),t}))}loadNode(e){const t=this,s=this.json.nodes[e],r=t._loadNodeShallow(e),n=[],o=s.children||[];for(let e=0,s=o.length;e<s;e++)n.push(t.getDependency("node",o[e]));const i=void 0===s.skin?Promise.resolve(null):t.getDependency("skin",s.skin);return Promise.all([r,Promise.all(n),i]).then((function(e){const t=e[0],s=e[1],r=e[2];null!==r&&t.traverse((function(e){e.isSkinnedMesh&&e.bind(r,z)}));for(let e=0,r=s.length;e<r;e++)t.add(s[e]);return t}))}_loadNodeShallow(e){const s=this.json,r=this.extensions,n=this;if(void 0!==this.nodeCache[e])return this.nodeCache[e];const o=s.nodes[e],i=o.name?n.createUniqueName(o.name):"",a=[],c=n._invokeOne((function(t){return t.createNodeMesh&&t.createNodeMesh(e)}));return c&&a.push(c),void 0!==o.camera&&a.push(n.getDependency("camera",o.camera).then((function(e){return n._getNodeRef(n.cameraCache,o.camera,e)}))),n._invokeAll((function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)})).forEach((function(e){a.push(e)})),this.nodeCache[e]=Promise.all(a).then((function(s){let a;if(a=!0===o.isBone?new t.Bone:s.length>1?new t.Group:1===s.length?s[0]:new t.Object3D,a!==s[0])for(let e=0,t=s.length;e<t;e++)a.add(s[e]);if(o.name&&(a.userData.name=o.name,a.name=i),K(a,o),o.extensions&&j(r,a,o),void 0!==o.matrix){const e=new t.Matrix4;e.fromArray(o.matrix),a.applyMatrix4(e)}else void 0!==o.translation&&a.position.fromArray(o.translation),void 0!==o.rotation&&a.quaternion.fromArray(o.rotation),void 0!==o.scale&&a.scale.fromArray(o.scale);return n.associations.has(a)||n.associations.set(a,{}),n.associations.get(a).nodes=e,a})),this.nodeCache[e]}loadScene(e){const s=this.extensions,r=this.json.scenes[e],n=this,o=new t.Group;r.name&&(o.name=n.createUniqueName(r.name)),K(o,r),r.extensions&&j(s,o,r);const i=r.nodes||[],a=[];for(let e=0,t=i.length;e<t;e++)a.push(n.getDependency("node",i[e]));return Promise.all(a).then((function(e){for(let t=0,s=e.length;t<s;t++)o.add(e[t]);return n.associations=(e=>{const s=new Map;for(const[e,r]of n.associations)(e instanceof t.Material||e instanceof t.Texture)&&s.set(e,r);return e.traverse((e=>{const t=n.associations.get(e);null!=t&&s.set(e,t)})),s})(o),o}))}}function Y(e,s,r){const n=s.attributes,o=[];function i(t,s){return r.getDependency("accessor",t).then((function(t){e.setAttribute(s,t)}))}for(const t in n){const s=D[t]||t.toLowerCase();s in e.attributes||o.push(i(n[t],s))}if(void 0!==s.indices&&!e.index){const t=r.getDependency("accessor",s.indices).then((function(t){e.setIndex(t)}));o.push(t)}return K(e,s),function(e,s,r){const n=s.attributes,o=new t.Box3;if(void 0===n.POSITION)return;{const e=r.json.accessors[n.POSITION],s=e.min,i=e.max;if(void 0===s||void 0===i)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(o.set(new t.Vector3(s[0],s[1],s[2]),new t.Vector3(i[0],i[1],i[2])),e.normalized){const t=q(P[e.componentType]);o.min.multiplyScalar(t),o.max.multiplyScalar(t)}}const i=s.targets;if(void 0!==i){const e=new t.Vector3,s=new t.Vector3;for(let t=0,n=i.length;t<n;t++){const n=i[t];if(void 0!==n.POSITION){const t=r.json.accessors[n.POSITION],o=t.min,i=t.max;if(void 0!==o&&void 0!==i){if(s.setX(Math.max(Math.abs(o[0]),Math.abs(i[0]))),s.setY(Math.max(Math.abs(o[1]),Math.abs(i[1]))),s.setZ(Math.max(Math.abs(o[2]),Math.abs(i[2]))),t.normalized){const e=q(P[t.componentType]);s.multiplyScalar(e)}e.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}o.expandByVector(e)}e.boundingBox=o;const a=new t.Sphere;o.getCenter(a.center),a.radius=o.min.distanceTo(o.max)/2,e.boundingSphere=a}(e,s,r),Promise.all(o).then((function(){return void 0!==s.targets?function(e,t,s){let r=!1,n=!1,o=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(r=!0),void 0!==s.NORMAL&&(n=!0),void 0!==s.COLOR_0&&(o=!0),r&&n&&o)break}if(!r&&!n&&!o)return Promise.resolve(e);const i=[],a=[],c=[];for(let l=0,u=t.length;l<u;l++){const u=t[l];if(r){const t=void 0!==u.POSITION?s.getDependency("accessor",u.POSITION):e.attributes.position;i.push(t)}if(n){const t=void 0!==u.NORMAL?s.getDependency("accessor",u.NORMAL):e.attributes.normal;a.push(t)}if(o){const t=void 0!==u.COLOR_0?s.getDependency("accessor",u.COLOR_0):e.attributes.color;c.push(t)}}return Promise.all([Promise.all(i),Promise.all(a),Promise.all(c)]).then((function(t){const s=t[0],i=t[1],a=t[2];return r&&(e.morphAttributes.position=s),n&&(e.morphAttributes.normal=i),o&&(e.morphAttributes.color=a),e.morphTargetsRelative=!0,e}))}(e,s.targets,r):e}))}const Z=new WeakMap;class J extends t.Loader{constructor(e){super(e),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(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,s,r,n){const o=new t.FileLoader(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,(e=>{this.parse(e,s,n)}),r,n)}parse(e,s,r){this.decodeDracoFile(e,s,null,null,t.SRGBColorSpace).catch(r)}decodeDracoFile(e,s,r,n,o=t.LinearSRGBColorSpace){const i={attributeIDs:r||this.defaultAttributeIDs,attributeTypes:n||this.defaultAttributeTypes,useUniqueIDs:!!r,vertexColorSpace:o};return this.decodeGeometry(e,i).then(s)}decodeGeometry(e,t){const s=JSON.stringify(t);if(Z.has(e)){const t=Z.get(e);if(t.key===s)return t.promise;if(0===e.byteLength)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let r;const n=this.workerNextTaskID++,o=e.byteLength,i=this._getWorker(n,o).then((s=>(r=s,new Promise(((s,o)=>{r._callbacks[n]={resolve:s,reject:o},r.postMessage({type:"decode",id:n,taskConfig:t,buffer:e},[e])}))))).then((e=>this._createGeometry(e.geometry)));return i.catch((()=>!0)).then((()=>{r&&n&&this._releaseTask(r,n)})),Z.set(e,{key:s,promise:i}),i}_createGeometry(e){const s=new t.BufferGeometry;e.index&&s.setIndex(new t.BufferAttribute(e.index.array,1));for(let r=0;r<e.attributes.length;r++){const n=e.attributes[r],o=n.name,i=n.array,a=n.itemSize,c=new t.BufferAttribute(i,a);"color"===o&&this._assignVertexColorSpace(c,n.vertexColorSpace),s.setAttribute(o,c)}return s}_assignVertexColorSpace(e,s){if(s!==t.SRGBColorSpace)return;const r=new t.Color;for(let t=0,s=e.count;t<s;t++)r.fromBufferAttribute(e,t).convertSRGBToLinear(),e.setXYZ(t,r.r,r.g,r.b)}_loadLibrary(e,s){const r=new t.FileLoader(this.manager);return r.setPath(this.decoderPath),r.setResponseType(s),r.setWithCredentials(this.withCredentials),new Promise(((t,s)=>{r.load(e,t,void 0,s)}))}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e="object"!=typeof WebAssembly||"js"===this.decoderConfig.type,t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then((t=>{const s=t[0];e||(this.decoderConfig.wasmBinary=t[1]);const r=$.toString(),n=["/* draco decoder */",s,"","/* worker */",r.substring(r.indexOf("{")+1,r.lastIndexOf("}"))].join("\n");this.workerSourceURL=URL.createObjectURL(new Blob([n]))})),this.decoderPending}_getWorker(e,t){return this._initDecoder().then((()=>{if(this.workerPool.length<this.workerLimit){const e=new Worker(this.workerSourceURL);e._callbacks={},e._taskCosts={},e._taskLoad=0,e.postMessage({type:"init",decoderConfig:this.decoderConfig}),e.onmessage=function(t){const s=t.data;switch(s.type){case"decode":e._callbacks[s.id].resolve(s);break;case"error":e._callbacks[s.id].reject(s);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+s.type+'"')}},this.workerPool.push(e)}else this.workerPool.sort((function(e,t){return e._taskLoad>t._taskLoad?-1:1}));const s=this.workerPool[this.workerPool.length-1];return s._taskCosts[e]=t,s._taskLoad+=t,s}))}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map((e=>e._taskLoad)))}dispose(){for(let e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,""!==this.workerSourceURL&&URL.revokeObjectURL(this.workerSourceURL),this}}function $(){let e,t;function s(e,t,s,r,n,o){const i=o.num_components(),a=s.num_points()*i,c=a*n.BYTES_PER_ELEMENT,l=function(e,t){switch(t){case Float32Array:return e.DT_FLOAT32;case Int8Array:return e.DT_INT8;case Int16Array:return e.DT_INT16;case Int32Array:return e.DT_INT32;case Uint8Array:return e.DT_UINT8;case Uint16Array:return e.DT_UINT16;case Uint32Array:return e.DT_UINT32}}(e,n),u=e._malloc(c);t.GetAttributeDataArrayForAllPoints(s,o,l,c,u);const h=new n(e.HEAPF32.buffer,u,a).slice();return e._free(u),{name:r,array:h,itemSize:i}}onmessage=function(r){const n=r.data;switch(n.type){case"init":e=n.decoderConfig,t=new Promise((function(t){e.onModuleLoaded=function(e){t({draco:e})},DracoDecoderModule(e)}));break;case"decode":const r=n.buffer,o=n.taskConfig;t.then((e=>{const t=e.draco,i=new t.Decoder;try{const e=function(e,t,r,n){const o=n.attributeIDs,i=n.attributeTypes;let a,c;const l=t.GetEncodedGeometryType(r);if(l===e.TRIANGULAR_MESH)a=new e.Mesh,c=t.DecodeArrayToMesh(r,r.byteLength,a);else{if(l!==e.POINT_CLOUD)throw new Error("THREE.DRACOLoader: Unexpected geometry type.");a=new e.PointCloud,c=t.DecodeArrayToPointCloud(r,r.byteLength,a)}if(!c.ok()||0===a.ptr)throw new Error("THREE.DRACOLoader: Decoding failed: "+c.error_msg());const u={index:null,attributes:[]};for(const r in o){const c=self[i[r]];let l,h;if(n.useUniqueIDs)h=o[r],l=t.GetAttributeByUniqueId(a,h);else{if(h=t.GetAttributeId(a,e[o[r]]),-1===h)continue;l=t.GetAttribute(a,h)}const d=s(e,t,a,r,c,l);"color"===r&&(d.vertexColorSpace=n.vertexColorSpace),u.attributes.push(d)}l===e.TRIANGULAR_MESH&&(u.index=function(e,t,s){const r=s.num_faces(),n=3*r,o=4*n,i=e._malloc(o);t.GetTrianglesUInt32Array(s,o,i);const a=new Uint32Array(e.HEAPF32.buffer,i,n).slice();return e._free(i),{array:a,itemSize:1}}(e,t,a));return e.destroy(a),u}(t,i,new Int8Array(r),o),a=e.attributes.map((e=>e.array.buffer));e.index&&a.push(e.index.array.buffer),self.postMessage({type:"decode",id:n.id,geometry:e},a)}catch(e){console.error(e),self.postMessage({type:"error",id:n.id,error:e.message})}finally{t.destroy(i)}}))}}}function ee(e,s,r={}){const n=new t.Vector3,o=new t.Quaternion,i=new t.Vector3,a=new t.Matrix4,c=new t.Matrix4,l=new t.Matrix4;r.preserveMatrix=void 0===r.preserveMatrix||r.preserveMatrix,r.preservePosition=void 0===r.preservePosition||r.preservePosition,r.preserveHipPosition=void 0!==r.preserveHipPosition&&r.preserveHipPosition,r.useTargetMatrix=void 0!==r.useTargetMatrix&&r.useTargetMatrix,r.hip=void 0!==r.hip?r.hip:"hip",r.names=r.names||{};const u=s.isObject3D?s.skeleton.bones:se(s),h=e.isObject3D?e.skeleton.bones:se(e);let d,p,m,f,A;if(e.isObject3D?e.skeleton.pose():(r.useTargetMatrix=!0,r.preserveMatrix=!1),r.preservePosition){A=[];for(let e=0;e<h.length;e++)A.push(h[e].position.clone())}if(r.preserveMatrix){e.updateMatrixWorld(),e.matrixWorld.identity();for(let t=0;t<e.children.length;++t)e.children[t].updateMatrixWorld(!0)}if(r.offsets){d=[];for(let e=0;e<h.length;++e)p=h[e],m=r.names[p.name]||p.name,r.offsets[m]&&(p.matrix.multiply(r.offsets[m]),p.matrix.decompose(p.position,p.quaternion,p.scale),p.updateMatrixWorld()),d.push(p.matrixWorld.clone())}for(let t=0;t<h.length;++t){if(p=h[t],m=r.names[p.name]||p.name,f=te(m,u),l.copy(p.matrixWorld),f){if(f.updateMatrixWorld(),r.useTargetMatrix?c.copy(f.matrixWorld):(c.copy(e.matrixWorld).invert(),c.multiply(f.matrixWorld)),i.setFromMatrixScale(c),c.scale(i.set(1/i.x,1/i.y,1/i.z)),l.makeRotationFromQuaternion(o.setFromRotationMatrix(c)),e.isObject3D){const t=h.indexOf(p),s=d?d[t]:a.copy(e.skeleton.boneInverses[t]).invert();l.multiply(s)}l.copyPosition(c)}p.parent&&p.parent.isBone?(p.matrix.copy(p.parent.matrixWorld).invert(),p.matrix.multiply(l)):p.matrix.copy(l),r.preserveHipPosition&&m===r.hip&&p.matrix.setPosition(n.set(0,p.position.y,0)),p.matrix.decompose(p.position,p.quaternion,p.scale),p.updateMatrixWorld()}if(r.preservePosition)for(let e=0;e<h.length;++e)p=h[e],m=r.names[p.name]||p.name,m!==r.hip&&p.position.copy(A[e]);r.preserveMatrix&&e.updateMatrixWorld(!0)}function te(e,t){for(let s=0,r=se(t);s<r.length;s++)if(e===r[s].name)return r[s]}function se(e){return Array.isArray(e)?e:e.bones}function re(e,t,s){s(e,t);for(let r=0;r<e.children.length;r++)re(e.children[r],t.children[r],s)}var ne=Object.freeze({__proto__:null,retarget:ee,retargetClip:function(e,s,r,n={}){n.useFirstFramePosition=void 0!==n.useFirstFramePosition&&n.useFirstFramePosition,n.fps=void 0!==n.fps?n.fps:30,n.names=n.names||[],s.isObject3D||(s=function(e){const s=new t.SkeletonHelper(e.bones[0]);return s.skeleton=e,s}(s));const o=Math.round(r.duration*(n.fps/1e3)*1e3),i=1/n.fps,a=[],c=new t.AnimationMixer(s),l=se(e.skeleton),u=[];let h,d,p,m,f;c.clipAction(r).play(),c.update(0),s.updateMatrixWorld();for(let t=0;t<o;++t){const r=t*i;ee(e,s,n);for(let e=0;e<l.length;++e)f=n.names[l[e].name]||l[e].name,p=te(f,s.skeleton),p&&(d=l[e],m=u[e]=u[e]||{bone:d},n.hip===f&&(m.pos||(m.pos={times:new Float32Array(o),values:new Float32Array(3*o)}),n.useFirstFramePosition&&(0===t&&(h=d.position.clone()),d.position.sub(h)),m.pos.times[t]=r,d.position.toArray(m.pos.values,3*t)),m.quat||(m.quat={times:new Float32Array(o),values:new Float32Array(4*o)}),m.quat.times[t]=r,d.quaternion.toArray(m.quat.values,4*t));c.update(i),s.updateMatrixWorld()}for(let e=0;e<u.length;++e)m=u[e],m&&(m.pos&&a.push(new t.VectorKeyframeTrack(".bones["+m.bone.name+"].position",m.pos.times,m.pos.values)),a.push(new t.QuaternionKeyframeTrack(".bones["+m.bone.name+"].quaternion",m.quat.times,m.quat.values)));return c.uncacheAction(r),new t.AnimationClip(r.name,-1,a)},clone:function(e){const t=new Map,s=new Map,r=e.clone();return re(e,r,(function(e,r){t.set(r,e),s.set(e,r)})),r.traverse((function(e){if(!e.isSkinnedMesh)return;const r=e,n=t.get(e),o=n.skeleton.bones;r.skeleton=n.skeleton.clone(),r.bindMatrix.copy(n.bindMatrix),r.skeleton.bones=o.map((function(e){return s.get(e)})),r.bind(r.skeleton,r.bindMatrix)})),r}});e.DRACOLoader=J,e.GLTFLoader=r,e.SkeletonUtils=ne,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ThreeAddons.js.map