Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Amanda Ghassaei
OrigamiSimulator
Commits
f60a89c8
Commit
f60a89c8
authored
Feb 25, 2017
by
amandaghassaei
Browse files
pause sim
parent
9008ee1f
Changes
5
Hide whitespace changes
Inline
Side-by-side
js/controls.js
View file @
f60a89c8
...
...
@@ -19,9 +19,13 @@ function initControls(globals){
});
var
dynamicSimVisCallback
=
function
(
val
){
if
(
val
)
$
(
"
.dynamicSim
"
).
show
();
if
(
val
)
{
$
(
"
.dynamicSim
"
).
show
();
if
(
globals
.
dynamicModel
)
globals
.
dynamicModel
.
resume
();
}
else
{
$
(
"
.dynamicSim
"
).
hide
();
if
(
globals
.
dynamicModel
)
globals
.
dynamicModel
.
pause
();
}
};
dynamicSimVisCallback
(
globals
.
dynamicSimVisible
);
...
...
js/crease.js
View file @
f60a89c8
...
...
@@ -2,13 +2,14 @@
* 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
this
.
edge
=
edge
;
this
.
face1Index
=
face1Index
;
this
.
face2Index
=
face2Index
;
this
.
targetTheta
=
targetTheta
;
this
.
type
=
type
;
this
.
node1
=
node1
;
this
.
node2
=
node2
;
node1
.
addCrease
(
this
);
...
...
@@ -31,6 +32,20 @@ Crease.prototype.getNormal2Index = function(){
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
(){
this
.
node1
.
removeCrease
(
this
);
this
.
node2
.
removeCrease
(
this
);
...
...
@@ -38,6 +53,7 @@ Crease.prototype.destroy = function(){
this
.
face1Index
=
null
;
this
.
face2Index
=
null
;
this
.
targetTheta
=
null
;
this
.
type
=
null
;
this
.
node1
=
null
;
this
.
node2
=
null
;
};
\ No newline at end of file
js/dynamicModel.js
View file @
f60a89c8
...
...
@@ -142,7 +142,7 @@ function initDynamicModel(globals){
globals
.
gpuMath
.
readPixels
(
0
,
0
,
textureDimCreases
*
vectorLength
,
height
,
pixels
);
var
parsedPixels
=
new
Float32Array
(
pixels
.
buffer
);
for
(
var
i
=
0
;
i
<
creases
.
length
;
i
++
)
{
console
.
log
(
parsedPixels
[
i
])
//
console.log(parsedPixels[i])
}
}
else
{
console
.
log
(
"
here
"
);
...
...
@@ -175,18 +175,9 @@ function initDynamicModel(globals){
console
.
log
(
"
here
"
);
}
globals
.
threeView
.
render
();
globals
.
gpuMath
.
setSize
(
textureDim
,
textureDim
);
}
function
setViewMode
(
mode
){
if
(
mode
==
"
material
"
){
_
.
each
(
edges
,
function
(
edge
){
edge
.
setMaterialColor
();
})
}
}
function
setSolveParams
(){
var
dt
=
calcDt
();
var
numSteps
=
0.5
/
dt
;
...
...
@@ -345,6 +336,17 @@ function initDynamicModel(globals){
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
(){
textureDim
=
calcTextureSize
(
nodes
.
length
);
...
...
@@ -395,20 +397,29 @@ function initDynamicModel(globals){
lastTheta
[
i
*
4
+
3
]
=
creases
[
i
].
getNormal2Index
();
}
updateCreaseVectors
();
updateNormals
();
updateOriginalPosition
();
updateMaterials
(
true
);
updateFixed
();
updateExternalForces
();
updateCreasesMeta
(
true
);
updateCreaseVectors
();
updateNormals
();
}
function
pause
(){
globals
.
threeView
.
pauseAnimation
();
}
function
resume
(){
runSolver
();
}
return
{
setVisibility
:
setVisibility
,
setViewMode
:
setViewMode
,
syncNodesAndEdges
:
syncNodesAndEdges
,
updateOriginalPosition
:
updateOriginalPosition
,
updateMaterials
:
updateMaterials
,
reset
:
reset
reset
:
reset
,
pause
:
pause
,
resume
:
resume
}
}
\ No newline at end of file
js/model.js
View file @
f60a89c8
...
...
@@ -22,7 +22,7 @@ function initModel(globals){
edges
.
push
(
new
Beam
([
nodes
[
3
],
nodes
[
2
]]));
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
){
globals
.
threeView
.
sceneAddModel
(
node
.
getObject3D
());
...
...
js/threeView.js
View file @
f60a89c8
...
...
@@ -11,6 +11,9 @@ function initThreeView(globals) {
var
renderer
=
new
THREE
.
WebGLRenderer
({
antialias
:
true
});
var
controls
;
var
animationRunning
=
false
;
var
pauseFlag
=
false
;
init
();
function
init
()
{
...
...
@@ -50,11 +53,18 @@ function initThreeView(globals) {
}
function
render
()
{
// renderer.render(scene, camera);
if
(
!
animationRunning
)
{
_render
();
}
}
function
startAnimation
(
callback
){
console
.
log
(
"
starting animation
"
);
if
(
animationRunning
){
console
.
warn
(
"
animation already running
"
);
return
;
}
animationRunning
=
true
;
_loop
(
function
(){
// if (!globals.stlEditing) //only run dynamic sim if not editing stl
callback
();
...
...
@@ -63,6 +73,10 @@ function initThreeView(globals) {
}
function
pauseAnimation
(){
if
(
animationRunning
)
pauseFlag
=
true
;
}
function
_render
(){
renderer
.
render
(
scene
,
camera
);
}
...
...
@@ -70,6 +84,12 @@ function initThreeView(globals) {
function
_loop
(
callback
){
callback
();
requestAnimationFrame
(
function
(){
if
(
pauseFlag
)
{
pauseFlag
=
false
;
animationRunning
=
false
;
console
.
log
(
"
pausing animation
"
);
return
;
}
_loop
(
callback
);
});
}
...
...
@@ -132,6 +152,7 @@ function initThreeView(globals) {
render
:
render
,
onWindowResize
:
onWindowResize
,
startAnimation
:
startAnimation
,
pauseAnimation
:
pauseAnimation
,
enableControls
:
enableControls
,
scene
:
scene
,
camera
:
camera
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment