diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index 1e8b8b1a606b73425733a45f9a87e62dc034b013..c582661731cbc44b470ee0a4eb0a695df9b4202e 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -77,9 +77,7 @@ Assembler = Backbone.Model.extend({ this.listenTo(options.lattice, "change:cellType change:connectionType", this._updateCellType); this.listenTo(options.appState, "change:cellMode", this._updateCellMode); - this.listenTo(this, "change:machineName", this._changeMachine); - - this._initOriginAndStock(options.lattice); + this._initOriginAndStock(); }, selectMachine: function(machineName){ @@ -142,7 +140,7 @@ Assembler = Backbone.Model.extend({ dmaGlobals.three.render(); }, - _initOriginAndStock: function(lattice){//todo this is ugly + _initOriginAndStock: function(){//todo this is ugly var origin = new THREE.Mesh(new THREE.SphereGeometry(1), new THREE.MeshBasicMaterial({color:0xff0000})); dmaGlobals.three.sceneAdd(origin); @@ -154,7 +152,7 @@ Assembler = Backbone.Model.extend({ dmaGlobals.three.sceneAdd(stock); this.set("stock", stock); this._moveStock(); - this._setCAMScale(lattice.get("scale")); + this._setCAMScale(); this._setCAMVisibility(); }, diff --git a/js/cam/Machine.js b/js/cam/Machine.js index 657819eaeae8500289d32a0f34051cfa5c601009..9d2bc95aafe5444bd218f7133208418250ff1a62 100644 --- a/js/cam/Machine.js +++ b/js/cam/Machine.js @@ -63,21 +63,28 @@ Machine.prototype.pause = function(){ }; Machine.prototype._animateMesh = function(mesh, axis, speed, target, callback){ + var increment = (target-mesh.position[axis])/20; + if (increment == 0) { + if (callback) callback(); + return; + } + var direction = 1; + if (increment<0) direction = -1; + increment = Math.max(Math.abs(increment), 0.0001)*direction; dmaGlobals.three.startAnimationLoop(); - var increment = (target-mesh.position[axis])/10; - this._incrementalMove(mesh, axis, increment, mesh.position[axis]+increment*10, callback); + this._incrementalMove(mesh, axis, increment, target, direction, callback); }; -Machine.prototype._incrementalMove = function(mesh, axis, increment, target, callback){ +Machine.prototype._incrementalMove = function(mesh, axis, increment, target, direction, callback){ var self = this; setTimeout(function(){ - if (mesh.position[axis] == target) { + if ((target-mesh.position[axis])*direction <= 0) { if (callback) callback(); return; } - mesh.position[axis] += increment; - console.log(mesh.position[axis]); - self._incrementalMove(mesh, axis, increment, target, callback) + if (Math.abs(target-mesh.position[axis]) < Math.abs(increment)) mesh.position[axis] = target;//don't overshoot + else mesh.position[axis] += increment; + self._incrementalMove(mesh, axis, increment, target, direction, callback) },100); }; diff --git a/js/models/ThreeModel.js b/js/models/ThreeModel.js index 96ebdeaecfc929c12dd9a97ad01542440f07669b..55eae6015a6a92c3a429bc69e61fc7f17b987c2f 100644 --- a/js/models/ThreeModel.js +++ b/js/models/ThreeModel.js @@ -112,13 +112,22 @@ function ThreeModel(){ } function _loop(){ - if (stopAnimationFlag) return console.log("animation stopped"); - render(); + if (stopAnimationFlag) { + animationLoopRunning = false; + console.log("animation stopped"); + return; + } +// console.log("loop"); + _render(); requestAnimationFrame(_loop); } function render(){ if (animationLoopRunning) return; + _render(); + } + + function _render(){ renderer.render(scene, camera); }