Commit 390926db authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

edit elementary materials

parent cffaf1fe
......@@ -8,7 +8,8 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
var materialsList = {
deleteMaterial: {
color: "#ff0000",
threeMaterial: makeMaterialObject("#ff0000")
threeMaterial: makeMaterialObject("#ff0000"),
noDelete: true
}
};
......@@ -29,7 +30,10 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
function setMaterial(id, data){
if (id && data === null) return deleteMaterial(id);
if (!materialsList[id]) materialsList[id] = {};
//check if colors have changed
var oldColor = materialsList[id].color;
var oldAltColor = materialsList[id].altColor;
var edited = false;
if (materialsList[id].sparseCells) edited = !(_.isEqual(data.sparseCells, materialsList[id].sparseCells));
......@@ -41,7 +45,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
else materialsList[id][key] = data[key];
});
if (!materialsList[id].threeMaterial || oldColor != materialsList[id].color) changeSingleMaterialColorScheme(id);
if (!materialsList[id].threeMaterial || oldColor != materialsList[id].color || oldAltColor != materialsList[id].altColor) changeSingleMaterialColorScheme(id);
if (edited){
var allChangedMaterialsList = getAllParentComposites(id);
allChangedMaterialsList.push(id);
......@@ -53,6 +57,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
lattice.reinitAllCellsOfTypes(allChangedMaterialsList);
}
console.log(materialsList);
return false;
}
......@@ -62,7 +67,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
console.warn("no delete flag on this material type");
return false;
}
delete materialsList[id];//todo check if being used first
delete materialsList[id];//todo check if being used first (instances)
var deleted = true;
if (deleted) setToDefaultMaterial();
return deleted;
......@@ -223,12 +228,35 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
}
}
//edit material definition
var editingMaterial = null;//material definition currently being edited
function setEditingMaterial(id){
editingMaterial = id;
}
function getEditingMaterial(){
return editingMaterial;
}
return {
list: materialsList,
setMaterial: setMaterial,
getCompositeKeys: getCompositeKeys,
getVaildAvailableCompositeKeys: getVaildAvailableCompositeKeys,
getChildCellTypes:getChildCellTypes,
setToDefaultMaterial: setToDefaultMaterial
setToDefaultMaterial: setToDefaultMaterial,
setEditingMaterial: setEditingMaterial,
getEditingMaterial: getEditingMaterial
};
});
\ No newline at end of file
......@@ -20,7 +20,15 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'materials', 'text!materi
_initialize: function(){
//bind events
this.material = _.clone(materials.list[this.model.get("materialType")]);
if (!materials.getEditingMaterial()) console.warn("no editing material id set");
this.material = _.clone(materials.list[materials.getEditingMaterial()]);
if (!this.material) this.material = {
name: "Material " + materialNameIndex++,
color: '#000000',
altColor: '#000000',
noDelete: false
};
},
getPropertyOwner: function($target){
......@@ -42,24 +50,20 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'materials', 'text!materi
_save: function(e){
e.preventDefault();
var name = this.material.name;
if (name == "") name = "Material " + materialNameIndex++;
materials.setMaterial(this.model.get("materialType"), {
name: name,
color: this.material.color,
altColor: this.material.altColor
});
if (this.material.name == "") this.material.name = "Material " + materialNameIndex++;
materials.setMaterial(materials.getEditingMaterial(), _.clone(this.material));
this._exit();
},
_saveMaterialToFile: function(e){
e.preventDefault();
fileSaver.saveMaterial(this.model.get("materialType"));
fileSaver.saveMaterial(materials.getEditingMaterial(), this.material);
},
_deleteMaterial: function(e){
e.preventDefault();
var deleted = materials.setMaterial(this.model.get("materialType"), null);
if (!materials.list(materials.getEditingMaterial())) this.exit();
var deleted = materials.setMaterial(materials.getEditingMaterial(), null);
if (deleted) this._exit();
},
......@@ -69,6 +73,8 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'materials', 'text!materi
},
_exit: function(){
this.material = null;
materials.setEditingMaterial(null);
this.model.set("currentNav", "navDesign");
},
......
......@@ -46,17 +46,12 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals', 'ma
e.preventDefault();
//first create dummy material
var id = "material" + this.cid + materialID++;
materials.setMaterial(id, {
name: "",
color: '#000000',
altColor: '#000000',
noDelete: false
});
this._openMaterialEditor(id);
},
_openMaterialEditor: function(id){
this.model.set("materialType", id);
console.log(id);
materials.setEditingMaterial(id);
this.model.set("currentTab", "materialEditor", {silent:true});
this.model.set("currentNav", "navMaterial");
},
......
......@@ -13,15 +13,25 @@ Material Class:   
<label class="radio colorSwatches">
<input type="radio" <%if (key == materialType){ %>checked<%}%> name="materialType" value="<%= key %>" data-toggle="radio" class="custom-radio appState"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
<div class="materialColorSwatch">
<div style="background-color:<% if(realisticColorScheme){ %><%= allMaterials[materialClass][key].color %><% }else{ %><%= allMaterials[materialClass][key].altColor %><% } %>"></div>
<span><span class="materialListTitle"><%= allMaterials[materialClass][key].name %></span><a data-id="<%= key %>" class="editMaterial">Edit...</a></span></div>
<div style="background-color:<% if(realisticColorScheme){ %><%= materials[key].color %><% }else{ %><%= materials[key].altColor %><% } %>"></div>
<span><span class="materialListTitle"><%= materials[key].name %></span><a data-id="<%= key %>" class="editMaterial">Edit...</a></span></div>
</label>
<% }); %>
<% _.each(materials, function(material, key){
if (key.substr(0,5) == "super") return;
if (material.noDelete) return; %>
<label class="radio colorSwatches">
<input type="radio" <%if (key == materialType){ %>checked<%}%> name="materialType" value="<%= key %>" data-toggle="radio" class="custom-radio appState"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
<div class="materialColorSwatch">
<div style="background-color:<% if(realisticColorScheme){ %><%= material.color %><% }else{ %><%= material.altColor %><% } %>"></div>
<span><span class="materialListTitle"><%= material.name %></span><a data-id="<%= key %>" class="editMaterial">Edit...</a></span></div>
</label>
<% }); %>
<!--<a id="newElementaryMaterial" href="#" class="btn btn-block btn-lg btn-default">+ Create New Material Definition</a>-->
<br/><label class="checkbox" for="realisticColorScheme">
<label class="checkbox" for="realisticColorScheme">
<input id="realisticColorScheme" data-property="realisticColorScheme" type="checkbox" <% if (realisticColorScheme){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="appState custom-checkbox">
<span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
Use realistic color scheme</label>
Use realistic color scheme</label><br/>
<a id="newElementaryMaterial" href="#" class="btn btn-block btn-lg btn-default">+ Create New Material Definition</a>
<% } %><br/>
Composite Materials:<br/>
<% if ((cellType == "octa" && connectionType != "vertex") || cellType == "tetra"){ %>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment