@soonspacejs/plugin-tiles 2.10.10 → 2.10.13
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 +3 -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{Matrix4 as s,DefaultLoadingManager as r,PointsMaterial as n,Vector3 as i,BufferGeometry as o,BufferAttribute as a,Color as l,Points as c,Quaternion as h,InstancedMesh as d,Group as u,Ray as p,Box3 as m,Spherical as g,MathUtils as _,Sphere as f,LoadingManager as b,Vector2 as w,Frustum as T}from"three";function y(e){let t;try{t=new URL(e,"http://fakehost.com/")}catch(e){return null}const s=t.pathname.split("/").pop(),r=s.lastIndexOf(".");if(-1===r||r===s.length-1)return null;return s.substring(r+1)}class x{constructor(){this.maxSize=800,this.minSize=600,this.unloadPercent=.05,this.itemSet=new Map,this.itemList=[],this.usedSet=new Set,this.callbacks=new Map,this.unloadPriorityCallback=null;const e=this.itemSet;this.defaultPriorityCallback=t=>e.get(t)}isFull(){return this.itemSet.size>=this.maxSize}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}remove(e){const t=this.usedSet,s=this.itemSet,r=this.itemList,n=this.callbacks;if(s.has(e)){n.get(e)(e);const i=r.indexOf(e);return r.splice(i,1),t.delete(e),s.delete(e),n.delete(e),!0}return!1}markUsed(e){const t=this.itemSet,s=this.usedSet;t.has(e)&&!s.has(e)&&(t.set(e,Date.now()),s.add(e))}markAllUnused(){this.usedSet.clear()}unloadUnusedContent(){const e=this.unloadPercent,t=this.minSize,s=this.itemList,r=this.itemSet,n=this.usedSet,i=this.callbacks,o=s.length-n.size,a=s.length-t,l=this.unloadPriorityCallback||this.defaultPriorityCallback;if(a>0&&o>0){s.sort(((e,t)=>{const s=n.has(e),r=n.has(t);return s&&r?0:s||r?s?1:-1:l(t)-l(e)}));const c=Math.min(a,o),h=Math.max(t*e,c*e);let d=Math.min(h,o);d=Math.ceil(d);const u=s.splice(0,d);for(let e=0,t=u.length;e<t;e++){const t=u[e];i.get(t)(t),r.delete(t),i.delete(t)}}}scheduleUnload(e=!0){var t;this.scheduled||(this.scheduled=!0,t=()=>{this.scheduled=!1,this.unloadUnusedContent(),e&&this.markAllUnused()},Promise.resolve().then(t))}}class S{constructor(){this.maxJobs=6,this.items=[],this.callbacks=new Map,this.currJobs=0,this.scheduled=!1,this.autoUpdate=!0,this.priorityCallback=()=>{throw new Error("PriorityQueue: PriorityCallback function not defined.")},this.schedulingCallback=e=>{requestAnimationFrame(e)},this._runjobs=()=>{this.tryRunJobs(),this.scheduled=!1}}sort(){const e=this.priorityCallback;this.items.sort(e)}add(e,t){return new Promise(((s,r)=>{const n=this.items,i=this.callbacks;n.push(e),i.set(e,((...e)=>t(...e).then(s).catch(r))),this.autoUpdate&&this.scheduleJobRun()}))}remove(e){const t=this.items,s=this.callbacks,r=t.indexOf(e);-1!==r&&(t.splice(r,1),s.delete(e))}tryRunJobs(){this.sort();const e=this.items,t=this.callbacks,s=this.maxJobs;let r=this.currJobs;for(;s>r&&e.length>0;){r++;const s=e.pop(),n=t.get(s);t.delete(s),n(s).then((()=>{this.currJobs--,this.autoUpdate&&this.scheduleJobRun()})).catch((()=>{this.currJobs--,this.autoUpdate&&this.scheduleJobRun()}))}this.currJobs=r}scheduleJobRun(){this.scheduled||(this.schedulingCallback(this._runjobs),this.scheduled=!0)}}const C=3,L=4,v=6378137;function E(e){return e===C||e===L}function R(e,t){return e.__lastFrameVisited===t&&e.__used}function P(e,t){e.__lastFrameVisited!==t&&(e.__lastFrameVisited=t,e.__used=!1,e.__inFrustum=!1,e.__isLeaf=!1,e.__visible=!1,e.__active=!1,e.__error=1/0,e.__distanceFromCamera=1/0,e.__childrenWereVisible=!1,e.__allChildrenLoaded=!1)}function U(e,t,s,r){if(r.ensureChildrenArePreprocessed(e),P(e,t),e.__used=!0,s.markUsed(e),e.__contentEmpty){const n=e.children;for(let e=0,i=n.length;e<i;e++)U(n[e],t,s,r)}}function M(e,t,s){s.ensureChildrenArePreprocessed(e);if(e.__contentEmpty&&(!e.__externalTileSet||E(e.__loadingState))){const r=e.children;for(let e=0,n=r.length;e<n;e++){const n=r[e];n.__depthFromRenderedParent=t,M(n,t,s)}}else s.requestTileContents(e)}function O(e,t=null,s=null,r=null,n=0){if(t&&t(e,r,n))return void(s&&s(e,r,n));const i=e.children;for(let r=0,o=i.length;r<o;r++)O(i[r],t,s,e,n+1);s&&s(e,r,n)}function A(e,t){t.ensureChildrenArePreprocessed(e);const s=t.stats,r=t.frameCount,n=t.errorTarget,i=t.maxDepth,o=t.loadSiblings,a=t.lruCache,l=t.stopAtEmptyTiles;P(e,r);if(!1===t.tileInView(e))return!1;if(e.__used=!0,a.markUsed(e),e.__inFrustum=!0,s.inFrustum++,(l||!e.__contentEmpty)&&!e.__externalTileSet){t.calculateError(e);if(e.__error<=n)return!0;if(t.maxDepth>0&&e.__depth+1>=i)return!0}let c=!1;const h=e.children;for(let e=0,s=h.length;e<s;e++){const s=A(h[e],t);c=c||s}if(c&&o)for(let e=0,s=h.length;e<s;e++){U(h[e],r,a,t)}return!0}function F(e,t){const s=t.stats,r=t.frameCount;if(!R(e,r))return;s.used++;const n=e.children;let i=!1;for(let e=0,t=n.length;e<t;e++){const t=n[e];i=i||R(t,r)}if(i){let s=!1,i=!0;for(let e=0,o=n.length;e<o;e++){const o=n[e];if(F(o,t),s=s||o.__wasSetVisible||o.__childrenWereVisible,R(o,r)){const e=o.__allChildrenLoaded||!o.__contentEmpty&&E(o.__loadingState)||o.__externalTileSet&&o.__loadingState===L;i=i&&e}}e.__childrenWereVisible=s,e.__allChildrenLoaded=i}else e.__isLeaf=!0}function D(e,t){const s=t.stats,r=t.frameCount;if(!R(e,r))return;const n=e.parent,i=n?n.__depthFromRenderedParent:-1;e.__depthFromRenderedParent=i;const o=t.lruCache;if(e.__isLeaf)return e.__depthFromRenderedParent++,void(e.__loadingState===C?(e.__inFrustum&&(e.__visible=!0,s.visible++),e.__active=!0,s.active++):o.isFull()||e.__contentEmpty&&!e.__externalTileSet||t.requestTileContents(e));const a=(t.errorTarget+1)*t.errorThreshold,l=e.__error<=a,c=l||"ADD"===e.refine,h=!e.__contentEmpty,d=h||e.__externalTileSet,u=E(e.__loadingState)&&d,p=e.__childrenWereVisible,m=e.children,g=e.__allChildrenLoaded;if(c&&h&&e.__depthFromRenderedParent++,c&&!u&&!o.isFull()&&d&&t.requestTileContents(e),(l&&!g&&!p&&u||"ADD"===e.refine&&u)&&(e.__inFrustum&&(e.__visible=!0,s.visible++),e.__active=!0,s.active++),"ADD"!==e.refine&&l&&!g&&u)for(let s=0,n=m.length;s<n;s++){const n=m[s];R(n,r)&&!o.isFull()&&(n.__depthFromRenderedParent=e.__depthFromRenderedParent+1,M(n,n.__depthFromRenderedParent,t))}else for(let e=0,s=m.length;e<s;e++){const s=m[e];R(s,r)&&D(s,t)}}function k(e,t){const s=R(e,t.frameCount);if(s||e.__usedLastFrame){let r=!1,n=!1;s&&(r=e.__active,n=t.displayActiveTiles&&e.__active||e.__visible),e.__contentEmpty||e.__loadingState!==C||(e.__wasSetActive!==r&&t.setTileActive(e,r),e.__wasSetVisible!==n&&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++){k(i[e],t)}}}const I=(e,t)=>e.__depth!==t.__depth?e.__depth>t.__depth?-1:1:e.__inFrustum!==t.__inFrustum?e.__inFrustum?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:0,N=e=>1/(e.__depthFromRenderedParent+1);class V{get rootTileSet(){const e=this.tileSets[this.rootURL];return!e||e instanceof Promise?null:e}get root(){const e=this.rootTileSet;return e?e.root:null}constructor(e){this.tileSets={},this.rootURL=e,this.fetchOptions={},this.preprocessURL=null;const t=new x;t.unloadPriorityCallback=N;const s=new S;s.maxJobs=4,s.priorityCallback=I;const r=new S;r.maxJobs=1,r.priorityCallback=I,this.lruCache=t,this.downloadQueue=s,this.parseQueue=r,this.stats={parsing:0,downloading:0,failed:0,inFrustum:0,used:0,active:0,visible:0},this.frameCount=0,this.errorTarget=6,this.errorThreshold=1/0,this.loadSiblings=!0,this.displayActiveTiles=!1,this.maxDepth=1/0,this.stopAtEmptyTiles=!0}traverse(e,t){const s=this.tileSets[this.rootURL];s&&s.root&&O(s.root,((t,...s)=>(this.ensureChildrenArePreprocessed(t),!!e&&e(t,...s))),t)}update(){const e=this.stats,t=this.lruCache,s=this.tileSets,r=s[this.rootURL];if(!(this.rootURL in s))return void this.loadRootTileSet(this.rootURL);if(!r||!r.root)return;const n=r.root;e.inFrustum=0,e.used=0,e.active=0,e.visible=0,this.frameCount++,A(n,this),F(n,this),D(n,this),k(n,this),t.scheduleUnload()}parseTile(e,t,s){return null}disposeTile(e){}preprocessNode(e,t,s=null){e.content&&(!("uri"in e.content)&&"url"in e.content&&(e.content.uri=e.content.url,delete e.content.url),e.content.uri&&(e.content.uri=new URL(e.content.uri,t+"/").toString()),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||[];if(e.content&&e.content.uri){const t=y(e.content.uri),s=Boolean(t&&"json"===t.toLowerCase());e.__externalTileSet=s,e.__contentEmpty=s}else e.__externalTileSet=!1,e.__contentEmpty=!0;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.__childrenWereVisible=!1,e.__allChildrenLoaded=!1,e.__wasSetActive=!1,e.__active=!1,e.__loadingState=0,e.__loadIndex=0,e.__loadAbort=null,e.__depthFromRenderedParent=-1,null===s?(e.__depth=0,e.refine=e.refine||"REPLACE"):(e.__depth=s.__depth+1,e.refine=e.refine||s.refine),e.__basePath=t}setTileActive(e,t){}setTileVisible(e,t){}calculateError(e){return 0}tileInView(e){return!0}ensureChildrenArePreprocessed(e){const t=e.children;for(let s=0,r=t.length;s<r;s++){const r=t[s];if("__depth"in r)break;this.preprocessNode(r,e.__basePath,e)}}resetFailedTiles(){const e=this.stats;0!==e.failed&&(this.traverse((e=>{e.__loadingState===L&&(e.__loadingState=0)})),e.failed=0)}fetchTileSet(e,t,s=null){return fetch(e,t).then((t=>{if(t.ok)return t.json();throw new Error(`TilesRenderer: Failed to load tileset "${e}" with status ${t.status} : ${t.statusText}`)})).then((t=>{const r=t.asset.version;console.assert("1.0"===r||"0.0"===r,'asset.version is expected to be a string of "1.0" or "0.0"');let n=e.replace(/\/[^\/]*\/?$/,"");return n=new URL(n,window.location.href).toString(),this.preprocessNode(t.root,n,s),t}))}loadRootTileSet(e){const t=this.tileSets;if(e in t)return t[e]instanceof Error?Promise.reject(t[e]):Promise.resolve(t[e]);{const s=this.fetchTileSet(this.preprocessURL?this.preprocessURL(e):e,this.fetchOptions).then((s=>{t[e]=s}));return s.catch((s=>{console.error(s),t[e]=s})),t[e]=s,s}}requestTileContents(e){if(0!==e.__loadingState)return;const t=this.stats,s=this.lruCache,r=this.downloadQueue,n=this.parseQueue,i=e.__externalTileSet;s.add(e,(e=>{1===e.__loadingState?(e.__loadAbort.abort(),e.__loadAbort=null):i?e.children.length=0:this.disposeTile(e),1===e.__loadingState?t.downloading--:2===e.__loadingState&&t.parsing--,e.__loadingState=0,e.__loadIndex++,n.remove(e),r.remove(e)})),e.__loadIndex++;const o=e.__loadIndex,a=new AbortController,l=a.signal;t.downloading++,e.__loadAbort=a,e.__loadingState=1;const c=i=>{e.__loadIndex===o&&("AbortError"!==i.name?(n.remove(e),r.remove(e),2===e.__loadingState?t.parsing--:1===e.__loadingState&&t.downloading--,t.failed++,console.error(`TilesRenderer : Failed to load tile at url "${e.content.uri}".`),console.error(i),e.__loadingState=L):s.remove(e))};i?r.add(e,(e=>{if(e.__loadIndex!==o)return Promise.resolve();const t=this.preprocessURL?this.preprocessURL(e.content.uri):e.content.uri;return this.fetchTileSet(t,Object.assign({signal:l},this.fetchOptions),e)})).then((s=>{e.__loadIndex===o&&(t.downloading--,e.__loadAbort=null,e.__loadingState=C,e.children.push(s.root))})).catch(c):r.add(e,(e=>{if(e.__loadIndex!==o)return Promise.resolve();const t=this.preprocessURL?this.preprocessURL(e.content.uri):e.content.uri;return fetch(t,Object.assign({signal:l},this.fetchOptions))})).then((t=>{if(e.__loadIndex===o){if(t.ok)return t.arrayBuffer();throw new Error(`Failed to load model with error code ${t.status}`)}})).then((s=>{if(e.__loadIndex===o)return t.downloading--,t.parsing++,e.__loadAbort=null,e.__loadingState=2,n.add(e,(e=>{if(e.__loadIndex!==o)return Promise.resolve();const t=y(e.content.uri);return this.parseTile(s,e,t)}))})).then((()=>{e.__loadIndex===o&&(t.parsing--,e.__loadingState=C,e.__wasSetVisible&&this.setTileVisible(e,!0),e.__wasSetActive&&this.setTileActive(e,!0))})).catch(c)}dispose(){const e=this.lruCache,t=[];this.traverse((e=>(t.push(e),!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}}function B(e){return(new TextDecoder).decode(e)}class z{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(B(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: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 "${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 "${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}getBuffer(e,t){const{buffer:s,binOffset:r}=this;return s.slice(r+e,r+e+t)}}class j extends z{constructor(e,t,s,r,n){super(e,s,r,n),this.batchSize=t}getData(e,t=null,s=null){return super.getData(e,this.batchSize,t,s)}}class W{constructor(){this.fetchOptions={},this.workingPath=""}load(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)?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.")}}function H(e){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 G extends W{parse(e){const t=new DataView(e),s=H(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),o=t.getUint32(16,!0),a=t.getUint32(20,!0),l=t.getUint32(24,!0),c=e.slice(28,28+i+o),h=new z(c,0,i,o),d=28+i+o,u=e.slice(d,d+a+l),p=new j(u,h.getData("BATCH_LENGTH"),0,a,l),m=d+a+l;return{version:r,featureTable:h,batchTable:p,glbBytes:new Uint8Array(e,m,n-m)}}}class Q extends G{constructor(e=r){super(),this.manager=e,this.adjustmentTransform=new s}parse(e){const s=super.parse(e),r=s.glbBytes.slice().buffer;return new Promise(((e,n)=>{const i=this.manager,o=this.fetchOptions,a=i.getHandler("path.gltf")||new t(i);"include"===o.credentials&&"cors"===o.mode&&a.setCrossOrigin("use-credentials"),"credentials"in o&&a.setWithCredentials("include"===o.credentials),o.headers&&a.setRequestHeader(o.headers);let l=this.workingPath;!/[\\/]$/.test(l)&&l.length&&(l+="/");const c=this.adjustmentTransform;a.parse(r,l,(t=>{const{batchTable:r,featureTable:n}=s,{scene:i}=t,o=n.getData("RTC_CENTER");o&&(i.position.x+=o[0],i.position.y+=o[1],i.position.z+=o[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)}))}}class $ extends W{parse(e){const t=new DataView(e),s=H(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),o=t.getUint32(16,!0),a=t.getUint32(20,!0),l=t.getUint32(24,!0),c=e.slice(28,28+i+o),h=new z(c,0,i,o),d=28+i+o,u=e.slice(d,d+a+l),p=new j(u,h.getData("BATCH_LENGTH")||h.getData("POINTS_LENGTH"),0,a,l);return Promise.resolve({version:r,featureTable:h,batchTable:p})}}function q(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 J={RGB:"color",POSITION:"position"};class Y extends ${constructor(e=r){super(),this.manager=e}parse(e){return super.parse(e).then((async e=>{const{featureTable:t}=e,s=new n,r=t.header.extensions,h=new i;let d;if(r&&r["3DTILES_draco_point_compression"]){const{byteOffset:e,byteLength:n,properties:i}=r["3DTILES_draco_point_compression"],o=this.manager.getHandler("draco.drc");if(null==o)throw new Error("PNTSLoader: dracoLoader not available.");const a={};for(const e in i)if(e in J&&e in i){a[J[e]]=i[e]}const l={attributeIDs:a,attributeTypes:{position:"Float32Array",color:"Uint8Array"},useUniqueIDs:!0},c=t.getBuffer(e,n);d=await o.decodeGeometry(c,l),d.attributes.color&&(s.vertexColors=!0)}else{const e=t.getData("POINTS_LENGTH"),r=t.getData("POSITION",e,"FLOAT","VEC3"),n=t.getData("RGB",e,"UNSIGNED_BYTE","VEC3"),i=t.getData("RGBA",e,"UNSIGNED_BYTE","VEC4"),c=t.getData("RGB565",e,"UNSIGNED_SHORT","SCALAR"),u=t.getData("CONSTANT_RGBA",e,"UNSIGNED_BYTE","VEC4"),p=t.getData("POSITION_QUANTIZED",e,"UNSIGNED_SHORT","VEC3"),m=t.getData("QUANTIZED_VOLUME_SCALE",e,"FLOAT","VEC3"),g=t.getData("QUANTIZED_VOLUME_OFFSET",e,"FLOAT","VEC3");if(d=new o,p){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]=p[r]/65535*m[e]}h.x=g[0],h.y=g[1],h.z=g[2],d.setAttribute("position",new a(t,3,!1))}else d.setAttribute("position",new a(r,3,!1));if(null!==i)d.setAttribute("color",new a(i,4,!0)),s.vertexColors=!0,s.transparent=!0,s.depthWrite=!1;else if(null!==n)d.setAttribute("color",new a(n,3,!0)),s.vertexColors=!0;else if(null!==c){const t=new Uint8Array(3*e);for(let s=0;s<e;s++){const e=q(c[s]);for(let r=0;r<3;r++){t[3*s+r]=e[r]}}d.setAttribute("color",new a(t,3,!0)),s.vertexColors=!0}else if(null!==u){const e=new l(u[0],u[1],u[2]);s.color=e;const t=u[3]/255;t<1&&(s.opacity=t,s.transparent=!0,s.depthWrite=!1)}}["BATCH_LENGTH","NORMAL","NORMAL_OCT16P"].forEach((e=>{e in t.header&&console.warn(`PNTSLoader: Unsupported FeatureTable feature "${e}" detected.`)}));const u=new c(d,s);u.position.copy(h),e.scene=u,e.scene.featureTable=t;const p=t.getData("RTC_CENTER");return p&&(e.scene.position.x+=p[0],e.scene.position.y+=p[1],e.scene.position.z+=p[2]),e}))}}class Z extends W{parse(e){const t=new DataView(e),s=H(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),o=t.getUint32(16,!0),a=t.getUint32(20,!0),l=t.getUint32(24,!0),c=t.getUint32(28,!0),h=e.slice(32,32+i+o),d=new z(h,0,i,o),u=32+i+o,p=e.slice(u,u+a+l),m=new j(p,d.getData("INSTANCES_LENGTH"),0,a,l),g=u+a+l,_=new Uint8Array(e,g,n-g);let f=null,b=null;if(c)f=_,b=Promise.resolve();else{const e=this.resolveExternalURL(B(_));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=>{f=new Uint8Array(e)}))}return b.then((()=>({version:r,featureTable:d,batchTable:m,glbBytes:f})))}}const K=new i,X=new i,ee=new i,te=new i,se=new h,re=new i,ne=new s;class ie extends Z{constructor(e=r){super(),this.manager=e,this.adjustmentTransform=new s}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(((e,o)=>{const a=this.fetchOptions,l=this.manager,c=l.getHandler("path.gltf")||new t(l);"include"===a.credentials&&"cors"===a.mode&&c.setCrossOrigin("use-credentials"),"credentials"in a&&c.setWithCredentials("include"===a.credentials),a.headers&&c.setRequestHeader(a.headers);let h=this.workingPath;/[\\/]$/.test(h)||(h+="/");const u=this.adjustmentTransform;c.parse(n,h,(t=>{const n=s.getData("INSTANCES_LENGTH"),o=s.getData("POSITION",n,"FLOAT","VEC3"),a=s.getData("NORMAL_UP",n,"FLOAT","VEC3"),l=s.getData("NORMAL_RIGHT",n,"FLOAT","VEC3"),c=s.getData("SCALE_NON_UNIFORM",n,"FLOAT","VEC3"),h=s.getData("SCALE",n,"FLOAT","SCALAR");["RTC_CENTER","QUANTIZED_VOLUME_OFFSET","QUANTIZED_VOLUME_SCALE","EAST_NORTH_UP","POSITION_QUANTIZED","NORMAL_UP_OCT32P","NORMAL_RIGHT_OCT32P"].forEach((e=>{e in s.header&&console.warn(`I3DMLoader: Unsupported FeatureTable feature "${e}" detected.`)}));const p=new Map,m=[];t.scene.traverse((e=>{if(e.isMesh){const{geometry:t,material:s}=e,r=new d(t,s,n);r.position.copy(e.position),r.rotation.copy(e.rotation),r.scale.copy(e.scale),m.push(r),p.set(e,r)}}));const g=new i;for(let e=0;e<n;e++)g.x+=o[3*e+0]/n,g.y+=o[3*e+1]/n,g.z+=o[3*e+2]/n;p.forEach(((e,t)=>{const s=t.parent;s&&(s.remove(t),s.add(e),e.updateMatrixWorld(),e.position.copy(g).applyMatrix4(e.matrixWorld))}));for(let e=0;e<n;e++){te.set(o[3*e+0]-g.x,o[3*e+1]-g.y,o[3*e+2]-g.z),a?(X.set(a[3*e+0],a[3*e+1],a[3*e+2]),ee.set(l[3*e+0],l[3*e+1],l[3*e+2]),K.crossVectors(ee,X).normalize(),ne.makeBasis(ee,X,K),se.setFromRotationMatrix(ne)):se.set(0,0,0,1),h?re.setScalar(h[e]):c?re.set(c[3*e+0],c[3*e+1],c[3*e+2]):re.set(1,1,1),ne.compose(te,se,re).multiply(u);for(let t=0,s=m.length;t<s;t++){m[t].setMatrixAt(e,ne)}}t.batchTable=r,t.featureTable=s,t.scene.batchTable=r,t.scene.featureTable=s,e(t)}),o)}))}))}}class oe extends W{parse(e){const t=new DataView(e),s=H(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),o=[];let a=16;for(let t=0;t<i;t++){const t=new DataView(e,a,12),s=H(t),r=t.getUint32(4,!0),n=t.getUint32(8,!0),i=new Uint8Array(e,a,n);o.push({type:s,buffer:i,version:r}),a+=n}return{version:r,tiles:o}}}class ae extends oe{constructor(e=r){super(),this.manager=e,this.adjustmentTransform=new s}parse(e){const t=super.parse(e),s=this.manager,r=this.adjustmentTransform,n=[];for(const e in t.tiles){const{type:i,buffer:o}=t.tiles[e];switch(i){case"b3dm":{const e=o.slice(),t=new Q(s);t.workingPath=this.workingPath,t.fetchOptions=this.fetchOptions,t.adjustmentTransform.copy(r);const i=t.parse(e.buffer);n.push(i);break}case"pnts":{const e=o.slice(),t=new Y(s);t.workingPath=this.workingPath,t.fetchOptions=this.fetchOptions;const r=t.parse(e.buffer);n.push(r);break}case"i3dm":{const e=o.slice(),t=new ie(s);t.workingPath=this.workingPath,t.fetchOptions=this.fetchOptions,t.adjustmentTransform.copy(r);const i=t.parse(e.buffer);n.push(i);break}}}return Promise.all(n).then((e=>{const t=new u;return e.forEach((e=>{t.add(e.scene)})),{tiles:e,scene:t}}))}}class le{constructor(){this.name="CESIUM_RTC"}afterRoot(e){if(e.parser.json.extensions&&e.parser.json.extensions.CESIUM_RTC){const{center:t}=e.parser.json.extensions.CESIUM_RTC;t&&(e.scene.position.x+=t[0],e.scene.position.y+=t[1],e.scene.position.z+=t[2])}}}class ce extends W{constructor(e=r){super(),this.manager=e}parse(e){return new Promise(((s,r)=>{const n=this.manager,i=this.fetchOptions;let o=n.getHandler("path.gltf")||n.getHandler("path.glb");o||(o=new t(n),o.register((()=>new le)),"include"===i.credentials&&"cors"===i.mode&&o.setCrossOrigin("use-credentials"),"credentials"in i&&o.setWithCredentials("include"===i.credentials),i.headers&&o.setRequestHeader(i.headers));let a=o.resourcePath||o.path||this.workingPath;!/[\\/]$/.test(a)&&a.length&&(a+="/"),o.parse(e,a,(e=>{s(e)}),r)}))}}const he=new s;class de extends u{constructor(e){super(),this.name="TilesRenderer.TilesGroup",this.tilesRenderer=e}raycast(e,t){this.tilesRenderer.optimizeRaycast&&this.tilesRenderer.raycast(e,t)}updateMatrixWorld(e){if(this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldNeedsUpdate||e){null===this.parent?he.copy(this.matrix):he.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1;const e=he.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(he);const e=this.children;for(let t=0,s=e.length;t<s;t++)e[t].updateMatrixWorld()}}}}const ue=new s,pe=new p,me=new i,ge=[];function _e(e,t){return e.distance-t.distance}function fe(e,t,s){e.traverse((e=>{Object.getPrototypeOf(e).raycast.call(e,t,s)}))}function be(e,t,s,r=null){const{group:n,activeTiles:i}=e;e.ensureChildrenArePreprocessed(t),null===r&&(r=pe,ue.copy(n.matrixWorld).invert(),r.copy(s.ray).applyMatrix4(ue));const o=[],a=t.children;for(let e=0,t=a.length;e<t;e++){const t=a[e];if(!t.__used)continue;null!==t.cached.boundingVolume.intersectRay(r,me)&&(me.applyMatrix4(n.matrixWorld),o.push({distance:me.distanceToSquared(s.ray.origin),tile:t}))}o.sort(_e);let l=null,c=1/0;if(i.has(t)){const e=function(e,t){fe(e,t,ge),ge.sort(_e);const s=ge[0]||null;return ge.length=0,s}(t.cached.scene,s);e&&(l=e,c=e.distance*e.distance)}for(let t=0,n=o.length;t<n;t++){const n=o[t],i=n.distance,a=n.tile;if(i>c)break;const h=be(e,a,s,r);if(h){const e=h.distance*h.distance;e<c&&(l=h,c=e)}}return l}function we(e,t,s,r,n=null){const{group:i,activeTiles:o}=e,{scene:a,boundingVolume:l}=t.cached;if(e.ensureChildrenArePreprocessed(t),null===n&&(n=pe,ue.copy(i.matrixWorld).invert(),n.copy(s.ray).applyMatrix4(ue)),!t.__used||!l.intersectsRay(n))return;o.has(t)&&fe(a,s,r);const c=t.children;for(let t=0,i=c.length;t<i;t++)we(e,c[t],s,r,n)}class Te{constructor(e=new m,t=new s){this.box=e.clone(),this.transform=t.clone(),this.inverseTransform=new s,this.points=new Array(8).fill().map((()=>new i))}update(){const{points:e,inverseTransform:t,transform:s,box:r}=this;t.copy(s).invert();const{min:n,max:i}=r;let o=0;for(let t=-1;t<=1;t+=2)for(let r=-1;r<=1;r+=2)for(let a=-1;a<=1;a+=2)e[o].set(t<0?n.x:i.x,r<0?n.y:i.y,a<0?n.z:i.z).applyMatrix4(s),o++}intersectsFrustum(e){const{points:t}=this,{planes:s}=e;for(let e=0;e<6;e++){const r=s[e];let n=-1/0;for(let e=0;e<8;e++){const s=t[e],i=r.distanceToPoint(s);n=n<i?i:n}if(n<0)return!1}return!0}}new g,new i;const ye=new g,xe=new i,Se=new i,Ce=new i,Le=new i,ve=new i,Ee=new i,Re=new i,Pe=new i;class Ue{constructor(e=1,t=1,s=1){this.radius=new i(e,t,s)}constructLatLonFrame(e,t,s){return this.getCartographicToPosition(e,t,0,Pe),this.getCartographicToNormal(e,t,Re),this.getNorthernTangent(e,t,Ee),ve.crossVectors(Ee,Re),s.makeBasis(ve,Ee,Re).setPosition(Pe)}getNorthernTangent(e,t,s,r=Le){let n=1,i=e+1e-7;e>Math.PI/4&&(n=-1,i=e-1e-7);const o=this.getCartographicToNormal(e,t,Se).normalize(),a=this.getCartographicToNormal(i,t,Ce).normalize();return r.crossVectors(o,a).normalize().multiplyScalar(n),s.crossVectors(r,o).normalize()}getCartographicToPosition(e,t,s,r){this.getCartographicToNormal(e,t,xe);const n=this.radius;Se.copy(xe),Se.x*=n.x**2,Se.y*=n.y**2,Se.z*=n.z**2;const i=Math.sqrt(xe.dot(Se));return Se.divideScalar(i),r.copy(Se).addScaledVector(xe,s)}getPositionToCartographic(e,t){this.getPositionToSurfacePoint(e,Se),this.getPositionToNormal(e,xe);const s=Ce.subVectors(e,Se);return t.lon=Math.atan2(xe.y,xe.x),t.lat=Math.asin(xe.z),t.height=Math.sign(s.dot(e))*s.length(),t}getCartographicToNormal(e,t,s){return ye.set(1,-e+Math.PI/2,t),s.setFromSpherical(ye).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,o=e.x*e.x*r,a=e.y*e.y*n,l=e.z*e.z*i,c=o+a+l,h=Math.sqrt(1/c),d=Se.copy(e).multiplyScalar(h);if(c<.1)return isFinite(h)?t.copy(d):null;const u=Ce.set(d.x*r*2,d.y*n*2,d.z*i*2);let p,m,g,_,f,b,w,T,y,x,S,C=(1-h)*e.length()/(.5*u.length()),L=0;do{C-=L,g=1/(1+C*r),_=1/(1+C*n),f=1/(1+C*i),b=g*g,w=_*_,T=f*f,y=b*g,x=w*_,S=T*f,p=o*b+a*w+l*T-1,m=o*y*r+a*x*n+l*S*i;L=p/(-2*m)}while(Math.abs(p)>1e-12);return t.set(e.x*g,e.y*_,e.z*f)}}const Me=Math.PI,Oe=Me/2,Ae=new i,Fe=new i,De=new i,ke=new s;let Ie=0;const Ne=[];function Ve(e=!1){return e?(Ne[Ie]||(Ne[Ie]=new i),Ie++,Ne[Ie-1]):new i}function Be(){Ie=0}class ze extends Ue{constructor(e,t,s,r=-Oe,n=Oe,i=0,o=2*Me,a=0,l=0){super(e,t,s),this.latStart=r,this.latEnd=n,this.lonStart=i,this.lonEnd=o,this.heightStart=a,this.heightEnd=l}_getPoints(e=!1){const{latStart:t,latEnd:s,lonStart:r,lonEnd:n,heightStart:i,heightEnd:o}=this,a=_.mapLinear(.5,0,1,t,s),l=_.mapLinear(.5,0,1,r,n),c=Math.floor(r/Oe)*Oe,h=[[-Me/2,0],[Me/2,0],[0,c],[0,c+Me/2],[0,c+Me],[0,c+3*Me/2],[t,n],[s,n],[t,r],[s,r],[0,r],[0,n],[a,l],[t,l],[s,l],[a,r],[a,n]],d=[],u=h.length;for(let a=0;a<=1;a++){const l=_.mapLinear(a,0,1,i,o);for(let i=0,o=u;i<o;i++){const[o,a]=h[i];if(o>=t&&o<=s&&a>=r&&a<=n){const t=Ve(e);d.push(t),this.getCartographicToPosition(o,a,l,t)}}}return d}getBoundingBox(e,t){Be();const{latStart:s,latEnd:r,lonStart:n,lonEnd:i}=this;if(r-s<Me/2){const e=_.mapLinear(.5,0,1,s,r),o=_.mapLinear(.5,0,1,n,i);this.getCartographicToNormal(e,o,De),Fe.set(0,0,1),Ae.crossVectors(Fe,De),Fe.crossVectors(Ae,De),t.makeBasis(Ae,Fe,De)}else Ae.set(1,0,0),Fe.set(0,1,0),De.set(0,0,1),t.makeBasis(Ae,Fe,De);ke.copy(t).invert();const o=this._getPoints(!0);for(let e=0,t=o.length;e<t;e++)o[e].applyMatrix4(ke);e.makeEmpty(),e.setFromPoints(o)}getBoundingSphere(e,t){Be();const s=this._getPoints(!0);e.makeEmpty(),e.setFromPoints(s,t)}}const je=new i,We=new i,He=new i,Ge=new i,Qe=new i,$e=new i,qe=new p;class Je{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&&(qe.copy(e).applyMatrix4(s.inverseTransform),!qe.intersectsBox(s.box)))}intersectRay(e,t=null){const s=this.sphere,r=this.obb||this.regionObb;let n=-1/0,i=-1/0;s&&e.intersectSphere(s,Qe)&&(n=s.containsPoint(e.origin)?0:e.origin.distanceToSquared(Qe)),r&&(qe.copy(e).applyMatrix4(r.inverseTransform),qe.intersectBox(r.box,$e)&&(i=r.box.containsPoint(qe.origin)?0:qe.origin.distanceToSquared($e)));const o=Math.max(n,i);return o===-1/0?null:(e.at(Math.sqrt(o),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&&(Ge.copy(e).applyMatrix4(s.inverseTransform),n=s.box.distanceToPoint(Ge)),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))}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 Te;je.set(e[3],e[4],e[5]),We.set(e[6],e[7],e[8]),He.set(e[9],e[10],e[11]);const r=je.length(),n=We.length(),i=He.length();je.normalize(),We.normalize(),He.normalize(),0===r&&je.crossVectors(We,He),0===n&&We.crossVectors(je,He),0===i&&He.crossVectors(je,We),s.transform.set(je.x,We.x,He.x,e[0],je.y,We.y,He.y,e[1],je.z,We.z,He.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 f;i.center.set(e,t,s),i.radius=r,i.applyMatrix4(n),this.sphere=i}setRegionData(e,t,s,r,n,i){const o=new ze(v,v,6356752.314245179,t,r,e,s,n,i),a=new Te;o.getBoundingBox(a.box,a.transform),a.update(),this.region=o,this.regionObb=a}}const Ye=Symbol("INITIAL_FRUSTUM_CULLED"),Ze=new s,Ke=new s,Xe=new i,et=new i(1,0,0),tt=new i(0,1,0);function st(e,t){e.traverse((e=>{e.frustumCulled=e[Ye]&&t}))}class rt extends V{get autoDisableRendererCulling(){return this._autoDisableRendererCulling}set autoDisableRendererCulling(e){this._autoDisableRendererCulling!==e&&(super._autoDisableRendererCulling=e,this.forEachLoadedModel((t=>{st(t,!e)})))}constructor(...e){super(...e),this.group=new de(this),this.cameras=[],this.cameraMap=new Map,this.cameraInfo=[],this.activeTiles=new Set,this.visibleTiles=new Set,this._autoDisableRendererCulling=!0,this.optimizeRaycast=!0,this.onLoadTileSet=null,this.onLoadModel=null,this.onDisposeModel=null,this.onTileVisibilityChange=null;const t=new b;t.setURLModifier((e=>this.preprocessURL?this.preprocessURL(e):e)),this.manager=t;const s=this;this._overridenRaycast=function(e,t){s.optimizeRaycast||Object.getPrototypeOf(this).raycast.call(this,e,t)}}getBounds(e){if(!this.root)return!1;const t=this.root.cached.boundingVolume;return!t||(t.getAABB(e),!0)}getOrientedBounds(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.scene;s&&e(s,t)}))}raycast(e,t){if(this.root)if(e.firstHitOnly){const s=be(this,this.root,e);s&&t.push(s)}else we(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 w),t.push(e),!0)}setResolution(e,t,s){const r=this.cameraMap;return!!r.has(e)&&(t instanceof w?r.get(e).copy(t):r.get(e).set(t,s),!0)}setResolutionFromRenderer(e,t){const s=this.cameraMap;if(!s.has(e))return!1;const r=s.get(e);return t.getSize(r),r.multiplyScalar(t.getPixelRatio()),!0}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),!0}return!1}fetchTileSet(e,...t){const s=super.fetchTileSet(e,...t);return s.then((t=>{this.onLoadTileSet&&Promise.resolve().then((()=>{this.onLoadTileSet(t,e)}))})),s}update(){const e=this.group,t=this.cameras,s=this.cameraMap,r=this.cameraInfo;if(0===t.length)return void console.warn("TilesRenderer: no cameras defined. Cannot update 3d tiles.");for(;r.length>t.length;)r.pop();for(;r.length<t.length;)r.push({frustum:new T,isOrthographic:!1,sseDenominator:-1,position:new i,invScale:-1,pixelSize:0});Ke.copy(e.matrixWorld).invert(),Xe.setFromMatrixScale(Ke);const n=Xe.x;Math.abs(Math.max(Xe.x-Xe.y,Xe.x-Xe.z))>1e-6&&console.warn("ThreeTilesRenderer : Non uniform scale used for tile which may cause issues when calculating screen space error.");for(let i=0,o=r.length;i<o;i++){const o=t[i],a=r[i],l=a.frustum,c=a.position,h=s.get(o);0!==h.width&&0!==h.height||console.warn("TilesRenderer: resolution for camera error calculation is not set.");const d=o.projectionMatrix.elements;if(a.isOrthographic=1===d[15],a.isOrthographic){const e=2/d[0],t=2/d[5];a.pixelSize=Math.max(t/h.height,e/h.width)}else a.sseDenominator=2/d[5]/h.height;a.invScale=n,Ze.copy(e.matrixWorld),Ze.premultiply(o.matrixWorldInverse),Ze.premultiply(o.projectionMatrix),l.setFromProjectionMatrix(Ze),c.set(0,0,0),c.applyMatrix4(o.matrixWorld),c.applyMatrix4(Ke)}super.update()}preprocessNode(e,t,r=null){super.preprocessNode(e,t,r);const n=new s;if(e.transform){const t=e.transform;for(let e=0;e<16;e++)n.elements[e]=t[e]}else n.identity();r&&n.premultiply(r.cached.transform);const i=(new s).copy(n).invert(),o=new Je;"sphere"in e.boundingVolume&&o.setSphereData(...e.boundingVolume.sphere,n),"box"in e.boundingVolume&&o.setObbData(e.boundingVolume.box,n),"region"in e.boundingVolume&&o.setRegionData(...e.boundingVolume.region),e.cached={loadIndex:0,transform:n,transformInverse:i,active:!1,inFrustum:[],boundingVolume:o,scene:null,geometry:null,material:null}}parseTile(e,t,r){t._loadIndex=t._loadIndex||0,t._loadIndex++;const n=t.content.uri.split(/[\\\/]/g);n.pop();const i=n.join("/"),o=this.fetchOptions,a=this.manager,l=t._loadIndex;let c=null;const h=this.rootTileSet.asset&&this.rootTileSet.asset.gltfUpAxis||"y",d=t.cached,u=d.transform,p=new s;switch(h.toLowerCase()){case"x":p.makeRotationAxis(tt,-Math.PI/2);break;case"y":p.makeRotationAxis(et,Math.PI/2);break;case"z":p.identity()}const m=(H(e)||r).toLowerCase();switch(m){case"b3dm":{const t=new Q(a);t.workingPath=i,t.fetchOptions=o,t.adjustmentTransform.copy(p),c=t.parse(e);break}case"pnts":{const t=new Y(a);t.workingPath=i,t.fetchOptions=o,c=t.parse(e);break}case"i3dm":{const t=new ie(a);t.workingPath=i,t.fetchOptions=o,t.adjustmentTransform.copy(p),c=t.parse(e);break}case"cmpt":{const t=new ae(a);t.workingPath=i,t.fetchOptions=o,t.adjustmentTransform.copy(p),c=t.parse(e).then((e=>e.scene));break}case"gltf":case"glb":const t=new ce(a);t.workingPath=i,t.fetchOptions=o,c=t.parse(e);break;default:console.warn(`TilesRenderer: Content type "${m}" not supported.`),c=Promise.resolve(null)}return c.then((e=>{let s,r;if(e.isObject3D?(s=e,r=null):(s=e.scene,r=e),t._loadIndex!==l)return;s.updateMatrix(),"glb"!==m&&"gltf"!==m||s.matrix.multiply(p),s.matrix.premultiply(u),s.matrix.decompose(s.position,s.quaternion,s.scale),s.traverse((e=>{e[Ye]=e.frustumCulled})),st(s,!this.autoDisableRendererCulling),s.traverse((e=>{e.raycast=this._overridenRaycast}));const n=[],i=[],o=[];s.traverse((e=>{if(e.geometry&&i.push(e.geometry),e.material){const t=e.material;n.push(e.material);for(const e in t){const s=t[e];s&&s.isTexture&&o.push(s)}}})),d.materials=n,d.geometry=i,d.textures=o,d.scene=s,d.metadata=r,this.onLoadModel&&this.onLoadModel(s,t)}))}disposeTile(e){const t=e.cached;if(t.scene){const s=t.materials,r=t.geometry,n=t.textures,i=t.scene.parent;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++){n[e].dispose()}i&&i.remove(t.scene),this.onDisposeModel&&this.onDisposeModel(t.scene,e),t.scene=null,t.materials=null,t.textures=null,t.geometry=null,t.metadata=null}this.activeTiles.delete(e),this.visibleTiles.delete(e),e._loadIndex++}setTileVisible(e,t){const s=e.cached.scene,r=this.visibleTiles,n=this.group;t?(n.add(s),r.add(e),s.updateMatrixWorld(!0)):(n.remove(s),r.delete(e)),this.onTileVisibilityChange&&this.onTileVisibilityChange(s,e,t)}setTileActive(e,t){const s=this.activeTiles;t?s.add(e):s.delete(e)}calculateError(e){const t=e.cached,s=t.inFrustum,r=this.cameras,n=this.cameraInfo,i=t.boundingVolume;let o=-1/0,a=1/0;for(let t=0,l=r.length;t<l;t++){if(!s[t])continue;const r=n[t],l=r.invScale;let c;if(r.isOrthographic){const t=r.pixelSize;c=e.geometricError/(t*l)}else{const t=i.distanceToPoint(r.position)*l,s=r.sseDenominator;c=e.geometricError/(t*s),a=Math.min(a,t)}o=Math.max(o,c)}e.__distanceFromCamera=a,e.__error=o}tileInView(e){const t=e.cached,s=t.boundingVolume,r=t.inFrustum,n=this.cameraInfo;let i=!1;for(let e=0,t=n.length;e<t;e++){const t=n[e].frustum;s.intersectsFrustum(t)?(i=!0,r[e]=!0):r[e]=!1}return i}}class nt{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 rt(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 o=new t(i.manager);o.register((()=>new le));const{dracoLoader:a,ktx2Loader:l,meshoptDecoder:c}=r.manager.store.modelManager.gltfLoader;a&&o.setDRACOLoader(a),l&&o.setKTX2Loader(l),c&&o.setMeshoptDecoder(c),i.manager.addHandler(/\.gltf$/,o),this.tilesMap.set(s,i),i.setCamera(this._tilesCamera),i.setResolutionFromRenderer(this._tilesCamera,n.renderer),i.lruCache.maxSize=300,i.lruCache.minSize=100,i.lruCache.unloadPercent=.5,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.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{nt as default};
|
|
1
|
+
import e from"soonspacejs";import{GLTFLoader as t}from"three/examples/jsm/loaders/GLTFLoader.js";import{Matrix4 as s,DefaultLoadingManager as r,PointsMaterial as n,Vector3 as i,BufferGeometry as o,BufferAttribute as a,Color as l,Points as c,Quaternion as h,InstancedMesh as d,Group as u,Ray as p,Box3 as m,Spherical as g,MathUtils as _,Sphere as f,LoadingManager as b,Vector2 as w,Frustum as T}from"three";function y(e){let t;try{t=new URL(e,"http://fakehost.com/")}catch(e){return null}const s=t.pathname.split("/").pop(),r=s.lastIndexOf(".");if(-1===r||r===s.length-1)return null;return s.substring(r+1)}class x{constructor(){this.maxSize=800,this.minSize=600,this.unloadPercent=.05,this.itemSet=new Map,this.itemList=[],this.usedSet=new Set,this.callbacks=new Map,this.unloadPriorityCallback=null;const e=this.itemSet;this.defaultPriorityCallback=t=>e.get(t)}isFull(){return this.itemSet.size>=this.maxSize}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}remove(e){const t=this.usedSet,s=this.itemSet,r=this.itemList,n=this.callbacks;if(s.has(e)){n.get(e)(e);const i=r.indexOf(e);return r.splice(i,1),t.delete(e),s.delete(e),n.delete(e),!0}return!1}markUsed(e){const t=this.itemSet,s=this.usedSet;t.has(e)&&!s.has(e)&&(t.set(e,Date.now()),s.add(e))}markAllUnused(){this.usedSet.clear()}unloadUnusedContent(){const e=this.unloadPercent,t=this.minSize,s=this.itemList,r=this.itemSet,n=this.usedSet,i=this.callbacks,o=s.length-n.size,a=s.length-t,l=this.unloadPriorityCallback||this.defaultPriorityCallback;if(a>0&&o>0){s.sort(((e,t)=>{const s=n.has(e),r=n.has(t);return s&&r?0:s||r?s?1:-1:l(t)-l(e)}));const c=Math.min(a,o),h=Math.max(t*e,c*e);let d=Math.min(h,o);d=Math.ceil(d);const u=s.splice(0,d);for(let e=0,t=u.length;e<t;e++){const t=u[e];i.get(t)(t),r.delete(t),i.delete(t)}}}scheduleUnload(e=!0){var t;this.scheduled||(this.scheduled=!0,t=()=>{this.scheduled=!1,this.unloadUnusedContent(),e&&this.markAllUnused()},Promise.resolve().then(t))}}class S{constructor(){this.maxJobs=6,this.items=[],this.callbacks=new Map,this.currJobs=0,this.scheduled=!1,this.autoUpdate=!0,this.priorityCallback=()=>{throw new Error("PriorityQueue: PriorityCallback function not defined.")},this.schedulingCallback=e=>{requestAnimationFrame(e)},this._runjobs=()=>{this.tryRunJobs(),this.scheduled=!1}}sort(){const e=this.priorityCallback;this.items.sort(e)}add(e,t){return new Promise(((s,r)=>{const n=this.items,i=this.callbacks;n.push(e),i.set(e,((...e)=>t(...e).then(s).catch(r))),this.autoUpdate&&this.scheduleJobRun()}))}remove(e){const t=this.items,s=this.callbacks,r=t.indexOf(e);-1!==r&&(t.splice(r,1),s.delete(e))}tryRunJobs(){this.sort();const e=this.items,t=this.callbacks,s=this.maxJobs;let r=this.currJobs;for(;s>r&&e.length>0;){r++;const s=e.pop(),n=t.get(s);t.delete(s),n(s).then((()=>{this.currJobs--,this.autoUpdate&&this.scheduleJobRun()})).catch((()=>{this.currJobs--,this.autoUpdate&&this.scheduleJobRun()}))}this.currJobs=r}scheduleJobRun(){this.scheduled||(this.schedulingCallback(this._runjobs),this.scheduled=!0)}}const C=3,L=4,E=6378137;function v(e){return e===C||e===L}function R(e,t){return e.__lastFrameVisited===t&&e.__used}function P(e,t){e.__lastFrameVisited!==t&&(e.__lastFrameVisited=t,e.__used=!1,e.__inFrustum=!1,e.__isLeaf=!1,e.__visible=!1,e.__active=!1,e.__error=1/0,e.__distanceFromCamera=1/0,e.__childrenWereVisible=!1,e.__allChildrenLoaded=!1)}function U(e,t,s,r){if(r.ensureChildrenArePreprocessed(e),P(e,t),e.__used=!0,s.markUsed(e),e.__contentEmpty){const n=e.children;for(let e=0,i=n.length;e<i;e++)U(n[e],t,s,r)}}function M(e,t,s){s.ensureChildrenArePreprocessed(e);if(e.__contentEmpty&&(!e.__externalTileSet||v(e.__loadingState))){const r=e.children;for(let e=0,n=r.length;e<n;e++){const n=r[e];n.__depthFromRenderedParent=t,M(n,t,s)}}else s.requestTileContents(e)}function O(e,t=null,s=null,r=null,n=0){if(t&&t(e,r,n))return void(s&&s(e,r,n));const i=e.children;for(let r=0,o=i.length;r<o;r++)O(i[r],t,s,e,n+1);s&&s(e,r,n)}function A(e,t){t.ensureChildrenArePreprocessed(e);const s=t.stats,r=t.frameCount,n=t.errorTarget,i=t.maxDepth,o=t.loadSiblings,a=t.lruCache,l=t.stopAtEmptyTiles;P(e,r);if(!1===t.tileInView(e))return!1;if(e.__used=!0,a.markUsed(e),e.__inFrustum=!0,s.inFrustum++,(l||!e.__contentEmpty)&&!e.__externalTileSet){t.calculateError(e);if(e.__error<=n)return!0;if(t.maxDepth>0&&e.__depth+1>=i)return!0}let c=!1;const h=e.children;for(let e=0,s=h.length;e<s;e++){const s=A(h[e],t);c=c||s}if(c&&o)for(let e=0,s=h.length;e<s;e++){U(h[e],r,a,t)}return!0}function F(e,t){const s=t.stats,r=t.frameCount;if(!R(e,r))return;s.used++;const n=e.children;let i=!1;for(let e=0,t=n.length;e<t;e++){const t=n[e];i=i||R(t,r)}if(i){let s=!1,i=!0;for(let e=0,o=n.length;e<o;e++){const o=n[e];if(F(o,t),s=s||o.__wasSetVisible||o.__childrenWereVisible,R(o,r)){const e=o.__allChildrenLoaded||!o.__contentEmpty&&v(o.__loadingState)||o.__externalTileSet&&o.__loadingState===L;i=i&&e}}e.__childrenWereVisible=s,e.__allChildrenLoaded=i}else e.__isLeaf=!0}function D(e,t){const s=t.stats,r=t.frameCount;if(!R(e,r))return;const n=e.parent,i=n?n.__depthFromRenderedParent:-1;e.__depthFromRenderedParent=i;const o=t.lruCache;if(e.__isLeaf)return e.__depthFromRenderedParent++,void(e.__loadingState===C?(e.__inFrustum&&(e.__visible=!0,s.visible++),e.__active=!0,s.active++):o.isFull()||e.__contentEmpty&&!e.__externalTileSet||t.requestTileContents(e));const a=(t.errorTarget+1)*t.errorThreshold,l=e.__error<=a,c=l||"ADD"===e.refine,h=!e.__contentEmpty,d=h||e.__externalTileSet,u=v(e.__loadingState)&&d,p=e.__childrenWereVisible,m=e.children,g=e.__allChildrenLoaded;if(c&&h&&e.__depthFromRenderedParent++,c&&!u&&!o.isFull()&&d&&t.requestTileContents(e),(l&&!g&&!p&&u||"ADD"===e.refine&&u)&&(e.__inFrustum&&(e.__visible=!0,s.visible++),e.__active=!0,s.active++),"ADD"!==e.refine&&l&&!g&&u)for(let s=0,n=m.length;s<n;s++){const n=m[s];R(n,r)&&!o.isFull()&&(n.__depthFromRenderedParent=e.__depthFromRenderedParent+1,M(n,n.__depthFromRenderedParent,t))}else for(let e=0,s=m.length;e<s;e++){const s=m[e];R(s,r)&&D(s,t)}}function k(e,t){const s=R(e,t.frameCount);if(s||e.__usedLastFrame){let r=!1,n=!1;s&&(r=e.__active,n=t.displayActiveTiles&&e.__active||e.__visible),e.__contentEmpty||e.__loadingState!==C||(e.__wasSetActive!==r&&t.setTileActive(e,r),e.__wasSetVisible!==n&&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++){k(i[e],t)}}}const I=(e,t)=>e.__depth!==t.__depth?e.__depth>t.__depth?-1:1:e.__inFrustum!==t.__inFrustum?e.__inFrustum?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:0,N=e=>1/(e.__depthFromRenderedParent+1);class V{get rootTileSet(){const e=this.tileSets[this.rootURL];return!e||e instanceof Promise?null:e}get root(){const e=this.rootTileSet;return e?e.root:null}constructor(e){this.tileSets={},this.rootURL=e,this.fetchOptions={},this.preprocessURL=null;const t=new x;t.unloadPriorityCallback=N;const s=new S;s.maxJobs=4,s.priorityCallback=I;const r=new S;r.maxJobs=1,r.priorityCallback=I,this.lruCache=t,this.downloadQueue=s,this.parseQueue=r,this.stats={parsing:0,downloading:0,failed:0,inFrustum:0,used:0,active:0,visible:0},this.frameCount=0,this.errorTarget=6,this.errorThreshold=1/0,this.loadSiblings=!0,this.displayActiveTiles=!1,this.maxDepth=1/0,this.stopAtEmptyTiles=!0}traverse(e,t){const s=this.tileSets[this.rootURL];s&&s.root&&O(s.root,((t,...s)=>(this.ensureChildrenArePreprocessed(t),!!e&&e(t,...s))),t)}update(){const e=this.stats,t=this.lruCache,s=this.tileSets,r=s[this.rootURL];if(!(this.rootURL in s))return void this.loadRootTileSet(this.rootURL);if(!r||!r.root)return;const n=r.root;e.inFrustum=0,e.used=0,e.active=0,e.visible=0,this.frameCount++,A(n,this),F(n,this),D(n,this),k(n,this),t.scheduleUnload()}parseTile(e,t,s){return null}disposeTile(e){}preprocessNode(e,t,s=null){e.content&&(!("uri"in e.content)&&"url"in e.content&&(e.content.uri=e.content.url,delete e.content.url),e.content.uri&&(e.content.uri=new URL(e.content.uri,t+"/").toString()),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||[];if(e.content&&e.content.uri){const t=y(e.content.uri),s=Boolean(t&&"json"===t.toLowerCase());e.__externalTileSet=s,e.__contentEmpty=s}else e.__externalTileSet=!1,e.__contentEmpty=!0;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.__childrenWereVisible=!1,e.__allChildrenLoaded=!1,e.__wasSetActive=!1,e.__active=!1,e.__loadingState=0,e.__loadIndex=0,e.__loadAbort=null,e.__depthFromRenderedParent=-1,null===s?(e.__depth=0,e.refine=e.refine||"REPLACE"):(e.__depth=s.__depth+1,e.refine=e.refine||s.refine),e.__basePath=t}setTileActive(e,t){}setTileVisible(e,t){}calculateError(e){return 0}tileInView(e){return!0}ensureChildrenArePreprocessed(e){const t=e.children;for(let s=0,r=t.length;s<r;s++){const r=t[s];if("__depth"in r)break;this.preprocessNode(r,e.__basePath,e)}}resetFailedTiles(){const e=this.stats;0!==e.failed&&(this.traverse((e=>{e.__loadingState===L&&(e.__loadingState=0)})),e.failed=0)}fetchTileSet(e,t,s=null){return fetch(e,t).then((t=>{if(t.ok)return t.json();throw new Error(`TilesRenderer: Failed to load tileset "${e}" with status ${t.status} : ${t.statusText}`)})).then((t=>{const r=t.asset.version;console.assert("1.0"===r||"0.0"===r,'asset.version is expected to be a string of "1.0" or "0.0"');let n=e.replace(/\/[^\/]*\/?$/,"");return n=new URL(n,window.location.href).toString(),this.preprocessNode(t.root,n,s),t}))}loadRootTileSet(e){const t=this.tileSets;if(e in t)return t[e]instanceof Error?Promise.reject(t[e]):Promise.resolve(t[e]);{const s=this.fetchTileSet(this.preprocessURL?this.preprocessURL(e):e,this.fetchOptions).then((s=>{t[e]=s}));return s.catch((s=>{console.error(s),t[e]=s})),t[e]=s,s}}requestTileContents(e){if(0!==e.__loadingState)return;const t=this.stats,s=this.lruCache,r=this.downloadQueue,n=this.parseQueue,i=e.__externalTileSet;s.add(e,(e=>{1===e.__loadingState?(e.__loadAbort.abort(),e.__loadAbort=null):i?e.children.length=0:this.disposeTile(e),1===e.__loadingState?t.downloading--:2===e.__loadingState&&t.parsing--,e.__loadingState=0,e.__loadIndex++,n.remove(e),r.remove(e)})),e.__loadIndex++;const o=e.__loadIndex,a=new AbortController,l=a.signal;t.downloading++,e.__loadAbort=a,e.__loadingState=1;const c=i=>{e.__loadIndex===o&&("AbortError"!==i.name?(n.remove(e),r.remove(e),2===e.__loadingState?t.parsing--:1===e.__loadingState&&t.downloading--,t.failed++,console.error(`TilesRenderer : Failed to load tile at url "${e.content.uri}".`),console.error(i),e.__loadingState=L):s.remove(e))};i?r.add(e,(e=>{if(e.__loadIndex!==o)return Promise.resolve();const t=this.preprocessURL?this.preprocessURL(e.content.uri):e.content.uri;return this.fetchTileSet(t,Object.assign({signal:l},this.fetchOptions),e)})).then((s=>{e.__loadIndex===o&&(t.downloading--,e.__loadAbort=null,e.__loadingState=C,e.children.push(s.root))})).catch(c):r.add(e,(e=>{if(e.__loadIndex!==o)return Promise.resolve();const t=this.preprocessURL?this.preprocessURL(e.content.uri):e.content.uri;return fetch(t,Object.assign({signal:l},this.fetchOptions))})).then((t=>{if(e.__loadIndex===o){if(t.ok)return t.arrayBuffer();throw new Error(`Failed to load model with error code ${t.status}`)}})).then((s=>{if(e.__loadIndex===o)return t.downloading--,t.parsing++,e.__loadAbort=null,e.__loadingState=2,n.add(e,(e=>{if(e.__loadIndex!==o)return Promise.resolve();const t=y(e.content.uri);return this.parseTile(s,e,t)}))})).then((()=>{e.__loadIndex===o&&(t.parsing--,e.__loadingState=C,e.__wasSetVisible&&this.setTileVisible(e,!0),e.__wasSetActive&&this.setTileActive(e,!0))})).catch(c)}dispose(){const e=this.lruCache,t=[];this.traverse((e=>(t.push(e),!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}}function B(e){return(new TextDecoder).decode(e)}class z{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(B(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: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 "${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 "${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}getBuffer(e,t){const{buffer:s,binOffset:r}=this;return s.slice(r+e,r+e+t)}}class j extends z{constructor(e,t,s,r,n){super(e,s,r,n),this.batchSize=t}getData(e,t=null,s=null){return super.getData(e,this.batchSize,t,s)}}class W{constructor(){this.fetchOptions={},this.workingPath=""}load(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)?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.")}}function H(e){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 G extends W{parse(e){const t=new DataView(e),s=H(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),o=t.getUint32(16,!0),a=t.getUint32(20,!0),l=t.getUint32(24,!0),c=e.slice(28,28+i+o),h=new z(c,0,i,o),d=28+i+o,u=e.slice(d,d+a+l),p=new j(u,h.getData("BATCH_LENGTH"),0,a,l),m=d+a+l;return{version:r,featureTable:h,batchTable:p,glbBytes:new Uint8Array(e,m,n-m)}}}class Q extends G{constructor(e=r){super(),this.manager=e,this.adjustmentTransform=new s}parse(e){const s=super.parse(e),r=s.glbBytes.slice().buffer;return new Promise(((e,n)=>{const i=this.manager,o=this.fetchOptions,a=i.getHandler("path.gltf")||new t(i);"include"===o.credentials&&"cors"===o.mode&&a.setCrossOrigin("use-credentials"),"credentials"in o&&a.setWithCredentials("include"===o.credentials),o.headers&&a.setRequestHeader(o.headers);let l=this.workingPath;!/[\\/]$/.test(l)&&l.length&&(l+="/");const c=this.adjustmentTransform;a.parse(r,l,(t=>{const{batchTable:r,featureTable:n}=s,{scene:i}=t,o=n.getData("RTC_CENTER");o&&(i.position.x+=o[0],i.position.y+=o[1],i.position.z+=o[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)}))}}class $ extends W{parse(e){const t=new DataView(e),s=H(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),o=t.getUint32(16,!0),a=t.getUint32(20,!0),l=t.getUint32(24,!0),c=e.slice(28,28+i+o),h=new z(c,0,i,o),d=28+i+o,u=e.slice(d,d+a+l),p=new j(u,h.getData("BATCH_LENGTH")||h.getData("POINTS_LENGTH"),0,a,l);return Promise.resolve({version:r,featureTable:h,batchTable:p})}}function q(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 J={RGB:"color",POSITION:"position"};class Y extends ${constructor(e=r){super(),this.manager=e}parse(e){return super.parse(e).then((async e=>{const{featureTable:t}=e,s=new n,r=t.header.extensions,h=new i;let d;if(r&&r["3DTILES_draco_point_compression"]){const{byteOffset:e,byteLength:n,properties:i}=r["3DTILES_draco_point_compression"],o=this.manager.getHandler("draco.drc");if(null==o)throw new Error("PNTSLoader: dracoLoader not available.");const a={};for(const e in i)if(e in J&&e in i){a[J[e]]=i[e]}const l={attributeIDs:a,attributeTypes:{position:"Float32Array",color:"Uint8Array"},useUniqueIDs:!0},c=t.getBuffer(e,n);d=await o.decodeGeometry(c,l),d.attributes.color&&(s.vertexColors=!0)}else{const e=t.getData("POINTS_LENGTH"),r=t.getData("POSITION",e,"FLOAT","VEC3"),n=t.getData("RGB",e,"UNSIGNED_BYTE","VEC3"),i=t.getData("RGBA",e,"UNSIGNED_BYTE","VEC4"),c=t.getData("RGB565",e,"UNSIGNED_SHORT","SCALAR"),u=t.getData("CONSTANT_RGBA",e,"UNSIGNED_BYTE","VEC4"),p=t.getData("POSITION_QUANTIZED",e,"UNSIGNED_SHORT","VEC3"),m=t.getData("QUANTIZED_VOLUME_SCALE",e,"FLOAT","VEC3"),g=t.getData("QUANTIZED_VOLUME_OFFSET",e,"FLOAT","VEC3");if(d=new o,p){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]=p[r]/65535*m[e]}h.x=g[0],h.y=g[1],h.z=g[2],d.setAttribute("position",new a(t,3,!1))}else d.setAttribute("position",new a(r,3,!1));if(null!==i)d.setAttribute("color",new a(i,4,!0)),s.vertexColors=!0,s.transparent=!0,s.depthWrite=!1;else if(null!==n)d.setAttribute("color",new a(n,3,!0)),s.vertexColors=!0;else if(null!==c){const t=new Uint8Array(3*e);for(let s=0;s<e;s++){const e=q(c[s]);for(let r=0;r<3;r++){t[3*s+r]=e[r]}}d.setAttribute("color",new a(t,3,!0)),s.vertexColors=!0}else if(null!==u){const e=new l(u[0],u[1],u[2]);s.color=e;const t=u[3]/255;t<1&&(s.opacity=t,s.transparent=!0,s.depthWrite=!1)}}["BATCH_LENGTH","NORMAL","NORMAL_OCT16P"].forEach((e=>{e in t.header&&console.warn(`PNTSLoader: Unsupported FeatureTable feature "${e}" detected.`)}));const u=new c(d,s);u.position.copy(h),e.scene=u,e.scene.featureTable=t;const p=t.getData("RTC_CENTER");return p&&(e.scene.position.x+=p[0],e.scene.position.y+=p[1],e.scene.position.z+=p[2]),e}))}}class Z extends W{parse(e){const t=new DataView(e),s=H(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),o=t.getUint32(16,!0),a=t.getUint32(20,!0),l=t.getUint32(24,!0),c=t.getUint32(28,!0),h=e.slice(32,32+i+o),d=new z(h,0,i,o),u=32+i+o,p=e.slice(u,u+a+l),m=new j(p,d.getData("INSTANCES_LENGTH"),0,a,l),g=u+a+l,_=new Uint8Array(e,g,n-g);let f=null,b=null;if(c)f=_,b=Promise.resolve();else{const e=this.resolveExternalURL(B(_));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=>{f=new Uint8Array(e)}))}return b.then((()=>({version:r,featureTable:d,batchTable:m,glbBytes:f})))}}const K=new i,X=new i,ee=new i,te=new i,se=new h,re=new i,ne=new s;class ie extends Z{constructor(e=r){super(),this.manager=e,this.adjustmentTransform=new s}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(((e,o)=>{const a=this.fetchOptions,l=this.manager,c=l.getHandler("path.gltf")||new t(l);"include"===a.credentials&&"cors"===a.mode&&c.setCrossOrigin("use-credentials"),"credentials"in a&&c.setWithCredentials("include"===a.credentials),a.headers&&c.setRequestHeader(a.headers);let h=this.workingPath;/[\\/]$/.test(h)||(h+="/");const u=this.adjustmentTransform;c.parse(n,h,(t=>{const n=s.getData("INSTANCES_LENGTH"),o=s.getData("POSITION",n,"FLOAT","VEC3"),a=s.getData("NORMAL_UP",n,"FLOAT","VEC3"),l=s.getData("NORMAL_RIGHT",n,"FLOAT","VEC3"),c=s.getData("SCALE_NON_UNIFORM",n,"FLOAT","VEC3"),h=s.getData("SCALE",n,"FLOAT","SCALAR");["RTC_CENTER","QUANTIZED_VOLUME_OFFSET","QUANTIZED_VOLUME_SCALE","EAST_NORTH_UP","POSITION_QUANTIZED","NORMAL_UP_OCT32P","NORMAL_RIGHT_OCT32P"].forEach((e=>{e in s.header&&console.warn(`I3DMLoader: Unsupported FeatureTable feature "${e}" detected.`)}));const p=new Map,m=[];t.scene.traverse((e=>{if(e.isMesh){const{geometry:t,material:s}=e,r=new d(t,s,n);r.position.copy(e.position),r.rotation.copy(e.rotation),r.scale.copy(e.scale),m.push(r),p.set(e,r)}}));const g=new i;for(let e=0;e<n;e++)g.x+=o[3*e+0]/n,g.y+=o[3*e+1]/n,g.z+=o[3*e+2]/n;p.forEach(((e,t)=>{const s=t.parent;s&&(s.remove(t),s.add(e),e.updateMatrixWorld(),e.position.copy(g).applyMatrix4(e.matrixWorld))}));for(let e=0;e<n;e++){te.set(o[3*e+0]-g.x,o[3*e+1]-g.y,o[3*e+2]-g.z),a?(X.set(a[3*e+0],a[3*e+1],a[3*e+2]),ee.set(l[3*e+0],l[3*e+1],l[3*e+2]),K.crossVectors(ee,X).normalize(),ne.makeBasis(ee,X,K),se.setFromRotationMatrix(ne)):se.set(0,0,0,1),h?re.setScalar(h[e]):c?re.set(c[3*e+0],c[3*e+1],c[3*e+2]):re.set(1,1,1),ne.compose(te,se,re).multiply(u);for(let t=0,s=m.length;t<s;t++){m[t].setMatrixAt(e,ne)}}t.batchTable=r,t.featureTable=s,t.scene.batchTable=r,t.scene.featureTable=s,e(t)}),o)}))}))}}class oe extends W{parse(e){const t=new DataView(e),s=H(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),o=[];let a=16;for(let t=0;t<i;t++){const t=new DataView(e,a,12),s=H(t),r=t.getUint32(4,!0),n=t.getUint32(8,!0),i=new Uint8Array(e,a,n);o.push({type:s,buffer:i,version:r}),a+=n}return{version:r,tiles:o}}}class ae extends oe{constructor(e=r){super(),this.manager=e,this.adjustmentTransform=new s}parse(e){const t=super.parse(e),s=this.manager,r=this.adjustmentTransform,n=[];for(const e in t.tiles){const{type:i,buffer:o}=t.tiles[e];switch(i){case"b3dm":{const e=o.slice(),t=new Q(s);t.workingPath=this.workingPath,t.fetchOptions=this.fetchOptions,t.adjustmentTransform.copy(r);const i=t.parse(e.buffer);n.push(i);break}case"pnts":{const e=o.slice(),t=new Y(s);t.workingPath=this.workingPath,t.fetchOptions=this.fetchOptions;const r=t.parse(e.buffer);n.push(r);break}case"i3dm":{const e=o.slice(),t=new ie(s);t.workingPath=this.workingPath,t.fetchOptions=this.fetchOptions,t.adjustmentTransform.copy(r);const i=t.parse(e.buffer);n.push(i);break}}}return Promise.all(n).then((e=>{const t=new u;return e.forEach((e=>{t.add(e.scene)})),{tiles:e,scene:t}}))}}class le{constructor(){this.name="CESIUM_RTC"}afterRoot(e){if(e.parser.json.extensions&&e.parser.json.extensions.CESIUM_RTC){const{center:t}=e.parser.json.extensions.CESIUM_RTC;t&&(e.scene.position.x+=t[0],e.scene.position.y+=t[1],e.scene.position.z+=t[2])}}}class ce extends W{constructor(e=r){super(),this.manager=e}parse(e){return new Promise(((s,r)=>{const n=this.manager,i=this.fetchOptions;let o=n.getHandler("path.gltf")||n.getHandler("path.glb");o||(o=new t(n),o.register((()=>new le)),"include"===i.credentials&&"cors"===i.mode&&o.setCrossOrigin("use-credentials"),"credentials"in i&&o.setWithCredentials("include"===i.credentials),i.headers&&o.setRequestHeader(i.headers));let a=o.resourcePath||o.path||this.workingPath;!/[\\/]$/.test(a)&&a.length&&(a+="/"),o.parse(e,a,(e=>{s(e)}),r)}))}}const he=new s;class de extends u{constructor(e){super(),this.name="TilesRenderer.TilesGroup",this.tilesRenderer=e}raycast(e,t){this.tilesRenderer.optimizeRaycast&&this.tilesRenderer.raycast(e,t)}updateMatrixWorld(e){if(this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldNeedsUpdate||e){null===this.parent?he.copy(this.matrix):he.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1;const e=he.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(he);const e=this.children;for(let t=0,s=e.length;t<s;t++)e[t].updateMatrixWorld()}}}}const ue=new s,pe=new p,me=new i,ge=[];function _e(e,t){return e.distance-t.distance}function fe(e,t,s){e.traverse((e=>{Object.getPrototypeOf(e).raycast.call(e,t,s)}))}function be(e,t,s,r=null){const{group:n,activeTiles:i}=e;e.ensureChildrenArePreprocessed(t),null===r&&(r=pe,ue.copy(n.matrixWorld).invert(),r.copy(s.ray).applyMatrix4(ue));const o=[],a=t.children;for(let e=0,t=a.length;e<t;e++){const t=a[e];if(!t.__used)continue;null!==t.cached.boundingVolume.intersectRay(r,me)&&(me.applyMatrix4(n.matrixWorld),o.push({distance:me.distanceToSquared(s.ray.origin),tile:t}))}o.sort(_e);let l=null,c=1/0;if(i.has(t)){const e=function(e,t){fe(e,t,ge),ge.sort(_e);const s=ge[0]||null;return ge.length=0,s}(t.cached.scene,s);e&&(l=e,c=e.distance*e.distance)}for(let t=0,n=o.length;t<n;t++){const n=o[t],i=n.distance,a=n.tile;if(i>c)break;const h=be(e,a,s,r);if(h){const e=h.distance*h.distance;e<c&&(l=h,c=e)}}return l}function we(e,t,s,r,n=null){const{group:i,activeTiles:o}=e,{scene:a,boundingVolume:l}=t.cached;if(e.ensureChildrenArePreprocessed(t),null===n&&(n=pe,ue.copy(i.matrixWorld).invert(),n.copy(s.ray).applyMatrix4(ue)),!t.__used||!l.intersectsRay(n))return;o.has(t)&&fe(a,s,r);const c=t.children;for(let t=0,i=c.length;t<i;t++)we(e,c[t],s,r,n)}class Te{constructor(e=new m,t=new s){this.box=e.clone(),this.transform=t.clone(),this.inverseTransform=new s,this.points=new Array(8).fill().map((()=>new i))}update(){const{points:e,inverseTransform:t,transform:s,box:r}=this;t.copy(s).invert();const{min:n,max:i}=r;let o=0;for(let t=-1;t<=1;t+=2)for(let r=-1;r<=1;r+=2)for(let a=-1;a<=1;a+=2)e[o].set(t<0?n.x:i.x,r<0?n.y:i.y,a<0?n.z:i.z).applyMatrix4(s),o++}intersectsFrustum(e){const{points:t}=this,{planes:s}=e;for(let e=0;e<6;e++){const r=s[e];let n=-1/0;for(let e=0;e<8;e++){const s=t[e],i=r.distanceToPoint(s);n=n<i?i:n}if(n<0)return!1}return!0}}new g,new i;const ye=new g,xe=new i,Se=new i,Ce=new i,Le=new i,Ee=new i,ve=new i,Re=new i,Pe=new i;class Ue{constructor(e=1,t=1,s=1){this.radius=new i(e,t,s)}constructLatLonFrame(e,t,s){return this.getCartographicToPosition(e,t,0,Pe),this.getCartographicToNormal(e,t,Re),this.getNorthernTangent(e,t,ve),Ee.crossVectors(ve,Re),s.makeBasis(Ee,ve,Re).setPosition(Pe)}getNorthernTangent(e,t,s,r=Le){let n=1,i=e+1e-7;e>Math.PI/4&&(n=-1,i=e-1e-7);const o=this.getCartographicToNormal(e,t,Se).normalize(),a=this.getCartographicToNormal(i,t,Ce).normalize();return r.crossVectors(o,a).normalize().multiplyScalar(n),s.crossVectors(r,o).normalize()}getCartographicToPosition(e,t,s,r){this.getCartographicToNormal(e,t,xe);const n=this.radius;Se.copy(xe),Se.x*=n.x**2,Se.y*=n.y**2,Se.z*=n.z**2;const i=Math.sqrt(xe.dot(Se));return Se.divideScalar(i),r.copy(Se).addScaledVector(xe,s)}getPositionToCartographic(e,t){this.getPositionToSurfacePoint(e,Se),this.getPositionToNormal(e,xe);const s=Ce.subVectors(e,Se);return t.lon=Math.atan2(xe.y,xe.x),t.lat=Math.asin(xe.z),t.height=Math.sign(s.dot(e))*s.length(),t}getCartographicToNormal(e,t,s){return ye.set(1,-e+Math.PI/2,t),s.setFromSpherical(ye).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,o=e.x*e.x*r,a=e.y*e.y*n,l=e.z*e.z*i,c=o+a+l,h=Math.sqrt(1/c),d=Se.copy(e).multiplyScalar(h);if(c<.1)return isFinite(h)?t.copy(d):null;const u=Ce.set(d.x*r*2,d.y*n*2,d.z*i*2);let p,m,g,_,f,b,w,T,y,x,S,C=(1-h)*e.length()/(.5*u.length()),L=0;do{C-=L,g=1/(1+C*r),_=1/(1+C*n),f=1/(1+C*i),b=g*g,w=_*_,T=f*f,y=b*g,x=w*_,S=T*f,p=o*b+a*w+l*T-1,m=o*y*r+a*x*n+l*S*i;L=p/(-2*m)}while(Math.abs(p)>1e-12);return t.set(e.x*g,e.y*_,e.z*f)}}const Me=Math.PI,Oe=Me/2,Ae=new i,Fe=new i,De=new i,ke=new s;let Ie=0;const Ne=[];function Ve(e=!1){return e?(Ne[Ie]||(Ne[Ie]=new i),Ie++,Ne[Ie-1]):new i}function Be(){Ie=0}class ze extends Ue{constructor(e,t,s,r=-Oe,n=Oe,i=0,o=2*Me,a=0,l=0){super(e,t,s),this.latStart=r,this.latEnd=n,this.lonStart=i,this.lonEnd=o,this.heightStart=a,this.heightEnd=l}_getPoints(e=!1){const{latStart:t,latEnd:s,lonStart:r,lonEnd:n,heightStart:i,heightEnd:o}=this,a=_.mapLinear(.5,0,1,t,s),l=_.mapLinear(.5,0,1,r,n),c=Math.floor(r/Oe)*Oe,h=[[-Me/2,0],[Me/2,0],[0,c],[0,c+Me/2],[0,c+Me],[0,c+3*Me/2],[t,n],[s,n],[t,r],[s,r],[0,r],[0,n],[a,l],[t,l],[s,l],[a,r],[a,n]],d=[],u=h.length;for(let a=0;a<=1;a++){const l=_.mapLinear(a,0,1,i,o);for(let i=0,o=u;i<o;i++){const[o,a]=h[i];if(o>=t&&o<=s&&a>=r&&a<=n){const t=Ve(e);d.push(t),this.getCartographicToPosition(o,a,l,t)}}}return d}getBoundingBox(e,t){Be();const{latStart:s,latEnd:r,lonStart:n,lonEnd:i}=this;if(r-s<Me/2){const e=_.mapLinear(.5,0,1,s,r),o=_.mapLinear(.5,0,1,n,i);this.getCartographicToNormal(e,o,De),Fe.set(0,0,1),Ae.crossVectors(Fe,De),Fe.crossVectors(Ae,De),t.makeBasis(Ae,Fe,De)}else Ae.set(1,0,0),Fe.set(0,1,0),De.set(0,0,1),t.makeBasis(Ae,Fe,De);ke.copy(t).invert();const o=this._getPoints(!0);for(let e=0,t=o.length;e<t;e++)o[e].applyMatrix4(ke);e.makeEmpty(),e.setFromPoints(o)}getBoundingSphere(e,t){Be();const s=this._getPoints(!0);e.makeEmpty(),e.setFromPoints(s,t)}}const je=new i,We=new i,He=new i,Ge=new i,Qe=new i,$e=new i,qe=new p;class Je{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&&(qe.copy(e).applyMatrix4(s.inverseTransform),!qe.intersectsBox(s.box)))}intersectRay(e,t=null){const s=this.sphere,r=this.obb||this.regionObb;let n=-1/0,i=-1/0;s&&e.intersectSphere(s,Qe)&&(n=s.containsPoint(e.origin)?0:e.origin.distanceToSquared(Qe)),r&&(qe.copy(e).applyMatrix4(r.inverseTransform),qe.intersectBox(r.box,$e)&&(i=r.box.containsPoint(qe.origin)?0:qe.origin.distanceToSquared($e)));const o=Math.max(n,i);return o===-1/0?null:(e.at(Math.sqrt(o),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&&(Ge.copy(e).applyMatrix4(s.inverseTransform),n=s.box.distanceToPoint(Ge)),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))}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 Te;je.set(e[3],e[4],e[5]),We.set(e[6],e[7],e[8]),He.set(e[9],e[10],e[11]);const r=je.length(),n=We.length(),i=He.length();je.normalize(),We.normalize(),He.normalize(),0===r&&je.crossVectors(We,He),0===n&&We.crossVectors(je,He),0===i&&He.crossVectors(je,We),s.transform.set(je.x,We.x,He.x,e[0],je.y,We.y,He.y,e[1],je.z,We.z,He.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 f;i.center.set(e,t,s),i.radius=r,i.applyMatrix4(n),this.sphere=i}setRegionData(e,t,s,r,n,i){const o=new ze(E,E,6356752.314245179,t,r,e,s,n,i),a=new Te;o.getBoundingBox(a.box,a.transform),a.update(),this.region=o,this.regionObb=a}}const Ye=Symbol("INITIAL_FRUSTUM_CULLED"),Ze=new s,Ke=new s,Xe=new i,et=new i(1,0,0),tt=new i(0,1,0);function st(e,t){e.traverse((e=>{e.frustumCulled=e[Ye]&&t}))}class rt extends V{get autoDisableRendererCulling(){return this._autoDisableRendererCulling}set autoDisableRendererCulling(e){this._autoDisableRendererCulling!==e&&(super._autoDisableRendererCulling=e,this.forEachLoadedModel((t=>{st(t,!e)})))}constructor(...e){super(...e),this.group=new de(this),this.cameras=[],this.cameraMap=new Map,this.cameraInfo=[],this.activeTiles=new Set,this.visibleTiles=new Set,this._autoDisableRendererCulling=!0,this.optimizeRaycast=!0,this.onLoadTileSet=null,this.onLoadModel=null,this.onDisposeModel=null,this.onTileVisibilityChange=null;const t=new b;t.setURLModifier((e=>this.preprocessURL?this.preprocessURL(e):e)),this.manager=t;const s=this;this._overridenRaycast=function(e,t){s.optimizeRaycast||Object.getPrototypeOf(this).raycast.call(this,e,t)}}getBounds(e){if(!this.root)return!1;const t=this.root.cached.boundingVolume;return!t||(t.getAABB(e),!0)}getOrientedBounds(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.scene;s&&e(s,t)}))}raycast(e,t){if(this.root)if(e.firstHitOnly){const s=be(this,this.root,e);s&&t.push(s)}else we(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 w),t.push(e),!0)}setResolution(e,t,s){const r=this.cameraMap;return!!r.has(e)&&(t instanceof w?r.get(e).copy(t):r.get(e).set(t,s),!0)}setResolutionFromRenderer(e,t){const s=this.cameraMap;if(!s.has(e))return!1;const r=s.get(e);return t.getSize(r),r.multiplyScalar(t.getPixelRatio()),!0}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),!0}return!1}fetchTileSet(e,...t){const s=super.fetchTileSet(e,...t);return s.then((t=>{this.onLoadTileSet&&Promise.resolve().then((()=>{this.onLoadTileSet(t,e)}))})),s}update(){const e=this.group,t=this.cameras,s=this.cameraMap,r=this.cameraInfo;if(0===t.length)return void console.warn("TilesRenderer: no cameras defined. Cannot update 3d tiles.");for(;r.length>t.length;)r.pop();for(;r.length<t.length;)r.push({frustum:new T,isOrthographic:!1,sseDenominator:-1,position:new i,invScale:-1,pixelSize:0});Ke.copy(e.matrixWorld).invert(),Xe.setFromMatrixScale(Ke);const n=Xe.x;Math.abs(Math.max(Xe.x-Xe.y,Xe.x-Xe.z))>1e-6&&console.warn("ThreeTilesRenderer : Non uniform scale used for tile which may cause issues when calculating screen space error.");for(let i=0,o=r.length;i<o;i++){const o=t[i],a=r[i],l=a.frustum,c=a.position,h=s.get(o);0!==h.width&&0!==h.height||console.warn("TilesRenderer: resolution for camera error calculation is not set.");const d=o.projectionMatrix.elements;if(a.isOrthographic=1===d[15],a.isOrthographic){const e=2/d[0],t=2/d[5];a.pixelSize=Math.max(t/h.height,e/h.width)}else a.sseDenominator=2/d[5]/h.height;a.invScale=n,Ze.copy(e.matrixWorld),Ze.premultiply(o.matrixWorldInverse),Ze.premultiply(o.projectionMatrix),l.setFromProjectionMatrix(Ze),c.set(0,0,0),c.applyMatrix4(o.matrixWorld),c.applyMatrix4(Ke)}super.update()}preprocessNode(e,t,r=null){super.preprocessNode(e,t,r);const n=new s;if(e.transform){const t=e.transform;for(let e=0;e<16;e++)n.elements[e]=t[e]}else n.identity();r&&n.premultiply(r.cached.transform);const i=(new s).copy(n).invert(),o=new Je;"sphere"in e.boundingVolume&&o.setSphereData(...e.boundingVolume.sphere,n),"box"in e.boundingVolume&&o.setObbData(e.boundingVolume.box,n),"region"in e.boundingVolume&&o.setRegionData(...e.boundingVolume.region),e.cached={loadIndex:0,transform:n,transformInverse:i,active:!1,inFrustum:[],boundingVolume:o,scene:null,geometry:null,material:null}}parseTile(e,t,r){t._loadIndex=t._loadIndex||0,t._loadIndex++;const n=t.content.uri.split(/[\\\/]/g);n.pop();const i=n.join("/"),o=this.fetchOptions,a=this.manager,l=t._loadIndex;let c=null;const h=this.rootTileSet.asset&&this.rootTileSet.asset.gltfUpAxis||"y",d=t.cached,u=d.transform,p=new s;switch(h.toLowerCase()){case"x":p.makeRotationAxis(tt,-Math.PI/2);break;case"y":p.makeRotationAxis(et,Math.PI/2);break;case"z":p.identity()}const m=(H(e)||r).toLowerCase();switch(m){case"b3dm":{const t=new Q(a);t.workingPath=i,t.fetchOptions=o,t.adjustmentTransform.copy(p),c=t.parse(e);break}case"pnts":{const t=new Y(a);t.workingPath=i,t.fetchOptions=o,c=t.parse(e);break}case"i3dm":{const t=new ie(a);t.workingPath=i,t.fetchOptions=o,t.adjustmentTransform.copy(p),c=t.parse(e);break}case"cmpt":{const t=new ae(a);t.workingPath=i,t.fetchOptions=o,t.adjustmentTransform.copy(p),c=t.parse(e).then((e=>e.scene));break}case"gltf":case"glb":const t=new ce(a);t.workingPath=i,t.fetchOptions=o,c=t.parse(e);break;default:console.warn(`TilesRenderer: Content type "${m}" not supported.`),c=Promise.resolve(null)}return c.then((e=>{let s,r;if(e.isObject3D?(s=e,r=null):(s=e.scene,r=e),t._loadIndex!==l)return;s.updateMatrix(),"glb"!==m&&"gltf"!==m||s.matrix.multiply(p),s.matrix.premultiply(u),s.matrix.decompose(s.position,s.quaternion,s.scale),s.traverse((e=>{e[Ye]=e.frustumCulled})),st(s,!this.autoDisableRendererCulling),s.traverse((e=>{e.raycast=this._overridenRaycast}));const n=[],i=[],o=[];s.traverse((e=>{if(e.geometry&&i.push(e.geometry),e.material){const t=e.material;n.push(e.material);for(const e in t){const s=t[e];s&&s.isTexture&&o.push(s)}}})),d.materials=n,d.geometry=i,d.textures=o,d.scene=s,d.metadata=r,this.onLoadModel&&this.onLoadModel(s,t)}))}disposeTile(e){const t=e.cached;if(t.scene){const s=t.materials,r=t.geometry,n=t.textures,i=t.scene.parent;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++){n[e].dispose()}i&&i.remove(t.scene),this.onDisposeModel&&this.onDisposeModel(t.scene,e),t.scene=null,t.materials=null,t.textures=null,t.geometry=null,t.metadata=null}this.activeTiles.delete(e),this.visibleTiles.delete(e),e._loadIndex++}setTileVisible(e,t){const s=e.cached.scene,r=this.visibleTiles,n=this.group;t?(n.add(s),r.add(e),s.updateMatrixWorld(!0)):(n.remove(s),r.delete(e)),this.onTileVisibilityChange&&this.onTileVisibilityChange(s,e,t)}setTileActive(e,t){const s=this.activeTiles;t?s.add(e):s.delete(e)}calculateError(e){const t=e.cached,s=t.inFrustum,r=this.cameras,n=this.cameraInfo,i=t.boundingVolume;let o=-1/0,a=1/0;for(let t=0,l=r.length;t<l;t++){if(!s[t])continue;const r=n[t],l=r.invScale;let c;if(r.isOrthographic){const t=r.pixelSize;c=e.geometricError/(t*l)}else{const t=i.distanceToPoint(r.position)*l,s=r.sseDenominator;c=e.geometricError/(t*s),a=Math.min(a,t)}o=Math.max(o,c)}e.__distanceFromCamera=a,e.__error=o}tileInView(e){const t=e.cached,s=t.boundingVolume,r=t.inFrustum,n=this.cameraInfo;let i=!1;for(let e=0,t=n.length;e<t;e++){const t=n[e].frustum;s.intersectsFrustum(t)?(i=!0,r[e]=!0):r[e]=!1}return i}}class nt{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 o=s.options.ktx2Loader;if(!o)throw new Error(`${e.utils.consoleSspTitle}请使用 setModelKtx2DecoderPath 设置 ktx2 解压库路径`);return s.loadTextureImage(t,n,o)}}class it{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 rt(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 o=new t(i.manager);o.register((()=>new le)),o.register((e=>new nt(e)));const{dracoLoader:a,ktx2Loader:l,meshoptDecoder:c}=r.manager.store.modelManager.gltfLoader;a&&o.setDRACOLoader(a),l&&o.setKTX2Loader(l),c&&o.setMeshoptDecoder(c),i.manager.addHandler(/\.gltf$/,o),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{it 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.10.
|
|
4
|
+
"version": "2.10.13",
|
|
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,8 @@
|
|
|
14
14
|
],
|
|
15
15
|
"author": "xunwei",
|
|
16
16
|
"license": "UNLICENSED",
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "eae3598a1919c9662556d7a3bd1b4af5ef750177",
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"soonspacejs": "2.10.
|
|
19
|
+
"soonspacejs": "2.10.13"
|
|
20
20
|
}
|
|
21
21
|
}
|