diff --git a/index.html b/index.html index f546f5ef5f33dcbefc9d538befbaea3414f9104d..430c6c0ac6528036c344cb563c1b68c477d45a5c 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 a6f544355d8f2f27729bd370dedec32ba8f89e22..fb29dbd06c34f0a341effda3ab470b5e00c6138b 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 248249cfef6e25f818f1ad0472e7de26bf6a4dd3..56f819cd3f720a23a6210000cad7f9402c32394c 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 bdaa3541a9c1b2d1a826a30826a5a52ae02b7161..930bcdb9de7163837f009f7c9eba96846dfc3ec4 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 e2c73331843f99dd24b48f3cebc5dd31845092a8..c6547274e7a51a46fe5211ce77a96645322870f7 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){