diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js index 896ca91a731f7f1c1635a9f078b36e0906c7b3a1..4ae136ea2fc05e7799f4ec588e42d7c805d6ec75 100644 --- a/js/lattice/CompositeEditorLattice.js +++ b/js/lattice/CompositeEditorLattice.js @@ -16,11 +16,15 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre defaults: _.extend(LatticeBase.prototype.defaults, { name: "", - color: makeRandomColor() + color: null }), __initialize: function(options){ - if (options.id === undefined) this.set("id", this.cid); + if (!options.id || options.id == "") this.set("id", this.cid); + if (!options.color || options.color == "") this.set("color", makeRandomColor(), {silent:true}); + this.set("numCells", 3);//todo remove this + this.set("cellsMin", new THREE.Vector3(0,0,0)); + this.set("cellsMax", new THREE.Vector3(0,0,0)); }, initLatticeSubclass: function(subclass){ @@ -59,7 +63,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre color: this.get("color"), altColor: this.get("color"), numCells: this.get("numCells"), - cells: JSON.parse(JSON.stringify(this.compositeCells)), + cells: JSON.parse(JSON.stringify(this.cells)), cellsMin: this.get("cellsMin").clone(), cellsMax: this.get("cellsMax").clone(), dimensions: new THREE.Vector3().subVectors(this.get("cellsMax"), this.get("cellsMin")) @@ -73,8 +77,12 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }, destroy: function(){ + this.clearCells(true); var self = this; - lattice.showCells(); + _.each(_.keys(this.attributes), function(key){ + self.set(key, null, {silent:true}); + self.unset(key, {silent:true}); + }); } }); diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 8aa021f2ecc87605585aac38e01c6c7421e4e074..90074f6dd02d7fc8c36cfab2b5b64a2ec27cb9ce 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -164,7 +164,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre _navChanged: function(){ var currentNav = appState.get("currentNav"); - if (!this.inCompositeMode() && this._undoCompositeEditor) this._undoCompositeEditor(); + if (!this.inCompositeMode() && this.exitCompositeEditing) this.exitCompositeEditing(); }, _updateCellSeparation: function(){ @@ -179,6 +179,11 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre three.render(); }, + __clearCells: function(silent){ + this.set("nodes", [], {silent:silent}); + if (globals.basePlane) globals.basePlane.set("zIndex", 0, {silent:silent}); + }, + @@ -258,8 +263,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return appState.get("currentNav") == "navComposite"; }, - clearCompositeCells: function(){ - + exitCompositeEditing: function(){ + if (this.compositeEditor) this.compositeEditor.destroy(); + this.compositeEditor = null; + this.showCells(); }, diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index ada87bb26adf73d065b3eb965683048dd8f18ded..0e2db9350168b4074e4b925cb9ec1c3897d5d5e2 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -116,18 +116,18 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre three.render(); }, - clearCells: function(){ + clearCells: function(silent){ + if (silent === undefined) silent = false; this._loopCells(this.sparseCells, function(cell){//send destroy to top level if (cell) cell.destroy(); }); three.removeAllCells();//todo add flag in cell destroy to avoid redundancy here this.cells = [[[null]]]; this.sparseCells = [[[null]]]; - this.set("cellsMax", null); - this.set("cellsMin", null); - this.set("nodes", []); - this.set("numCells", 0); - if (globals.basePlane) globals.basePlane.set("zIndex", 0); + this.set("cellsMax", null, {silent:silent}); + this.set("cellsMin", null, {silent:silent}); + this.set("numCells", 0, {silent:silent}); + if (this.__clearCells) this.__clearCells(silent); three.render(); }, diff --git a/js/menus/CompositeMenu.js b/js/menus/CompositeMenu.js index aa793393cc76981c0b987293ab1549c266b25c5b..2017ee1176cb5261170c96ad8aed5577fe58419d 100644 --- a/js/menus/CompositeMenu.js +++ b/js/menus/CompositeMenu.js @@ -16,7 +16,11 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ _initialize: function(){ - this.listenTo(lattice, "change", this.render); + if (!lattice.compositeEditor) { + console.warn("no composite editor inited"); + return; + } + this.listenTo(lattice.compositeEditor, "change", this.render); }, _updateDimensions: function(cells){ @@ -27,7 +31,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ _changeRandomColor: function(e){ e.preventDefault(); - lattice._changeRandomColor(); + lattice.compositeEditor._changeRandomColor(); }, updateHex: function(hex){ @@ -38,12 +42,12 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ _finishComposite: function(e){ e.preventDefault(); this.stopListening(); - if (!lattice.makeNewCompositeMaterial){ + if (!lattice.compositeEditor){ console.warn("lattice not in composite mode for finish composite call"); this._exit(); return; } - lattice.makeNewCompositeMaterial($("#compositeName").val()); + lattice.compositeEditor.makeNewCompositeMaterial($("#compositeName").val()); this._exit(); }, @@ -58,12 +62,12 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ _deleteComposite: function(e){ e.preventDefault(); - if (!lattice.deleteComposite){ + if (!lattice.compositeEditor){ console.warn("lattice not in composite mode for delete composite call"); this._exit(); return; } - lattice.deleteComposite(); + lattice.compositeEditor.deleteComposite(); this._exit(); },