From a23292c30f05b0f23b54521d6fecf724084c0c7d Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Thu, 11 Jun 2015 15:05:22 -0700 Subject: [PATCH] composite lattice setup --- js/lattice/CompositeEditorLattice.js | 49 ++++++++++++++++------------ js/lattice/Lattice.js | 5 ++- js/lattice/LatticeBase.js | 2 ++ 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js index 2c4920fb..77ce53e1 100644 --- a/js/lattice/CompositeEditorLattice.js +++ b/js/lattice/CompositeEditorLattice.js @@ -15,13 +15,22 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre var CompositeEditorLattice = LatticeBase.extend({ defaults: _.extend(LatticeBase.prototype.defaults, { - compositeName: "", - compositeColor: makeRandomColor() + name: "", + color: makeRandomColor() }), __initialize: function(options){ console.log(options); - this.set("id", this.cid); + console.log(this); + + if (options.id) this.set("id", options.id); + else this.set("id", this.cid); + + if (options.data){ + _.each(_.keys(data), function(key){ + self.set(key, data[key], {silent:true}); + }); + } }, initLatticeSubclass: function(subclass){ @@ -30,17 +39,17 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre _.extend(self, subclassObject); - //copy over cells to new lattice type - var cells = self.cells; - self._loopCells(cells, function(cell, x, y, z){ - if (!cell) return; - var index = _.clone(cell.index); - if (cell.destroy) cell.destroy(); - self.makeCellForLatticeType(index, function(newCell){ - cells[x][y][z] = newCell; - }); - }); - three.render(); +// //copy over cells to new lattice type +// var cells = self.cells; +// self._loopCells(cells, function(cell, x, y, z){ +// if (!cell) return; +// var index = _.clone(cell.index); +// if (cell.destroy) cell.destroy(); +// self.makeCellForLatticeType(index, function(newCell){ +// cells[x][y][z] = newCell; +// }); +// }); +// three.render(); }); }, @@ -57,13 +66,13 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre var id = this.get("id"); var data = { name: name, - color: this.get("compositeColor"), - altColor: this.get("compositeColor"), - numCells: this.get("numCompositeCells"), + color: this.get("color"), + altColor: this.get("color"), + numCells: this.get("numCells"), cells: JSON.parse(JSON.stringify(this.compositeCells)), - cellsMin: this.get("compositeCellsMin").clone(), - cellsMax: this.get("compositeCellsMax").clone(), - dimensions: new THREE.Vector3().subVectors(this.get("compositeCellsMax"), this.get("compositeCellsMin")) + cellsMin: this.get("cellsMin").clone(), + cellsMax: this.get("cellsMax").clone(), + dimensions: new THREE.Vector3().subVectors(this.get("cellsMax"), this.get("cellsMin")) }; globals.materials.compositeMaterials[id] = data;//todo trigger change on all instances }, diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 9ede3c2d..96de87a7 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -248,7 +248,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre console.warn("composite editor already allocated"); self.compositeEditor.destroy(); } - self.compositeEditor = new CompositeEditorLattice(); + self.compositeEditor = new CompositeEditorLattice({ + id: id, + data: data + }); self.compositeEditor.initLatticeSubclass(self._getSubclassForLatticeType()); appState.set("currentNav", "navComposite"); }); diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index ada87bb2..ee32cc55 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -23,6 +23,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre initialize: function(options){ + console.log(this); + this.cells = [[[null]]];//3D matrix containing all cells and null, dynamic size this.sparseCells = [[[null]]];//3D matrix containing highest hierarchical level of cells and null -- GitLab