From 06c2fee23edc65a732efd2f94960598839faa672 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 25 Feb 2015 03:36:56 -0500 Subject: [PATCH] cube and octa working --- js/fea/DmaCell.js | 8 +++++--- js/models/Lattice.js | 13 ++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 20c1e5d8..d5553f2c 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -209,8 +209,7 @@ DMACell.prototype.destroy = function(){ var unitCellGeo = new THREE.BoxGeometry(1,1,1); - var cellMaterials = [new THREE.MeshNormalMaterial(), - new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; + var cellMaterial = new THREE.MeshNormalMaterial(); function DMACubeCell(mode, indices, scale, lattice){ @@ -227,8 +226,11 @@ DMACell.prototype.destroy = function(){ }; DMACubeCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell - var mesh = THREE.SceneUtils.createMultiMaterialObject(unitCellGeo, cellMaterials); + var mesh = new THREE.Mesh(unitCellGeo, cellMaterial); mesh.myParent = this;//we need a reference to this instance from the mesh for intersection selection stuff + var wireframe = new THREE.BoxHelper(mesh); + wireframe.material.color.set(0x000000); +// mesh.add(wireframe); return mesh; }; diff --git a/js/models/Lattice.js b/js/models/Lattice.js index c56126a1..7d89ecd0 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -369,9 +369,12 @@ Lattice = Backbone.Model.extend({ }, getIndexForPosition: function(absPosition){ - var position = this._indexForPosition(absPosition); - if (position.z%2 == 1) position.y += 1; - return position; + var scale = this.get("scale"); + var yIndex = Math.floor(absPosition.y/this.yScale(scale)); + if (Math.abs(yIndex%2) == 1) absPosition.x += this.xScale(scale)/2; + var index = this._indexForPosition(absPosition); + if (index.z%2 == 1) index.y += 1; + return index; }, getPositionForIndex: function(index){ @@ -379,8 +382,8 @@ Lattice = Backbone.Model.extend({ var scale = this.get("scale"); var position = _.clone(index); var xScale = this.xScale(scale); - position.x = position.x*xScale; - position.y = position.y*this.yScale(scale)-xScale/Math.sqrt(3); + position.x = (position.x+1/2)*xScale; + position.y = position.y*this.yScale(scale)+scale/Math.sqrt(3)/2; position.z = (position.z+0.5)*this.zScale(scale); if (Math.abs(index.y%2) == 1) position.x -= this.xScale()/2; return position; -- GitLab