Skip to content

Commit

Permalink
Add support for 'z' command in SVG paths (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Jul 25, 2019
1 parent d41b6f8 commit 26ab9e3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions js/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ function initPattern(globals){
console.warn("path parser not supported");
return;
}
var startVertex = null;
var segments = path.getPathData();
for (var j=0;j<segments.length;j++){
var segment = segments[j];
Expand All @@ -210,6 +211,7 @@ function initPattern(globals){
vertex.x += segment.values[0];
vertex.z += segment.values[1];
}
startVertex = _verticesRaw.length;
_verticesRaw.push(vertex);
pathVertices.push(vertex);
break;
Expand Down Expand Up @@ -244,6 +246,7 @@ function initPattern(globals){

case "M"://x, y
var vertex = new THREE.Vector3(segment.values[0], 0, segment.values[1]);
startVertex = _verticesRaw.length;
_verticesRaw.push(vertex);
pathVertices.push(vertex);
break;
Expand Down Expand Up @@ -272,6 +275,14 @@ function initPattern(globals){
_verticesRaw.push(vertex);
pathVertices.push(vertex);
break;

case "z":
case "Z":
if (startVertex != null) {
_segmentsRaw.push([_verticesRaw.length-1, startVertex]);
startVertex = null;
}
break;
}
}
for (var j=0;j<pathVertices.length;j++){
Expand Down

1 comment on commit 26ab9e3

@evbernardes
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello!
I created a Masu Box pattern on Inkscape (coded to have some 180 and some 90 degrees angles to it) to test this:

  1. The first version has no closed paths and loads/folds correctly both on this corrected version and on the web hosted version.
  2. The second version has a closed path in the center (defining a square). On the web hosted version, it doesn't load the last stroke (connecting the last point to the first point) and you're probably aware of that, but on this version it loads it incorrectly: the last stroke does not have the desired opacity of 50% and the whole pattern is blocked and doesn't fold on the simulator.

I'm sending both sketches so you can try them!
masu_box.zip

Also, feel free to put the masu box online on the examples if you also think it's cool :)

Please sign in to comment.