2
0
Эх сурвалжийг харах

Merge branch 'dev' of https://github.com/mrdoob/three.js into dev

Mr.doob 7 жил өмнө
parent
commit
b26585f958

+ 22 - 16
src/renderers/WebGLRenderer.js

@@ -530,6 +530,8 @@ function WebGLRenderer( parameters ) {
 
 		vr.dispose();
 
+		stopAnimation();
+
 	};
 
 	// Events
@@ -1044,48 +1046,52 @@ function WebGLRenderer( parameters ) {
 	var isAnimating = false;
 	var onAnimationFrame = null;
 
-	function start() {
+	function startAnimation() {
 
 		if ( isAnimating ) return;
 
-		var device = vr.getDevice();
+		requestAnimationLoopFrame();
 
-		if ( device && device.isPresenting ) {
-
-			device.requestAnimationFrame( loop );
+		isAnimating = true;
 
-		} else {
+	}
 
-			window.requestAnimationFrame( loop );
+	function stopAnimation() {
 
-		}
-
-		isAnimating = true;
+		isAnimating = false;
 
 	}
 
-	function loop( time ) {
-
-		if ( onAnimationFrame !== null ) onAnimationFrame( time );
+	function requestAnimationLoopFrame() {
 
 		var device = vr.getDevice();
 
 		if ( device && device.isPresenting ) {
 
-			device.requestAnimationFrame( loop );
+			device.requestAnimationFrame( animationLoop );
 
 		} else {
 
-			window.requestAnimationFrame( loop );
+			window.requestAnimationFrame( animationLoop );
 
 		}
 
 	}
 
+	function animationLoop( time ) {
+
+		if ( isAnimating === false ) return;
+
+		onAnimationFrame( time );
+
+		requestAnimationLoopFrame();
+
+	}
+
 	this.animate = function ( callback ) {
 
 		onAnimationFrame = callback;
-		start();
+		onAnimationFrame !== null ? startAnimation() : stopAnimation();
 
 	};