diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index 8acd45aa15cb286be3c9ced4038633c124a7006a..cd4779963714ad97d3b24a16fa070fb8edc07025 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -73,6 +73,12 @@ DMACell.prototype.removePart = function(index){ this.parts[index].destroy(); this.parts[index] = null; + var hasAnyParts = false; + _.each(this.parts, function(part){ + if (part) hasAnyParts = true; + }); + console.log("amanda"); + if (!hasAnyParts) window.lattice.removeCell(this); }; DMACell.prototype._buildCellMesh = function(position, zIndex){//abstract mesh representation of cell diff --git a/js/main.js b/js/main.js index b5183a15f0e3ea1a2a71ae4c67875545572ee44a..3c6162c250bf4bb3fe65659e80aad41835f27b89 100644 --- a/js/main.js +++ b/js/main.js @@ -10,15 +10,15 @@ $(function(){ //init threeJS and geometry models window.three = new ThreeModel(); - var lattice = new Lattice(); + window.lattice = new Lattice(); //setup ui - var appState = new AppState({lattice:lattice}); - new MenuWrapper({lattice:lattice, model:appState}); + var appState = new AppState({lattice:window.lattice}); + new MenuWrapper({lattice:window.lattice, model:appState}); new NavBar({model:appState}); //threeJS View - new ThreeView({model:window.three, lattice:lattice, appState:appState}); + new ThreeView({model:window.three, lattice:window.lattice, appState:appState}); lattice.addCell(new THREE.Vector3(0,0,0)); }); diff --git a/js/models/lattice.js b/js/models/lattice.js index 707f00d96076d1d359ba1f1ee257a4c28593a021..bbb3a233c1862f02d02971d5781f3e20a7dbd24a 100644 --- a/js/models/lattice.js +++ b/js/models/lattice.js @@ -150,10 +150,14 @@ Lattice = Backbone.Model.extend({ return {x:pos1.x+pos2.x, y:pos1.y+pos2.y, z:pos1.z+pos2.z}; }, - removeCell: function(object){ + removeCellFromMesh: function(object){ if (!object) return; - var cell = object.parent.myCell; + this.removeCell(object.parent.myCell); + + }, + + removeCell: function(cell){ var index = this._subtract(cell.indices, this.get("cellsMin")); var cells = this.get("cells"); cell.destroy(); diff --git a/js/threeViews/threeView.js b/js/threeViews/threeView.js index 8146283b1e61f47d4df5ca1e75e8f0b92504944a..2a2c35d7160c818eca8da2eda1bfaedf2b917937 100644 --- a/js/threeViews/threeView.js +++ b/js/threeViews/threeView.js @@ -212,7 +212,7 @@ ThreeView = Backbone.View.extend({ this.lattice.addCell(this.highlighter.geometry.vertices[0]); } else { if (this.currentIntersectedCell === this.basePlane) return; - this.lattice.removeCell(this.currentIntersectedCell); + this.lattice.removeCellFromMesh(this.currentIntersectedCell); } this._hideHighlighter(); },