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

pulled scale hard coded into cell class

parent 53b93cd0
Branches
No related tags found
No related merge requests found
......@@ -7,30 +7,39 @@
(function () {
var octHeight = 2*30/Math.sqrt(6);
var unitOctHeight = 2/Math.sqrt(6);
var cellGeometry1 = new THREE.OctahedronGeometry(30/Math.sqrt(2));
cellGeometry1.applyMatrix(new THREE.Matrix4().makeRotationZ(-3*Math.PI/12));
cellGeometry1.applyMatrix(new THREE.Matrix4().makeRotationX(Math.asin(2/Math.sqrt(2)/Math.sqrt(3))));
var unitCellGeo1 = new THREE.OctahedronGeometry(1/Math.sqrt(2));
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))));
var cellGeometry2 = cellGeometry1.clone();
var unitCellGeo2 = unitCellGeo1.clone();
cellGeometry1.applyMatrix(new THREE.Matrix4().makeTranslation(0,-30/Math.sqrt(3),octHeight/2));
cellGeometry2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI));
cellGeometry2.applyMatrix(new THREE.Matrix4().makeTranslation(0,30/Math.sqrt(3),octHeight/2));
unitCellGeo1.applyMatrix(new THREE.Matrix4().makeTranslation(0,-1/Math.sqrt(3),unitOctHeight/2));
unitCellGeo2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI));
unitCellGeo2.applyMatrix(new THREE.Matrix4().makeTranslation(0,1/Math.sqrt(3),unitOctHeight/2));
var cellMaterials = [new THREE.MeshNormalMaterial(),
new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})];
var cellGeometry1;
var cellGeometry2;
function DMACell(mode, indices) {
setScale(30);
this.indices = indices;
this.position = this._calcPositionForScale(30);
function setScale(scale){
cellGeometry1 = unitCellGeo1.clone();
cellGeometry1.applyMatrix(new THREE.Matrix4().makeScale(scale, scale, scale));
cellGeometry2 = unitCellGeo2.clone();
cellGeometry2.applyMatrix(new THREE.Matrix4().makeScale(scale, scale, scale));
}
this.parts = this._initParts();
function DMACell(mode, indices, scale) {
this.indices = indices;
this.position = this._calcPositionForScale(scale);
this.parts = this._initParts();
this.drawForMode(mode);
}
......@@ -67,7 +76,7 @@
var mesh;
if (Math.round(position.z/octHeight)%2==0){
if (this.indices.z%2==0){
mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry1, cellMaterials);
} else {
mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry2, cellMaterials);
......@@ -76,6 +85,7 @@
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;
};
......
......@@ -55,7 +55,7 @@ Lattice = Backbone.Model.extend({
}
var index = this._subtract(position, this.get("cellsMin"));
cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), position);
cells[index.x][index.y][index.z] = new DMACell(this.get("cellMode"), position, scale);
this.set("numCells", this.get("numCells")+1);
window.three.render();
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment