PolyNode2D¶
Inherits: Node2D < CanvasItem < Node < Object
Inherited By: PolyCapsule2D, PolyCircle2D, PolyEllipse2D, PolyPath2D, PolyRectangle2D
Represents a single polygon-based node in the hierarchy of nested polygons.
Description¶
The class provides boolean operators used to shape the outlines of nodes at run-time, similarly to CSG nodes in 3D, while also giving ability to represent nested polygons.
Unlike in 3D, this class cannot be used as a collision object directly. Instead, use PolyCollisionShape2D to build collision shapes which can be applied to any CollisionObject2D node.
Drawing is only done on the level of the root node (see is_root), unless children do not perform any operation with parent nodes.
This data structure is also used to receive solutions from clipping and offsetting operations. It’s an alternative to the array-based data structures which also receive these solutions in PolyBoolean2D. The class has a major advantage over the Array structure by having an ability to properly represent the parent-child relationships of the returned polygons, but it may be more computationally expensive to process.
Properties¶
bool | antialiased | false |
Color | color | Color( 1, 1, 1, 1 ) |
bool | filled | true |
float | line_width | 2.0 |
Texture | normal_map | |
bool | open | false |
Operation | operation | 1 |
PoolVector2Array | points | PoolVector2Array( ) |
Texture | texture | |
Vector2 | texture_offset | Vector2( 0, 0 ) |
float | texture_rotation | |
float | texture_rotation_degrees | 0.0 |
Vector2 | texture_scale | Vector2( 1, 1 ) |
Methods¶
Array | build_outlines ( ) |
void | clear ( ) |
Array | get_outlines ( ) |
bool | is_inner ( ) const |
bool | is_root ( ) const |
void | make_from_outlines ( Array outlines ) |
PolyNode2D | new_child ( PoolVector2Array from_points ) |
Signals¶
- outlines_updated ( )
Emitted whenever the outlines are updated. Changes in local transform, operation and points of children triggers outlines to get updated on idle frame.
Enumerations¶
enum Operation:
- OP_NONE = 0 — No operation is applied. Nodes with no operation set are able to be drawn separately from the root
PolyNode2D
. - OP_UNION = 1 — Outlines of parent and child nodes are merged together.
- OP_DIFFERENCE = 2 — Outlines from the child node is subtracted from the parent’s outlines.
- OP_INTERSECTION = 3 — Only intersecting outlines from parent and child nodes remain, the rest is removed.
- OP_XOR = 4 — Common area defined by intersection of outlines between the parent and child is removed, the rest outlines remain unaffected.
Property Descriptions¶
- bool antialiased
Default | false |
Setter | set_antialiased(value) |
Getter | is_antialiased() |
Draws polygons and polylines antialiased.
Note: anti-aliasing may not work reliably in Godot 3.2, especially on GLES3 backend. This property will be removed in the future version of Godot.
- Color color
Default | Color( 1, 1, 1, 1 ) |
Setter | set_color(value) |
Getter | get_color() |
The color used to draw the node. Texture is also modulated by this property.
- bool filled
Default | true |
Setter | set_filled(value) |
Getter | is_filled() |
If true
, draws outlines with a solid color. Does not have an effect on polylines.
- float line_width
Default | 2.0 |
Setter | set_line_width(value) |
Getter | get_line_width() |
The line width used to draw polylines. Does not have an effect on polygons.
- Texture normal_map
Setter | set_normal_map(value) |
Getter | get_normal_map() |
The normal map used to provide depth to the texture.
- bool open
Default | false |
Setter | set_open(value) |
Getter | is_open() |
If true
, this node is treated as a polyline (open line), otherwise this is a polygon (closed outline).
- Operation operation
Default | 1 |
Setter | set_operation(value) |
Getter | get_operation() |
The boolean operation that is performed on this node. This is ignored for the first child node as the operation is between this node and the previous child of this nodes parent.
- PoolVector2Array points
Default | PoolVector2Array( ) |
Setter | set_points(value) |
Getter | get_points() |
The vertices which represent the outer or inner outline of this node.
- Texture texture
Setter | set_texture(value) |
Getter | get_texture() |
Texture object to draw. Only the area defined by get_outlines is drawn.
- Vector2 texture_offset
Default | Vector2( 0, 0 ) |
Setter | set_texture_offset(value) |
Getter | get_texture_offset() |
Amount to offset the texture. If (0, 0) the texture’s origin (its top-left corner) will be placed at the node’s position.
- float texture_rotation
Setter | set_texture_rotation(value) |
Getter | get_texture_rotation() |
The texture’s rotation in radians.
- float texture_rotation_degrees
Default | 0.0 |
Setter | set_texture_rotation_degrees(value) |
Getter | get_texture_rotation_degrees() |
The texture’s rotation in degrees.
- Vector2 texture_scale
Default | Vector2( 1, 1 ) |
Setter | set_texture_scale(value) |
Getter | get_texture_scale() |
Amount to multiply the uv
coordinates when using a texture. Larger values make the texture smaller, and vice versa.
Method Descriptions¶
- Array build_outlines ( )
Builds outlines from selected operation. Unlike get_outlines, returns outlines immediately without scheduling operation for the next frame, so prefer to use get_outlines if you care about performance over immediate information.
- void clear ( )
Removes all PolyNode2D
children immediately. Use Object.call_deferred if you want to emulate the Node.queue_free behavior.
- Array get_outlines ( )
Returns the outlines representing this node, which may result from the clipping operation. This is different from points.
- bool is_inner ( ) const
Tells whether this node is an inner or an outer node in the hierarchy of nested nodes. If this node has no PolyNode2D
parent and has empty points, this node is considered as inner node containing outer children. If points is not empty, this is an outer node.
- bool is_root ( ) const
Returns true
if this node has no PolyNode2D
as parent.
- void make_from_outlines ( Array outlines )
Constructs an hierarchy of nodes from an array of outer and inner outlines. New nodes are constructed to represent inner outlines with operation set to OP_DIFFERENCE.
- PolyNode2D new_child ( PoolVector2Array from_points )
Constructs a new PolyNode2D
using vertices from supplied points.