Răsfoiți Sursa

Editor: Added WebVR support.

Mr.doob 9 ani în urmă
părinte
comite
5f73e14129
4 a modificat fișierele cu 25 adăugiri și 18 ștergeri
  1. 1 0
      editor/index.html
  2. 7 0
      editor/js/Menubar.File.js
  3. 2 6
      editor/js/Player.js
  4. 15 12
      editor/js/libs/app.js

+ 1 - 0
editor/index.html

@@ -84,6 +84,7 @@
 
 		<script src="../examples/js/effects/VREffect.js"></script>
 		<script src="../examples/js/controls/VRControls.js"></script>
+		<script src="../examples/js/WebVR.js"></script>
 
 		<script src="js/Storage.js"></script>
 

+ 7 - 0
editor/js/Menubar.File.js

@@ -242,6 +242,7 @@ Menubar.File = function ( editor ) {
 
 				includes.push( '<script src="js/VRControls.js"></script>' );
 				includes.push( '<script src="js/VREffect.js"></script>' );
+				includes.push( '<script src="js/WebVR.js"></script>' );
 
 			}
 
@@ -275,6 +276,12 @@ Menubar.File = function ( editor ) {
 
 			} );
 
+			loader.load( '../examples/js/WebVR.js', function ( content ) {
+
+				zip.file( 'js/WebVR.js', content );
+
+			} );
+
 		}
 
 	} );

+ 2 - 6
editor/js/Player.js

@@ -14,11 +14,10 @@ var Player = function ( editor ) {
 	//
 
 	var player = new APP.Player();
+	container.dom.appendChild( player.dom );
 
 	window.addEventListener( 'resize', function () {
 
-		if ( player.dom === undefined ) return;
-
 		player.setSize( container.dom.clientWidth, container.dom.clientHeight );
 
 	} );
@@ -31,8 +30,6 @@ var Player = function ( editor ) {
 		player.setSize( container.dom.clientWidth, container.dom.clientHeight );
 		player.play();
 
-		container.dom.appendChild( player.dom );
-
 	} );
 
 	signals.stopPlayer.add( function () {
@@ -40,8 +37,7 @@ var Player = function ( editor ) {
 		container.setDisplay( 'none' );
 
 		player.stop();
-
-		container.dom.removeChild( player.dom );
+		player.dispose();
 
 	} );
 

+ 15 - 12
editor/js/libs/app.js

@@ -15,7 +15,7 @@ var APP = {
 
 		var events = {};
 
-		this.dom = undefined;
+		this.dom = document.createElement( 'div' );
 
 		this.width = 500;
 		this.height = 500;
@@ -35,7 +35,7 @@ var APP = {
 
 			}
 
-			this.dom = renderer.domElement;
+			this.dom.appendChild( renderer.domElement );
 
 			this.setScene( loader.parse( json.scene ) );
 			this.setCamera( loader.parse( json.camera ) );
@@ -133,21 +133,17 @@ var APP = {
 				controls = new THREE.VRControls( camera );
 				effect = new THREE.VREffect( renderer );
 
-				document.addEventListener( 'keyup', function ( event ) {
+				if ( WEBVR.isAvailable() === true ) {
 
-					switch ( event.keyCode ) {
-						case 90:
-							controls.zeroSensor();
-							break;
-					}
+					this.dom.appendChild( WEBVR.getButton( effect ) );
 
-				} );
+				}
 
-				this.dom.addEventListener( 'dblclick', function () {
+				if ( WEBVR.isLatestAvailable() === false ) {
 
-					effect.setFullScreen( true );
+					this.dom.appendChild( WEBVR.getMessage() );
 
-				} );
+				}
 
 			}
 
@@ -249,6 +245,13 @@ var APP = {
 
 		};
 
+		this.dispose = function () {
+
+			this.dom.removeChild( renderer.domElement );
+			renderer.dispose();
+
+		};
+
 		//
 
 		function onDocumentKeyDown( event ) {