Skip to content
Snippets Groups Projects
Commit e74d371a authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

hex lattice

parent 9145402a
Branches
No related tags found
No related merge requests found
...@@ -14,92 +14,32 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three', ...@@ -14,92 +14,32 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three',
_makeBasePlaneMesh: function(){ _makeBasePlaneMesh: function(){
var geometry = new THREE.Geometry(); var scale = lattice.xScale();
geometry.vertices = this._calcOctaFaceVertices(0.0); var dimX = this.get("dimX")*scale;
var faces = geometry.faces; var dimY = this.get("dimY")*scale;
var dimX = this.get("dimX"); // var geometry = new THREE.Geometry();
var dimY = this.get("dimY");
var currentOffset = 0;
for (var j=-dimX;j<=dimX;j++){
for (var i=-dimY;i<=dimY;i++){
currentOffset++;
if (j == -dimX || i == -dimY) continue;
if (Math.abs(j)%2==1){
faces.push(new THREE.Face3(3*currentOffset-4, 3*currentOffset-8-6*dimY, 3*currentOffset-6-6*dimY));//pt, base, base
} else {
faces.push(new THREE.Face3(3*currentOffset-1, 3*currentOffset-8-6*dimY, 3*currentOffset-6-6*dimY));//pt, base, base
}
}
}
geometry.computeFaceNormals();
return [new THREE.Mesh(geometry, this.get("material"))];
},
// _renderZIndexChange: function(){
// var zIndex = this.get("zIndex");
// var xScale = lattice.xScale();
// var yScale = lattice.yScale();
// var zScale = lattice.zScale();
// //
// _.each(this.get("mesh"), function(mesh){ // for ( var i = - dimX; i <= dimX+1; i += scale ) {
// mesh.position.set(xScale*(zIndex%2)/2, -yScale/3*(zIndex%2), zIndex*zScale); // geometry.vertices.push( new THREE.Vector3(-dimX-scale/2, i-scale/2, 0.01));
// mesh.rotation.set(Math.PI*(zIndex%2),0,0) // geometry.vertices.push( new THREE.Vector3(dimX-scale/2, i-scale/2, 0.01));
// }); // geometry.vertices.push( new THREE.Vector3(i-scale/2, -dimX-scale/2, 0.01));
// three.render(); // geometry.vertices.push( new THREE.Vector3(i-scale/2, dimX-scale/2, 0.01));
// }, //
// }
_calcOctaFaceVertices: function(xySep){ //
var planeGeometry = new THREE.Geometry();
var vertices = []; planeGeometry.vertices.push( new THREE.Vector3(-dimX-scale/2, -dimX-scale/2, 0));
planeGeometry.vertices.push( new THREE.Vector3(dimX+scale/2, -dimX-scale/2, 0));
var xScale = lattice.xScale(); planeGeometry.vertices.push( new THREE.Vector3(-dimX-scale/2, dimX+scale/2, 0));
var yScale = lattice.yScale(); planeGeometry.vertices.push( new THREE.Vector3(dimX+scale/2, dimX+scale/2, 0));
planeGeometry.faces.push(new THREE.Face3(0, 1, 3));
var dimX = this.get("dimX"); planeGeometry.faces.push(new THREE.Face3(0, 3, 2));
var dimY = this.get("dimY"); planeGeometry.computeFaceNormals();
var baseVertOffset = xySep/Math.sqrt(3); var mesh = new THREE.Mesh(planeGeometry, new THREE.MeshBasicMaterial({color:0x000000, transparent:true, opacity:0.0}));
var pointVertOffset = 2*baseVertOffset; return [mesh];
var horizontalOffset = xySep; // return [mesh, new THREE.Line(geometry, new THREE.LineBasicMaterial({color:0x000000, transparent:true, linewidth:2, opacity:this.get("material").opacity}), THREE.LinePieces)];
var yOffset = 1/Math.sqrt(3)/2;
for (var j=-dimX;j<=dimX;j++){
for (var i=-dimY;i<=dimY;i++){
var xOffset = 0;
if (Math.abs(j)%2!=0) {
xOffset = 1/2*xScale;
}
vertices.push(new THREE.Vector3(i*xScale + xOffset - horizontalOffset - xScale/2, j*yScale + baseVertOffset - yOffset, 0));
vertices.push(new THREE.Vector3(i*xScale + xOffset + horizontalOffset - xScale/2, j*yScale + baseVertOffset - yOffset, 0));
vertices.push(new THREE.Vector3(i*xScale + xOffset - xScale/2, j*yScale - pointVertOffset - yOffset, 0));
}
}
return vertices;
},
updateXYSeparation: function(xySep){
var geometry = this.get("mesh")[0].geometry;
geometry.vertices = this._calcOctaFaceVertices(xySep);
geometry.verticesNeedUpdate = true;
},
calcHighlighterParams: function(face, point){
point.z = 0;
var index = lattice.getIndexForPosition(point);
if (index.z%2 != 0) index.x -= 1;
return BasePlane.prototype.calcHighlighterParams.call(this, face, point, index);
} }
}); });
}); });
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
function(_, THREE, three, lattice, appState, DMACell){ function(_, THREE, three, lattice, appState, DMACell){
var unitCellGeo = new THREE.CylinderGeometry(Math.sqrt(3)/2, Math.sqrt(3)/2, 1, 6); var unitCellGeo = new THREE.CylinderGeometry(1, 1, 1, 6);
unitCellGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2)); unitCellGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2));
function HexagonalCell(json, superCell){ function HexagonalCell(json, superCell){
...@@ -26,5 +26,18 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], ...@@ -26,5 +26,18 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
// return wireframe; // return wireframe;
// }; // };
HexagonalCell.prototype._buildWireframe = function(mesh){//abstract mesh representation of cell
var wireframe = new THREE.EdgesHelper(mesh, 0x000000);
wireframe.matrixWorld = mesh.matrixWorld;
wireframe.matrixAutoUpdate = true;
return wireframe;
};
HexagonalCell.prototype.calcHighlighterParams = function(face, point){//this works for rectalinear, override in subclasses
var direction = this.applyAbsoluteRotation(face.normal.clone());//todo local orientation?
if (direction.z < 0.9) return null;
};
return HexagonalCell; return HexagonalCell;
}); });
\ No newline at end of file
...@@ -22,20 +22,28 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre ...@@ -22,20 +22,28 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
}, },
getIndexForPosition: function(absPosition){ getIndexForPosition: function(absPosition){
return this._indexForPosition(absPosition); var index = this._indexForPosition(absPosition);
if (index.y%2 != 0) {
absPosition.x += this.xScale()/2;
index = this._indexForPosition(absPosition);
}
return index;
}, },
getPositionForIndex: function(index){ getPositionForIndex: function(index){
return this._positionForIndex(index); var position = this._positionForIndex(index);
if ((index.y%2) != 0) position.x -= this.xScale()/2;
return position;
}, },
xScale: function(cellSeparation){ xScale: function(cellSeparation){
if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
return 2*Math.sqrt(3)+2*cellSeparation; return Math.sqrt(3)+2*cellSeparation;
}, },
yScale: function(cellSeparation){ yScale: function(cellSeparation){
return this.xScale(cellSeparation); if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
return 1.5+2*cellSeparation;
}, },
zScale: function(cellSeparation){ zScale: function(cellSeparation){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment