Jelajahi Sumber

Calculate SSE directly from projection matrix rather than specific Camera subclass properties

By relying only on the projectionMatrix, rather than specific properties from
PerspectiveCamera/OrthographicCamera, this allows for custom Camera implementations
that manage their own projection, transition between perspective and ortho views, etc.
Jason Johnston 4 tahun lalu
induk
melakukan
1f157f13d6
1 mengubah file dengan 12 tambahan dan 11 penghapusan
  1. 12 11
      src/three/TilesRenderer.js

+ 12 - 11
src/three/TilesRenderer.js

@@ -355,10 +355,11 @@ export class TilesRenderer extends TilesRendererBase {
 			cameraInfo.push( {
 
 				frustum: new Frustum(),
-				sseDenominator: - 1,
+				isOrthographic: false,
+				sseDenominator: - 1, // used if isOrthographic:false
 				position: new Vector3(),
 				invScale: - 1,
-				pixelSize: 0,
+				pixelSize: 0, // used if isOrthographic:true
 
 			} );
 
@@ -392,17 +393,18 @@ export class TilesRenderer extends TilesRendererBase {
 
 			}
 
-			if ( camera.isPerspectiveCamera ) {
+			const projection = camera.projectionMatrix.elements;
+			info.isOrthographic = projection[ 15 ] === 1;
 
-				info.sseDenominator = 2 * Math.tan( 0.5 * camera.fov * DEG2RAD ) / resolution.height;
+			if ( info.isOrthographic ) {
 
-			}
+				const w = 2 / projection[ 0 ];
+				const h = 2 / projection[ 5 ];
+				info.pixelSize = Math.max( h / resolution.height, w / resolution.width );
 
-			if ( camera.isOrthographicCamera ) {
+			} else {
 
-				const w = camera.right - camera.left;
-				const h = camera.top - camera.bottom;
-				info.pixelSize = Math.max( h / resolution.height, w / resolution.width );
+				info.sseDenominator = ( 2 / projection[ 5 ] ) / resolution.height;
 
 			}
 
@@ -842,12 +844,11 @@ export class TilesRenderer extends TilesRendererBase {
 				}
 
 				// transform camera position into local frame of the tile bounding box
-				const camera = cameras[ i ];
 				const info = cameraInfo[ i ];
 				const invScale = info.invScale;
 
 				let error;
-				if ( camera.isOrthographicCamera ) {
+				if ( info.isOrthographic ) {
 
 					const pixelSize = info.pixelSize;
 					error = tile.geometricError / ( pixelSize * invScale );