From a3812ceeeb16ee7d1a34fa8d5195840601c40124 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Fri, 5 Jun 2015 17:16:28 -0700
Subject: [PATCH] dma cell working again

---
 js/baseplane/BasePlane.js                     | 17 +++++-
 js/baseplane/OctaBasePlane.js                 | 12 ++--
 js/baseplane/RotEdgeOctaBasePlane.js          | 14 ++---
 js/baseplane/SquareBasePlane.js               |  9 ---
 js/cells/CubeCell.js                          | 12 ----
 js/cells/DMACell.js                           | 24 +++++++-
 js/cells/OctaEdgeCell.js                      |  2 +
 js/cells/OctaFaceCell.js                      | 10 ++--
 js/cells/OctaRotEdgeCell.js                   | 15 ++---
 js/cells/OctaVertexCell.js                    | 11 ++--
 js/cells/TruncatedCubeCell.js                 | 13 +----
 js/highlighter/Highlighter.js                 | 58 ++++++++++---------
 js/highlighter/OctaFaceHighlighter.js         |  2 +-
 ...Highlighter.js => SuperCellHighlighter.js} |  2 +-
 js/lattice/Lattice.js                         | 13 ++---
 js/lattice/OctaFaceLattice.js                 |  2 +-
 js/lattice/OctaRotEdgeLattice.js              | 13 ++---
 js/lattice/OctaVertexLattice.js               | 11 ++--
 js/main.js                                    |  2 +-
 js/three/ThreeView.js                         |  2 +
 20 files changed, 121 insertions(+), 123 deletions(-)
 rename js/highlighter/{GIKHighlighter.js => SuperCellHighlighter.js} (95%)

diff --git a/js/baseplane/BasePlane.js b/js/baseplane/BasePlane.js
index a5d587e9..97435485 100644
--- a/js/baseplane/BasePlane.js
+++ b/js/baseplane/BasePlane.js
@@ -36,7 +36,8 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'],
 
         updateXYSeparation: function(xySep) {},
 
-        getOrientation: function(){
+        getAbsoluteOrientation: function(){
+            console.log("baseplane orientation");
             return new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), Math.PI);
         },
 
@@ -45,8 +46,18 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'],
             three.render();
         },
 
-        getIndex: function(){
-            return this.index.clone();
+        getAbsoluteIndex: function(){
+            return this.highligherIndex.clone();
+        },
+
+        calcHighlighterParams: function(face, point, index){
+            point.z = 0;//todo this doesn't generalize when baseplane moves
+            if (!index || index === undefined) index = lattice.getIndexForPosition(point);
+            index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane
+            var position = lattice.getPositionForIndex(index);
+            position.z += lattice.zScale()/2;
+            this.highligherIndex = index;
+            return {direction: new THREE.Vector3(0,0,1), position:position};
         },
 
         _removeMesh: function(){
diff --git a/js/baseplane/OctaBasePlane.js b/js/baseplane/OctaBasePlane.js
index bc1ca132..2278bd67 100644
--- a/js/baseplane/OctaBasePlane.js
+++ b/js/baseplane/OctaBasePlane.js
@@ -89,15 +89,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three',
             geometry.verticesNeedUpdate = true;
         },
 
-        calcHighlighterPosition: function(face, position){
-            position.z = 0;
-            var index = lattice.getIndexForPosition(position);
+        calcHighlighterParams: function(face, point){
+            point.z = 0;
+            var index = lattice.getIndexForPosition(point);
             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 = lattice.getPositionForIndex(index);
-            position.z += lattice.zScale()/2;
-            this.index = new THREE.Vector3(index.x, index.y, index.z);//todo no!!!
-            return {index: index, direction: new THREE.Vector3(0,0,1), position:position};
+            return BasePlane.prototype.calcHighlighterParams.call(this, face, point, index);
         }
     });
 });
