From d6aba754faec33554236291be7b4bc7fa4afdd69 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Fri, 15 May 2015 21:50:10 -0400
Subject: [PATCH] end pieces look right

---
 js/fea/DMASuperCell.js |  2 +-
 js/fea/DmaCellOther.js |  3 ++-
 js/fea/DmaPart.js      | 22 ++++++++++++++++++++--
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/js/fea/DMASuperCell.js b/js/fea/DMASuperCell.js
index 2fb7ce1a..5cd6f6fb 100644
--- a/js/fea/DMASuperCell.js
+++ b/js/fea/DMASuperCell.js
@@ -43,7 +43,7 @@ DMASuperCell.prototype.setVisibility = function(visible){
 };
 
 DMASuperCell.prototype.getLength = function(){
-    return this.cells.length;
+    return this.cells.length-1;
 };
 
 DMASuperCell.prototype.destroy = function(){
diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js
index 123ceaaa..016e82f9 100644
--- a/js/fea/DmaCellOther.js
+++ b/js/fea/DmaCellOther.js
@@ -83,6 +83,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()];
     DMAGIKCell.prototype.setSuperCell = function(superCell, index){
         this.superCell = superCell;
         this.superCellIndex = index;
+        if (this.superCellIndex == this.superCell.getLength()) this.cellMesh.rotateZ(Math.PI);
         if (dmaGlobals.appState.get("cellMode")=="part") {
             this.parts = this.__initParts();
             this.draw();
@@ -91,7 +92,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()];
 
     DMAGIKCell.prototype.__initParts = function(){
         var parts  = [];
-        var isEnd = this.superCellIndex == 0 || this.superCellIndex == this.superCell.getLength()-1;
+        var isEnd = this.superCellIndex == 0 || this.superCellIndex == this.superCell.getLength();
         if (dmaGlobals.lattice.get("partType") == "lego") {
             if (isEnd) parts.push(new DMAGIKEndPart(0, this));
             else parts.push(new DMAGIKPart(0, this));
diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js
index ae66d74a..0c6f4c7f 100644
--- a/js/fea/DmaPart.js
+++ b/js/fea/DmaPart.js
@@ -268,6 +268,12 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE
     }
     DMAGIKPartLowPoly.prototype = Object.create(DMAGIKPart.prototype);
 
+    DMAGIKPartLowPoly.prototype._makeMeshForType = function(){
+        var mesh = new THREE.Mesh(unitPartGeo, partMaterial);
+        mesh.myPart = this;//need a ref back to this part
+        return mesh;
+    };
+
     self.DMAGIKPartLowPoly = DMAGIKPartLowPoly;
 
 })();
@@ -282,7 +288,7 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE
 
         unitPartGeo = geometry;
         unitPartGeo.computeBoundingBox();
-        unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(unitPartGeo.boundingBox.min.x+unitPartGeo.boundingBox.max.x)/2,
+        unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(unitPartGeo.boundingBox.min.x+0.5),
             -(unitPartGeo.boundingBox.min.y+unitPartGeo.boundingBox.max.y)/2, -(unitPartGeo.boundingBox.min.z+unitPartGeo.boundingBox.max.z)/2));
         var unitScale = 1/(1.2699999809265137);
         unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2));
@@ -294,6 +300,12 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE
     }
     DMAGIKEndPart.prototype = Object.create(DMAGIKPart.prototype);
 
+    DMAGIKEndPart.prototype._makeMeshForType = function(){
+        var mesh = new THREE.Mesh(unitPartGeo, partMaterial);
+        mesh.myPart = this;//need a ref back to this part
+        return mesh;
+    };
+
     self.DMAGIKEndPart = DMAGIKEndPart;
 
 })();
@@ -308,7 +320,7 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE
 
         unitPartGeo = geometry;
         unitPartGeo.computeBoundingBox();
-        unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(unitPartGeo.boundingBox.min.x+unitPartGeo.boundingBox.max.x)/2,
+        unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(unitPartGeo.boundingBox.min.x+0.5),
             -(unitPartGeo.boundingBox.min.y+unitPartGeo.boundingBox.max.y)/2, -(unitPartGeo.boundingBox.min.z+unitPartGeo.boundingBox.max.z)/2));
         var unitScale = 1/(1.2699999809265137);
         unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2));
@@ -320,6 +332,12 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE
     }
     DMAGIKEndPartLowPoly.prototype = Object.create(DMAGIKPart.prototype);
 
+    DMAGIKEndPartLowPoly.prototype._makeMeshForType = function(){
+        var mesh = new THREE.Mesh(unitPartGeo, partMaterial);
+        mesh.myPart = this;//need a ref back to this part
+        return mesh;
+    };
+
     self.DMAGIKEndPartLowPoly = DMAGIKEndPartLowPoly;
 
 })();
\ No newline at end of file
-- 
GitLab