Kaynağa Gözat

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

Mr.doob 5 yıl önce
ebeveyn
işleme
4650aa2fae

+ 1 - 1
src/renderers/WebGLRenderer.js

@@ -957,7 +957,7 @@ function WebGLRenderer( parameters ) {
 		onAnimationFrameCallback = callback;
 		onAnimationFrameCallback = callback;
 		xr.setAnimationLoop( callback );
 		xr.setAnimationLoop( callback );
 
 
-		animation.start();
+		( callback === null ) ? animation.stop() : animation.start();
 
 
 	};
 	};
 
 

+ 5 - 4
src/renderers/webgl/WebGLAnimation.js

@@ -7,14 +7,13 @@ function WebGLAnimation() {
 	let context = null;
 	let context = null;
 	let isAnimating = false;
 	let isAnimating = false;
 	let animationLoop = null;
 	let animationLoop = null;
+	let requestId = null;
 
 
 	function onAnimationFrame( time, frame ) {
 	function onAnimationFrame( time, frame ) {
 
 
-		if ( isAnimating === false ) return;
-
 		animationLoop( time, frame );
 		animationLoop( time, frame );
 
 
-		context.requestAnimationFrame( onAnimationFrame );
+		requestId = context.requestAnimationFrame( onAnimationFrame );
 
 
 	}
 	}
 
 
@@ -25,7 +24,7 @@ function WebGLAnimation() {
 			if ( isAnimating === true ) return;
 			if ( isAnimating === true ) return;
 			if ( animationLoop === null ) return;
 			if ( animationLoop === null ) return;
 
 
-			context.requestAnimationFrame( onAnimationFrame );
+			requestId = context.requestAnimationFrame( onAnimationFrame );
 
 
 			isAnimating = true;
 			isAnimating = true;
 
 
@@ -33,6 +32,8 @@ function WebGLAnimation() {
 
 
 		stop: function () {
 		stop: function () {
 
 
+			context.cancelAnimationFrame( requestId );
+
 			isAnimating = false;
 			isAnimating = false;
 
 
 		},
 		},