diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 7787b70485d93e6432228de790173336cec0ce68..f2d79d5161119d300d147c4cf8da5170179c44e3 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -108,12 +108,12 @@ DMACell.prototype.destroy = function(){ var cellMaterials = [new THREE.MeshNormalMaterial(), new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; - function DMASideOctaCell(indices, scale, lattice){ + function DMAFaceOctaCell(indices, scale, lattice){ DMACell.call(this, indices, scale, lattice); } - DMASideOctaCell.prototype = Object.create(DMACell.prototype); + DMAFaceOctaCell.prototype = Object.create(DMACell.prototype); - DMASideOctaCell.prototype._initParts = function(zIndex){ + DMAFaceOctaCell.prototype._initParts = function(zIndex){ var parts = []; for (var i=0;i<3;i++){ parts.push(new DMATrianglePart(i, zIndex%2==1, this)); @@ -121,7 +121,7 @@ DMACell.prototype.destroy = function(){ return parts; }; - DMASideOctaCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell + DMAFaceOctaCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell var mesh; mesh = THREE.SceneUtils.createMultiMaterialObject(unitCellGeo, cellMaterials); if (zIndex%2!=0) mesh.rotation.set(0, 0, Math.PI); @@ -130,7 +130,7 @@ DMACell.prototype.destroy = function(){ return mesh; }; - DMASideOctaCell.prototype.calcHighlighterPosition = function(face){ + DMAFaceOctaCell.prototype.calcHighlighterPosition = function(face){ var direction = face.normal; if (face.normal.z<0.99) direction = null;//only highlight horizontal faces @@ -140,7 +140,23 @@ DMACell.prototype.destroy = function(){ return {index: _.clone(this.indices), direction:direction, position:position}; } - self.DMASideOctaCell = DMASideOctaCell; + self.DMAFaceOctaCell = DMAFaceOctaCell; + + + function DMAEdgeOctaCell(indices, scale, lattice){ + DMAFaceOctaCell.call(this, indices, scale, lattice); + } + DMAEdgeOctaCell.prototype = Object.create(DMAFaceOctaCell.prototype); + + DMAEdgeOctaCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell + var mesh; + mesh = THREE.SceneUtils.createMultiMaterialObject(unitCellGeo, cellMaterials); + mesh.myParent = this;//we need a reference to this instance from the mesh for intersection selection stuff + dmaGlobals.three.sceneAdd(mesh, "cell"); + return mesh; + }; + + self.DMAEdgeOctaCell = DMAEdgeOctaCell; /////////////////////////////////////////////////TETRA CELL//////////////////////////////////// diff --git a/js/models/Lattice.js b/js/models/Lattice.js index e6da4c79d6b383eb10f27bb050a1549b6c79cc38..7b305625699a3b98493dc1d98d00be3db97f73c5 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -356,6 +356,7 @@ Lattice = Backbone.Model.extend({ if (connectionType == "face"){ _.extend(this, this.OctaFaceLattice); } else if (connectionType == "edge"){ + _.extend(this, this.OctaFaceLattice); _.extend(this, this.OctaEdgeLattice); } else if (connectionType == "edgeRot"){ @@ -510,7 +511,7 @@ Lattice = Backbone.Model.extend({ _makeCellForLatticeType: function(indices, scale){ this._addInverseCellsForIndex(indices); - return new DMASideOctaCell(indices, scale, this); + return new DMAFaceOctaCell(indices, scale, this); }, _makeInvCellForLatticeType: function(indices, scale){ @@ -580,11 +581,121 @@ Lattice = Backbone.Model.extend({ OctaEdgeLattice: { + getIndexForPosition: function(absPosition){ + var scale = this.get("scale"); + var yIndex = Math.floor(absPosition.y/this.yScale(scale)); + if (yIndex%2 != 0) absPosition.x += this.xScale(scale)/2; + var index = this._indexForPosition(absPosition); + if (index.z%2 == 1) index.y += 1; + return index; + }, + + getPositionForIndex: function(index){ + + var scale = this.get("scale"); + var position = _.clone(index); + var xScale = this.xScale(scale); + 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; + return position; + }, + + _makeCellForLatticeType: function(indices, scale){ + this._addInverseCellsForIndex(indices); + return new DMAEdgeOctaCell(indices, scale, this); + }, + + 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); + + if (!upPoint){ + 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; + } + + if (oddZ){ + position.z = (position.z + 1)*this.zScale(scale); + } else { + 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){ + 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 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); + } + }); + }, + _undo: function(){//remove all the mixins, this will help with debugging later var self = this; _.each(_.keys(this.OctaEdgeLattice), function(key){ self[key] = null; }); + this.OctaFaceLattice._undo(); } },