Image to polygon converter

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Image to polygon converter

Post by Bigfoot71 »

Following a recent topic I had the motivation to do something I had already thought of a few times, to obtain polygons representing the convex hull of an sprite. So I made it a small tool for my personal use and I just wanted to share it if it can help people ^^

It's a little program (made with löve, yes) where you just drag and drop an image into the window and it generates the list of vertices you want, selecting the max number of vertices you want.

The code is CC0 except for the SUIT library and nativfs which is included (I don't know if that is a problem), so what is mentioned as CC0 at the top of the file means that you do what you want with it :awesome:

Small animated demo:
Image

Example of what an exported file may look like, the program creates the file or simply adds the new table to the file:

Code: Select all

-- Normal
verts_1 = {70, 10, 159, 55, 0, 139}

-- Table of table checked
verts_2 = {{x = 70, y = 10}, {x = 159, y = 55}, {x = 0, y = 139}}

-- Normal formated
verts_3 = {
  70, 10,
  159, 55,
  0, 139,
}

-- Table of table formated
verts_4 = {
  {x = 70, y = 10};
  {x = 159, y = 55};
  {x = 0, y = 139};
}
I thought about adding the possibility of converting a whole folder at once, spritesheet management and being able to edit the vertices in the previews, I'll try to add all this when I have time or don't do not hesitate to suggest your modifications on the repository if you like ^^
I will also propose releases for Windows and Linux on the repository when I have time too.

https://github.com/Bigfoot71/Image-to-Polygon-converter
Attachments
image-to-polygon-converter.love
(20.89 KiB) Downloaded 144 times
My avatar code for the curious :D V1, V2, V3.
PotatoDude
Prole
Posts: 7
Joined: Wed May 04, 2022 8:01 am

Re: Image to polygon converter

Post by PotatoDude »

I know it's a year old post, but thank youu!! this's really what I need!
nvm
User avatar
darkfrei
Party member
Posts: 1181
Joined: Sat Feb 08, 2020 11:09 pm

Re: Image to polygon converter

Post by darkfrei »

Any post is better with examples.

We are have an image:
hexadecagon2.png
hexadecagon2.png (2.38 KiB) Viewed 57 times
Open file:
2024-04-26T17_15_39-Image to Polygon converter.png
2024-04-26T17_15_39-Image to Polygon converter.png (11.42 KiB) Viewed 57 times
Drag-n-drop the image.
Input 16 vertices and "Generate polygon":
2024-04-26T17_16_00-Image to Polygon converter.png
2024-04-26T17_16_00-Image to Polygon converter.png (16.18 KiB) Viewed 57 times
Output formats:

Code: Select all

{36, 112, 58, 68, 84, 42, 128, 20, 181, 20, 225, 42, 251, 68, 273, 112, 273, 165, 251, 209, 225, 235, 181, 257, 128, 257, 84, 235, 58, 209, 36, 165}

Code: Select all

{{x = 36, y = 112}, {x = 58, y = 68}, {x = 84, y = 42}, {x = 128, y = 20}, {x = 181, y = 20}, {x = 225, y = 42}, {x = 251, y = 68}, {x = 273, y = 112}, {x = 273, y = 165}, {x = 251, y = 209}, {x = 225, y = 235}, {x = 181, y = 257}, {x = 128, y = 257}, {x = 84, y = 235}, {x = 58, y = 209}, {x = 36, y = 165}}

Code: Select all

{
  {x = 36, y = 112};
  {x = 58, y = 68};
  {x = 84, y = 42};
  {x = 128, y = 20};
  {x = 181, y = 20};
  {x = 225, y = 42};
  {x = 251, y = 68};
  {x = 273, y = 112};
  {x = 273, y = 165};
  {x = 251, y = 209};
  {x = 225, y = 235};
  {x = 181, y = 257};
  {x = 128, y = 257};
  {x = 84, y = 235};
  {x = 58, y = 209};
  {x = 36, y = 165};
}

Code: Select all

{
  36, 112,
  58, 68,
  84, 42,
  128, 20,
  181, 20,
  225, 42,
  251, 68,
  273, 112,
  273, 165,
  251, 209,
  225, 235,
  181, 257,
  128, 257,
  84, 235,
  58, 209,
  36, 165,
}
(But some problems by resizing the window, just don't do that)
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: No registered users and 223 guests