diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index cd46d909423ac511fb55a22ed2fcf02d8e1e3663..8c0fa893323a9bda3461712d4868af6d4dfe22a0 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -40,7 +40,7 @@ Assembler = Backbone.Model.extend({ initialize: function(options){ - this.set("machine", new Machine()); + this.set("machine", new Shopbot()); _.bindAll(this, "postProcess"); @@ -73,6 +73,7 @@ Assembler = Backbone.Model.extend({ this.listenTo(dmaGlobals.appState, "change:stockSimulationPlaying", this._stockSimulation); this.listenTo(options.lattice, "change:partType", this._updatePartType); + this.listenTo(options.lattice, "change:cellType change:connectionType", this._updateCellType); this.listenTo(options.appState, "change:cellMode", this._updateCellMode); this._initOriginAndStock(options.lattice); @@ -92,8 +93,14 @@ Assembler = Backbone.Model.extend({ return (currentTab == "cam" || currentTab == "animate" || currentTab == "send"); }, + _updateCellType: function(){ + this.get("machine").updateCellType(); + this.get("machine").setVisibility(this._isVisible()); + }, + _updatePartType: function(){ - if (this._isVisible()) this.get("machine").updatePartType(); + this.get("machine").updatePartType(); + this.get("machine").setVisibility(this._isVisible()); }, _updateCellMode: function(){ diff --git a/js/cam/Machine.js b/js/cam/Machine.js index 6a0c47219f57947b21219beffb108a2d48935157..c7a5c29aba9ee9cf0b66effc0f76a8d0b341358e 100644 --- a/js/cam/Machine.js +++ b/js/cam/Machine.js @@ -7,34 +7,37 @@ function Machine() { this.hasStock = false; - //load end effector geo - var loader = new THREE.STLLoader(); + this.meshes = []; var self = this; - loader.load("data/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})); - self.endEffector = mesh; - dmaGlobals.three.sceneAdd(mesh); - mesh.visible = false; + this._buildMeshes(function(meshes){ + self.meshes = meshes; + _.each(meshes, function(mesh){ + dmaGlobals.three.sceneAdd(mesh); + }); }); - - this.cell = new DMARotatedEdgeCell(null); + this.cell = this._makeStockCell(); this.setVisibility(false); - } Machine.prototype.setVisibility = function(visible){ - if (visible){ - if (this.hasStock) this.cell.draw(); - if (this.endEffector) this.endEffector.visible = true; - } else { - this.cell.hide(); - if (this.endEffector) this.endEffector.visible = false; - } + if (visible && this.hasStock) this.cell.draw(); + else this.cell.hide(); + this._setMeshesVisiblity(visible); +}; + +Machine.prototype._setMeshesVisiblity = function(visible){ + _.each(this.meshes, function(mesh){ + mesh.visible = visible; + }); +}; + +Machine.prototype._makeStockCell = function(){ + return dmaGlobals.lattice.makeCellForLatticeType(null, dmaGlobals.lattice.get("scale")); +}; + +Machine.prototype.updateCellType = function(){ + if (this.cell) this.cell.destroy(); + this.cell = this._makeStockCell(); }; Machine.prototype.updatePartType = function(){ @@ -56,23 +59,58 @@ Machine.prototype.releaseStock = function(index){ Machine.prototype.pause = function(){ }; -Machine.prototype.moveTo = function(x, y, z, speed, wcs, callback){ +Machine.prototype.destroy = function(){ + this.cell.destroy(); + _.each(this.meshes, function(mesh){ + dmaGlobals.three.sceneRemove(mesh); + mesh = null; + }); + this.meshes = null; +}; + + + +/////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////SHOPBOT/////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////// + +function Shopbot(){ + Machine.call(this); +} +Shopbot.prototype = Object.create(Machine.prototype); + +Shopbot.prototype._buildMeshes = function(callback){ + var meshes = []; + (new THREE.STLLoader()).load("data/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})); + mesh.visible = false; + meshes.push(mesh); + callback(meshes); + }); +}; + +Shopbot.prototype.moveTo = function(x, y, z, speed, wcs, callback){ var self = this; + var endEffector = this.meshes[0]; setTimeout( function() { //reaching a little deep here, might want to find a better solution if (x != "") { var nextX = parseFloat(x)+wcs.x; - self.endEffector.position.x = nextX; + endEffector.position.x = nextX; self.cell.cellMesh.position.x = nextX; } if (y != "") { var nextY = parseFloat(y)+wcs.y; - self.endEffector.position.y = nextY; + endEffector.position.y = nextY; self.cell.cellMesh.position.y = nextY; } if (z != "") { var nextZ = parseFloat(z)+wcs.z; - self.endEffector.position.z = nextZ; + endEffector.position.z = nextZ; self.cell.cellMesh.position.z = nextZ; } self.cell.updateForScale(); @@ -80,4 +118,15 @@ Machine.prototype.moveTo = function(x, y, z, speed, wcs, callback){ return callback(); }, 500/dmaGlobals.assembler.get("simSpeed")); -}; \ No newline at end of file +}; + + + +/////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////ONE BIT/////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////// + +function OneBitBot(){ + Machine.call(this); +} +OneBitBot.prototype = Object.create(Machine.prototype); \ No newline at end of file diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index c3ce1fd712c227cfd74877110dec3e4c05cb561e..2d24cb3d38a8c665e3c5e19a8b968d333f22a163 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -15,14 +15,17 @@ function DMACell(indices, scale, cellMode, partType) { this.cellMesh = this._buildCellMesh(); this._doMeshTransformations(this.cellMesh);//some cell types require transformations - var sceneType = "cell"; - if (!indices) sceneType = null; - dmaGlobals.three.sceneAdd(this.cellMesh,sceneType); + dmaGlobals.three.sceneAdd(this.cellMesh,this._sceneType(indices)); this.draw(scale, cellMode, partType); } +DMACell.prototype._sceneType = function(indices){ + if (!indices || indices == null || indices === undefined) return null; + return "cell"; +}; + DMACell.prototype.draw = function(scale, cellMode, partType){ if (!scale) scale = dmaGlobals.lattice.get("scale"); if (!cellMode) cellMode = dmaGlobals.appState.get("cellMode"); @@ -221,7 +224,7 @@ DMACell.prototype._initBeams = function(nodes, faces){ DMACell.prototype.destroy = function(){ if (this.cellMesh) { - dmaGlobals.three.sceneRemove(this.cellMesh, "cell"); + dmaGlobals.three.sceneRemove(this.cellMesh, this._sceneType(this.indices)); this.cellMesh.myParent = null; // this.cellMesh.dispose(); // geometry.dispose(); diff --git a/js/fea/DmaCellOcta.js b/js/fea/DmaCellOcta.js index ad1b048961f76248a0f7e92f92b0a72b8bc0e967..ad3a8bd6eada2814c3747e0708fbdf1f0833c9ff 100644 --- a/js/fea/DmaCellOcta.js +++ b/js/fea/DmaCellOcta.js @@ -26,7 +26,7 @@ DMAFaceOctaCell.prototype._initParts = function(){ }; DMAFaceOctaCell.prototype._doMeshTransformations = function(mesh){ - if (this.indices.z%2!=0) mesh.rotation.set(0, 0, Math.PI); + if (this.indices && this.indices.z%2!=0) mesh.rotation.set(0, 0, Math.PI); }; DMAFaceOctaCell.prototype._getGeometry = function(){ diff --git a/js/main.js b/js/main.js index bade9628c1c9aea127305b7491c1be32908cf1d1..68addf3c52b47a73757838055b9d3b56eb1389c3 100644 --- a/js/main.js +++ b/js/main.js @@ -15,12 +15,10 @@ $(function(){ dmaGlobals.three = new ThreeModel(); dmaGlobals.appState = new AppState(); dmaGlobals.lattice = new Lattice({appState: dmaGlobals.appState}); - dmaGlobals.assembler = new Assembler({appState: dmaGlobals.appState, lattice:dmaGlobals.lattice}); - dmaGlobals.lattice.delayedInit(); + dmaGlobals.assembler = new Assembler({appState: dmaGlobals.appState, lattice:dmaGlobals.lattice}); dmaGlobals.appState.delayedInit(); - //ui new NavBar({model:dmaGlobals.appState}); new Ribbon({model:dmaGlobals.appState});