Main Menu

SVG Import tool

Started by jaymzjulian, December 22, 2019, 04:03:10 AM

Previous topic - Next topic

jaymzjulian

I was actually inspired by the beizer curve examples, interestingly ;).

It's still imperfect, but it's working _enough_ for me to import various things from inkscape - this was important for me so that I can have one of my artist friends draw me a title screen and some sprites :).  A few notes:

* Some things are actually filled outlines - we, of course, do not handle these usefully ;).  The rose example is actually one of these, but I picked it precisely because it is hard (also because I love b&tb....)

* It can output either a function that generates a display list (for things like title screens and such) or a arrray of commands (for movable sprites and such) - see the rose and spiral examples for details of this

* There are a bunch of object types currently unimplemented, msotly because of what inkscape outputs - specifically, I haven't done arcs yet.  They "generally will work" once I find an SVG that has them though - the library i'm using supports them, i just haven't hooked it up.

* It can optimize for either a certain amount of error (say, no more than 0.1 "units"), or a certain amount of vectors (i.e. no more than 512 vectors - which is, btw, approximatly what ends up fitting in DP ram, at least 768 fails for me)

* If you're importing complex objects, which have a lot of pen drift, the static function variant supports calling ReturnToOrigin every N commands.  Without this, the rose example looks absolutely terrible and jumps all over the place, though the spiral is weirdly fine.  The _OTHER_ reason for this, is because it supports the paged-DPram mode that takes advantage of 1.21 features, which of course does not actually exist yet ;) - I tested this with a version of rose with double the vectors, and it makes it look way better :).  But I've left that out of the samples until 1.21 is released, at which point I'll update it.

* I need to improve the MoveTo optimization just a little more - it tries to pick "near origin" as the first thing, but really it should pick "Thing that causes the least MoveTo commands".  I'll probably update that in github soon.

* There should be some kind of optimization that goes "These two lines can actually combine into one line with N loss", rather than "Line X is too short" - you can see this on the straight lines of the rose sample wasting some lines where because all of the inputs are beizer curves for that svg, it will just do, you know, a bunch of segments that are identically angled.  this... should be doable.  Something like "min angle" to go with "max length" - it's totally doable, but the optimization problem is sort of interesting and i decided not to yet...

Link:  https://github.com/jaymzjulian/vectrex32_tools
Samples: attachments :)


Vectrex32

Wow!! You rock, Jaymz!

- Bob

Vectrex32

#2
Here's what rose.bas looks like:


jaymzjulian

#3
I did end up adding the angle tunable for the bezier curves, and actually it improved fidelity on complex objects a lotat a given vector count - here's the output with the same svg file with that turned on.  I also included a double-dpram-page version in the github, which looks pretty decent to me, however I couldn't capture it well with my phone ;).

The heuristic for culling isn't _quite_ right at the moment - vectors just dissapear still if you have too many, rather than being quantized, and i didn't work out why yet, but if you turn up that angle tunable then it works well - obviously this is only really an issue with complex objects.

EDIT: Directly after posting this, I actually _did_ manage to find that bug, and heuristic the angle error/beizer accuracy stuff, and now it looks great _by default_.  woohoo!  Turns out I just didn't sleep enough ;).






troff

jaymzjulian,

This is very cool. I was hoping to convert so .SVG files on a mac to vectrex vectors. Wondering if you could maybe point me in the right direction, or have a cheat sheet on how I could install your converter on a mac?

Thanks,
Brandon