THREE.GLTFLoader=function(){function e(e){THREE.Loader.call(this,e),this.dracoLoader=null,this.ddsLoader=null}function t(){var e={};return{get:function(t){return e[t]},add:function(t,r){e[t]=r},remove:function(t){delete e[t]},removeAll:function(){e={}}}}e.prototype=Object.assign(Object.create(THREE.Loader.prototype),{constructor:e,load:function(e,t,r,a){var s,n=this;s=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:THREE.LoaderUtils.extractUrlBase(e),n.manager.itemStart(e);var o=function(t){a?a(t):console.error(t),n.manager.itemError(e),n.manager.itemEnd(e)},i=new THREE.FileLoader(n.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),"use-credentials"===n.crossOrigin&&i.setWithCredentials(!0),i.load(e,(function(r){try{n.parse(r,s,(function(r){t(r),n.manager.itemEnd(e)}),o)}catch(e){o(e)}}),r,o)},setDRACOLoader:function(e){return this.dracoLoader=e,this},setDDSLoader:function(e){return this.ddsLoader=e,this},parse:function(e,t,p,m){var f,E={};if("string"==typeof e)f=e;else if(THREE.LoaderUtils.decodeText(new Uint8Array(e,0,4))===i){try{E[r.KHR_BINARY_GLTF]=new l(e)}catch(e){return void(m&&m(e))}f=E[r.KHR_BINARY_GLTF].content}else f=THREE.LoaderUtils.decodeText(new Uint8Array(e));var T=JSON.parse(f);if(void 0===T.asset||T.asset.version[0]<2)m&&m(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));else{if(T.extensionsUsed)for(var g=0;g=0&&console.warn('THREE.GLTFLoader: Unknown extension "'+v+'".')}}new _(T,E,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,manager:this.manager}).parse(p,m)}}});var r={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_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",MSFT_TEXTURE_DDS:"MSFT_texture_dds"};function a(e){if(!e)throw new Error("THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader");this.name=r.MSFT_TEXTURE_DDS,this.ddsLoader=e}function s(e){this.name=r.KHR_LIGHTS_PUNCTUAL;var t=e.extensions&&e.extensions[r.KHR_LIGHTS_PUNCTUAL]||{};this.lightDefs=t.lights||[]}function n(){this.name=r.KHR_MATERIALS_UNLIT}function o(){this.name=r.KHR_MATERIALS_CLEARCOAT}s.prototype.loadLight=function(e){var t,r=this.lightDefs[e],a=new THREE.Color(16777215);void 0!==r.color&&a.fromArray(r.color);var s=void 0!==r.range?r.range:0;switch(r.type){case"directional":(t=new THREE.DirectionalLight(a)).target.position.set(0,0,-1),t.add(t.target);break;case"point":(t=new THREE.PointLight(a)).distance=s;break;case"spot":(t=new THREE.SpotLight(a)).distance=s,r.spot=r.spot||{},r.spot.innerConeAngle=void 0!==r.spot.innerConeAngle?r.spot.innerConeAngle:0,r.spot.outerConeAngle=void 0!==r.spot.outerConeAngle?r.spot.outerConeAngle:Math.PI/4,t.angle=r.spot.outerConeAngle,t.penumbra=1-r.spot.innerConeAngle/r.spot.outerConeAngle,t.target.position.set(0,0,-1),t.add(t.target);break;default:throw new Error('THREE.GLTFLoader: Unexpected light type, "'+r.type+'".')}return t.position.set(0,0,0),t.decay=2,void 0!==r.intensity&&(t.intensity=r.intensity),t.name=r.name||"light_"+e,Promise.resolve(t)},n.prototype.getMaterialType=function(){return THREE.MeshBasicMaterial},n.prototype.extendParams=function(e,t,r){var a=[];e.color=new THREE.Color(1,1,1),e.opacity=1;var s=t.pbrMetallicRoughness;if(s){if(Array.isArray(s.baseColorFactor)){var n=s.baseColorFactor;e.color.fromArray(n),e.opacity=n[3]}void 0!==s.baseColorTexture&&a.push(r.assignTexture(e,"map",s.baseColorTexture))}return Promise.all(a)},o.prototype.getMaterialType=function(){return THREE.MeshPhysicalMaterial},o.prototype.extendParams=function(e,t,r){var a=[],s=t.extensions[this.name];if(void 0!==s.clearcoatFactor&&(e.clearcoat=s.clearcoatFactor),void 0!==s.clearcoatTexture&&a.push(r.assignTexture(e,"clearcoatMap",s.clearcoatTexture)),void 0!==s.clearcoatRoughnessFactor&&(e.clearcoatRoughness=s.clearcoatRoughnessFactor),void 0!==s.clearcoatRoughnessTexture&&a.push(r.assignTexture(e,"clearcoatRoughnessMap",s.clearcoatRoughnessTexture)),void 0!==s.clearcoatNormalTexture&&(a.push(r.assignTexture(e,"clearcoatNormalMap",s.clearcoatNormalTexture)),void 0!==s.clearcoatNormalTexture.scale)){var n=s.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new THREE.Vector2(n,n)}return Promise.all(a)};var i="glTF";function l(e){this.name=r.KHR_BINARY_GLTF,this.content=null,this.body=null;var t=new DataView(e,0,12);if(this.header={magic:THREE.LoaderUtils.decodeText(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==i)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");for(var a=new DataView(e,12),s=0;s",t),e.fragmentShader=e.fragmentShader.replace("#include ",r),e.fragmentShader=e.fragmentShader.replace("#include ",a),e.fragmentShader=e.fragmentShader.replace("#include ",s),e.fragmentShader=e.fragmentShader.replace("#include ",n)},Object.defineProperties(this,{specular:{get:function(){return o.specular.value},set:function(e){o.specular.value=e}},specularMap:{get:function(){return o.specularMap.value},set:function(e){o.specularMap.value=e}},glossiness:{get:function(){return o.glossiness.value},set:function(e){o.glossiness.value=e}},glossinessMap:{get:function(){return o.glossinessMap.value},set:function(e){o.glossinessMap.value=e,e?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_ROUGHNESSMAP=""):(delete this.defines.USE_ROUGHNESSMAP,delete this.defines.USE_GLOSSINESSMAP)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(e)}function h(){return{name:r.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,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:function(){return p},extendParams:function(e,t,r){var a=t.extensions[this.name];e.color=new THREE.Color(1,1,1),e.opacity=1;var s=[];if(Array.isArray(a.diffuseFactor)){var n=a.diffuseFactor;e.color.fromArray(n),e.opacity=n[3]}if(void 0!==a.diffuseTexture&&s.push(r.assignTexture(e,"map",a.diffuseTexture)),e.emissive=new THREE.Color(0,0,0),e.glossiness=void 0!==a.glossinessFactor?a.glossinessFactor:1,e.specular=new THREE.Color(1,1,1),Array.isArray(a.specularFactor)&&e.specular.fromArray(a.specularFactor),void 0!==a.specularGlossinessTexture){var o=a.specularGlossinessTexture;s.push(r.assignTexture(e,"glossinessMap",o)),s.push(r.assignTexture(e,"specularMap",o))}return Promise.all(s)},createMaterial:function(e){var t=new p(e);return t.fog=!0,t.color=e.color,t.map=void 0===e.map?null:e.map,t.lightMap=null,t.lightMapIntensity=1,t.aoMap=void 0===e.aoMap?null:e.aoMap,t.aoMapIntensity=1,t.emissive=e.emissive,t.emissiveIntensity=1,t.emissiveMap=void 0===e.emissiveMap?null:e.emissiveMap,t.bumpMap=void 0===e.bumpMap?null:e.bumpMap,t.bumpScale=1,t.normalMap=void 0===e.normalMap?null:e.normalMap,t.normalMapType=THREE.TangentSpaceNormalMap,e.normalScale&&(t.normalScale=e.normalScale),t.displacementMap=null,t.displacementScale=1,t.displacementBias=0,t.specularMap=void 0===e.specularMap?null:e.specularMap,t.specular=e.specular,t.glossinessMap=void 0===e.glossinessMap?null:e.glossinessMap,t.glossiness=e.glossiness,t.alphaMap=null,t.envMap=void 0===e.envMap?null:e.envMap,t.envMapIntensity=1,t.refractionRatio=.98,t}}}function d(){this.name=r.KHR_MESH_QUANTIZATION}function m(e,t,r,a){THREE.Interpolant.call(this,e,t,r,a)}c.prototype.decodePrimitive=function(e,t){var r=this.json,a=this.dracoLoader,s=e.extensions[this.name].bufferView,n=e.extensions[this.name].attributes,o={},i={},l={};for(var c in n){var u=v[c]||c.toLowerCase();o[u]=n[c]}for(c in e.attributes){u=v[c]||c.toLowerCase();if(void 0!==n[c]){var p=r.accessors[e.attributes[c]],h=f[p.componentType];l[u]=h,i[u]=!0===p.normalized}}return t.getDependency("bufferView",s).then((function(e){return new Promise((function(t){a.decodeDracoFile(e,(function(e){for(var r in e.attributes){var a=e.attributes[r],s=i[r];void 0!==s&&(a.normalized=s)}t(e)}),o,l)}))}))},u.prototype.extendTexture=function(e,t){return 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),void 0!==t.texCoord&&console.warn('THREE.GLTFLoader: Custom UV sets in "'+this.name+'" extension not yet supported.'),e.needsUpdate=!0,e},p.prototype=Object.create(THREE.MeshStandardMaterial.prototype),p.prototype.constructor=p,p.prototype.copy=function(e){return THREE.MeshStandardMaterial.prototype.copy.call(this,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},m.prototype=Object.create(THREE.Interpolant.prototype),m.prototype.constructor=m,m.prototype.copySampleValue_=function(e){for(var t=this.resultBuffer,r=this.sampleValues,a=this.valueSize,s=e*a*3+a,n=0;n!==a;n++)t[n]=r[s+n];return t},m.prototype.beforeStart_=m.prototype.copySampleValue_,m.prototype.afterEnd_=m.prototype.copySampleValue_,m.prototype.interpolate_=function(e,t,r,a){for(var s=this.resultBuffer,n=this.sampleValues,o=this.valueSize,i=2*o,l=3*o,c=a-t,u=(r-t)/c,p=u*u,h=p*u,d=e*l,m=d-l,f=-2*h+3*p,E=h-p,T=1-f,g=E-p+u,v=0;v!==o;v++){var R=n[m+v+o],M=n[m+v+i]*c,y=n[d+v+o],S=n[d+v]*c;s[v]=T*R+g*M+f*y+E*S}return s};var f={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},E={9728:THREE.NearestFilter,9729:THREE.LinearFilter,9984:THREE.NearestMipmapNearestFilter,9985:THREE.LinearMipmapNearestFilter,9986:THREE.NearestMipmapLinearFilter,9987:THREE.LinearMipmapLinearFilter},T={33071:THREE.ClampToEdgeWrapping,33648:THREE.MirroredRepeatWrapping,10497:THREE.RepeatWrapping},g={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},v={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},R={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},M={CUBICSPLINE:void 0,LINEAR:THREE.InterpolateLinear,STEP:THREE.InterpolateDiscrete},y={"image/png":THREE.RGBAFormat,"image/jpeg":THREE.RGBFormat};function S(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 H(e,t,r){for(var a in r.extensions)void 0===e[a]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[a]=r.extensions[a])}function L(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 x(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(var r=0,a=t.weights.length;r=2&&n.setY(A,H[L*i+1]),i>=3&&n.setZ(A,H[L*i+2]),i>=4&&n.setW(A,H[L*i+3]),i>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return n}))},_.prototype.loadTexture=function(e){var t,a=this,s=this.json,n=this.options,o=this.textureLoader,i=self.URL||self.webkitURL,l=s.textures[e],c=l.extensions||{},u=(t=c[r.MSFT_TEXTURE_DDS]?s.images[c[r.MSFT_TEXTURE_DDS].source]:s.images[l.source]).uri,p=!1;return void 0!==t.bufferView&&(u=a.getDependency("bufferView",t.bufferView).then((function(e){p=!0;var r=new Blob([e],{type:t.mimeType});return u=i.createObjectURL(r)}))),Promise.resolve(u).then((function(e){var t=n.manager.getHandler(e);return t||(t=c[r.MSFT_TEXTURE_DDS]?a.extensions[r.MSFT_TEXTURE_DDS].ddsLoader:o),new Promise((function(r,a){t.load(S(e,n.path),r,void 0,a)}))})).then((function(e){!0===p&&i.revokeObjectURL(u),e.flipY=!1,l.name&&(e.name=l.name),t.mimeType in y&&(e.format=y[t.mimeType]);var r=(s.samplers||{})[l.sampler]||{};return e.magFilter=E[r.magFilter]||THREE.LinearFilter,e.minFilter=E[r.minFilter]||THREE.LinearMipmapLinearFilter,e.wrapS=T[r.wrapS]||THREE.RepeatWrapping,e.wrapT=T[r.wrapT]||THREE.RepeatWrapping,e}))},_.prototype.assignTexture=function(e,t,a){var s=this;return this.getDependency("texture",a.index).then((function(n){if(!n.isCompressedTexture)switch(t){case"aoMap":case"emissiveMap":case"metalnessMap":case"normalMap":case"roughnessMap":n.format=THREE.RGBFormat}if(void 0===a.texCoord||0==a.texCoord||"aoMap"===t&&1==a.texCoord||console.warn("THREE.GLTFLoader: Custom UV set "+a.texCoord+" for texture "+t+" not yet supported."),s.extensions[r.KHR_TEXTURE_TRANSFORM]){var o=void 0!==a.extensions?a.extensions[r.KHR_TEXTURE_TRANSFORM]:void 0;o&&(n=s.extensions[r.KHR_TEXTURE_TRANSFORM].extendTexture(n,o))}e[t]=n}))},_.prototype.assignFinalMaterial=function(e){var t=e.geometry,r=e.material,a=void 0!==t.attributes.tangent,s=void 0!==t.attributes.color,n=void 0===t.attributes.normal,o=!0===e.isSkinnedMesh,i=Object.keys(t.morphAttributes).length>0,l=i&&void 0!==t.morphAttributes.normal;if(e.isPoints){var c="PointsMaterial:"+r.uuid,u=this.cache.get(c);u||(u=new THREE.PointsMaterial,THREE.Material.prototype.copy.call(u,r),u.color.copy(r.color),u.map=r.map,u.sizeAttenuation=!1,this.cache.add(c,u)),r=u}else if(e.isLine){c="LineBasicMaterial:"+r.uuid;var p=this.cache.get(c);p||(p=new THREE.LineBasicMaterial,THREE.Material.prototype.copy.call(p,r),p.color.copy(r.color),this.cache.add(c,p)),r=p}if(a||s||n||o||i){c="ClonedMaterial:"+r.uuid+":";r.isGLTFSpecularGlossinessMaterial&&(c+="specular-glossiness:"),o&&(c+="skinning:"),a&&(c+="vertex-tangents:"),s&&(c+="vertex-colors:"),n&&(c+="flat-shading:"),i&&(c+="morph-targets:"),l&&(c+="morph-normals:");var h=this.cache.get(c);h||(h=r.clone(),o&&(h.skinning=!0),a&&(h.vertexTangents=!0),s&&(h.vertexColors=!0),n&&(h.flatShading=!0),i&&(h.morphTargets=!0),l&&(h.morphNormals=!0),this.cache.add(c,h)),r=h}r.aoMap&&void 0===t.attributes.uv2&&void 0!==t.attributes.uv&&t.setAttribute("uv2",new THREE.BufferAttribute(t.attributes.uv.array,2)),r.normalScale&&!a&&(r.normalScale.y=-r.normalScale.y),r.clearcoatNormalScale&&!a&&(r.clearcoatNormalScale.y=-r.clearcoatNormalScale.y),e.material=r},_.prototype.loadMaterial=function(e){var t,a=this.json,s=this.extensions,n=a.materials[e],o={},i=n.extensions||{},l=[];if(i[r.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){var c=s[r.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];t=c.getMaterialType(),l.push(c.extendParams(o,n,this))}else if(i[r.KHR_MATERIALS_UNLIT]){var u=s[r.KHR_MATERIALS_UNLIT];t=u.getMaterialType(),l.push(u.extendParams(o,n,this))}else{t=THREE.MeshStandardMaterial;var h=n.pbrMetallicRoughness||{};if(o.color=new THREE.Color(1,1,1),o.opacity=1,Array.isArray(h.baseColorFactor)){var d=h.baseColorFactor;o.color.fromArray(d),o.opacity=d[3]}void 0!==h.baseColorTexture&&l.push(this.assignTexture(o,"map",h.baseColorTexture)),o.metalness=void 0!==h.metallicFactor?h.metallicFactor:1,o.roughness=void 0!==h.roughnessFactor?h.roughnessFactor:1,void 0!==h.metallicRoughnessTexture&&(l.push(this.assignTexture(o,"metalnessMap",h.metallicRoughnessTexture)),l.push(this.assignTexture(o,"roughnessMap",h.metallicRoughnessTexture)))}!0===n.doubleSided&&(o.side=THREE.DoubleSide);var m=n.alphaMode||"OPAQUE";if("BLEND"===m?(o.transparent=!0,o.depthWrite=!1):(o.transparent=!1,"MASK"===m&&(o.alphaTest=void 0!==n.alphaCutoff?n.alphaCutoff:.5)),void 0!==n.normalTexture&&t!==THREE.MeshBasicMaterial&&(l.push(this.assignTexture(o,"normalMap",n.normalTexture)),o.normalScale=new THREE.Vector2(1,1),void 0!==n.normalTexture.scale&&o.normalScale.set(n.normalTexture.scale,n.normalTexture.scale)),void 0!==n.occlusionTexture&&t!==THREE.MeshBasicMaterial&&(l.push(this.assignTexture(o,"aoMap",n.occlusionTexture)),void 0!==n.occlusionTexture.strength&&(o.aoMapIntensity=n.occlusionTexture.strength)),void 0!==n.emissiveFactor&&t!==THREE.MeshBasicMaterial&&(o.emissive=(new THREE.Color).fromArray(n.emissiveFactor)),void 0!==n.emissiveTexture&&t!==THREE.MeshBasicMaterial&&l.push(this.assignTexture(o,"emissiveMap",n.emissiveTexture)),i[r.KHR_MATERIALS_CLEARCOAT]){var f=s[r.KHR_MATERIALS_CLEARCOAT];t=f.getMaterialType(),l.push(f.extendParams(o,{extensions:i},this))}return Promise.all(l).then((function(){var e;return e=t===p?s[r.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(o):new t(o),n.name&&(e.name=n.name),e.map&&(e.map.encoding=THREE.sRGBEncoding),e.emissiveMap&&(e.emissiveMap.encoding=THREE.sRGBEncoding),L(e,n),n.extensions&&H(s,e,n),e}))},_.prototype.loadGeometries=function(e){var t,a,s=this,n=this.extensions,o=this.primitiveCache;function i(e){return n[r.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then((function(t){return w(t,e,s)}))}for(var l=[],c=0,u=e.length;c0&&x(u,r),u.name=r.name||"mesh_"+e,o.length>1&&(u.name+="_"+l),L(u,r),t.assignFinalMaterial(u),i.push(u)}if(1===i.length)return i[0];var m=new THREE.Group;for(l=0,c=i.length;l1){var r=o[i.mesh]++;(t=e.clone()).name+="_instance_"+r}else t=e;return void 0!==i.weights&&t.traverse((function(e){if(e.isMesh)for(var t=0,r=i.weights.length;t1?new THREE.Group:1===e.length?e[0]:new THREE.Object3D)!==e[0])for(var r=0,a=e.length;r