From 75b22b7a0d1318a90d0726a0c00551e13c967167 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 28 Jan 2015 13:08:15 -0500 Subject: [PATCH] cell indices passed in only, no position --- js/fea/dmaCell.js | 18 ++++++++++++++++-- js/models/lattice.js | 9 +++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index 0c209116..219bb256 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -23,16 +23,30 @@ new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; - function DMACell(mode, position, indices) { + function DMACell(mode, indices) { - this.position = position; this.indices = indices; + this.position = this._calcPositionForScale(30); + this.parts = this._initParts(); this.drawForMode(mode); } + DMACell.prototype._calcPositionForScale = function(scale){ + var position = {}; + var indices = this.indices; + var octHeight = 3*scale/8*Math.sqrt(5);//this isn't quite right + var triHeight = scale/2*Math.sqrt(3); + position.x = indices.x*scale; + position.y = indices.y*triHeight; + position.z = indices.z*octHeight; + if (indices.y%2 == 1) position.x -= scale/2; + if (indices.z%2 == 1) position.y -= triHeight*4/3; + return position; + }; + DMACell.prototype._initParts = function(){ var parts = []; for (var i=0;i<3;i++){ diff --git a/js/models/lattice.js b/js/models/lattice.js index b8cc3f93..164484c3 100644 --- a/js/models/lattice.js +++ b/js/models/lattice.js @@ -55,7 +55,8 @@ Lattice = Backbone.Model.extend({ } var index = this._subtract(position, this.get("cellsMin")); - cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), absPosition, position); + cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), position); + this.set("numCells", this.get("numCells")+1); window.three.render(); }, @@ -146,14 +147,14 @@ Lattice = Backbone.Model.extend({ removeCell: function(object){ var cell = object.parent.myCell; - var relativeIndex = this._subtract(cell.indices, this.get("cellsMin")); + var index = this._subtract(cell.indices, this.get("cellsMin")); var cells = this.get("cells"); - cells[relativeIndex.x][relativeIndex.y][relativeIndex.z] = null; + cells[index.x][index.y][index.z] = null; cell.remove(); //todo shrink cells matrix if needed - this.set("numCells", cells.length); + this.set("numCells", this.get("numCells")-1); window.three.render(); }, -- GitLab