From 3de56558400908e2dbcc2a07baccba9ea5f27ea1 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Mon, 9 Mar 2015 02:09:20 -0400 Subject: [PATCH] starting to add beam --- js/fea/DmaBeam.js | 72 ++++++++++++++++++++++--------------------- js/fea/DmaCell.js | 55 +++++++++++++++++++++++++++++++++ js/fea/DmaNode.js | 54 ++++++-------------------------- js/fea/DmaPart.js | 14 ++------- js/models/AppState.js | 10 +++--- main.html | 4 +-- 6 files changed, 111 insertions(+), 98 deletions(-) diff --git a/js/fea/DmaBeam.js b/js/fea/DmaBeam.js index 94d9fdd7..65f3a79f 100644 --- a/js/fea/DmaBeam.js +++ b/js/fea/DmaBeam.js @@ -1,57 +1,59 @@ -/Math.pow(, - * Created by aghassaei on 1/13/15. +/* +Created by aghassaei on 1/13/15. */ //a single beam, made from two nodes -function Beam(node1, node2) { + +function DmaBeam(node1, node2) { this.nodes = [node1, node2]; var self = this; - _.each(nodes, function(node){//give each node a reference to the new beam it is connected to + _.each(this.nodes, function(node){//give each node a reference to the new beam it is connected to node.addBeam(self); }); } -Beam.prototype.render = function(scene){ - +DmaBeam.prototype.getIndex = function(){ + var index = []; + _.each(this.nodes, function(node){ + index.push(node.getIndex()); + }); + return index; }; +DmaBeam.prototype._buildBeamMesh = function(){ -BeamNode.prototype.translate = function(dx, dy, dz){ }; -Beam.prototype.rotate = function(rx, ry, rz){ -}; - -Beam.prototype.setStiffness = function(scene){ +DmaBeam.prototype.render = function(scene){ }; -Beam.prototype.calcStiffnessMatrix = function(){ - - var L = 0; - var A = 0; - var Iy = 0; - var Iz = 0; - var E = 0; - var G = 0; - - var K = [ - [A*E/L , 0 , 0 , 0 , 0 , 0 , -A*E/L , 0 , 0 , 0 , 0 , 0] ,//d1x - [0 , 12*E*Iz/Math.pow(L, 3) , 0 , 0 , 0 , 6*E*Iz/Math.pow(L, 2) , 0 , -12*E*Iz/Math.pow(L, 3) , 0 , 0 , 0 , 6*E*Iz/Math.pow(L, 2)] ,//d1y - [0 , 0 , 12*E*Iy/Math.pow(L, 3) , 0 , -6*E*Iy/Math.pow(L, 2) , 0 , 0 , 0 , -12*E*Iy/Math.pow(L, 3) , 0 , -6*E*Iy/Math.pow(L, 2) , 0] ,//d1z - [0 , 0 , 0 , G*J/L , 0 , 0 , 0 , 0 , 0 , -G*J/L , 0 , 0] , //r1x - [0 , 0 , -6*E*Iy/Math.pow(L, 2) , 0 , 4*E*Iy/L , 0 , 0 , 0 , 6*E*Iy/Math.pow(L, 2) , 0 , 2*E*Iy/L , 0] ,//r1y - [0 , 6*E*Iz/Math.pow(L, 2) , 0 , 0 , 0 , 4*E*Iz/L , 0 , -6*E*Iz/Math.pow(L, 2) , 0 , 0 , 0 , 2*E*Iz/L] ,//r1z - [-A*E/L , 0 , 0 , 0 , 0 , 0 , A*E/L , 0 , 0 , 0 , 0 , 0] , //d2x - [0 , -12*E*Iz/Math.pow(L, 3) , 0 , 0 , 0 , -6*E*Iz/Math.pow(L, 2) , 0 , 12*E*Iz/Math.pow(L, 3) , 0 , 0 , 0 , -6*E*Iz/Math.pow(L, 2)] ,//d2y - [0 , 0 , -12*E*Iy/Math.pow(L, 3) , 0 , 6*E*Iy/Math.pow(L, 2) , 0 , 0 , 0 , 12*E*Iy/Math.pow(L, 3) , 0 , 6*E*Iy/Math.pow(L, 2) , 0] ,//d2z - [0 , 0 , 0 , -G*J/L , 0 , 0 , 0 , 0 , 0 , G*J/L , 0 , 0] ,//r2x - [0 , 0 , -6*E*Iy/Math.pow(L, 2) , 0 , 2*E*Iy/L , 0 , 0 , 0 , 6*E*Iy/Math.pow(L, 2) , 0 , 4*E*Iy/L , 0] ,//r2y - [0 , 6*E*Iz/Math.pow(L, 2) , 0 , 0 , 0 , 2*E*Iz/L , 0 , -6*E*Iz/Math.pow(L, 2) , 0 , 0 , 0 , 4*E*Iz/L]//r2z - ]; - +DmaBeam.prototype.calcStiffnessMatrix = function(){ + +// var L = 0; +// var A = 0; +// var Iy = 0; +// var Iz = 0; +// var E = 0; +// var G = 0; +// +// +// var K = [ +// [A*E/L , 0 , 0 , 0 , 0 , 0 , -A*E/L , 0 , 0 , 0 , 0 , 0] ,//d1x +// [0 , 12*E*Iz/Math.pow(L, 3) , 0 , 0 , 0 , 6*E*Iz/Math.pow(L, 2) , 0 , -12*E*Iz/Math.pow(L, 3) , 0 , 0 , 0 , 6*E*Iz/Math.pow(L, 2)] ,//d1y +// [0 , 0 , 12*E*Iy/Math.pow(L, 3) , 0 , -6*E*Iy/Math.pow(L, 2) , 0 , 0 , 0 , -12*E*Iy/Math.pow(L, 3) , 0 , -6*E*Iy/Math.pow(L, 2) , 0] ,//d1z +// [0 , 0 , 0 , G*J/L , 0 , 0 , 0 , 0 , 0 , -G*J/L , 0 , 0] , //r1x +// [0 , 0 , -6*E*Iy/Math.pow(L, 2) , 0 , 4*E*Iy/L , 0 , 0 , 0 , 6*E*Iy/Math.pow(L, 2) , 0 , 2*E*Iy/L , 0] ,//r1y +// [0 , 6*E*Iz/Math.pow(L, 2) , 0 , 0 , 0 , 4*E*Iz/L , 0 , -6*E*Iz/Math.pow(L, 2) , 0 , 0 , 0 , 2*E*Iz/L] ,//r1z +// [-A*E/L , 0 , 0 , 0 , 0 , 0 , A*E/L , 0 , 0 , 0 , 0 , 0] , //d2x +// [0 , -12*E*Iz/Math.pow(L, 3) , 0 , 0 , 0 , -6*E*Iz/Math.pow(L, 2) , 0 , 12*E*Iz/Math.pow(L, 3) , 0 , 0 , 0 , -6*E*Iz/Math.pow(L, 2)] ,//d2y +// [0 , 0 , -12*E*Iy/Math.pow(L, 3) , 0 , 6*E*Iy/Math.pow(L, 2) , 0 , 0 , 0 , 12*E*Iy/Math.pow(L, 3) , 0 , 6*E*Iy/Math.pow(L, 2) , 0] ,//d2z +// [0 , 0 , 0 , -G*J/L , 0 , 0 , 0 , 0 , 0 , G*J/L , 0 , 0] ,//r2x +// [0 , 0 , -6*E*Iy/Math.pow(L, 2) , 0 , 2*E*Iy/L , 0 , 0 , 0 , 6*E*Iy/Math.pow(L, 2) , 0 , 4*E*Iy/L , 0] ,//r2y +// [0 , 6*E*Iz/Math.pow(L, 2) , 0 , 0 , 0 , 2*E*Iz/L , 0 , -6*E*Iz/Math.pow(L, 2) , 0 , 0 , 0 , 4*E*Iz/L]//r2z +// ]; }; diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index b68dc549..3cb9a371 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -15,6 +15,8 @@ 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.beams = this._initBeams(this.nodes, this.cellMesh.children[0].geometry.faces); var cellMode = dmaGlobals.lattice.get("cellMode"); var inverseMode = dmaGlobals.lattice.get("inverseMode"); @@ -97,6 +99,27 @@ DMACell.prototype._setCellMeshVisibility = function(visibility){ /////////////////////////////////META////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// +DMACell.prototype_initParts = function(){ + return [];//override in subclasses +} + +DMACell.prototype._initNodes = function(vertices){ + var position = this.getPosition(); + var orientation = this.getOrientation(); + var nodes = []; + for (var i=0;i<vertices.length;i++){ + var vertex = vertices[i]; + vertex.applyQuaternion(orientation); + vertex.add(position); + nodes.push(new DmaNode(vertex, i)); + } + return nodes; +}; + +DMACell.prototype._initBeams = function(){ + return []; +}; + DMACell.prototype.removePart = function(index){ this.parts[index].destroy(); this.parts[index] = null; @@ -123,6 +146,8 @@ DMACell.prototype.destroy = function(){ }); this.indices = null; this.parts = null; + this.nodes = null; + this.beams = null; }; DMACell.prototype.toJSON = function(){ @@ -160,6 +185,36 @@ DMACell.prototype.toJSON = function(){ return parts; }; + DMAFaceOctaCell.prototype._initBeams = function(nodes, faces){ + var beams = []; + var addBeamFunc = function(index1, index2){ + var duplicate = false; + _.each(beams, function(beam){ + var index = beam.getIndex(); + if (index[0] == index1 && index[1] == index2) duplicate = true; + }); + if (duplicate) return; + if (index2>index1) { + beams.push(new DmaBeam(nodes[index1], nodes[index2])); + } + }; + for (var i=0;i<nodes.length;i++){ + _.each(faces, function(face){ + if (face.a == i) { + addBeamFunc(i, face.b); + addBeamFunc(i, face.c); + } else if (face.b == i){ + addBeamFunc(i, face.a); + addBeamFunc(i, face.c); + } else if (face.c == i){ + addBeamFunc(i, face.a); + addBeamFunc(i, face.b); + } + }) + } + return beams; + }; + DMAFaceOctaCell.prototype._buildCellMesh = function(){ return this._superBuildCellMesh(unitCellGeo); }; diff --git a/js/fea/DmaNode.js b/js/fea/DmaNode.js index b20b8bb9..ab7e71d3 100644 --- a/js/fea/DmaNode.js +++ b/js/fea/DmaNode.js @@ -1,55 +1,21 @@ //a node, two for each dmaBeam, not to be confused with node.js -function BeamNode(x, y, z) { +function DmaNode(position, index) { this._beams = [];//store all beams attached to this node, eventually this will be used to calc global stiffness K - this.x = x; - this.y = y; - this.z = z; - this.render(); + this.position = position; + this.index = index; } -BeamNode.prototype.addBeam = function(beam){ - this._beams.push(beam); -}; - -BeamNode.prototype.render = function(){ - - var geometry = new THREE.BoxGeometry(2,2,2); - geometry.applyMatrix( new THREE.Matrix4().makeTranslation(this.x, this.y, this.z) ); - var mesh = new THREE.Mesh(geometry); - -// dmaGlobals.three.sceneAdd(mesh); -}; - - -BeamNode.prototype.deflect = function(dx, dy, dz){ -}; - -BeamNode.prototype.translate = function(dx, dy, dz){ - this.x += dx; - this.y += dy; - this.z += dz; -}; - -BeamNode.prototype.translateAbsolute = function(x, y, z){ - this.x = x; - this.y = y; - this.z = z; +DmaNode.prototype.getIndex = function(){ + return this.index; }; -BeamNode.prototype.rotate = function(rx, ry, rz){ +DmaNode.prototype.addBeam = function(beam){ + this._beams.push(beam); }; -BeamNode.prototype.destroy = function(){ +DmaNode.prototype.destroy = function(){ this._beams = null;//be sure to remove cyclic reference + this.position = null; + this.index = null; }; - -BeamNode.prototype.getMidPoint = function(node){ - - var x = (node.x+this.x)/2; - var y = (node.y+this.y)/2; - var z = (node.z+this.z)/2; - - return [x,y,z]; - -} diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js index 9638e54a..8f4772ce 100644 --- a/js/fea/DmaPart.js +++ b/js/fea/DmaPart.js @@ -13,6 +13,8 @@ DMAPart.prototype._draw = function(){ if (this.mesh) console.warn("part mesh already in scene"); this.mesh = this._makeMeshForType(this.type); + var rotation = this.parentCell.getEulerRotation(); + this.mesh.rotation.set(rotation.x, rotation.y, rotation.z); this.updateForScale(this.parentCell.getScale(), this.parentCell.getPosition()); dmaGlobals.three.sceneAdd(this.mesh, "part"); }; @@ -93,7 +95,6 @@ loader.load("data/trianglePart.stl", function(geometry){ unitPartGeo1 = geometry - unitPartGeo1.dynamic = true; unitPartGeo1.computeBoundingBox(); var unitScale = 1.2/unitPartGeo1.boundingBox.max.y; unitPartGeo1.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); @@ -106,15 +107,6 @@ unitPartGeo3 = unitPartGeo1.clone(); unitPartGeo3.applyMatrix(new THREE.Matrix4().makeRotationZ(-2*Math.PI/3)); - - unitPartGeo4 = unitPartGeo1.clone(); - unitPartGeo4.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); - - unitPartGeo5 = unitPartGeo2.clone(); - unitPartGeo5.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); - - unitPartGeo6 = unitPartGeo3.clone(); - unitPartGeo6.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); }); var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THREE.FlatShading }); @@ -139,8 +131,6 @@ break; } mesh.myPart = this;//need a ref back to this part - var rotation = this.parentCell.getEulerRotation(); - mesh.rotation.set(rotation.x, rotation.y, rotation.z); return mesh; }; diff --git a/js/models/AppState.js b/js/models/AppState.js index ff01a777..9e173cc0 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -25,11 +25,11 @@ AppState = Backbone.Model.extend({ }, allPartTypes:{ octa:{ - face: {triangle:"Triangle", default:"Default"}, - freeformFace: {triangle:"Triangle", default:"Default"}, - edge: {triangle:"Triangle", default:"Default"}, - edgeRot: {triangle:"Triangle", default:"Default"}, - vertex: {square:"Square", xShape:"X", default:"Default"} + face: {triangle:"Triangle", beam:"DmaBeam"}, + freeformFace: {triangle:"Triangle", beam:"DmaBeam"}, + edge: {triangle:"Triangle", beam:"DmaBeam"}, + edgeRot: {beam:"DmaBeam"}, + vertex: {square:"Square", xShape:"X", beam:"DmaBeam"} }, cube:{ face: null diff --git a/main.html b/main.html index 394f8027..ac1b5d53 100644 --- a/main.html +++ b/main.html @@ -46,10 +46,10 @@ <script src="js/persistentWorkers.js"></script><!--global workers--> <!--fea stuff--> + <script src="js/fea/DmaNode.js"></script> + <script src="js/fea/DmaBeam.js"></script> <script src="js/fea/DmaCell.js"></script> <script src="js/fea/DmaPart.js"></script> - <!--<script src="js/fea/DmaBeam.js"></script>--> - <script src="js/fea/DmaNode.js"></script> <!--models--> <script src="js/models/ThreeModel.js"></script> -- GitLab