UNPKG

@webarkit/arnft-threejs

Version:

The ARnft rendering engine, based on Three.js

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