diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 9c7cf0ad74e1e5cc50863569474ddebe8176960a..c9948123c2e913f98de27ef244e9f2f04576a89f 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -8,7 +8,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], var wireframeMaterial = new THREE.MeshBasicMaterial({color:0x000000, wireframe:true}); - function DMACell(index, superCell, material){ + function DMACell(index, superCell, material, stopSetMode){ if (index) this.index = new THREE.Vector3(index.x, index.y, index.z); if (superCell) this.superCell = superCell; @@ -29,7 +29,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], else this.hide();//stock cell } - this.setMode(); + if ((!stopSetMode || stopSetMode === undefined) && ( !superCell || superCell === undefined)) this.setMode(); } @@ -224,7 +224,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], DMACell.prototype.setOpacity = function(opacity){ }; - DMACell.prototype.setMode = function(mode){ + DMACell.prototype.setMode = function(mode, callback){ if (mode === undefined) mode = appState.get("cellMode"); var self = this; @@ -238,7 +238,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], setVisiblity(); break; case "part": - if (!this.cells && !this.parts) { + if (!this.parts) { this._initParts(function(parts){ self.parts = parts; setVisiblity(); @@ -264,6 +264,11 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], if (child.name == "object3D") return; child.visible = visible && (child.name == mode); }); + + if (callback) { + callback(); + return; + } three.conditionalRender(); } }; @@ -277,7 +282,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], //subcomponents DMACell.prototype._initParts = function(callback){ - return [];//override in subclasses + callback();//override in subclasses }; diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index 13af33755971627d967f5b534cb6ce31c7e7c14a..f3a0b06f91ebebad02e47047888d5656b0ac69c1 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -27,7 +27,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cubeCell'], if (!this.superCell) return; var self = this; var parts = []; - var length = this.superCell.getLength()+1; if (lattice.get("partType") == "lego") { require(['gikPart'], function(GIKPart){ diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 208a541a1c11918c8edf15b9f231c884de8f40d3..189a4efbb56244a9e8649903c62a0a88e76440d7 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -9,12 +9,12 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], function DMASuperCell(index, superCell){//supercells might have supercells - DMACell.call(this, index, superCell); + DMACell.call(this, index, superCell, null, true); var range = appState.get("superCellRange"); this.cells = this._makeChildCells(range, this.getMaterial()); - this.setMode(); + if (!superCell || superCell === undefined) this.setMode();//don't pass a call down to children again } DMASuperCell.prototype = Object.create(DMACell.prototype); @@ -34,7 +34,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], return cells; }; - DMASuperCell.prototype._makeSubCellForIndex = function(index, material){ + DMASuperCell.prototype._makeSubCellForIndex = function(index, supercell, material){ return null;//override in subclasses }; @@ -42,11 +42,23 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], return "supercell"; }; - DMASuperCell.prototype.setMode = function(mode){ - DMACell.prototype.setMode.call(this, mode); - this._loopCells(function(cell){ - if (cell) cell.setMode(mode); + DMASuperCell.prototype.setMode = function(mode, callback){ + var self = this; + DMACell.prototype.setMode.call(this, mode, function(){ + var numChildren = self.object3D.children.length-2; + self._loopCells(function(cell){ + if (cell) cell.setMode(mode, function(){ + if (--numChildren <= 0) { + if (callback) { + callback(); + return; + } + three.conditionalRender(); + } + }); + }); }); + }; diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 06ba9eed7fcdc3cc64fcdcf11a2510f1e99aa191..729880868bf6c788fc5f06502c279e0e1767311f 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -336,10 +336,12 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre _updateForMode: function(){ var cellMode = appState.get("cellMode"); + var numCells = this.get("numCells"); this._iterCells(this.sparseCells, function(cell){ - if (cell) cell.setMode(cellMode); + if (cell) cell.setMode(cellMode, function(){ + if (--numCells <= 0) three.render(); + }); }); - three.render(); }, _updateCellSeparation: function(){ diff --git a/js/parts/DMAPart.js b/js/parts/DMAPart.js index 2d18f5f1564d91a292915833e2941976dd8fd80f..b280b22f8dc508550ccb04aa9bb447e10a45bf5e 100644 --- a/js/parts/DMAPart.js +++ b/js/parts/DMAPart.js @@ -32,7 +32,6 @@ define(['underscore', 'three'], function(_, THREE){ }; DMAPart.prototype.destroy = function(){ - console.log("destroy"); if (this.mesh) { this.parentCell.removeChildren(this.mesh); this.mesh = null; diff --git a/js/three/ThreeModel.js b/js/three/ThreeModel.js index 90a2442a41bef075f35501bd776a5971d3bfa567..b24105d2e1139d017af122bd53b9fcf1e0f7a364 100644 --- a/js/three/ThreeModel.js +++ b/js/three/ThreeModel.js @@ -130,6 +130,7 @@ define(['underscore', 'three'], function(_, THREE){ function conditionalRender(){ if (shouldRender) render(); + shouldRender = false; } return {//return public properties/methods