diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index e6a48f3e33bb6be5e8784ad5693ec2e4c0731683..8acd45aa15cb286be3c9ced4038633c124a7006a 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -70,6 +70,11 @@ return parts; }; + DMACell.prototype.removePart = function(index){ + this.parts[index].destroy(); + this.parts[index] = null; + }; + DMACell.prototype._buildCellMesh = function(position, zIndex){//abstract mesh representation of cell var mesh; @@ -96,12 +101,12 @@ if (mode == "cell"){ this._setCellMeshVisibility(true); _.each(this.parts, function(part){ - part.hide(); + if (part) part.hide(); }); } else if (mode == "part"){ this._setCellMeshVisibility(false); _.each(this.parts, function(part){ - part.show(); + if (part) part.show(); }); } else { console.warn("unrecognized draw mode for cell"); @@ -130,7 +135,7 @@ this.position = this._calcPosition(scale, this.indices); this._setMeshPosition(this.cellMesh, this.position); _.each(this.parts, function(part){ - part.changeScale(scale, this.position); + if (part) part.changeScale(scale, this.position); }); }; @@ -155,7 +160,7 @@ this.cellMesh = null; } _.each(this.parts, function(part){ - part.destroy(); + if (part) part.destroy(); }); this.indices = null; this.scale = null; diff --git a/js/fea/dmaPart.js b/js/fea/dmaPart.js index dae36c09f68413357cd121671e7039c688327d9d..b6c0489bf2f70e4a5c6ac3f185b2681d5b4879c7 100644 --- a/js/fea/dmaPart.js +++ b/js/fea/dmaPart.js @@ -117,7 +117,14 @@ }; DMAPart.prototype.unhighlight = function(){ - this.mesh.material.color.setRGB(0.9619657144369509, 0.6625466032079207, 0.20799727886007258); + if (this.mesh) this.mesh.material.color.setRGB(0.9619657144369509, 0.6625466032079207, 0.20799727886007258); + }; + + DMAPart.prototype.removeFromCell = function(){//send message back to parent cell to destroy this + if (this.parentCell) { + this.parentCell.removePart(this.type); + window.three.render(); + } }; DMAPart.prototype.destroy = function(){ diff --git a/js/threeViews/threeView.js b/js/threeViews/threeView.js index 25f693c464cde1c8495db62714e980d707045e5e..8146283b1e61f47d4df5ca1e75e8f0b92504944a 100644 --- a/js/threeViews/threeView.js +++ b/js/threeViews/threeView.js @@ -90,7 +90,8 @@ ThreeView = Backbone.View.extend({ _mouseUp: function(){ this.mouseIsDown = false; - this._addRemoveVoxel(!this.appState.get("deleteMode")); + if (this.currentIntersectedPart) this.currentIntersectedPart.removeFromCell(); + else this._addRemoveVoxel(!this.appState.get("deleteMode")); }, _mouseDown: function(){