Browse Source

Refactored requestAnimationFrame logic.
Introduced animation stop function.

brunnerh 7 years ago
parent
commit
eadda9a08d
1 changed files with 18 additions and 16 deletions
  1. 18 16
      src/renderers/WebGLRenderer.js

+ 18 - 16
src/renderers/WebGLRenderer.js

@@ -1050,6 +1050,22 @@ function WebGLRenderer( parameters ) {
 
 
 		if ( isAnimating ) return;
 		if ( isAnimating ) return;
 
 
+		requestLoopFrame();
+
+		isAnimating = true;
+
+	}
+
+	function stop()
+	{
+
+		isAnimating = false;
+
+	}
+
+	function requestLoopFrame()
+	{
+
 		var device = vr.getDevice();
 		var device = vr.getDevice();
 
 
 		if ( device && device.isPresenting ) {
 		if ( device && device.isPresenting ) {
@@ -1062,37 +1078,23 @@ function WebGLRenderer( parameters ) {
 
 
 		}
 		}
 
 
-		isAnimating = true;
-
 	}
 	}
 
 
 	function loop( time ) {
 	function loop( time ) {
 
 
-		if ( onAnimationFrame === null ) isAnimating = false;
-
 		if ( isAnimating === false )
 		if ( isAnimating === false )
 			return;
 			return;
 
 
 		onAnimationFrame( time );
 		onAnimationFrame( time );
 
 
-		var device = vr.getDevice();
-
-		if ( device && device.isPresenting ) {
-
-			device.requestAnimationFrame( loop );
-
-		} else {
-
-			window.requestAnimationFrame( loop );
-
-		}
+		requestLoopFrame();
 
 
 	}
 	}
 
 
 	this.animate = function ( callback ) {
 	this.animate = function ( callback ) {
 
 
 		onAnimationFrame = callback;
 		onAnimationFrame = callback;
-		start();
+		onAnimationFrame !== null ? start() : stop();
 
 
 	};
 	};