From df5e5dd21d97608a92983644bbc0ac8b570fc588 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 3 Feb 2015 23:01:38 -0500
Subject: [PATCH] highlighter working again

---
 js/threeViews/Highlighter.js | 25 ++++++++++++++-----------
 js/threeViews/ThreeView.js   |  2 +-
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js
index 2780500a..6cd8d0e3 100644
--- a/js/threeViews/Highlighter.js
+++ b/js/threeViews/Highlighter.js
@@ -28,15 +28,18 @@ Highlighter = Backbone.View.extend({
     },
 
     hide: function(){
-        if (this.mesh.visible){
-            this.mesh.visible = false;
-            window.three.render();
-        }
+        this._setVisibility(false);
+    },
+
+    show: function(forceRender){
+        this._setVisibility(true, forceRender);
     },
 
-    show: function(){
-        if (!this.mesh.visible){
-            this.mesh.visible = true;
+    _setVisibility: function(visible, forceRender){
+        if (this.isVisible() != visible){
+            this.mesh.visible = visible;
+            window.three.render();
+        } else if (forceRender){
             window.three.render();
         }
     },
@@ -60,7 +63,7 @@ Highlighter = Backbone.View.extend({
 
         //update highlighter
         this._highlightFace(object, face);
-        this.show();
+        this.show(true);
     },
 
 
@@ -85,12 +88,12 @@ Highlighter = Backbone.View.extend({
     _calcNewHighlighterVertices: function(object, face){
         //the vertices don't include the position transformation applied to cell.  Add these to create highlighter vertices
         var vertices = object.geometry.vertices;
-        var position = (new THREE.Vector3()).setFromMatrixPosition(object.matrixWorld);
-        var newVertices =  [(new THREE.Vector3()).addVectors(vertices[face.a], position),
-            (new THREE.Vector3()).addVectors(vertices[face.b], position), (new THREE.Vector3()).addVectors(vertices[face.c], position)];
+        var newVertices = [vertices[face.a].clone(), vertices[face.b].clone(), vertices[face.c].clone()];
         var scale = this.model.get("scale");
+        var position = (new THREE.Vector3()).setFromMatrixPosition(object.matrixWorld);
         _.each(newVertices, function(vertex){//apply scale
             vertex.multiplyScalar(scale);
+            vertex.add(position);
         });
         return newVertices;
     },
diff --git a/js/threeViews/ThreeView.js b/js/threeViews/ThreeView.js
index ec1e7f0e..b53303ab 100644
--- a/js/threeViews/ThreeView.js
+++ b/js/threeViews/ThreeView.js
@@ -93,7 +93,7 @@ ThreeView = Backbone.View.extend({
 
         //check if we're intersecting anything
         var cellIntersections = this.mouseProjection.intersectObjects(this.model.cells.concat(this.model.basePlane), true);
-        if (cellIntersections.length == 0) {
+        if (cellIntersections.length == 0) {//no intersections
             this.highlighter.setNoCellIntersections();
             this._setNoPartIntersections();
             return;
-- 
GitLab