Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Amanda Ghassaei
OrigamiSimulator
Commits
af87b75c
Commit
af87b75c
authored
Jun 01, 2017
by
amandaghassaei
Browse files
adding tri stiffness
parent
308889db
Changes
4
Hide whitespace changes
Inline
Side-by-side
index.html
View file @
af87b75c
...
...
@@ -164,6 +164,12 @@
return
texture2D
(
tex
,
scaledIndex
);
}
vec3
getPosition
(
float
index1D
){
vec2
index
=
vec2
(
mod
(
index1D
,
u_textureDim
.
x
)
+
0.5
,
floor
(
index1D
/
u_textureDim
.
x
)
+
0.5
);
vec2
scaledIndex
=
index
/
u_textureDim
;
return
texture2D
(
u_lastPosition
,
scaledIndex
).
xyz
+
texture2D
(
u_originalPosition
,
scaledIndex
).
xyz
;
}
void
main
(){
vec2
fragCoord
=
gl_FragCoord
.
xy
;
vec2
scaledFragCoord
=
fragCoord
/
u_textureDim
;
...
...
@@ -266,24 +272,50 @@
if
(
j
>=
int
(
meta2
[
1
]))
break
;
vec4
faceMeta
=
getFromArray
(
meta2
[
0
]
+
float
(
j
),
u_textureDimNodeFaces
,
u_nodeFaceMeta
);
//[face index, a, b, c]
vec3
nominalAngles
=
getFromArray
(
faceMeta
.
x
,
u_textureDimFaces
,
u_nominalTriangles
).
xyz
;
//[angA, angB, angC]
vec3
nominalAngles
=
getFromArray
(
faceMeta
[
0
],
u_textureDimFaces
,
u_nominalTriangles
).
xyz
;
//[angA, angB, angC]
int
faceIndex
=
0
;
if
(
faceMeta
[
2
]
<
0.0
)
faceIndex
=
1
;
if
(
faceMeta
[
3
]
<
0.0
)
faceIndex
=
2
;
//get node positions
vec3
a
=
getFromArray
(
faceMeta
[
1
],
u_textureDim
,
u_lastPosition
).
xyz
;
vec3
b
=
getFromArray
(
faceMeta
[
2
],
u_textureDim
,
u_lastPosition
).
xyz
;
vec3
c
=
getFromArray
(
faceMeta
[
3
],
u_textureDim
,
u_lastPosition
).
xyz
;
vec3
a
=
faceIndex
==
0
?
lastPosition
+
originalPosition
:
getPosition
(
faceMeta
[
1
])
;
vec3
b
=
faceIndex
==
1
?
lastPosition
+
originalPosition
:
getPosition
(
faceMeta
[
2
])
;
vec3
c
=
faceIndex
==
2
?
lastPosition
+
originalPosition
:
getPosition
(
faceMeta
[
3
])
;
//calc angles
vec3
ab
=
normalize
(
b
-
a
)
;
vec3
ac
=
normalize
(
c
-
a
)
;
vec3
bc
=
normalize
(
b
-
b
)
;
vec3
ab
=
b
-
a
;
vec3
ac
=
c
-
a
;
vec3
bc
=
c
-
b
;
float
angA
=
acos
(
dot
(
ab
,
ac
));
float
angB
=
acos
(
-
1.0
*
dot
(
ab
,
bc
));
float
angC
=
acos
(
dot
(
ac
,
bc
));
float
lengthABsq
=
length
(
ab
);
float
lengthACsq
=
length
(
ac
);
float
lengthBCsq
=
length
(
bc
);
lengthABsq
*=
lengthABsq
;
lengthACsq
*=
lengthACsq
;
lengthBCsq
*=
lengthBCsq
;
//calc forces
vec3
angles
=
vec3
(
acos
(
dot
(
ab
,
ac
)),
acos
(
-
1.0
*
dot
(
ab
,
bc
)),
acos
(
dot
(
ac
,
bc
)));
vec3
anglesDiff
=
nominalAngles
-
angles
;
vec3
normal
=
getFromArray
(
faceMeta
[
0
],
u_textureDimFaces
,
u_normals
).
xyz
;
//calc forces
float
triangleStiffness
=
0.1
;
anglesDiff
*=
triangleStiffness
;
if
(
faceIndex
==
0
){
//a
force
-=
anglesDiff
[
0
]
*
(
cross
(
ac
,
normal
)
/
lengthACsq
-
cross
(
ab
,
normal
)
/
lengthABsq
);
force
+=
anglesDiff
[
1
]
*
cross
(
-
ab
,
normal
)
/
lengthABsq
;
force
-=
anglesDiff
[
2
]
*
cross
(
-
ac
,
normal
)
/
lengthACsq
;
}
else
if
(
faceIndex
==
1
){
force
-=
anglesDiff
[
0
]
*
cross
(
ab
,
normal
)
/
lengthABsq
;
force
-=
anglesDiff
[
1
]
*
(
cross
(
-
ab
,
normal
)
/
lengthABsq
-
cross
(
bc
,
normal
)
/
lengthBCsq
);
force
+=
anglesDiff
[
2
]
*
cross
(
-
bc
,
normal
)
/
lengthBCsq
;
}
else
if
(
faceIndex
==
2
){
force
+=
anglesDiff
[
0
]
*
cross
(
ac
,
normal
)
/
lengthACsq
;
force
-=
anglesDiff
[
1
]
*
cross
(
bc
,
normal
)
/
lengthBCsq
;
force
-=
anglesDiff
[
2
]
*
(
cross
(
-
bc
,
normal
)
/
lengthBCsq
-
cross
(
-
ac
,
normal
)
/
lengthACsq
);
}
}
...
...
@@ -412,7 +444,7 @@
vec3
node3
=
getPosition
(
creaseMeta
[
2
]);
vec3
node4
=
getPosition
(
creaseMeta
[
3
]);
float
tol
=
0.01
;
float
tol
=
0.
0000
01
;
vec3
creaseVector
=
node4
-
node3
;
float
creaseLength
=
length
(
creaseVector
);
...
...
@@ -633,6 +665,10 @@
<span
class=
"label-slider"
>
Axial Strength :
</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"
type=
"text"
>
</div>
<div
class=
"sliderInput paddingBottom"
id=
"triStiffness"
>
<span
class=
"label-slider"
>
Triangle Strength :
</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"
type=
"text"
>
</div>
<div
class=
"sliderInput"
id=
"creaseStiffness"
>
<span
class=
"label-slider"
>
Fold Strength :
</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"
type=
"text"
>
...
...
js/controls.js
View file @
af87b75c
...
...
@@ -179,6 +179,11 @@ function initControls(globals){
globals
.
materialHasChanged
=
true
;
});
setSliderInput
(
"
#triStiffness
"
,
globals
.
triStiffness
,
0
,
10
,
0.01
,
function
(
val
){
globals
.
triStiffness
=
val
;
//todo update
// globals.materialHasChanged = true;
});
setSliderInput
(
"
#creaseStiffness
"
,
globals
.
creaseStiffness
,
0
,
3
,
0.01
,
function
(
val
){
globals
.
creaseStiffness
=
val
;
globals
.
creaseMaterialHasChanged
=
true
;
...
...
js/dynamic/dynamicSolver.js
View file @
af87b75c
...
...
@@ -556,9 +556,9 @@ function initDynamicSolver(globals){
var
_index
=
(
index
+
j
)
*
4
;
var
face
=
faces
[
nodeFaces
[
i
][
j
]];
nodeFaceMeta
[
_index
]
=
nodeFaces
[
i
][
j
];
nodeFaceMeta
[
_index
+
1
]
=
face
[
0
];
nodeFaceMeta
[
_index
+
2
]
=
face
[
1
];
nodeFaceMeta
[
_index
+
3
]
=
face
[
2
];
nodeFaceMeta
[
_index
+
1
]
=
face
[
0
]
==
i
?
-
1
:
face
[
0
];
nodeFaceMeta
[
_index
+
2
]
=
face
[
1
]
==
i
?
-
1
:
face
[
1
];
nodeFaceMeta
[
_index
+
3
]
=
face
[
2
]
==
i
?
-
1
:
face
[
2
];
}
index
+=
num
;
}
...
...
js/globals.js
View file @
af87b75c
...
...
@@ -46,6 +46,7 @@ function initGlobals(){
axialStiffness
:
20
,
creaseStiffness
:
0.7
,
panelStiffness
:
0.7
,
triStiffness
:
1
,
//dynamic sim settings
percentDamping
:
0.5
,
...
...
Write
Preview
Markdown
is supported
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