Browse Source

comments, add cache info

Garrett Johnson 5 năm trước cách đây
mục cha
commit
48481e21cf
3 tập tin đã thay đổi với 42 bổ sung4 xóa
  1. 38 3
      example/index.js
  2. 1 1
      src/base/TilesRendererBase.js
  3. 3 0
      src/utilities/LRUCache.js

+ 38 - 3
example/index.js

@@ -17,6 +17,7 @@ import {
 	OrthographicCamera
 } from 'three';
 import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
+import { BufferGeometryUtils } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
 import * as dat from 'three/examples/jsm/libs/dat.gui.module.js';
 import Stats from 'three/examples/jsm/libs/stats.module.js';
 
@@ -225,7 +226,9 @@ function init() {
 	statsContainer.style.color = 'white';
 	statsContainer.style.width = '100%';
 	statsContainer.style.textAlign = 'center';
-	statsContainer.style.padding = '10px';
+	statsContainer.style.padding = '5px';
+	statsContainer.style.pointerEvents = 'none';
+	statsContainer.style.lineHeight = '1.5em';
 	document.body.appendChild( statsContainer );
 
 	// Stats
@@ -425,7 +428,39 @@ function render() {
 
 	}
 
-	statsContainer.innerText =
-		`Downloading: ${tiles.stats.downloading} Parsing: ${tiles.stats.parsing} Visible: ${tiles.group.children.length}`;
+	const geomSet = new Set();
+	tiles.traverse( tile => {
+
+		const scene = tile.cached.scene;
+		if ( scene ) {
+
+			scene.traverse( c => {
+
+				if ( c.geometry ) {
+
+					geomSet.add( c.geometry );
+
+				}
+
+			} );
+
+		}
+
+	} );
+
+	let count = 0;
+	geomSet.forEach( g => {
+
+		count += BufferGeometryUtils.estimateBytesUsed( g );
+
+	} );
+
+	const cacheFullness = tiles.lruCache.itemList.length / tiles.lruCache.minSize;
+	statsContainer.innerHTML =
+		`
+			Downloading: ${ tiles.stats.downloading } Parsing: ${ tiles.stats.parsing } Visible: ${ tiles.group.children.length }
+			<br/>
+			Cache: ${ ( 100 * cacheFullness ).toFixed( 2 ) }% ~${ ( count / 1000 / 1000 ).toFixed( 2 ) }mb
+		`;
 
 }

+ 1 - 1
src/base/TilesRendererBase.js

@@ -34,7 +34,7 @@ export class TilesRendererBase {
 		this.tileSets = {};
 		this.rootSet = url;
 		this.lruCache = cache;
-		this.fetchOptions = { credentials: 'same-origin' };
+		this.fetchOptions = {};
 
 		this.downloadQueue = downloadQueue;
 		this.parseQueue = parseQueue;

+ 3 - 0
src/utilities/LRUCache.js

@@ -1,3 +1,4 @@
+// TODO: can we remove the use of `indexOf` here because it's potentially slow? Possibly use time and sort as needed?
 class LRUCache {
 
 	constructor() {
@@ -95,6 +96,8 @@ class LRUCache {
 
 	}
 
+	// TODO: this should be renamed because it's not necessarily unloading all unused content
+	// Maybe call it "cleanup" or "unloadToMinSize"
 	unloadUnusedContent( prioritySortCb ) {
 
 		const unloadPercent = this.unloadPercent;