From 590ed258bf56f9dd0ce32101e69ef74b28347480 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 9 Jun 2015 18:10:25 -0700 Subject: [PATCH] gik super cell mostly working --- js/cells/DMACell.js | 21 ++++++--------------- js/cells/supercells/DMASuperCell.js | 14 +++++++++++--- js/cells/supercells/GIKSuperCell.js | 3 ++- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index c9948123..2a90f01f 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -21,15 +21,12 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], if (this.superCell) this.superCell.addChildren(this.object3D);//add as child of supercell - if (!superCell || superCell === undefined) { - if (this.index) { - three.sceneAdd(this.object3D); - if (!this.cells) three.addCell(this.object3D.children[0]);//add mesh as highlightable object - } - else this.hide();//stock cell - } + if (this.index){ + if (!this.cells) three.addCell(this.object3D.children[0]);//add mesh as highlightable object + if (!superCell || superCell === undefined) three.sceneAdd(this.object3D); + } else this.hide();//stock cell - if ((!stopSetMode || stopSetMode === undefined) && ( !superCell || superCell === undefined)) this.setMode(); + if (!this.cells && ( !superCell || superCell === undefined)) this.setMode(); } @@ -326,6 +323,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], //destroy DMACell.prototype.destroy = function(){ + this.destroyParts(); if (this.object3D) { if (this.superCell) this.superCell.removeChildren(this.object3D); else if (this.index) { @@ -338,7 +336,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], // material.dispose(); this.object3D = null; } - this.destroyParts(); this.nodes = null; this.beams = null; this.superCell = null; @@ -347,12 +344,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], }; DMACell.prototype.destroyParts = function(){ - if (this.cells){ - this._loopCells(function(cell){ - if (cell) cell.destroyParts(); - }); - return; - } 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 189a4efb..e02d5fd7 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -9,7 +9,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], function DMASuperCell(index, superCell){//supercells might have supercells - DMACell.call(this, index, superCell, null, true); + this.cells = true;//flag for now + + DMACell.call(this, index, superCell); var range = appState.get("superCellRange"); this.cells = this._makeChildCells(range, this.getMaterial()); @@ -66,7 +68,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], DMASuperCell.prototype.getLength = function(){ - if (this.cells) return this.cells.length-1; + if (this.cells && this.cells.length) return this.cells.length-1; return appState.get("superCellRange").x-1;//zero indexed }; @@ -100,7 +102,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], if (cell) cell.destroy(); }); this.cells = null; - DMACell.prototype.destroy.call(); + DMACell.prototype.destroy.call(this); + }; + + DMASuperCell.prototype.destroyParts = function(){ + this._loopCells(function(cell){ + if (cell) cell.destroyParts(); + }); }; return DMASuperCell; diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index 85cd8e3e..d5705c9b 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -19,7 +19,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', }; GIKSuperCell.prototype._rotateCell = function(object3D){ - if (this.index && this.index.z%2 != 0) object3D.rotateZ(Math.PI/2); + if (!this.index) return object3D; + if (this.getAbsoluteIndex().z%2 != 0) object3D.rotateZ(Math.PI/2); return object3D; }; -- GitLab