Commit ff6a05c4 authored by amandaghassaei's avatar amandaghassaei
Browse files

adding limits on theta

parent 6204f95e
...@@ -165,7 +165,7 @@ ...@@ -165,7 +165,7 @@
float nodeCreaseIndex1D = meta[2]+float(j); float nodeCreaseIndex1D = meta[2]+float(j);
vec2 nodeCreaseIndex = vec2(mod(nodeCreaseIndex1D, u_textureDimNodeCreases.x)+0.5, floor(nodeCreaseIndex1D/u_textureDimNodeCreases.x)+0.5); vec2 nodeCreaseIndex = vec2(mod(nodeCreaseIndex1D, u_textureDimNodeCreases.x)+0.5, floor(nodeCreaseIndex1D/u_textureDimNodeCreases.x)+0.5);
vec2 scaledNodeCreaseIndex = nodeCreaseIndex/u_textureDimNodeCreases; vec2 scaledNodeCreaseIndex = nodeCreaseIndex/u_textureDimNodeCreases;
vec4 creaseMeta2 = texture2D(u_creaseMeta2, scaledNodeCreaseIndex); vec4 creaseMeta2 = texture2D(u_creaseMeta2, scaledNodeCreaseIndex);//[creaseIndex, length to node, nodeIndex (1/2)]
float creaseIndex1D = creaseMeta2[0]; float creaseIndex1D = creaseMeta2[0];
vec2 creaseIndex = vec2(mod(creaseIndex1D, u_textureDimCreases.x)+0.5, floor(creaseIndex1D/u_textureDimCreases.x)+0.5); vec2 creaseIndex = vec2(mod(creaseIndex1D, u_textureDimCreases.x)+0.5, floor(creaseIndex1D/u_textureDimCreases.x)+0.5);
...@@ -175,10 +175,10 @@ ...@@ -175,10 +175,10 @@
vec3 creaseMeta = texture2D(u_creaseMeta, scaledCreaseIndex).xyz;//[k, d, targetTheta] vec3 creaseMeta = texture2D(u_creaseMeta, scaledCreaseIndex).xyz;//[k, d, targetTheta]
float nodeNum = creaseMeta2[2]; float nodeNum = creaseMeta2[2];
float normalIndex1D = thetas[2]; float normalIndex1D = thetas[2];//node #1
float targetTheta = creaseMeta[2] *= u_creasePercent; float targetTheta = creaseMeta[2] * u_creasePercent;
if (nodeNum > 1.1) { if (nodeNum > 1.1) {
normalIndex1D = thetas[3]; normalIndex1D = thetas[3];//node #2
} }
vec2 normalsIndex = vec2(mod(normalIndex1D, u_textureDimFaces.x)+0.5, floor(normalIndex1D/u_textureDimFaces.x)+0.5); vec2 normalsIndex = vec2(mod(normalIndex1D, u_textureDimFaces.x)+0.5, floor(normalIndex1D/u_textureDimFaces.x)+0.5);
vec2 scaledNormalsIndex = normalsIndex/u_textureDimFaces; vec2 scaledNormalsIndex = normalsIndex/u_textureDimFaces;
...@@ -188,15 +188,16 @@ ...@@ -188,15 +188,16 @@
float momentArm = creaseMeta2[1]; float momentArm = creaseMeta2[1];
vec3 _force = angForce/momentArm*normal; vec3 _force = angForce/momentArm*normal;
//force += _force; force += _force;
} }
vec3 velocity = force*u_dt/mass.x + lastVelocity; vec3 velocity = force*u_dt/mass[0] + lastVelocity;
gl_FragColor = vec4(velocity,0.0); gl_FragColor = vec4(velocity,0.0);
} }
</script> </script>
<script id="thetaCalcShader" type="x-shader/x-fragment"> <script id="thetaCalcShader" type="x-shader/x-fragment">
#define M_PI 3.1415926535897932384626433832795
precision mediump float; precision mediump float;
uniform vec2 u_textureDimFaces; uniform vec2 u_textureDimFaces;
uniform vec2 u_textureDimCreases; uniform vec2 u_textureDimCreases;
...@@ -212,7 +213,7 @@ ...@@ -212,7 +213,7 @@
vec4 lastTheta = texture2D(u_lastTheta, scaledFragCoord); vec4 lastTheta = texture2D(u_lastTheta, scaledFragCoord);
if (lastTheta[2]<0.0){ if (lastTheta[2]<0.0){
gl_FragColor = vec4(0.0, 0.0, -1.0, -1.0); gl_FragColor = vec4(lastTheta[0], 0.0, -1.0, -1.0);
return; return;
} }
...@@ -228,6 +229,11 @@ ...@@ -228,6 +229,11 @@
vec3 creaseVector = texture2D(u_creaseVectors, scaledFragCoord).xyz; vec3 creaseVector = texture2D(u_creaseVectors, scaledFragCoord).xyz;
float sign = dot(cross(normal1, normal2), creaseVector); float sign = dot(cross(normal1, normal2), creaseVector);
if (sign < 0.0) theta *= -1.0; if (sign < 0.0) theta *= -1.0;
if (lastTheta[1] < 0.0){//decreasing
if (theta > 1.0 && lastTheta[0] < -1.0) theta -= 2.0*M_PI*(1.0+mod(lastTheta[0], 2.0*M_PI));
} else {//increasing
if (theta < -1.0 && lastTheta[0] > 1.0) theta += 2.0*M_PI*(1.0+mod(lastTheta[0], 2.0*M_PI));
}
gl_FragColor = vec4(theta, theta-lastTheta[0], lastTheta[2], lastTheta[3]);//[theta, w, normal1Index, normal2Index] gl_FragColor = vec4(theta, theta-lastTheta[0], lastTheta[2], lastTheta[3]);//[theta, w, normal1Index, normal2Index]
} }
</script> </script>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by ghassaei on 9/16/16. * Created by ghassaei on 9/16/16.
*/ */
var beamMaterialHighlight = new THREE.LineBasicMaterial({color: 0xffffff, linewidth: 4}); var beamMaterialHighlight = new THREE.LineBasicMaterial({color: 0xff0000, linewidth: 4});
var beamMaterial = new THREE.LineBasicMaterial({color: 0x000000, linewidth: 4}); var beamMaterial = new THREE.LineBasicMaterial({color: 0x000000, linewidth: 4});
function Beam(nodes){ function Beam(nodes){
......
...@@ -54,8 +54,8 @@ function initDynamicModel(globals){ ...@@ -54,8 +54,8 @@ function initDynamicModel(globals){
var bounds = geometry.boundingBox; var bounds = geometry.boundingBox;
var avg = (bounds.min.add(bounds.max)).multiplyScalar(-0.5); var avg = (bounds.min.add(bounds.max)).multiplyScalar(-0.5);
object3D.position.set(avg.x, 0, avg.z); // object3D.position.set(avg.x, 0, avg.z);
globals.threeView.centerModel(avg); // globals.threeView.centerModel(avg);
initTypedArrays(); initTypedArrays();
...@@ -143,6 +143,8 @@ function initDynamicModel(globals){ ...@@ -143,6 +143,8 @@ function initDynamicModel(globals){
gpuMath.setSize(textureDimCreases, textureDimCreases); gpuMath.setSize(textureDimCreases, textureDimCreases);
gpuMath.step("thetaCalc", ["u_normals", "u_lastTheta", "u_creaseVectors"], "u_theta"); gpuMath.step("thetaCalc", ["u_normals", "u_lastTheta", "u_creaseVectors"], "u_theta");
gpuMath.setProgram("velocityCalc");
gpuMath.setSize(textureDim, textureDim);
gpuMath.step("velocityCalc", ["u_lastPosition", "u_lastVelocity", "u_originalPosition", "u_externalForces", 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_velocity");
gpuMath.step("positionCalc", ["u_velocity", "u_lastPosition", "u_mass"], "u_position"); gpuMath.step("positionCalc", ["u_velocity", "u_lastPosition", "u_mass"], "u_position");
...@@ -165,8 +167,8 @@ function initDynamicModel(globals){ ...@@ -165,8 +167,8 @@ function initDynamicModel(globals){
// var pixels = new Uint8Array(height*textureDimCreases*4*vectorLength); // var pixels = new Uint8Array(height*textureDimCreases*4*vectorLength);
// globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels); // globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels);
// var parsedPixels = new Float32Array(pixels.buffer); // var parsedPixels = new Float32Array(pixels.buffer);
// for (var i = 0; i < creases.length; i++) { // for (var i = 0; i < 1; i++) {
// // console.log(parsedPixels[i]) // console.log(parsedPixels[i])
// } // }
// } else { // } else {
// console.log("here"); // console.log("here");
......
...@@ -33,6 +33,7 @@ $(function() { ...@@ -33,6 +33,7 @@ $(function() {
draggingNode = null; draggingNode = null;
globals.fixedHasChanged = true; globals.fixedHasChanged = true;
globals.threeView.enableControls(true); globals.threeView.enableControls(true);
setHighlightedObj(null);
} }
mouseDown = false; mouseDown = false;
}, false); }, false);
......
...@@ -19,7 +19,7 @@ function initModel(globals){ ...@@ -19,7 +19,7 @@ function initModel(globals){
var edges = []; var edges = [];
edges.push(new Beam([nodes[0], nodes[1]])); edges.push(new Beam([nodes[0], nodes[1]]));
edges.push(new Beam([nodes[1], nodes[2]])); edges.push(new Beam([nodes[1], nodes[2]]));
edges.push(new Beam([nodes[0], nodes[2]])); edges.push(new Beam([nodes[2], nodes[0]]));
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]]));
...@@ -28,7 +28,7 @@ function initModel(globals){ ...@@ -28,7 +28,7 @@ function initModel(globals){
faces.push(new THREE.Face3(0,2,3)); faces.push(new THREE.Face3(0,2,3));
var creases = []; var creases = [];
creases.push(new Crease(edges[2], 1, 0, Math.PI/2, 1, nodes[3], nodes[1], 0)); creases.push(new Crease(edges[2], 0, 1, Math.PI/2, 1, nodes[1], nodes[3], 0));
function buildModel(_faces, _vertices, _allEdges, allCreaseParams){ function buildModel(_faces, _vertices, _allEdges, allCreaseParams){
...@@ -46,8 +46,9 @@ function initModel(globals){ ...@@ -46,8 +46,9 @@ function initModel(globals){
} }
var _creases = []; var _creases = [];
for (var i=0;i<allCreaseParams.length;i++) { for (var i=0;i<1;i++) {
var creaseParams = allCreaseParams[i];//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle var creaseParams = allCreaseParams[i];//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle
_edges[creaseParams[4]].highlight();
_creases.push(new Crease(_edges[creaseParams[4]], creaseParams[0], creaseParams[2], creaseParams[5], 1, _nodes[creaseParams[1]], _nodes[creaseParams[3]], _creases.length)); _creases.push(new Crease(_edges[creaseParams[4]], creaseParams[0], creaseParams[2], creaseParams[5], 1, _nodes[creaseParams[1]], _nodes[creaseParams[3]], _creases.length));
} }
......
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