From 0be743056a0e37c3ab33d09ee88117bad99afbd7 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Mon, 25 May 2015 19:55:47 -0700
Subject: [PATCH] removing scale from lattice view

---
 js/menus/LatticeMenuView.js  |  8 -------
 js/models/BasePlane.js       | 46 +++++++++++-------------------------
 js/models/LatticeOcta.js     | 20 ++++++++--------
 js/models/LatticeOther.js    | 16 ++++++-------
 js/threeViews/Highlighter.js | 20 ++++------------
 5 files changed, 36 insertions(+), 74 deletions(-)

diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js
index b14639e2..69ff6e80 100644
--- a/js/menus/LatticeMenuView.js
+++ b/js/menus/LatticeMenuView.js
@@ -9,7 +9,6 @@ LatticeMenuView = Backbone.View.extend({
 
     events: {
         "change #latticeScale":                         "_changeScale",
-        "slide #latticeMenuScaleSlider":                "_sliderDidSlide",
         "slideStop #latticeMenuScaleSlider":            "_changeScaleSlider"
     },
 
@@ -28,13 +27,6 @@ LatticeMenuView = Backbone.View.extend({
         globals.lattice.set("scale", val);
     },
 
-    _sliderDidSlide: function(e){
-        var scale = $(e.target)[0].value;
-        globals.lattice.previewScaleChange(scale);//does not trigger lattice change event - no rerendering of ui
-        $("#latticeScale").val(scale);
-        globals.three.render();
-    },
-
     _changeScaleSlider: function(e){
         globals.lattice.set("scale", $(e.target)[0].value);
     },
diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js
index 1e2f6d9b..f739c894 100644
--- a/js/models/BasePlane.js
+++ b/js/models/BasePlane.js
@@ -11,32 +11,21 @@ BasePlane = Backbone.Model.extend({
         dimX: 100,
         dimY: 100,
         material: new THREE.MeshBasicMaterial({color:0x000000, transparent:true, opacity:0.2, wireframe:true})
-//        currentScene: "default",
-//        allScenes: {default:"Default", "mars":"Mars"}
     },
 
-    initialize: function(options){
+    initialize: function(){
 
         //bind events
-//        this.listenTo(this, "change:currentScene", this._renderForCurrentScene);
         this.listenTo(this, "change:zIndex", this._renderZIndexChange);
 
         //draw mesh
         this.set("mesh", this._makeBasePlaneMesh());
-        this.updateScale(options.scale);
 
         var self = this;
         _.each(this.get("mesh"), function(mesh){
             globals.three.sceneAdd(mesh, self._checkIsHighlightable(mesh));
         });
         globals.three.render();
-
-    },
-
-    updateScale: function(scale){
-        _.each(this.get("mesh"), function(mesh){
-            mesh.scale.set(scale, scale, scale);
-        });
     },
 
     updateXYSeparation: function(xySep) {},
@@ -45,24 +34,15 @@ BasePlane = Backbone.Model.extend({
         return new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), Math.PI);
     },
 
-    getType: function(){
-        return "octa";
-    },
-
-//    _renderForCurrentScene: function(){
-//    },
-
     ///////////////////////////////////////////////////////////////////////////////////
     //////////////////////HIGHLIGHTER FUNCTIONALITY////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////////////
 
     _checkIsHighlightable: function(mesh){
-        if (mesh.type == "Mesh") return "basePlane";
+        if (mesh.type == "Mesh") return "basePlane";//don't try to highlight wireframe parts of baseplane
         return null;
     },
 
-    //subclasses handle getHighlighterVertices
-
     ///////////////////////////////////////////////////////////////////////////////////
     ////////////////////////////////////////DEALLOC////////////////////////////////////
     ///////////////////////////////////////////////////////////////////////////////////
@@ -129,12 +109,15 @@ OctaBasePlane = BasePlane.extend({
         return [mesh];
     },
 
+    getType: function(){//todo hack from freeform octa, get rid of this eventually
+        return "octa";
+    },
+
     _renderZIndexChange: function(){
         var zIndex = this.get("zIndex");
-        var scale = globals.lattice.get("scale");
-        var xScale = globals.lattice.xScale(scale);
-        var yScale = globals.lattice.yScale(scale);
-        var zScale = globals.lattice.zScale(scale);
+        var xScale = globals.lattice.xScale(1);
+        var yScale = globals.lattice.yScale(1);
+        var zScale = globals.lattice.zScale(1);
 
         _.each(this.get("mesh"), function(mesh){
             mesh.position.set(xScale*(zIndex%2)/2, -yScale/3*(zIndex%2), zIndex*zScale);
@@ -182,12 +165,11 @@ OctaBasePlane = BasePlane.extend({
     },
 
     calcHighlighterPosition: function(face, position){
-
         var index = globals.lattice.getIndexForPosition(position);
         if (index.z%2 != 0) index.x -= 1;
         index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane
         var position = globals.lattice.getPositionForIndex(index);
-        position.z += globals.lattice.zScale()/2;
+        position.z += globals.lattice.zScale(1)/2;
         return {index: index, direction: new THREE.Vector3(0,0,1), position:position};
     }
 
@@ -232,7 +214,7 @@ SquareBasePlane = BasePlane.extend({
 
     _renderZIndexChange: function(){
         var zIndex = this.get("zIndex");
-        var zScale = globals.lattice.zScale();
+        var zScale = globals.lattice.zScale(1);
         _.each(this.get("mesh"), function(mesh){
             mesh.position.set(0, 0, zIndex*zScale);
         });
@@ -243,7 +225,7 @@ SquareBasePlane = BasePlane.extend({
         var index = globals.lattice.getIndexForPosition(position);
         index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane
         var latticePosition = globals.lattice.getPositionForIndex(index);
-        latticePosition.z += globals.lattice.zScale()/2;
+        latticePosition.z += globals.lattice.zScale(1)/2;
         return {index: index, direction: new THREE.Vector3(0,0,1), position:latticePosition};
     }
 
@@ -261,8 +243,8 @@ RotEdgeOctaBasePlane = SquareBasePlane.extend({
         var index = globals.lattice.getIndexForPosition(position);
         index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane
         var latticePosition = globals.lattice.getPositionForIndex(index);
-        latticePosition.x -= globals.lattice.xScale()/2;
-        latticePosition.y -= globals.lattice.yScale()/2;
+        latticePosition.x -= globals.lattice.xScale(1)/2;
+        latticePosition.y -= globals.lattice.yScale(1)/2;
         return {index: index, direction: new THREE.Vector3(0,0,1), position:latticePosition};
     }
 });
\ No newline at end of file
diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js
index 6ecfd29b..9e50fca2 100644
--- a/js/models/LatticeOcta.js
+++ b/js/models/LatticeOcta.js
@@ -12,8 +12,8 @@ OctaLatticeSubclasses = {
     OctaFaceLattice: {
 
         _initLatticeType: function(){
-            globals.basePlane = new OctaBasePlane({scale:this.get("scale")});
-            globals.highlighter = new OctaFaceHighlighter({scale:this.get("scale")});
+            globals.basePlane = new OctaBasePlane();
+            globals.highlighter = new OctaFaceHighlighter();
         },
 
         getIndexForPosition: function(absPosition){
@@ -73,8 +73,8 @@ OctaLatticeSubclasses = {
     OctaFreeFormFaceLattice: {
 
         _initLatticeType: function(){
-            globals.basePlane = new OctaBasePlane({scale:this.get("scale")});
-            globals.highlighter = new OctaFreeFormHighlighter({scale:this.get("scale")});
+            globals.basePlane = new OctaBasePlane();
+            globals.highlighter = new OctaFreeFormHighlighter();
 
             this.set("freeformCellType", "octa");
 
@@ -151,8 +151,8 @@ OctaLatticeSubclasses = {
     OctaEdgeLattice: {
 
         _initLatticeType: function(){
-            globals.basePlane = new OctaBasePlane({scale:this.get("scale")});
-            globals.highlighter = new OctaEdgeHighlighter({scale:this.get("scale")});
+            globals.basePlane = new OctaBasePlane();
+            globals.highlighter = new OctaEdgeHighlighter();
 
         },
 
@@ -210,8 +210,8 @@ OctaLatticeSubclasses = {
     OctaRotEdgeLattice: {
 
         _initLatticeType: function(){
-            globals.basePlane = new RotEdgeOctaBasePlane({scale:this.get("scale")});
-            globals.highlighter = new OctaVertexHighlighter({scale:this.get("scale")});
+            globals.basePlane = new RotEdgeOctaBasePlane();
+            globals.highlighter = new OctaVertexHighlighter();
         },
 
         getIndexForPosition: function(absPosition){
@@ -273,8 +273,8 @@ OctaLatticeSubclasses = {
     OctaVertexLattice: {
 
         _initLatticeType: function(){
-            globals.basePlane = new SquareBasePlane({scale:this.get("scale")});
-            globals.highlighter = new OctaVertexHighlighter({scale:this.get("scale")});
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new OctaVertexHighlighter();
         },
 
         getIndexForPosition: function(absPosition){
diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js
index f1500d42..2ddd5851 100644
--- a/js/models/LatticeOther.js
+++ b/js/models/LatticeOther.js
@@ -12,8 +12,8 @@ OtherLatticeSubclasses = {
     CubeLattice: {
 
         _initLatticeType: function(){
-            globals.basePlane = new SquareBasePlane({scale:this.get("scale")});
-            globals.highlighter = new CubeHighlighter({scale:this.get("scale")});
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new CubeHighlighter();
         },
 
         getIndexForPosition: function(absPosition){
@@ -57,8 +57,8 @@ OtherLatticeSubclasses = {
     GIKLattice: {
 
         _initLatticeType: function(){
-            globals.basePlane = new SquareBasePlane({scale:this.get("scale")});
-            globals.highlighter = new GIKHighlighter({scale:this.get("scale")});
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new GIKHighlighter();
         },
 
         getIndexForPosition: function(absPosition){
@@ -160,8 +160,8 @@ OtherLatticeSubclasses = {
     TruncatedCubeLattice: {
 
         _initLatticeType: function(){
-            globals.basePlane = new SquareBasePlane({scale:this.get("scale")});
-            globals.highlighter = new TruncatedCubeHighlighter({scale:this.get("scale")});
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new TruncatedCubeHighlighter();
         },
 
         getIndexForPosition: function(absPosition){
@@ -207,8 +207,8 @@ OtherLatticeSubclasses = {
     KelvinLattice: {
 
         _initLatticeType: function(){
-            globals.basePlane = new SquareBasePlane({scale:this.get("scale")});
-            globals.highlighter = new TruncatedCubeHighlighter({scale:this.get("scale")});
+            globals.basePlane = new SquareBasePlane();
+            globals.highlighter = new TruncatedCubeHighlighter();
         },
 
         getIndexForPosition: function(absPosition){
diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js
index 742fef51..6900c66f 100644
--- a/js/threeViews/Highlighter.js
+++ b/js/threeViews/Highlighter.js
@@ -9,7 +9,7 @@ Highlighter = Backbone.View.extend({
     index: null,
     direction: null,
 
-    initialize: function(options){
+    initialize: function(){
 
         var geometry = this._makeGeometry();
         this.mesh = new THREE.Mesh(geometry,
@@ -22,7 +22,6 @@ Highlighter = Backbone.View.extend({
             }));
 
         globals.three.sceneAdd(this.mesh, null);
-        this.updateScale(options.scale);
         this.hide();
 
         //bind events
@@ -98,10 +97,6 @@ Highlighter = Backbone.View.extend({
         return null;
     },
 
-    updateScale: function(scale){
-        this.mesh.scale.set(scale, scale, scale);
-    },
-
     _setPosition: function(position){
         this.mesh.position.set(position.x, position.y, position.z);
     },
@@ -210,29 +205,22 @@ CubeHighlighter = Highlighter.extend({
 
 GIKHighlighter = Highlighter.extend({
 
-    updateScale: function(scale){
-        this.mesh.scale.set(globals.lattice.get("gikLength")*scale, scale, scale);
-    },
-
     _makeGeometry: function(){
         return new THREE.BoxGeometry(1,1,1);
     },
 
     _setPosition: function(position, direction){
-        var scale = this.mesh.scale.z/2;
-        this.mesh.position.set(position.x+scale*direction.x, position.y+scale*direction.y, position.z+globals.lattice.zScale()/2*direction.z);
+        this.mesh.position.set(position.x+direction.x, position.y+direction.y, position.z+globals.lattice.zScale(1)/2*direction.z);
     },
 
     _setRotation: function(direction, index){
         var superCellIndex = globals.appState.get("superCellIndex");
-        var scale  = this.mesh.scale.z;
         if ((index.z%2 == 0 && Math.abs(direction.z) > 0.9) || (index.z%2 != 0 && Math.abs(direction.z) < 0.1)) this.mesh.rotation.set(0, 0, Math.PI/2);
         else this.mesh.rotation.set(0,0,0);
-        this.mesh.translateX(-this.mesh.scale.x/2+scale/2+scale*superCellIndex);
+        this.mesh.translateX(superCellIndex);
     },
 
-    updateGikLength: function(scale){
-        this.updateScale(scale);
+    updateGikLength: function(){
         if (!this.direction) return;
         this._setPosition(this.position, this.direction);//position of center point
         this._setRotation(this.direction, this.index);
-- 
GitLab