diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 1b4989c5f1a0a9bef294634b25b07a8c971cac3b..1f94204c7462173039efac285f321cbb53cf2848 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -153,15 +153,23 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], }; DMACell.prototype.setDeleteMode = function(state){ - if (this.superCell) { - this.superCell.setDeleteMode(state); - return; - } + 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; + + if (this.cells){ + this._loopCells(function(cell){ + if (cell) cell.setDeleteMode(state); + }); + } + if (this.parts){ + _.each(this.parts, function(part){ + if (part) part.setMaterial(material); + }); + } this.object3D.children[0].material = material; three.render(); }; diff --git a/js/cells/supercells/CompositeCell.js b/js/cells/supercells/CompositeCell.js index ab6d23afd311517cf36dd4a1fc8eb718c2878158..7292d349ef2b9397d2ff8955b0665b32f3ca236a 100644 --- a/js/cells/supercells/CompositeCell.js +++ b/js/cells/supercells/CompositeCell.js @@ -11,14 +11,17 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', }; CompositeCell.prototype = Object.create(DMASuperCell.prototype); - CompositeCell.prototype._makeSubCellForIndex = function(json){ - return null; - }; - + CompositeCell.prototype._makeSubCellForIndex = function(json, callback){ + require([], function(){ + }); + }; CompositeCell.prototype._getGeometry = function(){ - return new THREE.BoxGeometry(); + var dimensions = appState.get("superCellRange"); + var geo = new THREE.BoxGeometry(dimensions.x, dimensions.y, dimensions.z); + geo.applyMatrix(new THREE.Matrix4().makeTranslation(dimensions.x/2-0.5, dimensions.y/2-0.5, dimensions.z/2-0.5)); + return geo; }; CompositeCell.prototype._buildWireframe = function(mesh){ diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 0d8c7fa0ce2fa37c23c83fae359e31aa25251edd..fcbc3d455daef90b7d899023fdc203c5d115b444 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -29,15 +29,19 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], cells[x].push([]); for (var z=0;z<range.z;z++){ //child cells add themselves to object3D - if (material.cells && material.cells[x][y][z]) cells[x][y].push(this._makeSubCellForIndex(new THREE.Vector3(x, y, z), this, material.cells[x][y][z].material)); - else cells[x][y].push(this._makeSubCellForIndex({index: new THREE.Vector3(x, y, z), material:this.material})); + var material = this.material; + if (material.cells && material.cells[x][y][z]) material = material.cells[x][y][z].material; + cells[x][y].push(null); + this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z)}, function(cell){ + cells[x][y][z] = cell; + }); } } } return cells; }; - DMASuperCell.prototype._makeSubCellForIndex = function(json){ + DMASuperCell.prototype._makeSubCellForIndex = function(json, callback){ return null;//override in subclasses }; diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index 4d28f4b025cb1113f70a211d6373b3ad1c5c665a..1f4cad71aa01e579bb82f2d39081c1931286dc2b 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -21,8 +21,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', }; GIKSuperCell.prototype = Object.create(DMASuperCell.prototype); - GIKSuperCell.prototype._makeSubCellForIndex = function(json){ - return new GIKCell(json, this); + GIKSuperCell.prototype._makeSubCellForIndex = function(json, callback){ + callback(new GIKCell(json, this)); }; GIKSuperCell.prototype._rotateCell = function(object3D){ diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js index 884b5b524b11a47c4fbafc814c8e11258addb652..2d332e665f8e4d921d0dc684f3eebb7cdcf84173 100644 --- a/js/highlighter/Highlighter.js +++ b/js/highlighter/Highlighter.js @@ -72,7 +72,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', ' setDeleteMode: function(object, state){ if (object && object.setDeleteMode) { if (state) this.hide(); - this.highlightedObject.setDeleteMode(state); + object.getParent().setDeleteMode(state); } }, diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index ef08736fe53ab33e6fe7b6734bb8088fa669ba78..84465643a67ddc90d0c6a725b0db0e162aef6ac5 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -14,6 +14,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre require(['superCellHighlighter'], function(superCellHighlighter){ globals.highlighter = new superCellHighlighter(); }); + appState.set("superCellRange", new THREE.Vector3(4, 1, 1)); + }, getIndexForPosition: function(absPosition){ diff --git a/js/parts/DMAPart.js b/js/parts/DMAPart.js index b280b22f8dc508550ccb04aa9bb447e10a45bf5e..7acd756b60c84f471abbf8ff818aa22fccd16bd4 100644 --- a/js/parts/DMAPart.js +++ b/js/parts/DMAPart.js @@ -31,8 +31,12 @@ define(['underscore', 'three'], function(_, THREE){ return this.parentCell.getMaterial(); }; + DMAPart.prototype.setMaterial = function(material){ + this.mesh.material = material; + }; + DMAPart.prototype.destroy = function(){ - if (this.mesh) { + if (this.mesh) {d this.parentCell.removeChildren(this.mesh); this.mesh = null; }