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
651ae2ba
Commit
651ae2ba
authored
May 31, 2017
by
amandaghassaei
Browse files
renaming
parent
84ad9608
Changes
2
Hide whitespace changes
Inline
Side-by-side
index.html
View file @
651ae2ba
...
@@ -146,10 +146,10 @@
...
@@ -146,10 +146,10 @@
uniform
sampler2D
u_originalPosition
;
uniform
sampler2D
u_originalPosition
;
uniform
sampler2D
u_externalForces
;
uniform
sampler2D
u_externalForces
;
uniform
sampler2D
u_mass
;
uniform
sampler2D
u_mass
;
uniform
sampler2D
u_meta
;
//[beamsIndex, numBeam,
c
reaseMeta
2
Index, numCreases]
uniform
sampler2D
u_meta
;
//[beamsIndex, numBeam,
nodeC
reaseMetaIndex, numCreases]
uniform
sampler2D
u_beamMeta
;
//[k, d, length, otherNodeIndex]
uniform
sampler2D
u_beamMeta
;
//[k, d, length, otherNodeIndex]
uniform
sampler2D
u_creaseMeta
;
//[k, d, targetTheta]
uniform
sampler2D
u_creaseMeta
;
//[k, d, targetTheta]
uniform
sampler2D
u_
c
reaseMeta
2
;
//[creaseIndex, nodeIndex, -, -]
uniform
sampler2D
u_
nodeC
reaseMeta
;
//[creaseIndex, nodeIndex, -, -]
uniform
sampler2D
u_normals
;
uniform
sampler2D
u_normals
;
uniform
sampler2D
u_theta
;
//[theta, z, normal1Index, normal2Index]
uniform
sampler2D
u_theta
;
//[theta, z, normal1Index, normal2Index]
uniform
sampler2D
u_creaseGeo
;
//[h1, h2, coef1, coef2]
uniform
sampler2D
u_creaseGeo
;
//[h1, h2, coef1, coef2]
...
@@ -206,9 +206,9 @@
...
@@ -206,9 +206,9 @@
float
nodeCreaseIndex1D
=
meta
[
2
]
+
float
(
j
);
float
nodeCreaseIndex1D
=
meta
[
2
]
+
float
(
j
);
vec2
nodeCreaseIndex
=
vec2
(
mod
(
nodeCreaseIndex1D
,
u_textureDimNodeCreases
.
x
)
+
0.5
,
floor
(
nodeCreaseIndex1D
/
u_textureDimNodeCreases
.
x
)
+
0.5
);
vec2
nodeCreaseIndex
=
vec2
(
mod
(
nodeCreaseIndex1D
,
u_textureDimNodeCreases
.
x
)
+
0.5
,
floor
(
nodeCreaseIndex1D
/
u_textureDimNodeCreases
.
x
)
+
0.5
);
vec2
scaledNodeCreaseIndex
=
nodeCreaseIndex
/
u_textureDimNodeCreases
;
vec2
scaledNodeCreaseIndex
=
nodeCreaseIndex
/
u_textureDimNodeCreases
;
vec4
c
reaseMeta
2
=
texture2D
(
u_
c
reaseMeta
2
,
scaledNodeCreaseIndex
);
//[creaseIndex, length to node, nodeType (1 or 2), isReaction]
vec4
nodeC
reaseMeta
=
texture2D
(
u_
nodeC
reaseMeta
,
scaledNodeCreaseIndex
);
//[creaseIndex, length to node, nodeType (1 or 2), isReaction]
float
creaseIndex1D
=
c
reaseMeta
2
[
0
];
float
creaseIndex1D
=
nodeC
reaseMeta
[
0
];
vec2
creaseIndex
=
vec2
(
mod
(
creaseIndex1D
,
u_textureDimCreases
.
x
)
+
0.5
,
floor
(
creaseIndex1D
/
u_textureDimCreases
.
x
)
+
0.5
);
vec2
creaseIndex
=
vec2
(
mod
(
creaseIndex1D
,
u_textureDimCreases
.
x
)
+
0.5
,
floor
(
creaseIndex1D
/
u_textureDimCreases
.
x
)
+
0.5
);
vec2
scaledCreaseIndex
=
creaseIndex
/
u_textureDimCreases
;
vec2
scaledCreaseIndex
=
creaseIndex
/
u_textureDimCreases
;
...
@@ -220,7 +220,7 @@
...
@@ -220,7 +220,7 @@
float
targetTheta
=
creaseMeta
[
2
]
*
u_creasePercent
;
float
targetTheta
=
creaseMeta
[
2
]
*
u_creasePercent
;
float
angForce
=
creaseMeta
[
0
]
*
(
targetTheta
-
thetas
[
0
]);
// + creaseMeta[1]*thetas[1];
float
angForce
=
creaseMeta
[
0
]
*
(
targetTheta
-
thetas
[
0
]);
// + creaseMeta[1]*thetas[1];
float
nodeNum
=
c
reaseMeta
2
[
1
];
//1, 2, 3, 4
float
nodeNum
=
nodeC
reaseMeta
[
1
];
//1, 2, 3, 4
if
(
nodeNum
>
2.0
){
//crease reaction, node is on a crease
if
(
nodeNum
>
2.0
){
//crease reaction, node is on a crease
...
@@ -375,13 +375,13 @@
...
@@ -375,13 +375,13 @@
uniform
vec2
u_textureDimCreases
;
uniform
vec2
u_textureDimCreases
;
uniform
sampler2D
u_lastPosition
;
uniform
sampler2D
u_lastPosition
;
uniform
sampler2D
u_originalPosition
;
uniform
sampler2D
u_originalPosition
;
uniform
sampler2D
u_creaseMeta
3
;
uniform
sampler2D
u_creaseMeta
2
;
void
main
(){
void
main
(){
vec2
fragCoord
=
gl_FragCoord
.
xy
;
vec2
fragCoord
=
gl_FragCoord
.
xy
;
vec2
scaledFragCoord
=
fragCoord
/
u_textureDimCreases
;
vec2
scaledFragCoord
=
fragCoord
/
u_textureDimCreases
;
vec4
creaseMeta
=
texture2D
(
u_creaseMeta
3
,
scaledFragCoord
);
vec4
creaseMeta
=
texture2D
(
u_creaseMeta
2
,
scaledFragCoord
);
vec2
node1Index
=
vec2
(
mod
(
creaseMeta
[
0
],
u_textureDim
.
x
)
+
0.5
,
floor
(
creaseMeta
[
0
]
/
u_textureDim
.
x
)
+
0.5
)
/
u_textureDim
;
vec2
node1Index
=
vec2
(
mod
(
creaseMeta
[
0
],
u_textureDim
.
x
)
+
0.5
,
floor
(
creaseMeta
[
0
]
/
u_textureDim
.
x
)
+
0.5
)
/
u_textureDim
;
vec2
node2Index
=
vec2
(
mod
(
creaseMeta
[
1
],
u_textureDim
.
x
)
+
0.5
,
floor
(
creaseMeta
[
1
]
/
u_textureDim
.
x
)
+
0.5
)
/
u_textureDim
;
vec2
node2Index
=
vec2
(
mod
(
creaseMeta
[
1
],
u_textureDim
.
x
)
+
0.5
,
floor
(
creaseMeta
[
1
]
/
u_textureDim
.
x
)
+
0.5
)
/
u_textureDim
;
...
...
js/dynamic/dynamicSolver.js
View file @
651ae2ba
...
@@ -25,9 +25,9 @@ function initDynamicSolver(globals){
...
@@ -25,9 +25,9 @@ function initDynamicSolver(globals){
var
normals
;
var
normals
;
var
faceVertexIndices
;
//[a,b,c]
var
faceVertexIndices
;
//[a,b,c]
var
creaseMeta
;
//[k, d, targetTheta
]
var
creaseMeta
;
//[k, d, targetTheta
, -] textureDimCreases
var
creaseMeta2
;
//[
creaseIndex (thetaI
ndex
)
, node
I
ndex
(1/2/3/4), -, -]
var
creaseMeta2
;
//[
node1Index, node2Index, node3i
ndex, node
4i
ndex
]//nodes 1 and 2 are opposite crease, 3 and 4 are on crease, textureDimCreases
var
c
reaseMeta
3
;
//[
node1Index, node2
Index, node
3i
ndex
, node4index]//nodes 1 and 2 are opposite crease, 3 and 4 are on c
rease
var
nodeC
reaseMeta
;
//[
creaseIndex (theta
Index
)
, node
I
ndex
(1/2/3/4), -, -] textureDimNodeC
rease
s
var
creaseGeo
;
//[h1, h2, coef1, coef2]
var
creaseGeo
;
//[h1, h2, coef1, coef2]
var
creaseVectors
;
//indices of crease nodes
var
creaseVectors
;
//indices of crease nodes
var
theta
;
//[theta, w, normalIndex1, normalIndex2]
var
theta
;
//[theta, w, normalIndex1, normalIndex2]
...
@@ -129,12 +129,12 @@ function initDynamicSolver(globals){
...
@@ -129,12 +129,12 @@ function initDynamicSolver(globals){
gpuMath
.
setProgram
(
"
updateCreaseGeo
"
);
gpuMath
.
setProgram
(
"
updateCreaseGeo
"
);
//already at textureDimCreasesxtextureDimCreases
//already at textureDimCreasesxtextureDimCreases
gpuMath
.
step
(
"
updateCreaseGeo
"
,
[
"
u_lastPosition
"
,
"
u_originalPosition
"
,
"
u_creaseMeta
3
"
],
"
u_creaseGeo
"
);
gpuMath
.
step
(
"
updateCreaseGeo
"
,
[
"
u_lastPosition
"
,
"
u_originalPosition
"
,
"
u_creaseMeta
2
"
],
"
u_creaseGeo
"
);
gpuMath
.
setProgram
(
"
velocityCalc
"
);
gpuMath
.
setProgram
(
"
velocityCalc
"
);
gpuMath
.
setSize
(
textureDim
,
textureDim
);
gpuMath
.
setSize
(
textureDim
,
textureDim
);
gpuMath
.
step
(
"
velocityCalc
"
,
[
"
u_lastPosition
"
,
"
u_lastVelocity
"
,
"
u_originalPosition
"
,
"
u_externalForces
"
,
gpuMath
.
step
(
"
velocityCalc
"
,
[
"
u_lastPosition
"
,
"
u_lastVelocity
"
,
"
u_originalPosition
"
,
"
u_externalForces
"
,
"
u_mass
"
,
"
u_meta
"
,
"
u_beamMeta
"
,
"
u_creaseMeta
"
,
"
u_
c
reaseMeta
2
"
,
"
u_normals
"
,
"
u_theta
"
,
"
u_creaseGeo
"
],
"
u_velocity
"
);
"
u_mass
"
,
"
u_meta
"
,
"
u_beamMeta
"
,
"
u_creaseMeta
"
,
"
u_
nodeC
reaseMeta
"
,
"
u_normals
"
,
"
u_theta
"
,
"
u_creaseGeo
"
],
"
u_velocity
"
);
gpuMath
.
step
(
"
positionCalc
"
,
[
"
u_velocity
"
,
"
u_lastPosition
"
,
"
u_mass
"
],
"
u_position
"
);
gpuMath
.
step
(
"
positionCalc
"
,
[
"
u_velocity
"
,
"
u_lastPosition
"
,
"
u_mass
"
],
"
u_position
"
);
gpuMath
.
swapTextures
(
"
u_theta
"
,
"
u_lastTheta
"
);
gpuMath
.
swapTextures
(
"
u_theta
"
,
"
u_lastTheta
"
);
...
@@ -264,8 +264,8 @@ function initDynamicSolver(globals){
...
@@ -264,8 +264,8 @@ function initDynamicSolver(globals){
gpuMath
.
initFrameBufferForTexture
(
"
u_normals
"
,
true
);
gpuMath
.
initFrameBufferForTexture
(
"
u_normals
"
,
true
);
gpuMath
.
initTextureFromData
(
"
u_meta
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
meta
,
true
);
gpuMath
.
initTextureFromData
(
"
u_meta
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
meta
,
true
);
gpuMath
.
initTextureFromData
(
"
u_
c
reaseMeta
2
"
,
textureDimNodeCreases
,
textureDimNodeCreases
,
"
FLOAT
"
,
c
reaseMeta
2
,
true
);
gpuMath
.
initTextureFromData
(
"
u_
nodeC
reaseMeta
"
,
textureDimNodeCreases
,
textureDimNodeCreases
,
"
FLOAT
"
,
nodeC
reaseMeta
,
true
);
gpuMath
.
initTextureFromData
(
"
u_creaseMeta
3
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
creaseMeta
3
,
true
);
gpuMath
.
initTextureFromData
(
"
u_creaseMeta
2
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
creaseMeta
2
,
true
);
gpuMath
.
initTextureFromData
(
"
u_creaseGeo
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
creaseGeo
,
true
);
gpuMath
.
initTextureFromData
(
"
u_creaseGeo
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
creaseGeo
,
true
);
gpuMath
.
initFrameBufferForTexture
(
"
u_creaseGeo
"
,
true
);
gpuMath
.
initFrameBufferForTexture
(
"
u_creaseGeo
"
,
true
);
gpuMath
.
initTextureFromData
(
"
u_faceVertexIndices
"
,
textureDimFaces
,
textureDimFaces
,
"
FLOAT
"
,
faceVertexIndices
,
true
);
gpuMath
.
initTextureFromData
(
"
u_faceVertexIndices
"
,
textureDimFaces
,
textureDimFaces
,
"
FLOAT
"
,
faceVertexIndices
,
true
);
...
@@ -285,7 +285,7 @@ function initDynamicSolver(globals){
...
@@ -285,7 +285,7 @@ function initDynamicSolver(globals){
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_meta
"
,
5
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_meta
"
,
5
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_beamMeta
"
,
6
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_beamMeta
"
,
6
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_creaseMeta
"
,
7
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_creaseMeta
"
,
7
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_
c
reaseMeta
2
"
,
8
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_
nodeC
reaseMeta
"
,
8
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_normals
"
,
9
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_normals
"
,
9
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_theta
"
,
10
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_theta
"
,
10
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_creaseGeo
"
,
11
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_creaseGeo
"
,
11
,
"
1i
"
);
...
@@ -331,7 +331,7 @@ function initDynamicSolver(globals){
...
@@ -331,7 +331,7 @@ function initDynamicSolver(globals){
gpuMath
.
createProgram
(
"
updateCreaseGeo
"
,
vertexShader
,
document
.
getElementById
(
"
updateCreaseGeo
"
).
text
);
gpuMath
.
createProgram
(
"
updateCreaseGeo
"
,
vertexShader
,
document
.
getElementById
(
"
updateCreaseGeo
"
).
text
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_lastPosition
"
,
0
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_lastPosition
"
,
0
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_originalPosition
"
,
1
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_originalPosition
"
,
1
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_creaseMeta
3
"
,
2
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_creaseMeta
2
"
,
2
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_textureDim
"
,
[
textureDim
,
textureDim
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_textureDim
"
,
[
textureDim
,
textureDim
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_textureDimCreases
"
,
[
textureDimCreases
,
textureDimCreases
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
updateCreaseGeo
"
,
"
u_textureDimCreases
"
,
[
textureDimCreases
,
textureDimCreases
],
"
2f
"
);
...
@@ -475,8 +475,8 @@ function initDynamicSolver(globals){
...
@@ -475,8 +475,8 @@ function initDynamicSolver(globals){
normals
=
new
Float32Array
(
textureDimFaces
*
textureDimFaces
*
4
);
normals
=
new
Float32Array
(
textureDimFaces
*
textureDimFaces
*
4
);
faceVertexIndices
=
new
Float32Array
(
textureDimFaces
*
textureDimFaces
*
4
);
faceVertexIndices
=
new
Float32Array
(
textureDimFaces
*
textureDimFaces
*
4
);
creaseMeta
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
creaseMeta
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
c
reaseMeta
2
=
new
Float32Array
(
textureDimNodeCreases
*
textureDimNodeCreases
*
4
);
nodeC
reaseMeta
=
new
Float32Array
(
textureDimNodeCreases
*
textureDimNodeCreases
*
4
);
creaseMeta
3
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
creaseMeta
2
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
creaseGeo
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
creaseGeo
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
creaseVectors
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
creaseVectors
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
theta
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
theta
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
...
@@ -512,22 +512,22 @@ function initDynamicSolver(globals){
...
@@ -512,22 +512,22 @@ function initDynamicSolver(globals){
// console.log(nodeInvCreases);
// console.log(nodeInvCreases);
meta
[
i
*
4
+
3
]
=
nodeCreases
.
length
+
nodeInvCreases
.
length
;
meta
[
i
*
4
+
3
]
=
nodeCreases
.
length
+
nodeInvCreases
.
length
;
for
(
var
j
=
0
;
j
<
nodeCreases
.
length
;
j
++
){
for
(
var
j
=
0
;
j
<
nodeCreases
.
length
;
j
++
){
c
reaseMeta
2
[
index
*
4
]
=
nodeCreases
[
j
].
getIndex
();
nodeC
reaseMeta
[
index
*
4
]
=
nodeCreases
[
j
].
getIndex
();
c
reaseMeta
2
[
index
*
4
+
1
]
=
nodeCreases
[
j
].
getNodeIndex
(
nodes
[
i
]);
//type 1, 2, 3, 4
nodeC
reaseMeta
[
index
*
4
+
1
]
=
nodeCreases
[
j
].
getNodeIndex
(
nodes
[
i
]);
//type 1, 2, 3, 4
index
++
;
index
++
;
}
}
for
(
var
j
=
0
;
j
<
nodeInvCreases
.
length
;
j
++
){
for
(
var
j
=
0
;
j
<
nodeInvCreases
.
length
;
j
++
){
c
reaseMeta
2
[
index
*
4
]
=
nodeInvCreases
[
j
].
getIndex
();
nodeC
reaseMeta
[
index
*
4
]
=
nodeInvCreases
[
j
].
getIndex
();
c
reaseMeta
2
[
index
*
4
+
1
]
=
nodeInvCreases
[
j
].
getNodeIndex
(
nodes
[
i
]);
//type 1, 2, 3, 4
nodeC
reaseMeta
[
index
*
4
+
1
]
=
nodeInvCreases
[
j
].
getNodeIndex
(
nodes
[
i
]);
//type 1, 2, 3, 4
index
++
;
index
++
;
}
}
}
}
for
(
var
i
=
0
;
i
<
creases
.
length
;
i
++
){
for
(
var
i
=
0
;
i
<
creases
.
length
;
i
++
){
var
crease
=
creases
[
i
];
var
crease
=
creases
[
i
];
creaseMeta
3
[
i
*
4
]
=
crease
.
node1
.
getIndex
();
creaseMeta
2
[
i
*
4
]
=
crease
.
node1
.
getIndex
();
creaseMeta
3
[
i
*
4
+
1
]
=
crease
.
node2
.
getIndex
();
creaseMeta
2
[
i
*
4
+
1
]
=
crease
.
node2
.
getIndex
();
creaseMeta
3
[
i
*
4
+
2
]
=
crease
.
edge
.
nodes
[
0
].
getIndex
();
creaseMeta
2
[
i
*
4
+
2
]
=
crease
.
edge
.
nodes
[
0
].
getIndex
();
creaseMeta
3
[
i
*
4
+
3
]
=
crease
.
edge
.
nodes
[
1
].
getIndex
();
creaseMeta
2
[
i
*
4
+
3
]
=
crease
.
edge
.
nodes
[
1
].
getIndex
();
index
++
;
index
++
;
}
}
...
...
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