Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
amandaghassaei committed Apr 29, 2018
1 parent 97cacfb commit f9af774
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 31 deletions.
46 changes: 46 additions & 0 deletions CreasePatternScripts/ReschTess/ReschTess.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import processing.pdf.*;

float edgeLength = 40;

void setup() {

//20in*72dpi= 1440px
size(600, 600, PDF, "resch.pdf");
background(255);

pushMatrix();
translate(edgeLength, edgeLength);
int size = 10;
for (int i=0;i<size;i++){
for (int j=0;j<size;j++){
pushMatrix();
float yOffset = j*edgeLength*3.0/2.0;
if (i%2==1) yOffset -= (edgeLength+edgeLength/2.0)/2.0;
translate(i*edgeLength*3.0/4.0*sqrt(3), yOffset);
drawTriangle();
popMatrix();
}
}


exit();

}

void drawTriangle(){
stroke(255, 0, 0, 255.0/2.0);//50%
line(0, -edgeLength, edgeLength/2*sqrt(3), edgeLength/2);
line(0, -edgeLength, -edgeLength/2*sqrt(3), edgeLength/2);
line(edgeLength/2*sqrt(3), edgeLength/2, 0, edgeLength/2);
line(-edgeLength/2*sqrt(3), edgeLength/2, 0, edgeLength/2);

stroke(255, 0, 0, 255.0/3.0);//33%
line(0,0,edgeLength/4*sqrt(3), (-edgeLength+edgeLength/2)/2);
line(0,0,-edgeLength/4*sqrt(3), (-edgeLength+edgeLength/2)/2);
line(0,0,0,edgeLength/2);

stroke(0, 0, 255);
line(0, -edgeLength, 0, 0);
line(0, 0, -edgeLength/2*sqrt(3), edgeLength/2);
line(0, 0, edgeLength/2*sqrt(3), edgeLength/2);
}
2 changes: 2 additions & 0 deletions CreasePatternScripts/ReschTess/sketch.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mode.id=processing.mode.java.JavaMode
mode=Java
11 changes: 8 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
uniform sampler2D u_meta2;//[nodesFaceIndex, numFaces]
uniform sampler2D u_nodeFaceMeta;//[faceIndex, a, b, c]
uniform sampler2D u_nominalTriangles;//[angleA, angleB, angleC]
uniform bool u_calcFaceStrain;

vec4 getFromArray(float index1D, vec2 dimensions, sampler2D tex){
vec2 index = vec2(mod(index1D, dimensions.x)+0.5, floor(index1D/dimensions.x)+0.5);
Expand Down Expand Up @@ -252,13 +253,13 @@
vec3 deltaP = neighborLastPosition-lastPosition+nominalDist;
float deltaPLength = length(deltaP);
deltaP -= deltaP*(beamMeta[2]/deltaPLength);
nodeError += abs(deltaPLength/length(nominalDist) - 1.0);
if (!u_calcFaceStrain) nodeError += abs(deltaPLength/length(nominalDist) - 1.0);
vec3 deltaV = neighborLastVelocity-lastVelocity;

vec3 _force = deltaP*beamMeta[0] + deltaV*beamMeta[1];
force += _force;
}
nodeError /= meta[1];
if (!u_calcFaceStrain) nodeError /= meta[1];

for (int j=0;j<100;j++){//for all creases (up to 100, had to put a const int in here)
if (j >= int(meta[3])) break;
Expand Down Expand Up @@ -358,23 +359,27 @@
vec3 normalCrossAC = cross(normal, ac)/lengthAC;
vec3 normalCrossAB = cross(normal, ab)/lengthAB;
force -= anglesDiff[0]*(normalCrossAC - normalCrossAB);
if (u_calcFaceStrain) nodeError += abs((nominalAngles[0]-angles[0])/nominalAngles[0]);
force -= anglesDiff[1]*normalCrossAB;
force += anglesDiff[2]*normalCrossAC;
} else if (faceIndex == 1){
vec3 normalCrossAB = cross(normal, ab)/lengthAB;
vec3 normalCrossBC = cross(normal, bc)/lengthBC;
force -= anglesDiff[0]*normalCrossAB;
force += anglesDiff[1]*(normalCrossAB + normalCrossBC);
if (u_calcFaceStrain) nodeError += abs((nominalAngles[1]-angles[1])/nominalAngles[1]);
force -= anglesDiff[2]*normalCrossBC;
} else if (faceIndex == 2){
vec3 normalCrossAC = cross(normal, ac)/lengthAC;
vec3 normalCrossBC = cross(normal, bc)/lengthBC;
force += anglesDiff[0]*normalCrossAC;
force -= anglesDiff[1]*normalCrossBC;
force += anglesDiff[2]*(normalCrossBC - normalCrossAC);
if (u_calcFaceStrain) nodeError += abs((nominalAngles[2]-angles[2])/nominalAngles[2]);
}

}
if (u_calcFaceStrain) nodeError /= meta2[1];

