From 6bf2c26ae2c5e27e8fe35d4a64a8aeaf995fa2ad Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 15 May 2015 22:46:55 -0400 Subject: [PATCH] material types --- js/fea/DMASuperCell.js | 14 +++++++++----- js/fea/DmaCellOther.js | 4 ++++ js/fea/DmaPart.js | 8 ++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/js/fea/DMASuperCell.js b/js/fea/DMASuperCell.js index 3b248259..69d01835 100644 --- a/js/fea/DMASuperCell.js +++ b/js/fea/DMASuperCell.js @@ -3,8 +3,8 @@ */ -var cellBrassMaterial = [new THREE.MeshLambertMaterial({color:"#b5a642"})]; -var cellFiberGlassMaterial = [new THREE.MeshLambertMaterial({color:"#fef1b5"})]; +var cellBrassMaterial = new THREE.MeshLambertMaterial({color:"#b5a642"}); +var cellFiberGlassMaterial = new THREE.MeshLambertMaterial({color:"#fef1b5"}); DMASuperCell = function(length, range, cells){ var shouldRotate = range.max.x == range.min.x; @@ -22,15 +22,19 @@ DMASuperCell.prototype._buildSuperCellMesh = function(length, shouldRotate){ superCellGeo.applyMatrix(new THREE.Matrix4().makeScale(length, 1, 1)); superCellGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(length/2-1/2), 0, 0)); if (shouldRotate) superCellGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/2)); - var material = cellBrassMaterial; - if (this.material == "fiberGlass") material = cellFiberGlassMaterial; - var mesh = THREE.SceneUtils.createMultiMaterialObject(superCellGeo, material); + var mesh = THREE.SceneUtils.createMultiMaterialObject(superCellGeo, [this.getMaterialType()]); var wireframe = new THREE.BoxHelper(mesh.children[0]); wireframe.material.color.set(0x000000); mesh.children.push(wireframe); return mesh; }; +DMASuperCell.prototype.getMaterialType = function(){ + var material = cellBrassMaterial; + if (this.material == "fiberGlass") material = cellFiberGlassMaterial; + return material; +}; + DMASuperCell.prototype._setPosition = function(index){ var position = dmaGlobals.lattice.getPositionForIndex(index); this.mesh.position.set(position.x, position.y, position.z); diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index 016e82f9..4c188089 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -90,6 +90,10 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; } }; + DMAGIKCell.prototype.getMaterialType = function(){ + return this.superCell.getMaterialType(); + }; + DMAGIKCell.prototype.__initParts = function(){ var parts = []; var isEnd = this.superCellIndex == 0 || this.superCellIndex == this.superCell.getLength(); diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js index 0c6f4c7f..6c9baafb 100644 --- a/js/fea/DmaPart.js +++ b/js/fea/DmaPart.js @@ -237,7 +237,7 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE DMAGIKPart.prototype = Object.create(DMAPart.prototype); DMAGIKPart.prototype._makeMeshForType = function(){ - var mesh = new THREE.Mesh(unitPartGeo, partMaterial); + var mesh = new THREE.Mesh(unitPartGeo, this.parentCell.getMaterialType()); mesh.myPart = this;//need a ref back to this part return mesh; }; @@ -269,7 +269,7 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE DMAGIKPartLowPoly.prototype = Object.create(DMAGIKPart.prototype); DMAGIKPartLowPoly.prototype._makeMeshForType = function(){ - var mesh = new THREE.Mesh(unitPartGeo, partMaterial); + var mesh = new THREE.Mesh(unitPartGeo, this.parentCell.getMaterialType()); mesh.myPart = this;//need a ref back to this part return mesh; }; @@ -301,7 +301,7 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE DMAGIKEndPart.prototype = Object.create(DMAGIKPart.prototype); DMAGIKEndPart.prototype._makeMeshForType = function(){ - var mesh = new THREE.Mesh(unitPartGeo, partMaterial); + var mesh = new THREE.Mesh(unitPartGeo, this.parentCell.getMaterialType()); mesh.myPart = this;//need a ref back to this part return mesh; }; @@ -333,7 +333,7 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE DMAGIKEndPartLowPoly.prototype = Object.create(DMAGIKPart.prototype); DMAGIKEndPartLowPoly.prototype._makeMeshForType = function(){ - var mesh = new THREE.Mesh(unitPartGeo, partMaterial); + var mesh = new THREE.Mesh(unitPartGeo, this.parentCell.getMaterialType()); mesh.myPart = this;//need a ref back to this part return mesh; }; -- GitLab