Commit 9008ee1f authored by amandaghassaei's avatar amandaghassaei

adding in crease stiffness

parent a11b6ce4
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<script id="zeroTexture" type="x-shader/x-fragment"> <script id="zeroTexture" type="x-shader/x-fragment">
void main(){ void main(){
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); gl_FragColor = vec4(0.0);
} }
</script> </script>
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
float isFixed = texture2D(u_mass, scaledFragCoord).y; float isFixed = texture2D(u_mass, scaledFragCoord).y;
if (isFixed == 1.0){ if (isFixed == 1.0){
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); gl_FragColor = vec4(0.0);
return; return;
} }
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
vec2 mass = texture2D(u_mass, scaledFragCoord).xy; vec2 mass = texture2D(u_mass, scaledFragCoord).xy;
if (mass.y == 1.0){ if (mass.y == 1.0){
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); gl_FragColor = vec4(0.0);
return; return;
} }
vec3 force = texture2D(u_externalForces, scaledFragCoord).xyz; vec3 force = texture2D(u_externalForces, scaledFragCoord).xyz;
...@@ -153,6 +153,42 @@ ...@@ -153,6 +153,42 @@
} }
</script> </script>
<script id="thetaCalcShader" type="x-shader/x-fragment">
precision mediump float;
uniform vec2 u_textureDimFaces;
uniform vec2 u_textureDimCreases;
uniform sampler2D u_normals;
uniform sampler2D u_lastTheta;
uniform sampler2D u_creaseVectors;
void main(){
vec2 fragCoord = gl_FragCoord.xy;
vec2 scaledFragCoord = fragCoord/u_textureDimCreases;
vec4 lastTheta = texture2D(u_lastTheta, scaledFragCoord);
if (lastTheta[2]<0.0){
gl_FragColor = vec4(0.0, 0.0, -1.0, -1.0);
return;
}
vec2 normal1Index = vec2(mod(lastTheta[2], u_textureDimFaces.x)+0.5, floor(lastTheta[2]/u_textureDimFaces.x)+0.5);
normal1Index /= u_textureDimFaces;
vec2 normal2Index = vec2(mod(lastTheta[3], u_textureDimFaces.x)+0.5, floor(lastTheta[3]/u_textureDimFaces.x)+0.5);
normal2Index /= u_textureDimFaces;
vec3 normal1 = texture2D(u_normals, normal1Index).xyz;
vec3 normal2 = texture2D(u_normals, normal2Index).xyz;
float theta = acos(dot(normal1, normal2));//normals are already normalized, no need to divide by length
vec3 creaseVector = texture2D(u_creaseVectors, scaledFragCoord).xyz;
float sign = dot(cross(normal1, normal2), creaseVector);
if (sign < 0.0) theta *= -1.0;
gl_FragColor = vec4(theta, theta-lastTheta[0], lastTheta[2], lastTheta[3]);//[theta, w, normal1Index, normal2Index]
}
</script>
<script type="text/javascript" src="dependencies/jquery-3.1.1.min.js"></script> <script type="text/javascript" src="dependencies/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="dependencies/jquery-ui.min.js"></script> <script type="text/javascript" src="dependencies/jquery-ui.min.js"></script>
<script type="text/javascript" src="dependencies/flat-ui.min.js"></script> <script type="text/javascript" src="dependencies/flat-ui.min.js"></script>
...@@ -169,6 +205,7 @@ ...@@ -169,6 +205,7 @@
<script type="text/javascript" src="js/globals.js"></script> <script type="text/javascript" src="js/globals.js"></script>
<script type="text/javascript" src="js/node.js"></script> <script type="text/javascript" src="js/node.js"></script>
<script type="text/javascript" src="js/beam.js"></script> <script type="text/javascript" src="js/beam.js"></script>
<script type="text/javascript" src="js/crease.js"></script>
<script type="text/javascript" src="js/model.js"></script> <script type="text/javascript" src="js/model.js"></script>
<script type="text/javascript" src="js/dynamicModel.js"></script> <script type="text/javascript" src="js/dynamicModel.js"></script>
...@@ -214,6 +251,12 @@ ...@@ -214,6 +251,12 @@
</div> </div>
<div id="controls"> <div id="controls">
<a href="#" id="about" class="btn btn-lg btn-default">About</a><br/><br/> <a href="#" id="about" class="btn btn-lg btn-default">About</a><br/><br/>
<div class="sliderInput" id="creaseAngle">
<span class="label-slider">Crease Angle : </span><div class="flat-slider ui-slider ui-corner-all ui-slider-horizontal ui-widget ui-widget-content"></div>
<input value="" placeholder="" class="form-control int" type="text">
</div>
<br/><br/><br/>
<div class="sliderInput" id="axialStiffness"> <div class="sliderInput" id="axialStiffness">
<span class="label-slider">Axial Stiffness : </span><div class="flat-slider ui-slider ui-corner-all ui-slider-horizontal ui-widget ui-widget-content"></div> <span class="label-slider">Axial Stiffness : </span><div class="flat-slider ui-slider ui-corner-all ui-slider-horizontal ui-widget ui-widget-content"></div>
<input value="" placeholder="" class="form-control int" type="text"> <input value="" placeholder="" class="form-control int" type="text">
......
...@@ -56,6 +56,10 @@ function initControls(globals){ ...@@ -56,6 +56,10 @@ function initControls(globals){
globals.dynamicModel.reset(); globals.dynamicModel.reset();
}); });
setSliderInput("#creaseAngle", globals.creaseAngle, 0, Math.PI, 0.1, function(val){
globals.creaseAngle = val;
});
function setDeltaT(val){ function setDeltaT(val){
$("#deltaT").html(val.toFixed(4)); $("#deltaT").html(val.toFixed(4));
} }
......
/**
* 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
This diff is collapsed.
...@@ -19,6 +19,7 @@ function initGlobals(){ ...@@ -19,6 +19,7 @@ function initGlobals(){
schematicVisible: true, schematicVisible: true,
//sim settings //sim settings
creaseAngle: 0,
axialStiffness: 100, axialStiffness: 100,
creaseStiffness: 1, creaseStiffness: 1,
panelStiffness: 1, panelStiffness: 1,
......
...@@ -21,6 +21,9 @@ function initModel(globals){ ...@@ -21,6 +21,9 @@ function initModel(globals){
edges.push(new Beam([nodes[3], nodes[0]])); edges.push(new Beam([nodes[3], nodes[0]]));
edges.push(new Beam([nodes[3], nodes[2]])); 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){ _.each(nodes, function(node){
globals.threeView.sceneAddModel(node.getObject3D()); globals.threeView.sceneAddModel(node.getObject3D());
}); });
...@@ -36,8 +39,13 @@ function initModel(globals){ ...@@ -36,8 +39,13 @@ function initModel(globals){
return edges; return edges;
} }
function getCreases(){
return creases;
}
return { return {
getNodes: getNodes, getNodes: getNodes,
getEdges: getEdges getEdges: getEdges,
getCreases: getCreases
} }
} }
\ No newline at end of file
...@@ -22,6 +22,7 @@ function Node(position, index){ ...@@ -22,6 +22,7 @@ function Node(position, index){
this.object3D._myNode = this; this.object3D._myNode = this;
this.beams = []; this.beams = [];
this.creases = [];
this.externalForce = null; this.externalForce = null;
this.fixed = false; this.fixed = false;
...@@ -78,6 +79,16 @@ Node.prototype.getMass = function(){ ...@@ -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){ Node.prototype.addBeam = function(beam){
this.beams.push(beam); this.beams.push(beam);
...@@ -163,5 +174,6 @@ Node.prototype.destroy = function(){ ...@@ -163,5 +174,6 @@ Node.prototype.destroy = function(){
this.object3D._myNode = null; this.object3D._myNode = null;
this.object3D = null; this.object3D = null;
this.beams = null; this.beams = null;
this.creases = null;
this.externalForce = null; this.externalForce = null;
}; };
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment