From 4f497dae89fabf976f711ff2ea697b72fa5355a4 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Fri, 12 Jun 2015 16:59:10 -0700
Subject: [PATCH] so close

---
 js/cells/CubeCell.js                 |  1 +
 js/cells/supercells/CompositeCell.js |  7 +------
 js/cells/supercells/DMASuperCell.js  | 12 ++++++++++--
 js/highlighter/Highlighter.js        |  2 +-
 js/lattice/LatticeBase.js            |  2 +-
 5 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/js/cells/CubeCell.js b/js/cells/CubeCell.js
index 81d38571..39db47d4 100644
--- a/js/cells/CubeCell.js
+++ b/js/cells/CubeCell.js
@@ -10,6 +10,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
 
     function CubeCell(json, superCell){
         DMACell.call(this, json, superCell);
+        console.log("init cube cell");
     }
     CubeCell.prototype = Object.create(DMACell.prototype);
 
diff --git a/js/cells/supercells/CompositeCell.js b/js/cells/supercells/CompositeCell.js
index 52ccdeef..0fa3d900 100644
--- a/js/cells/supercells/CompositeCell.js
+++ b/js/cells/supercells/CompositeCell.js
@@ -8,15 +8,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell',
 
     CompositeCell = function(json, superCell){
         DMASuperCell.call(this, json, superCell);
+        console.log("initComposite");
     };
     CompositeCell.prototype = Object.create(DMASuperCell.prototype);
 
-    CompositeCell.prototype._makeSubCellForIndex = function(json, callback){
-//        require([], function(){
-//
-//        });
-    };
-
     CompositeCell.prototype._getGeometry = function(){
         var dimensions = appState.get("superCellRange");
         var geo = new THREE.BoxGeometry(dimensions.x, dimensions.y, dimensions.z);
diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js
index ccd1b5c9..803abd71 100644
--- a/js/cells/supercells/DMASuperCell.js
+++ b/js/cells/supercells/DMASuperCell.js
@@ -38,7 +38,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
                             if (material.sparseCells[x][y][z].material) {
                                 cellMaterial = material.sparseCells[x][y][z].material;
                                 this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z), material:cellMaterial}, function(cell){
-                                    cells[x][y][z] = cell;
+                                    var index = cell.getIndex();
+                                    console.log(index);
+                                    cells[index.x][index.y][index.z] = cell;
                                 });
                             } else console.warn("no material for composite cell definition subcell");
                         }//else no cell in this spot
@@ -54,7 +56,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
     };
 
     DMASuperCell.prototype._makeSubCellForIndex = function(json, callback){
-        return null;//override in subclasses
+        var subclassFile = lattice.getCellSubclassFile();
+        if (json.material && json.material.substr(0,5) == "super") subclassFile = "compositeCell";
+        var self = this;
+        require([subclassFile], function(CellSubclass){
+            var cell = new CellSubclass(json, self);
+            if (callback) callback(cell);
+        });
     };
 
     DMASuperCell.prototype._getMeshName = function(){
diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js
index 69e39162..2a517004 100644
--- a/js/highlighter/Highlighter.js
+++ b/js/highlighter/Highlighter.js
@@ -156,7 +156,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
         addRemoveVoxel: function(shouldAdd){
             if (shouldAdd){
                 if (!this.isVisible() || !this.highlightedObject) return;
-                lattice.getUItarget().addCellAtIndex(this._getNextCellPosition());
+                lattice.getUItarget().addCellAtIndex(this._getNextCellPosition(), false, false, lattice.get("materialType"));
             } else {
                 if (!this.highlightedObject) return;
                 if (!(this.highlightedObject instanceof DMACell)) return;
diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js
index 2ee48c19..425fd3be 100644
--- a/js/lattice/LatticeBase.js
+++ b/js/lattice/LatticeBase.js
@@ -94,7 +94,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
 
         makeCellForLatticeType: function(json, callback){
             var subclassFile = this.getCellSubclassFile();
-            if (appState.lattice.get("materialType").substr(0,5) == "super") subclassFile = "compositeCell";
+            if (json.material && json.material.substr(0,5) == "super") subclassFile = "compositeCell";
             require([subclassFile], function(CellSubclass){
                 var cell = new CellSubclass(json);
                 if (callback) callback(cell);
-- 
GitLab