diff --git a/js/cam/assemblers/Assembler.js b/js/cam/assemblers/Assembler.js index c4fa5a07107b4d07d2900275517011439fa384b9..bf61b2d798d291855fd226ded289a1f5520eae25 100644 --- a/js/cam/assemblers/Assembler.js +++ b/js/cam/assemblers/Assembler.js @@ -339,11 +339,12 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' if (totalThreads > 0) return; callback(); } - var startingPos = {x:this.components.xAxis.getPosition().x, y:this.components.yAxis.getPosition().y, z:this.components.zAxis.getPosition().z}; - speed = this._normalizeSpeed(startingPos, position, new THREE.Vector3(speed, speed, speed)); - this.components.xAxis.moveTo(this._makeAxisVector(position, "x"), speed.x, sketchyCallback); - this.components.yAxis.moveTo(this._makeAxisVector(position, "y"), speed.y, sketchyCallback); - this.components.zAxis.moveTo(this._makeAxisVector(position, "z"), speed.z, sketchyCallback); + + var startingPos = this.components.zAxis.getAbsolutePosition();//get position of end effector + speed = this._normalizeSpeed(startingPos, position, new THREE.Vector3(speed, speed, speed));//todo fix this + this.components.xAxis.moveTo(position, speed.x, sketchyCallback); + this.components.frame.moveTo(position, speed.y, sketchyCallback); + this.components.zAxis.moveTo(position, speed.z, sketchyCallback); }; Assembler.prototype._normalizeSpeed = function(startingPos, position, speed){//todo make this more general diff --git a/js/cam/assemblers/Component.js b/js/cam/assemblers/Component.js index 8de54342c45abc221049edc9a110dff6da9be8a1..78f28b215d7345fce4772ffcfd9ba41703a0a416 100644 --- a/js/cam/assemblers/Component.js +++ b/js/cam/assemblers/Component.js @@ -84,6 +84,30 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ return this.object3D.position.clone(); }; + Component.prototype.getAbsolutePosition = function(){ + if (!this.parent) return this.getPosition(); + return this.parentObject.getAbsolutePosition().add(this.parentObject.applyRotation(this.getPosition())); + }; + + Component.prototype.getOrientation = function(){ + return this.object3D.quaternion.clone(); + }; + + Component.prototype.getAbsoluteOrientation = function(){ + if (!this.parent) return this.getOrientation(); + return this.getOrientation().multiply(this.parentObject.getAbsoluteOrientation());//order matters! + }; + + Component.prototype.applyRotation = function(vector){//todo local rotation? + vector.applyQuaternion(this.getAbsoluteOrientation()); + return vector; + }; + + Component.prototype.applyAbsoluteRotation = function(vector){ + vector.applyQuaternion(this.getAbsoluteOrientation()); + return vector; + }; + Component.prototype.setTranslucent = function(translucent){ if (this.stl === undefined) return; this.stl.material.transparent = translucent; @@ -145,10 +169,12 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ }; Component.prototype.moveTo = function(target, speed, callback){ + var target = this._multiplyVectors(target, this.motionVector); if (target === null){ if (callback) callback(); return; } + var currentPosition = this.getPosition(); var increment = speed/1500.0*cam.get("simSpeed"); var incrVector = target.clone().sub(currentPosition); @@ -163,6 +189,14 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ this._incrementalMove(incrVector, target, callback); }; + Component.prototype._multiplyVectors = function(target, motion){ + if (target.x === null && motion.x > 0) return null; + if (target.y === null && motion.y > 0) return null; + if (target.z === null && motion.z > 0) return null; + var target = new THREE.Vector3(target.x, target.y, target.z); + return target.multiply(motion); + }; + Component.prototype._incrementalMove = function(increment, target, callback){ var self = this; setTimeout(function(){ diff --git a/js/plists/CamPList.js b/js/plists/CamPList.js index 826ac328a3bf3f4335a7bc693131b902f5b40cef..04723a0e3be9fdaa9bc8a23e0dc866924bd33928 100644 --- a/js/plists/CamPList.js +++ b/js/plists/CamPList.js @@ -41,7 +41,6 @@ define(['three'], function(THREE){ xAxis: { name: "X Axis", rotary: false, - axisOfMotion: null, //minBound //maxBound parent: "yAxis", @@ -56,7 +55,6 @@ define(['three'], function(THREE){ frame: { name: "Y Axis", rotary: false, - axisOfMotion: null, //minBound //maxBound parent: "substrate", @@ -68,7 +66,6 @@ define(['three'], function(THREE){ zAxis: { name: "Z Axis", rotary: false, - axisOfMotion: null, //minBound //maxBound parent: "xAxis", @@ -80,7 +77,6 @@ define(['three'], function(THREE){ yAxis: { name: "Frame", rotary: false, - axisOfMotion: null, //minBound //maxBound parent: "frame", @@ -92,8 +88,7 @@ define(['three'], function(THREE){ substrate: { name: "Substrate", rotary: true, - axisOfMotion: null, - centerOfRotation: {x:10,y:10,z:0},//(5.08mm, 5.715mm) + centerOfRotation: {x:4,y:4.5,z:0},//(5.08mm, 5.715mm) //minBound //maxBound parent: null,