Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Creates a loop for custom animations, paused by default
- *
- * Use:
- * var loop = new Loop();
- * loop.update = function(delta, time) {
- * // Animate stuff
- * };
- *
- * loop.resume();
- * loop.pause();
- *
- */
- define([
- 'three',
- ], function() {
- return function() {
- var _this = this;
- _this.update = function() {};
- _this.stop = false;
- _this.clock = new THREE.Clock();
- var delta = 0;
- var time = 0;
- var loop = function() {
- if (_this.stop) return;
- requestAnimationFrame(loop);
- delta = _this.clock.getDelta();
- // Avoid jumps upon reactivation
- if (delta > 0.4) delta = 0;
- time += delta;
- _this.update(delta, time);
- };
- _this.pause = function() {
- _this.stop = true;
- };
- _this.resume = function() {
- _this.stop = false;
- requestAnimationFrame(loop);
- };
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement