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

heading home

parent c8bf9138
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@
var unitOctHeight = 2/Math.sqrt(6);
var unitCellGeo1 = new THREE.OctahedronGeometry(1/Math.sqrt(2));
unitCellGeo1.dynamic = true;
unitCellGeo1.applyMatrix(new THREE.Matrix4().makeRotationZ(-3*Math.PI/12));
unitCellGeo1.applyMatrix(new THREE.Matrix4().makeRotationX(Math.asin(2/Math.sqrt(2)/Math.sqrt(3))));
......@@ -25,13 +26,28 @@
var cellGeometry1;
var cellGeometry2;
setScale(30);
var globalCellScale = 30;
function setScale(scale){
setGlobalCellScale(globalCellScale);
function setGlobalCellScale(scale){
globalCellScale = scale;
cellGeometry1 = unitCellGeo1.clone();
cellGeometry1.applyMatrix(new THREE.Matrix4().makeScale(scale, scale, scale));
setFlags(cellGeometry1);
cellGeometry2 = unitCellGeo2.clone();
cellGeometry2.applyMatrix(new THREE.Matrix4().makeScale(scale, scale, scale));
setFlags(cellGeometry2);
}
function setFlags(geometry){
geometry.verticesNeedUpdate = true;
geometry.elementsNeedUpdate = true;
geometry.morphTargetsNeedUpdate = true;
geometry.uvsNeedUpdate = true;
geometry.normalsNeedUpdate = true;
geometry.colorsNeedUpdate = true;
geometry.tangentsNeedUpdate = true;
}
function DMACell(mode, indices, scale) {
......@@ -74,11 +90,16 @@
} else {
mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry2, cellMaterials);
}
mesh = this._setMeshPosition(mesh, position);
mesh.myCell = this;//we need a reference to this instance from the mesh for intersection selection stuff
return mesh;
};
DMACell.prototype._setMeshPosition = function(mesh, position){
mesh.position.x = position.x;
mesh.position.y = position.y;
mesh.position.z = position.z;
mesh.myCell = this;//we need a reference to this instance from the mesh for intersection selection stuff
return mesh;
};
......@@ -103,6 +124,15 @@
this.cellMesh.visible = visibility;
};
DMACell.prototype.changeScale = function(scale){
if (globalCellScale != scale) setGlobalCellScale(scale);
var position = this._calcPosition(scale, this.indices);
this._setMeshPosition(this.cellMesh, position);
_.each(this.parts, function(part){
part.changeScale(scale, position);
});
};
DMACell.prototype.remove = function(){
if (this.cellMesh) window.three.sceneRemove(this.cellMesh);
};
......
......@@ -38,14 +38,7 @@
DMAPart.prototype._makeMeshForType = function(type){
var mesh = new THREE.Mesh(partGeometry);
mesh.position.x = this.position.x;
mesh.position.y = -30/3*Math.sqrt(3)+this.position.y;
mesh.position.z = this.position.z;
if (this.oddZFlag){//adjust some offsets for odd z layers
mesh.position.y += 30 + 30/6;
mesh.rotateZ(Math.PI);
}
mesh = this._setMeshPosition(mesh, 30);
switch(type){
case 1:
......@@ -58,6 +51,24 @@
return mesh;
};
DMAPart.prototype._setMeshPosition = function(mesh, scale, position){
position = position || this.position;
mesh.position.x = position.x;
mesh.position.y = -scale/3*Math.sqrt(3)+position.y;
mesh.position.z = position.z;
if (this.oddZFlag){//adjust some offsets for odd z layers
mesh.position.y += 7*scale/6;
mesh.rotateZ(Math.PI);
}
return mesh;
};
DMAPart.prototype.changeScale = function(scale, position){
this.position = position;
if (this.mesh) this._setMeshPosition(this.mesh, scale, position);
};
DMAPart.prototype.show = function(){
if (!this.mesh) this._draw();
this.mesh.visible = true;
......
......@@ -8,8 +8,8 @@ LatticeMenuView = Backbone.View.extend({
el: "#menuContent",
events: {
"click #latticeMenuClearCells": "_clearCells"
"click #latticeMenuClearCells": "_clearCells",
"change #latticeScale": "_changeScale"
},
currentlySelected: false,
......@@ -30,6 +30,13 @@ LatticeMenuView = Backbone.View.extend({
this.model.clearCells();
},
_changeScale: function(e){
e.preventDefault();
var val = parseFloat($(e.target).val());
if (isNaN(val)) return;
this.model.set("scale", val);
},
_formatData: function(){
var formattedCellType = "Octagon";
var formattedConnectionType = "Face-Connected";
......@@ -45,7 +52,7 @@ LatticeMenuView = Backbone.View.extend({
template: _.template('\
Cell Type: &nbsp;&nbsp;<%= formattedCellType %><br/>\
Cell Connection:&nbsp;&nbsp;<%= formattedConnectionType %><br/>\
Scale:&nbsp;&nbsp;<%= scale %><br/>\
Scale:&nbsp;&nbsp;<input id="latticeScale" value="<%= scale %>" placeholder="enter scale" class="form-control" type="text"><br/>\
NumCells:&nbsp;&nbsp;<%= numCells %><br/>\
Show Bounding Box:<br/><br/>\
<a href="#" id="latticeMenuClearCells" class=" btn btn-block btn-lg btn-default">Clear All Cells</a><br/>\
......
......@@ -24,8 +24,13 @@ Lattice = Backbone.Model.extend({
//bind events
this.listenTo(this, "change:cellMode", this._cellModeDidChange);
this.listenTo(this, "change:scale", this._scaleDidChange);
},
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////ADD/REMOVE CELLS/////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
addCell: function(absPosition){
var cells = this.get("cells");
......@@ -167,6 +172,10 @@ Lattice = Backbone.Model.extend({
window.three.render();
},
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////EVENTS//////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
_cellModeDidChange: function(){
var mode = this.get("cellMode");
this._iterCells(this.get("cells"), function(cell){
......@@ -175,6 +184,18 @@ Lattice = Backbone.Model.extend({
window.three.render();
},
_scaleDidChange: function(){
var scale = this.get("scale");
this._iterCells(this.get("cells"), function(cell){
if (cell) cell.changeScale(scale);
});
window.three.render();
},
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////UTILS///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
_iterCells: function(cells, callback){
_.each(cells, function(cellLayer){
_.each(cellLayer, function(cellColumn){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment