diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index f2d79d5161119d300d147c4cf8da5170179c44e3..a349f0daedafc53bbc2a5fddc8ca54ff74d86045 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -165,16 +165,16 @@ DMACell.prototype.destroy = function(){ unitTetraCellGeo.applyMatrix(new THREE.Matrix4().makeRotationX((Math.PI-Math.atan(2*Math.sqrt(2)))/2)); unitTetraCellGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-1/Math.sqrt(6))); - function DMATetraCell(indices, scale, lattice){ + function DMATetraFaceCell(indices, scale, lattice){ DMACell.call(this, indices, scale, lattice, true); } - DMATetraCell.prototype = Object.create(DMACell.prototype); + DMATetraFaceCell.prototype = Object.create(DMACell.prototype); - DMATetraCell.prototype._initParts = function(){ + DMATetraFaceCell.prototype._initParts = function(){ return []; }; - DMATetraCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell + DMATetraFaceCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell var mesh; mesh = THREE.SceneUtils.createMultiMaterialObject(unitTetraCellGeo, cellMaterials); if (zIndex%2 !=0) mesh.rotateX(Math.PI); @@ -185,7 +185,7 @@ DMACell.prototype.destroy = function(){ return mesh; }; - DMATetraCell.prototype.calcHighlighterPosition = function(face){ + DMATetraFaceCell.prototype.calcHighlighterPosition = function(face){ var direction = face.normal; if (face.normal.z<0.99) direction = null;//only highlight horizontal faces @@ -195,11 +195,27 @@ DMACell.prototype.destroy = function(){ return {index: _.clone(this.indices), direction:direction, position:position}; }; - DMATetraCell.prototype.getPosition = function(){//need for part relay + DMATetraFaceCell.prototype.getPosition = function(){//need for part relay return dmaGlobals.lattice.getInvCellPositionForIndex(this.indices); }; - self.DMATetraCell = DMATetraCell; + self.DMATetraFaceCell = DMATetraFaceCell; + + function DMATetraEdgeCell(indices, scale, lattice){ + DMATetraFaceCell.call(this, indices, scale, lattice, true); + } + DMATetraEdgeCell.prototype = Object.create(DMATetraFaceCell.prototype); + + DMATetraEdgeCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell + var mesh; + mesh = THREE.SceneUtils.createMultiMaterialObject(unitTetraCellGeo, cellMaterials); + if (zIndex%2 !=0) mesh.rotateX(Math.PI); + mesh.myParent = this;//we need a reference to this instance from the mesh for intersection selection stuff + dmaGlobals.three.sceneAdd(mesh, "inverseCell"); + return mesh; + }; + + self.DMATetraEdgeCell = DMATetraEdgeCell; })(); diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 7b305625699a3b98493dc1d98d00be3db97f73c5..20acc0d11a59f6a75a3af76f20d71836d2c6be1c 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -454,7 +454,7 @@ Lattice = Backbone.Model.extend({ 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 ((index.y%2) != 0) position.x -= this.xScale()/2; + if ((index.y%2) != 0) position.x -= this.xScale(scale)/2; return position; }, @@ -515,19 +515,36 @@ Lattice = Backbone.Model.extend({ }, _makeInvCellForLatticeType: function(indices, scale){ - return new DMATetraCell(indices, scale, this); + return new DMATetraFaceCell(indices, scale, this); }, _addInverseCellsForIndex: function(index){ + var oddZ = index.z%2 != 0; + index = _.clone(index); + index.z*=2; + var inverseIndicesToAdd = this._getInverseIndicesToAdd(index, oddZ); + + var invCells = this.get("inverseCells"); + var scale = this.get("scale"); + var self = this; + _.each(inverseIndicesToAdd, function(invIndex){ + self._checkForMatrixExpansion(invCells, invIndex, invIndex, "inverseCellsMax", "inverseCellsMin"); + var indexRel = self._subtract(invIndex, self.get("inverseCellsMin")); + if (!invCells[indexRel.x][indexRel.y][indexRel.z]) { + invCells[indexRel.x][indexRel.y][indexRel.z] = self._makeInvCellForLatticeType(invIndex, scale); + self.set("numInvCells", self.get("numInvCells")+1); + } + }); + }, + + _getInverseIndicesToAdd: function(index, oddZ){ - var oddZ = index.z%2 != 0; var z0 = 0; if (oddZ) z0 = 1; var z1 = Math.abs(z0-1); - index.z*=2; var inverseIndicesToAdd; if (index.y%2 == 0){ @@ -551,18 +568,7 @@ Lattice = Backbone.Model.extend({ this._add(index, {x:0,y:0,z:z1}) ]; } - - var invCells = this.get("inverseCells"); - var scale = this.get("scale"); - var self = this; - _.each(inverseIndicesToAdd, function(invIndex){ - self._checkForMatrixExpansion(invCells, invIndex, invIndex, "inverseCellsMax", "inverseCellsMin"); - var indexRel = self._subtract(invIndex, self.get("inverseCellsMin")); - if (!invCells[indexRel.x][indexRel.y][indexRel.z]) { - invCells[indexRel.x][indexRel.y][indexRel.z] = self._makeInvCellForLatticeType(invIndex, scale); - self.set("numInvCells", self.get("numInvCells")+1); - } - }); + return inverseIndicesToAdd; }, _undo: function(){//remove all the mixins, this will help with debugging later @@ -581,7 +587,19 @@ Lattice = Backbone.Model.extend({ OctaEdgeLattice: { + _initLatticeType: function(){ + + //bind events + this.set("columnSeparation", 0.0); +// this.listenTo(this, "change:columnSeparation", this._changeColSeparation); + + this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); + this.set("highlighter", new OctaEdgeHighlighter({scale:this.get("scale")})); + + }, + getIndexForPosition: function(absPosition){ + //todo finish this var scale = this.get("scale"); var yIndex = Math.floor(absPosition.y/this.yScale(scale)); if (yIndex%2 != 0) absPosition.x += this.xScale(scale)/2; @@ -595,10 +613,17 @@ Lattice = Backbone.Model.extend({ var scale = this.get("scale"); var position = _.clone(index); var xScale = this.xScale(scale); + var yScale = scale/Math.sqrt(3); position.x = (position.x+1/2)*xScale; - position.y = position.y*this.yScale(scale)+scale/Math.sqrt(3)/2; + position.y = position.y*this.yScale(scale)+yScale/2; position.z = (position.z+0.5)*this.zScale(scale); - if ((index.y%2) != 0) position.x -= this.xScale()/2; + if (index.y%2 != 0) position.x -= this.xScale(scale)/2; + if (index.z%3 == 1) { + position.x += this.xScale(scale)/2; + position.y -= yScale/2; + } else if (index.z%3 == 2){ + position.y -= yScale; + } return position; }, @@ -607,21 +632,52 @@ Lattice = Backbone.Model.extend({ return new DMAEdgeOctaCell(indices, scale, this); }, + _makeInvCellForLatticeType: function(indices, scale){ + return new DMATetraEdgeCell(indices, scale, this); + }, + + _getInverseIndicesToAdd: function(index){ + var inverseIndicesToAdd; + if (index.y%2 == 0){ + + inverseIndicesToAdd = [ + this._add(index, {x:0,y:0,z:0}), + this._add(index, {x:0,y:1,z:0}), + this._add(index, {x:1,y:1,z:0}), + + this._add(index, {x:0,y:0,z:1}), + this._add(index, {x:0,y:1,z:1}), + this._add(index, {x:1,y:0,z:1}) + ]; + } else { + inverseIndicesToAdd = [ + this._add(index, {x:0,y:0,z:0}), + this._add(index, {x:-1,y:1,z:0}), + this._add(index, {x:0,y:1,z:0}), + + this._add(index, {x:-1,y:0,z:1}), + this._add(index, {x:0,y:1,z:1}), + this._add(index, {x:0,y:0,z:1}) + ]; + } + return inverseIndicesToAdd; + }, + getInvCellPositionForIndex: function(index){ var scale = this.get("scale"); var position = _.clone(index); var oddZ = position.z%2 != 0; - var upPoint = (position.z%4 == 0 || Math.abs(position.z%4) == 3); position.z = Math.floor(position.z/2); + var yScale = scale/Math.sqrt(3); - if (!upPoint){ + if (oddZ){ position.x = (position.x)*this.xScale(scale); position.y = position.y*this.yScale(scale); } else { position.x = (position.x+0.5)*this.xScale(scale); - position.y = (position.y)*this.yScale(scale)-scale/Math.sqrt(3)/2; + position.y = (position.y)*this.yScale(scale)-yScale/2; } if (oddZ){ @@ -630,64 +686,23 @@ Lattice = Backbone.Model.extend({ position.z = (position.z)*this.zScale(scale); } -// if (Math.abs(index.z%4) == 1 || Math.abs(index.z%4) == 2) position.z += this.zScale(scale); - if ((index.y%2) != 0) { - if (!upPoint){ + if (oddZ){ position.x += this.xScale(scale)/2; } else { position.x -= this.xScale(scale)/2; } } - return position; - }, - - _addInverseCellsForIndex: function(index){ - - index = _.clone(index); - - var oddZ = index.z%2 != 0; - var z0 = 0; - if (oddZ) z0 = 1; - var z1 = Math.abs(z0-1); - - index.z*=2; - var inverseIndicesToAdd; - if (index.y%2 == 0){ - - inverseIndicesToAdd = [ - this._add(index, {x:0,y:0,z:z0}), - this._add(index, {x:0,y:1,z:z0}), - this._add(index, {x:1,y:1,z:z0}), - - this._add(index, {x:0,y:0,z:z1}), - this._add(index, {x:0,y:1,z:z1}), - this._add(index, {x:1,y:0,z:z1}) - ]; - } else { - inverseIndicesToAdd = [ - this._add(index, {x:0,y:0,z:z0}), - this._add(index, {x:-1,y:1,z:z0}), - this._add(index, {x:0,y:1,z:z0}), - - this._add(index, {x:-1,y:0,z:z1}), - this._add(index, {x:0,y:1,z:z1}), - this._add(index, {x:0,y:0,z:z1}) - ]; + var zLayer = Math.floor(index.z/2)%3; + if (zLayer == 1) { + position.x += this.xScale(scale)/2; + position.y -= yScale/2; + } else if (zLayer == 2){ + position.y -= yScale; } - var invCells = this.get("inverseCells"); - var scale = this.get("scale"); - var self = this; - _.each(inverseIndicesToAdd, function(invIndex){ - self._checkForMatrixExpansion(invCells, invIndex, invIndex, "inverseCellsMax", "inverseCellsMin"); - var indexRel = self._subtract(invIndex, self.get("inverseCellsMin")); - if (!invCells[indexRel.x][indexRel.y][indexRel.z]) { - invCells[indexRel.x][indexRel.y][indexRel.z] = self._makeInvCellForLatticeType(invIndex, scale); - self.set("numInvCells", self.get("numInvCells")+1); - } - }); + return position; }, _undo: function(){//remove all the mixins, this will help with debugging later @@ -695,7 +710,9 @@ Lattice = Backbone.Model.extend({ _.each(_.keys(this.OctaEdgeLattice), function(key){ self[key] = null; }); - this.OctaFaceLattice._undo(); + _.each(_.keys(this.OctaFaceLattice), function(key){ + self[key] = null; + }); } }, diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 23f033d94225388db2f8f2e6d0a4f5c0dbba014f..ed7552fd258cff4a08322ab2e57fe66ceff62e53 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -148,6 +148,22 @@ OctaFaceHighlighter = Highlighter.extend({ }); +OctaEdgeHighlighter = Highlighter.extend({ + + _makeGeometry: function(){ + + var rad = 1/Math.sqrt(3); + var geometry = new THREE.CylinderGeometry(rad, rad, 0.01, 3);//short triangular prism + geometry.applyMatrix(new THREE.Matrix4().makeRotationX(-Math.PI/2)); + return geometry; + }, + + _setPosition: function(position){ + this.mesh.position.set(position.x, position.y, position.z); + } + +}); + OctaVertexHighlighter = Highlighter.extend({ _makeGeometry: function(){