Skip to content

Extract 2D debug collision drawing from CollisionShape2D to CollisionObject2D#59516

Open
rburing wants to merge 1 commit intogodotengine:masterfrom
rburing:collision_object_2d_debug_drawing
Open

Extract 2D debug collision drawing from CollisionShape2D to CollisionObject2D#59516
rburing wants to merge 1 commit intogodotengine:masterfrom
rburing:collision_object_2d_debug_drawing

Conversation

@rburing
Copy link
Copy Markdown
Member

@rburing rburing commented Mar 25, 2022

This is more flexible, as it allows displaying collision shapes which were created directly in the physics server without a CollisionShape2D node. In 3D the CollisionObject3D also handles the debug drawing.

Fixes #36499.

Would appreciate testing to confirm that the shapes are still drawn in the right position in all cases.

Note: This change implies that the debug shape of a "lone" CollisionShape2D node (not a child of any node derived from CollisionObject2D) is no longer drawn. I consider this an improvement, as it is less confusing (there is already an in-editor configuration warning saying a CollisionShape2D should only be used as a child of a node derived from CollisionObject2D). Moreover, this is the same behavior as it is currently in 3D.

Note 2: This change also allows to hide disabled collision shapes completely, which was not possible before due to the coupling with the editor code. I've hidden the disabled collision shapes in this PR, but this decision is up for debate (whether they should always be hidden, always be shown greyed out as in the editor, or whether an option to toggle the behavior should be added). In 3D, disabled collision shapes are always hidden.

@rburing rburing requested a review from a team as a code owner March 25, 2022 14:58
@KoBeWi KoBeWi added this to the 4.0 milestone Mar 25, 2022
@KoBeWi
Copy link
Copy Markdown
Member

KoBeWi commented Mar 25, 2022

Aren't server-created collision shapes usually used with server-created physics bodies? In that case they still wouldn't be drawn.

The solution is simple enough to be ok, but the use-case is weird 🤔

@rburing
Copy link
Copy Markdown
Member Author

rburing commented Mar 25, 2022

Putting the drawing code somewhere deep so it can draw all the things would be even better, but this PR at least puts the 2D situation on par with 3D.

Edit: Still have to make any changes to the shapes (e.g. the changed signal of the shape resources) trigger an update(); marking as draft until that's done.

@rburing rburing force-pushed the collision_object_2d_debug_drawing branch 2 times, most recently from 4fd5247 to 282856a Compare March 25, 2022 15:44
@rburing rburing marked this pull request as draft March 25, 2022 17:11
@rburing rburing force-pushed the collision_object_2d_debug_drawing branch from 282856a to a7e31c5 Compare March 25, 2022 19:49
@rburing rburing marked this pull request as ready for review March 25, 2022 19:52
@rburing rburing marked this pull request as draft March 25, 2022 20:25
@rburing rburing force-pushed the collision_object_2d_debug_drawing branch from a7e31c5 to a9d7648 Compare March 25, 2022 23:03
@rburing rburing changed the title Move 2D debug collision drawing from CollisionShape2D to CollisionObject2D Extract 2D debug collision drawing from CollisionShape2D to CollisionObject2D Mar 25, 2022
@rburing rburing force-pushed the collision_object_2d_debug_drawing branch 3 times, most recently from 4cdb3ab to 96c27fb Compare March 25, 2022 23:12
@rburing
Copy link
Copy Markdown
Member Author

rburing commented Mar 25, 2022

The editor still has to draw each individual collision shape (even if it is not a child of a CollisionObject2D) to keep editing usable, so I concluded it's not practical to remove the drawing code from CollisionShape2D. I've changed the drawing code of CollisionShape2D to run only in the editor, and the new debug drawing code for CollisionObject2D (based on the CollisionShape2D code and inspired by the 3D code) now runs only when not in the editor and the Visible Collision Shapes option is activated.

@rburing rburing marked this pull request as ready for review March 25, 2022 23:46
…Object2D

This is more flexible, as it allows displaying shapes which were created
directly in the physics server without a CollisionShape2D node.
Also, it allows hiding disabled shapes completely (which was not
possible before due to the coupling with the editor code).
The code is inspired by the code of CollisionObject3D.
@rburing rburing force-pushed the collision_object_2d_debug_drawing branch from 96c27fb to 096af18 Compare March 26, 2022 10:11
@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 9, 2023
@rburing rburing modified the milestones: 4.1, 4.2 Jun 7, 2023
@AThousandShips AThousandShips modified the milestones: 4.2, 4.3 Oct 26, 2023
@AThousandShips AThousandShips modified the milestones: 4.3, 4.4 Jul 25, 2024
@Repiteo Repiteo modified the milestones: 4.4, 4.x Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collision shapes created through CollisionObject2D APIs are not visible

5 participants