From e3e1c19285a520bb9a0b54e019543d44990438e8 Mon Sep 17 00:00:00 2001 From: amandaghassaei <amandaghassaei@gmail.com> Date: Wed, 1 Mar 2017 12:25:14 -0500 Subject: [PATCH] debugging --- index.html | 10 +++++----- js/GPUMath.js | 4 ++-- js/dynamicModel.js | 18 +++++++++--------- js/model.js | 9 +++++---- js/pattern.js | 3 +-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/index.html b/index.html index f546f5e..430c6c0 100644 --- a/index.html +++ b/index.html @@ -92,7 +92,7 @@ vec3 lastPosition = texture2D(u_lastPosition, scaledFragCoord).xyz; vec3 velocity = texture2D(u_velocity, scaledFragCoord).xyz; vec3 position = velocity*u_dt + lastPosition; - gl_FragColor = vec4(position,0.0); + gl_FragColor = vec4(position, 0.0); } </script> @@ -122,7 +122,7 @@ vec2 scaledFragCoord = fragCoord/u_textureDim; vec2 mass = texture2D(u_mass, scaledFragCoord).xy; - if (mass.y == 1.0){ + if (mass.y == 1.0){//fixed gl_FragColor = vec4(0.0); return; } @@ -154,7 +154,7 @@ deltaP -= normalize(deltaP)*beamMeta[2]; vec3 deltaV = neighborLastVelocity-lastVelocity; - vec3 _force = deltaP*beamMeta[0] + deltaV*beamMeta[1]; + vec3 _force = deltaP*beamMeta[0];// + deltaV*beamMeta[1]; force += _force; } @@ -183,7 +183,7 @@ vec2 scaledNormalsIndex = normalsIndex/u_textureDimFaces; vec3 normal = texture2D(u_normals, scaledNormalsIndex).xyz; - float angForce = creaseMeta[0]*(targetTheta-thetas[0]) + creaseMeta[1]*thetas[1];; + float angForce = creaseMeta[0]*(targetTheta-thetas[0]);// + creaseMeta[1]*thetas[1]; float momentArm = creaseMeta2[1]; vec3 _force = angForce/momentArm*normal; @@ -330,7 +330,7 @@ </div> <div id="controls"> <div class="sliderInput" id="creasePercent"> - <span class="label-slider">Crease Angle : </span><div class="flat-slider ui-slider ui-corner-all ui-slider-horizontal ui-widget ui-widget-content"></div> + <span class="label-slider">Crease Percent : </span><div class="flat-slider ui-slider ui-corner-all ui-slider-horizontal ui-widget ui-widget-content"></div> <input value="" placeholder="" class="form-control int" type="text"> </div> <br/><br/><br/> diff --git a/js/GPUMath.js b/js/GPUMath.js index a6f5443..fb29dbd 100644 --- a/js/GPUMath.js +++ b/js/GPUMath.js @@ -51,9 +51,9 @@ function initGPUMath(){ - GPUMath.prototype.initFrameBufferForTexture = function(textureName){ + GPUMath.prototype.initFrameBufferForTexture = function(textureName, shouldReplace){ var framebuffer = this.frameBuffers[textureName]; - if (framebuffer) { + if (framebuffer && (shouldReplace === undefined || !shouldReplace)) { console.warn("framebuffer already exists for texture " + textureName); return; } diff --git a/js/dynamicModel.js b/js/dynamicModel.js index 248249c..56f819c 100644 --- a/js/dynamicModel.js +++ b/js/dynamicModel.js @@ -57,6 +57,7 @@ function initDynamicModel(globals){ object3D.position.set(-avg.x, 0, -avg.z); initTypedArrays(); + if (firstTime === undefined) firstTime = false; initTexturesAndPrograms(globals.gpuMath, firstTime); steps = parseInt(setSolveParams()); } @@ -184,6 +185,7 @@ function initDynamicModel(globals){ for (var i = 0; i < nodes.length; i++) { var rgbaIndex = i * vectorLength; var nodePosition = new THREE.Vector3(parsedPixels[rgbaIndex], parsedPixels[rgbaIndex + 1], parsedPixels[rgbaIndex + 2]); + // console.log(nodePosition); nodes[i].render(nodePosition); } for (var i=0;i<edges.length;i++){ @@ -229,14 +231,12 @@ function initDynamicModel(globals){ gpuMath.initTextureFromData("u_theta", textureDimCreases, textureDimCreases, "FLOAT", theta, !firstTime); gpuMath.initTextureFromData("u_lastTheta", textureDimCreases, textureDimCreases, "FLOAT", lastTheta, !firstTime); - if (firstTime) { - gpuMath.initFrameBufferForTexture("u_position"); - gpuMath.initFrameBufferForTexture("u_lastPosition"); - gpuMath.initFrameBufferForTexture("u_velocity"); - gpuMath.initFrameBufferForTexture("u_lastVelocity"); - gpuMath.initFrameBufferForTexture("u_theta"); - gpuMath.initFrameBufferForTexture("u_lastTheta"); - } + gpuMath.initFrameBufferForTexture("u_position", !firstTime); + gpuMath.initFrameBufferForTexture("u_lastPosition", !firstTime); + gpuMath.initFrameBufferForTexture("u_velocity", !firstTime); + gpuMath.initFrameBufferForTexture("u_lastVelocity", !firstTime); + gpuMath.initFrameBufferForTexture("u_theta", !firstTime); + gpuMath.initFrameBufferForTexture("u_lastTheta", !firstTime); gpuMath.initTextureFromData("u_meta", textureDim, textureDim, "FLOAT", meta, true); gpuMath.initTextureFromData("u_creaseMeta2", textureDimNodeCreases, textureDimNodeCreases, "FLOAT", creaseMeta2, true); @@ -275,7 +275,7 @@ function initDynamicModel(globals){ gpuMath.createProgram("packToBytes", vertexShader, document.getElementById("packToBytesShader").text); gpuMath.initTextureFromData("outputBytes", textureDim*4, textureDim, "UNSIGNED_BYTE", null, !firstTime); - if (firstTime) gpuMath.initFrameBufferForTexture("outputBytes"); + gpuMath.initFrameBufferForTexture("outputBytes", !firstTime); gpuMath.setUniformForProgram("packToBytes", "u_floatTextureDim", [textureDim, textureDim], "2f"); gpuMath.createProgram("zeroTexture", vertexShader, document.getElementById("zeroTexture").text); diff --git a/js/model.js b/js/model.js index bdaa354..930bcdb 100644 --- a/js/model.js +++ b/js/model.js @@ -28,15 +28,16 @@ function initModel(globals){ var creases = []; creases.push(new Crease(edges[2], 1, 0, Math.PI/2, 1, nodes[3], nodes[1], 0)); - function buildModel(_faces, _vertices, _allEdges, allCreaseParams, numOutline, numMountians, numValleys, numCuts){ + function buildModel(_faces, _vertices, _allEdges, allCreaseParams){ var _nodes = []; for (var i=0;i<_vertices.length;i++){ _nodes.push(new Node(_vertices[i].clone(), _nodes.length)); } - _nodes[0].setFixed(true); - _nodes[1].setFixed(true); - _nodes[2].setFixed(true); + console.log(_faces[0]); + _nodes[_faces[0].a].setFixed(true); + _nodes[_faces[0].b].setFixed(true); + _nodes[_faces[0].c].setFixed(true); var _edges = []; for (var i=0;i<_allEdges.length;i++) { diff --git a/js/pattern.js b/js/pattern.js index e2c7333..c654727 100644 --- a/js/pattern.js +++ b/js/pattern.js @@ -167,8 +167,7 @@ function initPattern(globals){ var allCreaseParams = getFacesAndVerticesForEdges(faces, allEdges); - globals.model.buildModel(faces, vertices, allEdges, allCreaseParams, outlines.length, outlines.length+mountains.length, - outlines.length+mountains.length+valleys.length, outlines.length+mountains.length+valleys.length+cuts.length); + globals.model.buildModel(faces, vertices, allEdges, allCreaseParams); } function getFacesAndVerticesForEdges(faces, allEdges){ -- GitLab