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
d170663b
Commit
d170663b
authored
Mar 06, 2017
by
amandaghassaei
Browse files
removed instability
parent
e0adec0b
Changes
4
Show whitespace changes
Inline
Side-by-side
index.html
View file @
d170663b
...
...
@@ -174,6 +174,9 @@
vec4
thetas
=
texture2D
(
u_theta
,
scaledCreaseIndex
);
vec3
creaseMeta
=
texture2D
(
u_creaseMeta
,
scaledCreaseIndex
).
xyz
;
//[k, d, targetTheta]
float
targetTheta
=
creaseMeta
[
2
]
*
u_creasePercent
;
float
angForce
=
creaseMeta
[
0
]
*
(
targetTheta
-
thetas
[
0
]);
// + creaseMeta[1]*thetas[1];
if
(
creaseMeta2
[
3
]
<
0.0
){
//crease reaction
float
nodeNum
=
creaseMeta2
[
2
];
...
...
@@ -189,16 +192,14 @@
scaledNormalsIndex
=
normalsIndex
/
u_textureDimFaces
;
vec3
normal2
=
texture2D
(
u_normals
,
scaledNormalsIndex
).
xyz
;
float
targetTheta
=
creaseMeta
[
2
]
*
u_creasePercent
;
float
angForce
=
creaseMeta
[
0
]
*
(
targetTheta
-
thetas
[
0
]);
// + creaseMeta[1]*thetas[1];
float
momentArm1
=
creaseMeta2
[
1
];
float
momentArm2
=
creaseMeta2
[
2
];
vec3
_force
=
-
0.5
*
(
angForce
/
creaseMeta2
[
1
]
*
normal1
+
angForce
/
creaseMeta2
[
2
]
*
normal2
);
vec3
_force
=
-
0.5
*
(
angForce
/
momentArm1
*
normal1
+
angForce
/
momentArm2
*
normal2
);
force
+=
_force
;
}
else
{
float
nodeNum
=
creaseMeta2
[
2
];
float
normalIndex1D
=
thetas
[
2
];
//node #1
float
targetTheta
=
creaseMeta
[
2
]
*
u_creasePercent
;
if
(
nodeNum
>
1.1
)
{
normalIndex1D
=
thetas
[
3
];
//node #2
}
...
...
@@ -206,7 +207,6 @@
vec2
scaledNormalsIndex
=
normalsIndex
/
u_textureDimFaces
;
vec3
normal
=
texture2D
(
u_normals
,
scaledNormalsIndex
).
xyz
;
float
angForce
=
creaseMeta
[
0
]
*
(
targetTheta
-
thetas
[
0
]);
// + creaseMeta[1]*thetas[1];
float
momentArm
=
creaseMeta2
[
1
];
vec3
_force
=
angForce
/
momentArm
*
normal
;
...
...
@@ -221,7 +221,7 @@
</script>
<script
id=
"thetaCalcShader"
type=
"x-shader/x-fragment"
>
#
define
M
_PI
3.1415926535897932384626433832795
#
define
TWO
_PI
6.283185307179586476925286766559
precision
mediump
float
;
uniform
vec2
u_textureDimFaces
;
uniform
vec2
u_textureDimCreases
;
...
...
@@ -249,12 +249,15 @@
vec3
normal1
=
texture2D
(
u_normals
,
normal1Index
).
xyz
;
vec3
normal2
=
texture2D
(
u_normals
,
normal2Index
).
xyz
;
float
theta
=
acos
(
dot
(
normal1
,
normal2
));
//normals are already normalized, no need to divide by length
float
dotNormals
=
dot
(
normal1
,
normal2
);
//normals are already normalized, no need to divide by length
//if (dotNormals
<
-
0.999
)
dotNormals
=
-
0.999
;
//else if (dotNormals > 0.999) dotNormals = 0.999;
float
theta
=
acos
(
dotNormals
);
vec3
creaseVector
=
texture2D
(
u_creaseVectors
,
scaledFragCoord
).
xyz
;
float
sign
=
dot
(
cross
(
normal1
,
normal2
),
creaseVector
);
if
(
sign
<
0.0
)
theta
*=
-
1.0
;
if
(
theta
>
3
.0
&&
lastTheta
[
0
]
<
-
3
.0
)
theta
-=
2.0
*
M
_PI
*
(
1.0
+
floor
(
lastTheta
[
0
]
/
2.0
*
M
_PI
));
if
(
theta
<
-
3
.0
&&
lastTheta
[
0
]
>
3
.0
)
theta
+=
2.0
*
M
_PI
*
(
1.0
+
floor
(
lastTheta
[
0
]
/
2.0
*
M
_PI
));
if
(
theta
>
2
.0
&&
lastTheta
[
0
]
<
-
2
.0
)
theta
-=
TWO
_PI
*
(
1.0
+
floor
(
-
lastTheta
[
0
]
/
TWO
_PI
));
if
(
theta
<
-
2
.0
&&
lastTheta
[
0
]
>
2
.0
)
theta
+=
TWO
_PI
*
(
1.0
+
floor
(
lastTheta
[
0
]
/
TWO
_PI
));
gl_FragColor
=
vec4
(
theta
,
theta
-
lastTheta
[
0
],
lastTheta
[
2
],
lastTheta
[
3
]);
//[theta, w, normal1Index, normal2Index]
}
</script>
...
...
js/crease.js
View file @
d170663b
...
...
@@ -68,7 +68,12 @@ Crease.prototype.getLengthTo = function(node){
var
nodePosition
=
node
.
getOriginalPosition
();
var
vector2
=
nodePosition
.
sub
(
this
.
edge
.
nodes
[
1
].
getOriginalPosition
());
var
projLength
=
vector1
.
dot
(
vector2
);
return
Math
.
sqrt
(
vector2
.
lengthSq
()
-
projLength
*
projLength
);
var
length
=
Math
.
sqrt
(
vector2
.
lengthSq
()
-
projLength
*
projLength
);
if
(
length
<=
0.0
)
{
console
.
warn
(
"
bad moment arm
"
);
length
=
0.001
;
}
return
length
;
};
Crease
.
prototype
.
getNodeIndex
=
function
(
node
){
...
...
js/dynamicModel.js
View file @
d170663b
...
...
@@ -202,7 +202,7 @@ function initDynamicModel(globals){
console
.
log
(
"
here
"
);
}
globals
.
gpuMath
.
setSize
(
textureDim
,
textureDim
);
//
globals.gpuMath.setSize(textureDim, textureDim);
}
function
setSolveParams
(){
...
...
js/model.js
View file @
d170663b
...
...
@@ -46,7 +46,7 @@ function initModel(globals){
}
var
_creases
=
[];
for
(
var
i
=
0
;
i
<
1
;
i
++
)
{
//allCreaseParams.length
for
(
var
i
=
0
;
i
<
allCreaseParams
.
length
;
i
++
)
{
//allCreaseParams.length
var
creaseParams
=
allCreaseParams
[
i
];
//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle
_edges
[
creaseParams
[
4
]].
highlight
();
_creases
.
push
(
new
Crease
(
_edges
[
creaseParams
[
4
]],
creaseParams
[
0
],
creaseParams
[
2
],
creaseParams
[
5
],
1
,
_nodes
[
creaseParams
[
1
]],
_nodes
[
creaseParams
[
3
]],
_creases
.
length
));
...
...
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