From 4c5cf93cfbc54eccd40afd82d7680ec358d5b31d Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 26 May 2015 12:41:33 -0700 Subject: [PATCH] cells refer to lattice x y z scales --- js/cell/DMACellFreeform.js | 4 +- js/cell/DmaCell.js | 43 ++-- js/cell/DmaCellOcta.js | 38 +--- js/cell/DmaCellOther.js | 50 +---- js/cell/DmaCellTetra.js | 6 +- js/lattice/CubeLattice.js | 14 +- js/lattice/GIKLattice.js | 14 +- js/lattice/KelvinLattice.js | 14 +- js/lattice/OctaFaceLattice.js | 14 +- js/lattice/OctaFreeFormFaceLattice.js | 16 +- js/lattice/OctaRotEdgeLattice.js | 14 +- js/lattice/OctaVertexLattice.js | 14 +- js/lattice/TruncatedCubeLattice.js | 14 +- js/models/BasePlane.js | 22 +- js/models/LatticeOcta.js | 300 -------------------------- js/models/LatticeOther.js | 240 --------------------- 16 files changed, 114 insertions(+), 703 deletions(-) delete mode 100644 js/models/LatticeOcta.js delete mode 100644 js/models/LatticeOther.js diff --git a/js/cell/DMACellFreeform.js b/js/cell/DMACellFreeform.js index 2c5c6ac9..0e2b6f3e 100644 --- a/js/cell/DMACellFreeform.js +++ b/js/cell/DMACellFreeform.js @@ -27,9 +27,9 @@ DMAFreeFormCell.prototype._calcPosition = function(){//todo this might not be ne }; DMAFreeFormCell.prototype.calcHighlighterPosition = function(face){ - //var direction = face.normal.clone().applyEuler(this.cellMesh.rotation); + //var direction = face.normal.clone().applyEuler(this.mesh.rotation); var direction = face.normal.clone(); - direction.applyQuaternion(this.cellMesh.quaternion); + direction.applyQuaternion(this.mesh.quaternion); var position = this.getPosition(); position.add(direction.clone().multiplyScalar(this.zScale()/2)); return {index: _.clone(this.indices), direction:direction, position:position}; diff --git a/js/cell/DmaCell.js b/js/cell/DmaCell.js index 34359dbd..c6e922bb 100644 --- a/js/cell/DmaCell.js +++ b/js/cell/DmaCell.js @@ -11,12 +11,11 @@ var cellMaterials = [new THREE.MeshNormalMaterial(), function DMACell(indices, cellMode, partType) { this.indices = indices; + this.mesh = this._buildMesh(); + this._doMeshTransformations(this.mesh);//some cell types require transformations + this._setMeshPosition(this.mesh, this._calcPosition()); - this.cellMesh = this._buildCellMesh(); - this._doMeshTransformations(this.cellMesh);//some cell types require transformations - this._setMeshPosition(this.cellMesh, this._calcPosition()); - - globals.three.sceneAdd(this.cellMesh,this._sceneType(indices)); + globals.three.sceneAdd(this.mesh,this._sceneType(indices)); this.draw(cellMode, partType); @@ -39,8 +38,8 @@ DMACell.prototype.draw = function(cellMode, partType){ //init parts/beams if needed if (partMode &&!beamMode && !this.parts) this.parts = this._initParts(); if (beamMode && !this.beams) { - this.nodes = this._initNodes(this.cellMesh.children[0].geometry.vertices); - this.beams = this._initBeams(this.nodes, this.cellMesh.children[0].geometry.faces); + this.nodes = this._initNodes(this.mesh.children[0].geometry.vertices); + this.beams = this._initBeams(this.nodes, this.mesh.children[0].geometry.faces); } //set visibility @@ -74,7 +73,7 @@ DMACell.prototype._setMeshPosition = function(mesh, position){ }; DMACell.prototype.moveTo = function(position, axis){//used for stock simulations - this.cellMesh.position[axis] = position; + this.mesh.position[axis] = position; if (globals.appState.get("cellMode") == "part"){ _.each(this.parts, function(part){ if (part) part.moveTo(position, axis); @@ -87,36 +86,36 @@ DMACell.prototype.getType = function(){ }; DMACell.prototype.getPosition = function(){ - return this.cellMesh.position.clone(); + return this.mesh.position.clone(); }; DMACell.prototype.getOrientation = function(){ - return this.cellMesh.quaternion.clone(); + return this.mesh.quaternion.clone(); }; DMACell.prototype.getEulerRotation = function(){ - return this.cellMesh.rotation.clone(); + return this.mesh.rotation.clone(); }; DMACell.prototype._calcPosition = function(){//need for part relay if (this.indices) return globals.lattice.getPositionForIndex(this.indices); - return this.cellMesh.position;//used for cam simulation + return this.mesh.position;//used for cam simulation }; DMACell.prototype._setCellMeshVisibility = function(visibility){ - this.cellMesh.visible = visibility; + this.mesh.visible = visibility; }; DMACell.prototype.xScale = function(){ - return globals.lattice.xScale(); + return globals.lattice.xScale(0); }; DMACell.prototype.yScale = function(){ - return globals.lattice.yScale(); + return globals.lattice.yScale(0); }; DMACell.prototype.zScale = function(){ - return globals.lattice.zScale(); + return globals.lattice.zScale(0); }; @@ -124,7 +123,7 @@ DMACell.prototype.zScale = function(){ /////////////////////////////////META////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// -DMACell.prototype._buildCellMesh = function(material){//called from every subclass +DMACell.prototype._buildMesh = function(material){//called from every subclass var unitCellGeo = this._getGeometry(); if (!material) material = cellMaterials; var mesh = THREE.SceneUtils.createMultiMaterialObject(unitCellGeo, material); @@ -209,13 +208,13 @@ DMACell.prototype._initBeams = function(nodes, faces){ DMACell.prototype.destroy = function(){ if (this.destroyStarted) return; this.destroyStarted = true; - if (this.cellMesh) { - globals.three.sceneRemove(this.cellMesh, this._sceneType(this.indices)); - this.cellMesh.myParent = null; -// this.cellMesh.dispose(); + if (this.mesh) { + globals.three.sceneRemove(this.mesh, this._sceneType(this.indices)); + this.mesh.myParent = null; +// this.mesh.dispose(); // geometry.dispose(); // material.dispose(); - this.cellMesh = null; + this.mesh = null; } this.destroyParts(); this.indices = null; diff --git a/js/cell/DmaCellOcta.js b/js/cell/DmaCellOcta.js index aa3df371..7a760c11 100644 --- a/js/cell/DmaCellOcta.js +++ b/js/cell/DmaCellOcta.js @@ -33,18 +33,6 @@ DMAFaceOctaCell.prototype._getGeometry = function(){ return unitFaceOctaGeo; }; -DMAFaceOctaCell.prototype.xScale = function(){ - return 1; -}; - -DMAFaceOctaCell.prototype.yScale = function(){ - return this.xScale()/2*Math.sqrt(3); -}; - -DMAFaceOctaCell.prototype.zScale = function(){ - return 2/Math.sqrt(6); -}; - DMAFaceOctaCell.prototype.calcHighlighterPosition = function(face){ if (face.normal.z<0.99) return {index: _.clone(this.indices)};//only highlight horizontal faces var direction = face.normal; @@ -69,7 +57,7 @@ DMAEdgeOctaCell.prototype._doMeshTransformations = function(){}; //todo fix this DMAEdgeOctaCell.prototype.calcHighlighterPosition = function(face){ var direction = face.normal.clone(); - direction.applyQuaternion(this.cellMesh.quaternion); + direction.applyQuaternion(this.mesh.quaternion); var position = this.getPosition(); position.add(direction.clone().multiplyScalar(this.zScale()/2)); return {index: _.clone(this.indices), direction:direction, position:position}; @@ -168,18 +156,6 @@ DMARotatedEdgeCell.prototype.calcHighlighterPosition = function(face, point){ return {index: _.clone(this.indices), direction:direction, position:position}; }; -DMARotatedEdgeCell.prototype.xScale = function(){ - return 1; -}; - -DMARotatedEdgeCell.prototype.yScale = function(){ - return this.xScale(); -}; - -DMARotatedEdgeCell.prototype.zScale = function(){ - return Math.sqrt(2)/2; -}; - DMARotatedEdgeCell.prototype._getGeometry = function(){ return unitVertexOcta; }; @@ -235,16 +211,4 @@ DMAVertexOctaCell.prototype.calcHighlighterPosition = function(face, point){ DMAVertexOctaCell.prototype._getGeometry = function(){ return unitVertexOcta; -}; - -DMAVertexOctaCell.prototype.xScale = function(){ - return Math.sqrt(2); -}; - -DMAVertexOctaCell.prototype.yScale = function(){ - return this.xScale(); -}; - -DMAVertexOctaCell.prototype.zScale = function(){ - return this.xScale(); }; \ No newline at end of file diff --git a/js/cell/DmaCellOther.js b/js/cell/DmaCellOther.js index 27b19da8..d27fadaa 100644 --- a/js/cell/DmaCellOther.js +++ b/js/cell/DmaCellOther.js @@ -20,8 +20,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; } DMACubeCell.prototype = Object.create(DMACell.prototype); - DMACubeCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell - var mesh = DMACell.prototype._buildCellMesh.call(this, cellMaterial); + 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); @@ -30,7 +30,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; DMACubeCell.prototype.calcHighlighterPosition = function(face){ - var direction = face.normal.clone().applyEuler(this.cellMesh.rotation); + var direction = face.normal.clone().applyEuler(this.mesh.rotation); var position = this.getPosition(); var scale = this.xScale(); _.each(_.keys(position), function(key){ @@ -43,18 +43,6 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return unitCellGeo; }; - DMACubeCell.prototype.xScale = function(){ - return 1; - }; - - DMACubeCell.prototype.yScale = function(){ - return this.xScale(); - }; - - DMACubeCell.prototype.zScale = function(){ - return this.xScale(); - }; - self.DMACubeCell = DMACubeCell; })(); @@ -68,8 +56,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; } DMAGIKCell.prototype = Object.create(DMACubeCell.prototype); - DMAGIKCell.prototype._buildCellMesh = function(){ - return DMACubeCell.prototype._buildCellMesh.call(this, cellMaterial); + DMAGIKCell.prototype._buildMesh = function(){ + return DMACubeCell.prototype._buildMesh.call(this, cellMaterial); }; DMAGIKCell.prototype._doMeshTransformations = function(mesh){ @@ -77,14 +65,14 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; }; DMAGIKCell.prototype._setCellMeshVisibility = function(visible){ - this.cellMesh.visible = false; + 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.cellMesh.rotateZ(Math.PI); + if (this.superCellIndex == this.superCell.getLength()) this.mesh.rotateZ(Math.PI); if (globals.appState.get("cellMode")=="part") { this.parts = this.__initParts(); this.draw(); @@ -170,8 +158,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; } DMATruncCubeCell.prototype = Object.create(DMACell.prototype); - DMATruncCubeCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell - var mesh = DMACell.prototype._buildCellMesh.call(this, cellMaterial); + 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; }; @@ -193,18 +181,6 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return unitCellGeo; }; - DMATruncCubeCell.prototype.xScale = function(){ - return Math.sqrt(2); - }; - - DMATruncCubeCell.prototype.yScale = function(){ - return this.xScale(); - }; - - DMATruncCubeCell.prototype.zScale = function(){ - return this.xScale(); - }; - self.DMATruncCubeCell = DMATruncCubeCell; })(); @@ -312,8 +288,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; } DMATruncOctaCell.prototype = Object.create(DMATruncCubeCell.prototype); - DMATruncOctaCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell - var mesh = DMACell.prototype._buildCellMesh.call(this, cellMaterial); + 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; }; @@ -322,10 +298,6 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return unitCellGeo; }; - DMATruncOctaCell.prototype.xScale = function(){ - return 2*Math.sqrt(2); - }; - self.DMATruncOctaCell = DMATruncOctaCell; })(); diff --git a/js/cell/DmaCellTetra.js b/js/cell/DmaCellTetra.js index 6857eabe..7cb69a6d 100644 --- a/js/cell/DmaCellTetra.js +++ b/js/cell/DmaCellTetra.js @@ -19,10 +19,10 @@ function DMATetraFaceCell(indices, scale, cellMode, partType){ } DMATetraFaceCell.prototype = Object.create(DMACell.prototype); -DMATetraFaceCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell +DMATetraFaceCell.prototype._buildMesh = function(){//abstract mesh representation of cell var zIndex = this.indices.z; - if (zIndex%2 ==0) return DMACell.prototype._buildCellMesh.call(this); - return DMACell.prototype._buildCellMesh.call(this, unitCellGeoUpsideDown); + if (zIndex%2 ==0) return DMACell.prototype._buildMesh.call(this); + return DMACell.prototype._buildMesh.call(this, unitCellGeoUpsideDown); }; DMATetraFaceCell.prototype._doMeshTransformations = function(mesh){ diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js index e2ce706e..10c5e8f0 100644 --- a/js/lattice/CubeLattice.js +++ b/js/lattice/CubeLattice.js @@ -19,16 +19,18 @@ latticeSubclasses["CubeLattice"] = { return this._positionForIndex(index); }, - xScale: function(){ - return 1+2*this.get("cellSeparation").xy; + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; }, - yScale: function(){ - return this.xScale(); + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); }, - zScale: function(){ - return 1+2*this.get("cellSeparation").z; + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 1+2*cellSeparation; }, makeCellForLatticeType: function(indices){ diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index 98d5af06..e0ada953 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -19,16 +19,18 @@ latticeSubclasses["GIKLattice"] = { return this._positionForIndex(index); }, - xScale: function(){ - return 1+2*this.get("cellSeparation").xy; + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; }, - yScale: function(){ - return this.xScale(); + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); }, - zScale: function(){ - return 1.28*(1+2*this.get("cellSeparation").z); + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 1.28*(1+2*cellSeparation); }, makeCellForLatticeType: function(indices){ diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js index 96c9a6cb..124216e8 100644 --- a/js/lattice/KelvinLattice.js +++ b/js/lattice/KelvinLattice.js @@ -20,16 +20,18 @@ latticeSubclasses["KelvinLattice"] = { return this._positionForIndex(index); }, - xScale: function(){ - return 2*Math.sqrt(2)+2*this.get("cellSeparation").xy; + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 2*Math.sqrt(2)+2*cellSeparation; }, - yScale: function(){ - return this.xScale(); + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); }, - zScale: function(){ - return 2*Math.sqrt(2)+2*this.get("cellSeparation").z; + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 2*Math.sqrt(2)+2*cellSeparation; }, makeCellForLatticeType: function(indices){ diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js index 195cf6a0..3431adb1 100644 --- a/js/lattice/OctaFaceLattice.js +++ b/js/lattice/OctaFaceLattice.js @@ -28,16 +28,18 @@ latticeSubclasses["OctaFaceLattice"] = { return position; }, - xScale: function(){ - return 1+2*this.get("cellSeparation").xy; + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; }, - yScale: function(){ - return this.xScale()/2*Math.sqrt(3); + yScale: function(cellSeparation){ + return this.xScale(cellSeparation)/2*Math.sqrt(3); }, - zScale: function(){ - return 2/Math.sqrt(6)+2*this.get("cellSeparation").z; + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return 2/Math.sqrt(6)+2*cellSeparation; }, makeCellForLatticeType: function(indices){ diff --git a/js/lattice/OctaFreeFormFaceLattice.js b/js/lattice/OctaFreeFormFaceLattice.js index 5984a10f..1aa1d261 100644 --- a/js/lattice/OctaFreeFormFaceLattice.js +++ b/js/lattice/OctaFreeFormFaceLattice.js @@ -48,17 +48,19 @@ latticeSubclasses["OctaFreeFormFaceLattice"] = { return position; }, - xScale: function(){ - return 1+2*this.get("cellSeparation").xy; + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1+2*cellSeparation; }, - yScale: function(){ - return this.xScale()/2*Math.sqrt(3); + yScale: function(cellSeparation){ + return this.xScale(cellSeparation)/2*Math.sqrt(3); }, - zScale: function(){ - if (this.get("freeformCellType") == "octa") return 2/Math.sqrt(6)+2*this.get("cellSeparation").xy; - return 2/Math.sqrt(24)+2*this.get("cellSeparation").xy; + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;//todo xy? + if (this.get("freeformCellType") == "octa") return 2/Math.sqrt(6)+2*cellSeparation; + return 2/Math.sqrt(24)+2*cellSeparation; }, _undo: function(){//remove all the mixins diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js index 0582bb92..ebd5a7de 100644 --- a/js/lattice/OctaRotEdgeLattice.js +++ b/js/lattice/OctaRotEdgeLattice.js @@ -31,16 +31,18 @@ latticeSubclasses["OctaRotEdgeLattice"] = { return position; }, - xScale: function(){ - return 1 + 2*this.get("cellSeparation").xy; + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return 1 + 2*cellSeparation; }, - yScale: function(){ - return this.xScale(); + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); }, - zScale: function(){ - return Math.sqrt(2)/2 + 2*this.get("cellSeparation").z; + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return Math.sqrt(2)/2 + 2*cellSeparation; }, makeCellForLatticeType: function(indices){ diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js index 27c8a5cc..174bb730 100644 --- a/js/lattice/OctaVertexLattice.js +++ b/js/lattice/OctaVertexLattice.js @@ -27,16 +27,18 @@ latticeSubclasses["OctaVertexLattice"] = { return position; }, - xScale: function(){ - return Math.sqrt(2)+this.get("cellSeparation").xy; + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return Math.sqrt(2)+2*cellSeparation; }, - yScale: function(){ - return this.xScale(); + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); }, - zScale: function(){ - return Math.sqrt(2)+this.get("cellSeparation").z; + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return Math.sqrt(2)+2*cellSeparation; }, makeCellForLatticeType: function(indices){ diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js index edde79a7..3f7c01ec 100644 --- a/js/lattice/TruncatedCubeLattice.js +++ b/js/lattice/TruncatedCubeLattice.js @@ -19,16 +19,18 @@ latticeSubclasses["TruncatedCubeLattice"] = { return this._positionForIndex(index); }, - xScale: function(){ - return Math.sqrt(2)+2*this.get("cellSeparation").xy; + xScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy; + return Math.sqrt(2)+2*cellSeparation; }, - yScale: function(){ - return this.xScale(); + yScale: function(cellSeparation){ + return this.xScale(cellSeparation); }, - zScale: function(){ - return Math.sqrt(2)+2*this.get("cellSeparation").z; + zScale: function(cellSeparation){ + if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z; + return Math.sqrt(2)+2*cellSeparation; }, makeCellForLatticeType: function(indices){ diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index f739c894..9f5db8a5 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -115,9 +115,9 @@ OctaBasePlane = BasePlane.extend({ _renderZIndexChange: function(){ var zIndex = this.get("zIndex"); - var xScale = globals.lattice.xScale(1); - var yScale = globals.lattice.yScale(1); - var zScale = globals.lattice.zScale(1); + var xScale = globals.lattice.xScale(); + var yScale = globals.lattice.yScale(); + var zScale = globals.lattice.zScale(); _.each(this.get("mesh"), function(mesh){ mesh.position.set(xScale*(zIndex%2)/2, -yScale/3*(zIndex%2), zIndex*zScale); @@ -130,8 +130,8 @@ OctaBasePlane = BasePlane.extend({ var vertices = []; - var xScale = globals.lattice.xScale(1); - var yScale = globals.lattice.yScale(1); + var xScale = globals.lattice.xScale(); + var yScale = globals.lattice.yScale(); var dimX = this.get("dimX"); var dimY = this.get("dimY"); @@ -169,7 +169,7 @@ OctaBasePlane = BasePlane.extend({ if (index.z%2 != 0) index.x -= 1; index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane var position = globals.lattice.getPositionForIndex(index); - position.z += globals.lattice.zScale(1)/2; + position.z += globals.lattice.zScale()/2; return {index: index, direction: new THREE.Vector3(0,0,1), position:position}; } @@ -184,7 +184,7 @@ SquareBasePlane = BasePlane.extend({ _makeBasePlaneMesh: function(){ - var scale = globals.lattice.xScale(1); + var scale = globals.lattice.xScale(); var dimX = this.get("dimX")*scale; var dimY = this.get("dimY")*scale; @@ -214,7 +214,7 @@ SquareBasePlane = BasePlane.extend({ _renderZIndexChange: function(){ var zIndex = this.get("zIndex"); - var zScale = globals.lattice.zScale(1); + var zScale = globals.lattice.zScale(); _.each(this.get("mesh"), function(mesh){ mesh.position.set(0, 0, zIndex*zScale); }); @@ -225,7 +225,7 @@ SquareBasePlane = BasePlane.extend({ var index = globals.lattice.getIndexForPosition(position); index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane var latticePosition = globals.lattice.getPositionForIndex(index); - latticePosition.z += globals.lattice.zScale(1)/2; + latticePosition.z += globals.lattice.zScale()/2; return {index: index, direction: new THREE.Vector3(0,0,1), position:latticePosition}; } @@ -243,8 +243,8 @@ RotEdgeOctaBasePlane = SquareBasePlane.extend({ var index = globals.lattice.getIndexForPosition(position); index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane var latticePosition = globals.lattice.getPositionForIndex(index); - latticePosition.x -= globals.lattice.xScale(1)/2; - latticePosition.y -= globals.lattice.yScale(1)/2; + latticePosition.x -= globals.lattice.xScale()/2; + latticePosition.y -= globals.lattice.yScale()/2; return {index: index, direction: new THREE.Vector3(0,0,1), position:latticePosition}; } }); \ No newline at end of file diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js deleted file mode 100644 index 411f473b..00000000 --- a/js/models/LatticeOcta.js +++ /dev/null @@ -1,300 +0,0 @@ -/** - * Created by aghassaei on 3/10/15. - */ - - -//////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////FACE CONN OCTA LATTICE//////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - -OctaLatticeSubclasses = { - - OctaFaceLattice: { - - _initLatticeType: function(){ - globals.basePlane = new OctaBasePlane(); - globals.highlighter = new OctaFaceHighlighter(); - }, - - getIndexForPosition: function(absPosition){ - var yIndex = Math.floor(absPosition.y/this.yScale()); - if (yIndex%2 != 0) absPosition.x += this.xScale()/2; - var index = this._indexForPosition(absPosition); - if (index.z%2 == 1) index.y += 1; - return index; - }, - - getPositionForIndex: function(index){ - var position = _.clone(index); - position.x = (position.x+1/2); - position.y = position.y*this.yScale()+1/Math.sqrt(3)/2; - position.z = (position.z+0.5)*this.zScale(); - if ((index.y%2) != 0) position.x -= this.xScale()/2; - return position; - }, - - xScale: function(){ - return 1+2*this.get("cellSeparation").xy; - }, - - yScale: function(){ - return this.xScale()/2*Math.sqrt(3); - }, - - zScale: function(){ - return 2/Math.sqrt(6)+2*this.get("cellSeparation").z; - }, - - makeCellForLatticeType: function(indices){ - return new DMAFaceOctaCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.OctaFaceLattice), function(key){ - self[key] = null; - }); - } - }, - - - -//////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////FACE CONN OCTA FREEFORM//////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - - - OctaFreeFormFaceLattice: { - - _initLatticeType: function(){ - globals.basePlane = new OctaBasePlane(); - globals.highlighter = new OctaFreeFormHighlighter(); - - this.set("freeformCellType", "octa"); - - }, - - addFreeFormCell: function(parentCellPos, parentCellOrient, direction, parentType, type){ - var cells = this.get("cells"); - cells[0][0].push(this.makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, parentCellPos, parentCellOrient, direction, parentType, type)); - this.set("numCells", this.get("numCells")+1); - globals.three.render(); - }, - - makeCellForLatticeType: function(index, parentPosition, parentOrientation, direction, parentType, type){ - if (type){ - if (type == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType); - return new DMAFreeFormTetraCell(index, parentPosition, parentOrientation, direction, parentType); - } - if (this.get("freeformCellType") == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType); - return new DMAFreeFormTetraCell(index, parentPosition, parentOrientation, direction, parentType); - }, - - getIndexForPosition: function(absPosition){//only used by baseplane - var yIndex = Math.floor(absPosition.y/this.yScale()); - if (yIndex%2 != 0) absPosition.x += this.xScale()/2; - var index = this._indexForPosition(absPosition); - if (index.z%2 == 1) index.y += 1; - return index; - }, - - getPositionForIndex: function(index){//only used by baseplane - var position = _.clone(index); - var xScale = this.xScale(); - position.x = (position.x+1/2)*xScale; - position.y = position.y*this.yScale()+1/Math.sqrt(3)/2; - position.z = (position.z+0.5)*this.zScale(); - if ((index.y%2) != 0) position.x -= xScale/2; - return position; - }, - - xScale: function(){ - return 1+2*this.get("cellSeparation").xy; - }, - - yScale: function(){ - return this.xScale()/2*Math.sqrt(3); - }, - - zScale: function(){ - if (this.get("freeformCellType") == "octa") return 2/Math.sqrt(6)+2*this.get("cellSeparation").xy; - return 2/Math.sqrt(24)+2*this.get("cellSeparation").xy; - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - this.set("freeformCellType", null); - this.clearCells(); - _.each(_.keys(this.OctaFreeFormFaceLattice), function(key){ - self[key] = null; - }); - } - }, - - - -//////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////EDGE CONN OCTA LATTICE//////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - - OctaEdgeLattice: { - - _initLatticeType: function(){ - globals.basePlane = new OctaBasePlane(); - globals.highlighter = new OctaEdgeHighlighter(); - - }, - - getIndexForPosition: function(absPosition){ - //todo finish this - var yIndex = Math.floor(absPosition.y/this.yScale()); - if (yIndex%2 != 0) absPosition.x += this.xScale()/2; - var yScale = 1/Math.sqrt(3); - var index = this._indexForPosition(absPosition); - if (index.z%3 == 1) { - absPosition.x -= this.xScale()/2; - absPosition.y += yScale/2; - } else if (index.z%3 == 2){ - absPosition.y += yScale; - } - var index = this._indexForPosition(absPosition); - return index; - }, - - getPositionForIndex: function(index){ - - var position = _.clone(index); - var xScale = this.xScale(); - var yScale = 1/Math.sqrt(3); - position.x = (position.x+1/2)*xScale; - position.y = position.y*this.yScale()+yScale/2; - position.z = (position.z+0.5)*this.zScale(); - if (index.y%2 != 0) position.x -= this.xScale()/2; - if (index.z%3 == 1) { - position.x += this.xScale()/2; - position.y -= yScale/2; - } else if (index.z%3 == 2){ - position.y -= yScale; - } - return position; - }, - - makeCellForLatticeType: function(indices){ - return new DMAEdgeOctaCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.OctaEdgeLattice), function(key){ - self[key] = null; - }); - _.each(_.keys(this.OctaFaceLattice), function(key){ - self[key] = null; - }); - } - }, - - OctaRotEdgeLattice: { - - _initLatticeType: function(){ - globals.basePlane = new RotEdgeOctaBasePlane(); - globals.highlighter = new OctaVertexHighlighter(); - }, - - getIndexForPosition: function(absPosition){ - var position = {}; - position.x = Math.floor(absPosition.x/this.xScale()+0.5); - position.y = Math.floor(absPosition.y/this.yScale()+0.5); - position.z = Math.floor(absPosition.z/this.zScale()+0.5); - return position; - }, - - getPositionForIndex: function(index){ - var position = _.clone(index); - if (index.z %2 != 0){ - position.x += 0.5; - position.y += 0.5; - } - position.x = (position.x)*this.xScale(); - position.y = (position.y)*this.yScale(); - position.z = (position.z+1)*this.zScale(); - return position; - }, - - xScale: function(){ - return 1 + 2*this.get("cellSeparation").xy; - }, - - yScale: function(){ - return this.xScale(); - }, - - zScale: function(){ - return Math.sqrt(2)/2 + 2*this.get("cellSeparation").z; - }, - - makeCellForLatticeType: function(indices){ - return new DMARotatedEdgeCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.OctaRotEdgeLattice), function(key){ - self[key] = null; - }); - } - }, - - - -//////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////VERTEX CONN OCTA LATTICE////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - - OctaVertexLattice: { - - _initLatticeType: function(){ - globals.basePlane = new SquareBasePlane(); - globals.highlighter = new OctaVertexHighlighter(); - }, - - getIndexForPosition: function(absPosition){ - var position = {}; - position.x = Math.floor(absPosition.x/this.xScale()+0.5); - position.y = Math.floor(absPosition.y/this.yScale()+0.5); - position.z = Math.floor(absPosition.z/this.zScale()+0.5); - return position; - }, - - getPositionForIndex: function(index){ - var position = _.clone(index); - position.x = (position.x)*this.xScale(); - position.y = (position.y)*this.yScale(); - position.z = (position.z+0.5)*this.zScale(); - return position; - }, - - xScale: function(){ - return Math.sqrt(2)+this.get("cellSeparation").xy; - }, - - yScale: function(){ - return this.xScale(); - }, - - zScale: function(){ - return Math.sqrt(2)+this.get("cellSeparation").z; - }, - - makeCellForLatticeType: function(indices){ - return new DMAVertexOctaCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.OctaVertexLattice), function(key){ - self[key] = null; - }); - } - } -}; diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js deleted file mode 100644 index c167f4f5..00000000 --- a/js/models/LatticeOther.js +++ /dev/null @@ -1,240 +0,0 @@ -/** - * Created by aghassaei on 3/10/15. - */ - - -//////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////CUBE LATTICE////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - -OtherLatticeSubclasses = { - - CubeLattice: { - - _initLatticeType: function(){ - globals.basePlane = new SquareBasePlane(); - globals.highlighter = new CubeHighlighter(); - }, - - getIndexForPosition: function(absPosition){ - return this._indexForPosition(absPosition); - }, - - getPositionForIndex: function(index){ - return this._positionForIndex(index); - }, - - xScale: function(){ - return 1+2*this.get("cellSeparation").xy; - }, - - yScale: function(){ - return this.xScale(); - }, - - zScale: function(){ - return 1+2*this.get("cellSeparation").z; - }, - - makeCellForLatticeType: function(indices){ - return new DMACubeCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.CubeLattice), function(key){ - self[key] = null; - }); - } - }, - -//////////////////////////////////////////////////////////////////////////////////////// -///////////////////////////////GIK LATTICE////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - - GIKLattice: { - - _initLatticeType: function(){ - globals.basePlane = new SquareBasePlane(); - globals.highlighter = new GIKHighlighter(); - }, - - getIndexForPosition: function(absPosition){ - return this._indexForPosition(absPosition); - }, - - getPositionForIndex: function(index){ - return this._positionForIndex(index); - }, - - xScale: function(){ - return 1+2*this.get("cellSeparation").xy; - }, - - yScale: function(){ - return this.xScale(); - }, - - zScale: function(){ - return 1.28*(1+2*this.get("cellSeparation").z); - }, - - makeCellForLatticeType: function(indices){ - return new DMAGIKCell(indices); - }, - - makeSuperCell: function(range){ - var length = this.get("gikLength"); - var cells; - if (range) cells = this.addCellsInRange(range); - else { - cells = []; - for (var i=0;i<length;i++){ - cells.push(this.makeCellForLatticeType(null)); - } - } - if (cells.length < 1) return null; - var superCell = new DMASuperCell(length, range, cells); - _.each(cells, function(cell, index){ - cell.setSuperCell(superCell, index); - }); - return superCell; - }, - - _rasterGikCells: function(order, callback, var1, var2, var3, cells){ - for (var i=this._getRasterLoopInit(var1);this._getRasterLoopCondition(i,var1);i+=this._getRasterLoopIterator(var1)){ - for (var j=this._getRasterLoopInit(var2);this._getRasterLoopCondition(j,var2);j+=this._getRasterLoopIterator(var2)){ - for (var k=this._getRasterLoopInit(var3);this._getRasterLoopCondition(k,var3);k+=this._getRasterLoopIterator(var3)){ - var numToSkip = {x:0,y:0}; - if (var1.order == 0){ - if (var2.order == 1) numToSkip = this._doSuperCellCallback(cells, i, j, k, callback); - else if (var2.order == 2) numToSkip = this._doSuperCellCallback(cells, i, k, j, callback); - } else if (var1.order == 1){ - if (var2.order == 0) numToSkip = this._doSuperCellCallback(cells, j, i, k, callback); - else if (var2.order == 2) numToSkip = this._doSuperCellCallback(cells, k, i, j, callback); - } else { - if (var2.order == 0) { - numToSkip = this._doSuperCellCallback(cells, j, k, i, callback); - } - else if (var2.order == 1) { - numToSkip = this._doSuperCellCallback(cells, k, j, i, callback); - } - } - - } - } - } - }, - - _doSuperCellCallback: function(cells, x, y, z, callback){ - var cell = cells[x][y][z]; - if (z%2 != 0) cell = cells[y][x][z]; - if (!cell) { - callback(null, x, y, z); - return {x:0,y:0}; - } - var superCell = cell.superCell; - callback(superCell, x, y, z); - if (z%2 != 0) return {x:0, y:superCell.getLength()}; - return {x:superCell.getLength(), y:0}; - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.GIKLattice), function(key){ - self[key] = null; - }); - } - }, - - -//////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////TRUNCATED CUBE LATTICE//////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - - TruncatedCubeLattice: { - - _initLatticeType: function(){ - globals.basePlane = new SquareBasePlane(); - globals.highlighter = new TruncatedCubeHighlighter(); - }, - - getIndexForPosition: function(absPosition){ - return this._indexForPosition(absPosition); - }, - - getPositionForIndex: function(index){ - return this._positionForIndex(index); - }, - - xScale: function(){ - return Math.sqrt(2)+2*this.get("cellSeparation").xy; - }, - - yScale: function(){ - return this.xScale(); - }, - - zScale: function(){ - return Math.sqrt(2)+2*this.get("cellSeparation").z; - }, - - makeCellForLatticeType: function(indices){ - return new DMATruncCubeCell(indices); - }, - - _undo: function(){//remove all the mixins, this will help with debugging later - var self = this; - _.each(_.keys(this.TruncatedCubeLattice), function(key){ - self[key] = null; - }); - } - - }, - - - //////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////TRUNCATED CUBE LATTICE//////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - - KelvinLattice: { - - _initLatticeType: function(){ - globals.basePlane = new SquareBasePlane(); - globals.highlighter = new TruncatedCubeHighlighter(); - }, - - getIndexForPosition: function(absPosition){ - return this._indexForPosition(absPosition); - }, - - getPositionForIndex: function(index){ - return this._positionForIndex(index); - }, - - xScale: function(){ - return 2*Math.sqrt(2)+2*this.get("cellSeparation").xy; - }, - - yScale: function(){ - return this.xScale(); - }, - - zScale: function(){ - return 2*Math.sqrt(2)+2*this.get("cellSeparation").z; - }, - - makeCellForLatticeType: function(indices){ - return new DMATruncOctaCell(indices); - }, - - _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 -- GitLab