diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js index 732517ae302f6427f11f19b173b3dfe46a02ca4d..fa56e321ec8f8e9a6adc05c6e0a3512afd20b7e5 100644 --- a/js/lattice/CompositeEditorLattice.js +++ b/js/lattice/CompositeEditorLattice.js @@ -6,24 +6,25 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'three', 'threeModel'], function(_, Backbone, appState, lattice, globals, plist, THREE, three){ - var defaults = { - compositeId: null, - compositeColor: makeRandomColor(), - numCompositeCells:0, - compositeCellsMin: null, - compositeCellsMax: null - }; - function makeRandomColor(){ return '#' + Math.floor(Math.random()*16777215).toString(16); } - var CompositeEditorLattice = { - + var defaults = {}; + var compositeId = 0; + var CompositeEditorLattice = { _initCompositeEditor: function(id, data){ + _.extend(defaults, { + compositeId: "composite" + compositeId++,//todo real unique id + compositeColor: makeRandomColor(), + numCompositeCells:0, + compositeCellsMin: null, + compositeCellsMax: null + }); + var self = this; _.each(_.keys(defaults), function(key){ self.set(key, defaults[key], {silent:true}); @@ -34,7 +35,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th _.each(_.keys(data), function(key){ self.set(key, defaults[key], {silent:true}); }); - this.compositeCells = data.cells;//todo + this.compositeCells = data.cells;//todo parse cells this.set("compositeId", id, {silent:true}); } }, @@ -43,13 +44,20 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th this.set("compositeColor", makeRandomColor()); }, - _makeNewCompositeMaterial: function(name){ + makeNewCompositeMaterial: function(name){ + if (this.get("numCompositeCells") == 0) { + console.warn("no cells in this composite"); + return; + } var id = this.get("compositeId"); var data = { name: name, color: this.get("compositeColor"), altColor: this.get("compositeColor"), numCells: this.get("numCompositeCells"), + cells: JSON.stringify(this.get("compositeCells")), + cellsMin: this.get("compositeCellsMin").clone(), + cellsMax: this.get("compositeCellsMax").clone(), dimensions: new THREE.Vector3.subVectors(this.get("compositeCellsMax"), this.get("compositeCellsMin")) }; globals.materials.id = data;//todo trigger change on all instances @@ -65,6 +73,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th self.unset(key, {silent:true}); }); this.compositeCells = null; + console.log("done undo"); } }; diff --git a/js/menus/CompositeMenu.js b/js/menus/CompositeMenu.js index 0557449adc1606015dbb9e16975e8f68e855c0a1..00854a7731ace59bade96a358a8d26217299472c 100644 --- a/js/menus/CompositeMenu.js +++ b/js/menus/CompositeMenu.js @@ -31,6 +31,8 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ _finishComposite: function(e){ e.preventDefault(); + console.log("here"); + lattice.makeNewCompositeMaterial(); this.model.set("currentNav", "navDesign"); },