diff --git a/js/models/ThreeModel.js b/js/models/ThreeModel.js index 567dbb49be12b73d2f84b35f1caf0a88f60a41c1..96ebdeaecfc929c12dd9a97ad01542440f07669b 100644 --- a/js/models/ThreeModel.js +++ b/js/models/ThreeModel.js @@ -14,6 +14,9 @@ function ThreeModel(){ var parts = []; var basePlane = []; + var animationLoopRunning = false; + var stopAnimationFlag = false; + initialize(); function initialize(){ @@ -95,15 +98,36 @@ function ThreeModel(){ return objectToRemove; } + function startAnimationLoop(){ + if (animationLoopRunning) return; + stopAnimationFlag = false; + animationLoopRunning = true; + console.log("animation started"); + _loop(); + } + + function stopAnimationLoop(){ + if (!animationLoopRunning) return; + stopAnimationFlag = true; + } + + function _loop(){ + if (stopAnimationFlag) return console.log("animation stopped"); + render(); + requestAnimationFrame(_loop); + } + function render(){ + if (animationLoopRunning) return; renderer.render(scene, camera); } return {//return public properties/methods render: render, + startAnimationLoop: startAnimationLoop, + stopAnimationLoop: stopAnimationLoop, sceneRemove: sceneRemove, sceneAdd: sceneAdd, -// scene: scene, domElement: renderer.domElement, camera: camera, cells: cells, diff --git a/js/threeViews/ThreeView.js b/js/threeViews/ThreeView.js index 0087c29b8003c3cdcef9baf94c8258e458110477..e2d74f7746c3c53c1b11f85469875881df45a631 100644 --- a/js/threeViews/ThreeView.js +++ b/js/threeViews/ThreeView.js @@ -40,7 +40,7 @@ ThreeView = Backbone.View.extend({ this.$el.append(this.model.domElement);//render only once this.model.render(); - this._animate(); +// this._animate(); }, //////////////////////////////////////////////////////////////////////////////// @@ -48,8 +48,8 @@ ThreeView = Backbone.View.extend({ //////////////////////////////////////////////////////////////////////////////// _animate: function(){ - requestAnimationFrame(this._animate); - this.controls.update(); +// requestAnimationFrame(this._animate); +// this.controls.update(); }, _setControlsEnabled: function(){