Commit 30e2f145 authored by amandaghassaei's avatar amandaghassaei
Browse files

update h and coefs dynamically

parent e5bbfd9c
...@@ -137,7 +137,7 @@ ...@@ -137,7 +137,7 @@
uniform sampler2D u_meta;//[beamsIndex, numBeam, creaseMeta2Index, numCreases] uniform sampler2D u_meta;//[beamsIndex, numBeam, creaseMeta2Index, numCreases]
uniform sampler2D u_beamMeta;//[k, d, length, otherNodeIndex] uniform sampler2D u_beamMeta;//[k, d, length, otherNodeIndex]
uniform sampler2D u_creaseMeta;//[k, d, targetTheta] uniform sampler2D u_creaseMeta;//[k, d, targetTheta]
uniform sampler2D u_creaseMeta2;//[creaseIndex, momentArmLength, nodeIndex] uniform sampler2D u_creaseMeta2;//[creaseIndex, nodeIndex, -, -]
uniform sampler2D u_normals; uniform sampler2D u_normals;
uniform sampler2D u_theta;//[theta, z, normal1Index, normal2Index] uniform sampler2D u_theta;//[theta, z, normal1Index, normal2Index]
uniform sampler2D u_creaseGeo;//[h1, h2, coef1, coef2] uniform sampler2D u_creaseGeo;//[h1, h2, coef1, coef2]
...@@ -207,9 +207,9 @@ ...@@ -207,9 +207,9 @@
float targetTheta = creaseMeta[2] * u_creasePercent; float targetTheta = creaseMeta[2] * u_creasePercent;
float angForce = creaseMeta[0]*(targetTheta-thetas[0]);// + creaseMeta[1]*thetas[1]; float angForce = creaseMeta[0]*(targetTheta-thetas[0]);// + creaseMeta[1]*thetas[1];
float nodeNum = creaseMeta2[2];//1, 2, 3, 4 float nodeNum = creaseMeta2[1];//1, 2, 3, 4
if (creaseMeta2[3] < 0.0){//crease reaction, node is on a crease if (nodeNum > 2.0){//crease reaction, node is on a crease
//node #1 //node #1
float normalIndex1D = thetas[2]; float normalIndex1D = thetas[2];
...@@ -223,13 +223,13 @@ ...@@ -223,13 +223,13 @@
scaledNormalsIndex = normalsIndex/u_textureDimFaces; scaledNormalsIndex = normalsIndex/u_textureDimFaces;
vec3 normal2 = texture2D(u_normals, scaledNormalsIndex).xyz; vec3 normal2 = texture2D(u_normals, scaledNormalsIndex).xyz;
float coef1 = creaseMeta2[1]; float coef1 = creaseGeo[2];
float coef2 = creaseMeta2[2]; float coef2 = creaseGeo[3];
//if (nodeNum == 3.0){ if (nodeNum == 3.0){
// coef1 = 1.0-coef1; coef1 = 1.0-coef1;
// coef2 = 1.0-coef2; coef2 = 1.0-coef2;
//} }
vec3 _force = -angForce*(coef1/creaseGeo[0]*normal1 + coef2/creaseGeo[1]*normal2); vec3 _force = -angForce*(coef1/creaseGeo[0]*normal1 + coef2/creaseGeo[1]*normal2);
force += _force; force += _force;
...@@ -375,10 +375,10 @@ ...@@ -375,10 +375,10 @@
vec2 node3Index = vec2(mod(creaseMeta[2], u_textureDim.x)+0.5, floor(creaseMeta[2]/u_textureDim.x)+0.5)/u_textureDim; vec2 node3Index = vec2(mod(creaseMeta[2], u_textureDim.x)+0.5, floor(creaseMeta[2]/u_textureDim.x)+0.5)/u_textureDim;
vec2 node4Index = vec2(mod(creaseMeta[3], u_textureDim.x)+0.5, floor(creaseMeta[3]/u_textureDim.x)+0.5)/u_textureDim; vec2 node4Index = vec2(mod(creaseMeta[3], u_textureDim.x)+0.5, floor(creaseMeta[3]/u_textureDim.x)+0.5)/u_textureDim;
vec3 node1 = texture2D(u_lastPosition, node1Index).xyz + texture2D(u_originalPosition, node1Index).xyz; vec3 node1 = texture2D(u_originalPosition, node1Index).xyz + texture2D(u_lastPosition, node1Index).xyz;
vec3 node2 = texture2D(u_lastPosition, node2Index).xyz + texture2D(u_originalPosition, node2Index).xyz; vec3 node2 = texture2D(u_originalPosition, node2Index).xyz + texture2D(u_lastPosition, node2Index).xyz;
vec3 node3 = texture2D(u_lastPosition, node3Index).xyz + texture2D(u_originalPosition, node3Index).xyz; vec3 node3 = texture2D(u_originalPosition, node3Index).xyz + texture2D(u_lastPosition, node3Index).xyz;
vec3 node4 = texture2D(u_lastPosition, node4Index).xyz + texture2D(u_originalPosition, node4Index).xyz; vec3 node4 = texture2D(u_originalPosition, node4Index).xyz + texture2D(u_lastPosition, node4Index).xyz;
vec3 creaseVector = node4-node3; vec3 creaseVector = node4-node3;
float creaseLength = length(creaseVector); float creaseLength = length(creaseVector);
...@@ -392,11 +392,7 @@ ...@@ -392,11 +392,7 @@
float dist1 = sqrt(vector1.x*vector1.x+vector1.y*vector1.y+vector1.z*vector1.z-proj1Length*proj1Length); float dist1 = sqrt(vector1.x*vector1.x+vector1.y*vector1.y+vector1.z*vector1.z-proj1Length*proj1Length);
float dist2 = sqrt(vector2.x*vector2.x+vector2.y*vector2.y+vector2.z*vector2.z-proj2Length*proj2Length); float dist2 = sqrt(vector2.x*vector2.x+vector2.y*vector2.y+vector2.z*vector2.z-proj2Length*proj2Length);
float tol = 0.0001; gl_FragColor = vec4(dist1, dist2, proj1Length/creaseLength, proj2Length/creaseLength);
if (dist1<tol) dist1 = tol;
if (dist2<tol) dist2 = tol;
gl_FragColor = vec4(dist1, dist2, (proj1Length/creaseLength)/dist1, (proj2Length/creaseLength)/dist2);
} }
</script> </script>
......
...@@ -103,6 +103,7 @@ Crease.prototype.getNodeIndex = function(node){ ...@@ -103,6 +103,7 @@ Crease.prototype.getNodeIndex = function(node){
else if (node == this.node2) return 2; else if (node == this.node2) return 2;
else if (node == this.edge.nodes[0]) return 3; else if (node == this.edge.nodes[0]) return 3;
else if (node == this.edge.nodes[1]) return 4; else if (node == this.edge.nodes[1]) return 4;
console.log("unknown node type");
return 0; return 0;
}; };
......
...@@ -26,8 +26,7 @@ function initDynamicSolver(globals){ ...@@ -26,8 +26,7 @@ function initDynamicSolver(globals){
var normals; var normals;
var faceVertexIndices;//[a,b,c] var faceVertexIndices;//[a,b,c]
var creaseMeta;//[k, d, targetTheta] var creaseMeta;//[k, d, targetTheta]
var creaseMeta2;//[creaseIndex (thetaIndex), length to node, nodeIndex (1/2), 0] - this is for nodes which are opposite the crease var creaseMeta2;//[creaseIndex (thetaIndex), nodeIndex (1/2/3/4), -, -]
//[creaseIndex (thetaIndex), coef1, coef2, -1] - this is for nodes which are on the crease
var creaseMeta3;//[node1Index, node2Index, node3index, node4index]//nodes 1 and 2 are opposite crease, 3 and 4 are on crease var creaseMeta3;//[node1Index, node2Index, node3index, node4index]//nodes 1 and 2 are opposite crease, 3 and 4 are on crease
var creaseGeo;//[h1, h2, coef1, coef2] var creaseGeo;//[h1, h2, coef1, coef2]
var creaseVectors;//indices of crease nodes var creaseVectors;//indices of crease nodes
...@@ -511,15 +510,12 @@ function initDynamicSolver(globals){ ...@@ -511,15 +510,12 @@ function initDynamicSolver(globals){
meta[i*4+3] = nodeCreases.length + nodeInvCreases.length; meta[i*4+3] = nodeCreases.length + nodeInvCreases.length;
for (var j=0;j<nodeCreases.length;j++){ for (var j=0;j<nodeCreases.length;j++){
creaseMeta2[index*4] = nodeCreases[j].getIndex(); creaseMeta2[index*4] = nodeCreases[j].getIndex();
creaseMeta2[index*4+2] = nodeCreases[j].getNodeIndex(nodes[i]);//type 1, 2, 3, 4 creaseMeta2[index*4+1] = nodeCreases[j].getNodeIndex(nodes[i]);//type 1, 2, 3, 4
//creaseMeta2[index*4+2] = 0 tells us that it is a node opposite a crease
index++; index++;
} }
for (var j=0;j<nodeInvCreases.length;j++){ for (var j=0;j<nodeInvCreases.length;j++){
creaseMeta2[index*4] = nodeInvCreases[j].getIndex(); creaseMeta2[index*4] = nodeInvCreases[j].getIndex();
creaseMeta2[index*4+1] = nodeInvCreases[j].getCoef1(nodes[i]); creaseMeta2[index*4+1] = nodeInvCreases[j].getNodeIndex(nodes[i]);//type 1, 2, 3, 4
creaseMeta2[index*4+2] = nodeInvCreases[j].getCoef2(nodes[i]);
creaseMeta2[index*4+3] = -1;//this tells us that it is node on a crease
index++; index++;
} }
} }
......
...@@ -717,7 +717,7 @@ function initPattern(globals){ ...@@ -717,7 +717,7 @@ function initPattern(globals){
if (!containsInnerCrease) { if (!containsInnerCrease) {
polygons.splice(i,1); polygons.splice(i,1);
polygonEdges.splice(i,1); polygonEdges.splice(i,1);
break;//todo only remove once // break;//todo only remove once
} }
} }
......
Supports Markdown
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