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
f040ca36
Commit
f040ca36
authored
Mar 06, 2017
by
amandaghassaei
Browse files
added in crease reaction
parent
ff6a05c4
Changes
5
Show whitespace changes
Inline
Side-by-side
index.html
View file @
f040ca36
...
...
@@ -165,7 +165,7 @@
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
creaseMeta2
=
texture2D
(
u_creaseMeta2
,
scaledNodeCreaseIndex
);
//[creaseIndex, length to node, node
Index (1/2)
]
vec4
creaseMeta2
=
texture2D
(
u_creaseMeta2
,
scaledNodeCreaseIndex
);
//[creaseIndex, length to node, node
Type (1 or 2), isReaction
]
float
creaseIndex1D
=
creaseMeta2
[
0
];
vec2
creaseIndex
=
vec2
(
mod
(
creaseIndex1D
,
u_textureDimCreases
.
x
)
+
0.5
,
floor
(
creaseIndex1D
/
u_textureDimCreases
.
x
)
+
0.5
);
...
...
@@ -174,6 +174,28 @@
vec4
thetas
=
texture2D
(
u_theta
,
scaledCreaseIndex
);
vec3
creaseMeta
=
texture2D
(
u_creaseMeta
,
scaledCreaseIndex
).
xyz
;
//[k, d, targetTheta]
if
(
creaseMeta2
[
3
]
<
0.0
){
//crease reaction
float
nodeNum
=
creaseMeta2
[
2
];
//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
;
//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
;
float
targetTheta
=
creaseMeta
[
2
]
*
u_creasePercent
;
float
angForce
=
creaseMeta
[
0
]
*
(
targetTheta
-
thetas
[
0
]);
// + creaseMeta[1]*thetas[1];
vec3
_force
=
-
0.5
*
(
angForce
/
creaseMeta2
[
1
]
*
normal1
+
angForce
/
creaseMeta2
[
2
]
*
normal2
);
force
+=
_force
;
}
else
{
float
nodeNum
=
creaseMeta2
[
2
];
float
normalIndex1D
=
thetas
[
2
];
//node #1
float
targetTheta
=
creaseMeta
[
2
]
*
u_creasePercent
;
...
...
@@ -191,6 +213,8 @@
force
+=
_force
;
}
}
vec3
velocity
=
force
*
u_dt
/
mass
[
0
]
+
lastVelocity
;
gl_FragColor
=
vec4
(
velocity
,
0.0
);
}
...
...
js/controls.js
View file @
f040ca36
...
...
@@ -68,7 +68,7 @@ function initControls(globals){
globals
.
shouldResetDynamicSim
=
true
;
});
setSliderInput
(
"
#creasePercent
"
,
globals
.
creasePercent
,
0
,
1
,
0.01
,
function
(
val
){
setSliderInput
(
"
#creasePercent
"
,
globals
.
creasePercent
,
-
1
,
1
,
0.01
,
function
(
val
){
globals
.
creasePercent
=
val
;
globals
.
shouldChangeCreasePercent
=
true
;
});
...
...
js/crease.js
View file @
f040ca36
...
...
@@ -2,10 +2,14 @@
* Created by amandaghassaei on 2/25/17.
*/
function
Crease
(
edge
,
face1Index
,
face2Index
,
targetTheta
,
type
,
node1
,
node2
,
index
){
//type = 0 panel, 1 crease
function
Crease
(
edge
,
face1Index
,
face2Index
,
targetTheta
,
type
,
node1
,
node2
,
index
){
//type = 0 panel, 1 crease
//face1 corresponds to node1, face2 to node2
this
.
edge
=
edge
;
for
(
var
i
=
0
;
i
<
edge
.
nodes
.
length
;
i
++
){
edge
.
nodes
[
i
].
addInvCrease
(
this
);
}
this
.
face1Index
=
face1Index
;
this
.
face2Index
=
face2Index
;
this
.
targetTheta
=
targetTheta
;
...
...
@@ -51,6 +55,14 @@ Crease.prototype.getIndex = function(){
return
this
.
index
;
};
Crease
.
prototype
.
getLengthToNode1
=
function
(){
return
this
.
getLengthTo
(
this
.
node1
);
};
Crease
.
prototype
.
getLengthToNode2
=
function
(){
return
this
.
getLengthTo
(
this
.
node2
);
};
Crease
.
prototype
.
getLengthTo
=
function
(
node
){
var
vector1
=
this
.
getVector
().
normalize
();
var
nodePosition
=
node
.
getOriginalPosition
();
...
...
@@ -69,6 +81,11 @@ Crease.prototype.getNodeIndex = function(node){
Crease
.
prototype
.
destroy
=
function
(){
this
.
node1
.
removeCrease
(
this
);
this
.
node2
.
removeCrease
(
this
);
if
(
this
.
edge
&&
this
.
edge
.
nodes
){
for
(
var
i
=
0
;
i
<
this
.
edge
.
nodes
.
length
;
i
++
){
this
.
edge
.
nodes
[
i
].
removeInvCrease
(
this
);
}
}
this
.
edge
=
null
;
this
.
face1Index
=
null
;
this
.
face2Index
=
null
;
...
...
js/dynamicModel.js
View file @
f040ca36
...
...
@@ -28,7 +28,8 @@ function initDynamicModel(globals){
var
normals
;
var
creaseMeta
;
//[k, d, targetTheta]
var
creaseMeta2
;
//[creaseIndex, length to node, nodeIndex (1/2)]
var
creaseMeta2
;
//[creaseIndex (thetaIndex), length to node, nodeIndex (1/2), ]
//[creaseIndex (thetaIndex), length to node1, length to node2, -1]
var
creaseVectors
;
//vectors of oriented edges in crease
var
theta
;
//[theta, w, normalIndex1, normalIndex2]
var
lastTheta
;
//[theta, w, normalIndex1, normalIndex2]
...
...
@@ -408,18 +409,19 @@ function initDynamicModel(globals){
}
textureDimEdges
=
calcTextureSize
(
numEdges
);
var
numCreases
=
creases
.
length
;
textureDimCreases
=
calcTextureSize
(
numCreases
);
var
numNodeCreases
=
0
;
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
){
numNodeCreases
+=
nodes
[
i
].
numCreases
();
}
numNodeCreases
+=
numCreases
*
2
;
textureDimNodeCreases
=
calcTextureSize
(
numNodeCreases
);
var
numFaces
=
geometry
.
faces
.
length
;
textureDimFaces
=
calcTextureSize
(
numFaces
);
var
numCreases
=
creases
.
length
;
textureDimCreases
=
calcTextureSize
(
numCreases
);
originalPosition
=
new
Float32Array
(
textureDim
*
textureDim
*
4
);
position
=
new
Float32Array
(
textureDim
*
textureDim
*
4
);
lastPosition
=
new
Float32Array
(
textureDim
*
textureDim
*
4
);
...
...
@@ -459,11 +461,20 @@ function initDynamicModel(globals){
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
){
meta
[
i
*
4
+
2
]
=
index
;
var
nodeCreases
=
nodes
[
i
].
creases
;
meta
[
i
*
4
+
3
]
=
nodeCreases
.
length
;
var
nodeInvCreases
=
nodes
[
i
].
invCreases
;
// console.log(nodeInvCreases);
meta
[
i
*
4
+
3
]
=
nodeCreases
.
length
+
nodeInvCreases
.
length
;
for
(
var
j
=
0
;
j
<
nodeCreases
.
length
;
j
++
){
creaseMeta2
[
index
*
4
]
=
nodeCreases
[
j
].
getIndex
();
creaseMeta2
[
index
*
4
+
1
]
=
nodeCreases
[
j
].
getLengthTo
(
nodes
[
i
]);
creaseMeta2
[
index
*
4
+
2
]
=
nodeCreases
[
j
].
getNodeIndex
(
nodes
[
i
]);
creaseMeta2
[
index
*
4
+
2
]
=
nodeCreases
[
j
].
getNodeIndex
(
nodes
[
i
]);
//type 1 or 2
index
++
;
}
for
(
var
j
=
0
;
j
<
nodeInvCreases
.
length
;
j
++
){
creaseMeta2
[
index
*
4
]
=
nodeInvCreases
[
j
].
getIndex
();
creaseMeta2
[
index
*
4
+
1
]
=
nodeInvCreases
[
j
].
getLengthToNode1
();
creaseMeta2
[
index
*
4
+
2
]
=
nodeInvCreases
[
j
].
getLengthToNode2
();
creaseMeta2
[
index
*
4
+
3
]
=
-
1
;
index
++
;
}
}
...
...
js/node.js
View file @
f040ca36
...
...
@@ -22,6 +22,7 @@ function Node(position, index){
this
.
beams
=
[];
this
.
creases
=
[];
this
.
invCreases
=
[];
this
.
externalForce
=
null
;
this
.
fixed
=
false
;
...
...
@@ -92,6 +93,16 @@ Node.prototype.removeCrease = function(crease){
if
(
index
>=
0
)
this
.
creases
.
splice
(
index
,
1
);
};
Node
.
prototype
.
addInvCrease
=
function
(
crease
){
this
.
invCreases
.
push
(
crease
);
};
Node
.
prototype
.
removeInvCrease
=
function
(
crease
){
if
(
this
.
invCreases
===
null
)
return
;
var
index
=
this
.
invCreases
.
indexOf
(
crease
);
if
(
index
>=
0
)
this
.
invCreases
.
splice
(
index
,
1
);
};
Node
.
prototype
.
addBeam
=
function
(
beam
){
this
.
beams
.
push
(
beam
);
...
...
@@ -187,5 +198,6 @@ Node.prototype.destroy = function(){
this
.
object3D
=
null
;
this
.
beams
=
null
;
this
.
creases
=
null
;
this
.
invCreases
=
null
;
this
.
externalForce
=
null
;
};
\ No newline at end of file
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