diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 44d2d8c80f0b32306eb74d81904648946b4dc324..9412ea326fcd8b6dbb1f37670a97aa7aab6db328 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -245,10 +245,16 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' this.object3D.children[0].material = material; }; - DMACell.prototype.setTransparent = function(transparent){ + DMACell.prototype.setWireframeVisibility = function(visible){ + this.object3D.children[1].visible = visible; + }; + + DMACell.prototype.setTransparent = function(evalFunction){ + var transparent = evalFunction(this); if (transparent == this.isTransparent) return; this.isTransparent = transparent; this.setMaterial(this.getMaterial(true)); + this.setWireframeVisibility(!this.isTransparent); }; DMACell.prototype.setMode = function(mode, callback){ @@ -293,6 +299,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' var visible = true; if (mode == "supercell") visible = !self._isMiddleLayer();//middle layers are always hidden in supercell mode + self.setWireframeVisibility(!self.isTransparent); + _.each(self.object3D.children, function(child){ if (child.name == "object3D") return; child.visible = visible && (child.name == mode); @@ -400,6 +408,12 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' cellsArray[index.x][index.y][index.z] = this; }; + DMACell.prototype.removeFromDenseArray = function(cellsArray, min){ + var index = this.getAbsoluteIndex().sub(min); + cellsArray[index.x][index.y][index.z] = null; + }; + + diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 72af56beed0188527075670f15d5ee1aec5847e8..c8c96f9e9000fc211cb44ea8a82b5bfb0837cbb1 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -105,6 +105,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], return false; }; + DMASuperCell.prototype.setTransparent = function(evalFunction){ + DMACell.prototype.setTransparent.call(this, evalFunction); + this._loopCells(function(cell){ + if (cell) cell.setTransparent(evalFunction); + }) + }; + diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index c0976ea0088406bf64b2b5def940e2ac9c54fe0f..6f8d43dda8a8f310563c2fd1dded44c4ffa047af 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -461,6 +461,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre three.render(); }, + setOpaque: function(){ + this._loopCells(this.sparseCells, function(cell){ + if (cell) cell.setTransparent(function(){ + return false; + }); + }); + three.render(); + }, + diff --git a/js/lattice/LatticeEsim.js b/js/lattice/LatticeEsim.js index 438e40422478bf07917af2ddff63cc9fed0e3b15..08a6ebefee1dbaf9060a35af4545ba2ec320ec32 100644 --- a/js/lattice/LatticeEsim.js +++ b/js/lattice/LatticeEsim.js @@ -2,10 +2,31 @@ * Created by aghassaei on 6/30/15. */ -define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){ +define(['lattice', 'appState', 'threeModel', 'eSim', 'eSimCell'], function(lattice, appState, three, eSim){ + + var eSimMethods = { + _eSimTabChanged: function(){ + var currentTab = appState.get("currentTab"); + if (currentTab == "eSetup") this._showConductors(); + else this.setOpaque(); + }, + + _showConductors: function(){ + var groupNum = eSim.get("visibleConductorGroup"); + console.log(eSim.get("conductorGroups")); + console.log(groupNum); + var allVisible = groupNum < 0; + this._loopCells(this.sparseCells, function(cell){ + if (cell) cell.setTransparent(function(evalCell){ + return !evalCell.isConductive() || (!allVisible && groupNum != evalCell.getConductorGroupNum()) + }); + }); + three.render(); + }, + calculateConductorConnectivity: function(){ var num = 1; this._loopCells(this.cells, function(cell){ @@ -23,7 +44,7 @@ define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){ if (!cell) return; if (groups.indexOf(cell.getConductorGroupNum()) < 0 && cell.isConductive()) groups.push(cell.getConductorGroupNum()); }); - eSim.set("conductorGroups", _.keys(groups)); + eSim.set("conductorGroups", groups); }, propagateToNeighbors: function(index, callback){ @@ -42,5 +63,9 @@ define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){ }; _.extend(lattice, eSimMethods); + lattice.listenTo(appState, "change:currentTab", lattice._eSimTabChanged); + lattice.listenTo(eSim, "change:visibleConductorGroup", lattice._showConductors); + + return lattice; }); diff --git a/js/materials/DMAMaterials.js b/js/materials/DMAMaterials.js index 71fd2f0105ccef83acd0198a04b5f83ee2e0f574..f075689b3937b15feddf915e140ecaaf1c29d94e 100644 --- a/js/materials/DMAMaterials.js +++ b/js/materials/DMAMaterials.js @@ -8,7 +8,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu var materialsList = { deleteMaterial: { color: "#ff0000", - threeMaterial:new THREE.MeshLambertMaterial({color:"#ff0000", shading:THREE.FlatShading}) + threeMaterial: makeMaterialObject("#ff0000") } }; @@ -155,6 +155,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu newMaterials[key] = definitions[key]; var color = getMaterialColorForState(state, definitions[key], key); newMaterials[key].threeMaterial = makeMaterialObject(color); + newMaterials[key].transparentMaterial = makeMaterialObject(color, true); newMaterials[key].noDelete = true;//don't delete the predefined materials }); return newMaterials; @@ -181,8 +182,10 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu if (!state) state = appState.get("realisticColorScheme"); var materialInfo = materialsList[name]; var color = getMaterialColorForState(state, materialInfo, name); + if (materialInfo.threeMaterial) materialInfo.threeMaterial.color = new THREE.Color(color); else materialInfo.threeMaterial = makeMaterialObject(color); + if (materialInfo.transparentMaterial) materialInfo.transparentMaterial.color = new THREE.Color(color); else materialInfo.transparentMaterial = makeMaterialObject(color, true); } @@ -195,7 +198,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu } function makeMaterialObject(color, transparent){ - if (transparent) return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading, transparent: true, opacity:0.4}); + if (transparent) return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading, transparent: true, opacity:0.1}); return new THREE.MeshLambertMaterial({color:color, shading:THREE.FlatShading}); }