Skip to content

Commit

Permalink
WebGPURenderer: Make Animation WebXR compatible. (#29783)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Nov 5, 2024
1 parent f421bff commit c177eaf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/renderers/common/Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,55 @@ 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();

this.nodes.nodeFrame.update();

this.info.frame = this.nodes.nodeFrame.frameId;

if ( this.animationLoop !== null ) this.animationLoop( time, frame );
if ( this._animationLoop !== null ) this._animationLoop( time, frame );

};

update();

}

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();

}

Expand Down
1 change: 1 addition & 0 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class Renderer {

//

this._animation.start();
this._initialized = true;

resolve();
Expand Down

0 comments on commit c177eaf

Please sign in to comment.