diff --git a/index.html b/index.html index b9c08cd7acce9bc3d5b0b719d547716951e98539..03d473e251e6cba83c3ee82ac038f74b04674beb 100644 --- a/index.html +++ b/index.html @@ -65,7 +65,7 @@ @@ -83,7 +83,7 @@ float isFixed = texture2D(u_mass, scaledFragCoord).y; if (isFixed == 1.0){ - gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); + gl_FragColor = vec4(0.0); return; } @@ -113,7 +113,7 @@ vec2 mass = texture2D(u_mass, scaledFragCoord).xy; if (mass.y == 1.0){ - gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); + gl_FragColor = vec4(0.0); return; } vec3 force = texture2D(u_externalForces, scaledFragCoord).xyz; @@ -153,6 +153,42 @@ } + + @@ -169,6 +205,7 @@ + @@ -214,6 +251,12 @@
About

+ +
+ Crease Angle :
+ +
+


Axial Stiffness :
diff --git a/js/controls.js b/js/controls.js index 9518af6ee7b66f3405384ae9b9c3404016538a51..3f36e101837630db065bacf15fb60a70faa14d4f 100644 --- a/js/controls.js +++ b/js/controls.js @@ -56,6 +56,10 @@ function initControls(globals){ globals.dynamicModel.reset(); }); + setSliderInput("#creaseAngle", globals.creaseAngle, 0, Math.PI, 0.1, function(val){ + globals.creaseAngle = val; + }); + function setDeltaT(val){ $("#deltaT").html(val.toFixed(4)); } diff --git a/js/crease.js b/js/crease.js new file mode 100644 index 0000000000000000000000000000000000000000..a685cc8f275452ca28fd4ad75db889198238b927 --- /dev/null +++ b/js/crease.js @@ -0,0 +1,43 @@ +/** + * Created by amandaghassaei on 2/25/17. + */ + +function Crease(edge, face1Index, face2Index, targetTheta, node1, node2){ + + //face1 corresponds to node1, face2 to node2 + this.edge = edge; + this.face1Index = face1Index; + this.face2Index = face2Index; + this.targetTheta = targetTheta; + this.node1 = node1; + this.node2 = node2; + node1.addCrease(this); + node2.addCrease(this); +} + +Crease.prototype.getLength = function(){ + return this.edge.getLength(); +}; + +Crease.prototype.getVector = function(){ + return this.edge.getVector(); +}; + +Crease.prototype.getNormal1Index = function(){ + return this.face1Index; +}; + +Crease.prototype.getNormal2Index = function(){ + return this.face2Index; +}; + +Crease.prototype.destroy = function(){ + this.node1.removeCrease(this); + this.node2.removeCrease(this); + this.edge = null; + this.face1Index = null; + this.face2Index = null; + this.targetTheta = null; + this.node1 = null; + this.node2 = null; +}; \ No newline at end of file diff --git a/js/dynamicModel.js b/js/dynamicModel.js index 1e2f1954cfb43ce64301b691e4e07601db781d10..49eca0d0ffd6cb02067da5c9913d7b37681396fb 100644 --- a/js/dynamicModel.js +++ b/js/dynamicModel.js @@ -4,12 +4,15 @@ function initDynamicModel(globals){ - var object3D = new THREE.Object3D(); + var geometry = new THREE.Geometry(); + geometry.dynamic = true; + var object3D = new THREE.Mesh(geometry, new THREE.MeshNormalMaterial({shading: THREE.FlatShading, side: THREE.DoubleSide})); object3D.visible = globals.dynamicSimVisible; globals.threeView.sceneAddModel(object3D); var nodes; var edges; + var creases; var originalPosition; var position; @@ -18,14 +21,31 @@ function initDynamicModel(globals){ var lastVelocity; var externalForces; var mass; - var meta;//[beamsIndex, numBeams] + var meta;//[beamsIndex, numBeams, creasesIndex, numCreases] var beamMeta;//[K, D, length, otherNodeIndex] + var normals; + var creaseMeta;//[k, d, targetTheta, length (to node)] + var creaseVectors;//vectors of oriented edges in crease + var theta;//[theta, w, normalIndex1, normalIndex2] + var lastTheta;//[theta, w, normalIndex1, normalIndex2] + function syncNodesAndEdges(){ nodes = globals.model.getNodes(); edges = globals.model.getEdges(); //update mesh nodes + geometry.vertices = []; + for (var i=0;i= numCreases){ + lastTheta[i*4+2] = -1; + lastTheta[i*4+3] = -1; + continue; + } + lastTheta[i*4+2] = creases[i].getNormal1Index(); + lastTheta[i*4+3] = creases[i].getNormal2Index(); + } + + updateCreaseVectors(); + updateNormals(); updateOriginalPosition(); updateMaterials(true); updateFixed(); updateExternalForces(); } - function getChildren(){ - return object3D.children; - } - return { setVisibility: setVisibility, - getChildren: getChildren, setViewMode: setViewMode, syncNodesAndEdges: syncNodesAndEdges, updateOriginalPosition: updateOriginalPosition, diff --git a/js/globals.js b/js/globals.js index 28fc080c2e4ab58e1bfef47cb14e02ca6ca0dbf8..251456120637905c4477b89906c5bc7f1096a8be 100644 --- a/js/globals.js +++ b/js/globals.js @@ -19,6 +19,7 @@ function initGlobals(){ schematicVisible: true, //sim settings + creaseAngle: 0, axialStiffness: 100, creaseStiffness: 1, panelStiffness: 1, diff --git a/js/model.js b/js/model.js index 343f98a9f70f0c0945d1a30e74ba093ab83b4ae9..e5288ded9f274897251e29ce0e40fc2b240d3019 100644 --- a/js/model.js +++ b/js/model.js @@ -21,6 +21,9 @@ function initModel(globals){ edges.push(new Beam([nodes[3], nodes[0]])); edges.push(new Beam([nodes[3], nodes[2]])); + var creases = []; + creases.push(new Crease(edges[1], 1, 0, 0, nodes[1], nodes[0])); + _.each(nodes, function(node){ globals.threeView.sceneAddModel(node.getObject3D()); }); @@ -36,8 +39,13 @@ function initModel(globals){ return edges; } + function getCreases(){ + return creases; + } + return { getNodes: getNodes, - getEdges: getEdges + getEdges: getEdges, + getCreases: getCreases } } \ No newline at end of file diff --git a/js/node.js b/js/node.js index 1c18df9784fd894b08095b63f0d1aa3d5d034990..6b9adc1c33b8d4f1a48766e2d0318bee025226f8 100644 --- a/js/node.js +++ b/js/node.js @@ -22,6 +22,7 @@ function Node(position, index){ this.object3D._myNode = this; this.beams = []; + this.creases = []; this.externalForce = null; this.fixed = false; @@ -78,6 +79,16 @@ Node.prototype.getMass = function(){ +Node.prototype.addCrease = function(crease){ + this.creases.push(crease); +}; + +Node.prototype.removeCrease = function(crease){ + if (this.creases === null) return; + var index = this.creases.indexOf(crease); + if (index>=0) this.creases.splice(index, 1); +}; + Node.prototype.addBeam = function(beam){ this.beams.push(beam); @@ -163,5 +174,6 @@ Node.prototype.destroy = function(){ this.object3D._myNode = null; this.object3D = null; this.beams = null; + this.creases = null; this.externalForce = null; }; \ No newline at end of file