From ecabd88895194cd97a19474f65c2b13d4dca5047 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 24 Mar 2015 23:51:25 -0400
Subject: [PATCH] moving stuff around

---
 index.html              |  1 +
 js/cam/Assembler.js     |  2 +-
 js/cam/Machine.js       | 82 +++++++++++-----------------------------
 js/cam/MachineOneBit.js | 84 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 108 insertions(+), 61 deletions(-)
 create mode 100644 js/cam/MachineOneBit.js

diff --git a/index.html b/index.html
index ba8a5e6c..2cbbe14c 100644
--- a/index.html
+++ b/index.html
@@ -64,6 +64,7 @@
     <script src="js/models/extrudeVisualizer.js"></script>
     <script src="js/models/AppState.js"></script>
     <script src="js/cam/Machine.js"></script>
+    <script src="js/cam/MachineOneBit.js"></script>
     <script src="js/cam/Assembler.js"></script>
     <script src="js/cam/ShopbotExporter.js"></script>
     <script src="js/cam/GCodeExporter.js"></script>
diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js
index a3597c59..f409cb10 100644
--- a/js/cam/Assembler.js
+++ b/js/cam/Assembler.js
@@ -86,7 +86,7 @@ Assembler = Backbone.Model.extend({
             this.set("machine", new Shopbot());
             this.set("camProcess", "shopbot");
         } else if (machineName == "handOfGod"){
-            this.set("machine", new Shopbot());
+            this.set("machine", new God());
             this.set("camProcess", "gcode");
         } else if (machineName == "oneBitBot"){
             this.set("machine", new OneBitBot());
diff --git a/js/cam/Machine.js b/js/cam/Machine.js
index 90465b9e..87e8da80 100644
--- a/js/cam/Machine.js
+++ b/js/cam/Machine.js
@@ -244,86 +244,48 @@ Shopbot.prototype._moveAxis = function(startingPos, target, axis, speed, callbac
 
 
 ///////////////////////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////ONE BIT///////////////////////////////////////////////////
+/////////////////////////////////////GOD///////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////
 
-function OneBitBot(){
+function God(){
     Machine.call(this);
 }
-OneBitBot.prototype = Object.create(Machine.prototype);
-
-OneBitBot.prototype._buildMeshes = function(callback){
-    var meshes = [];
-    var numMeshes = 4;
-    function allLoaded(){
-        numMeshes -= 1;
-        return numMeshes <= 0;
-    }
-    function geometryScale(geometry){
-        var unitScale = 0.05;
+God.prototype = Object.create(Machine.prototype);
+
+God.prototype._buildMeshes = function(callback){
+    var meshes = {};
+    (new THREE.STLLoader()).load("assets/stls/shopbot/shopbotEndEffector.stl", function(geometry){
+        geometry.computeBoundingBox();
+        var unitScale = 1.5/geometry.boundingBox.max.y;
         geometry.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
-        return geometry;
-    }
-    function meshPrep(geometry, name){
-        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-10,-12.8,0));
+        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0,0, Math.sqrt(2)/2));
         var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({color:0xaaaaaa, shading: THREE.FlatShading}));
-        meshes[name] = mesh;
-        if (allLoaded()) callback(meshes);
-    }
-    var loader = new THREE.STLLoader();
-    loader.load("assets/stls/oneBitBot/zAxis.stl", function(geometry){
-        geometryScale(geometry);
-        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,-2.4,-0.8-1.9685));
-        meshPrep(geometry, "zAxis");
-    });
-    loader.load("assets/stls/oneBitBot/zDrive.stl", function(geometry){
-        geometryScale(geometry);
-        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,-2.4,0));
-        meshPrep(geometry, "zDrive");
-    });
-    loader.load("assets/stls/oneBitBot/yAxisMount.stl", function(geometry){
-        geometryScale(geometry);
-        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,0,0));
-        meshPrep(geometry, "yAxisMount");
-    });
-    loader.load("assets/stls/oneBitBot/basePlate.stl", function(geometry){
-        geometryScale(geometry);
-        meshPrep(geometry, "basePlate");
+        mesh.visible = false;
+        meshes.endEffector = mesh;
+        callback(meshes);
     });
 };
 
