Просмотр исходного кода

WebGPURenderer: Make `Animation` WebXR compatible. (#29783)

Michael Herzog 1 год назад
Родитель
Сommit
c177eaff37
2 измененных файлов с 24 добавлено и 11 удалено
  1. 23 11
      src/renderers/common/Animation.js
  2. 1 0
      src/renderers/common/Renderer.js

+ 23 - 11
src/renderers/common/Animation.js

@@ -5,18 +5,17 @@ class Animation {
 		this.nodes = nodes;
 		this.info = info;
 
-		this.animationLoop = null;
-		this.requestId = null;
-
-		this._init();
+		this._context = self;
+		this._animationLoop = null;
+		this._requestId = null;
 
 	}
 
-	_init() {
+	start() {
 
 		const update = ( time, frame ) => {
 
-			this.requestId = self.requestAnimationFrame( update );
+			this._requestId = this._context.requestAnimationFrame( update );
 
 			if ( this.info.autoReset === true ) this.info.reset();
 
@@ -24,7 +23,7 @@ class Animation {
 
 			this.info.frame = this.nodes.nodeFrame.frameId;
 
-			if ( this.animationLoop !== null ) this.animationLoop( time, frame );
+			if ( this._animationLoop !== null ) this._animationLoop( time, frame );
 
 		};
 
@@ -32,16 +31,29 @@ class Animation {
 
 	}
 
-	dispose() {
+	stop() {
+
+		this._context.cancelAnimationFrame( this._requestId );
 
-		self.cancelAnimationFrame( this.requestId );
-		this.requestId = null;
+		this._requestId = null;
 
 	}
 
 	setAnimationLoop( callback ) {
 
-		this.animationLoop = callback;
+		this._animationLoop = callback;
+
+	}
+
+	setContext( context ) {
+
+		this._context = context;
+
+	}
+
+	dispose() {
+
+		this.stop();
 
 	}
 

+ 1 - 0
src/renderers/common/Renderer.js

@@ -248,6 +248,7 @@ class Renderer {
 
 			//
 
+			this._animation.start();
 			this._initialized = true;
 
 			resolve();

粤ICP备19079148号