You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
797 B
59 lines
797 B
2 years ago
|
class WebGPUAnimation {
|
||
|
|
||
|
constructor() {
|
||
|
|
||
|
this.nodes = null;
|
||
|
|
||
|
this.animationLoop = null;
|
||
|
this.requestId = null;
|
||
|
|
||
|
this.isAnimating = false;
|
||
|
|
||
|
this.context = self;
|
||
|
|
||
|
}
|
||
|
|
||
|
start() {
|
||
|
|
||
|
if ( this.isAnimating === true || this.animationLoop === null || this.nodes === null ) return;
|
||
|
|
||
|
this.isAnimating = true;
|
||
|
|
||
|
const update = ( time, frame ) => {
|
||
|
|
||
|
this.requestId = self.requestAnimationFrame( update );
|
||
|
|
||
|
this.animationLoop( time, frame );
|
||
|
|
||
|
this.nodes.updateFrame();
|
||
|
|
||
|
};
|
||
|
|
||
|
this.requestId = self.requestAnimationFrame( update );
|
||
|
|
||
|
}
|
||
|
|
||
|
stop() {
|
||
|
|
||
|
self.cancelAnimationFrame( this.requestId );
|
||
|
|
||
|
this.isAnimating = false;
|
||
|
|
||
|
}
|
||
|
|
||
|
setAnimationLoop( callback ) {
|
||
|
|
||
|
this.animationLoop = callback;
|
||
|
|
||
|
}
|
||
|
|
||
|
setNodes( nodes ) {
|
||
|
|
||
|
this.nodes = nodes;
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export default WebGPUAnimation;
|