Spaces:
Sleeping
Sleeping
File size: 737 Bytes
2b7aae2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | function WebGLAnimation() {
let context = null;
let isAnimating = false;
let animationLoop = null;
let requestId = null;
function onAnimationFrame(time, frame) {
animationLoop(time, frame);
requestId = context.requestAnimationFrame(onAnimationFrame);
}
return {
start: function () {
if (isAnimating === true) return;
if (animationLoop === null) return;
requestId = context.requestAnimationFrame(onAnimationFrame);
isAnimating = true;
},
stop: function () {
context?.cancelAnimationFrame(requestId);
isAnimating = false;
},
setAnimationLoop: function (callback) {
animationLoop = callback;
},
setContext: function (value) {
context = value;
},
};
}
export { WebGLAnimation };
|