From 133211021e347282bbc1bee1f8c72537ee0fe57a Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Mon, 23 Feb 2015 18:08:53 -0500 Subject: [PATCH] add and remove cubes --- js/fea/DmaCell.js | 20 ++++++++++++++++++-- js/models/BasePlane.js | 1 + js/models/Lattice.js | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 241e1612..9cff4de9 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -247,7 +247,7 @@ DMACell.prototype.destroy = function(){ DMACubeCell.prototype._calcPosition = function(scale, indices){ var position = _.clone(indices); _.each(_.keys(position), function(key){ - position.key *= scale; + position[key] *= scale; }); return position; }; @@ -266,6 +266,22 @@ DMACell.prototype.destroy = function(){ return mesh; }; - self.DMAVertexOctaCell = DMACubeCell; + DMACubeCell.prototype.getHighlighterVertices = function(face){ + if (face.normal.z<0.99) return null;//only highlight horizontal faces + + //the vertices don't include the position transformation applied to cell. Add these to create highlighter vertices + var mesh = this.cellMesh.children[0]; + var vertices = mesh.geometry.vertices; + var newVertices = [vertices[face.a].clone(), vertices[face.b].clone(), vertices[face.c].clone(), new THREE.Vector3(0,0,0)]; + var scale = this.cellMesh.scale.x; + var position = (new THREE.Vector3()).setFromMatrixPosition(mesh.matrixWorld); + _.each(newVertices, function(vertex){//apply scale + vertex.multiplyScalar(scale); + vertex.add(position); + }); + return newVertices; + } + + self.DMACubeCell = DMACubeCell; })(); diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index c49bafe4..fb15c493 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -237,6 +237,7 @@ SquareBasePlane = BasePlane.extend({ getHighlighterVertices: function(face, position){ //the vertices don't include the position transformation applied to cell. Add these to create highlighter vertices var index = window.lattice.getIndexForPosition(position); + index.z += 1; var scale = this.get("mesh")[0].scale.x; var vertices = []; vertices.push(new THREE.Vector3(index.x*scale, index.y*scale, index.z*scale)); diff --git a/js/models/Lattice.js b/js/models/Lattice.js index d687ab92..88d27094 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -521,7 +521,7 @@ Lattice = Backbone.Model.extend({ var index = {}; index.x = Math.round((absPosition.x-scale/2)/scale); index.y = Math.round((absPosition.y-scale/2)/scale); - index.z = Math.round(absPosition.z/scale); + index.z = Math.round(absPosition.z/scale)-1; return index; }, -- GitLab