diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index ada9aa8c1566633f2f610816ff31e107c05cad1f..82d5e08811ce2d6dd8bb6baa4479f33a967d40f2 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 81990ccc24c27c4e6eccbd61ca7402ccf41bc59c..a41e3462c1a052427dd51b0647e20bb27a770b0a 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 57d67d2b3949140509a0729c3295a21d15789a1a..40cdd47e68de1502ffdb9ecc05d287805783e0b7 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 7a2fff7cd42a54098931eb3475870bed053e367b..23f033d94225388db2f8f2e6d0a4f5c0dbba014f 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); } });