Commit aec73897 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

change stock material

parent ad9d78e2
......@@ -3,7 +3,8 @@
*/
define(['underscore', 'cam', 'three', 'component', 'lattice'], function(_, cam, THREE, Component, lattice){
define(['underscore', 'cam', 'three', 'component', 'lattice', 'threeModel'],
function(_, cam, THREE, Component, lattice, three){
function StockComponent(id, json){
......@@ -33,6 +34,11 @@ define(['underscore', 'cam', 'three', 'component', 'lattice'], function(_, cam,
//todo rotation
};
StockComponent.prototype.setMaterial = function(materialName){
this.cell.changeMaterial(materialName);
three.render();
};
......@@ -67,6 +73,7 @@ define(['underscore', 'cam', 'three', 'component', 'lattice'], function(_, cam,
StockComponent.prototype.toJSON = function(){
var json = Component.prototype.toJSON.call(this);
json.material = this.cell.materialName
return json;
};
......
......@@ -243,9 +243,16 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
};
DMACell.prototype.setMaterial = function(material){
this.materialName = material;
this.object3D.children[0].material = material;
};
DMACell.prototype.changeMaterial = function(materialName, materialObject){
this.materialName = materialName;
if (materialObject === undefined) materialObject = materials.getMaterialForId(materialName).threeMaterial;
this.object3D.children[0].material = materialObject;
};
DMACell.prototype.setWireframeVisibility = function(visible, mode){
if (visible && mode === undefined) mode = this.getConditionalMode(appState.get("cellMode"));
this.object3D.children[1].visible = visible && this.object3D.children[1].name == mode;
......
......@@ -72,6 +72,9 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
return deleted;
}
function getMaterialForId(id){
return materialsList[id];
}
......@@ -251,6 +254,7 @@ define(['underscore', 'three', 'appState', 'lattice', 'plist', 'threeModel'], fu
return {
list: materialsList,
setMaterial: setMaterial,
getMaterialForId: getMaterialForId,
getCompositeKeys: getCompositeKeys,
getVaildAvailableCompositeKeys: getVaildAvailableCompositeKeys,
getChildCellTypes:getChildCellTypes,
......
......@@ -3,8 +3,8 @@
*/
define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponentMenuTemplate'],
function($, _, MenuParentView, plist, cam, template){
define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'materials', 'text!editComponentMenuTemplate'],
function($, _, MenuParentView, plist, cam, materials, template){
return MenuParentView.extend({
......@@ -13,7 +13,8 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponen
"click #deleteComponent": "_delete",
"click .removeChild": "_removeChild",
"click .addChild": "_addChild",
"click .changeParent": "_changeParent"
"click .changeParent": "_changeParent",
"click .stockMaterial": "_changeStockMaterial"
},
_initialize: function(){
......@@ -69,6 +70,15 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponen
this.render();
},
_changeStockMaterial: function(e){
e.preventDefault();
var $target = $(e.target);
var id = $target.data("id");
if (id === undefined) id = $target.closest("a").data("id");
cam.get("assembler").getComponent(cam.get("editingComponent")).setMaterial(id);
this.render();
},
_makeTemplateJSON: function(){
var assembler = cam.get("assembler");
var editingComponent = cam.get("editingComponent");
......@@ -82,8 +92,8 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'cam', 'text!editComponen
if (!correctBranch || assembler.tree[editingComponent] >= level) return;
allDescendants.push(id);
});
return _.extend(this.model.toJSON(), cam.toJSON(), assembler.toJSON(),
{thisComponent: component.toJSON(), ancestors:allAncestors, descendants:allDescendants});
return _.extend(this.model.toJSON(), cam.toJSON(), assembler.toJSON(), plist,
{thisComponent: component.toJSON(), ancestors:allAncestors, descendants:allDescendants, materials:materials.list});
},
template: _.template(template)
......
......@@ -53,6 +53,29 @@ Parent:   
<br/>
<a id="uploadStl" href="#" class="btn btn-block btn-lg btn-default">Upload STL</a><br/>
STL: &nbsp;&nbsp;STL Name<br/><br/>
<% } else { %>
Material: &nbsp;&nbsp;
<div class="btn-group">
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= materials[thisComponent.material].name %><span class="caret"></span></button>
<ul role="menu" class="dropdown-menu">
<% _.each(allMaterials[materialClass], function(material, key){ %>
<li><a class="stockMaterial dropdownSelector" data-id="<%= key %>" href="#">
<div class="materialColorSwatch">
<div style="background-color:<% if(realisticColorScheme){ %><%= material.color %><% }else{ %><%= material.altColor %><% } %>"></div>
<span><span class="materialListTitle"><%= material.name %></span></span></div>
</a></li>
<% }); %>
<% _.each(materials, function(material, key){
if (key.substr(0,5) == "super") return;
if (material.noDelete) return; %>
<li><a class="stockMaterial dropdownSelector" data-id="<%= key %>" href="#">
<div class="materialColorSwatch">
<div style="background-color:<% if(realisticColorScheme){ %><%= material.color %><% }else{ %><%= material.altColor %><% } %>"></div>
<span class="materialListTitle"><%= material.name %></span></div>
</a></li>
<% }); %>
</ul>
</div><br/><br/>
<% } %>
Offset (xyz):&nbsp;&nbsp;
<input data-property="translation" data-key="x" value="<%= translation.x %>" placeholder="X" class="form-control floatInput stl" type="text">&nbsp;
......
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