I am trying create ofMesh from a svg file. This basically works fine, but i need more points on the outline, so i am looking for a way to resample the path.
This is where i am with out any resampling:
svg.load("file.svg");
path = svg.getPaths()[0];
mesh = path.getTessellation();
I found out that it is possible to resample ofPolyline with getResampledBySpacing(5)
. But i can’t figure out how to convert the ofPolyline back in to a path.
Any help would be much appreciated.
zach
April 19, 2020, 10:27am
#2
if you have a closed polyline you can convert to a path (for tessellation) like this:
ofPath p
for (int i = 0; i < line.size(); i++){
if (i == 0) p.moveTo(line[i]);
else p.lineTo(line[i]);
}
p.close();
1 Like
Thank you @zach , worked beautifully!
Documentation of my case for others:
Resampled ofMesh from SVG file with complex polygon
or
Turn SVG with holes into mesh with evenly spaced vertices
// ofApp.h
ofxSVG svg;
ofPath path;
ofPath pathResampled;
ofMesh mesh;
// ofApp.cpp
svg.load("letter_B.svg");
path = svg.getPaths()[0];
for (int i = 0; i < path.getOutline().size(); i++) {
ofPolyline outline = path.getOutline()[i].getResampledBySpacing(5);
for (int j = 0; j < outline.getVertices().size(); j++){
if (j == 0) pathResampled.moveTo(outline[j]);
else pathResampled.lineTo(outline[j]);
}
pathResampled.close();
}
mesh = pathResampled.getTessellation();
1 Like