Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
97cbc9f
Fix perpendicular_distance
Sinowa-Programming Jul 20, 2026
e8fd24a
Fix RDP Algorithm
Sinowa-Programming Jul 21, 2024
b914d85
Handle self intersections
Sinowa-Programming Jul 21, 2024
2f21929
Add star shaped RDP algorithm
Sinowa-Programming Jul 20, 2026
899ed66
Make star RDP optional
Sinowa-Programming Jul 20, 2026
9786806
Revert "Make star RDP optional"
Sinowa-Programming Jul 20, 2026
cc41446
Make Star RDP optional
Sinowa-Programming Jul 20, 2026
e9c8ca2
Add GD Extension compatibility
Sinowa-Programming Jul 20, 2026
f219e1a
Star RDP optional for Atlas Texture
Sinowa-Programming Sep 23, 2024
fce5083
Add triangular visibility check
Sinowa-Programming Jul 20, 2026
e11f34b
Add Wikipedia link for RDP algorithm
Sinowa-Programming Nov 20, 2024
08bc611
Rename Star RDP flag to "Advanced RDP" for clarity
Sinowa-Programming Jul 20, 2026
c81c04c
Recursive MonoAtomic RDP Algorithm
Sinowa-Programming Jul 20, 2026
bdccccb
Fix dev_mode, double precision error
Sinowa-Programming Oct 12, 2025
4054605
Fix documentation
Sinowa-Programming Oct 12, 2025
88eb5b0
Update editor/scene/2d/sprite_2d_editor_plugin.cpp
Sinowa-Programming Oct 12, 2025
c7afa84
Update doc/classes/BitMap.xml
Sinowa-Programming Oct 12, 2025
12f9f21
Clean up variable names
Sinowa-Programming Oct 20, 2025
a6fdb6e
Fix newly created intersection not being detected.
Sinowa-Programming Nov 10, 2025
4157b1b
Speed Improvements
Sinowa-Programming Nov 18, 2025
dd3ae4f
Remove unused variable.
Sinowa-Programming Nov 18, 2025
b194e94
Add comments and cleanup code.
Sinowa-Programming Jul 19, 2026
c70bb9d
Add api validation for new rdp function
Sinowa-Programming Jul 20, 2026
6a8a566
Fix obb cache bug and add checks
Sinowa-Programming Jul 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/classes/BitMap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@
<return type="PackedVector2Array[]" />
<param index="0" name="rect" type="Rect2i" />
<param index="1" name="epsilon" type="float" default="2.0" />
<param index="2" name="advanced_rdp" type="bool" default="false" />
<description>
Creates an [Array] of polygons covering a rectangular portion of the bitmap. It uses a marching squares algorithm, followed by Ramer-Douglas-Peucker (RDP) reduction of the number of vertices. Each polygon is described as a [PackedVector2Array] of its vertices.
To get polygons covering the whole bitmap, pass:
[codeblock]
Rect2(Vector2(), get_size())
[/codeblock]
[param epsilon] is passed to RDP to control how accurately the polygons cover the bitmap: a lower [param epsilon] corresponds to more points in the polygons.
If [param advanced_rdp] is [code]true[/code], uses a more advanced RDP algorithm that prevents self-intersections, but is considerably slower.
</description>
</method>
<method name="resize">
Expand Down
4 changes: 4 additions & 0 deletions doc/classes/ResourceImporterTextureAtlas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<tutorials>
</tutorials>
<members>
<member name="advanced_rdp" type="bool" setter="" getter="" default="false">
If [code]true[/code], a slower [url=https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm]Ramer Douglas Peuker Algorithm[/url] is used that does not self-intersect.
[b]Note:[/b] Only effective if [member import_mode] is [b]Mesh2D[/b].
</member>
<member name="atlas_file" type="String" setter="" getter="" default="&quot;&quot;">
Path to the atlas spritesheet. This [i]must[/i] be set to valid path to a PNG image. Otherwise, the atlas will fail to import.
</member>
Expand Down
5 changes: 4 additions & 1 deletion editor/import/resource_importer_texture_atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ bool ResourceImporterTextureAtlas::get_option_visibility(const String &p_path, c
return false;
} else if (p_option == "trim_alpha_border_from_region" && int(p_options["import_mode"]) != IMPORT_MODE_REGION) {
return false;
} else if (p_option == "advanced_rdp" && int(p_options["import_mode"]) != IMPORT_MODE_2D_MESH) {
return false;
}

