Browse Source

Updated builds.

Mr.doob 6 years ago
parent
commit
00a9980717
3 changed files with 347 additions and 251 deletions
  1. 63 15
      build/three.js
  2. 221 221
      build/three.min.js
  3. 63 15
      build/three.module.js

+ 63 - 15
build/three.js

@@ -21264,7 +21264,66 @@
 
 		constructor: ArrayCamera,
 
-		isArrayCamera: true
+		isArrayCamera: true,
+
+		/**
+		 * Assumes 2 cameras that are perpendicular and share an X-axis, and that
+		 * the cameras' projection and world matrices have already been set.
+		 * And that near and far planes are identical for both cameras.
+		 */
+		setProjectionFromUnion: function () {
+			var cameraLPos = new Vector3();
+			var cameraRPos = new Vector3();
+
+			return function () {
+				cameraLPos.setFromMatrixPosition( this.cameras[ 0 ].matrixWorld );
+				cameraRPos.setFromMatrixPosition( this.cameras[ 1 ].matrixWorld );
+
+				var ipd = cameraLPos.distanceTo( cameraRPos );
+
+				var projL = this.cameras[ 0 ].projectionMatrix;
+				var projR = this.cameras[ 1 ].projectionMatrix;
+
+				// VR systems will have identical far and near planes, and
+				// most likely identical top and bottom frustum extents.
+				// via: https://computergraphics.stackexchange.com/a/4765
+				var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
+				var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
+
+				var leftFovL = ( projL[ 8 ] - 1 ) / projL[ 0 ];
+				var rightFovR = ( projR[ 8 ] + 1 ) / projR[ 0 ];
+				var leftL = leftFovL * near;
+				var rightR = rightFovR * near;
+				var topL = near * ( projL[ 9 ] + 1 ) / projL[ 5 ];
+				var topR = near * ( projR[ 9 ] + 1 ) / projR[ 5 ];
+				var bottomL = near * ( projL[ 9 ] - 1 ) / projL[ 5 ];
+				var bottomR = near * ( projR[ 9 ] - 1 ) / projR[ 5 ];
+
+				// Calculate the new camera's position offset from the
+				// left camera.
+				var zOffset = ipd / (leftFovL + rightFovR);
+				var xOffset = zOffset * leftFovL;
+
+				// TODO: Better way to apply this offset?
+				this.cameras[ 0 ].matrixWorld.decompose( this.position, this.quaternion, this.scale );
+				this.translateX(xOffset);
+				this.translateZ(-zOffset);
+				this.matrixWorld.compose( this.position, this.quaternion, this.scale );
+				this.matrixWorldInverse.getInverse(this.matrixWorld);
+
+				// Find the union of the frustum values of the cameras and scale
+				// the values so that the near plane's position does not change in world space,
+				// although must now be relative to the new union camera.
+				var near2 = near + zOffset;
+				var far2 = far + zOffset;
+				var left = leftL - xOffset;
+				var right = rightR + (ipd - xOffset);
+				var top = Math.max( topL, topR );
+				var bottom = Math.min( bottomL, bottomR );
+
+				this.projectionMatrix.makePerspective( left, right, top, bottom, near2, far2 );
+			}
+		}(),
 
 	} );
 
@@ -21551,9 +21610,6 @@
 			cameraL.far = camera.far;
 			cameraR.far = camera.far;
 
-			cameraVR.matrixWorld.copy( camera.matrixWorld );
-			cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
-
 			cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
 			cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
 
@@ -21587,10 +21643,7 @@
 			cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
 			cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
 
-			// HACK (mrdoob)
-			// https://github.com/w3c/webvr/issues/203
-
-			cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
+			cameraVR.setProjectionFromUnion();
 
 			//
 
@@ -21813,8 +21866,6 @@
 				var parent = camera.parent;
 				var cameras = cameraVR.cameras;
 
-				// apply camera.parent to cameraVR
-
 				updateCamera( cameraVR, parent );
 
 				for ( var i = 0; i < cameras.length; i ++ ) {
@@ -21835,6 +21886,8 @@
 
 				}
 
+				cameraVR.setProjectionFromUnion();
+
 				return cameraVR;
 
 			}
@@ -21873,11 +21926,6 @@
 
 						cameraVR.matrix.copy( camera.matrix );
 
-						// HACK (mrdoob)
-						// https://github.com/w3c/webvr/issues/203
-
-						cameraVR.projectionMatrix.copy( camera.projectionMatrix );
-
 					}
 
 				}

