From 46b6372abac8f0152fdf31ca4d0bcb237b7a94fb Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Mon, 8 Jun 2015 21:51:27 -0700
Subject: [PATCH] gik parts

---
 js/cells/DMACell.js        | 3 +--
 js/cells/GIKCell.js        | 6 +++---
 js/parts/GIKPartLowPoly.js | 3 ++-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js
index e8fadf15..7ab6ea12 100644
--- a/js/cells/DMACell.js
+++ b/js/cells/DMACell.js
@@ -342,9 +342,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'],
     };
 
     DMACell.prototype.destroyParts = function(){
-        if (!this.parts && !this.cells) return;
         if (this.cells){
-            _.each(this.cells, function(cell){
+            this._loopCells(function(cell){
                 if (cell) cell.destroyParts();
             });
             return;
diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js
index 64fe2ca2..2c8bf84e 100644
--- a/js/cells/GIKCell.js
+++ b/js/cells/GIKCell.js
@@ -23,7 +23,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cubeCell'],
         return null;
     };
 
-    GIKCell.prototype._initParts = function(){
+    GIKCell.prototype._initParts = function(callback){
         if (!this.superCell) return;
         var self = this;
         var parts  = [];
@@ -34,14 +34,14 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cubeCell'],
                 for (var i=0;i<length;i++){
                     parts.push(new GIKPart(i, self));
                 }
-                self.parts = parts;
+                callback(parts);
             });
         } else {
             require(['gikPartLowPoly'], function(GIKPartLowPoly){
                 for (var i=0;i<length;i++){
                     parts.push(new GIKPartLowPoly(i, self));
                 }
-                self.parts = parts;
+                callback(parts);
             });
         }
     };
diff --git a/js/parts/GIKPartLowPoly.js b/js/parts/GIKPartLowPoly.js
index e071eb12..0aa6ae06 100644
--- a/js/parts/GIKPartLowPoly.js
+++ b/js/parts/GIKPartLowPoly.js
@@ -11,6 +11,7 @@ define(['underscore', 'three', 'gikPart', 'bin!gikPartLowPolySTL', 'bin!gikEndPa
     var unitGeoEnd = preProcessGeo(loader.parse(gikEndPartLowPoly));
 
     function preProcessGeo(geo){
+        geo.computeBoundingBox();
         geo.applyMatrix(new THREE.Matrix4().makeTranslation(-(geo.boundingBox.min.x+0.5),
             -(geo.boundingBox.min.y+geo.boundingBox.max.y)/2, -(geo.boundingBox.min.z+geo.boundingBox.max.z)/2));
         var unitScale = 1/(1.2699999809265137);
@@ -25,7 +26,7 @@ define(['underscore', 'three', 'gikPart', 'bin!gikPartLowPolySTL', 'bin!gikEndPa
     GIKPartLowPoly.prototype = Object.create(GIKPart.prototype);
 
     GIKPartLowPoly.prototype._getGeometry = function(){
-        if (this.index == 0 || this.index == this.superCell.getLength()) return unitGeoEnd;
+        if (this._isEnd()) return unitGeoEnd;
         return unitGeo;
     };
 
-- 
GitLab