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
86707218
Commit
86707218
authored
Feb 26, 2017
by
amandaghassaei
Browse files
debugging
parent
3da80d69
Changes
2
Hide whitespace changes
Inline
Side-by-side
js/dynamicModel.js
View file @
86707218
...
@@ -33,11 +33,11 @@ function initDynamicModel(globals){
...
@@ -33,11 +33,11 @@ function initDynamicModel(globals){
var
theta
;
//[theta, w, normalIndex1, normalIndex2]
var
theta
;
//[theta, w, normalIndex1, normalIndex2]
var
lastTheta
;
//[theta, w, normalIndex1, normalIndex2]
var
lastTheta
;
//[theta, w, normalIndex1, normalIndex2]
function
syncNodesAndEdges
(){
function
syncNodesAndEdges
(
firstTime
){
nodes
=
globals
.
model
.
getNodes
();
nodes
=
globals
.
model
.
getNodes
();
edges
=
globals
.
model
.
getEdges
();
edges
=
globals
.
model
.
getEdges
();
faces
=
globals
.
model
.
getFaces
();
faces
=
globals
.
model
.
getFaces
();
//update mesh nodes
creases
=
globals
.
model
.
getCreases
();
var
vertices
=
[];
var
vertices
=
[];
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
){
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
){
...
@@ -56,9 +56,9 @@ function initDynamicModel(globals){
...
@@ -56,9 +56,9 @@ function initDynamicModel(globals){
var
avg
=
(
bounds
.
min
.
add
(
bounds
.
max
)).
multiplyScalar
(
0.5
);
var
avg
=
(
bounds
.
min
.
add
(
bounds
.
max
)).
multiplyScalar
(
0.5
);
object3D
.
position
.
set
(
-
avg
.
x
,
0
,
-
avg
.
z
);
object3D
.
position
.
set
(
-
avg
.
x
,
0
,
-
avg
.
z
);
creases
=
globals
.
model
.
getCreases
();
initTypedArrays
();
initTypedArrays
();
initTexturesAndPrograms
(
globals
.
gpuMath
,
firstTime
);
steps
=
parseInt
(
setSolveParams
());
}
}
var
steps
;
var
steps
;
...
@@ -69,9 +69,7 @@ function initDynamicModel(globals){
...
@@ -69,9 +69,7 @@ function initDynamicModel(globals){
var
textureDimFaces
=
0
;
var
textureDimFaces
=
0
;
var
textureDimCreases
=
0
;
var
textureDimCreases
=
0
;
var
textureDimNodeCreases
=
0
;
var
textureDimNodeCreases
=
0
;
syncNodesAndEdges
();
syncNodesAndEdges
(
true
);
initTexturesAndPrograms
(
globals
.
gpuMath
);
steps
=
parseInt
(
setSolveParams
());
runSolver
();
runSolver
();
function
reset
(){
function
reset
(){
...
@@ -89,9 +87,6 @@ function initDynamicModel(globals){
...
@@ -89,9 +87,6 @@ function initDynamicModel(globals){
function
runSolver
(){
function
runSolver
(){
globals
.
threeView
.
startAnimation
(
function
(){
globals
.
threeView
.
startAnimation
(
function
(){
if
(
!
globals
.
dynamicSimVisible
)
{
if
(
!
globals
.
dynamicSimVisible
)
{
if
(
globals
.
selfWeightMode
==
"
dynamic
"
){
globals
.
staticModel
.
setSelfWeight
();
}
return
;
return
;
}
}
for
(
var
j
=
0
;
j
<
steps
;
j
++
){
for
(
var
j
=
0
;
j
<
steps
;
j
++
){
...
@@ -110,6 +105,7 @@ function initDynamicModel(globals){
...
@@ -110,6 +105,7 @@ function initDynamicModel(globals){
if
(
globals
.
shouldSyncWithModel
){
if
(
globals
.
shouldSyncWithModel
){
syncNodesAndEdges
();
syncNodesAndEdges
();
// reset();
globals
.
shouldSyncWithModel
=
false
;
globals
.
shouldSyncWithModel
=
false
;
}
else
{
}
else
{
if
(
globals
.
forceHasChanged
)
{
if
(
globals
.
forceHasChanged
)
{
...
@@ -185,14 +181,14 @@ function initDynamicModel(globals){
...
@@ -185,14 +181,14 @@ function initDynamicModel(globals){
var
pixels
=
new
Uint8Array
(
height
*
textureDim
*
4
*
vectorLength
);
var
pixels
=
new
Uint8Array
(
height
*
textureDim
*
4
*
vectorLength
);
globals
.
gpuMath
.
readPixels
(
0
,
0
,
textureDim
*
vectorLength
,
height
,
pixels
);
globals
.
gpuMath
.
readPixels
(
0
,
0
,
textureDim
*
vectorLength
,
height
,
pixels
);
var
parsedPixels
=
new
Float32Array
(
pixels
.
buffer
);
var
parsedPixels
=
new
Float32Array
(
pixels
.
buffer
);
//
for (var i = 0; i < nodes.length; i++) {
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
//
var rgbaIndex = i * vectorLength;
var
rgbaIndex
=
i
*
vectorLength
;
//
var nodePosition = new THREE.Vector3(parsedPixels[rgbaIndex], parsedPixels[rgbaIndex + 1], parsedPixels[rgbaIndex + 2]);
var
nodePosition
=
new
THREE
.
Vector3
(
parsedPixels
[
rgbaIndex
],
parsedPixels
[
rgbaIndex
+
1
],
parsedPixels
[
rgbaIndex
+
2
]);
//
nodes[i].render(nodePosition);
nodes
[
i
].
render
(
nodePosition
);
//
}
}
//
for (var i=0;i<edges.length;i++){
for
(
var
i
=
0
;
i
<
edges
.
length
;
i
++
){
//
edges[i].render();
edges
[
i
].
render
();
//
}
}
geometry
.
verticesNeedUpdate
=
true
;
geometry
.
verticesNeedUpdate
=
true
;
geometry
.
computeFaceNormals
();
geometry
.
computeFaceNormals
();
updateNormals
();
updateNormals
();
...
@@ -222,25 +218,28 @@ function initDynamicModel(globals){
...
@@ -222,25 +218,28 @@ function initDynamicModel(globals){
return
(
1
/
(
2
*
Math
.
PI
*
maxFreqNat
))
*
0.9
;
//0.9 of max delta t for good measure
return
(
1
/
(
2
*
Math
.
PI
*
maxFreqNat
))
*
0.9
;
//0.9 of max delta t for good measure
}
}
function
initTexturesAndPrograms
(
gpuMath
){
function
initTexturesAndPrograms
(
gpuMath
,
firstTime
){
var
vertexShader
=
document
.
getElementById
(
"
vertexShader
"
).
text
;
var
vertexShader
=
document
.
getElementById
(
"
vertexShader
"
).
text
;
gpuMath
.
initTextureFromData
(
"
u_position
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
position
);
gpuMath
.
initTextureFromData
(
"
u_position
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
position
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
u_position
"
);
gpuMath
.
initTextureFromData
(
"
u_lastPosition
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
lastPosition
,
!
firstTime
);
gpuMath
.
initTextureFromData
(
"
u_lastPosition
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
lastPosition
);
gpuMath
.
initTextureFromData
(
"
u_velocity
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
velocity
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
u_lastPosition
"
);
gpuMath
.
initTextureFromData
(
"
u_lastVelocity
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
lastVelocity
,
!
firstTime
);
gpuMath
.
initTextureFromData
(
"
u_velocity
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
velocity
);
gpuMath
.
initTextureFromData
(
"
u_theta
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
theta
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
u_velocity
"
);
gpuMath
.
initTextureFromData
(
"
u_lastTheta
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
lastTheta
,
!
firstTime
);
gpuMath
.
initTextureFromData
(
"
u_lastVelocity
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
lastVelocity
);
gpuMath
.
initFrameBufferForTexture
(
"
u_lastVelocity
"
);
if
(
firstTime
)
{
gpuMath
.
initTextureFromData
(
"
u_theta
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
theta
);
gpuMath
.
initFrameBufferForTexture
(
"
u_position
"
);
gpuMath
.
initFrameBufferForTexture
(
"
u_theta
"
);
gpuMath
.
initFrameBufferForTexture
(
"
u_lastPosition
"
);
gpuMath
.
initTextureFromData
(
"
u_lastTheta
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
lastTheta
);
gpuMath
.
initFrameBufferForTexture
(
"
u_velocity
"
);
gpuMath
.
initFrameBufferForTexture
(
"
u_lastTheta
"
);
gpuMath
.
initFrameBufferForTexture
(
"
u_lastVelocity
"
);
gpuMath
.
initFrameBufferForTexture
(
"
u_theta
"
);
gpuMath
.
initTextureFromData
(
"
u_meta
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
meta
);
gpuMath
.
initFrameBufferForTexture
(
"
u_lastTheta
"
);
gpuMath
.
initTextureFromData
(
"
u_creaseMeta2
"
,
textureDimNodeCreases
,
textureDimNodeCreases
,
"
FLOAT
"
,
creaseMeta2
);
}
gpuMath
.
initTextureFromData
(
"
u_meta
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
meta
,
true
);
gpuMath
.
initTextureFromData
(
"
u_creaseMeta2
"
,
textureDimNodeCreases
,
textureDimNodeCreases
,
"
FLOAT
"
,
creaseMeta2
,
true
);
gpuMath
.
createProgram
(
"
positionCalc
"
,
vertexShader
,
document
.
getElementById
(
"
positionCalcShader
"
).
text
);
gpuMath
.
createProgram
(
"
positionCalc
"
,
vertexShader
,
document
.
getElementById
(
"
positionCalcShader
"
).
text
);
gpuMath
.
setUniformForProgram
(
"
positionCalc
"
,
"
u_velocity
"
,
0
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
positionCalc
"
,
"
u_velocity
"
,
0
,
"
1i
"
);
...
@@ -275,8 +274,8 @@ function initDynamicModel(globals){
...
@@ -275,8 +274,8 @@ function initDynamicModel(globals){
gpuMath
.
setUniformForProgram
(
"
thetaCalc
"
,
"
u_textureDimCreases
"
,
[
textureDimCreases
,
textureDimCreases
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
thetaCalc
"
,
"
u_textureDimCreases
"
,
[
textureDimCreases
,
textureDimCreases
],
"
2f
"
);
gpuMath
.
createProgram
(
"
packToBytes
"
,
vertexShader
,
document
.
getElementById
(
"
packToBytesShader
"
).
text
);
gpuMath
.
createProgram
(
"
packToBytes
"
,
vertexShader
,
document
.
getElementById
(
"
packToBytesShader
"
).
text
);
gpuMath
.
initTextureFromData
(
"
outputBytes
"
,
textureDim
*
4
,
textureDim
,
"
UNSIGNED_BYTE
"
,
null
);
gpuMath
.
initTextureFromData
(
"
outputBytes
"
,
textureDim
*
4
,
textureDim
,
"
UNSIGNED_BYTE
"
,
null
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
outputBytes
"
);
if
(
firstTime
)
gpuMath
.
initFrameBufferForTexture
(
"
outputBytes
"
);
gpuMath
.
setUniformForProgram
(
"
packToBytes
"
,
"
u_floatTextureDim
"
,
[
textureDim
,
textureDim
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
packToBytes
"
,
"
u_floatTextureDim
"
,
[
textureDim
,
textureDim
],
"
2f
"
);
gpuMath
.
createProgram
(
"
zeroTexture
"
,
vertexShader
,
document
.
getElementById
(
"
zeroTexture
"
).
text
);
gpuMath
.
createProgram
(
"
zeroTexture
"
,
vertexShader
,
document
.
getElementById
(
"
zeroTexture
"
).
text
);
...
...
js/model.js
View file @
86707218
...
@@ -26,7 +26,7 @@ function initModel(globals){
...
@@ -26,7 +26,7 @@ function initModel(globals){
faces
.
push
(
new
THREE
.
Face3
(
0
,
2
,
3
));
faces
.
push
(
new
THREE
.
Face3
(
0
,
2
,
3
));
var
creases
=
[];
var
creases
=
[];
//
creases.push(new Crease(edges[2], 1, 0, Math.PI/2, 1, nodes[3], nodes[1], 0));
creases
.
push
(
new
Crease
(
edges
[
2
],
1
,
0
,
Math
.
PI
/
2
,
1
,
nodes
[
3
],
nodes
[
1
],
0
));
function
buildModel
(
_faces
,
_vertices
,
_allEdges
,
numOutline
,
numMountians
,
numValleys
,
numCuts
){
function
buildModel
(
_faces
,
_vertices
,
_allEdges
,
numOutline
,
numMountians
,
numValleys
,
numCuts
){
...
@@ -68,10 +68,11 @@ function initModel(globals){
...
@@ -68,10 +68,11 @@ function initModel(globals){
var
oldCreases
=
creases
;
var
oldCreases
=
creases
;
nodes
=
_nodes
;
nodes
=
_nodes
;
edges
=
_edges
;
faces
=
_faces
;
faces
=
_faces
;
creases
=
_creases
;
creases
=
_creases
;
globals
.
dynamicModel
.
syncNodesAndEdges
()
;
globals
.
shouldSyncWithModel
=
true
;
for
(
var
i
=
0
;
i
<
oldNodes
.
length
;
i
++
){
for
(
var
i
=
0
;
i
<
oldNodes
.
length
;
i
++
){
oldNodes
[
i
].
destroy
();
oldNodes
[
i
].
destroy
();
...
...
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