diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index 96ad164fa8e316844dc44bc908ffced651f51cbf..7eb85b92740ed9e1a56610769746d4bbf91f4a67 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -91,11 +91,10 @@ }; DMACell.prototype.drawForMode = function(mode){ - position = this.position; if (mode == "cell"){ if (this.cellMesh) this._setCellMeshVisibility(true); else { - this.cellMesh = this._buildCellMesh(position); + this.cellMesh = this._buildCellMesh(this.position); window.three.sceneAdd(this.cellMesh); } } else if (mode == "parts"){ diff --git a/js/models/lattice.js b/js/models/lattice.js index 0b9c35a642d6acc22204a2ecec14e70c14956f2f..db09d1cd65c6cce9a72865fb16f5591c17a4010b 100644 --- a/js/models/lattice.js +++ b/js/models/lattice.js @@ -159,15 +159,8 @@ Lattice = Backbone.Model.extend({ }, clearCells: function(){ - _.each(this.get("cells"), function(cellLayer){ - _.each(cellLayer, function(cellCol){ - _.each(cellCol, function(cell){ - if (cell) { - cell.remove(); - } - }); - }); - + this._iterCells(this.get("cells"), function(cell){ + if (cell) cell.remove(); }); this.set("cells", this.defaults.cells); this.set("numCells", 0); @@ -176,10 +169,21 @@ Lattice = Backbone.Model.extend({ _cellModeDidChange: function(){ var mode = this.get("cellMode"); - _.each(this.get("cells"), function(cell){ - if (cell.drawForMode) cell.drawForMode(mode); + this._iterCells(this.get("cells"), function(cell){ + if (cell && cell.drawForMode) cell.drawForMode(mode); }); window.three.render(); + }, + + _iterCells: function(cells, callback, vars){ + _.each(cells, function(cellLayer){ + _.each(cellLayer, function(cellColumn){ + _.each(cellColumn, function(cell){ + callback(cell); + }); + }); + + }); } }); \ No newline at end of file