diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 2780500acb5dfd9642d5cebc94ad9bbcfbb91a37..6cd8d0e318ab0ca60a0f2702e12f6531764a0c8e 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 ec1e7f0ed34206766530b17c1818bb013c71ce13..b53303ab78494bf3b542c6e57c6315ed126335bb 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;