From 6baa005ebb3ff012b6308783cd22349d38446993 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Mon, 8 Jun 2015 16:26:55 -0700
Subject: [PATCH] vo part

---
 js/cells/OctaRotEdgeCell.js        | 26 +++++++-------
 js/main.js                         |  7 +++-
 js/parts/OctaEdgeVoxPart.js        | 56 ++++++------------------------
 js/parts/OctaEdgeVoxPartLowPoly.js | 24 +++++++++++++
 js/parts/OctaFaceTriPart.js        |  3 +-
 5 files changed, 56 insertions(+), 60 deletions(-)
 create mode 100644 js/parts/OctaEdgeVoxPartLowPoly.js

diff --git a/js/cells/OctaRotEdgeCell.js b/js/cells/OctaRotEdgeCell.js
index 8348f974..c41c0a56 100644
--- a/js/cells/OctaRotEdgeCell.js
+++ b/js/cells/OctaRotEdgeCell.js
@@ -14,18 +14,20 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
     }
     OctaRotEdgeCell.prototype = Object.create(DMACell.prototype);
 
-    OctaRotEdgeCell.prototype._initParts = function(){
-        var type = globals.lattice.get("partType");
-        var newParts = [];
-        if (type == "vox"){
-            newParts.push(new OctaEdgeVoxPart(0, this));
-        } else if (type == "voxLowPoly"){
-            newParts.push(new OctaEdgeVoxPartLowPoly(0, this));
-        } else {
-            console.warn("part type " + type + " not recognized");
-            return;
-        }
-        return newParts;
+    OctaRotEdgeCell.prototype._initParts = function(callback){
+        var self = this;
+        var type = lattice.get("partType");
+        if (type == "vox") type = "octaEdgeVoxPart";
+        else if (type == "voxLowPoly") type = "octaEdgeVoxPartLowPoly";
+        else console.warn("no part type " + type);
+
+        require([type], function(OctaEdgeVoxPart){
+            var parts  = [];
+            for (var i=0;i<3;i++){
+                parts.push(new OctaEdgeVoxPart(0, self));
+            }
+            callback(parts);
+        });
     };
 
     OctaRotEdgeCell.prototype._getGeometry = function(){
diff --git a/js/main.js b/js/main.js
index 747616d7..353360c4 100644
--- a/js/main.js
+++ b/js/main.js
@@ -71,6 +71,8 @@ require.config({
         //parts
         part: 'parts/DMAPart',
         octaFaceTriPart: 'parts/OctaFaceTriPart',
+        octaEdgeVoxPart: 'parts/OctaEdgeVoxPart',
+        octaEdgeVoxPartLowPoly: 'parts/OctaEdgeVoxPartLowPoly',
 
         //materials
         materials: 'materials/DMAMaterials',
@@ -96,7 +98,10 @@ require.config({
         sendMenu: 'menus/SendMenuView',
 
         //stls
-        octaFaceTrianglePart: '../assets/stls/parts/trianglePart.stl'
+        bin: 'bin',
+        octaFaceTrianglePartSTL: '../assets/stls/parts/trianglePart.stl',
+        octaEdgeVoxPartSTL: '../assets/stls/parts/edgeVoxPart.stl',
+        octaEdgeVoxPartLowPolySTL: '../assets/stls/parts/edgeVoxPartLowPoly.stl'
 
     },
 
diff --git a/js/parts/OctaEdgeVoxPart.js b/js/parts/OctaEdgeVoxPart.js
index 792e1c5c..96965123 100644
--- a/js/parts/OctaEdgeVoxPart.js
+++ b/js/parts/OctaEdgeVoxPart.js
@@ -2,22 +2,16 @@
  * Created by aghassaei on 5/26/15.
  */
 
+define(['underscore', 'three', 'part', 'bin!octaEdgeVoxPartSTL', 'stlLoader'], function(_, THREE, DMAPart, voxPart){
 
-(function () {
-
-    var unitPartGeo;
-
-    //import part geometry
     var loader = new THREE.STLLoader();
-    loader.load("assets/stls/parts/edgeVoxPart.stl", function(geometry){
-
-        unitPartGeo = geometry;
-        unitPartGeo.computeBoundingBox();
-        var unitScale = 0.706/unitPartGeo.boundingBox.max.y;
-        unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
-        unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationY(Math.PI));
-        unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,0.09));
-    });
+    var unitGeo = loader.parse(voxPart);
+    unitGeo.computeBoundingBox();
+    var unitScale = 0.706/unitGeo.boundingBox.max.y;
+    unitGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
+    unitGeo.applyMatrix(new THREE.Matrix4().makeRotationY(Math.PI));
+    unitGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,0.09));
+    unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4));
 
     function OctaEdgeVoxPart(type, parent){
         DMAPart.call(this, type, parent);
@@ -25,36 +19,8 @@
     OctaEdgeVoxPart.prototype = Object.create(DMAPart.prototype);
 
     OctaEdgeVoxPart.prototype._getGeometry = function(){
-        return unitPartGeo;
-    };
-
-    self.OctaEdgeVoxPart = OctaEdgeVoxPart;
-
-})();
-
-(function () {
-
-    var unitPartGeo;
-
-    //import part geometry
-    var loader = new THREE.STLLoader();
-    loader.load("assets/stls/parts/edgeVoxPartLowPoly.stl", function(geometry){
-
-        unitPartGeo = geometry;
-        unitPartGeo.computeBoundingBox();
-        var unitScale = 0.706/unitPartGeo.boundingBox.max.y;
-        unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
-    });
-
-    function OctaEdgeVoxPartLowPoly(type, parent){
-        DMAPart.call(this, type, parent);
-    }
-    OctaEdgeVoxPartLowPoly.prototype = Object.create(DMAPart.prototype);
-
-    OctaEdgeVoxPartLowPoly.prototype._getGeometry = function(){
-        return unitPartGeo;
+        return unitGeo;
     };
 
-    self.OctaEdgeVoxPartLowPoly = OctaEdgeVoxPartLowPoly;
-
-})();
\ No newline at end of file
+    return OctaEdgeVoxPart;
+});
\ No newline at end of file
diff --git a/js/parts/OctaEdgeVoxPartLowPoly.js b/js/parts/OctaEdgeVoxPartLowPoly.js
new file mode 100644
index 00000000..8f6d785a
--- /dev/null
+++ b/js/parts/OctaEdgeVoxPartLowPoly.js
@@ -0,0 +1,24 @@
+/**
+ * Created by aghassaei on 6/8/15.
+ */
+
+
+define(['underscore', 'three', 'part', 'bin!octaEdgeVoxPartLowPolySTL', 'stlLoader'], function(_, THREE, DMAPart, voxLowPoly){
+
+    var loader = new THREE.STLLoader();
+    var unitGeo = loader.parse(voxLowPoly);
+    unitGeo.computeBoundingBox();
+    var unitScale = 0.706/unitGeo.boundingBox.max.y;
+    unitGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
+
+    function OctaEdgeVoxPartLowPoly(type, parent){
+        DMAPart.call(this, type, parent);
+    }
+    OctaEdgeVoxPartLowPoly.prototype = Object.create(DMAPart.prototype);
+
+    OctaEdgeVoxPartLowPoly.prototype._getGeometry = function(){
+        return unitGeo;
+    };
+
+    return OctaEdgeVoxPartLowPoly;
+});
\ No newline at end of file
diff --git a/js/parts/OctaFaceTriPart.js b/js/parts/OctaFaceTriPart.js
index 339f49ad..b9c63dc7 100644
--- a/js/parts/OctaFaceTriPart.js
+++ b/js/parts/OctaFaceTriPart.js
@@ -3,7 +3,7 @@
  */
 
 
-define(['underscore', 'three', 'part', 'bin!octaFaceTrianglePart', 'stlLoader'], function(_, THREE, DMAPart, trianglePart){
+define(['underscore', 'three', 'part', 'bin!octaFaceTrianglePartSTL', 'stlLoader'], function(_, THREE, DMAPart, trianglePart){
 
     var loader = new THREE.STLLoader();
     var unitGeo = loader.parse(trianglePart);
@@ -19,7 +19,6 @@ define(['underscore', 'three', 'part', 'bin!octaFaceTrianglePart', 'stlLoader'],
     OctaFaceTriPart.prototype = Object.create(DMAPart.prototype);
 
     OctaFaceTriPart.prototype._getGeometry = function(){
-        if (!unitGeo || unitGeo === undefined) console.warn("geo not loaded yet");
         return unitGeo;
     };
 
-- 
GitLab