diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 46b20385f69f49e31e69f1f37f644dde2bb8284d..54cede4758e245507d057b474540264e87886e37 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -12,7 +12,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], function DMACell(index, superCell){ this.index = new THREE.Vector3(index.x, index.y, index.z); - if (superCell) this.superCell = superCell; + + if (superCell) { + this.superCell = superCell; + } else if (!this.cells){ + //lowest level child + this.material = lattice.get("materialType"); + } //object 3d is parent to all 3d elements related to cell, parts, beams, nodes, etc this.object3D = this._buildObject3D(); @@ -120,7 +126,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], }; DMACell.prototype.getMaterial = function(){ - return cellMaterial; + return this.superCell.getMaterial(); }; DMACell.prototype.setOpacity = function(opacity){ @@ -140,6 +146,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], if (mode === undefined) mode = appState.get("cellMode"); switch(mode) { + case "supercell": + if (!this.superCell) mode = "cell"; + break; case "cell": break; case "part": @@ -216,6 +225,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], }; DMACell.prototype.destroyParts = function(){ + if (!this.parts) return; _.each(this.parts, function(part){ if (part) part.destroy(); }); diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 386d46404680ab9ad8a6a934057638b62c4ba2a7..62e34f99bdba1f7689295065ce325e00dfdeaf0b 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -9,7 +9,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], function DMASuperCell(index, superCell){//supercells might have supercells - this.material = lattice.get("materialType");//todo move to dmacell var range = lattice.get("superCellRange"); this.cells = this._makeChildCells(index, range);//todo three dimensional array? DMACell.call(this, index, superCell); @@ -51,8 +50,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], cell.setMode(mode); }); - if (mode == "cell") mode = "supercell"; - if (mode == "part") mode = "object3D"; + if (mode == "cell" || mode == "supercell") mode = "supercell"; + else mode = "object3D"; _.each(this.object3D.children, function(child){ child.visible = child.name == mode; diff --git a/js/models/AppState.js b/js/models/AppState.js index a1593512d68e934ce5e7e8ab125bf4c4647f9a91..14566526d0ddfa1d61e02ceceb21603cbd2a9e6b 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -33,7 +33,7 @@ define(['underscore', 'backbone'], function(_, Backbone){ deleteMode: false, highlightMode: true, extrudeMode: false, - cellMode: "cell",//show cells vs part + cellMode: "cell",//supercell, cell, part, node, beam cellsVisible: true, superCellIndex: 0,//offset of superCell adds todo lattice?