From 1e1b91205b6b5bf6d3bcc30834269f75564de98c Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 27 May 2015 15:17:13 -0700 Subject: [PATCH] parts have reference to parent cells --- js/cells/DMACell.js | 6 +++++- js/cells/GIKCell.js | 4 ++-- js/cells/OctaRotEdgeCell.js | 4 ++-- js/cells/supercells/GIKSuperCell.js | 4 ++-- js/parts/DMAPart.js | 10 ++++++++-- js/parts/GIKPart.js | 4 ++++ js/parts/OctaEdgeVoxPart.js | 4 ++-- js/parts/OctaFaceTriPart.js | 4 ++-- 8 files changed, 27 insertions(+), 13 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index d0297963..c1e28eeb 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -38,7 +38,7 @@ DMACell.prototype._translateCell = function(object3D){ DMACell.prototype._buildMesh = function(){ var geometry = this._getGeometry(); var meshes = []; - var mesh = new THREE.Mesh(geometry, cellMaterial); + var mesh = new THREE.Mesh(geometry, this.getMaterial()); mesh.name = "cell"; meshes.push(mesh); var wireframe = this._buildWireframe(mesh, geometry); @@ -80,6 +80,10 @@ DMACell.prototype.show = function(mode){ this.setMode(mode); }; +DMACell.prototype.getMaterial = function(){ + return cellMaterial; +}; + DMACell.prototype.setOpacity = function(opacity){ }; diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index 412f1f55..eb7533d9 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -32,8 +32,8 @@ return object3D; }; - GIKCell.prototype.getMaterialType = function(){ - return this.superCell.getMaterialType(); + GIKCell.prototype.getMaterial = function(){ + return this.superCell.getMaterial(); }; GIKCell.prototype._initParts = function(){ diff --git a/js/cells/OctaRotEdgeCell.js b/js/cells/OctaRotEdgeCell.js index 8580a828..6af7524b 100644 --- a/js/cells/OctaRotEdgeCell.js +++ b/js/cells/OctaRotEdgeCell.js @@ -14,9 +14,9 @@ OctaRotEdgeCell.prototype._initParts = function(){ var type = globals.lattice.get("partType"); var newParts = []; if (type == "vox"){ - newParts.push(new OctaEdgeVoxPart(0)); + newParts.push(new OctaEdgeVoxPart(0, this)); } else if (type == "voxLowPoly"){ - newParts.push(new OctaEdgeVoxPartLowPoly(0)); + newParts.push(new OctaEdgeVoxPartLowPoly(0, this)); } else { console.warn("part type " + type + " not recognized"); return; diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index d211c39f..d18c44be 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -41,7 +41,7 @@ GIKSuperCell.prototype._buildMesh = function(length){ var superCellGeo = new THREE.BoxGeometry(1,1,1.28); superCellGeo.applyMatrix(new THREE.Matrix4().makeScale(length, 1, 1)); superCellGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-length/2+0.5, 0, 0)); - var mesh = new THREE.Mesh(superCellGeo, this.getMaterialType()); + var mesh = new THREE.Mesh(superCellGeo, this.getMaterial()); mesh.name = "supercell"; meshes.push(mesh); var wireframe = this._buildWireframe(mesh); @@ -59,7 +59,7 @@ GIKSuperCell.prototype._buildWireframe = function(mesh){ return wireframe; }; -GIKSuperCell.prototype.getMaterialType = function(){ +GIKSuperCell.prototype.getMaterial = function(){ var material = cellBrassMaterial; if (this.material == "fiberGlass") material = cellFiberGlassMaterial; return material; diff --git a/js/parts/DMAPart.js b/js/parts/DMAPart.js index 43ef549e..2eb06073 100644 --- a/js/parts/DMAPart.js +++ b/js/parts/DMAPart.js @@ -6,14 +6,15 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THREE.FlatShading }); partMaterial.color.setRGB( 0.9619657144369509, 0.6625466032079207, 0.20799727886007258 ); -function DMAPart(index) { +function DMAPart(index, parent) { + this.parentCell = parent; this.index = index;//todo need this? this.mesh = this._buildMesh(index); } DMAPart.prototype._buildMesh = function(index){ var geometry = this._getGeometry(index); - var mesh = new THREE.Mesh(geometry, partMaterial); + var mesh = new THREE.Mesh(geometry, this.getMaterial()); mesh.name = "part"; return mesh; }; @@ -37,11 +38,16 @@ DMAPart.prototype.getMesh = function(){//only call by parent cell return this.mesh; }; +DMAPart.prototype.getMaterial = function(){ + return partMaterial; +}; + DMAPart.prototype.destroy = function(){ if (this.mesh) { this.mesh.parent.remove(this.mesh); this.mesh = null; } + this.parentCell = null; this.index = null; }; diff --git a/js/parts/GIKPart.js b/js/parts/GIKPart.js index 6fb931e4..d0a2582c 100644 --- a/js/parts/GIKPart.js +++ b/js/parts/GIKPart.js @@ -40,6 +40,10 @@ return unitPartGeo;//this.parentCell.getMaterialType() }; + DMAPart.prototype.getMaterial = function(){ + return this.parentCell.getMaterial(); + }; + self.DMAGIKPart = DMAGIKPart; })(); diff --git a/js/parts/OctaEdgeVoxPart.js b/js/parts/OctaEdgeVoxPart.js index b4d29f18..792e1c5c 100644 --- a/js/parts/OctaEdgeVoxPart.js +++ b/js/parts/OctaEdgeVoxPart.js @@ -19,8 +19,8 @@ unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,0.09)); }); - function OctaEdgeVoxPart(type){ - DMAPart.call(this, type); + function OctaEdgeVoxPart(type, parent){ + DMAPart.call(this, type, parent); } OctaEdgeVoxPart.prototype = Object.create(DMAPart.prototype); diff --git a/js/parts/OctaFaceTriPart.js b/js/parts/OctaFaceTriPart.js index 317ab03e..d3f7612a 100644 --- a/js/parts/OctaFaceTriPart.js +++ b/js/parts/OctaFaceTriPart.js @@ -25,8 +25,8 @@ loader.load("assets/stls/parts/trianglePart.stl", function(geometry){ unitPartGeo3.applyMatrix(new THREE.Matrix4().makeRotationZ(-2*Math.PI/3)); }); -function OctaFaceTriPart(type){ - DMAPart.call(this, type); +function OctaFaceTriPart(type, parent){ + DMAPart.call(this, type, parent); } OctaFaceTriPart.prototype = Object.create(DMAPart.prototype); -- GitLab