@webarkit/arnft-threejs
Version:
The ARnft rendering engine, based on Three.js
1 lines • 54.2 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("three")):"function"==typeof define&&define.amd?define(["three"],t):"object"==typeof exports?exports.ARnftThreejs=t(require("three")):e.ARnftThreejs=t(e.THREE)}(this,e=>(()=>{"use strict";var t={818(t){t.exports=e}},r={};function n(e){var s=r[e];if(void 0!==s)return s.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var s={};function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){return o="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},o(e)}function a(e){var t=function(e){if("object"!=o(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==o(t)?t:t+""}function c(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,a(n.key),n)}}function l(e,t,r){return t&&c(e.prototype,t),r&&c(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function u(e,t,r){return(t=a(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}n.d(s,{default:()=>de});var h=n(818),d=function(){return l(function e(){i(this,e)},null,[{key:"interpolate",value:function(e){for(var t=0;t<16;t++)this.trackedMatrix.delta[t]=e[t]-this.trackedMatrix.interpolated[t],this.trackedMatrix.interpolated[t]=this.trackedMatrix.interpolated[t]+this.trackedMatrix.delta[t]/24;return this.trackedMatrix.interpolated}},{key:"isMobile",value:function(){return/Android|mobile|iPad|iPhone/i.test(navigator.userAgent)}},{key:"setMatrix",value:function(e,t){var r=[];for(var n in t)r[n]=t[n];"function"==typeof e.elements.set?e.elements.set(r):e.elements=[].slice.call(r)}}])}();u(d,"trackedMatrix",{delta:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],interpolated:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]});var p=function(){function e(t,r,s,o){i(this,e),u(this,"canvas_draw",void 0),u(this,"camera",void 0),u(this,"configData",void 0),u(this,"renderer",void 0),u(this,"uuid",void 0),u(this,"root",void 0),u(this,"target",void 0),u(this,"scene",void 0),u(this,"version",void 0),this.configData=t,this.uuid=s,this.target=window||n.g,this.renderer=new h.WebGLRenderer({canvas:r,context:t.renderer.context,alpha:t.renderer.alpha,premultipliedAlpha:t.renderer.premultipliedAlpha,antialias:t.renderer.antialias,stencil:t.renderer.stencil,precision:t.renderer.precision,depth:t.renderer.depth,logarithmicDepthBuffer:t.renderer.logarithmicDepthBuffer}),this.renderer.setPixelRatio(window.devicePixelRatio),this.scene=new h.Scene,e.globalScene=this.scene,this.camera=!0===o?new h.PerspectiveCamera(t.camera.fov,t.camera.ratio,t.camera.near,t.camera.far):new h.PerspectiveCamera,this.version="0.5.4",console.log("ARnftThreejs version: ",this.version)}return l(e,[{key:"initRenderer",value:function(){var e=this;this.camera.matrixAutoUpdate=!1,this.target.addEventListener("getProjectionMatrix",function(t){d.setMatrix(e.camera.projectionMatrix,t.detail.proj)}),this.scene.add(this.camera);var t=new h.AmbientLight(16777215);this.scene.add(t),this.target.addEventListener("getWindowSize",function(t){e.renderer.setSize(t.detail.sw,t.detail.sh)});var r=new CustomEvent("onInitThreejsRendering",{detail:{renderer:this.renderer,scene:this.scene,camera:this.camera}});this.target.dispatchEvent(r)}},{key:"draw",value:function(){this.renderer.render(this.scene,this.camera)}},{key:"getRenderer",value:function(){return this.renderer}},{key:"getScene",value:function(){return this.scene}},{key:"getCamera",value:function(){return this.camera}},{key:"setRenderer",value:function(e){this.renderer=e}},{key:"setScene",value:function(e){this.scene=e}},{key:"setCamera",value:function(e){this.camera=e}}],[{key:"getGlobalScene",value:function(){return e.globalScene}}])}();function m(e,t){if(t===h.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t===h.TriangleFanDrawMode||t===h.TriangleStripDrawMode){let r=e.getIndex();if(null===r){const t=[],n=e.getAttribute("position");if(void 0===n)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<n.count;e++)t.push(e);e.setIndex(t),r=e.getIndex()}const n=r.count-2,s=[];if(t===h.TriangleFanDrawMode)for(let e=1;e<=n;e++)s.push(r.getX(0)),s.push(r.getX(e)),s.push(r.getX(e+1));else for(let e=0;e<n;e++)e%2==0?(s.push(r.getX(e)),s.push(r.getX(e+1)),s.push(r.getX(e+2))):(s.push(r.getX(e+2)),s.push(r.getX(e+1)),s.push(r.getX(e)));s.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=e.clone();return i.setIndex(s),i.clearGroups(),i}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e}function f(e){const t=new Map,r=new Map,n=e.clone();return g(e,n,function(e,n){t.set(n,e),r.set(e,n)}),n.traverse(function(e){if(!e.isSkinnedMesh)return;const n=e,s=t.get(e),i=s.skeleton.bones;n.skeleton=s.skeleton.clone(),n.bindMatrix.copy(s.bindMatrix),n.skeleton.bones=i.map(function(e){return r.get(e)}),n.bind(n.skeleton,n.bindMatrix)}),n}function g(e,t,r){r(e,t);for(let n=0;n<e.children.length;n++)g(e.children[n],t.children[n],r)}u(p,"globalScene",void 0);class T extends h.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new _(e)}),this.register(function(e){return new E(e)}),this.register(function(e){return new P(e)}),this.register(function(e){return new k(e)}),this.register(function(e){return new H(e)}),this.register(function(e){return new S(e)}),this.register(function(e){return new A(e)}),this.register(function(e){return new b(e)}),this.register(function(e){return new I(e)}),this.register(function(e){return new w(e)}),this.register(function(e){return new C(e)}),this.register(function(e){return new L(e)}),this.register(function(e){return new O(e)}),this.register(function(e){return new N(e)}),this.register(function(e){return new M(e)}),this.register(function(e){return new F(e,x.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new F(e,x.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new D(e)})}load(e,t,r,n){const s=this;let i;if(""!==this.resourcePath)i=this.resourcePath;else if(""!==this.path){const t=h.LoaderUtils.extractUrlBase(e);i=h.LoaderUtils.resolveURL(t,this.path)}else i=h.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const o=function(t){n?n(t):console.error(t),s.manager.itemError(e),s.manager.itemEnd(e)},a=new h.FileLoader(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,function(r){try{s.parse(r,i,function(r){t(r),s.manager.itemEnd(e)},o)}catch(e){o(e)}},r,o)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,r,n){let s;const i={},o={},a=new TextDecoder;if("string"==typeof e)s=JSON.parse(e);else if(e instanceof ArrayBuffer)if(a.decode(new Uint8Array(e,0,4))===G){try{i[x.KHR_BINARY_GLTF]=new U(e)}catch(e){return void(n&&n(e))}s=JSON.parse(i[x.KHR_BINARY_GLTF].content)}else s=JSON.parse(a.decode(e));else s=e;if(void 0===s.asset||s.asset.version[0]<2)return void(n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const c=new le(s,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](c);t.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),o[t.name]=t,i[t.name]=!0}if(s.extensionsUsed)for(let e=0;e<s.extensionsUsed.length;++e){const t=s.extensionsUsed[e],r=s.extensionsRequired||[];switch(t){case x.KHR_MATERIALS_UNLIT:i[t]=new y;break;case x.KHR_DRACO_MESH_COMPRESSION:i[t]=new B(s,this.dracoLoader);break;case x.KHR_TEXTURE_TRANSFORM:i[t]=new K;break;case x.KHR_MESH_QUANTIZATION:i[t]=new j;break;default:r.indexOf(t)>=0&&void 0===o[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}c.setExtensions(i),c.setPlugins(o),c.parse(r,n)}parseAsync(e,t){const r=this;return new Promise(function(n,s){r.parse(e,t,n,s)})}}function v(){let e={};return{get:function(t){return e[t]},add:function(t,r){e[t]=r},remove:function(t){delete e[t]},removeAll:function(){e={}}}}function R(e,t,r){const n=e.json.materials[t];return n.extensions&&n.extensions[r]?n.extensions[r]:null}const x={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_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class M{constructor(e){this.parser=e,this.name=x.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let r=0,n=t.length;r<n;r++){const n=t[r];n.extensions&&n.extensions[this.name]&&void 0!==n.extensions[this.name].light&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(e){const t=this.parser,r="light:"+e;let n=t.cache.get(r);if(n)return n;const s=t.json,i=((s.extensions&&s.extensions[this.name]||{}).lights||[])[e];let o;const a=new h.Color(16777215);void 0!==i.color&&a.setRGB(i.color[0],i.color[1],i.color[2],h.LinearSRGBColorSpace);const c=void 0!==i.range?i.range:0;switch(i.type){case"directional":o=new h.DirectionalLight(a),o.target.position.set(0,0,-1),o.add(o.target);break;case"point":o=new h.PointLight(a),o.distance=c;break;case"spot":o=new h.SpotLight(a),o.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,o.angle=i.spot.outerConeAngle,o.penumbra=1-i.spot.innerConeAngle/i.spot.outerConeAngle,o.target.position.set(0,0,-1),o.add(o.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+i.type)}return o.position.set(0,0,0),ne(o,i),void 0!==i.intensity&&(o.intensity=i.intensity),o.name=t.createUniqueName(i.name||"light_"+e),n=Promise.resolve(o),t.cache.add(r,n),n}getDependency(e,t){if("light"===e)return this._loadLight(t)}createNodeAttachment(e){const t=this,r=this.parser,n=r.json.nodes[e],s=(n.extensions&&n.extensions[this.name]||{}).light;return void 0===s?null:this._loadLight(s).then(function(e){return r._getNodeRef(t.cache,s,e)})}}class y{constructor(){this.name=x.KHR_MATERIALS_UNLIT}getMaterialType(){return h.MeshBasicMaterial}extendParams(e,t,r){const n=[];e.color=new h.Color(1,1,1),e.opacity=1;const s=t.pbrMetallicRoughness;if(s){if(Array.isArray(s.baseColorFactor)){const t=s.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],h.LinearSRGBColorSpace),e.opacity=t[3]}void 0!==s.baseColorTexture&&n.push(r.assignTexture(e,"map",s.baseColorTexture,h.SRGBColorSpace))}return Promise.all(n)}}class w{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);return null===r||void 0!==r.emissiveStrength&&(t.emissiveIntensity=r.emissiveStrength),Promise.resolve()}}class _{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];if(void 0!==r.clearcoatFactor&&(t.clearcoat=r.clearcoatFactor),void 0!==r.clearcoatTexture&&n.push(this.parser.assignTexture(t,"clearcoatMap",r.clearcoatTexture)),void 0!==r.clearcoatRoughnessFactor&&(t.clearcoatRoughness=r.clearcoatRoughnessFactor),void 0!==r.clearcoatRoughnessTexture&&n.push(this.parser.assignTexture(t,"clearcoatRoughnessMap",r.clearcoatRoughnessTexture)),void 0!==r.clearcoatNormalTexture&&(n.push(this.parser.assignTexture(t,"clearcoatNormalMap",r.clearcoatNormalTexture)),void 0!==r.clearcoatNormalTexture.scale)){const e=r.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new h.Vector2(e,e)}return Promise.all(n)}}class E{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_DISPERSION}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);return null===r||(t.dispersion=void 0!==r.dispersion?r.dispersion:0),Promise.resolve()}}class L{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];return void 0!==r.iridescenceFactor&&(t.iridescence=r.iridescenceFactor),void 0!==r.iridescenceTexture&&n.push(this.parser.assignTexture(t,"iridescenceMap",r.iridescenceTexture)),void 0!==r.iridescenceIor&&(t.iridescenceIOR=r.iridescenceIor),void 0===t.iridescenceThicknessRange&&(t.iridescenceThicknessRange=[100,400]),void 0!==r.iridescenceThicknessMinimum&&(t.iridescenceThicknessRange[0]=r.iridescenceThicknessMinimum),void 0!==r.iridescenceThicknessMaximum&&(t.iridescenceThicknessRange[1]=r.iridescenceThicknessMaximum),void 0!==r.iridescenceThicknessTexture&&n.push(this.parser.assignTexture(t,"iridescenceThicknessMap",r.iridescenceThicknessTexture)),Promise.all(n)}}class S{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_SHEEN}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];if(t.sheenColor=new h.Color(0,0,0),t.sheenRoughness=0,t.sheen=1,void 0!==r.sheenColorFactor){const e=r.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],h.LinearSRGBColorSpace)}return void 0!==r.sheenRoughnessFactor&&(t.sheenRoughness=r.sheenRoughnessFactor),void 0!==r.sheenColorTexture&&n.push(this.parser.assignTexture(t,"sheenColorMap",r.sheenColorTexture,h.SRGBColorSpace)),void 0!==r.sheenRoughnessTexture&&n.push(this.parser.assignTexture(t,"sheenRoughnessMap",r.sheenRoughnessTexture)),Promise.all(n)}}class A{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];return void 0!==r.transmissionFactor&&(t.transmission=r.transmissionFactor),void 0!==r.transmissionTexture&&n.push(this.parser.assignTexture(t,"transmissionMap",r.transmissionTexture)),Promise.all(n)}}class b{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_VOLUME}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];t.thickness=void 0!==r.thicknessFactor?r.thicknessFactor:0,void 0!==r.thicknessTexture&&n.push(this.parser.assignTexture(t,"thicknessMap",r.thicknessTexture)),t.attenuationDistance=r.attenuationDistance||1/0;const s=r.attenuationColor||[1,1,1];return t.attenuationColor=(new h.Color).setRGB(s[0],s[1],s[2],h.LinearSRGBColorSpace),Promise.all(n)}}class I{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_IOR}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);return null===r||(t.ior=void 0!==r.ior?r.ior:1.5,0===t.ior&&(t.ior=1e3)),Promise.resolve()}}class C{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_SPECULAR}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];t.specularIntensity=void 0!==r.specularFactor?r.specularFactor:1,void 0!==r.specularTexture&&n.push(this.parser.assignTexture(t,"specularIntensityMap",r.specularTexture));const s=r.specularColorFactor||[1,1,1];return t.specularColor=(new h.Color).setRGB(s[0],s[1],s[2],h.LinearSRGBColorSpace),void 0!==r.specularColorTexture&&n.push(this.parser.assignTexture(t,"specularColorMap",r.specularColorTexture,h.SRGBColorSpace)),Promise.all(n)}}class N{constructor(e){this.parser=e,this.name=x.EXT_MATERIALS_BUMP}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];return t.bumpScale=void 0!==r.bumpFactor?r.bumpFactor:1,void 0!==r.bumpTexture&&n.push(this.parser.assignTexture(t,"bumpMap",r.bumpTexture)),Promise.all(n)}}class O{constructor(e){this.parser=e,this.name=x.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return null!==R(this.parser,e,this.name)?h.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const r=R(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];return void 0!==r.anisotropyStrength&&(t.anisotropy=r.anisotropyStrength),void 0!==r.anisotropyRotation&&(t.anisotropyRotation=r.anisotropyRotation),void 0!==r.anisotropyTexture&&n.push(this.parser.assignTexture(t,"anisotropyMap",r.anisotropyTexture)),Promise.all(n)}}class P{constructor(e){this.parser=e,this.name=x.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,r=t.json,n=r.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const s=n.extensions[this.name],i=t.options.ktx2Loader;if(!i){if(r.extensionsRequired&&r.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,s.source,i)}}class k{constructor(e){this.parser=e,this.name=x.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,r=this.parser,n=r.json,s=n.textures[e];if(!s.extensions||!s.extensions[t])return null;const i=s.extensions[t],o=n.images[i.source];let a=r.textureLoader;if(o.uri){const e=r.options.manager.getHandler(o.uri);null!==e&&(a=e)}return r.loadTextureImage(e,i.source,a)}}class H{constructor(e){this.parser=e,this.name=x.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,r=this.parser,n=r.json,s=n.textures[e];if(!s.extensions||!s.extensions[t])return null;const i=s.extensions[t],o=n.images[i.source];let a=r.textureLoader;if(o.uri){const e=r.options.manager.getHandler(o.uri);null!==e&&(a=e)}return r.loadTextureImage(e,i.source,a)}}class F{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){const t=this.parser.json,r=t.bufferViews[e];if(r.extensions&&r.extensions[this.name]){const e=r.extensions[this.name],n=this.parser.getDependency("buffer",e.buffer),s=this.parser.options.meshoptDecoder;if(!s||!s.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 n.then(function(t){const r=e.byteOffset||0,n=e.byteLength||0,i=e.count,o=e.byteStride,a=new Uint8Array(t,r,n);return s.decodeGltfBufferAsync?s.decodeGltfBufferAsync(i,o,a,e.mode,e.filter).then(function(e){return e.buffer}):s.ready.then(function(){const t=new ArrayBuffer(i*o);return s.decodeGltfBuffer(new Uint8Array(t),i,o,a,e.mode,e.filter),t})})}return null}}class D{constructor(e){this.name=x.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,r=t.nodes[e];if(!r.extensions||!r.extensions[this.name]||void 0===r.mesh)return null;const n=t.meshes[r.mesh];for(const e of n.primitives)if(e.mode!==q.TRIANGLES&&e.mode!==q.TRIANGLE_STRIP&&e.mode!==q.TRIANGLE_FAN&&void 0!==e.mode)return null;const s=r.extensions[this.name].attributes,i=[],o={};for(const e in s)i.push(this.parser.getDependency("accessor",s[e]).then(t=>(o[e]=t,o[e])));return i.length<1?null:(i.push(this.parser.createNodeMesh(e)),Promise.all(i).then(e=>{const t=e.pop(),r=t.isGroup?t.children:[t],n=e[0].count,s=[];for(const e of r){const t=new h.Matrix4,r=new h.Vector3,i=new h.Quaternion,a=new h.Vector3(1,1,1),c=new h.InstancedMesh(e.geometry,e.material,n);for(let e=0;e<n;e++)o.TRANSLATION&&r.fromBufferAttribute(o.TRANSLATION,e),o.ROTATION&&i.fromBufferAttribute(o.ROTATION,e),o.SCALE&&a.fromBufferAttribute(o.SCALE,e),c.setMatrixAt(e,t.compose(r,i,a));for(const t in o)if("_COLOR_0"===t){const e=o[t];c.instanceColor=new h.InstancedBufferAttribute(e.array,e.itemSize,e.normalized)}else"TRANSLATION"!==t&&"ROTATION"!==t&&"SCALE"!==t&&e.geometry.setAttribute(t,o[t]);h.Object3D.prototype.copy.call(c,e),this.parser.assignFinalMaterial(c),s.push(c)}return t.isGroup?(t.clear(),t.add(...s),t):s[0]}))}}const G="glTF";class U{constructor(e){this.name=x.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,12),r=new TextDecoder;if(this.header={magic:r.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==G)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,s=new DataView(e,12);let i=0;for(;i<n;){const t=s.getUint32(i,!0);i+=4;const n=s.getUint32(i,!0);if(i+=4,1313821514===n){const n=new Uint8Array(e,12+i,t);this.content=r.decode(n)}else if(5130562===n){const r=12+i;this.body=e.slice(r,r+t)}i+=t}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class B{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=x.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const r=this.json,n=this.dracoLoader,s=e.extensions[this.name].bufferView,i=e.extensions[this.name].attributes,o={},a={},c={};for(const e in i){const t=Z[e]||e.toLowerCase();o[t]=i[e]}for(const t in e.attributes){const n=Z[t]||t.toLowerCase();if(void 0!==i[t]){const s=r.accessors[e.attributes[t]],i=W[s.componentType];c[n]=i.name,a[n]=!0===s.normalized}}return t.getDependency("bufferView",s).then(function(e){return new Promise(function(t,r){n.decodeDracoFile(e,function(e){for(const t in e.attributes){const r=e.attributes[t],n=a[t];void 0!==n&&(r.normalized=n)}t(e)},o,c,h.LinearSRGBColorSpace,r)})})}}class K{constructor(){this.name=x.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&t.texCoord!==e.channel||void 0!==t.offset||void 0!==t.rotation||void 0!==t.scale?(e=e.clone(),void 0!==t.texCoord&&(e.channel=t.texCoord),void 0!==t.offset&&e.offset.fromArray(t.offset),void 0!==t.rotation&&(e.rotation=t.rotation),void 0!==t.scale&&e.repeat.fromArray(t.scale),e.needsUpdate=!0,e):e}}class j{constructor(){this.name=x.KHR_MESH_QUANTIZATION}}class V extends h.Interpolant{constructor(e,t,r,n){super(e,t,r,n)}copySampleValue_(e){const t=this.resultBuffer,r=this.sampleValues,n=this.valueSize,s=e*n*3+n;for(let e=0;e!==n;e++)t[e]=r[s+e];return t}interpolate_(e,t,r,n){const s=this.resultBuffer,i=this.sampleValues,o=this.valueSize,a=2*o,c=3*o,l=n-t,u=(r-t)/l,h=u*u,d=h*u,p=e*c,m=p-c,f=-2*d+3*h,g=d-h,T=1-f,v=g-h+u;for(let e=0;e!==o;e++){const t=i[m+e+o],r=i[m+e+a]*l,n=i[p+e+o],c=i[p+e]*l;s[e]=T*t+v*r+f*n+g*c}return s}}const X=new h.Quaternion;class z extends V{interpolate_(e,t,r,n){const s=super.interpolate_(e,t,r,n);return X.fromArray(s).normalize().toArray(s),s}}const q={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},W={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Y={9728:h.NearestFilter,9729:h.LinearFilter,9984:h.NearestMipmapNearestFilter,9985:h.LinearMipmapNearestFilter,9986:h.NearestMipmapLinearFilter,9987:h.LinearMipmapLinearFilter},J={33071:h.ClampToEdgeWrapping,33648:h.MirroredRepeatWrapping,10497:h.RepeatWrapping},Q={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Z={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},$={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},ee={CUBICSPLINE:void 0,LINEAR:h.InterpolateLinear,STEP:h.InterpolateDiscrete};function te(e){return void 0===e.DefaultMaterial&&(e.DefaultMaterial=new h.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:h.FrontSide})),e.DefaultMaterial}function re(e,t,r){for(const n in r.extensions)void 0===e[n]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[n]=r.extensions[n])}function ne(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 se(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let r=0,n=t.weights.length;r<n;r++)e.morphTargetInfluences[r]=t.weights[r];if(t.extras&&Array.isArray(t.extras.targetNames)){const r=t.extras.targetNames;if(e.morphTargetInfluences.length===r.length){e.morphTargetDictionary={};for(let t=0,n=r.length;t<n;t++)e.morphTargetDictionary[r[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function ie(e){let t;const r=e.extensions&&e.extensions[x.KHR_DRACO_MESH_COMPRESSION];if(t=r?"draco:"+r.bufferView+":"+r.indices+":"+oe(r.attributes):e.indices+":"+oe(e.attributes)+":"+e.mode,void 0!==e.targets)for(let r=0,n=e.targets.length;r<n;r++)t+=":"+oe(e.targets[r]);return t}function oe(e){let t="";const r=Object.keys(e).sort();for(let n=0,s=r.length;n<s;n++)t+=r[n]+":"+e[r[n]]+";";return t}function ae(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}const ce=new h.Matrix4;class le{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new v,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let r=!1,n=-1,s=!1,i=-1;if("undefined"!=typeof navigator&&void 0!==navigator.userAgent){const e=navigator.userAgent;r=!0===/^((?!chrome|android).)*safari/i.test(e);const t=e.match(/Version\/(\d+)/);n=r&&t?parseInt(t[1],10):-1,s=e.indexOf("Firefox")>-1,i=s?e.match(/Firefox\/([0-9]+)\./)[1]:-1}"undefined"==typeof createImageBitmap||r&&n<17||s&&i<98?this.textureLoader=new h.TextureLoader(this.options.manager):this.textureLoader=new h.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new h.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 r=this,n=this.json,s=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([r.getDependencies("scene"),r.getDependencies("animation"),r.getDependencies("camera")])}).then(function(t){const i={scene:t[0][n.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:n.asset,parser:r,userData:{}};return re(s,i,n),ne(i,n),Promise.all(r._invokeAll(function(e){return e.afterRoot&&e.afterRoot(i)})).then(function(){for(const e of i.scenes)e.updateMatrixWorld();e(i)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],r=this.json.meshes||[];for(let r=0,n=t.length;r<n;r++){const n=t[r].joints;for(let t=0,r=n.length;t<r;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&&(r[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,r){if(e.refs[t]<=1)return r;const n=r.clone(),s=(e,t)=>{const r=this.associations.get(e);null!=r&&this.associations.set(t,r);for(const[r,n]of e.children.entries())s(n,t.children[r])};return s(r,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let r=0;r<t.length;r++){const n=e(t[r]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const r=[];for(let n=0;n<t.length;n++){const s=e(t[n]);s&&r.push(s)}return r}getDependency(e,t){const r=e+":"+t;let n=this.cache.get(r);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this._invokeOne(function(e){return e.loadNode&&e.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._invokeOne(function(e){return e.loadAnimation&&e.loadAnimation(t)});break;case"camera":n=this.loadCamera(t);break;default:if(n=this._invokeOne(function(r){return r!=this&&r.getDependency&&r.getDependency(e,t)}),!n)throw new Error("Unknown type: "+e)}this.cache.add(r,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const r=this,n=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(n.map(function(t,n){return r.getDependency(e,n)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],r=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[x.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(e,s){r.load(h.LoaderUtils.resolveURL(t.uri,n.path),e,void 0,function(){s(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 r=t.byteLength||0,n=t.byteOffset||0;return e.slice(n,n+r)})}loadAccessor(e){const t=this,r=this.json,n=this.json.accessors[e];if(void 0===n.bufferView&&void 0===n.sparse){const e=Q[n.type],t=W[n.componentType],r=!0===n.normalized,s=new t(n.count*e);return Promise.resolve(new h.BufferAttribute(s,e,r))}const s=[];return void 0!==n.bufferView?s.push(this.getDependency("bufferView",n.bufferView)):s.push(null),void 0!==n.sparse&&(s.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),s.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(s).then(function(e){const s=e[0],i=Q[n.type],o=W[n.componentType],a=o.BYTES_PER_ELEMENT,c=a*i,l=n.byteOffset||0,u=void 0!==n.bufferView?r.bufferViews[n.bufferView].byteStride:void 0,d=!0===n.normalized;let p,m;if(u&&u!==c){const e=Math.floor(l/u),r="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+e+":"+n.count;let c=t.cache.get(r);c||(p=new o(s,e*u,n.count*u/a),c=new h.InterleavedBuffer(p,u/a),t.cache.add(r,c)),m=new h.InterleavedBufferAttribute(c,i,l%u/a,d)}else p=null===s?new o(n.count*i):new o(s,l,n.count*i),m=new h.BufferAttribute(p,i,d);if(void 0!==n.sparse){const t=Q.SCALAR,r=W[n.sparse.indices.componentType],a=n.sparse.indices.byteOffset||0,c=n.sparse.values.byteOffset||0,l=new r(e[1],a,n.sparse.count*t),u=new o(e[2],c,n.sparse.count*i);null!==s&&(m=new h.BufferAttribute(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let e=0,t=l.length;e<t;e++){const t=l[e];if(m.setX(t,u[e*i]),i>=2&&m.setY(t,u[e*i+1]),i>=3&&m.setZ(t,u[e*i+2]),i>=4&&m.setW(t,u[e*i+3]),i>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=d}return m})}loadTexture(e){const t=this.json,r=this.options,n=t.textures[e].source,s=t.images[n];let i=this.textureLoader;if(s.uri){const e=r.manager.getHandler(s.uri);null!==e&&(i=e)}return this.loadTextureImage(e,n,i)}loadTextureImage(e,t,r){const n=this,s=this.json,i=s.textures[e],o=s.images[t],a=(o.uri||o.bufferView)+":"+i.sampler;if(this.textureCache[a])return this.textureCache[a];const c=this.loadImageSource(t,r).then(function(t){t.flipY=!1,t.name=i.name||o.name||"",""===t.name&&"string"==typeof o.uri&&!1===o.uri.startsWith("data:image/")&&(t.name=o.uri);const r=(s.samplers||{})[i.sampler]||{};return t.magFilter=Y[r.magFilter]||h.LinearFilter,t.minFilter=Y[r.minFilter]||h.LinearMipmapLinearFilter,t.wrapS=J[r.wrapS]||h.RepeatWrapping,t.wrapT=J[r.wrapT]||h.RepeatWrapping,t.generateMipmaps=!t.isCompressedTexture&&t.minFilter!==h.NearestFilter&&t.minFilter!==h.LinearFilter,n.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[a]=c,c}loadImageSource(e,t){const r=this.json,n=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then(e=>e.clone());const s=r.images[e],i=self.URL||self.webkitURL;let o=s.uri||"",a=!1;if(void 0!==s.bufferView)o=this.getDependency("bufferView",s.bufferView).then(function(e){a=!0;const t=new Blob([e],{type:s.mimeType});return o=i.createObjectURL(t),o});else if(void 0===s.uri)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const c=Promise.resolve(o).then(function(e){return new Promise(function(r,s){let i=r;!0===t.isImageBitmapLoader&&(i=function(e){const t=new h.Texture(e);t.needsUpdate=!0,r(t)}),t.load(h.LoaderUtils.resolveURL(e,n.path),i,void 0,s)})}).then(function(e){var t;return!0===a&&i.revokeObjectURL(o),ne(e,s),e.userData.mimeType=s.mimeType||((t=s.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":t.search(/\.ktx2($|\?)/i)>0||0===t.search(/^data\:image\/ktx2/)?"image/ktx2":"image/png"),e}).catch(function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",o),e});return this.sourceCache[e]=c,c}assignTexture(e,t,r,n){const s=this;return this.getDependency("texture",r.index).then(function(i){if(!i)return null;if(void 0!==r.texCoord&&r.texCoord>0&&((i=i.clone()).channel=r.texCoord),s.extensions[x.KHR_TEXTURE_TRANSFORM]){const e=void 0!==r.extensions?r.extensions[x.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=s.associations.get(i);i=s.extensions[x.KHR_TEXTURE_TRANSFORM].extendTexture(i,e),s.associations.set(i,t)}}return void 0!==n&&(i.colorSpace=n),e[t]=i,i})}assignFinalMaterial(e){const t=e.geometry;let r=e.material;const n=void 0===t.attributes.tangent,s=void 0!==t.attributes.color,i=void 0===t.attributes.normal;if(e.isPoints){const e="PointsMaterial:"+r.uuid;let t=this.cache.get(e);t||(t=new h.PointsMaterial,h.Material.prototype.copy.call(t,r),t.color.copy(r.color),t.map=r.map,t.sizeAttenuation=!1,this.cache.add(e,t)),r=t}else if(e.isLine){const e="LineBasicMaterial:"+r.uuid;let t=this.cache.get(e);t||(t=new h.LineBasicMaterial,h.Material.prototype.copy.call(t,r),t.color.copy(r.color),t.map=r.map,this.cache.add(e,t)),r=t}if(n||s||i){let e="ClonedMaterial:"+r.uuid+":";n&&(e+="derivative-tangents:"),s&&(e+="vertex-colors:"),i&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=r.clone(),s&&(t.vertexColors=!0),i&&(t.flatShading=!0),n&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(r))),r=t}e.material=r}getMaterialType(){return h.MeshStandardMaterial}loadMaterial(e){const t=this,r=this.json,n=this.extensions,s=r.materials[e];let i;const o={},a=[];if((s.extensions||{})[x.KHR_MATERIALS_UNLIT]){const e=n[x.KHR_MATERIALS_UNLIT];i=e.getMaterialType(),a.push(e.extendParams(o,s,t))}else{const r=s.pbrMetallicRoughness||{};if(o.color=new h.Color(1,1,1),o.opacity=1,Array.isArray(r.baseColorFactor)){const e=r.baseColorFactor;o.color.setRGB(e[0],e[1],e[2],h.LinearSRGBColorSpace),o.opacity=e[3]}void 0!==r.baseColorTexture&&a.push(t.assignTexture(o,"map",r.baseColorTexture,h.SRGBColorSpace)),o.metalness=void 0!==r.metallicFactor?r.metallicFactor:1,o.roughness=void 0!==r.roughnessFactor?r.roughnessFactor:1,void 0!==r.metallicRoughnessTexture&&(a.push(t.assignTexture(o,"metalnessMap",r.metallicRoughnessTexture)),a.push(t.assignTexture(o,"roughnessMap",r.metallicRoughnessTexture))),i=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),a.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,o)})))}!0===s.doubleSided&&(o.side=h.DoubleSide);const c=s.alphaMode||"OPAQUE";if("BLEND"===c?(o.transparent=!0,o.depthWrite=!1):(o.transparent=!1,"MASK"===c&&(o.alphaTest=void 0!==s.alphaCutoff?s.alphaCutoff:.5)),void 0!==s.normalTexture&&i!==h.MeshBasicMaterial&&(a.push(t.assignTexture(o,"normalMap",s.normalTexture)),o.normalScale=new h.Vector2(1,1),void 0!==s.normalTexture.scale)){const e=s.normalTexture.scale;o.normalScale.set(e,e)}if(void 0!==s.occlusionTexture&&i!==h.MeshBasicMaterial&&(a.push(t.assignTexture(o,"aoMap",s.occlusionTexture)),void 0!==s.occlusionTexture.strength&&(o.aoMapIntensity=s.occlusionTexture.strength)),void 0!==s.emissiveFactor&&i!==h.MeshBasicMaterial){const e=s.emissiveFactor;o.emissive=(new h.Color).setRGB(e[0],e[1],e[2],h.LinearSRGBColorSpace)}return void 0!==s.emissiveTexture&&i!==h.MeshBasicMaterial&&a.push(t.assignTexture(o,"emissiveMap",s.emissiveTexture,h.SRGBColorSpace)),Promise.all(a).then(function(){const r=new i(o);return s.name&&(r.name=s.name),ne(r,s),t.associations.set(r,{materials:e}),s.extensions&&re(n,r,s),r})}createUniqueName(e){const t=h.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,r=this.extensions,n=this.primitiveCache;function s(e){return r[x.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then(function(r){return ue(r,e,t)})}const i=[];for(let r=0,o=e.length;r<o;r++){const o=e[r],a=ie(o),c=n[a];if(c)i.push(c.promise);else{let e;e=o.extensions&&o.extensions[x.KHR_DRACO_MESH_COMPRESSION]?s(o):ue(new h.BufferGeometry,o,t),n[a]={primitive:o,promise:e},i.push(e)}}return Promise.all(i)}loadMesh(e){const t=this,r=this.json,n=this.extensions,s=r.meshes[e],i=s.primitives,o=[];for(let e=0,t=i.length;e<t;e++){const t=void 0===i[e].material?te(this.cache):this.getDependency("material",i[e].material);o.push(t)}return o.push(t.loadGeometries(i)),Promise.all(o).then(function(r){const o=r.slice(0,r.length-1),a=r[r.length-1],c=[];for(let r=0,l=a.length;r<l;r++){const l=a[r],u=i[r];let d;const p=o[r];if(u.mode===q.TRIANGLES||u.mode===q.TRIANGLE_STRIP||u.mode===q.TRIANGLE_FAN||void 0===u.mode)d=!0===s.isSkinnedMesh?new h.SkinnedMesh(l,p):new h.Mesh(l,p),!0===d.isSkinnedMesh&&d.normalizeSkinWeights(),u.mode===q.TRIANGLE_STRIP?d.geometry=m(d.geometry,h.TriangleStripDrawMode):u.mode===q.TRIANGLE_FAN&&(d.geometry=m(d.geometry,h.TriangleFanDrawMode));else if(u.mode===q.LINES)d=new h.LineSegments(l,p);else if(u.mode===q.LINE_STRIP)d=new h.Line(l,p);else if(u.mode===q.LINE_LOOP)d=new h.LineLoop(l,p);else{if(u.mode!==q.POINTS)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+u.mode);d=new h.Points(l,p)}Object.keys(d.geometry.morphAttributes).length>0&&se(d,s),d.name=t.createUniqueName(s.name||"mesh_"+e),ne(d,s),u.extensions&&re(n,d,u),t.assignFinalMaterial(d),c.push(d)}for(let r=0,n=c.length;r<n;r++)t.associations.set(c[r],{meshes:e,primitives:r});if(1===c.length)return s.extensions&&re(n,c[0],s),c[0];const l=new h.Group;s.extensions&&re(n,l,s),t.associations.set(l,{meshes:e});for(let e=0,t=c.length;e<t;e++)l.add(c[e]);return l})}loadCamera(e){let t;const r=this.json.cameras[e],n=r[r.type];if(n)return"perspective"===r.type?t=new h.PerspectiveCamera(h.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):"orthographic"===r.type&&(t=new h.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),r.name&&(t.name=this.createUniqueName(r.name)),ne(t,r),Promise.resolve(t);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],r=[];for(let e=0,n=t.joints.length;e<n;e++)r.push(this._loadNodeShallow(t.joints[e]));return void 0!==t.inverseBindMatrices?r.push(this.getDependency("accessor",t.inverseBindMatrices)):r.push(null),Promise.all(r).then(function(e){const r=e.pop(),n=e,s=[],i=[];for(let e=0,o=n.length;e<o;e++){const o=n[e];if(o){s.push(o);const t=new h.Matrix4;null!==r&&t.fromArray(r.array,16*e),i.push(t)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[e])}return new h.Skeleton(s,i)})}loadAnimation(e){const t=this.json,r=this,n=t.animations[e],s=n.name?n.name:"animation_"+e,i=[],o=[],a=[],c=[],l=[];for(let e=0,t=n.channels.length;e<t;e++){const t=n.channels[e],r=n.samplers[t.sampler],s=t.target,u=s.node,h=void 0!==n.parameters?n.parameters[r.input]:r.input,d=void 0!==n.parameters?n.parameters[r.output]:r.output;void 0!==s.node&&(i.push(this.getDependency("node",u)),o.push(this.getDependency("accessor",h)),a.push(this.getDependency("accessor",d)),c.push(r),l.push(s))}return Promise.all([Promise.all(i),Promise.all(o),Promise.all(a),Promise.all(c),Promise.all(l)]).then(function(e){const t=e[0],i=e[1],o=e[2],a=e[3],c=e[4],l=[];for(let e=0,n=t.length;e<n;e++){const n=t[e],s=i[e],u=o[e],h=a[e],d=c[e];if(void 0===n)continue;n.updateMatrix&&n.updateMatrix();const p=r._createAnimationTracks(n,s,u,h,d);if(p)for(let e=0;e<p.length;e++)l.push(p[e])}const u=new h.AnimationClip(s,void 0,l);return ne(u,n),u})}createNodeMesh(e){const t=this.json,r=this,n=t.nodes[e];return void 0===n.mesh?null:r.getDependency("mesh",n.mesh).then(function(e){const t=r._getNodeRef(r.meshCache,n.mesh,e);return void 0!==n.weights&&t.traverse(function(e){if(e.isMesh)for(let t=0,r=n.weights.length;t<r;t++)e.morphTargetInfluences[t]=n.weights[t]}),t})}loadNode(e){const t=this,r=this.json.nodes[e],n=t._loadNodeShallow(e),s=[],i=r.children||[];for(let e=0,r=i.length;e<r;e++)s.push(t.getDependency("node",i[e]));const o=void 0===r.skin?Promise.resolve(null):t.getDependency("skin",r.skin);return Promise.all([n,Promise.all(s),o]).then(function(e){const t=e[0],r=e[1],n=e[2];null!==n&&t.traverse(function(e){e.isSkinnedMesh&&e.bind(n,ce)});for(let e=0,n=r.length;e<n;e++)t.add(r[e]);if(void 0!==t.userData.pivot&&r.length>0){const e=t.userData.pivot,n=r[0];t.pivot=(new h.Vector3).fromArray(e),t.position.x-=e[0],t.position.y-=e[1],t.position.z-=e[2],n.position.set(0,0,0),delete t.userData.pivot}return t})}_loadNodeShallow(e){const t=this.json,r=this.extensions,n=this;if(void 0!==this.nodeCache[e])return this.nodeCache[e];const s=t.nodes[e],i=s.name?n.createUniqueName(s.name):"",o=[],a=n._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return a&&o.push(a),void 0!==s.camera&&o.push(n.getDependency("camera",s.camera).then(function(e){return n._getNodeRef(n.cameraCache,s.camera,e)})),n._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){o.push(e)}),this.nodeCache[e]=Promise.all(o).then(function(t){let o;if(o=!0===s.isBone?new h.Bone:t.length>1?new h.Group:1===t.length?t[0]:new h.Object3D,o!==t[0])for(let e=0,r=t.length;e<r;e++)o.add(t[e]);if(s.name&&(o.userData.name=s.name,o.name=i),ne(o,s),s.extensions&&re(r,o,s),void 0!==s.matrix){const e=new h.Matrix4;e.fromArray(s.matrix),o.applyMatrix4(e)}else void 0!==s.translation&&o.position.fromArray(s.translation),void 0!==s.rotation&&o.quaternion.fromArray(s.rotation),void 0!==s.scale&&o.scale.fromArray(s.scale);if(n.associations.has(o)){if(void 0!==s.mesh&&n.meshCache.refs[s.mesh]>1){const e=n.associations.get(o);n.associations.set(o,{...e})}}else n.associations.set(o,{});return n.associations.get(o).nodes=e,o}),this.nodeCache[e]}loadScene(e){const t=this.extensions,r=this.json.scenes[e],n=this,s=new h.Group;r.name&&(s.name=n.createUniqueName(r.name)),ne(s,r),r.extensions&&re(t,s,r);const i=r.nodes||[],o=[];for(let e=0,t=i.length;e<t;e++)o.push(n.getDependency("node",i[e]));return Promise.all(o).then(function(e){for(let t=0,r=e.length;t<r;t++){const r=e[t];null!==r.parent?s.add(f(r)):s.add(r)}return n.associations=(e=>{const t=new Map;for(const[e,r]of n.associations)(e instanceof h.Material||e instanceof h.Texture)&&t.set(e,r);return e.traverse(e=>{const r=n.associations.get(e);null!=r&&t.set(e,r)}),t})(s),s})}_createAnimationTracks(e,t,r,n,s){const i=[],o=e.name?e.name:e.uuid,a=[];function c(e){e.morphTargetInfluences&&a.push(e.name?e.name:e.uuid)}let l;switch($[s.path]===$.weights?(c(e),e.isGroup&&e.children.forEach(c)):a.push(o),$[s.path]){case $.weights:l=h.NumberKeyframeTrack;break;case $.rotation:l=h.QuaternionKeyframeTrack;break;case $.translation:case $.scale:l=h.VectorKeyframeTrack;break;default:l=1===r.itemSize?h.NumberKeyframeTrack:h.VectorKeyframeTrack}const u=void 0!==n.interpolation?ee[n.interpolation]:h.InterpolateLinear,d=this._getArrayFromAccessor(r);for(let e=0,r=a.length;e<r;e++){const r=new l(a[e]+"."+$[s.path],t.array,d,u);"CUBICSPLINE"===n.interpolation&&this._createCubicSplineTrackInterpolant(r),i.push(r)}return i}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const e=ae(t.constructor),r=new Float32Array(t.length);for(let n=0,s=t.length;n<s;n++)r[n]=t[n]*e;t=r}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof h.QuaternionKeyframeTrack?z:V)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function ue(e,t,r){const n=t.attributes,s=[];function i(t,n){return r.getDependency("accessor",t).then(function(t){e.setAttribute(n,t)})}for(const t in n){const r=Z[t]||t.toLowerCase();r in e.attributes||s.push(i(n[t],r))}if(void 0!==t.indices&&!e.index){const n=r.getDependency("accessor",t.indices).then(function(t){e.setIndex(t)});s.push(n)}return h.ColorManagement.workingColorSpace!==h.LinearSRGBColorSpace&&"COLOR_0"in n&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${h.ColorManagement.workingColorSpace}" not supported.`),ne(e,t),function(e,t,r){const n=t.attributes,s=new h.Box3;if(void 0===n.POSITION)return;{const e=r.json.accessors[n.POSITION],t=e.min,i=e.max;if(void 0===t||void 0===i)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(s.set(new h.Vector3(t[0],t[1],t[2]),new h.Vector3(i[0],i[1],i[2])),e.normalized){const t=ae(W[e.componentType]);s.min.multiplyScalar(t),s.max.multiplyScalar(t)}}const i=t.targets;if(void 0!==i){const e=new h.Vector3,t=new h.Vector3;for(let n=0,s=i.length;n<s;n++){const s=i[n];if(void 0!==s.POSITION){const n=r.json.accessors[s.POSITION],i=n.min,o=n.max;if(void 0!==i&&void 0!==o){if(t.setX(Math.max(Math.abs(i[0]),Math.abs(o[0]))),t.setY(Math.max(Math.abs(i[1]),Math.abs(o[1]))),t.setZ(Math.max(Math.abs(i[2]),Math.abs(o[2]))),n.normalized){const e=ae(W[n.componentType]);t.multiplyScalar(e)}e.max(t)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}s.expandByVector(e)}e.boundingBox=s;const o=new h.Sphere;s.getCenter(o.center),o.radius=s.min.distanceTo(s.max)/2,e.boundingSphere=o}(e,t,r),Promise.all(s).then(function(){return void 0!==t.targets?function(e,t,r){let n=!1,s=!1,i=!1;for(let e=0,r=t.length;e<r;e++){const r=t[e];if(void 0!==r.POSITION&&(n=!0),void 0!==r.NORMAL&&(s=!0),void 0!==r.COLOR_0&&(i=!0),n&&s&&i)break}if(!n&&!s&&!i)return Promise.resolve(e);const o=[],a=[],c=[];for(let l=0,u=t.length;l<u;l++){const u=t[l];if(n){const t=void 0!==u.POSITION?r.getDependency("accessor",u.POSITION):e.attribute