Skip to content

Commit

Permalink
Update for Godot 4.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarShehata authored and Calinou committed Jun 26, 2024
1 parent b76c5d8 commit f846a9a
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 212 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Godot 4+ specific ignores
.godot/

# Godot-specific ignores
.import/
export.cfg
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright © 2022 Hugo Locurcio and contributors
Copyright © 2022-present Hugo Locurcio and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Antialiased Line2D add-on demo project for Godot 3.x
# Antialiased Line2D add-on demo project for Godot 4.x

![Screenshot](https://raw.githubusercontent.com/Calinou/media/master/godot-antialiased-line2d-demo/screenshot.png)

Expand All @@ -11,8 +11,6 @@ Please report issues specific to the add-on

## Try it out

**Note:** This add-on only supports Godot 3.x, not the current Godot `master` branch (4.0).

### Using the Asset Library

- Open the Godot project manager.
Expand All @@ -39,7 +37,7 @@ if you do not have Git installed.

## License

Copyright © 2022 Hugo Locurcio and contributors
Copyright © 2022-present Hugo Locurcio and contributors

Unless otherwise specified, files in this repository are licensed under the
MIT license. See [LICENSE.md](LICENSE.md) for more information.
9 changes: 6 additions & 3 deletions addons/antialiased_line2d/antialiased_line2d.gd
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
tool
class_name AntialiasedLine2D, "antialiased_line2d.svg"
@tool
@icon("antialiased_line2d.svg")
class_name AntialiasedLine2D
extends Line2D


func _ready() -> void:
texture = AntialiasedLine2DTexture.texture
texture_mode = Line2D.LINE_TEXTURE_TILE
texture_filter = TextureFilter.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC


static func construct_closed_line(p_polygon: PoolVector2Array) -> PoolVector2Array:
static func construct_closed_line(p_polygon: PackedVector2Array) -> PackedVector2Array:
var end_point: Vector2 = p_polygon[p_polygon.size() - 1]
var distance: float = end_point.distance_to(p_polygon[0]) # distance to start point
var bridge_point: Vector2 = end_point.move_toward(p_polygon[0], distance * 0.5)
# Close the polygon drawn by the line by adding superimposed bridge points between the start and end points.
var polygon_line := p_polygon
polygon_line.push_back(bridge_point)
polygon_line.insert(0, bridge_point)

return polygon_line
32 changes: 17 additions & 15 deletions addons/antialiased_line2d/antialiased_line2d.svg.import
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/antialiased_line2d.svg-9243613cd101e058db6c37ff468932c4.stex"
type="CompressedTexture2D"
uid="uid://guodfckewtpv"
path="res://.godot/imported/antialiased_line2d.svg-9243613cd101e058db6c37ff468932c4.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/antialiased_line2d/antialiased_line2d.svg"
dest_files=[ "res://.import/antialiased_line2d.svg-9243613cd101e058db6c37ff468932c4.stex" ]
dest_files=["res://.godot/imported/antialiased_line2d.svg-9243613cd101e058db6c37ff468932c4.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/hdr_compression=1
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
23 changes: 13 additions & 10 deletions addons/antialiased_line2d/antialiased_polygon2d.gd
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
# This is a convenience node that automatically synchronizes an AntialiasedLine2D
# with a Polygon2D.
tool
class_name AntialiasedPolygon2D, "antialiased_polygon2d.svg"
@tool
@icon("antialiased_polygon2d.svg")
class_name AntialiasedPolygon2D
extends Polygon2D

export var stroke_color := Color(0.4, 0.5, 1.0) setget set_stroke_color
export(float, 0.0, 1000.0) var stroke_width := 10.0 setget set_stroke_width
export(int, "Sharp", "Bevel", "Round") var stroke_joint_mode := Line2D.LINE_JOINT_SHARP setget set_stroke_joint_mode
export(float, 0.0, 1000.0) var stroke_sharp_limit := 2.0 setget set_stroke_sharp_limit
export(int, 1, 32) var stroke_round_precision := 8 setget set_stroke_round_precision
@export var stroke_color := Color(0.4, 0.5, 1.0): set = set_stroke_color
@export_range(0.0, 1000.0) var stroke_width:float = 10.0: set = set_stroke_width
@export var stroke_joint_mode:Line2D.LineJointMode = Line2D.LINE_JOINT_SHARP: set = set_stroke_joint_mode
@export_range(0.0, 1000.0) var stroke_sharp_limit:float = 2.0: set = set_stroke_sharp_limit
@export_range(1, 32) var stroke_round_precision: int = 8: set = set_stroke_round_precision

var line_2d := Line2D.new()


func _ready() -> void:
line_2d.texture = AntialiasedLine2DTexture.texture
line_2d.texture_mode = Line2D.LINE_TEXTURE_TILE
line_2d.texture_filter = TextureFilter.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC
if polygon.size() >= 1:
line_2d.points = AntialiasedLine2D.construct_closed_line(polygon)
add_child(line_2d)


func _set(property: String, value) -> bool:
if property == "polygon":
func _set(property: StringName, value: Variant) -> bool:
if property == &"polygon":
line_2d.points = AntialiasedLine2D.construct_closed_line(polygon)

return false


Expand All @@ -37,7 +40,7 @@ func set_stroke_width(p_stroke_width: float) -> void:
line_2d.width = stroke_width


func set_stroke_joint_mode(p_stroke_joint_mode: int) -> void:
func set_stroke_joint_mode(p_stroke_joint_mode: Line2D.LineJointMode) -> void:
stroke_joint_mode = p_stroke_joint_mode
line_2d.joint_mode = stroke_joint_mode

Expand Down
32 changes: 17 additions & 15 deletions addons/antialiased_line2d/antialiased_polygon2d.svg.import
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/antialiased_polygon2d.svg-d9d32c42c22022e4f4053cee124a07c0.stex"
type="CompressedTexture2D"
uid="uid://bkfc7y0qnfi4a"
path="res://.godot/imported/antialiased_polygon2d.svg-d9d32c42c22022e4f4053cee124a07c0.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/antialiased_line2d/antialiased_polygon2d.svg"
dest_files=[ "res://.import/antialiased_polygon2d.svg-d9d32c42c22022e4f4053cee124a07c0.stex" ]
dest_files=["res://.godot/imported/antialiased_polygon2d.svg-d9d32c42c22022e4f4053cee124a07c0.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/hdr_compression=1
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
37 changes: 19 additions & 18 deletions addons/antialiased_line2d/antialiased_regular_polygon2d.gd
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
# This is a convenience node that automatically synchronizes an AntialiasedLine2D
# with a Polygon2D, while also generating a regular Polygon2D shape (hexagon, octagon, …).
tool
class_name AntialiasedRegularPolygon2D, "antialiased_regular_polygon2d.svg"
@tool
@icon("antialiased_regular_polygon2d.svg")
class_name AntialiasedRegularPolygon2D
extends Polygon2D

export var size := Vector2(64, 64) setget set_size
export(int, 3, 128) var sides := 32 setget set_sides
export(float, 0.0, 360.0) var angle_degrees := 360.0 setget set_angle_degrees

export var stroke_color := Color(0.4, 0.5, 1.0) setget set_stroke_color
export(float, 0.0, 1000.0) var stroke_width := 10.0 setget set_stroke_width
export(int, "Sharp", "Bevel", "Round") var stroke_joint_mode := Line2D.LINE_JOINT_SHARP setget set_stroke_joint_mode
export(float, 0.0, 1000.0) var stroke_sharp_limit := 2.0 setget set_stroke_sharp_limit
export(int, 1, 32) var stroke_round_precision := 8 setget set_stroke_round_precision
@export var size := Vector2(64, 64): set = set_size
@export_range(3, 128) var sides: int = 32: set = set_sides
@export_range(0.0, 360.0) var angle_degrees: float = 360: set = set_angle_degrees
@export var stroke_color := Color(0.4, 0.5, 1.0): set = set_stroke_color
@export_range(0.0, 1000.0) var stroke_width:float = 10.0: set = set_stroke_width
@export var stroke_joint_mode:Line2D.LineJointMode = Line2D.LINE_JOINT_SHARP: set = set_stroke_joint_mode
@export_range(0.0, 1000.0) var stroke_sharp_limit:float = 2.0: set = set_stroke_sharp_limit
@export_range(1, 32) var stroke_round_precision: int = 8: set = set_stroke_round_precision

var line_2d := Line2D.new()


func _ready() -> void:
line_2d.texture = AntialiasedLine2DTexture.texture
line_2d.texture_mode = Line2D.LINE_TEXTURE_TILE
line_2d.texture_filter = TextureFilter.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC
update_points()
add_child(line_2d)


func _set(property: String, value) -> bool:
if property == "polygon":
line_2d.points = AntialiasedLine2D.construct_closed_line(polygon)
func _set(property: StringName, value: Variant) -> bool:
if property == &"polygon":
line_2d.points = AntialiasedLine2D.construct_closed_line(value)

return false


func update_points() -> void:
var points := PoolVector2Array()
var points := PackedVector2Array()
for side in sides:
points.push_back(Vector2(0, -1).rotated(side / float(sides) * deg2rad(angle_degrees)) * size * 0.5)
points.push_back(Vector2(0, -1).rotated(side / float(sides) * deg_to_rad(angle_degrees)) * size * 0.5)
if not is_equal_approx(angle_degrees, 360.0):
points.push_back(Vector2.ZERO)
polygon = points
Expand All @@ -60,13 +62,12 @@ func set_stroke_color(p_stroke_color: Color) -> void:
stroke_color = p_stroke_color
line_2d.default_color = stroke_color


func set_stroke_width(p_stroke_width: float) -> void:
stroke_width = p_stroke_width
line_2d.width = stroke_width


func set_stroke_joint_mode(p_stroke_joint_mode: int) -> void:
func set_stroke_joint_mode(p_stroke_joint_mode: Line2D.LineJointMode) -> void:
stroke_joint_mode = p_stroke_joint_mode
line_2d.joint_mode = stroke_joint_mode

Expand Down
32 changes: 17 additions & 15 deletions addons/antialiased_line2d/antialiased_regular_polygon2d.svg.import
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/antialiased_regular_polygon2d.svg-90c0efb58c0991f1567ca6f17fea2cda.stex"
type="CompressedTexture2D"
uid="uid://cypudkhnexspo"
path="res://.godot/imported/antialiased_regular_polygon2d.svg-90c0efb58c0991f1567ca6f17fea2cda.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/antialiased_line2d/antialiased_regular_polygon2d.svg"
dest_files=[ "res://.import/antialiased_regular_polygon2d.svg-90c0efb58c0991f1567ca6f17fea2cda.stex" ]
dest_files=["res://.godot/imported/antialiased_regular_polygon2d.svg-90c0efb58c0991f1567ca6f17fea2cda.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/hdr_compression=1
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
2 changes: 1 addition & 1 deletion addons/antialiased_line2d/plugin.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[plugin]

name="Antialiased Line2D"
description="Antialiased Line2D for any line width (supports GLES3 and GLES2)"
description="Antialiased Line2D and Polygon2D for any line width (supports all rendering methods)"
author="Calinou"
version="1.1.1"
script="plugin.gd"
2 changes: 1 addition & 1 deletion addons/antialiased_line2d/plugin.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tool
@tool
extends EditorPlugin


Expand Down
11 changes: 5 additions & 6 deletions addons/antialiased_line2d/texture.gd
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
tool
@tool
extends Node

# Generates the antialiased Line2D texture that will be used by the various nodes.
# We do this in a singleton to perform this generation once at load, rather than once
# for every AntialiasedLine2D node. This generation can take several dozen milliseconds,
# so it would cause stuttering if performed during gameplay.

var texture := ImageTexture.new()
var texture: ImageTexture = null


func _ready() -> void:
# Generate a texture with custom mipmaps (1-pixel feather on the top and bottom sides).
# The texture must be square for mipmaps to work correctly. The texture's in-memory size is still
# pretty low (less than 200 KB), so this should not cause any performance problems.
var data := PoolByteArray()
var data := PackedByteArray()
for mipmap in [256, 128, 64, 32, 16, 8, 4, 2, 1]:
for y in mipmap:
for x in mipmap:
Expand Down Expand Up @@ -42,6 +42,5 @@ func _ready() -> void:
# Average of 0 and 255 (there is only one pixel).
data.push_back(128)

var image := Image.new()
image.create_from_data(256, 256, true, Image.FORMAT_LA8, data)
texture.create_from_image(image)
var image = Image.create_from_data(256, 256, true, Image.FORMAT_LA8, data)
texture = ImageTexture.create_from_image(image)
Loading

0 comments on commit f846a9a

Please sign in to comment.