diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index 780f734107d8b601ced2a6b82e6acb98aac06201..58e8899ed2b1914f367d92b4f0642fb32d961650 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -93,7 +93,7 @@ Assembler = Backbone.Model.extend({ } else if (machineName == "oneBitBot"){ this.set("machine", new OneBitBot()); this.set("camProcess", "gcode"); - }else console.warn("selected machine not recognized"); + } else console.warn("selected machine not recognized"); }, makeProgramEdits: function(data){ diff --git a/js/cam/Machine.js b/js/cam/Machine.js index 31bd4cebc846697e186a9fe9bfdee39a0d039c2d..18a8f01e2ef5aa1acb507a3a95a31e126b45a4d5 100644 --- a/js/cam/Machine.js +++ b/js/cam/Machine.js @@ -8,6 +8,7 @@ function Machine() { this.hasStock = false; this.meshes = {}; + this.material = new THREE.MeshLambertMaterial({color:0xaaaaaa, shading: THREE.FlatShading, transparent:true, opacity:1}); this.cell = this._makeStockCell(); var self = this; this._buildMeshes(function(meshes){ @@ -15,7 +16,7 @@ function Machine() { _.each(_.values(meshes), function(mesh){ dmaGlobals.three.sceneAdd(mesh); }); - if (this.setMachinePosition) this.setMachinePosition(); + if (self.setMachinePosition) self.setMachinePosition(); self.setVisibility(); }); this.setVisibility(false); @@ -28,9 +29,20 @@ Machine.prototype.setVisibility = function(visible){ } if (visible && this.hasStock) this.cell.draw(); else this.cell.hide(); + this._setAlpha(); this._setMeshesVisiblity(visible); }; +Machine.prototype._setAlpha = function(visible){ + //todo make stock transparent + if (dmaGlobals.appState.get("currentTab") == "cam"){ + this.material.opacity = 0.5; + } else { + this.material.opacity = 1; + } + +}; + Machine.prototype._setMeshesVisiblity = function(visible){ _.each(_.values(this.meshes), function(mesh){ mesh.visible = visible; @@ -217,6 +229,7 @@ Machine.prototype.destroy = function(){ }); this.meshes = null; this.position = null; + this.material = null; }; @@ -231,12 +244,13 @@ Shopbot.prototype = Object.create(Machine.prototype); Shopbot.prototype._buildMeshes = function(callback){ var meshes = {}; + var material = this.material; (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)); 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})); + var mesh = new THREE.Mesh(geometry, material); mesh.visible = false; meshes.endEffector = mesh; callback(meshes); diff --git a/js/cam/MachineOneBit.js b/js/cam/MachineOneBit.js index b1e2765102ac1a85237421f4df22eefd840e4c60..05edf617c811a78a6b70a561277707a58b13b671 100644 --- a/js/cam/MachineOneBit.js +++ b/js/cam/MachineOneBit.js @@ -11,10 +11,8 @@ OneBitBot.prototype.setMachinePosition = function(){ if (!dmaGlobals.assembler) return; this.position = dmaGlobals.assembler.get("originPosition"); var self = this; - _.each(_.values(this.meshes), function(mesh){ - mesh.position.x += self.position.x; - mesh.position.y += self.position.y; - mesh.position.z += self.position.z; + _.each(_.values(this.meshes), function(mesh){//todo add cell? + mesh.position.set(self.position.x, self.position.y, self.position.z); }); dmaGlobals.three.render(); }; @@ -31,21 +29,21 @@ OneBitBot.prototype._buildMeshes = function(callback){ geometry.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); return geometry; } + var material = this.material; 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; + geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-10,-12.8-1.39194,0)); + meshes[name] = new THREE.Mesh(geometry, material); 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)); + geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,-2.4+1.39194,-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)); + geometry.applyMatrix(new THREE.Matrix4().makeTranslation(5,-2.4+1.39194,0)); meshPrep(geometry, "zDrive"); }); loader.load("assets/stls/oneBitBot/yAxisMount.stl", function(geometry){