Browse Source

Merge pull request #16365 from takahirox/SessionEvent

Dispatch start/endSession event on entering/existing immersive mode
Mr.doob 6 năm trước cách đây
mục cha
commit
b11e46a1b9
2 tập tin đã thay đổi với 16 bổ sung0 xóa
  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';
@@ -82,6 +83,8 @@ function WebVRManager( renderer ) {
 
 			animation.start();
 
+			scope.dispatchEvent( { type: 'sessionstart' } );
+
 		} else {
 
 			if ( scope.enabled ) {
@@ -92,6 +95,8 @@ function WebVRManager( renderer ) {
 
 			animation.stop();
 
+			scope.dispatchEvent( { type: 'sessionend' } );
+
 		}
 
 	}
@@ -416,4 +421,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 session = null;
@@ -90,6 +93,8 @@ function WebXRManager( renderer ) {
 		renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
 		animation.stop();
 
+		scope.dispatchEvent( { type: 'sessionend' } );
+
 	}
 
 	function onRequestReferenceSpace( value ) {
@@ -99,6 +104,8 @@ function WebXRManager( renderer ) {
 		animation.setContext( session );
 		animation.start();
 
+		scope.dispatchEvent( { type: 'sessionstart' } );
+
 	}
 
 	this.setFramebufferScaleFactor = function ( value ) {
@@ -321,4 +328,6 @@ function WebXRManager( renderer ) {
 
 }
 
+Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
+
 export { WebXRManager };