Three.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @author mr.doob / http://mrdoob.com/
  3. */
  4. var THREE = THREE || { REVISION: '50dev' };
  5. if ( ! self.Int32Array ) {
  6. self.Int32Array = Array;
  7. self.Float32Array = Array;
  8. }
  9. // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
  10. // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
  11. // requestAnimationFrame polyfill by Erik Möller
  12. // fixes from Paul Irish and Tino Zijdel
  13. ( function () {
  14. var lastTime = 0;
  15. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  16. for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++ x ) {
  17. window.requestAnimationFrame = window[ vendors[ x ] + 'RequestAnimationFrame' ];
  18. window.cancelAnimationFrame = window[ vendors[ x ] + 'CancelAnimationFrame' ] || window[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  19. }
  20. if ( !window.requestAnimationFrame ) {
  21. window.requestAnimationFrame = function ( callback, element ) {
  22. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  23. var id = window.setTimeout( function() { callback( currTime + timeToCall ); }, timeToCall );
  24. lastTime = currTime + timeToCall;
  25. return id;
  26. };
  27. }
  28. if ( !window.cancelAnimationFrame ) {
  29. window.cancelAnimationFrame = function ( id ) { clearTimeout( id ); };
  30. }
  31. }() );