From 511ba92fa134f2e342591b00d300acd4280c90cf Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Thu, 5 Feb 2015 02:18:23 -0500
Subject: [PATCH] baseplane subclass

---
 js/menus/LatticeMenuView.js |   4 ++
 js/models/BasePlane.js      | 115 ++++++++++++++++++++++++------------
 js/models/Lattice.js        |   7 +--
 3 files changed, 85 insertions(+), 41 deletions(-)

diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js
index f224be3f..495d51f2 100644
--- a/js/menus/LatticeMenuView.js
+++ b/js/menus/LatticeMenuView.js
@@ -132,6 +132,10 @@ LatticeMenuView = Backbone.View.extend({
             </div><br/><br/>\
         Scale:&nbsp;&nbsp;<input id="scaleSlider" data-slider-id="ex1Slider" type="text" data-slider-min="1" data-slider-max="100" data-slider-step="0.1" data-slider-value="<%= scale %>"/>\
         <br/><input id="latticeScale" value="<%= scale %>" placeholder="enter scale" class="form-control" type="text"><br/>\
+        <label class="checkbox" for="invertGeo">\
+            <input type="checkbox" checked="checked" value="" id="invertGeo" data-toggle="checkbox" class="custom-checkbox"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\
+            Show Inverse Geometry\
+        </label>\
         Num Cells:&nbsp;&nbsp;<%= numCells %><br/>\
         <br/>\
         <a href="#" id="latticeMenuClearCells" class=" btn btn-block btn-lg btn-default">Clear All Cells</a><br/>\
diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js
index 25384084..a27e9a00 100644
--- a/js/models/BasePlane.js
+++ b/js/models/BasePlane.js
@@ -28,12 +28,6 @@ BasePlane = Backbone.Model.extend({
 
     },
 
-    updateColSeparation: function(colSep){
-        var geometry = this.get("mesh").geometry;
-        geometry.vertices = this._calcOctaFaceVertices(colSep);
-        geometry.verticesNeedUpdate = true;
-    },
-
     _renderZIndexChange: function(){
         var zIndex = this.get("zIndex");
         var scale = this.get("mesh").scale.z;
@@ -55,26 +49,39 @@ BasePlane = Backbone.Model.extend({
         this.get("mesh").scale.set(scale, scale, scale);
     },
 
-    _makeBasePlaneMesh: function(cellType, connectionType){
-        if (cellType == "cube"){
-            return this._createGridMesh();
-        } else if (cellType == "octa"){
-            if (connectionType == "face"){
-                return this._createOctaFaceMesh();
-            } else if (connectionType == "edge"){
-                return this._createOctaFaceMesh();
-            } else if (connectionType == "vertex"){
-                return this._createOctaFaceMesh();
-            }
-        }
+    _showMesh: function(){
+        window.three.sceneAdd(this.get("mesh"), "basePlane");
+        window.three.render();
     },
 
-     _createOctaFaceMesh: function(colSep){
+    _removeMesh: function(){
+        window.three.sceneRemove(this.get("mesh"), "basePlane");
+    },
+
+    destroy: function(){
+        this.set("zIndex", null);
+        this.set("mesh", null);
+        this.set("material", null);
+        this.set("unitGeometry", null);
+        this.set("dimX", null);
+        this.set("dimY", null);
+    }
+
+});
+
+
+
+///////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////OCTA FACE/////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////
+
+OctaBasePlane = BasePlane.extend({
+
+    _makeBasePlaneMesh: function(){
 
-        colSep = colSep || 0.2;
         var geometry = new THREE.Geometry();
         geometry.dynamic = true;
-        geometry.vertices = this._calcOctaFaceVertices(colSep);
+        geometry.vertices = this._calcOctaFaceVertices(0.0);
         var faces = geometry.faces;
 
         var dimX = this.get("dimX");
@@ -134,26 +141,60 @@ BasePlane = Backbone.Model.extend({
         return vertices;
     },
 
-    _createGridMesh: function(){
-        return this._createOctaFaceMesh();
-    },
+    updateColSeparation: function(colSep){
+        var geometry = this.get("mesh").geometry;
+        geometry.vertices = this._calcOctaFaceVertices(colSep);
+        geometry.verticesNeedUpdate = true;
+    }
 
-    _showMesh: function(){
-        window.three.sceneAdd(this.get("mesh"), "basePlane");
-        window.three.render();
-    },
+});
 
-    _removeMesh: function(){
-        window.three.sceneRemove(this.get("mesh"), "basePlane");
+///////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////CUBE GRID/////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////
+
+SquareBasePlane = BasePlane.extend({
+
+    _makeBasePlaneMesh: function(){
+
+        var geometry = new THREE.Geometry();
+        geometry.vertices = this._calcVertices();
+        var faces = geometry.faces;
+
+        var dimX = this.get("dimX");
+        var dimY = this.get("dimY");
+
+        var currentOffset = 0;
+        for (var j=-dimX;j<=dimX;j++){
+            for (var i=-dimY;i<=dimY;i++){
+
+                currentOffset++;
+                if (j == -dimX || i == -dimY) continue;
+
+//                faces.push(new THREE.Face3(currentOffset, currentOffset-1, currentOffset-dimY));
+
+            }
+
+        }
+
+        geometry.computeFaceNormals();
+        return new THREE.Mesh(geometry, this.get("material"));
     },
 
-    destroy: function(){
-        this.set("zIndex", null);
-        this.set("mesh", null);
-        this.set("material", null);
-        this.set("unitGeometry", null);
-        this.set("dimX", null);
-        this.set("dimY", null);
+    _calcVertices: function(){
+
+        var vertices = [];
+        var dimX = this.get("dimX");
+        var dimY = this.get("dimY");
+
+        for (var j=-dimX;j<=dimX;j++){
+            for (var i=-dimY;i<=dimY;i++){
+
+                vertices.push(new THREE.Vector3(i,j,0));
+            }
+
+        }
+        return vertices;
     }
 
 });
\ No newline at end of file
diff --git a/js/models/Lattice.js b/js/models/Lattice.js
index 228d1246..a6c5b211 100644
--- a/js/models/Lattice.js
+++ b/js/models/Lattice.js
@@ -44,10 +44,6 @@ Lattice = Backbone.Model.extend({
         this.listenTo(this, "change:scale", this._scaleDidChange);
         this.listenTo(this, "change:cellType change:connectionType", this._changeLatticeStructure);
 
-        this.set("basePlane", new BasePlane({cellType:this.get("cellType"),
-            connectionType:this.get("connectionType"),
-            scale:this.get("scale")}));
-
         this._initialize();//call subclass init
     },
 
@@ -262,6 +258,9 @@ OctaFaceLattice = Lattice.extend({
         //bind events
         this.listenTo(this, "change:columnSeparation", this._changeColSeparation);
 
+        this.set("basePlane", new OctaBasePlane({cellType:this.get("cellType"),
+            connectionType:this.get("connectionType"),
+            scale:this.get("scale")}));
         this.set("columnSeparation", 0.0);
     },
 
-- 
GitLab