diff --git a/js/fea/DmaBeam.js b/js/fea/DmaBeam.js index 4eaecfbafb1cba10356cc48e47fae44df076b951..ebe433b1a297e4f7f6b66771a6ff1695daafb2d8 100644 --- a/js/fea/DmaBeam.js +++ b/js/fea/DmaBeam.js @@ -5,11 +5,12 @@ Created by aghassaei on 1/13/15. //a single beam, made from two nodes -var unitGeo = new THREE.CylinderGeometry(0.1, 0.1, 1, 6); +var unitGeo = new THREE.CylinderGeometry(0.05, 0.05, 1, 6); -function DmaBeam(node1, node2) { +function DmaBeam(node1, node2, parent) { this.nodes = [node1, node2]; + this.parentCell = parent; var self = this; _.each(this.nodes, function(node){//give each node a reference to the new beam it is connected to node.addBeam(self); @@ -30,12 +31,28 @@ DmaBeam.prototype._buildBeamMesh = function(){ var position = this.nodes[0].getPosition(); position.sub(this.nodes[1].getPosition()); position.multiplyScalar(0.5); - mesh.position.set(position); + mesh.position.set(position.x, position.y, position.z); + var scale = this.parentCell.getScale(); + mesh.scale.set(scale, scale, scale); + dmaGlobals.three.sceneAdd(mesh, "part"); return mesh; }; -DmaBeam.prototype.render = function(scene){ - if (!this.mesh) this.mesh = this._buildBeamMesh(); +DmaBeam.prototype.setVisibility = function(visible){ + if (visible && !this.mesh) this.mesh = this._buildBeamMesh(); + else if (!this.mesh) return; + this.mesh.visible = visible; +}; + +DmaBeam.prototype.destroy = function(){ + dmaGlobals.three.sceneRemove(this.mesh, "part"); + this.mesh = null; + var self = this; + _.each(this.nodes, function(node){ + node.removeBeam(self); + }); + this.nodes = null; + this.parentCell = null; }; DmaBeam.prototype.calcStiffnessMatrix = function(){ diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 35d1bd4bf30c39c92eb4685eadf5268e96acfced..dda72d77cedeed0d802896cf8d61ccf8e8e1847e 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -15,20 +15,24 @@ function DMACell(indices, scale, inverse) { if (!inverse) inverse = false; this.isInverse = inverse; this.cellMesh = this._buildCellMesh(); - this.nodes = this._initNodes(_.clone(this.cellMesh.children[0].geometry.vertices)); + this.nodes = this._initNodes(this.cellMesh.children[0].geometry.vertices); this.beams = this._initBeams(this.nodes, this.cellMesh.children[0].geometry.faces); var cellMode = dmaGlobals.lattice.get("cellMode"); var inverseMode = dmaGlobals.lattice.get("inverseMode"); - this.drawForMode(scale, cellMode, inverseMode); + var beamMode = dmaGlobals.lattice.get("partType") == "beam"; + this.drawForMode(scale, cellMode, inverseMode, beamMode); } -DMACell.prototype.drawForMode = function(scale, cellMode, inverseMode){ +DMACell.prototype.drawForMode = function(scale, cellMode, inverseMode, beamMode){ this.updateForScale(scale, cellMode); this._setCellMeshVisibility(cellMode == "cell" && inverseMode==this.isInverse);//only show if in the correct inverseMode - if (cellMode == "part" && !this.parts) this.parts = this._initParts(); + if (!beamMode && cellMode == "part" && !this.parts) this.parts = this._initParts(); _.each(this.parts, function(part){ - if (part) part.setVisibility(cellMode == "part"); + if (part) part.setVisibility(cellMode == "part" && !beamMode); + }); + _.each(this.beams, function(beam){ + beam.setVisibility(beamMode); }); }; @@ -107,10 +111,12 @@ 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]; + var vertex = vertices[i].clone(); vertex.applyQuaternion(orientation); vertex.add(position); + vertex.multiplyScalar(scale); nodes.push(new DmaNode(vertex, i)); } return nodes; @@ -187,6 +193,7 @@ DMACell.prototype.toJSON = function(){ DMAFaceOctaCell.prototype._initBeams = function(nodes, faces){ var beams = []; + var self = this; var addBeamFunc = function(index1, index2){ var duplicate = false; _.each(beams, function(beam){ @@ -195,7 +202,7 @@ DMACell.prototype.toJSON = function(){ }); if (duplicate) return; if (index2>index1) { - beams.push(new DmaBeam(nodes[index1], nodes[index2])); + beams.push(new DmaBeam(nodes[index1], nodes[index2], self)); } }; for (var i=0;i<nodes.length;i++){ diff --git a/js/fea/DmaNode.js b/js/fea/DmaNode.js index 69f0d3b8698679864eb280d46997223de05444f1..9f52be4b6aed8aa871d733a9232b22652778cca8 100644 --- a/js/fea/DmaNode.js +++ b/js/fea/DmaNode.js @@ -18,6 +18,10 @@ DmaNode.prototype.addBeam = function(beam){ this._beams.push(beam); }; +DmaNode.prototype.removeBeam = function(beam){ +// this._beams.push(beam); +}; + DmaNode.prototype.destroy = function(){ this._beams = null;//be sure to remove cyclic reference this.position = null; diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index 0f7c1339ddea95e8567867458178d5c444b01c6d..18f1b00982c2c0c55d79cfd65f3aca1431b5b5e2 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -7,7 +7,8 @@ PartMenuView = Backbone.View.extend({ el: "#menuContent", events: { - "slide #columnSepSlider": "_changeColSeparation" + "slide #columnSepSlider": "_changeColSeparation", + "click .partType": "_changePartType" }, initialize: function(options){ @@ -15,7 +16,7 @@ PartMenuView = Backbone.View.extend({ this.lattice = options.lattice; _.bindAll(this, "render"); - this.listenTo(this.model, "change:partType", this.render); + this.listenTo(this.lattice, "change:partType", this.render); }, @@ -23,9 +24,14 @@ PartMenuView = Backbone.View.extend({ this.lattice.set("columnSeparation", $(e.target).val()/100); }, + _changePartType: function(e){ + e.preventDefault(); + this.lattice.set("partType", $(e.target).data("type")); + }, + render: function(){ if (this.model.get("currentTab") != "part") return; - this.$el.html(this.template(this.model.attributes)); + this.$el.html(this.template(_.extend(this.model.attributes, this.lattice.attributes))); $('#columnSepSlider').slider({ formatter: function(value) { diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 8de2aa732544d80e9c8513eb821a8b5b4d3cf9b6..c3dd52ed0a7c524e80188cc5cfdd30dc1afa3632 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -41,7 +41,7 @@ Lattice = Backbone.Model.extend({ //bind events this.listenTo(this, "change:scale", this._scaleDidChange); - this.listenTo(this, "change:inverseMode change:cellMode", this._updateForMode); + this.listenTo(this, "change:inverseMode change:cellMode change:partType", this._updateForMode); this.listenTo(this, "change:cellType change:connectionType", this._updateLatticeType); }, @@ -334,12 +334,13 @@ Lattice = Backbone.Model.extend({ _updateForMode: function(){ var cellMode = this.get("cellMode"); var inverseMode = this.get("inverseMode"); + var beamMode = this.get("partType") == "beam"; var scale = this.get("scale"); this._iterCells(this.get("cells"), function(cell){ - if (cell) cell.drawForMode(scale, cellMode, inverseMode); + if (cell) cell.drawForMode(scale, cellMode, inverseMode, beamMode); }); this._iterCells(this.get("inverseCells"), function(cell){ - if (cell) cell.drawForMode(scale, cellMode, inverseMode); + if (cell) cell.drawForMode(scale, cellMode, inverseMode, beamMode); }); dmaGlobals.three.render(); },