diff --git a/js/baseplane/HexagonalBasePlane.js b/js/baseplane/HexagonalBasePlane.js new file mode 100644 index 0000000000000000000000000000000000000000..0aec6a61d7c0fd1773cf692db01a3f65c77ca004 --- /dev/null +++ b/js/baseplane/HexagonalBasePlane.js @@ -0,0 +1,105 @@ +/** + * Created by aghassaei on 8/17/15. + */ + +/** + * Created by aghassaei on 6/2/15. + */ + + +define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three', 'baseplane'], + function(_, Backbone, appState, lattice, three, THREE, BasePlane){ + + return BasePlane.extend({ + + _makeBasePlaneMesh: function(){ + + var geometry = new THREE.Geometry(); + geometry.vertices = this._calcOctaFaceVertices(0.0); + var faces = geometry.faces; + + var dimX = this.get("dimX"); + var dimY = this.get("dimY"); + + var currentOffset = 0; + for (var j=-dimX;j<=dimX;j++){ + for (var i=-dimY;i<=dimY;i++){ + + currentOffset++; + if (j == -dimX || i == -dimY) continue; + + if (Math.abs(j)%2==1){ + faces.push(new THREE.Face3(3*currentOffset-4, 3*currentOffset-8-6*dimY, 3*currentOffset-6-6*dimY));//pt, base, base + } else { + faces.push(new THREE.Face3(3*currentOffset-1, 3*currentOffset-8-6*dimY, 3*currentOffset-6-6*dimY));//pt, base, base + } + + } + + } + + geometry.computeFaceNormals(); + return [new THREE.Mesh(geometry, this.get("material"))]; + }, + +// _renderZIndexChange: function(){ +// var zIndex = this.get("zIndex"); +// var xScale = lattice.xScale(); +// var yScale = lattice.yScale(); +// var zScale = lattice.zScale(); +// +// _.each(this.get("mesh"), function(mesh){ +// mesh.position.set(xScale*(zIndex%2)/2, -yScale/3*(zIndex%2), zIndex*zScale); +// mesh.rotation.set(Math.PI*(zIndex%2),0,0) +// }); +// three.render(); +// }, + + _calcOctaFaceVertices: function(xySep){ + + var vertices = []; + + var xScale = lattice.xScale(); + var yScale = lattice.yScale(); + + var dimX = this.get("dimX"); + var dimY = this.get("dimY"); + + var baseVertOffset = xySep/Math.sqrt(3); + var pointVertOffset = 2*baseVertOffset; + var horizontalOffset = xySep; + + var yOffset = 1/Math.sqrt(3)/2; + + for (var j=-dimX;j<=dimX;j++){ + for (var i=-dimY;i<=dimY;i++){ + + var xOffset = 0; + if (Math.abs(j)%2!=0) { + xOffset = 1/2*xScale; + } + + vertices.push(new THREE.Vector3(i*xScale + xOffset - horizontalOffset - xScale/2, j*yScale + baseVertOffset - yOffset, 0)); + vertices.push(new THREE.Vector3(i*xScale + xOffset + horizontalOffset - xScale/2, j*yScale + baseVertOffset - yOffset, 0)); + vertices.push(new THREE.Vector3(i*xScale + xOffset - xScale/2, j*yScale - pointVertOffset - yOffset, 0)); + + } + + } + return vertices; + }, + + updateXYSeparation: function(xySep){ + var geometry = this.get("mesh")[0].geometry; + geometry.vertices = this._calcOctaFaceVertices(xySep); + geometry.verticesNeedUpdate = true; + }, + + calcHighlighterParams: function(face, point){ + point.z = 0; + var index = lattice.getIndexForPosition(point); + if (index.z%2 != 0) index.x -= 1; + return BasePlane.prototype.calcHighlighterParams.call(this, face, point, index); + } + }); +}); \ No newline at end of file diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index d32e56b9796c97b3eaf50fa630ea20804910d2ce..9af3dac24ab3c2cc876a58c99b6e4b17735c479e 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -70,33 +70,12 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre _getSubclassForLatticeType: function(){ var cellType = this.get("cellType"); var connectionType = this.get("connectionType"); - if (cellType == "octa"){ - if (connectionType == "face"){ - return "octaFaceLattice"; - } else if (connectionType == "edge"){ - return "octaEdgeLattice"; - } else if (connectionType == "edgeRot"){ - return "octaRotEdgeLattice"; - } else if (connectionType == "vertex"){ - return "octaVertexLattice"; - } - } else if (cellType == "tetra"){ - if (connectionType == "stacked") return "tetraStackedLattice"; - else if (connectionType == "vertex") return "tetraVertexLattice"; - } else if (cellType == "cube"){ - if (connectionType == "face"){ - return "cubeLattice"; - } else if (connectionType == "gik"){ - return "gikLattice"; - } - } else if (cellType == "truncatedCube"){ - return "truncatedCubeLattice"; - } else if (cellType == "kelvin"){ - return "kelvinLattice"; - } else { + var subclass = plist.allLatticeSubclasses[cellType][connectionType]; + if (subclass === undefined){ console.warn("unrecognized cell type " + cellType); + return null; } - return null; + return subclass; }, diff --git a/js/lattice/latticeSubclasses/HexagonalLattice.js b/js/lattice/latticeSubclasses/HexagonalLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..bceb37d70127d372e9169d88f051e65c034e5a4e --- /dev/null +++ b/js/lattice/latticeSubclasses/HexagonalLattice.js @@ -0,0 +1,60 @@ +/** + * Created by aghassaei on 8/17/15. + */ + + +define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'threeModel'], + function(_, Backbone, appState, globals, plist, THREE, three){ + + var KelvinLattice = { + + _initLatticeType: function(){ + require(['hexBaseplane'], function(SquareBasePlane){ + globals.basePlane = new SquareBasePlane(); + }); + require([this.getHighlighterFile()], function(TruncatedCubeHighlighter){ + globals.highlighter = new TruncatedCubeHighlighter(); + }); + }, + + getHighlighterFile: function(){ + return "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 2*Math.sqrt(2)+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 2*Math.sqrt(2)+2*cellSeparation; + }, + + getCellSubclassFile: function(){ + return "kelvinCell"; + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(KelvinLattice), function(key){ + self[key] = null; + }); + } + }; + + return KelvinLattice; + +}); diff --git a/js/main.js b/js/main.js index d7ddb87d7cd2d5dd379ae46ab8ed00e02a4cdd9a..2ea47c5e0e86742b96eb2f83aa7f931dddf51891 100644 --- a/js/main.js +++ b/js/main.js @@ -53,12 +53,14 @@ require.config({ truncatedCubeLattice: 'lattice/latticeSubclasses/TruncatedCubeLattice', tetraStackedLattice: 'lattice/latticeSubclasses/TetraStackedLattice', tetraVertexLattice: 'lattice/latticeSubclasses/TetraVertexLattice', + hexLattice: 'lattice/latticeSubClasses/HexagonalLattice', //baseplane baseplane: 'baseplane/BasePlane', squareBaseplane: 'baseplane/SquareBasePlane', octaBaseplane: 'baseplane/OctaBasePlane', rotEdgeOctaBaseplane: 'baseplane/RotEdgeOctaBasePlane', + hexBaseplane: 'baseplane/HexagonalBasePlane', //highlighter highlighter: 'highlighter/Highlighter', diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 0812f39fcc9c2b15982ae4359f1320651f107c64..42a471971656d185605fa6f924fad434e0747247 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -202,7 +202,6 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex }, _setOwnerProperty: function(owner, property, value){ - console.log(value); if (owner instanceof Backbone.Model) owner.set(property, value); else { owner[property] = value; diff --git a/js/plists/PList.js b/js/plists/PList.js index dfade1ae31e2d926970af02a320174f889f42a62..30f9a470c22ca1718eb0efa513cf3be4eec74576 100644 --- a/js/plists/PList.js +++ b/js/plists/PList.js @@ -57,14 +57,24 @@ define(['three'], function(THREE){ tetra: "Tetrahedron", cube:"Cube", truncatedCube:"Cuboctahedron", - kelvin:"Kelvin" + kelvin:"Kelvin", +// hex: "Hexagonal" }, allConnectionTypes: { octa: {face:"Face", edgeRot:"Edge", vertex:"Vertex"},// freeformFace:"Freeform Face" edge:"Edge", (Rotated) tetra: {stacked: "Stacked"},//vertex: "Vertex" cube: {face:"Face", gik: "GIK"}, truncatedCube: {face:"Face"}, - kelvin: {face: "Face"} + kelvin: {face: "Face"}, + hex: {face: "Face"} + }, + allLatticeSubclasses:{ + octa: {face:"octaFaceLattice", edgeRot:"octaRotEdgeLattice", vertex:"octaVertexLattice"},// freeformFace:"Freeform Face" edge:"octaEdgeLattice", (Rotated) + tetra: {stacked: "tetraStackedLattice"},//vertex: "tetraVertexLattice" + cube: {face:"cubeLattice", gik: "gikLattice"}, + truncatedCube: {face:"truncatedCubeLattice"}, + kelvin: {face: "kelvinLattice"}, + hex: {face: "hexLattice"} }, allPartTypes:{ octa:{ @@ -96,7 +106,8 @@ define(['three'], function(THREE){ // xShape:"X" // } }, - kelvin: {face: null} + kelvin: {face: null}, + hex: {face: null} }, allCellModes:{//supercell, cell, part, node, beam @@ -122,7 +133,8 @@ define(['three'], function(THREE){ gik: 'electronic' }, truncatedCube: {face: 'mechanical'}, - kelvin: {face: 'mechanical'} + kelvin: {face: 'mechanical'}, + hex: {face: 'mechanical'} }, allMaterialClasses:{