From e797beaaf5baedfab5df1fb6a3131d26dcaf0ad6 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 5 Jun 2015 17:45:55 -0700 Subject: [PATCH] delete mode highlighting in red --- js/cells/DMACell.js | 12 +++++++++++- js/highlighter/Highlighter.js | 20 ++++++++++++++++++++ js/models/Globals.js | 15 +++++++++------ js/three/ThreeView.js | 2 +- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 80c7fe83..c2d63513 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -153,6 +153,16 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], return {direction:direction, position:position}; }; + DMACell.prototype.setDeleteMode = function(state){ + var material; + if (state) material = globals.materials.deleteMaterial; + else material = this.getMaterial(); + if (!material) return;//cell may be deleted by now + if (this.object3D.children[0].material == material) return; + this.object3D.children[0].material = material; + three.render(); + }; + @@ -196,7 +206,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], }; DMACell.prototype.getMaterial = function(){ - if (!this.material) console.warn("no material for cell"); + if (!this.material) return null; var materialClass = lattice.get("materialClass"); if (!globals.materials[materialClass]) { console.warn("no material class found of type " + materialClass); diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js index bd7d570d..a114e6fe 100644 --- a/js/highlighter/Highlighter.js +++ b/js/highlighter/Highlighter.js @@ -28,6 +28,8 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', ' //bind events this.listenTo(lattice, "change:superCellRange", this._superCellParamDidChange); this.listenTo(appState, "change:superCellIndex", this._superCellParamDidChange); + + this.listenTo(appState, "change:deleteMode", this._updateDeleteMode); }, @@ -57,12 +59,24 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', ' }, setNothingHighlighted: function(){ + this.setDeleteMode(this.highlightedObject, false); this.highlightedObject = null; this.direction = null; this.position = null; this.hide(); }, + _updateDeleteMode: function(){ + this.setDeleteMode(this.highlightedObject, appState.get("deleteMode")); + }, + + setDeleteMode: function(object, state){ + if (object && object.setDeleteMode) { + if (state) this.hide(); + this.highlightedObject.setDeleteMode(state); + } + }, + @@ -76,8 +90,14 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', ' return; } + if (this.highlightedObject != highlighted.myParent) this.setDeleteMode(this.highlightedObject, false); this.highlightedObject = highlighted.myParent; + if (appState.get("deleteMode")) { + this.setDeleteMode(this.highlightedObject, true); + return; + } + var params = this.highlightedObject.calcHighlighterParams(intersection.face, intersection.point); if (!params) {//may be hovering over a face that we shouldn't highlight this.hide(); diff --git a/js/models/Globals.js b/js/models/Globals.js index beea4614..adf895ff 100644 --- a/js/models/Globals.js +++ b/js/models/Globals.js @@ -4,9 +4,12 @@ //globals namespace, not sure if there's a way to get around this -define({ - baseplane: null, - highlighter: null, - materials: {} - } -); \ No newline at end of file +define(['three'], function(THREE){ + return { + baseplane: null, + highlighter: null, + materials: { + deleteMaterial: new THREE.MeshLambertMaterial({color:"#ff0000"}) + } + }; +}); \ No newline at end of file diff --git a/js/three/ThreeView.js b/js/three/ThreeView.js index 14b3ee06..517c2d3c 100644 --- a/js/three/ThreeView.js +++ b/js/three/ThreeView.js @@ -59,7 +59,7 @@ define(['underscore', 'backbone', 'three', 'appState', 'globals', 'orbitControls //////////////////////////////////////////////////////////////////////////////// _mouseOut: function(){ - globals.highlighter.setNothingHighlighted(); + if (globals.highlighter) globals.highlighter.setNothingHighlighted(); this._setNoPartIntersections(); }, -- GitLab