From a673d24ad8539008687b0d9460c9731d5cdcfe85 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 5 Jun 2015 21:28:59 -0700 Subject: [PATCH] stacked tetra --- js/cells/OctaEdgeCell.js | 14 ++---- js/cells/TetraEdgeCell.js | 2 +- js/cells/TetraFaceCell.js | 34 -------------- js/cells/TetraStackedCell.js | 29 ++++++++++++ js/lattice/Lattice.js | 8 ++-- js/lattice/OctaEdgeLattice.js | 7 +-- js/lattice/TetraStackedLattice.js | 75 +++++++++++++++++++++++++++++++ js/lattice/TetraVertexLattice.js | 59 ++++++++++++++++++++++++ js/main.js | 4 +- js/models/PList.js | 11 +++-- 10 files changed, 183 insertions(+), 60 deletions(-) delete mode 100644 js/cells/TetraFaceCell.js create mode 100644 js/cells/TetraStackedCell.js create mode 100644 js/lattice/TetraStackedLattice.js create mode 100644 js/lattice/TetraVertexLattice.js diff --git a/js/cells/OctaEdgeCell.js b/js/cells/OctaEdgeCell.js index ae89f4e8..a81b11b7 100644 --- a/js/cells/OctaEdgeCell.js +++ b/js/cells/OctaEdgeCell.js @@ -11,17 +11,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'octaFaceCel } OctaEdgeCell.prototype = Object.create(OctaFaceCell.prototype); - OctaEdgeCell.prototype._rotateCell = function(object3D){ - return object3D; - }; - - //todo fix this - OctaEdgeCell.prototype.calcHighlighterPosition = function(face){ -// var direction = face.normal.clone().applyQuaternion(this.getAbsoluteOrientation()); -// var position = this.getAbsolutePosition(); - var direction = face.normal.clone(); - direction.applyQuaternion(this.mesh.quaternion); - var position = this.getPosition(); + OctaEdgeCell.prototype.calcHighlighterParams = function(face, point){ + var direction = face.normal.clone().applyQuaternion(this.getAbsoluteOrientation()); + var position = this.getAbsolutePosition(); position.add(direction.clone().multiplyScalar(this.zScale()/2)); return {index: _.clone(this.index), direction:direction, position:position}; }; diff --git a/js/cells/TetraEdgeCell.js b/js/cells/TetraEdgeCell.js index 597a2f8b..c40fb191 100644 --- a/js/cells/TetraEdgeCell.js +++ b/js/cells/TetraEdgeCell.js @@ -3,7 +3,7 @@ */ -define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'tetraFaceCell'], +define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'TetraStackedCell'], function(_, THREE, three, lattice, appState, TetraFaceCell){ function TetraEdgeCell(index, superCell){ diff --git a/js/cells/TetraFaceCell.js b/js/cells/TetraFaceCell.js deleted file mode 100644 index bd04a9a0..00000000 --- a/js/cells/TetraFaceCell.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Created by aghassaei on 5/26/15. - */ - - -define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], - function(_, THREE, three, lattice, appState, DMACell){ - - var unitGeo = new THREE.TetrahedronGeometry(Math.sqrt(3/8)); - unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4)); - unitGeo.applyMatrix(new THREE.Matrix4().makeRotationX((Math.PI-Math.atan(2*Math.sqrt(2)))/2)); - unitGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-1/Math.sqrt(6))); - - var unitGeoInverted = unitGeo.clone(); - unitGeoInverted.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI)); - - function TetraFaceCell(index, superCell){ - DMACell.call(this, index, superCell); - } - TetraFaceCell.prototype = Object.create(DMACell.prototype); - - TetraFaceCell.prototype._getGeometry = function(){//abstract mesh representation of cell - if (this.index.z%2 ==0) return unitGeo;//todo need this? - return unitGeoInverted; - }; - - TetraFaceCell.prototype._rotateCell = function(object3D){ - var zIndex = this.index.z; - if (Math.abs(zIndex%4) == 2 || Math.abs(zIndex%4) == 3) object3D.rotateZ(Math.PI/3); - return object3D; - }; - - return TetraFaceCell; -}); \ No newline at end of file diff --git a/js/cells/TetraStackedCell.js b/js/cells/TetraStackedCell.js new file mode 100644 index 00000000..e3fae8f4 --- /dev/null +++ b/js/cells/TetraStackedCell.js @@ -0,0 +1,29 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], + function(_, THREE, three, lattice, appState, DMACell){ + + var unitGeo = new THREE.TetrahedronGeometry(Math.sqrt(3/8)); + unitGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4)); + unitGeo.applyMatrix(new THREE.Matrix4().makeRotationX((Math.PI-Math.atan(2*Math.sqrt(2)))/2)); + unitGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-1/Math.sqrt(6))); + + function TetraStackedCell(index, superCell){ + DMACell.call(this, index, superCell); + } + TetraStackedCell.prototype = Object.create(DMACell.prototype); + + TetraStackedCell.prototype._getGeometry = function(){//abstract mesh representation of cell + return unitGeo; + }; + + TetraStackedCell.prototype._rotateCell = function(object3D){ + if (this.index.z%2 != 0) object3D.rotateX(Math.PI); + return object3D; + }; + + return TetraStackedCell; +}); \ No newline at end of file diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 9e9715a8..b594bd0a 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -22,8 +22,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //spacing for connectors/joints cellSeparation: {xy:0, z:0}, - cellType: "cube", - connectionType: "face", + cellType: "tetra", + connectionType: "stacked", partType: null, materialType: null, materialClass: "electronic", @@ -236,7 +236,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this._expandCellsArray(cells, (new THREE.Vector3()).subVectors(lastMin, newMin), true); this.set("cellsMin", newMin); } - console.log(cells); }, _expandCellsArray: function(cells, expansion, fromFront){ @@ -438,7 +437,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return "octaVertexLattice"; } } else if (cellType == "tetra"){ - return "cubeLattice"; + if (connectionType == "stacked") return "tetraStackedLattice"; + else if (connectionType == "vertex") return "tetraVertexLattice"; } else if (cellType == "cube"){ if (connectionType == "face"){ return "cubeLattice"; diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js index 8dabb82f..1a6f3d33 100644 --- a/js/lattice/OctaEdgeLattice.js +++ b/js/lattice/OctaEdgeLattice.js @@ -17,7 +17,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th }, getIndexForPosition: function(absPosition){ - //todo finish this var yIndex = Math.floor(absPosition.y/this.yScale()); if (yIndex%2 != 0) absPosition.x += this.xScale()/2; var yScale = 1/Math.sqrt(3); @@ -28,13 +27,11 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'th } else if (index.z%3 == 2){ absPosition.y += yScale; } - var index = this._indexForPosition(absPosition); - return index; + return this._indexForPosition(absPosition); }, getPositionForIndex: function(index){ - - var position = _.clone(index); + var position = index.clone(); var xScale = this.xScale(); var yScale = 1/Math.sqrt(3); position.x = (position.x+1/2)*xScale; diff --git a/js/lattice/TetraStackedLattice.js b/js/lattice/TetraStackedLattice.js new file mode 100644 index 00000000..1e4abb55 --- /dev/null +++ b/js/lattice/TetraStackedLattice.js @@ -0,0 +1,75 @@ +/** + * Created by aghassaei on 6/4/15. + */ + +define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'three', 'threeModel'], + function(_, Backbone, appState, lattice, globals, plist, THREE, three){ + + var TetraStackedLattice = { + + _initLatticeType: function(){ + require(['octaBaseplane'], function(OctaBasePlane){ + globals.basePlane = new OctaBasePlane(); + }); + require(['defaultHighlighter'], function(DefaultHighlighter){ + globals.highlighter = new DefaultHighlighter(); + }); + }, + +// getIndexForPosition: function(absPosition){ +// return this._indexForPosition(absPosition); +// }, +// +// getPositionForIndex: function(index){ +// return this._positionForIndex(index); +// }, + + getIndexForPosition: function(absPosition){ + var yIndex = Math.floor(absPosition.y/this.yScale()); + if (yIndex%2 != 0) absPosition.x += this.xScale()/2; + var index = this._indexForPosition(absPosition); + if (index.z%2 == 1) index.y += 1; + return index; + }, + + getPositionForIndex: function(index){ + var position = index.clone(); + position.x = (position.x+1/2); + position.y = position.y*this.yScale()+1/Math.sqrt(3)/2; + position.z = (position.z+0.5)*this.zScale(); + if ((index.y%2) != 0) position.x -= this.xScale()/2; + return position; + }, + + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + return this.xScale(cellSeparation)/2*Math.sqrt(3); + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 2/Math.sqrt(6)+2*cellSeparation; + }, + + makeCellForLatticeType: function(indices, callback){ + require(['tetraStackedCell'], function(TetraStackedCell){ + var cell = new TetraStackedCell(indices); + if (callback) callback(cell); + return cell; + }); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(TetraStackedLattice), function(key){ + self[key] = null; + }); + } + }; + + return TetraStackedLattice; +}); diff --git a/js/lattice/TetraVertexLattice.js b/js/lattice/TetraVertexLattice.js new file mode 100644 index 00000000..d142e840 --- /dev/null +++ b/js/lattice/TetraVertexLattice.js @@ -0,0 +1,59 @@ +/** + * Created by aghassaei on 6/5/15. + */ + + +define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'three', 'threeModel'], + function(_, Backbone, appState, lattice, globals, plist, THREE, three){ + + var TetraVertexLattice = { + + _initLatticeType: function(){ + require(['octaBaseplane'], function(OctaBasePlane){ + globals.basePlane = new OctaBasePlane(); + }); + require(['defaultHighlighter'], function(DefaultHighlighter){ + globals.highlighter = new DefaultHighlighter(); + }); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + return this.xScale(cellSeparation)/2*Math.sqrt(3); + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 2/Math.sqrt(6)+2*cellSeparation; + }, + + makeCellForLatticeType: function(indices, callback){ + require(['tetraStackedCell'], function(TetraVertexCell){ + var cell = new TetraVertexCell(indices); + if (callback) callback(cell); + return cell; + }); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(TetraVertexLattice), function(key){ + self[key] = null; + }); + } + }; + + return TetraVertexLattice; +}); \ No newline at end of file diff --git a/js/main.js b/js/main.js index 2cde81ed..88ac5176 100644 --- a/js/main.js +++ b/js/main.js @@ -35,6 +35,8 @@ require.config({ octaRotEdgeLattice: 'lattice/OctaRotEdgeLattice', octaVertexLattice: 'lattice/OctaVertexLattice', truncatedCubeLattice: 'lattice/TruncatedCubeLattice', + tetraStackedLattice: 'lattice/TetraStackedLattice', + tetraVertexLattice: 'lattice/TetraVertexLattice', //baseplane baseplane: 'baseplane/BasePlane', @@ -56,7 +58,7 @@ require.config({ octaEdgeCell: 'cells/OctaEdgeCell', octaVertexCell: 'cells/OctaVertexCell', octaRotEdgeCell: 'cells/OctaRotEdgeCell', - tetraEdgeCell: 'cells/TetraEdgeCell', + tetraStackedCell: 'cells/TetraStackedCell', tetraFaceCell: 'cells/TetraFaceCell', truncatedCubeCell: 'cells/TruncatedCubeCell', kelvinCell: 'cells/KelvinCell', diff --git a/js/models/PList.js b/js/models/PList.js index 417484a7..803e83f6 100644 --- a/js/models/PList.js +++ b/js/models/PList.js @@ -29,14 +29,14 @@ define(['three'], function(THREE){ allCellTypes: { octa:"Octahedron", - tetra: "Tetrahedron (Coming Soon)", + tetra: "Tetrahedron", cube:"Cube", truncatedCube:"Cuboctahedron", kelvin:"Kelvin" }, allConnectionTypes: { - octa: {face:"Face", edgeRot:"Edge", vertex:"Vertex"},//edge:"Edge", freeformFace:"Freeform Face" - tetra: {vertex: "Vertex"}, + octa: {face:"Face", edge:"Edge", edgeRot:"Edge (Rotated)", vertex:"Vertex"},// freeformFace:"Freeform Face" + tetra: {stacked: "Stacked", vertex: "Vertex"}, cube: {face:"Face", gik: "GIK"}, truncatedCube: {face:"Face"}, kelvin: {face: "Face"} @@ -79,7 +79,10 @@ define(['three'], function(THREE){ edgeRot: 'mechanical', vertex: 'mechanical' }, - tetra: {vertex: 'mechanical'}, + tetra: { + stacked: 'mechanical', + vertex: 'mechanical' + }, cube: { face: 'mechanical', gik: 'electronic' -- GitLab