From 0b32098c6dd85aaf54dc7f7f0658d517cb242c03 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 26 May 2015 19:11:22 -0700 Subject: [PATCH] other cell types --- index.html | 9 +- js/cells/CubeCell.js | 38 ++++ js/cells/DMACell.js | 6 +- js/cells/DmaCellOther.js | 303 ----------------------------- js/cells/DmaCellTetra.js | 48 ----- js/cells/GIKCell.js | 57 ++++++ js/cells/KelvinCell.js | 111 +++++++++++ js/cells/TetraEdgeCell.js | 11 ++ js/cells/TetraFaceCell.js | 28 +++ js/cells/TruncatedCubeCell.js | 80 ++++++++ js/lattice/CubeLattice.js | 2 +- js/lattice/GIKLattice.js | 2 +- js/lattice/KelvinLattice.js | 2 +- js/lattice/TruncatedCubeLattice.js | 2 +- 14 files changed, 341 insertions(+), 358 deletions(-) create mode 100644 js/cells/CubeCell.js delete mode 100644 js/cells/DmaCellOther.js delete mode 100644 js/cells/DmaCellTetra.js create mode 100644 js/cells/GIKCell.js create mode 100644 js/cells/KelvinCell.js create mode 100644 js/cells/TetraEdgeCell.js create mode 100644 js/cells/TetraFaceCell.js create mode 100644 js/cells/TruncatedCubeCell.js diff --git a/index.html b/index.html index 62041125..454c423f 100644 --- a/index.html +++ b/index.html @@ -52,8 +52,13 @@ <script src="js/cells/DMASuperCell.js"></script> <script src="js/cells/DMACellFreeform.js"></script> - <script src="js/cells/DmaCellTetra.js"></script> - <script src="js/cells/DmaCellOther.js"></script> + + <script src="js/cells/CubeCell.js"></script> + <script src="js/cells/GIKCell.js"></script> + <script src="js/cells/TruncatedCubeCell.js"></script> + <script src="js/cells/KelvinCell.js"></script> + <!--<script src="js/cells/TetraEdgeCell.js"></script>--> + <!--<script src="js/cells/TetraFaceCell.js"></script>--> <script src="js/parts/DmaPart.js"></script> <script src="js/parts/GIKMicroLegoPart.js"></script> diff --git a/js/cells/CubeCell.js b/js/cells/CubeCell.js new file mode 100644 index 00000000..355dddf5 --- /dev/null +++ b/js/cells/CubeCell.js @@ -0,0 +1,38 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +(function () { + + var unitCellGeo = new THREE.BoxGeometry(1,1,1); + + function CubeCell(indices){ + DMACell.call(this, indices); + } + CubeCell.prototype = Object.create(DMACell.prototype); + + CubeCell.prototype._getGeometry = function(){ + return unitCellGeo; + }; + + CubeCell.prototype._buildWireframe = function(mesh){//abstract mesh representation of cell + var wireframe = new THREE.BoxHelper(mesh); + wireframe.material.color.set(0x000000); + return wireframe; + }; + + CubeCell.prototype.calcHighlighterPosition = function(face){ + + var direction = face.normal.clone().applyEuler(this.object3D.rotation); + var position = this.getPosition(); + var scale = this.xScale(); + _.each(_.keys(position), function(key){ + position[key] += direction[key]*scale/2; + }); + return {index: _.clone(this.indices), direction:direction, position:position}; + }; + + self.CubeCell = CubeCell; + +})(); \ No newline at end of file diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 8b8ab7bd..688a09d8 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -63,13 +63,17 @@ DMACell.prototype._buildMesh = function(){//called from every subclass var meshes = []; var mesh = new THREE.Mesh(geometry, cellMaterial); mesh.name = "cell"; - var wireframe = new THREE.Mesh(geometry, wireframeMaterial); + var wireframe = this._buildWireframe(mesh, geometry); wireframe.name = "cell"; meshes.push(mesh); meshes.push(wireframe); return meshes; }; +DMACell.prototype._buildWireframe = function(mesh, geometry){//abstract mesh representation of cell + return new THREE.Mesh(geometry, wireframeMaterial); +}; + DMACell.prototype._initParts = function(){ return [];//override in subclasses }; diff --git a/js/cells/DmaCellOther.js b/js/cells/DmaCellOther.js deleted file mode 100644 index 99f1610c..00000000 --- a/js/cells/DmaCellOther.js +++ /dev/null @@ -1,303 +0,0 @@ -/** - * Created by aghassaei on 3/9/15. - */ - - -//var cellMaterial = [new THREE.MeshNormalMaterial()]; - - -/////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////CUBE CELL CLASS//////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// - - -(function () { - - var unitCellGeo = new THREE.BoxGeometry(1,1,1); - - function DMACubeCell(indices, cellMode, partType){ - DMACell.call(this, indices, cellMode, partType); - } - DMACubeCell.prototype = Object.create(DMACell.prototype); - - DMACubeCell.prototype._buildMesh = function(){//abstract mesh representation of cell - var mesh = DMACell.prototype._buildMesh.call(this, cellMaterial); - var wireframe = new THREE.BoxHelper(mesh.children[0]); - wireframe.material.color.set(0x000000); - mesh.children.push(wireframe); - return mesh; - }; - - DMACubeCell.prototype.calcHighlighterPosition = function(face){ - - var direction = face.normal.clone().applyEuler(this.mesh.rotation); - var position = this.getPosition(); - var scale = this.xScale(); - _.each(_.keys(position), function(key){ - position[key] += direction[key]*scale/2; - }); - return {index: _.clone(this.indices), direction:direction, position:position}; - }; - - DMACubeCell.prototype._getGeometry = function(){ - return unitCellGeo; - }; - - self.DMACubeCell = DMACubeCell; - -})(); - -(function () { - - var unitCellGeo = new THREE.BoxGeometry(1,1,1); - - function DMAGIKCell(indices, cellMode, partType){ - DMACubeCell.call(this, indices, cellMode, partType); - } - DMAGIKCell.prototype = Object.create(DMACubeCell.prototype); - - DMAGIKCell.prototype._buildMesh = function(){ - return DMACubeCell.prototype._buildMesh.call(this, cellMaterial); - }; - - DMAGIKCell.prototype._doMeshTransformations = function(mesh){ - if (this.indices && this.indices.z%2 != 0) mesh.rotateZ(Math.PI/2); - }; - - DMAGIKCell.prototype._setCellMeshVisibility = function(visible){ - this.mesh.visible = false; - if (this.superCell) this.superCell.setVisibility(visible); - }; - - DMAGIKCell.prototype.setSuperCell = function(superCell, index){ - this.superCell = superCell; - this.superCellIndex = index; - if (this.superCellIndex == this.superCell.getLength()) this.mesh.rotateZ(Math.PI); - if (globals.appState.get("cellMode")=="part") { - this.parts = this.__initParts(); - this.draw(); - } - }; - - DMAGIKCell.prototype.getMaterialType = function(){ - return this.superCell.getMaterialType(); - }; - - DMAGIKCell.prototype._initParts = function(){ - if (!this.superCell) return []; - var parts = []; - var isEnd = this.superCellIndex == 0 || this.superCellIndex == this.superCell.getLength(); - if (globals.lattice.get("partType") == "lego") { - if (isEnd) parts.push(new DMAGIKEndPart(0, this)); - else parts.push(new DMAGIKPart(0, this)); - } - else { - if (isEnd) parts.push(new DMAGIKEndPartLowPoly(0, this)); - else parts.push(new DMAGIKPartLowPoly(0, this)); - } - return parts; - }; - - self.DMAGIKCell = DMAGIKCell; - -})(); - - -/////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////TRUNCATED CUBE CLASS/////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// - -(function(){ - - var truncCubeRad = Math.sqrt(2)/2; - var unitCellGeo = new THREE.Geometry(); - unitCellGeo.vertices = [ - new THREE.Vector3(truncCubeRad, 0, truncCubeRad), - new THREE.Vector3(0, truncCubeRad, truncCubeRad), - new THREE.Vector3(-truncCubeRad, 0, truncCubeRad), - new THREE.Vector3(0, -truncCubeRad, truncCubeRad), - - new THREE.Vector3(truncCubeRad, truncCubeRad, 0), - new THREE.Vector3(-truncCubeRad, truncCubeRad, 0), - new THREE.Vector3(-truncCubeRad, -truncCubeRad, 0), - new THREE.Vector3(truncCubeRad, -truncCubeRad, 0), - - new THREE.Vector3(truncCubeRad, 0, -truncCubeRad), - new THREE.Vector3(0, truncCubeRad, -truncCubeRad), - new THREE.Vector3(-truncCubeRad, 0, -truncCubeRad), - new THREE.Vector3(0, -truncCubeRad, -truncCubeRad) - ]; - unitCellGeo.faces = [ - new THREE.Face3(1,0,4), - new THREE.Face3(2,1,5), - new THREE.Face3(3,2,6), - new THREE.Face3(0,3,7), - - new THREE.Face3(8,9,4), - new THREE.Face3(9,10,5), - new THREE.Face3(10,11,6), - new THREE.Face3(11,8,7), - - new THREE.Face3(0,1,3), - new THREE.Face3(2,3,1), - new THREE.Face3(8,11,9), - new THREE.Face3(11,10,9), - new THREE.Face3(0,8,4), - new THREE.Face3(0,7,8), - new THREE.Face3(1,9,5), - new THREE.Face3(1,4,9), - new THREE.Face3(2,10,6), - new THREE.Face3(2,5,10), - new THREE.Face3(3,11,7), - new THREE.Face3(3,6,11) - ]; - unitCellGeo.computeFaceNormals(); - - function DMATruncCubeCell(indices, cellMode, partType){ - DMACell.call(this, indices, cellMode, partType); - } - DMATruncCubeCell.prototype = Object.create(DMACell.prototype); - - DMATruncCubeCell.prototype._buildMesh = function(){//abstract mesh representation of cell - var mesh = DMACell.prototype._buildMesh.call(this, cellMaterial); - mesh.children.push(new THREE.EdgesHelper(mesh.children[0], 0x000000)); - return mesh; - }; - - DMATruncCubeCell.prototype.calcHighlighterPosition = function(face){ - - var direction = face.normal; - if (!(Math.abs(direction.x)>0.9 || Math.abs(direction.y)>0.9 || Math.abs(direction.z)>0.9)) return {index: _.clone(this.indices)}; - - var position = this.getPosition(); - var scale = this.zScale(); - _.each(_.keys(position), function(key){ - position[key] += direction[key]*scale/2; - }); - return {index: _.clone(this.indices), direction:direction, position:position}; - }; - - DMATruncCubeCell.prototype._getGeometry = function(){ - return unitCellGeo; - }; - - self.DMATruncCubeCell = DMATruncCubeCell; - -})(); - -/////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////TRUNCATED OCTA CLASS/////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// - -(function(){ - - var truncOctaRad = Math.sqrt(2); - var pyrRad = 1/Math.sqrt(2); - var unitCellGeo = new THREE.Geometry(); - unitCellGeo.vertices = [ - new THREE.Vector3(pyrRad, 0, truncOctaRad), - new THREE.Vector3(0, pyrRad, truncOctaRad), - new THREE.Vector3(-pyrRad, 0, truncOctaRad), - new THREE.Vector3(0, -pyrRad, truncOctaRad), - - new THREE.Vector3(pyrRad, 0, -truncOctaRad), - new THREE.Vector3(0, pyrRad, -truncOctaRad), - new THREE.Vector3(-pyrRad, 0, -truncOctaRad), - new THREE.Vector3(0, -pyrRad, -truncOctaRad), - - new THREE.Vector3(truncOctaRad, 0, pyrRad), - new THREE.Vector3(truncOctaRad, pyrRad, 0), - new THREE.Vector3(truncOctaRad, 0, -pyrRad), - new THREE.Vector3(truncOctaRad, -pyrRad, 0), - - new THREE.Vector3(-truncOctaRad, 0, pyrRad), - new THREE.Vector3(-truncOctaRad, pyrRad, 0), - new THREE.Vector3(-truncOctaRad, 0, -pyrRad), - new THREE.Vector3(-truncOctaRad, -pyrRad, 0), - - new THREE.Vector3(pyrRad, truncOctaRad, 0), - new THREE.Vector3(0, truncOctaRad, pyrRad), - new THREE.Vector3(-pyrRad, truncOctaRad, 0), - new THREE.Vector3(0, truncOctaRad, -pyrRad), - - new THREE.Vector3(pyrRad, -truncOctaRad, 0), - new THREE.Vector3(0, -truncOctaRad, pyrRad), - new THREE.Vector3(-pyrRad, -truncOctaRad, 0), - new THREE.Vector3(0, -truncOctaRad, -pyrRad) - ]; - unitCellGeo.faces = [ - new THREE.Face3(0,1,3), - new THREE.Face3(2,3,1), - new THREE.Face3(4,7,5), - new THREE.Face3(7,6,5), - - new THREE.Face3(8,11,9), - new THREE.Face3(10,9,11), - new THREE.Face3(12,13,15), - new THREE.Face3(15,13,14), - - new THREE.Face3(16,19,17), - new THREE.Face3(18,17,19), - new THREE.Face3(20,21,23), - new THREE.Face3(23,21,22), - - new THREE.Face3(0, 8, 1), - new THREE.Face3(16, 8, 9), - new THREE.Face3(16, 17, 1), - new THREE.Face3(1, 8, 16), - - new THREE.Face3(1, 12, 2), - new THREE.Face3(18, 13, 12), - new THREE.Face3(17, 18, 1), - new THREE.Face3(1, 18, 12), - - new THREE.Face3(3, 8, 0), - new THREE.Face3(20, 11, 8), - new THREE.Face3(20, 3, 21), - new THREE.Face3(20, 8, 3), - - new THREE.Face3(3, 2, 12), - new THREE.Face3(12, 15, 22), - new THREE.Face3(22, 21, 3), - new THREE.Face3(22, 3, 12), - - new THREE.Face3(4, 5, 10), - new THREE.Face3(16, 9, 10), - new THREE.Face3(16, 5, 19), - new THREE.Face3(5, 16, 10), - - new THREE.Face3(5, 6, 14), - new THREE.Face3(18, 14, 13), - new THREE.Face3(19, 5, 18), - new THREE.Face3(18, 5, 14), - - new THREE.Face3(7, 4, 10), - new THREE.Face3(20, 10, 11), - new THREE.Face3(20, 23, 7), - new THREE.Face3(20, 7, 10), - - new THREE.Face3(7, 14, 6), - new THREE.Face3(14, 22, 15), - new THREE.Face3(22, 7, 23), - new THREE.Face3(22, 14, 7), - ]; - unitCellGeo.computeFaceNormals(); - - function DMATruncOctaCell(indices, cellMode, partType){ - DMATruncCubeCell.call(this, indices, cellMode, partType); - } - DMATruncOctaCell.prototype = Object.create(DMATruncCubeCell.prototype); - - DMATruncOctaCell.prototype._buildMesh = function(){//abstract mesh representation of cell - var mesh = DMACell.prototype._buildMesh.call(this, cellMaterial); - mesh.children.push(new THREE.EdgesHelper(mesh.children[0], 0x000000)); - return mesh; - }; - - DMATruncOctaCell.prototype._getGeometry = function(){ - return unitCellGeo; - }; - - self.DMATruncOctaCell = DMATruncOctaCell; - -})(); diff --git a/js/cells/DmaCellTetra.js b/js/cells/DmaCellTetra.js deleted file mode 100644 index 7cb69a6d..00000000 --- a/js/cells/DmaCellTetra.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Created by aghassaei on 3/9/15. - */ - -/////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////FACE CONNECTED TETRA/////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// - -var unitCellGeo = new THREE.TetrahedronGeometry(Math.sqrt(3/8)); -unitCellGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4)); -unitCellGeo.applyMatrix(new THREE.Matrix4().makeRotationX((Math.PI-Math.atan(2*Math.sqrt(2)))/2)); -unitCellGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-1/Math.sqrt(6))); - -var unitCellGeoUpsideDown = unitCellGeo.clone(); -unitCellGeoUpsideDown.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI)); - -function DMATetraFaceCell(indices, scale, cellMode, partType){ - DMACell.call(this, indices, scale, cellMode, partType); -} -DMATetraFaceCell.prototype = Object.create(DMACell.prototype); - -DMATetraFaceCell.prototype._buildMesh = function(){//abstract mesh representation of cell - var zIndex = this.indices.z; - if (zIndex%2 ==0) return DMACell.prototype._buildMesh.call(this); - return DMACell.prototype._buildMesh.call(this, unitCellGeoUpsideDown); -}; - -DMATetraFaceCell.prototype._doMeshTransformations = function(mesh){ - var zIndex = this.indices.z; - if (Math.abs(zIndex%4) == 2 || Math.abs(zIndex%4) == 3) mesh.rotateZ(Math.PI/3); -}; - -DMATetraFaceCell.prototype._getGeometry = function(){ - return unitCellGeo; -}; - - - -/////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////EDGE CONNECTED TETRA/////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// - -function DMATetraEdgeCell(indices, scale, cellMode, partType){ - DMATetraFaceCell.call(this, indices, scale, cellMode, partType); -} -DMATetraEdgeCell.prototype = Object.create(DMATetraFaceCell.prototype); - -DMATetraEdgeCell.prototype._doMeshTransformations = function(){}; diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js new file mode 100644 index 00000000..35489cdf --- /dev/null +++ b/js/cells/GIKCell.js @@ -0,0 +1,57 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +(function () { + + function GIKCell(indices, cellMode, partType){ + CubeCell.call(this, indices, cellMode, partType); + } + GIKCell.prototype = Object.create(CubeCell.prototype); + + GIKCell.prototype._buildMesh = function(){ + return DMACubeCell.prototype._buildMesh.call(this, cellMaterial); + }; + + GIKCell.prototype._doMeshTransformations = function(mesh){ + if (this.indices && this.indices.z%2 != 0) mesh.rotateZ(Math.PI/2); + }; + + GIKCell.prototype._setCellMeshVisibility = function(visible){ + this.mesh.visible = false; + if (this.superCell) this.superCell.setVisibility(visible); + }; + + GIKCell.prototype.setSuperCell = function(superCell, index){ + this.superCell = superCell; + this.superCellIndex = index; + if (this.superCellIndex == this.superCell.getLength()) this.mesh.rotateZ(Math.PI); + if (globals.appState.get("cellMode")=="part") { + this.parts = this.__initParts(); + this.draw(); + } + }; + + GIKCell.prototype.getMaterialType = function(){ + return this.superCell.getMaterialType(); + }; + + GIKCell.prototype._initParts = function(){ + if (!this.superCell) return []; + var parts = []; + var isEnd = this.superCellIndex == 0 || this.superCellIndex == this.superCell.getLength(); + if (globals.lattice.get("partType") == "lego") { + if (isEnd) parts.push(new DMAGIKEndPart(0, this)); + else parts.push(new DMAGIKPart(0, this)); + } + else { + if (isEnd) parts.push(new DMAGIKEndPartLowPoly(0, this)); + else parts.push(new DMAGIKPartLowPoly(0, this)); + } + return parts; + }; + + self.GIKCell = GIKCell; + +})(); \ No newline at end of file diff --git a/js/cells/KelvinCell.js b/js/cells/KelvinCell.js new file mode 100644 index 00000000..4ae5de83 --- /dev/null +++ b/js/cells/KelvinCell.js @@ -0,0 +1,111 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +(function(){ + + var truncOctaRad = Math.sqrt(2); + var pyrRad = 1/Math.sqrt(2); + var unitCellGeo = new THREE.Geometry(); + unitCellGeo.vertices = [ + new THREE.Vector3(pyrRad, 0, truncOctaRad), + new THREE.Vector3(0, pyrRad, truncOctaRad), + new THREE.Vector3(-pyrRad, 0, truncOctaRad), + new THREE.Vector3(0, -pyrRad, truncOctaRad), + + new THREE.Vector3(pyrRad, 0, -truncOctaRad), + new THREE.Vector3(0, pyrRad, -truncOctaRad), + new THREE.Vector3(-pyrRad, 0, -truncOctaRad), + new THREE.Vector3(0, -pyrRad, -truncOctaRad), + + new THREE.Vector3(truncOctaRad, 0, pyrRad), + new THREE.Vector3(truncOctaRad, pyrRad, 0), + new THREE.Vector3(truncOctaRad, 0, -pyrRad), + new THREE.Vector3(truncOctaRad, -pyrRad, 0), + + new THREE.Vector3(-truncOctaRad, 0, pyrRad), + new THREE.Vector3(-truncOctaRad, pyrRad, 0), + new THREE.Vector3(-truncOctaRad, 0, -pyrRad), + new THREE.Vector3(-truncOctaRad, -pyrRad, 0), + + new THREE.Vector3(pyrRad, truncOctaRad, 0), + new THREE.Vector3(0, truncOctaRad, pyrRad), + new THREE.Vector3(-pyrRad, truncOctaRad, 0), + new THREE.Vector3(0, truncOctaRad, -pyrRad), + + new THREE.Vector3(pyrRad, -truncOctaRad, 0), + new THREE.Vector3(0, -truncOctaRad, pyrRad), + new THREE.Vector3(-pyrRad, -truncOctaRad, 0), + new THREE.Vector3(0, -truncOctaRad, -pyrRad) + ]; + unitCellGeo.faces = [ + new THREE.Face3(0,1,3), + new THREE.Face3(2,3,1), + new THREE.Face3(4,7,5), + new THREE.Face3(7,6,5), + + new THREE.Face3(8,11,9), + new THREE.Face3(10,9,11), + new THREE.Face3(12,13,15), + new THREE.Face3(15,13,14), + + new THREE.Face3(16,19,17), + new THREE.Face3(18,17,19), + new THREE.Face3(20,21,23), + new THREE.Face3(23,21,22), + + new THREE.Face3(0, 8, 1), + new THREE.Face3(16, 8, 9), + new THREE.Face3(16, 17, 1), + new THREE.Face3(1, 8, 16), + + new THREE.Face3(1, 12, 2), + new THREE.Face3(18, 13, 12), + new THREE.Face3(17, 18, 1), + new THREE.Face3(1, 18, 12), + + new THREE.Face3(3, 8, 0), + new THREE.Face3(20, 11, 8), + new THREE.Face3(20, 3, 21), + new THREE.Face3(20, 8, 3), + + new THREE.Face3(3, 2, 12), + new THREE.Face3(12, 15, 22), + new THREE.Face3(22, 21, 3), + new THREE.Face3(22, 3, 12), + + new THREE.Face3(4, 5, 10), + new THREE.Face3(16, 9, 10), + new THREE.Face3(16, 5, 19), + new THREE.Face3(5, 16, 10), + + new THREE.Face3(5, 6, 14), + new THREE.Face3(18, 14, 13), + new THREE.Face3(19, 5, 18), + new THREE.Face3(18, 5, 14), + + new THREE.Face3(7, 4, 10), + new THREE.Face3(20, 10, 11), + new THREE.Face3(20, 23, 7), + new THREE.Face3(20, 7, 10), + + new THREE.Face3(7, 14, 6), + new THREE.Face3(14, 22, 15), + new THREE.Face3(22, 7, 23), + new THREE.Face3(22, 14, 7), + ]; + unitCellGeo.computeFaceNormals(); + + function KelvinCell(indices, cellMode, partType){ + TruncatedCubeCell.call(this, indices, cellMode, partType); + } + KelvinCell.prototype = Object.create(TruncatedCubeCell.prototype); + + KelvinCell.prototype._getGeometry = function(){ + return unitCellGeo; + }; + + self.KelvinCell = KelvinCell; + +})(); \ No newline at end of file diff --git a/js/cells/TetraEdgeCell.js b/js/cells/TetraEdgeCell.js new file mode 100644 index 00000000..0b19fc61 --- /dev/null +++ b/js/cells/TetraEdgeCell.js @@ -0,0 +1,11 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +function DMATetraEdgeCell(indices, scale, cellMode, partType){ + TetraFaceCell.call(this, indices, scale, cellMode, partType); +} +DMATetraEdgeCell.prototype = Object.create(TetraFaceCell.prototype); + +DMATetraEdgeCell.prototype._rotateCell = function(){}; \ No newline at end of file diff --git a/js/cells/TetraFaceCell.js b/js/cells/TetraFaceCell.js new file mode 100644 index 00000000..bc076a47 --- /dev/null +++ b/js/cells/TetraFaceCell.js @@ -0,0 +1,28 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +var unitCellGeo = new THREE.TetrahedronGeometry(Math.sqrt(3/8)); +unitCellGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4)); +unitCellGeo.applyMatrix(new THREE.Matrix4().makeRotationX((Math.PI-Math.atan(2*Math.sqrt(2)))/2)); +unitCellGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-1/Math.sqrt(6))); + +var unitCellGeoUpsideDown = unitCellGeo.clone(); +unitCellGeoUpsideDown.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI)); + +function TetraFaceCell(indices){ + DMACell.call(this, indices); +} +TetraFaceCell.prototype = Object.create(DMACell.prototype); + +TetraFaceCell.prototype._getGeometry = function(){//abstract mesh representation of cell + if (this.indices.z%2 ==0) return unitCellGeo;//todo need this? + return unitCellGeoUpsideDown; +}; + +TetraFaceCell.prototype._rotateCell = function(object3D){ + var zIndex = this.indices.z; + if (Math.abs(zIndex%4) == 2 || Math.abs(zIndex%4) == 3) object3D.rotateZ(Math.PI/3); + return object3D; +}; \ No newline at end of file diff --git a/js/cells/TruncatedCubeCell.js b/js/cells/TruncatedCubeCell.js new file mode 100644 index 00000000..5e6665bd --- /dev/null +++ b/js/cells/TruncatedCubeCell.js @@ -0,0 +1,80 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +(function(){ + + var truncCubeRad = Math.sqrt(2)/2; + var unitCellGeo = new THREE.Geometry(); + unitCellGeo.vertices = [ + new THREE.Vector3(truncCubeRad, 0, truncCubeRad), + new THREE.Vector3(0, truncCubeRad, truncCubeRad), + new THREE.Vector3(-truncCubeRad, 0, truncCubeRad), + new THREE.Vector3(0, -truncCubeRad, truncCubeRad), + + new THREE.Vector3(truncCubeRad, truncCubeRad, 0), + new THREE.Vector3(-truncCubeRad, truncCubeRad, 0), + new THREE.Vector3(-truncCubeRad, -truncCubeRad, 0), + new THREE.Vector3(truncCubeRad, -truncCubeRad, 0), + + new THREE.Vector3(truncCubeRad, 0, -truncCubeRad), + new THREE.Vector3(0, truncCubeRad, -truncCubeRad), + new THREE.Vector3(-truncCubeRad, 0, -truncCubeRad), + new THREE.Vector3(0, -truncCubeRad, -truncCubeRad) + ]; + unitCellGeo.faces = [ + new THREE.Face3(1,0,4), + new THREE.Face3(2,1,5), + new THREE.Face3(3,2,6), + new THREE.Face3(0,3,7), + + new THREE.Face3(8,9,4), + new THREE.Face3(9,10,5), + new THREE.Face3(10,11,6), + new THREE.Face3(11,8,7), + + new THREE.Face3(0,1,3), + new THREE.Face3(2,3,1), + new THREE.Face3(8,11,9), + new THREE.Face3(11,10,9), + new THREE.Face3(0,8,4), + new THREE.Face3(0,7,8), + new THREE.Face3(1,9,5), + new THREE.Face3(1,4,9), + new THREE.Face3(2,10,6), + new THREE.Face3(2,5,10), + new THREE.Face3(3,11,7), + new THREE.Face3(3,6,11) + ]; + unitCellGeo.computeFaceNormals(); + + function TruncatedCubeCell(indices){ + DMACell.call(this, indices); + } + TruncatedCubeCell.prototype = Object.create(DMACell.prototype); + + TruncatedCubeCell.prototype._getGeometry = function(){ + return unitCellGeo; + }; + + TruncatedCubeCell.prototype._buildWireframe = function(mesh){//abstract mesh representation of cell + return new THREE.EdgesHelper(mesh, 0x000000); + }; + + TruncatedCubeCell.prototype.calcHighlighterPosition = function(face){ + + var direction = face.normal; + if (!(Math.abs(direction.x)>0.9 || Math.abs(direction.y)>0.9 || Math.abs(direction.z)>0.9)) return {index: _.clone(this.indices)}; + + var position = this.getPosition(); + var scale = this.zScale(); + _.each(_.keys(position), function(key){ + position[key] += direction[key]*scale/2; + }); + return {index: _.clone(this.indices), direction:direction, position:position}; + }; + + self.TruncatedCubeCell = TruncatedCubeCell; + +})(); \ No newline at end of file diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js index 10c5e8f0..527fa423 100644 --- a/js/lattice/CubeLattice.js +++ b/js/lattice/CubeLattice.js @@ -34,7 +34,7 @@ latticeSubclasses["CubeLattice"] = { }, makeCellForLatticeType: function(indices){ - return new DMACubeCell(indices); + return new CubeCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index e0ada953..377aee1b 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -34,7 +34,7 @@ latticeSubclasses["GIKLattice"] = { }, makeCellForLatticeType: function(indices){ - return new DMAGIKCell(indices); + return new GIKCell(indices); }, makeSuperCell: function(range){ diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js index 124216e8..fedacfd3 100644 --- a/js/lattice/KelvinLattice.js +++ b/js/lattice/KelvinLattice.js @@ -35,7 +35,7 @@ latticeSubclasses["KelvinLattice"] = { }, makeCellForLatticeType: function(indices){ - return new DMATruncOctaCell(indices); + return new KelvinCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js index 3f7c01ec..57006216 100644 --- a/js/lattice/TruncatedCubeLattice.js +++ b/js/lattice/TruncatedCubeLattice.js @@ -34,7 +34,7 @@ latticeSubclasses["TruncatedCubeLattice"] = { }, makeCellForLatticeType: function(indices){ - return new DMATruncCubeCell(indices); + return new TruncatedCubeCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later -- GitLab