File diff suppressed because it is too large
+ 221 - 221
build/three.min.js


+ 63 - 15
build/three.module.js

@@ -21258,7 +21258,66 @@ ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototyp
 
 	constructor: ArrayCamera,
 
-	isArrayCamera: true
+	isArrayCamera: true,
+
+	/**
+	 * Assumes 2 cameras that are perpendicular and share an X-axis, and that
+	 * the cameras' projection and world matrices have already been set.
+	 * And that near and far planes are identical for both cameras.
+	 */
+	setProjectionFromUnion: function () {
+		var cameraLPos = new Vector3();
+		var cameraRPos = new Vector3();
+
+		return function () {
+			cameraLPos.setFromMatrixPosition( this.cameras[ 0 ].matrixWorld );
+			cameraRPos.setFromMatrixPosition( this.cameras[ 1 ].matrixWorld );
+
+			var ipd = cameraLPos.distanceTo( cameraRPos );
+
+			var projL = this.cameras[ 0 ].projectionMatrix;
+			var projR = this.cameras[ 1 ].projectionMatrix;
+
+			// VR systems will have identical far and near planes, and
+			// most likely identical top and bottom frustum extents.
+			// via: https://computergraphics.stackexchange.com/a/4765
+			var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
+			var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
+
+			var leftFovL = ( projL[ 8 ] - 1 ) / projL[ 0 ];
+			var rightFovR = ( projR[ 8 ] + 1 ) / projR[ 0 ];
+			var leftL = leftFovL * near;
+			var rightR = rightFovR * near;
+			var topL = near * ( projL[ 9 ] + 1 ) / projL[ 5 ];
+			var topR = near * ( projR[ 9 ] + 1 ) / projR[ 5 ];
+			var bottomL = near * ( projL[ 9 ] - 1 ) / projL[ 5 ];
+			var bottomR = near * ( projR[ 9 ] - 1 ) / projR[ 5 ];
+
+			// Calculate the new camera's position offset from the
+			// left camera.
+			var zOffset = ipd / (leftFovL + rightFovR);
+			var xOffset = zOffset * leftFovL;
+
+			// TODO: Better way to apply this offset?
+			this.cameras[ 0 ].matrixWorld.decompose( this.position, this.quaternion, this.scale );
+			this.translateX(xOffset);
+			this.translateZ(-zOffset);
+			this.matrixWorld.compose( this.position, this.quaternion, this.scale );
+			this.matrixWorldInverse.getInverse(this.matrixWorld);
+
+			// Find the union of the frustum values of the cameras and scale
+			// the values so that the near plane's position does not change in world space,
+			// although must now be relative to the new union camera.
+			var near2 = near + zOffset;
+			var far2 = far + zOffset;
+			var left = leftL - xOffset;
+			var right = rightR + (ipd - xOffset);
+			var top = Math.max( topL, topR );
+			var bottom = Math.min( bottomL, bottomR );
+
+			this.projectionMatrix.makePerspective( left, right, top, bottom, near2, far2 );
+		}
+	}(),
 
 } );
 
@@ -21545,9 +21604,6 @@ function WebVRManager( renderer ) {
 		cameraL.far = camera.far;
 		cameraR.far = camera.far;
 
-		cameraVR.matrixWorld.copy( camera.matrixWorld );
-		cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
-
 		cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
 		cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
 
@@ -21581,10 +21637,7 @@ function WebVRManager( renderer ) {
 		cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
 		cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
 
-		// HACK (mrdoob)
-		// https://github.com/w3c/webvr/issues/203
-
-		cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
+		cameraVR.setProjectionFromUnion();
 
 		//
 
@@ -21807,8 +21860,6 @@ function WebXRManager( renderer ) {
 			var parent = camera.parent;
 			var cameras = cameraVR.cameras;
 
-			// apply camera.parent to cameraVR
-
 			updateCamera( cameraVR, parent );
 
 			for ( var i = 0; i < cameras.length; i ++ ) {
@@ -21829,6 +21880,8 @@ function WebXRManager( renderer ) {
 
 			}
 
+			cameraVR.setProjectionFromUnion();
+
 			return cameraVR;
 
 		}
@@ -21867,11 +21920,6 @@ function WebXRManager( renderer ) {
 
 					cameraVR.matrix.copy( camera.matrix );
 
-					// HACK (mrdoob)
-					// https://github.com/w3c/webvr/issues/203
-
-					cameraVR.projectionMatrix.copy( camera.projectionMatrix );
-
 				}
 
 			}

Some files were not shown because too many files changed in this diff