-OneBitBot.prototype._moveTo = function(x, y, z, speed, wcs, callback){
+God.prototype._moveTo = function(x, y, z, speed, wcs, callback){
     var totalThreads = 3;
     function sketchyCallback(){
         totalThreads -= 1;
         if (totalThreads > 0) return;
         callback();
     }
-    var startingPos = this.meshes["zAxis"].position.clone();
+    var startingPos = this.meshes.endEffector.position.clone();
     speed = this._normalizeSpeed(startingPos, x, y, this._reorganizeSpeed(speed));
-    this._moveXAxis(startingPos.x, x, "x", speed.x, sketchyCallback);
-    this._moveYAxis(startingPos.y, y, "y", speed.y, sketchyCallback);
-    this._moveZAxis(startingPos.z, z, "z", speed.z, sketchyCallback);
+    this._moveAxis(startingPos.x, x, "x", speed.x, sketchyCallback);
+    this._moveAxis(startingPos.y, y, "y", speed.y, sketchyCallback);
+    this._moveAxis(startingPos.z, z, "z", speed.z, sketchyCallback);
 };
 
-OneBitBot.prototype._moveXAxis = function(startingPos, target, axis, speed, callback){
-    if (target == null || target === undefined) {
-        callback();
-        return;
-    }
-    this._animateObjects([this.meshes["zAxis"], this.meshes["zDrive"], this.meshes["yAxisMount"], this.cell], axis, speed, startingPos, target, callback);
-};
-OneBitBot.prototype._moveYAxis = function(startingPos, target, axis, speed, callback){
+God.prototype._moveAxis = function(startingPos, target, axis, speed, callback){
     if (target == null || target === undefined) {
         callback();
         return;
     }
-    this._animateObjects([this.meshes["zAxis"], this.meshes["zDrive"],  this.cell], axis, speed, startingPos, target, callback);
+    this._animateObjects([this.meshes.endEffector, this.cell], axis, speed, startingPos, target, callback);
 };
-OneBitBot.prototype._moveZAxis = function(startingPos, target, axis, speed, callback){
-    if (target == null || target === undefined) {
-        callback();
-        return;
-    }
-    this._animateObjects([this.meshes["zAxis"], this.cell], axis, speed, startingPos, target, callback);
-};
\ No newline at end of file
+
+
diff --git a/js/cam/MachineOneBit.js b/js/cam/MachineOneBit.js
new file mode 100644
index 00000000..25947da9
--- /dev/null
+++ b/js/cam/MachineOneBit.js
@@ -0,0 +1,84 @@
+///////////////////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////ONE BIT///////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////
+
+function OneBitBot(){
+    Machine.call(this);
+}
+OneBitBot.prototype = Object.create(Machine.prototype);
+
+OneBitBot.prototype._buildMeshes = function(callback){
+    var meshes = [];
+    var numMeshes = 4;
+    function allLoaded(){
+        numMeshes -= 1;
+        return numMeshes <= 0;
+    }
+    function geometryScale(geometry){
+        var unitScale = 0.05;
+        geometry.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
+        return geometry;
+    }
+    function meshPrep(geometry, name){
+        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-10,-12.8,0));
+        var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({color:0xaaaaaa, shading: THREE.FlatShading}));
+        meshes[name] = mesh;
+        if (allLoaded()) callback(meshes);
+    }
+    var loader = new THREE.STLLoader();
+    loader.load("assets/stls/oneBitBot/zAxis.stl", function(geometry){
+        geometryScale(geometry);
+        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,-2.4,-0.8-1.9685));
+        meshPrep(geometry, "zAxis");
+    });
+    loader.load("assets/stls/oneBitBot/zDrive.stl", function(geometry){
+        geometryScale(geometry);
+        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,-2.4,0));
+        meshPrep(geometry, "zDrive");
+    });
+    loader.load("assets/stls/oneBitBot/yAxisMount.stl", function(geometry){
+        geometryScale(geometry);
+        geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,0,0));
+        meshPrep(geometry, "yAxisMount");
+    });
+    loader.load("assets/stls/oneBitBot/basePlate.stl", function(geometry){
+        geometryScale(geometry);
+        meshPrep(geometry, "basePlate");
+    });
+};
+
+OneBitBot.prototype._moveTo = function(x, y, z, speed, wcs, callback){
+    var totalThreads = 3;
+    function sketchyCallback(){
+        totalThreads -= 1;
+        if (totalThreads > 0) return;
+        callback();
+    }
+    var startingPos = this.meshes["zAxis"].position.clone();
+    speed = this._normalizeSpeed(startingPos, x, y, this._reorganizeSpeed(speed));
+    this._moveXAxis(startingPos.x, x, "x", speed.x, sketchyCallback);
+    this._moveYAxis(startingPos.y, y, "y", speed.y, sketchyCallback);
+    this._moveZAxis(startingPos.z, z, "z", speed.z, sketchyCallback);
+};
+
+OneBitBot.prototype._moveXAxis = function(startingPos, target, axis, speed, callback){
+    if (target == null || target === undefined) {
+        callback();
+        return;
+    }
+    this._animateObjects([this.meshes["zAxis"], this.meshes["zDrive"], this.meshes["yAxisMount"], this.cell], axis, speed, startingPos, target, callback);
+};
+OneBitBot.prototype._moveYAxis = function(startingPos, target, axis, speed, callback){
+    if (target == null || target === undefined) {
+        callback();
+        return;
+    }
+    this._animateObjects([this.meshes["zAxis"], this.meshes["zDrive"],  this.cell], axis, speed, startingPos, target, callback);
+};
+OneBitBot.prototype._moveZAxis = function(startingPos, target, axis, speed, callback){
+    if (target == null || target === undefined) {
+        callback();
+        return;
+    }
+    this._animateObjects([this.meshes["zAxis"], this.cell], axis, speed, startingPos, target, callback);
+};
\ No newline at end of file
-- 
GitLab