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
a60838a9
Commit
a60838a9
authored
Apr 30, 2017
by
amandaghassaei
Browse files
debugging
parent
57c070f8
Changes
6
Hide whitespace changes
Inline
Side-by-side
index.html
View file @
a60838a9
...
...
@@ -259,17 +259,50 @@
if
(
sign
<
0.0
)
theta
*=
-
1.0
;
float
diff
=
theta
-
lastTheta
[
0
];
float
projectedTheta
=
lastTheta
[
0
]
+
lastTheta
[
1
]
*
u_dt
;
if
(
diff
<
-
5.
5
||
(
diff
<
-
3.0
&&
projectedTheta
>
6.0
)
)
{
if
(
diff
<
-
5.
0
)
{
diff
+=
TWO_PI
;
theta
=
lastTheta
[
0
]
+
diff
;
}
else
if
(
diff
>
5.
5
||
(
diff
>
3.0
&&
projectedTheta
<
-
6.0
)
)
{
diff
-=
TWO_PI
;
}
else
if
(
diff
>
5.
0
)
{
diff
-=
TWO_PI
;
theta
=
lastTheta
[
0
]
+
diff
;
}
gl_FragColor
=
vec4
(
theta
,
diff
,
lastTheta
[
2
],
lastTheta
[
3
]);
//[theta, w, normal1Index, normal2Index]
}
</script>
<script
id=
"normalCalc"
type=
"x-shader/x-fragment"
>
precision
mediump
float
;
uniform
vec2
u_textureDim
;
uniform
vec2
u_textureDimFaces
;
uniform
sampler2D
u_faceVertexIndices
;
uniform
sampler2D
u_lastPosition
;
uniform
sampler2D
u_originalPosition
;
void
main
(){
vec2
fragCoord
=
gl_FragCoord
.
xy
;
vec2
scaledFragCoord
=
fragCoord
/
u_textureDimFaces
;
vec3
indices
=
texture2D
(
u_faceVertexIndices
,
scaledFragCoord
).
xyz
;
float
nodeIndex1D
=
indices
[
0
];
vec2
nodeIndex
=
vec2
(
mod
(
nodeIndex1D
,
u_textureDim
.
x
)
+
0.5
,
floor
(
nodeIndex1D
/
u_textureDim
.
x
)
+
0.5
);
vec2
scaledNodeIndex
=
nodeIndex
/
u_textureDim
;
vec3
a
=
texture2D
(
u_lastPosition
,
scaledNodeIndex
).
xyz
+
texture2D
(
u_originalPosition
,
scaledNodeIndex
).
xyz
;
nodeIndex1D
=
indices
[
1
];
nodeIndex
=
vec2
(
mod
(
nodeIndex1D
,
u_textureDim
.
x
)
+
0.5
,
floor
(
nodeIndex1D
/
u_textureDim
.
x
)
+
0.5
);
scaledNodeIndex
=
nodeIndex
/
u_textureDim
;
vec3
b
=
texture2D
(
u_lastPosition
,
scaledNodeIndex
).
xyz
+
texture2D
(
u_originalPosition
,
scaledNodeIndex
).
xyz
;
nodeIndex1D
=
indices
[
2
];
nodeIndex
=
vec2
(
mod
(
nodeIndex1D
,
u_textureDim
.
x
)
+
0.5
,
floor
(
nodeIndex1D
/
u_textureDim
.
x
)
+
0.5
);
scaledNodeIndex
=
nodeIndex
/
u_textureDim
;
vec3
c
=
texture2D
(
u_lastPosition
,
scaledNodeIndex
).
xyz
+
texture2D
(
u_originalPosition
,
scaledNodeIndex
).
xyz
;
gl_FragColor
=
vec4
(
normalize
(
cross
(
b
-
a
,
c
-
a
)),
0.0
);
}
</script>
<script
type=
"text/javascript"
src=
"dependencies/jquery-3.1.1.min.js"
></script>
<script
type=
"text/javascript"
src=
"dependencies/jquery-ui.min.js"
></script>
<script
type=
"text/javascript"
src=
"dependencies/flat-ui.min.js"
></script>
...
...
js/dynamic/dynamicModel.js
View file @
a60838a9
...
...
@@ -4,7 +4,7 @@
function
initDynamicModel
(
globals
){
var
material
=
new
THREE
.
MeshNormalMaterial
({
shading
:
THREE
.
FlatShading
,
side
:
THREE
.
Double
Side
});
var
material
=
new
THREE
.
MeshNormalMaterial
({
shading
:
THREE
.
FlatShading
,
side
:
THREE
.
Front
Side
});
var
geometry
=
new
THREE
.
Geometry
();
geometry
.
dynamic
=
true
;
var
object3D
=
new
THREE
.
Mesh
(
geometry
,
material
);
...
...
@@ -29,6 +29,7 @@ function initDynamicModel(globals){
var
beamMeta
;
//[K, D, length, otherNodeIndex]
var
normals
;
var
faceVertexIndices
;
//[a,b,c]
var
creaseMeta
;
//[k, d, targetTheta]
var
creaseMeta2
;
//[creaseIndex (thetaIndex), length to node, nodeIndex (1/2), ]
//[creaseIndex (thetaIndex), length to node1, length to node2, -1]
...
...
@@ -95,6 +96,7 @@ function initDynamicModel(globals){
if
(
!
globals
.
dynamicSimVisible
)
{
return
;
}
// steps = 1;
for
(
var
j
=
0
;
j
<
steps
;
j
++
){
solveStep
();
}
...
...
@@ -142,6 +144,10 @@ function initDynamicModel(globals){
var
gpuMath
=
globals
.
gpuMath
;
gpuMath
.
setProgram
(
"
normalCalc
"
);
gpuMath
.
setSize
(
textureDimFaces
,
textureDimFaces
);
gpuMath
.
step
(
"
normalCalc
"
,
[
"
u_faceVertexIndices
"
,
"
u_lastPosition
"
,
"
u_originalPosition
"
],
"
u_normals
"
);
gpuMath
.
setProgram
(
"
thetaCalc
"
);
gpuMath
.
setSize
(
textureDimCreases
,
textureDimCreases
);
gpuMath
.
step
(
"
thetaCalc
"
,
[
"
u_normals
"
,
"
u_lastTheta
"
,
"
u_creaseVectors
"
],
"
u_theta
"
);
...
...
@@ -159,11 +165,29 @@ function initDynamicModel(globals){
function
render
(){
// var vectorLength = 1;
var
vectorLength
=
1
;
globals
.
gpuMath
.
setProgram
(
"
packToBytes
"
);
globals
.
gpuMath
.
setUniformForProgram
(
"
packToBytes
"
,
"
u_vectorLength
"
,
vectorLength
,
"
1f
"
);
globals
.
gpuMath
.
setSize
(
textureDimCreases
*
vectorLength
,
textureDimCreases
);
globals
.
gpuMath
.
step
(
"
packToBytes
"
,
[
"
u_lastTheta
"
],
"
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
<
1
;
i
++
)
{
console
.
log
(
parsedPixels
);
}
}
else
{
console
.
log
(
"
here
"
);
}
// var vectorLength = 3;
// 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");
// globals.gpuMath.step("packToBytes", ["u_
normals
"], "outputBytes");
// if (globals.gpuMath.readyToRead()) {
// var numPixels = creases.length*vectorLength;
// var height = Math.ceil(numPixels/(textureDimCreases*vectorLength));
...
...
@@ -171,7 +195,7 @@ function initDynamicModel(globals){
// globals.gpuMath.readPixels(0, 0, textureDimCreases * vectorLength, height, pixels);
// var parsedPixels = new Float32Array(pixels.buffer);
// for (var i = 0; i < 1; i++) {
// console.log(parsedPixels[i]
)
// console.log(parsedPixels[i]
+ " " + parsedPixels[i+1] + " " + parsedPixels[i+2] + " ");
// }
// } else {
// console.log("here");
...
...
@@ -199,7 +223,6 @@ function initDynamicModel(globals){
}
geometry
.
verticesNeedUpdate
=
true
;
geometry
.
computeFaceNormals
();
updateNormals
();
}
else
{
console
.
log
(
"
here
"
);
}
...
...
@@ -238,6 +261,7 @@ function initDynamicModel(globals){
gpuMath
.
initTextureFromData
(
"
u_lastVelocity
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
lastVelocity
,
!
firstTime
);
gpuMath
.
initTextureFromData
(
"
u_theta
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
theta
,
!
firstTime
);
gpuMath
.
initTextureFromData
(
"
u_lastTheta
"
,
textureDimCreases
,
textureDimCreases
,
"
FLOAT
"
,
lastTheta
,
!
firstTime
);
gpuMath
.
initTextureFromData
(
"
u_normals
"
,
textureDimFaces
,
textureDimFaces
,
"
FLOAT
"
,
normals
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
u_position
"
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
u_lastPosition
"
,
!
firstTime
);
...
...
@@ -245,9 +269,11 @@ function initDynamicModel(globals){
gpuMath
.
initFrameBufferForTexture
(
"
u_lastVelocity
"
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
u_theta
"
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
u_lastTheta
"
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
u_normals
"
,
!
firstTime
);
gpuMath
.
initTextureFromData
(
"
u_meta
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
meta
,
true
);
gpuMath
.
initTextureFromData
(
"
u_creaseMeta2
"
,
textureDimNodeCreases
,
textureDimNodeCreases
,
"
FLOAT
"
,
creaseMeta2
,
true
);
gpuMath
.
initTextureFromData
(
"
u_faceVertexIndices
"
,
textureDimFaces
,
textureDimFaces
,
"
FLOAT
"
,
faceVertexIndices
,
true
);
gpuMath
.
createProgram
(
"
positionCalc
"
,
vertexShader
,
document
.
getElementById
(
"
positionCalcShader
"
).
text
);
gpuMath
.
setUniformForProgram
(
"
positionCalc
"
,
"
u_velocity
"
,
0
,
"
1i
"
);
...
...
@@ -281,6 +307,13 @@ function initDynamicModel(globals){
gpuMath
.
setUniformForProgram
(
"
thetaCalc
"
,
"
u_textureDimFaces
"
,
[
textureDimFaces
,
textureDimFaces
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
thetaCalc
"
,
"
u_textureDimCreases
"
,
[
textureDimCreases
,
textureDimCreases
],
"
2f
"
);
gpuMath
.
createProgram
(
"
normalCalc
"
,
vertexShader
,
document
.
getElementById
(
"
normalCalc
"
).
text
);
gpuMath
.
setUniformForProgram
(
"
normalCalc
"
,
"
u_faceVertexIndices
"
,
0
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
normalCalc
"
,
"
u_lastPosition
"
,
1
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
normalCalc
"
,
"
u_originalPosition
"
,
2
,
"
1i
"
);
gpuMath
.
setUniformForProgram
(
"
normalCalc
"
,
"
u_textureDim
"
,
[
textureDim
,
textureDim
],
"
2f
"
);
gpuMath
.
setUniformForProgram
(
"
normalCalc
"
,
"
u_textureDimFaces
"
,
[
textureDimFaces
,
textureDimFaces
],
"
2f
"
);
gpuMath
.
createProgram
(
"
packToBytes
"
,
vertexShader
,
document
.
getElementById
(
"
packToBytesShader
"
).
text
);
gpuMath
.
initTextureFromData
(
"
outputBytes
"
,
textureDim
*
4
,
textureDim
,
"
UNSIGNED_BYTE
"
,
null
,
!
firstTime
);
gpuMath
.
initFrameBufferForTexture
(
"
outputBytes
"
,
!
firstTime
);
...
...
@@ -355,17 +388,6 @@ function initDynamicModel(globals){
globals
.
gpuMath
.
initTextureFromData
(
"
u_originalPosition
"
,
textureDim
,
textureDim
,
"
FLOAT
"
,
originalPosition
,
true
);
}
function
updateNormals
(){
var
numFaces
=
geometry
.
faces
.
length
;
for
(
var
i
=
0
;
i
<
numFaces
;
i
++
){
var
normal
=
geometry
.
faces
[
i
].
normal
;
normals
[
i
*
4
]
=
normal
.
x
;
normals
[
i
*
4
+
1
]
=
normal
.
y
;
normals
[
i
*
4
+
2
]
=
normal
.
z
;
}
globals
.
gpuMath
.
initTextureFromData
(
"
u_normals
"
,
textureDimFaces
,
textureDimFaces
,
"
FLOAT
"
,
normals
,
true
);
}
function
updateCreaseVectors
(){
for
(
var
i
=
0
;
i
<
creases
.
length
;
i
++
){
var
rgbaIndex
=
i
*
4
;
...
...
@@ -437,18 +459,26 @@ function initDynamicModel(globals){
beamMeta
=
new
Float32Array
(
textureDimEdges
*
textureDimEdges
*
4
);
normals
=
new
Float32Array
(
textureDimFaces
*
textureDimFaces
*
4
);
faceVertexIndices
=
new
Float32Array
(
textureDimFaces
*
textureDimFaces
*
4
);
creaseMeta
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
creaseMeta2
=
new
Float32Array
(
textureDimNodeCreases
*
textureDimNodeCreases
*
4
);
creaseVectors
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
theta
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
lastTheta
=
new
Float32Array
(
textureDimCreases
*
textureDimCreases
*
4
);
for
(
var
i
=
0
;
i
<
faces
.
length
;
i
++
){
var
face
=
faces
[
i
];
faceVertexIndices
[
4
*
i
]
=
face
.
a
;
faceVertexIndices
[
4
*
i
+
1
]
=
face
.
b
;
faceVertexIndices
[
4
*
i
+
2
]
=
face
.
c
;
}
for
(
var
i
=
0
;
i
<
textureDim
*
textureDim
;
i
++
){
mass
[
4
*
i
+
1
]
=
1
;
//set all fixed by default
}
_
.
each
(
nodes
,
function
(
node
,
index
){
mass
[
4
*
index
]
=
node
.
getSimMass
();
mass
[
4
*
index
]
=
node
.
getSimMass
();
//todo move into bottom loop?
});
for
(
var
i
=
0
;
i
<
textureDimCreases
*
textureDimCreases
;
i
++
){
...
...
@@ -489,7 +519,6 @@ function initDynamicModel(globals){
updateExternalForces
();
updateCreasesMeta
(
true
);
updateCreaseVectors
();
updateNormals
();
}
function
pause
(){
...
...
js/main.js
View file @
a60838a9
...
...
@@ -121,7 +121,7 @@ $(function() {
globals
.
model
=
initModel
(
globals
);
globals
.
staticSolver
=
initStaticSolver
(
globals
);
globals
.
dynamicModel
=
initDynamicModel
(
globals
);
//
global.dynamicModel.syncNodesAndEdges(true);
global
s
.
dynamicModel
.
syncNodesAndEdges
(
true
);
// globals.staticSolver.syncNodesAndEdges();
globals
.
pattern
=
initPattern
(
globals
);
globals
.
threeView
.
render
();
...
...
js/model.js
View file @
a60838a9
...
...
@@ -13,12 +13,15 @@ function initModel(globals){
nodes
.
push
(
new
Node
(
new
THREE
.
Vector3
(
10
,
0
,
0
),
nodes
.
length
));
nodes
.
push
(
new
Node
(
new
THREE
.
Vector3
(
0
,
0
,
-
10
),
nodes
.
length
));
nodes
.
push
(
new
Node
(
new
THREE
.
Vector3
(
10
,
0
,
-
10
),
nodes
.
length
));
// nodes[0].setFixed(true);
// nodes[1].setFixed(true);
// nodes[2].setFixed(true);
// nodes.push(new Node(new THREE.Vector3(-10,0,0), nodes.length));
nodes
[
0
].
setFixed
(
true
);
nodes
[
1
].
setFixed
(
true
);
nodes
[
2
].
setFixed
(
true
);
var
edges
=
[];
edges
.
push
(
new
Beam
([
nodes
[
0
],
nodes
[
1
]]));
edges
.
push
(
new
Beam
([
nodes
[
1
],
nodes
[
0
]]));
edges
.
push
(
new
Beam
([
nodes
[
1
],
nodes
[
2
]]));
edges
.
push
(
new
Beam
([
nodes
[
2
],
nodes
[
0
]]));
edges
.
push
(
new
Beam
([
nodes
[
3
],
nodes
[
0
]]));
...
...
@@ -26,34 +29,47 @@ function initModel(globals){
edges
.
push
(
new
Beam
([
nodes
[
3
],
nodes
[
4
]]));
edges
.
push
(
new
Beam
([
nodes
[
2
],
nodes
[
4
]]));
// edges.push(new Beam([nodes[4], nodes[0]]));
// edges.push(new Beam([nodes[4], nodes[1]]));
// edges.push(new Beam([nodes[3], nodes[4]]));
var
faces
=
[];
faces
.
push
(
new
THREE
.
Face3
(
0
,
1
,
2
));
faces
.
push
(
new
THREE
.
Face3
(
0
,
2
,
3
));
faces
.
push
(
new
THREE
.
Face3
(
4
,
3
,
2
));
// faces.push(new THREE.Face3(4,1,0));
// faces.push(new THREE.Face3(3,4,0));
var
creases
=
[];
creases
.
push
(
new
Crease
(
edges
[
2
],
0
,
1
,
Math
.
PI
-
0.001
,
1
,
nodes
[
1
],
nodes
[
3
],
0
));
creases
.
push
(
new
Crease
(
edges
[
4
],
2
,
1
,
-
(
Math
.
PI
-
0.001
),
1
,
nodes
[
4
],
nodes
[
0
],
1
));
// creases.push(new Crease(edges[5], 3, 2, -(Math.PI-0.001), 1, nodes[3], nodes[1], 1));
// creases.push(new Crease(edges[0], 3, 0, (Math.PI-0.001), 1, nodes[4], nodes[2], 2));
var
_allNodeObject3Ds
=
[];
_
.
each
(
nodes
,
function
(
node
){
var
obj3D
=
node
.
getObject3D
();
_allNodeObject3Ds
.
push
(
obj3D
);
globals
.
threeView
.
sceneAddModel
(
obj3D
);
});
allNodeObject3Ds
=
_allNodeObject3Ds
;
_
.
each
(
edges
,
function
(
edge
){
globals
.
threeView
.
sceneAddModel
(
edge
.
getObject3D
());
});
function
buildModel
(
_faces
,
_vertices
,
_allEdges
,
allCreaseParams
){
// console.log(_allEdges);
var
_nodes
=
[];
for
(
var
i
=
0
;
i
<
_vertices
.
length
;
i
++
){
_nodes
.
push
(
new
Node
(
_vertices
[
i
].
clone
(),
_nodes
.
length
));
}
_nodes
[
_faces
[
0
].
a
].
setFixed
(
true
);
_nodes
[
_faces
[
0
].
b
].
setFixed
(
true
);
_nodes
[
_faces
[
0
].
c
].
setFixed
(
true
);
//
_nodes[_faces[0].a].setFixed(true);
//
_nodes[_faces[0].b].setFixed(true);
//
_nodes[_faces[0].c].setFixed(true);
var
_edges
=
[];
for
(
var
i
=
0
;
i
<
_allEdges
.
length
;
i
++
)
{
...
...
js/pattern.js
View file @
a60838a9
...
...
@@ -32,46 +32,46 @@ function initPattern(globals){
});
}
loadSVG
(
"
assets/Tessellations/SimpleVertex.svg
"
,
function
(
svg
){
var
_$svg
=
$
(
svg
);
//format all lines
var
$paths
=
_$svg
.
children
(
"
path
"
);
$paths
.
css
({
fill
:
"
none
"
,
'
stroke-width
'
:
3
,
'
stroke-dasharray
'
:
"
none
"
});
var
$outlines
=
$paths
.
filter
(
function
(){
var
stroke
=
$
(
this
).
attr
(
"
stroke
"
).
toLowerCase
();
return
stroke
==
"
#000000
"
||
stroke
==
"
#000
"
;
});
// $outlines.css({fill:'#ffffff'});
var
$mountains
=
$paths
.
filter
(
function
(){
var
stroke
=
$
(
this
).
attr
(
"
stroke
"
).
toLowerCase
();
return
stroke
==
"
#ff0000
"
||
stroke
==
"
#f00
"
;
});
$mountains
.
css
({
'
stroke-dasharray
'
:
'
12, 6, 3, 6
'
});
var
$valleys
=
$paths
.
filter
(
function
(){
var
stroke
=
$
(
this
).
attr
(
"
stroke
"
).
toLowerCase
();
return
stroke
==
"
#0000ff
"
||
stroke
==
"
#00f
"
;
});
$valleys
.
css
({
'
stroke-dasharray
'
:
'
7, 6, 7, 6
'
});
var
$cuts
=
$paths
.
filter
(
function
(){
var
stroke
=
$
(
this
).
attr
(
"
stroke
"
).
toLowerCase
();
return
stroke
==
"
#00ff00
"
||
stroke
==
"
#0f0
"
;
});
var
$svg
=
$
(
'
<svg version="1.1" viewBox="
'
+
_$svg
.
attr
(
"
viewBox
"
)
+
'
" id="mySVG" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> </svg>
'
);
$svg
.
append
(
$outlines
);
$svg
.
append
(
$mountains
);
$svg
.
append
(
$valleys
);
$svg
.
append
(
$cuts
);
$
(
"
#svgViewer
"
).
html
(
$svg
);
parseSVG
(
$outlines
,
$mountains
,
$valleys
,
$cuts
);
});
//
loadSVG("assets/Tessellations/SimpleVertex
2
.svg", function(svg){
//
var _$svg = $(svg);
//
//
//format all lines
//
var $paths = _$svg.children("path");
//
$paths.css({fill:"none", 'stroke-width':3, 'stroke-dasharray':"none"});
//
//
var $outlines = $paths.filter(function(){
//
var stroke = $(this).attr("stroke").toLowerCase();
//
return stroke == "#000000" || stroke == "#000";
//
});
//
// $outlines.css({fill:'#ffffff'});
//
//
var $mountains = $paths.filter(function(){
//
var stroke = $(this).attr("stroke").toLowerCase();
//
return stroke == "#ff0000" || stroke == "#f00";
//
});
//
$mountains.css({'stroke-dasharray':'12, 6, 3, 6'});
//
//
var $valleys = $paths.filter(function(){
//
var stroke = $(this).attr("stroke").toLowerCase();
//
return stroke == "#0000ff" || stroke == "#00f";
//
});
//
$valleys.css({'stroke-dasharray':'7, 6, 7, 6'});
//
//
var $cuts = $paths.filter(function(){
//
var stroke = $(this).attr("stroke").toLowerCase();
//
return stroke == "#00ff00" || stroke == "#0f0";
//
});
//
//
var $svg = $('<svg version="1.1" viewBox="'+_$svg.attr("viewBox")+'" id="mySVG" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> </svg>');
//
$svg.append($outlines);
//
$svg.append($mountains);
//
$svg.append($valleys);
//
$svg.append($cuts);
//
//
$("#svgViewer").html($svg);
//
//
parseSVG($outlines, $mountains, $valleys, $cuts);
//
});
function
parsePath
(
_verticesRaw
,
_segmentsRaw
,
$paths
){
for
(
var
i
=
0
;
i
<
$paths
.
length
;
i
++
){
...
...
@@ -193,16 +193,23 @@ function initPattern(globals){
}
creaseParams
.
push
(
faceVerts
[
0
]);
if
(
creaseParams
.
length
==
4
)
{
if
(
v2Index
-
v1Index
==
1
||
v2Index
-
v1Index
==
-
2
)
{
creaseParams
=
[
creaseParams
[
2
],
creaseParams
[
3
],
creaseParams
[
0
],
creaseParams
[
1
]];
}
creaseParams
.
push
(
i
);
if
(
i
<
(
outlines
.
length
+
mountains
.
length
+
valleys
.
length
)){
var
angle
=
Math
.
PI
;
var
angle
=
Math
.
PI
/
2
;
if
(
i
<
(
outlines
.
length
+
mountains
.
length
)){
angle
*=
-
1
;
}
creaseParams
.
push
(
angle
);
}
else
{
console
.
log
(
"
panel
"
);
creaseParams
.
push
(
0
);
}
console
.
log
(
creaseParams
);
allCreaseParams
.
push
(
creaseParams
);
break
;
}
...
...
@@ -210,36 +217,37 @@ function initPattern(globals){
}
}
}
for
(
var
i
=
outlines
.
length
+
mountains
.
length
+
valleys
.
length
+
cuts
.
length
;
i
<
allEdges
.
length
;
i
++
){
var
v1
=
allEdges
[
i
][
0
];
var
v2
=
allEdges
[
i
][
1
];
var
creaseParams
=
[];
for
(
var
j
=
0
;
j
<
faces
.
length
;
j
++
){
var
face
=
faces
[
j
];
var
faceVerts
=
[
face
.
a
,
face
.
b
,
face
.
c
];
var
v1Index
=
faceVerts
.
indexOf
(
v1
);
if
(
v1Index
>=
0
){
var
v2Index
=
faceVerts
.
indexOf
(
v2
);
if
(
v2Index
>=
0
){
creaseParams
.
push
(
j
);
if
(
v2Index
>
v1Index
)
{
faceVerts
.
splice
(
v2Index
,
1
);
faceVerts
.
splice
(
v1Index
,
1
);
}
else
{
faceVerts
.
splice
(
v1Index
,
1
);
faceVerts
.
splice
(
v2Index
,
1
);
}
creaseParams
.
push
(
faceVerts
[
0
]);
if
(
creaseParams
.
length
==
4
)
{
creaseParams
.
push
(
i
);
creaseParams
.
push
(
0
);
//zero target angle
allCreaseParams
.
push
(
creaseParams
);
break
;
}
}
}
}
}
//panels
// for (var i=outlines.length+mountains.length+valleys.length+cuts.length;i<allEdges.length;i++){
// var v1 = allEdges[i][0];
// var v2 = allEdges[i][1];
// var creaseParams = [];
// for (var j=0;j<faces.length;j++){
// var face = faces[j];
// var faceVerts = [face.a, face.b, face.c];
// var v1Index = faceVerts.indexOf(v1);
// if (v1Index>=0){
// var v2Index = faceVerts.indexOf(v2);
// if (v2Index>=0){
// creaseParams.push(j);
// if (v2Index>v1Index) {
// faceVerts.splice(v2Index, 1);
// faceVerts.splice(v1Index, 1);
// } else {
// faceVerts.splice(v1Index, 1);
// faceVerts.splice(v2Index, 1);
// }
// creaseParams.push(faceVerts[0]);
// if (creaseParams.length == 4) {
// creaseParams.push(i);
// creaseParams.push(0);//zero target angle
// allCreaseParams.push(creaseParams);
// break;
// }
// }
// }
// }
// }
return
allCreaseParams
;
}
...
...
js/staticSolver.js
View file @
a60838a9
...
...
@@ -5,7 +5,7 @@
function
initStaticSolver
(){
var
material
=
new
THREE
.
MeshNormalMaterial
({
shading
:
THREE
.
FlatShading
,
side
:
THREE
.
Double
Side
});
var
material
=
new
THREE
.
MeshNormalMaterial
({
shading
:
THREE
.
FlatShading
,
side
:
THREE
.
Front
Side
});
var
geometry
=
new
THREE
.
Geometry
();
geometry
.
dynamic
=
true
;
var
object3D
=
new
THREE
.
Mesh
(
geometry
,
material
);
...
...
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