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);
......
This diff is collapsed.
/**
* 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.cellsMin);
json = _.extend(json, material.sparseCells[x][y][z]);
cells[x][y][z] = this._makeCellForJSON(json);
}//else no cell in this spot
}
}
}
return cells;
};
DMASuperCell.prototype.setMode = function(mode, callback){
var self = this;
DMACell.prototype.setMode.call(this, mode, function(){
var numChildren = _.filter(self.object3D.children, function(child){
return child.name == "object3D";
}).length;//todo this is weird
self._loopCells(function(cell){
cell.setMode(mode, function(){
if (--numChildren <= 0) {
if (callback) {
callback();
return;
}
three.conditionalRender();
}
});
});
});
};
DMASuperCell.prototype._isBottomLayer = function(){
return false;
};
DMASuperCell.prototype._isMiddleLayer = function(){
return this.superCell !== null && this.superCell !== undefined;
};
DMASuperCell.prototype.getCells = function(){
return this._getCells(true);
};
DMASuperCell.prototype.getSparseCells = function(){
return this._getCells(false);
};
DMASuperCell.prototype._getCells = function(recursive){
var size = this.getAbsoluteDimensions();
var bounds = this.getAbsoluteBounds();
//create array of nulls
var cells = [];
for (var x=0;x<size.x;x++){
cells.push([]);
for (var y=0;y<size.y;y++){
cells[x].push([]);
for (var z=0;z<size.z;z++){
cells[x][y].push(null);
}
}
}
this._loopCells(function(cell, x, y, z){
if (recursive) cell.addToDenseArray(cells, bounds.min);
else DMACell.prototype.addToDenseArray.call(cell, cells, bounds.min);
});
return cells;
};
DMASuperCell.prototype.addToDenseArray = function(cellsArray, min, forCAM){
if (forCAM && this._isBottomLayer()) {
DMACell.prototype.addToDenseArray.call(this, cellsArray, min);
return;
}//this gives back the bottom layer cell for assembly, not necessarily the lattice pitch
this._loopCells(function(cell){
cell.addToDenseArray(cellsArray, min, forCAM);
});
};
DMASuperCell.prototype._loopCells = function(callback){
var cells = this.sparseCells;
if (!cells || cells === undefined) return;
for (var x=0;x<cells.length;x++){
for (var y=0;y<cells[0].length;y++){
for (var z=0;z<cells[0][0].length;z++){
if (cells[x][y][z]) callback(cells[x][y][z], x, y, z, this);
}
}
}
};
DMASuperCell.prototype.destroy = function(){
this._loopCells(function(cell){
cell.destroy();
cell = null;
});
DMACell.prototype.destroy.call(this);
this.sparseCells = null;
};
DMASuperCell.prototype.destroyParts = function(){
this._loopCells(function(cell){
cell.destroyParts();
});
};
return DMASuperCell;
});
\ No newline at end of file
......@@ -25,10 +25,8 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
opacity:0.4,
color:0xffffff
}));
if (this._makeWireframe) this._makeWireframe(this.mesh);
three.sceneAdd(this.mesh);
this._setScale();
this.hide();
//bind events
......@@ -96,7 +94,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
//highlight
getObjToIntersect: function(){
var objsToIntersect= lattice.getUItarget().getHighlightableCells();
var objsToIntersect= three.getCells();
if (!appState.get("deleteMode")) objsToIntersect = objsToIntersect.concat(three.getBasePlane());
// if (globals.get("highlighter").isVisible()) objsToIntersect = objsToIntersect.concat(globals.get("highlighter").mesh);
return objsToIntersect;
......@@ -159,7 +157,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
getHighlightedObjectPosition: function(){//origin selection
if (this.highlightedObject instanceof DMACell) {
var position = this.highlightedObject.getAbsolutePosition();
var position = this.highlightedObject.getPosition();
return new THREE.Vector3(parseFloat(position.x.toFixed(4)),
parseFloat(position.y.toFixed(4)),
parseFloat(position.z.toFixed(4)));
......@@ -176,18 +174,12 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
this.mesh.rotation.set(direction.y*Math.PI/2, direction.x*Math.PI/2, 0);
},
_setScale: function(){
},
//add/remove cells
_getNextCellIndex: function(){//add direction vector to current index
var newPosition;
if (this.highlightedObject.nextCellPosition) newPosition = this.highlightedObject.nextCellPosition(this.mesh.position.clone());
else newPosition = this.mesh.position.clone().add(this.mesh.position.clone().sub(this.highlightedObject.getAbsolutePosition()));
var newPosition = this.mesh.position.clone().add(this.mesh.position.clone().sub(this.highlightedObject.getPosition()));
return lattice.getIndexForPosition(newPosition);
},
......@@ -222,11 +214,11 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
}
if (shouldAdd){
if (!this.isVisible() || !this.highlightedObject) return;
lattice.getUItarget().addCellAtIndex(this._getNextCellIndex());
lattice.addCellAtIndex(this._getNextCellIndex());
} else {
if (!this.highlightedObject) return;
if (!(this.highlightedObject instanceof DMACell)) return;
lattice.getUItarget().removeCell(this.highlightedObject.getParent());
lattice.removeCell(this.highlightedObject.getParent());
}
this.setNothingHighlighted();
},
......
/**
* Created by aghassaei on 6/2/15.
*/
define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', 'three', 'highlighter'],
function(_, Backbone, three, appState, lattice, DMACell, THREE, Highlighter){
return Highlighter.extend({
_initialize: function(){
//bind events
this.listenTo(appState, "change:superCellRange", this._superCellParamDidChange);
this.listenTo(appState, "change:superCellIndex", this._superCellParamDidChange);
},
_makeGeometry: function(){
return new THREE.BoxGeometry(lattice.xScale(),lattice.yScale(),lattice.zScale());
},
_makeWireframe: function(mesh){
// console.log(mesh);
// var wireframe = new THREE.BoxHelper(mesh);
// wireframe.material.color.set(0x000000);
// wireframe.matrixWorld = mesh.matrixWorld;
// wireframe.matrixAutoUpdate = true;
// mesh.add(wireframe);
},
_setScale: function(){
var superCellRange = appState.get("superCellRange");
this.mesh.scale.set(superCellRange.x, superCellRange.y, superCellRange.z);
},
_setPosition: function(position, direction){
this.mesh.position.set(position.x+lattice.xScale()*direction.x/2, position.y+lattice.yScale()*direction.y/2,
position.z+lattice.zScale()*direction.z/2);
},
_setRotation: function(direction){
if (lattice._zIndexRotation){
if (!this.highlightedObject) return;
var index = this.highlightedObject.getAbsoluteIndex();
if (Math.abs(direction.z) > 0.9) index.z+=1;
if (appState._drawingWithCompositeMaterialType()) this.mesh.rotation.set(0,0, lattice._zIndexRotationSuperCell(index));
else this.mesh.rotation.set(0,0, lattice._zIndexRotation(index));
}
var superCellIndex = appState.get("superCellIndex");
this.mesh.translateX(-(superCellIndex.x + 0.5 - this.mesh.scale.x/2)*lattice.xScale());
this.mesh.translateY(-(superCellIndex.y + 0.5 - this.mesh.scale.y/2)*lattice.yScale());
this.mesh.translateZ(-(superCellIndex.z + 0.5 - this.mesh.scale.z/2)*lattice.zScale());
},
_superCellParamDidChange: function(){
if (!this.mesh) return;
this._setScale();
if (!this.direction) return;
this._setPosition(this.position, this.direction);//position of center point
this._setRotation(this.direction);
three.render();
},
_getNextCellIndex: function(){//add direction vector to current index
var newIndex = this.highlightedObject.getAbsoluteIndex();
newIndex.add(this.direction.clone()).round();
var offset = appState.get("superCellIndex").clone();
offset.applyQuaternion(this.mesh.quaternion).round();
newIndex.sub(offset);
return newIndex;
}
});
});
\ No newline at end of file
/**
* Created by aghassaei on 6/10/15.
*/
define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'threeModel', 'latticeBase', 'materials'],
function(_, Backbone, appState, globals, plist, THREE, three, LatticeBase, materials){
var CompositeEditorLattice = LatticeBase.extend({
__initialize: function(options, callback){
if (callback) callback(this);
},
//3d ui
addHighlightableCell: function(cell){
three.addCompositeCell(cell);
},
removeHighlightableCell: function(cell){
three.removeCompositeCell(cell);
},
getHighlightableCells: function(){
return three.getCompositeCells();
},
//deallocate
__clearCells: function(silent){
three.removeAllCompositeCells();//todo add flag in cell destroy to avoid redundancy here
},
destroy: function(){
this._clearCells(true);
var self = this;
_.each(_.keys(this.attributes), function(key){
self.set(key, null, {silent:true});
self.unset(key, {silent:true});
});
}
});
return CompositeEditorLattice;
});
......@@ -16,7 +16,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
cellType: "cube",
connectionType: "face",
applicationType: "default",
partType: null,
aspectRatio: null
}),
......@@ -24,8 +23,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
__initialize: function(){
this.listenTo(this, "change:partType", this._updatePartType);
this.listenTo(this, "change:cellType", function(){
this._cellTypeChanged();
});
......@@ -37,7 +34,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
});
this.listenTo(this, "change:aspectRatio", function(){
var aspectRatio = this.getAspectRatio();
myConsole.write("lattice.setAspectRatio(" + aspectRatio.x + ", " + aspectRatio.y + ", " + aspectRatio.z +")");
//myConsole.write("lattice.setAspectRatio(" + aspectRatio.x + ", " + aspectRatio.y + ", " + aspectRatio.z +")");
this.reloadCells();
});
......@@ -47,6 +44,11 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
});
this._applicationTypeChanged();
var self = this;
require(["cubeCell"], function(CubeCell){//todo fix this
self.cellSubclass = CubeCell;
});
},
......@@ -201,7 +203,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
_.extend(self, subclassObject);
self._initLatticeType();//init for lattice subclass
if (numCells > 0) {
self._bindRenderToNumCells(numCells);
self._setSparseCells(self.sparseCells, cellsMin);
}
});
......@@ -358,64 +359,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
getHighlightableCells: function(){
if (this.highlightableCells) return this.highlightableCells;
return three.getCells();
},
//composite Cells
_navChanged: function(){
var currentNav = appState.get("currentNav");
if (currentNav != "navComposite" && this.compositeEditor) this.exitCompositeEditing();
currentNav = plist.allMenus[currentNav].parent || currentNav;
// if (currentNav == "navAssemble") this._parseSparseCell();
},
setToCompositeMode: function(compositeLattice){
this.compositeEditor = compositeLattice;
},
inCompositeMode: function(){
return this.compositeEditor !== null && this.compositeEditor !== undefined;
},
exitCompositeEditing: function(){
if (this.compositeEditor) this.compositeEditor.destroy();
this.compositeEditor = null;
this.showCells();
},
getUItarget: function(){
if (this.inCompositeMode()) return this.compositeEditor;
return this;
},
reinitAllCellsOfTypes: function(types){//when material definition is changed
//todo add cells array to this
this._loopCells(this.sparseCells, function(cell, x, y, z, self){
var material = cell.getMaterial();
if (material && material.isComposite() && types.indexOf(material.getID()) > -1){
//re-init cell;
var json = cell.toJSON();
json.index = cell.getIndex();
self.makeCellWithJSON(json, function(newCell){
self.sparseCells[x][y][z] = newCell;
cell.destroy();
});
}
});
}
});
var lattice = new Lattice();
appState.setLattice(lattice);
return lattice;
......
This diff is collapsed.
......@@ -34,6 +34,7 @@ require.config({
arrow: 'three/Arrow',
svgRenderer: '../dependencies/SVGRenderer',
threeProjector: '../dependencies/Projector',
combinedCamera: 'three/CombinedCamera',
//plist
plist: 'plists/PList',
......@@ -48,7 +49,6 @@ require.config({
//lattice classes and extra methods
latticeBase: 'lattice/LatticeBase',
lattice: 'lattice/Lattice',
compositeEditorLattice: 'lattice/CompositeEditorLattice',
latticeImportGeo: 'lattice/ImportGeo',
//lattice "subclasses"
......@@ -66,8 +66,6 @@ require.config({
//cells
cell: 'cells/DMACell',
cubeCell: 'cells/CubeCell',
compositeCell: 'cells/supercells/CompositeCell',
superCell: 'cells/supercells/DMASuperCell',
//parts
part: 'parts/DMAPart',
......@@ -123,6 +121,10 @@ require.config({
deps: ['three'],