An addon for the Godot Engine which adds a few basic functions for creating and modifying shapes, and a few nodes that use those functions to create shapes and use them.
These functions and nodes are written in GDScript to make them universally compatible.
They are exposed to C# via wrapper classes in the BasicShapeCreation
namespace.
There are 2 ways to download the plugin:
- In the Godot editor, go to the AssetLib tab.
- Search for the "2D Regular Polygons" addon.
- Select and click
install
(and subsequentinstall
s.).
- Go to the Releases page.
- Download the zip file in Assets section of the wanted release.
- Extract the
basic_shape_creation
folder from the zip file and put it in theaddons
folder in the target project. Create theaddons
folder if it does not exist yet project.
Once downloaded, the addon can be enabled in Project
> Project Settings
> Plugins
.
This is a short introduction to how the addon works.
Currently, there are 2 nodes that this plugin offer:
A general purpose node for creating shapes, which can be both polygons or disconnected lines. After a shape is created, the node offers 2 ways of making use of it.
The first is to draw it, which can be enabled (and is by default) by setting draw_shape
to true. Colors and borders can
also be customized.
The second way is to send the created shape to other nodes so that they can use it for their own purposes.
The shapes can be obtained from a reference to the BasicPolygon2D with get_created_shape()
.
The signal shape_exported
is also emitted whenever a new shape is created, which can be connected to a different script.
Finally, the node has an export system where it can set properties of other nodes. This can be done by setting export_behavior
to export either or both in editor or in runtime, then setting export_targets
to an array of NodePath
s, relative to the BasicPolygon2D,
pointing to the properties to set. (The NodePath
s should look something like: ^"../../Relative/Path/To/Node:property:sub_property"
)
This node is a specialization of BasicPolygon2D, only providing a similarly generated shape
to a CollisionObject2D
, like CollisionPolygon2D
or CollisionShape2D
.
Both of these nodes share the same properties for generating the shape. Here are some of them and what they do below.
vertices_count
- Determines the number of vertices in the base shape. For instance, a value of3
creates a triangle. A value of1
is equivalent to a 32-point shape, and a value of2
creates a special shape of multiple radiating lines.sizes
- Determines the size of the shape, from the center to the outer vertices. Multiple values are allowed, cycling through for each vertex. For instance, a star shape can be created withsizes
set with 2 values. Note that this does not affect the number of vertices, so a 5-point star would require avertices_count
of10
.ring_ratio
- With values below 1, it can be used to create ring shapes.corner_size
/corner_detail
- Controls the size of the rounded corners, if to have any, and the number of points to make up each corner. Corners make use of quadratic Bézier curves.arc_start
/arc_angle
- Enables cutting out a slice of the base shape. For instance, it can be used to cut out a corner of a square.
The functions used for creating the bulk of these shapes are accessible under the BasicGeometry2D static class. All of them return the new shape. If they are passed a shape, that shape is directly modified as well as returned. The provided functions are:
add_shape
- Creates a shape and inserts it into the provided array at the provided index. Takesvertices_count
,sizes
, andarc_angle
.create_shape
- A variant of add_shape which puts the created shape into a newly created array.add_ring
- Takes a shape and duplicates its points to be some proportional amount closer to the shape center.add_rounded_corners
- Takes a shape and rounds the corners.
The provided nodes and the functions are exposed to C# via wrapper classes in the BasicShapeCreation
namespace.
These wrapper classes can also be used for creating these nodes.
Warning
Since static methods still require an instance to access, the BasicGeometry2D
class must create an object that must be
freed before the application ends. By default, the instance is freed when the root Window
is exiting the SceneTree
and
emits the TreeExiting
signal. If a custom behaviour needs to be supplied, the default behaviour can be disabled by setting
BasicGeometry2D.FreeOnWindowExit
to false, then calling BasicGeometry2D.Dispose
whenever the application is about to close.
The following methods have been converted into readonly properties.
get_created_shape()
> CreatedShape
get_created_shape_decomposed()
> CreatedShapeDecomposed
get_created_shape_type()
> CreatedShapeType
\
The following methods have been converted into readonly properties.
get_created_shape()
> CreatedShape
get_created_shape_decomposed()
> CreatedShapeDecomposed
get_created_shape_type()
> CreatedShapeType
shape_count()
> ShapeCount
get_basic_polygon()
> BasicPolygon
This addon is available under the MIT license, which is in the addon's folder. A copy is available in the root folder.
This addon uses several external packages for unit testing:
- GUT (Godot Unit Test) (Godot addon)
- Chickensoft.GoDotTest (Nuget package)
- Shouldly (Nuget package)