@soonspacejs/plugin-tiles 2.13.15 → 2.13.17
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.
- package/dist/index.esm.js +1 -1
- package/package.json +4 -3
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"soonspacejs";import{GLTFLoader as t}from"three/examples/jsm/loaders/GLTFLoader.js";import*as s from"three";import{Matrix4 as r,DefaultLoadingManager as n,Vector2 as i,MathUtils as a,Vector3 as o,PointsMaterial as l,BufferGeometry as c,BufferAttribute as h,Color as d,Points as u,Spherical as p,Sphere as m,Euler as g,Ray as f,InstancedMesh as _,Quaternion as b,Group as y,Plane as w,Box3 as T,Matrix3 as x,Frustum as S,LoadingManager as C,EventDispatcher as v}from"three";import{estimateBytesUsed as P}from"three/examples/jsm/utils/BufferGeometryUtils.js";function E(e){if(!e)return null;const t=e.replace(/[a-z]+:\/\/[^/]+/i,"").replace(/\?.*$/i,"").replace(/.*\//g,""),s=t.lastIndexOf(".");return-1===s?null:t.substring(s+1)||null}class M{get unloadPriorityCallback(){return this._unloadPriorityCallback}set unloadPriorityCallback(e){1===e.length?(console.warn('LRUCache: "unloadPriorityCallback" function has been changed to take two arguments.'),this._unloadPriorityCallback=(t,s)=>{const r=e(t),n=e(s);return r<n?-1:r>n?1:0}):this._unloadPriorityCallback=e}constructor(){this.minSize=6e3,this.maxSize=8e3,this.minBytesSize=322122547.2,this.maxBytesSize=429496729.6,this.unloadPercent=.05,this.autoMarkUnused=!0,this.itemSet=new Map,this.itemList=[],this.usedSet=new Set,this.callbacks=new Map,this.unloadingHandle=-1,this.cachedBytes=0,this.bytesMap=new Map,this.loadedSet=new Set,this._unloadPriorityCallback=null;const e=this.itemSet;this.defaultPriorityCallback=t=>e.get(t)}isFull(){return this.itemSet.size>=this.maxSize||this.cachedBytes>=this.maxBytesSize}getMemoryUsage(e){return this.bytesMap.get(e)||0}setMemoryUsage(e,t){const{bytesMap:s,itemSet:r}=this;r.has(e)&&(this.cachedBytes-=s.get(e)||0,s.set(e,t),this.cachedBytes+=t)}add(e,t){const s=this.itemSet;if(s.has(e))return!1;if(this.isFull())return!1;const r=this.usedSet,n=this.itemList,i=this.callbacks;return n.push(e),r.add(e),s.set(e,Date.now()),i.set(e,t),!0}has(e){return this.itemSet.has(e)}remove(e){const t=this.usedSet,s=this.itemSet,r=this.itemList,n=this.bytesMap,i=this.callbacks,a=this.loadedSet;if(s.has(e)){this.cachedBytes-=n.get(e)||0,n.delete(e),i.get(e)(e);const o=r.indexOf(e);return r.splice(o,1),t.delete(e),s.delete(e),i.delete(e),a.delete(e),!0}return!1}setLoaded(e,t){const{itemSet:s,loadedSet:r}=this;s.has(e)&&(!0===t?r.add(e):r.delete(e))}markUsed(e){const t=this.itemSet,s=this.usedSet;t.has(e)&&!s.has(e)&&(t.set(e,Date.now()),s.add(e))}markUnused(e){this.usedSet.delete(e)}markAllUnused(){this.usedSet.clear()}unloadUnusedContent(){const{unloadPercent:e,minSize:t,maxSize:s,itemList:r,itemSet:n,usedSet:i,loadedSet:a,callbacks:o,bytesMap:l,minBytesSize:c,maxBytesSize:h}=this,d=r.length-i.size,u=r.length-a.size,p=Math.max(Math.min(r.length-t,d),0),m=this.cachedBytes-c,g=this.unloadPriorityCallback||this.defaultPriorityCallback;let f=!1;const _=p>0&&d>0||u&&r.length>s;if(d&&this.cachedBytes>c||u&&this.cachedBytes>h||_){r.sort((e,t)=>{const s=i.has(e);if(s===i.has(t)){const s=a.has(e);return s===a.has(t)?-g(e,t):s?1:-1}return s?1:-1});const u=Math.max(t*e,p*e),_=Math.ceil(Math.min(u,d,p)),b=Math.max(e*m,e*c),y=Math.min(b,m);let w=0,T=0;for(;this.cachedBytes-T>h||r.length-w>s;){const e=r[w],t=l.get(e)||0;if(i.has(e)&&a.has(e)||this.cachedBytes-T-t<h&&r.length-w<=s)break;T+=t,w++}for(;T<y||w<_;){const e=r[w],t=l.get(e)||0;if(i.has(e)||this.cachedBytes-T-t<c&&w>=_)break;T+=t,w++}r.splice(0,w).forEach(e=>{this.cachedBytes-=l.get(e)||0,o.get(e)(e),l.delete(e),n.delete(e),o.delete(e),a.delete(e),i.delete(e)}),f=w<p||T<m&&w<d,f=f&&w>0}f&&(this.unloadingHandle=requestAnimationFrame(()=>this.scheduleUnload()))}scheduleUnload(){cancelAnimationFrame(this.unloadingHandle),this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{this.scheduled=!1,this.unloadUnusedContent()}))}}class L{get running(){return 0!==this.items.length||0!==this.currJobs}constructor(){this.maxJobs=6,this.items=[],this.callbacks=new Map,this.currJobs=0,this.scheduled=!1,this.autoUpdate=!0,this.priorityCallback=null,this.schedulingCallback=e=>{requestAnimationFrame(e)},this._runjobs=()=>{this.scheduled=!1,this.tryRunJobs()}}sort(){const e=this.priorityCallback,t=this.items;null!==e&&t.sort(e)}has(e){return this.callbacks.has(e)}add(e,t){const s={callback:t,reject:null,resolve:null,promise:null};return s.promise=new Promise((t,r)=>{const n=this.items,i=this.callbacks;s.resolve=t,s.reject=r,n.unshift(e),i.set(e,s),this.autoUpdate&&this.scheduleJobRun()}),s.promise}remove(e){const t=this.items,s=this.callbacks,r=t.indexOf(e);if(-1!==r){const n=s.get(e);n.promise.catch(()=>{}),n.reject(new Error("PriorityQueue: Item removed.")),t.splice(r,1),s.delete(e)}}removeByFilter(e){const{items:t}=this;for(let s=0;s<t.length;s++){const r=t[s];e(r)&&this.remove(r)}}tryRunJobs(){this.sort();const e=this.items,t=this.callbacks,s=this.maxJobs;let r=0;const n=()=>{this.currJobs--,this.autoUpdate&&this.scheduleJobRun()};for(;s>this.currJobs&&e.length>0&&r<s;){this.currJobs++,r++;const s=e.pop(),{callback:i,resolve:a,reject:o}=t.get(s);let l;t.delete(s);try{l=i(s)}catch(e){o(e),n()}l instanceof Promise?l.then(a).catch(o).finally(n):(a(l),n())}}scheduleJobRun(){this.scheduled||(this.schedulingCallback(this._runjobs),this.scheduled=!0)}}const F=-1,R=6378137,U={inView:!1,error:1/0,distanceFromCamera:1/0};function A(e){return 3===e||e===F}function O(e,t){return e.__lastFrameVisited===t&&e.__used}function k(e){return e.__childrenProcessed===e.children.length}function D(e,t){e.__lastFrameVisited!==t.frameCount&&(e.__lastFrameVisited=t.frameCount,e.__used=!1,e.__inFrustum=!1,e.__isLeaf=!1,e.__visible=!1,e.__active=!1,e.__error=1/0,e.__distanceFromCamera=1/0,e.__allChildrenLoaded=!1,t.calculateTileViewError(e,U),e.__inFrustum=U.inView,e.__error=U.error,e.__distanceFromCamera=U.distanceFromCamera)}function B(e,t){if(t.ensureChildrenArePreprocessed(e),D(e,t),I(e,t),e.__hasUnrenderableContent&&k(e)){const s=e.children;for(let e=0,r=s.length;e<r;e++)B(s[e],t)}}function N(e,t){if(t.ensureChildrenArePreprocessed(e),O(e,t.frameCount)&&(e.__hasContent&&t.queueTileForDownload(e),k(e))){const s=e.children;for(let e=0,r=s.length;e<r;e++)N(s[e],t)}}function I(e,t){e.__used||(e.__used=!0,t.markTileUsed(e),t.stats.used++,!0===e.__inFrustum&&t.stats.inFrustum++)}function V(e,t){if(t.ensureChildrenArePreprocessed(e),D(e,t),!e.__inFrustum)return;if(!function(e,t){return!(e.__error<=t.errorTarget&&!e.__hasUnrenderableContent||t.maxDepth>0&&e.__depth+1>=t.maxDepth||!k(e))}(e,t))return void I(e,t);let s=!1,r=!1;const n=e.children;for(let e=0,i=n.length;e<i;e++){const i=n[e];V(i,t),s=s||O(i,t.frameCount),r=r||i.__inFrustum}if(I(e,t),s&&"REPLACE"===e.refine&&(e.__depth,1))for(let e=0,s=n.length;e<s;e++){B(n[e],t)}}function z(e,t){const s=t.frameCount;if(!O(e,s))return;const r=e.children;let n=!1;for(let e=0,t=r.length;e<t;e++){const t=r[e];n=n||O(t,s)}if(n){let n=!0;for(let e=0,i=r.length;e<i;e++){const i=r[e];if(z(i,t),O(i,s)){const e=i.__allChildrenLoaded||!i.__hasContent||i.__hasRenderableContent&&A(i.__loadingState)||i.__hasUnrenderableContent&&i.__loadingState===F;n=n&&e}}e.__allChildrenLoaded=n}else e.__isLeaf=!0}function j(e,t){const s=t.stats;if(!O(e,t.frameCount))return;if(e.__isLeaf)return void(3===e.__loadingState?(e.__inFrustum&&(e.__visible=!0,s.visible++),e.__active=!0,s.active++):e.__hasContent&&t.queueTileForDownload(e));const r=e.children,n=e.__hasContent,i=A(e.__loadingState)&&n,a=(t.errorTarget+1)*t.errorThreshold,o=e.__error<=a,l="ADD"===e.refine,c=e.__allChildrenLoaded||0===e.__depth&&!1;if(n&&(o||l)&&t.queueTileForDownload(e),(o&&i&&!c||i&&l)&&(e.__inFrustum&&(e.__visible=!0,s.visible++),e.__active=!0,s.active++),l||!o||c)for(let e=0,s=r.length;e<s;e++)j(r[e],t);else for(let e=0,s=r.length;e<s;e++){const s=r[e];O(s,t.frameCount)&&N(s,t)}}function W(e,t){const s=O(e,t.frameCount);if(s||e.__usedLastFrame){let r=!1,n=!1;s?(r=e.__active,n=t.displayActiveTiles&&e.__active||e.__visible):D(e,t),e.__hasRenderableContent&&3===e.__loadingState&&(e.__wasSetActive!==r&&t.invokeOnePlugin(t=>t.setTileActive&&t.setTileActive(e,r)),e.__wasSetVisible!==n&&t.invokeOnePlugin(t=>t.setTileVisible&&t.setTileVisible(e,n))),e.__wasSetActive=r,e.__wasSetVisible=n,e.__usedLastFrame=s;const i=e.children;for(let e=0,s=i.length;e<s;e++){W(i[e],t)}}}const q=Symbol("PLUGIN_REGISTERED"),G=(e,t)=>{const s=e.priority||0,r=t.priority||0;return s!==r?s>r?1:-1:e.__used!==t.__used?e.__used?1:-1:e.__error!==t.__error?e.__error>t.__error?1:-1:e.__distanceFromCamera!==t.__distanceFromCamera?e.__distanceFromCamera>t.__distanceFromCamera?-1:1:e.__depthFromRenderedParent!==t.__depthFromRenderedParent?e.__depthFromRenderedParent>t.__depthFromRenderedParent?-1:1:0},H=(e,t)=>{const s=e.priority||0,r=t.priority||0;return s!==r?s>r?1:-1:e.__lastFrameVisited!==t.__lastFrameVisited?e.__lastFrameVisited>t.__lastFrameVisited?-1:1:e.__depthFromRenderedParent!==t.__depthFromRenderedParent?e.__depthFromRenderedParent>t.__depthFromRenderedParent?1:-1:e.__loadingState!==t.__loadingState?e.__loadingState>t.__loadingState?-1:1:e.__hasUnrenderableContent!==t.__hasUnrenderableContent?e.__hasUnrenderableContent?-1:1:e.__error!==t.__error?e.__error>t.__error?-1:1:0};class Q{get root(){const e=this.rootTileSet;return e?e.root:null}get loadProgress(){const{stats:e,isLoading:t}=this,s=e.downloading+e.parsing,r=e.inCacheSinceLoad+(t?1:0);return 0===r?1:1-s/r}get errorThreshold(){return this._errorThreshold}set errorThreshold(e){console.warn('TilesRenderer: The "errorThreshold" option has been deprecated.'),this._errorThreshold=e}constructor(e=null){this.rootLoadingState=0,this.rootTileSet=null,this.rootURL=e,this.fetchOptions={},this.plugins=[],this.queuedTiles=[],this.cachedSinceLoadComplete=new Set,this.isLoading=!1;const t=new M;t.unloadPriorityCallback=H;const s=new L;s.maxJobs=25,s.priorityCallback=G;const r=new L;r.maxJobs=5,r.priorityCallback=G;const n=new L;n.maxJobs=25,this.processedTiles=new WeakSet,this.visibleTiles=new Set,this.activeTiles=new Set,this.usedSet=new Set,this.lruCache=t,this.downloadQueue=s,this.parseQueue=r,this.processNodeQueue=n,this.stats={inCacheSinceLoad:0,inCache:0,parsing:0,downloading:0,failed:0,inFrustum:0,used:0,active:0,visible:0},this.frameCount=0,this._dispatchNeedsUpdateEvent=function(e){let t=null;return()=>{null===t&&(t=requestAnimationFrame(()=>{t=null,e()}))}}(()=>{this.dispatchEvent({type:"needs-update"})}),this.errorTarget=16,this._errorThreshold=1/0,this.displayActiveTiles=!1,this.maxDepth=1/0}registerPlugin(e){if(!0===e[q])throw new Error("TilesRendererBase: A plugin can only be registered to a single tile set");const t=this.plugins,s=e.priority||0;let r=t.length;for(let e=0;e<t.length;e++){if((t[e].priority||0)>s){r=e;break}}t.splice(r,0,e),e[q]=!0,e.init&&e.init(this)}unregisterPlugin(e){const t=this.plugins;if("string"==typeof e&&(e=this.getPluginByName(name)),t.includes(e)){const s=t.indexOf(e);return t.splice(s,1),e.dispose&&e.dispose(),!0}return!1}getPluginByName(e){return this.plugins.find(t=>t.name===e)||null}traverse(e,t,s=!0){this.root&&function(e,t=null,s=null){const r=[];for(r.push(e),r.push(null),r.push(0);r.length>0;){const e=r.pop(),n=r.pop(),i=r.pop();if(t&&t(i,n,e))return void(s&&s(i,n,e));const a=i.children;if(a)for(let t=a.length-1;t>=0;t--)r.push(a[t]),r.push(i),r.push(e+1);s&&s(i,n,e)}}(this.root,(t,...r)=>(s&&this.ensureChildrenArePreprocessed(t,!0),!!e&&e(t,...r)),t)}queueTileForDownload(e){0!==e.__loadingState||this.lruCache.isFull()||this.queuedTiles.push(e)}markTileUsed(e){this.usedSet.add(e),this.lruCache.markUsed(e)}update(){const{lruCache:e,usedSet:t,stats:s,root:r,downloadQueue:n,parseQueue:i,processNodeQueue:a}=this;if(0===this.rootLoadingState&&(this.rootLoadingState=1,this.invokeOnePlugin(e=>e.loadRootTileSet&&e.loadRootTileSet()).then(e=>{let t=this.rootURL;null!==t&&this.invokeAllPlugins(e=>t=e.preprocessURL?e.preprocessURL(t,null):t),this.rootLoadingState=3,this.rootTileSet=e,this.dispatchEvent({type:"needs-update"}),this.dispatchEvent({type:"load-content"}),this.dispatchEvent({type:"load-tile-set",tileSet:e,url:t})}).catch(e=>{this.rootLoadingState=F,console.error(e),this.rootTileSet=null,this.dispatchEvent({type:"load-error",tile:null,error:e,url:this.rootURL})})),!r)return;s.inFrustum=0,s.used=0,s.active=0,s.visible=0,this.frameCount++,t.forEach(t=>e.markUnused(t)),t.clear(),V(r,this),z(r,this),j(r,this),W(r,this);const o=this.queuedTiles;o.sort(e.unloadPriorityCallback);for(let t=0,s=o.length;t<s&&!e.isFull();t++)this.requestTileContents(o[t]);o.length=0,e.scheduleUnload();!1===(n.running||i.running||a.running)&&!0===this.isLoading&&(this.cachedSinceLoadComplete.clear(),s.inCacheSinceLoad=0,this.dispatchEvent({type:"tiles-load-end"}),this.isLoading=!1)}resetFailedTiles(){this.rootLoadingState===F&&(this.rootLoadingState=0);const e=this.stats;0!==e.failed&&(this.traverse(e=>{e.__loadingState===F&&(e.__loadingState=0)},null,!1),e.failed=0)}dispose(){[...this.plugins].forEach(e=>{this.unregisterPlugin(e)});const e=this.lruCache,t=[];this.traverse(e=>(t.push(e),!1),null,!1);for(let s=0,r=t.length;s<r;s++)e.remove(t[s]);this.stats={parsing:0,downloading:0,failed:0,inFrustum:0,used:0,active:0,visible:0},this.frameCount=0}calculateBytesUsed(e,t){return 0}dispatchEvent(e){}fetchData(e,t){return fetch(e,t)}parseTile(e,t,s){return null}disposeTile(e){e.__visible&&(this.invokeOnePlugin(t=>t.setTileVisible&&t.setTileVisible(e,!1)),e.__visible=!1),e.__active&&(this.invokeOnePlugin(t=>t.setTileActive&&t.setTileActive(e,!1)),e.__active=!1)}preprocessNode(e,t,s=null){if(this.processedTiles.add(e),e.content&&(!("uri"in e.content)&&"url"in e.content&&(e.content.uri=e.content.url,delete e.content.url),e.content.boundingVolume&&!("box"in e.content.boundingVolume||"sphere"in e.content.boundingVolume||"region"in e.content.boundingVolume)&&delete e.content.boundingVolume),e.parent=s,e.children=e.children||[],e.content?.uri){const t=E(e.content.uri);e.__hasContent=!0,e.__hasUnrenderableContent=Boolean(t&&/json$/.test(t)),e.__hasRenderableContent=!e.__hasUnrenderableContent}else e.__hasContent=!1,e.__hasUnrenderableContent=!1,e.__hasRenderableContent=!1;e.__childrenProcessed=0,s&&s.__childrenProcessed++,e.__distanceFromCamera=1/0,e.__error=1/0,e.__inFrustum=!1,e.__isLeaf=!1,e.__usedLastFrame=!1,e.__used=!1,e.__wasSetVisible=!1,e.__visible=!1,e.__allChildrenLoaded=!1,e.__wasSetActive=!1,e.__active=!1,e.__loadingState=0,null===s?(e.__depth=0,e.__depthFromRenderedParent=e.__hasRenderableContent?1:0,e.refine=e.refine||"REPLACE"):(e.__depth=s.__depth+1,e.__depthFromRenderedParent=s.__depthFromRenderedParent+(e.__hasRenderableContent?1:0),e.refine=e.refine||s.refine),e.__basePath=t,e.__lastFrameVisited=-1,this.invokeAllPlugins(r=>{r!==this&&r.preprocessNode&&r.preprocessNode(e,t,s)})}setTileActive(e,t){t?this.activeTiles.add(e):this.activeTiles.delete(e)}setTileVisible(e,t){t?this.visibleTiles.add(e):this.visibleTiles.delete(e)}calculateTileViewError(e,t){}ensureChildrenArePreprocessed(e,t=!1){const s=e.children;for(let r=0,n=s.length;r<n;r++){const n=s[r];if("__depth"in n)break;t?(this.processNodeQueue.remove(n),this.preprocessNode(n,e.__basePath,e)):this.processNodeQueue.has(n)||this.processNodeQueue.add(n,t=>{this.preprocessNode(t,e.__basePath,e),this._dispatchNeedsUpdateEvent()})}}getBytesUsed(e){let t=0;return this.invokeAllPlugins(s=>{s.calculateBytesUsed&&(t+=s.calculateBytesUsed(e,e.cached.scene)||0)}),t}recalculateBytesUsed(e=null){const{lruCache:t,processedTiles:s}=this;null===e?t.itemSet.forEach(e=>{s.has(e)&&t.setMemoryUsage(e,this.getBytesUsed(e))}):t.setMemoryUsage(e,this.getBytesUsed(e))}preprocessTileSet(e,t,s=null){const r=e.asset.version,[n,i]=r.split(".").map(e=>parseInt(e));console.assert(n<=1,"TilesRenderer: asset.version is expected to be a 1.x or a compatible version."),1===n&&i>0&&console.warn("TilesRenderer: tiles versions at 1.1 or higher have limited support. Some new extensions and features may not be supported.");let a=t.replace(/\/[^/]*$/,"");a=new URL(a,window.location.href).toString(),this.preprocessNode(e.root,a,s)}loadRootTileSet(){let e=this.rootURL;this.invokeAllPlugins(t=>e=t.preprocessURL?t.preprocessURL(e,null):e);return this.invokeOnePlugin(t=>t.fetchData&&t.fetchData(e,this.fetchOptions)).then(t=>{if(t instanceof Response){if(t.ok)return t.json();throw new Error(`TilesRenderer: Failed to load tileset "${e}" with status ${t.status} : ${t.statusText}`)}return t}).then(t=>(this.preprocessTileSet(t,e),t))}requestTileContents(e){if(0!==e.__loadingState)return;let t=!1,s=null,r=new URL(e.content.uri,e.__basePath+"/").toString();this.invokeAllPlugins(t=>r=t.preprocessURL?t.preprocessURL(r,e):r);const n=this.stats,i=this.lruCache,a=this.downloadQueue,o=this.parseQueue,l=E(r),c=new AbortController,h=c.signal;return i.add(e,s=>{c.abort(),t?(s.children.length=0,s.__childrenProcessed=0):this.invokeAllPlugins(e=>{e.disposeTile&&e.disposeTile(s)}),n.inCache--,this.cachedSinceLoadComplete.has(e)&&(this.cachedSinceLoadComplete.delete(e),n.inCacheSinceLoad--),1===s.__loadingState?n.downloading--:2===s.__loadingState&&n.parsing--,s.__loadingState=0,o.remove(s),a.remove(s)})?(this.isLoading||(this.isLoading=!0,this.dispatchEvent({type:"tiles-load-start"})),i.setMemoryUsage(e,this.getBytesUsed(e)),this.cachedSinceLoadComplete.add(e),n.inCacheSinceLoad++,n.inCache++,n.downloading++,e.__loadingState=1,a.add(e,t=>{if(h.aborted)return Promise.resolve();const s=this.invokeOnePlugin(e=>e.fetchData&&e.fetchData(r,{...this.fetchOptions,signal:h}));return this.dispatchEvent({type:"tile-download-start",tile:e}),s}).then(e=>{if(!h.aborted){if(e instanceof Response){if(e.ok)return"json"===l?e.json():e.arrayBuffer();throw new Error(`Failed to load model with error code ${e.status}`)}return e}}).then(i=>{if(!h.aborted)return n.downloading--,n.parsing++,e.__loadingState=2,o.add(e,n=>h.aborted?Promise.resolve():"json"===l&&i.root?(this.preprocessTileSet(i,r,e),e.children.push(i.root),s=i,t=!0,Promise.resolve()):this.invokeOnePlugin(e=>e.parseTile&&e.parseTile(i,n,l,r,h)))}).then(()=>{if(h.aborted)return;n.parsing--,e.__loadingState=3,i.setLoaded(e,!0);const a=this.getBytesUsed(e);0===i.getMemoryUsage(e)&&a>0&&i.isFull()?i.remove(e):(i.setMemoryUsage(e,a),this.dispatchEvent({type:"needs-update"}),this.dispatchEvent({type:"load-content"}),t&&this.dispatchEvent({type:"load-tile-set",tileSet:s,url:r}),e.cached.scene&&this.dispatchEvent({type:"load-model",scene:e.cached.scene,tile:e}))}).catch(t=>{h.aborted||("AbortError"!==t.name?(o.remove(e),a.remove(e),2===e.__loadingState?n.parsing--:1===e.__loadingState&&n.downloading--,n.failed++,console.error(`TilesRenderer : Failed to load tile at url "${e.content.uri}".`),console.error(t),e.__loadingState=F,i.setLoaded(e,!0),this.dispatchEvent({type:"load-error",tile:e,error:t,url:r})):i.remove(e))})):void 0}getAttributions(e=[]){return this.invokeAllPlugins(t=>t!==this&&t.getAttributions&&t.getAttributions(e)),e}invokeOnePlugin(e){const t=[...this.plugins,this];for(let s=0;s<t.length;s++){const r=e(t[s]);if(r)return r}return null}invokeAllPlugins(e){const t=[...this.plugins,this],s=[];for(let r=0;r<t.length;r++){const n=e(t[r]);n&&s.push(n)}return 0===s.length?null:Promise.all(s)}}class ${constructor(){this.fetchOptions={},this.workingPath=""}load(...e){return console.warn('Loader: "load" function has been deprecated in favor of "loadAsync".'),this.loadAsync(...e)}loadAsync(e){return fetch(e,this.fetchOptions).then(t=>{if(!t.ok)throw new Error(`Failed to load file "${e}" with status ${t.status} : ${t.statusText}`);return t.arrayBuffer()}).then(t=>(""===this.workingPath&&(this.workingPath=this.workingPathForURL(e)),this.parse(t)))}resolveExternalURL(e){return/^[^\\/]/.test(e)&&!/^http/.test(e)?this.workingPath+"/"+e:e}workingPathForURL(e){const t=e.split(/[\\/]/g);t.pop();return t.join("/")+"/"}parse(e){throw new Error("LoaderBase: Parse not implemented.")}}const J=new TextDecoder;function Y(e){return J.decode(e)}function Z(e,t,s,r,n,i){let a,o;switch(r){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 "${i}".`)}const l=s*a;switch(n){case"BYTE":o=new Int8Array(e,t,l);break;case"UNSIGNED_BYTE":o=new Uint8Array(e,t,l);break;case"SHORT":o=new Int16Array(e,t,l);break;case"UNSIGNED_SHORT":o=new Uint16Array(e,t,l);break;case"INT":o=new Int32Array(e,t,l);break;case"UNSIGNED_INT":o=new Uint32Array(e,t,l);break;case"FLOAT":o=new Float32Array(e,t,l);break;case"DOUBLE":o=new Float64Array(e,t,l);break;default:throw new Error(`FeatureTable : Feature component type not provided for "${i}".`)}return o}class X{constructor(e,t,s,r){this.buffer=e,this.binOffset=t+s,this.binLength=r;let n=null;if(0!==s){const r=new Uint8Array(e,t,s);n=JSON.parse(Y(r))}else n={};this.header=n}getKeys(){return Object.keys(this.header)}getData(e,t,s=null,r=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:a,binLength:o}=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.");const d=a+l,u=Z(n,d,t,c,h,e);if(d+u.byteLength>a+o)throw new Error("FeatureTable: Feature data read outside binary body length.");return u}}return i}getBuffer(e,t){const{buffer:s,binOffset:r}=this;return s.slice(r+e,r+e+t)}}class K{constructor(e){this.batchTable=e;const t=e.header.extensions["3DTILES_batch_table_hierarchy"];this.classes=t.classes;for(const e of this.classes){const t=e.instances;for(const s in t)e.instances[s]=this._parseProperty(t[s],e.length,s)}if(this.instancesLength=t.instancesLength,this.classIds=this._parseProperty(t.classIds,this.instancesLength,"classIds"),t.parentCounts?this.parentCounts=this._parseProperty(t.parentCounts,this.instancesLength,"parentCounts"):this.parentCounts=new Array(this.instancesLength).fill(1),t.parentIds){const e=this.parentCounts.reduce((e,t)=>e+t,0);this.parentIds=this._parseProperty(t.parentIds,e,"parentIds")}else this.parentIds=null;this.instancesIds=[];const s={};for(const e of this.classIds)s[e]=s[e]??0,this.instancesIds.push(s[e]),s[e]++}_parseProperty(e,t,s){if(Array.isArray(e))return e;{const{buffer:r,binOffset:n}=this.batchTable;return Z(r,n+e.byteOffset,t,"SCALAR",e.componentType||"UNSIGNED_SHORT",s)}}getDataFromId(e,t={}){const s=this.parentCounts[e];if(this.parentIds&&s>0){let r=0;for(let t=0;t<e;t++)r+=this.parentCounts[t];for(let n=0;n<s;n++){const s=this.parentIds[r+n];s!==e&&this.getDataFromId(s,t)}}const r=this.classIds[e],n=this.classes[r].instances,i=this.classes[r].name,a=this.instancesIds[e];for(const e in n)t[i]=t[i]||{},t[i][e]=n[e][a];return t}}class ee extends X{get batchSize(){return console.warn("BatchTable.batchSize has been deprecated and replaced with BatchTable.count."),this.count}constructor(e,t,s,r,n){super(e,s,r,n),this.count=t,this.extensions={};const i=this.header.extensions;i&&i["3DTILES_batch_table_hierarchy"]&&(this.extensions["3DTILES_batch_table_hierarchy"]=new K(this))}getData(e,t=null,s=null){return console.warn("BatchTable: BatchTable.getData is deprecated. Use BatchTable.getDataFromId to get allproperties for an id or BatchTable.getPropertyArray for getting an array of value for a property."),super.getData(e,this.count,t,s)}getDataFromId(e,t={}){if(e<0||e>=this.count)throw new Error(`BatchTable: id value "${e}" out of bounds for "${this.count}" features number.`);for(const s of this.getKeys())"extensions"!==s&&(t[s]=super.getData(s,this.count)[e]);for(const s in this.extensions){const r=this.extensions[s];r.getDataFromId instanceof Function&&(t[s]=t[s]||{},r.getDataFromId(e,t[s]))}return t}getPropertyArray(e){return super.getData(e,this.count)}}function te(e){if(null===e||e.byteLength<4)return"";let t;if(t=e instanceof DataView?e:new DataView(e),"{"===String.fromCharCode(t.getUint8(0)))return null;let s="";for(let e=0;e<4;e++)s+=String.fromCharCode(t.getUint8(e));return s}class se extends ${parse(e){const t=new DataView(e),s=te(t);console.assert("b3dm"===s);const r=t.getUint32(4,!0);console.assert(1===r);const n=t.getUint32(8,!0);console.assert(n===e.byteLength);const i=t.getUint32(12,!0),a=t.getUint32(16,!0),o=t.getUint32(20,!0),l=t.getUint32(24,!0),c=e.slice(28,28+i+a),h=new X(c,0,i,a),d=28+i+a,u=e.slice(d,d+o+l),p=new ee(u,h.getData("BATCH_LENGTH"),0,o,l),m=d+o+l;return{version:r,featureTable:h,batchTable:p,glbBytes:new Uint8Array(e,m,n-m)}}}class re extends ${parse(e){const t=new DataView(e),s=te(t);console.assert("i3dm"===s);const r=t.getUint32(4,!0);console.assert(1===r);const n=t.getUint32(8,!0);console.assert(n===e.byteLength);const i=t.getUint32(12,!0),a=t.getUint32(16,!0),o=t.getUint32(20,!0),l=t.getUint32(24,!0),c=t.getUint32(28,!0),h=e.slice(32,32+i+a),d=new X(h,0,i,a),u=32+i+a,p=e.slice(u,u+o+l),m=new ee(p,d.getData("INSTANCES_LENGTH"),0,o,l),g=u+o+l,f=new Uint8Array(e,g,n-g);let _=null,b=null,y=null;if(c)_=f,b=Promise.resolve();else{const e=this.resolveExternalURL(Y(f)),t=e.split(/[\\/]/g);t.pop(),y=t.join("/"),b=fetch(e,this.fetchOptions).then(t=>{if(!t.ok)throw new Error(`I3DMLoaderBase : Failed to load file "${e}" with status ${t.status} : ${t.statusText}`);return t.arrayBuffer()}).then(e=>{_=new Uint8Array(e)})}return b.then(()=>({version:r,featureTable:d,batchTable:m,glbBytes:_,gltfWorkingPath:y}))}}class ne extends ${parse(e){const t=new DataView(e),s=te(t);console.assert("pnts"===s);const r=t.getUint32(4,!0);console.assert(1===r);const n=t.getUint32(8,!0);console.assert(n===e.byteLength);const i=t.getUint32(12,!0),a=t.getUint32(16,!0),o=t.getUint32(20,!0),l=t.getUint32(24,!0),c=e.slice(28,28+i+a),h=new X(c,0,i,a),d=28+i+a,u=e.slice(d,d+o+l),p=new ee(u,h.getData("BATCH_LENGTH")||h.getData("POINTS_LENGTH"),0,o,l);return Promise.resolve({version:r,featureTable:h,batchTable:p})}}class ie extends ${parse(e){const t=new DataView(e),s=te(t);console.assert("cmpt"===s,'CMPTLoader: The magic bytes equal "cmpt".');const r=t.getUint32(4,!0);console.assert(1===r,'CMPTLoader: The version listed in the header is "1".');const n=t.getUint32(8,!0);console.assert(n===e.byteLength,"CMPTLoader: The contents buffer length listed in the header matches the file.");const i=t.getUint32(12,!0),a=[];let o=16;for(let t=0;t<i;t++){const t=new DataView(e,o,12),s=te(t),r=t.getUint32(4,!0),n=t.getUint32(8,!0),i=new Uint8Array(e,o,n);a.push({type:s,buffer:i,version:r}),o+=n}return{version:r,tiles:a}}}class ae extends se{constructor(e=n){super(),this.manager=e,this.adjustmentTransform=new r}parse(e){const s=super.parse(e),r=s.glbBytes.slice().buffer;return new Promise((e,n)=>{const i=this.manager,a=this.fetchOptions,o=i.getHandler("path.gltf")||new t(i);"include"===a.credentials&&"cors"===a.mode&&o.setCrossOrigin("use-credentials"),"credentials"in a&&o.setWithCredentials("include"===a.credentials),a.headers&&o.setRequestHeader(a.headers);let l=this.workingPath;!/[\\/]$/.test(l)&&l.length&&(l+="/");const c=this.adjustmentTransform;o.parse(r,l,t=>{const{batchTable:r,featureTable:n}=s,{scene:i}=t,a=n.getData("RTC_CENTER",1,"FLOAT","VEC3");a&&(i.position.x+=a[0],i.position.y+=a[1],i.position.z+=a[2]),t.scene.updateMatrix(),t.scene.matrix.multiply(c),t.scene.matrix.decompose(t.scene.position,t.scene.quaternion,t.scene.scale),t.batchTable=r,t.featureTable=n,i.batchTable=r,i.featureTable=n,e(t)},n)})}}function oe(e){const t=e>>11,s=e>>5&63,r=31&e;return[Math.round(t/31*255),Math.round(s/63*255),Math.round(r/31*255)]}const le=new i;function ce(e,t,s=new o){le.set(e,t).divideScalar(256).multiplyScalar(2).subScalar(1),s.set(le.x,le.y,1-Math.abs(le.x)-Math.abs(le.y));const r=a.clamp(-s.z,0,1);return s.x>=0?s.setX(s.x-r):s.setX(s.x+r),s.y>=0?s.setY(s.y-r):s.setY(s.y+r),s.normalize(),s}const he={RGB:"color",POSITION:"position"};class de extends ne{constructor(e=n){super(),this.manager=e}parse(e){return super.parse(e).then(async e=>{const{featureTable:t,batchTable:s}=e,r=new l,n=t.header.extensions,i=new o;let a;if(n&&n["3DTILES_draco_point_compression"]){const{byteOffset:e,byteLength:s,properties:i}=n["3DTILES_draco_point_compression"],o=this.manager.getHandler("draco.drc");if(null==o)throw new Error("PNTSLoader: dracoLoader not available.");const l={};for(const e in i)if(e in he&&e in i){l[he[e]]=i[e]}const c={attributeIDs:l,attributeTypes:{position:"Float32Array",color:"Uint8Array"},useUniqueIDs:!0},h=t.getBuffer(e,s);a=await o.decodeGeometry(h,c),a.attributes.color&&(r.vertexColors=!0)}else{const e=t.getData("POINTS_LENGTH"),s=t.getData("POSITION",e,"FLOAT","VEC3"),n=t.getData("NORMAL",e,"FLOAT","VEC3"),l=t.getData("NORMAL",e,"UNSIGNED_BYTE","VEC2"),u=t.getData("RGB",e,"UNSIGNED_BYTE","VEC3"),p=t.getData("RGBA",e,"UNSIGNED_BYTE","VEC4"),m=t.getData("RGB565",e,"UNSIGNED_SHORT","SCALAR"),g=t.getData("CONSTANT_RGBA",e,"UNSIGNED_BYTE","VEC4"),f=t.getData("POSITION_QUANTIZED",e,"UNSIGNED_SHORT","VEC3"),_=t.getData("QUANTIZED_VOLUME_SCALE",e,"FLOAT","VEC3"),b=t.getData("QUANTIZED_VOLUME_OFFSET",e,"FLOAT","VEC3");if(a=new c,f){const t=new Float32Array(3*e);for(let s=0;s<e;s++)for(let e=0;e<3;e++){const r=3*s+e;t[r]=f[r]/65535*_[e]}i.x=b[0],i.y=b[1],i.z=b[2],a.setAttribute("position",new h(t,3,!1))}else a.setAttribute("position",new h(s,3,!1));if(null!==n)a.setAttribute("normal",new h(n,3,!1));else if(null!==l){const t=new Float32Array(3*e),s=new o;for(let r=0;r<e;r++){const e=ce(l[2*r],l[2*r+1],s);t[3*r]=e.x,t[3*r+1]=e.y,t[3*r+2]=e.z}a.setAttribute("normal",new h(t,3,!1))}if(null!==p)a.setAttribute("color",new h(p,4,!0)),r.vertexColors=!0,r.transparent=!0,r.depthWrite=!1;else if(null!==u)a.setAttribute("color",new h(u,3,!0)),r.vertexColors=!0;else if(null!==m){const t=new Uint8Array(3*e);for(let s=0;s<e;s++){const e=oe(m[s]);for(let r=0;r<3;r++){t[3*s+r]=e[r]}}a.setAttribute("color",new h(t,3,!0)),r.vertexColors=!0}else if(null!==g){const e=new d(g[0],g[1],g[2]);r.color=e;const t=g[3]/255;t<1&&(r.opacity=t,r.transparent=!0,r.depthWrite=!1)}}const p=new u(a,r);p.position.copy(i),e.scene=p,e.scene.featureTable=t,e.scene.batchTable=s;const m=t.getData("RTC_CENTER",1,"FLOAT","VEC3");return m&&(e.scene.position.x+=m[0],e.scene.position.y+=m[1],e.scene.position.z+=m[2]),e})}}new p,new o;const ue=new p,pe=new o,me=new o,ge=new o,fe=new r,_e=new r,be=new r,ye=new m,we=new g,Te=new o,xe=new o,Se=new o,Ce=new o,ve=new f;class Pe{constructor(e=1,t=1,s=1){this.name="",this.radius=new o(e,t,s)}intersectRay(e,t){return fe.makeScale(...this.radius).invert(),ye.center.set(0,0,0),ye.radius=1,ve.copy(e).applyMatrix4(fe),ve.intersectSphere(ye,t)?(fe.makeScale(...this.radius),t.applyMatrix4(fe),t):null}getEastNorthUpFrame(e,t,s,r){return s.isMatrix4&&(r=s,s=0,console.warn('Ellipsoid: The signature for "getEastNorthUpFrame" has changed.')),this.getEastNorthUpAxes(e,t,Te,xe,Se),this.getCartographicToPosition(e,t,s,Ce),r.makeBasis(Te,xe,Se).setPosition(Ce)}getOrientedEastNorthUpFrame(e,t,s,r,n,i,a){return this.getObjectFrame(e,t,s,r,n,i,a,0)}getObjectFrame(e,t,s,r,n,i,a,o=2){return this.getEastNorthUpFrame(e,t,s,fe),we.set(n,i,-r,"ZXY"),a.makeRotationFromEuler(we).premultiply(fe),1===o?(we.set(Math.PI/2,0,0,"XYZ"),_e.makeRotationFromEuler(we),a.multiply(_e)):2===o&&(we.set(-Math.PI/2,0,Math.PI,"XYZ"),_e.makeRotationFromEuler(we),a.multiply(_e)),a}getCartographicFromObjectFrame(e,t,s=2){return 1===s?(we.set(-Math.PI/2,0,0,"XYZ"),_e.makeRotationFromEuler(we).premultiply(e)):2===s?(we.set(-Math.PI/2,0,Math.PI,"XYZ"),_e.makeRotationFromEuler(we).premultiply(e)):_e.copy(e),Ce.setFromMatrixPosition(_e),this.getPositionToCartographic(Ce,t),this.getEastNorthUpFrame(t.lat,t.lon,0,fe).invert(),_e.premultiply(fe),we.setFromRotationMatrix(_e,"ZXY"),t.azimuth=-we.z,t.elevation=we.x,t.roll=we.y,t}getEastNorthUpAxes(e,t,s,r,n,i=Ce){this.getCartographicToPosition(e,t,0,i),this.getCartographicToNormal(e,t,n),s.set(-i.y,i.x,0).normalize(),r.crossVectors(n,s).normalize()}getAzElRollFromRotationMatrix(e,t,s,r,n=0){return console.warn('Ellipsoid: "getAzElRollFromRotationMatrix" is deprecated. Use "getCartographicFromObjectFrame", instead.'),this.getCartographicToPosition(e,t,0,Ce),be.copy(s).setPosition(Ce),this.getCartographicFromObjectFrame(be,r,n),delete r.height,delete r.lat,delete r.lon,r}getRotationMatrixFromAzElRoll(e,t,s,r,n,i,a=0){return console.warn('Ellipsoid: "getRotationMatrixFromAzElRoll" function has been deprecated. Use "getObjectFrame", instead.'),this.getObjectFrame(e,t,0,s,r,n,i,a),i.setPosition(0,0,0),i}getFrame(e,t,s,r,n,i,a,o=0){return console.warn('Ellipsoid: "getFrame" function has been deprecated. Use "getObjectFrame", instead.'),this.getObjectFrame(e,t,i,s,r,n,a,o)}getCartographicToPosition(e,t,s,r){this.getCartographicToNormal(e,t,pe);const n=this.radius;me.copy(pe),me.x*=n.x**2,me.y*=n.y**2,me.z*=n.z**2;const i=Math.sqrt(pe.dot(me));return me.divideScalar(i),r.copy(me).addScaledVector(pe,s)}getPositionToCartographic(e,t){this.getPositionToSurfacePoint(e,me),this.getPositionToNormal(e,pe);const s=ge.subVectors(e,me);return t.lon=Math.atan2(pe.y,pe.x),t.lat=Math.asin(pe.z),t.height=Math.sign(s.dot(e))*s.length(),t}getCartographicToNormal(e,t,s){return ue.set(1,-e+Math.PI/2,t),s.setFromSpherical(ue).normalize(),function(e){const{x:t,y:s,z:r}=e;e.x=r,e.y=t,e.z=s}(s),s}getPositionToNormal(e,t){const s=this.radius;return t.copy(e),t.x/=s.x**2,t.y/=s.y**2,t.z/=s.z**2,t.normalize(),t}getPositionToSurfacePoint(e,t){const s=this.radius,r=1/s.x**2,n=1/s.y**2,i=1/s.z**2,a=e.x*e.x*r,o=e.y*e.y*n,l=e.z*e.z*i,c=a+o+l,h=Math.sqrt(1/c),d=me.copy(e).multiplyScalar(h);if(c<.1)return isFinite(h)?t.copy(d):null;const u=ge.set(d.x*r*2,d.y*n*2,d.z*i*2);let p,m,g,f,_,b,y,w,T,x,S,C=(1-h)*e.length()/(.5*u.length()),v=0;do{C-=v,g=1/(1+C*r),f=1/(1+C*n),_=1/(1+C*i),b=g*g,y=f*f,w=_*_,T=b*g,x=y*f,S=w*_,p=a*b+o*y+l*w-1,m=a*T*r+o*x*n+l*S*i;v=p/(-2*m)}while(Math.abs(p)>1e-12);return t.set(e.x*g,e.y*f,e.z*_)}calculateHorizonDistance(e,t){const s=this.calculateEffectiveRadius(e);return Math.sqrt(2*s*t+t**2)}calculateEffectiveRadius(e){const t=this.radius.x,s=1-this.radius.z**2/t**2,r=e*a.DEG2RAD,n=Math.sin(r)**2;return t/Math.sqrt(1-s*n)}getPositionElevation(e){this.getPositionToSurfacePoint(e,me);const t=ge.subVectors(e,me);return Math.sign(t.dot(e))*t.length()}copy(e){return this.radius.copy(e.radius),this}clone(){return(new this.constructor).copy(this)}}const Ee=new Pe(R,R,6356752.314245179);Ee.name="WGS84 Earth";const Me=new o,Le=new o,Fe=new o,Re=new o,Ue=new b,Ae=new o,Oe=new r,ke=new r,De=new o,Be=new r,Ne=new b,Ie={};class Ve extends re{constructor(e=n){super(),this.manager=e,this.adjustmentTransform=new r,this.ellipsoid=Ee.clone()}resolveExternalURL(e){return this.manager.resolveURL(super.resolveExternalURL(e))}parse(e){return super.parse(e).then(e=>{const{featureTable:s,batchTable:r}=e,n=e.glbBytes.slice().buffer;return new Promise((i,a)=>{const l=this.fetchOptions,c=this.manager,h=c.getHandler("path.gltf")||new t(c);"include"===l.credentials&&"cors"===l.mode&&h.setCrossOrigin("use-credentials"),"credentials"in l&&h.setWithCredentials("include"===l.credentials),l.headers&&h.setRequestHeader(l.headers);let d=e.gltfWorkingPath??this.workingPath;/[\\/]$/.test(d)||(d+="/");const u=this.adjustmentTransform;h.parse(n,d,e=>{const t=s.getData("INSTANCES_LENGTH"),n=s.getData("POSITION",t,"FLOAT","VEC3"),a=s.getData("NORMAL_UP",t,"FLOAT","VEC3"),l=s.getData("NORMAL_RIGHT",t,"FLOAT","VEC3"),c=s.getData("SCALE_NON_UNIFORM",t,"FLOAT","VEC3"),h=s.getData("SCALE",t,"FLOAT","SCALAR"),d=s.getData("RTC_CENTER",1,"FLOAT","VEC3"),p=s.getData("EAST_NORTH_UP");["QUANTIZED_VOLUME_OFFSET","QUANTIZED_VOLUME_SCALE","POSITION_QUANTIZED","NORMAL_UP_OCT32P","NORMAL_RIGHT_OCT32P"].forEach(e=>{e in s.header&&console.warn(`I3DMLoader: Unsupported FeatureTable feature "${e}" detected.`)});const m=new o;for(let e=0;e<t;e++)m.x+=n[3*e+0]/t,m.y+=n[3*e+1]/t,m.z+=n[3*e+2]/t;const g=[],f=[];e.scene.updateMatrixWorld(),e.scene.traverse(e=>{if(e.isMesh){f.push(e);const{geometry:s,material:r}=e,n=new _(s,r,t);n.position.copy(m),d&&(n.position.x+=d[0],n.position.y+=d[1],n.position.z+=d[2]),g.push(n)}});for(let e=0;e<t;e++){Re.set(n[3*e+0]-m.x,n[3*e+1]-m.y,n[3*e+2]-m.z),Ue.identity(),a&&(Le.set(a[3*e+0],a[3*e+1],a[3*e+2]),Fe.set(l[3*e+0],l[3*e+1],l[3*e+2]),Me.crossVectors(Fe,Le).normalize(),Oe.makeBasis(Fe,Le,Me),Ue.setFromRotationMatrix(Oe)),Ae.set(1,1,1),c&&Ae.set(c[3*e+0],c[3*e+1],c[3*e+2]),h&&Ae.multiplyScalar(h[e]);for(let t=0,s=g.length;t<s;t++){const s=g[t];Ne.copy(Ue),p&&(s.updateMatrixWorld(),De.copy(Re).applyMatrix4(s.matrixWorld),this.ellipsoid.getPositionToCartographic(De,Ie),this.ellipsoid.getEastNorthUpFrame(Ie.lat,Ie.lon,Be),Ne.setFromRotationMatrix(Be)),Oe.compose(Re,Ne,Ae).multiply(u);const r=f[t];ke.multiplyMatrices(Oe,r.matrixWorld),s.setMatrixAt(e,ke)}}e.scene.clear(),e.scene.add(...g),e.batchTable=r,e.featureTable=s,e.scene.batchTable=r,e.scene.featureTable=s,i(e)},a)})})}}class ze extends ie{constructor(e=n){super(),this.manager=e,this.adjustmentTransform=new r,this.ellipsoid=Ee.clone()}parse(e){const t=super.parse(e),{manager:s,ellipsoid:r,adjustmentTransform:n}=this,i=[];for(const e in t.tiles){const{type:a,buffer:o}=t.tiles[e];switch(a){case"b3dm":{const e=o.slice(),t=new ae(s);t.workingPath=this.workingPath,t.fetchOptions=this.fetchOptions,t.adjustmentTransform.copy(n);const r=t.parse(e.buffer);i.push(r);break}case"pnts":{const e=o.slice(),t=new de(s);t.workingPath=this.workingPath,t.fetchOptions=this.fetchOptions;const r=t.parse(e.buffer);i.push(r);break}case"i3dm":{const e=o.slice(),t=new Ve(s);t.workingPath=this.workingPath,t.fetchOptions=this.fetchOptions,t.ellipsoid.copy(r),t.adjustmentTransform.copy(n);const a=t.parse(e.buffer);i.push(a);break}}}return Promise.all(i).then(e=>{const t=new y;return e.forEach(e=>{t.add(e.scene)}),{tiles:e,scene:t}})}}const je=new r;class We extends y{constructor(e){super(),this.isTilesGroup=!0,this.name="TilesRenderer.TilesGroup",this.tilesRenderer=e,this.matrixWorldInverse=new r}raycast(e,t){return!this.tilesRenderer.optimizeRaycast||(this.tilesRenderer.raycast(e,t),!1)}updateMatrixWorld(e){if(this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldNeedsUpdate||e){null===this.parent?je.copy(this.matrix):je.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1;const e=je.elements,t=this.matrixWorld.elements;let s=!1;for(let r=0;r<16;r++){const n=e[r],i=t[r];if(Math.abs(n-i)>Number.EPSILON){s=!0;break}}if(s){this.matrixWorld.copy(je),this.matrixWorldInverse.copy(je).invert();const e=this.children;for(let t=0,s=e.length;t<s;t++)e[t].updateMatrixWorld()}}}updateWorldMatrix(e,t){this.parent&&e&&this.parent.updateWorldMatrix(e,!1),this.updateMatrixWorld(!0)}}const qe=new f,Ge=new o,He=[];function Qe(e,t){return e.distance-t.distance}function $e(e,t,s,r){const{scene:n}=e.cached;s.invokeOnePlugin(s=>s.raycastTile&&s.raycastTile(e,n,t,r))||t.intersectObject(n,!0,r)}function Je(e){return"__used"in e}function Ye(e,t,s,r=null){const{group:n,activeTiles:i}=e;null===r&&(r=qe).copy(s.ray).applyMatrix4(n.matrixWorldInverse);const a=[],o=t.children;for(let e=0,t=o.length;e<t;e++){const t=o[e];if(!Je(t)||!t.__used)continue;null!==t.cached.boundingVolume.intersectRay(r,Ge)&&(Ge.applyMatrix4(n.matrixWorld),a.push({distance:Ge.distanceToSquared(s.ray.origin),tile:t}))}a.sort(Qe);let l=null,c=1/0;if(i.has(t)){const r=function(e,t,s){$e(e,t,s,He),He.sort(Qe);const r=He[0]||null;return He.length=0,r}(t,s,e);r&&(l=r,c=r.distance*r.distance)}for(let t=0,n=a.length;t<n;t++){const n=a[t],i=n.distance,o=n.tile;if(i>c)break;const h=Ye(e,o,s,r);if(h){const e=h.distance*h.distance;e<c&&(l=h,c=e)}}return l}function Ze(e,t,s,r,n=null){if(!Je(t))return;const{group:i,activeTiles:a}=e,{boundingVolume:o}=t.cached;if(null===n&&(n=qe).copy(s.ray).applyMatrix4(i.matrixWorldInverse),!t.__used||!o.intersectsRay(n))return;a.has(t)&&$e(t,s,e,r);const l=t.children;for(let t=0,i=l.length;t<i;t++)Ze(e,l[t],s,r,n)}const Xe=new o,Ke=new o,et=new o,tt=new f;class st{constructor(e=new T,t=new r){this.box=e.clone(),this.transform=t.clone(),this.inverseTransform=new r,this.points=new Array(8).fill().map(()=>new o),this.planes=new Array(6).fill().map(()=>new w)}copy(e){return this.box.copy(e.box),this.transform.copy(e.transform),this.update(),this}clone(){return(new this.constructor).copy(this)}clampPoint(e,t){return t.copy(e).applyMatrix4(this.inverseTransform).clamp(this.box.min,this.box.max).applyMatrix4(this.transform)}distanceToPoint(e){return this.clampPoint(e,et).distanceTo(e)}containsPoint(e){return et.copy(e).applyMatrix4(this.inverseTransform),this.box.containsPoint(et)}intersectsRay(e){return tt.copy(e).applyMatrix4(this.inverseTransform),tt.intersectsBox(this.box)}intersectRay(e,t){return tt.copy(e).applyMatrix4(this.inverseTransform),tt.intersectBox(this.box,t)?(t.applyMatrix4(this.transform),t):null}update(){const{points:e,inverseTransform:t,transform:s,box:r}=this;t.copy(s).invert();const{min:n,max:i}=r;let a=0;for(let t=-1;t<=1;t+=2)for(let r=-1;r<=1;r+=2)for(let o=-1;o<=1;o+=2)e[a].set(t<0?n.x:i.x,r<0?n.y:i.y,o<0?n.z:i.z).applyMatrix4(s),a++;this.updatePlanes()}updatePlanes(){Xe.copy(this.box.min).applyMatrix4(this.transform),Ke.copy(this.box.max).applyMatrix4(this.transform),et.set(0,0,1).transformDirection(this.transform),this.planes[0].setFromNormalAndCoplanarPoint(et,Xe),this.planes[1].setFromNormalAndCoplanarPoint(et,Ke).negate(),et.set(0,1,0).transformDirection(this.transform),this.planes[2].setFromNormalAndCoplanarPoint(et,Xe),this.planes[3].setFromNormalAndCoplanarPoint(et,Ke).negate(),et.set(1,0,0).transformDirection(this.transform),this.planes[4].setFromNormalAndCoplanarPoint(et,Xe),this.planes[5].setFromNormalAndCoplanarPoint(et,Ke).negate()}intersectsSphere(e){return this.clampPoint(e.center,et),et.distanceToSquared(e.center)<=e.radius*e.radius}intersectsFrustum(e){return this._intersectsPlaneShape(e.planes,e.points)}intersectsOBB(e){return this._intersectsPlaneShape(e.planes,e.points)}_intersectsPlaneShape(e,t){const s=this.points,r=this.planes;for(let t=0;t<6;t++){const r=e[t];let n=-1/0;for(let e=0;e<8;e++){const t=s[e],i=r.distanceToPoint(t);n=n<i?i:n}if(n<0)return!1}for(let e=0;e<6;e++){const s=r[e];let n=-1/0;for(let e=0;e<8;e++){const r=t[e],i=s.distanceToPoint(r);n=n<i?i:n}if(n<0)return!1}return!0}}const rt=Math.PI,nt=rt/2,it=new o,at=new o,ot=new o,lt=new r;let ct=0;const ht=[];function dt(e=!1){return e?(ht[ct]||(ht[ct]=new o),ct++,ht[ct-1]):new o}function ut(){ct=0}class pt extends Pe{constructor(e,t,s,r=-nt,n=nt,i=0,a=2*rt,o=0,l=0){super(e,t,s),this.latStart=r,this.latEnd=n,this.lonStart=i,this.lonEnd=a,this.heightStart=o,this.heightEnd=l}_getPoints(e=!1){const{latStart:t,latEnd:s,lonStart:r,lonEnd:n,heightStart:i,heightEnd:o}=this,l=a.mapLinear(.5,0,1,t,s),c=a.mapLinear(.5,0,1,r,n),h=Math.floor(r/nt)*nt,d=[[-rt/2,0],[rt/2,0],[0,h],[0,h+rt/2],[0,h+rt],[0,h+3*rt/2],[t,n],[s,n],[t,r],[s,r],[0,r],[0,n],[l,c],[t,c],[s,c],[l,r],[l,n]],u=[],p=d.length;for(let l=0;l<=1;l++){const c=a.mapLinear(l,0,1,i,o);for(let i=0,a=p;i<a;i++){const[a,o]=d[i];if(a>=t&&a<=s&&o>=r&&o<=n){const t=dt(e);u.push(t),this.getCartographicToPosition(a,o,c,t)}}}return u}getBoundingBox(e,t){ut();const{latStart:s,latEnd:r,lonStart:n,lonEnd:i}=this;if(r-s<rt/2){const e=a.mapLinear(.5,0,1,s,r),o=a.mapLinear(.5,0,1,n,i);this.getCartographicToNormal(e,o,ot),at.set(0,0,1),it.crossVectors(at,ot),at.crossVectors(it,ot),t.makeBasis(it,at,ot)}else it.set(1,0,0),at.set(0,1,0),ot.set(0,0,1),t.makeBasis(it,at,ot);lt.copy(t).invert();const o=this._getPoints(!0);for(let e=0,t=o.length;e<t;e++)o[e].applyMatrix4(lt);e.makeEmpty(),e.setFromPoints(o)}getBoundingSphere(e,t){ut();const s=this._getPoints(!0);e.makeEmpty(),e.setFromPoints(s,t)}}const mt=new o,gt=new o,ft=new o,_t=new o,bt=new o;class yt{constructor(){this.sphere=null,this.obb=null,this.region=null,this.regionObb=null}intersectsRay(e){const t=this.sphere,s=this.obb||this.regionObb;return!(t&&!e.intersectsSphere(t))&&!(s&&!s.intersectsRay(e))}intersectRay(e,t=null){const s=this.sphere,r=this.obb||this.regionObb;let n=-1/0,i=-1/0;s&&e.intersectSphere(s,_t)&&(n=s.containsPoint(e.origin)?0:e.origin.distanceToSquared(_t)),r&&r.intersectRay(e,bt)&&(i=r.containsPoint(e.origin)?0:e.origin.distanceToSquared(bt));const a=Math.max(n,i);return a===-1/0?null:(e.at(Math.sqrt(a),t),t)}distanceToPoint(e){const t=this.sphere,s=this.obb||this.regionObb;let r=-1/0,n=-1/0;return t&&(r=Math.max(t.distanceToPoint(e),0)),s&&(n=s.distanceToPoint(e)),r>n?r:n}intersectsFrustum(e){const t=this.obb||this.regionObb,s=this.sphere;return!(s&&!e.intersectsSphere(s))&&(!(t&&!t.intersectsFrustum(e))&&Boolean(s||t))}intersectsSphere(e){const t=this.obb||this.regionObb,s=this.sphere;return!(s&&!s.intersectsSphere(e))&&(!(t&&!t.intersectsSphere(e))&&Boolean(s||t))}intersectsOBB(e){const t=this.obb||this.regionObb,s=this.sphere;return!(s&&!e.intersectsSphere(s))&&(!(t&&!t.intersectsOBB(e))&&Boolean(s||t))}getOBB(e,t){const s=this.obb||this.regionObb;s?(e.copy(s.box),t.copy(s.transform)):(this.getAABB(e),t.identity())}getAABB(e){if(this.sphere)this.sphere.getBoundingBox(e);else{const t=this.obb||this.regionObb;e.copy(t.box).applyMatrix4(t.transform)}}getSphere(e){if(this.sphere)e.copy(this.sphere);else if(this.region)this.region.getBoundingSphere(e);else{const t=this.obb||this.regionObb;t.box.getBoundingSphere(e),e.applyMatrix4(t.transform)}}setObbData(e,t){const s=new st;mt.set(e[3],e[4],e[5]),gt.set(e[6],e[7],e[8]),ft.set(e[9],e[10],e[11]);const r=mt.length(),n=gt.length(),i=ft.length();mt.normalize(),gt.normalize(),ft.normalize(),0===r&&mt.crossVectors(gt,ft),0===n&>.crossVectors(mt,ft),0===i&&ft.crossVectors(mt,gt),s.transform.set(mt.x,gt.x,ft.x,e[0],mt.y,gt.y,ft.y,e[1],mt.z,gt.z,ft.z,e[2],0,0,0,1).premultiply(t),s.box.min.set(-r,-n,-i),s.box.max.set(r,n,i),s.update(),this.obb=s}setSphereData(e,t,s,r,n){const i=new m;i.center.set(e,t,s),i.radius=r,i.applyMatrix4(n),this.sphere=i}setRegionData(e,t,s,r,n,i,a){const o=new pt(...e.radius,s,n,t,r,i,a),l=new st;o.getBoundingBox(l.box,l.transform),l.update(),this.region=o,this.regionObb=l}}const wt=new x;class Tt extends S{constructor(){super(),this.points=Array(8).fill().map(()=>new o)}setFromProjectionMatrix(e,t){return super.setFromProjectionMatrix(e,t),this.calculateFrustumPoints(),this}calculateFrustumPoints(){const{planes:e,points:t}=this;[[e[0],e[3],e[4]],[e[1],e[3],e[4]],[e[0],e[2],e[4]],[e[1],e[2],e[4]],[e[0],e[3],e[5]],[e[1],e[3],e[5]],[e[0],e[2],e[5]],[e[1],e[2],e[5]]].forEach((e,s)=>{!function(e,t,s,r){const n=wt.set(e.normal.x,e.normal.y,e.normal.z,t.normal.x,t.normal.y,t.normal.z,s.normal.x,s.normal.y,s.normal.z);r.set(-e.constant,-t.constant,-s.constant),r.applyMatrix3(n.invert())}(e[0],e[1],e[2],t[s])})}}function xt(e){const{TextureUtils:t}=s;if(!t||!e)return 0;const{format:r,type:n,image:i}=e,{width:a,height:o}=i;let l=t.getByteLength(a,o,r,n);return l*=e.generateMipmaps?4/3:1,l}const St=new r,Ct=new g,vt=Symbol("INITIAL_FRUSTUM_CULLED"),Pt=new r,Et=new o,Mt=new i,Lt={inView:!1,error:1/0},Ft=new o(1,0,0),Rt=new o(0,1,0);function Ut(e,t){e.traverse(e=>{e.frustumCulled=e[vt]&&t})}class At extends Q{get autoDisableRendererCulling(){return this._autoDisableRendererCulling}set autoDisableRendererCulling(e){this._autoDisableRendererCulling!==e&&(super._autoDisableRendererCulling=e,this.forEachLoadedModel(t=>{Ut(t,!e)}))}get optimizeRaycast(){return this._optimizeRaycast}set optimizeRaycast(e){console.warn('TilesRenderer: The "optimizeRaycast" option has been deprecated.'),this._optimizeRaycast=e}constructor(...e){super(...e),this.group=new We(this),this.ellipsoid=Ee.clone(),this.cameras=[],this.cameraMap=new Map,this.cameraInfo=[],this._optimizeRaycast=!0,this._upRotationMatrix=new r,this._bytesUsed=new WeakMap,this._autoDisableRendererCulling=!0;const t=new C;t.setURLModifier(e=>this.preprocessURL?this.preprocessURL(e):e),this.manager=t,this._listeners={}}addEventListener(...e){v.prototype.addEventListener.call(this,...e)}hasEventListener(...e){v.prototype.hasEventListener.call(this,...e)}removeEventListener(...e){v.prototype.removeEventListener.call(this,...e)}dispatchEvent(...e){v.prototype.dispatchEvent.call(this,...e)}getBoundingBox(e){if(!this.root)return!1;const t=this.root.cached.boundingVolume;return!!t&&(t.getAABB(e),!0)}getOrientedBoundingBox(e,t){if(!this.root)return!1;const s=this.root.cached.boundingVolume;return!!s&&(s.getOBB(e,t),!0)}getBoundingSphere(e){if(!this.root)return!1;const t=this.root.cached.boundingVolume;return!!t&&(t.getSphere(e),!0)}forEachLoadedModel(e){this.traverse(t=>{const s=t.cached&&t.cached.scene;s&&e(s,t)},null,!1)}raycast(e,t){if(this.root)if(e.firstHitOnly){const s=Ye(this,this.root,e);s&&t.push(s)}else Ze(this,this.root,e,t)}hasCamera(e){return this.cameraMap.has(e)}setCamera(e){const t=this.cameras,s=this.cameraMap;return!s.has(e)&&(s.set(e,new i),t.push(e),this.dispatchEvent({type:"add-camera",camera:e}),!0)}setResolution(e,t,s){const r=this.cameraMap;if(!r.has(e))return!1;const n=t.isVector2?t.x:t,i=t.isVector2?t.y:s,a=r.get(e);return a.width===n&&a.height===i||(a.set(n,i),this.dispatchEvent({type:"camera-resolution-change"})),!0}setResolutionFromRenderer(e,t){return t.getSize(Mt),this.setResolution(e,Mt.x,Mt.y)}deleteCamera(e){const t=this.cameras,s=this.cameraMap;if(s.has(e)){const r=t.indexOf(e);return t.splice(r,1),s.delete(e),this.dispatchEvent({type:"delete-camera",camera:e}),!0}return!1}loadRootTileSet(...e){return super.loadRootTileSet(...e).then(e=>{const{asset:t,extensions:s={}}=e;switch((t&&t.gltfUpAxis||"y").toLowerCase()){case"x":this._upRotationMatrix.makeRotationAxis(Rt,-Math.PI/2);break;case"y":this._upRotationMatrix.makeRotationAxis(Ft,Math.PI/2)}if("3DTILES_ellipsoid"in s){const e=s["3DTILES_ellipsoid"],{ellipsoid:t}=this;t.name=e.body,e.radii?t.radius.set(...e.radii):t.radius.set(1,1,1)}return e})}update(){let e=null;if(this.invokeAllPlugins(t=>{if(t.doTilesNeedUpdate){const s=t.doTilesNeedUpdate();e=null===e?s:Boolean(e||s)}}),!1===e)return this.dispatchEvent({type:"update-before"}),void this.dispatchEvent({type:"update-after"});this.dispatchEvent({type:"update-before"});const t=this.group,s=this.cameras,r=this.cameraMap,n=this.cameraInfo;for(;n.length>s.length;)n.pop();for(;n.length<s.length;)n.push({frustum:new Tt,isOrthographic:!1,sseDenominator:-1,position:new o,invScale:-1,pixelSize:0});Et.setFromMatrixScale(t.matrixWorldInverse),Math.abs(Math.max(Et.x-Et.y,Et.x-Et.z))>1e-6&&console.warn("ThreeTilesRenderer : Non uniform scale used for tile which may cause issues when calculating screen space error.");for(let e=0,i=n.length;e<i;e++){const i=s[e],a=n[e],o=a.frustum,l=a.position,c=r.get(i);0!==c.width&&0!==c.height||console.warn("TilesRenderer: resolution for camera error calculation is not set.");const h=i.projectionMatrix.elements;if(a.isOrthographic=1===h[15],a.isOrthographic){const e=2/h[0],t=2/h[5];a.pixelSize=Math.max(t/c.height,e/c.width)}else a.sseDenominator=2/h[5]/c.height;Pt.copy(t.matrixWorld),Pt.premultiply(i.matrixWorldInverse),Pt.premultiply(i.projectionMatrix),o.setFromProjectionMatrix(Pt),l.set(0,0,0),l.applyMatrix4(i.matrixWorld),l.applyMatrix4(t.matrixWorldInverse)}if(super.update(),this.dispatchEvent({type:"update-after"}),0===s.length&&this.root){let e=!1;this.invokeAllPlugins(t=>e=e||Boolean(t!==this&&t.calculateTileViewError)),!1===e&&console.warn("TilesRenderer: no cameras defined. Cannot update 3d tiles.")}}preprocessNode(e,t,s=null){super.preprocessNode(e,t,s);const n=new r;if(e.transform){const t=e.transform;for(let e=0;e<16;e++)n.elements[e]=t[e]}s&&n.premultiply(s.cached.transform);const i=(new r).copy(n).invert(),a=new yt;"sphere"in e.boundingVolume&&a.setSphereData(...e.boundingVolume.sphere,n),"box"in e.boundingVolume&&a.setObbData(e.boundingVolume.box,n),"region"in e.boundingVolume&&a.setRegionData(this.ellipsoid,...e.boundingVolume.region),e.cached={transform:n,transformInverse:i,active:!1,boundingVolume:a,metadata:null,scene:null,geometry:null,materials:null,textures:null}}async parseTile(e,s,r,n,i){const a=s.cached,o=n.split(/[\\/]/g);o.pop();const l=o.join("/"),c=this.fetchOptions,h=this.manager;let d=null;const u=a.transform,p=this._upRotationMatrix,m=(te(e)||r).toLowerCase();switch(m){case"b3dm":{const t=new ae(h);t.workingPath=l,t.fetchOptions=c,t.adjustmentTransform.copy(p),d=t.parse(e);break}case"pnts":{const t=new de(h);t.workingPath=l,t.fetchOptions=c,d=t.parse(e);break}case"i3dm":{const t=new Ve(h);t.workingPath=l,t.fetchOptions=c,t.adjustmentTransform.copy(p),t.ellipsoid.copy(this.ellipsoid),d=t.parse(e);break}case"cmpt":{const t=new ze(h);t.workingPath=l,t.fetchOptions=c,t.adjustmentTransform.copy(p),t.ellipsoid.copy(this.ellipsoid),d=t.parse(e).then(e=>e.scene);break}case"gltf":case"glb":{const s=h.getHandler("path.gltf")||h.getHandler("path.glb")||new t(h);s.setWithCredentials("include"===c.credentials),s.setRequestHeader(c.headers||{}),"include"===c.credentials&&"cors"===c.mode&&s.setCrossOrigin("use-credentials");let r=s.resourcePath||s.path||l;!/[\\/]$/.test(r)&&r.length&&(r+="/"),d=s.parseAsync(e,r).then(e=>{e.scene=e.scene||new y;const{scene:t}=e;return t.updateMatrix(),t.matrix.multiply(p).decompose(t.position,t.quaternion,t.scale),e});break}default:d=this.invokeOnePlugin(t=>t.parseToMesh&&t.parseToMesh(e,s,r,n,i))}const g=await d;if(null===g)throw new Error(`TilesRenderer: Content type "${m}" not supported.`);let f,_;g.isObject3D?(f=g,_=null):(f=g.scene,_=g),f.updateMatrix(),f.matrix.premultiply(u),f.matrix.decompose(f.position,f.quaternion,f.scale),await this.invokeAllPlugins(e=>e.processTileModel&&e.processTileModel(f,s)),f.traverse(e=>{e[vt]=e.frustumCulled}),Ut(f,!this.autoDisableRendererCulling);const b=[],w=[],T=[];if(f.traverse(e=>{if(e.geometry&&w.push(e.geometry),e.material){const t=e.material;b.push(e.material);for(const e in t){const s=t[e];s&&s.isTexture&&T.push(s)}}}),i.aborted)for(let e=0,t=T.length;e<t;e++){const t=T[e];t.image instanceof ImageBitmap&&t.image.close(),t.dispose()}else a.materials=b,a.geometry=w,a.textures=T,a.scene=f,a.metadata=_}disposeTile(e){super.disposeTile(e);const t=e.cached;if(t.scene){const s=t.materials,r=t.geometry,n=t.textures,i=t.scene.parent;t.scene.traverse(e=>{e.userData.meshFeatures&&e.userData.meshFeatures.dispose(),e.userData.structuralMetadata&&e.userData.structuralMetadata.dispose()});for(let e=0,t=r.length;e<t;e++)r[e].dispose();for(let e=0,t=s.length;e<t;e++)s[e].dispose();for(let e=0,t=n.length;e<t;e++){const t=n[e];t.image instanceof ImageBitmap&&t.image.close(),t.dispose()}i&&i.remove(t.scene),this.dispatchEvent({type:"dispose-model",scene:t.scene,tile:e}),t.scene=null,t.materials=null,t.textures=null,t.geometry=null,t.metadata=null}}setTileVisible(e,t){const s=e.cached.scene,r=this.group;t?s&&(r.add(s),s.updateMatrixWorld(!0)):s&&r.remove(s),super.setTileVisible(e,t),this.dispatchEvent({type:"tile-visibility-change",scene:s,tile:e,visible:t})}calculateBytesUsed(e,t){const s=this._bytesUsed;return!s.has(e)&&t&&s.set(e,function(e){const t=new Set;let s=0;return e.traverse(e=>{if(e.geometry&&!t.has(e.geometry)&&(s+=P(e.geometry),t.add(e.geometry)),e.material){const r=e.material;for(const e in r){const n=r[e];n&&n.isTexture&&!t.has(n)&&(s+=xt(n),t.add(n))}}}),s}(t)),s.get(e)??null}calculateTileViewError(e,t){const s=e.cached,r=this.cameras,n=this.cameraInfo,i=s.boundingVolume;let a=!1,o=-1/0,l=1/0,c=-1/0,h=1/0;for(let t=0,s=r.length;t<s;t++){const s=n[t];let r,d;if(s.isOrthographic){const t=s.pixelSize;r=e.geometricError/t,d=1/0}else{const t=s.sseDenominator;d=i.distanceToPoint(s.position),r=0===d?1/0:e.geometricError/(d*t)}const u=n[t].frustum;i.intersectsFrustum(u)&&(a=!0,o=Math.max(o,r),l=Math.min(l,d)),c=Math.max(c,r),h=Math.min(h,d)}this.invokeAllPlugins(t=>{t!==this&&t.calculateTileViewError&&(t.calculateTileViewError(e,Lt),Lt.inView&&(a=!0,o=Math.max(o,Lt.error)),c=Math.max(c,Lt.error))}),a?(t.inView=!0,t.error=o,t.distanceFromCamera=l):(t.inView=!1,t.error=c,t.distanceFromCamera=h)}setLatLonToYUp(e,t){console.warn("TilesRenderer: setLatLonToYUp is deprecated. Use the ReorientationPlugin, instead.");const{ellipsoid:s,group:r}=this;Ct.set(Math.PI/2,Math.PI/2,0),St.makeRotationFromEuler(Ct),s.getEastNorthUpFrame(e,t,0,r.matrix).multiply(St).invert().decompose(r.position,r.quaternion,r.scale),r.updateMatrixWorld(!0)}dispose(){super.dispose(),this.group.removeFromParent()}}class Ot{constructor(e){this.parser=e,this.name="KHR_texture_basisu_patch"}loadTexture(t){const s=this.parser,r=s.json,n=r.textures[t].source,i=r.images[n];if(!i||"image/ktx2"!==i.mimeType)return null;const a=s.options.ktx2Loader;if(!a)throw new Error(`${e.utils.consoleSspTitle}请使用 setModelKtx2DecoderPath 设置 ktx2 解压库路径`);return s.loadTextureImage(t,n,a)}}class kt{constructor(e){this.ssp=e,this.tilesMap=new Map,this.needsUpdate=!0,this.cameraTransitionStart=!1,this._tilesCamera=this.ssp.viewport.camera,this.lruCache=null,this.parseQueue=null,this.downloadQueue=null;const{controls:t,viewport:s}=e;t.addEventListener("transitionstart",()=>{this.cameraTransitionStart=!0,s.state.useFreq=1}),t.addEventListener("rest",()=>{this.cameraTransitionStart=!1,this.needsUpdate=!0,s.state.useFreq=60}),e.signals.beforeRender.add(()=>{this.needsUpdate&&(this.needsUpdate=!1,e.viewport.camera.updateMatrixWorld(),this.tilesMap.forEach(e=>{e.group.updateMatrixWorld(),e.update()}))}),e.signals.cameraObjectChange.add(()=>{this.tilesMap.forEach(t=>{t.deleteCamera(this._tilesCamera),t.setCamera(e.viewport.camera),t.setResolutionFromRenderer(e.viewport.camera,e.viewport.renderer)}),this._tilesCamera=e.viewport.camera})}async loadTiles(s){if(this.tilesMap.has(s))return void e.utils.warn(`${s} already loaded`);const{ssp:r,ssp:{viewport:n}}=this,i=new At(s);null===this.lruCache?this.lruCache=i.lruCache:i.lruCache=this.lruCache,null===this.parseQueue?this.parseQueue=i.parseQueue:i.parseQueue=this.parseQueue,null===this.downloadQueue?this.downloadQueue=i.downloadQueue:i.downloadQueue=this.downloadQueue;const a=new t(i.manager);a.register(e=>new Ot(e));const{dracoLoader:o,ktx2Loader:l,meshoptDecoder:c}=r.manager.store.modelManager.gltfLoader;o&&a.setDRACOLoader(o),l&&a.setKTX2Loader(l),c&&a.setMeshoptDecoder(c),i.manager.addHandler(/\.gltf$/,a),this.tilesMap.set(s,i),i.setCamera(this._tilesCamera),i.setResolutionFromRenderer(this._tilesCamera,n.renderer),i.lruCache.maxSize=600,i.lruCache.minSize=300,i.lruCache.unloadPercent=.8,r.addObject(i.group);const h=()=>{this.cameraTransitionStart||(this.needsUpdate=!0,r.render())};return i.onLoadModel=()=>h(),i.onDisposeModel=(e,t)=>{if(t.cached.textures){const{textures:e}=t.cached;for(let t=0,s=e.length;t<s;t++){const s=e[t];s.mipmaps.length>0&&(s.mipmaps.length=0),s.image instanceof ImageBitmap&&s.image.close()}}},new Promise(e=>{i.onLoadTileSet=()=>{h(),e(i)}})}removeTiles(e){const t=this.tilesMap.get(e);return!!t&&(t.dispose(),this.tilesMap.delete(e),this.ssp.removeObject(t.group),!0)}}export{kt as default};
|
|
1
|
+
import e from"soonspacejs";import{TilesRenderer as t}from"3d-tiles-renderer";import{GLTFLoader as s}from"three/examples/jsm/loaders/GLTFLoader.js";class a{constructor(e){this.parser=e,this.name="KHR_texture_basisu_patch"}loadTexture(t){const s=this.parser,a=s.json,r=a.textures[t].source,i=a.images[r];if(!i||"image/ktx2"!==i.mimeType)return null;const o=s.options.ktx2Loader;if(!o)throw new Error(`${e.utils.consoleSspTitle}请使用 setModelKtx2DecoderPath 设置 ktx2 解压库路径`);return s.loadTextureImage(t,r,o)}}class r{constructor(e){this.ssp=e,this.tilesMap=new Map,this.needsUpdate=!0,this.cameraTransitionStart=!1,this._tilesCamera=this.ssp.viewport.camera,this.lruCache=null,this.parseQueue=null,this.downloadQueue=null;const{controls:t,viewport:s}=e;t.addEventListener("transitionstart",()=>{this.cameraTransitionStart=!0,s.state.useFreq=1}),t.addEventListener("rest",()=>{this.cameraTransitionStart=!1,this.needsUpdate=!0,s.state.useFreq=60}),e.signals.beforeRender.add(()=>{this.needsUpdate&&(this.needsUpdate=!1,e.viewport.camera.updateMatrixWorld(),this.tilesMap.forEach(e=>{e.group.updateMatrixWorld(),e.update()}))}),e.signals.cameraObjectChange.add(()=>{this.tilesMap.forEach(t=>{t.deleteCamera(this._tilesCamera),t.setCamera(e.viewport.camera),t.setResolutionFromRenderer(e.viewport.camera,e.viewport.renderer)}),this._tilesCamera=e.viewport.camera})}async loadTiles(r){if(this.tilesMap.has(r))return void e.utils.warn(`${r} already loaded`);const{ssp:i,ssp:{viewport:o}}=this,n=new t(r);null===this.lruCache?this.lruCache=n.lruCache:n.lruCache=this.lruCache,null===this.parseQueue?this.parseQueue=n.parseQueue:n.parseQueue=this.parseQueue,null===this.downloadQueue?this.downloadQueue=n.downloadQueue:n.downloadQueue=this.downloadQueue;const l=new s(n.manager);l.register(e=>new a(e));const{dracoLoader:d,ktx2Loader:u,meshoptDecoder:h}=i.manager.store.modelManager.gltfLoader;d&&l.setDRACOLoader(d),u&&l.setKTX2Loader(u),h&&l.setMeshoptDecoder(h),n.manager.addHandler(/\.gltf$/,l),this.tilesMap.set(r,n),n.setCamera(this._tilesCamera),n.setResolutionFromRenderer(this._tilesCamera,o.renderer),n.lruCache.maxSize=600,n.lruCache.minSize=300,n.lruCache.unloadPercent=.8,i.addObject(n.group);const p=()=>{this.cameraTransitionStart||(this.needsUpdate=!0,i.render())};return n.onLoadModel=()=>p(),n.onDisposeModel=(e,t)=>{if(t.cached.textures){const{textures:e}=t.cached;for(let t=0,s=e.length;t<s;t++){const s=e[t];s.mipmaps.length>0&&(s.mipmaps.length=0),s.image instanceof ImageBitmap&&s.image.close()}}},new Promise(e=>{n.onLoadTileSet=()=>{p(),e(n)}})}removeTiles(e){const t=this.tilesMap.get(e);return!!t&&(t.dispose(),this.tilesMap.delete(e),this.ssp.removeObject(t.group),!0)}}export{r as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-tiles",
|
|
3
3
|
"pluginName": "TilesPlugin",
|
|
4
|
-
"version": "2.13.
|
|
4
|
+
"version": "2.13.17",
|
|
5
5
|
"description": "3D Tiles plugin for SoonSpace.js",
|
|
6
6
|
"main": "dist/index.esm.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
],
|
|
15
15
|
"author": "xunwei",
|
|
16
16
|
"license": "UNLICENSED",
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "8afa5fda9a0ef2c080060e7d8e71a8bf168fd4d2",
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"
|
|
19
|
+
"3d-tiles-renderer": "^0.4.14",
|
|
20
|
+
"soonspacejs": "2.13.17"
|
|
20
21
|
}
|
|
21
22
|
}
|