-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Create CollisionObject3D debug shapes using RS #48175
Conversation
c54b55f
to
6326d2f
Compare
5ee46fe
to
ef00708
Compare
There was a problem hiding this 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)
I see. I thought it was a RS bug 😅. |
ef00708
to
a5f13d1
Compare
There was a problem hiding this 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 inCollisionObject3D
(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
andPhysicalBone3D::_direct_state_changed
to handle transform changes from the physics simulation (the notification is not propagated in this case).
a5f13d1
to
83fde64
Compare
@AndreaCatania Now I listen for shape changes and the issue I had is gone. |
83fde64
to
2a8bb4d
Compare
@pouleyKetchoupp Done |
There was a problem hiding this 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!
Debug shapes are added only in one place, so it's useless to add a function for that. |
2a8bb4d
to
e8cb5cb
Compare
fc9a395
to
e91238d
Compare
There was a problem hiding this 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!
4eb9889
to
9a00ce3
Compare
9a00ce3
to
5b19c7d
Compare
There was a problem hiding this 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!
Feedback addressed AFAICT, review was otherwise an approval.
Thanks! |
@trollodel Would you be able to make a PR to backport these changes to |
@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. |
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: fixedSince 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