Skip to content

Commit c177eaf

Browse files
authored
WebGPURenderer: Make Animation WebXR compatible. (#29783)
1 parent f421bff commit c177eaf

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/renderers/common/Animation.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,55 @@ class Animation {
55
this.nodes = nodes;
66
this.info = info;
77

8-
this.animationLoop = null;
9-
this.requestId = null;
10-
11-
this._init();
8+
this._context = self;
9+
this._animationLoop = null;
10+
this._requestId = null;
1211

1312
}
1413

15-
_init() {
14+
start() {
1615

1716
const update = ( time, frame ) => {
1817

19-
this.requestId = self.requestAnimationFrame( update );
18+
this._requestId = this._context.requestAnimationFrame( update );
2019

2120
if ( this.info.autoReset === true ) this.info.reset();
2221

2322
this.nodes.nodeFrame.update();
2423

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

27-
if ( this.animationLoop !== null ) this.animationLoop( time, frame );
26+
if ( this._animationLoop !== null ) this._animationLoop( time, frame );
2827

2928
};
3029

3130
update();
3231

3332
}
3433

35-
dispose() {
34+
stop() {
35+
36+
this._context.cancelAnimationFrame( this._requestId );
3637

37-
self.cancelAnimationFrame( this.requestId );
38-
this.requestId = null;
38+
this._requestId = null;
3939

4040
}
4141

4242
setAnimationLoop( callback ) {
4343

44-
this.animationLoop = callback;
44+
this._animationLoop = callback;
45+
46+
}
47+
48+
setContext( context ) {
49+
50+
this._context = context;
51+
52+
}
53+
54+
dispose() {
55+
56+
this.stop();
4557

4658
}
4759

src/renderers/common/Renderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class Renderer {
248248

249249
//
250250

251+
this._animation.start();
251252
this._initialized = true;
252253

253254
resolve();

0 commit comments

Comments
 (0)