diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 67eaf8ec452a35317a7a7c09c3affaa15a0bec05..cf43bad9c024735895f418379284959c1656d04c 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -218,9 +218,9 @@ function DMAFreeFormCell(indices, scale, parentCellPos, parentCellQuat, directio } DMAFreeFormCell.prototype = Object.create(DMACell.prototype); -DMAFreeFormCell.prototype._calcPosition = function(){ +DMAFreeFormCell.prototype._calcPosition = function(){//todo this might not be necessary - put in lattice var position = {}; - var zScale = this.zScale(); + var zScale = dmaGlobals.lattice.zScale(); position.x = this.parentPos.x+this.parentDirection.x*zScale/2; position.y = this.parentPos.y+this.parentDirection.y*zScale/2; position.z = this.parentPos.z+this.parentDirection.z*zScale/2; diff --git a/js/fea/DmaCellOcta.js b/js/fea/DmaCellOcta.js index 9424aed0aedf9b3a9cc0d105eb763b2f2523c147..ca5c14bc49dcfa96549907e0b7ffdc4253387202 100644 --- a/js/fea/DmaCellOcta.js +++ b/js/fea/DmaCellOcta.js @@ -33,6 +33,20 @@ DMAFaceOctaCell.prototype._getGeometry = function(){ return unitFaceOctaGeo; }; +DMAFaceOctaCell.prototype.xScale = function(scale){ + if (!scale) scale = this.getScale(); + return scale; +}; + +DMAFaceOctaCell.prototype.yScale = function(scale){ + return this.xScale(scale)/2*Math.sqrt(3); +}; + +DMAFaceOctaCell.prototype.zScale = function(scale){ + if (!scale) scale = this.getScale(); + return scale*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; @@ -86,12 +100,22 @@ DMAFreeFormOctaCell.prototype._getGeometry = function(){ return unitFaceOctaGeo; }; +DMAFreeFormOctaCell.prototype.xScale = function(scale){ + if (!scale) scale = this.getScale(); + return scale; +}; + +DMAFreeFormOctaCell.prototype.yScale = function(scale){ + return this.xScale(scale)/2*Math.sqrt(3); +}; + DMAFreeFormOctaCell.prototype.zScale = function(scale){ - if (!scale) scale = dmaGlobals.lattice.get("scale"); - return 2*scale/Math.sqrt(6); + if (!scale) scale = this.getScale(); + return scale*2/Math.sqrt(6); }; + /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////EDGE CONNECTED///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// @@ -188,7 +212,7 @@ DMARotatedEdgeCell.prototype.calcHighlighterPosition = function(face, point){ }; DMARotatedEdgeCell.prototype.xScale = function(scale){ - if (!scale) scale = dmaGlobals.lattice.get("scale"); + if (!scale) scale = this.getScale(); return scale; }; @@ -197,7 +221,7 @@ DMARotatedEdgeCell.prototype.yScale = function(scale){ }; DMARotatedEdgeCell.prototype.zScale = function(scale){ - if (!scale) scale = dmaGlobals.lattice.get("scale"); + if (!scale) scale = this.getScale(); return Math.sqrt(2)/2*scale; }; @@ -256,4 +280,18 @@ DMAVertexOctaCell.prototype.calcHighlighterPosition = function(face, point){ DMAVertexOctaCell.prototype._getGeometry = function(){ return unitVertexOcta; +}; + +DMAVertexOctaCell.prototype.xScale = function(scale){ + if (!scale) scale = this.getScale(); + return scale*Math.sqrt(2); +}; + +DMAVertexOctaCell.prototype.yScale = function(scale){ + return this.xScale(scale); +}; + +DMAVertexOctaCell.prototype.zScale = function(scale){ + if (!scale) scale = this.getScale(); + return this.xScale(scale); }; \ No newline at end of file diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index 5e485ddb2775f24ef4bd281b1609308fdb846ab0..8241bbe2babd863e0a185b0513438292e7fec6c5 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -43,6 +43,19 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return unitCellGeo; }; + DMACubeCell.prototype.xScale = function(scale){ + if (!scale) scale = this.getScale(); + return scale; + }; + + DMACubeCell.prototype.yScale = function(scale){ + return this.xScale(scale); + }; + + DMACubeCell.prototype.zScale = function(scale){ + return this.xScale(scale); + }; + self.DMACubeCell = DMACubeCell; })(); @@ -126,6 +139,19 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return unitCellGeo; }; + DMATruncCubeCell.prototype.xScale = function(scale){ + if (!scale) scale = this.getScale(); + return scale*Math.sqrt(2); + }; + + DMATruncCubeCell.prototype.yScale = function(scale){ + return this.xScale(scale); + }; + + DMATruncCubeCell.prototype.zScale = function(scale){ + return this.xScale(scale); + }; + self.DMATruncCubeCell = DMATruncCubeCell; })(); @@ -243,6 +269,11 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return unitCellGeo; }; + DMATruncOctaCell.prototype.xScale = function(scale){ + if (!scale) scale = this.getScale(); + return scale*2*Math.sqrt(2); + }; + self.DMATruncOctaCell = DMATruncOctaCell; })(); diff --git a/js/fea/DmaCellTetra.js b/js/fea/DmaCellTetra.js index dc42d5e4f29aef6c9fe241ecb47c55da982a706b..9f8b87ce64d91e4f672ebc58a4735710099507c7 100644 --- a/js/fea/DmaCellTetra.js +++ b/js/fea/DmaCellTetra.js @@ -83,9 +83,18 @@ DMAFreeFormTetraCell.prototype.getType = function(){ return "tetra"; }; +DMAFreeFormTetraCell.prototype.xScale = function(scale){ + if (!scale) scale = this.getScale(); + return scale; +}; + +DMAFreeFormTetraCell.prototype.yScale = function(scale){ + return this.xScale(scale)/2*Math.sqrt(3); +}; + DMAFreeFormTetraCell.prototype.zScale = function(scale){ - if (!scale) scale = dmaGlobals.lattice.get("scale"); - return 2*scale/Math.sqrt(24); + if (!scale) scale = this.getScale(); + return scale*2/Math.sqrt(24); }; DMAFreeFormTetraCell.prototype._getGeometry = function(){ diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 0ec1ea487c2e0f37b18f314069a0a2e17848ae82..532d9b6862137b69cd4e3057acf5aeef5caa8e24 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -26,25 +26,10 @@ LatticeMenuView = Backbone.View.extend({ this.lattice = options.lattice; _.bindAll(this, "render"); - _.bindAll(this, "_onKeyup"); //bind events this.listenTo(this.lattice, "change", this.render); this.listenTo(this.model, "change:units", this.render); - $(document).bind('keyup', {state:false}, this._onKeyup); - }, - - _onKeyup: function(e){ - if ($(".cellSeparation").is(":focus")) this._updateNumber(e, "cellSeparation"); - }, - - _updateNumber: function(e, property){ - e.preventDefault(); - var newVal = parseFloat($(e.target).val()); - if (isNaN(newVal)) return; - var object = this.lattice.get(property); - object[$(e.target).data("type")] = newVal; - this.lattice.trigger("change:"+property); }, _clearCells: function(e){ @@ -175,8 +160,6 @@ LatticeMenuView = Backbone.View.extend({ <% }); %>\ </ul>\ </div><br/><br/>\ - Cell Separation (xy, z): <input data-type="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control numberInput cellSeparation" type="text">\ - <input data-type="z" value="<%= cellSeparation.z %>" placeholder="Z" class="form-control numberInput cellSeparation" type="text">\ Num Cells: <%= numCells %><br/>\ <br/>\ <a href="#" id="latticeMenuClearCells" class=" btn btn-block btn-lg btn-default">Clear All Cells</a><br/>\ diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index c9ad50493c5bdab9c7468041730f159b67a7a664..a0ddb6c8c5574bfaefbe238ff5839163fe43d34a 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -7,7 +7,6 @@ PartMenuView = Backbone.View.extend({ el: "#menuContent", events: { - "slide #columnSepSlider": "_changeColSeparation", "click .partType": "_changePartType" }, @@ -16,12 +15,24 @@ PartMenuView = Backbone.View.extend({ this.lattice = options.lattice; _.bindAll(this, "render"); + _.bindAll(this, "_onKeyup"); + //bind events this.listenTo(this.lattice, "change:partType", this.render); + $(document).bind('keyup', {state:false}, this._onKeyup); }, - _changeColSeparation: function(e){ - this.lattice.set("columnSeparation", $(e.target).val()/100); + _onKeyup: function(e){ + if ($(".cellSeparation").is(":focus")) this._updateNumber(e, "cellSeparation"); + }, + + _updateNumber: function(e, property){ + e.preventDefault(); + var newVal = parseFloat($(e.target).val()); + if (isNaN(newVal)) return; + var object = this.lattice.get(property); + object[$(e.target).data("type")] = newVal; + this.lattice.trigger("change:"+property); }, _changePartType: function(e){ @@ -32,12 +43,6 @@ PartMenuView = Backbone.View.extend({ render: function(){ if (this.model.get("currentTab") != "part") return; this.$el.html(this.template(_.extend(this.model.toJSON(), this.lattice.toJSON()))); - - $('#columnSepSlider').slider({ - formatter: function(value) { - return value + "%"; - } - }); }, template: _.template('\ @@ -50,8 +55,8 @@ 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="35" data-slider-step="0.1" data-slider-value="<%= columnSeparation*100 %>"/>\ - <br/><br/>\ + Cell Separation (xy, z): <input data-type="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control numberInput cellSeparation" type="text">\ + <input data-type="z" value="<%= cellSeparation.z %>" placeholder="Z" class="form-control numberInput cellSeparation" type="text">\ todo: generic beam part type, part types for new lattice configurations\ ') diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 05c94aeeafeed620f62980dcd055ffb5eb583025..50cf15998c9ee26fbed5e4c1e282fd11b235d1f6 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -19,7 +19,6 @@ Lattice = Backbone.Model.extend({ shouldPreserveCells: true,//preserve cells when changing lattice type //spacing for connectors/joints - columnSeparation: 0.0,//todo get rid of this cellSeparation: {xy:0.1, z:0}, cellMode: "cell",//show cells vs parts @@ -38,6 +37,7 @@ Lattice = Backbone.Model.extend({ this.listenTo(this, "change:scale", this._scaleDidChange); this.listenTo(this, "change:cellMode change:partType", this._updateForMode); this.listenTo(this, "change:cellType change:connectionType", this._updateLatticeType); + this.listenTo(this, "change:cellSeparation", this._updateCellSeparation); }, @@ -308,6 +308,17 @@ Lattice = Backbone.Model.extend({ dmaGlobals.three.render(); }, + _updateCellSeparation: function(){ + var cellSep = this.get("cellSeparation"); + var scale = this.get("scale"); + var cellMode = this.get("cellMode"); + //this.get("basePlane").updateColSeparation(cellSep.xy); + this._iterCells(this.get("cells"), function(cell){ + if (cell) cell.updateForScale(scale, cellMode); + }); + dmaGlobals.three.render(); + }, + _scaleDidChange: function(){ var scale = this.get("scale"); this.get("basePlane").updateScale(scale); diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js index 4cea50a54d2116114f6a3d36033331f0f65c370c..232f9084aff687d23e1b6cf1ca32415e31b08e91 100644 --- a/js/models/LatticeOcta.js +++ b/js/models/LatticeOcta.js @@ -12,26 +12,10 @@ OctaLatticeSubclasses = { OctaFaceLattice: { _initLatticeType: function(){ - - //bind events - this.set("columnSeparation", 0.0); - this.listenTo(this, "change:columnSeparation", this._changeColSeparation); - this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); this.set("highlighter", new OctaFaceHighlighter({scale:this.get("scale")})); }, - _changeColSeparation: function(){ - var colSep = this.get("columnSeparation"); - var scale = this.get("scale"); - var cellMode = this.get("cellMode"); - this.get("basePlane").updateColSeparation(colSep); - this._iterCells(this.get("cells"), function(cell){ - if (cell) cell.updateForScale(scale, cellMode); - }); - dmaGlobals.three.render(); - }, - getIndexForPosition: function(absPosition){ var scale = this.get("scale"); var yIndex = Math.floor(absPosition.y/this.yScale(scale)); @@ -55,8 +39,7 @@ OctaLatticeSubclasses = { xScale: function(scale){ if (!scale) scale = this.get("scale"); - var colSep = this.get("columnSeparation"); - return scale*(1+2*colSep); + return scale*(1+2*this.get("cellSeparation").xy); }, yScale: function(scale){ @@ -65,7 +48,7 @@ OctaLatticeSubclasses = { zScale: function(scale){ if (!scale) scale = this.get("scale"); - return 2*scale/Math.sqrt(6); + return scale*(2/Math.sqrt(6)+2*this.get("cellSeparation").z); }, makeCellForLatticeType: function(indices, scale){ @@ -73,7 +56,6 @@ OctaLatticeSubclasses = { }, _undo: function(){//remove all the mixins, this will help with debugging later - this.stopListening(this, "change:columnSeparation"); var self = this; _.each(_.keys(this.OctaFaceLattice), function(key){ self[key] = null; @@ -140,18 +122,17 @@ OctaLatticeSubclasses = { xScale: function(scale){ if (!scale) scale = this.get("scale"); - var colSep = this.get("columnSeparation"); - return scale*(1+2*colSep); + return scale*(1+2*this.get("cellSeparation").xy); }, yScale: function(scale){ return this.xScale(scale)/2*Math.sqrt(3); }, - zScale: function(scale){//base plane calls this, need it + zScale: function(scale){ if (!scale) scale = this.get("scale"); - if (this.get("freeformCellType") == "octa") return 2*scale/Math.sqrt(6); - return 2*scale/Math.sqrt(24); + 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); }, _undo: function(){//remove all the mixins, this will help with debugging later @@ -175,8 +156,6 @@ OctaLatticeSubclasses = { _initLatticeType: function(){ //bind events - this.set("columnSeparation", 0.0); -// this.listenTo(this, "change:columnSeparation", this._changeColSeparation); this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); this.set("highlighter", new OctaEdgeHighlighter({scale:this.get("scale")})); @@ -330,7 +309,7 @@ OctaLatticeSubclasses = { xScale: function(scale){ if (!scale) scale = this.get("scale"); - return scale*Math.sqrt(2); + return scale*(Math.sqrt(2)+this.get("cellSeparation").xy); }, yScale: function(scale){ @@ -338,7 +317,8 @@ OctaLatticeSubclasses = { }, zScale: function(scale){ - return this.xScale(scale); + if (!scale) scale = this.get("scale"); + return scale*(Math.sqrt(2)+this.get("cellSeparation").z); }, makeCellForLatticeType: function(indices, scale){ diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index ca0f11c85f8c77798fa83458bd48c15d6a8cbedf..cf3e6b3ea2b29aab32ef85fdff6f011996980ffe 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -29,7 +29,7 @@ OtherLatticeSubclasses = { xScale: function(scale){ if (!scale) scale = this.get("scale"); - return scale; + return scale*(1+2*this.get("cellSeparation").xy); }, yScale: function(scale){ @@ -37,7 +37,8 @@ OtherLatticeSubclasses = { }, zScale: function(scale){ - return this.xScale(scale); + if (!scale) scale = this.get("scale"); + return scale*(1+2*this.get("cellSeparation").z); }, makeCellForLatticeType: function(indices, scale){ @@ -76,7 +77,7 @@ OtherLatticeSubclasses = { xScale: function(scale){ if (!scale) scale = this.get("scale"); - return scale*Math.sqrt(2); + return scale*(Math.sqrt(2)+2*this.get("cellSeparation").xy); }, yScale: function(scale){ @@ -84,7 +85,8 @@ OtherLatticeSubclasses = { }, zScale: function(scale){ - return this.xScale(scale); + if (!scale) scale = this.get("scale"); + return scale*(Math.sqrt(2)+2*this.get("cellSeparation").z); }, makeCellForLatticeType: function(indices, scale){ @@ -125,7 +127,7 @@ OtherLatticeSubclasses = { xScale: function(scale){ if (!scale) scale = this.get("scale"); - return scale*2*Math.sqrt(2); + return scale*(2*Math.sqrt(2)+2*this.get("cellSeparation").xy); }, yScale: function(scale){ @@ -133,7 +135,8 @@ OtherLatticeSubclasses = { }, zScale: function(scale){ - return this.xScale(scale); + if (!scale) scale = this.get("scale"); + return scale*(2*Math.sqrt(2)+2*this.get("cellSeparation").z); }, makeCellForLatticeType: function(indices, scale){