Sfoglia il codice sorgente

Editor: Improved VR support.

Mr.doob 10 anni fa
parent
commit
e2b015e11b
3 ha cambiato i file con 33 aggiunte e 15 eliminazioni
  1. 3 0
      editor/js/Editor.js
  2. 0 1
      editor/js/Player.js
  3. 30 14
      editor/js/libs/app.js

+ 3 - 0
editor/js/Editor.js

@@ -470,6 +470,9 @@ Editor.prototype = {
 
 		return {
 
+			project: {
+				vr: this.config.getKey( 'project/vr' )
+			},
 			camera: this.camera.toJSON(),
 			scene: this.scene.toJSON(),
 			scripts: this.scripts

+ 0 - 1
editor/js/Player.js

@@ -27,7 +27,6 @@ var Player = function ( editor ) {
 
 		container.setDisplay( '' );
 
-		player.setVR( editor.config.getKey( 'project/vr' ) );
 		player.load( editor.toJSON() );
 		player.setSize( container.dom.clientWidth, container.dom.clientHeight );
 		player.play();

+ 30 - 14
editor/js/libs/app.js

@@ -22,12 +22,15 @@ var APP = {
 
 		this.load = function ( json ) {
 
+			vr = json.project.vr;
+
 			renderer = new THREE.WebGLRenderer( { antialias: true } );
 			renderer.setClearColor( 0x000000 );
 			renderer.setPixelRatio( window.devicePixelRatio );
+			this.dom = renderer.domElement;
 
-			camera = loader.parse( json.camera );
-			scene = loader.parse( json.scene );
+			this.setScene( loader.parse( json.scene ) );
+			this.setCamera( loader.parse( json.camera ) );
 
 			events = {
 				keydown: [],
@@ -72,10 +75,30 @@ var APP = {
 
 			}
 
-			this.dom = renderer.domElement;
+		};
+
+		this.setCamera = function ( value ) {
+
+			camera = value;
+			camera.aspect = this.width / this.height;
+			camera.updateProjectionMatrix();
+
 
 			if ( vr === true ) {
 
+				if ( camera.parent === undefined ) {
+
+					// camera needs to be in the scene so camera2 matrix updates
+					
+					scene.add( camera );
+
+				}
+
+				var camera2 = camera.clone();
+				camera.add( camera2 );
+
+				camera = camera2;
+
 				controls = new THREE.VRControls( camera );
 				renderer = new THREE.VREffect( renderer );
 
@@ -94,23 +117,16 @@ var APP = {
 					renderer.setFullScreen( true );
 
 				} );
-			}
 
-		};
-
-		this.setCamera = function ( value ) {
-
-			camera = value;
-			camera.aspect = this.width / this.height;
-			camera.updateProjectionMatrix();
+			}
 
 		};
 
-		this.setVR = function ( value ) {
+		this.setScene = function ( value ) {
 
-			vr = value;
+			scene = value;
 
-		};
+		},
 
 		this.setSize = function ( width, height ) {