Commit dcf4a83e authored by amandaghassaei's avatar amandaghassaei
Browse files

crease nodes coef

parent 65741047
......@@ -205,7 +205,7 @@
float targetTheta = creaseMeta[2] * u_creasePercent;
float angForce = creaseMeta[0]*(targetTheta-thetas[0]);// + creaseMeta[1]*thetas[1];
if (creaseMeta2[3] < 0.0){//crease reaction
if (creaseMeta2[3] < 0.0){//crease reaction, node is on a crease
float nodeNum = creaseMeta2[2];
//node #1
......@@ -220,10 +220,10 @@
scaledNormalsIndex = normalsIndex/u_textureDimFaces;
vec3 normal2 = texture2D(u_normals, scaledNormalsIndex).xyz;
float momentArm1 = creaseMeta2[1];
float momentArm2 = creaseMeta2[2];
float coef1 = creaseMeta2[1];
float coef2 = creaseMeta2[2];
vec3 _force = -0.5*(angForce/momentArm1*normal1 + angForce/momentArm2*normal2);
vec3 _force = -angForce*(coef1*normal1 + coef2*normal2);
force += _force;
} else {
float nodeNum = creaseMeta2[2];
......
......@@ -14,8 +14,8 @@ function Crease(edge, face1Index, face2Index, targetTheta, type, node1, node2, i
this.face2Index = face2Index;
this.targetTheta = targetTheta;
this.type = type;
this.node1 = node1;
this.node2 = node2;
this.node1 = node1;//node at vertex of face 1
this.node2 = node2;//node at vertex of face 2
this.index = index;
node1.addCrease(this);
node2.addCrease(this);
......@@ -25,8 +25,8 @@ Crease.prototype.getLength = function(){
return this.edge.getLength();
};
Crease.prototype.getVector = function(){
return this.edge.getVector();
Crease.prototype.getVector = function(fromNode){
return this.edge.getVector(fromNode);
};
Crease.prototype.getNormal1Index = function(){
......@@ -65,6 +65,28 @@ Crease.prototype.getLengthToNode2 = function(){
return this.getLengthTo(this.node2);
};
Crease.prototype.getCoef1 = function(edgeNode){
return this.getCoef(this.node1, edgeNode);
};
Crease.prototype.getCoef2 = function(edgeNode){
return this.getCoef(this.node2, edgeNode);
};
Crease.prototype.getCoef = function(node, edgeNode){
var vector1 = this.getVector(edgeNode);
var creaseLength = vector1.length();
vector1.normalize();
var nodePosition = node.getOriginalPosition();
var vector2 = nodePosition.sub(edgeNode.getOriginalPosition());
var projLength = vector1.dot(vector2);
var length = Math.sqrt(vector2.lengthSq()-projLength*projLength);
if (length <= 0.0) {
console.warn("bad moment arm");
length = 0.001;
}
return (1-projLength/creaseLength)/length;
};
Crease.prototype.getLengthTo = function(node){
var vector1 = this.getVector().normalize();
var nodePosition = node.getOriginalPosition();
......
......@@ -26,7 +26,7 @@ function initDynamicSolver(globals){
var normals;
var faceVertexIndices;//[a,b,c]
var creaseMeta;//[k, d, targetTheta]
var creaseMeta2;//[creaseIndex (thetaIndex), length to node, nodeIndex (1/2), ]
var creaseMeta2;//[creaseIndex (thetaIndex), length to node, nodeIndex (1/2)]
//[creaseIndex (thetaIndex), length to node1, length to node2, -1]
var creaseVectors;//indices of crease nodes
var theta;//[theta, w, normalIndex1, normalIndex2]
......@@ -395,6 +395,7 @@ function initDynamicSolver(globals){
// this.vertices[1].clone().sub(this.vertices[0]);
creaseVectors[rgbaIndex] = nodes[0].getIndex();
creaseVectors[rgbaIndex+1] = nodes[1].getIndex();
//todo percent to moment arm here?
}
globals.gpuMath.initTextureFromData("u_creaseVectors", textureDimCreases, textureDimCreases, "FLOAT", creaseVectors, true);
}
......@@ -403,9 +404,8 @@ function initDynamicSolver(globals){
for (var i=0;i<creases.length;i++){
var crease = creases[i];
creaseMeta[i*4] = crease.getK();
creaseMeta[i*4+1] = crease.getD();
creaseMeta[i*4+1] = crease.getD();//todo not using this
if (initing) creaseMeta[i*4+2] = crease.getTargetTheta();
// if (crease.getTargetTheta()<)
}
globals.gpuMath.initTextureFromData("u_creaseMeta", textureDimCreases, textureDimCreases, "FLOAT", creaseMeta, true);
}
......@@ -494,20 +494,21 @@ function initDynamicSolver(globals){
mass[4*i] = nodes[i].getSimMass();
meta[i*4+2] = index;
var nodeCreases = nodes[i].creases;
var nodeInvCreases = nodes[i].invCreases;
var nodeInvCreases = nodes[i].invCreases;//nodes attached to crease move in opposite direction
// console.log(nodeInvCreases);
meta[i*4+3] = nodeCreases.length + nodeInvCreases.length;
for (var j=0;j<nodeCreases.length;j++){
creaseMeta2[index*4] = nodeCreases[j].getIndex();
creaseMeta2[index*4+1] = nodeCreases[j].getLengthTo(nodes[i]);
creaseMeta2[index*4+2] = nodeCreases[j].getNodeIndex(nodes[i]);//type 1 or 2
//creaseMeta2[index*4+2] = 0 tells us that it is a node opposite a crease
index++;
}
for (var j=0;j<nodeInvCreases.length;j++){
creaseMeta2[index*4] = nodeInvCreases[j].getIndex();
creaseMeta2[index*4+1] = nodeInvCreases[j].getLengthToNode1();
creaseMeta2[index*4+2] = nodeInvCreases[j].getLengthToNode2();
creaseMeta2[index*4+3] = -1;
creaseMeta2[index*4+1] = nodeInvCreases[j].getCoef1(nodes[i]);
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++;
}
}
......
......@@ -96,7 +96,6 @@ function initThreeView(globals) {
}
function render() {
console.log("here");
if (!animationRunning) {
console.log("render");
_render();
......
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