preparing vector graphics for use in a game
December 21, 2008 9:30 PM   Subscribe

how to convert a vector drawing to line segments & convex polygons, and then export as an array of points?

Hello,

I'm looking to convert vector artwork for a 2d video game into a format that can be used by code. Ideally I'd like a flexible semi-automated way to convert a vector drawing into an array of points which define line segments and/or convex polygons.

The vector artwork is curved.
The line segments, and polygon edges will naturally be straight.

I will want to make compromises between the number of points used, and how faithfully the original artwork is represented to find a good trade off between the appearance while keeping the number of points used low.

does anyone have any suggestions?

thanks

mat
posted by compound eye to Computers & Internet (7 answers total) 3 users marked this as a favorite
 
What you're talking about is discretization, but:

The vector artwork's curves are probably splines.

OpenGL can handle splines natively. I assume DirectX can too, although I've never used it. Using the appropriate API calls for splines will get your video card to do the discretization heavy lifting.
posted by qxntpqbbbqxl at 10:39 PM on December 21, 2008


a general suggestion i would have is it might be easier to convert the drawing into a fairly detailed raster and go from there, that way you avoid having to deal with aspects of the problem like beizer curves - unless you get an out of the box solution for that (i dont know of any, but i would be surprized if there wasnt one), then it might get mathematically tricky. even with an out of the box solution you may have some limitations that you might not like.

One way I could think of, that im also sure isnt the most optimal, just a way i could see working is take your vector into illustrator, export into 3ds max, and 3ds max has maxscript from which you can do pretty much anything you can think of - it just might take you a while to figure out the functions you need to be using to read all the information properly, and export that as a set of arrays.
posted by figTree at 10:39 PM on December 21, 2008


How is your vector art defined? If your vector art creation program uses things like Bezier curves and line segments to define your art object, then a API like DirectX or OpenGL can render them too.

Without knowing the format you have the art in now and what your target format is for your 2D game, it will be hard to help you further. Also, if you do not plan to change the scale of your art too much during the game, rasterizing to a bitmap format might be easier to deal with.
posted by demiurge at 11:27 PM on December 21, 2008


Try Blender:

Adobe Illustrator vector illustration to Blender object conversion
Blender object to GLfloat array conversion

You can use subdivide smoothing and the merge/collapse functions to add and remove smoothing, resp. This adds and removes vertices, i.e. "number of points".
posted by Blazecock Pileon at 6:49 AM on December 22, 2008


I'd suggest you keep it as bezier curves or such, & deal with it in the actual program so you can keep it smooth even if you need high detail for something. This is a reasonably common approach.
posted by devilsbrigade at 11:08 AM on December 22, 2008


I should have noted earlier that OpenGL (and possibly DirectX) has direct support for bezier curves in the form of evaluators. The Red Book ch12 has some information on them. If you're using b-splines or something else other than bezier curves, you can convert them to bezier curves first.
posted by devilsbrigade at 4:30 PM on December 22, 2008


Response by poster: thank you very much for the suggestions,
you've given me plenty of options to explore.

I actually want to import the data for two reasons,

display with opengl ES (i didn't think it could handle splines but i'd love to be wrong, perhaps i'll write a tool to do the conversion)

and for import into a 2d physics engine (box 2d) which doesn't use splines

cheers

mat
posted by compound eye at 12:52 AM on December 23, 2008


« Older Will operating an external hard drive at a 45...   |   vocabulary question: African and Australia/Pacific... Newer »
This thread is closed to new comments.