\ No newline at end of file
diff --git a/js/baseplane/RotEdgeOctaBasePlane.js b/js/baseplane/RotEdgeOctaBasePlane.js
index 2c59ce3d..7c4b4413 100644
--- a/js/baseplane/RotEdgeOctaBasePlane.js
+++ b/js/baseplane/RotEdgeOctaBasePlane.js
@@ -8,14 +8,12 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three',
 
     return SquareBasePlane.extend({
 
-        calcHighlighterPosition: function(face, position){
-            var index = lattice.getIndexForPosition(position);
-            index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane
-            var latticePosition = lattice.getPositionForIndex(index);
-            latticePosition.x -= lattice.xScale()/2;
-            latticePosition.y -= lattice.yScale()/2;
-            this.index = new THREE.Vector3(index.x, index.y, index.z);//todo no!!!
-            return {index: index, direction: new THREE.Vector3(0,0,1), position:latticePosition};
+        calcHighlighterParams: function(face, point){
+            var params = SquareBasePlane.prototype.calcHighlighterParams.call(this, face, point);
+            params.position.x -= lattice.xScale()/2;
+            params.position.y -= lattice.yScale()/2;
+            params.position.z -= lattice.zScale()/2;
+            return params;
         }
     });
 });
\ No newline at end of file
diff --git a/js/baseplane/SquareBasePlane.js b/js/baseplane/SquareBasePlane.js
index 00021c20..29bdbc73 100644
--- a/js/baseplane/SquareBasePlane.js
+++ b/js/baseplane/SquareBasePlane.js
@@ -45,14 +45,5 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three',
             });
             three.render();
         },
-
-        calcHighlighterPosition: function(face, position){
-            var index = lattice.getIndexForPosition(position);
-            index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane
-            var latticePosition = lattice.getPositionForIndex(index);
-            latticePosition.z += lattice.zScale()/2;
-            this.index = new THREE.Vector3(index.x, index.y, index.z);//todo no!!!
-            return {index: index, direction: new THREE.Vector3(0,0,1), position:latticePosition};
-        }
     });
 });
diff --git a/js/cells/CubeCell.js b/js/cells/CubeCell.js
index f66b17bb..ff808f38 100644
--- a/js/cells/CubeCell.js
+++ b/js/cells/CubeCell.js
@@ -25,17 +25,5 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
         return wireframe;
     };
 
-    CubeCell.prototype.calcHighlighterPosition = function(face){
-
-        var direction = face.normal.clone().applyEuler(this.object3D.rotation);
-        var position = this.getPosition();
-        var scale = this.xScale();
-        _.each(_.keys(position), function(key){
-            position[key] += direction[key]*scale/2;
-        });
-        return {index: _.clone(this.index), direction:direction, position:position};
-    };
-
     return CubeCell;
-
 });
\ No newline at end of file
diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js
index 86243b29..80c7fe83 100644
--- a/js/cells/DMACell.js
+++ b/js/cells/DMACell.js
@@ -20,7 +20,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'],
 
         if (this.superCell) this.superCell.addChildren(this.object3D);//add as child of supercell
 
