diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js index 3322393a66887b335467255c9c22497dabd990cf..a94a17f955439b4017283f915afecc22b135e08d 100644 --- a/js/cam/assemblers/Assembler.js +++ b/js/cam/assemblers/Assembler.js @@ -224,15 +224,13 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' }; Assembler.prototype.pickUpStock = function(index, position, speed, settings, callback){ - if (index.z%2 != 0) {//rotate on odd rows - this.components.frame.rotateTo(new THREE.Vector3(0, 0, Math.PI/2), speed, callback); - } else { - this.components.frame.rotateTo(new THREE.Vector3(0, 0, 0), speed, callback); - } _.each(this.stock, function(stock){ stock.show(); }); - callback(); + if (index.z%2 != 0) {//rotate on odd rows + this.components.frame.rotateTo(new THREE.Vector3(0, 0, Math.PI/2), speed, callback); + } + this.components.frame.rotateTo(new THREE.Vector3(0, 0, 0), speed, callback); }; Assembler.prototype.releaseStock = function(index, position, settings){ diff --git a/js/cam/assemblers/Component.js b/js/cam/assemblers/Component.js index b8f9319a44e3955d0e7f611aae0d39a2a91d4fc3..1a9b0b2b886ba89079eddbf0d3331b18fd534256 100644 --- a/js/cam/assemblers/Component.js +++ b/js/cam/assemblers/Component.js @@ -74,7 +74,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ }; Component.prototype.getRotation = function(){ - return this.object3D.rotation.toVector3(); + return this.object3D.rotation.toVector3().clone(); }; Component.prototype.getObject3D = function(){ @@ -88,41 +88,34 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ } var currentPosition = this.getRotation(); var increment = 0.15;//speed/1500.0*cam.get("simSpeed"); - var incrVector = target.clone().sub(currentPosition); + var axis = new THREE.Vector3().subVectors(target, currentPosition); - if (increment == 0 || incrVector.length() == 0) { + if (increment == 0 || axis.length() == 0) { if (callback) callback(); return; } increment = Math.max(increment, 0.00001);//need to put a min on the increment - otherwise this stalls out with floating pt tol - incrVector.normalize().multiplyScalar(increment); - this._incrementalRotation(incrVector, target, callback); + this._incrementalRotation(increment, target, axis, callback); }; - Component.prototype._incrementalRotation = function(increment, target, callback){ + Component.prototype._incrementalRotation = function(increment, target, axis, callback){ var self = this; setTimeout(function(){ var remainingDist = (target.clone().sub(self.getRotation())).length(); - var nextPos; - if (remainingDist == 0) { + if (remainingDist < 0.01) { if (callback) callback(); return; - } else if (remainingDist < increment.length()){ - nextPos = target;//don't overshoot + } else if (remainingDist < Math.abs(increment)){ self.object3D.rotation.x = target.x; self.object3D.rotation.y = target.y; self.object3D.rotation.z = target.z; if (callback) callback(); return; - } else { - nextPos = self.getRotation().add(increment); } -// console.log(target.clone().normalize()); - console.log(increment); - self.object3D.rotateOnAxis(target.clone().normalize(), nextPos.z); - self._incrementalRotation(increment, target, callback); + self.object3D.rotateOnAxis(axis.clone().normalize(), increment); + self._incrementalRotation(increment, target, axis, callback); }, 10); };