vec3 velocity = force*u_dt/mass[0] + lastVelocity;
gl_FragColor = vec4(velocity,nodeError);
Expand Down Expand Up @@ -1197,7 +1202,7 @@
</div>
<div id="controlsToggle" class="bigToggle">
<div>
<a href="#" id="orbitToggle"><div class="active"><img class="preserveAspect" src="assets/rotateSmall.png"/><span>Rotate 3D</span></div></a><div class="separator"></div><a href="#" id="grabToggle"><div><img class="preserveAspect" src="assets/grabSmall.png"/><span>Grab</span></div></a>
<a href="#" id="orbitToggle"><div class="active"><img class="preserveAspect" src="assets/rotateSmall.png"/><span>Rotate</span></div></a><div class="separator"></div><a href="#" id="grabToggle"><div><img class="preserveAspect" src="assets/grabSmall.png"/><span>Grab</span></div></a>
</div>
Control Mode
</div>
Expand Down
28 changes: 2 additions & 26 deletions js/dynamic/dynamicSolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,33 +183,8 @@ function initDynamicSolver(globals){
return avgPosition;
}

window.ke = [];

function render(){

// var vectorLength = 2;
// globals.gpuMath.setProgram("packToBytes");
// globals.gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
// globals.gpuMath.setUniformForProgram("packToBytes", "u_floatTextureDim", [textureDimCreases, textureDimCreases], "2f");
// globals.gpuMath.setSize(textureDimCreases*vectorLength, textureDimCreases);
// globals.gpuMath.step("packToBytes", ["u_lastTheta"], "outputBytes");
//
// if (globals.gpuMath.readyToRead()) {
// var numPixels = nodes.length*vectorLength;
// var height = Math.ceil(numPixels/(textureDimCreases*vectorLength));
// var pixels = new Uint8Array(height*textureDimCreases*4*vectorLength);
// globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels);
// var parsedPixels = new Float32Array(pixels.buffer);
// for (var i=0;i<parsedPixels.length;i+=2){
// if (Math.abs(parsedPixels[i+1])>Math.PI-1) {
// console.log(parsedPixels[i+1]);//theta
// }
//
// }
// } else {
// console.log("here");
// }

var vectorLength = 4;
globals.gpuMath.setProgram("packToBytes");
globals.gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
Expand Down Expand Up @@ -244,7 +219,6 @@ function initDynamicSolver(globals){
colors[3*i+2] = color.b;
}
}
window.ke.push(globalError);
$errorOutput.html((globalError/nodes.length).toFixed(7) + " %");
} else {
console.log("shouldn't be here");
Expand Down Expand Up @@ -345,6 +319,7 @@ function initDynamicSolver(globals){
gpuMath.setUniformForProgram("velocityCalc", "u_creasePercent", globals.creasePercent, "1f");
gpuMath.setUniformForProgram("velocityCalc", "u_axialStiffness", globals.axialStiffness, "1f");
gpuMath.setUniformForProgram("velocityCalc", "u_faceStiffness", globals.faceStiffness, "1f");
gpuMath.setUniformForProgram("velocityCalc", "u_calcFaceStrain", globals.calcFaceStrain, "1f");

gpuMath.createProgram("positionCalcVerlet", vertexShader, document.getElementById("positionCalcVerletShader").text);
gpuMath.setUniformForProgram("positionCalcVerlet", "u_lastPosition", 0, "1i");
Expand Down Expand Up @@ -372,6 +347,7 @@ function initDynamicSolver(globals){
gpuMath.setUniformForProgram("positionCalcVerlet", "u_creasePercent", globals.creasePercent, "1f");
gpuMath.setUniformForProgram("positionCalcVerlet", "u_axialStiffness", globals.axialStiffness, "1f");
gpuMath.setUniformForProgram("positionCalcVerlet", "u_faceStiffness", globals.faceStiffness, "1f");
gpuMath.setUniformForProgram("positionCalcVerlet", "u_calcFaceStrain", globals.calcFaceStrain, "1f");

gpuMath.createProgram("thetaCalc", vertexShader, document.getElementById("thetaCalcShader").text);
gpuMath.setUniformForProgram("thetaCalc", "u_normals", 0, "1i");
Expand Down
1 change: 1 addition & 0 deletions js/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function initGlobals(){

//view
colorMode: "color",
calcFaceStrain: false,
color1: "ec008b",
color2: "dddddd",
edgesVisible: true,
Expand Down
4 changes: 2 additions & 2 deletions js/saveSTL.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ function saveOBJ(){
obj += "#e " + (edge[0]+1) + " " + (edge[1]+1) + " ";
if (fold.edges_assignment[i] == "F") obj += 1;
else if (fold.edges_assignment[i] == "B") obj += 0;
else if (fold.edges_assignment[i] == "M") obj += 2;
else if (fold.edges_assignment[i] == "V") obj += 3;
else if (fold.edges_assignment[i] == "M") obj += 3;
else if (fold.edges_assignment[i] == "V") obj += 2;
else {
console.log("don't know how to convert type " + fold.edges_assignment[i]);
obj += 0;
Expand Down

0 comments on commit f9af774

Please sign in to comment.