Commit 9bf341e1 authored by amandaghassaei's avatar amandaghassaei

deleting a lot of junk

parent 42816e5d
......@@ -96,6 +96,8 @@
<li><a id="videoRendering" href="#">Video Rendering 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="orthoCamera" href="#">Orthographic Camera</a></li>
<li><a id="persCamera" href="#">Perspective Camera</a></li>
</ul>
</li>
<!--<li class="dropdown-submenu">-->
......
......@@ -107,25 +107,11 @@ define(['lattice', 'plist', 'console'], function(lattice, plist, myConsole){
lattice.clearCells();
},
getSparseCells: function(){
myConsole.write("lattice.getSparseCells()");
return lattice.getSparseCells();
},
setSparseCells: function(cells){
lattice.setSparseCells(cells);
},
getCells: function(){
myConsole.write("lattice.getCells()");
return lattice.getCells();
},
loopSparseCells: function(){
myConsole.write("lattice.loopSparseCells()");
},
loopCells: function(){
myConsole.write("lattice.loopCells()");
......
......@@ -77,12 +77,12 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'],
lines.position[normalAxis] = object3D.position[normalAxis];
},
getAbsoluteIndex: function(){
getIndex: function(){
return this.highligherIndex.clone();
},
getAbsolutePosition: function(){
return lattice.getPositionForIndex(this.getAbsoluteIndex());
getPosition: function(){
return lattice.getPositionForIndex(this.getIndex());
},
calcHighlighterParams: function(face, point, index){//index comes from subclass
......
......@@ -3,8 +3,8 @@
*/
define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
function(_, THREE, three, lattice, appState, DMACell){
define(['three', 'cell'],
function(THREE, DMACell){
var unitCellGeo = new THREE.BoxGeometry(1,1,1);
......
......@@ -8,42 +8,37 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
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 (superCell) this.superCell = superCell;
this.material = materials.getMaterialForId(json.materialID || appState.get("materialType"));
else console.warn("no index given for new cell");
this.material = materials.getMaterialForId(json.materialID || appState.get("materialType"));//material object
this.isTransparent = false;
//object 3d is parent to all 3d elements owned by cell: cell mesh and wireframe, parts, beams, nodes, etc
this.object3D = this._buildObject3D();
this.addChildren(this._buildMesh(), this.object3D);//build cell meshes
if (this.superCell) this.superCell.addChildren(this.object3D);//add as child of supercell
if (!this.sparseCells) this.setMode();
var object3D = this._buildObject3D();
this.object3D = object3D;//save object3D reference
var cellMeshes = this._buildCellMeshes();//cell mesh and wireframe
this.addChildren(cellMeshes, object3D);//build cell meshes
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
DMACell.prototype._buildObject3D = function() {
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";
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(){
return this.object3D.children[0];
};
......@@ -58,7 +53,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
return object3D;
};
DMACell.prototype._buildMesh = function(){
DMACell.prototype._buildCellMeshes = function(){
var geometry = this._getGeometry();
var meshes = [];
......@@ -74,8 +69,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
};
DMACell.prototype._getMeshName = function(){
if (this._isBottomLayer()) return "cell";
return "supercell";
return "cell";
};
DMACell.prototype._buildWireframe = function(mesh, geometry){//for "cell" view
......@@ -92,63 +86,27 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
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(){
return new THREE.Vector3(1,1,1);
};
DMACell.prototype.getAbsoluteDimensions = function(){
return this.getDimensions();
};
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.getLatticeIndex = function(){//relative index in lattice
return this.getIndex().sub(lattice.get("cellsMin"));
};
DMACell.prototype.getPosition = function(){
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(){
return this.object3D.quaternion.clone();
};
DMACell.prototype.getAbsoluteOrientation = function(){
if (!this.superCell) return this.getOrientation();
return this.getOrientation().multiply(this.superCell.getAbsoluteOrientation());//order matters!
};
DMACell.prototype.applyRotation = function(vector){//todo local rotation?
DMACell.prototype.applyRotation = function(vector){
vector.applyQuaternion(this.getOrientation());
return vector;
};
DMACell.prototype.applyAbsoluteRotation = function(vector){
vector.applyQuaternion(this.getAbsoluteOrientation());
return vector;
};
......@@ -158,34 +116,23 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
//highlighting
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 position = this.getAbsolutePosition();
var direction = this.applyRotation(face.normal.clone());
var position = this.getPosition();
position.add(direction.clone().multiply(this.aspectRatio().divideScalar(2)));
return {direction:direction, position:position};
};
DMACell.prototype.setDeleteMode = function(state){
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();
else threeMaterial = this.getMaterial(true);
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);
};
DMACell.prototype.getParent = function(){
if (this.superCell) return this.superCell.getParent();
DMACell.prototype.getParent = function(){//todo need this?
return this;
};
......@@ -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
this._addRemoveChildren(true, children, object3D);
......@@ -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
if (object3D === undefined) object3D = this.object3D;
if (children.constructor === Array){
_.each(children, function(child){
if (shouldAdd) object3D.add(child);
else object3D.remove(child);
});
} 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', '
this.object3D.visible = false;
};
DMACell.prototype.show = function(mode, callback){
DMACell.prototype.show = function(){
this.object3D.visible = true;
this.setMode(mode, callback);
};
DMACell.prototype.getMaterialID = function(){
......@@ -254,16 +199,11 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
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);
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){
this._setTransparent(transparent);
};
......@@ -280,109 +220,32 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', '
}
};
DMACell.prototype.getConditionalMode = function(mode){
if (mode == "supercell" && this._isBottomLayer() && this._isTopLayer()) return "cell";//in super cell mode, cell w/o parent are still visible
return mode;
DMACell.prototype.setWireframeVisibility = function(visible){
this.object3D.children[1].visible = visible;
};
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
var geometry = [];
if (this.isTransparent) return geometry;
if (!this.object3D.visible) return geometry;
var meshes = _.filter(this.object3D.children, function(child){
return child.visible && child instanceof THREE.Mesh
});
if (meshes.length > 0) {
var self = this;
_.each(meshes, function(mesh){
geometry.push({geo: mesh.geometry, offset:self.getAbsolutePosition(), orientation:mesh.quaternion.clone().multiply(self.getAbsoluteOrientation())});
});
return geometry;
}
if (!this.sparseCells) return geometry;
this._loopCells(function(cell){
if (cell) geometry = geometry.concat(cell.getVisibleGeometry());
});
//var meshes = _.filter(this.object3D.children, function(child){
// return child.visible && child instanceof THREE.Mesh
//});
//if (meshes.length > 0) {
// var self = this;
// _.each(meshes, function(mesh){
// geometry.push({geo: mesh.geometry, offset:self.getAbsolutePosition(), orientation:mesh.quaternion.clone().multiply(self.getAbsoluteOrientation())});
// });
//}
var mesh = this.getHighlightableMesh();
if (mesh.visible) geometry.push(mesh);
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', '
};
//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
DMACell.prototype.destroy = function(){//todo remove reference from lattice.cells
this.destroyParts();
if (this.object3D) {
if (this.superCell) this.superCell.removeChildren(this.object3D);
else if (this.index) three.sceneRemove(this.object3D);
if (!this.sparseCells) lattice.getUItarget().removeHighlightableCell(this.getHighlightableMesh());//remove mesh as highlightable object
this.object3D.myParent = null;
var object3D = this.object3D;
three.sceneRemove(object3D);
lattice.removeHighlightableCell(this.getHighlightableMesh());//remove mesh as highlightable object
object3D.myParent = null;
_.each(this.object3D.children, function(child, index){
object3D.children[index] = null;
});
// this.object3D.dispose();
// geometry.dispose();
// material.dispose();
this.object3D = null;
}
this.superCell = null;
this.material = null;
this.index = null;
this.length = null;
};
DMACell.prototype.destroyParts = function(){
if (!this.parts) return;
_.each(this.parts, function(part){
if (part) part.destroy();
});
this.parts = null;
};
DMACell.prototype.toJSON = function(){
var data = {
materialID: this.getMaterialID()
};
// if (this.material.sparseCells) return data;//material definition in material composites
// if (this.sparseCells) data.cells = this.sparseCells;
return data;
};
......
/**
* Created by aghassaei on 6/12/15.
*/
define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', "cubeCell", 'globals', 'materials'],
function(_, THREE, three, lattice, appState, DMASuperCell, CubeCell, globals, materials){
function CompositeCell(json, superCell){
DMASuperCell.call(this, json, superCell);
}
CompositeCell.prototype = Object.create(DMASuperCell.prototype);
CompositeCell.prototype._getGeometry = function(){
var dimensions = this.material.dimensions;
var geo = new THREE.BoxGeometry(dimensions.x*lattice.xScale(), dimensions.y*lattice.yScale(), dimensions.z*lattice.zScale());
geo.applyMatrix(new THREE.Matrix4().makeTranslation((dimensions.x/2-0.5)*lattice.xScale(), (dimensions.y/2-0.5)*lattice.yScale(), (dimensions.z/2-0.5)*lattice.zScale()));
return geo;
};
CompositeCell.prototype._buildWireframe = function(mesh){
var wireframe = new THREE.BoxHelper(mesh);
wireframe.material.color.set(0x000000);
wireframe.matrixWorld = mesh.matrixWorld;
wireframe.matrixAutoUpdate = true;
return wireframe;
};
CompositeCell.prototype._makeCellForJSON = function(json){
if (materials.getMaterialForId(json.materialID).isComposite()) return new CompositeCell(json, this);
return new CubeCell(json, this);
};
CompositeCell.prototype.getDimensions = function(){
return this.getMaterial().getDimensions();
};
return CompositeCell;
});
\ No newline at end of file
/**
* Created by aghassaei on 6/1/15.
*/
define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'],
function(_, THREE, three, lattice, appState, DMACell){
function DMASuperCell(json, superCell){//supercells might have supercells
this.sparseCells = true;//flag for now
DMACell.call(this, json, superCell);
var material = this.getMaterial();
this.sparseCells = this._makeChildCells(this.material.getDimensions(), material);
DMACell.prototype.setMode.call(this, null, function(){
three.conditionalRender();
});//don't pass a call down to children again
}
DMASuperCell.prototype = Object.create(DMACell.prototype);
DMASuperCell.prototype.getOrigin = function(){
return new THREE.Vector3(0,0,0);
};
DMASuperCell.prototype.getAbsoluteOrigin = function(){
if (!this.superCell) return this.applyRotation(this.getOrigin());
return this.applyAbsoluteRotation(this.getOrigin()).round();
};
DMASuperCell.prototype.getAbsoluteDimensions = function(){
var rotationPt = this.getOrigin().add(new THREE.Vector3(1,1,1));
var dims = this.applyAbsoluteRotation(this.getDimensions().sub(rotationPt)).add(rotationPt);
_.each(dims, function(val, key){
if (val < 0) dims[key] = -val;
});
return dims.round();
};
DMASuperCell.prototype.getBounds = function(){
var origin = this.getOrigin();
var index = this.getIndex();
var min = index.clone().sub(origin);
var max = index.add(this.getDimensions()).sub(origin).sub(new THREE.Vector3(1,1,1));
return {min: min, max: max};
};
DMASuperCell.prototype.getAbsoluteBounds = function(){
var origin = this.getAbsoluteOrigin();
var index = this.getAbsoluteIndex();
var min = index.clone().sub(origin);
var max = index.add(this.getAbsoluteDimensions()).sub(origin).sub(new THREE.Vector3(1,1,1));
return {min: min, max: max};
};
DMASuperCell.prototype._makeChildCells = function(range, material){
var cells = [];
for (var x=0;x<range.x;x++){
cells.push([]);
for (var y=0;y<range.y;y++){
cells[x].push([]);
for (var z=0;z<range.z;z++){
//child cells add themselves to object3D
cells[x][y].push(null);
if (material.sparseCells[x][y][z]){
var json = {index: new THREE.Vector3(x, y, z)};
json.index.add(material.