瀏覽代碼

Merge pull request #19695 from Mugen87/dev45

WebGLRenderer: Accept null when using setAnimationLoop().
Mr.doob 5 年之前
父節點
當前提交
fd784a6073
共有 2 個文件被更改,包括 6 次插入5 次删除
  1. 1 1
      src/renderers/WebGLRenderer.js
  2. 5 4
      src/renderers/webgl/WebGLAnimation.js

+ 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 - 4
src/renderers/webgl/WebGLAnimation.js

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