diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index ade16c1f5692f04d3ed783da1f9f073c862512f9..265a99239c125727030e717e292dee37107a8d9b 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -160,10 +160,10 @@ DMACell.prototype.destroy = function(){ DMATetraCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell var mesh; mesh = THREE.SceneUtils.createMultiMaterialObject(unitTetraCellGeo, cellMaterials); - if (zIndex%2!=0) mesh.rotation.set(Math.PI,0,0); + if (Math.abs(zIndex%4) == 1 || Math.abs(zIndex%4) == 2) mesh.rotation.set(Math.PI,0,0); mesh.myParent = this;//we need a reference to this instance from the mesh for intersection selection stuff -// dmaGlobals.three.sceneAdd(mesh, "inverseCell"); + dmaGlobals.three.sceneAdd(mesh, "inverseCell"); mesh.visible = false; return mesh; }; diff --git a/js/models/Lattice.js b/js/models/Lattice.js index efdb29e91b6222bc565391cafa76926cd123aa97..a18e6725f1855b3b0e63db08a404a15a1f93d310 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -424,26 +424,26 @@ Lattice = Backbone.Model.extend({ var position = _.clone(index); var oddZ = (position.z%2 != 0); - position.z /= 2; - var xScale = this.xScale(scale); + position.z = Math.floor(position.z/2); + if (oddZ){ - position.x = (position.x)*xScale; + position.x = (position.x)*this.xScale(scale); position.y = position.y*this.yScale(scale); - position.z = (position.z+0.5)*this.zScale(scale); } else { - position.x = (position.x+0.5)*xScale; + position.x = (position.x+0.5)*this.xScale(scale); position.y = (position.y)*this.yScale(scale)-scale/Math.sqrt(3)/2; - position.z = (position.z)*this.zScale(scale); } + 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 (Math.round((index.y/2)%2) != 0) { - position.x -= this.xScale()/2; - } - } else { - if (Math.round((index.y/2)%2) != 0) { - position.x -= this.xScale(); + if (oddZ){ + position.x += this.xScale(scale)/2; + } else { + position.x -= this.xScale(scale)/2; } } + return position; }, @@ -478,15 +478,28 @@ Lattice = Backbone.Model.extend({ index = _.clone(index); index.z*=2; - 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:1,z:0}), - - this._add(index, {x:0,y:0,z:1}), - this._add(index, {x:1,y:0,z:1}), - this._add(index, {x:1,y:1,z:1}) - ]; + 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}) + ]; + } var invCells = this.get("inverseCells"); var scale = this.get("scale"); diff --git a/js/models/ThreeModel.js b/js/models/ThreeModel.js index a6e8b17a04f0b062b8e4c2bc5cc7ea154276b573..9da34ed690934a668ffffe9d4362e05cc6922780 100644 --- a/js/models/ThreeModel.js +++ b/js/models/ThreeModel.js @@ -11,6 +11,7 @@ function ThreeModel(){ //store all meshes to highlight var cells = []; + var invCells = []; var parts = []; var basePlane = []; @@ -54,6 +55,8 @@ function ThreeModel(){ if (type == "cell"){ cells.push(object); + } else if (type == "inverseCell"){ + invCells.push(object); } else if (type == "part"){ parts.push(object); } else if (type == "basePlane"){ @@ -70,6 +73,8 @@ function ThreeModel(){ if (type == "cell"){ cells.splice(cells.indexOf(objectToRemove), 1); + } else if (type == "inverseCell"){ + invCells.splice(invCells.indexOf(objectToRemove), 1); } else if (type == "part"){ parts.splice(parts.indexOf(objectToRemove), 1); } else if (type == "basePlane"){ @@ -85,6 +90,9 @@ function ThreeModel(){ _.each(parts, function(part){ sceneRemove(part, "part"); }); + _.each(invCells, function(cell){ + sceneRemove(cell, "inverseCell"); + }); cells.splice(0, cells.length);; parts.splice(0, parts.length); } @@ -101,6 +109,7 @@ function ThreeModel(){ domElement: renderer.domElement, camera: camera, cells: cells, + invCells: invCells, parts: parts, basePlane: basePlane, removeAllCells: removeAllCells