diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 4854dba909044865176400eee89978e92c1aec2c..e5ebfb454ccebfb5c4a3494a3cb008f3486afd6b 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -381,10 +381,19 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' + //parse + DMACell.prototype.addToDenseArray = function(cellsArray, min){ + var index = this.getAbsoluteIndex().sub(min); + cellsArray[index.x][index.y][index.z] = this; + }; + + + + //destroy - DMACell.prototype.destroy = function(){ + DMACell.prototype.destroy = function(){//todo remove reference from lattice.cells this.destroyParts(); if (this.object3D) { if (this.superCell) this.superCell.removeChildren(this.object3D); diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 045e736eb93f690e6641e5e42c46f67dc16b5f11..72af56beed0188527075670f15d5ee1aec5847e8 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -109,6 +109,19 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], + //parse + DMASuperCell.prototype.addToDenseArray = function(cellsArray, min){ + this._loopCells(function(cell){ + if (cell) cell.addToDenseArray(cellsArray, min); + }); + }; + + + + + + + DMASuperCell.prototype._loopCells = function(callback){ var cells = this.cells; if (!cells || cells === undefined) return; diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index e6444a228f1779029bb9d98a4409531d1cf54334..c19814c0ae47be174ba6f5bf446a4e9727dd338c 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -130,16 +130,35 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //cells array _parseSparseCell: function(){ - this.cells = [[[null]]]; + if (this.get("numCells") == 0) { console.warn("no cells in assembly"); + this.cells = [[[null]]]; return; } var bounds = this.calculateBoundingBox(); var size = bounds.max.sub(bounds.min); - console.log(size); + //create array of nulls + var cells = []; + for (var x=0;x<size.x;x++){ + cells.push([]); + for (var y=0;y<size.y;y++){ + cells[x].push([]); + for (var z=0;z<size.z;z++){ + cells[x][y].push(null); + } + } + } + + var min = this.get("cellsMin").sub(bounds.min); + this._loopCells(this.sparseCells, function(cell){ + if (!cell) return; + cell.addToDenseArray(cells, min); + }); + + this.cells = cells; }, diff --git a/js/models/AppState.js b/js/models/AppState.js index abe5cc9c082bf590fe715b04a513c16b29899103..20cc30d05fa5db294d44d8c2247bf608676de065 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -110,6 +110,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'], fu this.set("highlighterIsVisible", false); } else if (navSelection == "navAssemble"){ } + }, _materialTypeChanged: function(){ var materialType = this.get("materialType");