Commit 7945e46a authored by amandaghassaei's avatar amandaghassaei
Browse files

update crease vectors

parent 6e437fa9
......@@ -223,11 +223,14 @@
<script id="thetaCalcShader" type="x-shader/x-fragment">
#define TWO_PI 6.283185307179586476925286766559
precision mediump float;
uniform vec2 u_textureDim;
uniform vec2 u_textureDimFaces;
uniform vec2 u_textureDimCreases;
uniform sampler2D u_normals;
uniform sampler2D u_lastTheta;
uniform sampler2D u_creaseVectors;
uniform sampler2D u_lastPosition;
uniform sampler2D u_originalPosition;
uniform float u_dt;
void main(){
......@@ -254,7 +257,17 @@
if (dotNormals < -1.0) dotNormals = -1.0;
else if (dotNormals > 1.0) dotNormals = 1.0;
float theta = acos(dotNormals);
vec3 creaseVector = texture2D(u_creaseVectors, scaledFragCoord).xyz;
vec2 creaseVectorIndices = texture2D(u_creaseVectors, scaledFragCoord).xy;
vec2 creaseNodeIndex = vec2(mod(creaseVectorIndices[0], u_textureDim.x)+0.5, floor(creaseVectorIndices[0]/u_textureDim.x)+0.5);
vec2 scaledNodeIndex = creaseNodeIndex/u_textureDim;
vec3 node0 = texture2D(u_lastPosition, scaledNodeIndex).xyz + texture2D(u_originalPosition, scaledNodeIndex).xyz;
creaseNodeIndex = vec2(mod(creaseVectorIndices[1], u_textureDim.x)+0.5, floor(creaseVectorIndices[1]/u_textureDim.x)+0.5);
scaledNodeIndex = creaseNodeIndex/u_textureDim;
vec3 node1 = texture2D(u_lastPosition, scaledNodeIndex).xyz + texture2D(u_originalPosition, scaledNodeIndex).xyz;
vec3 creaseVector = node0-node1;
float sign = dot(cross(normal1, normal2), creaseVector);
if (sign < 0.0) theta *= -1.0;
float diff = theta-lastTheta[0];
......
......@@ -33,7 +33,7 @@ function initDynamicModel(globals){
var creaseMeta;//[k, d, targetTheta]
var creaseMeta2;//[creaseIndex (thetaIndex), length to node, nodeIndex (1/2), ]
//[creaseIndex (thetaIndex), length to node1, length to node2, -1]
var creaseVectors;//vectors of oriented edges in crease
var creaseVectors;//indices of crease nodes
var theta;//[theta, w, normalIndex1, normalIndex2]
var lastTheta;//[theta, w, normalIndex1, normalIndex2]
......@@ -150,7 +150,7 @@ function initDynamicModel(globals){
gpuMath.setProgram("thetaCalc");
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_lastPosition", "u_originalPosition"], "u_theta");
gpuMath.setProgram("velocityCalc");
gpuMath.setSize(textureDim, textureDim);
......@@ -165,23 +165,23 @@ function initDynamicModel(globals){
function render(){
var vectorLength = 1;
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);
console.log(parsedPixels);
} else {
console.log("here");
}
// 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);
// console.log(parsedPixels);
// } else {
// console.log("here");
// }
var vectorLength = 3;
globals.gpuMath.setProgram("packToBytes");
......@@ -287,6 +287,9 @@ function initDynamicModel(globals){
gpuMath.setUniformForProgram("thetaCalc", "u_normals", 0, "1i");
gpuMath.setUniformForProgram("thetaCalc", "u_lastTheta", 1, "1i");
gpuMath.setUniformForProgram("thetaCalc", "u_creaseVectors", 2, "1i");
gpuMath.setUniformForProgram("thetaCalc", "u_lastPosition", 3, "1i");
gpuMath.setUniformForProgram("thetaCalc", "u_originalPosition", 4, "1i");
gpuMath.setUniformForProgram("thetaCalc", "u_textureDim", [textureDim, textureDim], "2f");
gpuMath.setUniformForProgram("thetaCalc", "u_textureDimFaces", [textureDimFaces, textureDimFaces], "2f");
gpuMath.setUniformForProgram("thetaCalc", "u_textureDimCreases", [textureDimCreases, textureDimCreases], "2f");
......@@ -375,10 +378,13 @@ function initDynamicModel(globals){
function updateCreaseVectors(){
for (var i=0;i<creases.length;i++){
var rgbaIndex = i*4;
var vector = creases[i].getVector();
creaseVectors[rgbaIndex] = -vector.x;
creaseVectors[rgbaIndex+1] = -vector.y;
creaseVectors[rgbaIndex+2] = -vector.z;
var nodes = creases[i].edge.nodes;
// this.vertices[1].clone().sub(this.vertices[0]);
creaseVectors[rgbaIndex] =nodes[0];
creaseVectors[rgbaIndex+1] = nodes[1];
// creaseVectors[rgbaIndex] = -vector.x;
// creaseVectors[rgbaIndex+1] = -vector.y;
// creaseVectors[rgbaIndex+2] = -vector.z;
}
globals.gpuMath.initTextureFromData("u_creaseVectors", textureDimCreases, textureDimCreases, "FLOAT", creaseVectors, true);
}
......
......@@ -42,11 +42,11 @@ function initModel(globals){
// faces.push(new THREE.Face3(3,4,0));
var creases = [];
creases.push(new Crease(edges[2], 0, 1, Math.PI-0.001, 1, nodes[1], nodes[3], 0));
creases.push(new Crease(edges[4], 2, 1, -(Math.PI-0.001), 1, nodes[4], nodes[0], 1));
creases.push(new Crease(edges[2], 0, 1, Math.PI, 1, nodes[1], nodes[3], 0));
creases.push(new Crease(edges[4], 2, 1, Math.PI, 1, nodes[4], nodes[0], 1));
// creases.push(new Crease(edges[5], 3, 2, -(Math.PI-0.001), 1, nodes[3], nodes[1], 1));
// creases.push(new Crease(edges[0], 3, 0, (Math.PI-0.001), 1, nodes[4], nodes[2], 2));
// creases.push(new Crease(edges[5], 3, 2, Math.PI, 1, nodes[3], nodes[1], 1));
// creases.push(new Crease(edges[0], 3, 0, Math.PI, 1, nodes[4], nodes[2], 2));
var _allNodeObject3Ds = [];
......
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