@jdultra/threedtiles 9.0.3 → 9.0.5

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.
@@ -1,2 +1,3 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.threedtiles=t():e.threedtiles=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{InstancedOGC3DTile:()=>ge,InstancedTileLoader:()=>Ve,OGC3DTile:()=>Q,OcclusionCullingService:()=>a,TileLoader:()=>A});const n=require("three"),r=require("three/src/math/MathUtils");function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(i=r.key,a=void 0,a=function(e,t){if("object"!==o(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(i,"string"),"symbol"===o(a)?a:String(a)),r)}var i,a}var a=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.cullMap=[],this.cullMaterial=new n.MeshBasicMaterial({vertexColors:!0}),this.cullMaterial.side=n.FrontSide,this.cullTarget=this.createCullTarget(),this.cullPixels=new Uint8Array(4*this.cullTarget.width*this.cullTarget.height)}var t,o,a;return t=e,(o=[{key:"setSide",value:function(e){this.cullMaterial.side=e}},{key:"createCullTarget",value:function(){var e=new n.WebGLRenderTarget(Math.floor(.05*window.innerWidth),Math.floor(.05*window.innerHeight));return e.texture.format=n.RGBAFormat,e.texture.encoding=n.LinearEncoding,e.texture.minFilter=n.NearestFilter,e.texture.magFilter=n.NearestFilter,e.texture.generateMipmaps=!1,e.stencilBuffer=!1,e.depthBuffer=!0,e.depthTexture=new n.DepthTexture,e.depthTexture.format=n.DepthFormat,e.depthTexture.type=n.UnsignedShortType,e}},{key:"update",value:function(e,t,n){var o=t.getRenderTarget(),i=e.overrideMaterial;e.overrideMaterial=this.cullMaterial,t.setRenderTarget(this.cullTarget),t.render(e,n),e.overrideMaterial=i,t.setRenderTarget(o),t.readRenderTargetPixels(this.cullTarget,0,0,this.cullTarget.width,this.cullTarget.height,this.cullPixels),this.cullMap=[];for(var a=0;a<this.cullPixels.length;a+=4){var s=(0,r.clamp)(this.cullPixels[a],0,255)<<16^(0,r.clamp)(this.cullPixels[a+1],0,255)<<8^(0,r.clamp)(this.cullPixels[a+2],0,255)<<0;this.cullMap[s]=!0}}},{key:"hasID",value:function(e){return this.cullMap[e]}}])&&i(t.prototype,o),a&&i(t,a),Object.defineProperty(t,"prototype",{writable:!1}),e}();function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function l(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==s(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==s(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===s(i)?i:String(i)),r)}var o,i}var u=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.center=new n.Vector3(t[0],t[1],t[2]);var r=new n.Vector3(t[3],t[4],t[4]),o=new n.Vector3(t[6],t[7],t[8]),i=new n.Vector3(t[9],t[10],t[11]);this.halfWidth=r.length(),this.halfHeight=o.length(),this.halfDepth=i.length(),r.normalize(),o.normalize(),i.normalize(),this.sphere=new n.Sphere(this.center,Math.sqrt(this.halfWidth*this.halfWidth+this.halfHeight*this.halfHeight+this.halfDepth*this.halfDepth)),this.matrixToOBBCoordinateSystem=new n.Matrix3,this.matrixToOBBCoordinateSystem.set(r.x,r.y,r.z,o.x,o.y,o.z,i.x,i.y,i.z)}var t,r,o;return t=e,(r=[{key:"inFrustum",value:function(e){return e.intersectsSphere(this.sphere)}},{key:"distanceToPoint",value:function(e){var t=e.clone();t.sub(this.center),t.applyMatrix3(this.matrixToOBBCoordinateSystem);var n=Math.max(0,Math.max(-this.halfWidth-t.x,t.x-this.halfWidth)),r=Math.max(0,Math.max(-this.halfHeight-t.y,t.y-this.halfHeight)),o=Math.max(0,Math.max(-this.halfDepth-t.z,t.z-this.halfDepth));return Math.sqrt(n*n+r*r+o*o)}}])&&l(t.prototype,r),o&&l(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();const c=require("js-utils-z"),h=require("three/examples/jsm/loaders/GLTFLoader.js"),d=require("three/examples/jsm/loaders/DRACOLoader.js"),f=require("three/examples/jsm/loaders/KTX2Loader");function p(e){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},p(e)}function m(){return m="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=g(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(arguments.length<3?e:n):o.value}},m.apply(this,arguments)}function y(e,t){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},y(e,t)}function b(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=g(e);if(t){var o=g(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"===p(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function g(e){return g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},g(e)}function v(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function w(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==p(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==p(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===p(i)?i:String(i)),r)}var o,i}function j(e,t,n){return t&&w(e.prototype,t),n&&w(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}var C=new TextDecoder,M=function(){function e(t,n,r,o){v(this,e),this.buffer=t,this.binOffset=n+r,this.binLength=o;var i=null;if(0!==r)try{var a=new Uint8Array(t,n,r);i=JSON.parse(C.decode(a))}catch(e){i={}}else i={};this.header=i}return j(e,[{key:"getKeys",value:function(){return Object.keys(this.header)}},{key:"getData",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=this.header;if(!(e in o))return null;var i=o[e];if(i instanceof Object){if(Array.isArray(i))return i;var a,s,l=this.buffer,u=this.binOffset,c=this.binLength,h=i.byteOffset||0,d=i.type||r,f=i.componentType||n;if("type"in i&&r&&i.type!==r)throw new Error("FeatureTable: Specified type does not match expected type.");switch(d){case"SCALAR":a=1;break;case"VEC2":a=2;break;case"VEC3":a=3;break;case"VEC4":a=4;break;default:throw new Error('FeatureTable : Feature type not provided for "'.concat(e,'".'))}var p=u+h,m=t*a;switch(f){case"BYTE":s=new Int8Array(l,p,m);break;case"UNSIGNED_BYTE":s=new Uint8Array(l,p,m);break;case"SHORT":s=new Int16Array(l,p,m);break;case"UNSIGNED_SHORT":s=new Uint16Array(l,p,m);break;case"INT":s=new Int32Array(l,p,m);break;case"UNSIGNED_INT":s=new Uint32Array(l,p,m);break;case"FLOAT":s=new Float32Array(l,p,m);break;case"DOUBLE":s=new Float64Array(l,p,m);break;default:throw new Error('FeatureTable : Feature component type not provided for "'.concat(e,'".'))}if(p+m*s.BYTES_PER_ELEMENT>u+c)throw new Error("FeatureTable: Feature data read outside binary body length.");return s}return i}}]),e}(),x=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&y(e,t)}(n,e);var t=b(n);function n(e,r,o,i,a){var s;return v(this,n),(s=t.call(this,e,o,i,a)).batchSize=r,s}return j(n,[{key:"getData",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return m(g(n.prototype),"getData",this).call(this,e,this.batchSize,t,r)}}]),n}(M);function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function S(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==T(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==T(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===T(i)?i:String(i)),r)}var o,i}var k=new n.Matrix4;k.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);var O=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.gltfLoader=new h.GLTFLoader;var r=new d.DRACOLoader;if(r.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(r),t){var o=new f.KTX2Loader;o.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(t),this.gltfLoader.setKTX2Loader(o)}this.tempMatrix=new n.Matrix4}var t,r,o;return t=e,(r=[{key:"parseB3DM",value:function(e,t,n,r){var o=this,i=new DataView(e),a=String.fromCharCode(i.getUint8(0))+String.fromCharCode(i.getUint8(1))+String.fromCharCode(i.getUint8(2))+String.fromCharCode(i.getUint8(3));console.assert("b3dm"===a);var s=i.getUint32(8,!0);console.assert(s===e.byteLength);var l=i.getUint32(12,!0),u=i.getUint32(16,!0),c=i.getUint32(20,!0),h=i.getUint32(24,!0),d=new M(e,28,l,u),f=28+l+u,p=(new x(e,d.getData("BATCH_LENGTH"),f,c,h),f+c+h),m=new Uint8Array(e,p,s-p).slice().buffer;return new Promise((function(e,i){o.gltfLoader.parse(m,null,(function(i){var a=d.getData("RTC_CENTER");a?(o.tempMatrix.makeTranslation(a[0],a[1],a[2]),i.scene.applyMatrix4(o.tempMatrix)):i.userData.gltfExtensions&&i.userData.gltfExtensions.CESIUM_RTC&&(o.tempMatrix.makeTranslation(i.userData.gltfExtensions.CESIUM_RTC.center[0],i.userData.gltfExtensions.CESIUM_RTC.center[1],i.userData.gltfExtensions.CESIUM_RTC.center[2]),i.scene.applyMatrix4(o.tempMatrix)),r||i.scene.applyMatrix4(k),i.scene.traverse((function(e){e.isMesh&&(e.geometricError=n,r&&e.applyMatrix4(k),t&&t(e))})),e(i.scene)}),(function(e){console.error(e)}))}))}},{key:"parseB3DMInstanced",value:function(e,t,r,o){return this.parseB3DM(e,t,o).then((function(e){var t;return e.updateWorldMatrix(!1,!0),e.traverse((function(e){e.isMesh&&((t=new n.InstancedMesh(e.geometry,e.material,r)).baseMatrix=e.matrixWorld)})),t}))}}])&&S(t.prototype,r),o&&S(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();const E=require("set-interval-async/dynamic"),V=require("three/examples/jsm/loaders/GLTFLoader");function P(e){return P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},P(e)}function D(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==P(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==P(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===P(i)?i:String(i)),r)}var o,i}var L=0,R=new n.Matrix4;R.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);var A=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.maxCachedItems=100,t&&(this.meshCallback=t.meshCallback,this.pointsCallback=t.pointsCallback,t.maxCachedItems&&(this.maxCachedItems=t.maxCachedItems)),this.gltfLoader=new V.GLTFLoader;var n=new d.DRACOLoader;if(n.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(n),t&&t.renderer){var r=new f.KTX2Loader;r.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(t.renderer),this.gltfLoader.setKTX2Loader(r),this.b3dmDecoder=new O(t.renderer)}else this.b3dmDecoder=new O(null);this.cache=new c.LinkedHashMap,this.register={},this.ready=[],this.downloads=[],this.nextReady=[],this.nextDownloads=[],this.init()}var t,n,r;return t=e,(n=[{key:"init",value:function(){var e=this;(0,E.setIntervalAsync)((function(){e.download()}),10),(0,E.setIntervalAsync)((function(){var t=Date.now(),n=0;do{n=e.loadBatch()}while(n>0&&Date.now()-t<=0)}),10)}},{key:"scheduleDownload",value:function(e){this.downloads.unshift(e)}},{key:"download",value:function(){if(0!=this.nextDownloads.length||(this.getNextDownloads(),0!=this.nextDownloads.length))for(;this.nextDownloads.length>0&&L<500;){var e=this.nextDownloads.shift();e&&e.shouldDoDownload()&&e.doDownload()}}},{key:"meshReceived",value:function(e,t,n,r,o,i,a){this.ready.unshift([e,t,n,r,o,i,a])}},{key:"loadBatch",value:function(){if(0==this.nextReady.length&&(this.getNextReady(),0==this.nextReady.length))return 0;var e=this.nextReady.shift();if(!e)return 0;var t=e[0],n=e[1],r=e[2],o=t.get(r);return o&&n[r]&&Object.keys(n[r]).forEach((function(e){var t=n[r][e];t&&(t(o),n[r][e]=null)})),1}},{key:"getNextDownloads",value:function(){for(var e=Number.MAX_VALUE,t=-1,n=this.downloads.length-1;n>=0;n--)this.downloads[n].shouldDoDownload()?this.downloads[n].distanceFunction||this.nextDownloads.push(this.downloads.splice(n,1)[0]):this.downloads.splice(n,1);if(!(this.nextDownloads.length>0)){for(var r=this.downloads.length-1;r>=0;r--){var o=this.downloads[r].distanceFunction()*this.downloads[r].level;o<e&&(e=o,t=r)}if(t>=0){var i=this.downloads.splice(t,1).pop();this.nextDownloads.push(i);for(var a=i.getSiblings(),s=this.downloads.length-1;s>=0;s--)a.includes(this.downloads[s].uuid)&&this.nextDownloads.push(this.downloads.splice(s,1).pop())}}}},{key:"getNextReady",value:function(){for(var e=Number.MAX_VALUE,t=-1,n=this.ready.length-1;n>=0;n--)this.ready[n][3]||this.nextReady.push(this.ready.splice(n,1)[0]);if(!(this.nextReady.length>0)){for(var r=this.ready.length-1;r>=0;r--){var o=this.ready[r][3]()*this.ready[r][5];o<e&&(e=o,t=r)}if(t>=0){var i=this.ready.splice(t,1).pop();this.nextReady.push(i);for(var a=i[4](),s=this.ready.length-1;s>=0;s--)a.includes(this.ready[s][6])&&this.nextready.push(this.ready.splice(s,1).pop())}}}},{key:"get",value:function(e,t,n,r,o,i,a,s,l){var u=this,c=this,h=U(n),d=new AbortController;if(e.signal.addEventListener("abort",(function(){c.register[h]&&0!=Object.keys(c.register[h]).length||d.abort()})),n.includes(".b3dm")||n.includes(".json")||n.includes(".gltf")||n.includes(".glb")){if(c.register[h]||(c.register[h]={}),c.register[h][t]&&console.error(" a tile should only be loaded once"),c.register[h][t]=r,c.cache.get(h))this.meshReceived(c.cache,c.register,h,o,i,a,t);else if(1==Object.keys(c.register[h]).length){var f;n.includes(".b3dm")?f=function(){L++,fetch(n,{signal:d.signal}).then((function(e){if(L--,!e.ok)throw console.error("could not load tile with path : "+n),new Error("couldn't load \"".concat(n,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.arrayBuffer()})).then((function(e){return u.b3dmDecoder.parseB3DM(e,c.meshCallback,l,s)})).then((function(e){c.cache.put(h,e),c.checkSize(),u.meshReceived(c.cache,c.register,h,o,i,a,t)})).catch((function(){}))}:n.includes(".glb")||n.includes(".gltf")?f=function(){L++,u.gltfLoader.load(n,(function(e){e.scene.traverse((function(e){e.geometricError=l,e.isMesh&&(s&&e.applyMatrix4(R),c.meshCallback&&c.meshCallback(e)),e.isPoints&&(s&&e.applyMatrix4(R),c.pointsCallback&&c.pointsCallback(e))})),c.cache.put(h,e.scene),c.checkSize(),c.meshReceived(c.cache,c.register,h,o,i,a,t)}))}:n.includes(".json")&&(f=function(){L++,fetch(n,{signal:d.signal}).then((function(e){if(L--,!e.ok)throw console.error("could not load tile with path : "+n),new Error("couldn't load \"".concat(n,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.json()})).then((function(e){c.cache.put(h,e),c.checkSize(),c.meshReceived(c.cache,c.register,h)})).catch((function(e){return console.error("tile download aborted")}))}),this.scheduleDownload({shouldDoDownload:function(){return!e.signal.aborted&&!!c.register[h]&&Object.keys(c.register[h]).length>0},doDownload:f,distanceFunction:o,getSiblings:i,level:a,uuid:t})}}else console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data")}},{key:"invalidate",value:function(e,t){var n=U(e);this.register[n]&&delete this.register[n][t]}},{key:"checkSize",value:function(){for(var e=this,t=0;e.cache.size()>e.maxCachedItems&&t<e.cache.size();){t++;var n=e.cache.head(),r=e.register[n.key];r&&(Object.keys(r).length>0?(e.cache.remove(n.key),e.cache.put(n.key,n.value)):(e.cache.remove(n.key),delete e.register[n.key],n.value.traverse((function(e){if(e.material)if(e.material.length)for(var t=0;t<e.material.length;++t)e.material[t].dispose();else e.material.dispose();e.geometry&&e.geometry.dispose()}))))}}}])&&D(t.prototype,n),r&&D(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function U(e){for(var t=e.split("/"),n=[],r=0,o=0;o<t.length;o++){var i=t[o];"."!==i&&""!==i&&".."!==i?n[r++]=i:".."===i&&r>0&&r--}if(0===r)return"/";var a="";for(o=0;o<r;o++)a+="/"+n[o];return a}const _=require("uuid"),F=require("path-browserify");function I(e){return I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},I(e)}function B(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==I(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==I(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===I(i)?i:String(i)),r)}var o,i}function N(e,t){return N=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},N(e,t)}function W(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=G(e);if(t){var o=G(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"===I(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return z(e)}(this,n)}}function z(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function G(e){return G=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},G(e)}var q=new n.Sphere(new n.Vector3(0,0,0),1),H=new n.Vector3(0,0,0),J=new n.Vector3(0,0,0),X=new n.Vector3(0,1,0),K=new n.Vector2(1e3,1e3),Y=new n.Quaternion,Q=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&N(e,t)}(s,e);var t,o,i,a=W(s);function s(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s);var o=z(t=a.call(this));if(t.uuid=(0,_.v4)(),e.tileLoader)t.tileLoader=e.tileLoader;else{var i={};i.meshCallback=e.meshCallback?e.meshCallback:function(e){e.material.wireframe=!1,e.material.side=n.DoubleSide},i.pointsCallback=e.pointsCallback?e.pointsCallback:function(e){e.material.size=.1,e.material.sizeAttenuation=!0},t.tileLoader=new A(i)}return t.geometricErrorMultiplier=e.geometricErrorMultiplier?e.geometricErrorMultiplier:1,t.renderer=e.renderer,t.meshCallback=e.meshCallback,t.loadOutsideView=e.loadOutsideView,t.cameraOnLoad=e.cameraOnLoad,t.parentTile=e.parentTile,t.occlusionCullingService=e.occlusionCullingService,t.static=e.static,t.occlusionCullingService&&(t.color=new n.Color,t.color.setHex(16777215*Math.random()),t.colorID=(0,r.clamp)(255*o.color.r,0,255)<<16^(0,r.clamp)(255*o.color.g,0,255)<<8^(0,r.clamp)(255*o.color.b,0,255)<<0),t.static&&(t.matrixAutoUpdate=!1),t.childrenTiles=[],t.meshContent,t.tileContent,t.refinement,t.rootPath,t.geometricError,t.boundingVolume,t.json,t.materialVisibility=!1,t.inFrustum=!0,t.level=e.level?e.level:0,t.hasMeshContent=!1,t.hasUnloadedJSONContent=!1,t.centerModel=e.centerModel,t.abortController=new AbortController,t.layers.disable(0),e.json?(o.setup(e),e.onLoadCallback&&e.onLoadCallback(o)):e.url&&fetch(e.url,{signal:o.abortController.signal}).then((function(r){if(!r.ok)throw new Error("couldn't load \"".concat(e.url,'". Request failed with status ').concat(r.status," : ").concat(r.statusText));r.json().then((function(r){if(o.setup({rootPath:F.dirname(e.url),json:r}),e.onLoadCallback&&e.onLoadCallback(o),o.centerModel){var i=new n.Sphere;o.boundingVolume instanceof u?i.copy(o.boundingVolume.sphere):o.boundingVolume instanceof n.Sphere&&i.copy(o.boundingVolume),t.json.boundingVolume.region&&(t.transformWGS84ToCartesian(.5*(t.json.boundingVolume.region[0]+t.json.boundingVolume.region[2]),.5*(t.json.boundingVolume.region[1]+t.json.boundingVolume.region[3]),.5*(t.json.boundingVolume.region[4]+t.json.boundingVolume.region[5]),H),Y.setFromUnitVectors(H.normalize(),X.normalize()),o.applyQuaternion(Y)),o.translateX(-i.center.x*o.scale.x),o.translateY(-i.center.y*o.scale.y),o.translateZ(-i.center.z*o.scale.z)}}))})),t}return t=s,(o=[{key:"setup",value:function(e){if(e.json.root?(this.json=e.json.root,this.json.refinement||(this.json.refinement=e.json.refinement),this.json.geometricError||(this.json.geometricError=e.json.geometricError),this.json.transform||(this.json.transform=e.json.transform),this.json.boundingVolume||(this.json.boundingVolume=e.json.boundingVolume)):this.json=e.json,this.rootPath=e.json.rootPath?e.json.rootPath:e.rootPath,this.json.refinement?this.refinement=this.json.refinement:this.refinement=e.parentRefinement,this.json.geometricError?this.geometricError=this.json.geometricError:this.geometricError=e.parentGeometricError,this.json.transform&&!this.centerModel){var t=new n.Matrix4;t.elements=this.json.transform,this.applyMatrix4(t)}if(this.json.boundingVolume)if(this.json.boundingVolume.box)this.boundingVolume=new u(this.json.boundingVolume.box);else if(this.json.boundingVolume.region){var r=this.json.boundingVolume.region;this.transformWGS84ToCartesian(r[0],r[1],r[4],H),this.transformWGS84ToCartesian(r[2],r[3],r[5],J),H.lerp(J,.5),this.boundingVolume=new n.Sphere(new n.Vector3(H.x,H.y,H.z),H.distanceTo(J))}else if(this.json.boundingVolume.sphere){var o=this.json.boundingVolume.sphere;this.boundingVolume=new n.Sphere(new n.Vector3(o[0],o[1],o[2]),o[3])}else this.boundingVolume=e.parentBoundingVolume;else this.boundingVolume=e.parentBoundingVolume;this.json.content&&(this.json.content.uri&&this.json.content.uri.includes("json")||this.json.content.url&&this.json.content.url.includes("json")?this.hasUnloadedJSONContent=!0:this.hasMeshContent=!0,this.load())}},{key:"isAbsolutePathOrURL",value:function(e){var t=/^(?:http|https|ftp|tcp|udp):\/\/\S+/.test(e),n=e.startsWith("/")&&!e.startsWith("//");return t||n}},{key:"load",value:function(){var e,t=this;t.deleted||t.json.content&&(t.json.content.uri?e=F.isAbsolute(t.json.content.uri)||t.isAbsolutePathOrURL(t.json.content.uri)?t.json.content.uri:t.rootPath+F.sep+t.json.content.uri:t.json.content.url&&(e=F.isAbsolute(t.json.content.url)||t.isAbsolutePathOrURL(t.json.content.url)?t.json.content.url:t.rootPath+F.sep+t.json.content.url),e&&(e.includes(".b3dm")||e.includes(".glb")||e.includes(".gltf")?(t.contentURL=e,t.tileLoader.get(t.abortController,this.uuid,e,(function(e){t.deleted||(e.traverse((function(e){if(e.isMesh){if(e.layers.disable(0),t.occlusionCullingService){for(var r=e.geometry.attributes.position,o=[],i=0;i<r.count;i++)o.push(t.color.r,t.color.g,t.color.b);e.geometry.setAttribute("color",new n.Float32BufferAttribute(o,3))}t.static&&(e.matrixAutoUpdate=!1)}})),t.add(e),t.updateWorldMatrix(!1,!0),t.meshContent=e)}),t.cameraOnLoad?function(){return t.calculateDistanceToCamera(t.cameraOnLoad)}:function(){return 0},(function(){return t.getSiblings()}),t.level,!!t.json.boundingVolume.region,t.geometricError)):e.includes(".json")&&t.tileLoader.get(t.abortController,this.uuid,e,(function(n){t.deleted||(t.json.children||(t.json.children=[]),n.rootPath=F.dirname(e),t.json.children.push(n),delete t.json.content,t.hasUnloadedJSONContent=!1)}))))}},{key:"dispose",value:function(){var e=this;e.childrenTiles.forEach((function(e){return e.dispose()})),e.deleted=!0,this.traverse((function(t){t.contentURL&&e.tileLoader.invalidate(t.contentURL,t.uuid),t.abortController&&t.abortController.abort()})),this.parent=null,this.parentTile=null,this.dispatchEvent({type:"removed"})}},{key:"disposeChildren",value:function(){var e=this;e.childrenTiles.forEach((function(e){return e.dispose()})),e.childrenTiles=[],e.children=[],e.meshContent&&e.children.push(e.meshContent)}},{key:"update",value:function(e){var t=new n.Frustum;t.setFromProjectionMatrix((new n.Matrix4).multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse)),this._update(e,t)}},{key:"_update",value:function(e,t){var n,r=this,o=r.materialVisibility;function i(e){if(r.hasMeshContent&&r.meshContent){if(e<0)return r.inFrustum=!1,void r.changeContentVisibility(!!r.loadOutsideView);if(r.inFrustum=!0,0!=r.childrenTiles.length){if(e>=r.geometricErrorMultiplier*r.geometricError)r.changeContentVisibility(!0);else if(e<r.geometricErrorMultiplier*r.geometricError){var t=!0;r.childrenTiles.every((function(e){return!!e.isReady()||(t=!1,!1)})),t&&r.changeContentVisibility(!1)}}else r.changeContentVisibility(!0)}}r.boundingVolume&&r.geometricError&&(r.metric=r.calculateUpdateMetric(e,t)),r.childrenTiles.forEach((function(n){return n._update(e,t)})),i(r.metric),(n=r.metric)<0&&r.hasMeshContent||r.occlusionCullingService&&r.hasMeshContent&&!r.occlusionCullingService.hasID(r.colorID)||(!r.hasMeshContent||n<r.geometricErrorMultiplier*r.geometricError&&r.meshContent)&&r.json&&r.json.children&&r.childrenTiles.length!=r.json.children.length&&r.json.children.forEach((function(t){var n=new s({parentTile:r,parentGeometricError:r.geometricError,parentBoundingVolume:r.boundingVolume,parentRefinement:r.refinement,json:t,rootPath:r.rootPath,geometricErrorMultiplier:r.geometricErrorMultiplier,loadOutsideView:r.loadOutsideView,level:r.level+1,tileLoader:r.tileLoader,cameraOnLoad:e,occlusionCullingService:r.occlusionCullingService,renderer:r.renderer,static:r.static,centerModel:!1});r.childrenTiles.push(n),r.add(n)})),function(e,t){if(r.hasMeshContent)r.inFrustum?r.occlusionCullingService&&!t&&r.hasMeshContent&&r.meshContent&&r.meshDisplayed&&r.areAllChildrenLoadedAndHidden()?(r.disposeChildren(),i(e)):e>=r.geometricErrorMultiplier*r.geometricError&&(r.disposeChildren(),i()):(r.disposeChildren(),i(e))}(r.metric,o)}},{key:"areAllChildrenLoadedAndHidden",value:function(){var e=!0,t=this;return this.childrenTiles.every((function(n){if(n.hasMeshContent){if(n.childrenTiles.length>0)return e=!1,!1;if(!n.inFrustum)return!0;if(!n.materialVisibility||n.meshDisplayed)return e=!1,!1;if(t.occlusionCullingService.hasID(n.colorID))return e=!1,!1}else if(!n.areAllChildrenLoadedAndHidden())return e=!1,!1;return!0})),e}},{key:"isReady",value:function(){if(!this.inFrustum)return!0;if(this.hasUnloadedJSONContent)return!1;if((!this.hasMeshContent||!this.meshContent||!this.materialVisibility)&&this.childrenTiles.length>0){var e=!0;return this.childrenTiles.every((function(t){return!!t.isReady()||(e=!1,!1)})),e}return!this.hasMeshContent||!!this.meshContent&&!!this.materialVisibility&&!!this.meshDisplayed}},{key:"changeContentVisibility",value:function(e){var t=this;function n(e,n){e.material.visible=n,n&&(e.onAfterRender=function(){delete e.onAfterRender,t.meshDisplayed=!0})}t.hasMeshContent&&t.meshContent&&(e?t.meshContent.traverse((function(e){e.isMesh&&e.layers.enable(0)})):t.meshContent.traverse((function(e){e.isMesh&&e.layers.disable(0)}))),t.materialVisibility!=e&&(t.materialVisibility=e,t.meshDisplayed=!0,t.meshContent.traverse?t.meshContent.traverse((function(t){t.material&&n(t,e)})):t.meshContent.scenes&&t.meshContent.scenes.forEach((function(t){return t.traverse((function(t){t.material&&n(t,e)}))})))}},{key:"calculateUpdateMetric",value:function(e,t){if(this.boundingVolume instanceof u){if(q.copy(this.boundingVolume.sphere),q.applyMatrix4(this.matrixWorld),!t.intersectsSphere(q))return-1}else{if(!(this.boundingVolume instanceof n.Sphere))return console.error("unsupported shape"),-1;if(q.copy(this.boundingVolume),q.applyMatrix4(this.matrixWorld),!t.intersectsSphere(q))return-1}var r=Math.max(0,e.position.distanceTo(q.center)-q.radius);if(0==r)return 0;var o=this.matrixWorld.getMaxScaleOnAxis();this.renderer&&this.renderer.getDrawingBufferSize(K);var i=K.y,a=e.fov;e.aspect<1&&(a*=e.aspect,i=K.x);var s=2*Math.tan(.5*a*.017453292519943295)*r;return 16*window.devicePixelRatio*s/(i*o)}},{key:"getSiblings",value:function(){var e=this,t=[];if(!e.parentTile)return t;for(var n=e.parentTile;!n.hasMeshContent&&n.parentTile;)n=n.parentTile;return n.childrenTiles.forEach((function(n){if(n&&n!=e){for(;!n.hasMeshContent&&n.childrenTiles[0];)n=n.childrenTiles[0];t.push(n)}})),t}},{key:"calculateDistanceToCamera",value:function(e){return this.boundingVolume instanceof u?(q.copy(this.boundingVolume.sphere),q.applyMatrix4(this.matrixWorld)):this.boundingVolume instanceof n.Sphere?(q.copy(this.boundingVolume),q.applyMatrix4(this.matrixWorld)):console.error("unsupported shape"),Math.max(0,e.position.distanceTo(q.center)-q.radius)}},{key:"setGeometricErrorMultiplier",value:function(e){this.geometricErrorMultiplier=e,this.childrenTiles.forEach((function(t){return t.setGeometricErrorMultiplier(e)}))}},{key:"transformWGS84ToCartesian",value:function(e,t,n,r){var o=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(t),2)),i=Math.cos(t),a=Math.cos(e),s=Math.sin(t),l=o+n,u=l*i*a,c=l*i*Math.sin(e),h=(.993305615557957*o+n)*s;r.set(u,c,h)}}])&&B(t.prototype,o),i&&B(t,i),Object.defineProperty(t,"prototype",{writable:!1}),s}(n.Object3D);function Z(e){return Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Z(e)}function $(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==Z(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==Z(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===Z(i)?i:String(i)),r)}var o,i}function ee(e,t){return ee=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},ee(e,t)}function te(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=re(e);if(t){var o=re(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"===Z(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return ne(e)}(this,n)}}function ne(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function re(e){return re=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},re(e)}var oe=new n.Sphere(new n.Vector3(0,0,0),1),ie=new n.Vector3(0,0,0),ae=new n.Vector3(0,0,0),se=new n.Vector3(0,1,0),le=new n.Vector2,ue=new n.Quaternion,ce=new n.Matrix4,he=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ee(e,t)}(a,e);var t,r,o,i=te(a);function a(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a);var r=ne(t=i.call(this));return t.uuid=(0,_.v4)(),e.tileLoader?t.tileLoader=e.tileLoader:console.error("an instanced tileset must be provided an InstancedTilesetLoader"),t.master=e.master,t.meshCallback=e.meshCallback,t.loadOutsideView=e.loadOutsideView,t.cameraOnLoad=e.cameraOnLoad,t.parentTile=e.parentTile,t.childrenTiles=[],t.jsonChildren=[],t.meshContent,t.tileContent,t.refinement,t.rootPath,t.geometricError,t.boundingVolume,t.json,t.materialVisibility=!1,t.inFrustum=!0,t.level=e.level?e.level:0,t.hasMeshContent=!1,t.hasUnloadedJSONContent=!1,t.centerModel=e.centerModel,t.deleted=!1,t.abortController=new AbortController,e.json?(t.rootPath=e.json.rootPath?e.json.rootPath:e.rootPath,e.json.children&&(t.jsonChildren=e.json.children),r.setup(e),e.onLoadCallback&&e.onLoadCallback(r)):e.url&&(t.loadJson=function(o,i){var a=F.dirname(i);if(r.setup({rootPath:a,json:o}),r.centerModel){var s=new n.Sphere;r.boundingVolume instanceof u?s.copy(r.boundingVolume.sphere):r.boundingVolume instanceof n.Sphere&&s.copy(r.boundingVolume),t.json.boundingVolume.region&&(r.transformWGS84ToCartesian(.5*(r.json.boundingVolume.region[0]+r.json.boundingVolume.region[2]),.5*(r.json.boundingVolume.region[1]+r.json.boundingVolume.region[3]),.5*(r.json.boundingVolume.region[4]+r.json.boundingVolume.region[5]),ie),ue.setFromUnitVectors(ie.normalize(),se.normalize()),r.master.applyQuaternion(ue),r.master.updateWorldMatrix(!1,!1)),ce.makeTranslation(-s.center.x*r.scale.x,-s.center.y*r.scale.y,-s.center.z*r.scale.z),r.master.matrix.multiply(ce),r.master.matrix.decompose(r.master.position,r.master.quaternion,r.master.scale)}e.onLoadCallback&&e.onLoadCallback(r)},r.tileLoader.get(r.abortController,e.url,r.uuid,r)),t}return t=a,(r=[{key:"setup",value:function(e){if(this.isSetup=!0,e.json.root?(this.json=e.json.root,this.jsonChildren=this.json.children,this.json.refinement||(this.json.refinement=e.json.refinement),this.json.geometricError||(this.json.geometricError=e.json.geometricError),this.json.transform||(this.json.transform=e.json.transform),this.json.boundingVolume||(this.json.boundingVolume=e.json.boundingVolume)):this.json=e.json,this.rootPath=e.json.rootPath?e.json.rootPath:e.rootPath,this.json.refinement?this.refinement=this.json.refinement:this.refinement=e.parentRefinement,this.json.geometricError?this.geometricError=this.json.geometricError:this.geometricError=e.parentGeometricError,this.json.transform&&!this.centerModel){var t=new n.Matrix4;t.elements=this.json.transform,this.master.applyMatrix4(t)}if(this.json.boundingVolume)if(this.json.boundingVolume.box)this.boundingVolume=new u(this.json.boundingVolume.box);else if(this.json.boundingVolume.region){var r=this.json.boundingVolume.region;this.transformWGS84ToCartesian(r[0],r[1],r[4],ie),this.transformWGS84ToCartesian(r[2],r[3],r[5],ae),ie.lerp(ae,.5),this.boundingVolume=new n.Sphere(new n.Vector3(ie.x,ie.y,ie.z),ie.distanceTo(ae))}else if(this.json.boundingVolume.sphere){var o=this.json.boundingVolume.sphere;this.boundingVolume=new n.Sphere(new n.Vector3(o[0],o[2],-o[1]),o[3])}else this.boundingVolume=e.parentBoundingVolume;else this.boundingVolume=e.parentBoundingVolume;this.json.content&&(this.json.content.uri&&this.json.content.uri.includes("json")||this.json.content.url&&this.json.content.url.includes("json")?this.hasUnloadedJSONContent=!0:this.hasMeshContent=!0,this.load())}},{key:"isAbsolutePathOrURL",value:function(e){var t=/^(?:http|https|ftp|tcp|udp):\/\/\S+/.test(e),n=e.startsWith("/")&&!e.startsWith("//");return t||n}},{key:"load",value:function(){var e,t=this;t.deleted||(t.json.content&&(t.json.content.uri?e=F.isAbsolute(t.json.content.uri)||t.isAbsolutePathOrURL(t.json.content.uri)?t.json.content.uri:t.rootPath+F.sep+t.json.content.uri:t.json.content.url&&(e=F.isAbsolute(t.json.content.url)||t.isAbsolutePathOrURL(t.json.content.url)?t.json.content.url:t.rootPath+F.sep+t.json.content.url),e&&(e.includes(".b3dm")||e.includes(".glb")||e.includes(".gltf")?(t.contentURL=e,t.tileLoader.get(t.abortController,e,t.uuid,t,t.cameraOnLoad?function(){return t.calculateDistanceToCamera(t.cameraOnLoad)}:function(){return 0},(function(){return t.getSiblings()}),t.level,!!t.json.boundingVolume.region,t.geometricError)):e.includes(".json")&&t.tileLoader.get(t.abortController,e,t.uuid,t))),t.matrixWorldNeedsUpdate=!0,t.updateWorldMatrix(!0,!0))}},{key:"loadMesh",value:function(e){this.deleted||(this.meshContent=e)}},{key:"loadJson",value:function(e,t){this.deleted||(this.json.children&&(this.jsonChildren=this.json.children),e.rootPath=F.dirname(t),this.jsonChildren.push(e),this.hasUnloadedJSONContent=!1)}},{key:"dispose",value:function(){var e=this;e.childrenTiles.forEach((function(e){return e.dispose()})),e.deleted=!0,e.abortController&&e.abortController.abort(),this.parent=null,this.parentTile=null,this.dispatchEvent({type:"removed"})}},{key:"disposeChildren",value:function(){this.childrenTiles.forEach((function(e){return e.dispose()})),this.childrenTiles=[]}},{key:"_update",value:function(e,t){var n,r=this;function o(e){if(r.hasMeshContent&&r.meshContent){if(e<0)return r.inFrustum=!1,void r.changeContentVisibility(!!r.loadOutsideView);if(r.inFrustum=!0,0!=r.childrenTiles.length){if(e>=r.master.geometricErrorMultiplier*r.geometricError)r.changeContentVisibility(!0);else if(e<r.master.geometricErrorMultiplier*r.geometricError){var t=!0;r.childrenTiles.every((function(e){return!!e.isReady()||(t=!1,!1)})),t&&r.changeContentVisibility(!1)}}else r.changeContentVisibility(!0)}}r.materialVisibility,r.boundingVolume&&r.geometricError&&(r.metric=r.calculateUpdateMetric(e,t)),r.childrenTiles.forEach((function(n){return n._update(e,t)})),o(r.metric),(n=r.metric)<0&&r.hasMeshContent||(!r.hasMeshContent&&r.rootPath||n<r.master.geometricErrorMultiplier*r.geometricError&&r.meshContent)&&r.json&&r.jsonChildren&&r.childrenTiles.length!=r.jsonChildren.length&&r.jsonChildren.forEach((function(t){var n=new a({parentTile:r,parentGeometricError:r.geometricError,parentBoundingVolume:r.boundingVolume,parentRefinement:r.refinement,json:t,rootPath:r.rootPath,loadOutsideView:r.loadOutsideView,level:r.level+1,tileLoader:r.tileLoader,cameraOnLoad:e,master:r.master,centerModel:!1});r.childrenTiles.push(n)})),function(e,t){if(r.hasMeshContent)r.inFrustum?e>=r.master.geometricErrorMultiplier*r.geometricError&&(r.disposeChildren(),o(e)):(r.disposeChildren(),o(e))}(r.metric)}},{key:"areAllChildrenLoadedAndHidden",value:function(){var e=!0;return this.childrenTiles.every((function(t){if(t.hasMeshContent){if(t.childrenTiles.length>0)return e=!1,!1;if(!t.inFrustum)return!0;if(!t.materialVisibility||t.meshesToDisplay!=t.meshesDisplayed)return e=!1,!1}else if(!t.areAllChildrenLoadedAndHidden())return e=!1,!1;return!0})),e}},{key:"isReady",value:function(){if(!this.inFrustum)return!0;if(this.hasUnloadedJSONContent)return!1;if((!this.hasMeshContent||!this.meshContent||!this.materialVisibility)&&this.childrenTiles.length>0){var e=!0;return this.childrenTiles.every((function(t){return!!t.isReady()||(e=!1,!1)})),e}return!this.hasMeshContent||!!this.meshContent&&!!this.materialVisibility&&!!this.meshContent.displayedOnce}},{key:"changeContentVisibility",value:function(e){this.materialVisibility=e}},{key:"calculateUpdateMetric",value:function(e,t){if(this.boundingVolume instanceof u){if(oe.copy(this.boundingVolume.sphere),oe.applyMatrix4(this.master.matrixWorld),!t.intersectsSphere(oe))return-1}else{if(!(this.boundingVolume instanceof n.Sphere))return console.error("unsupported shape"),-1;if(oe.copy(this.boundingVolume),oe.applyMatrix4(this.master.matrixWorld),!t.intersectsSphere(oe))return-1}if(this.boundingVolume instanceof u||this.boundingVolume instanceof n.Sphere){var r=Math.max(0,e.position.distanceTo(oe.center)-oe.radius);if(0==r)return 0;var o=this.master.matrixWorld.getMaxScaleOnAxis();this.master.renderer.getDrawingBufferSize(le);var i=le.y,a=e.fov;e.aspect<1&&(a*=e.aspect,i=le.x);var s=2*Math.tan(.5*a*.017453292519943295)*r;return 16*window.devicePixelRatio*s/(i*o)}if(this.boundingVolume instanceof n.Box3)return-1}},{key:"getSiblings",value:function(){var e=this,t=[];if(!e.parentTile)return t;for(var n=e.parentTile;!n.hasMeshContent&&n.parentTile;)n=n.parentTile;return n.childrenTiles.forEach((function(n){if(n&&n!=e){for(;!n.hasMeshContent&&n.childrenTiles[0];)n=n.childrenTiles[0];t.push(n)}})),t}},{key:"calculateDistanceToCamera",value:function(e){return this.boundingVolume instanceof u?(oe.copy(this.boundingVolume.sphere),oe.applyMatrix4(this.master.matrixWorld)):this.boundingVolume instanceof n.Sphere?(oe.copy(this.boundingVolume),oe.applyMatrix4(this.master.matrixWorld)):console.error("unsupported shape"),Math.max(0,e.position.distanceTo(oe.center)-oe.radius)}},{key:"getWorldMatrix",value:function(){return this.master.matrixWorld}},{key:"transformWGS84ToCartesian",value:function(e,t,n,r){var o=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(t),2)),i=Math.cos(t),a=Math.cos(e),s=Math.sin(t),l=o+n,u=l*i*a,c=l*i*Math.sin(e),h=(.993305615557957*o+n)*s;r.set(u,c,h)}}])&&$(t.prototype,r),o&&$(t,o),Object.defineProperty(t,"prototype",{writable:!1}),a}(n.Object3D);function de(e){return de="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},de(e)}function fe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==de(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==de(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===de(i)?i:String(i)),r)}var o,i}function pe(e,t){return pe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},pe(e,t)}function me(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=be(e);if(t){var o=be(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"===de(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return ye(e)}(this,n)}}function ye(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function be(e){return be=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},be(e)}var ge=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&pe(e,t)}(a,e);var t,r,o,i=me(a);function a(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),t=i.call(this),e.master=ye(t),t.renderer=e.renderer,t.geometricErrorMultiplier=e.geometricErrorMultiplier?e.geometricErrorMultiplier:1,t.tileset=new he(e),e.static&&(t.matrixAutoUpdate=!1),t}return t=a,(r=[{key:"update",value:function(e,t){if(t)this.tileset._update(e,t);else{var r=new n.Frustum;r.setFromProjectionMatrix((new n.Matrix4).multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse)),this.tileset._update(e,r)}}},{key:"updateWithFrustum",value:function(e,t){this.tileset._update(e,t)}},{key:"setGeometricErrorMultiplier",value:function(e){this.geometricErrorMultiplier=e||1}}])&&fe(t.prototype,r),o&&fe(t,o),Object.defineProperty(t,"prototype",{writable:!1}),a}(n.Object3D);function ve(e){return ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ve(e)}function we(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==ve(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==ve(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===ve(i)?i:String(i)),r)}var o,i}var je=new n.Matrix4,Ce=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var r=this;r.scene=t,r.instancedTiles=[],r.instancedMesh,r.reuseableMatrix=new n.Matrix4}var t,r,o;return t=e,(r=[{key:"addInstance",value:function(e){var t=this;e.added=!0,e.listOMesh=t.instancedTiles,t.instancedTiles.push(e),t.instancedMesh&&e.loadMesh(t.instancedMesh)}},{key:"addToScene",value:function(){var e=this;e.instancedMesh.setMatrixAt(0,new n.Matrix4),e.instancedMesh.instanceMatrix.needsUpdate=!0,e.instancedMesh.count=1,e.scene.add(e.instancedMesh),e.instancedMesh.onAfterRender=function(){delete e.instancedMesh.onAfterRender,e.instancedMesh.displayedOnce=!0}}},{key:"setObject",value:function(e){var t=this;t.instancedMesh=e;for(var n=0;n<t.instancedTiles.length;n++)t.instancedTiles[n].loadMesh(t.instancedMesh)}},{key:"update",value:function(){for(var e=this,t=e.instancedTiles.length-1;t>=0;t--)e.instancedTiles[t].deleted&&e.instancedTiles.splice(t,1);if(e.instancedMesh){e.instancedMesh.count=0;for(var n=0;n<e.instancedTiles.length;n++)e.instancedTiles[n].meshContent=e.instancedMesh,e.instancedTiles[n].materialVisibility&&e.instancedTiles[n].meshContent&&(e.instancedMesh.count++,e.reuseableMatrix.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.reuseableMatrix.multiply(e.instancedTiles[n].master.matrixWorld),e.reuseableMatrix.multiply(e.instancedMesh.baseMatrix),e.instancedMesh.setMatrixAt(e.instancedMesh.count-1,e.reuseableMatrix),e.instancedMesh.getMatrixAt(0,je),console.log());e.instancedMesh.instanceMatrix.needsUpdate=!0}}},{key:"getCount",value:function(){return this.instancedTiles.length}}])&&we(t.prototype,r),o&&we(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Me(e){return Me="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Me(e)}function xe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==Me(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==Me(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===Me(i)?i:String(i)),r)}var o,i}var Te=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var t=this;t.count=0,t.json,t.instancedTiles=[]}var t,n,r;return t=e,(n=[{key:"addInstance",value:function(e){this.instancedTiles.push(e),this.json&&e.loadJson(this.json,this.url)}},{key:"setObject",value:function(e,t){var n=this;n.json=e,n.url=t;for(var r=0;r<n.instancedTiles.length;r++)n.instancedTiles[r].loadJson(n.json,n.url)}},{key:"getCount",value:function(){return this.instancedTiles.length}},{key:"update",value:function(){for(var e=this,t=e.instancedTiles.length-1;t>=0;t--)e.instancedTiles[t].deleted&&e.instancedTiles.splice(t,1)}}])&&xe(t.prototype,n),r&&xe(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Se(e){return Se="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Se(e)}function ke(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==Se(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==Se(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===Se(i)?i:String(i)),r)}var o,i}var Oe=0,Ee=new n.Matrix4;Ee.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);var Ve=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.maxCachedItems=100,this.maxInstances=1,n&&(this.meshCallback=n.meshCallback,this.pointsCallback=n.pointsCallback,n.maxCachedItems&&(this.maxCachedItems=n.maxCachedItems),n.maxInstances&&(this.maxInstances=n.maxInstances)),this.gltfLoader=new V.GLTFLoader;var r=new d.DRACOLoader;if(r.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(r),n&&n.renderer){var o=new f.KTX2Loader;o.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(n.renderer),this.gltfLoader.setKTX2Loader(o),this.b3dmDecoder=new O(n.renderer)}else this.b3dmDecoder=new O(null);this.cache=new c.LinkedHashMap,this.scene=t,this.ready=[],this.downloads=[],this.nextReady=[],this.nextDownloads=[],this.init()}var t,r,o;return t=e,(r=[{key:"update",value:function(){this.cache._data.forEach((function(e){e.update()}))}},{key:"init",value:function(){var e=this;(0,E.setIntervalAsync)((function(){e.download()}),10),(0,E.setIntervalAsync)((function(){var t=Date.now(),n=0;do{n=e.loadBatch()}while(n>0&&Date.now()-t<=0)}),10)}},{key:"download",value:function(){var e=this,t=this;if(0!=t.nextDownloads.length||(t.getNextDownloads(),0!=t.nextDownloads.length))for(var r=function(){var r=t.nextDownloads.shift();r&&r.shouldDoDownload()&&(Oe++,r.path.includes(".b3dm")&&fetch(r.path,{signal:r.abortController.signal}).then((function(e){if(Oe--,!e.ok)throw console.error("could not load tile with path : "+path),new Error("couldn't load \"".concat(path,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.arrayBuffer()})).then((function(n){return e.b3dmDecoder.parseB3DMInstanced(n,t.meshCallback,t.maxInstances,r.zUpToYUp)})).then((function(e){r.tile.setObject(e),t.ready.unshift(r)})).catch((function(e){return console.error(e)})),r.path.includes(".glb")||r.path.includes(".gltf")?e.gltfLoader.load(r.path,(function(e){var o;e.scene.traverse((function(e){e.geometricError=r.geometricError,e.isMesh&&(r.zUpToYUp&&e.applyMatrix4(Ee),t.meshCallback&&t.meshCallback(e)),e.isPoints&&console.error("instanced point cloud is not supported")})),e.scene.updateWorldMatrix(!1,!0),e.scene.traverse((function(e){e.isMesh&&((o=new n.InstancedMesh(e.geometry,e.material,t.maxInstances)).baseMatrix=e.matrixWorld)})),t.ready.unshift(r),o?r.tile.setObject(o):e.scene.traverse((function(e){e.dispose&&e.dispose(),e.material&&e.material.dispose()}))})):r.path.includes(".json")&&(Oe++,fetch(r.path,{signal:r.abortController.signal}).then((function(e){if(Oe--,!e.ok)throw console.error("could not load tile with path : "+path),new Error("couldn't load \"".concat(path,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.json()})).then((function(e){r.tile.setObject(e,r.path),t.ready.unshift(r)})).catch((function(e){return console.error(e)}))))};t.nextDownloads.length>0&&Oe<500;)r()}},{key:"loadBatch",value:function(){if(0==this.nextReady.length&&(this.getNextReady(),0==this.nextReady.length))return 0;var e=this.nextReady.shift();return e?(e.tile.addToScene&&e.tile.addToScene(),1):0}},{key:"getNextReady",value:function(){for(var e=Number.MAX_VALUE,t=-1,n=this.ready.length-1;n>=0;n--)this.ready[n].distanceFunction||this.nextReady.push(this.ready.splice(n,1)[0]);if(!(this.nextReady.length>0)){for(var r=this.ready.length-1;r>=0;r--){var o=this.ready[r].distanceFunction()*this.ready[r].level;o<e&&(e=o,t=r)}if(t>=0){var i=this.ready.splice(t,1).pop();this.nextReady.push(i);for(var a=i.getSiblings(),s=this.ready.length-1;s>=0;s--)a.includes(this.ready[s].uuid)&&this.nextready.push(this.ready.splice(s,1).pop())}}}},{key:"get",value:function(e,t,n,r,o,i,a,s,l){var u=this,c=function(e){for(var t=e.split("/"),n=[],r=0,o=0;o<t.length;o++){var i=t[o];"."!==i&&""!==i&&".."!==i?n[r++]=i:".."===i&&r>0&&r--}if(0===r)return"/";var a="";for(o=0;o<r;o++)a+="/"+n[o];return a}(t);if(t.includes(".b3dm")||t.includes(".json")||t.includes(".glb")||t.includes(".gltf")){var h=u.cache.get(c);if(h)h.addInstance(r);else if(t.includes(".b3dm")||t.includes(".glb")||t.includes(".gltf")){var d=new Ce(u.scene);d.addInstance(r),u.cache.put(c,d);var f=new AbortController;e.signal.addEventListener("abort",(function(){0==d.getCount()&&f.abort()})),this.downloads.push({abortController:f,tile:d,key:c,path:t,distanceFunction:o,getSiblings:i,level:a,uuid:n,zUpToYUp:s,geometricError:l,shouldDoDownload:function(){return!0}})}else if(t.includes(".json")){var p=new Te;p.addInstance(r),u.cache.put(c,p);var m=new AbortController;e.signal.addEventListener("abort",(function(){0==p.getCount()&&m.abort()})),this.downloads.push({abortController:m,tile:p,key:c,path:t,distanceFunction:o,getSiblings:i,level:a,shouldDoDownload:function(){return!0}})}}else console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data")}},{key:"getNextDownloads",value:function(){for(var e=Number.MAX_VALUE,t=-1,n=this.downloads.length-1;n>=0;n--){var r=this.downloads[n];r.shouldDoDownload()?r.distanceFunction||this.nextDownloads.push(this.downloads.splice(n,1)[0]):this.downloads.splice(n,1)}if(!(this.nextDownloads.length>0)){for(var o=this.downloads.length-1;o>=0;o--){var i=this.downloads[o],a=i.distanceFunction()*i.level;a<e&&(e=a,t=o)}if(t>=0){var s=this.downloads.splice(t,1).pop();this.nextDownloads.push(s);for(var l=s.getSiblings(),u=this.downloads.length-1;u>=0;u--)l.includes(this.downloads[u].uuid)&&this.nextDownloads.push(this.downloads.splice(u,1).pop())}}}},{key:"checkSize",value:function(){for(var e=this,t=0;e.cache.size()>e.maxCachedItems&&t<e.cache.size();){t++;var n=e.cache.head();n.value.getCount()>0?(e.cache.remove(n.key),e.cache.put(n.key,n.value)):(e.cache.remove(n.key),n.value.instancedMesh&&n.value.instancedMesh.traverse((function(e){if(e.material)if(e.material.length)for(var t=0;t<e.material.length;++t)e.material[t].dispose();else e.material.dispose();e.geometry&&e.geometry.dispose()})))}}}])&&ke(t.prototype,r),o&&ke(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();return t})()));
1
+ /*! For license information please see threedtiles.min.js.LICENSE.txt */
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.threedtiles=t():e.threedtiles=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{InstancedOGC3DTile:()=>we,InstancedTileLoader:()=>Re,OGC3DTile:()=>$,OcclusionCullingService:()=>a,TileLoader:()=>A});const n=require("three"),r=require("three/src/math/MathUtils");function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(i=r.key,a=void 0,a=function(e,t){if("object"!==o(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(i,"string"),"symbol"===o(a)?a:String(a)),r)}var i,a}var a=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.cullMap=[],this.cullMaterial=new n.MeshBasicMaterial({vertexColors:!0}),this.cullMaterial.side=n.FrontSide,this.cullTarget=this.createCullTarget(),this.cullPixels=new Uint8Array(4*this.cullTarget.width*this.cullTarget.height)}var t,o,a;return t=e,(o=[{key:"setSide",value:function(e){this.cullMaterial.side=e}},{key:"createCullTarget",value:function(){var e=new n.WebGLRenderTarget(Math.floor(.05*window.innerWidth),Math.floor(.05*window.innerHeight));return e.texture.format=n.RGBAFormat,e.texture.encoding=n.LinearEncoding,e.texture.minFilter=n.NearestFilter,e.texture.magFilter=n.NearestFilter,e.texture.generateMipmaps=!1,e.stencilBuffer=!1,e.depthBuffer=!0,e.depthTexture=new n.DepthTexture,e.depthTexture.format=n.DepthFormat,e.depthTexture.type=n.UnsignedShortType,e}},{key:"update",value:function(e,t,n){var o=t.getRenderTarget(),i=e.overrideMaterial;e.overrideMaterial=this.cullMaterial,t.setRenderTarget(this.cullTarget),t.render(e,n),e.overrideMaterial=i,t.setRenderTarget(o),t.readRenderTargetPixels(this.cullTarget,0,0,this.cullTarget.width,this.cullTarget.height,this.cullPixels),this.cullMap=[];for(var a=0;a<this.cullPixels.length;a+=4){var s=(0,r.clamp)(this.cullPixels[a],0,255)<<16^(0,r.clamp)(this.cullPixels[a+1],0,255)<<8^(0,r.clamp)(this.cullPixels[a+2],0,255)<<0;this.cullMap[s]=!0}}},{key:"hasID",value:function(e){return this.cullMap[e]}}])&&i(t.prototype,o),a&&i(t,a),Object.defineProperty(t,"prototype",{writable:!1}),e}();function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function l(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==s(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==s(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===s(i)?i:String(i)),r)}var o,i}var c=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.center=new n.Vector3(t[0],t[1],t[2]);var r=new n.Vector3(t[3],t[4],t[4]),o=new n.Vector3(t[6],t[7],t[8]),i=new n.Vector3(t[9],t[10],t[11]);this.halfWidth=r.length(),this.halfHeight=o.length(),this.halfDepth=i.length(),r.normalize(),o.normalize(),i.normalize(),this.sphere=new n.Sphere(this.center,Math.sqrt(this.halfWidth*this.halfWidth+this.halfHeight*this.halfHeight+this.halfDepth*this.halfDepth)),this.matrixToOBBCoordinateSystem=new n.Matrix3,this.matrixToOBBCoordinateSystem.set(r.x,r.y,r.z,o.x,o.y,o.z,i.x,i.y,i.z)}var t,r,o;return t=e,(r=[{key:"inFrustum",value:function(e){return e.intersectsSphere(this.sphere)}},{key:"distanceToPoint",value:function(e){var t=e.clone();t.sub(this.center),t.applyMatrix3(this.matrixToOBBCoordinateSystem);var n=Math.max(0,Math.max(-this.halfWidth-t.x,t.x-this.halfWidth)),r=Math.max(0,Math.max(-this.halfHeight-t.y,t.y-this.halfHeight)),o=Math.max(0,Math.max(-this.halfDepth-t.z,t.z-this.halfDepth));return Math.sqrt(n*n+r*r+o*o)}}])&&l(t.prototype,r),o&&l(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();const u=require("js-utils-z"),h=require("three/examples/jsm/loaders/GLTFLoader.js"),f=require("three/examples/jsm/loaders/DRACOLoader.js"),d=require("three/examples/jsm/loaders/KTX2Loader");function p(e){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},p(e)}function m(){return m="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=g(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(arguments.length<3?e:n):o.value}},m.apply(this,arguments)}function y(e,t){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},y(e,t)}function v(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=g(e);if(t){var o=g(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"===p(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,n)}}function g(e){return g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},g(e)}function b(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function w(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==p(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==p(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===p(i)?i:String(i)),r)}var o,i}function j(e,t,n){return t&&w(e.prototype,t),n&&w(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}var x=new TextDecoder,C=function(){function e(t,n,r,o){b(this,e),this.buffer=t,this.binOffset=n+r,this.binLength=o;var i=null;if(0!==r)try{var a=new Uint8Array(t,n,r);i=JSON.parse(x.decode(a))}catch(e){i={}}else i={};this.header=i}return j(e,[{key:"getKeys",value:function(){return Object.keys(this.header)}},{key:"getData",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=this.header;if(!(e in o))return null;var i=o[e];if(i instanceof Object){if(Array.isArray(i))return i;var a,s,l=this.buffer,c=this.binOffset,u=this.binLength,h=i.byteOffset||0,f=i.type||r,d=i.componentType||n;if("type"in i&&r&&i.type!==r)throw new Error("FeatureTable: Specified type does not match expected type.");switch(f){case"SCALAR":a=1;break;case"VEC2":a=2;break;case"VEC3":a=3;break;case"VEC4":a=4;break;default:throw new Error('FeatureTable : Feature type not provided for "'.concat(e,'".'))}var p=c+h,m=t*a;switch(d){case"BYTE":s=new Int8Array(l,p,m);break;case"UNSIGNED_BYTE":s=new Uint8Array(l,p,m);break;case"SHORT":s=new Int16Array(l,p,m);break;case"UNSIGNED_SHORT":s=new Uint16Array(l,p,m);break;case"INT":s=new Int32Array(l,p,m);break;case"UNSIGNED_INT":s=new Uint32Array(l,p,m);break;case"FLOAT":s=new Float32Array(l,p,m);break;case"DOUBLE":s=new Float64Array(l,p,m);break;default:throw new Error('FeatureTable : Feature component type not provided for "'.concat(e,'".'))}if(p+m*s.BYTES_PER_ELEMENT>c+u)throw new Error("FeatureTable: Feature data read outside binary body length.");return s}return i}}]),e}(),M=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&y(e,t)}(n,e);var t=v(n);function n(e,r,o,i,a){var s;return b(this,n),(s=t.call(this,e,o,i,a)).batchSize=r,s}return j(n,[{key:"getData",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return m(g(n.prototype),"getData",this).call(this,e,this.batchSize,t,r)}}]),n}(C);function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function S(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==T(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==T(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===T(i)?i:String(i)),r)}var o,i}var E=new n.Matrix4;E.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);var O=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.gltfLoader=new h.GLTFLoader;var r=new f.DRACOLoader;if(r.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(r),t){var o=new d.KTX2Loader;o.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(t),this.gltfLoader.setKTX2Loader(o)}this.tempMatrix=new n.Matrix4}var t,r,o;return t=e,(r=[{key:"parseB3DM",value:function(e,t,n,r){var o=this,i=new DataView(e),a=String.fromCharCode(i.getUint8(0))+String.fromCharCode(i.getUint8(1))+String.fromCharCode(i.getUint8(2))+String.fromCharCode(i.getUint8(3));console.assert("b3dm"===a);var s=i.getUint32(8,!0);console.assert(s===e.byteLength);var l=i.getUint32(12,!0),c=i.getUint32(16,!0),u=i.getUint32(20,!0),h=i.getUint32(24,!0),f=new C(e,28,l,c),d=28+l+c,p=(new M(e,f.getData("BATCH_LENGTH"),d,u,h),d+u+h),m=new Uint8Array(e,p,s-p).slice().buffer;return new Promise((function(e,i){o.gltfLoader.parse(m,null,(function(i){var a=f.getData("RTC_CENTER");a?(o.tempMatrix.makeTranslation(a[0],a[1],a[2]),i.scene.applyMatrix4(o.tempMatrix)):i.userData.gltfExtensions&&i.userData.gltfExtensions.CESIUM_RTC&&(o.tempMatrix.makeTranslation(i.userData.gltfExtensions.CESIUM_RTC.center[0],i.userData.gltfExtensions.CESIUM_RTC.center[1],i.userData.gltfExtensions.CESIUM_RTC.center[2]),i.scene.applyMatrix4(o.tempMatrix)),r||i.scene.applyMatrix4(E),i.scene.traverse((function(e){e.isMesh&&(e.geometricError=n,r&&e.applyMatrix4(E),t&&t(e))})),e(i.scene)}),(function(e){console.error(e)}))}))}},{key:"parseB3DMInstanced",value:function(e,t,r,o){return this.parseB3DM(e,t,o).then((function(e){var t;return e.updateWorldMatrix(!1,!0),e.traverse((function(e){e.isMesh&&((t=new n.InstancedMesh(e.geometry,e.material,r)).baseMatrix=e.matrixWorld)})),t}))}}])&&S(t.prototype,r),o&&S(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();const k=require("three/examples/jsm/loaders/GLTFLoader");function L(){L=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function l(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,n){return e[t]=n}}function c(e,t,n,o){var i=t&&t.prototype instanceof f?t:f,a=Object.create(i.prototype),s=new T(o||[]);return r(a,"_invoke",{value:j(e,n,s)}),a}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var h={};function f(){}function d(){}function p(){}var m={};l(m,i,(function(){return this}));var y=Object.getPrototypeOf,v=y&&y(y(S([])));v&&v!==t&&n.call(v,i)&&(m=v);var g=p.prototype=f.prototype=Object.create(m);function b(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function o(r,i,a,s){var l=u(e[r],e,i);if("throw"!==l.type){var c=l.arg,h=c.value;return h&&"object"==V(h)&&n.call(h,"__await")?t.resolve(h.__await).then((function(e){o("next",e,a,s)}),(function(e){o("throw",e,a,s)})):t.resolve(h).then((function(e){c.value=e,a(c)}),(function(e){return o("throw",e,a,s)}))}s(l.arg)}var i;r(this,"_invoke",{value:function(e,n){function r(){return new t((function(t,r){o(e,n,t,r)}))}return i=i?i.then(r,r):r()}})}function j(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return E()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var s=x(a,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var l=u(e,t,n);if("normal"===l.type){if(r=n.done?"completed":"suspendedYield",l.arg===h)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(r="completed",n.method="throw",n.arg=l.arg)}}}function x(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),h;var o=u(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,h;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function C(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function M(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(C,this),this.reset(!0)}function S(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:E}}function E(){return{value:void 0,done:!0}}return d.prototype=p,r(g,"constructor",{value:p,configurable:!0}),r(p,"constructor",{value:d,configurable:!0}),d.displayName=l(p,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,l(e,s,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},b(w.prototype),l(w.prototype,a,(function(){return this})),e.AsyncIterator=w,e.async=function(t,n,r,o,i){void 0===i&&(i=Promise);var a=new w(c(t,n,r,o),i);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},b(g),l(g,s,"Generator"),l(g,i,(function(){return this})),l(g,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},e.values=S,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(M),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),l=n.call(i,"finallyLoc");if(s&&l){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),h},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),M(n),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;M(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:S(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),h}},e}function P(e,t,n,r,o,i,a){try{var s=e[i](a),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,o)}function V(e){return V="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},V(e)}function D(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==V(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==V(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===V(i)?i:String(i)),r)}var o,i}var R=0,_=new n.Matrix4;_.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);var A=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.maxCachedItems=100,t&&(this.meshCallback=t.meshCallback,this.pointsCallback=t.pointsCallback,t.maxCachedItems&&(this.maxCachedItems=t.maxCachedItems)),this.gltfLoader=new k.GLTFLoader;var n=new f.DRACOLoader;if(n.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(n),t&&t.renderer){var r=new d.KTX2Loader;r.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(t.renderer),this.gltfLoader.setKTX2Loader(r),this.b3dmDecoder=new O(t.renderer)}else this.b3dmDecoder=new O(null);this.cache=new u.LinkedHashMap,this.register={},this.ready=[],this.downloads=[],this.nextReady=[],this.nextDownloads=[],this.init()}var t,n,r;return t=e,(n=[{key:"init",value:function(){var e=this;U((function(){e.download()}),10),U((function(){var t=Date.now(),n=0;do{n=e.loadBatch()}while(n>0&&Date.now()-t<=0)}),10)}},{key:"scheduleDownload",value:function(e){this.downloads.unshift(e)}},{key:"download",value:function(){if(0!=this.nextDownloads.length||(this.getNextDownloads(),0!=this.nextDownloads.length))for(;this.nextDownloads.length>0&&R<500;){var e=this.nextDownloads.shift();e&&e.shouldDoDownload()&&e.doDownload()}}},{key:"meshReceived",value:function(e,t,n,r,o,i,a){this.ready.unshift([e,t,n,r,o,i,a])}},{key:"loadBatch",value:function(){if(0==this.nextReady.length&&(this.getNextReady(),0==this.nextReady.length))return 0;var e=this.nextReady.shift();if(!e)return 0;var t=e[0],n=e[1],r=e[2],o=t.get(r);return o&&n[r]&&Object.keys(n[r]).forEach((function(e){var t=n[r][e];t&&(t(o),n[r][e]=null)})),1}},{key:"getNextDownloads",value:function(){for(var e=Number.MAX_VALUE,t=-1,n=this.downloads.length-1;n>=0;n--)this.downloads[n].shouldDoDownload()?this.downloads[n].distanceFunction||this.nextDownloads.push(this.downloads.splice(n,1)[0]):this.downloads.splice(n,1);if(!(this.nextDownloads.length>0)){for(var r=this.downloads.length-1;r>=0;r--){var o=this.downloads[r].distanceFunction()*this.downloads[r].level;o<e&&(e=o,t=r)}if(t>=0){var i=this.downloads.splice(t,1).pop();this.nextDownloads.push(i);for(var a=i.getSiblings(),s=this.downloads.length-1;s>=0;s--)a.includes(this.downloads[s].uuid)&&this.nextDownloads.push(this.downloads.splice(s,1).pop())}}}},{key:"getNextReady",value:function(){for(var e=Number.MAX_VALUE,t=-1,n=this.ready.length-1;n>=0;n--)this.ready[n][3]||this.nextReady.push(this.ready.splice(n,1)[0]);if(!(this.nextReady.length>0)){for(var r=this.ready.length-1;r>=0;r--){var o=this.ready[r][3]()*this.ready[r][5];o<e&&(e=o,t=r)}if(t>=0){var i=this.ready.splice(t,1).pop();this.nextReady.push(i);for(var a=i[4](),s=this.ready.length-1;s>=0;s--)a.includes(this.ready[s][6])&&this.nextready.push(this.ready.splice(s,1).pop())}}}},{key:"get",value:function(e,t,n,r,o,i,a,s,l){var c=this,u=this,h=F(n),f=new AbortController;if(e.signal.addEventListener("abort",(function(){u.register[h]&&0!=Object.keys(u.register[h]).length||f.abort()})),n.includes(".b3dm")||n.includes(".json")||n.includes(".gltf")||n.includes(".glb")){if(u.register[h]||(u.register[h]={}),u.register[h][t]&&console.error(" a tile should only be loaded once"),u.register[h][t]=r,u.cache.get(h))this.meshReceived(u.cache,u.register,h,o,i,a,t);else if(1==Object.keys(u.register[h]).length){var d;n.includes(".b3dm")?d=function(){R++,fetch(n,{signal:f.signal}).then((function(e){if(R--,!e.ok)throw console.error("could not load tile with path : "+n),new Error("couldn't load \"".concat(n,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.arrayBuffer()})).then((function(e){return c.b3dmDecoder.parseB3DM(e,u.meshCallback,l,s)})).then((function(e){u.cache.put(h,e),u.checkSize(),c.meshReceived(u.cache,u.register,h,o,i,a,t)})).catch((function(){}))}:n.includes(".glb")||n.includes(".gltf")?d=function(){R++,c.gltfLoader.load(n,(function(e){e.scene.traverse((function(e){e.geometricError=l,e.isMesh&&(s&&e.applyMatrix4(_),u.meshCallback&&u.meshCallback(e)),e.isPoints&&(s&&e.applyMatrix4(_),u.pointsCallback&&u.pointsCallback(e))})),u.cache.put(h,e.scene),u.checkSize(),u.meshReceived(u.cache,u.register,h,o,i,a,t)}))}:n.includes(".json")&&(d=function(){R++,fetch(n,{signal:f.signal}).then((function(e){if(R--,!e.ok)throw console.error("could not load tile with path : "+n),new Error("couldn't load \"".concat(n,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.json()})).then((function(e){u.cache.put(h,e),u.checkSize(),u.meshReceived(u.cache,u.register,h)})).catch((function(e){return console.error("tile download aborted")}))}),this.scheduleDownload({shouldDoDownload:function(){return!e.signal.aborted&&!!u.register[h]&&Object.keys(u.register[h]).length>0},doDownload:d,distanceFunction:o,getSiblings:i,level:a,uuid:t})}}else console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data")}},{key:"invalidate",value:function(e,t){var n=F(e);this.register[n]&&delete this.register[n][t]}},{key:"checkSize",value:function(){for(var e=this,t=0;e.cache.size()>e.maxCachedItems&&t<e.cache.size();){t++;var n=e.cache.head(),r=e.register[n.key];r&&(Object.keys(r).length>0?(e.cache.remove(n.key),e.cache.put(n.key,n.value)):(e.cache.remove(n.key),delete e.register[n.key],n.value.traverse((function(e){if(e.material)if(e.material.length)for(var t=0;t<e.material.length;++t)e.material[t].dispose();else e.material.dispose();e.geometry&&e.geometry.dispose()}))))}}}])&&D(t.prototype,n),r&&D(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function U(e,t){var n,r=function(){var o=function(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){P(i,r,o,a,s,"next",e)}function s(e){P(i,r,o,a,s,"throw",e)}a(void 0)}))}}(L().mark((function o(){var i,a,s;return L().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return i=Date.now(),o.prev=1,o.next=4,e();case 4:o.next=9;break;case 6:o.prev=6,o.t0=o.catch(1),console.error(o.t0);case 9:return o.prev=9,a=Date.now(),s=a-i,n=setTimeout(r,s>=t?0:t-s),o.finish(9);case 15:case"end":return o.stop()}}),o,null,[[1,6,9,15]])})));return function(){return o.apply(this,arguments)}}();return n=setTimeout(r,t),{clearInterval:function(){return clearTimeout(n)}}}function F(e){for(var t=e.split("/"),n=[],r=0,o=0;o<t.length;o++){var i=t[o];"."!==i&&""!==i&&".."!==i?n[r++]=i:".."===i&&r>0&&r--}if(0===r)return"/";var a="";for(o=0;o<r;o++)a+="/"+n[o];return a}const N=require("uuid"),I=require("path-browserify");function B(e){return B="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},B(e)}function G(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==B(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==B(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===B(i)?i:String(i)),r)}var o,i}function W(e,t){return W=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},W(e,t)}function z(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=H(e);if(t){var o=H(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"===B(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return q(e)}(this,n)}}function q(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function H(e){return H=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},H(e)}var J=new n.Sphere(new n.Vector3(0,0,0),1),X=new n.Vector3(0,0,0),Y=new n.Vector3(0,0,0),K=new n.Vector3(0,1,0),Q=new n.Vector2(1e3,1e3),Z=new n.Quaternion,$=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&W(e,t)}(s,e);var t,o,i,a=z(s);function s(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s);var o=q(t=a.call(this));if(t.uuid=(0,N.v4)(),e.tileLoader)t.tileLoader=e.tileLoader;else{var i={};i.meshCallback=e.meshCallback?e.meshCallback:function(e){e.material.wireframe=!1,e.material.side=n.DoubleSide},i.pointsCallback=e.pointsCallback?e.pointsCallback:function(e){e.material.size=.1,e.material.sizeAttenuation=!0},t.tileLoader=new A(i)}return t.geometricErrorMultiplier=e.geometricErrorMultiplier?e.geometricErrorMultiplier:1,t.renderer=e.renderer,t.meshCallback=e.meshCallback,t.loadOutsideView=e.loadOutsideView,t.cameraOnLoad=e.cameraOnLoad,t.parentTile=e.parentTile,t.occlusionCullingService=e.occlusionCullingService,t.static=e.static,t.occlusionCullingService&&(t.color=new n.Color,t.color.setHex(16777215*Math.random()),t.colorID=(0,r.clamp)(255*o.color.r,0,255)<<16^(0,r.clamp)(255*o.color.g,0,255)<<8^(0,r.clamp)(255*o.color.b,0,255)<<0),t.static&&(t.matrixAutoUpdate=!1),t.childrenTiles=[],t.meshContent,t.tileContent,t.refinement,t.rootPath,t.geometricError,t.boundingVolume,t.json,t.materialVisibility=!1,t.inFrustum=!0,t.level=e.level?e.level:0,t.hasMeshContent=!1,t.hasUnloadedJSONContent=!1,t.centerModel=e.centerModel,t.abortController=new AbortController,t.layers.disable(0),e.json?(o.setup(e),e.onLoadCallback&&e.onLoadCallback(o)):e.url&&fetch(e.url,{signal:o.abortController.signal}).then((function(r){if(!r.ok)throw new Error("couldn't load \"".concat(e.url,'". Request failed with status ').concat(r.status," : ").concat(r.statusText));r.json().then((function(r){if(o.setup({rootPath:I.dirname(e.url),json:r}),e.onLoadCallback&&e.onLoadCallback(o),o.centerModel){var i=new n.Sphere;o.boundingVolume instanceof c?i.copy(o.boundingVolume.sphere):o.boundingVolume instanceof n.Sphere&&i.copy(o.boundingVolume),t.json.boundingVolume.region&&(t.transformWGS84ToCartesian(.5*(t.json.boundingVolume.region[0]+t.json.boundingVolume.region[2]),.5*(t.json.boundingVolume.region[1]+t.json.boundingVolume.region[3]),.5*(t.json.boundingVolume.region[4]+t.json.boundingVolume.region[5]),X),Z.setFromUnitVectors(X.normalize(),K.normalize()),o.applyQuaternion(Z)),o.translateX(-i.center.x*o.scale.x),o.translateY(-i.center.y*o.scale.y),o.translateZ(-i.center.z*o.scale.z)}}))})),t}return t=s,(o=[{key:"setup",value:function(e){if(e.json.root?(this.json=e.json.root,this.json.refinement||(this.json.refinement=e.json.refinement),this.json.geometricError||(this.json.geometricError=e.json.geometricError),this.json.transform||(this.json.transform=e.json.transform),this.json.boundingVolume||(this.json.boundingVolume=e.json.boundingVolume)):this.json=e.json,this.rootPath=e.json.rootPath?e.json.rootPath:e.rootPath,this.json.refinement?this.refinement=this.json.refinement:this.refinement=e.parentRefinement,this.json.geometricError?this.geometricError=this.json.geometricError:this.geometricError=e.parentGeometricError,this.json.transform&&!this.centerModel){var t=new n.Matrix4;t.elements=this.json.transform,this.applyMatrix4(t)}if(this.json.boundingVolume)if(this.json.boundingVolume.box)this.boundingVolume=new c(this.json.boundingVolume.box);else if(this.json.boundingVolume.region){var r=this.json.boundingVolume.region;this.transformWGS84ToCartesian(r[0],r[1],r[4],X),this.transformWGS84ToCartesian(r[2],r[3],r[5],Y),X.lerp(Y,.5),this.boundingVolume=new n.Sphere(new n.Vector3(X.x,X.y,X.z),X.distanceTo(Y))}else if(this.json.boundingVolume.sphere){var o=this.json.boundingVolume.sphere;this.boundingVolume=new n.Sphere(new n.Vector3(o[0],o[1],o[2]),o[3])}else this.boundingVolume=e.parentBoundingVolume;else this.boundingVolume=e.parentBoundingVolume;this.json.content&&(this.json.content.uri&&this.json.content.uri.includes("json")||this.json.content.url&&this.json.content.url.includes("json")?this.hasUnloadedJSONContent=!0:this.hasMeshContent=!0,this.load())}},{key:"isAbsolutePathOrURL",value:function(e){var t=/^(?:http|https|ftp|tcp|udp):\/\/\S+/.test(e),n=e.startsWith("/")&&!e.startsWith("//");return t||n}},{key:"load",value:function(){var e,t=this;t.deleted||t.json.content&&(t.json.content.uri?e=I.isAbsolute(t.json.content.uri)||t.isAbsolutePathOrURL(t.json.content.uri)?t.json.content.uri:t.rootPath+I.sep+t.json.content.uri:t.json.content.url&&(e=I.isAbsolute(t.json.content.url)||t.isAbsolutePathOrURL(t.json.content.url)?t.json.content.url:t.rootPath+I.sep+t.json.content.url),e&&(e.includes(".b3dm")||e.includes(".glb")||e.includes(".gltf")?(t.contentURL=e,t.tileLoader.get(t.abortController,this.uuid,e,(function(e){t.deleted||(e.traverse((function(e){if(e.isMesh){if(e.layers.disable(0),t.occlusionCullingService){for(var r=e.geometry.attributes.position,o=[],i=0;i<r.count;i++)o.push(t.color.r,t.color.g,t.color.b);e.geometry.setAttribute("color",new n.Float32BufferAttribute(o,3))}t.static&&(e.matrixAutoUpdate=!1)}})),t.add(e),t.updateWorldMatrix(!1,!0),t.meshContent=e)}),t.cameraOnLoad?function(){return t.calculateDistanceToCamera(t.cameraOnLoad)}:function(){return 0},(function(){return t.getSiblings()}),t.level,!!t.json.boundingVolume.region,t.geometricError)):e.includes(".json")&&t.tileLoader.get(t.abortController,this.uuid,e,(function(n){t.deleted||(t.json.children||(t.json.children=[]),n.rootPath=I.dirname(e),t.json.children.push(n),delete t.json.content,t.hasUnloadedJSONContent=!1)}))))}},{key:"dispose",value:function(){var e=this;e.childrenTiles.forEach((function(e){return e.dispose()})),e.deleted=!0,this.traverse((function(t){t.contentURL&&e.tileLoader.invalidate(t.contentURL,t.uuid),t.abortController&&t.abortController.abort()})),this.parent=null,this.parentTile=null,this.dispatchEvent({type:"removed"})}},{key:"disposeChildren",value:function(){var e=this;e.childrenTiles.forEach((function(e){return e.dispose()})),e.childrenTiles=[],e.children=[],e.meshContent&&e.children.push(e.meshContent)}},{key:"update",value:function(e){var t=new n.Frustum;t.setFromProjectionMatrix((new n.Matrix4).multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse)),this._update(e,t)}},{key:"_update",value:function(e,t){var n,r=this,o=r.materialVisibility;function i(e){if(r.hasMeshContent&&r.meshContent){if(e<0)return r.inFrustum=!1,void r.changeContentVisibility(!!r.loadOutsideView);if(r.inFrustum=!0,0!=r.childrenTiles.length){if(e>=r.geometricErrorMultiplier*r.geometricError)r.changeContentVisibility(!0);else if(e<r.geometricErrorMultiplier*r.geometricError){var t=!0;r.childrenTiles.every((function(e){return!!e.isReady()||(t=!1,!1)})),t&&r.changeContentVisibility(!1)}}else r.changeContentVisibility(!0)}}r.boundingVolume&&r.geometricError&&(r.metric=r.calculateUpdateMetric(e,t)),r.childrenTiles.forEach((function(n){return n._update(e,t)})),i(r.metric),(n=r.metric)<0&&r.hasMeshContent||r.occlusionCullingService&&r.hasMeshContent&&!r.occlusionCullingService.hasID(r.colorID)||(!r.hasMeshContent||n<r.geometricErrorMultiplier*r.geometricError&&r.meshContent)&&r.json&&r.json.children&&r.childrenTiles.length!=r.json.children.length&&r.json.children.forEach((function(t){var n=new s({parentTile:r,parentGeometricError:r.geometricError,parentBoundingVolume:r.boundingVolume,parentRefinement:r.refinement,json:t,rootPath:r.rootPath,geometricErrorMultiplier:r.geometricErrorMultiplier,loadOutsideView:r.loadOutsideView,level:r.level+1,tileLoader:r.tileLoader,cameraOnLoad:e,occlusionCullingService:r.occlusionCullingService,renderer:r.renderer,static:r.static,centerModel:!1});r.childrenTiles.push(n),r.add(n)})),function(e,t){if(r.hasMeshContent)r.inFrustum?r.occlusionCullingService&&!t&&r.hasMeshContent&&r.meshContent&&r.meshDisplayed&&r.areAllChildrenLoadedAndHidden()?(r.disposeChildren(),i(e)):e>=r.geometricErrorMultiplier*r.geometricError&&(r.disposeChildren(),i()):(r.disposeChildren(),i(e))}(r.metric,o)}},{key:"areAllChildrenLoadedAndHidden",value:function(){var e=!0,t=this;return this.childrenTiles.every((function(n){if(n.hasMeshContent){if(n.childrenTiles.length>0)return e=!1,!1;if(!n.inFrustum)return!0;if(!n.materialVisibility||n.meshDisplayed)return e=!1,!1;if(t.occlusionCullingService.hasID(n.colorID))return e=!1,!1}else if(!n.areAllChildrenLoadedAndHidden())return e=!1,!1;return!0})),e}},{key:"isReady",value:function(){if(!this.inFrustum)return!0;if(this.hasUnloadedJSONContent)return!1;if((!this.hasMeshContent||!this.meshContent||!this.materialVisibility)&&this.childrenTiles.length>0){var e=!0;return this.childrenTiles.every((function(t){return!!t.isReady()||(e=!1,!1)})),e}return!this.hasMeshContent||!!this.meshContent&&!!this.materialVisibility&&!!this.meshDisplayed}},{key:"changeContentVisibility",value:function(e){var t=this;function n(e,n){e.material.visible=n,n&&(e.onAfterRender=function(){delete e.onAfterRender,t.meshDisplayed=!0})}t.hasMeshContent&&t.meshContent&&(e?t.meshContent.traverse((function(e){e.isMesh&&e.layers.enable(0)})):t.meshContent.traverse((function(e){e.isMesh&&e.layers.disable(0)}))),t.materialVisibility!=e&&(t.materialVisibility=e,t.meshDisplayed=!0,t.meshContent.traverse?t.meshContent.traverse((function(t){t.material&&n(t,e)})):t.meshContent.scenes&&t.meshContent.scenes.forEach((function(t){return t.traverse((function(t){t.material&&n(t,e)}))})))}},{key:"calculateUpdateMetric",value:function(e,t){if(this.boundingVolume instanceof c){if(J.copy(this.boundingVolume.sphere),J.applyMatrix4(this.matrixWorld),!t.intersectsSphere(J))return-1}else{if(!(this.boundingVolume instanceof n.Sphere))return console.error("unsupported shape"),-1;if(J.copy(this.boundingVolume),J.applyMatrix4(this.matrixWorld),!t.intersectsSphere(J))return-1}var r=Math.max(0,e.position.distanceTo(J.center)-J.radius);if(0==r)return 0;var o=this.matrixWorld.getMaxScaleOnAxis();this.renderer&&this.renderer.getDrawingBufferSize(Q);var i=Q.y,a=e.fov;e.aspect<1&&(a*=e.aspect,i=Q.x);var s=2*Math.tan(.5*a*.017453292519943295)*r;return 16*window.devicePixelRatio*s/(i*o)}},{key:"getSiblings",value:function(){var e=this,t=[];if(!e.parentTile)return t;for(var n=e.parentTile;!n.hasMeshContent&&n.parentTile;)n=n.parentTile;return n.childrenTiles.forEach((function(n){if(n&&n!=e){for(;!n.hasMeshContent&&n.childrenTiles[0];)n=n.childrenTiles[0];t.push(n)}})),t}},{key:"calculateDistanceToCamera",value:function(e){return this.boundingVolume instanceof c?(J.copy(this.boundingVolume.sphere),J.applyMatrix4(this.matrixWorld)):this.boundingVolume instanceof n.Sphere?(J.copy(this.boundingVolume),J.applyMatrix4(this.matrixWorld)):console.error("unsupported shape"),Math.max(0,e.position.distanceTo(J.center)-J.radius)}},{key:"setGeometricErrorMultiplier",value:function(e){this.geometricErrorMultiplier=e,this.childrenTiles.forEach((function(t){return t.setGeometricErrorMultiplier(e)}))}},{key:"transformWGS84ToCartesian",value:function(e,t,n,r){var o=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(t),2)),i=Math.cos(t),a=Math.cos(e),s=Math.sin(t),l=o+n,c=l*i*a,u=l*i*Math.sin(e),h=(.993305615557957*o+n)*s;r.set(c,u,h)}}])&&G(t.prototype,o),i&&G(t,i),Object.defineProperty(t,"prototype",{writable:!1}),s}(n.Object3D);function ee(e){return ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ee(e)}function te(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==ee(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==ee(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===ee(i)?i:String(i)),r)}var o,i}function ne(e,t){return ne=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},ne(e,t)}function re(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=ie(e);if(t){var o=ie(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"===ee(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return oe(e)}(this,n)}}function oe(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function ie(e){return ie=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ie(e)}var ae=new n.Sphere(new n.Vector3(0,0,0),1),se=new n.Vector3(0,0,0),le=new n.Vector3(0,0,0),ce=new n.Vector3(0,1,0),ue=new n.Vector2,he=new n.Quaternion,fe=new n.Matrix4,de=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ne(e,t)}(a,e);var t,r,o,i=re(a);function a(e){var t;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a);var r=oe(t=i.call(this));return t.uuid=(0,N.v4)(),e.tileLoader?t.tileLoader=e.tileLoader:console.error("an instanced tileset must be provided an InstancedTilesetLoader"),t.master=e.master,t.meshCallback=e.meshCallback,t.loadOutsideView=e.loadOutsideView,t.cameraOnLoad=e.cameraOnLoad,t.parentTile=e.parentTile,t.childrenTiles=[],t.jsonChildren=[],t.meshContent,t.tileContent,t.refinement,t.rootPath,t.geometricError,t.boundingVolume,t.json,t.materialVisibility=!1,t.inFrustum=!0,t.level=e.level?e.level:0,t.hasMeshContent=!1,t.hasUnloadedJSONContent=!1,t.centerModel=e.centerModel,t.deleted=!1,t.abortController=new AbortController,e.json?(t.rootPath=e.json.rootPath?e.json.rootPath:e.rootPath,e.json.children&&(t.jsonChildren=e.json.children),r.setup(e),e.onLoadCallback&&e.onLoadCallback(r)):e.url&&(t.loadJson=function(o,i){var a=I.dirname(i);if(r.setup({rootPath:a,json:o}),r.centerModel){var s=new n.Sphere;r.boundingVolume instanceof c?s.copy(r.boundingVolume.sphere):r.boundingVolume instanceof n.Sphere&&s.copy(r.boundingVolume),t.json.boundingVolume.region&&(r.transformWGS84ToCartesian(.5*(r.json.boundingVolume.region[0]+r.json.boundingVolume.region[2]),.5*(r.json.boundingVolume.region[1]+r.json.boundingVolume.region[3]),.5*(r.json.boundingVolume.region[4]+r.json.boundingVolume.region[5]),se),he.setFromUnitVectors(se.normalize(),ce.normalize()),r.master.applyQuaternion(he),r.master.updateWorldMatrix(!1,!1)),fe.makeTranslation(-s.center.x*r.scale.x,-s.center.y*r.scale.y,-s.center.z*r.scale.z),r.master.matrix.multiply(fe),r.master.matrix.decompose(r.master.position,r.master.quaternion,r.master.scale)}e.onLoadCallback&&e.onLoadCallback(r)},r.tileLoader.get(r.abortController,e.url,r.uuid,r)),t}return t=a,(r=[{key:"setup",value:function(e){if(this.isSetup=!0,e.json.root?(this.json=e.json.root,this.jsonChildren=this.json.children,this.json.refinement||(this.json.refinement=e.json.refinement),this.json.geometricError||(this.json.geometricError=e.json.geometricError),this.json.transform||(this.json.transform=e.json.transform),this.json.boundingVolume||(this.json.boundingVolume=e.json.boundingVolume)):this.json=e.json,this.rootPath=e.json.rootPath?e.json.rootPath:e.rootPath,this.json.refinement?this.refinement=this.json.refinement:this.refinement=e.parentRefinement,this.json.geometricError?this.geometricError=this.json.geometricError:this.geometricError=e.parentGeometricError,this.json.transform&&!this.centerModel){var t=new n.Matrix4;t.elements=this.json.transform,this.master.applyMatrix4(t)}if(this.json.boundingVolume)if(this.json.boundingVolume.box)this.boundingVolume=new c(this.json.boundingVolume.box);else if(this.json.boundingVolume.region){var r=this.json.boundingVolume.region;this.transformWGS84ToCartesian(r[0],r[1],r[4],se),this.transformWGS84ToCartesian(r[2],r[3],r[5],le),se.lerp(le,.5),this.boundingVolume=new n.Sphere(new n.Vector3(se.x,se.y,se.z),se.distanceTo(le))}else if(this.json.boundingVolume.sphere){var o=this.json.boundingVolume.sphere;this.boundingVolume=new n.Sphere(new n.Vector3(o[0],o[2],-o[1]),o[3])}else this.boundingVolume=e.parentBoundingVolume;else this.boundingVolume=e.parentBoundingVolume;this.json.content&&(this.json.content.uri&&this.json.content.uri.includes("json")||this.json.content.url&&this.json.content.url.includes("json")?this.hasUnloadedJSONContent=!0:this.hasMeshContent=!0,this.load())}},{key:"isAbsolutePathOrURL",value:function(e){var t=/^(?:http|https|ftp|tcp|udp):\/\/\S+/.test(e),n=e.startsWith("/")&&!e.startsWith("//");return t||n}},{key:"load",value:function(){var e,t=this;t.deleted||(t.json.content&&(t.json.content.uri?e=I.isAbsolute(t.json.content.uri)||t.isAbsolutePathOrURL(t.json.content.uri)?t.json.content.uri:t.rootPath+I.sep+t.json.content.uri:t.json.content.url&&(e=I.isAbsolute(t.json.content.url)||t.isAbsolutePathOrURL(t.json.content.url)?t.json.content.url:t.rootPath+I.sep+t.json.content.url),e&&(e.includes(".b3dm")||e.includes(".glb")||e.includes(".gltf")?(t.contentURL=e,t.tileLoader.get(t.abortController,e,t.uuid,t,t.cameraOnLoad?function(){return t.calculateDistanceToCamera(t.cameraOnLoad)}:function(){return 0},(function(){return t.getSiblings()}),t.level,!!t.json.boundingVolume.region,t.geometricError)):e.includes(".json")&&t.tileLoader.get(t.abortController,e,t.uuid,t))),t.matrixWorldNeedsUpdate=!0,t.updateWorldMatrix(!0,!0))}},{key:"loadMesh",value:function(e){this.deleted||(this.meshContent=e)}},{key:"loadJson",value:function(e,t){this.deleted||(this.json.children&&(this.jsonChildren=this.json.children),e.rootPath=I.dirname(t),this.jsonChildren.push(e),this.hasUnloadedJSONContent=!1)}},{key:"dispose",value:function(){var e=this;e.childrenTiles.forEach((function(e){return e.dispose()})),e.deleted=!0,e.abortController&&e.abortController.abort(),this.parent=null,this.parentTile=null,this.dispatchEvent({type:"removed"})}},{key:"disposeChildren",value:function(){this.childrenTiles.forEach((function(e){return e.dispose()})),this.childrenTiles=[]}},{key:"_update",value:function(e,t){var n,r=this;function o(e){if(r.hasMeshContent&&r.meshContent){if(e<0)return r.inFrustum=!1,void r.changeContentVisibility(!!r.loadOutsideView);if(r.inFrustum=!0,0!=r.childrenTiles.length){if(e>=r.master.geometricErrorMultiplier*r.geometricError)r.changeContentVisibility(!0);else if(e<r.master.geometricErrorMultiplier*r.geometricError){var t=!0;r.childrenTiles.every((function(e){return!!e.isReady()||(t=!1,!1)})),t&&r.changeContentVisibility(!1)}}else r.changeContentVisibility(!0)}}r.materialVisibility,r.boundingVolume&&r.geometricError&&(r.metric=r.calculateUpdateMetric(e,t)),r.childrenTiles.forEach((function(n){return n._update(e,t)})),o(r.metric),(n=r.metric)<0&&r.hasMeshContent||(!r.hasMeshContent&&r.rootPath||n<r.master.geometricErrorMultiplier*r.geometricError&&r.meshContent)&&r.json&&r.jsonChildren&&r.childrenTiles.length!=r.jsonChildren.length&&r.jsonChildren.forEach((function(t){var n=new a({parentTile:r,parentGeometricError:r.geometricError,parentBoundingVolume:r.boundingVolume,parentRefinement:r.refinement,json:t,rootPath:r.rootPath,loadOutsideView:r.loadOutsideView,level:r.level+1,tileLoader:r.tileLoader,cameraOnLoad:e,master:r.master,centerModel:!1});r.childrenTiles.push(n)})),function(e,t){if(r.hasMeshContent)r.inFrustum?e>=r.master.geometricErrorMultiplier*r.geometricError&&(r.disposeChildren(),o(e)):(r.disposeChildren(),o(e))}(r.metric)}},{key:"areAllChildrenLoadedAndHidden",value:function(){var e=!0;return this.childrenTiles.every((function(t){if(t.hasMeshContent){if(t.childrenTiles.length>0)return e=!1,!1;if(!t.inFrustum)return!0;if(!t.materialVisibility||t.meshesToDisplay!=t.meshesDisplayed)return e=!1,!1}else if(!t.areAllChildrenLoadedAndHidden())return e=!1,!1;return!0})),e}},{key:"isReady",value:function(){if(!this.inFrustum)return!0;if(this.hasUnloadedJSONContent)return!1;if((!this.hasMeshContent||!this.meshContent||!this.materialVisibility)&&this.childrenTiles.length>0){var e=!0;return this.childrenTiles.every((function(t){return!!t.isReady()||(e=!1,!1)})),e}return!this.hasMeshContent||!!this.meshContent&&!!this.materialVisibility&&!!this.meshContent.displayedOnce}},{key:"changeContentVisibility",value:function(e){this.materialVisibility=e}},{key:"calculateUpdateMetric",value:function(e,t){if(this.boundingVolume instanceof c){if(ae.copy(this.boundingVolume.sphere),ae.applyMatrix4(this.master.matrixWorld),!t.intersectsSphere(ae))return-1}else{if(!(this.boundingVolume instanceof n.Sphere))return console.error("unsupported shape"),-1;if(ae.copy(this.boundingVolume),ae.applyMatrix4(this.master.matrixWorld),!t.intersectsSphere(ae))return-1}if(this.boundingVolume instanceof c||this.boundingVolume instanceof n.Sphere){var r=Math.max(0,e.position.distanceTo(ae.center)-ae.radius);if(0==r)return 0;var o=this.master.matrixWorld.getMaxScaleOnAxis();this.master.renderer.getDrawingBufferSize(ue);var i=ue.y,a=e.fov;e.aspect<1&&(a*=e.aspect,i=ue.x);var s=2*Math.tan(.5*a*.017453292519943295)*r;return 16*window.devicePixelRatio*s/(i*o)}if(this.boundingVolume instanceof n.Box3)return-1}},{key:"getSiblings",value:function(){var e=this,t=[];if(!e.parentTile)return t;for(var n=e.parentTile;!n.hasMeshContent&&n.parentTile;)n=n.parentTile;return n.childrenTiles.forEach((function(n){if(n&&n!=e){for(;!n.hasMeshContent&&n.childrenTiles[0];)n=n.childrenTiles[0];t.push(n)}})),t}},{key:"calculateDistanceToCamera",value:function(e){return this.boundingVolume instanceof c?(ae.copy(this.boundingVolume.sphere),ae.applyMatrix4(this.master.matrixWorld)):this.boundingVolume instanceof n.Sphere?(ae.copy(this.boundingVolume),ae.applyMatrix4(this.master.matrixWorld)):console.error("unsupported shape"),Math.max(0,e.position.distanceTo(ae.center)-ae.radius)}},{key:"getWorldMatrix",value:function(){return this.master.matrixWorld}},{key:"transformWGS84ToCartesian",value:function(e,t,n,r){var o=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(t),2)),i=Math.cos(t),a=Math.cos(e),s=Math.sin(t),l=o+n,c=l*i*a,u=l*i*Math.sin(e),h=(.993305615557957*o+n)*s;r.set(c,u,h)}}])&&te(t.prototype,r),o&&te(t,o),Object.defineProperty(t,"prototype",{writable:!1}),a}(n.Object3D);function pe(e){return pe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},pe(e)}function me(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==pe(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==pe(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===pe(i)?i:String(i)),r)}var o,i}function ye(e,t){return ye=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},ye(e,t)}function ve(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=be(e);if(t){var o=be(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"===pe(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return ge(e)}(this,n)}}function ge(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function be(e){return be=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},be(e)}var we=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ye(e,t)}(a,e);var t,r,o,i=ve(a);function a(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),t=i.call(this),e.master=ge(t),t.renderer=e.renderer,t.geometricErrorMultiplier=e.geometricErrorMultiplier?e.geometricErrorMultiplier:1,t.tileset=new de(e),e.static&&(t.matrixAutoUpdate=!1),t}return t=a,(r=[{key:"update",value:function(e,t){if(t)this.tileset._update(e,t);else{var r=new n.Frustum;r.setFromProjectionMatrix((new n.Matrix4).multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse)),this.tileset._update(e,r)}}},{key:"updateWithFrustum",value:function(e,t){this.tileset._update(e,t)}},{key:"setGeometricErrorMultiplier",value:function(e){this.geometricErrorMultiplier=e||1}}])&&me(t.prototype,r),o&&me(t,o),Object.defineProperty(t,"prototype",{writable:!1}),a}(n.Object3D);function je(e){return je="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},je(e)}function xe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==je(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==je(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===je(i)?i:String(i)),r)}var o,i}var Ce=new n.Matrix4,Me=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var r=this;r.scene=t,r.instancedTiles=[],r.instancedMesh,r.reuseableMatrix=new n.Matrix4}var t,r,o;return t=e,(r=[{key:"addInstance",value:function(e){var t=this;e.added=!0,e.listOMesh=t.instancedTiles,t.instancedTiles.push(e),t.instancedMesh&&e.loadMesh(t.instancedMesh)}},{key:"addToScene",value:function(){var e=this;e.instancedMesh.setMatrixAt(0,new n.Matrix4),e.instancedMesh.instanceMatrix.needsUpdate=!0,e.instancedMesh.count=1,e.scene.add(e.instancedMesh),e.instancedMesh.onAfterRender=function(){delete e.instancedMesh.onAfterRender,e.instancedMesh.displayedOnce=!0}}},{key:"setObject",value:function(e){var t=this;t.instancedMesh=e;for(var n=0;n<t.instancedTiles.length;n++)t.instancedTiles[n].loadMesh(t.instancedMesh)}},{key:"update",value:function(){for(var e=this,t=e.instancedTiles.length-1;t>=0;t--)e.instancedTiles[t].deleted&&e.instancedTiles.splice(t,1);if(e.instancedMesh){e.instancedMesh.count=0;for(var n=0;n<e.instancedTiles.length;n++)e.instancedTiles[n].meshContent=e.instancedMesh,e.instancedTiles[n].materialVisibility&&e.instancedTiles[n].meshContent&&(e.instancedMesh.count++,e.reuseableMatrix.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),e.reuseableMatrix.multiply(e.instancedTiles[n].master.matrixWorld),e.reuseableMatrix.multiply(e.instancedMesh.baseMatrix),e.instancedMesh.setMatrixAt(e.instancedMesh.count-1,e.reuseableMatrix),e.instancedMesh.getMatrixAt(0,Ce),console.log());e.instancedMesh.instanceMatrix.needsUpdate=!0}}},{key:"getCount",value:function(){return this.instancedTiles.length}}])&&xe(t.prototype,r),o&&xe(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Te(e){return Te="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Te(e)}function Se(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==Te(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==Te(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===Te(i)?i:String(i)),r)}var o,i}var Ee=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var t=this;t.count=0,t.json,t.instancedTiles=[]}var t,n,r;return t=e,(n=[{key:"addInstance",value:function(e){this.instancedTiles.push(e),this.json&&e.loadJson(this.json,this.url)}},{key:"setObject",value:function(e,t){var n=this;n.json=e,n.url=t;for(var r=0;r<n.instancedTiles.length;r++)n.instancedTiles[r].loadJson(n.json,n.url)}},{key:"getCount",value:function(){return this.instancedTiles.length}},{key:"update",value:function(){for(var e=this,t=e.instancedTiles.length-1;t>=0;t--)e.instancedTiles[t].deleted&&e.instancedTiles.splice(t,1)}}])&&Se(t.prototype,n),r&&Se(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Oe(){Oe=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function l(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,n){return e[t]=n}}function c(e,t,n,o){var i=t&&t.prototype instanceof f?t:f,a=Object.create(i.prototype),s=new T(o||[]);return r(a,"_invoke",{value:j(e,n,s)}),a}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var h={};function f(){}function d(){}function p(){}var m={};l(m,i,(function(){return this}));var y=Object.getPrototypeOf,v=y&&y(y(S([])));v&&v!==t&&n.call(v,i)&&(m=v);var g=p.prototype=f.prototype=Object.create(m);function b(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function o(r,i,a,s){var l=u(e[r],e,i);if("throw"!==l.type){var c=l.arg,h=c.value;return h&&"object"==Le(h)&&n.call(h,"__await")?t.resolve(h.__await).then((function(e){o("next",e,a,s)}),(function(e){o("throw",e,a,s)})):t.resolve(h).then((function(e){c.value=e,a(c)}),(function(e){return o("throw",e,a,s)}))}s(l.arg)}var i;r(this,"_invoke",{value:function(e,n){function r(){return new t((function(t,r){o(e,n,t,r)}))}return i=i?i.then(r,r):r()}})}function j(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return E()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var s=x(a,n);if(s){if(s===h)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var l=u(e,t,n);if("normal"===l.type){if(r=n.done?"completed":"suspendedYield",l.arg===h)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(r="completed",n.method="throw",n.arg=l.arg)}}}function x(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),h;var o=u(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,h;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function C(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function M(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(C,this),this.reset(!0)}function S(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:E}}function E(){return{value:void 0,done:!0}}return d.prototype=p,r(g,"constructor",{value:p,configurable:!0}),r(p,"constructor",{value:d,configurable:!0}),d.displayName=l(p,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,l(e,s,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},b(w.prototype),l(w.prototype,a,(function(){return this})),e.AsyncIterator=w,e.async=function(t,n,r,o,i){void 0===i&&(i=Promise);var a=new w(c(t,n,r,o),i);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},b(g),l(g,s,"Generator"),l(g,i,(function(){return this})),l(g,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},e.values=S,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(M),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),l=n.call(i,"finallyLoc");if(s&&l){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),h},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),M(n),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;M(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:S(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),h}},e}function ke(e,t,n,r,o,i,a){try{var s=e[i](a),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,o)}function Le(e){return Le="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Le(e)}function Pe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,i=function(e,t){if("object"!==Le(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==Le(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===Le(i)?i:String(i)),r)}var o,i}var Ve=0,De=new n.Matrix4;De.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);var Re=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.maxCachedItems=100,this.maxInstances=1,n&&(this.meshCallback=n.meshCallback,this.pointsCallback=n.pointsCallback,n.maxCachedItems&&(this.maxCachedItems=n.maxCachedItems),n.maxInstances&&(this.maxInstances=n.maxInstances)),this.gltfLoader=new k.GLTFLoader;var r=new f.DRACOLoader;if(r.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(r),n&&n.renderer){var o=new d.KTX2Loader;o.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(n.renderer),this.gltfLoader.setKTX2Loader(o),this.b3dmDecoder=new O(n.renderer)}else this.b3dmDecoder=new O(null);this.cache=new u.LinkedHashMap,this.scene=t,this.ready=[],this.downloads=[],this.nextReady=[],this.nextDownloads=[],this.init()}var t,r,o;return t=e,(r=[{key:"update",value:function(){this.cache._data.forEach((function(e){e.update()}))}},{key:"init",value:function(){var e=this;_e((function(){e.download()}),10),_e((function(){var t=Date.now(),n=0;do{n=e.loadBatch()}while(n>0&&Date.now()-t<=0)}),10)}},{key:"download",value:function(){var e=this,t=this;if(0!=t.nextDownloads.length||(t.getNextDownloads(),0!=t.nextDownloads.length))for(var r=function(){var r=t.nextDownloads.shift();r&&r.shouldDoDownload()&&(Ve++,r.path.includes(".b3dm")&&fetch(r.path,{signal:r.abortController.signal}).then((function(e){if(Ve--,!e.ok)throw console.error("could not load tile with path : "+path),new Error("couldn't load \"".concat(path,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.arrayBuffer()})).then((function(n){return e.b3dmDecoder.parseB3DMInstanced(n,t.meshCallback,t.maxInstances,r.zUpToYUp)})).then((function(e){r.tile.setObject(e),t.ready.unshift(r)})).catch((function(e){return console.error(e)})),r.path.includes(".glb")||r.path.includes(".gltf")?e.gltfLoader.load(r.path,(function(e){var o;e.scene.traverse((function(e){e.geometricError=r.geometricError,e.isMesh&&(r.zUpToYUp&&e.applyMatrix4(De),t.meshCallback&&t.meshCallback(e)),e.isPoints&&console.error("instanced point cloud is not supported")})),e.scene.updateWorldMatrix(!1,!0),e.scene.traverse((function(e){e.isMesh&&((o=new n.InstancedMesh(e.geometry,e.material,t.maxInstances)).baseMatrix=e.matrixWorld)})),t.ready.unshift(r),o?r.tile.setObject(o):e.scene.traverse((function(e){e.dispose&&e.dispose(),e.material&&e.material.dispose()}))})):r.path.includes(".json")&&(Ve++,fetch(r.path,{signal:r.abortController.signal}).then((function(e){if(Ve--,!e.ok)throw console.error("could not load tile with path : "+path),new Error("couldn't load \"".concat(path,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.json()})).then((function(e){r.tile.setObject(e,r.path),t.ready.unshift(r)})).catch((function(e){return console.error(e)}))))};t.nextDownloads.length>0&&Ve<500;)r()}},{key:"loadBatch",value:function(){if(0==this.nextReady.length&&(this.getNextReady(),0==this.nextReady.length))return 0;var e=this.nextReady.shift();return e?(e.tile.addToScene&&e.tile.addToScene(),1):0}},{key:"getNextReady",value:function(){for(var e=Number.MAX_VALUE,t=-1,n=this.ready.length-1;n>=0;n--)this.ready[n].distanceFunction||this.nextReady.push(this.ready.splice(n,1)[0]);if(!(this.nextReady.length>0)){for(var r=this.ready.length-1;r>=0;r--){var o=this.ready[r].distanceFunction()*this.ready[r].level;o<e&&(e=o,t=r)}if(t>=0){var i=this.ready.splice(t,1).pop();this.nextReady.push(i);for(var a=i.getSiblings(),s=this.ready.length-1;s>=0;s--)a.includes(this.ready[s].uuid)&&this.nextready.push(this.ready.splice(s,1).pop())}}}},{key:"get",value:function(e,t,n,r,o,i,a,s,l){var c=this,u=function(e){for(var t=e.split("/"),n=[],r=0,o=0;o<t.length;o++){var i=t[o];"."!==i&&""!==i&&".."!==i?n[r++]=i:".."===i&&r>0&&r--}if(0===r)return"/";var a="";for(o=0;o<r;o++)a+="/"+n[o];return a}(t);if(t.includes(".b3dm")||t.includes(".json")||t.includes(".glb")||t.includes(".gltf")){var h=c.cache.get(u);if(h)h.addInstance(r);else if(t.includes(".b3dm")||t.includes(".glb")||t.includes(".gltf")){var f=new Me(c.scene);f.addInstance(r),c.cache.put(u,f);var d=new AbortController;e.signal.addEventListener("abort",(function(){0==f.getCount()&&d.abort()})),this.downloads.push({abortController:d,tile:f,key:u,path:t,distanceFunction:o,getSiblings:i,level:a,uuid:n,zUpToYUp:s,geometricError:l,shouldDoDownload:function(){return!0}})}else if(t.includes(".json")){var p=new Ee;p.addInstance(r),c.cache.put(u,p);var m=new AbortController;e.signal.addEventListener("abort",(function(){0==p.getCount()&&m.abort()})),this.downloads.push({abortController:m,tile:p,key:u,path:t,distanceFunction:o,getSiblings:i,level:a,shouldDoDownload:function(){return!0}})}}else console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data")}},{key:"getNextDownloads",value:function(){for(var e=Number.MAX_VALUE,t=-1,n=this.downloads.length-1;n>=0;n--){var r=this.downloads[n];r.shouldDoDownload()?r.distanceFunction||this.nextDownloads.push(this.downloads.splice(n,1)[0]):this.downloads.splice(n,1)}if(!(this.nextDownloads.length>0)){for(var o=this.downloads.length-1;o>=0;o--){var i=this.downloads[o],a=i.distanceFunction()*i.level;a<e&&(e=a,t=o)}if(t>=0){var s=this.downloads.splice(t,1).pop();this.nextDownloads.push(s);for(var l=s.getSiblings(),c=this.downloads.length-1;c>=0;c--)l.includes(this.downloads[c].uuid)&&this.nextDownloads.push(this.downloads.splice(c,1).pop())}}}},{key:"checkSize",value:function(){for(var e=this,t=0;e.cache.size()>e.maxCachedItems&&t<e.cache.size();){t++;var n=e.cache.head();n.value.getCount()>0?(e.cache.remove(n.key),e.cache.put(n.key,n.value)):(e.cache.remove(n.key),n.value.instancedMesh&&n.value.instancedMesh.traverse((function(e){if(e.material)if(e.material.length)for(var t=0;t<e.material.length;++t)e.material[t].dispose();else e.material.dispose();e.geometry&&e.geometry.dispose()})))}}}])&&Pe(t.prototype,r),o&&Pe(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}();function _e(e,t){var n,r=function(){var o=function(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){ke(i,r,o,a,s,"next",e)}function s(e){ke(i,r,o,a,s,"throw",e)}a(void 0)}))}}(Oe().mark((function o(){var i,a,s;return Oe().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return i=Date.now(),o.prev=1,o.next=4,e();case 4:o.next=9;break;case 6:o.prev=6,o.t0=o.catch(1),console.error(o.t0);case 9:return o.prev=9,a=Date.now(),s=a-i,n=setTimeout(r,s>=t?0:t-s),o.finish(9);case 15:case"end":return o.stop()}}),o,null,[[1,6,9,15]])})));return function(){return o.apply(this,arguments)}}();return n=setTimeout(r,t),{clearInterval:function(){return clearTimeout(n)}}}return t})()));
2
3
  //# sourceMappingURL=threedtiles.min.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jdultra/threedtiles",
3
- "version": "9.0.3",
3
+ "version": "9.0.5",
4
4
  "description": "An OGC 3DTiles viewer for Three.js",
5
5
  "main": "dist/threedtiles.min.js",
6
6
  "files": [
@@ -29,16 +29,14 @@
29
29
  "license": "MIT",
30
30
 
31
31
  "peerDependencies": {
32
-
32
+ "three": "^0.140.0"
33
+ },
34
+ "dependencies": {
33
35
  "js-utils-z": "^1.2.1",
34
36
  "path-browserify": "^1.0.1",
35
37
  "regenerator-runtime": "^0.13.11",
36
- "set-interval-async": "^2.0.3",
37
38
  "uuid": "^8.3.2"
38
39
  },
39
- "dependencies": {
40
- "three": "^0.149.0"
41
- },
42
40
  "devDependencies": {
43
41
  "@babel/core": "^7.21.4",
44
42
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",