WebGLAnimation.js 761 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. function WebGLAnimation() {
  5. var context = null;
  6. var isAnimating = false;
  7. var animationLoop = null;
  8. function onAnimationFrame( time, frame ) {
  9. if ( isAnimating === false ) return;
  10. animationLoop( time, frame );
  11. context.requestAnimationFrame( onAnimationFrame );
  12. }
  13. return {
  14. start: function () {
  15. if ( isAnimating === true ) return;
  16. if ( animationLoop === null ) return;
  17. context.requestAnimationFrame( onAnimationFrame );
  18. isAnimating = true;
  19. },
  20. stop: function () {
  21. isAnimating = false;
  22. },
  23. setAnimationLoop: function ( callback ) {
  24. animationLoop = callback;
  25. },
  26. setContext: function ( value ) {
  27. context = value;
  28. }
  29. };
  30. }
  31. export { WebGLAnimation };
粤ICP备19079148号