Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concave CollisionPolygon2D debug drawing and docs #89820

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion doc/classes/CollisionPolygon2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
A node that provides a polygon shape to a [CollisionObject2D] parent.
</brief_description>
<description>
A node that provides a thickened polygon shape (a prism) to a [CollisionObject2D] parent and allows to edit it. The polygon can be concave or convex. This can give a detection shape to an [Area2D] or turn [PhysicsBody2D] into a solid object.
A node that provides a polygon shape to a [CollisionObject2D] parent and allows to edit it. The polygon can be concave or convex. This can give a detection shape to an [Area2D], turn [PhysicsBody2D] into a solid object, or give a hollow shape to a [StaticBody2D].
[b]Warning:[/b] A non-uniformly scaled [CollisionShape2D] will likely not behave as expected. Make sure to keep its scale the same on all axes and adjust its shape resource instead.
</description>
<tutorials>
Expand Down
19 changes: 9 additions & 10 deletions scene/2d/physics/collision_polygon_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,16 @@ void CollisionPolygon2D::_notification(int p_what) {
}

if (polygon.size() > 2) {
#define DEBUG_DECOMPOSE
#if defined(TOOLS_ENABLED) && defined(DEBUG_DECOMPOSE)
Vector<Vector<Vector2>> decomp = _decompose_in_convex();

Color c(0.4, 0.9, 0.1);
for (int i = 0; i < decomp.size(); i++) {
c.set_hsv(Math::fmod(c.get_h() + 0.738, 1), c.get_s(), c.get_v(), 0.5);
draw_colored_polygon(decomp[i], c);
#ifdef TOOLS_ENABLED
if (build_mode == BUILD_SOLIDS) {
Vector<Vector<Vector2>> decomp = _decompose_in_convex();

Color c(0.4, 0.9, 0.1);
for (int i = 0; i < decomp.size(); i++) {
c.set_hsv(Math::fmod(c.get_h() + 0.738, 1), c.get_s(), c.get_v(), 0.5);
draw_colored_polygon(decomp[i], c);
}
}
#else
draw_colored_polygon(polygon, get_tree()->get_debug_collisions_color());
#endif

const Color stroke_color = Color(0.9, 0.2, 0.0);
Expand Down
Loading