tbfleming / jscut

In-browser CAM package
http://jscut.org
GNU General Public License v3.0
295 stars 136 forks source link

Use svg.js ? #10

Closed peteruithoven closed 9 years ago

peteruithoven commented 9 years ago

Hi folks, In collaboration with the maintainer of the svg.js library I've been able to make it very easy to import and parse svg files. We worked on making importing and converting all shapes to polygons as simple as:

var svg = SVG(containerElement)
svg.svg(importedSVGContent);
svg.toPath(true).toPoly("2px",true);

This imports the contents of a svg file into a svg, converts all shapes (eclipse, rects etc) into path's and then converts all paths into polygons. The import functionality supports Illustrator and Inkscape files. toPoly also subdivides curves into straight lines by a determined sample rate (in this case 2px).

This uses svg.js, import, toPath and toPoly

We still have to work on ungrouping: https://github.com/wout/svg.js/issues/238

Maybe this is something you can use?

By improving the existing svg.js library and plugins I hope to make it easier for others to build other digital fabrication interfaces, like your jscut. My personal goal is to use these webbased interfaces for another project: Tosqa

tbfleming commented 9 years ago

jscut uses snap.svg, a competitor to svg.js.

peteruithoven commented 9 years ago

Alright, but maybe you can implement the toPath plugin into snap.js. https://github.com/wout/svg.topath.js/blob/master/svg.topath.js This converts all shapes to paths, except text for example.

Also, the toPoly plugin includes existing vector points and skips straight parts to improve the result.