Commit f60a89c8 authored by amandaghassaei's avatar amandaghassaei
Browse files

pause sim

parent 9008ee1f
...@@ -19,9 +19,13 @@ function initControls(globals){ ...@@ -19,9 +19,13 @@ function initControls(globals){
}); });
var dynamicSimVisCallback = function(val){ var dynamicSimVisCallback = function(val){
if (val) $(".dynamicSim").show(); if (val) {
$(".dynamicSim").show();
if (globals.dynamicModel) globals.dynamicModel.resume();
}
else { else {
$(".dynamicSim").hide(); $(".dynamicSim").hide();
if (globals.dynamicModel) globals.dynamicModel.pause();
} }
}; };
dynamicSimVisCallback(globals.dynamicSimVisible); dynamicSimVisCallback(globals.dynamicSimVisible);
......
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
* Created by amandaghassaei on 2/25/17. * Created by amandaghassaei on 2/25/17.
*/ */
function Crease(edge, face1Index, face2Index, targetTheta, node1, node2){ function Crease(edge, face1Index, face2Index, targetTheta, type, node1, node2){//type = 0 panel, 1 crease
//face1 corresponds to node1, face2 to node2 //face1 corresponds to node1, face2 to node2
this.edge = edge; this.edge = edge;
this.face1Index = face1Index; this.face1Index = face1Index;
this.face2Index = face2Index; this.face2Index = face2Index;
this.targetTheta = targetTheta; this.targetTheta = targetTheta;
this.type = type;
this.node1 = node1; this.node1 = node1;
this.node2 = node2; this.node2 = node2;
node1.addCrease(this); node1.addCrease(this);
...@@ -31,6 +32,20 @@ Crease.prototype.getNormal2Index = function(){ ...@@ -31,6 +32,20 @@ Crease.prototype.getNormal2Index = function(){
return this.face2Index; return this.face2Index;
}; };
Crease.prototype.getTargetTheta = function(){
return this.targetTheta;
};
Crease.prototype.getK = function(){
var length = this.getLength();
if (this.type == 0) return globals.panelStiffness*length;
return globals.creaseStiffness*length;
};
Crease.prototype.getD = function(){
return globals.percentDamping*2*Math.sqrt(this.getK());
};
Crease.prototype.destroy = function(){ Crease.prototype.destroy = function(){
this.node1.removeCrease(this); this.node1.removeCrease(this);
this.node2.removeCrease(this); this.node2.removeCrease(this);
...@@ -38,6 +53,7 @@ Crease.prototype.destroy = function(){ ...@@ -38,6 +53,7 @@ Crease.prototype.destroy = function(){
this.face1Index = null; this.face1Index = null;
this.face2Index = null; this.face2Index = null;
this.targetTheta = null; this.targetTheta = null;
this.type = null;
this.node1 = null; this.node1 = null;
this.node2 = null; this.node2 = null;
}; };
\ No newline at end of file
...@@ -142,7 +142,7 @@ function initDynamicModel(globals){ ...@@ -142,7 +142,7 @@ function initDynamicModel(globals){
globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels); globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels);
var parsedPixels = new Float32Array(pixels.buffer); var parsedPixels = new Float32Array(pixels.buffer);
for (var i = 0; i < creases.length; i++) { for (var i = 0; i < creases.length; i++) {
console.log(parsedPixels[i]) // console.log(parsedPixels[i])
} }
} else { } else {
console.log("here"); console.log("here");
...@@ -175,18 +175,9 @@ function initDynamicModel(globals){ ...@@ -175,18 +175,9 @@ function initDynamicModel(globals){
console.log("here"); console.log("here");
} }
globals.threeView.render();
globals.gpuMath.setSize(textureDim, textureDim); globals.gpuMath.setSize(textureDim, textureDim);
} }
function setViewMode(mode){
if (mode == "material"){
_.each(edges, function(edge){
edge.setMaterialColor();
})
}
}
function setSolveParams(){ function setSolveParams(){
var dt = calcDt(); var dt = calcDt();
var numSteps = 0.5/dt; var numSteps = 0.5/dt;
...@@ -345,6 +336,17 @@ function initDynamicModel(globals){ ...@@ -345,6 +336,17 @@ function initDynamicModel(globals){
globals.gpuMath.initTextureFromData("u_creaseVectors", textureDimCreases, textureDimCreases, "FLOAT", creaseVectors, true); globals.gpuMath.initTextureFromData("u_creaseVectors", textureDimCreases, textureDimCreases, "FLOAT", creaseVectors, true);
} }
function updateCreasesMeta(initing){
for (var i=0;i<creases.length;i++){
var crease = creases[i];
creaseMeta[i*4] = crease.getK();
creaseMeta[i*4+1] = crease.getD();
if (initing) creaseMeta[i*4+2] = crease.getTargetTheta();
}
globals.gpuMath.initTextureFromData("u_creaseMeta", textureDimCreases, textureDimCreases, "FLOAT", creaseMeta, true);
}
function initTypedArrays(){ function initTypedArrays(){
textureDim = calcTextureSize(nodes.length); textureDim = calcTextureSize(nodes.length);
...@@ -395,20 +397,29 @@ function initDynamicModel(globals){ ...@@ -395,20 +397,29 @@ function initDynamicModel(globals){
lastTheta[i*4+3] = creases[i].getNormal2Index(); lastTheta[i*4+3] = creases[i].getNormal2Index();
} }
updateCreaseVectors();
updateNormals();
updateOriginalPosition(); updateOriginalPosition();
updateMaterials(true); updateMaterials(true);
updateFixed(); updateFixed();
updateExternalForces(); updateExternalForces();
updateCreasesMeta(true);
updateCreaseVectors();
updateNormals();
}
function pause(){
globals.threeView.pauseAnimation();
}
function resume(){
runSolver();
} }
return { return {
setVisibility: setVisibility,
setViewMode: setViewMode,
syncNodesAndEdges: syncNodesAndEdges, syncNodesAndEdges: syncNodesAndEdges,
updateOriginalPosition: updateOriginalPosition, updateOriginalPosition: updateOriginalPosition,
updateMaterials:updateMaterials, updateMaterials:updateMaterials,
reset: reset reset: reset,
pause: pause,
resume: resume
} }
} }
\ No newline at end of file
...@@ -22,7 +22,7 @@ function initModel(globals){ ...@@ -22,7 +22,7 @@ function initModel(globals){
edges.push(new Beam([nodes[3], nodes[2]])); edges.push(new Beam([nodes[3], nodes[2]]));
var creases = []; var creases = [];
creases.push(new Crease(edges[1], 1, 0, 0, nodes[1], nodes[0])); creases.push(new Crease(edges[1], 1, 0, 0, 0, nodes[1], nodes[0]));
_.each(nodes, function(node){ _.each(nodes, function(node){
globals.threeView.sceneAddModel(node.getObject3D()); globals.threeView.sceneAddModel(node.getObject3D());
......
...@@ -11,6 +11,9 @@ function initThreeView(globals) { ...@@ -11,6 +11,9 @@ function initThreeView(globals) {
var renderer = new THREE.WebGLRenderer({antialias: true}); var renderer = new THREE.WebGLRenderer({antialias: true});
var controls; var controls;
var animationRunning = false;
var pauseFlag = false;
init(); init();
function init() { function init() {
...@@ -50,11 +53,18 @@ function initThreeView(globals) { ...@@ -50,11 +53,18 @@ function initThreeView(globals) {
} }
function render() { function render() {
// renderer.render(scene, camera); if (!animationRunning) {
_render();
}
} }
function startAnimation(callback){ function startAnimation(callback){
console.log("starting animation"); console.log("starting animation");
if (animationRunning){
console.warn("animation already running");
return;
}
animationRunning = true;
_loop(function(){ _loop(function(){
// if (!globals.stlEditing) //only run dynamic sim if not editing stl // if (!globals.stlEditing) //only run dynamic sim if not editing stl
callback(); callback();
...@@ -63,6 +73,10 @@ function initThreeView(globals) { ...@@ -63,6 +73,10 @@ function initThreeView(globals) {
} }
function pauseAnimation(){
if (animationRunning) pauseFlag = true;
}
function _render(){ function _render(){
renderer.render(scene, camera); renderer.render(scene, camera);
} }
...@@ -70,6 +84,12 @@ function initThreeView(globals) { ...@@ -70,6 +84,12 @@ function initThreeView(globals) {
function _loop(callback){ function _loop(callback){
callback(); callback();
requestAnimationFrame(function(){ requestAnimationFrame(function(){
if (pauseFlag) {
pauseFlag = false;
animationRunning = false;
console.log("pausing animation");
return;
}
_loop(callback); _loop(callback);
}); });
} }
...@@ -132,6 +152,7 @@ function initThreeView(globals) { ...@@ -132,6 +152,7 @@ function initThreeView(globals) {
render: render, render: render,
onWindowResize: onWindowResize, onWindowResize: onWindowResize,
startAnimation: startAnimation, startAnimation: startAnimation,
pauseAnimation: pauseAnimation,
enableControls: enableControls, enableControls: enableControls,
scene: scene, scene: scene,
camera: camera camera: camera
......
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