Commit 9bf341e1 authored by amandaghassaei's avatar amandaghassaei

deleting a lot of junk

parent 42816e5d
...@@ -96,6 +96,8 @@ ...@@ -96,6 +96,8 @@
<li><a id="videoRendering" href="#">Video Rendering Setup</a></li> <li><a id="videoRendering" href="#">Video Rendering Setup</a></li>
<li><a id="photoSetup" href="#">Photo Setup</a></li> <li><a id="photoSetup" href="#">Photo Setup</a></li>
<li><a id="undoPhotoSetup" href="#">Undo Photo Setup</a></li> <li><a id="undoPhotoSetup" href="#">Undo Photo Setup</a></li>
<li><a id="orthoCamera" href="#">Orthographic Camera</a></li>
<li><a id="persCamera" href="#">Perspective Camera</a></li>
</ul> </ul>
</li> </li>
<!--<li class="dropdown-submenu">--> <!--<li class="dropdown-submenu">-->
......
...@@ -107,25 +107,11 @@ define(['lattice', 'plist', 'console'], function(lattice, plist, myConsole){ ...@@ -107,25 +107,11 @@ define(['lattice', 'plist', 'console'], function(lattice, plist, myConsole){
lattice.clearCells(); lattice.clearCells();
}, },
getSparseCells: function(){
myConsole.write("lattice.getSparseCells()");
return lattice.getSparseCells();
},
setSparseCells: function(cells){
lattice.setSparseCells(cells);
},
getCells: function(){ getCells: function(){
myConsole.write("lattice.getCells()"); myConsole.write("lattice.getCells()");
return lattice.getCells(); return lattice.getCells();
}, },
loopSparseCells: function(){
myConsole.write("lattice.loopSparseCells()");
},
loopCells: function(){ loopCells: function(){
myConsole.write("lattice.loopCells()"); myConsole.write("lattice.loopCells()");
......
...@@ -77,12 +77,12 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'], ...@@ -77,12 +77,12 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'],
lines.position[normalAxis] = object3D.position[normalAxis]; lines.position[normalAxis] = object3D.position[normalAxis];
}, },
getAbsoluteIndex: function(){ getIndex: function(){
return this.highligherIndex.clone(); return this.highligherIndex.clone();
}, },
getAbsolutePosition: function(){ getPosition: function(){
return lattice.getPositionForIndex(this.getAbsoluteIndex()); return lattice.getPositionForIndex(this.getIndex());
}, },
calcHighlighterParams: function(face, point, index){//index comes from subclass calcHighlighterParams: function(face, point, index){//index comes from subclass
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
*/ */
define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], define(['three', 'cell'],
function(_, THREE, three, lattice, appState, DMACell){ function(THREE, DMACell){
var unitCellGeo = new THREE.BoxGeometry(1,1,1); var unitCellGeo = new THREE.BoxGeometry(1,1,1);
......
...@@ -8,42 +8,37 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -8,42 +8,37 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
var wireframeMaterial = new THREE.MeshBasicMaterial({color:0x000000, wireframe:true}); var wireframeMaterial = new THREE.MeshBasicMaterial({color:0x000000, wireframe:true});
function DMACell(json, superCell){ function DMACell(json){
if (json.index) this.index = new THREE.Vector3(json.index.x, json.index.y, json.index.z); if (json.index) this.index = new THREE.Vector3(json.index.x, json.index.y, json.index.z);
if (superCell) this.superCell = superCell; else console.warn("no index given for new cell");
this.material = materials.getMaterialForId(json.materialID || appState.get("materialType"));
this.material = materials.getMaterialForId(json.materialID || appState.get("materialType"));//material object
this.isTransparent = false; this.isTransparent = false;
//object 3d is parent to all 3d elements owned by cell: cell mesh and wireframe, parts, beams, nodes, etc //object 3d is parent to all 3d elements owned by cell: cell mesh and wireframe, parts, beams, nodes, etc
this.object3D = this._buildObject3D(); var object3D = this._buildObject3D();
this.addChildren(this._buildMesh(), this.object3D);//build cell meshes this.object3D = object3D;//save object3D reference
var cellMeshes = this._buildCellMeshes();//cell mesh and wireframe
if (this.superCell) this.superCell.addChildren(this.object3D);//add as child of supercell this.addChildren(cellMeshes, object3D);//build cell meshes
if (!this.sparseCells) this.setMode(); this.addToScene(object3D);
} }
DMACell.prototype.addToScene = function(superCell){
if (!this.sparseCells) lattice.getUItarget().addHighlightableCell(this.getHighlightableMesh());//add mesh as highlightable object, only for lowest level of hierarchy
if (!superCell || superCell === undefined) three.sceneAdd(this.object3D);//add object3d as child of scene if top level of hierarchy
if (this.sparseCells){
var self = this;
this._loopCells(function(cell){
cell.addToScene(self);
});
}
};
//make 3d stuff //make 3d stuff
DMACell.prototype._buildObject3D = function() { DMACell.prototype._buildObject3D = function() {
var object3D = this._translateCell(this._rotateCell(new THREE.Object3D())); var object3D = this._translateCell(this._rotateCell(new THREE.Object3D()));
if (this._isBottomLayer()) object3D.myParent = this;//reference to get mouse raycasting back, only for lowest level of hierarchy object3D.myParent = this;//reference to get mouse raycasting back
object3D.name = "object3D"; object3D.name = "object3D";
return object3D; return object3D;
}; };
DMACell.prototype.addToScene = function(object3D){
lattice.addHighlightableCell(this.getHighlightableMesh());//add mesh as highlightable object
three.sceneAdd(object3D);//add object3d as child of scene
};
DMACell.prototype.getHighlightableMesh = function(){ DMACell.prototype.getHighlightableMesh = function(){
return this.object3D.children[0]; return this.object3D.children[0];
}; };
...@@ -58,7 +53,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -58,7 +53,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
return object3D; return object3D;
}; };
DMACell.prototype._buildMesh = function(){ DMACell.prototype._buildCellMeshes = function(){
var geometry = this._getGeometry(); var geometry = this._getGeometry();
var meshes = []; var meshes = [];
...@@ -74,8 +69,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -74,8 +69,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
}; };
DMACell.prototype._getMeshName = function(){ DMACell.prototype._getMeshName = function(){
if (this._isBottomLayer()) return "cell"; return "cell";
return "supercell";
}; };
DMACell.prototype._buildWireframe = function(mesh, geometry){//for "cell" view DMACell.prototype._buildWireframe = function(mesh, geometry){//for "cell" view
...@@ -92,63 +86,27 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -92,63 +86,27 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
return this.index.clone(); return this.index.clone();
}; };
DMACell.prototype.getAbsoluteIndex = function(){
if (!this.superCell) return this.getIndex();
var superCellIndex = this.superCell.getAbsoluteIndex();
return superCellIndex.add(this.superCell.applyRotation(this.getIndex()).round());
};
DMACell.prototype.getDimensions = function(){ DMACell.prototype.getDimensions = function(){
return new THREE.Vector3(1,1,1); return new THREE.Vector3(1,1,1);
}; };
DMACell.prototype.getAbsoluteDimensions = function(){ DMACell.prototype.getLatticeIndex = function(){//relative index in lattice
return this.getDimensions(); return this.getIndex().sub(lattice.get("cellsMin"));
};
DMACell.prototype.getBounds = function(){//todo need to account for origin eventually
var index = this.getIndex();
return {min: index, max: index};
};
DMACell.prototype.getAbsoluteBounds = function(){
var index = this.getAbsoluteIndex();
return {min: index, max: index};
};
DMACell.prototype.getLatticeIndex = function(){
var parent = lattice.getUItarget();//todo no
return this.getAbsoluteIndex().sub(parent.get("cellsMin"));
}; };
DMACell.prototype.getPosition = function(){ DMACell.prototype.getPosition = function(){
return this.object3D.position.clone(); return this.object3D.position.clone();
}; };
DMACell.prototype.getAbsolutePosition = function(){
if (!this.superCell) return this.getPosition();
return this.superCell.getAbsolutePosition().add(this.superCell.applyRotation(this.getPosition()));
};
DMACell.prototype.getOrientation = function(){ DMACell.prototype.getOrientation = function(){
return this.object3D.quaternion.clone(); return this.object3D.quaternion.clone();
}; };
DMACell.prototype.getAbsoluteOrientation = function(){ DMACell.prototype.applyRotation = function(vector){
if (!this.superCell) return this.getOrientation();
return this.getOrientation().multiply(this.superCell.getAbsoluteOrientation());//order matters!
};
DMACell.prototype.applyRotation = function(vector){//todo local rotation?
vector.applyQuaternion(this.getOrientation()); vector.applyQuaternion(this.getOrientation());
return vector; return vector;
}; };
DMACell.prototype.applyAbsoluteRotation = function(vector){
vector.applyQuaternion(this.getAbsoluteOrientation());
return vector;
};
...@@ -158,34 +116,23 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -158,34 +116,23 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
//highlighting //highlighting
DMACell.prototype.calcHighlighterParams = function(face, point){//this works for cells where addition happens orthogonal to all faces DMACell.prototype.calcHighlighterParams = function(face, point){//this works for cells where addition happens orthogonal to all faces
var direction = this.applyAbsoluteRotation(face.normal.clone());//todo local orientation? var direction = this.applyRotation(face.normal.clone());
var position = this.getAbsolutePosition(); var position = this.getPosition();
position.add(direction.clone().multiply(this.aspectRatio().divideScalar(2))); position.add(direction.clone().multiply(this.aspectRatio().divideScalar(2)));
return {direction:direction, position:position}; return {direction:direction, position:position};
}; };
DMACell.prototype.setDeleteMode = function(state){ DMACell.prototype.setDeleteMode = function(state){
var threeMaterial; var threeMaterial;
if (!state && !this.material) return;//cell may be deleted by now if (!state && !this.material) return;//cell may be deleted by now todo need this?
if (state) threeMaterial = materials.getDeleteMaterial(); if (state) threeMaterial = materials.getDeleteMaterial();
else threeMaterial = this.getMaterial(true); else threeMaterial = this.getMaterial(true);
if (!threeMaterial) return;//no material object found if (!threeMaterial) return;//no material object found
if (this.sparseCells){
this._loopCells(function(cell){
if (cell) cell.setDeleteMode(state);
});
}
if (this.parts){
_.each(this.parts, function(part){
if (part) part.setMaterial(threeMaterial);
});
}
this._setTHREEMaterial(threeMaterial); this._setTHREEMaterial(threeMaterial);
}; };
DMACell.prototype.getParent = function(){ DMACell.prototype.getParent = function(){//todo need this?
if (this.superCell) return this.superCell.getParent();
return this; return this;
}; };
...@@ -195,7 +142,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -195,7 +142,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
//children //children of object3D
DMACell.prototype.addChildren = function(children, object3D){//accepts an array or a single mesh DMACell.prototype.addChildren = function(children, object3D){//accepts an array or a single mesh
this._addRemoveChildren(true, children, object3D); this._addRemoveChildren(true, children, object3D);
...@@ -206,14 +153,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -206,14 +153,13 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
}; };
DMACell.prototype._addRemoveChildren = function(shouldAdd, children, object3D){//accepts an array or a single mesh DMACell.prototype._addRemoveChildren = function(shouldAdd, children, object3D){//accepts an array or a single mesh
if (object3D === undefined) object3D = this.object3D;
if (children.constructor === Array){ if (children.constructor === Array){
_.each(children, function(child){ _.each(children, function(child){
if (shouldAdd) object3D.add(child); if (shouldAdd) object3D.add(child);
else object3D.remove(child); else object3D.remove(child);
}); });
} else if (shouldAdd) object3D.add(children); } else if (shouldAdd) object3D.add(children);
else object3D.remove(children);//todo this ok? else object3D.remove(children);
}; };
...@@ -226,9 +172,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -226,9 +172,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
this.object3D.visible = false; this.object3D.visible = false;
}; };
DMACell.prototype.show = function(mode, callback){ DMACell.prototype.show = function(){
this.object3D.visible = true; this.object3D.visible = true;
this.setMode(mode, callback);
}; };
DMACell.prototype.getMaterialID = function(){ DMACell.prototype.getMaterialID = function(){
...@@ -254,16 +199,11 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -254,16 +199,11 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
return this.material.getThreeMaterial(); return this.material.getThreeMaterial();
}; };
DMACell.prototype.changeMaterial = function(materialID, material){ DMACell.prototype.changeMaterial = function(materialID, material){//todo should use this?
if (material === undefined) material = materials.getMaterialForId(materialID); if (material === undefined) material = materials.getMaterialForId(materialID);
this.setMaterial(material); this.setMaterial(material);
}; };
DMACell.prototype.setWireframeVisibility = function(visible, mode){
if (visible && mode === undefined) mode = this.getConditionalMode(appState.get("cellMode"));
this.object3D.children[1].visible = visible && this.object3D.children[1].name == mode;
};
DMACell.prototype.setTransparent = function(transparent){ DMACell.prototype.setTransparent = function(transparent){
this._setTransparent(transparent); this._setTransparent(transparent);
}; };
...@@ -280,109 +220,32 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -280,109 +220,32 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
} }
}; };
DMACell.prototype.getConditionalMode = function(mode){ DMACell.prototype.setWireframeVisibility = function(visible){
if (mode == "supercell" && this._isBottomLayer() && this._isTopLayer()) return "cell";//in super cell mode, cell w/o parent are still visible this.object3D.children[1].visible = visible;
return mode;
}; };
DMACell.prototype.setMode = function(mode, callback){
if (!mode || mode === undefined) mode = appState.get("cellMode");
var self = this;
mode = this.getConditionalMode(mode);
switch(mode) {
case "supercell":
setVisiblity();
break;
case "cell":
setVisiblity();
break;
case "part":
if (!this.sparseCells && !this.parts) {
this._initParts(function(parts){
self.parts = parts;
setVisiblity();
});
} else setVisiblity();
break;
default:
break;
}
function setVisiblity(){
var visible = true;
if (mode == "supercell") visible = !self._isMiddleLayer();//middle layers are always hidden in supercell mode
_.each(self.object3D.children, function(child){
if (child.name == "object3D") return;
child.visible = visible && (child.name == mode);
});
self.setWireframeVisibility(!self.isTransparent && visible, mode);
if (callback) {
callback();
return;
}
if (!self.superCell) three.conditionalRender();
}
};
DMACell.prototype._isBottomLayer = function(){
return true;
};
DMACell.prototype._isMiddleLayer = function(){
return false;
};
DMACell.prototype._isTopLayer = function(){
return this.superCell === null || this.superCell === undefined;
};
DMACell.prototype.getVisibleGeometry = function(){//for save stl DMACell.prototype.getVisibleGeometry = function(){//for save stl
var geometry = []; var geometry = [];
if (this.isTransparent) return geometry; if (this.isTransparent) return geometry;
if (!this.object3D.visible) return geometry; if (!this.object3D.visible) return geometry;
var meshes = _.filter(this.object3D.children, function(child){ //var meshes = _.filter(this.object3D.children, function(child){
return child.visible && child instanceof THREE.Mesh // return child.visible && child instanceof THREE.Mesh
}); //});
if (meshes.length > 0) { //if (meshes.length > 0) {
var self = this; // var self = this;
_.each(meshes, function(mesh){ // _.each(meshes, function(mesh){
geometry.push({geo: mesh.geometry, offset:self.getAbsolutePosition(), orientation:mesh.quaternion.clone().multiply(self.getAbsoluteOrientation())}); // geometry.push({geo: mesh.geometry, offset:self.getAbsolutePosition(), orientation:mesh.quaternion.clone().multiply(self.getAbsoluteOrientation())});
}); // });
return geometry; //}
} var mesh = this.getHighlightableMesh();
if (!this.sparseCells) return geometry; if (mesh.visible) geometry.push(mesh);
this._loopCells(function(cell){
if (cell) geometry = geometry.concat(cell.getVisibleGeometry());
});
return geometry; return geometry;
}; };
DMACell.prototype.getCells = function(){
return [[[this]]];
};
DMACell.prototype.getSparseCells = function(){
return null;
};
//subcomponents
DMACell.prototype._initParts = function(callback){
if (callback) callback();//override in subclasses
return [];
};
...@@ -407,57 +270,30 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' ...@@ -407,57 +270,30 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
}; };
//parse
DMACell.prototype.addToDenseArray = function(cellsArray, min){
var index = this.getAbsoluteIndex().sub(min);
if (cellsArray[index.x][index.y][index.z]) {
console.warn("cell overlap, something bad happened");
return;
}
cellsArray[index.x][index.y][index.z] = this;
};
//destroy //destroy
DMACell.prototype.destroy = function(){//todo remove reference from lattice.cells DMACell.prototype.destroy = function(){//todo remove reference from lattice.cells
this.destroyParts();
if (this.object3D) { if (this.object3D) {
if (this.superCell) this.superCell.removeChildren(this.object3D); var object3D = this.object3D;
else if (this.index) three.sceneRemove(this.object3D); three.sceneRemove(object3D);
if (!this.sparseCells) lattice.getUItarget().removeHighlightableCell(this.getHighlightableMesh());//remove mesh as highlightable object lattice.removeHighlightableCell(this.getHighlightableMesh());//remove mesh as highlightable object
this.object3D.myParent = null; object3D.myParent = null;
_.each(this.object3D.children, function(child, index){
object3D.children[index] = null;
});
// this.object3D.dispose(); // this.object3D.dispose();
// geometry.dispose(); // geometry.dispose();
// material.dispose(); // material.dispose();
this.object3D = null; this.object3D = null;
} }
this.superCell = null;
this.material = null; this.material = null;
this.index = null; this.index = null;
this.length = null;
};
DMACell.prototype.destroyParts = function(){
if (!this.parts) return;
_.each(this.parts, function(part){
if (part) part.destroy();
});