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

WebGLRenderer: Accept null when using setAnimationLoop().

Mugen87 5 жил өмнө
parent
commit
81a31ced6c

+ 1 - 1
src/renderers/WebGLRenderer.js

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

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

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