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

Create CollisionObject3D debug shapes using RS #48175

Merged
merged 1 commit into from
May 9, 2021

Conversation

trollodel
Copy link
Contributor

@trollodel trollodel commented Apr 25, 2021

Fixes #48085, fixes #48281

In #45783, I added the possibility to show debug shapes directly in CollisionObject3D. To be conservative (and because it's my first PR), I displayed debug shapes using MeshInstances, as it was done in CollisionShape3D. This unfortunately came with some drawbacks and one of them was described in #48085.

In this PR I replace MeshInstances with direct calls to RenderingServer.
When I test this, the debug shape disappears when the Shape3D resource changes and reappears only when I change the transform. EDIT: fixed
Since I'm not sure if it is my fault or a RS bug, I want to backport it to 3.x soon to see if the same issue appears.

EDIT: I have backported this and the issue doesn't happen, so it's a RS bug.
EDIT 2: See this comment

Bugsquad edit: test scenes here: CollisionObject_debug_meshes.zip

@trollodel trollodel marked this pull request as ready for review April 25, 2021 09:48
@trollodel trollodel requested a review from a team as a code owner April 25, 2021 09:48
@Calinou Calinou added this to the 4.0 milestone Apr 25, 2021
@Calinou Calinou added cherrypick:3.x Considered for cherry-picking into a future 3.x release cherrypick:3.3 labels Apr 25, 2021
@pouleyKetchoupp pouleyKetchoupp requested a review from a team April 26, 2021 22:40
scene/3d/collision_object_3d.cpp Outdated Show resolved Hide resolved
scene/3d/collision_object_3d.cpp Outdated Show resolved Hide resolved
@trollodel trollodel force-pushed the collisionobject3d-no-mi branch 3 times, most recently from 5ee46fe to ef00708 Compare April 27, 2021 09:39
Copy link
Contributor

@AndreaCatania AndreaCatania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a good idea, however what happens if the shape size changes? I think this was destroying and creating the mesh each frame for this reason. I think you should listen to the shape changed event, and destroy it if changed.

In alternative, you should consider to change how https://github.com/godotengine/godot/blob/master/scene/resources/shape_3d.cpp#L60 works. So that when the shape changes, if it has a debug mesh, the mesh is updated. (Right now it's just destroyed: https://github.com/godotengine/godot/blob/master/scene/resources/shape_3d.cpp#L98)

scene/3d/collision_object_3d.cpp Outdated Show resolved Hide resolved
scene/3d/collision_object_3d.h Outdated Show resolved Hide resolved
@trollodel
Copy link
Contributor Author

Right now it's just destroyed

I see. I thought it was a RS bug 😅.

Copy link
Contributor

@pouleyKetchoupp pouleyKetchoupp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the shape changes, it gets properly propagated through CollisionShape3D and the owner gets notified, which triggers the re-creation of the debug shape. So with the last changes it seems fine on this aspect.

One thing that's currently not working is updating the transform of the debug shape when the collision object moves. It was handled directly by having a node in the tree before, now it's not (my bad, I completely forgot about that before).

It can be handled in a relatively simple way:

  • Add a protected method _on_transform_changed to update the debug shapes transform in CollisionObject3D (it can just return immediately if there's no debug shape).
  • It needs to be called on NOTIFICATION_TRANSFORM_CHANGED to handle transform changes from script.
  • It also needs to be called in RigidBody3D::_direct_state_changed and PhysicalBone3D::_direct_state_changed to handle transform changes from the physics simulation (the notification is not propagated in this case).

scene/3d/collision_object_3d.cpp Outdated Show resolved Hide resolved
@trollodel
Copy link
Contributor Author

trollodel commented Apr 27, 2021

@AndreaCatania Now I listen for shape changes and the issue I had is gone.

@trollodel
Copy link
Contributor Author

One thing that's currently not working is updating the transform of the debug shape when the collision object moves. It was handled directly by having a node in the tree before, now it's not (my bad, I completely forgot about that before).

@pouleyKetchoupp Done

Copy link
Contributor

@AndreaCatania AndreaCatania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small things to change, but it look nice already. As improvement, if you really feel like, you may consider to add two functions: to add and remove the debug shapes, so you can avoid have a lot of connect / disconnect spread around. But this is not required I think.
Thanks!

scene/3d/collision_object_3d.cpp Show resolved Hide resolved
scene/3d/collision_object_3d.cpp Outdated Show resolved Hide resolved
@trollodel
Copy link
Contributor Author

trollodel commented Apr 29, 2021

you may consider to add two functions: to add and remove the debug shapes

Debug shapes are added only in one place, so it's useless to add a function for that.

scene/3d/collision_object_3d.cpp Outdated Show resolved Hide resolved
scene/3d/collision_object_3d.cpp Outdated Show resolved Hide resolved
scene/3d/collision_object_3d.cpp Outdated Show resolved Hide resolved
scene/3d/collision_object_3d.cpp Outdated Show resolved Hide resolved
scene/3d/collision_object_3d.cpp Show resolved Hide resolved
scene/3d/collision_object_3d.cpp Show resolved Hide resolved
@trollodel trollodel force-pushed the collisionobject3d-no-mi branch 3 times, most recently from fc9a395 to e91238d Compare May 1, 2021 17:52
Copy link
Contributor

@pouleyKetchoupp pouleyKetchoupp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added another comment on a detail, otherwise it all seems to work fine!

scene/3d/collision_object_3d.cpp Show resolved Hide resolved
@trollodel trollodel force-pushed the collisionobject3d-no-mi branch 2 times, most recently from 4eb9889 to 9a00ce3 Compare May 4, 2021 20:57
Copy link
Contributor

@pouleyKetchoupp pouleyKetchoupp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@akien-mga akien-mga dismissed AndreaCatania’s stale review May 9, 2021 14:41

Feedback addressed AFAICT, review was otherwise an approval.

@akien-mga akien-mga merged commit aac0145 into godotengine:master May 9, 2021
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

@trollodel Would you be able to make a PR to backport these changes to 3.x? It's not trivially cherry-pickable as is.

@trollodel
Copy link
Contributor Author

trollodel commented May 9, 2021

@akien-mga I already have a working backport of this PR (I need to update it after the reviews), I was waiting for this PR to be (finally 😀) merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants