diff --git a/js/baseplane/BasePlane.js b/js/baseplane/BasePlane.js index 8f312f57748c47d27e074cf750e0fc2ed8de39c8..5bf95c125cdac524cbd5049b8ff36a5e8ab78a70 100644 --- a/js/baseplane/BasePlane.js +++ b/js/baseplane/BasePlane.js @@ -56,6 +56,10 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'], return this.highligherIndex.clone(); }, + getAbsolutePosition: function(){ + return lattice.getPositionForIndex(this.getAbsoluteIndex()); + }, + calcHighlighterParams: function(face, point, index){//index comes from subclass point.z = 0;//todo this doesn't generalize when baseplane moves if (!index || index === undefined) index = lattice.getIndexForPosition(point); diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 0046dab88e7609bde2dbd59375d72bbf6ed94b73..7d90cfc3970854a7b84c905d55a16e7e172e8478 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -141,13 +141,10 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' //highlighting - DMACell.prototype.calcHighlighterParams = function(face, point){//this works for rectalinear, override in subclasses + 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 self = this; - _.each(_.keys(position), function(key){ - position[key] += direction[key]*self.axisScale(key)/2; - }); + position.add(direction.clone().multiply(this.aspectRatio().divideScalar(2))); return {direction:direction, position:position}; }; @@ -395,19 +392,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' //scale - DMACell.prototype.axisScale = function(axis){ - switch (axis){ - case "x": - return this.xScale(); - case "y": - return this.yScale(); - case "z": - return this.zScale(); - default: - console.warn(axis + " axis not recognized"); - break; - } - return null; + DMACell.prototype.aspectRatio = function(){ + return new THREE.Vector3(this.xScale(), this.yScale(), this.zScale()); }; DMACell.prototype.xScale = function(){ diff --git a/js/cells/HexagonalCell.js b/js/cells/HexagonalCell.js index 3b5b687462e0906303de46e1b80e724a0e931a91..e075af4d69e27d213e914ce41a9526e96d064c9a 100644 --- a/js/cells/HexagonalCell.js +++ b/js/cells/HexagonalCell.js @@ -18,15 +18,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], return unitCellGeo; }; -// HexagonalCell.prototype._buildWireframe = function(mesh){//abstract mesh representation of cell -// var wireframe = new THREE.BoxHelper(mesh); -// wireframe.material.color.set(0x000000); -// wireframe.matrixWorld = mesh.matrixWorld; -// wireframe.matrixAutoUpdate = true; -// return wireframe; -// }; - - HexagonalCell.prototype._buildWireframe = function(mesh){//abstract mesh representation of cell var wireframe = new THREE.EdgesHelper(mesh, 0x000000); wireframe.matrixWorld = mesh.matrixWorld; @@ -34,10 +25,5 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], return wireframe; }; - HexagonalCell.prototype.calcHighlighterParams = function(face, point){//this works for rectalinear, override in subclasses - var direction = this.applyAbsoluteRotation(face.normal.clone());//todo local orientation? - if (direction.z < 0.9) return null; - }; - return HexagonalCell; }); \ No newline at end of file diff --git a/js/cells/HexagonalRotCell.js b/js/cells/HexagonalRotCell.js new file mode 100644 index 0000000000000000000000000000000000000000..16103610a6eb54bb2072113ed0837ac9fb61231b --- /dev/null +++ b/js/cells/HexagonalRotCell.js @@ -0,0 +1,23 @@ +/** + * Created by aghassaei on 8/17/15. + */ + + + +define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'hexCell'], + function(_, THREE, three, lattice, appState, HexCell){ + + var unitCellGeo = new THREE.CylinderGeometry(1, 1, 1, 6); + unitCellGeo.applyMatrix(new THREE.Matrix4().makeRotationY(Math.PI/2)); + + function HexagonalCell(json, superCell){ + HexCell.call(this, json, superCell); + } + HexagonalCell.prototype = Object.create(HexCell.prototype); + + HexagonalCell.prototype._getGeometry = function(){ + return unitCellGeo; + }; + + return HexagonalCell; +}); \ No newline at end of file diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js index 182fa9c6d6e4b52bd0e84fff2a218466784dab31..b524355736272211b621a9b8f9b4ba08e0975878 100644 --- a/js/highlighter/Highlighter.js +++ b/js/highlighter/Highlighter.js @@ -147,12 +147,8 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', ' //add/remove cells _getNextCellPosition: function(){//add direction vector to current index - var newIndex = this.highlightedObject.getAbsoluteIndex().clone(); - var direction = this.direction; - _.each(_.keys(newIndex), function(key){ - newIndex[key] = Math.round(newIndex[key] + direction[key]); - }); - return newIndex; + var newPosition = this.mesh.position.clone().add(this.mesh.position.clone().sub(this.highlightedObject.getAbsolutePosition())); + return lattice.getIndexForPosition(newPosition); }, addRemoveVoxel: function(shouldAdd){ diff --git a/js/lattice/latticeSubclasses/HexagonalLattice.js b/js/lattice/latticeSubclasses/HexagonalLattice.js index b62b5c27dd5df9a616e5070a8c78c4a69c1db3e4..98fbbb5aed7b0d3a1edbb1b7785119a9d8449970 100644 --- a/js/lattice/latticeSubclasses/HexagonalLattice.js +++ b/js/lattice/latticeSubclasses/HexagonalLattice.js @@ -9,7 +9,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre var HexLattice = { _initLatticeType: function(){ - require(['hexBaseplane'], function(BasePlaneClass){ + require(['squareBaseplane'], function(BasePlaneClass){ globals.basePlane = new BasePlaneClass(); }); require([this.getHighlighterFile()], function(HighlighterClass){ diff --git a/js/lattice/latticeSubclasses/HexagonalRotLattice.js b/js/lattice/latticeSubclasses/HexagonalRotLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..70bef6e89bb2b9641977612ae834ace439dfcde2 --- /dev/null +++ b/js/lattice/latticeSubclasses/HexagonalRotLattice.js @@ -0,0 +1,72 @@ +/** + * Created by aghassaei on 8/17/15. + */ + +/** + * Created by aghassaei on 8/17/15. + */ + + +define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'threeModel'], + function(_, Backbone, appState, globals, plist, THREE, three){ + + var HexRotLattice = { + + _initLatticeType: function(){ + require(['squareBaseplane'], function(BasePlaneClass){ + globals.basePlane = new BasePlaneClass(); + }); + require([this.getHighlighterFile()], function(HighlighterClass){ + globals.highlighter = new HighlighterClass(); + }); + }, + + getHighlighterFile: function(){ + return "defaultHighlighter"; + }, + + getIndexForPosition: function(absPosition){ + var index = this._indexForPosition(absPosition); + if (index.z%2 != 0) { + absPosition.x += this.xScale()/2; + index = this._indexForPosition(absPosition); + } + return index; + }, + + getPositionForIndex: function(index){ + var position = this._positionForIndex(index); + if ((index.y%2) != 0) position.x -= this.xScale()/2; + return position; + }, + + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 2+Math.sqrt(3)/2+2*cellSeparation; + }, + + yScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; + }, + + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return Math.sqrt(3)+2*cellSeparation; + }, + + getCellSubclassFile: function(){ + return "hexRotCell"; + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(HexRotLattice), function(key){ + self[key] = null; + }); + } + }; + + return HexRotLattice; + +}); diff --git a/js/main.js b/js/main.js index 86e6dcc874e94e4250e5d34e58519cef13d76425..f129385a69de2b26b57edeb70a614f34acfdf7ec 100644 --- a/js/main.js +++ b/js/main.js @@ -54,6 +54,7 @@ require.config({ tetraStackedLattice: 'lattice/latticeSubclasses/TetraStackedLattice', tetraVertexLattice: 'lattice/latticeSubclasses/TetraVertexLattice', hexLattice: 'lattice/latticeSubClasses/HexagonalLattice', + hexRotLattice: 'lattice/latticeSubClasses/HexagonalRotLattice', //baseplane baseplane: 'baseplane/BasePlane', @@ -86,6 +87,7 @@ require.config({ gikSuperCell: 'cells/supercells/GIKSuperCell', compositeCell: "cells/supercells/CompositeCell", hexCell: 'cells/HexagonalCell', + hexRotCell: 'cells/HexagonalRotCell', //parts part: 'parts/DMAPart', diff --git a/js/plists/PList.js b/js/plists/PList.js index b73fc996c5d7c53baa7f75f8d73e8370f255dc82..b15c3f75c4f10833524644200c31fde63de2a96b 100644 --- a/js/plists/PList.js +++ b/js/plists/PList.js @@ -66,7 +66,7 @@ define(['three'], function(THREE){ cube: {face:"Face", gik: "GIK"}, truncatedCube: {face:"Face"}, kelvin: {face: "Face"}, - hex: {face: "Face"} + hex: {face: "Face", faceRot: "Face (Rotated)"} }, allLatticeSubclasses:{ octa: {face:"octaFaceLattice", edgeRot:"octaRotEdgeLattice", vertex:"octaVertexLattice"},// freeformFace:"Freeform Face" edge:"octaEdgeLattice", (Rotated) @@ -74,7 +74,7 @@ define(['three'], function(THREE){ cube: {face:"cubeLattice", gik: "gikLattice"}, truncatedCube: {face:"truncatedCubeLattice"}, kelvin: {face: "kelvinLattice"}, - hex: {face: "hexLattice"} + hex: {face: "hexLattice", faceRot: "hexRotLattice"} }, allPartTypes:{ octa:{ @@ -107,7 +107,7 @@ define(['three'], function(THREE){ // } }, kelvin: {face: null}, - hex: {face: null} + hex: {face: null, faceRot: null} }, allCellModes:{//supercell, cell, part, node, beam @@ -134,7 +134,7 @@ define(['three'], function(THREE){ }, truncatedCube: {face: 'mechanical'}, kelvin: {face: 'mechanical'}, - hex: {face: 'mechanical'} + hex: {face: 'mechanical', faceRot: 'mechanical'} }, allMaterialClasses:{