Page 1 of 1

Image to polygon converter

Posted: Thu Mar 09, 2023 1:13 pm
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

Re: Image to polygon converter

Posted: Fri Apr 26, 2024 2:57 pm
by PotatoDude
I know it's a year old post, but thank youu!! this's really what I need!

Re: Image to polygon converter

Posted: Fri Apr 26, 2024 3:18 pm
by darkfrei
Any post is better with examples.

We are have an image:
hexadecagon2.png
hexadecagon2.png (2.38 KiB) Viewed 240 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 240 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 240 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)