UNPKG

prophetk-3d-viewer

Version:

A Three.js r128 based GLB/GLTF model viewer for WeChat Mini Program and Web.

1 lines • 40.9 kB
!function(e){let t=null,s=!1;class n extends e.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new l(e)}),this.register(function(e){return new u(e)}),this.register(function(e){return new h(e)}),this.register(function(e){return new c(e)}),this.register(function(e){return new i(e)}),this.register(function(e){return new p(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,n,r){let i;const l={},c={};if("string"==typeof t)i=t;else if(e.LoaderUtils.decodeText(new Uint8Array(t,0,4))===d){try{l[o.KHR_BINARY_GLTF]=new m(t)}catch(e){return void(r&&r(e))}i=l[o.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(r&&r(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const h=new F(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 o.KHR_MATERIALS_UNLIT:l[t]=new a;break;case o.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:l[t]=new x;break;case o.KHR_DRACO_MESH_COMPRESSION:l[t]=new f(u,this.dracoLoader);break;case o.KHR_TEXTURE_TRANSFORM:l[t]=new g;break;case o.KHR_MESH_QUANTIZATION:l[t]=new M;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(n,r)}}function r(){let e={};return{get:function(t){return e[t]},add:function(t,s){e[t]=s},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const o={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",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 i{constructor(e){this.parser=e,this.name=o.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,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 a{constructor(){this.name=o.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 l{constructor(e){this.parser=e,this.name=o.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 c{constructor(e){this.parser=e,this.name=o.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 u{constructor(e){this.parser=e,this.name=o.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 h{constructor(e){this.parser=e,this.name=o.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 p{constructor(e){this.name=o.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const e=s.extensions[this.name],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 d="glTF";class m{constructor(t){this.name=o.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!==d)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const n=this.header.length-12,r=new DataView(t,12);let i=0;for(;i<n;){const s=r.getUint32(i,!0);i+=4;const n=r.getUint32(i,!0);if(i+=4,1313821514===n){const n=new Uint8Array(t,12+i,s);this.content=e.LoaderUtils.decodeText(n)}else if(5130562===n){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 f{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=o.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,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=w[e]||e.toLowerCase();i[t]=o[e]}for(const t in e.attributes){const n=w[t]||t.toLowerCase();if(void 0!==o[t]){const r=s.accessors[e.attributes[t]],o=v[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 g{constructor(){this.name=o.KHR_TEXTURE_TRANSFORM}extendTexture(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}}class T 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 x{constructor(){this.name=o.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 T}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 T(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 M{constructor(){this.name=o.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,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 v={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},R={9728:e.NearestFilter,9729:e.LinearFilter,9984:e.NearestMipmapNearestFilter,9985:e.LinearMipmapNearestFilter,9986:e.NearestMipmapLinearFilter,9987:e.LinearMipmapLinearFilter},S={33071:e.ClampToEdgeWrapping,33648:e.MirroredRepeatWrapping,10497:e.RepeatWrapping},A={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},w={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},_={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},E={CUBICSPLINE:void 0,LINEAR:e.InterpolateLinear,STEP:e.InterpolateDiscrete};function L(t){return void 0===t.DefaultMaterial&&(t.DefaultMaterial=new e.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:e.FrontSide})),t.DefaultMaterial}function b(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 I(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 P(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 O(e){const t=e.extensions&&e.extensions[o.KHR_DRACO_MESH_COMPRESSION];let s;return s=t?"draco:"+t.bufferView+":"+t.indices+":"+N(t.attributes):e.indices+":"+N(e.attributes)+":"+e.mode,s}function N(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 C(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 F{constructor(t={},s={}){this.json=t,this.extensions={},this.plugins={},this.options=s,this.cache=new r,this.associations=new Map,this.primitiveCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},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:{}};b(r,o,n),I(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[o.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(e,r){var o,i;s.load((o=t.uri,i=n.path,"string"!=typeof o||""===o?"":(/^https?:\/\//i.test(i)&&/^\//.test(o)&&(i=i.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(o)||/^data:.*,.*$/i.test(o)||/^blob:.*$/i.test(o)?o:i+o)),e,void 0,function(){r(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=A[r.type],a=v[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=A.SCALAR,n=v[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 THREE.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(n,r,o){const i=this,a=this.json,l=(this.options,a.textures[n]),c="undefined"!=typeof self&&(self.URL||self.webkitURL)||{createObjectURL:function(e){return""},revokeObjectURL:function(){}};let u=r.uri,h=!1,p=null,d=!0;if("image/jpeg"===r.mimeType&&(d=!1),void 0!==r.bufferView)u=i.getDependency("bufferView",r.bufferView).then(function(e){if("image/png"===r.mimeType){const t=new DataView(e,25,1).getUint8(0,!1);d=6===t||4===t||3===t}if(h=!0,"undefined"!=typeof wx&&wx.getFileSystemManager){const t=wx.getFileSystemManager(),o="image/png"===r.mimeType?"png":"jpg",i=wx.env.USER_DATA_PATH+"/gltf_tex_"+n+"_"+Date.now()+"."+o;!function(){if(!s&&"undefined"!=typeof wx&&wx.env){s=!0;try{const e=wx.getFileSystemManager(),t=e.readdirSync(wx.env.USER_DATA_PATH);for(let s=0;s<t.length;s++)if(/^gltf_tex_\d+_\d+\.(png|jpg)$/.test(t[s]))try{e.unlinkSync(wx.env.USER_DATA_PATH+"/"+t[s])}catch(e){}}catch(e){}}}(),t.writeFileSync(i,e),p=i,u=i}else u=c.createObjectURL(new Blob([e],{type:r.mimeType}));return u});else if(void 0===r.uri)throw new Error("THREE.GLTFLoader: Image "+n+" is missing URI and bufferView");return Promise.resolve(u).then(function(s){return new Promise(function(n,r){const o=t&&t.createImage?t.createImage():"undefined"!=typeof Image?new Image:null;if(o)t||void 0===o.crossOrigin||(o.crossOrigin="anonymous"),o.onload=function(){const t=new e.Texture(o);t.needsUpdate=!0,n(t)},o.onerror=function(e){if(p){try{"undefined"!=typeof wx&&wx.getFileSystemManager().unlinkSync(p)}catch(e){}p=null}r(e)},o.src=s;else{const t=new Uint8Array([255,255,255,255]);n(new e.DataTexture(t,1,1,e.RGBAFormat))}})}).then(function(t){if(!0===h&&c.revokeObjectURL(u),p){try{"undefined"!=typeof wx&&wx.getFileSystemManager().unlinkSync(p)}catch(e){}p=null}t.flipY=!1,l.name&&(t.name=l.name),d||(t.format=e.RGBFormat);const s=(a.samplers||{})[l.sampler]||{};return t.magFilter=R[s.magFilter]||e.LinearFilter,t.minFilter=R[s.minFilter]||e.LinearMipmapLinearFilter,t.wrapS=S[s.wrapS]||e.RepeatWrapping,t.wrapT=S[s.wrapT]||e.RepeatWrapping,i.associations.set(t,{type:"textures",index:n}),t})}assignTexture(e,t,s){const n=this;return this.getDependency("texture",s.index).then(function(r){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."),n.extensions[o.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[o.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=n.associations.get(r);r=n.extensions[o.KHR_TEXTURE_TRANSFORM].extendTexture(r,e),n.associations.set(r,t)}}e[t]=r})}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,a=!0===t.isSkinnedMesh,l=Object.keys(s.morphAttributes).length>0,c=l&&void 0!==s.morphAttributes.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||a||l){let e="ClonedMaterial:"+n.uuid+":";n.isGLTFSpecularGlossinessMaterial&&(e+="specular-glossiness:"),a&&(e+="skinning:"),r&&(e+="vertex-tangents:"),o&&(e+="vertex-colors:"),i&&(e+="flat-shading:"),l&&(e+="morph-targets:"),c&&(e+="morph-normals:");let t=this.cache.get(e);t||(t=n.clone(),a&&(t.skinning=!0),o&&(t.vertexColors=!0),i&&(t.flatShading=!0),l&&(t.morphTargets=!0),c&&(t.morphNormals=!0),r&&(t.vertexTangents=!0,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,n=this.json,r=this.extensions,i=n.materials[t];let a;const l={},c=i.extensions||{},u=[];if(c[o.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){const e=r[o.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];a=e.getMaterialType(),u.push(e.extendParams(l,i,s))}else if(c[o.KHR_MATERIALS_UNLIT]){const e=r[o.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||"OPAQUE";return"BLEND"===h?(l.transparent=!0,l.depthWrite=!1):(l.transparent=!1,"MASK"===h&&(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 n;return n=a===T?r[o.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(l):new a(l),i.name&&(n.name=i.name),n.map&&(n.map.encoding=e.sRGBEncoding),n.emissiveMap&&(n.emissiveMap.encoding=e.sRGBEncoding),I(n,i),s.associations.set(n,{type:"materials",index:t}),i.extensions&&b(r,n,i),n})}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,n=this.extensions,r=this.primitiveCache;function i(e){return n[o.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then(function(t){return H(t,e,s)})}const a=[];for(let n=0,l=t.length;n<l;n++){const l=t[n],c=O(l),u=r[c];if(u)a.push(u.promise);else{let t;t=l.extensions&&l.extensions[o.KHR_DRACO_MESH_COMPRESSION]?i(l):H(new e.BufferGeometry,l,s),r[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 e=0,t=i.length;e<t;e++){const t=void 0===i[e].material?L(this.cache):this.getDependency("material",i[e].material);a.push(t)}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(4===h.mode||5===h.mode||6===h.mode||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(),5===h.mode?p.geometry=k(p.geometry,e.TriangleStripDrawMode):6===h.mode&&(p.geometry=k(p.geometry,e.TriangleFanDrawMode));else if(1===h.mode)p=new e.LineSegments(u,d);else if(3===h.mode)p=new e.Line(u,d);else if(2===h.mode)p=new e.LineLoop(u,d);else{if(0!==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&&P(p,o),p.name=s.createUniqueName(o.name||"mesh_"+t),I(p,o),h.extensions&&b(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)),I(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,_[p.path]){case _.weights:d=e.NumberKeyframeTrack;break;case _.rotation:d=e.QuaternionKeyframeTrack;break;default:d=e.VectorKeyframeTrack}const m=s.name?s.name:s.uuid,f=void 0!==h.interpolation?E[h.interpolation]:e.InterpolateLinear,g=[];_[p.path]===_.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=C(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]+"."+_[p.path],n.array,T,f);"CUBICSPLINE"===h.interpolation&&(t.createInterpolant=function(e){return new y(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),I(a,o),o.extensions&&b(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)),I(i,r),r.extensions&&b(n,i,r);const a=r.nodes||[],l=[];for(let e=0,t=a.length;e<t;e++)l.push(U(a[e],i,s,o));return Promise.all(l).then(function(){return i})}}function U(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(U(i,e,n,r))}}return Promise.all(t)})}function H(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=w[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 I(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=C(v[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=C(v[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 k(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}n.setCanvas=function(e){t=e},e.GLTFLoader=n,module.exports=n}(require("./three-r128.js"));