diff --git a/index.html b/index.html index d2d11aefc17571482ab01ef83c27531a9ebcacd3..ac6c6f4780a9fd8ab708adf0bee7540eb4f2e648 100644 --- a/index.html +++ b/index.html @@ -44,7 +44,6 @@ <script src="js/fea/DmaNode.js"></script> <script src="js/fea/DmaBeam.js"></script> - <script src="js/cells/DMAParentCell.js"></script> <script src="js/cells/DmaCell.js"></script> <script src="js/cells/OctaFaceCell.js"></script> <script src="js/cells/OctaEdgeCell.js"></script> diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 6f1ba1cb8753af52151d73a80f335a6c6c2e0f62..7adc5cbafeb4099c2720d30b9c8e14b9a2fd4d97 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -13,16 +13,10 @@ function DMACell(indices){ //object 3d is parent to all 3d elements related to cell, parts, beams, nodes, etc this.object3D = this._buildObject3D(); this._addChildren(this._buildMesh(), this.object3D);//build cell meshes - if (!this.superCell) globals.three.sceneAdd(this.object3D, this._getSceneType()); + if (!this.superCell && this.indices) globals.three.sceneAdd(this.object3D, "cell"); this.setMode(); } -DMACell.prototype = Object.create(DMAParentCell.prototype); - -DMACell.prototype._getSceneType = function(){//todo need this? - if (this.indices) return "cell"; - return null; -}; DMACell.prototype._buildObject3D = function(){ var object3D = this._translateCell(this._rotateCell(new THREE.Object3D())); @@ -31,9 +25,15 @@ DMACell.prototype._buildObject3D = function(){ return object3D; }; -DMACell.prototype.getObject3D = function(){//only called by supercells - return this.object3D; -} +DMACell.prototype._rotateCell = function(object3D){ + return object3D;//by default, no mesh transformations +}; + +DMACell.prototype._translateCell = function(object3D){ + var position = globals.lattice.getPositionForIndex(this.indices); + object3D.position.set(position.x, position.y, position.z); + return object3D; +}; DMACell.prototype._buildMesh = function(){ var geometry = this._getGeometry(); @@ -52,6 +52,37 @@ DMACell.prototype._buildWireframe = function(mesh, geometry){//abstract mesh rep return new THREE.Mesh(geometry, wireframeMaterial); }; +DMACell.prototype._addChildren = function(children, object3D){//accepts an array or a single mesh + this._addRemoveChildren(true, children, object3D); +}; + +DMACell.prototype._removeChildren = function(children, object3D){//accepts an array or a single mesh + this._addRemoveMeshes(false, children, object3D); +}; + +DMACell.prototype._addRemoveChildren = function(shouldAdd, children, object3D){//accepts an array or a single mesh + if (object3D === undefined) object3D = this.object3D; + if (children.constructor === Array){ + _.each(children, function(child){ + if (shouldAdd) object3D.add(child); + else object3D.remove(child); + }); + } else if (shouldAdd) object3D.add(children); + else object3D.remove(children); +}; + +DMACell.prototype.hide = function(){ + this.object3D.visible = false; +}; + +DMACell.prototype.show = function(mode){ + this.object3D.visible = true; + this.setMode(mode); +}; + +DMACell.prototype.setOpacity = function(opacity){ +}; + DMACell.prototype._initParts = function(){ return [];//override in subclasses }; @@ -96,6 +127,18 @@ DMACell.prototype.setMode = function(mode){ }); }; +DMACell.prototype.getPosition = function(){ + return this.object3D.position.clone(); +}; + +DMACell.prototype.getQuaternion = function(){ + return this.object3D.quaternion.clone(); +}; + +DMACell.prototype.getEuler = function(){ + return this.object3D.rotation.clone(); +}; + DMACell.prototype.xScale = function(){ return globals.lattice.xScale(0); }; @@ -112,7 +155,8 @@ DMACell.prototype.destroy = function(){ if (this.destroyStarted) return; this.destroyStarted = true; if (this.object3D) { - globals.three.sceneRemove(this.object3D, this._getSceneType()); + if (this.superCell) this.object3D.parent.remove(this.object3D); + else if (this.indices) globals.three.sceneRemove(this.object3D, "cell"); this.object3D.myParent = null; // this.object3D.dispose(); // geometry.dispose(); diff --git a/js/cells/DMAParentCell.js b/js/cells/DMAParentCell.js deleted file mode 100644 index 21ac7195302283af43c3d5af8c38600f4933ea9e..0000000000000000000000000000000000000000 --- a/js/cells/DMAParentCell.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Created by aghassaei on 5/27/15. - */ - - -//common methods between cell and supercell classes - -function DMAParentCell(){ -} - -DMAParentCell.prototype._rotateCell = function(object3D){ - return object3D;//by default, no mesh transformations -}; - -DMAParentCell.prototype._translateCell = function(object3D){ - var position = globals.lattice.getPositionForIndex(this.indices); - object3D.position.set(position.x, position.y, position.z); - return object3D; -}; - -DMAParentCell.prototype._addChildren = function(children, object3D){//accepts an array or a single mesh - this._addRemoveChildren(true, children, object3D); -}; - -DMAParentCell.prototype._removeChildren = function(children, object3D){//accepts an array or a single mesh - this._addRemoveMeshes(false, children, object3D); -}; - -DMAParentCell.prototype._addRemoveChildren = function(shouldAdd, children, object3D){//accepts an array or a single mesh - if (object3D === undefined) object3D = this.object3D; - if (children.constructor === Array){ - _.each(children, function(child){ - if (shouldAdd) object3D.add(child); - else object3D.remove(child); - }); - } else if (shouldAdd) object3D.add(children); - else object3D.remove(children); -}; - -DMAParentCell.prototype.hide = function(){ - this.object3D.visible = false; -}; - -DMAParentCell.prototype.show = function(mode){ - this.object3D.visible = true; - this.setMode(mode); -}; - -DMAParentCell.prototype.setOpacity = function(opacity){ -}; - -DMAParentCell.prototype.getPosition = function(){ - return this.object3D.position.clone(); -}; - -DMAParentCell.prototype.getQuaternion = function(){ - return this.object3D.quaternion.clone(); -}; - -DMAParentCell.prototype.getEuler = function(){ - return this.object3D.rotation.clone(); -}; \ No newline at end of file diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index 1e7ea8c017e7e6e79572942e9f098dfc3905d998..7aacaa64ad747c848d854d058bfd1c34bffcc2fe 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -15,6 +15,7 @@ this.superCellIndex = index; CubeCell.call(this, this.indices); if (this.superCellIndex == this.superCell.getLength()) this.object3D.rotateZ(Math.PI); + return this.object3D; }; GIKCell.prototype._translateCell = function(object3D){ diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index 59d8e09073358cb8a05fbb01598f9dec95fd773b..dda8c5f259836f59576378c7f474da86d5429f23 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -13,35 +13,22 @@ GIKSuperCell = function(length, range, cells){ this.object3D = this._buildObject3D(); this._addChildren(this._buildMesh(length), this.object3D); - - globals.three.sceneAdd(this.object3D, this._getSceneType()); + var self = this; + _.each(cells, function(cell, index){ + self.addObject3D(cell.setSuperCell(self, index)); + }); + if (this.indices) globals.three.sceneAdd(this.object3D, "supercell"); // this.setMode(); - -}; -GIKSuperCell.prototype = Object.create(DMAParentCell.prototype); - -GIKSuperCell.prototype._getSceneType = function(){//todo need this? - if (this.indices) return "supercell"; - return null; }; +GIKSuperCell.prototype = Object.create(DMACell.prototype); 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){ - var object3D = cell.getObject3D(); - object3Ds.push(object3D); - }); - return object3Ds; +GIKSuperCell.prototype.addObject3D = function(object3D){ + this._addChildren(object3D); }; GIKSuperCell.prototype._rotateCell = function(object3D){ diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index d211fc4ad032a78856a5d36c0b6eb84eb9ac0f46..1cc3e3d843b66d2a28521b14f870659a34f63a7e 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -48,12 +48,7 @@ latticeSubclasses["GIKLattice"] = { } } if (cells.length < 1) return null; - var superCell = new GIKSuperCell(length, range, cells); - _.each(cells, function(cell, index){ - cell.setSuperCell(superCell, index); - }); - superCell.addCellsToScene(); - return superCell; + return new GIKSuperCell(length, range, cells); }, _rasterGikCells: function(order, callback, var1, var2, var3, cells){