From dadef243272d97b66a22fd4b72e7d1e081ad38fd Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 27 May 2015 12:14:48 -0700 Subject: [PATCH] working through gik cell --- js/cells/DMACell.js | 2 +- js/cells/GIKCell.js | 11 +++++++--- js/cells/supercells/GIKSuperCell.js | 33 ++++++++--------------------- js/lattice/GIKLattice.js | 1 + js/models/ThreeModel.js | 2 +- 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 08e91992..6f1ba1cb 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -27,7 +27,7 @@ DMACell.prototype._getSceneType = function(){//todo need this? DMACell.prototype._buildObject3D = function(){ var object3D = this._translateCell(this._rotateCell(new THREE.Object3D())); object3D.myParent = this;//reference to get mouse raycasting back - object3D.name = "object3d"; + object3D.name = "object3D"; return object3D; }; diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index f156f061..1e7ea8c0 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -6,23 +6,28 @@ (function () { function GIKCell(indices){ - this.superCell = true; - CubeCell.call(this, indices, true); + this.indices = indices; } GIKCell.prototype = Object.create(CubeCell.prototype); GIKCell.prototype.setSuperCell = function(superCell, index){ this.superCell = superCell; this.superCellIndex = index; + CubeCell.call(this, this.indices); if (this.superCellIndex == this.superCell.getLength()) this.object3D.rotateZ(Math.PI); }; + GIKCell.prototype._translateCell = function(object3D){ + if (this.superCellIndex) object3D.position.set(-this.superCellIndex*this.xScale(),0, 0); + return object3D; + }; + GIKCell.prototype.getMaterialType = function(){ return this.superCell.getMaterialType(); }; GIKCell.prototype._initParts = function(){ - if (!this.superCell || this.superCell === true) return null; + if (!this.superCell) return null; var parts = []; var isEnd = this.superCellIndex == 0 || this.superCellIndex == this.superCell.getLength(); if (globals.lattice.get("partType") == "lego") { diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index aeb4cce8..59d8e090 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -13,7 +13,7 @@ GIKSuperCell = function(length, range, cells){ this.object3D = this._buildObject3D(); this._addChildren(this._buildMesh(length), this.object3D); - this._addChildren(this._getCellObject3Ds(cells)); + globals.three.sceneAdd(this.object3D, this._getSceneType()); // this.setMode(); @@ -30,10 +30,16 @@ GIKSuperCell.prototype._buildObject3D = function(){ return this._translateCell(this._rotateCell(new THREE.Object3D())); }; +GIKSuperCell.prototype.addCellsToScene = function(){ + this._addChildren(this._getCellObject3Ds(this.cells)); +}; + GIKSuperCell.prototype._getCellObject3Ds = function(cells){ var object3Ds = []; + var self = this; _.each(cells, function(cell){ - object3Ds.push(cell.getObject3D()); + var object3D = cell.getObject3D(); + object3Ds.push(object3D); }); return object3Ds; }; @@ -76,28 +82,7 @@ GIKSuperCell.prototype.setMode = function(mode){ if (mode === undefined) mode = globals.appState.get("cellMode"); if (mode == "cell") mode = "supercell"; - - switch(mode) { - case "supercell": - break; - case "cell": - break; - case "part": - if (!this.parts) { - this.parts = this._initParts(); - var self = this; - _.each(this.parts, function(part){ - self._addChildren(part.getMesh()); - }); - } - break; - case "beam": - if (!this.beams) this.beams = this._initBeams(); - break; - case "node": - if (!this.nodes) this.nodes = this._initNodes(); - break; - } + if (mode == "part") mode = "object3D"; _.each(this.object3D.children, function(child){ child.visible = child.name == mode; diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index 6cb2826e..d211fc4a 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -52,6 +52,7 @@ latticeSubclasses["GIKLattice"] = { _.each(cells, function(cell, index){ cell.setSuperCell(superCell, index); }); + superCell.addCellsToScene(); return superCell; }, diff --git a/js/models/ThreeModel.js b/js/models/ThreeModel.js index 11870b1d..809f598b 100644 --- a/js/models/ThreeModel.js +++ b/js/models/ThreeModel.js @@ -59,7 +59,7 @@ function ThreeModel(){ cells.push(object.children[0]); } else if (type == "supercell"){ _.each(object.children, function(child){//add cells as hover - if (child.name != "object3d") return; + if (child.name != "object3D") return; cells.push(child.children[0]); }); } else if (type == "part"){//todo change this -- GitLab