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

parts

parent 0cad19e2
No related branches found
No related tags found
No related merge requests found
File deleted
File deleted
File deleted
File added
File deleted
File deleted
......@@ -39,7 +39,7 @@
this.indices = indices;
this.position = this._calcPositionForScale(scale);
this.parts = this._initParts();
this.parts = this._initParts(this.position);
this.drawForMode(mode);
}
......@@ -56,18 +56,10 @@
return position;
};
DMACell.prototype._initParts = function(){
DMACell.prototype._initParts = function(position){
var parts = [];
for (var i=0;i<3;i++){
parts.push(new DMAPart(i));
}
return parts;
};
DMACell.prototype._buildPartsMesh = function(position){
var parts = [];
for (var i=0;i<nodes.length;i++){
parts.push(new Part(nodes[i], config[i]));
parts.push(new DMAPart(i, position));
}
return parts;
};
......@@ -85,24 +77,26 @@
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;
};
DMACell.prototype.drawForMode = function(mode){
console.log(mode);
if (mode == "cell"){
if (this.cellMesh) this._setCellMeshVisibility(true);
else {
this.cellMesh = this._buildCellMesh(this.position);
window.three.sceneAdd(this.cellMesh);
}
_.each(this.parts, function(part){
part.hide();
});
} else if (mode == "parts"){
if (this.cellMesh) this._setCellMeshVisibility(false);
else {
// this.parts = this._buildPartsMesh();
// window.three.sceneAdd(this.parts);
}
this._setCellMeshVisibility(false);
_.each(this.parts, function(part){
part.show();
});
} else {
console.warn("unrecognized draw mode for cell");
}
......@@ -111,9 +105,6 @@
DMACell.prototype._setCellMeshVisibility = function(visibility){
if (!this.cellMesh) return;
this.cellMesh.visible = visibility;
// _.each(this.cellMesh.children, function(childMesh){
// childMesh.visible = visibility;
// });
};
DMACell.prototype.remove = function(){
......
......@@ -7,16 +7,61 @@
(function () {
//import part geometry
var loader = new THREE.STLLoader();
loader.addEventListener('load', onMeshLoad);
loader.load("data/trianglePart.stl");
var partGeometry1;
var partGeometry;
function onMeshLoad(e){
console.log("part loaded");
partGeometry = e.content;
partGeometry.computeBoundingBox();
var unitScale = 1/partGeometry.boundingBox.max.y;
partGeometry.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale));
partGeometry.applyMatrix(new THREE.Matrix4().makeTranslation(0.2,-0.5, 0));
partGeometry.applyMatrix(new THREE.Matrix4().makeRotationZ(-Math.PI/6));
partGeometry.applyMatrix(new THREE.Matrix4().makeScale(30,30,30));
}
function DMAPart(type, position) {
function DMAPart(type) {
this.position = position;
this.type = type;
// this.nodes = nodes;
// this.beams = this._createBeams(nodes, config);
this.scale = 10;
// this.geometry = geometry;
}
DMAPart.prototype._draw = function(){
this.mesh = this._makeMeshForType(this.type);
window.three.sceneAdd(this.mesh);
};
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;
//todo this sucks, go back and fix the real problem
if (Math.round(mesh.position.z/(2*30/Math.sqrt(6)))%2 == 1){
mesh.position.y += 30 + 30/6;
mesh.rotateZ(Math.PI);
}
switch(type){
case 1:
mesh.rotateZ(2*Math.PI/3);
break;
case 2:
mesh.rotateZ(-2*Math.PI/3);
break;
}
return mesh;
};
DMAPart.prototype._createBeams = function(nodes, config){
// var beams = [];
// _.each(config, function(pair){
......@@ -25,7 +70,13 @@
// return beams;
};
DMAPart.prototype.render = function(){
DMAPart.prototype.show = function(){
if (!this.mesh) this._draw();
this.mesh.visibility = true;
};
DMAPart.prototype.hide = function(){
if (this.mesh) this.mesh.visibility = false;
};
self.DMAPart = DMAPart;
......
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