diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index f5911a9835c5e3fe1f9140dffbaf60fd9faae674..588374ad0e46bfc5ace223c43483037793e0c9e5 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -66,6 +66,7 @@ DMACell.prototype.getScale = function(){//need for part relay }; DMACell.prototype.getPosition = function(){//need for part relay + if (this.isInverse) return dmaGlobals.lattice.getInvCellPositionForIndex(this.indices); return dmaGlobals.lattice.getPositionForIndex(this.indices); }; @@ -231,27 +232,22 @@ DMACell.prototype.destroy = function(){ (function () { - var unitCellGeo = new THREE.OctahedronGeometry(1/Math.sqrt(2)); + var vertexOctaGeo = new THREE.OctahedronGeometry(1/Math.sqrt(2)); var cellMaterials = [new THREE.MeshNormalMaterial(), new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; - function DMAVertexOctaCell(indices, scale, lattice){ DMACell.call(this, indices, scale, lattice); } DMAVertexOctaCell.prototype = Object.create(DMACell.prototype); - DMAVertexOctaCell.prototype._initParts = function(zIndex){ - var parts = []; -// for (var i=0;i<3;i++){ -// parts.push(new DMAPart(i, zIndex%2==1, this)); -// } - return parts; + DMAVertexOctaCell.prototype._initParts = function(){ + return []; }; - DMAVertexOctaCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell - var mesh = THREE.SceneUtils.createMultiMaterialObject(unitCellGeo, cellMaterials); + DMAVertexOctaCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell + var mesh = THREE.SceneUtils.createMultiMaterialObject(vertexOctaGeo, 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; @@ -271,7 +267,25 @@ DMACell.prototype.destroy = function(){ /////////////////////////////////////////TRUNCATED CUBE//////////////////////////////////// + var truncCubeGeo = new THREE.BoxGeometry(Math.sqrt(2), Math.sqrt(2), Math.sqrt(2)); + + function DMATruncCubeCell(indices, scale, lattice){ + DMACell.call(this, indices, scale, lattice, true); + } + DMATruncCubeCell.prototype = Object.create(DMACell.prototype); + + DMATruncCubeCell.prototype._initParts = function(){ + return []; + }; + + DMATruncCubeCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell + var mesh = THREE.SceneUtils.createMultiMaterialObject(truncCubeGeo, cellMaterials); + 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.DMATruncCubeCell = DMATruncCubeCell; })(); diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 01288ef00f134c714f196d8cfde3cf520c9c443b..eceae0c4706718321d350a7401292762d9ab29a9 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -723,6 +723,17 @@ Lattice = Backbone.Model.extend({ return this._positionForIndex(index); }, + getInvCellPositionForIndex: function(index){ + + var position = this._positionForIndex(index); + + var scale = this.get("scale"); + position.x -= this.xScale(scale)/2; + position.y -= this.yScale(scale)/2; + position.z -= this.zScale(scale)/2; + return position; + }, + xScale: function(scale){ if (!scale) scale = this.get("scale"); return scale*Math.sqrt(2); @@ -737,9 +748,43 @@ Lattice = Backbone.Model.extend({ }, _makeCellForLatticeType: function(indices, scale){ + this._addInverseCellsForIndex(indices); return new DMAVertexOctaCell(indices, scale, this); }, + _makeInvCellForLatticeType: function(indices, scale){ + return new DMATruncCubeCell(indices, scale, this); + }, + + _addInverseCellsForIndex: function(index){ + + index = _.clone(index); + + var 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:0,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}), + this._add(index, {x:1,y:1,z:1}) + ]; + + 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.OctaVertexLattice), function(key){