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
7dd459e6
Commit
7dd459e6
authored
Jun 01, 2017
by
amandaghassaei
Browse files
adding code
parent
4cac5e41
Changes
2
Hide whitespace changes
Inline
Side-by-side
index.html
View file @
7dd459e6
...
...
@@ -139,6 +139,7 @@
uniform
vec2
u_textureDimFaces
;
uniform
vec2
u_textureDimCreases
;
uniform
vec2
u_textureDimNodeCreases
;
uniform
vec2
u_textureDimNodeFaces
;
uniform
float
u_creasePercent
;
uniform
float
u_dt
;
uniform
sampler2D
u_lastPosition
;
...
...
@@ -157,6 +158,12 @@
uniform
sampler2D
u_nodeFaceMeta
;
//[faceIndex, a, b, c]
uniform
sampler2D
u_nominalTriangles
;
//[angleA, angleB, angleC]
vec4
getFromArray
(
float
index1D
,
vec2
dimensions
,
sampler2D
tex
){
vec2
index
=
vec2
(
mod
(
index1D
,
dimensions
.
x
)
+
0.5
,
floor
(
index1D
/
dimensions
.
x
)
+
0.5
);
vec2
scaledIndex
=
index
/
dimensions
;
return
texture2D
(
tex
,
scaledIndex
);
}
void
main
(){
vec2
fragCoord
=
gl_FragCoord
.
xy
;
vec2
scaledFragCoord
=
fragCoord
/
u_textureDim
;
...
...
@@ -173,16 +180,14 @@
vec4
neighborIndices
=
texture2D
(
u_meta
,
scaledFragCoord
);
vec4
meta
=
texture2D
(
u_meta
,
scaledFragCoord
);
vec2
meta2
=
texture2D
(
u_meta2
,
scaledFragCoord
).
xy
;
float
nodeError
=
0.0
;
for
(
int
j
=
0
;
j
<
100
;
j
++
){
//for all beams (up to 100, had to put a const int in here)
if
(
j
>=
int
(
meta
[
1
]))
break
;
float
beamIndex1D
=
meta
[
0
]
+
float
(
j
);
vec2
beamIndex
=
vec2
(
mod
(
beamIndex1D
,
u_textureDimEdges
.
x
)
+
0.5
,
floor
(
beamIndex1D
/
u_textureDimEdges
.
x
)
+
0.5
);
vec2
scaledBeamIndex
=
beamIndex
/
u_textureDimEdges
;
vec4
beamMeta
=
texture2D
(
u_beamMeta
,
scaledBeamIndex
);
vec4
beamMeta
=
getFromArray
(
meta
[
0
]
+
float
(
j
),
u_textureDimEdges
,
u_beamMeta
);
float
neighborIndex1D
=
beamMeta
[
3
];
vec2
neighborIndex
=
vec2
(
mod
(
neighborIndex1D
,
u_textureDim
.
x
)
+
0.5
,
floor
(
neighborIndex1D
/
u_textureDim
.
x
)
+
0.5
);
...
...
@@ -206,10 +211,7 @@
for
(
int
j
=
0
;
j
<
100
;
j
++
){
//for all creases (up to 100, had to put a const int in here)
if
(
j
>=
int
(
meta
[
3
]))
break
;
float
nodeCreaseIndex1D
=
meta
[
2
]
+
float
(
j
);
vec2
nodeCreaseIndex
=
vec2
(
mod
(
nodeCreaseIndex1D
,
u_textureDimNodeCreases
.
x
)
+
0.5
,
floor
(
nodeCreaseIndex1D
/
u_textureDimNodeCreases
.
x
)
+
0.5
);
vec2
scaledNodeCreaseIndex
=
nodeCreaseIndex
/
u_textureDimNodeCreases
;
vec4
nodeCreaseMeta
=
texture2D
(
u_nodeCreaseMeta
,
scaledNodeCreaseIndex
);
//[creaseIndex, length to node, nodeType (1 or 2), isReaction]
vec4
nodeCreaseMeta
=
getFromArray
(
meta
[
2
]
+
float
(
j
),
u_textureDimNodeCreases
,
u_nodeCreaseMeta
);
float
creaseIndex1D
=
nodeCreaseMeta
[
0
];
vec2
creaseIndex
=
vec2
(
mod
(
creaseIndex1D
,
u_textureDimCreases
.
x
)
+
0.5
,
floor
(
creaseIndex1D
/
u_textureDimCreases
.
x
)
+
0.5
);
...
...
@@ -228,16 +230,10 @@
if
(
nodeNum
>
2.0
){
//crease reaction, node is on a crease
//node #1
float
normalIndex1D
=
thetas
[
2
];
vec2
normalsIndex
=
vec2
(
mod
(
normalIndex1D
,
u_textureDimFaces
.
x
)
+
0.5
,
floor
(
normalIndex1D
/
u_textureDimFaces
.
x
)
+
0.5
);
vec2
scaledNormalsIndex
=
normalsIndex
/
u_textureDimFaces
;
vec3
normal1
=
texture2D
(
u_normals
,
scaledNormalsIndex
).
xyz
;
vec3
normal1
=
getFromArray
(
thetas
[
2
],
u_textureDimFaces
,
u_normals
).
xyz
;
//node #2
normalIndex1D
=
thetas
[
3
];
normalsIndex
=
vec2
(
mod
(
normalIndex1D
,
u_textureDimFaces
.
x
)
+
0.5
,
floor
(
normalIndex1D
/
u_textureDimFaces
.
x
)
+
0.5
);
scaledNormalsIndex
=
normalsIndex
/
u_textureDimFaces
;
vec3
normal2
=
texture2D
(
u_normals
,
scaledNormalsIndex
).
xyz
;
vec3
normal2
=
getFromArray
(
thetas
[
3
],
u_textureDimFaces
,
u_normals
).
xyz
;
float
coef1
=
creaseGeo
[
2
];
float
coef2
=
creaseGeo
[
3
];
...
...
@@ -258,13 +254,36 @@
normalIndex1D
=
thetas
[
3
];
//node #2
momentArm
=
creaseGeo
[
1
];
//node #2
}
vec2
normalsIndex
=
vec2
(
mod
(
normalIndex1D
,
u_textureDimFaces
.
x
)
+
0.5
,
floor
(
normalIndex1D
/
u_textureDimFaces
.
x
)
+
0.5
);
vec2
scaledNormalsIndex
=
normalsIndex
/
u_textureDimFaces
;
vec3
normal
=
texture2D
(
u_normals
,
scaledNormalsIndex
).
xyz
;
vec3
normal
=
getFromArray
(
normalIndex1D
,
u_textureDimFaces
,
u_normals
).
xyz
;
vec3
_force
=
angForce
/
momentArm
*
normal
;
force
+=
_force
;
}
}
for
(
int
j
=
0
;
j
<
100
;
j
++
){
//for all faces (up to 100, had to put a const int in here)
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]
//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
;
//calc angles
vec3
ab
=
normalize
(
b
-
a
);
vec3
ac
=
normalize
(
c
-
a
);
vec3
bc
=
normalize
(
b
-
b
);
float
angA
=
acos
(
dot
(
ab
,
ac
));
float
angB
=
acos
(
-
1.0
*
dot
(
ab
,
bc
));
float
angC
=
acos
(
dot
(
ac
,
bc
));
//calc forces
}
...
...
js/dynamic/dynamicSolver.js
View file @
7dd459e6
...
...
@@ -277,6 +277,7 @@ function initDynamicSolver(globals){
gpuMath
.
initTextureFromData
(
"
u_creaseGeo
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
creaseGeo
,
true
);
gpuMath
.
initFrameBufferForTexture
(
"
u_creaseGeo
"
,
true
);
gpuMath
.
initTextureFromData
(
"
u_faceVertexIndices
"
,
textureDimFaces
,
textureDimFaces
,
"
FLOAT
"
,
faceVertexIndices
,
true
);
gpuMath
.
initTextureFromData
(
"
u_nominalTriangles
"
,
textureDimFaces
,
textureDimFaces
,
"
FLOAT
"
,
nominalTriangles
,
true
);
gpuMath
.
createProgram
(
"
positionCalc
"
,
vertexShader
,
document
.
getElementById
(
"
positionCalcShader
"
).
text
);
gpuMath
.
setUniformForProgram
(
"
positionCalc
"
,
"
u_velocity
"
,
0
,
"
1i
"
);
...
...
@@ -305,6 +306,7 @@ function initDynamicSolver(globals){
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_textureDimFaces
"
,
[
textureDimFaces
,
textureDimFaces
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_textureDimCreases
"
,
[
textureDimCreases
,
textureDimCreases
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_textureDimNodeCreases
"
,
[
textureDimNodeCreases
,
textureDimNodeCreases
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_textureDimNodeFaces
"
,
[
textureDimNodeFaces
,
textureDimNodeFaces
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_creasePercent
"
,
globals
.
creasePercent
,
"
1f
"
);
gpuMath
.
createProgram
(
"
thetaCalc
"
,
vertexShader
,
document
.
getElementById
(
"
thetaCalcShader
"
).
text
);
...
...
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