UNPKG

@webarkit/arnft-threejs

Version:

The ARnft rendering engine, based on Three.js

1 lines 55.5 kB
!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={381:t=>{t.exports=e}},s={};function n(e){var r=s[e];if(void 0!==r)return r.exports;var i=s[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var s in t)n.o(t,s)&&!n.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},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 r={};return(()=>{function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e){return t="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},t(e)}function s(e){var s=function(e,s){if("object"!==t(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!==t(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===t(s)?s:String(s)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,s(r.key),r)}}function o(e,t,s){return t&&i(e.prototype,t),s&&i(e,s),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(r,{default:()=>ie});var c=n(381),l=function(){function t(){e(this,t)}return o(t,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 s=[];for(var n in t)s[n]=t[n];"function"==typeof e.elements.set?e.elements.set(s):e.elements=[].slice.call(s)}}]),t}();a(l,"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 u=function(){function t(s,r,i,o){e(this,t),a(this,"canvas_draw",void 0),a(this,"camera",void 0),a(this,"configData",void 0),a(this,"renderer",void 0),a(this,"uuid",void 0),a(this,"root",void 0),a(this,"target",void 0),a(this,"scene",void 0),a(this,"version",void 0),this.configData=s,this.uuid=i,this.target=window||n.g,this.renderer=new c.WebGLRenderer({canvas:r,context:s.renderer.context,alpha:s.renderer.alpha,premultipliedAlpha:s.renderer.premultipliedAlpha,antialias:s.renderer.antialias,stencil:s.renderer.stencil,precision:s.renderer.precision,depth:s.renderer.depth,logarithmicDepthBuffer:s.renderer.logarithmicDepthBuffer}),this.renderer.setPixelRatio(window.devicePixelRatio),this.scene=new c.Scene,t.globalScene=this.scene,this.camera=!0===o?new c.PerspectiveCamera(s.camera.fov,s.camera.ratio,s.camera.near,s.camera.far):new c.PerspectiveCamera,this.version="0.5.1",console.log("ARnftThreejs version: ",this.version)}return o(t,[{key:"initRenderer",value:function(){var e=this;this.camera.matrixAutoUpdate=!1,this.target.addEventListener("getProjectionMatrix",(function(t){l.setMatrix(e.camera.projectionMatrix,t.detail.proj)})),this.scene.add(this.camera);var t=new c.AmbientLight(16777215);this.scene.add(t),this.target.addEventListener("getWindowSize",(function(t){e.renderer.setSize(t.detail.sw,t.detail.sh)}));var s=new CustomEvent("onInitThreejsRendering",{detail:{renderer:this.renderer,scene:this.scene,camera:this.camera}});this.target.dispatchEvent(s)}},{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 t.globalScene}}]),t}();function h(e,t){if(t===c.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t===c.TriangleFanDrawMode||t===c.TriangleStripDrawMode){let s=e.getIndex();if(null===s){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),s=e.getIndex()}const n=s.count-2,r=[];if(t===c.TriangleFanDrawMode)for(let e=1;e<=n;e++)r.push(s.getX(0)),r.push(s.getX(e)),r.push(s.getX(e+1));else for(let e=0;e<n;e++)e%2==0?(r.push(s.getX(e)),r.push(s.getX(e+1)),r.push(s.getX(e+2))):(r.push(s.getX(e+2)),r.push(s.getX(e+1)),r.push(s.getX(e)));r.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=e.clone();return i.setIndex(r),i.clearGroups(),i}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e}a(u,"globalScene",void 0);class d extends c.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new T(e)})),this.register((function(e){return new x(e)})),this.register((function(e){return new S(e)})),this.register((function(e){return new b(e)})),this.register((function(e){return new I(e)})),this.register((function(e){return new R(e)})),this.register((function(e){return new w(e)})),this.register((function(e){return new y(e)})),this.register((function(e){return new E(e)})),this.register((function(e){return new A(e)})),this.register((function(e){return new M(e)})),this.register((function(e){return new v(e)})),this.register((function(e){return new L(e)})),this.register((function(e){return new _(e)})),this.register((function(e){return new f(e)})),this.register((function(e){return new C(e)})),this.register((function(e){return new N(e)}))}load(e,t,s,n){const r=this;let i;if(""!==this.resourcePath)i=this.resourcePath;else if(""!==this.path){const t=c.LoaderUtils.extractUrlBase(e);i=c.LoaderUtils.resolveURL(t,this.path)}else i=c.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const o=function(t){n?n(t):console.error(t),r.manager.itemError(e),r.manager.itemEnd(e)},a=new c.FileLoader(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,(function(s){try{r.parse(s,i,(function(s){t(s),r.manager.itemEnd(e)}),o)}catch(e){o(e)}}),s,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,s,n){let r;const i={},o={},a=new TextDecoder;if("string"==typeof e)r=JSON.parse(e);else if(e instanceof ArrayBuffer)if(a.decode(new Uint8Array(e,0,4))===P){try{i[m.KHR_BINARY_GLTF]=new O(e)}catch(e){return void(n&&n(e))}r=JSON.parse(i[m.KHR_BINARY_GLTF].content)}else r=JSON.parse(a.decode(e));else r=e;if(void 0===r.asset||r.asset.version[0]<2)return void(n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const c=new se(r,{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(r.extensionsUsed)for(let e=0;e<r.extensionsUsed.length;++e){const t=r.extensionsUsed[e],s=r.extensionsRequired||[];switch(t){case m.KHR_MATERIALS_UNLIT:i[t]=new g;break;case m.KHR_DRACO_MESH_COMPRESSION:i[t]=new k(r,this.dracoLoader);break;case m.KHR_TEXTURE_TRANSFORM:i[t]=new H;break;case m.KHR_MESH_QUANTIZATION:i[t]=new F;break;default:s.indexOf(t)>=0&&void 0===o[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}c.setExtensions(i),c.setPlugins(o),c.parse(s,n)}parseAsync(e,t){const s=this;return new Promise((function(n,r){s.parse(e,t,n,r)}))}}function p(){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 m={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",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class f{constructor(e){this.parser=e,this.name=m.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(e){const t=this.parser,s="light:"+e;let n=t.cache.get(s);if(n)return n;const r=t.json,i=((r.extensions&&r.extensions[this.name]||{}).lights||[])[e];let o;const a=new c.Color(16777215);void 0!==i.color&&a.setRGB(i.color[0],i.color[1],i.color[2],c.LinearSRGBColorSpace);const l=void 0!==i.range?i.range:0;switch(i.type){case"directional":o=new c.DirectionalLight(a),o.target.position.set(0,0,-1),o.add(o.target);break;case"point":o=new c.PointLight(a),o.distance=l;break;case"spot":o=new c.SpotLight(a),o.distance=l,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),o.decay=2,Y(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(s,n),n}getDependency(e,t){if("light"===e)return this._loadLight(t)}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 g{constructor(){this.name=m.KHR_MATERIALS_UNLIT}getMaterialType(){return c.MeshBasicMaterial}extendParams(e,t,s){const n=[];e.color=new c.Color(1,1,1),e.opacity=1;const r=t.pbrMetallicRoughness;if(r){if(Array.isArray(r.baseColorFactor)){const t=r.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],c.LinearSRGBColorSpace),e.opacity=t[3]}void 0!==r.baseColorTexture&&n.push(s.assignTexture(e,"map",r.baseColorTexture,c.SRGBColorSpace))}return Promise.all(n)}}class A{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=s.extensions[this.name].emissiveStrength;return void 0!==n&&(t.emissiveIntensity=n),Promise.resolve()}}class T{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.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=[],i=n.extensions[this.name];if(void 0!==i.clearcoatFactor&&(t.clearcoat=i.clearcoatFactor),void 0!==i.clearcoatTexture&&r.push(s.assignTexture(t,"clearcoatMap",i.clearcoatTexture)),void 0!==i.clearcoatRoughnessFactor&&(t.clearcoatRoughness=i.clearcoatRoughnessFactor),void 0!==i.clearcoatRoughnessTexture&&r.push(s.assignTexture(t,"clearcoatRoughnessMap",i.clearcoatRoughnessTexture)),void 0!==i.clearcoatNormalTexture&&(r.push(s.assignTexture(t,"clearcoatNormalMap",i.clearcoatNormalTexture)),void 0!==i.clearcoatNormalTexture.scale)){const e=i.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new c.Vector2(e,e)}return Promise.all(r)}}class x{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_DISPERSION}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=s.extensions[this.name];return t.dispersion=void 0!==n.dispersion?n.dispersion:0,Promise.resolve()}}class v{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.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=[],i=n.extensions[this.name];return void 0!==i.iridescenceFactor&&(t.iridescence=i.iridescenceFactor),void 0!==i.iridescenceTexture&&r.push(s.assignTexture(t,"iridescenceMap",i.iridescenceTexture)),void 0!==i.iridescenceIor&&(t.iridescenceIOR=i.iridescenceIor),void 0===t.iridescenceThicknessRange&&(t.iridescenceThicknessRange=[100,400]),void 0!==i.iridescenceThicknessMinimum&&(t.iridescenceThicknessRange[0]=i.iridescenceThicknessMinimum),void 0!==i.iridescenceThicknessMaximum&&(t.iridescenceThicknessRange[1]=i.iridescenceThicknessMaximum),void 0!==i.iridescenceThicknessTexture&&r.push(s.assignTexture(t,"iridescenceThicknessMap",i.iridescenceThicknessTexture)),Promise.all(r)}}class R{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_SHEEN}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.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=[];t.sheenColor=new c.Color(0,0,0),t.sheenRoughness=0,t.sheen=1;const i=n.extensions[this.name];if(void 0!==i.sheenColorFactor){const e=i.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],c.LinearSRGBColorSpace)}return void 0!==i.sheenRoughnessFactor&&(t.sheenRoughness=i.sheenRoughnessFactor),void 0!==i.sheenColorTexture&&r.push(s.assignTexture(t,"sheenColorMap",i.sheenColorTexture,c.SRGBColorSpace)),void 0!==i.sheenRoughnessTexture&&r.push(s.assignTexture(t,"sheenRoughnessMap",i.sheenRoughnessTexture)),Promise.all(r)}}class w{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.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=[],i=n.extensions[this.name];return void 0!==i.transmissionFactor&&(t.transmission=i.transmissionFactor),void 0!==i.transmissionTexture&&r.push(s.assignTexture(t,"transmissionMap",i.transmissionTexture)),Promise.all(r)}}class y{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_VOLUME}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.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=[],i=n.extensions[this.name];t.thickness=void 0!==i.thicknessFactor?i.thicknessFactor:0,void 0!==i.thicknessTexture&&r.push(s.assignTexture(t,"thicknessMap",i.thicknessTexture)),t.attenuationDistance=i.attenuationDistance||1/0;const o=i.attenuationColor||[1,1,1];return t.attenuationColor=(new c.Color).setRGB(o[0],o[1],o[2],c.LinearSRGBColorSpace),Promise.all(r)}}class E{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_IOR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const n=s.extensions[this.name];return t.ior=void 0!==n.ior?n.ior:1.5,Promise.resolve()}}class M{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_SPECULAR}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.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=[],i=n.extensions[this.name];t.specularIntensity=void 0!==i.specularFactor?i.specularFactor:1,void 0!==i.specularTexture&&r.push(s.assignTexture(t,"specularIntensityMap",i.specularTexture));const o=i.specularColorFactor||[1,1,1];return t.specularColor=(new c.Color).setRGB(o[0],o[1],o[2],c.LinearSRGBColorSpace),void 0!==i.specularColorTexture&&r.push(s.assignTexture(t,"specularColorMap",i.specularColorTexture,c.SRGBColorSpace)),Promise.all(r)}}class _{constructor(e){this.parser=e,this.name=m.EXT_MATERIALS_BUMP}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.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=[],i=n.extensions[this.name];return t.bumpScale=void 0!==i.bumpFactor?i.bumpFactor:1,void 0!==i.bumpTexture&&r.push(s.assignTexture(t,"bumpMap",i.bumpTexture)),Promise.all(r)}}class L{constructor(e){this.parser=e,this.name=m.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const t=this.parser.json.materials[e];return t.extensions&&t.extensions[this.name]?c.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=[],i=n.extensions[this.name];return void 0!==i.anisotropyStrength&&(t.anisotropy=i.anisotropyStrength),void 0!==i.anisotropyRotation&&(t.anisotropyRotation=i.anisotropyRotation),void 0!==i.anisotropyTexture&&r.push(s.assignTexture(t,"anisotropyMap",i.anisotropyTexture)),Promise.all(r)}}class S{constructor(e){this.parser=e,this.name=m.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],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,r.source,i)}}class b{constructor(e){this.parser=e,this.name=m.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 i=r.extensions[t],o=n.images[i.source];let a=s.textureLoader;if(o.uri){const e=s.options.manager.getHandler(o.uri);null!==e&&(a=e)}return this.detectSupport().then((function(r){if(r)return s.loadTextureImage(e,i.source,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 I{constructor(e){this.parser=e,this.name=m.EXT_TEXTURE_AVIF,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 i=r.extensions[t],o=n.images[i.source];let a=s.textureLoader;if(o.uri){const e=s.options.manager.getHandler(o.uri);null!==e&&(a=e)}return this.detectSupport().then((function(r){if(r)return s.loadTextureImage(e,i.source,a);if(n.extensionsRequired&&n.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF 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/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(1===t.height)}}))),this.isSupported}}class C{constructor(e){this.name=m.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 n.then((function(t){const s=e.byteOffset||0,n=e.byteLength||0,i=e.count,o=e.byteStride,a=new Uint8Array(t,s,n);return r.decodeGltfBufferAsync?r.decodeGltfBufferAsync(i,o,a,e.mode,e.filter).then((function(e){return e.buffer})):r.ready.then((function(){const t=new ArrayBuffer(i*o);return r.decodeGltfBuffer(new Uint8Array(t),i,o,a,e.mode,e.filter),t}))}))}return null}}class N{constructor(e){this.name=m.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,s=t.nodes[e];if(!s.extensions||!s.extensions[this.name]||void 0===s.mesh)return null;const n=t.meshes[s.mesh];for(const e of n.primitives)if(e.mode!==U.TRIANGLES&&e.mode!==U.TRIANGLE_STRIP&&e.mode!==U.TRIANGLE_FAN&&void 0!==e.mode)return null;const r=s.extensions[this.name].attributes,i=[],o={};for(const e in r)i.push(this.parser.getDependency("accessor",r[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(),s=t.isGroup?t.children:[t],n=e[0].count,r=[];for(const e of s){const t=new c.Matrix4,s=new c.Vector3,i=new c.Quaternion,a=new c.Vector3(1,1,1),l=new c.InstancedMesh(e.geometry,e.material,n);for(let e=0;e<n;e++)o.TRANSLATION&&s.fromBufferAttribute(o.TRANSLATION,e),o.ROTATION&&i.fromBufferAttribute(o.ROTATION,e),o.SCALE&&a.fromBufferAttribute(o.SCALE,e),l.setMatrixAt(e,t.compose(s,i,a));for(const t in o)if("_COLOR_0"===t){const e=o[t];l.instanceColor=new c.InstancedBufferAttribute(e.array,e.itemSize,e.normalized)}else"TRANSLATION"!==t&&"ROTATION"!==t&&"SCALE"!==t&&e.geometry.setAttribute(t,o[t]);c.Object3D.prototype.copy.call(l,e),this.parser.assignFinalMaterial(l),r.push(l)}return t.isGroup?(t.clear(),t.add(...r),t):r[0]})))}}const P="glTF";class O{constructor(e){this.name=m.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,12),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==P)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(e,12);let i=0;for(;i<n;){const t=r.getUint32(i,!0);i+=4;const n=r.getUint32(i,!0);if(i+=4,1313821514===n){const n=new Uint8Array(e,12+i,t);this.content=s.decode(n)}else if(5130562===n){const s=12+i;this.body=e.slice(s,s+t)}i+=t}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class k{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=m.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,i=e.extensions[this.name].attributes,o={},a={},l={};for(const e in i){const t=q[e]||e.toLowerCase();o[t]=i[e]}for(const t in e.attributes){const n=q[t]||t.toLowerCase();if(void 0!==i[t]){const r=s.accessors[e.attributes[t]],i=j[r.componentType];l[n]=i.name,a[n]=!0===r.normalized}}return t.getDependency("bufferView",r).then((function(e){return new Promise((function(t,s){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)}),o,l,c.LinearSRGBColorSpace,s)}))}))}}class H{constructor(){this.name=m.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 F{constructor(){this.name=m.KHR_MESH_QUANTIZATION}}class B extends c.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}interpolate_(e,t,s,n){const r=this.resultBuffer,i=this.sampleValues,o=this.valueSize,a=2*o,c=3*o,l=n-t,u=(s-t)/l,h=u*u,d=h*u,p=e*c,m=p-c,f=-2*d+3*h,g=d-h,A=1-f,T=g-h+u;for(let e=0;e!==o;e++){const t=i[m+e+o],s=i[m+e+a]*l,n=i[p+e+o],c=i[p+e]*l;r[e]=A*t+T*s+f*n+g*c}return r}}const D=new c.Quaternion;class G extends B{interpolate_(e,t,s,n){const r=super.interpolate_(e,t,s,n);return D.fromArray(r).normalize().toArray(r),r}}const U={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},j={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},K={9728:c.NearestFilter,9729:c.LinearFilter,9984:c.NearestMipmapNearestFilter,9985:c.LinearMipmapNearestFilter,9986:c.NearestMipmapLinearFilter,9987:c.LinearMipmapLinearFilter},V={33071:c.ClampToEdgeWrapping,33648:c.MirroredRepeatWrapping,10497:c.RepeatWrapping},X={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},q={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"},z={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},W={CUBICSPLINE:void 0,LINEAR:c.InterpolateLinear,STEP:c.InterpolateDiscrete};function Q(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 Y(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 Z(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 J(e){let t;const s=e.extensions&&e.extensions[m.KHR_DRACO_MESH_COMPRESSION];if(t=s?"draco:"+s.bufferView+":"+s.indices+":"+$(s.attributes):e.indices+":"+$(e.attributes)+":"+e.mode,void 0!==e.targets)for(let s=0,n=e.targets.length;s<n;s++)t+=":"+$(e.targets[s]);return t}function $(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 ee(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 te=new c.Matrix4;class se{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new p,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 s=!1,n=-1,r=!1,i=-1;if("undefined"!=typeof navigator){const e=navigator.userAgent;s=!0===/^((?!chrome|android).)*safari/i.test(e);const t=e.match(/Version\/(\d+)/);n=s&&t?parseInt(t[1],10):-1,r=e.indexOf("Firefox")>-1,i=r?e.match(/Firefox\/([0-9]+)\./)[1]:-1}"undefined"==typeof createImageBitmap||s&&n<17||r&&i<98?this.textureLoader=new c.TextureLoader(this.options.manager):this.textureLoader=new c.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new c.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.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([s.getDependencies("scene"),s.getDependencies("animation"),s.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:s,userData:{}};return Q(r,i,n),Y(i,n),Promise.all(s._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||[],s=this.json.meshes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s].joints;for(let t=0,s=n.length;t<s;t++)e[n[t]].isBone=!0}for(let t=0,n=e.length;t<n;t++){const n=e[t];void 0!==n.mesh&&(this._addNodeRef(this.meshCache,n.mesh),void 0!==n.skin&&(s[n.mesh].isSkinnedMesh=!0)),void 0!==n.camera&&this._addNodeRef(this.cameraCache,n.camera)}}_addNodeRef(e,t){void 0!==t&&(void 0===e.refs[t]&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const n=s.clone(),r=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,n]of e.children.entries())r(n,t.children[s])};return r(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const r=e(t[n]);r&&s.push(r)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this._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(s){return s!=this&&s.getDependency&&s.getDependency(e,t)})),!n)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[m.KHR_BINARY_GLTF].body);const n=this.options;return new Promise((function(e,r){s.load(c.LoaderUtils.resolveURL(t.uri,n.path),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(e){const t=this,s=this.json,n=this.json.accessors[e];if(void 0===n.bufferView&&void 0===n.sparse){const e=X[n.type],t=j[n.componentType],s=!0===n.normalized,r=new t(n.count*e);return Promise.resolve(new c.BufferAttribute(r,e,s))}const r=[];return void 0!==n.bufferView?r.push(this.getDependency("bufferView",n.bufferView)):r.push(null),void 0!==n.sparse&&(r.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),r.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(r).then((function(e){const r=e[0],i=X[n.type],o=j[n.componentType],a=o.BYTES_PER_ELEMENT,l=a*i,u=n.byteOffset||0,h=void 0!==n.bufferView?s.bufferViews[n.bufferView].byteStride:void 0,d=!0===n.normalized;let p,m;if(h&&h!==l){const e=Math.floor(u/h),s="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+e+":"+n.count;let l=t.cache.get(s);l||(p=new o(r,e*h,n.count*h/a),l=new c.InterleavedBuffer(p,h/a),t.cache.add(s,l)),m=new c.InterleavedBufferAttribute(l,i,u%h/a,d)}else p=null===r?new o(n.count*i):new o(r,u,n.count*i),m=new c.BufferAttribute(p,i,d);if(void 0!==n.sparse){const t=X.SCALAR,s=j[n.sparse.indices.componentType],a=n.sparse.indices.byteOffset||0,l=n.sparse.values.byteOffset||0,u=new s(e[1],a,n.sparse.count*t),h=new o(e[2],l,n.sparse.count*i);null!==r&&(m=new c.BufferAttribute(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let e=0,t=u.length;e<t;e++){const t=u[e];if(m.setX(t,h[e*i]),i>=2&&m.setY(t,h[e*i+1]),i>=3&&m.setZ(t,h[e*i+2]),i>=4&&m.setW(t,h[e*i+3]),i>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=d}return m}))}loadTexture(e){const t=this.json,s=this.options,n=t.textures[e].source,r=t.images[n];let i=this.textureLoader;if(r.uri){const e=s.manager.getHandler(r.uri);null!==e&&(i=e)}return this.loadTextureImage(e,n,i)}loadTextureImage(e,t,s){const n=this,r=this.json,i=r.textures[e],o=r.images[t],a=(o.uri||o.bufferView)+":"+i.sampler;if(this.textureCache[a])return this.textureCache[a];const l=this.loadImageSource(t,s).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 s=(r.samplers||{})[i.sampler]||{};return t.magFilter=K[s.magFilter]||c.LinearFilter,t.minFilter=K[s.minFilter]||c.LinearMipmapLinearFilter,t.wrapS=V[s.wrapS]||c.RepeatWrapping,t.wrapT=V[s.wrapT]||c.RepeatWrapping,n.associations.set(t,{textures:e}),t})).catch((function(){return null}));return this.textureCache[a]=l,l}loadImageSource(e,t){const s=this.json,n=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then((e=>e.clone()));const r=s.images[e],i=self.URL||self.webkitURL;let o=r.uri||"",a=!1;if(void 0!==r.bufferView)o=this.getDependency("bufferView",r.bufferView).then((function(e){a=!0;const t=new Blob([e],{type:r.mimeType});return o=i.createObjectURL(t),o}));else if(void 0===r.uri)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const l=Promise.resolve(o).then((function(e){return new Promise((function(s,r){let i=s;!0===t.isImageBitmapLoader&&(i=function(e){const t=new c.Texture(e);t.needsUpdate=!0,s(t)}),t.load(c.LoaderUtils.resolveURL(e,n.path),i,void 0,r)}))})).then((function(e){var t;return!0===a&&i.revokeObjectURL(o),Y(e,r),e.userData.mimeType=r.mimeType||((t=r.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":"image/png"),e})).catch((function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",o),e}));return this.sourceCache[e]=l,l}assignTexture(e,t,s,n){const r=this;return this.getDependency("texture",s.index).then((function(i){if(!i)return null;if(void 0!==s.texCoord&&s.texCoord>0&&((i=i.clone()).channel=s.texCoord),r.extensions[m.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[m.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=r.associations.get(i);i=r.extensions[m.KHR_TEXTURE_TRANSFORM].extendTexture(i,e),r.associations.set(i,t)}}return void 0!==n&&(i.colorSpace=n),e[t]=i,i}))}assignFinalMaterial(e){const t=e.geometry;let s=e.material;const n=void 0===t.attributes.tangent,r=void 0!==t.attributes.color,i=void 0===t.attributes.normal;if(e.isPoints){const e="PointsMaterial:"+s.uuid;let t=this.cache.get(e);t||(t=new c.PointsMaterial,c.Material.prototype.copy.call(t,s),t.color.copy(s.color),t.map=s.map,t.sizeAttenuation=!1,this.cache.add(e,t)),s=t}else if(e.isLine){const e="LineBasicMaterial:"+s.uuid;let t=this.cache.get(e);t||(t=new c.LineBasicMaterial,c.Material.prototype.copy.call(t,s),t.color.copy(s.color),t.map=s.map,this.cache.add(e,t)),s=t}if(n||r||i){let e="ClonedMaterial:"+s.uuid+":";n&&(e+="derivative-tangents:"),r&&(e+="vertex-colors:"),i&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=s.clone(),r&&(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(s))),s=t}e.material=s}getMaterialType(){return c.MeshStandardMaterial}loadMaterial(e){const t=this,s=this.json,n=this.extensions,r=s.materials[e];let i;const o={},a=[];if((r.extensions||{})[m.KHR_MATERIALS_UNLIT]){const e=n[m.KHR_MATERIALS_UNLIT];i=e.getMaterialType(),a.push(e.extendParams(o,r,t))}else{const s=r.pbrMetallicRoughness||{};if(o.color=new c.Color(1,1,1),o.opacity=1,Array.isArray(s.baseColorFactor)){const e=s.baseColorFactor;o.color.setRGB(e[0],e[1],e[2],c.LinearSRGBColorSpace),o.opacity=e[3]}void 0!==s.baseColorTexture&&a.push(t.assignTexture(o,"map",s.baseColorTexture,c.SRGBColorSpace)),o.metalness=void 0!==s.metallicFactor?s.metallicFactor:1,o.roughness=void 0!==s.roughnessFactor?s.roughnessFactor:1,void 0!==s.metallicRoughnessTexture&&(a.push(t.assignTexture(o,"metalnessMap",s.metallicRoughnessTexture)),a.push(t.assignTexture(o,"roughnessMap",s.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===r.doubleSided&&(o.side=c.DoubleSide);const l=r.alphaMode||"OPAQUE";if("BLEND"===l?(o.transparent=!0,o.depthWrite=!1):(o.transparent=!1,"MASK"===l&&(o.alphaTest=void 0!==r.alphaCutoff?r.alphaCutoff:.5)),void 0!==r.normalTexture&&i!==c.MeshBasicMaterial&&(a.push(t.assignTexture(o,"normalMap",r.normalTexture)),o.normalScale=new c.Vector2(1,1),void 0!==r.normalTexture.scale)){const e=r.normalTexture.scale;o.normalScale.set(e,e)}if(void 0!==r.occlusionTexture&&i!==c.MeshBasicMaterial&&(a.push(t.assignTexture(o,"aoMap",r.occlusionTexture)),void 0!==r.occlusionTexture.strength&&(o.aoMapIntensity=r.occlusionTexture.strength)),void 0!==r.emissiveFactor&&i!==c.MeshBasicMaterial){const e=r.emissiveFactor;o.emissive=(new c.Color).setRGB(e[0],e[1],e[2],c.LinearSRGBColorSpace)}return void 0!==r.emissiveTexture&&i!==c.MeshBasicMaterial&&a.push(t.assignTexture(o,"emissiveMap",r.emissiveTexture,c.SRGBColorSpace)),Promise.all(a).then((function(){const s=new i(o);return r.name&&(s.name=r.name),Y(s,r),t.associations.set(s,{materials:e}),r.extensions&&Q(n,s,r),s}))}createUniqueName(e){const t=c.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,s=this.extensions,n=this.primitiveCache;function r(e){return s[m.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then((function(s){return ne(s,e,t)}))}const i=[];for(let s=0,o=e.length;s<o;s++){const o=e[s],a=J(o),l=n[a];if(l)i.push(l.promise);else{let e;e=o.extensions&&o.extensions[m.KHR_DRACO_MESH_COMPRESSION]?r(o):ne(new c.BufferGeometry,o,t),n[a]={primitive:o,promise:e},i.push(e)}}return Promise.all(i)}loadMesh(e){const t=this,s=this.json,n=this.extensions,r=s.meshes[e],i=r.primitives,o=[];for(let e=0,t=i.length;e<t;e++){const t=void 0===i[e].material?(void 0===(a=this.cache).DefaultMaterial&&(a.DefaultMaterial=new c.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:c.FrontSide})),a.DefaultMaterial):this.getDependency("material",i[e].material);o.push(t)}var a;return o.push(t.loadGeometries(i)),Promise.all(o).then((function(s){const o=s.slice(0,s.length-1),a=s[s.length-1],l=[];for(let s=0,u=a.length;s<u;s++){const u=a[s],d=i[s];let p;const m=o[s];if(d.mode===U.TRIANGLES||d.mode===U.TRIANGLE_STRIP||d.mode===U.TRIANGLE_FAN||void 0===d.mode)p=!0===r.isSkinnedMesh?new c.SkinnedMesh(u,m):new c.Mesh(u,m),!0===p.isSkinnedMesh&&p.normalizeSkinWeights(),d.mode===U.TRIANGLE_STRIP?p.geometry=h(p.geometry,c.TriangleStripDrawMode):d.mode===U.TRIANGLE_FAN&&(p.geometry=h(p.geometry,c.TriangleFanDrawMode));else if(d.mode===U.LINES)p=new c.LineSegments(u,m);else if(d.mode===U.LINE_STRIP)p=new c.Line(u,m);else if(d.mode===U.LINE_LOOP)p=new c.LineLoop(u,m);else{if(d.mode!==U.POINTS)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+d.mode);p=new c.Points(u,m)}Object.keys(p.geometry.morphAttributes).length>0&&Z(p,r),p.name=t.createUniqueName(r.name||"mesh_"+e),Y(p,r),d.extensions&&Q(n,p,d),t.assignFinalMaterial(p),l.push(p)}for(let s=0,n=l.length;s<n;s++)t.associations.set(l[s],{meshes:e,primitives:s});if(1===l.length)return r.extensions&&Q(n,l[0],r),l[0];const u=new c.Group;r.extensions&&Q(n,u,r),t.associations.set(u,{meshes:e});for(let e=0,t=l.length;e<t;e++)u.add(l[e]);return u}))}loadCamera(e){let t;const s=this.json.cameras[e],n=s[s.type];if(n)return"perspective"===s.type?t=new c.PerspectiveCamera(c.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):"orthographic"===s.type&&(t=new c.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(t.name=this.createUniqueName(s.name)),Y(t,s),Promise.resolve(t);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],s=[];for(let e=0,n=t.joints.length;e<n;e++)s.push(this._loadNodeShallow(t.joints[e]));return void 0!==t.inverseBindMatrices?s.push(this.getDependency("accessor",t.inverseBindMatrices)):s.push(null),Promise.all(s).then((function(e){const s=e.pop(),n=e,r=[],i=[];for(let e=0,o=n.length;e<o;e++){const o=n[e];if(o){r.push(o);const t=new c.Matrix4;null!==s&&t.fromArray(s.array,16*e),i.push(t)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[e])}return new c.Skeleton(r,i)}))}loadAnimation(e){const t=this.json,s=this,n=t.animations[e],r=n.name?n.name:"animation_"+e,i=[],o=[],a=[],l=[],u=[];for(let e=0,t=n.channels.length;e<t;e++){const t=n.channels[e],s=n.samplers[t.sampler],r=t.target,c=r.node,h=void 0!==n.parameters?n.parameters[s.input]:s.input,d=void 0!==n.parameters?n.parameters[s.output]:s.output;void 0!==r.node&&(i.push(this.getDependency("node",c)),o.push(this.getDependency("accessor",h)),a.push(this.getDependency("accessor",d)),l.push(s),u.push(r))}return Promise.all([Promise.all(i),Promise.all(o),Promise.all(a),Promise.all(l),Promise.all(u)]).then((function(e){const t=e[0],n=e[1],i=e[2],o=e[3],a=e[4],l=[];for(let e=0,r=t.length;e<r;e++){const r=t[e],c=n[e],u=i[e],h=o[e],d=a[e];if(void 0===r)continue;r.updateMatrix&&r.updateMatrix();const p=s._createAnimationTracks(r,c,u,h,d);if(p)for(let e=0;e<p.length;e++)l.push(p[e])}return new c.AnimationClip(r,void 0,l)}))}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(e){const t=this,s=this.json.nodes[e],n=t._loadNodeShallow(e),r=[],i=s.children||[];for(let e=0,s=i.length;e<s;e++)r.push(t.getDependency("node",i[e]));const o=void 0===s.skin?Promise.resolve(null):t.getDependency("skin",s.skin);return Promise.all([n,Promise.all(r),o]).then((function(e){const t=e[0],s=e[1],n=e[2];null!==n&&t.traverse((function(e){e.isSkinnedMesh&&e.bind(n,te)}));for(let e=0,n=s.length;e<n;e++)t.add(s[e]);return t}))}_loadNodeShallow(e){const t=this.json,s=this.extensions,n=this;if(void 0!==this.nodeCache[e])return this.nodeCache[e];const r=t.nodes[e],i=r.name?n.createUniqueName(r.name):"",o=[],a=n._invokeOne((function(t){return t.createNodeMesh&&t.createNodeMesh(e)}));return a&&o.push(a),void 0!==r.camera&&o.push(n.getDependency("camera",r.camera).then((function(e){return n._getNodeRef(n.cameraCache,r.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===r.isBone?new c.Bone:t.length>1?new c.Group:1===t.length?t[0]:new c.Object3D,o!==t[0])for(let e=0,s=t.length;e<s;e++)o.add(t[e]);if(r.name&&(o.userData.name=r.name,o.name=i),Y(o,r),r.extensions&&Q(s,o,r),void 0!==r.matrix){const e=new c.Matrix4;e.fromArray(r.matrix),o.applyMatrix4(e)}else void 0!==r.translation&&o.position.fromArray(r.translation),void 0!==r.rotation&&o.quaternion.fromArray(r.rotation),void 0!==r.scale&&o.scale.fromArray(r.scale);return n.associations.has(o)||n.associations.set(o,{}),n.associations.get(o).nodes=e,o})),this.nodeCache[e]}loadScene(e){const t=this.extensions,s=this.json.scenes[e],n=this,r=new c.Group;s.name&&(r.name=n.createUniqueName(s.name)),Y(r,s),s.extensions&&Q(t,r,s);const i=s.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,s=e.length;t<s;t++)r.add(e[t]);return n.associations=(e=>{const t=new Map;for(const[e,s]of n.associations)(e instanceof c.Material||e instanceof c.Texture)&&t.set(e,s);return e.traverse((e=>{const s=n.associations.get(e);null!=s&&t.set(e,s)})),t})(r),r}))}_createAnimationTracks(e,t,s,n,r){const i=[],o=e.name?e.name:e.uuid,a=[];let l;switch(z[r.path]===z.weights?e.traverse((function(e){e.morphTargetInfluences&&a.push(e.name?e.name:e.uuid)})):a.push(o),z[r.path]){case z.weights:l=c.NumberKeyframeTrack;break;case z.rotation:l=c.QuaternionKeyframeTrack;break;case z.position:case z.scale:l=c.VectorKeyframeTrack;break;default:l=1===s.itemSize?c.NumberKeyframeTrack:c.VectorKeyframeTrack}const u=void 0!==n.interpolation?W[n.interpolation]:c.InterpolateLinear,h=this._getArrayFromAccessor(s);for(let e=0,s=a.length;e<s;e++){const s=new l(a[e]+"."+z[r.path],t.array,h,u);"CUBICSPLINE"===n.interpolation&&this._createCubicSplineTrackInterpolant(s),i.push(s)}return i}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const e=ee(t.constructor),s=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n++)s[n]=t[n]*e;t=s}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof c.QuaternionKeyframeTrack?G:B)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function ne(e,t,s){const n=t.attributes,r=[];function i(t,n){return s.getDependency("accessor",t).then((function(t){e.setAttribute(n,t)}))}for(const t in n){const s=q[t]||t.toLowerCase();s in e.attributes||r.push(i(n[t],s))}if(void 0!==t.indices&&!e.index){const n=s.getDependency("accessor",t.indices).then((function(t){e.setIndex(t)}));r.push(n)}return c.ColorManagement.workingColorSpace!==c.LinearSRGBColorSpace&&"COLOR_0"in n&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${c.ColorManagement.workingColorSpace}" not supported.`),Y(e,t),function(e,t,s){const n=t.attributes,r=new c.Box3;if(void 0===n.POSITION)return;{const e=s.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(r.set(ne