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

eod

parent f4ef2126
No related branches found
No related tags found
No related merge requests found
...@@ -19,38 +19,62 @@ ...@@ -19,38 +19,62 @@
cellGeometry2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); cellGeometry2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI));
cellGeometry2.applyMatrix(new THREE.Matrix4().makeTranslation(0,30/Math.sqrt(3),octHeight/2)); cellGeometry2.applyMatrix(new THREE.Matrix4().makeTranslation(0,30/Math.sqrt(3),octHeight/2));
var cellMaterials = [new THREE.MeshNormalMaterial(), new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; var cellMaterials = [new THREE.MeshNormalMaterial(),
new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})];
function Cell(position) { function Cell(mode, position) {
if (Math.round(position.z/octHeight)%2==0){ this.position = position;
this.mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry1, cellMaterials); this.drawForMode(mode, position);
} else {
this.mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry2, cellMaterials);
}
this.mesh.position.x = position.x;
this.mesh.position.y = position.y;
this.mesh.position.z = position.z;
this.mesh.myCell = this;//we need a reference to this instance from the mesh for
this._draw(); this._draw();
// this.parts = this._createParts(nodes, config); // this.parts = this._createParts(nodes, config);
} }
//Cell.prototype._createParts = function(nodes, config){ Cell.prototype._buildPartsMesh = function(){
// var parts = []; // var parts = [];
// for (var i=0;i<nodes.length;i++){ // for (var i=0;i<nodes.length;i++){
// parts.push(new Part(nodes[i], config[i])); // parts.push(new Part(nodes[i], config[i]));
// } // }
// return parts; // return parts;
//}; };
Cell.prototype._buildCellMesh = function(position){//abstract mesh representation of cell
var mesh;
if (Math.round(position.z/octHeight)%2==0){
mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry1, cellMaterials);
} else {
mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry2, cellMaterials);
}
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;
};
Cell.prototype._draw = function(){ Cell.prototype._draw = function(){
window.three.sceneAdd(this.mesh); window.three.sceneAdd(this.mesh);
}; };
Cell.prototype.drawForMode = function(mode, position){
if (this.mesh) this.remove();
this.mesh = null;
position = position || this.position;
if (mode == "cell"){
this.mesh = this._buildCellMesh(position);
} else if (mode == "parts"){
this.mesh = this._buildPartsMesh();
} else {
console.warn("unrecognized draw mode for cell");
}
if (this.mesh) this._draw();
};
Cell.prototype.remove = function(){ Cell.prototype.remove = function(){
window.three.sceneRemove(this.mesh); window.three.sceneRemove(this.mesh);
}; };
......
...@@ -12,7 +12,8 @@ Lattice = Backbone.Model.extend({ ...@@ -12,7 +12,8 @@ Lattice = Backbone.Model.extend({
nodes: [], nodes: [],
cells: [], cells: [],
numCells: 0, numCells: 0,
partType: "triangle" partType: "triangle",
cellMode: "cell"
}, },
//pass in fillGeometry //pass in fillGeometry
...@@ -24,7 +25,7 @@ Lattice = Backbone.Model.extend({ ...@@ -24,7 +25,7 @@ Lattice = Backbone.Model.extend({
addCell: function(position){ addCell: function(position){
var cells = this.get("cells"); var cells = this.get("cells");
cells.push(new Cell(position)); cells.push(new Cell(this.get("cellMode"), position));
this.set("numCells", cells.length); this.set("numCells", cells.length);
window.three.render(); window.three.render();
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment