Ver Fonte

Mirror: Fixed VR support

Mr.doob há 8 anos atrás
pai
commit
e1addc38ef
1 ficheiros alterados com 20 adições e 0 exclusões
  1. 20 0
      examples/js/Mirror.js

+ 20 - 0
examples/js/Mirror.js

@@ -13,6 +13,8 @@ THREE.Mirror = function ( width, height, options ) {
 
 	options = options || {};
 
+	var viewport = new THREE.Vector4();
+
 	var textureWidth = options.textureWidth !== undefined ? options.textureWidth : 512;
 	var textureHeight = options.textureHeight !== undefined ? options.textureHeight : 512;
 
@@ -201,6 +203,24 @@ THREE.Mirror = function ( width, height, options ) {
 
 		renderer.setRenderTarget( currentRenderTarget );
 
+		// Restore viewport
+
+		var bounds = camera.bounds;
+
+		if ( bounds !== undefined ) {
+
+			var size = renderer.getSize();
+			var pixelRatio = renderer.getPixelRatio();
+
+			viewport.x = bounds.x * size.width * pixelRatio;
+			viewport.y = bounds.y * size.height * pixelRatio;
+			viewport.z = bounds.z * size.width * pixelRatio;
+			viewport.w = bounds.w * size.height * pixelRatio;
+
+			renderer.state.viewport( viewport );
+
+		}
+
 		scope.visible = true;
 
 	};