diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index d688cd0f019c23b89d1252c9af7365c837a6b046..9e5842bc078500146c00f7656a2d9f1ea24c76ff 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -38,10 +38,11 @@ cellGeometry2.applyMatrix(new THREE.Matrix4().makeScale(scale, scale, scale)); } - function DMACell(mode, indices, scale) { + function DMACell(mode, indices, scale, lattice) { this.indices = indices; this.scale = scale; + this.lattice = lattice;//need ref back to lattice this.position = this._calcPosition(scale, indices); this.cellMesh = this._buildCellMesh(this.position, indices.z); window.three.sceneAdd(this.cellMesh, "cell"); @@ -77,7 +78,7 @@ _.each(this.parts, function(part){ if (part) hasAnyParts = true; }); - if (!hasAnyParts) window.lattice.removeCell(this); + if (!hasAnyParts) this.lattice.removeCell(this); }; DMACell.prototype._buildCellMesh = function(position, zIndex){//abstract mesh representation of cell @@ -170,6 +171,7 @@ this.indices = null; this.scale = null; this.position = null; + this.lattice = null; this.parts = null; }; diff --git a/js/models/lattice.js b/js/models/lattice.js index bbb3a233c1862f02d02971d5781f3e20a7dbd24a..91ac22501aa6675d79c46af5ae58224f2122fef6 100644 --- a/js/models/lattice.js +++ b/js/models/lattice.js @@ -60,12 +60,46 @@ Lattice = Backbone.Model.extend({ } var index = this._subtract(position, this.get("cellsMin")); - if (!cells[index.x][index.y][index.z]) cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), position, scale); + if (!cells[index.x][index.y][index.z]) cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), position, scale, this); else console.warn("already a cell there"); this.set("numCells", this.get("numCells")+1); window.three.render(); }, + removeCellFromMesh: function(object){ + + if (!object) return; + this.removeCell(object.parent.myCell); + + }, + + removeCell: function(cell){ + var index = this._subtract(cell.indices, this.get("cellsMin")); + var cells = this.get("cells"); + cell.destroy(); + cells[index.x][index.y][index.z] = null; + + //todo shrink cells matrix if needed + + this.set("numCells", this.get("numCells")-1); + window.three.render(); + }, + + clearCells: function(){ + this._iterCells(this.get("cells"), function(cell){ + if (cell) cell.destroy(); + }); + this.set("cells", this.defaults.cells); + this.set("cellsMax", this.defaults.cellsMax); + this.set("cellsMin", this.defaults.cellsMin); + this.set("numCells", 0); + window.three.render(); + }, + + //////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////CELLS ARRAY////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////// + _expandCellsArray: function(cells, expansion, fromFront){ _.each(_.keys(expansion), function(key){ @@ -150,36 +184,6 @@ Lattice = Backbone.Model.extend({ return {x:pos1.x+pos2.x, y:pos1.y+pos2.y, z:pos1.z+pos2.z}; }, - removeCellFromMesh: function(object){ - - if (!object) return; - this.removeCell(object.parent.myCell); - - }, - - removeCell: function(cell){ - var index = this._subtract(cell.indices, this.get("cellsMin")); - var cells = this.get("cells"); - cell.destroy(); - cells[index.x][index.y][index.z] = null; - - //todo shrink cells matrix if needed - - this.set("numCells", this.get("numCells")-1); - window.three.render(); - }, - - clearCells: function(){ - this._iterCells(this.get("cells"), function(cell){ - if (cell) cell.destroy(); - }); - this.set("cells", this.defaults.cells); - this.set("cellsMax", this.defaults.cellsMax); - this.set("cellsMin", this.defaults.cellsMin); - this.set("numCells", 0); - window.three.render(); - }, - //////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////EVENTS////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////