From 44b1d07c4293e2e775b3e7c408bc8c116313b980 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 4 Feb 2015 16:15:57 -0500 Subject: [PATCH] adding in col sep controls --- js/fea/DmaCell.js | 9 +++++++-- js/menus/PartMenuView.js | 4 ++-- js/models/BasePlane.js | 7 ++++--- js/models/Lattice.js | 13 ++++++++----- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index f0af65e2..bdfaae56 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -55,7 +55,8 @@ DMACell.prototype._setCellMeshVisibility = function(visibility){ this.cellMesh.visible = visibility; }; -DMACell.prototype.updateForScale = function(scale){ +DMACell.prototype.updateForScale = function(){ + var scale = this.getScale(); this.cellMesh.scale.set(scale, scale, scale); var position = this._calcPosition(scale, this.indices); this._setMeshPosition(this.cellMesh, position); @@ -114,7 +115,7 @@ DMACell.prototype.destroy = function(){ function DMASideOctaCell(mode, indices, scale, lattice){ - DMACell.call(this, mode, indices, scale, lattice); + DMACell.call(this, mode, indices, scale*(1-lattice.get("columnSeparation")), lattice); } DMASideOctaCell.prototype = Object.create(DMACell.prototype); @@ -130,6 +131,10 @@ DMACell.prototype.destroy = function(){ return position; }; + DMACell.prototype.getScale = function(){ + return this.lattice.get("scale")*(1-this.lattice.get("columnSeparation")); + }; + DMASideOctaCell.prototype._initParts = function(zIndex){ var parts = []; for (var i=0;i<3;i++){ diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index 0cd12c3e..ac6a8c8a 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -20,7 +20,7 @@ PartMenuView = Backbone.View.extend({ }, _changeColSeparation: function(e){ - this.model.set("columnSeparation", $(e.target).val()); + this.model.set("columnSeparation", $(e.target).val()/100); }, render: function(){ @@ -44,7 +44,7 @@ PartMenuView = Backbone.View.extend({ <% }); %>\ </ul>\ </div><br/><br/>\ - Column Separation: <input id="columnSepSlider" data-slider-id="ex1Slider" type="text" data-slider-min="0" data-slider-max="50" data-slider-step="0.1" data-slider-value="<%= scale %>"/>\ + Column Separation: <input id="columnSepSlider" data-slider-id="ex1Slider" type="text" data-slider-min="0" data-slider-max="35" data-slider-step="0.1" data-slider-value="<%= columnSeparation*100 %>"/>\ ') }); \ No newline at end of file diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index 4ec7eb79..ec0ba7c5 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -30,7 +30,7 @@ BasePlane = Backbone.Model.extend({ updateColSeparation: function(colSep){ var geometry = this.get("mesh").geometry; - geometry.vertices = this._calcOctaFaceVertices(); + geometry.vertices = this._calcOctaFaceVertices(colSep); geometry.verticesNeedUpdate = true; }, @@ -69,11 +69,12 @@ BasePlane = Backbone.Model.extend({ } }, - _createOctaFaceMesh: function(){ + _createOctaFaceMesh: function(colSep){ + colSep = colSep || 0; var geometry = new THREE.Geometry(); geometry.dynamic = true; - geometry.vertices = this._calcOctaFaceVertices(0.2); + geometry.vertices = this._calcOctaFaceVertices(colSep); var faces = geometry.faces; var dimX = this.get("dimX"); diff --git a/js/models/Lattice.js b/js/models/Lattice.js index b2f7570a..b4b77df7 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -214,7 +214,7 @@ Lattice = Backbone.Model.extend({ var scale = this.get("scale"); this.get("basePlane").updateScale(scale); this._iterCells(this.get("cells"), function(cell){ - if (cell) cell.updateForScale(scale); + if (cell) cell.updateForScale(); }); window.three.render(); }, @@ -259,16 +259,19 @@ OctaFaceLattice = Lattice.extend({ _initialize: function(){ - this.set("columnSeparation", 0.2); - //bind events this.listenTo(this, "change:columnSeparation", this._changeColSeparation); + + this.set("columnSeparation", 0.2); }, _changeColSeparation: function(){ var colSep = this.get("columnSeparation"); - console.log(colSep); this.get("basePlane").updateColSeparation(colSep); + this._iterCells(this.get("cells"), function(cell){ + if (cell) cell.updateForScale(); + }); + window.three.render(); }, addCellAtPosition: function(absPosition){ @@ -287,7 +290,7 @@ OctaFaceLattice = Lattice.extend({ }, _makeCellForLatticeType: function(indices, scale){ - return new DMASideOctaCell(this.get("cellMode"), indices, scale, this); + return new DMASideOctaCell(this.get("cellMode"), indices, scale*(1.0-this.get("columnSeparation")), this); } }); -- GitLab