Commit f8d44b53 authored by amandaghassaei's avatar amandaghassaei
Browse files

start stop reset

parent eed5b668
...@@ -309,3 +309,13 @@ svg{ ...@@ -309,3 +309,13 @@ svg{
#aboutStiffness{ #aboutStiffness{
line-height: 28px; line-height: 28px;
} }
#start, #stepForwardOptions{
display: none;
}
#reset{
margin-left: 20px;
}
#stepForward{
margin-left: 13px;
}
...@@ -460,8 +460,18 @@ ...@@ -460,8 +460,18 @@
<div class="indent"> <div class="indent">
<label>Average node error: <span id="globalError"></span></label> <label>Average node error: <span id="globalError"></span></label>
<a class="about floatRight" href="#" id="aboutError"><span class="fui-question-circle"></span></a> <a class="about floatRight" href="#" id="aboutError"><span class="fui-question-circle"></span></a>
</div><br/>
<b>Animation Settings:</b><br/>
<span class="floatRight">&Delta; t = <span id="deltaT"></span> seconds</span><br/><br/>
<a href="#" id="reset" class="btn btn-lg btn-default">Reset</a>
<a href="#" id="start" class="btn btn-lg btn-success">Start Simulation</a>
<a href="#" id="pause" class="btn btn-lg btn-warning">Pause Simulation</a>
<br/><br/>
<div id="stepForwardOptions" class="floatRight">
Num Steps: &nbsp;&nbsp;<input id="numSteps" value="100" placeholder="" class="form-control" type="text">
<a href="#" id="stepForward" class="btn btn-lg btn-default">Step Forward</a>
</div> </div>
<br/><br/>
<div class="extraSpace"></div> <div class="extraSpace"></div>
</div> </div>
<div id="svgViewer"></div> <div id="svgViewer"></div>
......
...@@ -409,6 +409,32 @@ function initControls(globals){ ...@@ -409,6 +409,32 @@ function initControls(globals){
$("#aboutAxialStrainModal").modal("show"); $("#aboutAxialStrainModal").modal("show");
}); });
setLink("#start", function(){
$("#pause").show();
$("#reset").show();
$("#start").hide();
$("#stepForwardOptions").hide();
globals.model.resume();
});
setLink("#pause", function(){
$("#start").show();
$("#stepForwardOptions").show();
$("#pause").hide();
globals.model.pause();
});
setLink("#reset", function(){
if (!globals.threeView.running()) $("#reset").hide();
globals.model.reset();
});
setLink("#stepForward", function(){
var numSteps = $("#numSteps").val();
numSteps = parseInt(numSteps);
if (isNaN(numSteps)) return;
if (numSteps<=0) return;
$("#numSteps").val(numSteps);
globals.model.step(numSteps);
});
setInput("#strainClip", globals.strainClip, function(val){ setInput("#strainClip", globals.strainClip, function(val){
globals.strainClip = val; globals.strainClip = val;
}, 0.0001, 100); }, 0.0001, 100);
......
...@@ -61,6 +61,7 @@ function initDynamicSolver(globals){ ...@@ -61,6 +61,7 @@ function initDynamicSolver(globals){
globals.gpuMath.step("zeroTexture", [], "u_lastPosition"); globals.gpuMath.step("zeroTexture", [], "u_lastPosition");
globals.gpuMath.step("zeroTexture", [], "u_velocity"); globals.gpuMath.step("zeroTexture", [], "u_velocity");
globals.gpuMath.step("zeroTexture", [], "u_lastVelocity"); globals.gpuMath.step("zeroTexture", [], "u_lastVelocity");
render();
//todo zero thetas //todo zero thetas
// for (var i=0;i<creases.length;i++){ // for (var i=0;i<creases.length;i++){
// lastTheta[i*4] = 0; // lastTheta[i*4] = 0;
...@@ -68,10 +69,9 @@ function initDynamicSolver(globals){ ...@@ -68,10 +69,9 @@ function initDynamicSolver(globals){
// } // }
} }
function solve(){ function solve(_numSteps){
if (globals.shouldSyncWithModel){ if (globals.shouldSyncWithModel){
syncNodesAndEdges(); syncNodesAndEdges();
// reset();
globals.shouldSyncWithModel = false; globals.shouldSyncWithModel = false;
} else { } else {
if (globals.forceHasChanged) { if (globals.forceHasChanged) {
...@@ -94,17 +94,14 @@ function initDynamicSolver(globals){ ...@@ -94,17 +94,14 @@ function initDynamicSolver(globals){
updateMaterials(); updateMaterials();
globals.materialHasChanged = false; globals.materialHasChanged = false;
} }
if (globals.shouldResetDynamicSim) {
reset();
globals.shouldResetDynamicSim = false;
}
if (globals.shouldChangeCreasePercent) { if (globals.shouldChangeCreasePercent) {
setCreasePercent(globals.creasePercent); setCreasePercent(globals.creasePercent);
globals.shouldChangeCreasePercent = false; globals.shouldChangeCreasePercent = false;
} }
} }
for (var j=0;j<steps;j++){ if (_numSteps == undefined) _numSteps = steps;
for (var j=0;j<_numSteps;j++){
solveStep(); solveStep();
} }
render(); render();
...@@ -200,6 +197,7 @@ function initDynamicSolver(globals){ ...@@ -200,6 +197,7 @@ function initDynamicSolver(globals){
function setSolveParams(){ function setSolveParams(){
var dt = calcDt()/10;//todo factor of ten? var dt = calcDt()/10;//todo factor of ten?
$("#deltaT").html(dt);
var numSteps = 0.5/dt; var numSteps = 0.5/dt;
globals.gpuMath.setProgram("thetaCalc"); globals.gpuMath.setProgram("thetaCalc");
globals.gpuMath.setUniformForProgram("thetaCalc", "u_dt", dt, "1f"); globals.gpuMath.setUniformForProgram("thetaCalc", "u_dt", dt, "1f");
...@@ -494,6 +492,7 @@ function initDynamicSolver(globals){ ...@@ -494,6 +492,7 @@ function initDynamicSolver(globals){
return { return {
syncNodesAndEdges: syncNodesAndEdges, syncNodesAndEdges: syncNodesAndEdges,
updateFixed: updateFixed, updateFixed: updateFixed,
solve: solve solve: solve,
reset: reset
} }
} }
\ No newline at end of file
...@@ -52,7 +52,8 @@ function initGlobals(){ ...@@ -52,7 +52,8 @@ function initGlobals(){
//save stl settings //save stl settings
filename: null, filename: null,
extension: null, extension: null,
doublesidedSTL: false doublesidedSTL: false,
scale: 1
}; };
......
...@@ -126,6 +126,32 @@ function initModel(globals){ ...@@ -126,6 +126,32 @@ function initModel(globals){
startSolver(); startSolver();
} }
function reset(){
if (globals.simType == "dynamic"){
globals.dynamicSolver.reset();
} else {
globals.staticSolver.reset();
}
setGeoUpdates();
globals.threeView.render();
}
function step(numSteps){
if (globals.simType == "dynamic"){
globals.dynamicSolver.solve(numSteps);
} else {
globals.staticSolver.step(numSteps);
}
setGeoUpdates();
globals.threeView.render();
}
function setGeoUpdates(){
geometry.attributes.position.needsUpdate = true;
if (globals.colorMode == "axialStrain") geometry.attributes.color.needsUpdate = true;
geometry.computeVertexNormals();
}
var inited = false; var inited = false;
startSolver(); startSolver();
...@@ -138,9 +164,7 @@ function initModel(globals){ ...@@ -138,9 +164,7 @@ function initModel(globals){
console.log("static"); console.log("static");
} }
geometry.attributes.position.needsUpdate = true; geometry.attributes.position.needsUpdate = true;
if (globals.colorMode == "axialStrain") geometry.attributes.color.needsUpdate = true; setGeoUpdates();
geometry.computeVertexNormals();
// geometry.computeFlatVertexNormals();
}); });
} }
...@@ -287,6 +311,8 @@ function initModel(globals){ ...@@ -287,6 +311,8 @@ function initModel(globals){
return { return {
pause: pause, pause: pause,
resume: resume, resume: resume,
reset: reset,
step: step,
getNodes: getNodes, getNodes: getNodes,
getEdges: getEdges, getEdges: getEdges,
getFaces: getFaces, getFaces: getFaces,
......
...@@ -174,7 +174,6 @@ function initPattern(globals){ ...@@ -174,7 +174,6 @@ function initPattern(globals){
} }
function getFacesAndVerticesForEdges(faces, allEdges){ function getFacesAndVerticesForEdges(faces, allEdges){
//todo merge this
var allCreaseParams = [];//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle var allCreaseParams = [];//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle
for (var i=outlines.length;i<allEdges.length;i++){ for (var i=outlines.length;i<allEdges.length;i++){
if (i>=outlines.length+mountains.length+valleys.length && if (i>=outlines.length+mountains.length+valleys.length &&
......
...@@ -61,6 +61,7 @@ function initThreeView(globals) { ...@@ -61,6 +61,7 @@ function initThreeView(globals) {
controls.noPan = true; controls.noPan = true;
controls.staticMoving = true; controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3; controls.dynamicDampingFactor = 0.3;
controls.addEventListener("change", render);
var renderPass = new THREE.RenderPass( scene, camera ); var renderPass = new THREE.RenderPass( scene, camera );
...@@ -90,9 +91,9 @@ function initThreeView(globals) { ...@@ -90,9 +91,9 @@ function initThreeView(globals) {
} }
function render() { function render() {
// if (!animationRunning) { if (!animationRunning) {
// _render(); _render();
// } }
} }
function startAnimation(callback){ function startAnimation(callback){
...@@ -113,6 +114,10 @@ function initThreeView(globals) { ...@@ -113,6 +114,10 @@ function initThreeView(globals) {
if (animationRunning) pauseFlag = true; if (animationRunning) pauseFlag = true;
} }
function running(){
return animationRunning;
}
function _render(){ function _render(){
if (globals.ambientOcclusion) { if (globals.ambientOcclusion) {
// Render depth into depthRenderTarget // Render depth into depthRenderTarget
...@@ -186,6 +191,7 @@ function initThreeView(globals) { ...@@ -186,6 +191,7 @@ function initThreeView(globals) {
pauseAnimation: pauseAnimation, pauseAnimation: pauseAnimation,
enableControls: enableControls, enableControls: enableControls,
scene: scene, scene: scene,
camera: camera camera: camera,
running: running
} }
} }
\ No newline at end of file
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