From 49a3d85424cb1d0ae3ad15dc6d0484af9a0dc8bc Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Thu, 26 Feb 2015 01:48:53 -0500
Subject: [PATCH] eod

---
 js/fea/DmaCell.js            | 16 +++++++++---
 js/models/BasePlane.js       | 50 ++++++++++++++++++++++++++++++++++++
 js/models/Lattice.js         | 42 +++++++++++++++++++++++++++++-
 js/threeViews/Highlighter.js |  2 +-
 4 files changed, 105 insertions(+), 5 deletions(-)

diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js
index ada9aa8c..82d5e088 100644
--- a/js/fea/DmaCell.js
+++ b/js/fea/DmaCell.js
@@ -217,9 +217,9 @@ DMACell.prototype.destroy = function(){
 
     DMAVertexOctaCell.prototype._initParts = function(zIndex){
         var parts  = [];
-        for (var i=0;i<3;i++){
-            parts.push(new DMAPart(i, zIndex%2==1, this));
-        }
+//        for (var i=0;i<3;i++){
+//            parts.push(new DMAPart(i, zIndex%2==1, this));
+//        }
         return parts;
     };
 
@@ -230,6 +230,16 @@ DMACell.prototype.destroy = function(){
         return mesh;
     };
 
+    DMAVertexOctaCell.prototype.calcHighlighterPosition = function(face){
+
+        var direction = new THREE.Vector3(0,0,1);
+        if (face.normal.z<0) direction = null;
+
+        var position = dmaGlobals.lattice.getPositionForIndex(this.indices);
+        position.z += dmaGlobals.lattice.zScale()/2;
+        return {index: _.clone(this.indices), direction:direction, position:position};
+    };
+
     self.DMAVertexOctaCell = DMAVertexOctaCell;
 
 })();
diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js
index 81990ccc..a41e3462 100644
--- a/js/models/BasePlane.js
+++ b/js/models/BasePlane.js
@@ -242,5 +242,55 @@ SquareBasePlane = BasePlane.extend({
         return {index: index, direction: new THREE.Vector3(0,0,1), position:position};
     }
 
+});
+
+OctaVertexBasePlane = BasePlane.extend({
+
+    _makeBasePlaneMesh: function(){
+
+        var scale = dmaGlobals.lattice.xScale(1);
+        var dimX = this.get("dimX")*scale;
+        var dimY = this.get("dimY")*scale;
+
+        var geometry = new THREE.Geometry();
+
+        for ( var i = - dimX; i <= dimX; i += scale ) {
+            geometry.vertices.push( new THREE.Vector3(-dimX, i, 0));
+            geometry.vertices.push( new THREE.Vector3(dimX, i, 0));
+            geometry.vertices.push( new THREE.Vector3(i, -dimX, 0));
+            geometry.vertices.push( new THREE.Vector3(i, dimX, 0));
+
+        }
+
+        var planeGeometry = new THREE.Geometry();
+        planeGeometry.vertices.push( new THREE.Vector3(-dimX, -dimX, 0));
+        planeGeometry.vertices.push( new THREE.Vector3(dimX, -dimX, 0));
+        planeGeometry.vertices.push( new THREE.Vector3(-dimX, dimX, 0));
+        planeGeometry.vertices.push( new THREE.Vector3(dimX, dimX, 0));
+        planeGeometry.faces.push(new THREE.Face3(0, 1, 3));
+        planeGeometry.faces.push(new THREE.Face3(0, 3, 2));
+        planeGeometry.computeFaceNormals();
+
+        var mesh = new THREE.Mesh(planeGeometry, new THREE.MeshBasicMaterial({color:0x000000, transparent:true, opacity:0.0, side:THREE.DoubleSide}));
+        mesh.myParent = this;//reference used for intersection highlighting
+        return [mesh, new THREE.Line(geometry, new THREE.LineBasicMaterial({color:0x000000, transparent:true, linewidth:2, opacity:this.get("material").opacity}), THREE.LinePieces)];
+    },
+
+    _renderZIndexChange: function(){
+        var zIndex = this.get("zIndex");
+        var zScale = dmaGlobals.lattice.zScale();
+        _.each(this.get("mesh"), function(mesh){
+            mesh.position.set(0, 0, zIndex*zScale);
+        });
+        dmaGlobals.three.render();
+    },
+
+    calcHighlighterPosition: function(face, position){
+        var index = dmaGlobals.lattice.getIndexForPosition(position);
+        index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane
+        var position = dmaGlobals.lattice.getPositionForIndex(index);
+        position.z += dmaGlobals.lattice.zScale()/2;
+        return {index: index, direction: new THREE.Vector3(0,0,1), position:position};
+    }
 
 });
\ No newline at end of file
diff --git a/js/models/Lattice.js b/js/models/Lattice.js
index 57d67d2b..40cdd47e 100644
--- a/js/models/Lattice.js
+++ b/js/models/Lattice.js
@@ -326,6 +326,9 @@ Lattice = Backbone.Model.extend({
         this._iterCells(this.get("cells"), function(cell){
             if (cell) cell.updateForScale(scale);
         });
+        this._iterCells(this.get("inverseCells"), function(cell){
+            if (cell) cell.updateForScale(scale);
+        });
         dmaGlobals.three.render();
     },
 
@@ -591,6 +594,43 @@ Lattice = Backbone.Model.extend({
 
     OctaVertexLattice: {
 
+        _initLatticeType: function(){
+
+            //bind events
+
+            this.set("basePlane", new SquareBasePlane({scale:this.get("scale")}));
+            this.set("highlighter", new OctaVertexHighlighter({scale:this.get("scale")}));
+        },
+
+        getIndexForPosition: function(absPosition){
+            return this._indexForPosition(absPosition);
+        },
+
+        getPositionForIndex: function(index){
+            return this._positionForIndex(index);
+        },
+
+        xScale: function(scale){
+            if (!scale) scale = this.get("scale");
+            return scale*Math.sqrt(2);
+        },
+
+        yScale: function(scale){
+            return this.xScale(scale);
+        },
+
+        zScale: function(scale){
+            return this.xScale(scale);
+        },
+
+        _makeCellForLatticeType: function(indices, scale){
+            return new DMAVertexOctaCell(indices, scale, this);
+        },
+
+        _shouldHaveInverseCells: function(){
+            return false;
+        },
+
         _undo: function(){//remove all the mixins, this will help with debugging later
             var self = this;
             _.each(_.keys(this.OctaVertexLattice), function(key){
@@ -625,7 +665,7 @@ Lattice = Backbone.Model.extend({
         },
 
         xScale: function(scale){
-            if (!scale) scale = this.get("scale")
+            if (!scale) scale = this.get("scale");
             return scale;
         },
 
diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js
index 7a2fff7c..23f033d9 100644
--- a/js/threeViews/Highlighter.js
+++ b/js/threeViews/Highlighter.js
@@ -151,7 +151,7 @@ OctaFaceHighlighter = Highlighter.extend({
 OctaVertexHighlighter = Highlighter.extend({
 
     _makeGeometry: function(){
-        return new THREE.SphereGeometry(1);
+        return new THREE.SphereGeometry(0.2);
     }
 
 });
-- 
GitLab