diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index b20f0ec53aaf9675d1649b5b907c8da68b0e658e..5b2c8e29beeee457bc8afb12ece28cb8ed64c324 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -182,14 +182,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }, calculateBoundingBox: function(){ - var scale = this._allAxesScales(); - var min = _.clone(this.get("cellsMin")); - var max = _.clone(this.get("cellsMax")); - _.each(_.keys(scale), function(key){ - min[key] *= scale[key]; - max[key] *= scale[key]; - }); - return {min:min, max:max}; + if (!this.get("cellsMax") || !this.get("cellsMin")) return new THREE.Vector3(0,0,0); + return (new THREE.Vector3()).subVectors(this.get("cellsMax"), this.get("cellsMin")).add(new THREE.Vector3(1,1,1)); }, diff --git a/js/menus/CompositeMenu.js b/js/menus/CompositeMenu.js index 9e51a21be81254aace0d283e524fd5e48edda3b5..5c464084d1eae3870405ac7f5d41a41af5478b59 100644 --- a/js/menus/CompositeMenu.js +++ b/js/menus/CompositeMenu.js @@ -2,7 +2,7 @@ * Created by aghassaei on 6/10/15. */ -define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _, MenuParentView, plist, lattice){ +define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals'], function($, _, MenuParentView, plist, lattice, globals){ return MenuParentView.extend({ @@ -23,12 +23,6 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ this.listenTo(lattice.compositeEditor, "change", this.render); }, - _updateDimensions: function(cells){ - this.material.dimensions.x = cells.length; - this.material.dimensions.y = cells[0].length; - this.material.dimensions.z = cells[0][0].length; - }, - _changeRandomColor: function(e){ e.preventDefault(); lattice.compositeEditor._changeRandomColor(); @@ -76,18 +70,41 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ }, _makeTemplateJSON: function(){ - return _.extend(lattice.compositeEditor.toJSON()); + return _.extend(plist, this.model.toJSON(), globals, lattice.compositeEditor.toJSON(), + { + materialClass:lattice.get("materialClass"), + materialType:lattice.get("materialType"), + dimensions: lattice.compositeEditor.calculateBoundingBox() + }); }, template: _.template('\ <a href="#" class="btn btn-halfWidth btn-lg btn-default importJSON">Load Composite</a>\ <a id="saveComposite" href="#" class="btn btn-halfWidth btn-lg pull-right btn-default">Save Composite</a><br/><br/>\ Name: <input id="compositeName" data-property="name" value="<%= name %>" placeholder="Enter Name" class="seventyFiveWidth form-control textInput compositeEditor" type="text"><br/><br/>\ - Num Cells: <%= numCells %><br/><br/>\ - Bounding Box: ()<br/><br/>\ + Num Cells: <%= numCells %><br/><br/>\ + Bounding Box: <%= dimensions.x %> x <%= dimensions.y %> x <%= dimensions.z %><br/><br/>\ Display Color: \ <input id="compositeColor" style="border-color: <%= color %> ;" data-property="color" value="<%= color %>" placeholder="Enter HEX" class="halfWidth compositeEditor form-control hexInput" type="text"><br/><br/>\ - <a id="newRandomColor" href="#" class="btn btn-block btn-lg btn-default">New Random Color</a><br/><br/>\ + <a id="newRandomColor" href="#" class="btn btn-block btn-lg btn-default">New Random Color</a><br/>\ + Available Materials:<br/>\ + <% _.each(_.keys(allMaterials[materialClass]), function(key){ %>\ + <label class="radio colorSwatches">\ + <input type="radio" <%if (key == materialType){ %>checked<%}%> name="materialType" value="<%= key %>" data-toggle="radio" class="custom-radio lattice"><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><%= allMaterials[materialClass][key].name %></span></div>\ + </label>\ + <% }); %>\ + <% _.each(_.keys(materials.compositeMaterials), function(key){ \ + if (key == id) return; %>\ + <label class="radio colorSwatches">\ + <input type="radio" <%if (key == materialType){ %>checked<%}%> name="materialType" value="<%= key %>" data-toggle="radio" class="custom-radio lattice"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ + <div class="materialColorSwatch">\ + <div style="background-color:<% if(realisticColorScheme){ %><%= materials.compositeMaterials[key].color %><% }else{ %><%= materials.compositeMaterials[key].altColor %><% } %>"></div>\ + <span><%= materials.compositeMaterials[key].name %></span></div>\ + </label>\ + <% }); %><br/>\ <a id="finishComposite" href="#" class="btn btn-block btn-lg btn-success">Finish Composite</a><br/>\ <a id="cancelComposite" href="#" class="btn btn-halfWidth btn-lg btn-default">Cancel / Exit</a>\ <a id="deleteComposite" href="#" class="btn btn-halfWidth pull-right btn-lg btn-default"><span class="fui-trash"></span> Delete</a><br/>\ diff --git a/js/menus/MenuParentView.js b/js/menus/MenuParentView.js index 176ab925ed2f431670338c5d309fa43800ed0abb..4ac9728d8d4b5cd327784ba05208d0938069fdda 100644 --- a/js/menus/MenuParentView.js +++ b/js/menus/MenuParentView.js @@ -19,7 +19,7 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone){ render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if ($("input[type=text]").is(":focus")) return; - this.$el.html(this.template(this._makeTemplateJSON())); + if (this._preRender) this._preRender(); this.$el.html(this.template(this._makeTemplateJSON())); if (this._render) this._render(); },