UNPKG

three-loaders

Version:

This is a wrapper around threejs loaders to import it from any threejs application

166 lines 43.3 kB
"use strict";function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}/** * @author Rich Tibbett / https://github.com/richtr * @author mrdoob / http://mrdoob.com/ * @author Tony Parisi / http://www.tonyparisi.com/ * @author Takahiro / https://github.com/takahirox * @author Don McCurdy / https://www.donmccurdy.com */var THREE=require("three"),DRACOLoader=require("./THREEDracoLoader"),_GLTFLoader=function(){function e(e){this.manager=void 0===e?THREE.DefaultLoadingManager:e,this.dracoLoader=null}/* GLTFREGISTRY */function a(){var e={};return{get:function t(a){return e[a]},add:function s(a,t){e[a]=t},remove:function t(a){delete e[a]},removeAll:function a(){e={}}}}/*********************************/ /********** EXTENSIONS ***********/ /*********************************/ /** * DDS Texture Extension * * Specification: * https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds * */function t(){if(!THREE.DDSLoader)throw new Error("THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader");this.name=v.MSFT_TEXTURE_DDS,this.ddsLoader=new THREE.DDSLoader}/** * Lights Extension * * Specification: PENDING */function s(e){this.name=v.KHR_LIGHTS_PUNCTUAL;var a=e.extensions&&e.extensions[v.KHR_LIGHTS_PUNCTUAL]||{};this.lightDefs=a.lights||[]}/** * Unlit Materials Extension (pending) * * PR: https://github.com/KhronosGroup/glTF/pull/1163 */function r(){this.name=v.KHR_MATERIALS_UNLIT}function n(e){this.name=v.KHR_BINARY_GLTF,this.content=null,this.body=null;var a=new DataView(e,0,12);if(this.header={magic:THREE.LoaderUtils.decodeText(new Uint8Array(e.slice(0,4))),version:a.getUint32(4,!0),length:a.getUint32(8,!0)},"glTF"!==this.header.magic)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");else if(2>this.header.version)throw new Error("THREE.GLTFLoader: Legacy binary file detected. Use LegacyGLTFLoader instead.");for(var t,s=new DataView(e,12),r=0;r<s.byteLength;){t=s.getUint32(r,!0),r+=4;var n=s.getUint32(r,!0);if(r+=4,n===b.JSON){var i=new Uint8Array(e,12+r,t);this.content=THREE.LoaderUtils.decodeText(i)}else if(n===b.BIN){var o=12+r;this.body=e.slice(o,o+t)}// Clients must ignore chunks with unknown types. r+=t}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}/** * DRACO Mesh Compression Extension * * Specification: https://github.com/KhronosGroup/glTF/pull/874 */function o(e,a){if(!a)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=v.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=a,DRACOLoader.getDecoderModule()}/** * Texture Transform Extension * * Specification: */function l(){this.name=v.KHR_TEXTURE_TRANSFORM}/** * Specular-Glossiness Extension * * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness */function p(){return{name:v.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,specularGlossinessParams:["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity","refractionRatio"],getMaterialType:function e(){return THREE.ShaderMaterial},extendParams:function u(e,a,t){var s=a.extensions[this.name],r=THREE.ShaderLib.standard,n=THREE.UniformsUtils.clone(r.uniforms),i=r.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>","#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif").replace("#include <metalnessmap_pars_fragment>","#ifdef USE_GLOSSINESSMAP\n\tuniform sampler2D glossinessMap;\n#endif").replace("#include <roughnessmap_fragment>","vec3 specularFactor = specular;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\ttexelSpecular = sRGBToLinear( texelSpecular );\n\t// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture\n\tspecularFactor *= texelSpecular.rgb;\n#endif").replace("#include <metalnessmap_fragment>","float glossinessFactor = glossiness;\n#ifdef USE_GLOSSINESSMAP\n\tvec4 texelGlossiness = texture2D( glossinessMap, vUv );\n\t// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture\n\tglossinessFactor *= texelGlossiness.a;\n#endif").replace("#include <lights_physical_fragment>","PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularRoughness = clamp( 1.0 - glossinessFactor, 0.04, 1.0 );\nmaterial.specularColor = specularFactor.rgb;");delete n.roughness,delete n.metalness,delete n.roughnessMap,delete n.metalnessMap,n.specular={value:new THREE.Color().setHex(1118481)},n.glossiness={value:.5},n.specularMap={value:null},n.glossinessMap={value:null},e.vertexShader=r.vertexShader,e.fragmentShader=i,e.uniforms=n,e.defines={STANDARD:""},e.color=new THREE.Color(1,1,1),e.opacity=1;var o=[];if(Array.isArray(s.diffuseFactor)){var l=s.diffuseFactor;e.color.fromArray(l),e.opacity=l[3]}if(void 0!==s.diffuseTexture&&o.push(t.assignTexture(e,"map",s.diffuseTexture)),e.emissive=new THREE.Color(0,0,0),e.glossiness=void 0===s.glossinessFactor?1:s.glossinessFactor,e.specular=new THREE.Color(1,1,1),Array.isArray(s.specularFactor)&&e.specular.fromArray(s.specularFactor),void 0!==s.specularGlossinessTexture){var p=s.specularGlossinessTexture;o.push(t.assignTexture(e,"glossinessMap",p)),o.push(t.assignTexture(e,"specularMap",p))}return Promise.all(o)},createMaterial:function t(e){// setup material properties based on MeshStandardMaterial for Specular-Glossiness var a=new THREE.ShaderMaterial({defines:e.defines,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader,uniforms:e.uniforms,fog:!0,lights:!0,opacity:e.opacity,transparent:e.transparent});return a.isGLTFSpecularGlossinessMaterial=!0,a.color=e.color,a.map=void 0===e.map?null:e.map,a.lightMap=null,a.lightMapIntensity=1,a.aoMap=void 0===e.aoMap?null:e.aoMap,a.aoMapIntensity=1,a.emissive=e.emissive,a.emissiveIntensity=1,a.emissiveMap=void 0===e.emissiveMap?null:e.emissiveMap,a.bumpMap=void 0===e.bumpMap?null:e.bumpMap,a.bumpScale=1,a.normalMap=void 0===e.normalMap?null:e.normalMap,e.normalScale&&(a.normalScale=e.normalScale),a.displacementMap=null,a.displacementScale=1,a.displacementBias=0,a.specularMap=void 0===e.specularMap?null:e.specularMap,a.specular=e.specular,a.glossinessMap=void 0===e.glossinessMap?null:e.glossinessMap,a.glossiness=e.glossiness,a.alphaMap=null,a.envMap=void 0===e.envMap?null:e.envMap,a.envMapIntensity=1,a.refractionRatio=.98,a.extensions.derivatives=!0,a},/** * Clones a GLTFSpecularGlossinessMaterial instance. The ShaderMaterial.copy() method can * copy only properties it knows about or inherits, and misses many properties that would * normally be defined by MeshStandardMaterial. * * This method allows GLTFSpecularGlossinessMaterials to be cloned in the process of * loading a glTF model, but cloning later (e.g. by the user) would require these changes * AND also updating `.onBeforeRender` on the parent mesh. * * @param {THREE.ShaderMaterial} source * @return {THREE.ShaderMaterial} */cloneMaterial:function n(e){var a=e.clone();a.isGLTFSpecularGlossinessMaterial=!0;for(var t=this.specularGlossinessParams,s=0,r=t.length;s<r;s++)a[t[s]]=e[t[s]];return a},// Here's based on refreshUniformsCommon() and refreshUniformsStandard() in WebGLRenderer. refreshUniforms:function l(e,a,t,s,r){if(!0===r.isGLTFSpecularGlossinessMaterial){var n=r.uniforms,i=r.defines;n.opacity.value=r.opacity,n.diffuse.value.copy(r.color),n.emissive.value.copy(r.emissive).multiplyScalar(r.emissiveIntensity),n.map.value=r.map,n.specularMap.value=r.specularMap,n.alphaMap.value=r.alphaMap,n.lightMap.value=r.lightMap,n.lightMapIntensity.value=r.lightMapIntensity,n.aoMap.value=r.aoMap,n.aoMapIntensity.value=r.aoMapIntensity;// uv repeat and offset setting priorities // 1. color map // 2. specular map // 3. normal map // 4. bump map // 5. alpha map // 6. emissive map var o;r.map?o=r.map:r.specularMap?o=r.specularMap:r.displacementMap?o=r.displacementMap:r.normalMap?o=r.normalMap:r.bumpMap?o=r.bumpMap:r.glossinessMap?o=r.glossinessMap:r.alphaMap?o=r.alphaMap:r.emissiveMap&&(o=r.emissiveMap),void 0!==o&&(o.isWebGLRenderTarget&&(o=o.texture),!0===o.matrixAutoUpdate&&o.updateMatrix(),n.uvTransform.value.copy(o.matrix)),r.envMap&&(n.envMap.value=r.envMap,n.envMapIntensity.value=r.envMapIntensity,n.flipEnvMap.value=r.envMap.isCubeTexture?-1:1,n.reflectivity.value=r.reflectivity,n.refractionRatio.value=r.refractionRatio,n.maxMipLevel.value=e.properties.get(r.envMap).__maxMipLevel),n.specular.value.copy(r.specular),n.glossiness.value=r.glossiness,n.glossinessMap.value=r.glossinessMap,n.emissiveMap.value=r.emissiveMap,n.bumpMap.value=r.bumpMap,n.normalMap.value=r.normalMap,n.displacementMap.value=r.displacementMap,n.displacementScale.value=r.displacementScale,n.displacementBias.value=r.displacementBias,null!==n.glossinessMap.value&&void 0===i.USE_GLOSSINESSMAP&&(i.USE_GLOSSINESSMAP="",i.USE_ROUGHNESSMAP=""),null===n.glossinessMap.value&&void 0!==i.USE_GLOSSINESSMAP&&(delete i.USE_GLOSSINESSMAP,delete i.USE_ROUGHNESSMAP)}}}}/*********************************/ /********** INTERPOLATION ********/ /*********************************/ // Spline Interpolation // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation function u(e,a,t,s){THREE.Interpolant.call(this,e,a,t,s)}/* UTILITY FUNCTIONS */function c(e,a){// Invalid URL return"string"!=typeof e||""===e?"":/^(https?:)?\/\//i.test(e)?e:/^data:.*,.*$/i.test(e)?e:/^blob:.*$/i.test(e)?e:a+e;// Absolute URL http://,https://,// // Data URI // Blob URL // Relative URL }/** * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material */function d(){return new THREE.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:THREE.FrontSide})}function m(e,a,t){// Add unknown glTF extensions to an object's userData. for(var s in t.extensions)void 0===e[s]&&(a.userData.gltfExtensions=a.userData.gltfExtensions||{},a.userData.gltfExtensions[s]=t.extensions[s])}/** * @param {THREE.Object3D|THREE.Material|THREE.BufferGeometry} object * @param {GLTF.definition} gltfDef */function g(e,a){void 0!==a.extras&&("object"===_typeof(a.extras)?e.userData=a.extras:console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+a.extras))}/** * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets * * @param {THREE.BufferGeometry} geometry * @param {Array<GLTF.Target>} targets * @param {GLTFParser} parser * @return {Promise<THREE.BufferGeometry>} */function h(e,a,t){for(var s,r=!1,n=!1,o=0,l=a.length;o<l&&(s=a[o],void 0!==s.POSITION&&(r=!0),void 0!==s.NORMAL&&(n=!0),!(r&&n));o++);if(!r&&!n)return Promise.resolve(e);for(var s,p=[],u=[],o=0,l=a.length;o<l;o++){if(s=a[o],r){// TODO: Error-prone use of a callback inside a loop. var c=void 0===s.POSITION?e.attributes.position:t.getDependency("accessor",s.POSITION).then(function(e){// Cloning not to pollute original accessor below return E(e)});p.push(c)}if(n){// TODO: Error-prone use of a callback inside a loop. var c=void 0===s.NORMAL?e.attributes.normal:t.getDependency("accessor",s.NORMAL).then(function(e){return E(e)});u.push(c)}}return Promise.all([Promise.all(p),Promise.all(u)]).then(function(t){for(var s=t[0],o=t[1],l=0,p=a.length;l<p;l++){var u=a[l],c="morphTarget"+l;if(r&&void 0!==u.POSITION)// Three.js morph position is absolute value. The formula is // basePosition // + weight0 * ( morphPosition0 - basePosition ) // + weight1 * ( morphPosition1 - basePosition ) // ... // while the glTF one is relative // basePosition // + weight0 * glTFmorphPosition0 // + weight1 * glTFmorphPosition1 // ... // then we need to convert from relative to absolute here. {var d=s[l];d.name=c;for(var m=e.attributes.position,g=0,h=d.count;g<h;g++)d.setXYZ(g,d.getX(g)+m.getX(g),d.getY(g)+m.getY(g),d.getZ(g)+m.getZ(g))}if(n&&void 0!==u.NORMAL)// see target.POSITION's comment {var f=o[l];f.name=c;for(var S=e.attributes.normal,g=0,h=f.count;g<h;g++)f.setXYZ(g,f.getX(g)+S.getX(g),f.getY(g)+S.getY(g),f.getZ(g)+S.getZ(g))}}return r&&(e.morphAttributes.position=s),n&&(e.morphAttributes.normal=o),e})}/** * @param {THREE.Mesh} mesh * @param {GLTF.Mesh} meshDef */function f(e,a){if(e.updateMorphTargets(),void 0!==a.weights)for(var t=0,s=a.weights.length;t<s;t++)e.morphTargetInfluences[t]=a.weights[t];// .extras has user-defined data, so check that .extras.targetNames is an array. if(a.extras&&Array.isArray(a.extras.targetNames)){var r=a.extras.targetNames;if(e.morphTargetInfluences.length===r.length){e.morphTargetDictionary={};for(var t=0,s=r.length;t<s;t++)e.morphTargetDictionary[r[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function S(e,a){var t=e.extensions?e.extensions[v.KHR_DRACO_MESH_COMPRESSION]:void 0,s=a.extensions?a.extensions[v.KHR_DRACO_MESH_COMPRESSION]:void 0;return t&&s?t.bufferView===s.bufferView&&M(t.attributes,s.attributes):e.indices===a.indices&&M(e.attributes,a.attributes)}function M(e,a){if(Object.keys(e).length!==Object.keys(a).length)return!1;for(var t in e)if(e[t]!==a[t])return!1;return!0}function T(e,a){if(e.length!==a.length)return!1;for(var t=0,s=e.length;t<s;t++)if(e[t]!==a[t])return!1;return!0}function y(e,a){for(var t,s=0,r=e.length;s<r;s++)if(t=e[s],S(t.primitive,a))return t.promise;return null}function R(e,a){for(var t,s=0,r=e.length;s<r;s++)if(t=e[s],T(a,t.baseGeometries))return t.geometry;return null}function L(e,a,t){for(var s,r=0,n=e.length;r<n;r++)if(s=e[r],a===s.baseGeometry&&T(t,s.primitives))return s.geometry;return null}function E(e){if(e.isInterleavedBufferAttribute){for(var a=e.count,t=e.itemSize,s=e.array.slice(0,a*t),r=0,n=0;r<a;++r)s[n++]=e.getX(r),2<=t&&(s[n++]=e.getY(r)),3<=t&&(s[n++]=e.getZ(r)),4<=t&&(s[n++]=e.getW(r));return new THREE.BufferAttribute(s,t,e.normalized)}return e.clone()}/** * Checks if we can build a single Mesh with MultiMaterial from multiple primitives. * Returns true if all primitives use the same attributes/morphAttributes/mode * and also have index. Otherwise returns false. * * @param {Array<GLTF.Primitive>} primitives * @return {Boolean} */function _(e){if(2>e.length)return!1;var a=e[0],t=a.targets||[];if(void 0===a.indices)return!1;for(var s,r=1,n=e.length;r<n;r++){if(s=e[r],a.mode!==s.mode)return!1;if(void 0===s.indices)return!1;if(s.extensions&&s.extensions[v.KHR_DRACO_MESH_COMPRESSION])return!1;if(!M(a.attributes,s.attributes))return!1;var o=s.targets||[];if(t.length!==o.length)return!1;for(var l=0,p=t.length;l<p;l++)if(!M(t[l],o[l]))return!1}return!0}/* GLTF PARSER */function A(e,t,s){this.json=e||{},this.extensions=t||{},this.options=s||{},this.cache=new a,this.primitiveCache=[],this.multiplePrimitivesCache=[],this.multiPassGeometryCache=[],this.textureLoader=new THREE.TextureLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.fileLoader=new THREE.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer")}/** * @param {THREE.BufferGeometry} geometry * @param {GLTF.Primitive} primitiveDef * @param {GLTFParser} parser * @return {Promise<THREE.BufferGeometry>} */function x(e,a,t){function s(a,s){return t.getDependency("accessor",a).then(function(a){e.addAttribute(s,a)})}var r=a.attributes,n=[];for(var i in r){var o=w[i];o&&!(o in e.attributes)&&n.push(s(r[i],o))}if(void 0!==a.indices&&!e.index){var l=t.getDependency("accessor",a.indices).then(function(a){e.setIndex(a)});n.push(l)}return g(e,a),Promise.all(n).then(function(){return void 0===a.targets?e:h(e,a.targets,t)})}/** * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry * * Creates BufferGeometries from primitives. * If we can build a single BufferGeometry with .groups from multiple primitives, returns one BufferGeometry. * Otherwise, returns BufferGeometries without .groups as many as primitives. * * @param {Array<GLTF.Primitive>} primitives * @return {Promise<Array<THREE.BufferGeometry>>} */e.prototype={constructor:e,crossOrigin:"anonymous",load:function p(a,t,s,r){var n,i=this;n=void 0===this.resourcePath?void 0===this.path?THREE.LoaderUtils.extractUrlBase(a):this.path:this.resourcePath,i.manager.itemStart(a);var o=function(t){r?r(t):console.error(t),i.manager.itemError(a),i.manager.itemEnd(a)},l=new THREE.FileLoader(i.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.load(a,function(e){try{i.parse(e,n,function(e){t(e),i.manager.itemEnd(a)},o)}catch(a){o(a)}},s,o)},setCrossOrigin:function a(e){return this.crossOrigin=e,this},setPath:function a(e){return this.path=e,this},setResourcePath:function a(e){return this.resourcePath=e,this},setDRACOLoader:function a(e){return this.dracoLoader=e,this},parse:function R(e,a,u,c){var d,g={};if("string"==typeof e)d=e;else{var h=THREE.LoaderUtils.decodeText(new Uint8Array(e,0,4));if(h===I){try{g[v.KHR_BINARY_GLTF]=new n(e)}catch(e){return void(c&&c(e))}d=g[v.KHR_BINARY_GLTF].content}else d=THREE.LoaderUtils.decodeText(new Uint8Array(e))}var f=JSON.parse(d);if(void 0===f.asset||2>f.asset.version[0])return void(c&&c(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported. Use LegacyGLTFLoader instead.")));if(f.extensionsUsed)for(var S=0;S<f.extensionsUsed.length;++S){var M=f.extensionsUsed[S],T=f.extensionsRequired||[];M===v.KHR_LIGHTS_PUNCTUAL?g[M]=new s(f):M===v.KHR_MATERIALS_UNLIT?g[M]=new r(f):M===v.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS?g[M]=new p(f):M===v.KHR_DRACO_MESH_COMPRESSION?g[M]=new o(f,this.dracoLoader):M===v.MSFT_TEXTURE_DDS?g[v.MSFT_TEXTURE_DDS]=new t(f):M===v.KHR_TEXTURE_TRANSFORM?g[v.KHR_TEXTURE_TRANSFORM]=new l(f):0<=T.indexOf(M)&&console.warn("THREE.GLTFLoader: Unknown extension \""+M+"\".")}var y=new A(f,g,{path:a||this.resourcePath||"",crossOrigin:this.crossOrigin,manager:this.manager});y.parse(function(e,a,t,s,r){var n={scene:e,scenes:a,cameras:t,animations:s,asset:r.asset,parser:y,userData:{}};m(g,n,r),u(n)},c)}};var v={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",MSFT_TEXTURE_DDS:"MSFT_texture_dds"};s.prototype.loadLight=function(e){var t,a=Math.PI,s=this.lightDefs[e],r=new THREE.Color(16777215);void 0!==s.color&&r.fromArray(s.color);var n=void 0===s.range?0:s.range;switch(s.type){case"directional":t=new THREE.DirectionalLight(r),t.target.position.set(0,0,-1),t.add(t.target);break;case"point":t=new THREE.PointLight(r),t.distance=n;break;case"spot":t=new THREE.SpotLight(r),t.distance=n,s.spot=s.spot||{},s.spot.innerConeAngle=void 0===s.spot.innerConeAngle?0:s.spot.innerConeAngle,s.spot.outerConeAngle=void 0===s.spot.outerConeAngle?a/4:s.spot.outerConeAngle,t.angle=s.spot.outerConeAngle,t.penumbra=1-s.spot.innerConeAngle/s.spot.outerConeAngle,t.target.position.set(0,0,-1),t.add(t.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type, \""+s.type+"\".");}return t.decay=2,void 0!==s.intensity&&(t.intensity=s.intensity),t.name=s.name||"light_"+e,Promise.resolve(t)},r.prototype.getMaterialType=function(){return THREE.MeshBasicMaterial},r.prototype.extendParams=function(e,a,t){var s=[];e.color=new THREE.Color(1,1,1),e.opacity=1;var r=a.pbrMetallicRoughness;if(r){if(Array.isArray(r.baseColorFactor)){var n=r.baseColorFactor;e.color.fromArray(n),e.opacity=n[3]}void 0!==r.baseColorTexture&&s.push(t.assignTexture(e,"map",r.baseColorTexture))}return Promise.all(s)};/* BINARY EXTENSION */var I="glTF",b={JSON:1313821514,BIN:5130562};o.prototype.decodePrimitive=function(e,a){var t=this.json,s=this.dracoLoader,r=e.extensions[this.name].bufferView,n=e.extensions[this.name].attributes,i={},o={},l={};for(var p in n)p in w&&(i[w[p]]=n[p]);for(p in e.attributes)if(void 0!==w[p]&&void 0!==n[p]){var u=t.accessors[e.attributes[p]],c=D[u.componentType];l[w[p]]=c,o[w[p]]=!0===u.normalized}return a.getDependency("bufferView",r).then(function(e){return new Promise(function(a){s.decodeDracoFile(e,function(e){for(var t in e.attributes){var s=e.attributes[t],r=o[t];void 0!==r&&(s.normalized=r)}a(e)},i,l)})})},l.prototype.extendTexture=function(e,a){return e=e.clone(),void 0!==a.offset&&e.offset.fromArray(a.offset),void 0!==a.rotation&&(e.rotation=a.rotation),void 0!==a.scale&&e.repeat.fromArray(a.scale),void 0!==a.texCoord&&console.warn("THREE.GLTFLoader: Custom UV sets in \""+this.name+"\" extension not yet supported."),e.needsUpdate=!0,e},u.prototype=Object.create(THREE.Interpolant.prototype),u.prototype.constructor=u,u.prototype.copySampleValue_=function(e){// Copies a sample value to the result buffer. See description of glTF // CUBICSPLINE values layout in interpolate_() function below. for(var a=this.resultBuffer,t=this.sampleValues,s=this.valueSize,r=0;r!==s;r++)a[r]=t[3*(e*s)+s+r];return a},u.prototype.beforeStart_=u.prototype.copySampleValue_,u.prototype.afterEnd_=u.prototype.copySampleValue_,u.prototype.interpolate_=function(e,a,s,t){// Layout of keyframe output values for CUBICSPLINE animations: // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ] for(var r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,l=3*o,u=t-a,c=(s-a)/u,p=c*c,d=p*c,m=e*l,g=m-l,h=-2*d+3*p,f=d-p,S=0;S!==o;S++){var M=n[g+S+o],T=n[g+S+2*o]*u,y=n[m+S+o],R=n[m+S]*u;// splineVertex_k r[S]=(1-h)*M+(f-p+c)*T+h*y+f*R}return r};/*********************************/ /********** INTERNALS ************/ /*********************************/ /* CONSTANTS */var N={FLOAT:5126,//FLOAT_MAT2: 35674, 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},F={5126:Number,//35674: THREE.Matrix2, 35675:THREE.Matrix3,35676:THREE.Matrix4,35664:THREE.Vector2,35665:THREE.Vector3,35666:THREE.Vector4,35678:THREE.Texture},D={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},O={9728:THREE.NearestFilter,9729:THREE.LinearFilter,9984:THREE.NearestMipMapNearestFilter,9985:THREE.LinearMipMapNearestFilter,9986:THREE.NearestMipMapLinearFilter,9987:THREE.LinearMipMapLinearFilter},G={33071:THREE.ClampToEdgeWrapping,33648:THREE.MirroredRepeatWrapping,10497:THREE.RepeatWrapping},U={1028:THREE.BackSide,// Culling front 1029:THREE.FrontSide// Culling back //1032: THREE.NoSide // Culling front and back, what to do? },C={512:THREE.NeverDepth,513:THREE.LessDepth,514:THREE.EqualDepth,515:THREE.LessEqualDepth,516:THREE.GreaterEqualDepth,517:THREE.NotEqualDepth,518:THREE.GreaterEqualDepth,519:THREE.AlwaysDepth},P={32774:THREE.AddEquation,32778:THREE.SubtractEquation,32779:THREE.ReverseSubtractEquation},H={0:THREE.ZeroFactor,1:THREE.OneFactor,768:THREE.SrcColorFactor,769:THREE.OneMinusSrcColorFactor,770:THREE.SrcAlphaFactor,771:THREE.OneMinusSrcAlphaFactor,772:THREE.DstAlphaFactor,773:THREE.OneMinusDstAlphaFactor,774:THREE.DstColorFactor,775:THREE.OneMinusDstColorFactor,776:THREE.SrcAlphaSaturateFactor// The followings are not supported by Three.js yet //32769: CONSTANT_COLOR, //32770: ONE_MINUS_CONSTANT_COLOR, //32771: CONSTANT_ALPHA, //32772: ONE_MINUS_CONSTANT_COLOR },B={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},w={POSITION:"position",NORMAL:"normal",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},K={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},k={CUBICSPLINE:THREE.InterpolateSmooth,// We use custom interpolation GLTFCubicSplineInterpolation for CUBICSPLINE. // KeyframeTrack.optimize() can't handle glTF Cubic Spline output values layout, // using THREE.InterpolateSmooth for KeyframeTrack instantiation to prevent optimization. // See KeyframeTrack.optimize() for the detail. LINEAR:THREE.InterpolateLinear,STEP:THREE.InterpolateDiscrete},V={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"},j={"image/png":THREE.RGBAFormat,"image/jpeg":THREE.RGBFormat};return A.prototype.parse=function(e,a){var t=this.json;// Clear the loader cache this.cache.removeAll(),this.markDefs(),this.getMultiDependencies(["scene","animation","camera"]).then(function(a){var s=a.scenes||[],r=s[t.scene||0],n=a.animations||[],i=a.cameras||[];e(r,s,i,n,t)}).catch(a)},A.prototype.markDefs=function(){// Nothing in the node definition indicates whether it is a Bone or an // Object3D. Use the skins' joint references to mark bones. for(var e,a=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[],r={},n={},o=0,l=t.length;o<l;o++){e=t[o].joints;for(var p=0,u=e.length;p<u;p++)a[e[p]].isBone=!0}// Meshes can (and should) be reused by multiple nodes in a glTF asset. To // avoid having more than one THREE.Mesh with the same name, count // references and rename instances below. // // Example: CesiumMilkTruck sample model reuses "Wheel" meshes. for(var c,d=0,m=a.length;d<m;d++)c=a[d],void 0!==c.mesh&&(void 0===r[c.mesh]&&(r[c.mesh]=n[c.mesh]=0),r[c.mesh]++,void 0!==c.skin&&(s[c.mesh].isSkinnedMesh=!0));this.json.meshReferences=r,this.json.meshUses=n},A.prototype.getDependency=function(e,a){var t=e+":"+a,s=this.cache.get(t);if(!s){switch(e){case"scene":s=this.loadScene(a);break;case"node":s=this.loadNode(a);break;case"mesh":s=this.loadMesh(a);break;case"accessor":s=this.loadAccessor(a);break;case"bufferView":s=this.loadBufferView(a);break;case"buffer":s=this.loadBuffer(a);break;case"material":s=this.loadMaterial(a);break;case"texture":s=this.loadTexture(a);break;case"skin":s=this.loadSkin(a);break;case"animation":s=this.loadAnimation(a);break;case"camera":s=this.loadCamera(a);break;case"light":s=this.extensions[v.KHR_LIGHTS_PUNCTUAL].loadLight(a);break;default:throw new Error("Unknown type: "+e);}this.cache.add(t,s)}return s},A.prototype.getDependencies=function(e){var a=this.cache.get(e);if(!a){var t=this,s=this.json[e+("mesh"===e?"es":"s")]||[];a=Promise.all(s.map(function(a,s){return t.getDependency(e,s)})),this.cache.add(e,a)}return a},A.prototype.getMultiDependencies=function(e){for(var a={},t=[],s=0,r=e.length;s<r;s++){var n=e[s],o=this.getDependencies(n);o=o.then(function(e,t){a[e]=t}.bind(this,n+("mesh"===n?"es":"s"))),t.push(o)}return Promise.all(t).then(function(){return a})},A.prototype.loadBuffer=function(e){var a=this.json.buffers[e],t=this.fileLoader;if(a.type&&"arraybuffer"!==a.type)throw new Error("THREE.GLTFLoader: "+a.type+" buffer type is not supported.");// If present, GLB container is required to be the first buffer. if(void 0===a.uri&&0===e)return Promise.resolve(this.extensions[v.KHR_BINARY_GLTF].body);var s=this.options;return new Promise(function(e,r){t.load(c(a.uri,s.path),e,void 0,function(){r(new Error("THREE.GLTFLoader: Failed to load buffer \""+a.uri+"\"."))})})},A.prototype.loadBufferView=function(e){var a=this.json.bufferViews[e];return this.getDependency("buffer",a.buffer).then(function(e){var t=a.byteLength||0,s=a.byteOffset||0;return e.slice(s,s+t)})},A.prototype.loadAccessor=function(e){var a=this,t=this.json,s=this.json.accessors[e];if(void 0===s.bufferView&&void 0===s.sparse)// Ignore empty accessors, which may be used to declare runtime // information about attributes coming from another source (e.g. Draco // compression extension). return Promise.resolve(null);var r=[];return void 0===s.bufferView?r.push(null):r.push(this.getDependency("bufferView",s.bufferView)),void 0!==s.sparse&&(r.push(this.getDependency("bufferView",s.sparse.indices.bufferView)),r.push(this.getDependency("bufferView",s.sparse.values.bufferView))),Promise.all(r).then(function(e){var r,n,o=e[0],l=B[s.type],p=D[s.componentType],u=p.BYTES_PER_ELEMENT,c=s.byteOffset||0,d=void 0===s.bufferView?void 0:t.bufferViews[s.bufferView].byteStride,m=!0===s.normalized;// The buffer is not interleaved if the stride is the item size in bytes. if(d&&d!==u*l){var g="InterleavedBuffer:"+s.bufferView+":"+s.componentType,h=a.cache.get(g);h||(r=new p(o),h=new THREE.InterleavedBuffer(r,d/u),a.cache.add(g,h)),n=new THREE.InterleavedBufferAttribute(h,l,c/u,m)}else r=null===o?new p(s.count*l):new p(o,c,s.count*l),n=new THREE.BufferAttribute(r,l,m);// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors if(void 0!==s.sparse){var f=B.SCALAR,S=D[s.sparse.indices.componentType],M=s.sparse.indices.byteOffset||0,T=s.sparse.values.byteOffset||0,y=new S(e[1],M,s.sparse.count*f),R=new p(e[2],T,s.sparse.count*l);null!==o&&n.setArray(n.array.slice());for(var L,E=0,_=y.length;E<_;E++)if(L=y[E],n.setX(L,R[E*l]),2<=l&&n.setY(L,R[E*l+1]),3<=l&&n.setZ(L,R[E*l+2]),4<=l&&n.setW(L,R[E*l+3]),5<=l)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}return n})},A.prototype.loadTexture=function(e){var a,t=this,s=this.json,r=this.options,n=this.textureLoader,i=window.URL||window.webkitURL,o=s.textures[e],l=o.extensions||{};a=l[v.MSFT_TEXTURE_DDS]?s.images[l[v.MSFT_TEXTURE_DDS].source]:s.images[o.source];var p=a.uri,u=!1;return void 0!==a.bufferView&&(p=t.getDependency("bufferView",a.bufferView).then(function(e){u=!0;var t=new Blob([e],{type:a.mimeType});return p=i.createObjectURL(t),p})),Promise.resolve(p).then(function(e){// Load Texture resource. var a=THREE.Loader.Handlers.get(e);return a||(a=l[v.MSFT_TEXTURE_DDS]?t.extensions[v.MSFT_TEXTURE_DDS].ddsLoader:n),new Promise(function(t,s){a.load(c(e,r.path),t,void 0,s)})}).then(function(e){!0===u&&i.revokeObjectURL(p),e.flipY=!1,void 0!==o.name&&(e.name=o.name),a.mimeType in j&&(e.format=j[a.mimeType]);var t=s.samplers||{},r=t[o.sampler]||{};return e.magFilter=O[r.magFilter]||THREE.LinearFilter,e.minFilter=O[r.minFilter]||THREE.LinearMipMapLinearFilter,e.wrapS=G[r.wrapS]||THREE.RepeatWrapping,e.wrapT=G[r.wrapT]||THREE.RepeatWrapping,e})},A.prototype.assignTexture=function(e,a,t){var s=this;return this.getDependency("texture",t.index).then(function(r){if(s.extensions[v.KHR_TEXTURE_TRANSFORM]){var n=void 0===t.extensions?void 0:t.extensions[v.KHR_TEXTURE_TRANSFORM];n&&(r=s.extensions[v.KHR_TEXTURE_TRANSFORM].extendTexture(r,n))}e[a]=r})},A.prototype.loadMaterial=function(e){var a,t=this,s=this.json,r=this.extensions,n=s.materials[e],i={},o=n.extensions||{},l=[];if(o[v.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){var p=r[v.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];a=p.getMaterialType(n),l.push(p.extendParams(i,n,t))}else if(o[v.KHR_MATERIALS_UNLIT]){var u=r[v.KHR_MATERIALS_UNLIT];a=u.getMaterialType(n),l.push(u.extendParams(i,n,t))}else{a=THREE.MeshStandardMaterial;var c=n.pbrMetallicRoughness||{};if(i.color=new THREE.Color(1,1,1),i.opacity=1,Array.isArray(c.baseColorFactor)){var d=c.baseColorFactor;i.color.fromArray(d),i.opacity=d[3]}void 0!==c.baseColorTexture&&l.push(t.assignTexture(i,"map",c.baseColorTexture)),i.metalness=void 0===c.metallicFactor?1:c.metallicFactor,i.roughness=void 0===c.roughnessFactor?1:c.roughnessFactor,void 0!==c.metallicRoughnessTexture&&(l.push(t.assignTexture(i,"metalnessMap",c.metallicRoughnessTexture)),l.push(t.assignTexture(i,"roughnessMap",c.metallicRoughnessTexture)))}!0===n.doubleSided&&(i.side=THREE.DoubleSide);var h=n.alphaMode||V.OPAQUE;return h===V.BLEND?i.transparent=!0:(i.transparent=!1,h===V.MASK&&(i.alphaTest=void 0===n.alphaCutoff?.5:n.alphaCutoff)),void 0!==n.normalTexture&&a!==THREE.MeshBasicMaterial&&(l.push(t.assignTexture(i,"normalMap",n.normalTexture)),i.normalScale=new THREE.Vector2(1,1),void 0!==n.normalTexture.scale&&i.normalScale.set(n.normalTexture.scale,n.normalTexture.scale)),void 0!==n.occlusionTexture&&a!==THREE.MeshBasicMaterial&&(l.push(t.assignTexture(i,"aoMap",n.occlusionTexture)),void 0!==n.occlusionTexture.strength&&(i.aoMapIntensity=n.occlusionTexture.strength)),void 0!==n.emissiveFactor&&a!==THREE.MeshBasicMaterial&&(i.emissive=new THREE.Color().fromArray(n.emissiveFactor)),void 0!==n.emissiveTexture&&a!==THREE.MeshBasicMaterial&&l.push(t.assignTexture(i,"emissiveMap",n.emissiveTexture)),Promise.all(l).then(function(){var e;return e=a===THREE.ShaderMaterial?r[v.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(i):new a(i),void 0!==n.name&&(e.name=n.name),e.normalScale&&(e.normalScale.y=-e.normalScale.y),e.map&&(e.map.encoding=THREE.sRGBEncoding),e.emissiveMap&&(e.emissiveMap.encoding=THREE.sRGBEncoding),e.specularMap&&(e.specularMap.encoding=THREE.sRGBEncoding),g(e,n),n.extensions&&m(r,e,n),e})},A.prototype.loadGeometries=function(e){function a(e){return r[v.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then(function(a){return x(a,e,s)})}var t,s=this,r=this.extensions,n=this.primitiveCache,o=_(e);o&&(t=e,e=[e[0]]);for(var l=[],p=0,u=e.length;p<u;p++){var c=e[p],d=y(n,c);// See if we've already created this geometry if(d)l.push(d);else{var m;m=c.extensions&&c.extensions[v.KHR_DRACO_MESH_COMPRESSION]?a(c):x(new THREE.BufferGeometry,c,s),n.push({primitive:c,promise:m}),l.push(m)}}return Promise.all(l).then(function(a){if(o){var r=a[0],n=s.multiPassGeometryCache,l=L(n,r,t);// See if we've already created this combined geometry if(null!==l)return[l.geometry];// Cloning geometry because of index override. // Attributes can be reused so cloning by myself here. var p=new THREE.BufferGeometry;for(var u in p.name=r.name,p.userData=r.userData,r.attributes)p.addAttribute(u,r.attributes[u]);for(var u in r.morphAttributes)p.morphAttributes[u]=r.morphAttributes[u];for(var c=[],d=0,m=t.length;d<m;d++)c.push(s.getDependency("accessor",t[d].indices));return Promise.all(c).then(function(e){for(var a,s=[],o=0,l=0,u=t.length;l<u;l++){a=e[l];for(var c=0,d=a.count;c<d;c++)s.push(a.array[c]);p.addGroup(o,a.count,l),o+=a.count}return p.setIndex(s),n.push({geometry:p,baseGeometry:r,primitives:t}),[p]})}if(1<a.length&&void 0!==THREE.BufferGeometryUtils){// Tries to merge geometries with BufferGeometryUtils if possible for(var d=1,m=e.length;d<m;d++)// can't merge if draw mode is different if(e[0].mode!==e[d].mode)return a;// See if we've already created this combined geometry var n=s.multiplePrimitivesCache,l=R(n,a);if(!l){var p=THREE.BufferGeometryUtils.mergeBufferGeometries(a,!0);if(n.push({geometry:p,baseGeometries:a}),null!==p)return[p]}else if(null!==l.geometry)return[l.geometry]}return a})},A.prototype.loadMesh=function(e){for(var a,t=this,s=this.json,r=this.extensions,n=s.meshes[e],o=n.primitives,l=[],p=0,u=o.length;p<u;p++)a=void 0===o[p].material?d():this.getDependency("material",o[p].material),l.push(a);return Promise.all(l).then(function(a){return t.loadGeometries(o).then(function(s){for(var l=1===s.length&&0<s[0].groups.length,p=[],u=0,c=s.length;u<c;u++){var d,m=s[u],h=o[u],S=l?a:a[u];if(h.mode===N.TRIANGLES||h.mode===N.TRIANGLE_STRIP||h.mode===N.TRIANGLE_FAN||void 0===h.mode)d=!0===n.isSkinnedMesh?new THREE.SkinnedMesh(m,S):new THREE.Mesh(m,S),!0===d.isSkinnedMesh&&d.normalizeSkinWeights(),h.mode===N.TRIANGLE_STRIP?d.drawMode=THREE.TriangleStripDrawMode:h.mode===N.TRIANGLE_FAN&&(d.drawMode=THREE.TriangleFanDrawMode);else if(h.mode===N.LINES)d=new THREE.LineSegments(m,S);else if(h.mode===N.LINE_STRIP)d=new THREE.Line(m,S);else if(h.mode===N.LINE_LOOP)d=new THREE.LineLoop(m,S);else if(h.mode===N.POINTS)d=new THREE.Points(m,S);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+h.mode);0<Object.keys(d.geometry.morphAttributes).length&&f(d,n),d.name=n.name||"mesh_"+e,1<s.length&&(d.name+="_"+u),g(d,n),p.push(d);for(var S,M=l?d.material:[d.material],T=void 0!==m.attributes.color,y=void 0===m.attributes.normal,R=!0===d.isSkinnedMesh,L=0<Object.keys(m.morphAttributes).length,E=L&&void 0!==m.morphAttributes.normal,_=0,A=M.length;_<A;_++){if(S=M[_],d.isPoints){var x="PointsMaterial:"+S.uuid,I=t.cache.get(x);I||(I=new THREE.PointsMaterial,THREE.Material.prototype.copy.call(I,S),I.color.copy(S.color),I.map=S.map,I.lights=!1,t.cache.add(x,I)),S=I}else if(d.isLine){var x="LineBasicMaterial:"+S.uuid,b=t.cache.get(x);b||(b=new THREE.LineBasicMaterial,THREE.Material.prototype.copy.call(b,S),b.color.copy(S.color),b.lights=!1,t.cache.add(x,b)),S=b}// Clone the material if it will be modified if(T||y||R||L){var x="ClonedMaterial:"+S.uuid+":";S.isGLTFSpecularGlossinessMaterial&&(x+="specular-glossiness:"),R&&(x+="skinning:"),T&&(x+="vertex-colors:"),y&&(x+="flat-shading:"),L&&(x+="morph-targets:"),E&&(x+="morph-normals:");var F=t.cache.get(x);F||(F=S.isGLTFSpecularGlossinessMaterial?r[v.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].cloneMaterial(S):S.clone(),R&&(F.skinning=!0),T&&(F.vertexColors=THREE.VertexColors),y&&(F.flatShading=!0),L&&(F.morphTargets=!0),E&&(F.morphNormals=!0),t.cache.add(x,F)),S=F}M[_]=S,S.aoMap&&void 0===m.attributes.uv2&&void 0!==m.attributes.uv&&(console.log("THREE.GLTFLoader: Duplicating UVs to support aoMap."),m.addAttribute("uv2",new THREE.BufferAttribute(m.attributes.uv.array,2))),S.isGLTFSpecularGlossinessMaterial&&(d.onBeforeRender=r[v.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].refreshUniforms)}d.material=l?M:M[0]}if(1===p.length)return p[0];for(var D=new THREE.Group,u=0,c=p.length;u<c;u++)D.add(p[u]);return D})})},A.prototype.loadCamera=function(e){var a,t=this.json.cameras[e],s=t[t.type];return s?("perspective"===t.type?a=new THREE.PerspectiveCamera(THREE.Math.radToDeg(s.yfov),s.aspectRatio||1,s.znear||1,s.zfar||2e6):"orthographic"===t.type&&(a=new THREE.OrthographicCamera(s.xmag/-2,s.xmag/2,s.ymag/2,s.ymag/-2,s.znear,s.zfar)),void 0!==t.name&&(a.name=t.name),g(a,t),Promise.resolve(a)):void console.warn("THREE.GLTFLoader: Missing camera parameters.")},A.prototype.loadSkin=function(e){var a=this.json.skins[e],t={joints:a.joints};return void 0===a.inverseBindMatrices?Promise.resolve(t):this.getDependency("accessor",a.inverseBindMatrices).then(function(e){return t.inverseBindMatrices=e,t})},A.prototype.loadAnimation=function(e){for(var a=this.json,t=a.animations[e],s=[],r=[],n=[],o=[],l=[],p=0,c=t.channels.length;p<c;p++){var d=t.channels[p],m=t.samplers[d.sampler],g=d.target,h=void 0===g.node?g.id:g.node,f=void 0===t.parameters?m.input:t.parameters[m.input],S=void 0===t.parameters?m.output:t.parameters[m.output];s.push(this.getDependency("node",h)),r.push(this.getDependency("accessor",f)),n.push(this.getDependency("accessor",S)),o.push(m),l.push(g)}return Promise.all([Promise.all(s),Promise.all(r),Promise.all(n),Promise.all(o),Promise.all(l)]).then(function(a){for(var s=a[0],r=a[1],n=a[2],o=a[3],l=a[4],p=[],c=0,d=s.length;c<d;c++){var m=s[c],g=r[c],h=n[c],f=o[c],S=l[c];if(void 0!==m){m.updateMatrix(),m.matrixAutoUpdate=!0;var M;switch(K[S.path]){case K.weights:M=THREE.NumberKeyframeTrack;break;case K.rotation:M=THREE.QuaternionKeyframeTrack;break;case K.position:case K.scale:default:M=THREE.VectorKeyframeTrack;}var T=m.name?m.name:m.uuid,y=void 0===f.interpolation?THREE.InterpolateLinear:k[f.interpolation],R=[];K[S.path]===K.weights?m.traverse(function(e){!0===e.isMesh&&e.morphTargetInfluences&&R.push(e.name?e.name:e.uuid)}):R.push(T);// KeyframeTrack.optimize() will modify given 'times' and 'values' // buffers before creating a truncated copy to keep. Because buffers may // be reused by other tracks, make copies here. for(var L,E=0,_=R.length;E<_;E++)L=new M(R[E]+"."+K[S.path],THREE.AnimationUtils.arraySlice(g.array,0),THREE.AnimationUtils.arraySlice(h.array,0),y),"CUBICSPLINE"===f.interpolation&&(L.createInterpolant=function(e){// A CUBICSPLINE keyframe in glTF has three output values for each input value, // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize() // must be divided by three to get the interpolant's sampleSize argument. return new u(this.times,this.values,this.getValueSize()/3,e)},L.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),p.push(L)}}var A=void 0===t.name?"animation_"+e:t.name;return new THREE.AnimationClip(A,void 0,p)})},A.prototype.loadNode=function(e){var a=this.json,t=this.extensions,s=this,r=a.meshReferences,n=a.meshUses,l=a.nodes[e];return function(){// .isBone isn't in glTF spec. See .markDefs return!0===l.isBone?Promise.resolve(new THREE.Bone):void 0===l.mesh?void 0===l.camera?l.extensions&&l.extensions[v.KHR_LIGHTS_PUNCTUAL]&&void 0!==l.extensions[v.KHR_LIGHTS_PUNCTUAL].light?s.getDependency("light",l.extensions[v.KHR_LIGHTS_PUNCTUAL].light):Promise.resolve(new THREE.Object3D):s.getDependency("camera",l.camera):s.getDependency("mesh",l.mesh).then(function(e){var a;if(1<r[l.mesh]){var t=n[l.mesh]++;a=e.clone(),a.name+="_instance_"+t,a.onBeforeRender=e.onBeforeRender;for(var s=0,o=a.children.length;s<o;s++)a.children[s].name+="_instance_"+t,a.children[s].onBeforeRender=e.children[s].onBeforeRender}else a=e;// if weights are provided on the node, override weights on the mesh. return void 0!==l.weights&&a.traverse(function(e){if(e.isMesh)for(var a=0,t=l.weights.length;a<t;a++)e.morphTargetInfluences[a]=l.weights[a]}),a})}().then(function(e){if(void 0!==l.name&&(e.name=THREE.PropertyBinding.sanitizeNodeName(l.name)),g(e,l),l.extensions&&m(t,e,l),void 0!==l.matrix){var a=new THREE.Matrix4;a.fromArray(l.matrix),e.applyMatrix(a)}else void 0!==l.translation&&e.position.fromArray(l.translation),void 0!==l.rotation&&e.quaternion.fromArray(l.rotation),void 0!==l.scale&&e.scale.fromArray(l.scale);return e})},A.prototype.loadScene=function(){// scene node hierachy builder function e(a,t,s,r){var n=s.nodes[a];return r.getDependency("node",a).then(function(e){if(void 0===n.skin)return e;// build skeleton here as well var a;return r.getDependency("skin",n.skin).then(function(e){a=e;for(var t=[],s=0,n=a.joints.length;s<n;s++)t.push(r.getDependency("node",a.joints[s]));return Promise.all(t)}).then(function(t){for(var s=!0===e.isGroup?e.children:[e],r=0,n=s.length;r<n;r++){for(var o,l=s[r],p=[],u=[],c=0,d=t.length;c<d;c++)if(o=t[c],o){p.push(o);var m=new THREE.Matrix4;void 0!==a.inverseBindMatrices&&m.fromArray(a.inverseBindMatrices.array,16*c),u.push(m)}else console.warn("THREE.GLTFLoader: Joint \"%s\" could not be found.",a.joints[c]);l.bind(new THREE.Skeleton(p,u),l.matrixWorld)}return e})}).then(function(a){t.add(a);var o=[];if(n.children)for(var l,p=n.children,u=0,c=p.length;u<c;u++)l=p[u],o.push(e(l,a,s,r));return Promise.all(o)})}return function(a){var t=this.json,s=this.extensions,r=this.json.scenes[a],n=this,o=new THREE.Scene;void 0!==r.name&&(o.name=r.name),g(o,r),r.extensions&&m(s,o,r);for(var l=r.nodes||[],p=[],u=0,c=l.length;u<c;u++)p.push(e(l[u],o,t,n));return Promise.all(p).then(function(){return o})}}(),e}();module.exports=_GLTFLoader;