From 283341e984fa940ddbbcc83e424473a7662cd308 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 15 May 2015 19:23:59 -0400 Subject: [PATCH] supercell stuff --- js/fea/DMASuperCell.js | 7 ++++++- js/models/Lattice.js | 6 +++++- js/models/LatticeOther.js | 3 +-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/js/fea/DMASuperCell.js b/js/fea/DMASuperCell.js index 84281610..3f522246 100644 --- a/js/fea/DMASuperCell.js +++ b/js/fea/DMASuperCell.js @@ -5,10 +5,11 @@ var cellMaterials = [new THREE.MeshNormalMaterial()]; -DMASuperCell = function(length, range){ +DMASuperCell = function(length, range, cells){ var shouldRotate = range.max.x == range.min.x; this.mesh = this._buildSuperCellMesh(length, shouldRotate); this.index = _.clone(range.max); + this.cells = cells; this.setScale(); dmaGlobals.three.sceneAdd(this.mesh); }; @@ -38,6 +39,10 @@ DMASuperCell.prototype.setScale = function(scale){ DMASuperCell.prototype.destroy = function(){ dmaGlobals.three.sceneRemove(this.mesh); + _.each(this.cells, function(cell){ + if (cell) cell.destroy(); + }); + this.cells = null; this.mesh = null; this.index = null; } \ No newline at end of file diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 32e8c3cd..29d32729 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -55,6 +55,7 @@ Lattice = Backbone.Model.extend({ addCellsInRange: function(range){//add a block of cells (extrude) var scale = this.get("scale"); var cells = this.get("cells"); + var newCells = []; this.checkForMatrixExpansion(cells, range.max, range.min); var cellsMin = this.get("cellsMin"); @@ -65,13 +66,16 @@ Lattice = Backbone.Model.extend({ for (var y=relativeMin.y;y<=relativeMax.y;y++){ for (var z=relativeMin.z;z<=relativeMax.z;z++){ if (!cells[x][y][z]) { - cells[x][y][z] = this.makeCellForLatticeType(this._add({x:x, y:y, z:z}, cellsMin), scale); + var cell = this.makeCellForLatticeType(this._add({x:x, y:y, z:z}, cellsMin), scale); + cells[x][y][z] = cell; + newCells.push(cell); this.set("numCells", this.get("numCells")+1); } else console.warn("already a cell there"); } } } dmaGlobals.three.render(); + return newCells; }, addCellAtIndex: function(indices, noRender, noCheck){ diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index 4eb01ccc..b8197b78 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -88,10 +88,9 @@ OtherLatticeSubclasses = { }, addSuperCell: function(range){ - var length = this.get("gikLength"); - var superCell = new DMASuperCell(length, range); var cells = this.addCellsInRange(range); + var superCell = new DMASuperCell(length, range, cells); _.each(cells, function(cell, index){ cell.setSuperCell(superCell, index, length); }); -- GitLab