From 5cf06223c93c98e6ff805b504616a9348d346247 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 23 Sep 2015 19:47:39 -0400 Subject: [PATCH] material object on cell --- js/cells/DMACell.js | 19 +++++++++++-------- js/materials/DMAMaterial.js | 7 ++++--- js/materials/DMAMaterials.js | 8 ++++---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index ffbc7417..be05c6df 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -156,12 +156,11 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' }; DMACell.prototype.setDeleteMode = function(state){ - var material; + var threeMaterial; if (!state && !this.material) return;//cell may be deleted by now - if (state) material = materials.getDeleteMaterial(); - else material = this.getMaterial(true); - if (!material) return;//no material object found - if (this.object3D.children[0].material == material) return; + if (state) threeMaterial = materials.getDeleteMaterial(); + else threeMaterial = this.getMaterial(true); + if (!threeMaterial) return;//no material object found if (this.cells){ this._loopCells(function(cell){ @@ -170,10 +169,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' } if (this.parts){ _.each(this.parts, function(part){ - if (part) part.setMaterial(material); + if (part) part.setMaterial(threeMaterial); }); } - this.setMaterial(material); + this._setTHREEMaterial(threeMaterial); }; DMACell.prototype.getParent = function(){ @@ -229,7 +228,11 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' DMACell.prototype.setMaterial = function(material){ this.material = material; - this.object3D.children[0].material = this.getMaterial(true); + this._setTHREEMaterial(this.getMaterial(true)); + }; + + DMACell.prototype._setTHREEMaterial = function(threeMaterial){ + this.object3D.children[0].material = threeMaterial; }; DMACell.prototype.getMaterial = function(returnTHREEObject){ diff --git a/js/materials/DMAMaterial.js b/js/materials/DMAMaterial.js index a2b90abe..ae23b7f9 100644 --- a/js/materials/DMAMaterial.js +++ b/js/materials/DMAMaterial.js @@ -16,15 +16,16 @@ define(['underscore', 'appState'], function(_, appState){ DMAMaterial.prototype.set = function(data){ + //check if colors have changed + var oldColor = this.color; + var oldAltColor = this.altColor; + var self = this; _.each(_.keys(data), function(key){ if (data[key] && data[key].x) self[key] = new THREE.Vector3(data[key].x, data[key].y, data[key].z); else self[key] = data[key]; }); - //check if colors have changed - var oldColor = this.color; - var oldAltColor = this.altColor; if (!this.threeMaterial || (data.color && oldColor != data.color) || (data.altColor && oldAltColor != data.altColor)) this.changeColorScheme();//don't need to set edited flag for this, render will handle it diff --git a/js/materials/DMAMaterials.js b/js/materials/DMAMaterials.js index 50e86911..76a0d5bb 100644 --- a/js/materials/DMAMaterials.js +++ b/js/materials/DMAMaterials.js @@ -11,7 +11,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel', 'ma color: "#ff0000", altColor: "#ff0000", noDelete: true - }) + }, "deleteMaterial") }; @@ -72,7 +72,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel', 'ma var edited = false; if (!material) { - materialsList[id] = new DMAMaterial(data); + materialsList[id] = new DMAMaterial(data, id); return; } else { if (data.elementaryChildren) data.properties = getPropertiesFromChildren(data.elementaryChildren); @@ -109,7 +109,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel', 'ma } function getDeleteMaterial(){ - return materialsList.deleteMaterial.getThreeMaterial("deleteMaterial"); + return materialsList.deleteMaterial.threeMaterial; } @@ -207,7 +207,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel', 'ma var newMaterials = {}; _.each(definitions, function(data, key){ data.noDelete = true; - newMaterials[key] = new DMAMaterial(data); + newMaterials[key] = new DMAMaterial(data, key); }); return newMaterials; } -- GitLab