diff --git a/index.html b/index.html index ba8a5e6cf4cc24b8b16ec8305388defd1dd75cec..2cbbe14cf8a964e90c237edcc1457f299a222539 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 a3597c5945888a78637090f1d5051476b9b6059e..f409cb10b7faae17b61698aa681c382d81febbe0 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 90465b9e3557a7b25796c4bae0a17a4e72249f0a..87e8da80a4474c4ef170eff0e75a762705a4dce9 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 0000000000000000000000000000000000000000..25947da95308269f37838a57223e7de1a6fe86ed --- /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