Commit e5bbfd9c authored by amandaghassaei's avatar amandaghassaei
Browse files

update dist to nodes 1 and 2 form crease

parent 6e5bede4
......@@ -230,6 +230,9 @@ span.modal-close{
.checkbox input.custom-checkbox[type="checkbox"]:checked + .icons .icon-checked, .radio input.custom-checkbox[type="checkbox"]:checked + .icons .icon-checked, .checkbox input.custom-radio[type="radio"]:checked + .icons .icon-checked, .radio input.custom-radio[type="radio"]:checked + .icons .icon-checked {
color: #666;
}
.checkbox .icon-checked, .radio .icon-checked, .checkbox .icon-unchecked, .radio .icon-unchecked {
color: #bdc3c7;
}
.radio .icon-checked{
transition-duration: 0s;
......
......@@ -140,6 +140,7 @@
uniform sampler2D u_creaseMeta2;//[creaseIndex, momentArmLength, nodeIndex]
uniform sampler2D u_normals;
uniform sampler2D u_theta;//[theta, z, normal1Index, normal2Index]
uniform sampler2D u_creaseGeo;//[h1, h2, coef1, coef2]
void main(){
vec2 fragCoord = gl_FragCoord.xy;
......@@ -201,12 +202,14 @@
vec4 thetas = texture2D(u_theta, scaledCreaseIndex);
vec3 creaseMeta = texture2D(u_creaseMeta, scaledCreaseIndex).xyz;//[k, d, targetTheta]
vec4 creaseGeo = texture2D(u_creaseGeo, scaledCreaseIndex);//[h1, h2, coef1, coef2]
float targetTheta = creaseMeta[2] * u_creasePercent;
float angForce = creaseMeta[0]*(targetTheta-thetas[0]);// + creaseMeta[1]*thetas[1];
float nodeNum = creaseMeta2[2];//1, 2, 3, 4
if (creaseMeta2[3] < 0.0){//crease reaction, node is on a crease
float nodeNum = creaseMeta2[2];
//node #1
float normalIndex1D = thetas[2];
......@@ -223,20 +226,26 @@
float coef1 = creaseMeta2[1];
float coef2 = creaseMeta2[2];
vec3 _force = -angForce*(coef1*normal1 + coef2*normal2);
//if (nodeNum == 3.0){
// coef1 = 1.0-coef1;
// coef2 = 1.0-coef2;
//}
vec3 _force = -angForce*(coef1/creaseGeo[0]*normal1 + coef2/creaseGeo[1]*normal2);
force += _force;
} else {
float nodeNum = creaseMeta2[2];
float normalIndex1D = thetas[2];//node #1
if (nodeNum > 1.1) {
float momentArm = creaseGeo[0];//node #1
if (nodeNum == 2.0) {
normalIndex1D = thetas[3];//node #2
momentArm = creaseGeo[1];//node #2
}
vec2 normalsIndex = vec2(mod(normalIndex1D, u_textureDimFaces.x)+0.5, floor(normalIndex1D/u_textureDimFaces.x)+0.5);
vec2 scaledNormalsIndex = normalsIndex/u_textureDimFaces;
vec3 normal = texture2D(u_normals, scaledNormalsIndex).xyz;
float momentArm = creaseMeta2[1];
vec3 _force = angForce/momentArm*normal;
force += _force;
}
......@@ -347,6 +356,50 @@
}
</script>
<script id="updateCreaseGeo" type="x-shader/x-fragment">
precision mediump float;
uniform vec2 u_textureDim;
uniform vec2 u_textureDimCreases;
uniform sampler2D u_lastPosition;
uniform sampler2D u_originalPosition;
uniform sampler2D u_creaseMeta3;
void main(){
vec2 fragCoord = gl_FragCoord.xy;
vec2 scaledFragCoord = fragCoord/u_textureDimCreases;
vec4 creaseMeta = texture2D(u_creaseMeta3, scaledFragCoord);
vec2 node1Index = vec2(mod(creaseMeta[0], u_textureDim.x)+0.5, floor(creaseMeta[0]/u_textureDim.x)+0.5)/u_textureDim;
vec2 node2Index = vec2(mod(creaseMeta[1], u_textureDim.x)+0.5, floor(creaseMeta[1]/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;
vec3 node1 = texture2D(u_lastPosition, node1Index).xyz + texture2D(u_originalPosition, node1Index).xyz;
vec3 node2 = texture2D(u_lastPosition, node2Index).xyz + texture2D(u_originalPosition, node2Index).xyz;
vec3 node3 = texture2D(u_lastPosition, node3Index).xyz + texture2D(u_originalPosition, node3Index).xyz;
vec3 node4 = texture2D(u_lastPosition, node4Index).xyz + texture2D(u_originalPosition, node4Index).xyz;
vec3 creaseVector = node4-node3;
float creaseLength = length(creaseVector);
creaseVector /= creaseLength;
vec3 vector1 = node1-node3;
vec3 vector2 = node2-node3;
float proj1Length = dot(creaseVector, vector1);
float proj2Length = dot(creaseVector, vector2);
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 tol = 0.0001;
if (dist1<tol) dist1 = tol;
if (dist2<tol) dist2 = tol;
gl_FragColor = vec4(dist1, dist2, (proj1Length/creaseLength)/dist1, (proj2Length/creaseLength)/dist2);
}
</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/flat-ui.min.js"></script>
......
......@@ -82,7 +82,7 @@ Crease.prototype.getCoef = function(node, edgeNode){
console.warn("bad moment arm");
length = 0.001;
}
return (1-projLength/creaseLength)/length;
return (1-projLength/creaseLength);
};
Crease.prototype.getLengthTo = function(node){
......@@ -101,7 +101,8 @@ Crease.prototype.getLengthTo = function(node){
Crease.prototype.getNodeIndex = function(node){
if (node == this.node1) return 1;
else if (node == this.node2) return 2;
console.warn("no node found");
else if (node == this.edge.nodes[0]) return 3;
else if (node == this.edge.nodes[1]) return 4;
return 0;
};
......
......@@ -28,6 +28,8 @@ function initDynamicSolver(globals){
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
//[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 creaseGeo;//[h1, h2, coef1, coef2]
var creaseVectors;//indices of crease nodes
var theta;//[theta, w, normalIndex1, normalIndex2]
var lastTheta;//[theta, w, normalIndex1, normalIndex2]
......@@ -124,10 +126,14 @@ function initDynamicSolver(globals){
gpuMath.step("thetaCalc", ["u_normals", "u_lastTheta", "u_creaseVectors", "u_lastPosition",
"u_originalPosition"], "u_theta");
gpuMath.setProgram("updateCreaseGeo");
//already at textureDimCreasesxtextureDimCreases
gpuMath.step("updateCreaseGeo", ["u_lastPosition", "u_originalPosition", "u_creaseMeta3"], "u_creaseGeo");
gpuMath.setProgram("velocityCalc");
gpuMath.setSize(textureDim, textureDim);
gpuMath.step("velocityCalc", ["u_lastPosition", "u_lastVelocity", "u_originalPosition", "u_externalForces",
"u_mass", "u_meta", "u_beamMeta", "u_creaseMeta", "u_creaseMeta2", "u_normals", "u_theta"], "u_velocity");
"u_mass", "u_meta", "u_beamMeta", "u_creaseMeta", "u_creaseMeta2", "u_normals", "u_theta", "u_creaseGeo"], "u_velocity");
gpuMath.step("positionCalc", ["u_velocity", "u_lastPosition", "u_mass"], "u_position");
gpuMath.swapTextures("u_theta", "u_lastTheta");
......@@ -261,6 +267,9 @@ function initDynamicSolver(globals){
gpuMath.initTextureFromData("u_meta", textureDim, textureDim, "FLOAT", meta, true);
gpuMath.initTextureFromData("u_creaseMeta2", textureDimNodeCreases, textureDimNodeCreases, "FLOAT", creaseMeta2, true);
gpuMath.initTextureFromData("u_creaseMeta3", textureDimCreases, textureDimCreases, "FLOAT", creaseMeta3, true);
gpuMath.initTextureFromData("u_creaseGeo", textureDimCreases, textureDimCreases, "FLOAT", creaseGeo, true);
gpuMath.initFrameBufferForTexture("u_creaseGeo", true);
gpuMath.initTextureFromData("u_faceVertexIndices", textureDimFaces, textureDimFaces, "FLOAT", faceVertexIndices, true);
gpuMath.createProgram("positionCalc", vertexShader, document.getElementById("positionCalcShader").text);
......@@ -281,6 +290,7 @@ function initDynamicSolver(globals){
gpuMath.setUniformForProgram("velocityCalc", "u_creaseMeta2", 8, "1i");
gpuMath.setUniformForProgram("velocityCalc", "u_normals", 9, "1i");
gpuMath.setUniformForProgram("velocityCalc", "u_theta", 10, "1i");
gpuMath.setUniformForProgram("velocityCalc", "u_creaseGeo", 11, "1i");
gpuMath.setUniformForProgram("velocityCalc", "u_textureDim", [textureDim, textureDim], "2f");
gpuMath.setUniformForProgram("velocityCalc", "u_textureDimEdges", [textureDimEdges, textureDimEdges], "2f");
gpuMath.setUniformForProgram("velocityCalc", "u_textureDimFaces", [textureDimFaces, textureDimFaces], "2f");
......@@ -316,6 +326,13 @@ function initDynamicSolver(globals){
gpuMath.setUniformForProgram("centerTexture", "u_lastPosition", 0, "1i");
gpuMath.setUniformForProgram("centerTexture", "u_textureDim", [textureDim, textureDim], "2f");
gpuMath.createProgram("updateCreaseGeo", vertexShader, document.getElementById("updateCreaseGeo").text);
gpuMath.setUniformForProgram("updateCreaseGeo", "u_lastPosition", 0, "1i");
gpuMath.setUniformForProgram("updateCreaseGeo", "u_originalPosition", 1, "1i");
gpuMath.setUniformForProgram("updateCreaseGeo", "u_creaseMeta3", 2, "1i");
gpuMath.setUniformForProgram("updateCreaseGeo", "u_textureDim", [textureDim, textureDim], "2f");
gpuMath.setUniformForProgram("updateCreaseGeo", "u_textureDimCreases", [textureDimCreases, textureDimCreases], "2f");
gpuMath.setSize(textureDim, textureDim);
programsInited = true;
......@@ -437,7 +454,7 @@ function initDynamicSolver(globals){
for (var i=0;i<nodes.length;i++){
numNodeCreases += nodes[i].numCreases();
}
numNodeCreases += numCreases*2;
numNodeCreases += numCreases*2;//reactions
textureDimNodeCreases = calcTextureSize(numNodeCreases);
var numFaces = faces.length;
......@@ -457,6 +474,8 @@ function initDynamicSolver(globals){
faceVertexIndices = new Float32Array(textureDimFaces*textureDimFaces*4);
creaseMeta = new Float32Array(textureDimCreases*textureDimCreases*4);
creaseMeta2 = new Float32Array(textureDimNodeCreases*textureDimNodeCreases*4);
creaseMeta3 = new Float32Array(textureDimCreases*textureDimCreases*4);
creaseGeo = new Float32Array(textureDimCreases*textureDimCreases*4);
creaseVectors = new Float32Array(textureDimCreases*textureDimCreases*4);
theta = new Float32Array(textureDimCreases*textureDimCreases*4);
lastTheta = new Float32Array(textureDimCreases*textureDimCreases*4);
......@@ -492,8 +511,7 @@ function initDynamicSolver(globals){
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] = 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++;
}
......@@ -505,6 +523,14 @@ function initDynamicSolver(globals){
index++;
}
}
for (var i=0;i<creases.length;i++){
var crease = creases[i];
creaseMeta3[i*4] = crease.node1.getIndex();
creaseMeta3[i*4+1] = crease.node2.getIndex();
creaseMeta3[i*4+2] = crease.edge.nodes[0].getIndex();
creaseMeta3[i*4+3] = crease.edge.nodes[1].getIndex();
index++;
}
updateOriginalPosition();
updateMaterials(true);
......
......@@ -8,7 +8,7 @@ var nodeMaterialHighlight = new THREE.MeshBasicMaterial({color: 0xffffff, side:T
var transparentMaterial = new THREE.MeshBasicMaterial({color: 0xffffff, opacity:0.5, transparent:true});
var transparentVRMaterial = new THREE.MeshBasicMaterial({color: 0xeeeeee, opacity:0.8, transparent:true});
var nodeGeo = new THREE.SphereGeometry(0.04,20);
var nodeGeo = new THREE.SphereGeometry(0.02,20);
var nodeFixedGeo = new THREE.CubeGeometry(1, 1, 1);
function Node(position, index){
......@@ -150,7 +150,7 @@ Node.prototype.setTransparent = function(){
Node.prototype.setTransparentVR = function(){
this.object3D.material = transparentVRMaterial;
this.object3D.scale.set(0.2, 0.2, 0.2);
this.object3D.scale.set(0.4, 0.4, 0.4);
};
Node.prototype.hide = function(){
......
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