Time to revisit SVG path to LDraw conversion?


RE: Time to revisit SVG path to LDraw conversion?
#11
(2022-12-15, 7:45)Lasse Deleuran Wrote: Thanks for the screenshots. The points you show there seem to be erroneous. There should be no such "Steiner points" on line segments, unless they were added to remove T-Junktions.

The code is open source, so if a new tool should be made, then the existing code can be used for inspiration. The primary pieces of code to convert from SVG to LDraw is: 
This files, which converts svg files to straight line primitives

These helper files:
Convert arc primitives
Convert Bezier curves

From your reply, I will raise and prioritize the tasks as follows:
1) Fix the bugs with triangles and additional points, that should not be there.
2) Add point output for "0 !LPE VERTEX meta" as toggle
3) Change precision to "max angle" and allow the max angle to be configured.
4) Fix those InkScape overlapping path color conversions.

Thank you, and I will look through those code files and see if I can learn a thing or two about how such things can be programmed.

Just for reference, and to write it out for myself, this is the basic logic that I'm applying to the process, along with which tool/agent could be responsible for each step. Svg2ldraw already does more than this, of course, and this isn't meant to change how that tool works, only to lay out the process for the limited task of converting SVG paths. There are doubtless steps that I'm missing!

Input cleanup
  1. Make paths "true" - remove/render/apply any path effects, matrix transforms, etc. so that the SVG path represents the actual appearance of the pattern. (Done by user in Inkscape or other tool, but LDraw tool could generate warnings if these elements are found. Tool could also apply matrix transforms fairly easily.)
  2. Make paths absolute - convert relative lineto or curveto commands into absolute coord pairs, and add starting coords to any h or v commands. (Done easily by Inkscape extension, but also possible by LDraw tool.)
  3. Break paths apart - split subpaths to separate paths, and paths into individual segments. (If necessary??)
Curve removal
  1. Interpolate additional points between curve endpoints, to get new endpoints for straight segments. (Done by LDraw tool according to user settings.)
  2. Convert curves to lines - using the new endpoints, strip all curveto commands to make Bezier segments into linear segments. (LDraw tool.)
Format conversion
  1. Add missing 'z' coord to the absolute x/y pairs generated so far. (LDraw tool.)
  2. Change syntax from SVG format to !LPE VERTEX meta commands or other appropriate LDraw format. (LDraw tool.)
Reply
« Next Oldest | Next Newest »



Messages In This Thread
RE: Time to revisit SVG path to LDraw conversion? - by N. W. Perry - 2022-12-15, 14:05
RE: SVG... - by Franklin W. Cain - 2022-12-15, 14:53
RE: SVG... - by Orion Pobursky - 2022-12-15, 15:38

Forum Jump:


Users browsing this thread: 1 Guest(s)