From b3a43120960e1b5bdf663a76abdac9df15bdfcca Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 27 Jan 2015 20:10:21 -0500 Subject: [PATCH] removing cells works --- js/fea/dmaCell.js | 3 ++- js/models/lattice.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index a19cb7cb..0c209116 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 74103aa2..89a72c24 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(); }, -- GitLab