@inweb/viewer-three 27.6.3 → 27.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,4 +21,4 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("three"),require("@inweb/viewer-three")):"function"==typeof define&&define.amd?define(["exports","three","@inweb/viewer-three"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).ODA=e.ODA||{},e.ODA.Three=e.ODA.Three||{},e.ODA.Three.Extensions=e.ODA.Three.Extensions||{}),e.THREE,e.ODA.Three)}(this,function(e,t,s){"use strict";function n(e,s){if(s===t.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(s===t.TriangleFanDrawMode||s===t.TriangleStripDrawMode){let n=e.getIndex();if(null===n){const t=[],s=e.getAttribute("position");if(void 0===s)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<s.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}const r=n.count-2,i=[];if(s===t.TriangleFanDrawMode)for(let e=1;e<=r;e++)i.push(n.getX(0)),i.push(n.getX(e)),i.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(i.push(n.getX(e)),i.push(n.getX(e+1)),i.push(n.getX(e+2))):(i.push(n.getX(e+2)),i.push(n.getX(e+1)),i.push(n.getX(e)));i.length/3!==r&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const o=e.clone();return o.setIndex(i),o.clearGroups(),o}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",s),e}class r extends t.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new u(e)}),this.register(function(e){return new h(e)}),this.register(function(e){return new v(e)}),this.register(function(e){return new _(e)}),this.register(function(e){return new M(e)}),this.register(function(e){return new m(e)}),this.register(function(e){return new p(e)}),this.register(function(e){return new f(e)}),this.register(function(e){return new g(e)}),this.register(function(e){return new l(e)}),this.register(function(e){return new T(e)}),this.register(function(e){return new d(e)}),this.register(function(e){return new R(e)}),this.register(function(e){return new x(e)}),this.register(function(e){return new a(e)}),this.register(function(e){return new w(e)}),this.register(function(e){return new E(e)})}load(e,s,n,r){const i=this;let o;if(""!==this.resourcePath)o=this.resourcePath;else if(""!==this.path){const s=t.LoaderUtils.extractUrlBase(e);o=t.LoaderUtils.resolveURL(s,this.path)}else o=t.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=function(t){r?r(t):console.error(t),i.manager.itemError(e),i.manager.itemEnd(e)},c=new t.FileLoader(this.manager);c.setPath(this.path),c.setResponseType("arraybuffer"),c.setRequestHeader(this.requestHeader),c.setWithCredentials(this.withCredentials),c.load(e,function(t){try{i.parse(t,o,function(t){s(t),i.manager.itemEnd(e)},a)}catch(e){a(e)}},n,a)}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={},a={},l=new TextDecoder;if("string"==typeof e)r=JSON.parse(e);else if(e instanceof ArrayBuffer){if(l.decode(new Uint8Array(e,0,4))===A){try{i[o.KHR_BINARY_GLTF]=new S(e)}catch(e){return void(n&&n(e))}r=JSON.parse(i[o.KHR_BINARY_GLTF].content)}else r=JSON.parse(l.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 u=new ee(r,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});u.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](u);t.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[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 o.KHR_MATERIALS_UNLIT:i[t]=new c;break;case o.KHR_DRACO_MESH_COMPRESSION:i[t]=new I(r,this.dracoLoader);break;case o.KHR_TEXTURE_TRANSFORM:i[t]=new b;break;case o.KHR_MESH_QUANTIZATION:i[t]=new C;break;default:s.indexOf(t)>=0&&void 0===a[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}u.setExtensions(i),u.setPlugins(a),u.parse(s,n)}parseAsync(e,t){const s=this;return new Promise(function(n,r){s.parse(e,t,n,r)})}}function i(){let e={};return{get:function(t){return e[t]},add:function(t,s){e[t]=s},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const o={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_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 a{constructor(e){this.parser=e,this.name=o.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const n=t[s];n.extensions&&n.extensions[this.name]&&void 0!==n.extensions[this.name].light&&e._addNodeRef(this.cache,n.extensions[this.name].light)}}_loadLight(e){const s=this.parser,n="light:"+e;let r=s.cache.get(n);if(r)return r;const i=s.json,o=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let a;const c=new t.Color(16777215);void 0!==o.color&&c.setRGB(o.color[0],o.color[1],o.color[2],t.LinearSRGBColorSpace);const l=void 0!==o.range?o.range:0;switch(o.type){case"directional":a=new t.DirectionalLight(c),a.target.position.set(0,0,-1),a.add(a.target);break;case"point":a=new t.PointLight(c),a.distance=l;break;case"spot":a=new t.SpotLight(c),a.distance=l,o.spot=o.spot||{},o.spot.innerConeAngle=void 0!==o.spot.innerConeAngle?o.spot.innerConeAngle:0,o.spot.outerConeAngle=void 0!==o.spot.outerConeAngle?o.spot.outerConeAngle:Math.PI/4,a.angle=o.spot.outerConeAngle,a.penumbra=1-o.spot.innerConeAngle/o.spot.outerConeAngle,a.target.position.set(0,0,-1),a.add(a.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+o.type)}return a.position.set(0,0,0),W(a,o),void 0!==o.intensity&&(a.intensity=o.intensity),a.name=s.createUniqueName(o.name||"light_"+e),r=Promise.resolve(a),s.cache.add(n,r),r}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 c{constructor(){this.name=o.KHR_MATERIALS_UNLIT}getMaterialType(){return t.MeshBasicMaterial}extendParams(e,s,n){const r=[];e.color=new t.Color(1,1,1),e.opacity=1;const i=s.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const s=i.baseColorFactor;e.color.setRGB(s[0],s[1],s[2],t.LinearSRGBColorSpace),e.opacity=s[3]}void 0!==i.baseColorTexture&&r.push(n.assignTexture(e,"map",i.baseColorTexture,t.SRGBColorSpace))}return Promise.all(r)}}class l{constructor(e){this.parser=e,this.name=o.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 u{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];if(void 0!==o.clearcoatFactor&&(s.clearcoat=o.clearcoatFactor),void 0!==o.clearcoatTexture&&i.push(n.assignTexture(s,"clearcoatMap",o.clearcoatTexture)),void 0!==o.clearcoatRoughnessFactor&&(s.clearcoatRoughness=o.clearcoatRoughnessFactor),void 0!==o.clearcoatRoughnessTexture&&i.push(n.assignTexture(s,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),void 0!==o.clearcoatNormalTexture&&(i.push(n.assignTexture(s,"clearcoatNormalMap",o.clearcoatNormalTexture)),void 0!==o.clearcoatNormalTexture.scale)){const e=o.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new t.Vector2(e,e)}return Promise.all(i)}}class h{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_DISPERSION}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.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 d{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.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 m{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_SHEEN}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[];s.sheenColor=new t.Color(0,0,0),s.sheenRoughness=0,s.sheen=1;const o=r.extensions[this.name];if(void 0!==o.sheenColorFactor){const e=o.sheenColorFactor;s.sheenColor.setRGB(e[0],e[1],e[2],t.LinearSRGBColorSpace)}return void 0!==o.sheenRoughnessFactor&&(s.sheenRoughness=o.sheenRoughnessFactor),void 0!==o.sheenColorTexture&&i.push(n.assignTexture(s,"sheenColorMap",o.sheenColorTexture,t.SRGBColorSpace)),void 0!==o.sheenRoughnessTexture&&i.push(n.assignTexture(s,"sheenRoughnessMap",o.sheenRoughnessTexture)),Promise.all(i)}}class p{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.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 f{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_VOLUME}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];s.thickness=void 0!==o.thicknessFactor?o.thicknessFactor:0,void 0!==o.thicknessTexture&&i.push(n.assignTexture(s,"thicknessMap",o.thicknessTexture)),s.attenuationDistance=o.attenuationDistance||1/0;const a=o.attenuationColor||[1,1,1];return s.attenuationColor=(new t.Color).setRGB(a[0],a[1],a[2],t.LinearSRGBColorSpace),Promise.all(i)}}class g{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_IOR}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.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 T{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_SPECULAR}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const n=this.parser,r=n.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const i=[],o=r.extensions[this.name];s.specularIntensity=void 0!==o.specularFactor?o.specularFactor:1,void 0!==o.specularTexture&&i.push(n.assignTexture(s,"specularIntensityMap",o.specularTexture));const a=o.specularColorFactor||[1,1,1];return s.specularColor=(new t.Color).setRGB(a[0],a[1],a[2],t.LinearSRGBColorSpace),void 0!==o.specularColorTexture&&i.push(n.assignTexture(s,"specularColorMap",o.specularColorTexture,t.SRGBColorSpace)),Promise.all(i)}}class x{constructor(e){this.parser=e,this.name=o.EXT_MATERIALS_BUMP}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.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 R{constructor(e){this.parser=e,this.name=o.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const s=this.parser.json.materials[e];return s.extensions&&s.extensions[this.name]?t.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 v{constructor(e){this.parser=e,this.name=o.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const r=n.extensions[this.name],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 _{constructor(e){this.parser=e,this.name=o.EXT_TEXTURE_WEBP}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 s.loadTextureImage(e,i.source,a)}}class M{constructor(e){this.parser=e,this.name=o.EXT_TEXTURE_AVIF}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 s.loadTextureImage(e,i.source,a)}}class w{constructor(e){this.name=o.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const e=s.extensions[this.name],n=this.parser.getDependency("buffer",e.buffer),r=this.parser.options.meshoptDecoder;if(!r||!r.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return 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 E{constructor(e){this.name=o.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const s=this.parser.json,n=s.nodes[e];if(!n.extensions||!n.extensions[this.name]||void 0===n.mesh)return null;const r=s.meshes[n.mesh];for(const e of r.primitives)if(e.mode!==H.TRIANGLES&&e.mode!==H.TRIANGLE_STRIP&&e.mode!==H.TRIANGLE_FAN&&void 0!==e.mode)return null;const i=n.extensions[this.name].attributes,o=[],a={};for(const e in i)o.push(this.parser.getDependency("accessor",i[e]).then(t=>(a[e]=t,a[e])));return o.length<1?null:(o.push(this.parser.createNodeMesh(e)),Promise.all(o).then(e=>{const s=e.pop(),n=s.isGroup?s.children:[s],r=e[0].count,i=[];for(const e of n){const s=new t.Matrix4,n=new t.Vector3,o=new t.Quaternion,c=new t.Vector3(1,1,1),l=new t.InstancedMesh(e.geometry,e.material,r);for(let e=0;e<r;e++)a.TRANSLATION&&n.fromBufferAttribute(a.TRANSLATION,e),a.ROTATION&&o.fromBufferAttribute(a.ROTATION,e),a.SCALE&&c.fromBufferAttribute(a.SCALE,e),l.setMatrixAt(e,s.compose(n,o,c));for(const s in a)if("_COLOR_0"===s){const e=a[s];l.instanceColor=new t.InstancedBufferAttribute(e.array,e.itemSize,e.normalized)}else"TRANSLATION"!==s&&"ROTATION"!==s&&"SCALE"!==s&&e.geometry.setAttribute(s,a[s]);t.Object3D.prototype.copy.call(l,e),this.parser.assignFinalMaterial(l),i.push(l)}return s.isGroup?(s.clear(),s.add(...i),s):i[0]}))}}const A="glTF",y=1313821514,L=5130562;class S{constructor(e){this.name=o.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!==A)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,n===y){const n=new Uint8Array(e,12+i,t);this.content=s.decode(n)}else if(n===L){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 I{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=o.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,s){const n=this.json,r=this.dracoLoader,i=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},c={},l={};for(const e in o){const t=G[e]||e.toLowerCase();a[t]=o[e]}for(const t in e.attributes){const s=G[t]||t.toLowerCase();if(void 0!==o[t]){const r=n.accessors[e.attributes[t]],i=F[r.componentType];l[s]=i.name,c[s]=!0===r.normalized}}return s.getDependency("bufferView",i).then(function(e){return new Promise(function(s,n){r.decodeDracoFile(e,function(e){for(const t in e.attributes){const s=e.attributes[t],n=c[t];void 0!==n&&(s.normalized=n)}s(e)},a,l,t.LinearSRGBColorSpace,n)})})}}class b{constructor(){this.name=o.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 C{constructor(){this.name=o.KHR_MESH_QUANTIZATION}}class N extends t.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,m=e*c,p=m-c,f=-2*d+3*h,g=d-h,T=1-f,x=g-h+u;for(let e=0;e!==o;e++){const t=i[p+e+o],s=i[p+e+a]*l,n=i[m+e+o],c=i[m+e]*l;r[e]=T*t+x*s+f*n+g*c}return r}}const O=new t.Quaternion;class P extends N{interpolate_(e,t,s,n){const r=super.interpolate_(e,t,s,n);return O.fromArray(r).normalize().toArray(r),r}}const H={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},F={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},k={9728:t.NearestFilter,9729:t.LinearFilter,9984:t.NearestMipmapNearestFilter,9985:t.LinearMipmapNearestFilter,9986:t.NearestMipmapLinearFilter,9987:t.LinearMipmapLinearFilter},D={33071:t.ClampToEdgeWrapping,33648:t.MirroredRepeatWrapping,10497:t.RepeatWrapping},U={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},G={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"},B={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},K={CUBICSPLINE:void 0,LINEAR:t.InterpolateLinear,STEP:t.InterpolateDiscrete},j="OPAQUE",V="MASK",X="BLEND";function z(e){return void 0===e.DefaultMaterial&&(e.DefaultMaterial=new t.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:t.FrontSide})),e.DefaultMaterial}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 W(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 Y(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 Q(e){let t;const s=e.extensions&&e.extensions[o.KHR_DRACO_MESH_COMPRESSION];if(t=s?"draco:"+s.bufferView+":"+s.indices+":"+J(s.attributes):e.indices+":"+J(e.attributes)+":"+e.mode,void 0!==e.targets)for(let s=0,n=e.targets.length;s<n;s++)t+=":"+J(e.targets[s]);return t}function J(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 Z(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 $=new t.Matrix4;class ee{constructor(e={},s={}){this.json=e,this.extensions={},this.plugins={},this.options=s,this.cache=new i,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,o=!1,a=-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,o=e.indexOf("Firefox")>-1,a=o?e.match(/Firefox\/([0-9]+)\./)[1]:-1}"undefined"==typeof createImageBitmap||n&&r<17||o&&a<98?this.textureLoader=new t.TextureLoader(this.options.manager):this.textureLoader=new t.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new t.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),W(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 s=this.json.buffers[e],n=this.fileLoader;if(s.type&&"arraybuffer"!==s.type)throw new Error("THREE.GLTFLoader: "+s.type+" buffer type is not supported.");if(void 0===s.uri&&0===e)return Promise.resolve(this.extensions[o.KHR_BINARY_GLTF].body);const r=this.options;return new Promise(function(e,i){n.load(t.LoaderUtils.resolveURL(s.uri,r.path),e,void 0,function(){i(new Error('THREE.GLTFLoader: Failed to load buffer "'+s.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 s=this,n=this.json,r=this.json.accessors[e];if(void 0===r.bufferView&&void 0===r.sparse){const e=U[r.type],s=F[r.componentType],n=!0===r.normalized,i=new s(r.count*e);return Promise.resolve(new t.BufferAttribute(i,e,n))}const i=[];return void 0!==r.bufferView?i.push(this.getDependency("bufferView",r.bufferView)):i.push(null),void 0!==r.sparse&&(i.push(this.getDependency("bufferView",r.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",r.sparse.values.bufferView))),Promise.all(i).then(function(e){const i=e[0],o=U[r.type],a=F[r.componentType],c=a.BYTES_PER_ELEMENT,l=c*o,u=r.byteOffset||0,h=void 0!==r.bufferView?n.bufferViews[r.bufferView].byteStride:void 0,d=!0===r.normalized;let m,p;if(h&&h!==l){const e=Math.floor(u/h),n="InterleavedBuffer:"+r.bufferView+":"+r.componentType+":"+e+":"+r.count;let l=s.cache.get(n);l||(m=new a(i,e*h,r.count*h/c),l=new t.InterleavedBuffer(m,h/c),s.cache.add(n,l)),p=new t.InterleavedBufferAttribute(l,o,u%h/c,d)}else m=null===i?new a(r.count*o):new a(i,u,r.count*o),p=new t.BufferAttribute(m,o,d);if(void 0!==r.sparse){const s=U.SCALAR,n=F[r.sparse.indices.componentType],c=r.sparse.indices.byteOffset||0,l=r.sparse.values.byteOffset||0,u=new n(e[1],c,r.sparse.count*s),h=new a(e[2],l,r.sparse.count*o);null!==i&&(p=new t.BufferAttribute(p.array.slice(),p.itemSize,p.normalized)),p.normalized=!1;for(let e=0,t=u.length;e<t;e++){const t=u[e];if(p.setX(t,h[e*o]),o>=2&&p.setY(t,h[e*o+1]),o>=3&&p.setZ(t,h[e*o+2]),o>=4&&p.setW(t,h[e*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}p.normalized=d}return p})}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,s,n){const r=this,i=this.json,o=i.textures[e],a=i.images[s],c=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[c])return this.textureCache[c];const l=this.loadImageSource(s,n).then(function(s){s.flipY=!1,s.name=o.name||a.name||"",""===s.name&&"string"==typeof a.uri&&!1===a.uri.startsWith("data:image/")&&(s.name=a.uri);const n=(i.samplers||{})[o.sampler]||{};return s.magFilter=k[n.magFilter]||t.LinearFilter,s.minFilter=k[n.minFilter]||t.LinearMipmapLinearFilter,s.wrapS=D[n.wrapS]||t.RepeatWrapping,s.wrapT=D[n.wrapT]||t.RepeatWrapping,s.generateMipmaps=!s.isCompressedTexture&&s.minFilter!==t.NearestFilter&&s.minFilter!==t.LinearFilter,r.associations.set(s,{textures:e}),s}).catch(function(){return null});return this.textureCache[c]=l,l}loadImageSource(e,s){const n=this,r=this.json,i=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then(e=>e.clone());const o=r.images[e],a=self.URL||self.webkitURL;let c=o.uri||"",l=!1;if(void 0!==o.bufferView)c=n.getDependency("bufferView",o.bufferView).then(function(e){l=!0;const t=new Blob([e],{type:o.mimeType});return c=a.createObjectURL(t),c});else if(void 0===o.uri)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const u=Promise.resolve(c).then(function(e){return new Promise(function(n,r){let o=n;!0===s.isImageBitmapLoader&&(o=function(e){const s=new t.Texture(e);s.needsUpdate=!0,n(s)}),s.load(t.LoaderUtils.resolveURL(e,i.path),o,void 0,r)})}).then(function(e){var t;return!0===l&&a.revokeObjectURL(c),W(e,o),e.userData.mimeType=o.mimeType||((t=o.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":t.search(/\.ktx2($|\?)/i)>0||0===t.search(/^data\:image\/ktx2/)?"image/ktx2":"image/png"),e}).catch(function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",c),e});return this.sourceCache[e]=u,u}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[o.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[o.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=r.associations.get(i);i=r.extensions[o.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 s=e.geometry;let n=e.material;const r=void 0===s.attributes.tangent,i=void 0!==s.attributes.color,o=void 0===s.attributes.normal;if(e.isPoints){const e="PointsMaterial:"+n.uuid;let s=this.cache.get(e);s||(s=new t.PointsMaterial,t.Material.prototype.copy.call(s,n),s.color.copy(n.color),s.map=n.map,s.sizeAttenuation=!1,this.cache.add(e,s)),n=s}else if(e.isLine){const e="LineBasicMaterial:"+n.uuid;let s=this.cache.get(e);s||(s=new t.LineBasicMaterial,t.Material.prototype.copy.call(s,n),s.color.copy(n.color),s.map=n.map,this.cache.add(e,s)),n=s}if(r||i||o){let e="ClonedMaterial:"+n.uuid+":";r&&(e+="derivative-tangents:"),i&&(e+="vertex-colors:"),o&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),o&&(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 t.MeshStandardMaterial}loadMaterial(e){const s=this,n=this.json,r=this.extensions,i=n.materials[e];let a;const c={},l=[];if((i.extensions||{})[o.KHR_MATERIALS_UNLIT]){const e=r[o.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),l.push(e.extendParams(c,i,s))}else{const n=i.pbrMetallicRoughness||{};if(c.color=new t.Color(1,1,1),c.opacity=1,Array.isArray(n.baseColorFactor)){const e=n.baseColorFactor;c.color.setRGB(e[0],e[1],e[2],t.LinearSRGBColorSpace),c.opacity=e[3]}void 0!==n.baseColorTexture&&l.push(s.assignTexture(c,"map",n.baseColorTexture,t.SRGBColorSpace)),c.metalness=void 0!==n.metallicFactor?n.metallicFactor:1,c.roughness=void 0!==n.roughnessFactor?n.roughnessFactor:1,void 0!==n.metallicRoughnessTexture&&(l.push(s.assignTexture(c,"metalnessMap",n.metallicRoughnessTexture)),l.push(s.assignTexture(c,"roughnessMap",n.metallicRoughnessTexture))),a=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,c)})))}!0===i.doubleSided&&(c.side=t.DoubleSide);const u=i.alphaMode||j;if(u===X?(c.transparent=!0,c.depthWrite=!1):(c.transparent=!1,u===V&&(c.alphaTest=void 0!==i.alphaCutoff?i.alphaCutoff:.5)),void 0!==i.normalTexture&&a!==t.MeshBasicMaterial&&(l.push(s.assignTexture(c,"normalMap",i.normalTexture)),c.normalScale=new t.Vector2(1,1),void 0!==i.normalTexture.scale)){const e=i.normalTexture.scale;c.normalScale.set(e,e)}if(void 0!==i.occlusionTexture&&a!==t.MeshBasicMaterial&&(l.push(s.assignTexture(c,"aoMap",i.occlusionTexture)),void 0!==i.occlusionTexture.strength&&(c.aoMapIntensity=i.occlusionTexture.strength)),void 0!==i.emissiveFactor&&a!==t.MeshBasicMaterial){const e=i.emissiveFactor;c.emissive=(new t.Color).setRGB(e[0],e[1],e[2],t.LinearSRGBColorSpace)}return void 0!==i.emissiveTexture&&a!==t.MeshBasicMaterial&&l.push(s.assignTexture(c,"emissiveMap",i.emissiveTexture,t.SRGBColorSpace)),Promise.all(l).then(function(){const t=new a(c);return i.name&&(t.name=i.name),W(t,i),s.associations.set(t,{materials:e}),i.extensions&&q(r,t,i),t})}createUniqueName(e){const s=t.PropertyBinding.sanitizeNodeName(e||"");return s in this.nodeNamesUsed?s+"_"+ ++this.nodeNamesUsed[s]:(this.nodeNamesUsed[s]=0,s)}loadGeometries(e){const s=this,n=this.extensions,r=this.primitiveCache;function i(e){return n[o.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then(function(t){return te(t,e,s)})}const a=[];for(let n=0,c=e.length;n<c;n++){const c=e[n],l=Q(c),u=r[l];if(u)a.push(u.promise);else{let e;e=c.extensions&&c.extensions[o.KHR_DRACO_MESH_COMPRESSION]?i(c):te(new t.BufferGeometry,c,s),r[l]={primitive:c,promise:e},a.push(e)}}return Promise.all(a)}loadMesh(e){const s=this,r=this.json,i=this.extensions,o=r.meshes[e],a=o.primitives,c=[];for(let e=0,t=a.length;e<t;e++){const t=void 0===a[e].material?z(this.cache):this.getDependency("material",a[e].material);c.push(t)}return c.push(s.loadGeometries(a)),Promise.all(c).then(function(r){const c=r.slice(0,r.length-1),l=r[r.length-1],u=[];for(let r=0,h=l.length;r<h;r++){const h=l[r],d=a[r];let m;const p=c[r];if(d.mode===H.TRIANGLES||d.mode===H.TRIANGLE_STRIP||d.mode===H.TRIANGLE_FAN||void 0===d.mode)m=!0===o.isSkinnedMesh?new t.SkinnedMesh(h,p):new t.Mesh(h,p),!0===m.isSkinnedMesh&&m.normalizeSkinWeights(),d.mode===H.TRIANGLE_STRIP?m.geometry=n(m.geometry,t.TriangleStripDrawMode):d.mode===H.TRIANGLE_FAN&&(m.geometry=n(m.geometry,t.TriangleFanDrawMode));else if(d.mode===H.LINES)m=new t.LineSegments(h,p);else if(d.mode===H.LINE_STRIP)m=new t.Line(h,p);else if(d.mode===H.LINE_LOOP)m=new t.LineLoop(h,p);else{if(d.mode!==H.POINTS)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+d.mode);m=new t.Points(h,p)}Object.keys(m.geometry.morphAttributes).length>0&&Y(m,o),m.name=s.createUniqueName(o.name||"mesh_"+e),W(m,o),d.extensions&&q(i,m,d),s.assignFinalMaterial(m),u.push(m)}for(let t=0,n=u.length;t<n;t++)s.associations.set(u[t],{meshes:e,primitives:t});if(1===u.length)return o.extensions&&q(i,u[0],o),u[0];const h=new t.Group;o.extensions&&q(i,h,o),s.associations.set(h,{meshes:e});for(let e=0,t=u.length;e<t;e++)h.add(u[e]);return h})}loadCamera(e){let s;const n=this.json.cameras[e],r=n[n.type];if(r)return"perspective"===n.type?s=new t.PerspectiveCamera(t.MathUtils.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):"orthographic"===n.type&&(s=new t.OrthographicCamera(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(s.name=this.createUniqueName(n.name)),W(s,n),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const s=this.json.skins[e],n=[];for(let e=0,t=s.joints.length;e<t;e++)n.push(this._loadNodeShallow(s.joints[e]));return void 0!==s.inverseBindMatrices?n.push(this.getDependency("accessor",s.inverseBindMatrices)):n.push(null),Promise.all(n).then(function(e){const n=e.pop(),r=e,i=[],o=[];for(let e=0,a=r.length;e<a;e++){const a=r[e];if(a){i.push(a);const s=new t.Matrix4;null!==n&&s.fromArray(n.array,16*e),o.push(s)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[e])}return new t.Skeleton(i,o)})}loadAnimation(e){const s=this.json,n=this,r=s.animations[e],i=r.name?r.name:"animation_"+e,o=[],a=[],c=[],l=[],u=[];for(let e=0,t=r.channels.length;e<t;e++){const t=r.channels[e],s=r.samplers[t.sampler],n=t.target,i=n.node,h=void 0!==r.parameters?r.parameters[s.input]:s.input,d=void 0!==r.parameters?r.parameters[s.output]:s.output;void 0!==n.node&&(o.push(this.getDependency("node",i)),a.push(this.getDependency("accessor",h)),c.push(this.getDependency("accessor",d)),l.push(s),u.push(n))}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(c),Promise.all(l),Promise.all(u)]).then(function(e){const s=e[0],o=e[1],a=e[2],c=e[3],l=e[4],u=[];for(let e=0,t=s.length;e<t;e++){const t=s[e],r=o[e],i=a[e],h=c[e],d=l[e];if(void 0===t)continue;t.updateMatrix&&t.updateMatrix();const m=n._createAnimationTracks(t,r,i,h,d);if(m)for(let e=0;e<m.length;e++)u.push(m[e])}const h=new t.AnimationClip(i,void 0,u);return W(h,r),h})}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,$)});for(let e=0,n=s.length;e<n;e++)t.add(s[e]);return t})}_loadNodeShallow(e){const s=this.json,n=this.extensions,r=this;if(void 0!==this.nodeCache[e])return this.nodeCache[e];const i=s.nodes[e],o=i.name?r.createUniqueName(i.name):"",a=[],c=r._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return c&&a.push(c),void 0!==i.camera&&a.push(r.getDependency("camera",i.camera).then(function(e){return r._getNodeRef(r.cameraCache,i.camera,e)})),r._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){a.push(e)}),this.nodeCache[e]=Promise.all(a).then(function(s){let a;if(a=!0===i.isBone?new t.Bone:s.length>1?new t.Group:1===s.length?s[0]:new t.Object3D,a!==s[0])for(let e=0,t=s.length;e<t;e++)a.add(s[e]);if(i.name&&(a.userData.name=i.name,a.name=o),W(a,i),i.extensions&&q(n,a,i),void 0!==i.matrix){const e=new t.Matrix4;e.fromArray(i.matrix),a.applyMatrix4(e)}else void 0!==i.translation&&a.position.fromArray(i.translation),void 0!==i.rotation&&a.quaternion.fromArray(i.rotation),void 0!==i.scale&&a.scale.fromArray(i.scale);if(r.associations.has(a)){if(void 0!==i.mesh&&r.meshCache.refs[i.mesh]>1){const e=r.associations.get(a);r.associations.set(a,{...e})}}else r.associations.set(a,{});return r.associations.get(a).nodes=e,a}),this.nodeCache[e]}loadScene(e){const s=this.extensions,n=this.json.scenes[e],r=this,i=new t.Group;n.name&&(i.name=r.createUniqueName(n.name)),W(i,n),n.extensions&&q(s,i,n);const o=n.nodes||[],a=[];for(let e=0,t=o.length;e<t;e++)a.push(r.getDependency("node",o[e]));return Promise.all(a).then(function(e){for(let t=0,s=e.length;t<s;t++)i.add(e[t]);return r.associations=(e=>{const s=new Map;for(const[e,n]of r.associations)(e instanceof t.Material||e instanceof t.Texture)&&s.set(e,n);return e.traverse(e=>{const t=r.associations.get(e);null!=t&&s.set(e,t)}),s})(i),i})}_createAnimationTracks(e,s,n,r,i){const o=[],a=e.name?e.name:e.uuid,c=[];let l;switch(B[i.path]===B.weights?e.traverse(function(e){e.morphTargetInfluences&&c.push(e.name?e.name:e.uuid)}):c.push(a),B[i.path]){case B.weights:l=t.NumberKeyframeTrack;break;case B.rotation:l=t.QuaternionKeyframeTrack;break;case B.translation:case B.scale:l=t.VectorKeyframeTrack;break;default:if(1===n.itemSize)l=t.NumberKeyframeTrack;else l=t.VectorKeyframeTrack}const u=void 0!==r.interpolation?K[r.interpolation]:t.InterpolateLinear,h=this._getArrayFromAccessor(n);for(let e=0,t=c.length;e<t;e++){const t=new l(c[e]+"."+B[i.path],s.array,h,u);"CUBICSPLINE"===r.interpolation&&this._createCubicSplineTrackInterpolant(t),o.push(t)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const e=Z(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 t.QuaternionKeyframeTrack?P:N)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function te(e,s,n){const r=s.attributes,i=[];function o(t,s){return n.getDependency("accessor",t).then(function(t){e.setAttribute(s,t)})}for(const t in r){const s=G[t]||t.toLowerCase();s in e.attributes||i.push(o(r[t],s))}if(void 0!==s.indices&&!e.index){const t=n.getDependency("accessor",s.indices).then(function(t){e.setIndex(t)});i.push(t)}return t.ColorManagement.workingColorSpace!==t.LinearSRGBColorSpace&&"COLOR_0"in r&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${t.ColorManagement.workingColorSpace}" not supported.`),W(e,s),function(e,s,n){const r=s.attributes,i=new t.Box3;if(void 0===r.POSITION)return;{const e=n.json.accessors[r.POSITION],s=e.min,o=e.max;if(void 0===s||void 0===o)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(i.set(new t.Vector3(s[0],s[1],s[2]),new t.Vector3(o[0],o[1],o[2])),e.normalized){const t=Z(F[e.componentType]);i.min.multiplyScalar(t),i.max.multiplyScalar(t)}}const o=s.targets;if(void 0!==o){const e=new t.Vector3,s=new t.Vector3;for(let t=0,r=o.length;t<r;t++){const r=o[t];if(void 0!==r.POSITION){const t=n.json.accessors[r.POSITION],i=t.min,o=t.max;if(void 0!==i&&void 0!==o){if(s.setX(Math.max(Math.abs(i[0]),Math.abs(o[0]))),s.setY(Math.max(Math.abs(i[1]),Math.abs(o[1]))),s.setZ(Math.max(Math.abs(i[2]),Math.abs(o[2]))),t.normalized){const e=Z(F[t.componentType]);s.multiplyScalar(e)}e.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}i.expandByVector(e)}e.boundingBox=i;const a=new t.Sphere;i.getCenter(a.center),a.radius=i.min.distanceTo(i.max)/2,e.boundingSphere=a}(e,s,n),Promise.all(i).then(function(){return void 0!==s.targets?function(e,t,s){let n=!1,r=!1,i=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(n=!0),void 0!==s.NORMAL&&(r=!0),void 0!==s.COLOR_0&&(i=!0),n&&r&&i)break}if(!n&&!r&&!i)return Promise.resolve(e);const o=[],a=[],c=[];for(let l=0,u=t.length;l<u;l++){const u=t[l];if(n){const t=void 0!==u.POSITION?s.getDependency("accessor",u.POSITION):e.attributes.position;o.push(t)}if(r){const t=void 0!==u.NORMAL?s.getDependency("accessor",u.NORMAL):e.attributes.normal;a.push(t)}if(i){const t=void 0!==u.COLOR_0?s.getDependency("accessor",u.COLOR_0):e.attributes.color;c.push(t)}}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(c)]).then(function(t){const s=t[0],o=t[1],a=t[2];return n&&(e.morphAttributes.position=s),r&&(e.morphAttributes.normal=o),i&&(e.morphAttributes.color=a),e.morphTargetsRelative=!0,e})}(e,s.targets,n):e})}class se extends s.Loader{constructor(e){super(),this.viewer=e,this.manager=null}dispose(){this.manager&&this.manager.dispose()}isSupport(e,t=""){return("string"==typeof e||e instanceof globalThis.File||e instanceof ArrayBuffer)&&/(gltf|glb)$/i.test(t)}async load(e,t,n={}){this.manager=new s.GLTFLoadingManager(e,n);const i=new r(this.manager);i.setPath(this.manager.path),i.setCrossOrigin(n.crossOrigin||i.crossOrigin),i.setRequestHeader(n.requestHeader||{}),i.setWithCredentials(n.withCredentials||i.withCredentials);const o=await i.loadAsync(this.manager.fileURL,t=>{const{lengthComputable:s,loaded:n,total:r}=t,i=s?n/r:1;this.viewer.emitEvent({type:"geometryprogress",data:i,file:e})});if(!this.viewer.scene)return this;let a=1;o.scene.traverse(e=>{e.userData={handle:a+"",...e.userData},a++});const c=new s.ModelImpl(o.scene);return c.id=n.modelId||this.extractFileName(e),this.viewer.scene.add(o.scene),this.viewer.models.push(c),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.emitEvent({type:"databasechunk",data:o.scene,file:e}),this.viewer.update(!0),this}}s.loaders.registerLoader("gltf-file",e=>new se(e)),e.GLTFFileLoader=se});
24
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("three"),require("@inweb/viewer-three")):"function"==typeof define&&define.amd?define(["exports","three","@inweb/viewer-three"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).ODA=e.ODA||{},e.ODA.Three=e.ODA.Three||{},e.ODA.Three.Extensions=e.ODA.Three.Extensions||{}),e.THREE,e.ODA.Three)}(this,function(e,t,s){"use strict";function r(e,s){if(s===t.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(s===t.TriangleFanDrawMode||s===t.TriangleStripDrawMode){let r=e.getIndex();if(null===r){const t=[],s=e.getAttribute("position");if(void 0===s)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;e<s.count;e++)t.push(e);e.setIndex(t),r=e.getIndex()}const n=r.count-2,i=[];if(s===t.TriangleFanDrawMode)for(let e=1;e<=n;e++)i.push(r.getX(0)),i.push(r.getX(e)),i.push(r.getX(e+1));else for(let e=0;e<n;e++)e%2==0?(i.push(r.getX(e)),i.push(r.getX(e+1)),i.push(r.getX(e+2))):(i.push(r.getX(e+2)),i.push(r.getX(e+1)),i.push(r.getX(e)));i.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const o=e.clone();return o.setIndex(i),o.clearGroups(),o}return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",s),e}function n(e){const t=new Map,s=new Map,r=e.clone();return i(e,r,function(e,r){t.set(r,e),s.set(e,r)}),r.traverse(function(e){if(!e.isSkinnedMesh)return;const r=e,n=t.get(e),i=n.skeleton.bones;r.skeleton=n.skeleton.clone(),r.bindMatrix.copy(n.bindMatrix),r.skeleton.bones=i.map(function(e){return s.get(e)}),r.bind(r.skeleton,r.bindMatrix)}),r}function i(e,t,s){s(e,t);for(let r=0;r<e.children.length;r++)i(e.children[r],t.children[r],s)}class o extends t.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new p(e)}),this.register(function(e){return new m(e)}),this.register(function(e){return new w(e)}),this.register(function(e){return new E(e)}),this.register(function(e){return new A(e)}),this.register(function(e){return new g(e)}),this.register(function(e){return new T(e)}),this.register(function(e){return new R(e)}),this.register(function(e){return new x(e)}),this.register(function(e){return new d(e)}),this.register(function(e){return new v(e)}),this.register(function(e){return new f(e)}),this.register(function(e){return new M(e)}),this.register(function(e){return new _(e)}),this.register(function(e){return new u(e)}),this.register(function(e){return new y(e,l.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new y(e,l.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new S(e)})}load(e,s,r,n){const i=this;let o;if(""!==this.resourcePath)o=this.resourcePath;else if(""!==this.path){const s=t.LoaderUtils.extractUrlBase(e);o=t.LoaderUtils.resolveURL(s,this.path)}else o=t.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=function(t){n?n(t):console.error(t),i.manager.itemError(e),i.manager.itemEnd(e)},c=new t.FileLoader(this.manager);c.setPath(this.path),c.setResponseType("arraybuffer"),c.setRequestHeader(this.requestHeader),c.setWithCredentials(this.withCredentials),c.load(e,function(t){try{i.parse(t,o,function(t){s(t),i.manager.itemEnd(e)},a)}catch(e){a(e)}},r,a)}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,r){let n;const i={},o={},a=new TextDecoder;if("string"==typeof e)n=JSON.parse(e);else if(e instanceof ArrayBuffer){if(a.decode(new Uint8Array(e,0,4))===L){try{i[l.KHR_BINARY_GLTF]=new C(e)}catch(e){return void(r&&r(e))}n=JSON.parse(i[l.KHR_BINARY_GLTF].content)}else n=JSON.parse(a.decode(e))}else n=e;if(void 0===n.asset||n.asset.version[0]<2)return void(r&&r(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const c=new re(n,{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(n.extensionsUsed)for(let e=0;e<n.extensionsUsed.length;++e){const t=n.extensionsUsed[e],s=n.extensionsRequired||[];switch(t){case l.KHR_MATERIALS_UNLIT:i[t]=new h;break;case l.KHR_DRACO_MESH_COMPRESSION:i[t]=new O(n,this.dracoLoader);break;case l.KHR_TEXTURE_TRANSFORM:i[t]=new N;break;case l.KHR_MESH_QUANTIZATION:i[t]=new P;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,r)}parseAsync(e,t){const s=this;return new Promise(function(r,n){s.parse(e,t,r,n)})}}function a(){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={}}}}function c(e,t,s){const r=e.json.materials[t];return r.extensions&&r.extensions[s]?r.extensions[s]:null}const l={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class u{constructor(e){this.parser=e,this.name=l.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,r=t.length;s<r;s++){const r=t[s];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 s=this.parser,r="light:"+e;let n=s.cache.get(r);if(n)return n;const i=s.json,o=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e];let a;const c=new t.Color(16777215);void 0!==o.color&&c.setRGB(o.color[0],o.color[1],o.color[2],t.LinearSRGBColorSpace);const l=void 0!==o.range?o.range:0;switch(o.type){case"directional":a=new t.DirectionalLight(c),a.target.position.set(0,0,-1),a.add(a.target);break;case"point":a=new t.PointLight(c),a.distance=l;break;case"spot":a=new t.SpotLight(c),a.distance=l,o.spot=o.spot||{},o.spot.innerConeAngle=void 0!==o.spot.innerConeAngle?o.spot.innerConeAngle:0,o.spot.outerConeAngle=void 0!==o.spot.outerConeAngle?o.spot.outerConeAngle:Math.PI/4,a.angle=o.spot.outerConeAngle,a.penumbra=1-o.spot.innerConeAngle/o.spot.outerConeAngle,a.target.position.set(0,0,-1),a.add(a.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+o.type)}return a.position.set(0,0,0),J(a,o),void 0!==o.intensity&&(a.intensity=o.intensity),a.name=s.createUniqueName(o.name||"light_"+e),n=Promise.resolve(a),s.cache.add(r,n),n}getDependency(e,t){if("light"===e)return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,r=s.json.nodes[e],n=(r.extensions&&r.extensions[this.name]||{}).light;return void 0===n?null:this._loadLight(n).then(function(e){return s._getNodeRef(t.cache,n,e)})}}class h{constructor(){this.name=l.KHR_MATERIALS_UNLIT}getMaterialType(){return t.MeshBasicMaterial}extendParams(e,s,r){const n=[];e.color=new t.Color(1,1,1),e.opacity=1;const i=s.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const s=i.baseColorFactor;e.color.setRGB(s[0],s[1],s[2],t.LinearSRGBColorSpace),e.opacity=s[3]}void 0!==i.baseColorTexture&&n.push(r.assignTexture(e,"map",i.baseColorTexture,t.SRGBColorSpace))}return Promise.all(n)}}class d{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const s=c(this.parser,e,this.name);return null===s||void 0!==s.emissiveStrength&&(t.emissiveIntensity=s.emissiveStrength),Promise.resolve()}}class p{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const r=c(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];if(void 0!==r.clearcoatFactor&&(s.clearcoat=r.clearcoatFactor),void 0!==r.clearcoatTexture&&n.push(this.parser.assignTexture(s,"clearcoatMap",r.clearcoatTexture)),void 0!==r.clearcoatRoughnessFactor&&(s.clearcoatRoughness=r.clearcoatRoughnessFactor),void 0!==r.clearcoatRoughnessTexture&&n.push(this.parser.assignTexture(s,"clearcoatRoughnessMap",r.clearcoatRoughnessTexture)),void 0!==r.clearcoatNormalTexture&&(n.push(this.parser.assignTexture(s,"clearcoatNormalMap",r.clearcoatNormalTexture)),void 0!==r.clearcoatNormalTexture.scale)){const e=r.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new t.Vector2(e,e)}return Promise.all(n)}}class m{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_DISPERSION}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=c(this.parser,e,this.name);return null===s||(t.dispersion=void 0!==s.dispersion?s.dispersion:0),Promise.resolve()}}class f{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=c(this.parser,e,this.name);if(null===s)return Promise.resolve();const r=[];return void 0!==s.iridescenceFactor&&(t.iridescence=s.iridescenceFactor),void 0!==s.iridescenceTexture&&r.push(this.parser.assignTexture(t,"iridescenceMap",s.iridescenceTexture)),void 0!==s.iridescenceIor&&(t.iridescenceIOR=s.iridescenceIor),void 0===t.iridescenceThicknessRange&&(t.iridescenceThicknessRange=[100,400]),void 0!==s.iridescenceThicknessMinimum&&(t.iridescenceThicknessRange[0]=s.iridescenceThicknessMinimum),void 0!==s.iridescenceThicknessMaximum&&(t.iridescenceThicknessRange[1]=s.iridescenceThicknessMaximum),void 0!==s.iridescenceThicknessTexture&&r.push(this.parser.assignTexture(t,"iridescenceThicknessMap",s.iridescenceThicknessTexture)),Promise.all(r)}}class g{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_SHEEN}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const r=c(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];if(s.sheenColor=new t.Color(0,0,0),s.sheenRoughness=0,s.sheen=1,void 0!==r.sheenColorFactor){const e=r.sheenColorFactor;s.sheenColor.setRGB(e[0],e[1],e[2],t.LinearSRGBColorSpace)}return void 0!==r.sheenRoughnessFactor&&(s.sheenRoughness=r.sheenRoughnessFactor),void 0!==r.sheenColorTexture&&n.push(this.parser.assignTexture(s,"sheenColorMap",r.sheenColorTexture,t.SRGBColorSpace)),void 0!==r.sheenRoughnessTexture&&n.push(this.parser.assignTexture(s,"sheenRoughnessMap",r.sheenRoughnessTexture)),Promise.all(n)}}class T{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=c(this.parser,e,this.name);if(null===s)return Promise.resolve();const r=[];return void 0!==s.transmissionFactor&&(t.transmission=s.transmissionFactor),void 0!==s.transmissionTexture&&r.push(this.parser.assignTexture(t,"transmissionMap",s.transmissionTexture)),Promise.all(r)}}class R{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_VOLUME}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const r=c(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];s.thickness=void 0!==r.thicknessFactor?r.thicknessFactor:0,void 0!==r.thicknessTexture&&n.push(this.parser.assignTexture(s,"thicknessMap",r.thicknessTexture)),s.attenuationDistance=r.attenuationDistance||1/0;const i=r.attenuationColor||[1,1,1];return s.attenuationColor=(new t.Color).setRGB(i[0],i[1],i[2],t.LinearSRGBColorSpace),Promise.all(n)}}class x{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_IOR}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=c(this.parser,e,this.name);return null===s||(t.ior=void 0!==s.ior?s.ior:1.5,0===t.ior&&(t.ior=1e3)),Promise.resolve()}}class v{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_SPECULAR}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,s){const r=c(this.parser,e,this.name);if(null===r)return Promise.resolve();const n=[];s.specularIntensity=void 0!==r.specularFactor?r.specularFactor:1,void 0!==r.specularTexture&&n.push(this.parser.assignTexture(s,"specularIntensityMap",r.specularTexture));const i=r.specularColorFactor||[1,1,1];return s.specularColor=(new t.Color).setRGB(i[0],i[1],i[2],t.LinearSRGBColorSpace),void 0!==r.specularColorTexture&&n.push(this.parser.assignTexture(s,"specularColorMap",r.specularColorTexture,t.SRGBColorSpace)),Promise.all(n)}}class _{constructor(e){this.parser=e,this.name=l.EXT_MATERIALS_BUMP}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=c(this.parser,e,this.name);if(null===s)return Promise.resolve();const r=[];return t.bumpScale=void 0!==s.bumpFactor?s.bumpFactor:1,void 0!==s.bumpTexture&&r.push(this.parser.assignTexture(t,"bumpMap",s.bumpTexture)),Promise.all(r)}}class M{constructor(e){this.parser=e,this.name=l.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return null!==c(this.parser,e,this.name)?t.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=c(this.parser,e,this.name);if(null===s)return Promise.resolve();const r=[];return void 0!==s.anisotropyStrength&&(t.anisotropy=s.anisotropyStrength),void 0!==s.anisotropyRotation&&(t.anisotropyRotation=s.anisotropyRotation),void 0!==s.anisotropyTexture&&r.push(this.parser.assignTexture(t,"anisotropyMap",s.anisotropyTexture)),Promise.all(r)}}class w{constructor(e){this.parser=e,this.name=l.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,r=s.textures[e];if(!r.extensions||!r.extensions[this.name])return null;const n=r.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,n.source,i)}}class E{constructor(e){this.parser=e,this.name=l.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,s=this.parser,r=s.json,n=r.textures[e];if(!n.extensions||!n.extensions[t])return null;const i=n.extensions[t],o=r.images[i.source];let a=s.textureLoader;if(o.uri){const e=s.options.manager.getHandler(o.uri);null!==e&&(a=e)}return s.loadTextureImage(e,i.source,a)}}class A{constructor(e){this.parser=e,this.name=l.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,s=this.parser,r=s.json,n=r.textures[e];if(!n.extensions||!n.extensions[t])return null;const i=n.extensions[t],o=r.images[i.source];let a=s.textureLoader;if(o.uri){const e=s.options.manager.getHandler(o.uri);null!==e&&(a=e)}return s.loadTextureImage(e,i.source,a)}}class y{constructor(e,t){this.name=t,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],r=this.parser.getDependency("buffer",e.buffer),n=this.parser.options.meshoptDecoder;if(!n||!n.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 s=e.byteOffset||0,r=e.byteLength||0,i=e.count,o=e.byteStride,a=new Uint8Array(t,s,r);return n.decodeGltfBufferAsync?n.decodeGltfBufferAsync(i,o,a,e.mode,e.filter).then(function(e){return e.buffer}):n.ready.then(function(){const t=new ArrayBuffer(i*o);return n.decodeGltfBuffer(new Uint8Array(t),i,o,a,e.mode,e.filter),t})})}return null}}class S{constructor(e){this.name=l.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const s=this.parser.json,r=s.nodes[e];if(!r.extensions||!r.extensions[this.name]||void 0===r.mesh)return null;const n=s.meshes[r.mesh];for(const e of n.primitives)if(e.mode!==D.TRIANGLES&&e.mode!==D.TRIANGLE_STRIP&&e.mode!==D.TRIANGLE_FAN&&void 0!==e.mode)return null;const i=r.extensions[this.name].attributes,o=[],a={};for(const e in i)o.push(this.parser.getDependency("accessor",i[e]).then(t=>(a[e]=t,a[e])));return o.length<1?null:(o.push(this.parser.createNodeMesh(e)),Promise.all(o).then(e=>{const s=e.pop(),r=s.isGroup?s.children:[s],n=e[0].count,i=[];for(const e of r){const s=new t.Matrix4,r=new t.Vector3,o=new t.Quaternion,c=new t.Vector3(1,1,1),l=new t.InstancedMesh(e.geometry,e.material,n);for(let e=0;e<n;e++)a.TRANSLATION&&r.fromBufferAttribute(a.TRANSLATION,e),a.ROTATION&&o.fromBufferAttribute(a.ROTATION,e),a.SCALE&&c.fromBufferAttribute(a.SCALE,e),l.setMatrixAt(e,s.compose(r,o,c));for(const s in a)if("_COLOR_0"===s){const e=a[s];l.instanceColor=new t.InstancedBufferAttribute(e.array,e.itemSize,e.normalized)}else"TRANSLATION"!==s&&"ROTATION"!==s&&"SCALE"!==s&&e.geometry.setAttribute(s,a[s]);t.Object3D.prototype.copy.call(l,e),this.parser.assignFinalMaterial(l),i.push(l)}return s.isGroup?(s.clear(),s.add(...i),s):i[0]}))}}const L="glTF",I=1313821514,b=5130562;class C{constructor(e){this.name=l.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!==L)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,n=new DataView(e,12);let i=0;for(;i<r;){const t=n.getUint32(i,!0);i+=4;const r=n.getUint32(i,!0);if(i+=4,r===I){const r=new Uint8Array(e,12+i,t);this.content=s.decode(r)}else if(r===b){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 O{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=l.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,s){const r=this.json,n=this.dracoLoader,i=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},c={},l={};for(const e in o){const t=V[e]||e.toLowerCase();a[t]=o[e]}for(const t in e.attributes){const s=V[t]||t.toLowerCase();if(void 0!==o[t]){const n=r.accessors[e.attributes[t]],i=U[n.componentType];l[s]=i.name,c[s]=!0===n.normalized}}return s.getDependency("bufferView",i).then(function(e){return new Promise(function(s,r){n.decodeDracoFile(e,function(e){for(const t in e.attributes){const s=e.attributes[t],r=c[t];void 0!==r&&(s.normalized=r)}s(e)},a,l,t.LinearSRGBColorSpace,r)})})}}class N{constructor(){this.name=l.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 P{constructor(){this.name=l.KHR_MESH_QUANTIZATION}}class H extends t.Interpolant{constructor(e,t,s,r){super(e,t,s,r)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,r=this.valueSize,n=e*r*3+r;for(let e=0;e!==r;e++)t[e]=s[n+e];return t}interpolate_(e,t,s,r){const n=this.resultBuffer,i=this.sampleValues,o=this.valueSize,a=2*o,c=3*o,l=r-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,T=1-f,R=g-h+u;for(let e=0;e!==o;e++){const t=i[m+e+o],s=i[m+e+a]*l,r=i[p+e+o],c=i[p+e]*l;n[e]=T*t+R*s+f*r+g*c}return n}}const k=new t.Quaternion;class F extends H{interpolate_(e,t,s,r){const n=super.interpolate_(e,t,s,r);return k.fromArray(n).normalize().toArray(n),n}}const D={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},U={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},G={9728:t.NearestFilter,9729:t.LinearFilter,9984:t.NearestMipmapNearestFilter,9985:t.LinearMipmapNearestFilter,9986:t.NearestMipmapLinearFilter,9987:t.LinearMipmapLinearFilter},B={33071:t.ClampToEdgeWrapping,33648:t.MirroredRepeatWrapping,10497:t.RepeatWrapping},K={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},V={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},j={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},X={CUBICSPLINE:void 0,LINEAR:t.InterpolateLinear,STEP:t.InterpolateDiscrete},z="OPAQUE",q="MASK",W="BLEND";function Y(e){return void 0===e.DefaultMaterial&&(e.DefaultMaterial=new t.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:t.FrontSide})),e.DefaultMaterial}function Q(e,t,s){for(const r in s.extensions)void 0===e[r]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=s.extensions[r])}function J(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,r=t.weights.length;s<r;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,r=s.length;t<r;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function $(e){let t;const s=e.extensions&&e.extensions[l.KHR_DRACO_MESH_COMPRESSION];if(t=s?"draco:"+s.bufferView+":"+s.indices+":"+ee(s.attributes):e.indices+":"+ee(e.attributes)+":"+e.mode,void 0!==e.targets)for(let s=0,r=e.targets.length;s<r;s++)t+=":"+ee(e.targets[s]);return t}function ee(e){let t="";const s=Object.keys(e).sort();for(let r=0,n=s.length;r<n;r++)t+=s[r]+":"+e[s[r]]+";";return t}function te(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 t.Matrix4;class re{constructor(e={},s={}){this.json=e,this.extensions={},this.plugins={},this.options=s,this.cache=new a,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let r=!1,n=-1,i=!1,o=-1;if("undefined"!=typeof navigator&&void 0!==navigator.userAgent){const e=navigator.userAgent;r=!0===/^((?!chrome|android).)*safari/i.test(e);const t=e.match(/Version\/(\d+)/);n=r&&t?parseInt(t[1],10):-1,i=e.indexOf("Firefox")>-1,o=i?e.match(/Firefox\/([0-9]+)\./)[1]:-1}"undefined"==typeof createImageBitmap||r&&n<17||i&&o<98?this.textureLoader=new t.TextureLoader(this.options.manager):this.textureLoader=new t.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new t.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,r=this.json,n=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][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:s,userData:{}};return Q(n,i,r),J(i,r),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,r=t.length;s<r;s++){const r=t[s].joints;for(let t=0,s=r.length;t<s;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&&(s[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,s){if(e.refs[t]<=1)return s;const r=s.clone(),n=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,r]of e.children.entries())n(r,t.children[s])};return n(s,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const r=e(t[s]);if(r)return r}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let r=0;r<t.length;r++){const n=e(t[r]);n&&s.push(n)}return s}getDependency(e,t){const s=e+":"+t;let r=this.cache.get(s);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(s){return s!=this&&s.getDependency&&s.getDependency(e,t)}),!r)throw new Error("Unknown type: "+e)}this.cache.add(s,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,r=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(r.map(function(t,r){return s.getDependency(e,r)})),this.cache.add(e,t)}return t}loadBuffer(e){const s=this.json.buffers[e],r=this.fileLoader;if(s.type&&"arraybuffer"!==s.type)throw new Error("THREE.GLTFLoader: "+s.type+" buffer type is not supported.");if(void 0===s.uri&&0===e)return Promise.resolve(this.extensions[l.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(e,i){r.load(t.LoaderUtils.resolveURL(s.uri,n.path),e,void 0,function(){i(new Error('THREE.GLTFLoader: Failed to load buffer "'+s.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(e){const s=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+s)})}loadAccessor(e){const s=this,r=this.json,n=this.json.accessors[e];if(void 0===n.bufferView&&void 0===n.sparse){const e=K[n.type],s=U[n.componentType],r=!0===n.normalized,i=new s(n.count*e);return Promise.resolve(new t.BufferAttribute(i,e,r))}const i=[];return void 0!==n.bufferView?i.push(this.getDependency("bufferView",n.bufferView)):i.push(null),void 0!==n.sparse&&(i.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(i).then(function(e){const i=e[0],o=K[n.type],a=U[n.componentType],c=a.BYTES_PER_ELEMENT,l=c*o,u=n.byteOffset||0,h=void 0!==n.bufferView?r.bufferViews[n.bufferView].byteStride:void 0,d=!0===n.normalized;let p,m;if(h&&h!==l){const e=Math.floor(u/h),r="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+e+":"+n.count;let l=s.cache.get(r);l||(p=new a(i,e*h,n.count*h/c),l=new t.InterleavedBuffer(p,h/c),s.cache.add(r,l)),m=new t.InterleavedBufferAttribute(l,o,u%h/c,d)}else p=null===i?new a(n.count*o):new a(i,u,n.count*o),m=new t.BufferAttribute(p,o,d);if(void 0!==n.sparse){const s=K.SCALAR,r=U[n.sparse.indices.componentType],c=n.sparse.indices.byteOffset||0,l=n.sparse.values.byteOffset||0,u=new r(e[1],c,n.sparse.count*s),h=new a(e[2],l,n.sparse.count*o);null!==i&&(m=new t.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*o]),o>=2&&m.setY(t,h[e*o+1]),o>=3&&m.setZ(t,h[e*o+2]),o>=4&&m.setW(t,h[e*o+3]),o>=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,r=t.textures[e].source,n=t.images[r];let i=this.textureLoader;if(n.uri){const e=s.manager.getHandler(n.uri);null!==e&&(i=e)}return this.loadTextureImage(e,r,i)}loadTextureImage(e,s,r){const n=this,i=this.json,o=i.textures[e],a=i.images[s],c=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[c])return this.textureCache[c];const l=this.loadImageSource(s,r).then(function(s){s.flipY=!1,s.name=o.name||a.name||"",""===s.name&&"string"==typeof a.uri&&!1===a.uri.startsWith("data:image/")&&(s.name=a.uri);const r=(i.samplers||{})[o.sampler]||{};return s.magFilter=G[r.magFilter]||t.LinearFilter,s.minFilter=G[r.minFilter]||t.LinearMipmapLinearFilter,s.wrapS=B[r.wrapS]||t.RepeatWrapping,s.wrapT=B[r.wrapT]||t.RepeatWrapping,s.generateMipmaps=!s.isCompressedTexture&&s.minFilter!==t.NearestFilter&&s.minFilter!==t.LinearFilter,n.associations.set(s,{textures:e}),s}).catch(function(){return null});return this.textureCache[c]=l,l}loadImageSource(e,s){const r=this,n=this.json,i=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then(e=>e.clone());const o=n.images[e],a=self.URL||self.webkitURL;let c=o.uri||"",l=!1;if(void 0!==o.bufferView)c=r.getDependency("bufferView",o.bufferView).then(function(e){l=!0;const t=new Blob([e],{type:o.mimeType});return c=a.createObjectURL(t),c});else if(void 0===o.uri)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const u=Promise.resolve(c).then(function(e){return new Promise(function(r,n){let o=r;!0===s.isImageBitmapLoader&&(o=function(e){const s=new t.Texture(e);s.needsUpdate=!0,r(s)}),s.load(t.LoaderUtils.resolveURL(e,i.path),o,void 0,n)})}).then(function(e){var t;return!0===l&&a.revokeObjectURL(c),J(e,o),e.userData.mimeType=o.mimeType||((t=o.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":t.search(/\.ktx2($|\?)/i)>0||0===t.search(/^data\:image\/ktx2/)?"image/ktx2":"image/png"),e}).catch(function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",c),e});return this.sourceCache[e]=u,u}assignTexture(e,t,s,r){const n=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),n.extensions[l.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[l.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=n.associations.get(i);i=n.extensions[l.KHR_TEXTURE_TRANSFORM].extendTexture(i,e),n.associations.set(i,t)}}return void 0!==r&&(i.colorSpace=r),e[t]=i,i})}assignFinalMaterial(e){const s=e.geometry;let r=e.material;const n=void 0===s.attributes.tangent,i=void 0!==s.attributes.color,o=void 0===s.attributes.normal;if(e.isPoints){const e="PointsMaterial:"+r.uuid;let s=this.cache.get(e);s||(s=new t.PointsMaterial,t.Material.prototype.copy.call(s,r),s.color.copy(r.color),s.map=r.map,s.sizeAttenuation=!1,this.cache.add(e,s)),r=s}else if(e.isLine){const e="LineBasicMaterial:"+r.uuid;let s=this.cache.get(e);s||(s=new t.LineBasicMaterial,t.Material.prototype.copy.call(s,r),s.color.copy(r.color),s.map=r.map,this.cache.add(e,s)),r=s}if(n||i||o){let e="ClonedMaterial:"+r.uuid+":";n&&(e+="derivative-tangents:"),i&&(e+="vertex-colors:"),o&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=r.clone(),i&&(t.vertexColors=!0),o&&(t.flatShading=!0),n&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(r))),r=t}e.material=r}getMaterialType(){return t.MeshStandardMaterial}loadMaterial(e){const s=this,r=this.json,n=this.extensions,i=r.materials[e];let o;const a={},c=[];if((i.extensions||{})[l.KHR_MATERIALS_UNLIT]){const e=n[l.KHR_MATERIALS_UNLIT];o=e.getMaterialType(),c.push(e.extendParams(a,i,s))}else{const r=i.pbrMetallicRoughness||{};if(a.color=new t.Color(1,1,1),a.opacity=1,Array.isArray(r.baseColorFactor)){const e=r.baseColorFactor;a.color.setRGB(e[0],e[1],e[2],t.LinearSRGBColorSpace),a.opacity=e[3]}void 0!==r.baseColorTexture&&c.push(s.assignTexture(a,"map",r.baseColorTexture,t.SRGBColorSpace)),a.metalness=void 0!==r.metallicFactor?r.metallicFactor:1,a.roughness=void 0!==r.roughnessFactor?r.roughnessFactor:1,void 0!==r.metallicRoughnessTexture&&(c.push(s.assignTexture(a,"metalnessMap",r.metallicRoughnessTexture)),c.push(s.assignTexture(a,"roughnessMap",r.metallicRoughnessTexture))),o=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,a)})))}!0===i.doubleSided&&(a.side=t.DoubleSide);const u=i.alphaMode||z;if(u===W?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===q&&(a.alphaTest=void 0!==i.alphaCutoff?i.alphaCutoff:.5)),void 0!==i.normalTexture&&o!==t.MeshBasicMaterial&&(c.push(s.assignTexture(a,"normalMap",i.normalTexture)),a.normalScale=new t.Vector2(1,1),void 0!==i.normalTexture.scale)){const e=i.normalTexture.scale;a.normalScale.set(e,e)}if(void 0!==i.occlusionTexture&&o!==t.MeshBasicMaterial&&(c.push(s.assignTexture(a,"aoMap",i.occlusionTexture)),void 0!==i.occlusionTexture.strength&&(a.aoMapIntensity=i.occlusionTexture.strength)),void 0!==i.emissiveFactor&&o!==t.MeshBasicMaterial){const e=i.emissiveFactor;a.emissive=(new t.Color).setRGB(e[0],e[1],e[2],t.LinearSRGBColorSpace)}return void 0!==i.emissiveTexture&&o!==t.MeshBasicMaterial&&c.push(s.assignTexture(a,"emissiveMap",i.emissiveTexture,t.SRGBColorSpace)),Promise.all(c).then(function(){const t=new o(a);return i.name&&(t.name=i.name),J(t,i),s.associations.set(t,{materials:e}),i.extensions&&Q(n,t,i),t})}createUniqueName(e){const s=t.PropertyBinding.sanitizeNodeName(e||"");return s in this.nodeNamesUsed?s+"_"+ ++this.nodeNamesUsed[s]:(this.nodeNamesUsed[s]=0,s)}loadGeometries(e){const s=this,r=this.extensions,n=this.primitiveCache;function i(e){return r[l.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then(function(t){return ne(t,e,s)})}const o=[];for(let r=0,a=e.length;r<a;r++){const a=e[r],c=$(a),u=n[c];if(u)o.push(u.promise);else{let e;e=a.extensions&&a.extensions[l.KHR_DRACO_MESH_COMPRESSION]?i(a):ne(new t.BufferGeometry,a,s),n[c]={primitive:a,promise:e},o.push(e)}}return Promise.all(o)}loadMesh(e){const s=this,n=this.json,i=this.extensions,o=n.meshes[e],a=o.primitives,c=[];for(let e=0,t=a.length;e<t;e++){const t=void 0===a[e].material?Y(this.cache):this.getDependency("material",a[e].material);c.push(t)}return c.push(s.loadGeometries(a)),Promise.all(c).then(function(n){const c=n.slice(0,n.length-1),l=n[n.length-1],u=[];for(let n=0,h=l.length;n<h;n++){const h=l[n],d=a[n];let p;const m=c[n];if(d.mode===D.TRIANGLES||d.mode===D.TRIANGLE_STRIP||d.mode===D.TRIANGLE_FAN||void 0===d.mode)p=!0===o.isSkinnedMesh?new t.SkinnedMesh(h,m):new t.Mesh(h,m),!0===p.isSkinnedMesh&&p.normalizeSkinWeights(),d.mode===D.TRIANGLE_STRIP?p.geometry=r(p.geometry,t.TriangleStripDrawMode):d.mode===D.TRIANGLE_FAN&&(p.geometry=r(p.geometry,t.TriangleFanDrawMode));else if(d.mode===D.LINES)p=new t.LineSegments(h,m);else if(d.mode===D.LINE_STRIP)p=new t.Line(h,m);else if(d.mode===D.LINE_LOOP)p=new t.LineLoop(h,m);else{if(d.mode!==D.POINTS)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+d.mode);p=new t.Points(h,m)}Object.keys(p.geometry.morphAttributes).length>0&&Z(p,o),p.name=s.createUniqueName(o.name||"mesh_"+e),J(p,o),d.extensions&&Q(i,p,d),s.assignFinalMaterial(p),u.push(p)}for(let t=0,r=u.length;t<r;t++)s.associations.set(u[t],{meshes:e,primitives:t});if(1===u.length)return o.extensions&&Q(i,u[0],o),u[0];const h=new t.Group;o.extensions&&Q(i,h,o),s.associations.set(h,{meshes:e});for(let e=0,t=u.length;e<t;e++)h.add(u[e]);return h})}loadCamera(e){let s;const r=this.json.cameras[e],n=r[r.type];if(n)return"perspective"===r.type?s=new t.PerspectiveCamera(t.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):"orthographic"===r.type&&(s=new t.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),r.name&&(s.name=this.createUniqueName(r.name)),J(s,r),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const s=this.json.skins[e],r=[];for(let e=0,t=s.joints.length;e<t;e++)r.push(this._loadNodeShallow(s.joints[e]));return void 0!==s.inverseBindMatrices?r.push(this.getDependency("accessor",s.inverseBindMatrices)):r.push(null),Promise.all(r).then(function(e){const r=e.pop(),n=e,i=[],o=[];for(let e=0,a=n.length;e<a;e++){const a=n[e];if(a){i.push(a);const s=new t.Matrix4;null!==r&&s.fromArray(r.array,16*e),o.push(s)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[e])}return new t.Skeleton(i,o)})}loadAnimation(e){const s=this.json,r=this,n=s.animations[e],i=n.name?n.name:"animation_"+e,o=[],a=[],c=[],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,i=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&&(o.push(this.getDependency("node",i)),a.push(this.getDependency("accessor",h)),c.push(this.getDependency("accessor",d)),l.push(s),u.push(r))}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(c),Promise.all(l),Promise.all(u)]).then(function(e){const s=e[0],o=e[1],a=e[2],c=e[3],l=e[4],u=[];for(let e=0,t=s.length;e<t;e++){const t=s[e],n=o[e],i=a[e],h=c[e],d=l[e];if(void 0===t)continue;t.updateMatrix&&t.updateMatrix();const p=r._createAnimationTracks(t,n,i,h,d);if(p)for(let e=0;e<p.length;e++)u.push(p[e])}const h=new t.AnimationClip(i,void 0,u);return J(h,n),h})}createNodeMesh(e){const t=this.json,s=this,r=t.nodes[e];return void 0===r.mesh?null:s.getDependency("mesh",r.mesh).then(function(e){const t=s._getNodeRef(s.meshCache,r.mesh,e);return void 0!==r.weights&&t.traverse(function(e){if(e.isMesh)for(let t=0,s=r.weights.length;t<s;t++)e.morphTargetInfluences[t]=r.weights[t]}),t})}loadNode(e){const s=this,r=this.json.nodes[e],n=s._loadNodeShallow(e),i=[],o=r.children||[];for(let e=0,t=o.length;e<t;e++)i.push(s.getDependency("node",o[e]));const a=void 0===r.skin?Promise.resolve(null):s.getDependency("skin",r.skin);return Promise.all([n,Promise.all(i),a]).then(function(e){const s=e[0],r=e[1],n=e[2];null!==n&&s.traverse(function(e){e.isSkinnedMesh&&e.bind(n,se)});for(let e=0,t=r.length;e<t;e++)s.add(r[e]);if(void 0!==s.userData.pivot&&r.length>0){const e=s.userData.pivot,n=r[0];s.pivot=(new t.Vector3).fromArray(e),s.position.x-=e[0],s.position.y-=e[1],s.position.z-=e[2],n.position.set(0,0,0),delete s.userData.pivot}return s})}_loadNodeShallow(e){const s=this.json,r=this.extensions,n=this;if(void 0!==this.nodeCache[e])return this.nodeCache[e];const i=s.nodes[e],o=i.name?n.createUniqueName(i.name):"",a=[],c=n._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return c&&a.push(c),void 0!==i.camera&&a.push(n.getDependency("camera",i.camera).then(function(e){return n._getNodeRef(n.cameraCache,i.camera,e)})),n._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){a.push(e)}),this.nodeCache[e]=Promise.all(a).then(function(s){let a;if(a=!0===i.isBone?new t.Bone:s.length>1?new t.Group:1===s.length?s[0]:new t.Object3D,a!==s[0])for(let e=0,t=s.length;e<t;e++)a.add(s[e]);if(i.name&&(a.userData.name=i.name,a.name=o),J(a,i),i.extensions&&Q(r,a,i),void 0!==i.matrix){const e=new t.Matrix4;e.fromArray(i.matrix),a.applyMatrix4(e)}else void 0!==i.translation&&a.position.fromArray(i.translation),void 0!==i.rotation&&a.quaternion.fromArray(i.rotation),void 0!==i.scale&&a.scale.fromArray(i.scale);if(n.associations.has(a)){if(void 0!==i.mesh&&n.meshCache.refs[i.mesh]>1){const e=n.associations.get(a);n.associations.set(a,{...e})}}else n.associations.set(a,{});return n.associations.get(a).nodes=e,a}),this.nodeCache[e]}loadScene(e){const s=this.extensions,r=this.json.scenes[e],i=this,o=new t.Group;r.name&&(o.name=i.createUniqueName(r.name)),J(o,r),r.extensions&&Q(s,o,r);const a=r.nodes||[],c=[];for(let e=0,t=a.length;e<t;e++)c.push(i.getDependency("node",a[e]));return Promise.all(c).then(function(e){for(let t=0,s=e.length;t<s;t++){const s=e[t];null!==s.parent?o.add(n(s)):o.add(s)}return i.associations=(e=>{const s=new Map;for(const[e,r]of i.associations)(e instanceof t.Material||e instanceof t.Texture)&&s.set(e,r);return e.traverse(e=>{const t=i.associations.get(e);null!=t&&s.set(e,t)}),s})(o),o})}_createAnimationTracks(e,s,r,n,i){const o=[],a=e.name?e.name:e.uuid,c=[];function l(e){e.morphTargetInfluences&&c.push(e.name?e.name:e.uuid)}let u;switch(j[i.path]===j.weights?(l(e),e.isGroup&&e.children.forEach(l)):c.push(a),j[i.path]){case j.weights:u=t.NumberKeyframeTrack;break;case j.rotation:u=t.QuaternionKeyframeTrack;break;case j.translation:case j.scale:u=t.VectorKeyframeTrack;break;default:if(1===r.itemSize)u=t.NumberKeyframeTrack;else u=t.VectorKeyframeTrack}const h=void 0!==n.interpolation?X[n.interpolation]:t.InterpolateLinear,d=this._getArrayFromAccessor(r);for(let e=0,t=c.length;e<t;e++){const t=new u(c[e]+"."+j[i.path],s.array,d,h);"CUBICSPLINE"===n.interpolation&&this._createCubicSplineTrackInterpolant(t),o.push(t)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const e=te(t.constructor),s=new Float32Array(t.length);for(let r=0,n=t.length;r<n;r++)s[r]=t[r]*e;t=s}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof t.QuaternionKeyframeTrack?F:H)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function ne(e,s,r){const n=s.attributes,i=[];function o(t,s){return r.getDependency("accessor",t).then(function(t){e.setAttribute(s,t)})}for(const t in n){const s=V[t]||t.toLowerCase();s in e.attributes||i.push(o(n[t],s))}if(void 0!==s.indices&&!e.index){const t=r.getDependency("accessor",s.indices).then(function(t){e.setIndex(t)});i.push(t)}return t.ColorManagement.workingColorSpace!==t.LinearSRGBColorSpace&&"COLOR_0"in n&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${t.ColorManagement.workingColorSpace}" not supported.`),J(e,s),function(e,s,r){const n=s.attributes,i=new t.Box3;if(void 0===n.POSITION)return;{const e=r.json.accessors[n.POSITION],s=e.min,o=e.max;if(void 0===s||void 0===o)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(i.set(new t.Vector3(s[0],s[1],s[2]),new t.Vector3(o[0],o[1],o[2])),e.normalized){const t=te(U[e.componentType]);i.min.multiplyScalar(t),i.max.multiplyScalar(t)}}const o=s.targets;if(void 0!==o){const e=new t.Vector3,s=new t.Vector3;for(let t=0,n=o.length;t<n;t++){const n=o[t];if(void 0!==n.POSITION){const t=r.json.accessors[n.POSITION],i=t.min,o=t.max;if(void 0!==i&&void 0!==o){if(s.setX(Math.max(Math.abs(i[0]),Math.abs(o[0]))),s.setY(Math.max(Math.abs(i[1]),Math.abs(o[1]))),s.setZ(Math.max(Math.abs(i[2]),Math.abs(o[2]))),t.normalized){const e=te(U[t.componentType]);s.multiplyScalar(e)}e.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}i.expandByVector(e)}e.boundingBox=i;const a=new t.Sphere;i.getCenter(a.center),a.radius=i.min.distanceTo(i.max)/2,e.boundingSphere=a}(e,s,r),Promise.all(i).then(function(){return void 0!==s.targets?function(e,t,s){let r=!1,n=!1,i=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(r=!0),void 0!==s.NORMAL&&(n=!0),void 0!==s.COLOR_0&&(i=!0),r&&n&&i)break}if(!r&&!n&&!i)return Promise.resolve(e);const o=[],a=[],c=[];for(let l=0,u=t.length;l<u;l++){const u=t[l];if(r){const t=void 0!==u.POSITION?s.getDependency("accessor",u.POSITION):e.attributes.position;o.push(t)}if(n){const t=void 0!==u.NORMAL?s.getDependency("accessor",u.NORMAL):e.attributes.normal;a.push(t)}if(i){const t=void 0!==u.COLOR_0?s.getDependency("accessor",u.COLOR_0):e.attributes.color;c.push(t)}}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(c)]).then(function(t){const s=t[0],o=t[1],a=t[2];return r&&(e.morphAttributes.position=s),n&&(e.morphAttributes.normal=o),i&&(e.morphAttributes.color=a),e.morphTargetsRelative=!0,e})}(e,s.targets,r):e})}class ie extends s.Loader{constructor(e){super(),this.viewer=e,this.manager=null}dispose(){this.manager&&this.manager.dispose()}isSupport(e,t=""){return("string"==typeof e||e instanceof globalThis.File||e instanceof ArrayBuffer)&&/(gltf|glb)$/i.test(t)}async load(e,t,r={}){this.manager=new s.GLTFLoadingManager(e,r);const n=new o(this.manager);n.setPath(this.manager.path),n.setCrossOrigin(r.crossOrigin||n.crossOrigin),n.setRequestHeader(r.requestHeader||{}),n.setWithCredentials(r.withCredentials||n.withCredentials);const i=await n.loadAsync(this.manager.fileURL,t=>{const{lengthComputable:s,loaded:r,total:n}=t,i=s?r/n:1;this.viewer.emitEvent({type:"geometryprogress",data:i,file:e})});if(!this.viewer.scene)return this;let a=1;i.scene.traverse(e=>{e.userData={handle:a+"",...e.userData},a++});const c=new s.ModelImpl(i.scene);return c.id=r.modelId||this.extractFileName(e),this.viewer.scene.add(i.scene),this.viewer.models.push(c),this.viewer.syncOptions(),this.viewer.syncOverlay(),this.viewer.emitEvent({type:"databasechunk",data:i.scene,file:e}),this.viewer.update(!0),this}}s.loaders.registerLoader("gltf-file",e=>new ie(e)),e.GLTFFileLoader=ie});
@@ -93,23 +93,23 @@
93
93
  ctrl = inData[ inPtr ++ ];
94
94
  if ( ctrl < ( 1 << 5 ) ) {
95
95
  ctrl ++;
96
- if ( outPtr + ctrl > outLength ) throw new Error( 'Output buffer is not large enough' );
97
- if ( inPtr + ctrl > inLength ) throw new Error( 'Invalid compressed data' );
96
+ if ( outPtr + ctrl > outLength ) throw new Error( 'THREE.PCDLoader: Output buffer is not large enough' );
97
+ if ( inPtr + ctrl > inLength ) throw new Error( 'THREE.PCDLoader: Invalid compressed data' );
98
98
  do {
99
99
  outData[ outPtr ++ ] = inData[ inPtr ++ ];
100
100
  } while ( -- ctrl );
101
101
  } else {
102
102
  len = ctrl >> 5;
103
103
  ref = outPtr - ( ( ctrl & 0x1f ) << 8 ) - 1;
104
- if ( inPtr >= inLength ) throw new Error( 'Invalid compressed data' );
104
+ if ( inPtr >= inLength ) throw new Error( 'THREE.PCDLoader: Invalid compressed data' );
105
105
  if ( len === 7 ) {
106
106
  len += inData[ inPtr ++ ];
107
- if ( inPtr >= inLength ) throw new Error( 'Invalid compressed data' );
107
+ if ( inPtr >= inLength ) throw new Error( 'THREE.PCDLoader: Invalid compressed data' );
108
108
  }
109
109
  ref -= inData[ inPtr ++ ];
110
- if ( outPtr + len + 2 > outLength ) throw new Error( 'Output buffer is not large enough' );
111
- if ( ref < 0 ) throw new Error( 'Invalid compressed data' );
112
- if ( ref >= outPtr ) throw new Error( 'Invalid compressed data' );
110
+ if ( outPtr + len + 2 > outLength ) throw new Error( 'THREE.PCDLoader: Output buffer is not large enough' );
111
+ if ( ref < 0 ) throw new Error( 'THREE.PCDLoader: Invalid compressed data' );
112
+ if ( ref >= outPtr ) throw new Error( 'THREE.PCDLoader: Invalid compressed data' );
113
113
  do {
114
114
  outData[ outPtr ++ ] = outData[ ref ++ ];
115
115
  } while ( -- len + 2 );
@@ -279,7 +279,7 @@
279
279
  }
280
280
  if ( offset.label !== undefined ) {
281
281
  const labelIndex = PCDheader.fields.indexOf( 'label' );
282
- label.push( dataview.getInt32( ( PCDheader.points * offset.label ) + PCDheader.size[ labelIndex ] * i, this.littleEndian ) );
282
+ label.push( this._getDataView( dataview, ( PCDheader.points * offset.label ) + PCDheader.size[ labelIndex ] * i, PCDheader.type[ labelIndex ], PCDheader.size[ labelIndex ] ) );
283
283
  }
284
284
  }
285
285
  }
@@ -315,7 +315,8 @@
315
315
  intensity.push( this._getDataView( dataview, row + offset.intensity, PCDheader.type[ intensityIndex ], PCDheader.size[ intensityIndex ] ) );
316
316
  }
317
317
  if ( offset.label !== undefined ) {
318
- label.push( dataview.getInt32( row + offset.label, this.littleEndian ) );
318
+ const labelIndex = PCDheader.fields.indexOf( 'label' );
319
+ label.push( this._getDataView( dataview, row + offset.label, PCDheader.type[ labelIndex ], PCDheader.size[ labelIndex ] ) );
319
320
  }
320
321
  }
321
322
  }