diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 80c7fe83cad366e88e311c60e5499206ce043731..c2d6351310b5f15f2220321689eff2b483fc6e5c 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 bd7d570dc65c764449ca7666709dde7de1af0c78..a114e6fe409eec8b403838f181f30d2d70b2232b 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 beea4614ad4145e87ca1faaeb2b496f921df8558..adf895ffa7c635e45889713ed5f8a780188f08b0 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 14b3ee068284b52576e250a32184b94c5f91c2a5..517c2d3c0f4400b342a838b17951db2012450fc7 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(); },