@jdultra/threedtiles 9.0.5 → 9.0.6

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,3 +1,3 @@
1
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
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("three")):"function"==typeof define&&define.amd?define(["three"],t):"object"==typeof exports?exports.threedtiles=t(require("three")):e.threedtiles=t(e.THREE)}(this,(e=>(()=>{var t={852:(e,t,s)=>{const r=s(959),n=s(84),i=s(932);e.exports={Heap:r,Queue:n,LinkedHashMap:i}},959:e=>{e.exports=class{constructor(e,t){if(this._data=[],this._comparator=function(e,t){return e>=t},null!=e){if(!Array.isArray(e))throw Error("Constructor expects data to be an array");this._data=e}if(null!=t){if("function"!=typeof t)throw Error("Constructor expects comparator to be a function");this._comparator=t}}peek(){return this.size()<1?null:this._data[0]}pop(){if(this.size()<1)return null;const e=this._data[0];return this.swap(this.size()-1,0),this._data.pop(),this.heapifyDown(0),e}replaceTop(e){if(this.size()<1)return null;const t=this._data[0];return this._data[0]=e,this.heapifyDown(0),t}push(e){this._data.push(e),this.heapifyUp(this._data.length-1)}size(){return this._data.length}swap(e,t){const s=this._data[e];this._data[e]=this._data[t],this._data[t]=s}heapifyUp(e){if(0===e)return;const t=Math.floor((e-1)/2);this._comparator(this._data[e],this._data[t])||(this.swap(e,t),this.heapifyUp(t))}heapifyDown(e){const t=2*e+1,s=2*e+2;if(t>=this._data.length)return;const r=s<this._data.length&&!this._comparator(this._data[s],this._data[t])?s:t;this._comparator(this._data[e],this._data[r])&&(this.swap(e,r),this.heapifyDown(r))}}},932:e=>{e.exports=class{constructor(){this._data=new Map,this._link=new Map,this._head=void 0,this._tail=void 0}put(e,t,s=!1){this.has(e)?this._data.set(e,t):(this._data.set(e,t),this._link.set(e,{previous:void 0,next:void 0}),null==this._head?(this._head=e,this._tail=e):s?(this._link.get(this._head).previous=e,this._link.get(e).next=this._head,this._head=e):(this._link.get(this._tail).next=e,this._link.get(e).previous=this._tail,this._tail=e))}head(){return{key:this._head,value:this.get(this._head),next:()=>this.next(this._head),previous:()=>null}}tail(){return{key:this._tail,value:this.get(this._tail),next:()=>null,previous:()=>this.previous(this._tail)}}get(e){return this._data.get(e)}previousKey(e){const t=this._link.get(e);return null!=t?t.previous:void 0}previousValue(e){return this.get(this.previousKey(e))}previous(e){const t=this.previousKey(e);return{key:t,value:this.get(t),next:()=>this.next(t),previous:()=>this.previous(t)}}nextKey(e){const t=this._link.get(e);return null!=t?t.next:void 0}nextValue(e){return this.get(this.nextKey(e))}next(e){const t=this.nextKey(e);return{key:t,value:this.get(t),next:()=>this.next(t),previous:()=>this.previous(t)}}remove(e){const t=this._data.get(e);if(null!=t)if(1===this.size())this.reset();else{if(e===this._head){const e=this._link.get(this._head);this._link.get(e.next).previous=null,this._head=e.next}else if(e===this._tail){const e=this._link.get(this._tail);this._link.get(e.previous).next=null,this._tail=e.previous}else{const t=this._link.get(e),s=this._link.get(t.previous),r=this._link.get(t.next);s.next=t.next,r.previous=t.previous}this._link.delete(e),this._data.delete(e)}return t}has(e){return this._data.has(e)}size(){return this._data.size}reset(){this._data.clear(),this._link.clear(),this._head=void 0,this._tail=void 0}keys(){return this._data.keys()}values(){return this._data.values()}entries(){return this._data.entries()}toArray(e="orderByInsert"){if("orderByInsert"!==e){const e=[];let t=this._head;for(;null!=t;)e.push({key:t,value:this.get(t)}),t=this.nextKey(t);return e}return Array.from(this.keys()).map((e=>({key:e,value:this.get(e)})))}}},84:e=>{e.exports=class{constructor(e,t){if(this._data=[],this._head=0,this._cap=null,null!=e){if(!Array.isArray(e))throw Error("Constructor expects data to be an array");this._data=e}if(null!=t){if("number"!=typeof t)throw Error("Constructor expects capacity to be a number");this._cap=t}}enqueue(e){return!(null!=this._cap&&this.size()>=this._cap)&&(this._data.push(e),!0)}dequeue(){if(0===this.size())return null;const e=this._data[this._head];return this._head+=1,2*this._head>=this._data.length&&(this._data=this._data.slice(this._head),this._head=0),e}peek(e=!1){return this.size()>0?e?this._data[this._data.length-1]:this._data[this._head]:null}size(){return this._data.length-this._head}updateCapacity(e){this._cap=e}reset(){this._data=[],this._head=0}forEach(e){for(let t=this._head;t<this._data.length;t+=1)e(this._data[t],t-this._head)}toArray(){return this._data.slice(this._head)}}},470:e=>{"use strict";function t(e){if("string"!=typeof e)throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function s(e,t){for(var s,r="",n=0,i=-1,o=0,a=0;a<=e.length;++a){if(a<e.length)s=e.charCodeAt(a);else{if(47===s)break;s=47}if(47===s){if(i===a-1||1===o);else if(i!==a-1&&2===o){if(r.length<2||2!==n||46!==r.charCodeAt(r.length-1)||46!==r.charCodeAt(r.length-2))if(r.length>2){var l=r.lastIndexOf("/");if(l!==r.length-1){-1===l?(r="",n=0):n=(r=r.slice(0,l)).length-1-r.lastIndexOf("/"),i=a,o=0;continue}}else if(2===r.length||1===r.length){r="",n=0,i=a,o=0;continue}t&&(r.length>0?r+="/..":r="..",n=2)}else r.length>0?r+="/"+e.slice(i+1,a):r=e.slice(i+1,a),n=a-i-1;i=a,o=0}else 46===s&&-1!==o?++o:o=-1}return r}var r={resolve:function(){for(var e,r="",n=!1,i=arguments.length-1;i>=-1&&!n;i--){var o;i>=0?o=arguments[i]:(void 0===e&&(e=process.cwd()),o=e),t(o),0!==o.length&&(r=o+"/"+r,n=47===o.charCodeAt(0))}return r=s(r,!n),n?r.length>0?"/"+r:"/":r.length>0?r:"."},normalize:function(e){if(t(e),0===e.length)return".";var r=47===e.charCodeAt(0),n=47===e.charCodeAt(e.length-1);return 0!==(e=s(e,!r)).length||r||(e="."),e.length>0&&n&&(e+="/"),r?"/"+e:e},isAbsolute:function(e){return t(e),e.length>0&&47===e.charCodeAt(0)},join:function(){if(0===arguments.length)return".";for(var e,s=0;s<arguments.length;++s){var n=arguments[s];t(n),n.length>0&&(void 0===e?e=n:e+="/"+n)}return void 0===e?".":r.normalize(e)},relative:function(e,s){if(t(e),t(s),e===s)return"";if((e=r.resolve(e))===(s=r.resolve(s)))return"";for(var n=1;n<e.length&&47===e.charCodeAt(n);++n);for(var i=e.length,o=i-n,a=1;a<s.length&&47===s.charCodeAt(a);++a);for(var l=s.length-a,c=o<l?o:l,h=-1,d=0;d<=c;++d){if(d===c){if(l>c){if(47===s.charCodeAt(a+d))return s.slice(a+d+1);if(0===d)return s.slice(a+d)}else o>c&&(47===e.charCodeAt(n+d)?h=d:0===d&&(h=0));break}var u=e.charCodeAt(n+d);if(u!==s.charCodeAt(a+d))break;47===u&&(h=d)}var p="";for(d=n+h+1;d<=i;++d)d!==i&&47!==e.charCodeAt(d)||(0===p.length?p+="..":p+="/..");return p.length>0?p+s.slice(a+h):(a+=h,47===s.charCodeAt(a)&&++a,s.slice(a))},_makeLong:function(e){return e},dirname:function(e){if(t(e),0===e.length)return".";for(var s=e.charCodeAt(0),r=47===s,n=-1,i=!0,o=e.length-1;o>=1;--o)if(47===(s=e.charCodeAt(o))){if(!i){n=o;break}}else i=!1;return-1===n?r?"/":".":r&&1===n?"//":e.slice(0,n)},basename:function(e,s){if(void 0!==s&&"string"!=typeof s)throw new TypeError('"ext" argument must be a string');t(e);var r,n=0,i=-1,o=!0;if(void 0!==s&&s.length>0&&s.length<=e.length){if(s.length===e.length&&s===e)return"";var a=s.length-1,l=-1;for(r=e.length-1;r>=0;--r){var c=e.charCodeAt(r);if(47===c){if(!o){n=r+1;break}}else-1===l&&(o=!1,l=r+1),a>=0&&(c===s.charCodeAt(a)?-1==--a&&(i=r):(a=-1,i=l))}return n===i?i=l:-1===i&&(i=e.length),e.slice(n,i)}for(r=e.length-1;r>=0;--r)if(47===e.charCodeAt(r)){if(!o){n=r+1;break}}else-1===i&&(o=!1,i=r+1);return-1===i?"":e.slice(n,i)},extname:function(e){t(e);for(var s=-1,r=0,n=-1,i=!0,o=0,a=e.length-1;a>=0;--a){var l=e.charCodeAt(a);if(47!==l)-1===n&&(i=!1,n=a+1),46===l?-1===s?s=a:1!==o&&(o=1):-1!==s&&(o=-1);else if(!i){r=a+1;break}}return-1===s||-1===n||0===o||1===o&&s===n-1&&s===r+1?"":e.slice(s,n)},format:function(e){if(null===e||"object"!=typeof e)throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return function(e,t){var s=t.dir||t.root,r=t.base||(t.name||"")+(t.ext||"");return s?s===t.root?s+r:s+e+r:r}("/",e)},parse:function(e){t(e);var s={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return s;var r,n=e.charCodeAt(0),i=47===n;i?(s.root="/",r=1):r=0;for(var o=-1,a=0,l=-1,c=!0,h=e.length-1,d=0;h>=r;--h)if(47!==(n=e.charCodeAt(h)))-1===l&&(c=!1,l=h+1),46===n?-1===o?o=h:1!==d&&(d=1):-1!==o&&(d=-1);else if(!c){a=h+1;break}return-1===o||-1===l||0===d||1===d&&o===l-1&&o===a+1?-1!==l&&(s.base=s.name=0===a&&i?e.slice(1,l):e.slice(a,l)):(0===a&&i?(s.name=e.slice(1,o),s.base=e.slice(1,l)):(s.name=e.slice(a,o),s.base=e.slice(a,l)),s.ext=e.slice(o,l)),a>0?s.dir=e.slice(0,a-1):i&&(s.dir="/"),s},sep:"/",delimiter:":",win32:null,posix:null};r.posix=r,e.exports=r},381:t=>{"use strict";t.exports=e}},s={};function r(e){var n=s[e];if(void 0!==n)return n.exports;var i=s[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{InstancedOGC3DTile:()=>Ye,InstancedTileLoader:()=>st,OGC3DTile:()=>Ne,OcclusionCullingService:()=>i,TileLoader:()=>_e});var e=r(381);const t=[];for(let e=0;e<256;e++)t[e]=(e<16?"0":"")+e.toString(16);Math.PI,Math.PI;function s(e,t,s){return Math.max(t,Math.min(s,e))}class i{constructor(){this.cullMap=[],this.cullMaterial=new e.MeshBasicMaterial({vertexColors:!0}),this.cullMaterial.side=e.FrontSide,this.cullTarget=this.createCullTarget(),this.cullPixels=new Uint8Array(4*this.cullTarget.width*this.cullTarget.height)}setSide(e){this.cullMaterial.side=e}createCullTarget(){const t=new e.WebGLRenderTarget(Math.floor(.05*window.innerWidth),Math.floor(.05*window.innerHeight));return t.texture.format=e.RGBAFormat,t.texture.encoding=e.LinearEncoding,t.texture.minFilter=e.NearestFilter,t.texture.magFilter=e.NearestFilter,t.texture.generateMipmaps=!1,t.stencilBuffer=!1,t.depthBuffer=!0,t.depthTexture=new e.DepthTexture,t.depthTexture.format=e.DepthFormat,t.depthTexture.type=e.UnsignedShortType,t}update(e,t,r){let n=t.getRenderTarget(),i=e.overrideMaterial;e.overrideMaterial=this.cullMaterial,t.setRenderTarget(this.cullTarget),t.render(e,r),e.overrideMaterial=i,t.setRenderTarget(n),t.readRenderTargetPixels(this.cullTarget,0,0,this.cullTarget.width,this.cullTarget.height,this.cullPixels),this.cullMap=[];for(let e=0;e<this.cullPixels.length;e+=4){const t=s(this.cullPixels[e],0,255)<<16^s(this.cullPixels[e+1],0,255)<<8^s(this.cullPixels[e+2],0,255)<<0;this.cullMap[t]=!0}}hasID(e){return this.cullMap[e]}}class o{constructor(t){this.center=new e.Vector3(t[0],t[1],t[2]);var s=new e.Vector3(t[3],t[4],t[4]),r=new e.Vector3(t[6],t[7],t[8]),n=new e.Vector3(t[9],t[10],t[11]);this.halfWidth=s.length(),this.halfHeight=r.length(),this.halfDepth=n.length(),s.normalize(),r.normalize(),n.normalize(),this.sphere=new e.Sphere(this.center,Math.sqrt(this.halfWidth*this.halfWidth+this.halfHeight*this.halfHeight+this.halfDepth*this.halfDepth)),this.matrixToOBBCoordinateSystem=new e.Matrix3,this.matrixToOBBCoordinateSystem.set(s.x,s.y,s.z,r.x,r.y,r.z,n.x,n.y,n.z)}inFrustum(e){return e.intersectsSphere(this.sphere)}distanceToPoint(e){let t=e.clone();t.sub(this.center),t.applyMatrix3(this.matrixToOBBCoordinateSystem);let s=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)),n=Math.max(0,Math.max(-this.halfDepth-t.z,t.z-this.halfDepth));return Math.sqrt(s*s+r*r+n*n)}}var a=r(852);class l extends e.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register((function(e){return new m(e)})),this.register((function(e){return new w(e)})),this.register((function(e){return new b(e)})),this.register((function(e){return new f(e)})),this.register((function(e){return new g(e)})),this.register((function(e){return new T(e)})),this.register((function(e){return new y(e)})),this.register((function(e){return new p(e)})),this.register((function(e){return new x(e)})),this.register((function(e){return new d(e)})),this.register((function(e){return new _(e)}))}load(t,s,r,n){const i=this;let o;o=""!==this.resourcePath?this.resourcePath:""!==this.path?this.path:e.LoaderUtils.extractUrlBase(t),this.manager.itemStart(t);const a=function(e){n?n(e):console.error(e),i.manager.itemError(t),i.manager.itemEnd(t)},l=new e.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(t,(function(e){try{i.parse(e,o,(function(e){s(e),i.manager.itemEnd(t)}),a)}catch(e){a(e)}}),r,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return-1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return-1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(t,s,r,n){let i;const o={},a={};if("string"==typeof t)i=t;else{if(e.LoaderUtils.decodeText(new Uint8Array(t,0,4))===M){try{o[h.KHR_BINARY_GLTF]=new E(t)}catch(e){return void(n&&n(e))}i=o[h.KHR_BINARY_GLTF].content}else i=e.LoaderUtils.decodeText(new Uint8Array(t))}const l=JSON.parse(i);if(void 0===l.asset||l.asset.version[0]<2)return void(n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")));const c=new ne(l,{path:s||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){const t=this.pluginCallbacks[e](c);a[t.name]=t,o[t.name]=!0}if(l.extensionsUsed)for(let e=0;e<l.extensionsUsed.length;++e){const t=l.extensionsUsed[e],s=l.extensionsRequired||[];switch(t){case h.KHR_MATERIALS_UNLIT:o[t]=new u;break;case h.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:o[t]=new L;break;case h.KHR_DRACO_MESH_COMPRESSION:o[t]=new R(l,this.dracoLoader);break;case h.KHR_TEXTURE_TRANSFORM:o[t]=new A;break;case h.KHR_MESH_QUANTIZATION:o[t]=new k;break;default:s.indexOf(t)>=0&&void 0===a[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}c.setExtensions(o),c.setPlugins(a),c.parse(r,n)}parseAsync(e,t){const s=this;return new Promise((function(r,n){s.parse(e,t,r,n)}))}}function c(){let e={};return{get:function(t){return e[t]},add:function(t,s){e[t]=s},remove:function(t){delete e[t]},removeAll:function(){e={}}}}const h={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:"KHR_materials_pbrSpecularGlossiness",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression"};class d{constructor(e){this.parser=e,this.name=h.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,r=t.length;s<r;s++){const r=t[s];r.extensions&&r.extensions[this.name]&&void 0!==r.extensions[this.name].light&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(t){const s=this.parser,r="light:"+t;let n=s.cache.get(r);if(n)return n;const i=s.json,o=((i.extensions&&i.extensions[this.name]||{}).lights||[])[t];let a;const l=new e.Color(16777215);void 0!==o.color&&l.fromArray(o.color);const c=void 0!==o.range?o.range:0;switch(o.type){case"directional":a=new e.DirectionalLight(l),a.target.position.set(0,0,-1),a.add(a.target);break;case"point":a=new e.PointLight(l),a.distance=c;break;case"spot":a=new e.SpotLight(l),a.distance=c,o.spot=o.spot||{},o.spot.innerConeAngle=void 0!==o.spot.innerConeAngle?o.spot.innerConeAngle:0,o.spot.outerConeAngle=void 0!==o.spot.outerConeAngle?o.spot.outerConeAngle:Math.PI/4,a.angle=o.spot.outerConeAngle,a.penumbra=1-o.spot.innerConeAngle/o.spot.outerConeAngle,a.target.position.set(0,0,-1),a.add(a.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+o.type)}return a.position.set(0,0,0),a.decay=2,void 0!==o.intensity&&(a.intensity=o.intensity),a.name=s.createUniqueName(o.name||"light_"+t),n=Promise.resolve(a),s.cache.add(r,n),n}createNodeAttachment(e){const t=this,s=this.parser,r=s.json.nodes[e],n=(r.extensions&&r.extensions[this.name]||{}).light;return void 0===n?null:this._loadLight(n).then((function(e){return s._getNodeRef(t.cache,n,e)}))}}class u{constructor(){this.name=h.KHR_MATERIALS_UNLIT}getMaterialType(){return e.MeshBasicMaterial}extendParams(t,s,r){const n=[];t.color=new e.Color(1,1,1),t.opacity=1;const i=s.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const e=i.baseColorFactor;t.color.fromArray(e),t.opacity=e[3]}void 0!==i.baseColorTexture&&n.push(r.assignTexture(t,"map",i.baseColorTexture,e.sRGBEncoding))}return Promise.all(n)}}class p{constructor(e){this.parser=e,this.name=h.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=s.extensions[this.name].emissiveStrength;return void 0!==r&&(t.emissiveIntensity=r),Promise.resolve()}}class m{constructor(e){this.parser=e,this.name=h.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const r=this.parser,n=r.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];if(void 0!==o.clearcoatFactor&&(s.clearcoat=o.clearcoatFactor),void 0!==o.clearcoatTexture&&i.push(r.assignTexture(s,"clearcoatMap",o.clearcoatTexture)),void 0!==o.clearcoatRoughnessFactor&&(s.clearcoatRoughness=o.clearcoatRoughnessFactor),void 0!==o.clearcoatRoughnessTexture&&i.push(r.assignTexture(s,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),void 0!==o.clearcoatNormalTexture&&(i.push(r.assignTexture(s,"clearcoatNormalMap",o.clearcoatNormalTexture)),void 0!==o.clearcoatNormalTexture.scale)){const t=o.clearcoatNormalTexture.scale;s.clearcoatNormalScale=new e.Vector2(t,t)}return Promise.all(i)}}class f{constructor(e){this.parser=e,this.name=h.KHR_MATERIALS_SHEEN}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const r=this.parser,n=r.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[];s.sheenColor=new e.Color(0,0,0),s.sheenRoughness=0,s.sheen=1;const o=n.extensions[this.name];return void 0!==o.sheenColorFactor&&s.sheenColor.fromArray(o.sheenColorFactor),void 0!==o.sheenRoughnessFactor&&(s.sheenRoughness=o.sheenRoughnessFactor),void 0!==o.sheenColorTexture&&i.push(r.assignTexture(s,"sheenColorMap",o.sheenColorTexture,e.sRGBEncoding)),void 0!==o.sheenRoughnessTexture&&i.push(r.assignTexture(s,"sheenRoughnessMap",o.sheenRoughnessTexture)),Promise.all(i)}}class g{constructor(e){this.parser=e,this.name=h.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser,r=s.json.materials[e];if(!r.extensions||!r.extensions[this.name])return Promise.resolve();const n=[],i=r.extensions[this.name];return void 0!==i.transmissionFactor&&(t.transmission=i.transmissionFactor),void 0!==i.transmissionTexture&&n.push(s.assignTexture(t,"transmissionMap",i.transmissionTexture)),Promise.all(n)}}class T{constructor(e){this.parser=e,this.name=h.KHR_MATERIALS_VOLUME}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const r=this.parser,n=r.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];s.thickness=void 0!==o.thicknessFactor?o.thicknessFactor:0,void 0!==o.thicknessTexture&&i.push(r.assignTexture(s,"thicknessMap",o.thicknessTexture)),s.attenuationDistance=o.attenuationDistance||0;const a=o.attenuationColor||[1,1,1];return s.attenuationColor=new e.Color(a[0],a[1],a[2]),Promise.all(i)}}class y{constructor(e){this.parser=e,this.name=h.KHR_MATERIALS_IOR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const s=this.parser.json.materials[e];if(!s.extensions||!s.extensions[this.name])return Promise.resolve();const r=s.extensions[this.name];return t.ior=void 0!==r.ior?r.ior:1.5,Promise.resolve()}}class x{constructor(e){this.parser=e,this.name=h.KHR_MATERIALS_SPECULAR}getMaterialType(t){const s=this.parser.json.materials[t];return s.extensions&&s.extensions[this.name]?e.MeshPhysicalMaterial:null}extendMaterialParams(t,s){const r=this.parser,n=r.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];s.specularIntensity=void 0!==o.specularFactor?o.specularFactor:1,void 0!==o.specularTexture&&i.push(r.assignTexture(s,"specularIntensityMap",o.specularTexture));const a=o.specularColorFactor||[1,1,1];return s.specularColor=new e.Color(a[0],a[1],a[2]),void 0!==o.specularColorTexture&&i.push(r.assignTexture(s,"specularColorMap",o.specularColorTexture,e.sRGBEncoding)),Promise.all(i)}}class w{constructor(e){this.parser=e,this.name=h.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,r=s.textures[e];if(!r.extensions||!r.extensions[this.name])return null;const n=r.extensions[this.name],i=t.options.ktx2Loader;if(!i){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,n.source,i)}}class b{constructor(e){this.parser=e,this.name=h.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,r=s.json,n=r.textures[e];if(!n.extensions||!n.extensions[t])return null;const i=n.extensions[t],o=r.images[i.source];let a=s.textureLoader;if(o.uri){const e=s.options.manager.getHandler(o.uri);null!==e&&(a=e)}return this.detectSupport().then((function(n){if(n)return s.loadTextureImage(e,i.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return s.loadTexture(e)}))}detectSupport(){return this.isSupported||(this.isSupported=new Promise((function(e){const t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}}))),this.isSupported}}class _{constructor(e){this.name=h.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const e=s.extensions[this.name],r=this.parser.getDependency("buffer",e.buffer),n=this.parser.options.meshoptDecoder;if(!n||!n.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return Promise.all([r,n.ready]).then((function(t){const s=e.byteOffset||0,r=e.byteLength||0,i=e.count,o=e.byteStride,a=new ArrayBuffer(i*o),l=new Uint8Array(t[0],s,r);return n.decodeGltfBuffer(new Uint8Array(a),i,o,l,e.mode,e.filter),a}))}return null}}const M="glTF",C=1313821514,v=5130562;class E{constructor(t){this.name=h.KHR_BINARY_GLTF,this.content=null,this.body=null;const s=new DataView(t,0,12);if(this.header={magic:e.LoaderUtils.decodeText(new Uint8Array(t.slice(0,4))),version:s.getUint32(4,!0),length:s.getUint32(8,!0)},this.header.magic!==M)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const r=this.header.length-12,n=new DataView(t,12);let i=0;for(;i<r;){const s=n.getUint32(i,!0);i+=4;const r=n.getUint32(i,!0);if(i+=4,r===C){const r=new Uint8Array(t,12+i,s);this.content=e.LoaderUtils.decodeText(r)}else if(r===v){const e=12+i;this.body=t.slice(e,e+s)}i+=s}if(null===this.content)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class R{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=h.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,r=this.dracoLoader,n=e.extensions[this.name].bufferView,i=e.extensions[this.name].attributes,o={},a={},l={};for(const e in i){const t=z[e]||e.toLowerCase();o[t]=i[e]}for(const t in e.attributes){const r=z[t]||t.toLowerCase();if(void 0!==i[t]){const n=s.accessors[e.attributes[t]],i=G[n.componentType];l[r]=i,a[r]=!0===n.normalized}}return t.getDependency("bufferView",n).then((function(e){return new Promise((function(t){r.decodeDracoFile(e,(function(e){for(const t in e.attributes){const s=e.attributes[t],r=a[t];void 0!==r&&(s.normalized=r)}t(e)}),o,l)}))}))}}class A{constructor(){this.name=h.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return void 0!==t.texCoord&&console.warn('THREE.GLTFLoader: Custom UV sets in "'+this.name+'" extension not yet supported.'),void 0===t.offset&&void 0===t.rotation&&void 0===t.scale||(e=e.clone(),void 0!==t.offset&&e.offset.fromArray(t.offset),void 0!==t.rotation&&(e.rotation=t.rotation),void 0!==t.scale&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class S extends e.MeshStandardMaterial{constructor(t){super(),this.isGLTFSpecularGlossinessMaterial=!0;const s=["#ifdef USE_SPECULARMAP","\tuniform sampler2D specularMap;","#endif"].join("\n"),r=["#ifdef USE_GLOSSINESSMAP","\tuniform sampler2D glossinessMap;","#endif"].join("\n"),n=["vec3 specularFactor = specular;","#ifdef USE_SPECULARMAP","\tvec4 texelSpecular = texture2D( specularMap, vUv );","\t// reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture","\tspecularFactor *= texelSpecular.rgb;","#endif"].join("\n"),i=["float glossinessFactor = glossiness;","#ifdef USE_GLOSSINESSMAP","\tvec4 texelGlossiness = texture2D( glossinessMap, vUv );","\t// reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture","\tglossinessFactor *= texelGlossiness.a;","#endif"].join("\n"),o=["PhysicalMaterial material;","material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );","vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );","material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.specularColor = specularFactor;"].join("\n"),a={specular:{value:(new e.Color).setHex(16777215)},glossiness:{value:1},specularMap:{value:null},glossinessMap:{value:null}};this._extraUniforms=a,this.onBeforeCompile=function(e){for(const t in a)e.uniforms[t]=a[t];e.fragmentShader=e.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>",s).replace("#include <metalnessmap_pars_fragment>",r).replace("#include <roughnessmap_fragment>",n).replace("#include <metalnessmap_fragment>",i).replace("#include <lights_physical_fragment>",o)},Object.defineProperties(this,{specular:{get:function(){return a.specular.value},set:function(e){a.specular.value=e}},specularMap:{get:function(){return a.specularMap.value},set:function(e){a.specularMap.value=e,e?this.defines.USE_SPECULARMAP="":delete this.defines.USE_SPECULARMAP}},glossiness:{get:function(){return a.glossiness.value},set:function(e){a.glossiness.value=e}},glossinessMap:{get:function(){return a.glossinessMap.value},set:function(e){a.glossinessMap.value=e,e?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_UV=""):(delete this.defines.USE_GLOSSINESSMAP,delete this.defines.USE_UV)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(t)}copy(e){return super.copy(e),this.specularMap=e.specularMap,this.specular.copy(e.specular),this.glossinessMap=e.glossinessMap,this.glossiness=e.glossiness,delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this}}class L{constructor(){this.name=h.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,this.specularGlossinessParams=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","normalMapType","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity"]}getMaterialType(){return S}extendParams(t,s,r){const n=s.extensions[this.name];t.color=new e.Color(1,1,1),t.opacity=1;const i=[];if(Array.isArray(n.diffuseFactor)){const e=n.diffuseFactor;t.color.fromArray(e),t.opacity=e[3]}if(void 0!==n.diffuseTexture&&i.push(r.assignTexture(t,"map",n.diffuseTexture,e.sRGBEncoding)),t.emissive=new e.Color(0,0,0),t.glossiness=void 0!==n.glossinessFactor?n.glossinessFactor:1,t.specular=new e.Color(1,1,1),Array.isArray(n.specularFactor)&&t.specular.fromArray(n.specularFactor),void 0!==n.specularGlossinessTexture){const s=n.specularGlossinessTexture;i.push(r.assignTexture(t,"glossinessMap",s)),i.push(r.assignTexture(t,"specularMap",s,e.sRGBEncoding))}return Promise.all(i)}createMaterial(t){const s=new S(t);return s.fog=!0,s.color=t.color,s.map=void 0===t.map?null:t.map,s.lightMap=null,s.lightMapIntensity=1,s.aoMap=void 0===t.aoMap?null:t.aoMap,s.aoMapIntensity=1,s.emissive=t.emissive,s.emissiveIntensity=void 0===t.emissiveIntensity?1:t.emissiveIntensity,s.emissiveMap=void 0===t.emissiveMap?null:t.emissiveMap,s.bumpMap=void 0===t.bumpMap?null:t.bumpMap,s.bumpScale=1,s.normalMap=void 0===t.normalMap?null:t.normalMap,s.normalMapType=e.TangentSpaceNormalMap,t.normalScale&&(s.normalScale=t.normalScale),s.displacementMap=null,s.displacementScale=1,s.displacementBias=0,s.specularMap=void 0===t.specularMap?null:t.specularMap,s.specular=t.specular,s.glossinessMap=void 0===t.glossinessMap?null:t.glossinessMap,s.glossiness=t.glossiness,s.alphaMap=null,s.envMap=void 0===t.envMap?null:t.envMap,s.envMapIntensity=1,s}}class k{constructor(){this.name=h.KHR_MESH_QUANTIZATION}}class P extends e.Interpolant{constructor(e,t,s,r){super(e,t,s,r)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,r=this.valueSize,n=e*r*3+r;for(let e=0;e!==r;e++)t[e]=s[n+e];return t}}P.prototype.beforeStart_=P.prototype.copySampleValue_,P.prototype.afterEnd_=P.prototype.copySampleValue_,P.prototype.interpolate_=function(e,t,s,r){const n=this.resultBuffer,i=this.sampleValues,o=this.valueSize,a=2*o,l=3*o,c=r-t,h=(s-t)/c,d=h*h,u=d*h,p=e*l,m=p-l,f=-2*u+3*d,g=u-d,T=1-f,y=g-d+h;for(let e=0;e!==o;e++){const t=i[m+e+o],s=i[m+e+a]*c,r=i[p+e+o],l=i[p+e]*c;n[e]=T*t+y*s+f*r+g*l}return n};const j=new e.Quaternion;class F extends P{interpolate_(e,t,s,r){const n=super.interpolate_(e,t,s,r);return j.fromArray(n).normalize().toArray(n),n}}const I=0,D=1,O=2,U=3,V=4,B=5,N=6,G={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},H={9728:e.NearestFilter,9729:e.LinearFilter,9984:e.NearestMipmapNearestFilter,9985:e.LinearMipmapNearestFilter,9986:e.NearestMipmapLinearFilter,9987:e.LinearMipmapLinearFilter},K={33071:e.ClampToEdgeWrapping,33648:e.MirroredRepeatWrapping,10497:e.RepeatWrapping},W={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},z={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},X={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},q={CUBICSPLINE:void 0,LINEAR:e.InterpolateLinear,STEP:e.InterpolateDiscrete},J="OPAQUE",Y="MASK",Q="BLEND";function Z(e,t,s){for(const r in s.extensions)void 0===e[r]&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=s.extensions[r])}function $(e,t){void 0!==t.extras&&("object"==typeof t.extras?Object.assign(e.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function ee(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let s=0,r=t.weights.length;s<r;s++)e.morphTargetInfluences[s]=t.weights[s];if(t.extras&&Array.isArray(t.extras.targetNames)){const s=t.extras.targetNames;if(e.morphTargetInfluences.length===s.length){e.morphTargetDictionary={};for(let t=0,r=s.length;t<r;t++)e.morphTargetDictionary[s[t]]=t}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function te(e){const t=e.extensions&&e.extensions[h.KHR_DRACO_MESH_COMPRESSION];let s;return s=t?"draco:"+t.bufferView+":"+t.indices+":"+se(t.attributes):e.indices+":"+se(e.attributes)+":"+e.mode,s}function se(e){let t="";const s=Object.keys(e).sort();for(let r=0,n=s.length;r<n;r++)t+=s[r]+":"+e[s[r]]+";";return t}function re(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}class ne{constructor(t={},s={}){this.json=t,this.extensions={},this.plugins={},this.options=s,this.cache=new c,this.associations=new Map,this.primitiveCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};const r=!0===/^((?!chrome|android).)*safari/i.test(navigator.userAgent),n=navigator.userAgent.indexOf("Firefox")>-1,i=n?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1;"undefined"==typeof createImageBitmap||r||n&&i<98?this.textureLoader=new e.TextureLoader(this.options.manager):this.textureLoader=new e.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new e.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,r=this.json,n=this.extensions;this.cache.removeAll(),this._invokeAll((function(e){return e._markDefs&&e._markDefs()})),Promise.all(this._invokeAll((function(e){return e.beforeRoot&&e.beforeRoot()}))).then((function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])})).then((function(t){const i={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:s,userData:{}};Z(n,i,r),$(i,r),Promise.all(s._invokeAll((function(e){return e.afterRoot&&e.afterRoot(i)}))).then((function(){e(i)}))})).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let s=0,r=t.length;s<r;s++){const r=t[s].joints;for(let t=0,s=r.length;t<s;t++)e[r[t]].isBone=!0}for(let t=0,r=e.length;t<r;t++){const r=e[t];void 0!==r.mesh&&(this._addNodeRef(this.meshCache,r.mesh),void 0!==r.skin&&(s[r.mesh].isSkinnedMesh=!0)),void 0!==r.camera&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){void 0!==t&&(void 0===e.refs[t]&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const r=s.clone(),n=(e,t)=>{const s=this.associations.get(e);null!=s&&this.associations.set(t,s);for(const[s,r]of e.children.entries())n(r,t.children[s])};return n(s,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const r=e(t[s]);if(r)return r}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let r=0;r<t.length;r++){const n=e(t[r]);n&&s.push(n)}return s}getDependency(e,t){const s=e+":"+t;let r=this.cache.get(s);if(!r){switch(e){case"scene":r=this.loadScene(t);break;case"node":r=this.loadNode(t);break;case"mesh":r=this._invokeOne((function(e){return e.loadMesh&&e.loadMesh(t)}));break;case"accessor":r=this.loadAccessor(t);break;case"bufferView":r=this._invokeOne((function(e){return e.loadBufferView&&e.loadBufferView(t)}));break;case"buffer":r=this.loadBuffer(t);break;case"material":r=this._invokeOne((function(e){return e.loadMaterial&&e.loadMaterial(t)}));break;case"texture":r=this._invokeOne((function(e){return e.loadTexture&&e.loadTexture(t)}));break;case"skin":r=this.loadSkin(t);break;case"animation":r=this._invokeOne((function(e){return e.loadAnimation&&e.loadAnimation(t)}));break;case"camera":r=this.loadCamera(t);break;default:throw new Error("Unknown type: "+e)}this.cache.add(s,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,r=this.json[e+("mesh"===e?"es":"s")]||[];t=Promise.all(r.map((function(t,r){return s.getDependency(e,r)}))),this.cache.add(e,t)}return t}loadBuffer(t){const s=this.json.buffers[t],r=this.fileLoader;if(s.type&&"arraybuffer"!==s.type)throw new Error("THREE.GLTFLoader: "+s.type+" buffer type is not supported.");if(void 0===s.uri&&0===t)return Promise.resolve(this.extensions[h.KHR_BINARY_GLTF].body);const n=this.options;return new Promise((function(t,i){r.load(e.LoaderUtils.resolveURL(s.uri,n.path),t,void 0,(function(){i(new Error('THREE.GLTFLoader: Failed to load buffer "'+s.uri+'".'))}))}))}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then((function(e){const s=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+s)}))}loadAccessor(t){const s=this,r=this.json,n=this.json.accessors[t];if(void 0===n.bufferView&&void 0===n.sparse)return Promise.resolve(null);const i=[];return void 0!==n.bufferView?i.push(this.getDependency("bufferView",n.bufferView)):i.push(null),void 0!==n.sparse&&(i.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(i).then((function(t){const i=t[0],o=W[n.type],a=G[n.componentType],l=a.BYTES_PER_ELEMENT,c=l*o,h=n.byteOffset||0,d=void 0!==n.bufferView?r.bufferViews[n.bufferView].byteStride:void 0,u=!0===n.normalized;let p,m;if(d&&d!==c){const t=Math.floor(h/d),r="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+t+":"+n.count;let c=s.cache.get(r);c||(p=new a(i,t*d,n.count*d/l),c=new e.InterleavedBuffer(p,d/l),s.cache.add(r,c)),m=new e.InterleavedBufferAttribute(c,o,h%d/l,u)}else p=null===i?new a(n.count*o):new a(i,h,n.count*o),m=new e.BufferAttribute(p,o,u);if(void 0!==n.sparse){const s=W.SCALAR,r=G[n.sparse.indices.componentType],l=n.sparse.indices.byteOffset||0,c=n.sparse.values.byteOffset||0,h=new r(t[1],l,n.sparse.count*s),d=new a(t[2],c,n.sparse.count*o);null!==i&&(m=new e.BufferAttribute(m.array.slice(),m.itemSize,m.normalized));for(let e=0,t=h.length;e<t;e++){const t=h[e];if(m.setX(t,d[e*o]),o>=2&&m.setY(t,d[e*o+1]),o>=3&&m.setZ(t,d[e*o+2]),o>=4&&m.setW(t,d[e*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return m}))}loadTexture(e){const t=this.json,s=this.options,r=t.textures[e].source,n=t.images[r];let i=this.textureLoader;if(n.uri){const e=s.manager.getHandler(n.uri);null!==e&&(i=e)}return this.loadTextureImage(e,r,i)}loadTextureImage(t,s,r){const n=this,i=this.json,o=i.textures[t],a=i.images[s],l=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[l])return this.textureCache[l];const c=this.loadImageSource(s,r).then((function(s){s.flipY=!1,o.name&&(s.name=o.name);const r=(i.samplers||{})[o.sampler]||{};return s.magFilter=H[r.magFilter]||e.LinearFilter,s.minFilter=H[r.minFilter]||e.LinearMipmapLinearFilter,s.wrapS=K[r.wrapS]||e.RepeatWrapping,s.wrapT=K[r.wrapT]||e.RepeatWrapping,n.associations.set(s,{textures:t}),s})).catch((function(){return null}));return this.textureCache[l]=c,c}loadImageSource(t,s){const r=this,n=this.json,i=this.options;if(void 0!==this.sourceCache[t])return this.sourceCache[t].then((e=>e.clone()));const o=n.images[t],a=self.URL||self.webkitURL;let l=o.uri||"",c=!1;if(void 0!==o.bufferView)l=r.getDependency("bufferView",o.bufferView).then((function(e){c=!0;const t=new Blob([e],{type:o.mimeType});return l=a.createObjectURL(t),l}));else if(void 0===o.uri)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");const h=Promise.resolve(l).then((function(t){return new Promise((function(r,n){let o=r;!0===s.isImageBitmapLoader&&(o=function(t){const s=new e.Texture(t);s.needsUpdate=!0,r(s)}),s.load(e.LoaderUtils.resolveURL(t,i.path),o,void 0,n)}))})).then((function(e){var t;return!0===c&&a.revokeObjectURL(l),e.userData.mimeType=o.mimeType||((t=o.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":"image/png"),e})).catch((function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",l),e}));return this.sourceCache[t]=h,h}assignTexture(e,t,s,r){const n=this;return this.getDependency("texture",s.index).then((function(i){if(void 0===s.texCoord||0==s.texCoord||"aoMap"===t&&1==s.texCoord||console.warn("THREE.GLTFLoader: Custom UV set "+s.texCoord+" for texture "+t+" not yet supported."),n.extensions[h.KHR_TEXTURE_TRANSFORM]){const e=void 0!==s.extensions?s.extensions[h.KHR_TEXTURE_TRANSFORM]:void 0;if(e){const t=n.associations.get(i);i=n.extensions[h.KHR_TEXTURE_TRANSFORM].extendTexture(i,e),n.associations.set(i,t)}}return void 0!==r&&(i.encoding=r),e[t]=i,i}))}assignFinalMaterial(t){const s=t.geometry;let r=t.material;const n=void 0===s.attributes.tangent,i=void 0!==s.attributes.color,o=void 0===s.attributes.normal;if(t.isPoints){const t="PointsMaterial:"+r.uuid;let s=this.cache.get(t);s||(s=new e.PointsMaterial,e.Material.prototype.copy.call(s,r),s.color.copy(r.color),s.map=r.map,s.sizeAttenuation=!1,this.cache.add(t,s)),r=s}else if(t.isLine){const t="LineBasicMaterial:"+r.uuid;let s=this.cache.get(t);s||(s=new e.LineBasicMaterial,e.Material.prototype.copy.call(s,r),s.color.copy(r.color),this.cache.add(t,s)),r=s}if(n||i||o){let e="ClonedMaterial:"+r.uuid+":";r.isGLTFSpecularGlossinessMaterial&&(e+="specular-glossiness:"),n&&(e+="derivative-tangents:"),i&&(e+="vertex-colors:"),o&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=r.clone(),i&&(t.vertexColors=!0),o&&(t.flatShading=!0),n&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(r))),r=t}r.aoMap&&void 0===s.attributes.uv2&&void 0!==s.attributes.uv&&s.setAttribute("uv2",s.attributes.uv),t.material=r}getMaterialType(){return e.MeshStandardMaterial}loadMaterial(t){const s=this,r=this.json,n=this.extensions,i=r.materials[t];let o;const a={},l=i.extensions||{},c=[];if(l[h.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]){const e=n[h.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];o=e.getMaterialType(),c.push(e.extendParams(a,i,s))}else if(l[h.KHR_MATERIALS_UNLIT]){const e=n[h.KHR_MATERIALS_UNLIT];o=e.getMaterialType(),c.push(e.extendParams(a,i,s))}else{const r=i.pbrMetallicRoughness||{};if(a.color=new e.Color(1,1,1),a.opacity=1,Array.isArray(r.baseColorFactor)){const e=r.baseColorFactor;a.color.fromArray(e),a.opacity=e[3]}void 0!==r.baseColorTexture&&c.push(s.assignTexture(a,"map",r.baseColorTexture,e.sRGBEncoding)),a.metalness=void 0!==r.metallicFactor?r.metallicFactor:1,a.roughness=void 0!==r.roughnessFactor?r.roughnessFactor:1,void 0!==r.metallicRoughnessTexture&&(c.push(s.assignTexture(a,"metalnessMap",r.metallicRoughnessTexture)),c.push(s.assignTexture(a,"roughnessMap",r.metallicRoughnessTexture))),o=this._invokeOne((function(e){return e.getMaterialType&&e.getMaterialType(t)})),c.push(Promise.all(this._invokeAll((function(e){return e.extendMaterialParams&&e.extendMaterialParams(t,a)}))))}!0===i.doubleSided&&(a.side=e.DoubleSide);const d=i.alphaMode||J;if(d===Q?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,d===Y&&(a.alphaTest=void 0!==i.alphaCutoff?i.alphaCutoff:.5)),void 0!==i.normalTexture&&o!==e.MeshBasicMaterial&&(c.push(s.assignTexture(a,"normalMap",i.normalTexture)),a.normalScale=new e.Vector2(1,1),void 0!==i.normalTexture.scale)){const e=i.normalTexture.scale;a.normalScale.set(e,e)}return void 0!==i.occlusionTexture&&o!==e.MeshBasicMaterial&&(c.push(s.assignTexture(a,"aoMap",i.occlusionTexture)),void 0!==i.occlusionTexture.strength&&(a.aoMapIntensity=i.occlusionTexture.strength)),void 0!==i.emissiveFactor&&o!==e.MeshBasicMaterial&&(a.emissive=(new e.Color).fromArray(i.emissiveFactor)),void 0!==i.emissiveTexture&&o!==e.MeshBasicMaterial&&c.push(s.assignTexture(a,"emissiveMap",i.emissiveTexture,e.sRGBEncoding)),Promise.all(c).then((function(){let e;return e=o===S?n[h.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(a):new o(a),i.name&&(e.name=i.name),$(e,i),s.associations.set(e,{materials:t}),i.extensions&&Z(n,e,i),e}))}createUniqueName(t){const s=e.PropertyBinding.sanitizeNodeName(t||"");let r=s;for(let e=1;this.nodeNamesUsed[r];++e)r=s+"_"+e;return this.nodeNamesUsed[r]=!0,r}loadGeometries(t){const s=this,r=this.extensions,n=this.primitiveCache;function i(e){return r[h.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,s).then((function(t){return oe(t,e,s)}))}const o=[];for(let r=0,a=t.length;r<a;r++){const a=t[r],l=te(a),c=n[l];if(c)o.push(c.promise);else{let t;t=a.extensions&&a.extensions[h.KHR_DRACO_MESH_COMPRESSION]?i(a):oe(new e.BufferGeometry,a,s),n[l]={primitive:a,promise:t},o.push(t)}}return Promise.all(o)}loadMesh(t){const s=this,r=this.json,n=this.extensions,i=r.meshes[t],o=i.primitives,a=[];for(let t=0,s=o.length;t<s;t++){const s=void 0===o[t].material?(void 0===(l=this.cache).DefaultMaterial&&(l.DefaultMaterial=new e.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:e.FrontSide})),l.DefaultMaterial):this.getDependency("material",o[t].material);a.push(s)}var l;return a.push(s.loadGeometries(o)),Promise.all(a).then((function(r){const a=r.slice(0,r.length-1),l=r[r.length-1],c=[];for(let r=0,h=l.length;r<h;r++){const h=l[r],d=o[r];let u;const p=a[r];if(d.mode===V||d.mode===B||d.mode===N||void 0===d.mode)u=!0===i.isSkinnedMesh?new e.SkinnedMesh(h,p):new e.Mesh(h,p),!0!==u.isSkinnedMesh||u.geometry.attributes.skinWeight.normalized||u.normalizeSkinWeights(),d.mode===B?u.geometry=ae(u.geometry,e.TriangleStripDrawMode):d.mode===N&&(u.geometry=ae(u.geometry,e.TriangleFanDrawMode));else if(d.mode===D)u=new e.LineSegments(h,p);else if(d.mode===U)u=new e.Line(h,p);else if(d.mode===O)u=new e.LineLoop(h,p);else{if(d.mode!==I)throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+d.mode);u=new e.Points(h,p)}Object.keys(u.geometry.morphAttributes).length>0&&ee(u,i),u.name=s.createUniqueName(i.name||"mesh_"+t),$(u,i),d.extensions&&Z(n,u,d),s.assignFinalMaterial(u),c.push(u)}for(let e=0,r=c.length;e<r;e++)s.associations.set(c[e],{meshes:t,primitives:e});if(1===c.length)return c[0];const h=new e.Group;s.associations.set(h,{meshes:t});for(let e=0,t=c.length;e<t;e++)h.add(c[e]);return h}))}loadCamera(t){let s;const r=this.json.cameras[t],n=r[r.type];if(n)return"perspective"===r.type?s=new e.PerspectiveCamera(e.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):"orthographic"===r.type&&(s=new e.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),r.name&&(s.name=this.createUniqueName(r.name)),$(s,r),Promise.resolve(s);console.warn("THREE.GLTFLoader: Missing camera parameters.")}loadSkin(e){const t=this.json.skins[e],s={joints:t.joints};return void 0===t.inverseBindMatrices?Promise.resolve(s):this.getDependency("accessor",t.inverseBindMatrices).then((function(e){return s.inverseBindMatrices=e,s}))}loadAnimation(t){const s=this.json.animations[t],r=[],n=[],i=[],o=[],a=[];for(let e=0,t=s.channels.length;e<t;e++){const t=s.channels[e],l=s.samplers[t.sampler],c=t.target,h=void 0!==c.node?c.node:c.id,d=void 0!==s.parameters?s.parameters[l.input]:l.input,u=void 0!==s.parameters?s.parameters[l.output]:l.output;r.push(this.getDependency("node",h)),n.push(this.getDependency("accessor",d)),i.push(this.getDependency("accessor",u)),o.push(l),a.push(c)}return Promise.all([Promise.all(r),Promise.all(n),Promise.all(i),Promise.all(o),Promise.all(a)]).then((function(r){const n=r[0],i=r[1],o=r[2],a=r[3],l=r[4],c=[];for(let t=0,s=n.length;t<s;t++){const s=n[t],r=i[t],h=o[t],d=a[t],u=l[t];if(void 0===s)continue;let p;switch(s.updateMatrix(),s.matrixAutoUpdate=!0,X[u.path]){case X.weights:p=e.NumberKeyframeTrack;break;case X.rotation:p=e.QuaternionKeyframeTrack;break;default:p=e.VectorKeyframeTrack}const m=s.name?s.name:s.uuid,f=void 0!==d.interpolation?q[d.interpolation]:e.InterpolateLinear,g=[];X[u.path]===X.weights?s.traverse((function(e){e.morphTargetInfluences&&g.push(e.name?e.name:e.uuid)})):g.push(m);let T=h.array;if(h.normalized){const e=re(T.constructor),t=new Float32Array(T.length);for(let s=0,r=T.length;s<r;s++)t[s]=T[s]*e;T=t}for(let t=0,s=g.length;t<s;t++){const s=new p(g[t]+"."+X[u.path],r.array,T,f);"CUBICSPLINE"===d.interpolation&&(s.createInterpolant=function(t){return new(this instanceof e.QuaternionKeyframeTrack?F:P)(this.times,this.values,this.getValueSize()/3,t)},s.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0),c.push(s)}}const h=s.name?s.name:"animation_"+t;return new e.AnimationClip(h,void 0,c)}))}createNodeMesh(e){const t=this.json,s=this,r=t.nodes[e];return void 0===r.mesh?null:s.getDependency("mesh",r.mesh).then((function(e){const t=s._getNodeRef(s.meshCache,r.mesh,e);return void 0!==r.weights&&t.traverse((function(e){if(e.isMesh)for(let t=0,s=r.weights.length;t<s;t++)e.morphTargetInfluences[t]=r.weights[t]})),t}))}loadNode(t){const s=this.json,r=this.extensions,n=this,i=s.nodes[t],o=i.name?n.createUniqueName(i.name):"";return function(){const e=[],s=n._invokeOne((function(e){return e.createNodeMesh&&e.createNodeMesh(t)}));return s&&e.push(s),void 0!==i.camera&&e.push(n.getDependency("camera",i.camera).then((function(e){return n._getNodeRef(n.cameraCache,i.camera,e)}))),n._invokeAll((function(e){return e.createNodeAttachment&&e.createNodeAttachment(t)})).forEach((function(t){e.push(t)})),Promise.all(e)}().then((function(s){let a;if(a=!0===i.isBone?new e.Bone:s.length>1?new e.Group:1===s.length?s[0]:new e.Object3D,a!==s[0])for(let e=0,t=s.length;e<t;e++)a.add(s[e]);if(i.name&&(a.userData.name=i.name,a.name=o),$(a,i),i.extensions&&Z(r,a,i),void 0!==i.matrix){const t=new e.Matrix4;t.fromArray(i.matrix),a.applyMatrix4(t)}else void 0!==i.translation&&a.position.fromArray(i.translation),void 0!==i.rotation&&a.quaternion.fromArray(i.rotation),void 0!==i.scale&&a.scale.fromArray(i.scale);return n.associations.has(a)||n.associations.set(a,{}),n.associations.get(a).nodes=t,a}))}loadScene(t){const s=this.json,r=this.extensions,n=this.json.scenes[t],i=this,o=new e.Group;n.name&&(o.name=i.createUniqueName(n.name)),$(o,n),n.extensions&&Z(r,o,n);const a=n.nodes||[],l=[];for(let e=0,t=a.length;e<t;e++)l.push(ie(a[e],o,s,i));return Promise.all(l).then((function(){return i.associations=(t=>{const s=new Map;for(const[t,r]of i.associations)(t instanceof e.Material||t instanceof e.Texture)&&s.set(t,r);return t.traverse((e=>{const t=i.associations.get(e);null!=t&&s.set(e,t)})),s})(o),o}))}}function ie(t,s,r,n){const i=r.nodes[t];return n.getDependency("node",t).then((function(t){if(void 0===i.skin)return t;let s;return n.getDependency("skin",i.skin).then((function(e){s=e;const t=[];for(let e=0,r=s.joints.length;e<r;e++)t.push(n.getDependency("node",s.joints[e]));return Promise.all(t)})).then((function(r){return t.traverse((function(t){if(!t.isMesh)return;const n=[],i=[];for(let t=0,o=r.length;t<o;t++){const o=r[t];if(o){n.push(o);const r=new e.Matrix4;void 0!==s.inverseBindMatrices&&r.fromArray(s.inverseBindMatrices.array,16*t),i.push(r)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',s.joints[t])}t.bind(new e.Skeleton(n,i),t.matrixWorld)})),t}))})).then((function(e){s.add(e);const t=[];if(i.children){const s=i.children;for(let i=0,o=s.length;i<o;i++){const o=s[i];t.push(ie(o,e,r,n))}}return Promise.all(t)}))}function oe(t,s,r){const n=s.attributes,i=[];function o(e,s){return r.getDependency("accessor",e).then((function(e){t.setAttribute(s,e)}))}for(const e in n){const s=z[e]||e.toLowerCase();s in t.attributes||i.push(o(n[e],s))}if(void 0!==s.indices&&!t.index){const e=r.getDependency("accessor",s.indices).then((function(e){t.setIndex(e)}));i.push(e)}return $(t,s),function(t,s,r){const n=s.attributes,i=new e.Box3;if(void 0===n.POSITION)return;{const t=r.json.accessors[n.POSITION],s=t.min,o=t.max;if(void 0===s||void 0===o)return void console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");if(i.set(new e.Vector3(s[0],s[1],s[2]),new e.Vector3(o[0],o[1],o[2])),t.normalized){const e=re(G[t.componentType]);i.min.multiplyScalar(e),i.max.multiplyScalar(e)}}const o=s.targets;if(void 0!==o){const t=new e.Vector3,s=new e.Vector3;for(let e=0,n=o.length;e<n;e++){const n=o[e];if(void 0!==n.POSITION){const e=r.json.accessors[n.POSITION],i=e.min,o=e.max;if(void 0!==i&&void 0!==o){if(s.setX(Math.max(Math.abs(i[0]),Math.abs(o[0]))),s.setY(Math.max(Math.abs(i[1]),Math.abs(o[1]))),s.setZ(Math.max(Math.abs(i[2]),Math.abs(o[2]))),e.normalized){const t=re(G[e.componentType]);s.multiplyScalar(t)}t.max(s)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}i.expandByVector(t)}t.boundingBox=i;const a=new e.Sphere;i.getCenter(a.center),a.radius=i.min.distanceTo(i.max)/2,t.boundingSphere=a}(t,s,r),Promise.all(i).then((function(){return void 0!==s.targets?function(e,t,s){let r=!1,n=!1,i=!1;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(void 0!==s.POSITION&&(r=!0),void 0!==s.NORMAL&&(n=!0),void 0!==s.COLOR_0&&(i=!0),r&&n&&i)break}if(!r&&!n&&!i)return Promise.resolve(e);const o=[],a=[],l=[];for(let c=0,h=t.length;c<h;c++){const h=t[c];if(r){const t=void 0!==h.POSITION?s.getDependency("accessor",h.POSITION):e.attributes.position;o.push(t)}if(n){const t=void 0!==h.NORMAL?s.getDependency("accessor",h.NORMAL):e.attributes.normal;a.push(t)}if(i){const t=void 0!==h.COLOR_0?s.getDependency("accessor",h.COLOR_0):e.attributes.color;l.push(t)}}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(l)]).then((function(t){const s=t[0],o=t[1],a=t[2];return r&&(e.morphAttributes.position=s),n&&(e.morphAttributes.normal=o),i&&(e.morphAttributes.color=a),e.morphTargetsRelative=!0,e}))}(t,s.targets,r):t}))}function ae(t,s){let r=t.getIndex();if(null===r){const e=[],s=t.getAttribute("position");if(void 0===s)return console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),t;for(let t=0;t<s.count;t++)e.push(t);t.setIndex(e),r=t.getIndex()}const n=r.count-2,i=[];if(s===e.TriangleFanDrawMode)for(let e=1;e<=n;e++)i.push(r.getX(0)),i.push(r.getX(e)),i.push(r.getX(e+1));else for(let e=0;e<n;e++)e%2==0?(i.push(r.getX(e)),i.push(r.getX(e+1)),i.push(r.getX(e+2))):(i.push(r.getX(e+2)),i.push(r.getX(e+1)),i.push(r.getX(e)));i.length/3!==n&&console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const o=t.clone();return o.setIndex(i),o}const le=new WeakMap;class ce extends e.Loader{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(t,s,r,n){const i=new e.FileLoader(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(t,(e=>{const t={attributeIDs:this.defaultAttributeIDs,attributeTypes:this.defaultAttributeTypes,useUniqueIDs:!1};this.decodeGeometry(e,t).then(s).catch(n)}),r,n)}decodeDracoFile(e,t,s,r){const n={attributeIDs:s||this.defaultAttributeIDs,attributeTypes:r||this.defaultAttributeTypes,useUniqueIDs:!!s};this.decodeGeometry(e,n).then(t)}decodeGeometry(e,t){for(const e in t.attributeTypes){const s=t.attributeTypes[e];void 0!==s.BYTES_PER_ELEMENT&&(t.attributeTypes[e]=s.name)}const s=JSON.stringify(t);if(le.has(e)){const t=le.get(e);if(t.key===s)return t.promise;if(0===e.byteLength)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let r;const n=this.workerNextTaskID++,i=e.byteLength,o=this._getWorker(n,i).then((s=>(r=s,new Promise(((s,i)=>{r._callbacks[n]={resolve:s,reject:i},r.postMessage({type:"decode",id:n,taskConfig:t,buffer:e},[e])}))))).then((e=>this._createGeometry(e.geometry)));return o.catch((()=>!0)).then((()=>{r&&n&&this._releaseTask(r,n)})),le.set(e,{key:s,promise:o}),o}_createGeometry(t){const s=new e.BufferGeometry;t.index&&s.setIndex(new e.BufferAttribute(t.index.array,1));for(let r=0;r<t.attributes.length;r++){const n=t.attributes[r],i=n.name,o=n.array,a=n.itemSize;s.setAttribute(i,new e.BufferAttribute(o,a))}return s}_loadLibrary(t,s){const r=new e.FileLoader(this.manager);return r.setPath(this.decoderPath),r.setResponseType(s),r.setWithCredentials(this.withCredentials),new Promise(((e,s)=>{r.load(t,e,void 0,s)}))}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e="object"!=typeof WebAssembly||"js"===this.decoderConfig.type,t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then((t=>{const s=t[0];e||(this.decoderConfig.wasmBinary=t[1]);const r=he.toString(),n=["/* draco decoder */",s,"","/* worker */",r.substring(r.indexOf("{")+1,r.lastIndexOf("}"))].join("\n");this.workerSourceURL=URL.createObjectURL(new Blob([n]))})),this.decoderPending}_getWorker(e,t){return this._initDecoder().then((()=>{if(this.workerPool.length<this.workerLimit){const e=new Worker(this.workerSourceURL);e._callbacks={},e._taskCosts={},e._taskLoad=0,e.postMessage({type:"init",decoderConfig:this.decoderConfig}),e.onmessage=function(t){const s=t.data;switch(s.type){case"decode":e._callbacks[s.id].resolve(s);break;case"error":e._callbacks[s.id].reject(s);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+s.type+'"')}},this.workerPool.push(e)}else this.workerPool.sort((function(e,t){return e._taskLoad>t._taskLoad?-1:1}));const s=this.workerPool[this.workerPool.length-1];return s._taskCosts[e]=t,s._taskLoad+=t,s}))}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map((e=>e._taskLoad)))}dispose(){for(let e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,this}}function he(){let e,t;function s(e,t,s,r,n,i){const o=i.num_components(),a=s.num_points()*o,l=a*n.BYTES_PER_ELEMENT,c=function(e,t){switch(t){case Float32Array:return e.DT_FLOAT32;case Int8Array:return e.DT_INT8;case Int16Array:return e.DT_INT16;case Int32Array:return e.DT_INT32;case Uint8Array:return e.DT_UINT8;case Uint16Array:return e.DT_UINT16;case Uint32Array:return e.DT_UINT32}}(e,n),h=e._malloc(l);t.GetAttributeDataArrayForAllPoints(s,i,c,l,h);const d=new n(e.HEAPF32.buffer,h,a).slice();return e._free(h),{name:r,array:d,itemSize:o}}onmessage=function(r){const n=r.data;switch(n.type){case"init":e=n.decoderConfig,t=new Promise((function(t){e.onModuleLoaded=function(e){t({draco:e})},DracoDecoderModule(e)}));break;case"decode":const r=n.buffer,i=n.taskConfig;t.then((e=>{const t=e.draco,o=new t.Decoder,a=new t.DecoderBuffer;a.Init(new Int8Array(r),r.byteLength);try{const e=function(e,t,r,n){const i=n.attributeIDs,o=n.attributeTypes;let a,l;const c=t.GetEncodedGeometryType(r);if(c===e.TRIANGULAR_MESH)a=new e.Mesh,l=t.DecodeBufferToMesh(r,a);else{if(c!==e.POINT_CLOUD)throw new Error("THREE.DRACOLoader: Unexpected geometry type.");a=new e.PointCloud,l=t.DecodeBufferToPointCloud(r,a)}if(!l.ok()||0===a.ptr)throw new Error("THREE.DRACOLoader: Decoding failed: "+l.error_msg());const h={index:null,attributes:[]};for(const r in i){const l=self[o[r]];let c,d;if(n.useUniqueIDs)d=i[r],c=t.GetAttributeByUniqueId(a,d);else{if(d=t.GetAttributeId(a,e[i[r]]),-1===d)continue;c=t.GetAttribute(a,d)}h.attributes.push(s(e,t,a,r,l,c))}c===e.TRIANGULAR_MESH&&(h.index=function(e,t,s){const r=s.num_faces(),n=3*r,i=4*n,o=e._malloc(i);t.GetTrianglesUInt32Array(s,i,o);const a=new Uint32Array(e.HEAPF32.buffer,o,n).slice();return e._free(o),{array:a,itemSize:1}}(e,t,a));return e.destroy(a),h}(t,o,a,i),r=e.attributes.map((e=>e.array.buffer));e.index&&r.push(e.index.array.buffer),self.postMessage({type:"decode",id:n.id,geometry:e},r)}catch(e){console.error(e),self.postMessage({type:"error",id:n.id,error:e.message})}finally{t.destroy(a),t.destroy(o)}}))}}}class de{constructor(e=4){this.pool=e,this.queue=[],this.workers=[],this.workersResolve=[],this.workerStatus=0}_initWorker(e){if(!this.workers[e]){const t=this.workerCreator();t.addEventListener("message",this._onMessage.bind(this,e)),this.workers[e]=t}}_getIdleWorker(){for(let e=0;e<this.pool;e++)if(!(this.workerStatus&1<<e))return e;return-1}_onMessage(e,t){const s=this.workersResolve[e];if(s&&s(t),this.queue.length){const{resolve:t,msg:s,transfer:r}=this.queue.shift();this.workersResolve[e]=t,this.workers[e].postMessage(s,r)}else this.workerStatus^=1<<e}setWorkerCreator(e){this.workerCreator=e}setWorkerLimit(e){this.pool=e}postMessage(e,t){return new Promise((s=>{const r=this._getIdleWorker();-1!==r?(this._initWorker(r),this.workerStatus|=1<<r,this.workersResolve[r]=s,this.workers[r].postMessage(e,t)):this.queue.push({resolve:s,msg:e,transfer:t})}))}dispose(){this.workers.forEach((e=>e.terminate())),this.workersResolve.length=0,this.workers.length=0,this.queue.length=0,this.workerStatus=0}}const ue=new WeakMap;let pe=0;class me extends e.Loader{constructor(e){super(e),this.transcoderPath="",this.transcoderBinary=null,this.transcoderPending=null,this.workerPool=new de,this.workerSourceURL="",this.workerConfig=null,"undefined"!=typeof MSC_TRANSCODER&&console.warn('THREE.KTX2Loader: Please update to latest "basis_transcoder". "msc_basis_transcoder" is no longer supported in three.js r125+.')}setTranscoderPath(e){return this.transcoderPath=e,this}setWorkerLimit(e){return this.workerPool.setWorkerLimit(e),this}detectSupport(e){return this.workerConfig={astcSupported:e.extensions.has("WEBGL_compressed_texture_astc"),etc1Supported:e.extensions.has("WEBGL_compressed_texture_etc1"),etc2Supported:e.extensions.has("WEBGL_compressed_texture_etc"),dxtSupported:e.extensions.has("WEBGL_compressed_texture_s3tc"),bptcSupported:e.extensions.has("EXT_texture_compression_bptc"),pvrtcSupported:e.extensions.has("WEBGL_compressed_texture_pvrtc")||e.extensions.has("WEBKIT_WEBGL_compressed_texture_pvrtc")},e.capabilities.isWebGL2&&(this.workerConfig.etc1Supported=!1),this}init(){if(!this.transcoderPending){const t=new e.FileLoader(this.manager);t.setPath(this.transcoderPath),t.setWithCredentials(this.withCredentials);const s=t.loadAsync("basis_transcoder.js"),r=new e.FileLoader(this.manager);r.setPath(this.transcoderPath),r.setResponseType("arraybuffer"),r.setWithCredentials(this.withCredentials);const n=r.loadAsync("basis_transcoder.wasm");this.transcoderPending=Promise.all([s,n]).then((([e,t])=>{const s=me.BasisWorker.toString(),r=["/* constants */","let _EngineFormat = "+JSON.stringify(me.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(me.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(me.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this.workerSourceURL=URL.createObjectURL(new Blob([r])),this.transcoderBinary=t,this.workerPool.setWorkerCreator((()=>{const e=new Worker(this.workerSourceURL),t=this.transcoderBinary.slice(0);return e.postMessage({type:"init",config:this.workerConfig,transcoderBinary:t},[t]),e}))})),pe>0&&console.warn("THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues. Use a single KTX2Loader instance, or call .dispose() on old instances."),pe++}return this.transcoderPending}load(t,s,r,n){if(null===this.workerConfig)throw new Error("THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.");const i=new e.FileLoader(this.manager);i.setResponseType("arraybuffer"),i.setWithCredentials(this.withCredentials);const o=new e.CompressedTexture;return i.load(t,(e=>{if(ue.has(e)){return ue.get(e).promise.then(s).catch(n)}this._createTexture([e]).then((function(e){o.copy(e),o.needsUpdate=!0,s&&s(o)})).catch(n)}),r,n),o}_createTextureFrom(t){const{mipmaps:s,width:r,height:n,format:i,type:o,error:a,dfdTransferFn:l,dfdFlags:c}=t;if("error"===o)return Promise.reject(a);const h=new e.CompressedTexture(s,r,n,i,e.UnsignedByteType);return h.minFilter=1===s.length?e.LinearFilter:e.LinearMipmapLinearFilter,h.magFilter=e.LinearFilter,h.generateMipmaps=!1,h.needsUpdate=!0,h.encoding=2===l?e.sRGBEncoding:e.LinearEncoding,h.premultiplyAlpha=!!(1&c),h}_createTexture(e,t={}){const s=t,r=this.init().then((()=>this.workerPool.postMessage({type:"transcode",buffers:e,taskConfig:s},e))).then((e=>this._createTextureFrom(e.data)));return ue.set(e[0],{promise:r}),r}dispose(){return this.workerPool.dispose(),this.workerSourceURL&&URL.revokeObjectURL(this.workerSourceURL),pe--,this}}me.BasisFormat={ETC1S:0,UASTC_4x4:1},me.TranscoderFormat={ETC1:0,ETC2:1,BC1:2,BC3:3,BC4:4,BC5:5,BC7_M6_OPAQUE_ONLY:6,BC7_M5:7,PVRTC1_4_RGB:8,PVRTC1_4_RGBA:9,ASTC_4x4:10,ATC_RGB:11,ATC_RGBA_INTERPOLATED_ALPHA:12,RGBA32:13,RGB565:14,BGR565:15,RGBA4444:16},me.EngineFormat={RGBAFormat:e.RGBAFormat,RGBA_ASTC_4x4_Format:e.RGBA_ASTC_4x4_Format,RGBA_BPTC_Format:e.RGBA_BPTC_Format,RGBA_ETC2_EAC_Format:e.RGBA_ETC2_EAC_Format,RGBA_PVRTC_4BPPV1_Format:e.RGBA_PVRTC_4BPPV1_Format,RGBA_S3TC_DXT5_Format:e.RGBA_S3TC_DXT5_Format,RGB_ETC1_Format:e.RGB_ETC1_Format,RGB_ETC2_Format:e.RGB_ETC2_Format,RGB_PVRTC_4BPPV1_Format:e.RGB_PVRTC_4BPPV1_Format,RGB_S3TC_DXT1_Format:e.RGB_S3TC_DXT1_Format},me.BasisWorker=function(){let e,t,s;const r=_EngineFormat,n=_TranscoderFormat,i=_BasisFormat;self.addEventListener("message",(function(o){const h=o.data;switch(h.type){case"init":e=h.config,d=h.transcoderBinary,t=new Promise((e=>{s={wasmBinary:d,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.KTX2File&&console.warn("THREE.KTX2Loader: Please update Basis Universal transcoder.")}));break;case"transcode":t.then((()=>{try{const{width:t,height:o,hasAlpha:d,mipmaps:u,format:p,dfdTransferFn:m,dfdFlags:f}=function(t){const o=new s.KTX2File(new Uint8Array(t));function h(){o.close(),o.delete()}if(!o.isValid())throw h(),new Error("THREE.KTX2Loader:\tInvalid or unsupported .ktx2 file");const d=o.isUASTC()?i.UASTC_4x4:i.ETC1S,u=o.getWidth(),p=o.getHeight(),m=o.getLevels(),f=o.getHasAlpha(),g=o.getDFDTransferFunc(),T=o.getDFDFlags(),{transcoderFormat:y,engineFormat:x}=function(t,s,o,h){let d,u;const p=t===i.ETC1S?a:l;for(let r=0;r<p.length;r++){const n=p[r];if(e[n.if]&&(n.basisFormat.includes(t)&&!(h&&n.transcoderFormat.length<2)&&(!n.needsPowerOfTwo||c(s)&&c(o))))return d=n.transcoderFormat[h?1:0],u=n.engineFormat[h?1:0],{transcoderFormat:d,engineFormat:u}}return console.warn("THREE.KTX2Loader: No suitable compressed texture format found. Decoding to RGBA32."),d=n.RGBA32,u=r.RGBAFormat,{transcoderFormat:d,engineFormat:u}}(d,u,p,f);if(!u||!p||!m)throw h(),new Error("THREE.KTX2Loader:\tInvalid texture");if(!o.startTranscoding())throw h(),new Error("THREE.KTX2Loader: .startTranscoding failed");const w=[];for(let e=0;e<m;e++){const t=o.getImageLevelInfo(e,0,0),s=t.origWidth,r=t.origHeight,n=new Uint8Array(o.getImageTranscodedSizeInBytes(e,0,0,y));if(!o.transcodeImage(n,e,0,0,y,0,-1,-1))throw h(),new Error("THREE.KTX2Loader: .transcodeImage failed.");w.push({data:n,width:s,height:r})}return h(),{width:u,height:p,hasAlpha:f,mipmaps:w,format:x,dfdTransferFn:g,dfdFlags:T}}(h.buffers[0]),g=[];for(let e=0;e<u.length;++e)g.push(u[e].data.buffer);self.postMessage({type:"transcode",id:h.id,width:t,height:o,hasAlpha:d,mipmaps:u,format:p,dfdTransferFn:m,dfdFlags:f},g)}catch(e){console.error(e),self.postMessage({type:"error",id:h.id,error:e.message})}}))}var d}));const o=[{if:"astcSupported",basisFormat:[i.UASTC_4x4],transcoderFormat:[n.ASTC_4x4,n.ASTC_4x4],engineFormat:[r.RGBA_ASTC_4x4_Format,r.RGBA_ASTC_4x4_Format],priorityETC1S:1/0,priorityUASTC:1,needsPowerOfTwo:!1},{if:"bptcSupported",basisFormat:[i.ETC1S,i.UASTC_4x4],transcoderFormat:[n.BC7_M5,n.BC7_M5],engineFormat:[r.RGBA_BPTC_Format,r.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[i.ETC1S,i.UASTC_4x4],transcoderFormat:[n.BC1,n.BC3],engineFormat:[r.RGB_S3TC_DXT1_Format,r.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[i.ETC1S,i.UASTC_4x4],transcoderFormat:[n.ETC1,n.ETC2],engineFormat:[r.RGB_ETC2_Format,r.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[i.ETC1S,i.UASTC_4x4],transcoderFormat:[n.ETC1],engineFormat:[r.RGB_ETC1_Format],priorityETC1S:2,priorityUASTC:4,needsPowerOfTwo:!1},{if:"pvrtcSupported",basisFormat:[i.ETC1S,i.UASTC_4x4],transcoderFormat:[n.PVRTC1_4_RGB,n.PVRTC1_4_RGBA],engineFormat:[r.RGB_PVRTC_4BPPV1_Format,r.RGBA_PVRTC_4BPPV1_Format],priorityETC1S:5,priorityUASTC:6,needsPowerOfTwo:!0}],a=o.sort((function(e,t){return e.priorityETC1S-t.priorityETC1S})),l=o.sort((function(e,t){return e.priorityUASTC-t.priorityUASTC}));function c(e){return e<=2||0==(e&e-1)&&0!==e}};const fe=new TextDecoder;class ge{constructor(e,t,s,r){this.buffer=e,this.binOffset=t+s,this.binLength=r;let n=null;if(0!==s)try{const r=new Uint8Array(e,t,s);n=JSON.parse(fe.decode(r))}catch(e){n={}}else n={};this.header=n}getKeys(){return Object.keys(this.header)}getData(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;const n=this.header;if(!(e in n))return null;const i=n[e];if(i instanceof Object){if(Array.isArray(i))return i;{const{buffer:n,binOffset:o,binLength:a}=this,l=i.byteOffset||0,c=i.type||r,h=i.componentType||s;if("type"in i&&r&&i.type!==r)throw new Error("FeatureTable: Specified type does not match expected type.");let d,u;switch(c){case"SCALAR":d=1;break;case"VEC2":d=2;break;case"VEC3":d=3;break;case"VEC4":d=4;break;default:throw new Error('FeatureTable : Feature type not provided for "'.concat(e,'".'))}const p=o+l,m=t*d;switch(h){case"BYTE":u=new Int8Array(n,p,m);break;case"UNSIGNED_BYTE":u=new Uint8Array(n,p,m);break;case"SHORT":u=new Int16Array(n,p,m);break;case"UNSIGNED_SHORT":u=new Uint16Array(n,p,m);break;case"INT":u=new Int32Array(n,p,m);break;case"UNSIGNED_INT":u=new Uint32Array(n,p,m);break;case"FLOAT":u=new Float32Array(n,p,m);break;case"DOUBLE":u=new Float64Array(n,p,m);break;default:throw new Error('FeatureTable : Feature component type not provided for "'.concat(e,'".'))}if(p+m*u.BYTES_PER_ELEMENT>o+a)throw new Error("FeatureTable: Feature data read outside binary body length.");return u}}return i}}class Te extends ge{constructor(e,t,s,r,n){super(e,s,r,n),this.batchSize=t}getData(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return super.getData(e,this.batchSize,t,s)}}const ye=new e.Matrix4;ye.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);class xe{constructor(t){this.gltfLoader=new l;const s=new ce;if(s.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(s),t){const e=new me;e.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(t),this.gltfLoader.setKTX2Loader(e)}this.tempMatrix=new e.Matrix4}parseB3DM(e,t,s,r){const n=new DataView(e),i=String.fromCharCode(n.getUint8(0))+String.fromCharCode(n.getUint8(1))+String.fromCharCode(n.getUint8(2))+String.fromCharCode(n.getUint8(3));console.assert("b3dm"===i);const o=n.getUint32(8,!0);console.assert(o===e.byteLength);const a=n.getUint32(12,!0),l=n.getUint32(16,!0),c=n.getUint32(20,!0),h=n.getUint32(24,!0),d=new ge(e,28,a,l),u=28+a+l,p=(new Te(e,d.getData("BATCH_LENGTH"),u,c,h),u+c+h),m=new Uint8Array(e,p,o-p).slice().buffer;return new Promise(((e,n)=>{this.gltfLoader.parse(m,null,(n=>{const i=d.getData("RTC_CENTER");i?(this.tempMatrix.makeTranslation(i[0],i[1],i[2]),n.scene.applyMatrix4(this.tempMatrix)):n.userData.gltfExtensions&&n.userData.gltfExtensions.CESIUM_RTC&&(this.tempMatrix.makeTranslation(n.userData.gltfExtensions.CESIUM_RTC.center[0],n.userData.gltfExtensions.CESIUM_RTC.center[1],n.userData.gltfExtensions.CESIUM_RTC.center[2]),n.scene.applyMatrix4(this.tempMatrix)),r||n.scene.applyMatrix4(ye),n.scene.traverse((e=>{e.isMesh&&(e.geometricError=s,r&&e.applyMatrix4(ye),t&&t(e))})),e(n.scene)}),(e=>{console.error(e)}))}))}parseB3DMInstanced(t,s,r,n){return this.parseB3DM(t,s,n).then((t=>{let s;return t.updateWorldMatrix(!1,!0),t.traverse((t=>{t.isMesh&&(s=new e.InstancedMesh(t.geometry,t.material,r),s.baseMatrix=t.matrixWorld)})),s}))}}let we=0;const be=new e.Matrix4;be.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);class _e{constructor(e){this.maxCachedItems=100,e&&(this.meshCallback=e.meshCallback,this.pointsCallback=e.pointsCallback,e.maxCachedItems&&(this.maxCachedItems=e.maxCachedItems)),this.gltfLoader=new l;const t=new ce;if(t.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(t),e&&e.renderer){const t=new me;t.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(e.renderer),this.gltfLoader.setKTX2Loader(t),this.b3dmDecoder=new xe(e.renderer)}else this.b3dmDecoder=new xe(null);this.cache=new a.LinkedHashMap,this.register={},this.ready=[],this.downloads=[],this.nextReady=[],this.nextDownloads=[],this.init()}init(){const e=this;Me((()=>{e.download()}),10),Me((()=>{const t=Date.now();let s=0;do{s=e.loadBatch()}while(s>0&&Date.now()-t<=0)}),10)}scheduleDownload(e){this.downloads.unshift(e)}download(){if(0!=this.nextDownloads.length||(this.getNextDownloads(),0!=this.nextDownloads.length))for(;this.nextDownloads.length>0&&we<500;){const e=this.nextDownloads.shift();e&&e.shouldDoDownload()&&e.doDownload()}}meshReceived(e,t,s,r,n,i,o){this.ready.unshift([e,t,s,r,n,i,o])}loadBatch(){if(0==this.nextReady.length&&(this.getNextReady(),0==this.nextReady.length))return 0;const e=this.nextReady.shift();if(!e)return 0;const t=e[0],s=e[1],r=e[2],n=t.get(r);return n&&s[r]&&Object.keys(s[r]).forEach((e=>{const t=s[r][e];t&&(t(n),s[r][e]=null)})),1}getNextDownloads(){let e=Number.MAX_VALUE,t=-1;for(let e=this.downloads.length-1;e>=0;e--)this.downloads[e].shouldDoDownload()?this.downloads[e].distanceFunction||this.nextDownloads.push(this.downloads.splice(e,1)[0]):this.downloads.splice(e,1);if(!(this.nextDownloads.length>0)){for(let s=this.downloads.length-1;s>=0;s--){const r=this.downloads[s].distanceFunction()*this.downloads[s].level;r<e&&(e=r,t=s)}if(t>=0){const e=this.downloads.splice(t,1).pop();this.nextDownloads.push(e);const s=e.getSiblings();for(let e=this.downloads.length-1;e>=0;e--)s.includes(this.downloads[e].uuid)&&this.nextDownloads.push(this.downloads.splice(e,1).pop())}}}getNextReady(){let e=Number.MAX_VALUE,t=-1;for(let e=this.ready.length-1;e>=0;e--)this.ready[e][3]||this.nextReady.push(this.ready.splice(e,1)[0]);if(!(this.nextReady.length>0)){for(let s=this.ready.length-1;s>=0;s--){const r=this.ready[s][3]()*this.ready[s][5];r<e&&(e=r,t=s)}if(t>=0){const e=this.ready.splice(t,1).pop();this.nextReady.push(e);const s=e[4]();for(let e=this.ready.length-1;e>=0;e--)s.includes(this.ready[e][6])&&this.nextready.push(this.ready.splice(e,1).pop())}}}get(e,t,s,r,n,i,o,a,l){const c=this,h=Ce(s),d=new AbortController;if(e.signal.addEventListener("abort",(()=>{c.register[h]&&0!=Object.keys(c.register[h]).length||d.abort()})),!(s.includes(".b3dm")||s.includes(".json")||s.includes(".gltf")||s.includes(".glb")))return void console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data");c.register[h]||(c.register[h]={}),c.register[h][t]&&console.error(" a tile should only be loaded once"),c.register[h][t]=r;if(c.cache.get(h))this.meshReceived(c.cache,c.register,h,n,i,o,t);else if(1==Object.keys(c.register[h]).length){let r;s.includes(".b3dm")?r=()=>{we++,fetch(s,{signal:d.signal}).then((e=>{if(we--,!e.ok)throw console.error("could not load tile with path : "+s),new Error("couldn't load \"".concat(s,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.arrayBuffer()})).then((e=>this.b3dmDecoder.parseB3DM(e,c.meshCallback,l,a))).then((e=>{c.cache.put(h,e),c.checkSize(),this.meshReceived(c.cache,c.register,h,n,i,o,t)})).catch((()=>{}))}:s.includes(".glb")||s.includes(".gltf")?r=()=>{we++,this.gltfLoader.load(s,(e=>{e.scene.traverse((e=>{e.geometricError=l,e.isMesh&&(a&&e.applyMatrix4(be),c.meshCallback&&c.meshCallback(e)),e.isPoints&&(a&&e.applyMatrix4(be),c.pointsCallback&&c.pointsCallback(e))})),c.cache.put(h,e.scene),c.checkSize(),c.meshReceived(c.cache,c.register,h,n,i,o,t)}))}:s.includes(".json")&&(r=()=>{we++,fetch(s,{signal:d.signal}).then((e=>{if(we--,!e.ok)throw console.error("could not load tile with path : "+s),new Error("couldn't load \"".concat(s,'". Request failed with status ').concat(e.status," : ").concat(e.statusText));return e.json()})).then((e=>{c.cache.put(h,e),c.checkSize(),c.meshReceived(c.cache,c.register,h)})).catch((e=>console.error("tile download aborted")))}),this.scheduleDownload({shouldDoDownload:()=>!e.signal.aborted&&!!c.register[h]&&Object.keys(c.register[h]).length>0,doDownload:r,distanceFunction:n,getSiblings:i,level:o,uuid:t})}}invalidate(e,t){const s=Ce(e);this.register[s]&&delete this.register[s][t]}checkSize(){const e=this;let t=0;for(;e.cache.size()>e.maxCachedItems&&t<e.cache.size();){t++;const s=e.cache.head(),r=e.register[s.key];r&&(Object.keys(r).length>0?(e.cache.remove(s.key),e.cache.put(s.key,s.value)):(e.cache.remove(s.key),delete e.register[s.key],s.value.traverse((e=>{if(e.material)if(e.material.length)for(let t=0;t<e.material.length;++t)e.material[t].dispose();else e.material.dispose();e.geometry&&e.geometry.dispose()}))))}}}function Me(e,t){let s;const r=async()=>{const n=Date.now();try{await e()}catch(e){console.error(e)}finally{const e=Date.now()-n;s=setTimeout(r,e>=t?0:t-e)}};return s=setTimeout(r,t),{clearInterval:()=>clearTimeout(s)}}function Ce(e){for(var t=e.split("/"),s=[],r=0,n=0;n<t.length;n++){var i=t[n];"."!==i&&""!==i&&".."!==i?s[r++]=i:".."===i&&r>0&&r--}if(0===r)return"/";var o="";for(n=0;n<r;n++)o+="/"+s[n];return o}var ve,Ee=new Uint8Array(16);function Re(){if(!ve&&!(ve="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ve(Ee)}const Ae=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;const Se=function(e){return"string"==typeof e&&Ae.test(e)};for(var Le=[],ke=0;ke<256;++ke)Le.push((ke+256).toString(16).substr(1));const Pe=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,s=(Le[e[t+0]]+Le[e[t+1]]+Le[e[t+2]]+Le[e[t+3]]+"-"+Le[e[t+4]]+Le[e[t+5]]+"-"+Le[e[t+6]]+Le[e[t+7]]+"-"+Le[e[t+8]]+Le[e[t+9]]+"-"+Le[e[t+10]]+Le[e[t+11]]+Le[e[t+12]]+Le[e[t+13]]+Le[e[t+14]]+Le[e[t+15]]).toLowerCase();if(!Se(s))throw TypeError("Stringified UUID is invalid");return s};const je=function(e,t,s){var r=(e=e||{}).random||(e.rng||Re)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){s=s||0;for(var n=0;n<16;++n)t[s+n]=r[n];return t}return Pe(r)};var Fe=r(470);const Ie=new e.Sphere(new e.Vector3(0,0,0),1),De=new e.Vector3(0,0,0),Oe=new e.Vector3(0,0,0),Ue=new e.Vector3(0,1,0),Ve=new e.Vector2(1e3,1e3),Be=new e.Quaternion;class Ne extends e.Object3D{constructor(t){super();const r=this;if(this.uuid=je(),t.tileLoader)this.tileLoader=t.tileLoader;else{const s={};s.meshCallback=t.meshCallback?t.meshCallback:t=>{t.material.wireframe=!1,t.material.side=e.DoubleSide},s.pointsCallback=t.pointsCallback?t.pointsCallback:e=>{e.material.size=.1,e.material.sizeAttenuation=!0},this.tileLoader=new _e(s)}this.geometricErrorMultiplier=t.geometricErrorMultiplier?t.geometricErrorMultiplier:1,this.renderer=t.renderer,this.meshCallback=t.meshCallback,this.loadOutsideView=t.loadOutsideView,this.cameraOnLoad=t.cameraOnLoad,this.parentTile=t.parentTile,this.occlusionCullingService=t.occlusionCullingService,this.static=t.static,this.occlusionCullingService&&(this.color=new e.Color,this.color.setHex(16777215*Math.random()),this.colorID=s(255*r.color.r,0,255)<<16^s(255*r.color.g,0,255)<<8^s(255*r.color.b,0,255)<<0),this.static&&(this.matrixAutoUpdate=!1),this.childrenTiles=[],this.meshContent,this.tileContent,this.refinement,this.rootPath,this.geometricError,this.boundingVolume,this.json,this.materialVisibility=!1,this.inFrustum=!0,this.level=t.level?t.level:0,this.hasMeshContent=!1,this.hasUnloadedJSONContent=!1,this.centerModel=t.centerModel,this.abortController=new AbortController,this.layers.disable(0),t.json?(r.setup(t),t.onLoadCallback&&t.onLoadCallback(r)):t.url&&fetch(t.url,{signal:r.abortController.signal}).then((s=>{if(!s.ok)throw new Error("couldn't load \"".concat(t.url,'". Request failed with status ').concat(s.status," : ").concat(s.statusText));s.json().then((s=>{if(r.setup({rootPath:Fe.dirname(t.url),json:s}),t.onLoadCallback&&t.onLoadCallback(r),r.centerModel){const t=new e.Sphere;r.boundingVolume instanceof o?t.copy(r.boundingVolume.sphere):r.boundingVolume instanceof e.Sphere&&t.copy(r.boundingVolume),this.json.boundingVolume.region&&(this.transformWGS84ToCartesian(.5*(this.json.boundingVolume.region[0]+this.json.boundingVolume.region[2]),.5*(this.json.boundingVolume.region[1]+this.json.boundingVolume.region[3]),.5*(this.json.boundingVolume.region[4]+this.json.boundingVolume.region[5]),De),Be.setFromUnitVectors(De.normalize(),Ue.normalize()),r.applyQuaternion(Be)),r.translateX(-t.center.x*r.scale.x),r.translateY(-t.center.y*r.scale.y),r.translateZ(-t.center.z*r.scale.z)}}))}))}setup(t){if(t.json.root?(this.json=t.json.root,this.json.refinement||(this.json.refinement=t.json.refinement),this.json.geometricError||(this.json.geometricError=t.json.geometricError),this.json.transform||(this.json.transform=t.json.transform),this.json.boundingVolume||(this.json.boundingVolume=t.json.boundingVolume)):this.json=t.json,this.rootPath=t.json.rootPath?t.json.rootPath:t.rootPath,this.json.refinement?this.refinement=this.json.refinement:this.refinement=t.parentRefinement,this.json.geometricError?this.geometricError=this.json.geometricError:this.geometricError=t.parentGeometricError,this.json.transform&&!this.centerModel){let t=new e.Matrix4;t.elements=this.json.transform,this.applyMatrix4(t)}if(this.json.boundingVolume)if(this.json.boundingVolume.box)this.boundingVolume=new o(this.json.boundingVolume.box);else if(this.json.boundingVolume.region){const t=this.json.boundingVolume.region;this.transformWGS84ToCartesian(t[0],t[1],t[4],De),this.transformWGS84ToCartesian(t[2],t[3],t[5],Oe),De.lerp(Oe,.5),this.boundingVolume=new e.Sphere(new e.Vector3(De.x,De.y,De.z),De.distanceTo(Oe))}else if(this.json.boundingVolume.sphere){const t=this.json.boundingVolume.sphere;this.boundingVolume=new e.Sphere(new e.Vector3(t[0],t[1],t[2]),t[3])}else this.boundingVolume=t.parentBoundingVolume;else this.boundingVolume=t.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())}isAbsolutePathOrURL(e){const t=/^(?:http|https|ftp|tcp|udp):\/\/\S+/.test(e),s=e.startsWith("/")&&!e.startsWith("//");return t||s}load(){var t=this;if(!t.deleted&&t.json.content){let s;t.json.content.uri?s=Fe.isAbsolute(t.json.content.uri)||t.isAbsolutePathOrURL(t.json.content.uri)?t.json.content.uri:t.rootPath+Fe.sep+t.json.content.uri:t.json.content.url&&(s=Fe.isAbsolute(t.json.content.url)||t.isAbsolutePathOrURL(t.json.content.url)?t.json.content.url:t.rootPath+Fe.sep+t.json.content.url),s&&(s.includes(".b3dm")||s.includes(".glb")||s.includes(".gltf")?(t.contentURL=s,t.tileLoader.get(t.abortController,this.uuid,s,(s=>{t.deleted||(s.traverse((s=>{if(s.isMesh){if(s.layers.disable(0),t.occlusionCullingService){const r=s.geometry.attributes.position,n=[];for(let e=0;e<r.count;e++)n.push(t.color.r,t.color.g,t.color.b);s.geometry.setAttribute("color",new e.Float32BufferAttribute(n,3))}t.static&&(s.matrixAutoUpdate=!1)}})),t.add(s),t.updateWorldMatrix(!1,!0),t.meshContent=s)}),t.cameraOnLoad?()=>t.calculateDistanceToCamera(t.cameraOnLoad):()=>0,(()=>t.getSiblings()),t.level,!!t.json.boundingVolume.region,t.geometricError)):s.includes(".json")&&t.tileLoader.get(t.abortController,this.uuid,s,(e=>{t.deleted||(t.json.children||(t.json.children=[]),e.rootPath=Fe.dirname(s),t.json.children.push(e),delete t.json.content,t.hasUnloadedJSONContent=!1)})))}}dispose(){const e=this;e.childrenTiles.forEach((e=>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"})}disposeChildren(){var e=this;e.childrenTiles.forEach((e=>e.dispose())),e.childrenTiles=[],e.children=[],e.meshContent&&e.children.push(e.meshContent)}update(t){const s=new e.Frustum;s.setFromProjectionMatrix((new e.Matrix4).multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse)),this._update(t,s)}_update(e,t){const s=this,r=s.materialVisibility;function n(e){if(s.hasMeshContent&&s.meshContent){if(e<0)return s.inFrustum=!1,void s.changeContentVisibility(!!s.loadOutsideView);if(s.inFrustum=!0,0!=s.childrenTiles.length){if(e>=s.geometricErrorMultiplier*s.geometricError)s.changeContentVisibility(!0);else if(e<s.geometricErrorMultiplier*s.geometricError){let e=!0;s.childrenTiles.every((t=>!!t.isReady()||(e=!1,!1))),e&&s.changeContentVisibility(!1)}}else s.changeContentVisibility(!0)}}s.boundingVolume&&s.geometricError&&(s.metric=s.calculateUpdateMetric(e,t)),s.childrenTiles.forEach((s=>s._update(e,t))),n(s.metric),function(t){if(t<0&&s.hasMeshContent)return;if(s.occlusionCullingService&&s.hasMeshContent&&!s.occlusionCullingService.hasID(s.colorID))return;if((!s.hasMeshContent||t<s.geometricErrorMultiplier*s.geometricError&&s.meshContent)&&s.json&&s.json.children&&s.childrenTiles.length!=s.json.children.length)s.json.children.forEach((t=>{let r=new Ne({parentTile:s,parentGeometricError:s.geometricError,parentBoundingVolume:s.boundingVolume,parentRefinement:s.refinement,json:t,rootPath:s.rootPath,geometricErrorMultiplier:s.geometricErrorMultiplier,loadOutsideView:s.loadOutsideView,level:s.level+1,tileLoader:s.tileLoader,cameraOnLoad:e,occlusionCullingService:s.occlusionCullingService,renderer:s.renderer,static:s.static,centerModel:!1});s.childrenTiles.push(r),s.add(r)}))}(s.metric),function(e,t){if(!s.hasMeshContent)return;if(!s.inFrustum)return s.disposeChildren(),void n(e);if(s.occlusionCullingService&&!t&&s.hasMeshContent&&s.meshContent&&s.meshDisplayed&&s.areAllChildrenLoadedAndHidden())return s.disposeChildren(),void n(e);if(e>=s.geometricErrorMultiplier*s.geometricError)s.disposeChildren(),n()}(s.metric,r)}areAllChildrenLoadedAndHidden(){let e=!0;const t=this;return this.childrenTiles.every((s=>{if(s.hasMeshContent){if(s.childrenTiles.length>0)return e=!1,!1;if(!s.inFrustum)return!0;if(!s.materialVisibility||s.meshDisplayed)return e=!1,!1;if(t.occlusionCullingService.hasID(s.colorID))return e=!1,!1}else if(!s.areAllChildrenLoadedAndHidden())return e=!1,!1;return!0})),e}isReady(){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((t=>!!t.isReady()||(e=!1,!1))),e}return!this.hasMeshContent||!!this.meshContent&&(!!this.materialVisibility&&!!this.meshDisplayed)}changeContentVisibility(e){const t=this;function s(e,s){e.material.visible=s,s&&(e.onAfterRender=()=>{delete e.onAfterRender,t.meshDisplayed=!0})}t.hasMeshContent&&t.meshContent&&(e?t.meshContent.traverse((e=>{e.isMesh&&e.layers.enable(0)})):t.meshContent.traverse((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&&s(t,e)})):t.meshContent.scenes&&t.meshContent.scenes.forEach((t=>t.traverse((function(t){t.material&&s(t,e)})))))}calculateUpdateMetric(t,s){if(this.boundingVolume instanceof o){if(Ie.copy(this.boundingVolume.sphere),Ie.applyMatrix4(this.matrixWorld),!s.intersectsSphere(Ie))return-1}else{if(!(this.boundingVolume instanceof e.Sphere))return console.error("unsupported shape"),-1;if(Ie.copy(this.boundingVolume),Ie.applyMatrix4(this.matrixWorld),!s.intersectsSphere(Ie))return-1}const r=Math.max(0,t.position.distanceTo(Ie.center)-Ie.radius);if(0==r)return 0;const n=this.matrixWorld.getMaxScaleOnAxis();this.renderer&&this.renderer.getDrawingBufferSize(Ve);let i=Ve.y,a=t.fov;t.aspect<1&&(a*=t.aspect,i=Ve.x);let l=2*Math.tan(.5*a*.017453292519943295)*r;return 16*window.devicePixelRatio*l/(i*n)}getSiblings(){const e=this,t=[];if(!e.parentTile)return t;let s=e.parentTile;for(;!s.hasMeshContent&&s.parentTile;)s=s.parentTile;return s.childrenTiles.forEach((s=>{if(s&&s!=e){for(;!s.hasMeshContent&&s.childrenTiles[0];)s=s.childrenTiles[0];t.push(s)}})),t}calculateDistanceToCamera(t){return this.boundingVolume instanceof o?(Ie.copy(this.boundingVolume.sphere),Ie.applyMatrix4(this.matrixWorld)):this.boundingVolume instanceof e.Sphere?(Ie.copy(this.boundingVolume),Ie.applyMatrix4(this.matrixWorld)):console.error("unsupported shape"),Math.max(0,t.position.distanceTo(Ie.center)-Ie.radius)}setGeometricErrorMultiplier(e){this.geometricErrorMultiplier=e,this.childrenTiles.forEach((t=>t.setGeometricErrorMultiplier(e)))}transformWGS84ToCartesian(e,t,s,r){const n=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(t),2)),i=Math.cos(t),o=Math.cos(e),a=Math.sin(t),l=n+s,c=l*i*o,h=l*i*Math.sin(e),d=(.993305615557957*n+s)*a;r.set(c,h,d)}}const Ge=new e.Sphere(new e.Vector3(0,0,0),1),He=new e.Vector3(0,0,0),Ke=new e.Vector3(0,0,0),We=new e.Vector3(0,1,0),ze=new e.Vector2,Xe=new e.Quaternion,qe=new e.Matrix4;class Je extends e.Object3D{constructor(t){super();const s=this;this.uuid=je(),t.tileLoader?this.tileLoader=t.tileLoader:console.error("an instanced tileset must be provided an InstancedTilesetLoader"),this.master=t.master,this.meshCallback=t.meshCallback,this.loadOutsideView=t.loadOutsideView,this.cameraOnLoad=t.cameraOnLoad,this.parentTile=t.parentTile,this.childrenTiles=[],this.jsonChildren=[],this.meshContent,this.tileContent,this.refinement,this.rootPath,this.geometricError,this.boundingVolume,this.json,this.materialVisibility=!1,this.inFrustum=!0,this.level=t.level?t.level:0,this.hasMeshContent=!1,this.hasUnloadedJSONContent=!1,this.centerModel=t.centerModel,this.deleted=!1,this.abortController=new AbortController,t.json?(this.rootPath=t.json.rootPath?t.json.rootPath:t.rootPath,t.json.children&&(this.jsonChildren=t.json.children),s.setup(t),t.onLoadCallback&&t.onLoadCallback(s)):t.url&&(this.loadJson=(r,n)=>{const i=Fe.dirname(n);if(s.setup({rootPath:i,json:r}),s.centerModel){const t=new e.Sphere;s.boundingVolume instanceof o?t.copy(s.boundingVolume.sphere):s.boundingVolume instanceof e.Sphere&&t.copy(s.boundingVolume),this.json.boundingVolume.region&&(s.transformWGS84ToCartesian(.5*(s.json.boundingVolume.region[0]+s.json.boundingVolume.region[2]),.5*(s.json.boundingVolume.region[1]+s.json.boundingVolume.region[3]),.5*(s.json.boundingVolume.region[4]+s.json.boundingVolume.region[5]),He),Xe.setFromUnitVectors(He.normalize(),We.normalize()),s.master.applyQuaternion(Xe),s.master.updateWorldMatrix(!1,!1)),qe.makeTranslation(-t.center.x*s.scale.x,-t.center.y*s.scale.y,-t.center.z*s.scale.z),s.master.matrix.multiply(qe),s.master.matrix.decompose(s.master.position,s.master.quaternion,s.master.scale)}t.onLoadCallback&&t.onLoadCallback(s)},s.tileLoader.get(s.abortController,t.url,s.uuid,s))}setup(t){if(this.isSetup=!0,t.json.root?(this.json=t.json.root,this.jsonChildren=this.json.children,this.json.refinement||(this.json.refinement=t.json.refinement),this.json.geometricError||(this.json.geometricError=t.json.geometricError),this.json.transform||(this.json.transform=t.json.transform),this.json.boundingVolume||(this.json.boundingVolume=t.json.boundingVolume)):this.json=t.json,this.rootPath=t.json.rootPath?t.json.rootPath:t.rootPath,this.json.refinement?this.refinement=this.json.refinement:this.refinement=t.parentRefinement,this.json.geometricError?this.geometricError=this.json.geometricError:this.geometricError=t.parentGeometricError,this.json.transform&&!this.centerModel){let t=new e.Matrix4;t.elements=this.json.transform,this.master.applyMatrix4(t)}if(this.json.boundingVolume)if(this.json.boundingVolume.box)this.boundingVolume=new o(this.json.boundingVolume.box);else if(this.json.boundingVolume.region){const t=this.json.boundingVolume.region;this.transformWGS84ToCartesian(t[0],t[1],t[4],He),this.transformWGS84ToCartesian(t[2],t[3],t[5],Ke),He.lerp(Ke,.5),this.boundingVolume=new e.Sphere(new e.Vector3(He.x,He.y,He.z),He.distanceTo(Ke))}else if(this.json.boundingVolume.sphere){const t=this.json.boundingVolume.sphere;this.boundingVolume=new e.Sphere(new e.Vector3(t[0],t[2],-t[1]),t[3])}else this.boundingVolume=t.parentBoundingVolume;else this.boundingVolume=t.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())}isAbsolutePathOrURL(e){const t=/^(?:http|https|ftp|tcp|udp):\/\/\S+/.test(e),s=e.startsWith("/")&&!e.startsWith("//");return t||s}load(){var e=this;if(!e.deleted){if(e.json.content){let t;e.json.content.uri?t=Fe.isAbsolute(e.json.content.uri)||e.isAbsolutePathOrURL(e.json.content.uri)?e.json.content.uri:e.rootPath+Fe.sep+e.json.content.uri:e.json.content.url&&(t=Fe.isAbsolute(e.json.content.url)||e.isAbsolutePathOrURL(e.json.content.url)?e.json.content.url:e.rootPath+Fe.sep+e.json.content.url),t&&(t.includes(".b3dm")||t.includes(".glb")||t.includes(".gltf")?(e.contentURL=t,e.tileLoader.get(e.abortController,t,e.uuid,e,e.cameraOnLoad?()=>e.calculateDistanceToCamera(e.cameraOnLoad):()=>0,(()=>e.getSiblings()),e.level,!!e.json.boundingVolume.region,e.geometricError)):t.includes(".json")&&e.tileLoader.get(e.abortController,t,e.uuid,e))}e.matrixWorldNeedsUpdate=!0,e.updateWorldMatrix(!0,!0)}}loadMesh(e){this.deleted||(this.meshContent=e)}loadJson(e,t){this.deleted||(this.json.children&&(this.jsonChildren=this.json.children),e.rootPath=Fe.dirname(t),this.jsonChildren.push(e),this.hasUnloadedJSONContent=!1)}dispose(){const e=this;e.childrenTiles.forEach((e=>e.dispose())),e.deleted=!0,e.abortController&&e.abortController.abort(),this.parent=null,this.parentTile=null,this.dispatchEvent({type:"removed"})}disposeChildren(){this.childrenTiles.forEach((e=>e.dispose())),this.childrenTiles=[]}_update(e,t){const s=this;s.materialVisibility;function r(e){if(s.hasMeshContent&&s.meshContent){if(e<0)return s.inFrustum=!1,void s.changeContentVisibility(!!s.loadOutsideView);if(s.inFrustum=!0,0!=s.childrenTiles.length){if(e>=s.master.geometricErrorMultiplier*s.geometricError)s.changeContentVisibility(!0);else if(e<s.master.geometricErrorMultiplier*s.geometricError){let e=!0;s.childrenTiles.every((t=>!!t.isReady()||(e=!1,!1))),e&&s.changeContentVisibility(!1)}}else s.changeContentVisibility(!0)}}s.boundingVolume&&s.geometricError&&(s.metric=s.calculateUpdateMetric(e,t)),s.childrenTiles.forEach((s=>s._update(e,t))),r(s.metric),function(t){if(t<0&&s.hasMeshContent)return;if((!s.hasMeshContent&&s.rootPath||t<s.master.geometricErrorMultiplier*s.geometricError&&s.meshContent)&&s.json&&s.jsonChildren&&s.childrenTiles.length!=s.jsonChildren.length)s.jsonChildren.forEach((t=>{let r=new Je({parentTile:s,parentGeometricError:s.geometricError,parentBoundingVolume:s.boundingVolume,parentRefinement:s.refinement,json:t,rootPath:s.rootPath,loadOutsideView:s.loadOutsideView,level:s.level+1,tileLoader:s.tileLoader,cameraOnLoad:e,master:s.master,centerModel:!1});s.childrenTiles.push(r)}))}(s.metric),function(e,t){if(!s.hasMeshContent)return;if(!s.inFrustum)return s.disposeChildren(),void r(e);if(e>=s.master.geometricErrorMultiplier*s.geometricError)s.disposeChildren(),r(e)}(s.metric)}areAllChildrenLoadedAndHidden(){let e=!0;return this.childrenTiles.every((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}isReady(){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((t=>!!t.isReady()||(e=!1,!1))),e}return!this.hasMeshContent||!!this.meshContent&&(!!this.materialVisibility&&!!this.meshContent.displayedOnce)}changeContentVisibility(e){this.materialVisibility=e}calculateUpdateMetric(t,s){if(this.boundingVolume instanceof o){if(Ge.copy(this.boundingVolume.sphere),Ge.applyMatrix4(this.master.matrixWorld),!s.intersectsSphere(Ge))return-1}else{if(!(this.boundingVolume instanceof e.Sphere))return console.error("unsupported shape"),-1;if(Ge.copy(this.boundingVolume),Ge.applyMatrix4(this.master.matrixWorld),!s.intersectsSphere(Ge))return-1}if(this.boundingVolume instanceof o||this.boundingVolume instanceof e.Sphere){const e=Math.max(0,t.position.distanceTo(Ge.center)-Ge.radius);if(0==e)return 0;const s=this.master.matrixWorld.getMaxScaleOnAxis();this.master.renderer.getDrawingBufferSize(ze);let r=ze.y,n=t.fov;t.aspect<1&&(n*=t.aspect,r=ze.x);let i=2*Math.tan(.5*n*.017453292519943295)*e;return 16*window.devicePixelRatio*i/(r*s)}if(this.boundingVolume instanceof e.Box3)return-1}getSiblings(){const e=this,t=[];if(!e.parentTile)return t;let s=e.parentTile;for(;!s.hasMeshContent&&s.parentTile;)s=s.parentTile;return s.childrenTiles.forEach((s=>{if(s&&s!=e){for(;!s.hasMeshContent&&s.childrenTiles[0];)s=s.childrenTiles[0];t.push(s)}})),t}calculateDistanceToCamera(t){return this.boundingVolume instanceof o?(Ge.copy(this.boundingVolume.sphere),Ge.applyMatrix4(this.master.matrixWorld)):this.boundingVolume instanceof e.Sphere?(Ge.copy(this.boundingVolume),Ge.applyMatrix4(this.master.matrixWorld)):console.error("unsupported shape"),Math.max(0,t.position.distanceTo(Ge.center)-Ge.radius)}getWorldMatrix(){return this.master.matrixWorld}transformWGS84ToCartesian(e,t,s,r){const n=6378137/Math.sqrt(1-.006694384442042*Math.pow(Math.sin(t),2)),i=Math.cos(t),o=Math.cos(e),a=Math.sin(t),l=n+s,c=l*i*o,h=l*i*Math.sin(e),d=(.993305615557957*n+s)*a;r.set(c,h,d)}}class Ye extends e.Object3D{constructor(e){super(),e.master=this,this.renderer=e.renderer,this.geometricErrorMultiplier=e.geometricErrorMultiplier?e.geometricErrorMultiplier:1,this.tileset=new Je(e),e.static&&(this.matrixAutoUpdate=!1)}update(t,s){if(s)this.tileset._update(t,s);else{const s=new e.Frustum;s.setFromProjectionMatrix((new e.Matrix4).multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse)),this.tileset._update(t,s)}}updateWithFrustum(e,t){this.tileset._update(e,t)}setGeometricErrorMultiplier(e){this.geometricErrorMultiplier=e||1}}const Qe=new e.Matrix4;class Ze{constructor(t){const s=this;s.scene=t,s.instancedTiles=[],s.instancedMesh,s.reuseableMatrix=new e.Matrix4}addInstance(e){const t=this;e.added=!0,e.listOMesh=t.instancedTiles,t.instancedTiles.push(e),t.instancedMesh&&e.loadMesh(t.instancedMesh)}addToScene(){const t=this;t.instancedMesh.setMatrixAt(0,new e.Matrix4),t.instancedMesh.instanceMatrix.needsUpdate=!0,t.instancedMesh.count=1,t.scene.add(t.instancedMesh),t.instancedMesh.onAfterRender=()=>{delete t.instancedMesh.onAfterRender,t.instancedMesh.displayedOnce=!0}}setObject(e){const t=this;t.instancedMesh=e;for(let e=0;e<t.instancedTiles.length;e++)t.instancedTiles[e].loadMesh(t.instancedMesh)}update(){const e=this;for(let 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(let t=0;t<e.instancedTiles.length;t++)e.instancedTiles[t].meshContent=e.instancedMesh,e.instancedTiles[t].materialVisibility&&e.instancedTiles[t].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[t].master.matrixWorld),e.reuseableMatrix.multiply(e.instancedMesh.baseMatrix),e.instancedMesh.setMatrixAt(e.instancedMesh.count-1,e.reuseableMatrix),e.instancedMesh.getMatrixAt(0,Qe),console.log());e.instancedMesh.instanceMatrix.needsUpdate=!0}}getCount(){return this.instancedTiles.length}}class $e{constructor(){const e=this;e.count=0,e.json,e.instancedTiles=[]}addInstance(e){this.instancedTiles.push(e),this.json&&e.loadJson(this.json,this.url)}setObject(e,t){const s=this;s.json=e,s.url=t;for(let e=0;e<s.instancedTiles.length;e++)s.instancedTiles[e].loadJson(s.json,s.url)}getCount(){return this.instancedTiles.length}update(){const e=this;for(let t=e.instancedTiles.length-1;t>=0;t--)e.instancedTiles[t].deleted&&e.instancedTiles.splice(t,1)}}let et=0;const tt=new e.Matrix4;tt.set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);class st{constructor(e,t){this.maxCachedItems=100,this.maxInstances=1,t&&(this.meshCallback=t.meshCallback,this.pointsCallback=t.pointsCallback,t.maxCachedItems&&(this.maxCachedItems=t.maxCachedItems),t.maxInstances&&(this.maxInstances=t.maxInstances)),this.gltfLoader=new l;const s=new ce;if(s.setDecoderPath("https://www.gstatic.com/draco/versioned/decoders/1.4.3/"),this.gltfLoader.setDRACOLoader(s),t&&t.renderer){const e=new me;e.setTranscoderPath("https://storage.googleapis.com/ogc-3d-tiles/basis/").detectSupport(t.renderer),this.gltfLoader.setKTX2Loader(e),this.b3dmDecoder=new xe(t.renderer)}else this.b3dmDecoder=new xe(null);this.cache=new a.LinkedHashMap,this.scene=e,this.ready=[],this.downloads=[],this.nextReady=[],this.nextDownloads=[],this.init()}update(){this.cache._data.forEach((e=>{e.update()}))}init(){const e=this;rt((()=>{e.download()}),10),rt((()=>{const t=Date.now();let s=0;do{s=e.loadBatch()}while(s>0&&Date.now()-t<=0)}),10)}download(){const t=this;if(0!=t.nextDownloads.length||(t.getNextDownloads(),0!=t.nextDownloads.length))for(;t.nextDownloads.length>0&&et<500;){const s=t.nextDownloads.shift();s&&s.shouldDoDownload()&&(et++,s.path.includes(".b3dm")&&fetch(s.path,{signal:s.abortController.signal}).then((e=>{if(et--,!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((e=>this.b3dmDecoder.parseB3DMInstanced(e,t.meshCallback,t.maxInstances,s.zUpToYUp))).then((e=>{s.tile.setObject(e),t.ready.unshift(s)})).catch((e=>console.error(e))),s.path.includes(".glb")||s.path.includes(".gltf")?this.gltfLoader.load(s.path,(r=>{let n;r.scene.traverse((e=>{e.geometricError=s.geometricError,e.isMesh&&(s.zUpToYUp&&e.applyMatrix4(tt),t.meshCallback&&t.meshCallback(e)),e.isPoints&&console.error("instanced point cloud is not supported")})),r.scene.updateWorldMatrix(!1,!0),r.scene.traverse((s=>{s.isMesh&&(n=new e.InstancedMesh(s.geometry,s.material,t.maxInstances),n.baseMatrix=s.matrixWorld)})),t.ready.unshift(s),n?s.tile.setObject(n):r.scene.traverse((e=>{e.dispose&&e.dispose(),e.material&&e.material.dispose()}))})):s.path.includes(".json")&&(et++,fetch(s.path,{signal:s.abortController.signal}).then((e=>{if(et--,!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((e=>{s.tile.setObject(e,s.path),t.ready.unshift(s)})).catch((e=>console.error(e)))))}}loadBatch(){if(0==this.nextReady.length&&(this.getNextReady(),0==this.nextReady.length))return 0;const e=this.nextReady.shift();return e?(e.tile.addToScene&&e.tile.addToScene(),1):0}getNextReady(){let e=Number.MAX_VALUE,t=-1;for(let e=this.ready.length-1;e>=0;e--)this.ready[e].distanceFunction||this.nextReady.push(this.ready.splice(e,1)[0]);if(!(this.nextReady.length>0)){for(let s=this.ready.length-1;s>=0;s--){const r=this.ready[s].distanceFunction()*this.ready[s].level;r<e&&(e=r,t=s)}if(t>=0){const e=this.ready.splice(t,1).pop();this.nextReady.push(e);const s=e.getSiblings();for(let e=this.ready.length-1;e>=0;e--)s.includes(this.ready[e].uuid)&&this.nextready.push(this.ready.splice(e,1).pop())}}}get(e,t,s,r,n,i,o,a,l){const c=this,h=function(e){for(var t=e.split("/"),s=[],r=0,n=0;n<t.length;n++){var i=t[n];"."!==i&&""!==i&&".."!==i?s[r++]=i:".."===i&&r>0&&r--}if(0===r)return"/";var o="";for(n=0;n<r;n++)o+="/"+s[n];return o}(t);if(!(t.includes(".b3dm")||t.includes(".json")||t.includes(".glb")||t.includes(".gltf")))return void console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data");const d=c.cache.get(h);if(d)d.addInstance(r);else if(t.includes(".b3dm")||t.includes(".glb")||t.includes(".gltf")){const d=new Ze(c.scene);d.addInstance(r),c.cache.put(h,d);const u=new AbortController;e.signal.addEventListener("abort",(()=>{0==d.getCount()&&u.abort()})),this.downloads.push({abortController:u,tile:d,key:h,path:t,distanceFunction:n,getSiblings:i,level:o,uuid:s,zUpToYUp:a,geometricError:l,shouldDoDownload:()=>!0})}else if(t.includes(".json")){const s=new $e;s.addInstance(r),c.cache.put(h,s);const a=new AbortController;e.signal.addEventListener("abort",(()=>{0==s.getCount()&&a.abort()})),this.downloads.push({abortController:a,tile:s,key:h,path:t,distanceFunction:n,getSiblings:i,level:o,shouldDoDownload:()=>!0})}}getNextDownloads(){let e=Number.MAX_VALUE,t=-1;for(let e=this.downloads.length-1;e>=0;e--){const t=this.downloads[e];t.shouldDoDownload()?t.distanceFunction||this.nextDownloads.push(this.downloads.splice(e,1)[0]):this.downloads.splice(e,1)}if(!(this.nextDownloads.length>0)){for(let s=this.downloads.length-1;s>=0;s--){const r=this.downloads[s],n=r.distanceFunction()*r.level;n<e&&(e=n,t=s)}if(t>=0){const e=this.downloads.splice(t,1).pop();this.nextDownloads.push(e);const s=e.getSiblings();for(let e=this.downloads.length-1;e>=0;e--)s.includes(this.downloads[e].uuid)&&this.nextDownloads.push(this.downloads.splice(e,1).pop())}}}checkSize(){const e=this;let t=0;for(;e.cache.size()>e.maxCachedItems&&t<e.cache.size();){t++;const s=e.cache.head();s.value.getCount()>0?(e.cache.remove(s.key),e.cache.put(s.key,s.value)):(e.cache.remove(s.key),s.value.instancedMesh&&s.value.instancedMesh.traverse((e=>{if(e.material)if(e.material.length)for(let t=0;t<e.material.length;++t)e.material[t].dispose();else e.material.dispose();e.geometry&&e.geometry.dispose()})))}}}function rt(e,t){let s;const r=async()=>{const n=Date.now();try{await e()}catch(e){console.error(e)}finally{const e=Date.now()-n;s=setTimeout(r,e>=t?0:t-e)}};return s=setTimeout(r,t),{clearInterval:()=>clearTimeout(s)}}})(),n})()));
3
3
  //# sourceMappingURL=threedtiles.min.js.map
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@jdultra/threedtiles",
3
- "version": "9.0.5",
3
+ "version": "9.0.6",
4
4
  "description": "An OGC 3DTiles viewer for Three.js",
5
5
  "main": "dist/threedtiles.min.js",
6
6
  "files": [
7
7
  "dist/threedtiles.min.js",
8
8
  "README.md",
9
9
  "LICENSE"
10
- ],
10
+ ],
11
11
  "scripts": {
12
12
  "build": "webpack --config webpack.prod.config.js",
13
13
  "watch": "webpack --watch --config webpack.dev.config.js",
@@ -27,7 +27,6 @@
27
27
  ],
28
28
  "author": "Emeric Beaufays",
29
29
  "license": "MIT",
30
-
31
30
  "peerDependencies": {
32
31
  "three": "^0.140.0"
33
32
  },
@@ -54,4 +53,4 @@
54
53
  "webpack-node-externals": "^3.0.0",
55
54
  "whatwg-fetch": "^3.5.0"
56
55
  }
57
- }
56
+ }