From fe201064d3534bdba7df6d9f54979d76b2ae00a4 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sat, 7 Mar 2015 01:33:15 -0500 Subject: [PATCH] save freeform files --- js/fea/DmaCell.js | 7 +++++-- js/models/Lattice.js | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index e69ff8be..c894dd78 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -234,8 +234,11 @@ DMACell.prototype.toJSON = function(){ DMAFreeFormOctaCell.prototype.toJSON = function(){ var json = DMACell.prototype.toJSON.call(this); _.extend(json, { - position: this.getPosition(), - orientation: this.getOrientation() + parentPosition: this.parentPos, + parentOrientation: this.parentQuaternion, + direction: this.parentDirection +// position: this.getPosition(), +// orientation: this.getOrientation() }); return json; } diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 5e660e52..a549a772 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -403,11 +403,16 @@ Lattice = Backbone.Model.extend({ this._clearInverseCells(); this._loopCells(cells, function(cell, x, y, z){ if (!cell) return; + var index = _.clone(cell.indices); var parts = _.clone(cell.parts); -// if (cell.orientation) orientation + 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.destroy) cell.destroy(); - var newCell = self._makeCellForLatticeType(index, scale); + var newCell = self._makeCellForLatticeType(index, scale, parentPos, parentOrientation, direction); + if (parts) { //todo make this better newCell.parts = newCell._initParts(); @@ -416,7 +421,6 @@ Lattice = Backbone.Model.extend({ } } cells[x][y][z] = newCell; - }); dmaGlobals.three.render(); } @@ -643,11 +647,15 @@ Lattice = Backbone.Model.extend({ addFreeFormCell: function(parentCellPos, parentCellOrient, direction){ var scale = this.get("scale"); var cells = this.get("cells"); - cells[0][0].push(new DMAFreeFormOctaCell({x:0,y:0,z:cells[0][0].length}, scale, parentCellPos, parentCellOrient, direction)); + cells[0][0].push(this._makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, scale, parentCellPos, parentCellOrient, direction)); this.set("numCells", this.get("numCells")+1); dmaGlobals.three.render(); }, + _makeCellForLatticeType: function(index, scale, parentPosition, parentOrientation, direction){ + return new DMAFreeFormOctaCell(index, scale, parentPosition, parentOrientation, direction); + }, + getIndexForPosition: function(absPosition){//only used by baseplane var scale = this.get("scale"); var yIndex = Math.floor(absPosition.y/this.yScale(scale)); -- GitLab