Commit 3c6c6862 authored by amandaghassaei's avatar amandaghassaei

materials visibility and stl export

parent 86af735f
......@@ -668,4 +668,18 @@ label {
#comingSoon, #genericModal{
top:20%;
}
.materialVisibility{
display: block;
position: relative;
margin-bottom: 12px;
font-size: 14px;
line-height: 1.5;
min-height: 20px;
margin-top: 10px;
}
.leftOffset{
left: 30px!important;
}
\ No newline at end of file
......@@ -244,6 +244,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
DMACell.prototype._setTransparent = function(transparent){
if (transparent == this.isTransparent) return;
this.isTransparent = transparent;
this.refreshMaterial();
};
DMACell.prototype.refreshMaterial = function(){
this._setTHREEMaterial(this.getMaterial(true));
this.setWireframeVisibility(!this.isTransparent);
if (this.parts) {
......@@ -270,6 +274,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
DMACell.prototype.getVisibleGeometry = function(){//for save stl
var geometry = [];
if (this.isTransparent) return geometry;
if (this.getMaterial().isTransparent()) return geometry;
if (!this.object3D.visible) return geometry;
var mesh = this.getVisibleMesh();
if (mesh.visible) geometry.push({geo: mesh.geometry, offset:this.getPosition(), orientation:mesh.quaternion.clone().multiply(this.getOrientation())});
......
......@@ -334,6 +334,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
return cellsMax.clone().sub(cellsMin).divideScalar(2).add(cellsMin);
},
_navChanged: function(){
this.refreshCellsMaterial();
},
......
......@@ -440,6 +440,13 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
three.render();
},
refreshCellsMaterial: function(){
this._loopCells(this.cells, function(cell){
cell.refreshMaterial();
});
three.render();
},
setOpaque: function(){
this._loopCells(this.cells, function(cell){
cell.setTransparent(false);
......
......@@ -84,7 +84,6 @@ require.config({
ribbon: 'menus/otherUI/Ribbon',
modalView: 'menus/otherUI/ModalView',
console: 'menus/otherUI/Console',
contextMenu: 'menus/contextMenu/ContextMenu',
scriptView: 'menus/otherUI/ScriptView',
menuWrapper: 'menus/MenuWrapperView',
menuParent: 'menus/MenuParentView',
......@@ -166,7 +165,7 @@ require.config({
//init stuff
require(['appState', 'lattice', 'navbar', 'threeModel', 'threeView', 'globals',
'flatUI', 'bootstrapSlider', 'ribbon', 'menuWrapper', 'scriptView', 'contextMenu', 'console'],
'flatUI', 'bootstrapSlider', 'ribbon', 'menuWrapper', 'scriptView', 'console'],
function(appState, lattice, Navbar, three, ThreeView, globals){
new Navbar({model:appState});
......
......@@ -296,7 +296,9 @@ define(['underscore', 'appState', 'three'], function(_, appState, THREE){
color: randomColor,
altColor: randomColor,
noDelete: false,
properties:{}
properties:{},
hidden: false,//global material visibility setting
transparent:false//global material visibility setting
};
json = _.extend(defaults, json);
this.set(json, true);
......@@ -442,6 +444,7 @@ define(['underscore', 'appState', 'three'], function(_, appState, THREE){
console.warn("no three material found for material " + this.getID());
return null;
}
if (this.isTransparent()) return this.getTransparentMaterial();
return this.threeMaterial;
};
......@@ -489,6 +492,17 @@ define(['underscore', 'appState', 'three'], function(_, appState, THREE){
return !this.noDelete;
};
DMAMaterial.prototype.setTransparent = function(state){
this.transparent = state;
require(['lattice'], function(lattice){
lattice.refreshCellsMaterial();
});
};
DMAMaterial.prototype.isTransparent = function(){
return this.transparent && appState.get("currentNav") == "navDesign";
};
DMAMaterial.prototype.toJSON = function(){
return {
name: this.name,
......@@ -498,7 +512,9 @@ define(['underscore', 'appState', 'three'], function(_, appState, THREE){
noDelete: this.noDelete,
properties: this.getProperties(),
texture: this.texture,
mesh: this.mesh
mesh: this.mesh,
hidden: this.hidden,
transparent: this.transparent
}
};
......
......@@ -2,8 +2,8 @@
* Created by aghassaei on 1/26/15.
*/
define(['jquery', 'underscore', 'menuParent', 'plist', 'text!menus/templates/SketchMenuView.html', 'globals'],
function($, _, MenuParentView, plist, template, globals){
define(['jquery', 'underscore', 'menuParent', 'plist', 'text!menus/templates/SketchMenuView.html', 'globals', 'materialsPlist', "materials"],
function($, _, MenuParentView, plist, template, globals, materialsPlist, materials){
return MenuParentView.extend({
......@@ -17,11 +17,12 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'text!menus/templates/Ske
getPropertyOwner: function($target){
if ($target.hasClass('baseplane')) return globals.get("baseplane");
if ($target.hasClass('material')) return materials.getMaterialForId($target.data("id"));
return null;
},
_makeTemplateJSON: function(){
return _.extend(this.model.toJSON(), plist, globals.get("baseplane").toJSON());
return _.extend(this.model.toJSON(), plist, globals.get("baseplane").toJSON(), materials.toJSON(), materialsPlist);
},
_render: function(){
......
/**
* Created by aghassaei on 10/23/15.
*/
define(['jquery', 'underscore', 'backbone', 'text!menus/contextMenu/MaterialsContextMenu.html'],
function($, _, Backbone, template){
if (document.addEventListener) {
document.addEventListener('contextmenu', function(e) {
var type = getContextMenuType(e);
if (type) {
e.preventDefault();
handleContextMenuEvent(e, type);
}
}, false);
} else {
document.attachEvent('oncontextmenu', function() {
var type = getContextMenuType(window.event);
if (type) {
window.event.returnValue = false;
handleContextMenuEvent(e, type);
}
});
}
var $wrapper = $("#contextMenuWrapper");
var ContextMenu = Backbone.View.extend({
el: '#contextMenu',
object: null,
initialize: function(){
},
renderMaterialsMenu: function(e){
this.object = $(e.target).parents("label.colorSwatches").children("input").val();
var templateJSON = {};
this.$el.html(_.template(template)(templateJSON));
this.showMenu(e);
},
showMenu: function(e){
var padding = parseInt($wrapper.css("padding"));
var left = e.pageX-padding;
if ($('body').width()-200 < left) left -= 200;
$wrapper.css({left:left, top: e.pageY-padding});
$wrapper.show();
},
hideMenu: function(){
$wrapper.hide();
}
});
var contextMenu = new ContextMenu();
$wrapper.mouseleave(function(){
contextMenu.hideMenu();
});
function getContextMenuType(e){
var $target = $(e.target);
var elem = $target.get(0);
if ($target.parents("label.colorSwatches").length == 1){
return "materials";
}
return null;
}
function handleContextMenuEvent(e, type){
if (type == "materials") contextMenu.renderMaterialsMenu(e);
}
});
\ No newline at end of file
<ul>
<li>Set Transparent</li>
<li>Hide</li>
</ul>
......@@ -10,7 +10,7 @@
<li class="dropdown-submenu">
<a tabindex="-1">3D UI<span class="pull-right fui-arrow-right"></span></a>
<ul class="dropdown-menu">
<li><a class="appState boolProperty" data-property="basePlaneIsVisible" href="#">Sketch Plane</a></li>
<li><a class="appState boolProperty" data-property="basePlaneIsVisible" href="#">Selection Plane</a></li>
<li><a class="appState boolProperty<% if (currentNav != "navDesign"){ %> disabled<% } %>" data-property="highlighterIsVisible" href="#">Hover Tool</a></li>
<li><a class="appState boolProperty" data-property="axesAreVisible" href="#">Axes</a></li>
<li><a class="appState boolProperty" data-property="focusOnLattice" href="#">Center on Lattice</a></li>
......
Orientation:&nbsp;&nbsp;<div class="btn-group">
Selection Plane Orientation:&nbsp;&nbsp;<div class="btn-group">
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allBaseplaneTypes[planeType] %><span class="caret"></span></button>
<ul role="menu" class="dropdown-menu">
<% _.each(allBaseplaneTypes, function(val, key){ %>
......@@ -6,7 +6,7 @@ Orientation:&nbsp;&nbsp;<div class="btn-group">
<% }); %>
</ul>
</div><br/><br/>
Sketch Plane Height:&nbsp;&nbsp;<input data-property="zIndex" value="<%= zIndex %>" placeholder="us" class="form-control intInput baseplane" type="text"><br/>
Selection Plane Height:&nbsp;&nbsp;<input data-property="zIndex" value="<%= zIndex %>" placeholder="us" class="form-control intInput baseplane" type="text"><br/>
<label class="checkbox" for="showOneLayer">
<input id="showOneLayer" data-property="showOneLayer" type="checkbox" <% if (showOneLayer){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="appState custom-checkbox">
<span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
......@@ -15,5 +15,31 @@ Sketch Plane Height:&nbsp;&nbsp;<input data-property="zIndex" value="<%= zIndex
<input id="orientationFlipped" data-property="orientationFlipped" type="checkbox" <% if (orientationFlipped){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="baseplane custom-checkbox">
<span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
Flip orientation</label>
<br/>
Material Visibility:
<% _.each(_.keys(allMaterials[materialClass]), function(key){ %>
<% var material = materials[key];%>
<label class="checkbox colorSwatches materialVisibility">
<input data-id="<%= key %>" data-property="transparent" type="checkbox" <% if (!material.transparent){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="material custom-checkbox">
<span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
<!--<input data-property="<%= key %>" type="checkbox" <% if (material.hidden){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="leftOffset custom-checkbox">-->
<!--<span class="leftOffset 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 %><% } %>">
<% if (material.texture) {%><img src="assets/textures/<%= material.texture %>Thumb.png"><% } %>
</div>
<span><span class="materialListTitle"><%= material.name %></span></span></div>
</label>
<% }); %>
<% _.each(materials, function(material, key){ %>
<% if(material.noDelete) return; %>
<label class="checkbox colorSwatches materialVisibility">
<input data-id="<%= key %>" data-property="transparent" type="checkbox" <% if (!material.transparent){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="material custom-checkbox">
<span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
<!--<input data-property="<%= key %>" type="checkbox" <% if (material.hidden){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="leftOffset custom-checkbox">-->
<!--<span class="leftOffset 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><%= material.name %></span></span></div>
</label>
<% }); %>
\ No newline at end of file
Markdown is supported
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