WebGLAnimation.js 767 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function WebGLAnimation() {
  2. let context = null;
  3. let isAnimating = false;
  4. let animationLoop = null;
  5. let requestId = null;
  6. function onAnimationFrame( time, frame ) {
  7. animationLoop( time, frame );
  8. requestId = context.requestAnimationFrame( onAnimationFrame );
  9. }
  10. return {
  11. start: function () {
  12. if ( isAnimating === true ) return;
  13. if ( animationLoop === null ) return;
  14. requestId = context.requestAnimationFrame( onAnimationFrame );
  15. isAnimating = true;
  16. },
  17. stop: function () {
  18. context.cancelAnimationFrame( requestId );
  19. isAnimating = false;
  20. },
  21. setAnimationLoop: function ( callback ) {
  22. animationLoop = callback;
  23. },
  24. setContext: function ( value ) {
  25. context = value;
  26. }
  27. };
  28. }
  29. export { WebGLAnimation };