From b6744e67b1f914ec74328d81c05ca48ac3ce25b2 Mon Sep 17 00:00:00 2001 From: amandaghassaei <amandaghassaei@gmail.com> Date: Mon, 23 Mar 2015 12:36:17 -0400 Subject: [PATCH] removed should preserve cells on lattice change --- js/models/Lattice.js | 67 ++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/js/models/Lattice.js b/js/models/Lattice.js index f6074323..5785a5a3 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -18,8 +18,6 @@ Lattice = Backbone.Model.extend({ basePlane: null,//plane to build from scale: 20, highlighter: null,//highlights build-able surfaces - //todo this is not exposed in ui, is that useful? - shouldPreserveCells: true,//preserve cells when changing lattice type //spacing for connectors/joints cellSeparation: {xy:0, z:0}, @@ -382,7 +380,6 @@ Lattice = Backbone.Model.extend({ if (typeof loadingFromFile == "undefined") loadingFromFile = false; var cellType = this.get("cellType"); var connectionType = this.get("connectionType"); - if (!loadingFromFile && !this.get("shouldPreserveCells")) this.clearCells(); if (this._undo) this._undo(); if (this.get("basePlane")) this.get("basePlane").destroy(); if (this.get("highlighter")) this.get("highlighter").destroy(); @@ -412,39 +409,37 @@ Lattice = Backbone.Model.extend({ this._initLatticeType(); //todo refactor this eventually - if (loadingFromFile || this.get("shouldPreserveCells")){ - var self = this; - var scale = this.get("scale"); - var cells = this.get("cells"); - this._loopCells(cells, function(cell, x, y, z){ - if (!cell) return; - - var index = _.clone(cell.indices); - //var parts = null; - //if (loadingFromFile) parts = _.clone(cell.parts); - if (cell.parentOrientation) var parentOrientation = new THREE.Quaternion(cell.parentOrientation._x, cell.parentOrientation._y, cell.parentOrientation._z, cell.parentOrientation._w); - if (cell.parentPosition) var parentPos = cell.parentPosition; - if (cell.direction) var direction = new THREE.Vector3(cell.direction.x, cell.direction.y, cell.direction.z); - if (cell.parentType) var parentType = cell.parentType; - if (cell.type) var type = cell.type; - - if (cell.destroy) cell.destroy(); - var newCell = self.makeCellForLatticeType(index, scale, parentPos, parentOrientation, direction, parentType, type); - - //if (parts) { - // //todo make this better - // newCell.parts = newCell._initParts(); - // for (var i=0;i<newCell.parts.length;i++){ - // if (!parts[i]) { - // newCell.parts[i].destroy(); - // newCell.parts[i] = null; - // } - // } - //} - cells[x][y][z] = newCell; - }); - dmaGlobals.three.render(); - } + var self = this; + var scale = this.get("scale"); + var cells = this.get("cells"); + this._loopCells(cells, function(cell, x, y, z){ + if (!cell) return; + + var index = _.clone(cell.indices); + //var parts = null; + //if (loadingFromFile) parts = _.clone(cell.parts); + if (cell.parentOrientation) var parentOrientation = new THREE.Quaternion(cell.parentOrientation._x, cell.parentOrientation._y, cell.parentOrientation._z, cell.parentOrientation._w); + if (cell.parentPosition) var parentPos = cell.parentPosition; + if (cell.direction) var direction = new THREE.Vector3(cell.direction.x, cell.direction.y, cell.direction.z); + if (cell.parentType) var parentType = cell.parentType; + if (cell.type) var type = cell.type; + + if (cell.destroy) cell.destroy(); + var newCell = self.makeCellForLatticeType(index, scale, parentPos, parentOrientation, direction, parentType, type); + + //if (parts) { + // //todo make this better + // newCell.parts = newCell._initParts(); + // for (var i=0;i<newCell.parts.length;i++){ + // if (!parts[i]) { + // newCell.parts[i].destroy(); + // newCell.parts[i] = null; + // } + // } + //} + cells[x][y][z] = newCell; + }); + dmaGlobals.three.render(); }, //////////////////////////////////////////////////////////////////////////////////// -- GitLab