Browse Source

Dispatch start/endSession event on entering/existing immersive mode

Takahiro 6 years ago
parent
commit
5cd8fe02fe
2 changed files with 16 additions and 0 deletions
  1. 7 0
      src/renderers/webvr/WebVRManager.js
  2. 9 0
      src/renderers/webvr/WebXRManager.js

+ 7 - 0
src/renderers/webvr/WebVRManager.js

@@ -2,6 +2,7 @@
  * @author mrdoob / http://mrdoob.com/
  */
 
+import { EventDispatcher } from '../../core/EventDispatcher.js';
 import { Group } from '../../objects/Group.js';
 import { Matrix4 } from '../../math/Matrix4.js';
 import { Vector2 } from '../../math/Vector2.js';
@@ -78,6 +79,8 @@ function WebVRManager( renderer ) {
 
 			animation.start();
 
+			scope.dispatchEvent( { type: 'startSession' } );
+
 		} else {
 
 			if ( scope.enabled ) {
@@ -88,6 +91,8 @@ function WebVRManager( renderer ) {
 
 			animation.stop();
 
+			scope.dispatchEvent( { type: 'endSession' } );
+
 		}
 
 	}
@@ -401,4 +406,6 @@ function WebVRManager( renderer ) {
 
 }
 
+Object.assign( WebVRManager.prototype, EventDispatcher.prototype );
+
 export { WebVRManager };

+ 9 - 0
src/renderers/webvr/WebXRManager.js

@@ -2,6 +2,7 @@
  * @author mrdoob / http://mrdoob.com/
  */
 
+import { EventDispatcher } from '../../core/EventDispatcher.js';
 import { Group } from '../../objects/Group.js';
 import { Matrix4 } from '../../math/Matrix4.js';
 import { Vector4 } from '../../math/Vector4.js';
@@ -12,6 +13,8 @@ import { setProjectionFromUnion } from './WebVRUtils.js';
 
 function WebXRManager( renderer ) {
 
+	var scope = this;
+
 	var gl = renderer.context;
 
 	var device = null;
@@ -97,6 +100,8 @@ function WebXRManager( renderer ) {
 		renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
 		animation.stop();
 
+		scope.dispatchEvent( { type: 'endSession' } );
+
 	}
 
 	this.setFramebufferScaleFactor = function ( value ) {
@@ -132,6 +137,8 @@ function WebXRManager( renderer ) {
 				animation.setContext( session );
 				animation.start();
 
+				scope.dispatchEvent( { type: 'startSession' } );
+
 			} );
 
 			//
@@ -312,4 +319,6 @@ function WebXRManager( renderer ) {
 
 }
 
+Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
+
 export { WebXRManager };