return true;
Expand All @@ -85,6 +87,7 @@ void ResourceImporterTextureAtlas::get_import_options(const String &p_path, List
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "import_mode", PROPERTY_HINT_ENUM, "Region,Mesh2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "crop_to_region"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "trim_alpha_border_from_region"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "advanced_rdp"), false));
}

String ResourceImporterTextureAtlas::get_option_group_file() const {
Expand Down Expand Up @@ -252,7 +255,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
Ref<BitMap> bit_map;
bit_map.instantiate();
bit_map->create_from_image_alpha(image);
Vector<Vector<Vector2>> polygons = bit_map->clip_opaque_to_polygons(Rect2(Vector2(), image->get_size()));
Vector<Vector<Vector2>> polygons = bit_map->clip_opaque_to_polygons(Rect2(Vector2(), image->get_size()), 2.0, options["advanced_rdp"]);

for (int j = 0; j < polygons.size(); j++) {
EditorAtlasPacker::Chart chart;
Expand Down
7 changes: 6 additions & 1 deletion editor/scene/2d/sprite_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ void Sprite2DEditor::_update_mesh_data() {
}

float epsilon = simplification->get_value();
bool advanced_rdp = enable_advanced_rdp->is_pressed();

Vector<Vector<Vector2>> lines = bm->clip_opaque_to_polygons(rect, epsilon);
Vector<Vector<Vector2>> lines = bm->clip_opaque_to_polygons(rect, epsilon, advanced_rdp);

uv_lines.clear();

Expand Down Expand Up @@ -711,6 +712,10 @@ Sprite2DEditor::Sprite2DEditor() {
grow_pixels->set_accessibility_name(TTRC("Grow (Pixels):"));
hb->add_child(grow_pixels);
hb->add_spacer();
hb->add_child(memnew(Label(TTRC("Enable Advanced RDP:"))));
enable_advanced_rdp = memnew(CheckBox);
hb->add_child(enable_advanced_rdp);
hb->add_spacer();
update_preview = memnew(Button);
update_preview->set_text(TTR("Update Preview"));
update_preview->connect(SceneStringName(pressed), callable_mp(this, &Sprite2DEditor::_update_mesh_data));
Expand Down
2 changes: 2 additions & 0 deletions editor/scene/2d/sprite_2d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class HBoxContainer;
class MenuButton;
class Panel;
class ViewPanner;
class CheckBox;

class Sprite2DEditor : public Control {
GDCLASS(Sprite2DEditor, Control);
Expand Down Expand Up @@ -85,6 +86,7 @@ class Sprite2DEditor : public Control {
SpinBox *simplification = nullptr;
SpinBox *grow_pixels = nullptr;
SpinBox *shrink_pixels = nullptr;
CheckBox *enable_advanced_rdp = nullptr;
Button *update_preview = nullptr;

void _menu_option(int p_option);
Expand Down
5 changes: 5 additions & 0 deletions misc/extension_api_validation/4.7-stable/GH-94602.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GH-94602
--------
Validate extension JSON: Error: Field 'classes/BitMap/methods/opaque_to_polygons/arguments': size changed value in new API, from 2 to 3.

Add an optional argument to use a star-region-restricted Ramer-Douglas-Peucker Algorithm. No adjustments should be necessary.
48 changes: 48 additions & 0 deletions scene/resources/bit_map.compat.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**************************************************************************/
/* bit_map.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef DISABLE_DEPRECATED

#include "core/object/class_db.h"
#include "core/variant/typed_array.h"

Vector<Vector<Vector2>> BitMap::_clip_opaque_to_polygons_bind_compat_94602(const Rect2i &p_rect, float p_epsilon) const {
return clip_opaque_to_polygons(p_rect, p_epsilon, false);
}

TypedArray<PackedVector2Array> BitMap::_opaque_to_polygons_bind_compat_94602(const Rect2i &p_rect, float p_epsilon) const {
return _opaque_to_polygons_bind(p_rect, p_epsilon, false);
}

void BitMap::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("opaque_to_polygons", "rect", "epsilon"), &BitMap::_opaque_to_polygons_bind_compat_94602, DEFVAL(2.0));
}

#endif // DISABLE_DEPRECATED
Loading