Просмотр исходного кода

Merge pull request #53 from NASA-AMMOS/fix-zoom-gaps

Misc updates
Garrett Johnson 5 лет назад
Родитель
Сommit
84ad62ddfd

+ 16 - 3
example/index.js

@@ -213,8 +213,9 @@ function init() {
 		GEOMETRIC_ERROR: 2,
 		DISTANCE: 3,
 		DEPTH: 4,
-		IS_LEAF: 5,
-		RANDOM_COLOR: 6,
+		RELATIVE_DEPTH: 5,
+		IS_LEAF: 6,
+		RANDOM_COLOR: 7,
 
 	} );
 	debug.open();
@@ -224,7 +225,19 @@ function init() {
 	exampleOptions.add( params, 'orthographic' );
 	exampleOptions.add( params, 'showThirdPerson' );
 	exampleOptions.add( params, 'showSecondView' ).onChange( onWindowResize );
-	exampleOptions.add( params, 'enableUpdate' );
+	exampleOptions.add( params, 'enableUpdate' ).onChange( v => {
+
+		tiles.parseQueue.autoUpdate = v;
+		tiles.downloadQueue.autoUpdate = v;
+
+		if ( v ) {
+
+			tiles.parseQueue.scheduleJobRun();
+			tiles.downloadQueue.scheduleJobRun();
+
+		}
+
+	} );
 	exampleOptions.add( params, 'enableRaycast' );
 	exampleOptions.add( params, 'enableCacheDisplay' );
 	exampleOptions.open();

+ 1 - 0
src/base/TilesRendererBase.js

@@ -182,6 +182,7 @@ export class TilesRendererBase {
 		tile.__wasSetVisible = false;
 		tile.__visible = false;
 		tile.__childrenWereVisible = false;
+		tile.__allChildrenLoaded = false;
 
 		tile.__wasSetActive = false;
 		tile.__active = false;

+ 11 - 13
src/base/traverseFunctions.js

@@ -20,6 +20,7 @@ function resetFrameState( tile, frameCount ) {
 		tile.__active = false;
 		tile.__error = 0;
 		tile.__childrenWereVisible = false;
+		tile.__allChildrenLoaded = false;
 
 	}
 
@@ -188,14 +189,23 @@ export function markUsedSetLeaves( tile, renderer ) {
 	} else {
 
 		let childrenWereVisible = false;
+		let allChildrenLoaded = true;
 		for ( let i = 0, l = children.length; i < l; i ++ ) {
 
 			const c = children[ i ];
 			markUsedSetLeaves( c, renderer );
 			childrenWereVisible = childrenWereVisible || c.__wasSetVisible || c.__childrenWereVisible;
 
+			if ( isUsedThisFrame( c, frameCount ) ) {
+
+				const childLoaded = ( ! c.__contentEmpty && c.__loadingState === LOADED ) || c.__allChildrenLoaded;
+				allChildrenLoaded = allChildrenLoaded && childLoaded;
+
+			}
+
 		}
 		tile.__childrenWereVisible = childrenWereVisible;
+		tile.__allChildrenLoaded = allChildrenLoaded;
 
 	}
 
@@ -249,19 +259,7 @@ export function skipTraversal( tile, renderer ) {
 	const loadedContent = tile.__loadingState === LOADED && ! tile.__contentEmpty;
 	const childrenWereVisible = tile.__childrenWereVisible;
 	const children = tile.children;
-	let allChildrenHaveContent = true;
-	for ( let i = 0, l = children.length; i < l; i ++ ) {
-
-		const c = children[ i ];
-		if ( isUsedThisFrame( c, frameCount ) ) {
-
-			// TODO: This doesn't seem right -- we should check down to the next children with content?
-			const childContent = c.__loadingState === LOADED || tile.__contentEmpty;
-			allChildrenHaveContent = allChildrenHaveContent && childContent;
-
-		}
-
-	}
+	let allChildrenHaveContent = tile.__allChildrenLoaded;
 
 	// Increment the relative depth of the node to the nearest rendered parent if it has content
 	// and is being rendered.

+ 10 - 2
src/three/DebugTilesRenderer.js

@@ -9,8 +9,9 @@ const SCREEN_ERROR = 1;
 const GEOMETRIC_ERROR = 2;
 const DISTANCE = 3;
 const DEPTH = 4;
-const IS_LEAF = 5;
-const RANDOM_COLOR = 6;
+const RELATIVE_DEPTH = 5;
+const IS_LEAF = 6;
+const RANDOM_COLOR = 7;
 
 function emptyRaycast() {}
 
@@ -205,6 +206,13 @@ export class DebugTilesRenderer extends TilesRenderer {
 							break;
 
 						}
+						case RELATIVE_DEPTH: {
+
+							const val = tile.__depthFromRenderedParent / maxDepth;
+							c.material.color.setRGB( val, val, val );
+							break;
+
+						}
 						case SCREEN_ERROR: {
 
 							const val = tile.__error / errorTarget;

+ 18 - 3
src/utilities/PriorityQueue.js

@@ -16,6 +16,7 @@ class PriorityQueue {
 		this.callbacks = new Map();
 		this.currJobs = 0;
 		this.scheduled = false;
+		this.autoUpdate = true;
 
 		this.priorityCallback = () => {
 
@@ -48,7 +49,11 @@ class PriorityQueue {
 			items.push( item );
 			callbacks.set( item, prCallback );
 
-			this.scheduleJobRun();
+			if ( this.autoUpdate ) {
+
+				this.scheduleJobRun();
+
+			}
 
 		} );
 
@@ -87,13 +92,23 @@ class PriorityQueue {
 				.then( () => {
 
 					this.currJobs --;
-					this.scheduleJobRun();
+
+					if ( this.autoUpdate ) {
+
+						this.scheduleJobRun();
+
+					}
 
 				} )
 				.catch( () => {
 
 					this.currJobs --;
-					this.scheduleJobRun();
+
+					if ( this.autoUpdate ) {
+
+						this.scheduleJobRun();
+
+					}
 
 				} );
 

+ 32 - 0
test/PriorityQueue.test.js

@@ -154,4 +154,36 @@ describe( 'PriorityQueue', () => {
 
 	} );
 
+	it( 'should not automatically run if autoUpdate is false.', async () => {
+
+		const queue = new PriorityQueue();
+		queue.priorityCallback = () => 0;
+		queue.autoUpdate = false;
+		queue.maxJobs = 1;
+
+		queue.add( {}, async () => {} );
+		queue.add( {}, async () => {} );
+
+		expect( queue.items ).toHaveLength( 2 );
+
+		await nextTick();
+
+		expect( queue.items ).toHaveLength( 2 );
+
+		queue.scheduleJobRun();
+		await nextTick();
+
+		expect( queue.items ).toHaveLength( 1 );
+
+		await nextTick();
+
+		expect( queue.items ).toHaveLength( 1 );
+
+		queue.scheduleJobRun();
+		await nextTick();
+
+		expect( queue.items ).toHaveLength( 0 );
+
+	});
+
 } );