diff --git a/index.html b/index.html
index 2db56e14d1ac134933eb2c2c1adf47fccd12f44d..10c2d88b396bbde0fb338d9e33b2d69d78236abb 100644
--- a/index.html
+++ b/index.html
@@ -96,6 +96,8 @@
Video Rendering Setup
Photo Setup
Undo Photo Setup
+ Orthographic Camera
+ Perspective Camera
diff --git a/js/API/LatticeAPI.js b/js/API/LatticeAPI.js
index 244e0ba4da13e258a0304b4190f13a10474a32f3..596a4a3968ed89dc1bef200b9edce32a38418866 100644
--- a/js/API/LatticeAPI.js
+++ b/js/API/LatticeAPI.js
@@ -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()");
diff --git a/js/baseplane/BasePlane.js b/js/baseplane/BasePlane.js
index 99fee7600f7bfe764010b243a732065e57490d5d..f89a9d175b9aee14db4d2230e781ef2ba1ac442b 100644
--- a/js/baseplane/BasePlane.js
+++ b/js/baseplane/BasePlane.js
@@ -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
diff --git a/js/cells/CubeCell.js b/js/cells/CubeCell.js
index 81d38571cc8bf9e05eb2bde3bcf6e5184e391db0..ef526b68de599900da0a097f1fc3355f262dc759 100644
--- a/js/cells/CubeCell.js
+++ b/js/cells/CubeCell.js
@@ -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);
diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js
index 9191202f9afae1d93b02771291b3b8c94554f105..858f053560db78ed278d4782ef273cdfa593ea90 100644
--- a/js/cells/DMACell.js
+++ b/js/cells/DMACell.js
@@ -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;
};
diff --git a/js/cells/supercells/CompositeCell.js b/js/cells/supercells/CompositeCell.js
deleted file mode 100644
index 03587fe7929d261871fc62e25b479842feeec4ec..0000000000000000000000000000000000000000
--- a/js/cells/supercells/CompositeCell.js
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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
diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js
deleted file mode 100644
index 392d7679377972209bd7d75b0ed86f4869e45078..0000000000000000000000000000000000000000
--- a/js/cells/supercells/DMASuperCell.js
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * 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 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
diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js
deleted file mode 100644
index a653a7dd27d08145ccf3dd44f684d09e1dd383a7..0000000000000000000000000000000000000000
--- a/js/lattice/CompositeEditorLattice.js
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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;
-});
diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js
index 2494f44f408b532d728c6eb8892a064136f970ec..dcfa19a49c0fe6a2d67ebbe48f4ac0f5f6afe984 100644
--- a/js/lattice/Lattice.js
+++ b/js/lattice/Lattice.js
@@ -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;
diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js
index 862ed8da459713ef24b6c9b691c164afa011ef95..d7d4b75580272741a0f2406ca6cf4a2bc59b8e96 100644
--- a/js/lattice/LatticeBase.js
+++ b/js/lattice/LatticeBase.js
@@ -3,8 +3,8 @@
*/
-define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'threeModel', 'console'],
- function(_, Backbone, appState, globals, plist, THREE, three, myConsole){
+define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'threeModel'],
+ function(_, Backbone, appState, globals, plist, THREE, three){
return Backbone.Model.extend({
@@ -19,10 +19,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
initialize: function(options, classProperties, callback){
this.cells = [[[null]]];//3D matrix containing all cells and null, dynamic size
- this.sparseCells = [[[null]]];//3D matrix containing highest hierarchical level of cells and null
//bind events
- this.listenTo(appState, "change:cellMode", this._updateForMode);
+ this.listenTo(appState, "change:cellMode", this._updateForMode);//show hide cells
if (this.__initialize) this.__initialize(options, callback);
},
@@ -54,31 +53,14 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
return this.get("numCells");
},
- getSparseCells: function(){
- return this.sparseCells;
- },
-
getCells: function(){
return this.cells;
},
- getSparseCellsJSON: function(){
- return JSON.parse(JSON.stringify(this.sparseCells));
- },
-
getCellsJSON: function(){
return JSON.parse(JSON.stringify(this.cells));
},
- getSparseCellAtIndex: function(index){
- if (this._checkForIndexOutsideBounds(index)) return null;
- return this._getSparseCellAtIndex(this._getCellsIndexForLatticeIndex(index));
- },
-
- _getSparseCellAtIndex: function(index){
- return this.sparseCells[index.x][index.y][index.z];
- },
-
getCellAtIndex: function(index){
if (this._checkForIndexOutsideBounds(index)) return null;
return this._getCellAtIndex(index);
@@ -102,32 +84,14 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
return plist.allLattices[this.get("cellType")].connection[this.get("connectionType")].type[this.get("applicationType")];
},
- _bindRenderToNumCells: function(numCells){
- var self = this;
- if (numCells > 0) this.listenTo(this, "change:numCells", function(){
- if (self.get("numCells") >= numCells){
- self.stopListening(self, "change:numCells");
- three.render();
- }
- });
- },
-
//add/remove cells
- makeCellWithJSON: function(json, callback){
- var subclassFile = appState.lattice.getCellSubclassFile();
- require(['materials'], function(materials){
- var materialID = json.materialID || appState.get("materialType");
- if (materials.isComposite(materialID)) subclassFile = "compositeCell";
- require([subclassFile], function(CellSubclass){
- var cell = new CellSubclass(json);
- if (callback) callback(cell);
- });
- });
+ makeCellWithJSON: function(json){
+ return new this.cellSubclass(json);
},
addCellsInRange: function(range, clone){//add a block of cells (extrude)
@@ -137,30 +101,10 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
var materialID = appState.get("materialType");
- var lastCellIndex = range.max;
- if (clone){
- var cloneSize = clone.get("size");
- var lastCloneIndex = new THREE.Vector3(0,0,0);
- for (var x=0;x0) this.clearCells();
- this.set("cellsMin", new THREE.Vector3(offset.x, offset.y, offset.z));
- this.parseCellsJSON(cells);
- },
+ //setSparsecells: function(cells, offset){
+ // if (cells === undefined || cells == null) {
+ // console.warn("no cells given to setcells");
+ // return;
+ // }
+ // this._setcells(cells, offset);
+ //},
+ //
+ //_setSparsecells: function(cells, offset){
+ //
+ // offset = offset || this.getOffset() || new THREE.Vector3(0,0,0);
+ // if(this.get("numCells")>0) this.clearCells();
+ // this.set("cellsMin", new THREE.Vector3(offset.x, offset.y, offset.z));
+ // this.parseCellsJSON(cells);
+ //},
@@ -378,7 +282,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
this.set("cellsMin", indicesMin);
var size = indicesMax.clone().sub(indicesMin);
this._expandArray(this.cells, size, false);
- this._expandArray(this.sparseCells, size, false);
+ this._expandArray(this.cells, size, false);
return;
}
@@ -387,13 +291,13 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
if (!indicesMax.equals(lastMax)) {
var size = indicesMax.clone().sub(lastMax);
this._expandArray(this.cells, size, false);
- this._expandArray(this.sparseCells, size, false);
+ this._expandArray(this.cells, size, false);
this.set("cellsMax", indicesMax);
}
if (!indicesMin.equals(lastMin)) {
var size = lastMin.clone().sub(indicesMin);
this._expandArray(this.cells, size, true);
- this._expandArray(this.sparseCells, size, true);
+ this._expandArray(this.cells, size, true);
this.set("cellsMin", indicesMin);
}
},
@@ -463,9 +367,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
if (maxDiff.equals(zero) && minDiff.equals(zero)) return;
this._contractCellsArray(this.cells, false, maxDiff);
- this._contractCellsArray(this.sparseCells, false, maxDiff);
+ this._contractCellsArray(this.cells, false, maxDiff);
+ this._contractCellsArray(this.cells, true, minDiff);
this._contractCellsArray(this.cells, true, minDiff);
- this._contractCellsArray(this.sparseCells, true, minDiff);
this.set("cellsMax", newMax, {silent:true});
this.set("cellsMin", newMin);
@@ -517,58 +421,34 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
//events
- _updatePartType: function(){
- this._loopCells(this.sparseCells, function(cell){
- cell.destroyParts();
- });
- this._updateForMode();
- },
-
_updateForMode: function(){
var cellMode = appState.get("cellMode");
if (cellMode == "hide"){
this.hideCells();
return;
}
-
if (appState.previous("cellMode") == "hide"){
this.showCells();
- } else {
- this._setAllCellsMode(cellMode);
}
},
- _setAllCellsMode: function(cellMode){
- var numCells = this.get("numCells");
- var renderCallback = function(){
- if (--numCells <= 0) three.render();
- };
- this._loopCells(this.sparseCells, function(cell){
- cell.setMode(cellMode, renderCallback);
- });
- },
-
hideCells: function(noRender){
- this._loopCells(this.sparseCells, function(cell){
+ this._loopCells(this.cells, function(cell){
cell.hide();
});
if (!noRender) three.render();
},
showCells: function(){
- var cellMode = appState.get("cellMode");
- var numCells = this.get("numCells");
- var renderCallback = function(){
- if (--numCells <= 0) three.render();
- };
- this._loopCells(this.sparseCells, function(cell){
+ this._loopCells(this.cells, function(cell){
cell.setTransparent(false);
- cell.show(cellMode, renderCallback);
+ cell.show();
});
+ three.render();
},
setOpaque: function(){
- this._loopCells(this.sparseCells, function(cell){
+ this._loopCells(this.cells, function(cell){
cell.setTransparent(false);
});
three.render();
@@ -635,7 +515,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
},
loopCells: function(callback){
- this._loopCells(this.sparseCells, callback);
+ this._loopCells(this.cells, callback);
},
_loopCells: function(cells, callback){
@@ -668,9 +548,9 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
//save/load
- parseCellsJSON: function(sparseCells){
+ parseCellsJSON: function(cells){
var cellsMin = this.get("cellsMin");
- this._loopCells(sparseCells, function(json, x, y, z, self){
+ this._loopCells(cells, function(json, x, y, z, self){
var index = (new THREE.Vector3(x, y, z)).add(cellsMin);
self._addCellAtIndex(index, json);
});
@@ -679,7 +559,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
getSaveJSON: function(){
var data = this.toJSON();
- data.sparseCells = this.sparseCells;
+ data.cells = this.cells;
return data;
}
diff --git a/js/main.js b/js/main.js
index 9bf90099439aa37058f312a5d58b431c1ec0e88b..996dab1d52a9b9fc8c1eca8c133ccdacc7630431 100644
--- a/js/main.js
+++ b/js/main.js
@@ -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'],
exports: "THREE"
},
+ combinedCamera: {
+ deps: ['three'],
+ exports: "THREE"
+ },
svgRenderer: {
deps: ['three', 'threeProjector'],
exports: "THREE.SVGRenderer"
diff --git a/js/materials/DMAMaterial.js b/js/materials/DMAMaterial.js
index 41baba10fe56136bc033761c3a1519f653f74d25..f3443fd23ac59e72344160e6bc4e834c0ee222fc 100644
--- a/js/materials/DMAMaterial.js
+++ b/js/materials/DMAMaterial.js
@@ -97,7 +97,6 @@ define(['underscore', 'appState', 'three'], function(_, appState, THREE){
});
}
parentComposites.push(self.getID());
-// lattice.reinitAllCellsOfTypes(parentComposites);
});
}
diff --git a/js/menus/otherUI/Navbar.js b/js/menus/otherUI/Navbar.js
index f284a6e40dde1a5877e1b00dc35976e6c669fca7..f759dccd007c51dec07f874736319d793ae69d7a 100644
--- a/js/menus/otherUI/Navbar.js
+++ b/js/menus/otherUI/Navbar.js
@@ -29,7 +29,9 @@ define(['jquery', 'underscore', 'backbone', 'fileSaver', 'navViewMenu', 'appStat
"click #viewMenuDropdown": "_renderViewMenu",
"click #videoRendering": "_videoRenderingSetup",
"click #photoSetup": "_photoSetup",
- "click #undoPhotoSetup": "_undoPhotoSetup"
+ "click #undoPhotoSetup": "_undoPhotoSetup",
+ "click #orthoCamera": "_orthoCamera",
+ "click #perspectiveCamera": "_perspectiveCamera"
},
initialize: function(){
@@ -133,6 +135,16 @@ define(['jquery', 'underscore', 'backbone', 'fileSaver', 'navViewMenu', 'appStat
three.setBackgroundColor(0xcccccc);
},
+ _orthoCamera: function(e){
+ e.preventDefault();
+ three.orthographicCamera();
+ },
+
+ _perspectiveCamera: function(e){
+ e.preventDefault();
+ three.perspectiveCamera();
+ },
+
_save: function(e){
diff --git a/js/models/AppState.js b/js/models/AppState.js
index dcff9438507e2c57f00bf61d299529b89cb09f81..7a806227127014f7530f79d315ac48d9933063ac 100644
--- a/js/models/AppState.js
+++ b/js/models/AppState.js
@@ -33,17 +33,11 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
shift: false,
deleteMode: false,
extrudeMode: false,
- cellMode: "cell",//supercell, cell, part, hide
-
- superCellIndex: new THREE.Vector3(0,0,0),//offset of superCell adds
- gikLength: 4,//this updates super cell range when using non-composite materials
- superCellRange: new THREE.Vector3(1,1,1),
+ cellMode: "cell",//cell, hide
realisticColorScheme: false,
materialType: null,
- materialClass: null,
-
- stockSimulationPlaying: false
+ materialClass: null
},
initialize: function(){
@@ -59,8 +53,6 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
this.listenTo(this, "change:currentTab", this._tabChanged);
this.listenTo(this, "change:currentNav", this._navChanged);
- this.listenTo(this, "change:materialType", this._materialTypeChanged);
- this.listenTo(this, "change:gikLength", this._gikLengthChanged);
this.listenTo(this, "change:turnOffRendering", this._renderingOnOff);
this.listenTo(this, "change:axesAreVisible", this._showAxes);
this.listenTo(this, "change:focusOnLattice", this._focusOnLattice);
@@ -98,17 +90,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
_tabChanged: function(){
var currentTab = this.get("currentTab");
- if (currentTab != "animate") this.set("stockSimulationPlaying", false);
- if (currentTab == "import" && this.lattice.get("connectionType") == "edgeRot") this.lattice.set("partType", "voxLowPoly");
this.get("lastNavTab")[this.get("currentNav")] = currentTab;//store tab
- this._updateCellMode(currentTab);
- },
-
- _updateCellMode: function(currentTab){
-// if (currentTab == "lattice" || currentTab == "import") this.set("cellMode", "cell");
- //else if (currentTab == "import") this.set("cellMode", "cell");
- //else if (currentTab == "sketch") this.set("cellMode", "cell");
- if (currentTab == "part") this.set("cellMode", "part");
},
_navChanged: function(){
@@ -127,11 +109,6 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
this.set("basePlaneIsVisible", true);
globals.get("baseplane").set("planeType", 'xy');
this.set("highlighterIsVisible", false);
- } else if (navSelection == "navAssemble"){
- this.set("highlighterIsVisible", false);
- } else if (navSelection == "navComm"){
- this.set("basePlaneIsVisible", false);
- this.set("highlighterIsVisible", false);
}
if (navSelection != "navDesign") this.set("showOneLayer", false);
@@ -140,41 +117,8 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
this.lattice.showCells();
},
- _materialTypeChanged: function(){
- var self = this;
- require(['materials'], function(materials){
- var materialType = self.get("materialType");
- //verify that correct class is in sync
- if (!materials.isComposite(materialType)) {
-//// if (self.previous("materialType") && !materials.isComposite(self.previous("materialType"))) return;
-// //re init highlighter
-// if (!self.lattice.getHighlighterFile) return;
-// require([self.lattice.getHighlighterFile()], function(HighlighterClass){
-// globals.get("highlighter") = new HighlighterClass();
-// });
- return;
- }
- //composite material
- require(['superCellHighlighter'], function(SuperCellHighlighter){
- globals.get("highlighter").destroy();
- globals.get("highlighter").set(new SuperCellHighlighter());
- });
- });
-
- },
-
- _gikLengthChanged: function(){
- if (this.get("materialType").substr(0,5) != "super"){
- this.set("superCellRange", new THREE.Vector3(this.get("gikLength"), 1, 1));
- }
- },
-
- _drawingWithCompositeMaterialType: function(){
- return this.get("materialType").substr(0,5) == "super";
- },
-
_renderingOnOff: function(){
- if (!this.get("turnOffRendering")) three.render();
+ if (!this.get("turnOffRendering")) three.render();//send a render command if rending has just been turned back on
},
_showAxes: function(){
@@ -209,6 +153,8 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
$("#jsonInput").click();
},
+
+ //todo this should go to lattice
showSketchLayer: function(){
var index;
if (this.get("showOneLayer")){
@@ -305,7 +251,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
if (state && (e.ctrlKey || e.metaKey)){
if (e.shiftKey){
e.preventDefault();
- location.reload();
+ location.reload();///refresh
return;
}
}
@@ -317,17 +263,6 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
}
else this.set("cellMode", this.lastCellMode);
break;
- case 72://h hierarchical mode
- if (state) {
- this.lastCellMode = this.get("cellMode");
- this.set("cellMode", "supercell");
- }
- else this.set("cellMode", this.lastCellMode);
- break;
- case 69://e
- // if (currentTab != "sketch") return;
-// this.set("extrudeMode", state);
- break;
case 80://p
if (e.ctrlKey || e.metaKey){//command + shift + p = print svg screenshot
if (e.shiftKey){
@@ -336,11 +271,11 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
return;
}
}
- if (state) {//p part mode
- this.lastCellMode = this.get("cellMode");
- this.set("cellMode", "part");
- }
- else this.set("cellMode", this.lastCellMode);
+ //if (state) {//p part mode
+ // this.lastCellMode = this.get("cellMode");
+ // this.set("cellMode", "part");
+ //}
+ //else this.set("cellMode", this.lastCellMode);
break;
case 83://s save
if (e.ctrlKey || e.metaKey){//command
@@ -350,8 +285,6 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
} else {
globals.fileSaver.save();
}
- } else {
- if (state) this.set("superCellIndex", this._incrementSuperCellIndex("y", this.get("superCellIndex").clone()));
}
break;
case 79://o open
@@ -368,56 +301,10 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
break;
case 32://space bar (play/pause simulation)
e.preventDefault();
- if (state && this.get("currentTab") == "animate") this.set("stockSimulationPlaying", !this.get("stockSimulationPlaying"));
- break;
- case 49://1-9
- case 50:
- case 51:
- case 52:
- case 53:
- case 54:
- case 55:
- case 56:
- case 57:
- if (this.lattice.get("connectionType") != "gik") break;
- if (state) {
- var val = e.keyCode-48;
- var range = plist.allLattices[this.lattice.get("cellType")].connection[this.lattice.get("connectionType")].type[this.lattice.get("applicationType")].options.gikRange;
- if (range){
- if ((range[0] > 0 && val < range[0]) || (range[1] > 1 && val > range[1])){
- console.warn("gik length out of range");
- return;
- }
- }
- this.set("gikLength", val);
- }
- break;
- case 87://w - increase supercell index
- if (state) this.set("superCellIndex", this._incrementSuperCellIndex("x", this.get("superCellIndex").clone()));
- break;
- case 81://q - decrease supercell index
- if (state) this.set("superCellIndex", this._decrementSuperCellIndex("x", this.get("superCellIndex").clone()));
- break;
- case 65://a - decrease supercell index
- if (state) this.set("superCellIndex", this._decrementSuperCellIndex("y", this.get("superCellIndex").clone()));
- break;
- case 88://x - increase supercell index
- if (state) this.set("superCellIndex", this._incrementSuperCellIndex("z", this.get("superCellIndex").clone()));
- break;
- case 90://z - decrease supercell index
- if (state) this.set("superCellIndex", this._decrementSuperCellIndex("z", this.get("superCellIndex").clone()));
break;
case 38://up arrow
- if (!state || this.get("currentNav") != "electronicNavSim") return;
- require(['eSim'], function(eSim){
- eSim.setZSimHeight(eSim.get("simZHeight")+1);
- });
break;
case 40://down arrow
- if (!state || this.get("currentNav") != "electronicNavSim") return;
- require(['eSim'], function(eSim){
- eSim.setZSimHeight(eSim.get("simZHeight")-1);
- });
break;
case 13://enter
if (state){
@@ -429,6 +316,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
e.preventDefault();
e.stopPropagation();
//also continue to case 46
+ break;
case 46://delete
if (state){
var selection3D = globals.get("selection3D");
@@ -440,18 +328,6 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist', 'globals'],
}
},
- _incrementSuperCellIndex: function(key, object){
- object[key] += 1;
- if (object[key] > this.get("superCellRange")[key]-1) object[key] = 0;
- return object;
- },
-
- _decrementSuperCellIndex: function(key, object){
- object[key] -= 1;
- if (object[key] < 0) object[key] = this.get("superCellRange")[key]-1;
- return object;
- },
-
_handleScroll: function(e){//disable two finger swipe back
if (Math.abs(e.originalEvent.deltaX) > Math.abs(e.originalEvent.deltaY)) e.preventDefault();
}
diff --git a/js/plists/MaterialsPlist.js b/js/plists/MaterialsPlist.js
index e876b9a334f7259704c39aaa843bc31c1c049f29..8bad226597e7e41c4bdf55163effc20b0124ffe8 100644
--- a/js/plists/MaterialsPlist.js
+++ b/js/plists/MaterialsPlist.js
@@ -94,7 +94,7 @@ define([], function(){
piezo: {
- name: "Piezo",
+ name: "Actuator",
color: "#FFCC00",
altColor: "#FFCC00",
properties:{
diff --git a/js/three/CombinedCamera.js b/js/three/CombinedCamera.js
new file mode 100644
index 0000000000000000000000000000000000000000..126f0513c4a1572d91b26476c935ebe7cf83829a
--- /dev/null
+++ b/js/three/CombinedCamera.js
@@ -0,0 +1,239 @@
+/**
+ * @author zz85 / http://twitter.com/blurspline / http://www.lab4games.net/zz85/blog
+ *
+ * A general perpose camera, for setting FOV, Lens Focal Length,
+ * and switching between perspective and orthographic views easily.
+ * Use this only if you do not wish to manage
+ * both a Orthographic and Perspective Camera
+ *
+ */
+
+
+THREE.CombinedCamera = function ( width, height, fov, near, far, orthoNear, orthoFar ) {
+
+ THREE.Camera.call( this );
+
+ this.fov = fov;
+
+ this.left = - width / 2;
+ this.right = width / 2;
+ this.top = height / 2;
+ this.bottom = - height / 2;
+
+ // We could also handle the projectionMatrix internally, but just wanted to test nested camera objects
+
+ this.cameraO = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, orthoNear, orthoFar );
+ this.cameraP = new THREE.PerspectiveCamera( fov, width / height, near, far );
+
+ this.zoom = 1;
+
+ this.toPerspective();
+
+};
+
+THREE.CombinedCamera.prototype = Object.create( THREE.Camera.prototype );
+THREE.CombinedCamera.prototype.constructor = THREE.CombinedCamera;
+
+THREE.CombinedCamera.prototype.toPerspective = function () {
+
+ // Switches to the Perspective Camera
+
+ this.near = this.cameraP.near;
+ this.far = this.cameraP.far;
+
+ this.cameraP.fov = this.fov / this.zoom ;
+
+ this.cameraP.updateProjectionMatrix();
+
+ this.projectionMatrix = this.cameraP.projectionMatrix;
+
+ this.inPerspectiveMode = true;
+ this.inOrthographicMode = false;
+
+};
+
+THREE.CombinedCamera.prototype.toOrthographic = function () {
+
+ // Switches to the Orthographic camera estimating viewport from Perspective
+
+ var fov = this.fov;
+ var aspect = this.cameraP.aspect;
+ var near = this.cameraP.near;
+ var far = this.cameraP.far;
+
+ // The size that we set is the mid plane of the viewing frustum
+
+ var hyperfocus = ( near + far ) / 2;
+
+ var halfHeight = Math.tan( fov * Math.PI / 180 / 2 ) * hyperfocus;
+ var planeHeight = 2 * halfHeight;
+ var planeWidth = planeHeight * aspect;
+ var halfWidth = planeWidth / 2;
+
+ halfHeight /= this.zoom;
+ halfWidth /= this.zoom;
+
+ this.cameraO.left = - halfWidth;
+ this.cameraO.right = halfWidth;
+ this.cameraO.top = halfHeight;
+ this.cameraO.bottom = - halfHeight;
+
+ // this.cameraO.left = -farHalfWidth;
+ // this.cameraO.right = farHalfWidth;
+ // this.cameraO.top = farHalfHeight;
+ // this.cameraO.bottom = -farHalfHeight;
+
+ // this.cameraO.left = this.left / this.zoom;
+ // this.cameraO.right = this.right / this.zoom;
+ // this.cameraO.top = this.top / this.zoom;
+ // this.cameraO.bottom = this.bottom / this.zoom;
+
+ this.cameraO.updateProjectionMatrix();
+
+ this.near = this.cameraO.near;
+ this.far = this.cameraO.far;
+ this.projectionMatrix = this.cameraO.projectionMatrix;
+
+ this.inPerspectiveMode = false;
+ this.inOrthographicMode = true;
+
+};
+
+
+THREE.CombinedCamera.prototype.setSize = function( width, height ) {
+
+ this.cameraP.aspect = width / height;
+ this.left = - width / 2;
+ this.right = width / 2;
+ this.top = height / 2;
+ this.bottom = - height / 2;
+
+};
+
+
+THREE.CombinedCamera.prototype.setFov = function( fov ) {
+
+ this.fov = fov;
+
+ if ( this.inPerspectiveMode ) {
+
+ this.toPerspective();
+
+ } else {
+
+ this.toOrthographic();
+
+ }
+
+};
+
+// For maintaining similar API with PerspectiveCamera
+
+THREE.CombinedCamera.prototype.updateProjectionMatrix = function() {
+
+ if ( this.inPerspectiveMode ) {
+
+ this.toPerspective();
+
+ } else {
+
+ this.toPerspective();
+ this.toOrthographic();
+
+ }
+
+};
+
+/*
+* Uses Focal Length (in mm) to estimate and set FOV
+* 35mm (full frame) camera is used if frame size is not specified;
+* Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
+*/
+THREE.CombinedCamera.prototype.setLens = function ( focalLength, filmGauge ) {
+
+ if ( filmGauge === undefined ) filmGauge = 35;
+
+ var vExtentSlope = 0.5 * filmGauge /
+ ( focalLength * Math.max( this.cameraP.aspect, 1 ) );
+
+ var fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
+
+ this.setFov( fov );
+
+ return fov;
+
+};
+
+
+THREE.CombinedCamera.prototype.setZoom = function( zoom ) {
+
+ this.zoom = zoom;
+
+ if ( this.inPerspectiveMode ) {
+
+ this.toPerspective();
+
+ } else {
+
+ this.toOrthographic();
+
+ }
+
+};
+
+THREE.CombinedCamera.prototype.toFrontView = function() {
+
+ this.rotation.x = 0;
+ this.rotation.y = 0;
+ this.rotation.z = 0;
+
+ // should we be modifing the matrix instead?
+
+ this.rotationAutoUpdate = false;
+
+};
+
+THREE.CombinedCamera.prototype.toBackView = function() {
+
+ this.rotation.x = 0;
+ this.rotation.y = Math.PI;
+ this.rotation.z = 0;
+ this.rotationAutoUpdate = false;
+
+};
+
+THREE.CombinedCamera.prototype.toLeftView = function() {
+
+ this.rotation.x = 0;
+ this.rotation.y = - Math.PI / 2;
+ this.rotation.z = 0;
+ this.rotationAutoUpdate = false;
+
+};
+
+THREE.CombinedCamera.prototype.toRightView = function() {
+
+ this.rotation.x = 0;
+ this.rotation.y = Math.PI / 2;
+ this.rotation.z = 0;
+ this.rotationAutoUpdate = false;
+
+};
+
+THREE.CombinedCamera.prototype.toTopView = function() {
+
+ this.rotation.x = - Math.PI / 2;
+ this.rotation.y = 0;
+ this.rotation.z = 0;
+ this.rotationAutoUpdate = false;
+
+};
+
+THREE.CombinedCamera.prototype.toBottomView = function() {
+
+ this.rotation.x = Math.PI / 2;
+ this.rotation.y = 0;
+ this.rotation.z = 0;
+ this.rotationAutoUpdate = false;
+
+};
diff --git a/js/three/ThreeModel.js b/js/three/ThreeModel.js
index 084d85476134f22d58b0aace6bbc8f5e9189fff3..ef6ba28f6d5e0c4d502b9d9d3c49d1cc1c678ce6 100644
--- a/js/three/ThreeModel.js
+++ b/js/three/ThreeModel.js
@@ -3,8 +3,9 @@
*/
-define(['underscore', 'three'], function(_, THREE){
+define(['underscore', 'three', 'combinedCamera'], function(_, THREE){
+ //var camera = new THREE.CombinedCamera( window.innerWidth / 2, window.innerHeight / 2, 60, 0.01, 1000, - 500, 1000 );
var camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 0.01, 1000);
// camera.setLens(50);
var scene = new THREE.Scene();
@@ -23,7 +24,6 @@ define(['underscore', 'three'], function(_, THREE){
//store all meshes to highlight
var cells = [];
- var compositeCells = [];
// var parts = [];
var basePlane = [];
@@ -44,8 +44,8 @@ define(['underscore', 'three'], function(_, THREE){
function initialize(){
- resetCameraPosition();
camera.up.set(0,0,1);//set z axis as "up"
+ resetCameraPosition();
// scene.fog = new THREE.FogExp2(fogColor, 0.001);
@@ -90,6 +90,14 @@ define(['underscore', 'three'], function(_, THREE){
render();
}
+ function orthographicCamera(){
+ camera.toOrthographic();
+ }
+
+ function perspectiveCamera(){
+ camera.toPerspective();
+ }
+
function onWindowResize(){
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
@@ -128,30 +136,16 @@ define(['underscore', 'three'], function(_, THREE){
cells.push(cell);
}
- function addCompositeCell(cell){
- compositeCells.push(cell);
- }
-
function removeCell(cell){
var index = cells.indexOf(cell);
if (index < 0) return;
cells.splice(index, 1);
}
- function removeCompositeCell(cell){
- var index = compositeCells.indexOf(cell);
- if (index < 0) return;
- compositeCells.splice(index, 1);
- }
-
function getCells(){
return cells;
}
- function getCompositeCells(){
- return compositeCells;
- }
-
function setupDragPlane(position, orientation){
var quaternion = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0,0,1), orientation.normalize());
var euler = new THREE.Euler().setFromQuaternion(quaternion);
@@ -182,10 +176,6 @@ define(['underscore', 'three'], function(_, THREE){
cells = [];
}
- function removeAllCompositeCells(){
- compositeCells = [];
- }
-
function startAnimationLoop(callback){
if (appState.get("turnOffRendering") || animationLoopRunning) return;
stopAnimationFlag = false;
@@ -282,20 +272,18 @@ define(['underscore', 'three'], function(_, THREE){
domElement: renderer.domElement,
camera: camera,
getCells: getCells,
- getCompositeCells: getCompositeCells,
addCell: addCell,
- addCompositeCell: addCompositeCell,
removeCell: removeCell,
- removeCompositeCell: removeCompositeCell,
getBasePlane: getBasePlane,
removeAllCells: removeAllCells,
- removeAllCompositeCells: removeAllCompositeCells,
setupDragPlane: setupDragPlane,
resetCameraPosition: resetCameraPosition,
setThreeView: setThreeView,
saveSVG: saveSVG,
getGLContext: getGLContext,
- setBackgroundColor: setBackgroundColor
+ setBackgroundColor: setBackgroundColor,
+ orthographicCamera: orthographicCamera,
+ perspectiveCamera: perspectiveCamera
}
});
\ No newline at end of file