Forráskód Böngészése

Remove reduntant calls to visible set

Garrett Johnson 5 éve
szülő
commit
77aa659446
3 módosított fájl, 40 hozzáadás és 37 törlés
  1. 14 6
      src/base/TilesRendererBase.js
  2. 18 12
      src/base/traverseFunctions.js
  3. 8 19
      src/three/TilesRenderer.js

+ 14 - 6
src/base/TilesRendererBase.js

@@ -162,16 +162,15 @@ export class TilesRendererBase {
 		tile.__inFrustum = false;
 		tile.__isLeaf = false;
 
-		tile.__wasUsed = false;
+		tile.__usedLastFrame = false;
 		tile.__used = false;
 
-		tile.__wasVisible = false;
+		tile.__wasSetVisible = false;
 		tile.__visible = false;
 
-		tile.__wasActive = false;
+		tile.__wasSetActive = false;
 		tile.__active = false;
 
-		tile.__childrenActive = false;
 		tile.__loadingState = UNLOADED;
 		tile.__loadIndex = 0;
 
@@ -386,8 +385,17 @@ export class TilesRendererBase {
 
 				stats.parsing --;
 				tile.__loadingState = LOADED;
-				this.setTileActive( tile, tile.__active );
-				this.setTileVisible( tile, tile.__visible );
+				if ( tile.__wasSetVisible ) {
+
+					this.setTileVisible( tile, true );
+
+				}
+
+				if ( tile.__wasSetActive ) {
+
+					this.setTileActive( tile, true );
+
+				}
 
 			} )
 			.catch( e => {

+ 18 - 12
src/base/traverseFunctions.js

@@ -280,28 +280,34 @@ export function toggleTiles( tile, renderer ) {
 	const isUsed = isUsedThisFrame( tile, frameCount );
 	if ( isUsed || tile.__usedLastFrame ) {
 
-		if ( ! isUsed ) {
+		let setActive = false;
+		let setVisible = false;
+		if ( isUsed ) {
 
-			if ( ! tile.__contentEmpty && tile.__loadingState === LOADED ) {
+			// enable visibility if active due to shadows
+			setActive = tile.__active;
+			setVisible = tile.__active || tile.__visible;
 
-				renderer.setTileVisible( tile, false );
-				renderer.setTileActive( tile, false );
+		}
 
-			}
-			tile.__usedLastFrame = false;
+		if ( ! tile.__contentEmpty && tile.__loadingState === LOADED ) {
+
+			if ( tile.__wasSetActive !== setActive ) {
 
-		} else {
+				renderer.setTileVisible( tile, setActive );
+
+			}
 
-			if ( ! tile.__contentEmpty && tile.__loadingState === LOADED ) {
+			if ( tile.__wasSetVisible !== setVisible ) {
 
-				// enable visibility if active due to shadows
-				renderer.setTileActive( tile, tile.__active );
-				renderer.setTileVisible( tile, tile.__active || tile.__visible );
+				renderer.setTileActive( tile, setVisible );
 
 			}
-			tile.__usedLastFrame = true;
 
 		}
+		tile.__wasSetActive = setActive;
+		tile.__wasSetVisible = setVisible;
+		tile.__usedLastFrame = isUsed;
 
 		const children = tile.children;
 		for ( let i = 0, l = children.length; i < l; i ++ ) {

+ 8 - 19
src/three/TilesRenderer.js

@@ -417,15 +417,9 @@ export class TilesRenderer extends TilesRendererBase {
 		const group = this.group;
 		if ( visible ) {
 
-			// TODO: Should set visible be called if the scene hasn't been loaded yet?
-			// Ideally this would only be called on state change and when it's relevant
-			if ( scene && ! scene.parent ) {
-
-				group.add( scene );
-				visibleTiles.add( tile );
-				scene.updateMatrixWorld( true );
-
-			}
+			group.add( scene );
+			visibleTiles.add( tile );
+			scene.updateMatrixWorld( true );
 
 		} else {
 
@@ -438,20 +432,14 @@ export class TilesRenderer extends TilesRendererBase {
 
 	setTileActive( tile, active ) {
 
-		const cached = tile.cached;
 		const activeTiles = this.activeTiles;
-		if ( active !== cached.active ) {
+		if ( active ) {
 
-			cached.active = active;
-			if ( active ) {
+			activeTiles.add( tile );
 
-				activeTiles.add( tile );
-
-			} else {
-
-				activeTiles.delete( tile );
+		} else {
 
-			}
+			activeTiles.delete( tile );
 
 		}
 
@@ -559,6 +547,7 @@ export class TilesRenderer extends TilesRendererBase {
 		const sphere = tile.cached.sphere;
 		if ( sphere ) {
 
+			// TODO: we should cache the sphere in the tileset root frame instead of transforming it here
 			_sphere.copy( sphere );
 			_sphere.applyMatrix4( tile.cached.transform );