From 6c8c31fd6b82257934de9b62919bdce22a7242c1 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 30 Jun 2015 16:44:11 -0700 Subject: [PATCH] parse cells --- js/cells/DMACell.js | 11 ++++++++++- js/cells/supercells/DMASuperCell.js | 13 +++++++++++++ js/lattice/Lattice.js | 23 +++++++++++++++++++++-- js/models/AppState.js | 1 + 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 4854dba9..e5ebfb45 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 045e736e..72af56be 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 e6444a22..c19814c0 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 abe5cc9c..20cc30d0 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"); -- GitLab