diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index a19cb7cb30b65a6be95da8fc247d263fc7c309f9..0c209116ee6e44c020442be7c7abaa8fb0b7ebb2 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -23,9 +23,10 @@ new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; - function DMACell(mode, position) { + function DMACell(mode, position, indices) { this.position = position; + this.indices = indices; this.parts = this._initParts(); diff --git a/js/models/lattice.js b/js/models/lattice.js index 74103aa24d5c4d4b6a069b75db41776dd37f4be5..89a72c2449a23cf61ed99503009447a35c51dbec 100644 --- a/js/models/lattice.js +++ b/js/models/lattice.js @@ -55,7 +55,7 @@ Lattice = Backbone.Model.extend({ } var index = this._subtract(position, this.get("cellsMin")); - cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), absPosition); + cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), absPosition, position); window.three.render(); }, @@ -144,15 +144,15 @@ Lattice = Backbone.Model.extend({ }, removeCell: function(object){ - var cells = this.get("cells"); + var cell = object.parent.myCell; - var index = cells.indexOf(cell); - if (index == -1) {//I think this is happening when two intersection/remove calls are done on the same cell before the next render loop finished - console.warn("problem locating cell in cell array"); - return; - } - cells.splice(index, 1); + var relativeIndex = this._subtract(cell.indices, this.get("cellsMin")); + var cells = this.get("cells"); + cells[relativeIndex.x][relativeIndex.y][relativeIndex.z] = null; cell.remove(); + + //todo shrink cells matrix if needed + this.set("numCells", cells.length); window.three.render(); },