From e1fb1a5b735e1778fa1196657cdefb25a9bf6c29 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Wed, 28 Jan 2015 13:48:14 -0500
Subject: [PATCH] pulled scale hard coded into cell class

---
 js/fea/dmaCell.js    | 36 +++++++++++++++++++++++-------------
 js/models/lattice.js |  2 +-
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js
index f0cb89ef..96ad164f 100644
--- a/js/fea/dmaCell.js
+++ b/js/fea/dmaCell.js
@@ -7,30 +7,39 @@
 
 (function () {
 
-    var octHeight = 2*30/Math.sqrt(6);
+    var unitOctHeight = 2/Math.sqrt(6);
 
-    var cellGeometry1 = new THREE.OctahedronGeometry(30/Math.sqrt(2));
-    cellGeometry1.applyMatrix(new THREE.Matrix4().makeRotationZ(-3*Math.PI/12));
-    cellGeometry1.applyMatrix(new THREE.Matrix4().makeRotationX(Math.asin(2/Math.sqrt(2)/Math.sqrt(3))));
+    var unitCellGeo1 = new THREE.OctahedronGeometry(1/Math.sqrt(2));
+    unitCellGeo1.applyMatrix(new THREE.Matrix4().makeRotationZ(-3*Math.PI/12));
+    unitCellGeo1.applyMatrix(new THREE.Matrix4().makeRotationX(Math.asin(2/Math.sqrt(2)/Math.sqrt(3))));
 
-    var cellGeometry2 = cellGeometry1.clone();
+    var unitCellGeo2 = unitCellGeo1.clone();
 
-    cellGeometry1.applyMatrix(new THREE.Matrix4().makeTranslation(0,-30/Math.sqrt(3),octHeight/2));
-    cellGeometry2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI));
-    cellGeometry2.applyMatrix(new THREE.Matrix4().makeTranslation(0,30/Math.sqrt(3),octHeight/2));
+    unitCellGeo1.applyMatrix(new THREE.Matrix4().makeTranslation(0,-1/Math.sqrt(3),unitOctHeight/2));
+    unitCellGeo2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI));
+    unitCellGeo2.applyMatrix(new THREE.Matrix4().makeTranslation(0,1/Math.sqrt(3),unitOctHeight/2));
 
     var cellMaterials = [new THREE.MeshNormalMaterial(),
         new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})];
 
+    var cellGeometry1;
+    var cellGeometry2;
 
-    function DMACell(mode, indices) {
+    setScale(30);
 
-        this.indices = indices;
-        this.position = this._calcPositionForScale(30);
+    function setScale(scale){
+        cellGeometry1 = unitCellGeo1.clone();
+        cellGeometry1.applyMatrix(new THREE.Matrix4().makeScale(scale, scale, scale));
+        cellGeometry2 = unitCellGeo2.clone();
+        cellGeometry2.applyMatrix(new THREE.Matrix4().makeScale(scale, scale, scale));
+    }
 
-        this.parts = this._initParts();
+    function DMACell(mode, indices, scale) {
 
+        this.indices = indices;
+        this.position = this._calcPositionForScale(scale);
 
+        this.parts = this._initParts();
         this.drawForMode(mode);
     }
 
@@ -67,7 +76,7 @@
 
         var mesh;
 
-        if (Math.round(position.z/octHeight)%2==0){
+        if (this.indices.z%2==0){
             mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry1, cellMaterials);
         } else {
             mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry2, cellMaterials);
@@ -76,6 +85,7 @@
         mesh.position.y = position.y;
         mesh.position.z = position.z;
 
+
         mesh.myCell = this;//we need a reference to this instance from the mesh for intersection selection stuff
         return mesh;
     };
diff --git a/js/models/lattice.js b/js/models/lattice.js
index 77c6462c..0b9c35a6 100644
--- a/js/models/lattice.js
+++ b/js/models/lattice.js
@@ -55,7 +55,7 @@ Lattice = Backbone.Model.extend({
         }
 
         var index = this._subtract(position, this.get("cellsMin"));
-        cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), position);
+        cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), position, scale);
         this.set("numCells", this.get("numCells")+1);
         window.three.render();
     },
-- 
GitLab