From b44ec8974bc99ef96c3982952660bb073326c3eb Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 22 Sep 2015 01:49:18 -0400
Subject: [PATCH] starting composite material class

---
 js/materials/DMACompositeMaterial.js | 37 ++++++++++++++++++++++++++++
 js/materials/DMAMaterial.js          | 14 ++++++++---
 2 files changed, 48 insertions(+), 3 deletions(-)
 create mode 100644 js/materials/DMACompositeMaterial.js

diff --git a/js/materials/DMACompositeMaterial.js b/js/materials/DMACompositeMaterial.js
new file mode 100644
index 00000000..0bc338f9
--- /dev/null
+++ b/js/materials/DMACompositeMaterial.js
@@ -0,0 +1,37 @@
+/**
+ * Created by aghassaei on 9/22/15.
+ */
+
+
+define(['material'], function(DMAMaterial){
+
+    function DMACompositeMaterial(data){
+        DMAMaterial.call(this, data);
+    }
+    DMACompositeMaterial.prototype = Object.create(DMAMaterial.prototype);
+
+    DMACompositeMaterial.prototype.set = function(data){
+        var edited = DMAMaterial.prototype.set.call(this, data);
+        if (this.sparseCells) edited |= !(_.isEqual(data.sparseCells, this.sparseCells));
+        return edited;
+    };
+
+    DMACompositeMaterial.prototype.getDimensions = function(){
+        return this.dimensions.clone();
+    };
+
+    DMACompositeMaterial.prototype.isComposite = function(){
+        return true;
+    };
+
+    DMACompositeMaterial.prototype.toJSON = function(){
+        return {
+                name: this.name,
+                color: this.color,
+                altColor: this.altColor,
+                noDelete: this.noDelete,
+                properties: this.properties
+            }
+    };
+
+});
\ No newline at end of file
diff --git a/js/materials/DMAMaterial.js b/js/materials/DMAMaterial.js
index de5904a1..c695d4bb 100644
--- a/js/materials/DMAMaterial.js
+++ b/js/materials/DMAMaterial.js
@@ -3,7 +3,7 @@
  */
 
 
-define(['appState'], function(appState){
+define(['underscore', 'appState'], function(_, appState){
 
     function DMAMaterial(json){
         this.set(json);
@@ -16,7 +16,6 @@ define(['appState'], function(appState){
         var oldAltColor = this.altColor;
 
         var edited = false;
-        if (this.sparseCells) edited = !(_.isEqual(data.sparseCells, this.sparseCells));
 
         var self = this;
         _.each(_.keys(data), function(key){
@@ -27,6 +26,8 @@ define(['appState'], function(appState){
         if (!this.threeMaterial || oldColor != this.color || oldAltColor != this.altColor) this.changeColorScheme();
 
         if (!data.noDelete) this.noDelete = false;
+
+        return edited;
     };
 
     DMAMaterial.prototype.changeColorScheme = function(state){
@@ -70,6 +71,10 @@ define(['appState'], function(appState){
         return false;
     };
 
+    DMAMaterial.prototype.isComposite = function(){
+        return false;
+    };
+
     DMAMaterial.prototype.getProperties = function(){
         return this.properties;
     };
@@ -93,7 +98,10 @@ define(['appState'], function(appState){
     };
 
     DMAMaterial.prototype.destroy = function(){
-
+        var self = this;
+        _.each(this, function(property, key){
+            self[key] = null;
+        });
     };
 
     return DMAMaterial;
-- 
GitLab