Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OrigamiSimulator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Amanda Ghassaei
OrigamiSimulator
Commits
f9c48575
Commit
f9c48575
authored
Feb 25, 2017
by
amandaghassaei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eod
parent
39d05ea4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
33 deletions
+47
-33
index.html
index.html
+6
-3
js/controls.js
js/controls.js
+6
-5
js/dynamicModel.js
js/dynamicModel.js
+32
-24
js/globals.js
js/globals.js
+2
-0
js/model.js
js/model.js
+1
-1
No files found.
index.html
View file @
f9c48575
...
...
@@ -101,6 +101,7 @@
uniform
vec2
u_textureDimFaces
;
uniform
vec2
u_textureDimCreases
;
uniform
vec2
u_textureDimNodeCreases
;
uniform
float
u_creasePercent
;
uniform
float
u_dt
;
uniform
sampler2D
u_lastPosition
;
uniform
sampler2D
u_lastVelocity
;
...
...
@@ -124,7 +125,6 @@
return
;
}
vec3
force
=
texture2D
(
u_externalForces
,
scaledFragCoord
).
xyz
;
force
.
y
=
1.0
;
vec3
lastPosition
=
texture2D
(
u_lastPosition
,
scaledFragCoord
).
xyz
;
vec3
lastVelocity
=
texture2D
(
u_lastVelocity
,
scaledFragCoord
).
xyz
;
vec3
originalPosition
=
texture2D
(
u_originalPosition
,
scaledFragCoord
).
xyz
;
...
...
@@ -173,12 +173,15 @@
float
nodeNum
=
creaseMeta2
[
2
];
float
normalIndex1D
=
thetas
[
2
];
if
(
nodeNum
>
1.1
)
normalIndex1D
=
thetas
[
3
];
float
targetTheta
=
creaseMeta
[
2
]
*=
u_creasePercent
;
if
(
nodeNum
>
1.1
)
{
normalIndex1D
=
thetas
[
3
];
}
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
;
float
angForce
=
creaseMeta
[
0
]
*
(
creaseMeta
[
2
]
-
thetas
[
0
])
+
creaseMeta
[
1
]
*
thetas
[
1
];;
float
angForce
=
creaseMeta
[
0
]
*
(
targetTheta
-
thetas
[
0
])
+
creaseMeta
[
1
]
*
thetas
[
1
];;
float
momentArm
=
creaseMeta2
[
1
];
vec3
_force
=
angForce
/
momentArm
*
normal
;
...
...
js/controls.js
View file @
f9c48575
...
...
@@ -48,28 +48,29 @@ function initControls(globals){
setSliderInput
(
"
#axialStiffness
"
,
globals
.
axialStiffness
,
100
,
1000
,
1
,
function
(
val
){
globals
.
axialStiffness
=
val
;
globals
.
dynamicModel
.
updateMaterials
()
;
globals
.
materialHasChanged
=
true
;
});
setSliderInput
(
"
#creaseStiffness
"
,
globals
.
creaseStiffness
,
0
,
100
,
1
,
function
(
val
){
globals
.
creaseStiffness
=
val
;
globals
.
dynamicModel
.
updateCreasesMeta
()
;
globals
.
creaseMaterialHasChanged
=
true
;
});
setSliderInput
(
"
#panelStiffness
"
,
globals
.
panelStiffness
,
0
,
100
,
1
,
function
(
val
){
globals
.
panelStiffness
=
val
;
globals
.
dynamicModel
.
updateCreasesMeta
()
;
globals
.
creaseMaterialHasChanged
=
true
;
});
setSlider
(
"
#damping
"
,
globals
.
percentDamping
,
0.05
,
1
,
0.01
,
function
(
val
){
globals
.
percentDamping
=
val
;
},
function
(){
globals
.
dynamicModel
.
updateMaterials
()
;
globals
.
dynamicModel
.
reset
()
;
globals
.
materialHasChanged
=
true
;
globals
.
shouldResetDynamicSim
=
true
;
});
setSliderInput
(
"
#creasePercent
"
,
globals
.
creasePercent
,
0
,
1
,
0.01
,
function
(
val
){
globals
.
creasePercent
=
val
;
globals
.
shouldChangeCreasePercent
=
true
;
});
function
setDeltaT
(
val
){
...
...
js/dynamicModel.js
View file @
f9c48575
...
...
@@ -68,7 +68,6 @@ function initDynamicModel(globals){
globals
.
gpuMath
.
step
(
"
zeroTexture
"
,
[],
"
u_lastPosition
"
);
globals
.
gpuMath
.
step
(
"
zeroTexture
"
,
[],
"
u_velocity
"
);
globals
.
gpuMath
.
step
(
"
zeroTexture
"
,
[],
"
u_lastVelocity
"
);
// for (var i=0;i<creases.length;i++){
// lastTheta[i*4] = 0;
// lastTheta[i*4+1] = 0;
...
...
@@ -109,10 +108,18 @@ function initDynamicModel(globals){
updateMaterials
();
globals
.
materialHasChanged
=
false
;
}
if
(
globals
.
creaseMaterialHasChanged
){
updateCreasesMeta
();
globals
.
creaseMaterialHasChanged
=
false
;
}
if
(
globals
.
shouldResetDynamicSim
){
reset
();
globals
.
shouldResetDynamicSim
=
false
;
}
if
(
globals
.
shouldChangeCreasePercent
){
setCreasePercent
(
globals
.
creasePercent
);
globals
.
shouldChangeCreasePercent
=
false
;
}
var
gpuMath
=
globals
.
gpuMath
;
...
...
@@ -131,25 +138,23 @@ function initDynamicModel(globals){
function
render
(){
var
vectorLength
=
1
;
globals
.
gpuMath
.
setProgram
(
"
packToBytes
"
);
globals
.
gpuMath
.
setUniformForProgram
(
"
packToBytes
"
,
"
u_vectorLength
"
,
vectorLength
,
"
1f
"
);
globals
.
gpuMath
.
setSize
(
textureDim
*
vectorLength
,
textureDim
);
globals
.
gpuMath
.
step
(
"
packToBytes
"
,
[
"
u_theta
"
],
"
outputBytes
"
);
if
(
globals
.
gpuMath
.
readyToRead
())
{
var
numPixels
=
creases
.
length
*
vectorLength
;
var
height
=
Math
.
ceil
(
numPixels
/
(
textureDimCreases
*
vectorLength
));
var
pixels
=
new
Uint8Array
(
height
*
textureDimCreases
*
4
*
vectorLength
);
globals
.
gpuMath
.
readPixels
(
0
,
0
,
textureDimCreases
*
vectorLength
,
height
,
pixels
);
var
parsedPixels
=
new
Float32Array
(
pixels
.
buffer
);
for
(
var
i
=
0
;
i
<
creases
.
length
;
i
++
)
{
// console.log(parsedPixels[i])
}
}
else
{
console
.
log
(
"
here
"
);
}
// var vectorLength = 1;
// globals.gpuMath.setProgram("packToBytes");
// globals.gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
// globals.gpuMath.setSize(textureDim*vectorLength, textureDim);
// globals.gpuMath.step("packToBytes", ["u_theta"], "outputBytes");
// if (globals.gpuMath.readyToRead()) {
// var numPixels = creases.length*vectorLength;
// var height = Math.ceil(numPixels/(textureDimCreases*vectorLength));
// var pixels = new Uint8Array(height*textureDimCreases*4*vectorLength);
// globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels);
// var parsedPixels = new Float32Array(pixels.buffer);
// for (var i = 0; i < creases.length; i++) {
// // console.log(parsedPixels[i])
// }
// } else {
// console.log("here");
// }
var
vectorLength
=
3
;
globals
.
gpuMath
.
setProgram
(
"
packToBytes
"
);
...
...
@@ -243,6 +248,7 @@ function initDynamicModel(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_creasePercent
"
,
globals
.
creasePercent
,
"
1f
"
);
gpuMath
.
createProgram
(
"
thetaCalc
"
,
vertexShader
,
document
.
getElementById
(
"
thetaCalcShader
"
).
text
);
gpuMath
.
setUniformForProgram
(
"
thetaCalc
"
,
"
u_normals
"
,
0
,
"
1i
"
);
...
...
@@ -275,6 +281,7 @@ function initDynamicModel(globals){
}
function
updateMaterials
(
initing
){
var
index
=
0
;
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
){
if
(
initing
)
{
...
...
@@ -357,6 +364,11 @@ function initDynamicModel(globals){
}
function
setCreasePercent
(
percent
){
globals
.
gpuMath
.
setProgram
(
"
velocityCalc
"
);
globals
.
gpuMath
.
setUniformForProgram
(
"
velocityCalc
"
,
"
u_creasePercent
"
,
percent
,
"
1f
"
);
}
function
initTypedArrays
(){
textureDim
=
calcTextureSize
(
nodes
.
length
);
...
...
@@ -446,10 +458,6 @@ function initDynamicModel(globals){
return
{
syncNodesAndEdges
:
syncNodesAndEdges
,
updateOriginalPosition
:
updateOriginalPosition
,
updateMaterials
:
updateMaterials
,
updateCreasesMeta
:
updateCreasesMeta
,
reset
:
reset
,
pause
:
pause
,
resume
:
resume
,
setVisibility
:
setVisibility
...
...
js/globals.js
View file @
f9c48575
...
...
@@ -11,7 +11,9 @@ function initGlobals(){
fixedHasChanged
:
false
,
forceHasChanged
:
false
,
materialHasChanged
:
false
,
creaseMaterialHasChanged
:
false
,
shouldResetDynamicSim
:
false
,
shouldChangeCreasePercent
:
false
,
//3d vis
dynamicSimVisible
:
true
,
...
...
js/model.js
View file @
f9c48575
...
...
@@ -22,7 +22,7 @@ function initModel(globals){
edges
.
push
(
new
Beam
([
nodes
[
3
],
nodes
[
2
]]));
var
creases
=
[];
creases
.
push
(
new
Crease
(
edges
[
2
],
1
,
0
,
0
,
0
,
nodes
[
3
],
nodes
[
1
],
0
));
creases
.
push
(
new
Crease
(
edges
[
2
],
1
,
0
,
Math
.
PI
,
1
,
nodes
[
3
],
nodes
[
1
],
0
));
_
.
each
(
nodes
,
function
(
node
){
globals
.
threeView
.
sceneAddModel
(
node
.
getObject3D
());
...
...
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