diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index 24bf0d46700565866b5b6604c41f80939ceca5b8..e4bc76bc3e070174f7191f4b2e5bd5d309131f2c 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -5,6 +5,45 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; + +/////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////CUBE CELL CLASS//////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////// + + +(function () { + + var unitCellGeo = new THREE.BoxGeometry(1,1,1); + + function DMACubeCell(indices, scale){ + DMACell.call(this, indices, scale); + } + DMACubeCell.prototype = Object.create(DMACell.prototype); + + DMACubeCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell + var mesh = DMACell.prototype._buildCellMesh.call(this, unitCellGeo, 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; + 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.DMACubeCell = DMACubeCell; + +})(); + + /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////TRUNCATED CUBE CLASS/////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// @@ -69,10 +108,10 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; DMATruncCubeCell.prototype.calcHighlighterPosition = function(face){ var direction = face.normal; - if (!(direction.x>0.9 || direction.y>0.9 || direction.z>0.9)) return {index: _.clone(this.indices)}; + 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 = dmaGlobals.lattice.zScale(); + var scale = this.zScale(); _.each(_.keys(position), function(key){ position[key] += direction[key]*scale/2; }); @@ -83,40 +122,77 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; })(); - /////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////CUBE CELL CLASS//////////////////////////////////////////////////////// +////////////////////////TRUNCATED OCTA CLASS/////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// +(function(){ -(function () { + var truncOctaRad = Math.sqrt(3)/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), - var unitCellGeo = new THREE.BoxGeometry(1,1,1); + new THREE.Face3(8,11,9), + new THREE.Face3(10,9,11), + new THREE.Face3(12,13,15), + new THREE.Face3(15,13,14), - function DMACubeCell(indices, scale){ - DMACell.call(this, indices, scale); + new THREE.Face3(16,19,17), + new THREE.Face3(18,17,19), + new THREE.Face3(20,21,23), + new THREE.Face3(23,21,22), + + + ]; + unitCellGeo.computeFaceNormals(); + + function DMATruncOctaCell(indices, scale){ + DMATruncCubeCell.call(this, indices, scale); } - DMACubeCell.prototype = Object.create(DMACell.prototype); + DMATruncOctaCell.prototype = Object.create(DMATruncCubeCell.prototype); - DMACubeCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell + DMATruncOctaCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell var mesh = DMACell.prototype._buildCellMesh.call(this, unitCellGeo, cellMaterial); - var wireframe = new THREE.BoxHelper(mesh.children[0]); - wireframe.material.color.set(0x000000); - mesh.children.push(wireframe); + mesh.children.push(new THREE.EdgesHelper(mesh.children[0], 0x000000)); return mesh; }; - DMACubeCell.prototype.calcHighlighterPosition = function(face){ - - var direction = face.normal; - var position = this.getPosition(); - var scale = dmaGlobals.lattice.xScale(); - _.each(_.keys(position), function(key){ - position[key] += direction[key]*scale/2; - }); - return {index: _.clone(this.indices), direction:direction, position:position}; - } - - self.DMACubeCell = DMACubeCell; + self.DMATruncOctaCell = DMATruncOctaCell; })(); diff --git a/js/models/AppState.js b/js/models/AppState.js index abb11d674120da4a87791de3b92ee68532e5177c..f8ea30456df34f1860bb63e405ec1a500ba3c78a 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -18,9 +18,10 @@ AppState = Backbone.Model.extend({ menuWrapper: null, - allCellTypes: {octa:"Octahedron", cube:"Cube", truncatedCube:"Truncated Cube", kelvin:"Kelvin (coming soon)"}, + allCellTypes: {octa:"Octahedron", tetra: "Tetrahedron (Coming Soon)", cube:"Cube", truncatedCube:"Cuboctahedron", kelvin:"Truncated Octahedron"}, allConnectionTypes: { octa: {face:"Face", freeformFace:"Freeform Face", edgeRot:"Edge", vertex:"Vertex"},//edge:"Edge", + tetra: {vertex: "Vertex"}, cube: {face:"Face"}, truncatedCube: {face:"Face"}, kelvin: {face: "Face"} @@ -33,6 +34,9 @@ AppState = Backbone.Model.extend({ edgeRot: {beam:"Beam"}, vertex: {beam:"Beam", square:"Square", xShape:"X"} }, + tetra: { + vertex: {beam: "Beam"} + }, cube:{ face: {beam:"Beam"} }, diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 6b1db6badab8a879bd2d5b687fd92a4a91c4acdf..1cd038171fe499488aaa13a298dc8a072837c9c4 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -353,12 +353,14 @@ Lattice = Backbone.Model.extend({ } else if (connectionType == "vertex"){ _.extend(this, this.OctaVertexLattice); } + } else if (cellType == "tetra"){ + _.extend(this, this.CubeLattice); } else if (cellType == "cube"){ _.extend(this, this.CubeLattice); } else if (cellType == "truncatedCube"){ _.extend(this, this.TruncatedCubeLattice); } else if (cellType == "kelvin"){ - _.extend(this, this.CubeLattice); + _.extend(this, this.KelvinLattice); } this._initLatticeType(); diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index 6a2fc6802ba0f36828e80790d0573abab85c0d3e..1475423293316429ac2de3caac2e0e3434a874b6 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -98,6 +98,55 @@ OtherLatticeSubclasses = { }); } + }, + + + //////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////TRUNCATED CUBE LATTICE//////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////// + + KelvinLattice: { + + _initLatticeType: function(){ + + //bind events + + this.set("basePlane", new SquareBasePlane({scale:this.get("scale")})); + this.set("highlighter", new TruncatedCubeHighlighter({scale:this.get("scale")})); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(scale){ + if (!scale) scale = this.get("scale"); + return scale*(3+Math.sqrt(3)); + }, + + yScale: function(scale){ + return this.xScale(scale); + }, + + zScale: function(scale){ + return this.xScale(scale); + }, + + _makeCellForLatticeType: function(indices, scale){ + return new DMATruncOctaCell(indices, scale); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(this.KelvinLattice), function(key){ + self[key] = null; + }); + } + } }; \ No newline at end of file diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 1d53053c9cf1f23a216484fcaf987040ea2b6009..a5201a92d363628cb8ec45e703252512a7a31dc4 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -202,7 +202,6 @@ TruncatedCubeHighlighter = Highlighter.extend({ _setRotation: function(direction){ this.mesh.rotation.set(direction.y*Math.PI/2, direction.x*Math.PI/2, Math.PI/4); -// this.mesh.rotation.set(0,0,Math.PI/4); } }); \ No newline at end of file