Get the newest version of the source/final scripts on Github.



DEVELOPER WORDS

I am currently using this tool in my game Fracture Hell. You can take a look to see what it is capable of or how it can be used. Buying Fracture Hell is a great way to support me if you are interested and any feedback regarding this tool or Fracture Hell is greatly appreciated. Fracture Hell is available on SteamItch Io, and Gotm.

You can play the demo for free right here on itch in the browser, enjoy!



Updates

- UPDATE v1.4.0 Restore Polygon System implemented. Supershape functions added.

- UPDATE v1.3.0 Texture System and Point Fracture System implemented.

- HOTFIX v1.2.1 Pool Instances were not freed on game exit. (memory leak)

- UPDATE v1.2.0 overhauled the mouse cut system (bonus: pool manager-script)

- UPDATE v1.1.0 adds cutting of polygons.



Info

Two simple scripts for fracturing and cutting polygons. PolygonFracture.gd is the actual script that fractures/cuts polygons. PolygonLib.gd adds nice helper functions for polygons like calculateArea, triangulate, getRandomPointsInPolygon, getBoundingRect, makeCirclePolygon etc.


Tested with Godot Versions: 3.2.3, 3.3, 3.3.1, 3.3.2

Point Fracture

Originally I wanted to do a more sophisticated point fracture system but it always turned out to be a complicated mess. Finally, I figured out a simpler way by using the already implemented Cut-Fracture system. I added a func to generate a randomized polygon and with a point (like a collision point), this randomized polygon can be used in the cut fracture method.



Texture System

Polygons with textures can now be fractured too. Texture Offset/Rotation/Scale can be any value or randomized. Fracture Shards and Finals Shapes update their textures accordingly. 




Cut Methods

There is just one cut method. It uses 1 polygon as the source and 1 polygon as a cut shape. The intersected shape (the parts overlapping in both polygons) can be fractured if desired. I also added helper funcs to PolygonLib.gd to create simple polygon shapes (currently: rectangle, circle, beam).


NEW SYSTEM (v1.2.0)



OLD SYSTEM




Fracturing Methods

There are two different systems for fracturing polygons.

 - Delaunay Fracture -> uses the delaunay triangulation to calculate random triangles inside the polygon. DelaunyFractureConvex assumes the polygon is convex and     DelaunyFractureRectangle assumes the polygon is a rectangle (convex/rectangle makes the fracturing simpler). Produces triangle fractures.

 - Fracture -> uses randomly generated cut lines to actually cut the polygon. Fracture and Fracture simple have different methods of obtaining the random cut lines but are otherwise the same. Produces polygon fractures.


Delaunay System



Cut Line System




RESTORE POLYGONS

I implemented 2 different methods of restoring polygons.

Simple

Use the polygon restorer class to save polygons in a stack. The first element of the stack represents the original state the last element represents the previous state. By simply getting the last element, the polygon can be restored to the previous state.




Advanced

The advanced method just uses one function in the polygon lib. While the simple method restores only discrete states of the polygon the advanced method can restore any amount of the polygon by growing it and restraining it to the shape of the original polygon. The advanced method has a bigger impact on performance.




Superellipse & Supershape

I added functions for creating superellipse and supershape polygons to the polygon lib. 

I had the idea after watching a coding challenge from The Coding Train. Really well-explained tutorials with the source code provided. 

I highly recommend checking it out :D 

Supershape coding challenge

Superellipse coding challenge

Check out The Coding Train on GitHub or on the Website.



My method is not the best or most performant method out there, and also implemented via GDScript (for ease of use), so don´t expect any performance miracles. There are other solutions out there, but I did not find a simple solution for fracturing 2d polygons in the way I wanted. Maybe sometime in the future, I will look into Voronoi fractures, to make the fractures look better. (Now the polygon is just randomly fractured) 


Support Me

You can support me here on itch io or via GitHub Sponsors. I truly appreciate any support!


StatusReleased
CategoryTool
PlatformsWindows, Linux, HTML5
Rating
Rated 5.0 out of 5 stars
(7 total ratings)
AuthorDave Green
Made withGodot
Tags2D, Destruction

Download

Download NowName your own price

Click download now to get access to the following files:

Polygon 2D Fracture Demo (v1.4.0) - win [newest] 13 MB
Polygon 2D Fracture Demo (v1.4.0) - linux [newest] 13 MB
Polygon 2D Fracture Source (v1.4.0) [newest] 11 MB
Polygon 2D Fracture Demo (v1.3.0) - win 12 MB
Polygon 2D Fracture Source (v1.3.0) 10 MB

Development log

Comments

Log in with itch.io to leave a comment.

Does this work with Godot 4?

I don´t know. I haven´t checked it and am currently not using Godot, so unfortunately I don´t know. You would have to try it out ;)

This looks like a brilliant tool, and very impressive demos :)

Will definitely check out the source for inspiration, I've been experimenting with the 2D geometry methods introduced in Godot 3.2 for a little project of mine :)

Thank you :) 

Yeah, this tool only uses the geometry class and my own code (if I remember correctly xD). Basically, the triangulation and Delaunay triangulation functions were the most important for me.

(+1)

It would be nice to have binary version for Linux

(+2)

I just uploaded one from the latest release (v1.4.0) ;) 

Thanks for sharing this. Looks incredible!

Thanks a lot, I really appreciate it :D

This is awesome!

Thank you very much :D