three-stdlib 2.6.3 → 2.6.4
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs.js +1 -1
- package/loaders/AMFLoader.js +1 -3
- package/loaders/ColladaLoader.cjs.js +1 -1
- package/loaders/ColladaLoader.js +58 -35
- package/loaders/EXRLoader.cjs.js +1 -1
- package/loaders/EXRLoader.js +197 -262
- package/loaders/FBXLoader.cjs.js +1 -1
- package/loaders/FBXLoader.js +41 -90
- package/loaders/GLTFLoader.cjs.js +1 -1
- package/loaders/GLTFLoader.js +160 -72
- package/loaders/HDRCubeTextureLoader.cjs.js +1 -1
- package/loaders/HDRCubeTextureLoader.js +2 -2
- package/loaders/RGBELoader.cjs.js +1 -1
- package/loaders/RGBELoader.js +10 -9
- package/loaders/RGBMLoader.cjs.js +1 -1
- package/loaders/RGBMLoader.js +181 -257
- package/loaders/SVGLoader.cjs.js +1 -1
- package/loaders/SVGLoader.js +46 -30
- package/loaders/VRMLLoader.cjs.js +1 -1
- package/loaders/VRMLLoader.js +2 -1
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new i(e)})),this.register((function(e){return new h(e)})),this.register((function(e){return new p(e)})),this.register((function(e){return new a(e)})),this.register((function(e){return new l(e)})),this.register((function(e){return new c(e)})),this.register((function(e){return new u(e)})),this.register((function(e){return new r(e)})),this.register((function(e){return new d(e)}))}load(t,s,n,r){const o=this;let i;i=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:e.LoaderUtils.extractUrlBase(t),this.manager.itemStart(t);const a=function(e){r?r(e):console.error(e),o.manager.itemError(t),o.manager.itemEnd(t)},l=new e.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(t,(function(e){try{o.parse(e,i,(function(e){s(e),o.manager.itemEnd(t)}),a)}catch(e){a(e)}}),n,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(t,s,r,i){let a;const l={},c={};if("string"==typeof t)a=t;else{if(e.LoaderUtils.decodeText(new Uint8Array(t,0,4))===m){try{l[n.KHR_BINARY_GLTF]=new T(t)}catch(e){return void(i&&i(e))}a=l[n.KHR_BINARY_GLTF].content}else a=e.LoaderUtils.decodeText(new Uint8Array(t))}const u=JSON.parse(a);if(void 0===u.asset||u.asset.version[0]<2)return void(i&&i(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const h=new W(u,{path:s||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});h.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](h);c[t.name]=t,l[t.name]=!0}if(u.extensionsUsed)for(let e=0;e<u.extensionsUsed.length;++e){const t=u.extensionsUsed[e],s=u.extensionsRequired||[];switch(t){case n.KHR_MATERIALS_UNLIT:l[t]=new o;break;case n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:l[t]=new v;break;case n.KHR_DRACO_MESH_COMPRESSION:l[t]=new x(u,this.dracoLoader);break;case n.KHR_TEXTURE_TRANSFORM:l[t]=new M;break;case n.KHR_MESH_QUANTIZATION:l[t]=new y;break;default:s.indexOf(t)>=0&&void 0===c[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}h.setExtensions(l),h.setPlugins(c),h.parse(r,i)}}function s(){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 n={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_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",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",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression"};class r{constructor(e){this.parser=e,this.name=n.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s];n.extensions&&n.extensions[this.name]&&void 0!==n.extensions[this.name].light&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(t){const s=this.parser,n="light:"+t;let r=s.cache.get(n);if(r)return r;const o=s.json,i=((o.extensions&&o.extensions[this.name]||{}).lights||[])[t];let a;const l=new e.Color(16777215);void 0!==i.color&&l.fromArray(i.color);const c=void 0!==i.range?i.range:0;switch(i.type){case"directional":a=new e.DirectionalLight(l),a.target.position.set(0,0,-1),a.add(a.target);break;case"point":a=new e.PointLight(l),a.distance=c;break;case"spot":a=new e.SpotLight(l),a.distance=c,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,void 0!==i.intensity&&(a.intensity=i.intensity),a.name=s.createUniqueName(i.name||"light_"+t),r=Promise.resolve(a),s.cache.add(n,r),r}createNodeAttachment(e){const t=this,s=this.parser,n=s.json.nodes[e],r=(n.extensions&&n.extensions[this.name]||{}).light;return void 0===r?null:this._loadLight(r).then((function(e){return s._getNodeRef(t.cache,r,e)}))}}class o{constructor(){this.name=n.KHR_MATERIALS_UNLIT}getMaterialType(){return e.MeshBasicMaterial}extendParams(t,s,n){const r=[];t.color=new e.Color(1,1,1),t.opacity=1;const o=s.pbrMetallicRoughness;if(o){if(Array.isArray(o.baseColorFactor)){const e=o.baseColorFactor;t.color.fromArray(e),t.opacity=e[3]}void 0!==o.baseColorTexture&&r.push(n.assignTexture(t,"map",o.baseColorTexture))}return Promise.all(r)}}class i{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];if(void 0!==i.clearcoatFactor&&(s.clearcoat=i.clearcoatFactor),void 0!==i.clearcoatTexture&&o.push(n.assignTexture(s,"clearcoatMap",i.clearcoatTexture)),void 0!==i.clearcoatRoughnessFactor&&(s.clearcoatRoughness=i.clearcoatRoughnessFactor),void 0!==i.clearcoatRoughnessTexture&&o.push(n.assignTexture(s,"clearcoatRoughnessMap",i.clearcoatRoughnessTexture)),void 0!==i.clearcoatNormalTexture&&(o.push(n.assignTexture(s,"clearcoatNormalMap",i.clearcoatNormalTexture)),void 0!==i.clearcoatNormalTexture.scale)){const t=i.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new e.Vector2(t,-t)}return Promise.all(o)}}class a{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return void 0!==o.transmissionFactor&&(t.transmission=o.transmissionFactor),void 0!==o.transmissionTexture&&r.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(r)}}class l{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_VOLUME}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];s.thickness=void 0!==i.thicknessFactor?i.thicknessFactor:0,void 0!==i.thicknessTexture&&o.push(n.assignTexture(s,"thicknessMap",i.thicknessTexture)),s.attenuationDistance=i.attenuationDistance||0;const a=i.attenuationColor||[1,1,1];return s.attenuationTint=new e.Color(a[0],a[1],a[2]),Promise.all(o)}}class c{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_IOR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=s.extensions[this.name];return t.ior=void 0!==n.ior?n.ior:1.5,Promise.resolve()}}class u{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SPECULAR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],i=r.extensions[this.name];s.specularIntensity=void 0!==i.specularFactor?i.specularFactor:1,void 0!==i.specularTexture&&o.push(n.assignTexture(s,"specularIntensityMap",i.specularTexture));const a=i.specularColorFactor||[1,1,1];return s.specularTint=new e.Color(a[0],a[1],a[2]),void 0!==i.specularColorTexture&&o.push(n.assignTexture(s,"specularTintMap",i.specularColorTexture).then((function(t){t.encoding=e.sRGBEncoding}))),Promise.all(o)}}class h{constructor(e){this.parser=e,this.name=n.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const r=n.extensions[this.name],o=s.images[r.source],i=t.options.ktx2Loader;if(!i){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,o,i)}}class p{constructor(e){this.parser=e,this.name=n.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,r=n.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],i=n.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(r){if(r)return s.loadTextureImage(e,i,a);if(n.extensionsRequired&&n.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 d{constructor(e){this.name=n.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],n=this.parser.getDependency("buffer",e.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.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 Promise.all([n,r.ready]).then((function(t){const s=e.byteOffset||0,n=e.byteLength||0,o=e.count,i=e.byteStride,a=new ArrayBuffer(o*i),l=new Uint8Array(t[0],s,n);return r.decodeGltfBuffer(new Uint8Array(a),o,i,l,e.mode,e.filter),a}))}return null}}const m="glTF",f=1313821514,g=5130562;class T{constructor(t){this.name=n.KHR_BINARY_GLTF,this.content=null,this.body=null;const s=new DataView(t,0,12);if(this.header={magic:e.LoaderUtils.decodeText(new Uint8Array(t.slice(0,4))),version:s.getUint32(4,!0),length:s.getUint32(8,!0)},this.header.magic!==m)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,o=new DataView(t,12);let i=0;for(;i<r;){const s=o.getUint32(i,!0);i+=4;const n=o.getUint32(i,!0);if(i+=4,n===f){const n=new Uint8Array(t,12+i,s);this.content=e.LoaderUtils.decodeText(n)}else if(n===g){const e=12+i;this.body=t.slice(e,e+s)}i+=s}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class x{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=n.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,r=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,i={},a={},l={};for(const e in o){const t=F[e]||e.toLowerCase();i[t]=o[e]}for(const t in e.attributes){const n=F[t]||t.toLowerCase();if(void 0!==o[t]){const r=s.accessors[e.attributes[t]],o=P[r.componentType];l[n]=o,a[n]=!0===r.normalized}}return t.getDependency("bufferView",r).then((function(e){return new Promise((function(t){n.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],n=a[t];void 0!==n&&(s.normalized=n)}t(e)}),i,l)}))}))}}class M{constructor(){this.name=n.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&console.warn('THREE.GLTFLoader: Custom UV sets in "'+this.name+'" extension not yet supported.'),void 0===t.offset&&void 0===t.rotation&&void 0===t.scale||(e=e.clone(),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}}class R extends e.MeshStandardMaterial{constructor(t){super(),this.isGLTFSpecularGlossinessMaterial=!0;const s=["#ifdef USE_SPECULARMAP","\tuniform sampler2D specularMap;","#endif"].join("\n"),n=["#ifdef USE_GLOSSINESSMAP","\tuniform sampler2D glossinessMap;","#endif"].join("\n"),r=["vec3 specularFactor = specular;","#ifdef USE_SPECULARMAP","\tvec4 texelSpecular = texture2D( specularMap, vUv );","\ttexelSpecular = sRGBToLinear( texelSpecular );","\t// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture","\tspecularFactor *= texelSpecular.rgb;","#endif"].join("\n"),o=["float glossinessFactor = glossiness;","#ifdef USE_GLOSSINESSMAP","\tvec4 texelGlossiness = texture2D( glossinessMap, vUv );","\t// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture","\tglossinessFactor *= texelGlossiness.a;","#endif"].join("\n"),i=["PhysicalMaterial material;","material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );","vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );","material.specularRoughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.","material.specularRoughness += geometryRoughness;","material.specularRoughness = min( material.specularRoughness, 1.0 );","material.specularColor = specularFactor;"].join("\n"),a={specular:{value:(new e.Color).setHex(16777215)},glossiness:{value:1},specularMap:{value:null},glossinessMap:{value:null}};this._extraUniforms=a,this.onBeforeCompile=function(e){for(const t in a)e.uniforms[t]=a[t];e.fragmentShader=e.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>",s).replace("#include <metalnessmap_pars_fragment>",n).replace("#include <roughnessmap_fragment>",r).replace("#include <metalnessmap_fragment>",o).replace("#include <lights_physical_fragment>",i)},Object.defineProperties(this,{specular:{get:function(){return a.specular.value},set:function(e){a.specular.value=e}},specularMap:{get:function(){return a.specularMap.value},set:function(e){a.specularMap.value=e,e?this.defines.USE_SPECULARMAP="":delete this.defines.USE_SPECULARMAP}},glossiness:{get:function(){return a.glossiness.value},set:function(e){a.glossiness.value=e}},glossinessMap:{get:function(){return a.glossinessMap.value},set:function(e){a.glossinessMap.value=e,e?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_UV=""):(delete this.defines.USE_GLOSSINESSMAP,delete this.defines.USE_UV)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(t)}copy(e){return super.copy(e),this.specularMap=e.specularMap,this.specular.copy(e.specular),this.glossinessMap=e.glossinessMap,this.glossiness=e.glossiness,delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this}}class v{constructor(){this.name=n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,this.specularGlossinessParams=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","normalMapType","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity","refractionRatio"]}getMaterialType(){return R}extendParams(t,s,n){const r=s.extensions[this.name];t.color=new e.Color(1,1,1),t.opacity=1;const o=[];if(Array.isArray(r.diffuseFactor)){const e=r.diffuseFactor;t.color.fromArray(e),t.opacity=e[3]}if(void 0!==r.diffuseTexture&&o.push(n.assignTexture(t,"map",r.diffuseTexture)),t.emissive=new e.Color(0,0,0),t.glossiness=void 0!==r.glossinessFactor?r.glossinessFactor:1,t.specular=new e.Color(1,1,1),Array.isArray(r.specularFactor)&&t.specular.fromArray(r.specularFactor),void 0!==r.specularGlossinessTexture){const e=r.specularGlossinessTexture;o.push(n.assignTexture(t,"glossinessMap",e)),o.push(n.assignTexture(t,"specularMap",e))}return Promise.all(o)}createMaterial(t){const s=new R(t);return s.fog=!0,s.color=t.color,s.map=void 0===t.map?null:t.map,s.lightMap=null,s.lightMapIntensity=1,s.aoMap=void 0===t.aoMap?null:t.aoMap,s.aoMapIntensity=1,s.emissive=t.emissive,s.emissiveIntensity=1,s.emissiveMap=void 0===t.emissiveMap?null:t.emissiveMap,s.bumpMap=void 0===t.bumpMap?null:t.bumpMap,s.bumpScale=1,s.normalMap=void 0===t.normalMap?null:t.normalMap,s.normalMapType=e.TangentSpaceNormalMap,t.normalScale&&(s.normalScale=t.normalScale),s.displacementMap=null,s.displacementScale=1,s.displacementBias=0,s.specularMap=void 0===t.specularMap?null:t.specularMap,s.specular=t.specular,s.glossinessMap=void 0===t.glossinessMap?null:t.glossinessMap,s.glossiness=t.glossiness,s.alphaMap=null,s.envMap=void 0===t.envMap?null:t.envMap,s.envMapIntensity=1,s.refractionRatio=.98,s}}class y{constructor(){this.name=n.KHR_MESH_QUANTIZATION}}class S extends e.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,r=e*n*3+n;for(let e=0;e!==n;e++)t[e]=s[r+e];return t}}S.prototype.beforeStart_=S.prototype.copySampleValue_,S.prototype.afterEnd_=S.prototype.copySampleValue_,S.prototype.interpolate_=function(e,t,s,n){const r=this.resultBuffer,o=this.sampleValues,i=this.valueSize,a=2*i,l=3*i,c=n-t,u=(s-t)/c,h=u*u,p=h*u,d=e*l,m=d-l,f=-2*p+3*h,g=p-h,T=1-f,x=g-h+u;for(let e=0;e!==i;e++){const t=o[m+e+i],s=o[m+e+a]*c,n=o[d+e+i],l=o[d+e]*c;r[e]=T*t+x*s+f*n+g*l}return r};const _=0,A=1,E=2,L=3,w=4,b=5,I=6,P={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},C={9728:e.NearestFilter,9729:e.LinearFilter,9984:e.NearestMipmapNearestFilter,9985:e.LinearMipmapNearestFilter,9986:e.NearestMipmapLinearFilter,9987:e.LinearMipmapLinearFilter},O={33071:e.ClampToEdgeWrapping,33648:e.MirroredRepeatWrapping,10497:e.RepeatWrapping},N={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},F={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},H={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},U={CUBICSPLINE:void 0,LINEAR:e.InterpolateLinear,STEP:e.InterpolateDiscrete},k="OPAQUE",D="MASK",G="BLEND";function B(e,t){return"string"!=typeof e||""===e?"":(/^https?:\/\//i.test(t)&&/^\//.test(e)&&(t=t.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(e)||/^data:.*,.*$/i.test(e)||/^blob:.*$/i.test(e)?e:t+e)}function j(e,t,s){for(const n in s.extensions)void 0===e[n]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[n]=s.extensions[n])}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,n=t.weights.length;s<n;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,n=s.length;t<n;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[n.KHR_DRACO_MESH_COMPRESSION];let s;return s=t?"draco:"+t.bufferView+":"+t.indices+":"+q(t.attributes):e.indices+":"+q(e.attributes)+":"+e.mode,s}function q(e){let t="";const s=Object.keys(e).sort();for(let n=0,r=s.length;n<r;n++)t+=s[n]+":"+e[s[n]]+";";return t}function z(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.")}}class W{constructor(t={},n={}){this.json=t,this.extensions={},this.plugins={},this.options=n,this.cache=new s,this.associations=new Map,this.primitiveCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.textureCache={},this.nodeNamesUsed={},"undefined"!=typeof createImageBitmap&&!1===/Firefox/.test(navigator.userAgent)?this.textureLoader=new e.ImageBitmapLoader(this.options.manager):this.textureLoader=new e.TextureLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new e.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,n=this.json,r=this.extensions;this.cache.removeAll(),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][n.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:n.asset,parser:s,userData:{}};j(r,o,n),K(o,n),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,n=t.length;s<n;s++){const n=t[s].joints;for(let t=0,s=n.length;t<s;t++)e[n[t]].isBone=!0}for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0!==n.mesh&&(this._addNodeRef(this.meshCache,n.mesh),void 0!==n.skin&&(s[n.mesh].isSkinnedMesh=!0)),void 0!==n.camera&&this._addNodeRef(this.cameraCache,n.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 n=s.clone();return n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const r=e(t[n]);r&&s.push(r)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this.loadNode(t);break;case"mesh":n=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":n=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":n=this.loadSkin(t);break;case"animation":n=this.loadAnimation(t);break;case"camera":n=this.loadCamera(t);break;default:throw new Error("Unknown type: "+e)}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(n.map((function(t,n){return s.getDependency(e,n)}))),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],s=this.fileLoader;if(t.type&&"arraybuffer"!==t.type)throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(void 0===t.uri&&0===e)return Promise.resolve(this.extensions[n.KHR_BINARY_GLTF].body);const r=this.options;return new Promise((function(e,n){s.load(B(t.uri,r.path),e,void 0,(function(){n(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(e){const s=t.byteLength||0,n=t.byteOffset||0;return e.slice(n,n+s)}))}loadAccessor(t){const s=this,n=this.json,r=this.json.accessors[t];if(void 0===r.bufferView&&void 0===r.sparse)return Promise.resolve(null);const o=[];return void 0!==r.bufferView?o.push(this.getDependency("bufferView",r.bufferView)):o.push(null),void 0!==r.sparse&&(o.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),o.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(o).then((function(t){const o=t[0],i=N[r.type],a=P[r.componentType],l=a.BYTES_PER_ELEMENT,c=l*i,u=r.byteOffset||0,h=void 0!==r.bufferView?n.bufferViews[r.bufferView].byteStride:void 0,p=!0===r.normalized;let d,m;if(h&&h!==c){const t=Math.floor(u/h),n="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+t+":"+r.count;let c=s.cache.get(n);c||(d=new a(o,t*h,r.count*h/l),c=new e.InterleavedBuffer(d,h/l),s.cache.add(n,c)),m=new e.InterleavedBufferAttribute(c,i,u%h/l,p)}else d=null===o?new a(r.count*i):new a(o,u,r.count*i),m=new e.BufferAttribute(d,i,p);if(void 0!==r.sparse){const s=N.SCALAR,n=P[r.sparse.indices.componentType],l=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,u=new n(t[1],l,r.sparse.count*s),h=new a(t[2],c,r.sparse.count*i);null!==o&&(m=new e.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,n=t.textures[e],r=t.images[n.source];let o=this.textureLoader;if(r.uri){const e=s.manager.getHandler(r.uri);null!==e&&(o=e)}return this.loadTextureImage(e,r,o)}loadTextureImage(t,s,n){const r=this,o=this.json,i=this.options,a=o.textures[t],l=(s.uri||s.bufferView)+":"+a.sampler;if(this.textureCache[l])return this.textureCache[l];const c=self.URL||self.webkitURL;let u=s.uri||"",h=!1,p=!0;const d=u.search(/\.jpe?g($|\?)/i)>0||0===u.search(/^data\:image\/jpeg/);if(("image/jpeg"===s.mimeType||d)&&(p=!1),void 0!==s.bufferView)u=r.getDependency("bufferView",s.bufferView).then((function(e){if("image/png"===s.mimeType){const t=new DataView(e,25,1).getUint8(0,!1);p=6===t||4===t||3===t}h=!0;const t=new Blob([e],{type:s.mimeType});return u=c.createObjectURL(t),u}));else if(void 0===s.uri)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");const m=Promise.resolve(u).then((function(t){return new Promise((function(s,r){let o=s;!0===n.isImageBitmapLoader&&(o=function(t){const n=new e.Texture(t);n.needsUpdate=!0,s(n)}),n.load(B(t,i.path),o,void 0,r)}))})).then((function(s){!0===h&&c.revokeObjectURL(u),s.flipY=!1,a.name&&(s.name=a.name),p||(s.format=e.RGBFormat);const n=(o.samplers||{})[a.sampler]||{};return s.magFilter=C[n.magFilter]||e.LinearFilter,s.minFilter=C[n.minFilter]||e.LinearMipmapLinearFilter,s.wrapS=O[n.wrapS]||e.RepeatWrapping,s.wrapT=O[n.wrapT]||e.RepeatWrapping,r.associations.set(s,{type:"textures",index:t}),s})).catch((function(){return console.error("THREE.GLTFLoader: Couldn't load texture",u),null}));return this.textureCache[l]=m,m}assignTexture(e,t,s){const r=this;return this.getDependency("texture",s.index).then((function(o){if(void 0===s.texCoord||0==s.texCoord||"aoMap"===t&&1==s.texCoord||console.warn("THREE.GLTFLoader: Custom UV set "+s.texCoord+" for texture "+t+" not yet supported."),r.extensions[n.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[n.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=r.associations.get(o);o=r.extensions[n.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),r.associations.set(o,t)}}return e[t]=o,o}))}assignFinalMaterial(t){const s=t.geometry;let n=t.material;const r=void 0!==s.attributes.tangent,o=void 0!==s.attributes.color,i=void 0===s.attributes.normal;if(t.isPoints){const t="PointsMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.PointsMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),s.map=n.map,s.sizeAttenuation=!1,this.cache.add(t,s)),n=s}else if(t.isLine){const t="LineBasicMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.LineBasicMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),this.cache.add(t,s)),n=s}if(r||o||i){let e="ClonedMaterial:"+n.uuid+":";n.isGLTFSpecularGlossinessMaterial&&(e+="specular-glossiness:"),r&&(e+="vertex-tangents:"),o&&(e+="vertex-colors:"),i&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),o&&(t.vertexColors=!0),i&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}n.aoMap&&void 0===s.attributes.uv2&&void 0!==s.attributes.uv&&s.setAttribute("uv2",s.attributes.uv),t.material=n}getMaterialType(){return e.MeshStandardMaterial}loadMaterial(t){const s=this,r=this.json,o=this.extensions,i=r.materials[t];let a;const l={},c=i.extensions||{},u=[];if(c[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){const e=o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];a=e.getMaterialType(),u.push(e.extendParams(l,i,s))}else if(c[n.KHR_MATERIALS_UNLIT]){const e=o[n.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),u.push(e.extendParams(l,i,s))}else{const n=i.pbrMetallicRoughness||{};if(l.color=new e.Color(1,1,1),l.opacity=1,Array.isArray(n.baseColorFactor)){const e=n.baseColorFactor;l.color.fromArray(e),l.opacity=e[3]}void 0!==n.baseColorTexture&&u.push(s.assignTexture(l,"map",n.baseColorTexture)),l.metalness=void 0!==n.metallicFactor?n.metallicFactor:1,l.roughness=void 0!==n.roughnessFactor?n.roughnessFactor:1,void 0!==n.metallicRoughnessTexture&&(u.push(s.assignTexture(l,"metalnessMap",n.metallicRoughnessTexture)),u.push(s.assignTexture(l,"roughnessMap",n.metallicRoughnessTexture))),a=this._invokeOne((function(e){return e.getMaterialType&&e.getMaterialType(t)})),u.push(Promise.all(this._invokeAll((function(e){return e.extendMaterialParams&&e.extendMaterialParams(t,l)}))))}!0===i.doubleSided&&(l.side=e.DoubleSide);const h=i.alphaMode||k;return h===G?(l.transparent=!0,l.depthWrite=!1):(l.transparent=!1,h===D&&(l.alphaTest=void 0!==i.alphaCutoff?i.alphaCutoff:.5)),void 0!==i.normalTexture&&a!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"normalMap",i.normalTexture)),l.normalScale=new e.Vector2(1,-1),void 0!==i.normalTexture.scale&&l.normalScale.set(i.normalTexture.scale,-i.normalTexture.scale)),void 0!==i.occlusionTexture&&a!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"aoMap",i.occlusionTexture)),void 0!==i.occlusionTexture.strength&&(l.aoMapIntensity=i.occlusionTexture.strength)),void 0!==i.emissiveFactor&&a!==e.MeshBasicMaterial&&(l.emissive=(new e.Color).fromArray(i.emissiveFactor)),void 0!==i.emissiveTexture&&a!==e.MeshBasicMaterial&&u.push(s.assignTexture(l,"emissiveMap",i.emissiveTexture)),Promise.all(u).then((function(){let r;return r=a===R?o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(l):new a(l),i.name&&(r.name=i.name),r.map&&(r.map.encoding=e.sRGBEncoding),r.emissiveMap&&(r.emissiveMap.encoding=e.sRGBEncoding),K(r,i),s.associations.set(r,{type:"materials",index:t}),i.extensions&&j(o,r,i),r}))}createUniqueName(t){const s=e.PropertyBinding.sanitizeNodeName(t||"");let n=s;for(let e=1;this.nodeNamesUsed[n];++e)n=s+"_"+e;return this.nodeNamesUsed[n]=!0,n}loadGeometries(t){const s=this,r=this.extensions,o=this.primitiveCache;function i(e){return r[n.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then((function(t){return Q(t,e,s)}))}const a=[];for(let r=0,l=t.length;r<l;r++){const l=t[r],c=X(l),u=o[c];if(u)a.push(u.promise);else{let t;t=l.extensions&&l.extensions[n.KHR_DRACO_MESH_COMPRESSION]?i(l):Q(new e.BufferGeometry,l,s),o[c]={primitive:l,promise:t},a.push(t)}}return Promise.all(a)}loadMesh(t){const s=this,n=this.json,r=this.extensions,o=n.meshes[t],i=o.primitives,a=[];for(let t=0,s=i.length;t<s;t++){const s=void 0===i[t].material?(void 0===(l=this.cache).DefaultMaterial&&(l.DefaultMaterial=new e.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:e.FrontSide})),l.DefaultMaterial):this.getDependency("material",i[t].material);a.push(s)}var l;return a.push(s.loadGeometries(i)),Promise.all(a).then((function(n){const a=n.slice(0,n.length-1),l=n[n.length-1],c=[];for(let n=0,u=l.length;n<u;n++){const u=l[n],h=i[n];let p;const d=a[n];if(h.mode===w||h.mode===b||h.mode===I||void 0===h.mode)p=!0===o.isSkinnedMesh?new e.SkinnedMesh(u,d):new e.Mesh(u,d),!0!==p.isSkinnedMesh||p.geometry.attributes.skinWeight.normalized||p.normalizeSkinWeights(),h.mode===b?p.geometry=J(p.geometry,e.TriangleStripDrawMode):h.mode===I&&(p.geometry=J(p.geometry,e.TriangleFanDrawMode));else if(h.mode===A)p=new e.LineSegments(u,d);else if(h.mode===L)p=new e.Line(u,d);else if(h.mode===E)p=new e.LineLoop(u,d);else{if(h.mode!==_)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+h.mode);p=new e.Points(u,d)}Object.keys(p.geometry.morphAttributes).length>0&&V(p,o),p.name=s.createUniqueName(o.name||"mesh_"+t),K(p,o),h.extensions&&j(r,p,h),s.assignFinalMaterial(p),c.push(p)}if(1===c.length)return c[0];const u=new e.Group;for(let e=0,t=c.length;e<t;e++)u.add(c[e]);return u}))}loadCamera(t){let s;const n=this.json.cameras[t],r=n[n.type];if(r)return"perspective"===n.type?s=new e.PerspectiveCamera(e.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):"orthographic"===n.type&&(s=new e.OrthographicCamera(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(s.name=this.createUniqueName(n.name)),K(s,n),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],s={joints:t.joints};return void 0===t.inverseBindMatrices?Promise.resolve(s):this.getDependency("accessor",t.inverseBindMatrices).then((function(e){return s.inverseBindMatrices=e,s}))}loadAnimation(t){const s=this.json.animations[t],n=[],r=[],o=[],i=[],a=[];for(let e=0,t=s.channels.length;e<t;e++){const t=s.channels[e],l=s.samplers[t.sampler],c=t.target,u=void 0!==c.node?c.node:c.id,h=void 0!==s.parameters?s.parameters[l.input]:l.input,p=void 0!==s.parameters?s.parameters[l.output]:l.output;n.push(this.getDependency("node",u)),r.push(this.getDependency("accessor",h)),o.push(this.getDependency("accessor",p)),i.push(l),a.push(c)}return Promise.all([Promise.all(n),Promise.all(r),Promise.all(o),Promise.all(i),Promise.all(a)]).then((function(n){const r=n[0],o=n[1],i=n[2],a=n[3],l=n[4],c=[];for(let t=0,s=r.length;t<s;t++){const s=r[t],n=o[t],u=i[t],h=a[t],p=l[t];if(void 0===s)continue;let d;switch(s.updateMatrix(),s.matrixAutoUpdate=!0,H[p.path]){case H.weights:d=e.NumberKeyframeTrack;break;case H.rotation:d=e.QuaternionKeyframeTrack;break;case H.position:case H.scale:default:d=e.VectorKeyframeTrack}const m=s.name?s.name:s.uuid,f=void 0!==h.interpolation?U[h.interpolation]:e.InterpolateLinear,g=[];H[p.path]===H.weights?s.traverse((function(e){!0===e.isMesh&&e.morphTargetInfluences&&g.push(e.name?e.name:e.uuid)})):g.push(m);let T=u.array;if(u.normalized){const e=z(T.constructor),t=new Float32Array(T.length);for(let s=0,n=T.length;s<n;s++)t[s]=T[s]*e;T=t}for(let e=0,t=g.length;e<t;e++){const t=new d(g[e]+"."+H[p.path],n.array,T,f);"CUBICSPLINE"===h.interpolation&&(t.createInterpolant=function(e){return new S(this.times,this.values,this.getValueSize()/3,e)},t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),c.push(t)}}const u=s.name?s.name:"animation_"+t;return new e.AnimationClip(u,void 0,c)}))}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return void 0===n.mesh?null:s.getDependency("mesh",n.mesh).then((function(e){const t=s._getNodeRef(s.meshCache,n.mesh,e);return void 0!==n.weights&&t.traverse((function(e){if(e.isMesh)for(let t=0,s=n.weights.length;t<s;t++)e.morphTargetInfluences[t]=n.weights[t]})),t}))}loadNode(t){const s=this.json,n=this.extensions,r=this,o=s.nodes[t],i=o.name?r.createUniqueName(o.name):"";return function(){const e=[],s=r._invokeOne((function(e){return e.createNodeMesh&&e.createNodeMesh(t)}));return s&&e.push(s),void 0!==o.camera&&e.push(r.getDependency("camera",o.camera).then((function(e){return r._getNodeRef(r.cameraCache,o.camera,e)}))),r._invokeAll((function(e){return e.createNodeAttachment&&e.createNodeAttachment(t)})).forEach((function(t){e.push(t)})),Promise.all(e)}().then((function(s){let a;if(a=!0===o.isBone?new e.Bone:s.length>1?new e.Group:1===s.length?s[0]:new e.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(n,a,o),void 0!==o.matrix){const t=new e.Matrix4;t.fromArray(o.matrix),a.applyMatrix4(t)}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 r.associations.set(a,{type:"nodes",index:t}),a}))}loadScene(t){const s=this.json,n=this.extensions,r=this.json.scenes[t],o=this,i=new e.Group;r.name&&(i.name=o.createUniqueName(r.name)),K(i,r),r.extensions&&j(n,i,r);const a=r.nodes||[],l=[];for(let e=0,t=a.length;e<t;e++)l.push(Y(a[e],i,s,o));return Promise.all(l).then((function(){return i}))}}function Y(t,s,n,r){const o=n.nodes[t];return r.getDependency("node",t).then((function(t){if(void 0===o.skin)return t;let s;return r.getDependency("skin",o.skin).then((function(e){s=e;const t=[];for(let e=0,n=s.joints.length;e<n;e++)t.push(r.getDependency("node",s.joints[e]));return Promise.all(t)})).then((function(n){return t.traverse((function(t){if(!t.isMesh)return;const r=[],o=[];for(let t=0,i=n.length;t<i;t++){const i=n[t];if(i){r.push(i);const n=new e.Matrix4;void 0!==s.inverseBindMatrices&&n.fromArray(s.inverseBindMatrices.array,16*t),o.push(n)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[t])}t.bind(new e.Skeleton(r,o),t.matrixWorld)})),t}))})).then((function(e){s.add(e);const t=[];if(o.children){const s=o.children;for(let o=0,i=s.length;o<i;o++){const i=s[o];t.push(Y(i,e,n,r))}}return Promise.all(t)}))}function Q(t,s,n){const r=s.attributes,o=[];function i(e,s){return n.getDependency("accessor",e).then((function(e){t.setAttribute(s,e)}))}for(const e in r){const s=F[e]||e.toLowerCase();s in t.attributes||o.push(i(r[e],s))}if(void 0!==s.indices&&!t.index){const e=n.getDependency("accessor",s.indices).then((function(e){t.setIndex(e)}));o.push(e)}return K(t,s),function(t,s,n){const r=s.attributes,o=new e.Box3;if(void 0===r.POSITION)return;{const t=n.json.accessors[r.POSITION],s=t.min,i=t.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 e.Vector3(s[0],s[1],s[2]),new e.Vector3(i[0],i[1],i[2])),t.normalized){const e=z(P[t.componentType]);o.min.multiplyScalar(e),o.max.multiplyScalar(e)}}const i=s.targets;if(void 0!==i){const t=new e.Vector3,s=new e.Vector3;for(let e=0,r=i.length;e<r;e++){const r=i[e];if(void 0!==r.POSITION){const e=n.json.accessors[r.POSITION],o=e.min,i=e.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]))),e.normalized){const t=z(P[e.componentType]);s.multiplyScalar(t)}t.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}o.expandByVector(t)}t.boundingBox=o;const a=new e.Sphere;o.getCenter(a.center),a.radius=o.min.distanceTo(o.max)/2,t.boundingSphere=a}(t,s,n),Promise.all(o).then((function(){return void 0!==s.targets?function(e,t,s){let n=!1,r=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(n=!0),void 0!==s.NORMAL&&(r=!0),n&&r)break}if(!n&&!r)return Promise.resolve(e);const o=[],i=[];for(let a=0,l=t.length;a<l;a++){const l=t[a];if(n){const t=void 0!==l.POSITION?s.getDependency("accessor",l.POSITION):e.attributes.position;o.push(t)}if(r){const t=void 0!==l.NORMAL?s.getDependency("accessor",l.NORMAL):e.attributes.normal;i.push(t)}}return Promise.all([Promise.all(o),Promise.all(i)]).then((function(t){const s=t[0],o=t[1];return n&&(e.morphAttributes.position=s),r&&(e.morphAttributes.normal=o),e.morphTargetsRelative=!0,e}))}(t,s.targets,n):t}))}function J(t,s){let n=t.getIndex();if(null===n){const e=[],s=t.getAttribute("position");if(void 0===s)return console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),t;for(let t=0;t<s.count;t++)e.push(t);t.setIndex(e),n=t.getIndex()}const r=n.count-2,o=[];if(s===e.TriangleFanDrawMode)for(let e=1;e<=r;e++)o.push(n.getX(0)),o.push(n.getX(e)),o.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(o.push(n.getX(e)),o.push(n.getX(e+1)),o.push(n.getX(e+2))):(o.push(n.getX(e+2)),o.push(n.getX(e+1)),o.push(n.getX(e)));o.length/3!==r&&console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=t.clone();return i.setIndex(o),i}exports.GLTFLoader=t;
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new a(e)})),this.register((function(e){return new p(e)})),this.register((function(e){return new d(e)})),this.register((function(e){return new i(e)})),this.register((function(e){return new l(e)})),this.register((function(e){return new c(e)})),this.register((function(e){return new u(e)})),this.register((function(e){return new h(e)})),this.register((function(e){return new r(e)})),this.register((function(e){return new m(e)}))}load(t,s,n,r){const o=this;let a;a=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:e.LoaderUtils.extractUrlBase(t),this.manager.itemStart(t);const i=function(e){r?r(e):console.error(e),o.manager.itemError(t),o.manager.itemEnd(t)},l=new e.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(t,(function(e){try{o.parse(e,a,(function(e){s(e),o.manager.itemEnd(t)}),i)}catch(e){i(e)}}),n,i)}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(t,s,r,a){let i;const l={},c={};if("string"==typeof t)i=t;else{if(e.LoaderUtils.decodeText(new Uint8Array(t,0,4))===f){try{l[n.KHR_BINARY_GLTF]=new x(t)}catch(e){return void(a&&a(e))}i=l[n.KHR_BINARY_GLTF].content}else i=e.LoaderUtils.decodeText(new Uint8Array(t))}const u=JSON.parse(i);if(void 0===u.asset||u.asset.version[0]<2)return void(a&&a(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const h=new Y(u,{path:s||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});h.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](h);c[t.name]=t,l[t.name]=!0}if(u.extensionsUsed)for(let e=0;e<u.extensionsUsed.length;++e){const t=u.extensionsUsed[e],s=u.extensionsRequired||[];switch(t){case n.KHR_MATERIALS_UNLIT:l[t]=new o;break;case n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:l[t]=new S;break;case n.KHR_DRACO_MESH_COMPRESSION:l[t]=new M(u,this.dracoLoader);break;case n.KHR_TEXTURE_TRANSFORM:l[t]=new R;break;case n.KHR_MESH_QUANTIZATION:l[t]=new _;break;default:s.indexOf(t)>=0&&void 0===c[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}h.setExtensions(l),h.setPlugins(c),h.parse(r,a)}parseAsync(e,t){const s=this;return new Promise((function(n,r){s.parse(e,t,n,r)}))}}function s(){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 n={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_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",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",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression"};class r{constructor(e){this.parser=e,this.name=n.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s];n.extensions&&n.extensions[this.name]&&void 0!==n.extensions[this.name].light&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(t){const s=this.parser,n="light:"+t;let r=s.cache.get(n);if(r)return r;const o=s.json,a=((o.extensions&&o.extensions[this.name]||{}).lights||[])[t];let i;const l=new e.Color(16777215);void 0!==a.color&&l.fromArray(a.color);const c=void 0!==a.range?a.range:0;switch(a.type){case"directional":i=new e.DirectionalLight(l),i.target.position.set(0,0,-1),i.add(i.target);break;case"point":i=new e.PointLight(l),i.distance=c;break;case"spot":i=new e.SpotLight(l),i.distance=c,a.spot=a.spot||{},a.spot.innerConeAngle=void 0!==a.spot.innerConeAngle?a.spot.innerConeAngle:0,a.spot.outerConeAngle=void 0!==a.spot.outerConeAngle?a.spot.outerConeAngle:Math.PI/4,i.angle=a.spot.outerConeAngle,i.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,i.target.position.set(0,0,-1),i.add(i.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+a.type)}return i.position.set(0,0,0),i.decay=2,void 0!==a.intensity&&(i.intensity=a.intensity),i.name=s.createUniqueName(a.name||"light_"+t),r=Promise.resolve(i),s.cache.add(n,r),r}createNodeAttachment(e){const t=this,s=this.parser,n=s.json.nodes[e],r=(n.extensions&&n.extensions[this.name]||{}).light;return void 0===r?null:this._loadLight(r).then((function(e){return s._getNodeRef(t.cache,r,e)}))}}class o{constructor(){this.name=n.KHR_MATERIALS_UNLIT}getMaterialType(){return e.MeshBasicMaterial}extendParams(t,s,n){const r=[];t.color=new e.Color(1,1,1),t.opacity=1;const o=s.pbrMetallicRoughness;if(o){if(Array.isArray(o.baseColorFactor)){const e=o.baseColorFactor;t.color.fromArray(e),t.opacity=e[3]}void 0!==o.baseColorTexture&&r.push(n.assignTexture(t,"map",o.baseColorTexture))}return Promise.all(r)}}class a{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],a=r.extensions[this.name];if(void 0!==a.clearcoatFactor&&(s.clearcoat=a.clearcoatFactor),void 0!==a.clearcoatTexture&&o.push(n.assignTexture(s,"clearcoatMap",a.clearcoatTexture)),void 0!==a.clearcoatRoughnessFactor&&(s.clearcoatRoughness=a.clearcoatRoughnessFactor),void 0!==a.clearcoatRoughnessTexture&&o.push(n.assignTexture(s,"clearcoatRoughnessMap",a.clearcoatRoughnessTexture)),void 0!==a.clearcoatNormalTexture&&(o.push(n.assignTexture(s,"clearcoatNormalMap",a.clearcoatNormalTexture)),void 0!==a.clearcoatNormalTexture.scale)){const t=a.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new e.Vector2(t,t)}return Promise.all(o)}}class i{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SHEEN}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[];s.sheenColor=new e.Color(0,0,0),s.sheenRoughness=0,s.sheen=1;const a=r.extensions[this.name];return void 0!==a.sheenColorFactor&&s.sheenColor.fromArray(a.sheenColorFactor),void 0!==a.sheenRoughnessFactor&&(s.sheenRoughness=a.sheenRoughnessFactor),void 0!==a.sheenColorTexture&&o.push(n.assignTexture(s,"sheenColorMap",a.sheenColorTexture)),void 0!==a.sheenRoughnessTexture&&o.push(n.assignTexture(s,"sheenRoughnessMap",a.sheenRoughnessTexture)),Promise.all(o)}}class l{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return void 0!==o.transmissionFactor&&(t.transmission=o.transmissionFactor),void 0!==o.transmissionTexture&&r.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(r)}}class c{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_VOLUME}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],a=r.extensions[this.name];s.thickness=void 0!==a.thicknessFactor?a.thicknessFactor:0,void 0!==a.thicknessTexture&&o.push(n.assignTexture(s,"thicknessMap",a.thicknessTexture)),s.attenuationDistance=a.attenuationDistance||0;const i=a.attenuationColor||[1,1,1];return s.attenuationColor=new e.Color(i[0],i[1],i[2]),Promise.all(o)}}class u{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_IOR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=s.extensions[this.name];return t.ior=void 0!==n.ior?n.ior:1.5,Promise.resolve()}}class h{constructor(e){this.parser=e,this.name=n.KHR_MATERIALS_SPECULAR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const n=this.parser,r=n.json.materials[t];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const o=[],a=r.extensions[this.name];s.specularIntensity=void 0!==a.specularFactor?a.specularFactor:1,void 0!==a.specularTexture&&o.push(n.assignTexture(s,"specularIntensityMap",a.specularTexture));const i=a.specularColorFactor||[1,1,1];return s.specularColor=new e.Color(i[0],i[1],i[2]),void 0!==a.specularColorTexture&&o.push(n.assignTexture(s,"specularColorMap",a.specularColorTexture).then((function(t){t.encoding=e.sRGBEncoding}))),Promise.all(o)}}class p{constructor(e){this.parser=e,this.name=n.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const r=n.extensions[this.name],o=s.images[r.source],a=t.options.ktx2Loader;if(!a){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,o,a)}}class d{constructor(e){this.parser=e,this.name=n.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,r=n.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],a=n.images[o.source];let i=s.textureLoader;if(a.uri){const e=s.options.manager.getHandler(a.uri);null!==e&&(i=e)}return this.detectSupport().then((function(r){if(r)return s.loadTextureImage(e,a,i);if(n.extensionsRequired&&n.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 m{constructor(e){this.name=n.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],n=this.parser.getDependency("buffer",e.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.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 Promise.all([n,r.ready]).then((function(t){const s=e.byteOffset||0,n=e.byteLength||0,o=e.count,a=e.byteStride,i=new ArrayBuffer(o*a),l=new Uint8Array(t[0],s,n);return r.decodeGltfBuffer(new Uint8Array(i),o,a,l,e.mode,e.filter),i}))}return null}}const f="glTF",g=1313821514,T=5130562;class x{constructor(t){this.name=n.KHR_BINARY_GLTF,this.content=null,this.body=null;const s=new DataView(t,0,12);if(this.header={magic:e.LoaderUtils.decodeText(new Uint8Array(t.slice(0,4))),version:s.getUint32(4,!0),length:s.getUint32(8,!0)},this.header.magic!==f)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,o=new DataView(t,12);let a=0;for(;a<r;){const s=o.getUint32(a,!0);a+=4;const n=o.getUint32(a,!0);if(a+=4,n===g){const n=new Uint8Array(t,12+a,s);this.content=e.LoaderUtils.decodeText(n)}else if(n===T){const e=12+a;this.body=t.slice(e,e+s)}a+=s}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class M{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=n.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,r=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},i={},l={};for(const e in o){const t=k[e]||e.toLowerCase();a[t]=o[e]}for(const t in e.attributes){const n=k[t]||t.toLowerCase();if(void 0!==o[t]){const r=s.accessors[e.attributes[t]],o=N[r.componentType];l[n]=o,i[n]=!0===r.normalized}}return t.getDependency("bufferView",r).then((function(e){return new Promise((function(t){n.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],n=i[t];void 0!==n&&(s.normalized=n)}t(e)}),a,l)}))}))}}class R{constructor(){this.name=n.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&console.warn('THREE.GLTFLoader: Custom UV sets in "'+this.name+'" extension not yet supported.'),void 0===t.offset&&void 0===t.rotation&&void 0===t.scale||(e=e.clone(),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}}class v extends e.MeshStandardMaterial{constructor(t){super(),this.isGLTFSpecularGlossinessMaterial=!0;const s=["#ifdef USE_SPECULARMAP","\tuniform sampler2D specularMap;","#endif"].join("\n"),n=["#ifdef USE_GLOSSINESSMAP","\tuniform sampler2D glossinessMap;","#endif"].join("\n"),r=["vec3 specularFactor = specular;","#ifdef USE_SPECULARMAP","\tvec4 texelSpecular = texture2D( specularMap, vUv );","\ttexelSpecular = sRGBToLinear( texelSpecular );","\t// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture","\tspecularFactor *= texelSpecular.rgb;","#endif"].join("\n"),o=["float glossinessFactor = glossiness;","#ifdef USE_GLOSSINESSMAP","\tvec4 texelGlossiness = texture2D( glossinessMap, vUv );","\t// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture","\tglossinessFactor *= texelGlossiness.a;","#endif"].join("\n"),a=["PhysicalMaterial material;","material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );","vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );","material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.specularColor = specularFactor;"].join("\n"),i={specular:{value:(new e.Color).setHex(16777215)},glossiness:{value:1},specularMap:{value:null},glossinessMap:{value:null}};this._extraUniforms=i,this.onBeforeCompile=function(e){for(const t in i)e.uniforms[t]=i[t];e.fragmentShader=e.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>",s).replace("#include <metalnessmap_pars_fragment>",n).replace("#include <roughnessmap_fragment>",r).replace("#include <metalnessmap_fragment>",o).replace("#include <lights_physical_fragment>",a)},Object.defineProperties(this,{specular:{get:function(){return i.specular.value},set:function(e){i.specular.value=e}},specularMap:{get:function(){return i.specularMap.value},set:function(e){i.specularMap.value=e,e?this.defines.USE_SPECULARMAP="":delete this.defines.USE_SPECULARMAP}},glossiness:{get:function(){return i.glossiness.value},set:function(e){i.glossiness.value=e}},glossinessMap:{get:function(){return i.glossinessMap.value},set:function(e){i.glossinessMap.value=e,e?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_UV=""):(delete this.defines.USE_GLOSSINESSMAP,delete this.defines.USE_UV)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(t)}copy(e){return super.copy(e),this.specularMap=e.specularMap,this.specular.copy(e.specular),this.glossinessMap=e.glossinessMap,this.glossiness=e.glossiness,delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this}}class S{constructor(){this.name=n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,this.specularGlossinessParams=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","normalMapType","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity","refractionRatio"]}getMaterialType(){return v}extendParams(t,s,n){const r=s.extensions[this.name];t.color=new e.Color(1,1,1),t.opacity=1;const o=[];if(Array.isArray(r.diffuseFactor)){const e=r.diffuseFactor;t.color.fromArray(e),t.opacity=e[3]}if(void 0!==r.diffuseTexture&&o.push(n.assignTexture(t,"map",r.diffuseTexture)),t.emissive=new e.Color(0,0,0),t.glossiness=void 0!==r.glossinessFactor?r.glossinessFactor:1,t.specular=new e.Color(1,1,1),Array.isArray(r.specularFactor)&&t.specular.fromArray(r.specularFactor),void 0!==r.specularGlossinessTexture){const e=r.specularGlossinessTexture;o.push(n.assignTexture(t,"glossinessMap",e)),o.push(n.assignTexture(t,"specularMap",e))}return Promise.all(o)}createMaterial(t){const s=new v(t);return s.fog=!0,s.color=t.color,s.map=void 0===t.map?null:t.map,s.lightMap=null,s.lightMapIntensity=1,s.aoMap=void 0===t.aoMap?null:t.aoMap,s.aoMapIntensity=1,s.emissive=t.emissive,s.emissiveIntensity=1,s.emissiveMap=void 0===t.emissiveMap?null:t.emissiveMap,s.bumpMap=void 0===t.bumpMap?null:t.bumpMap,s.bumpScale=1,s.normalMap=void 0===t.normalMap?null:t.normalMap,s.normalMapType=e.TangentSpaceNormalMap,t.normalScale&&(s.normalScale=t.normalScale),s.displacementMap=null,s.displacementScale=1,s.displacementBias=0,s.specularMap=void 0===t.specularMap?null:t.specularMap,s.specular=t.specular,s.glossinessMap=void 0===t.glossinessMap?null:t.glossinessMap,s.glossiness=t.glossiness,s.alphaMap=null,s.envMap=void 0===t.envMap?null:t.envMap,s.envMapIntensity=1,s.refractionRatio=.98,s}}class _{constructor(){this.name=n.KHR_MESH_QUANTIZATION}}class y extends e.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,r=e*n*3+n;for(let e=0;e!==n;e++)t[e]=s[r+e];return t}}y.prototype.beforeStart_=y.prototype.copySampleValue_,y.prototype.afterEnd_=y.prototype.copySampleValue_,y.prototype.interpolate_=function(e,t,s,n){const r=this.resultBuffer,o=this.sampleValues,a=this.valueSize,i=2*a,l=3*a,c=n-t,u=(s-t)/c,h=u*u,p=h*u,d=e*l,m=d-l,f=-2*p+3*h,g=p-h,T=1-f,x=g-h+u;for(let e=0;e!==a;e++){const t=o[m+e+a],s=o[m+e+i]*c,n=o[d+e+a],l=o[d+e]*c;r[e]=T*t+x*s+f*n+g*l}return r};const A=new e.Quaternion;class E extends y{interpolate_(e,t,s,n){const r=super.interpolate_(e,t,s,n);return A.fromArray(r).normalize().toArray(r),r}}const L=0,w=1,b=2,P=3,I=4,C=5,O=6,N={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},F={9728:e.NearestFilter,9729:e.LinearFilter,9984:e.NearestMipmapNearestFilter,9985:e.LinearMipmapNearestFilter,9986:e.NearestMipmapLinearFilter,9987:e.LinearMipmapLinearFilter},H={33071:e.ClampToEdgeWrapping,33648:e.MirroredRepeatWrapping,10497:e.RepeatWrapping},U={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},k={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},D={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},G={CUBICSPLINE:void 0,LINEAR:e.InterpolateLinear,STEP:e.InterpolateDiscrete},B="OPAQUE",K="MASK",j="BLEND";function V(e,t,s){for(const n in s.extensions)void 0===e[n]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[n]=s.extensions[n])}function X(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 q(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let s=0,n=t.weights.length;s<n;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,n=s.length;t<n;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function z(e){const t=e.extensions&&e.extensions[n.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 n=0,r=s.length;n<r;n++)t+=s[n]+":"+e[s[n]]+";";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.")}}class Y{constructor(t={},n={}){this.json=t,this.extensions={},this.plugins={},this.options=n,this.cache=new s,this.associations=new Map,this.primitiveCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.textureCache={},this.nodeNamesUsed={},"undefined"!=typeof createImageBitmap&&!1===/Firefox|Safari/.test(navigator.userAgent)?this.textureLoader=new e.ImageBitmapLoader(this.options.manager):this.textureLoader=new e.TextureLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new e.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,n=this.json,r=this.extensions;this.cache.removeAll(),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][n.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:n.asset,parser:s,userData:{}};V(r,o,n),X(o,n),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,n=t.length;s<n;s++){const n=t[s].joints;for(let t=0,s=n.length;t<s;t++)e[n[t]].isBone=!0}for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0!==n.mesh&&(this._addNodeRef(this.meshCache,n.mesh),void 0!==n.skin&&(s[n.mesh].isSkinnedMesh=!0)),void 0!==n.camera&&this._addNodeRef(this.cameraCache,n.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 n=s.clone(),r=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,n]of e.children.entries())r(n,t.children[s])};return r(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const r=e(t[n]);r&&s.push(r)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this.loadNode(t);break;case"mesh":n=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":n=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":n=this.loadSkin(t);break;case"animation":n=this.loadAnimation(t);break;case"camera":n=this.loadCamera(t);break;default:throw new Error("Unknown type: "+e)}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(n.map((function(t,n){return s.getDependency(e,n)}))),this.cache.add(e,t)}return t}loadBuffer(t){const s=this.json.buffers[t],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===t)return Promise.resolve(this.extensions[n.KHR_BINARY_GLTF].body);const o=this.options;return new Promise((function(t,n){r.load(e.LoaderUtils.resolveURL(s.uri,o.path),t,void 0,(function(){n(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,n=t.byteOffset||0;return e.slice(n,n+s)}))}loadAccessor(t){const s=this,n=this.json,r=this.json.accessors[t];if(void 0===r.bufferView&&void 0===r.sparse)return Promise.resolve(null);const o=[];return void 0!==r.bufferView?o.push(this.getDependency("bufferView",r.bufferView)):o.push(null),void 0!==r.sparse&&(o.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),o.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(o).then((function(t){const o=t[0],a=U[r.type],i=N[r.componentType],l=i.BYTES_PER_ELEMENT,c=l*a,u=r.byteOffset||0,h=void 0!==r.bufferView?n.bufferViews[r.bufferView].byteStride:void 0,p=!0===r.normalized;let d,m;if(h&&h!==c){const t=Math.floor(u/h),n="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+t+":"+r.count;let c=s.cache.get(n);c||(d=new i(o,t*h,r.count*h/l),c=new e.InterleavedBuffer(d,h/l),s.cache.add(n,c)),m=new e.InterleavedBufferAttribute(c,a,u%h/l,p)}else d=null===o?new i(r.count*a):new i(o,u,r.count*a),m=new e.BufferAttribute(d,a,p);if(void 0!==r.sparse){const s=U.SCALAR,n=N[r.sparse.indices.componentType],l=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,u=new n(t[1],l,r.sparse.count*s),h=new i(t[2],c,r.sparse.count*a);null!==o&&(m=new e.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*a]),a>=2&&m.setY(t,h[e*a+1]),a>=3&&m.setZ(t,h[e*a+2]),a>=4&&m.setW(t,h[e*a+3]),a>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return m}))}loadTexture(e){const t=this.json,s=this.options,n=t.textures[e],r=t.images[n.source];let o=this.textureLoader;if(r.uri){const e=s.manager.getHandler(r.uri);null!==e&&(o=e)}return this.loadTextureImage(e,r,o)}loadTextureImage(t,s,n){const r=this,o=this.json,a=this.options,i=o.textures[t],l=(s.uri||s.bufferView)+":"+i.sampler;if(this.textureCache[l])return this.textureCache[l];const c=self.URL||self.webkitURL;let u=s.uri||"",h=!1;if(void 0!==s.bufferView)u=r.getDependency("bufferView",s.bufferView).then((function(e){h=!0;const t=new Blob([e],{type:s.mimeType});return u=c.createObjectURL(t),u}));else if(void 0===s.uri)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");const p=Promise.resolve(u).then((function(t){return new Promise((function(s,r){let o=s;!0===n.isImageBitmapLoader&&(o=function(t){const n=new e.Texture(t);n.needsUpdate=!0,s(n)}),n.load(e.LoaderUtils.resolveURL(t,a.path),o,void 0,r)}))})).then((function(s){!0===h&&c.revokeObjectURL(u),s.flipY=!1,i.name&&(s.name=i.name);const n=(o.samplers||{})[i.sampler]||{};return s.magFilter=F[n.magFilter]||e.LinearFilter,s.minFilter=F[n.minFilter]||e.LinearMipmapLinearFilter,s.wrapS=H[n.wrapS]||e.RepeatWrapping,s.wrapT=H[n.wrapT]||e.RepeatWrapping,r.associations.set(s,{textures:t}),s})).catch((function(){return console.error("THREE.GLTFLoader: Couldn't load texture",u),null}));return this.textureCache[l]=p,p}assignTexture(e,t,s){const r=this;return this.getDependency("texture",s.index).then((function(o){if(void 0===s.texCoord||0==s.texCoord||"aoMap"===t&&1==s.texCoord||console.warn("THREE.GLTFLoader: Custom UV set "+s.texCoord+" for texture "+t+" not yet supported."),r.extensions[n.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[n.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=r.associations.get(o);o=r.extensions[n.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),r.associations.set(o,t)}}return e[t]=o,o}))}assignFinalMaterial(t){const s=t.geometry;let n=t.material;const r=void 0===s.attributes.tangent,o=void 0!==s.attributes.color,a=void 0===s.attributes.normal;if(t.isPoints){const t="PointsMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.PointsMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),s.map=n.map,s.sizeAttenuation=!1,this.cache.add(t,s)),n=s}else if(t.isLine){const t="LineBasicMaterial:"+n.uuid;let s=this.cache.get(t);s||(s=new e.LineBasicMaterial,e.Material.prototype.copy.call(s,n),s.color.copy(n.color),this.cache.add(t,s)),n=s}if(r||o||a){let e="ClonedMaterial:"+n.uuid+":";n.isGLTFSpecularGlossinessMaterial&&(e+="specular-glossiness:"),r&&(e+="derivative-tangents:"),o&&(e+="vertex-colors:"),a&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),o&&(t.vertexColors=!0),a&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}n.aoMap&&void 0===s.attributes.uv2&&void 0!==s.attributes.uv&&s.setAttribute("uv2",s.attributes.uv),t.material=n}getMaterialType(){return e.MeshStandardMaterial}loadMaterial(t){const s=this,r=this.json,o=this.extensions,a=r.materials[t];let i;const l={},c=a.extensions||{},u=[];if(c[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){const e=o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];i=e.getMaterialType(),u.push(e.extendParams(l,a,s))}else if(c[n.KHR_MATERIALS_UNLIT]){const e=o[n.KHR_MATERIALS_UNLIT];i=e.getMaterialType(),u.push(e.extendParams(l,a,s))}else{const n=a.pbrMetallicRoughness||{};if(l.color=new e.Color(1,1,1),l.opacity=1,Array.isArray(n.baseColorFactor)){const e=n.baseColorFactor;l.color.fromArray(e),l.opacity=e[3]}void 0!==n.baseColorTexture&&u.push(s.assignTexture(l,"map",n.baseColorTexture)),l.metalness=void 0!==n.metallicFactor?n.metallicFactor:1,l.roughness=void 0!==n.roughnessFactor?n.roughnessFactor:1,void 0!==n.metallicRoughnessTexture&&(u.push(s.assignTexture(l,"metalnessMap",n.metallicRoughnessTexture)),u.push(s.assignTexture(l,"roughnessMap",n.metallicRoughnessTexture))),i=this._invokeOne((function(e){return e.getMaterialType&&e.getMaterialType(t)})),u.push(Promise.all(this._invokeAll((function(e){return e.extendMaterialParams&&e.extendMaterialParams(t,l)}))))}!0===a.doubleSided&&(l.side=e.DoubleSide);const h=a.alphaMode||B;if(h===j?(l.transparent=!0,l.depthWrite=!1):(l.format=e.RGBFormat,l.transparent=!1,h===K&&(l.alphaTest=void 0!==a.alphaCutoff?a.alphaCutoff:.5)),void 0!==a.normalTexture&&i!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"normalMap",a.normalTexture)),l.normalScale=new e.Vector2(1,1),void 0!==a.normalTexture.scale)){const e=a.normalTexture.scale;l.normalScale.set(e,e)}return void 0!==a.occlusionTexture&&i!==e.MeshBasicMaterial&&(u.push(s.assignTexture(l,"aoMap",a.occlusionTexture)),void 0!==a.occlusionTexture.strength&&(l.aoMapIntensity=a.occlusionTexture.strength)),void 0!==a.emissiveFactor&&i!==e.MeshBasicMaterial&&(l.emissive=(new e.Color).fromArray(a.emissiveFactor)),void 0!==a.emissiveTexture&&i!==e.MeshBasicMaterial&&u.push(s.assignTexture(l,"emissiveMap",a.emissiveTexture)),Promise.all(u).then((function(){let r;return r=i===v?o[n.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(l):new i(l),a.name&&(r.name=a.name),r.map&&(r.map.encoding=e.sRGBEncoding),r.emissiveMap&&(r.emissiveMap.encoding=e.sRGBEncoding),X(r,a),s.associations.set(r,{materials:t}),a.extensions&&V(o,r,a),r}))}createUniqueName(t){const s=e.PropertyBinding.sanitizeNodeName(t||"");let n=s;for(let e=1;this.nodeNamesUsed[n];++e)n=s+"_"+e;return this.nodeNamesUsed[n]=!0,n}loadGeometries(t){const s=this,r=this.extensions,o=this.primitiveCache;function a(e){return r[n.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then((function(t){return Z(t,e,s)}))}const i=[];for(let r=0,l=t.length;r<l;r++){const l=t[r],c=z(l),u=o[c];if(u)i.push(u.promise);else{let t;t=l.extensions&&l.extensions[n.KHR_DRACO_MESH_COMPRESSION]?a(l):Z(new e.BufferGeometry,l,s),o[c]={primitive:l,promise:t},i.push(t)}}return Promise.all(i)}loadMesh(t){const s=this,n=this.json,r=this.extensions,o=n.meshes[t],a=o.primitives,i=[];for(let t=0,s=a.length;t<s;t++){const s=void 0===a[t].material?(void 0===(l=this.cache).DefaultMaterial&&(l.DefaultMaterial=new e.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:e.FrontSide})),l.DefaultMaterial):this.getDependency("material",a[t].material);i.push(s)}var l;return i.push(s.loadGeometries(a)),Promise.all(i).then((function(n){const i=n.slice(0,n.length-1),l=n[n.length-1],c=[];for(let n=0,u=l.length;n<u;n++){const u=l[n],h=a[n];let p;const d=i[n];if(h.mode===I||h.mode===C||h.mode===O||void 0===h.mode)p=!0===o.isSkinnedMesh?new e.SkinnedMesh(u,d):new e.Mesh(u,d),!0!==p.isSkinnedMesh||p.geometry.attributes.skinWeight.normalized||p.normalizeSkinWeights(),h.mode===C?p.geometry=$(p.geometry,e.TriangleStripDrawMode):h.mode===O&&(p.geometry=$(p.geometry,e.TriangleFanDrawMode));else if(h.mode===w)p=new e.LineSegments(u,d);else if(h.mode===P)p=new e.Line(u,d);else if(h.mode===b)p=new e.LineLoop(u,d);else{if(h.mode!==L)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+h.mode);p=new e.Points(u,d)}Object.keys(p.geometry.morphAttributes).length>0&&q(p,o),p.name=s.createUniqueName(o.name||"mesh_"+t),X(p,o),h.extensions&&V(r,p,h),s.assignFinalMaterial(p),c.push(p)}for(let e=0,n=c.length;e<n;e++)s.associations.set(c[e],{meshes:t,primitives:e});if(1===c.length)return c[0];const u=new e.Group;s.associations.set(u,{meshes:t});for(let e=0,t=c.length;e<t;e++)u.add(c[e]);return u}))}loadCamera(t){let s;const n=this.json.cameras[t],r=n[n.type];if(r)return"perspective"===n.type?s=new e.PerspectiveCamera(e.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):"orthographic"===n.type&&(s=new e.OrthographicCamera(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(s.name=this.createUniqueName(n.name)),X(s,n),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],s={joints:t.joints};return void 0===t.inverseBindMatrices?Promise.resolve(s):this.getDependency("accessor",t.inverseBindMatrices).then((function(e){return s.inverseBindMatrices=e,s}))}loadAnimation(t){const s=this.json.animations[t],n=[],r=[],o=[],a=[],i=[];for(let e=0,t=s.channels.length;e<t;e++){const t=s.channels[e],l=s.samplers[t.sampler],c=t.target,u=void 0!==c.node?c.node:c.id,h=void 0!==s.parameters?s.parameters[l.input]:l.input,p=void 0!==s.parameters?s.parameters[l.output]:l.output;n.push(this.getDependency("node",u)),r.push(this.getDependency("accessor",h)),o.push(this.getDependency("accessor",p)),a.push(l),i.push(c)}return Promise.all([Promise.all(n),Promise.all(r),Promise.all(o),Promise.all(a),Promise.all(i)]).then((function(n){const r=n[0],o=n[1],a=n[2],i=n[3],l=n[4],c=[];for(let t=0,s=r.length;t<s;t++){const s=r[t],n=o[t],u=a[t],h=i[t],p=l[t];if(void 0===s)continue;let d;switch(s.updateMatrix(),s.matrixAutoUpdate=!0,D[p.path]){case D.weights:d=e.NumberKeyframeTrack;break;case D.rotation:d=e.QuaternionKeyframeTrack;break;case D.position:case D.scale:default:d=e.VectorKeyframeTrack}const m=s.name?s.name:s.uuid,f=void 0!==h.interpolation?G[h.interpolation]:e.InterpolateLinear,g=[];D[p.path]===D.weights?s.traverse((function(e){e.morphTargetInfluences&&g.push(e.name?e.name:e.uuid)})):g.push(m);let T=u.array;if(u.normalized){const e=Q(T.constructor),t=new Float32Array(T.length);for(let s=0,n=T.length;s<n;s++)t[s]=T[s]*e;T=t}for(let t=0,s=g.length;t<s;t++){const s=new d(g[t]+"."+D[p.path],n.array,T,f);"CUBICSPLINE"===h.interpolation&&(s.createInterpolant=function(t){return new(this instanceof e.QuaternionKeyframeTrack?E:y)(this.times,this.values,this.getValueSize()/3,t)},s.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),c.push(s)}}const u=s.name?s.name:"animation_"+t;return new e.AnimationClip(u,void 0,c)}))}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return void 0===n.mesh?null:s.getDependency("mesh",n.mesh).then((function(e){const t=s._getNodeRef(s.meshCache,n.mesh,e);return void 0!==n.weights&&t.traverse((function(e){if(e.isMesh)for(let t=0,s=n.weights.length;t<s;t++)e.morphTargetInfluences[t]=n.weights[t]})),t}))}loadNode(t){const s=this.json,n=this.extensions,r=this,o=s.nodes[t],a=o.name?r.createUniqueName(o.name):"";return function(){const e=[],s=r._invokeOne((function(e){return e.createNodeMesh&&e.createNodeMesh(t)}));return s&&e.push(s),void 0!==o.camera&&e.push(r.getDependency("camera",o.camera).then((function(e){return r._getNodeRef(r.cameraCache,o.camera,e)}))),r._invokeAll((function(e){return e.createNodeAttachment&&e.createNodeAttachment(t)})).forEach((function(t){e.push(t)})),Promise.all(e)}().then((function(s){let i;if(i=!0===o.isBone?new e.Bone:s.length>1?new e.Group:1===s.length?s[0]:new e.Object3D,i!==s[0])for(let e=0,t=s.length;e<t;e++)i.add(s[e]);if(o.name&&(i.userData.name=o.name,i.name=a),X(i,o),o.extensions&&V(n,i,o),void 0!==o.matrix){const t=new e.Matrix4;t.fromArray(o.matrix),i.applyMatrix4(t)}else void 0!==o.translation&&i.position.fromArray(o.translation),void 0!==o.rotation&&i.quaternion.fromArray(o.rotation),void 0!==o.scale&&i.scale.fromArray(o.scale);return r.associations.has(i)||r.associations.set(i,{}),r.associations.get(i).nodes=t,i}))}loadScene(t){const s=this.json,n=this.extensions,r=this.json.scenes[t],o=this,a=new e.Group;r.name&&(a.name=o.createUniqueName(r.name)),X(a,r),r.extensions&&V(n,a,r);const i=r.nodes||[],l=[];for(let e=0,t=i.length;e<t;e++)l.push(J(i[e],a,s,o));return Promise.all(l).then((function(){return o.associations=(t=>{const s=new Map;for(const[t,n]of o.associations)(t instanceof e.Material||t instanceof e.Texture)&&s.set(t,n);return t.traverse((e=>{const t=o.associations.get(e);null!=t&&s.set(e,t)})),s})(a),a}))}}function J(t,s,n,r){const o=n.nodes[t];return r.getDependency("node",t).then((function(t){if(void 0===o.skin)return t;let s;return r.getDependency("skin",o.skin).then((function(e){s=e;const t=[];for(let e=0,n=s.joints.length;e<n;e++)t.push(r.getDependency("node",s.joints[e]));return Promise.all(t)})).then((function(n){return t.traverse((function(t){if(!t.isMesh)return;const r=[],o=[];for(let t=0,a=n.length;t<a;t++){const a=n[t];if(a){r.push(a);const n=new e.Matrix4;void 0!==s.inverseBindMatrices&&n.fromArray(s.inverseBindMatrices.array,16*t),o.push(n)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[t])}t.bind(new e.Skeleton(r,o),t.matrixWorld)})),t}))})).then((function(e){s.add(e);const t=[];if(o.children){const s=o.children;for(let o=0,a=s.length;o<a;o++){const a=s[o];t.push(J(a,e,n,r))}}return Promise.all(t)}))}function Z(t,s,n){const r=s.attributes,o=[];function a(e,s){return n.getDependency("accessor",e).then((function(e){t.setAttribute(s,e)}))}for(const e in r){const s=k[e]||e.toLowerCase();s in t.attributes||o.push(a(r[e],s))}if(void 0!==s.indices&&!t.index){const e=n.getDependency("accessor",s.indices).then((function(e){t.setIndex(e)}));o.push(e)}return X(t,s),function(t,s,n){const r=s.attributes,o=new e.Box3;if(void 0===r.POSITION)return;{const t=n.json.accessors[r.POSITION],s=t.min,a=t.max;if(void 0===s||void 0===a)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(o.set(new e.Vector3(s[0],s[1],s[2]),new e.Vector3(a[0],a[1],a[2])),t.normalized){const e=Q(N[t.componentType]);o.min.multiplyScalar(e),o.max.multiplyScalar(e)}}const a=s.targets;if(void 0!==a){const t=new e.Vector3,s=new e.Vector3;for(let e=0,r=a.length;e<r;e++){const r=a[e];if(void 0!==r.POSITION){const e=n.json.accessors[r.POSITION],o=e.min,a=e.max;if(void 0!==o&&void 0!==a){if(s.setX(Math.max(Math.abs(o[0]),Math.abs(a[0]))),s.setY(Math.max(Math.abs(o[1]),Math.abs(a[1]))),s.setZ(Math.max(Math.abs(o[2]),Math.abs(a[2]))),e.normalized){const t=Q(N[e.componentType]);s.multiplyScalar(t)}t.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}o.expandByVector(t)}t.boundingBox=o;const i=new e.Sphere;o.getCenter(i.center),i.radius=o.min.distanceTo(o.max)/2,t.boundingSphere=i}(t,s,n),Promise.all(o).then((function(){return void 0!==s.targets?function(e,t,s){let n=!1,r=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(n=!0),void 0!==s.NORMAL&&(r=!0),n&&r)break}if(!n&&!r)return Promise.resolve(e);const o=[],a=[];for(let i=0,l=t.length;i<l;i++){const l=t[i];if(n){const t=void 0!==l.POSITION?s.getDependency("accessor",l.POSITION):e.attributes.position;o.push(t)}if(r){const t=void 0!==l.NORMAL?s.getDependency("accessor",l.NORMAL):e.attributes.normal;a.push(t)}}return Promise.all([Promise.all(o),Promise.all(a)]).then((function(t){const s=t[0],o=t[1];return n&&(e.morphAttributes.position=s),r&&(e.morphAttributes.normal=o),e.morphTargetsRelative=!0,e}))}(t,s.targets,n):t}))}function $(t,s){let n=t.getIndex();if(null===n){const e=[],s=t.getAttribute("position");if(void 0===s)return console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),t;for(let t=0;t<s.count;t++)e.push(t);t.setIndex(e),n=t.getIndex()}const r=n.count-2,o=[];if(s===e.TriangleFanDrawMode)for(let e=1;e<=r;e++)o.push(n.getX(0)),o.push(n.getX(e)),o.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(o.push(n.getX(e)),o.push(n.getX(e+1)),o.push(n.getX(e+2))):(o.push(n.getX(e+2)),o.push(n.getX(e+1)),o.push(n.getX(e)));o.length/3!==r&&console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const a=t.clone();return a.setIndex(o),a}exports.GLTFLoader=t;
|