From 1327c10dcc77fa203f0395e4b1d9f4a8a48a1686 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 10 Mar 2015 03:00:05 -0400 Subject: [PATCH] truncated cube --- js/fea/DmaCellOcta.js | 4 +-- js/fea/DmaCellOther.js | 13 ++++++++ js/models/AppState.js | 6 +++- js/models/BasePlane.js | 6 ++-- js/models/Lattice.js | 19 ++--------- js/models/LatticeOcta.js | 64 ------------------------------------ js/models/LatticeOther.js | 49 +++++++++++++++++++++++++++ js/threeViews/Highlighter.js | 32 ++++++++++++------ 8 files changed, 96 insertions(+), 97 deletions(-) diff --git a/js/fea/DmaCellOcta.js b/js/fea/DmaCellOcta.js index 032ea09c..b1e5e88c 100644 --- a/js/fea/DmaCellOcta.js +++ b/js/fea/DmaCellOcta.js @@ -35,9 +35,9 @@ DMAFaceOctaCell.prototype._doMeshTransformations = function(mesh){ DMAFaceOctaCell.prototype.calcHighlighterPosition = function(face){ - var direction = face.normal; - if (face.normal.z<0.99) direction = null;//only highlight horizontal faces + if (face.normal.z<0.99) return {index: _.clone(this.indices)};//only highlight horizontal faces + var direction = face.normal; var position = this.getPosition(); position.z += face.normal.z*dmaGlobals.lattice.zScale()/2; return {index: _.clone(this.indices), direction:direction, position:position}; diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index 3de932db..24bf0d46 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -66,6 +66,19 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return mesh; }; + 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)}; + + var position = this.getPosition(); + var scale = dmaGlobals.lattice.zScale(); + _.each(_.keys(position), function(key){ + position[key] += direction[key]*scale/2; + }); + return {index: _.clone(this.indices), direction:direction, position:position}; + } + self.DMATruncCubeCell = DMATruncCubeCell; })(); diff --git a/js/models/AppState.js b/js/models/AppState.js index 6ef2c5d6..347ed247 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -18,10 +18,11 @@ AppState = Backbone.Model.extend({ menuWrapper: null, - allCellTypes: {octa:"Octahedron", cube:"Cube", kelvin:"Kelvin (coming soon)"}, + allCellTypes: {octa:"Octahedron", cube:"Cube", truncatedCube:"Truncated Cube", kelvin:"Kelvin (coming soon)"}, allConnectionTypes: { octa: {face:"Face", freeformFace:"Freeform Face", edge:"Edge", edgeRot:"Rotated Edge", vertex:"Vertex"}, cube: {face:"Face"}, + truncatedCube: {face:"Face"}, kelvin: {face: "Face"} }, allPartTypes:{ @@ -35,6 +36,9 @@ AppState = Backbone.Model.extend({ cube:{ face: {beam:"Beam"} }, + truncatedCube:{ + face: {beam:"Beam"} + }, kelvin:{ face: {beam:"Beam"} } diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index c08648dd..90a3a9fa 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -242,9 +242,9 @@ SquareBasePlane = BasePlane.extend({ calcHighlighterPosition: function(face, position){ var index = dmaGlobals.lattice.getIndexForPosition(position); index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane - var position = dmaGlobals.lattice.getPositionForIndex(index); - position.z += dmaGlobals.lattice.zScale()/2; - return {index: index, direction: new THREE.Vector3(0,0,1), position:position}; + var latticePosition = dmaGlobals.lattice.getPositionForIndex(index); + latticePosition.z += dmaGlobals.lattice.zScale()/2; + return {index: index, direction: new THREE.Vector3(0,0,1), position:latticePosition}; } }); \ No newline at end of file diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 82ad93b3..ce41bda7 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -84,23 +84,6 @@ Lattice = Backbone.Model.extend({ }, -// _addInverseCellsForIndex: function(index){ -// -// var inverseIndicesToAdd = this._inverseIndicesToAdd(_.clone(index)); -// -// var invCells = this.get("inverseCells"); -// var scale = this.get("scale"); -// var self = this; -// _.each(inverseIndicesToAdd, function(invIndex){ -// self._checkForMatrixExpansion(invCells, invIndex, invIndex, "inverseCellsMax", "inverseCellsMin"); -// var indexRel = self._subtract(invIndex, self.get("inverseCellsMin")); -// if (!invCells[indexRel.x][indexRel.y][indexRel.z]) { -// invCells[indexRel.x][indexRel.y][indexRel.z] = self._makeInvCellForLatticeType(invIndex, scale); -// self.set("numInvCells", self.get("numInvCells")+1); -// } -// }); -// }, - _indexForPosition: function(absPosition){ var position = {}; var scale = this.get("scale"); @@ -372,6 +355,8 @@ Lattice = Backbone.Model.extend({ } } else if (cellType == "cube"){ _.extend(this, this.CubeLattice); + } else if (cellType == "truncatedCube"){ + _.extend(this, this.TruncatedCubeLattice); } else if (cellType == "kelvin"){ _.extend(this, this.CubeLattice); } diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js index dcceb93c..d207510e 100644 --- a/js/models/LatticeOcta.js +++ b/js/models/LatticeOcta.js @@ -108,45 +108,6 @@ OctaLatticeSubclasses = { return new DMAFaceOctaCell(indices, scale); }, -// _inverseIndicesToAdd: function(index){ -// -// var oddZ = index.z%2 != 0; -// -// index = _.clone(index); -// index.z*=2; -// -// var z0 = 0; -// if (oddZ) z0 = 1; -// -// if (this.get("connectionType") == "edge") z0 = 0; -// var z1 = Math.abs(z0-1); -// -// var inverseIndicesToAdd; -// if (index.y%2 == 0){ -// -// inverseIndicesToAdd = [ -// this._add(index, {x:0,y:0,z:z0}), -// this._add(index, {x:0,y:1,z:z0}), -// this._add(index, {x:1,y:1,z:z0}), -// -// this._add(index, {x:0,y:0,z:z1}), -// this._add(index, {x:0,y:1,z:z1}), -// this._add(index, {x:1,y:0,z:z1}) -// ]; -// } else { -// inverseIndicesToAdd = [ -// this._add(index, {x:0,y:0,z:z0}), -// this._add(index, {x:-1,y:1,z:z0}), -// this._add(index, {x:0,y:1,z:z0}), -// -// this._add(index, {x:-1,y:0,z:z1}), -// this._add(index, {x:0,y:1,z:z1}), -// this._add(index, {x:0,y:0,z:z1}) -// ]; -// } -// return inverseIndicesToAdd; -// }, - _undo: function(){//remove all the mixins, this will help with debugging later this.stopListening(this, "change:columnSeparation"); var self = this; @@ -419,31 +380,6 @@ OctaLatticeSubclasses = { return this._positionForIndex(index); }, -// getInvCellPositionForIndex: function(index){ -// -// var position = this._positionForIndex(index); -// -// var scale = this.get("scale"); -// position.x -= this.xScale(scale)/2; -// position.y -= this.yScale(scale)/2; -// position.z -= this.zScale(scale)/2; -// return position; -// }, - -// _inverseIndicesToAdd: function(index){ -// return [ -// this._add(index, {x:0,y:0,z:0}), -// this._add(index, {x:0,y:1,z:0}), -// this._add(index, {x:1,y:0,z:0}), -// this._add(index, {x:1,y:1,z:0}), -// -// this._add(index, {x:0,y:0,z:1}), -// this._add(index, {x:0,y:1,z:1}), -// this._add(index, {x:1,y:0,z:1}), -// this._add(index, {x:1,y:1,z:1}) -// ]; -// }, - xScale: function(scale){ if (!scale) scale = this.get("scale"); return scale*Math.sqrt(2); diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index 11b33419..6a2fc680 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -50,5 +50,54 @@ OtherLatticeSubclasses = { self[key] = null; }); } + }, + +//////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////TRUNCATED CUBE LATTICE//////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////// + + TruncatedCubeLattice: { + + _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*Math.sqrt(2); + }, + + yScale: function(scale){ + return this.xScale(scale); + }, + + zScale: function(scale){ + return this.xScale(scale); + }, + + _makeCellForLatticeType: function(indices, scale){ + return new DMATruncCubeCell(indices, scale); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(this.TruncatedCubeLattice), function(key){ + self[key] = null; + }); + } + } + }; \ No newline at end of file diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 71cf229a..1d53053c 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -74,7 +74,8 @@ Highlighter = Backbone.View.extend({ return; } this.direction = highlightedPos.direction; - this._setPosition(highlightedPos.position, this.direction);//position of center point + this._setPosition(highlightedPos.position);//position of center point + this._setRotation(this.direction); this.show(true); }, @@ -87,8 +88,11 @@ Highlighter = Backbone.View.extend({ this.mesh.scale.set(scale, scale, scale); }, - _setPosition: function(position, direction){ + _setPosition: function(position){ this.mesh.position.set(position.x, position.y, position.z); + }, + + _setRotation: function(direction){ this.mesh.rotation.set(direction.y*Math.PI/2, direction.x*Math.PI/2, 0); }, @@ -145,8 +149,7 @@ OctaFaceHighlighter = Highlighter.extend({ return geometry; }, - _setPosition: function(position){ - this.mesh.position.set(position.x, position.y, position.z); + _setRotation: function(){ this.mesh.rotation.set(0,0,(this.index.z+1)%2*Math.PI); } @@ -158,9 +161,7 @@ OctaEdgeHighlighter = Highlighter.extend({ return new THREE.SphereGeometry(0.2); }, - _setPosition: function(position){ - this.mesh.position.set(position.x, position.y, position.z); - } + _setRotation: function(){} }); @@ -178,9 +179,7 @@ OctaFreeFormHighlighter = Highlighter.extend({ return new THREE.SphereGeometry(0.2); }, - _setPosition: function(position, direction){ - this.mesh.position.set(position.x, position.y, position.z); - } + _setRotation: function(){} }); /////////////////////////////////////////////////////////////////////////////////// @@ -193,4 +192,17 @@ CubeHighlighter = Highlighter.extend({ return new THREE.BoxGeometry(1,1,0.01);; } +}); + +TruncatedCubeHighlighter = Highlighter.extend({ + + _makeGeometry: function(){ + return new THREE.BoxGeometry(1,1,0.01);; + }, + + _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 -- GitLab