Skip to content
Snippets Groups Projects
Commit 88811bb7 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

materials api

parent 17698bb0
No related branches found
No related tags found
No related merge requests found
......@@ -587,6 +587,7 @@ label {
border-bottom-width: 0;
border-top-width: 0;
overflow: auto;
overflow-x: hidden;
resize: vertical;
padding: 8px 20px;
font-family: Courier, monospace;
......
......@@ -3,12 +3,15 @@
*/
define(['materials'], function(materials){
define(['materials', 'console'], function(materials, myConsole){
function _printGetter(output){
myConsole.log(output);
}
return {
init: function(json){//create a new material
newMaterial: function(json){//create a new material
return materials.newMaterial(json);//return DMAMaterial object
},
......@@ -17,7 +20,9 @@ define(['materials'], function(materials){
},
getMaterialForId: function(id){
return materials.getMaterialForId(id);
var output = materials.getMaterialID(id);
_printGetter(output);
return output;
},
getMaterials: function(){
......
......@@ -3,8 +3,8 @@
*/
//everything is a top level material with a threeMaterial object
define(['underscore', 'three', 'appState', 'lattice', 'materialsPlist', 'threeModel', 'material', 'compositeMaterial'],
function(_, THREE, appState, lattice, materialsPlist, three, DMAMaterial, DMACompositeMaterial){
define(['underscore', 'three', 'appState', 'lattice', 'materialsPlist', 'threeModel', 'material', 'compositeMaterial', 'console'],
function(_, THREE, appState, lattice, materialsPlist, three, DMAMaterial, DMACompositeMaterial, myConsole){
var materialsList = {
......@@ -15,10 +15,10 @@ define(['underscore', 'three', 'appState', 'lattice', 'materialsPlist', 'threeMo
color: "#ff0000",
altColor: "#ff0000",
noDelete: true
});
}, {silent:true} );
var compositeID = 0;
var materialID = 0;
var compositeID = 1;
var materialID = 1;
function getNextCompositeID(){
return "super" + compositeID++;
......@@ -40,7 +40,8 @@ define(['underscore', 'three', 'appState', 'lattice', 'materialsPlist', 'threeMo
function newMaterial(data, noAdd){
function newMaterial(data, options){
options = options || {};
var material, id;
if (data.sparseCells) {
id = data.id || getNextCompositeID();
......@@ -50,9 +51,10 @@ define(['underscore', 'three', 'appState', 'lattice', 'materialsPlist', 'threeMo
material = new DMAMaterial(data, id);
}
if (noAdd) return material;//in the new material menu, you may init a material before saving changes
if (options.noAdd) return material;//in the new material menu, you may init a material before saving changes
materialsList[id] = material;
if (!options.silent) myConsole.write("materials.newMaterial(" + JSON.stringify(material.toJSON()) + "}");
return material;
}
......@@ -61,11 +63,14 @@ define(['underscore', 'three', 'appState', 'lattice', 'materialsPlist', 'threeMo
console.warn("this material was never saved");
return true;
}
if (!materialsList[id].canDelete()) {
console.warn("no delete flag on this material type");
var material = materialsList[id];
if (!material.canDelete()) {
myConsole.warn("noDelete flag on this material type, deleteMaterial operation cancelled");
return false;
}
materialsList[id].destroy();
myConsole.write("materials.deleteMaterial(" + id + "}");
myConsole.log(JSON.stringify(material.toJSON()));
material.destroy();
materialsList[id] = null;
delete materialsList[id];//todo check if being used first (instances)
var deleted = true;
......@@ -90,6 +95,8 @@ define(['underscore', 'three', 'appState', 'lattice', 'materialsPlist', 'threeMo
edited = material.set(data);
}
myConsole.write("materials.setMaterial(" + id + ", " + JSON.stringify(material.toJSON()) + "}");
if (edited){
var allChangedMaterialsList = getAllParentComposites(id);
allChangedMaterialsList.push(id);
......@@ -217,7 +224,8 @@ define(['underscore', 'three', 'appState', 'lattice', 'materialsPlist', 'threeMo
var newMaterials = {};
_.each(definitions, function(data, key){
data.noDelete = true;
newMaterials[key] = new DMAMaterial(data, key);
data.id = key;
newMaterial(data, {silent:true});
});
return newMaterials;
}
......
......@@ -26,7 +26,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'materials', 'text!menus/
var json = {};
if (material) json = material.toJSON();
this.material = materials.newMaterial(json, true);
this.material = materials.newMaterial(json, {noAdd: true});
},
getPropertyOwner: function($target){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment