From f1e53fa26501e43e4e67f14a8688c4f045cefa8a Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Mon, 25 May 2015 21:03:09 -0700 Subject: [PATCH] removed scale from cells --- js/fea/DMACellFreeform.js | 40 ++++----- js/fea/DmaCell.js | 52 ++---------- js/fea/DmaCellOcta.js | 58 ++++++------- js/fea/DmaCellOther.js | 47 +++++------ js/models/Lattice.js | 64 ++++----------- js/models/LatticeOcta.js | 169 ++++++++++++++++---------------------- js/models/LatticeOther.js | 75 ++++++++--------- 7 files changed, 199 insertions(+), 306 deletions(-) diff --git a/js/fea/DMACellFreeform.js b/js/fea/DMACellFreeform.js index d240876f..2c5c6ac9 100644 --- a/js/fea/DMACellFreeform.js +++ b/js/fea/DMACellFreeform.js @@ -8,12 +8,12 @@ /////////////////////////////////////////////////////////////////////////////////////////////// -function DMAFreeFormCell(indices, scale, parentCellPos, parentCellQuat, direction, parentType){//no rigid lattice structure for cells +function DMAFreeFormCell(indices, parentCellPos, parentCellQuat, direction, parentType){//no rigid lattice structure for cells this.parentPos = parentCellPos; this.parentQuaternion = parentCellQuat; this.parentDirection = direction; this.parentType = parentType; - DMACell.call(this, indices, scale); + DMACell.call(this, indices); } DMAFreeFormCell.prototype = Object.create(DMACell.prototype); @@ -54,8 +54,8 @@ DMAFreeFormCell.prototype.toJSON = function(){ /////////////////////////////////////////////////////////////////////////////////////////////// -function DMAFreeFormOctaCell(indices, scale, parentCellPos, parentCellQuat, direction, parentType){ - DMAFreeFormCell.call(this, indices, scale, parentCellPos, parentCellQuat, direction, parentType); +function DMAFreeFormOctaCell(indices, parentCellPos, parentCellQuat, direction, parentType){ + DMAFreeFormCell.call(this, indices, parentCellPos, parentCellQuat, direction, parentType); } DMAFreeFormOctaCell.prototype = Object.create(DMAFreeFormCell.prototype); @@ -98,18 +98,16 @@ DMAFreeFormOctaCell.prototype._getGeometry = function(){ return unitFaceOctaGeo; }; -DMAFreeFormOctaCell.prototype.xScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale; +DMAFreeFormOctaCell.prototype.xScale = function(){ + return 1; }; -DMAFreeFormOctaCell.prototype.yScale = function(scale){ - return this.xScale(scale)/2*Math.sqrt(3); +DMAFreeFormOctaCell.prototype.yScale = function(){ + return this.xScale()/2*Math.sqrt(3); }; -DMAFreeFormOctaCell.prototype.zScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale*2/Math.sqrt(6); +DMAFreeFormOctaCell.prototype.zScale = function(){ + return 2/Math.sqrt(6); }; @@ -124,8 +122,8 @@ var unitCellGeo2 = new THREE.TetrahedronGeometry(Math.sqrt(3/8)); unitCellGeo2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4)); unitCellGeo2.applyMatrix(new THREE.Matrix4().makeRotationX((Math.PI-Math.atan(2*Math.sqrt(2)))/2)); -function DMAFreeFormTetraCell(indices, scale, parentCellPos, parentCellQuat, direction, parentType){ - DMAFreeFormCell.call(this, indices, scale, parentCellPos, parentCellQuat, direction, parentType); +function DMAFreeFormTetraCell(indices, parentCellPos, parentCellQuat, direction, parentType){ + DMAFreeFormCell.call(this, indices, parentCellPos, parentCellQuat, direction, parentType); } DMAFreeFormTetraCell.prototype = Object.create(DMAFreeFormCell.prototype); @@ -161,18 +159,16 @@ DMAFreeFormTetraCell.prototype._initParts = function(){ return parts; }; -DMAFreeFormTetraCell.prototype.xScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale; +DMAFreeFormTetraCell.prototype.xScale = function(){ + return 1; }; -DMAFreeFormTetraCell.prototype.yScale = function(scale){ - return this.xScale(scale)/2*Math.sqrt(3); +DMAFreeFormTetraCell.prototype.yScale = function(){ + return this.xScale()/2*Math.sqrt(3); }; -DMAFreeFormTetraCell.prototype.zScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale*2/Math.sqrt(24); +DMAFreeFormTetraCell.prototype.zScale = function(){ + return 2/Math.sqrt(24); }; DMAFreeFormTetraCell.prototype._getGeometry = function(){ diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index fada48f7..369017c2 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -8,7 +8,7 @@ var cellMaterials = [new THREE.MeshNormalMaterial(), new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; -function DMACell(indices, scale, cellMode, partType) { +function DMACell(indices, cellMode, partType) { this.indices = indices; @@ -17,7 +17,7 @@ function DMACell(indices, scale, cellMode, partType) { globals.three.sceneAdd(this.cellMesh,this._sceneType(indices)); - this.draw(scale, cellMode, partType); + this.draw(cellMode, partType); this.hideForStockSimulation = false; } @@ -27,9 +27,8 @@ DMACell.prototype._sceneType = function(indices){ return "cell"; }; -DMACell.prototype.draw = function(scale, cellMode, partType){ +DMACell.prototype.draw = function(cellMode, partType){ if (this.hideForStockSimulation) return; - if (!scale) scale = globals.lattice.get("scale"); if (!cellMode) cellMode = globals.appState.get("cellMode"); if (!partType) partType = globals.lattice.get("partType"); //var beamMode = partType == "beam"; @@ -43,9 +42,6 @@ DMACell.prototype.draw = function(scale, cellMode, partType){ this.beams = this._initBeams(this.nodes, this.cellMesh.children[0].geometry.faces); } - //update scale - this.updateForScale(scale, cellMode, partType); - //set visibility this._setCellMeshVisibility(!partMode); _.each(this.parts, function(part){ @@ -70,30 +66,6 @@ DMACell.prototype.hide = function(){//only used in the context of stock simulati /////////////////////////////////SCALE/POSITION//////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// -DMACell.prototype.updateForScale = function(scale, cellMode, partType){ - if (!scale) scale = globals.lattice.get("scale"); - var position = this._calcPosition(); - this._setMeshPosition(this.cellMesh, position); - this.cellMesh.scale.set(scale, scale, scale);//must do this so highlighting works properly in part mode - - if (this.superCell && this.superCellIndex == 0) this.superCell.setScale(scale); - - //only update visible object to scale - if (!cellMode) cellMode = globals.appState.get("cellMode"); - if (!partType) partType = globals.lattice.get("partType"); - if (cellMode == "part"){ - if (partType == "beam"){ - _.each(this.beams, function(beam){ - if (beam) beam.updateForScale(scale, position);//todo this is not working quite right yet - }); - } else { - _.each(this.parts, function(part){ - if (part) part.updateForScale(scale, position); - }); - } - } -}; - DMACell.prototype._setMeshPosition = function(mesh, position){ mesh.position.x = position.x; mesh.position.y = position.y; @@ -113,10 +85,6 @@ DMACell.prototype.getType = function(){ return null;//only used in freeform layout }; -DMACell.prototype.getScale = function(){//need for part relay - return globals.lattice.get("scale"); -}; - DMACell.prototype.getPosition = function(){ return this.cellMesh.position.clone(); }; @@ -138,16 +106,16 @@ DMACell.prototype._setCellMeshVisibility = function(visibility){ this.cellMesh.visible = visibility; }; -DMACell.prototype.xScale = function(scale){ - return globals.lattice.xScale(scale); +DMACell.prototype.xScale = function(){ + return globals.lattice.xScale(); }; -DMACell.prototype.yScale = function(scale){ - return globals.lattice.yScale(scale); +DMACell.prototype.yScale = function(){ + return globals.lattice.yScale(); }; -DMACell.prototype.zScale = function(scale){ - return globals.lattice.zScale(scale); +DMACell.prototype.zScale = function(){ + return globals.lattice.zScale(); }; @@ -194,12 +162,10 @@ DMACell.prototype._initNodes = function(vertices){ var position = this.getPosition(); var orientation = this.getOrientation(); var nodes = []; - var scale = this.getScale(); for (var i=0;i<vertices.length;i++){ var vertex = vertices[i].clone(); vertex.applyQuaternion(orientation); vertex.add(position); - //vertex.multiplyScalar(scale); nodes.push(new DmaNode(vertex, i)); } return nodes; diff --git a/js/fea/DmaCellOcta.js b/js/fea/DmaCellOcta.js index 9172a3ce..aa3df371 100644 --- a/js/fea/DmaCellOcta.js +++ b/js/fea/DmaCellOcta.js @@ -12,8 +12,8 @@ var unitFaceOctaGeo = new THREE.OctahedronGeometry(1/Math.sqrt(2)); unitFaceOctaGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(-3*Math.PI/12)); unitFaceOctaGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.asin(2/Math.sqrt(2)/Math.sqrt(3)))); -function DMAFaceOctaCell(indices, scale, cellMode, partType){ - DMACell.call(this, indices, scale, cellMode, partType); +function DMAFaceOctaCell(indices, cellMode, partType){ + DMACell.call(this, indices, cellMode, partType); } DMAFaceOctaCell.prototype = Object.create(DMACell.prototype); @@ -33,18 +33,16 @@ DMAFaceOctaCell.prototype._getGeometry = function(){ return unitFaceOctaGeo; }; -DMAFaceOctaCell.prototype.xScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale; +DMAFaceOctaCell.prototype.xScale = function(){ + return 1; }; -DMAFaceOctaCell.prototype.yScale = function(scale){ - return this.xScale(scale)/2*Math.sqrt(3); +DMAFaceOctaCell.prototype.yScale = function(){ + return this.xScale()/2*Math.sqrt(3); }; -DMAFaceOctaCell.prototype.zScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale*2/Math.sqrt(6); +DMAFaceOctaCell.prototype.zScale = function(){ + return 2/Math.sqrt(6); }; DMAFaceOctaCell.prototype.calcHighlighterPosition = function(face){ @@ -61,8 +59,8 @@ DMAFaceOctaCell.prototype.calcHighlighterPosition = function(face){ /////////////////////////////////////////////////////////////////////////////////////////////// -function DMAEdgeOctaCell(indices, scale, cellMode, partType){ - DMAFaceOctaCell.call(this, indices, scale, cellMode, partType); +function DMAEdgeOctaCell(indices, cellMode, partType){ + DMAFaceOctaCell.call(this, indices, cellMode, partType); } DMAEdgeOctaCell.prototype = Object.create(DMAFaceOctaCell.prototype); @@ -85,8 +83,8 @@ DMAEdgeOctaCell.prototype.calcHighlighterPosition = function(face){ var unitVertexOcta = new THREE.OctahedronGeometry(1/Math.sqrt(2)); -function DMARotatedEdgeCell(indices, scale, cellMode, partType){ - DMACell.call(this, indices, scale, cellMode, partType); +function DMARotatedEdgeCell(indices, cellMode, partType){ + DMACell.call(this, indices, cellMode, partType); } DMARotatedEdgeCell.prototype = Object.create(DMACell.prototype); @@ -170,18 +168,16 @@ DMARotatedEdgeCell.prototype.calcHighlighterPosition = function(face, point){ return {index: _.clone(this.indices), direction:direction, position:position}; }; -DMARotatedEdgeCell.prototype.xScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale; +DMARotatedEdgeCell.prototype.xScale = function(){ + return 1; }; -DMARotatedEdgeCell.prototype.yScale = function(scale){ - return this.xScale(scale); +DMARotatedEdgeCell.prototype.yScale = function(){ + return this.xScale(); }; -DMARotatedEdgeCell.prototype.zScale = function(scale){ - if (!scale) scale = this.getScale(); - return Math.sqrt(2)/2*scale; +DMARotatedEdgeCell.prototype.zScale = function(){ + return Math.sqrt(2)/2; }; DMARotatedEdgeCell.prototype._getGeometry = function(){ @@ -194,8 +190,8 @@ DMARotatedEdgeCell.prototype._getGeometry = function(){ /////////////////////////////////////////////////////////////////////////////////////////////// -function DMAVertexOctaCell(indices, scale, cellMode, partType){ - DMACell.call(this, indices, scale, cellMode, partType); +function DMAVertexOctaCell(indices, cellMode, partType){ + DMACell.call(this, indices, cellMode, partType); } DMAVertexOctaCell.prototype = Object.create(DMACell.prototype); @@ -241,16 +237,14 @@ DMAVertexOctaCell.prototype._getGeometry = function(){ return unitVertexOcta; }; -DMAVertexOctaCell.prototype.xScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale*Math.sqrt(2); +DMAVertexOctaCell.prototype.xScale = function(){ + return Math.sqrt(2); }; -DMAVertexOctaCell.prototype.yScale = function(scale){ - return this.xScale(scale); +DMAVertexOctaCell.prototype.yScale = function(){ + return this.xScale(); }; -DMAVertexOctaCell.prototype.zScale = function(scale){ - if (!scale) scale = this.getScale(); - return this.xScale(scale); +DMAVertexOctaCell.prototype.zScale = function(){ + return this.xScale(); }; \ No newline at end of file diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index c1ca3682..27b19da8 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -15,8 +15,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; var unitCellGeo = new THREE.BoxGeometry(1,1,1); - function DMACubeCell(indices, scale, cellMode, partType){ - DMACell.call(this, indices, scale, cellMode, partType); + function DMACubeCell(indices, cellMode, partType){ + DMACell.call(this, indices, cellMode, partType); } DMACubeCell.prototype = Object.create(DMACell.prototype); @@ -43,17 +43,16 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return unitCellGeo; }; - DMACubeCell.prototype.xScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale; + DMACubeCell.prototype.xScale = function(){ + return 1; }; - DMACubeCell.prototype.yScale = function(scale){ - return this.xScale(scale); + DMACubeCell.prototype.yScale = function(){ + return this.xScale(); }; - DMACubeCell.prototype.zScale = function(scale){ - return this.xScale(scale); + DMACubeCell.prototype.zScale = function(){ + return this.xScale(); }; self.DMACubeCell = DMACubeCell; @@ -64,8 +63,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; var unitCellGeo = new THREE.BoxGeometry(1,1,1); - function DMAGIKCell(indices, scale, cellMode, partType){ - DMACubeCell.call(this, indices, scale, cellMode, partType); + function DMAGIKCell(indices, cellMode, partType){ + DMACubeCell.call(this, indices, cellMode, partType); } DMAGIKCell.prototype = Object.create(DMACubeCell.prototype); @@ -166,8 +165,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; ]; unitCellGeo.computeFaceNormals(); - function DMATruncCubeCell(indices, scale, cellMode, partType){ - DMACell.call(this, indices, scale, cellMode, partType); + function DMATruncCubeCell(indices, cellMode, partType){ + DMACell.call(this, indices, cellMode, partType); } DMATruncCubeCell.prototype = Object.create(DMACell.prototype); @@ -194,17 +193,16 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return unitCellGeo; }; - DMATruncCubeCell.prototype.xScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale*Math.sqrt(2); + DMATruncCubeCell.prototype.xScale = function(){ + return Math.sqrt(2); }; - DMATruncCubeCell.prototype.yScale = function(scale){ - return this.xScale(scale); + DMATruncCubeCell.prototype.yScale = function(){ + return this.xScale(); }; - DMATruncCubeCell.prototype.zScale = function(scale){ - return this.xScale(scale); + DMATruncCubeCell.prototype.zScale = function(){ + return this.xScale(); }; self.DMATruncCubeCell = DMATruncCubeCell; @@ -309,8 +307,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; ]; unitCellGeo.computeFaceNormals(); - function DMATruncOctaCell(indices, scale, cellMode, partType){ - DMATruncCubeCell.call(this, indices, scale, cellMode, partType); + function DMATruncOctaCell(indices, cellMode, partType){ + DMATruncCubeCell.call(this, indices, cellMode, partType); } DMATruncOctaCell.prototype = Object.create(DMATruncCubeCell.prototype); @@ -324,9 +322,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return unitCellGeo; }; - DMATruncOctaCell.prototype.xScale = function(scale){ - if (!scale) scale = this.getScale(); - return scale*2*Math.sqrt(2); + DMATruncOctaCell.prototype.xScale = function(){ + return 2*Math.sqrt(2); }; self.DMATruncOctaCell = DMATruncOctaCell; diff --git a/js/models/Lattice.js b/js/models/Lattice.js index ae85ba65..ce643731 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -34,7 +34,6 @@ Lattice = Backbone.Model.extend({ _.extend(this, OctaLatticeSubclasses, OtherLatticeSubclasses); //bind events - this.listenTo(this, "change:scale", this._scaleDidChange); this.listenTo(this, "change:gikLength", this._gikLengthDidChange); this.listenTo(globals.appState, "change:superCellIndex", this._gikLengthDidChange); this.listenTo(globals.appState, "change:cellMode", this._updateForMode); @@ -53,7 +52,6 @@ Lattice = Backbone.Model.extend({ //////////////////////////////////////////////////////////////////////////////////// addCellsInRange: function(range){//add a block of cells (extrude) - var scale = this.get("scale"); var cells = this.get("cells"); var newCells = []; this.checkForMatrixExpansion(cells, range.max, range.min); @@ -66,7 +64,7 @@ Lattice = Backbone.Model.extend({ for (var y=relativeMin.y;y<=relativeMax.y;y++){ for (var z=relativeMin.z;z<=relativeMax.z;z++){ if (!cells[x][y][z]) { - var cell = this.makeCellForLatticeType(this._add({x:x, y:y, z:z}, cellsMin), scale); + var cell = this.makeCellForLatticeType(this._add({x:x, y:y, z:z}, cellsMin)); cells[x][y][z] = cell; newCells.push(cell); this.set("numCells", this.get("numCells")+1); @@ -80,13 +78,12 @@ Lattice = Backbone.Model.extend({ addCellAtIndex: function(indices, noRender, noCheck){ - var scale = this.get("scale"); var cells = this.get("cells"); if (!noCheck) this.checkForMatrixExpansion(cells, indices, indices); var index = this._subtract(indices, this.get("cellsMin")); if (!cells[index.x][index.y][index.z]) { - cells[index.x][index.y][index.z] = this.makeCellForLatticeType(indices, scale); + cells[index.x][index.y][index.z] = this.makeCellForLatticeType(indices); this.set("numCells", this.get("numCells")+1); if (!noRender) globals.three.render(); } else console.warn("already a cell there"); @@ -95,19 +92,17 @@ Lattice = Backbone.Model.extend({ _indexForPosition: function(absPosition){ var position = {}; - var scale = this.get("scale"); - position.x = Math.floor(absPosition.x/this.xScale(scale)); - position.y = Math.floor(absPosition.y/this.yScale(scale)); - position.z = Math.floor(absPosition.z/this.zScale(scale)); + position.x = Math.floor(absPosition.x/this.xScale()); + position.y = Math.floor(absPosition.y/this.yScale()); + position.z = Math.floor(absPosition.z/this.zScale()); return position; }, _positionForIndex: function(index){ - var scale = this.get("scale"); var position = _.clone(index); - position.x = (position.x+0.5)*this.xScale(scale); - position.y = (position.y+0.5)*this.yScale(scale); - position.z = (position.z+0.5)*this.zScale(scale); + position.x = (position.x+0.5)*this.xScale(); + position.y = (position.y+0.5)*this.yScale(); + position.z = (position.z+0.5)*this.zScale(); return position; }, @@ -159,10 +154,9 @@ Lattice = Backbone.Model.extend({ }, _allAxesScales: function(){ - var scale = this.get("scale"); - var xScale = this.xScale(scale); - var yScale = this.yScale(scale); - var zScale = this.zScale(scale); + var xScale = this.xScale(); + var yScale = this.yScale(); + var zScale = this.zScale(); return {x:xScale, y:yScale, z:zScale}; }, @@ -173,10 +167,9 @@ Lattice = Backbone.Model.extend({ subtractMesh: function(mesh){ //todo this is specific to octa face - var scale = this.get("scale"); - var xScale = this.xScale(scale); - var yScale = this.yScale(scale); - var zScale = this.zScale(scale); + var xScale = this.xScale(); + var yScale = this.yScale(); + var zScale = this.zScale(); var cells = this.get("cells"); var cellsMin = this.get("cellsMin"); @@ -340,9 +333,8 @@ Lattice = Backbone.Model.extend({ _updateForMode: function(){ var cellMode = globals.appState.get("cellMode"); var partType = this.get("partType"); - var scale = this.get("scale"); this._iterCells(this.get("cells"), function(cell){ - if (cell) cell.draw(scale, cellMode, partType); + if (cell) cell.draw(cellMode, partType); }); globals.three.render(); }, @@ -351,35 +343,16 @@ Lattice = Backbone.Model.extend({ var cellSep = this.get("cellSeparation"); globals.basePlane.updateXYSeparation(cellSep.xy); - var scale = this.get("scale"); var cellMode = globals.appState.get("cellMode"); var partType = this.get("partType"); this._iterCells(this.get("cells"), function(cell){ - if (cell) cell.updateForScale(scale, cellMode, partType); + if (cell) cell.updateForScale(cellMode, partType); }); globals.three.render(); }, - _scaleDidChange: function(){ - var scale = this.get("scale"); - globals.basePlane.updateScale(scale); - globals.highlighter.updateScale(scale); - - var cellMode = globals.appState.get("cellMode"); - var partType = this.get("partType"); - this._iterCells(this.get("cells"), function(cell){ - if (cell && cell.updateForScale) cell.updateForScale(scale, cellMode, partType); - }); - - globals.three.render(); - }, - _gikLengthDidChange: function(){ - if (globals.highlighter.updateGikLength) globals.highlighter.updateGikLength(this.get("scale")); - }, - - previewScaleChange: function(scale){ - globals.basePlane.updateScale(scale); + if (globals.highlighter.updateGikLength) globals.highlighter.updateGikLength(); }, _setCellVisibility: function(){//todo maybe leave wireframes? @@ -465,7 +438,6 @@ Lattice = Backbone.Model.extend({ //todo refactor this eventually var self = this; - var scale = this.get("scale"); var cells = this.get("cells"); this._loopCells(cells, function(cell, x, y, z){ if (!cell) return; @@ -480,7 +452,7 @@ Lattice = Backbone.Model.extend({ if (cell.type) var type = cell.type; if (cell.destroy) cell.destroy(); - var newCell = self.makeCellForLatticeType(index, scale, parentPos, parentOrientation, direction, parentType, type); + var newCell = self.makeCellForLatticeType(index, parentPos, parentOrientation, direction, parentType, type); //if (parts) { // //todo make this better diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js index 9e50fca2..411f473b 100644 --- a/js/models/LatticeOcta.js +++ b/js/models/LatticeOcta.js @@ -17,42 +17,36 @@ OctaLatticeSubclasses = { }, getIndexForPosition: function(absPosition){ - var scale = this.get("scale"); - var yIndex = Math.floor(absPosition.y/this.yScale(scale)); - if (yIndex%2 != 0) absPosition.x += this.xScale(scale)/2; + 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 scale = this.get("scale"); var position = _.clone(index); - var xScale = this.xScale(scale); - position.x = (position.x+1/2)*xScale; - position.y = position.y*this.yScale(scale)+scale/Math.sqrt(3)/2; - position.z = (position.z+0.5)*this.zScale(scale); - if ((index.y%2) != 0) position.x -= this.xScale(scale)/2; + 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(scale){ - if (!scale) scale = this.get("scale"); - return scale*(1+2*this.get("cellSeparation").xy); + xScale: function(){ + return 1+2*this.get("cellSeparation").xy; }, - yScale: function(scale){ - return this.xScale(scale)/2*Math.sqrt(3); + yScale: function(){ + return this.xScale()/2*Math.sqrt(3); }, - zScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(2/Math.sqrt(6)+2*this.get("cellSeparation").z); + zScale: function(){ + return 2/Math.sqrt(6)+2*this.get("cellSeparation").z; }, - makeCellForLatticeType: function(indices, scale){ - return new DMAFaceOctaCell(indices, scale); + makeCellForLatticeType: function(indices){ + return new DMAFaceOctaCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later @@ -81,55 +75,50 @@ OctaLatticeSubclasses = { }, addFreeFormCell: function(parentCellPos, parentCellOrient, direction, parentType, type){ - var scale = this.get("scale"); var cells = this.get("cells"); - cells[0][0].push(this.makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, scale, parentCellPos, parentCellOrient, direction, parentType, type)); + 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, scale, parentPosition, parentOrientation, direction, parentType, type){ + makeCellForLatticeType: function(index, parentPosition, parentOrientation, direction, parentType, type){ if (type){ - if (type == "octa") return new DMAFreeFormOctaCell(index, scale, parentPosition, parentOrientation, direction, parentType); - return new DMAFreeFormTetraCell(index, scale, parentPosition, parentOrientation, direction, parentType); + 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, scale, parentPosition, parentOrientation, direction, parentType); - return new DMAFreeFormTetraCell(index, scale, 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 scale = this.get("scale"); - var yIndex = Math.floor(absPosition.y/this.yScale(scale)); - if (yIndex%2 != 0) absPosition.x += this.xScale(scale)/2; + 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 scale = this.get("scale"); var position = _.clone(index); - var xScale = this.xScale(scale); + var xScale = this.xScale(); position.x = (position.x+1/2)*xScale; - position.y = position.y*this.yScale(scale)+scale/Math.sqrt(3)/2; - position.z = (position.z+0.5)*this.zScale(scale); - if ((index.y%2) != 0) position.x -= this.xScale(scale)/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 -= xScale/2; return position; }, - xScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(1+2*this.get("cellSeparation").xy); + xScale: function(){ + return 1+2*this.get("cellSeparation").xy; }, - yScale: function(scale){ - return this.xScale(scale)/2*Math.sqrt(3); + yScale: function(){ + return this.xScale()/2*Math.sqrt(3); }, - zScale: function(scale){ - if (!scale) scale = this.get("scale"); - if (this.get("freeformCellType") == "octa") return scale*(2/Math.sqrt(6)+2*this.get("cellSeparation").xy); - return scale*(2/Math.sqrt(24)+2*this.get("cellSeparation").xy); + 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 @@ -158,13 +147,12 @@ OctaLatticeSubclasses = { getIndexForPosition: function(absPosition){ //todo finish this - var scale = this.get("scale"); - var yIndex = Math.floor(absPosition.y/this.yScale(scale)); - if (yIndex%2 != 0) absPosition.x += this.xScale(scale)/2; - var yScale = scale/Math.sqrt(3); + 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(scale)/2; + absPosition.x -= this.xScale()/2; absPosition.y += yScale/2; } else if (index.z%3 == 2){ absPosition.y += yScale; @@ -175,16 +163,15 @@ OctaLatticeSubclasses = { getPositionForIndex: function(index){ - var scale = this.get("scale"); var position = _.clone(index); - var xScale = this.xScale(scale); - var yScale = scale/Math.sqrt(3); + var xScale = this.xScale(); + var yScale = 1/Math.sqrt(3); position.x = (position.x+1/2)*xScale; - position.y = position.y*this.yScale(scale)+yScale/2; - position.z = (position.z+0.5)*this.zScale(scale); - if (index.y%2 != 0) position.x -= this.xScale(scale)/2; + 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(scale)/2; + position.x += this.xScale()/2; position.y -= yScale/2; } else if (index.z%3 == 2){ position.y -= yScale; @@ -192,8 +179,8 @@ OctaLatticeSubclasses = { return position; }, - makeCellForLatticeType: function(indices, scale){ - return new DMAEdgeOctaCell(indices, scale); + makeCellForLatticeType: function(indices){ + return new DMAEdgeOctaCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later @@ -216,44 +203,38 @@ OctaLatticeSubclasses = { getIndexForPosition: function(absPosition){ var position = {}; - var scale = this.get("scale"); - position.x = Math.floor(absPosition.x/this.xScale(scale)+0.5); - position.y = Math.floor(absPosition.y/this.yScale(scale)+0.5); - position.z = Math.floor(absPosition.z/this.zScale(scale)+0.5); + 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 scale = this.get("scale"); var position = _.clone(index); if (index.z %2 != 0){ position.x += 0.5; position.y += 0.5; } - position.x = (position.x)*this.xScale(scale); - position.y = (position.y)*this.yScale(scale); - position.z = (position.z+1)*this.zScale(scale); + position.x = (position.x)*this.xScale(); + position.y = (position.y)*this.yScale(); + position.z = (position.z+1)*this.zScale(); return position; }, - xScale: function(scale){ - if (!scale) scale = this.get("scale"); - scale *= 1 + 2*this.get("cellSeparation").xy; - return scale; + xScale: function(){ + return 1 + 2*this.get("cellSeparation").xy; }, - yScale: function(scale){ - return this.xScale(scale); + yScale: function(){ + return this.xScale(); }, - zScale: function(scale){ - if (!scale) scale = this.get("scale"); - scale *= Math.sqrt(2)/2 + 2*this.get("cellSeparation").z; - return scale; + zScale: function(){ + return Math.sqrt(2)/2 + 2*this.get("cellSeparation").z; }, - makeCellForLatticeType: function(indices, scale){ - return new DMARotatedEdgeCell(indices, scale); + makeCellForLatticeType: function(indices){ + return new DMARotatedEdgeCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later @@ -279,38 +260,34 @@ OctaLatticeSubclasses = { getIndexForPosition: function(absPosition){ var position = {}; - var scale = this.get("scale"); - position.x = Math.floor(absPosition.x/this.xScale(scale)+0.5); - position.y = Math.floor(absPosition.y/this.yScale(scale)+0.5); - position.z = Math.floor(absPosition.z/this.zScale(scale)+0.5); + 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 scale = this.get("scale"); var position = _.clone(index); - position.x = (position.x)*this.xScale(scale); - position.y = (position.y)*this.yScale(scale); - position.z = (position.z+0.5)*this.zScale(scale); + position.x = (position.x)*this.xScale(); + position.y = (position.y)*this.yScale(); + position.z = (position.z+0.5)*this.zScale(); return position; }, - xScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(Math.sqrt(2)+this.get("cellSeparation").xy); + xScale: function(){ + return Math.sqrt(2)+this.get("cellSeparation").xy; }, - yScale: function(scale){ - return this.xScale(scale); + yScale: function(){ + return this.xScale(); }, - zScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(Math.sqrt(2)+this.get("cellSeparation").z); + zScale: function(){ + return Math.sqrt(2)+this.get("cellSeparation").z; }, - makeCellForLatticeType: function(indices, scale){ - return new DMAVertexOctaCell(indices, scale); + makeCellForLatticeType: function(indices){ + return new DMAVertexOctaCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index 2ddd5851..c167f4f5 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -24,22 +24,20 @@ OtherLatticeSubclasses = { return this._positionForIndex(index); }, - xScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(1+2*this.get("cellSeparation").xy); + xScale: function(){ + return 1+2*this.get("cellSeparation").xy; }, - yScale: function(scale){ - return this.xScale(scale); + yScale: function(){ + return this.xScale(); }, - zScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(1+2*this.get("cellSeparation").z); + zScale: function(){ + return 1+2*this.get("cellSeparation").z; }, - makeCellForLatticeType: function(indices, scale){ - return new DMACubeCell(indices, scale); + makeCellForLatticeType: function(indices){ + return new DMACubeCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later @@ -69,22 +67,20 @@ OtherLatticeSubclasses = { return this._positionForIndex(index); }, - xScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(1+2*this.get("cellSeparation").xy); + xScale: function(){ + return 1+2*this.get("cellSeparation").xy; }, - yScale: function(scale){ - return this.xScale(scale); + yScale: function(){ + return this.xScale(); }, - zScale: function(scale){ - if (!scale) scale = this.get("scale"); - return 1.28*scale*(1+2*this.get("cellSeparation").z); + zScale: function(){ + return 1.28*(1+2*this.get("cellSeparation").z); }, - makeCellForLatticeType: function(indices, scale){ - return new DMAGIKCell(indices, scale); + makeCellForLatticeType: function(indices){ + return new DMAGIKCell(indices); }, makeSuperCell: function(range){ @@ -93,9 +89,8 @@ OtherLatticeSubclasses = { if (range) cells = this.addCellsInRange(range); else { cells = []; - var scale = this.get("scale"); for (var i=0;i<length;i++){ - cells.push(this.makeCellForLatticeType(null, scale)); + cells.push(this.makeCellForLatticeType(null)); } } if (cells.length < 1) return null; @@ -172,22 +167,20 @@ OtherLatticeSubclasses = { return this._positionForIndex(index); }, - xScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(Math.sqrt(2)+2*this.get("cellSeparation").xy); + xScale: function(){ + return Math.sqrt(2)+2*this.get("cellSeparation").xy; }, - yScale: function(scale){ - return this.xScale(scale); + yScale: function(){ + return this.xScale(); }, - zScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(Math.sqrt(2)+2*this.get("cellSeparation").z); + zScale: function(){ + return Math.sqrt(2)+2*this.get("cellSeparation").z; }, - makeCellForLatticeType: function(indices, scale){ - return new DMATruncCubeCell(indices, scale); + makeCellForLatticeType: function(indices){ + return new DMATruncCubeCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later @@ -219,22 +212,20 @@ OtherLatticeSubclasses = { return this._positionForIndex(index); }, - xScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(2*Math.sqrt(2)+2*this.get("cellSeparation").xy); + xScale: function(){ + return 2*Math.sqrt(2)+2*this.get("cellSeparation").xy; }, - yScale: function(scale){ - return this.xScale(scale); + yScale: function(){ + return this.xScale(); }, - zScale: function(scale){ - if (!scale) scale = this.get("scale"); - return scale*(2*Math.sqrt(2)+2*this.get("cellSeparation").z); + zScale: function(){ + return 2*Math.sqrt(2)+2*this.get("cellSeparation").z; }, - makeCellForLatticeType: function(indices, scale){ - return new DMATruncOctaCell(indices, scale); + makeCellForLatticeType: function(indices){ + return new DMATruncOctaCell(indices); }, _undo: function(){//remove all the mixins, this will help with debugging later -- GitLab