-        if (superCell === undefined) {
+        if (!superCell || superCell === undefined) {
             if (this.index) {
                 three.sceneAdd(this.object3D);
                 if (!this.cells) three.addCell(this.object3D.children[0]);//add mesh as highlightable object
@@ -63,7 +63,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'],
         var geometry = this._getGeometry();
 
         var meshes = [];
-        var mesh = new THREE.Mesh(geometry, this._getMaterial());
+        var mesh = new THREE.Mesh(geometry, this.getMaterial());
         mesh.name = this._getMeshName();
         meshes.push(mesh);
 
@@ -141,6 +141,24 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'],
 
 
 
+    //highlighting
+
+    DMACell.prototype.calcHighlighterParams = function(face, point){//this works for rectalinear, override in subclasses
+        var direction = face.normal.clone().applyQuaternion(this.getAbsoluteOrientation());
+        var position = this.getAbsolutePosition();
+        var self  = this;
+        _.each(_.keys(position), function(key){
+            position[key] += direction[key]*self.axisScale(key)/2;
+        });
+        return {direction:direction, position:position};
+    };
+
+
+
+
+
+
+
     //children
 
     DMACell.prototype.addChildren = function(children, object3D){//accepts an array or a single mesh
@@ -177,7 +195,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'],
         this.setMode(mode);
     };
 
-    DMACell.prototype._getMaterial = function(){
+    DMACell.prototype.getMaterial = function(){
         if (!this.material) console.warn("no material for cell");
         var materialClass = lattice.get("materialClass");
         if (!globals.materials[materialClass]) {
diff --git a/js/cells/OctaEdgeCell.js b/js/cells/OctaEdgeCell.js
index 98278401..ae89f4e8 100644
--- a/js/cells/OctaEdgeCell.js
+++ b/js/cells/OctaEdgeCell.js
@@ -17,6 +17,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'octaFaceCel
 
     //todo fix this
     OctaEdgeCell.prototype.calcHighlighterPosition = function(face){
+//        var direction = face.normal.clone().applyQuaternion(this.getAbsoluteOrientation());
+//        var position = this.getAbsolutePosition();
         var direction = face.normal.clone();
         direction.applyQuaternion(this.mesh.quaternion);
         var position = this.getPosition();
diff --git a/js/cells/OctaFaceCell.js b/js/cells/OctaFaceCell.js
index db85c640..0b6fe324 100644
--- a/js/cells/OctaFaceCell.js
+++ b/js/cells/OctaFaceCell.js
@@ -33,12 +33,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
         return parts;
     };
 
-    OctaFaceCell.prototype.calcHighlighterPosition = function(face){
-        if (face.normal.z<0.99) return {index: _.clone(this.index)};//only highlight horizontal faces
-        var direction = face.normal;
-        var position = this.getPosition();
-        position.z += face.normal.z*this.zScale()/2;
-        return {index:_.clone(this.index), direction:direction, position:position};
+    OctaFaceCell.prototype.calcHighlighterParams = function(face){
+        var direction = face.normal.clone().applyQuaternion(this.getAbsoluteOrientation());
+        if (direction.z<0.99) return null;//only highlight horizontal faces
+        return DMACell.prototype.calcHighlighterParams.call(this, face);
     };
 
     return OctaFaceCell;
diff --git a/js/cells/OctaRotEdgeCell.js b/js/cells/OctaRotEdgeCell.js
index 28aee99a..8348f974 100644
--- a/js/cells/OctaRotEdgeCell.js
+++ b/js/cells/OctaRotEdgeCell.js
@@ -7,6 +7,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
     function(_, THREE, three, lattice, appState, DMACell){
 
     var unitGeo = new THREE.OctahedronGeometry(1/Math.sqrt(2));
+    unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4));
 
     function OctaRotEdgeCell(index, superCell){
         DMACell.call(this, index, superCell);
@@ -31,14 +32,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
         return unitGeo;
     };
 
-    OctaRotEdgeCell.prototype._rotateCell = function(object3D){
-        object3D.rotation.set(0, 0, Math.PI/4);
-        return object3D;
-    };
-
-    OctaRotEdgeCell.prototype.calcHighlighterPosition = function(face, point){
+    OctaRotEdgeCell.prototype.calcHighlighterParams = function(face, point){
 
-        var position = this.getPosition();
+//        point.applyQuaternion(this.getAbsoluteOrientation());
+        var position = this.getAbsolutePosition();
         var direction = new THREE.Vector3(0,0,0);
         var rad = this.xScale()*Math.sqrt(2)/6;
 
@@ -90,8 +87,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
             position.y += direction.y*this.yScale()/2;
         }
 
-        return {index: _.clone(this.index), direction:direction, position:position};
+        return {direction:direction, position:position};
     };
 
-    return OctaVertexCell;
+    return OctaRotEdgeCell;
 });
\ No newline at end of file
diff --git a/js/cells/OctaVertexCell.js b/js/cells/OctaVertexCell.js
index 6231d0c6..e60050e9 100644
--- a/js/cells/OctaVertexCell.js
+++ b/js/cells/OctaVertexCell.js
@@ -6,18 +6,21 @@
 define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
     function(_, THREE, three, lattice, appState, DMACell){
 
+    var unitGeo = new THREE.OctahedronGeometry(1/Math.sqrt(2));
+
     function OctaVertexCell(index, superCell){
         DMACell.call(this, index, superCell);
     }
     OctaVertexCell.prototype = Object.create(DMACell.prototype);
 
     OctaVertexCell.prototype._getGeometry = function(){
-        return unitVertexOcta;
+        return unitGeo;
     };
 
-    OctaVertexCell.prototype.calcHighlighterPosition = function(face, point){
+    OctaVertexCell.prototype.calcHighlighterParams = function(face, point){
 
-        var position = this.getPosition();
+//        point.applyQuaternion(this.getAbsoluteOrientation());
+        var position = this.getAbsolutePosition();
         var direction = null;
 
         var xScale = this.xScale();
@@ -50,7 +53,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
             }
         }
 
-        return {index: _.clone(this.index), direction:direction, position:position};
+        return {direction:direction, position:position};
     };
 
     return OctaVertexCell;
diff --git a/js/cells/TruncatedCubeCell.js b/js/cells/TruncatedCubeCell.js
index c623bde0..ee4addcf 100644
--- a/js/cells/TruncatedCubeCell.js
+++ b/js/cells/TruncatedCubeCell.js
@@ -66,17 +66,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
         return wireframe;
     };
 
-    TruncatedCubeCell.prototype.calcHighlighterPosition = function(face){
-
+    TruncatedCubeCell.prototype.calcHighlighterParams = function(face){
         var direction = face.normal;
-        if (!(Math.abs(direction.x)>0.9 || Math.abs(direction.y)>0.9 || Math.abs(direction.z)>0.9)) return {index: _.clone(this.index)};
-
-        var position = this.getPosition();
-        var scale = this.zScale();
-        _.each(_.keys(position), function(key){
-            position[key] += direction[key]*scale/2;
-        });
-        return {index: _.clone(this.index), direction:direction, position:position};
+        if (!(Math.abs(direction.x)>0.9 || Math.abs(direction.y)>0.9 || Math.abs(direction.z)>0.9)) return null;
+        return DMACell.prototype.calcHighlighterParams.call(this, face);
     };
 
     return TruncatedCubeCell;
diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js
index a2a86e75..bd7d570d 100644
--- a/js/highlighter/Highlighter.js
+++ b/js/highlighter/Highlighter.js
@@ -17,11 +17,9 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
             var geometry = this._makeGeometry();
             this.mesh = new THREE.Mesh(geometry,
                 new THREE.MeshBasicMaterial({
-    //                side:THREE.DoubleSide,
                     transparent:true,
                     opacity:0.4,
                     color:0xffffff
-    //                vertexColors:THREE.FaceColors
                 }));
 
             three.sceneAdd(this.mesh);
@@ -32,9 +30,10 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
             this.listenTo(appState, "change:superCellIndex", this._superCellParamDidChange);
         },
 
-        ///////////////////////////////////////////////////////////////////////////////////
-        /////////////////////////////VISIBILITY////////////////////////////////////////////
-        ///////////////////////////////////////////////////////////////////////////////////
+
+
+
+        //visibility
 
         hide: function(){
             this._setVisibility(false);
@@ -64,47 +63,51 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
             this.hide();
         },
 
+
+
+
+        //highlight
+
         highlight: function(intersection){
             if (!intersection.object) return;
-            var highlighted = intersection.object;
-            if (!(highlighted.parent instanceof THREE.Scene)) highlighted = highlighted.parent;//cell mesh parent is object3d
-            if (!highlighted.myParent) {
+            var highlighted = intersection.object.parent;//cell mesh parent is object3d
+            if (!highlighted.myParent) {//myParent is cell instance
                 console.warn("no parent for highlighted object");
                 return;
             }
 
             this.highlightedObject = highlighted.myParent;
 
-            var highlightedPos = this.highlightedObject.calcHighlighterPosition(intersection.face, intersection.point);
-            this.position = highlightedPos.position;//todo used just for gik
-            if (!highlightedPos.direction) {//may be hovering over a face that we shouldn't highlight
+            var params = this.highlightedObject.calcHighlighterParams(intersection.face, intersection.point);
+            if (!params) {//may be hovering over a face that we shouldn't highlight
                 this.hide();
                 return;
             }
-            this.direction = highlightedPos.direction;
-            this._setPosition(highlightedPos.position, this.direction);//position of center point
-            this._setRotation(this.direction);
+            this.position = params.position;
+            this.direction = params.direction;
+            this._setPosition(params.position, params.direction);//position of center point
+            this._setRotation(params.direction);
 
             this.show(true);
         },
 
-        ///////////////////////////////////////////////////////////////////////////////////
-        /////////////////////////////POSITION/SCALE////////////////////////////////////////
-        ///////////////////////////////////////////////////////////////////////////////////
+
+
+
+        //position/scale/rotation
 
         getHighlightedObjectPosition: function(){//origin selection
             if (this.highlightedObject instanceof DMACell) {
                 var position = this.highlightedObject.getPosition();
-                return {
-                    x:parseFloat(position.x.toFixed(4)),
-                    y:parseFloat(position.y.toFixed(4)),
-                    z:parseFloat(position.z.toFixed(4))
-                };
+                return new THREE.Vector3(parseFloat(position.x.toFixed(4)),
+                    parseFloat(position.y.toFixed(4)),
+                    parseFloat(position.z.toFixed(4)));
             }
+            console.warn("highlighted object is not a DMACell")
             return null;
         },
 
-        _setPosition: function(position){
+        _setPosition: function(position, direction){
             this.mesh.position.set(position.x, position.y, position.z);
         },
 
@@ -116,12 +119,13 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
             if (this.updateGikLength) this.updateGikLength();
         },
 
-        ///////////////////////////////////////////////////////////////////////////////////
-        /////////////////////////////ADD REMOVE////////////////////////////////////////////
-        ///////////////////////////////////////////////////////////////////////////////////
+
+
+
+        //add/remove cells
 
         _getNextCellPosition: function(){//add direction vector to current index
-            var newIndex = _.clone(this.highlightedObject.getIndex());
+            var newIndex = this.highlightedObject.getAbsoluteIndex().clone();
             var direction = this.direction;
             _.each(_.keys(newIndex), function(key){
                 newIndex[key] = Math.round(newIndex[key] + direction[key]);
diff --git a/js/highlighter/OctaFaceHighlighter.js b/js/highlighter/OctaFaceHighlighter.js
index 826c4a48..67e0289b 100644
--- a/js/highlighter/OctaFaceHighlighter.js
+++ b/js/highlighter/OctaFaceHighlighter.js
@@ -17,7 +17,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
         },
 
         _setRotation: function(){
-            this.mesh.rotation.set(0,0,(this.highlightedObject.getIndex().z+1)%2*Math.PI);
+            this.mesh.rotation.set(0,0,(this.highlightedObject.getAbsoluteIndex().z+1)%2*Math.PI);
         }
 
     });
diff --git a/js/highlighter/GIKHighlighter.js b/js/highlighter/SuperCellHighlighter.js
similarity index 95%
rename from js/highlighter/GIKHighlighter.js
rename to js/highlighter/SuperCellHighlighter.js
index e674fedf..02818430 100644
--- a/js/highlighter/GIKHighlighter.js
+++ b/js/highlighter/SuperCellHighlighter.js
@@ -8,7 +8,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
     return Highlighter.extend({
 
         _makeGeometry: function(){
-            return new THREE.BoxGeometry(1,1,lattice.zScale(0));
+            return new THREE.BoxGeometry(lattice.xScale(0),lattice.yScale(0),lattice.zScale(0));
         },
 
         _setPosition: function(position, direction){
diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js
index e7e01f56..050a20fc 100644
--- a/js/lattice/Lattice.js
+++ b/js/lattice/Lattice.js
@@ -95,15 +95,14 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
         },
 
         _indexForPosition: function(absPosition){
-            var position = {};
-            position.x = Math.floor(absPosition.x/this.xScale());
-            position.y = Math.floor(absPosition.y/this.yScale());
-            position.z = Math.floor(absPosition.z/this.zScale());
-            return position;
+            return new THREE.Vector3(
+                Math.floor(absPosition.x/this.xScale()),
+                Math.floor(absPosition.y/this.yScale()),
+                Math.floor(absPosition.z/this.zScale()));
         },
 
         _positionForIndex: function(index){
-            var position = _.clone(index);
+            var position = index.clone();
             position.x = (position.x+0.5)*this.xScale();
             position.y = (position.y+0.5)*this.yScale();
             position.z = (position.z+0.5)*this.zScale();
@@ -133,7 +132,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
 
         clearCells: function(){
             this._iterCells(this.sparseCells, function(cell){//send destroy to top level
-                if (cell && cell.destroy) cell.destroy();
+                if (cell) cell.destroy();
             });
             three.removeAllCells();//todo add flag in cell destroy to avoid redundancy here
             this.cells = [[[null]]];
diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js
index 58203379..0927d3e6 100644
--- a/js/lattice/OctaFaceLattice.js
+++ b/js/lattice/OctaFaceLattice.js
@@ -25,7 +25,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
         },
 
         getPositionForIndex: function(index){
-            var position = _.clone(index);
+            var position = index.clone();
             position.x = (position.x+1/2);
             position.y = position.y*this.yScale()+1/Math.sqrt(3)/2;
             position.z = (position.z+0.5)*this.zScale();
diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js
index 7b5d359b..88ab171e 100644
--- a/js/lattice/OctaRotEdgeLattice.js
+++ b/js/lattice/OctaRotEdgeLattice.js
@@ -8,7 +8,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
     var OctaRotEdgeLattice = {
 
         _initLatticeType: function(){
-            require(['rotEdgeOctaBasePlane'], function(RotEdgeOctaBasePlane){
+            require(['rotEdgeOctaBaseplane'], function(RotEdgeOctaBasePlane){
                 globals.basePlane = new RotEdgeOctaBasePlane();
             });
             require(['defaultHighlighter'], function(DefaultHighlighter){
@@ -17,15 +17,14 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
         },
 
         getIndexForPosition: function(absPosition){
-            var position = {};
-            position.x = Math.floor(absPosition.x/this.xScale()+0.5);
-            position.y = Math.floor(absPosition.y/this.yScale()+0.5);
-            position.z = Math.floor(absPosition.z/this.zScale()+0.5);
-            return position;
+            return new THREE.Vector3(
+                Math.floor(absPosition.x/this.xScale()+0.5),
+                Math.floor(absPosition.y/this.yScale()+0.5),
+                Math.floor(absPosition.z/this.zScale())+0.5);
         },
 
         getPositionForIndex: function(index){
-            var position = _.clone(index);
+            var position = index.clone();
             if (index.z %2 != 0){
                 position.x += 0.5;
                 position.y += 0.5;
diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js
index babdeecf..76764cb9 100644
--- a/js/lattice/OctaVertexLattice.js
+++ b/js/lattice/OctaVertexLattice.js
@@ -17,15 +17,14 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th
         },
 
         getIndexForPosition: function(absPosition){
-            var position = {};
-            position.x = Math.floor(absPosition.x/this.xScale()+0.5);
-            position.y = Math.floor(absPosition.y/this.yScale()+0.5);
-            position.z = Math.floor(absPosition.z/this.zScale()+0.5);
-            return position;
+            return new THREE.Vector3(
+                Math.floor(absPosition.x/this.xScale()+0.5),
+                Math.floor(absPosition.y/this.yScale()+0.5),
+                Math.floor(absPosition.z/this.zScale())+0.5);
         },
 
         getPositionForIndex: function(index){
-            var position = _.clone(index);
+            var position = index.clone();
             position.x = (position.x)*this.xScale();
             position.y = (position.y)*this.yScale();
             position.z = (position.z+0.5)*this.zScale();
diff --git a/js/main.js b/js/main.js
index a4687101..2cde81ed 100644
--- a/js/main.js
+++ b/js/main.js
@@ -46,7 +46,7 @@ require.config({
         highlighter: 'highlighter/Highlighter',
         defaultHighlighter: 'highlighter/DefaultHighlighter',
         cubeHighlighter: 'highlighter/CubeHighlighter',
-        gikHighlighter: 'highlighter/GIKHighlighter',
+        superCellHighlighter: 'highlighter/SuperCellHighlighter',
         octaFaceHighlighter: 'highlighter/OctaFaceHighlighter',
         truncatedCubeHighlighter: 'highlighter/TruncatedCubeHighlighter',
 
diff --git a/js/three/ThreeView.js b/js/three/ThreeView.js
index a75b5de4..14b3ee06 100644
--- a/js/three/ThreeView.js
+++ b/js/three/ThreeView.js
@@ -83,6 +83,8 @@ define(['underscore', 'backbone', 'three', 'appState', 'globals', 'orbitControls
 
         _mouseMoved: function(e){
 
+            if (!globals.highlighter) return;//highlighter not loaded yet
+
             if (!appState.get("highlightMode") && !(appState.get("manualSelectOrigin"))) return;
 
             if (this.mouseIsDown && !this.controls.noRotate) {//in the middle of a camera move
-- 
GitLab