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 CSGShape3D debug collision shapes being visible in editor #86699

Merged

Conversation

MajorMcDoom
Copy link
Contributor

@MajorMcDoom MajorMcDoom commented Jan 2, 2024

CSGShape3D is improperly co-opting the debug collision visualization system to render editor gizmos. As such, the gizmos do not respect any gizmo visibility settings (see #87919 ).

The only way to control the visibility of the collision gizmos currently is to make the CSGShape3D itself invisible (workaround comes from #84174). This is incorrect because an invisible CSGShape3D can still have collision, so the gizmo should still be visible. This also affects runtime debug collision visualization (see #96767).

This PR makes the debug collision geometry only visible in the running game, essentially removing their usage as gizmos.

@MajorMcDoom MajorMcDoom requested a review from a team as a code owner January 2, 2024 01:41
@MajorMcDoom
Copy link
Contributor Author

MajorMcDoom commented Jan 2, 2024

UPDATE:

This issue was previously reported, and was unfortunately misdiagnosed and led to an incorrect solution that introduces another problem that will have to be corrected (perhaps as part of this pull request):
Original issue report: #84132
Merged incorrect fix: #84174

The issue was misdiagnosed as being a gizmo that fails to hide. This is not the case - it is runtime debug collision shape visualization, not an editor gizmo.

The subsequent merge made the debug collision shape visibility dependent on the visibility of the CSG node itself. While this partially masked the problem of the previously unhideable wireframe (it is now hideable by hiding the CSG visuals), it still is not hideable via the gizmo toggles, and also leads to a new incorrect behaviour: As the documentation for the use_collision property states: making a CSG invisible does not disable the collision. This means the debug collision shape visualization should remain visible to accurately reflect the presence of the collision shape, regardless of the visibility of the CSG.

Because this new pull request will completely remove the debug collision shapes from the editor, the visibility dependency introduced by #84174 can be reverted. I will do this in a commit amend tomorrow.

@MajorMcDoom MajorMcDoom closed this Jan 2, 2024
@MajorMcDoom MajorMcDoom deleted the editor-csg-collision-gizmo-fix branch January 2, 2024 07:52
@MajorMcDoom MajorMcDoom restored the editor-csg-collision-gizmo-fix branch January 2, 2024 07:59
@MajorMcDoom MajorMcDoom reopened this Jan 2, 2024
@MajorMcDoom MajorMcDoom force-pushed the editor-csg-collision-gizmo-fix branch from b5fe323 to 10babe2 Compare January 2, 2024 08:33
@MajorMcDoom
Copy link
Contributor Author

Aforementioned changes from #84174 have been reverted.

@fire
Copy link
Member

fire commented Jan 3, 2024

Let us know if #84174 fixes your bug.

@MajorMcDoom
Copy link
Contributor Author

MajorMcDoom commented Jan 3, 2024

Let us know if #84174 fixes your bug.

@fire See my two followup comments. That's a merge which actually misdiagnosed the problem and introduced another issue, which this merge would also fix.

@MajorMcDoom MajorMcDoom force-pushed the editor-csg-collision-gizmo-fix branch from cf97bf2 to 7b9e280 Compare January 5, 2024 19:51
@BastiaanOlij
Copy link
Contributor

@MajorMcDoom it's worth adding screenshots to PRs like this to make clear what the change is.

I haven't followed the previous discussions, but this is an interesting one.

Traditionally Godot has always had the visual and physics part of an object separate. Collision shapes are drawn in editor as well. You can see this clearly when you move the collision shape away from the object:
image
You can hide the collision shapes however if they are in the way, something that doesn't effect physics for all the right reasons, but does catch people off guard.

CSG breaks the mould. It's a single node that handles both the visual and the physics aspect of the object. Showing the collision shape superimposed over the mesh is in a way expected behaviour, you can tell immediately whether you've forgotten to enable collisions or if they are indeed enabled.

However, if you're not interested there is no way to hide them, and especially for complex extruded shapes, it can be a lot of visual clutter not to mention that it slows the IDE down. I use CSGPolygon a lot to create stuff like race tracks, often the track itself will be several CSGPolygon shapes all following the same path but without collisions just to bring in detail, and a separate CSGPolygon shape that is used to create the collision shape. It gets pretty gnarly at times :)

While I find it important to be able to see the collision shape and would not want that removed, I'd love to hide it once I'm happy with the composition of the scene.

@MajorMcDoom
Copy link
Contributor Author

@BastiaanOlij Thanks for the response!

I'm not sure if there's been a miscommunication somewhere, but I'm aware that CSG is a "hybrid" between visual and collision.

The problem is:

The debug collision shape is still important to have for CSG at runtime, because the feature should work for all collision shapes. That is why this PR still leaves that intact.

Whether or not a CSG should show collision gizmos is a discussion beyond the scope of this PR. The fact is, however, that they are currently not showing gizmos - they are improperly using debug collision shapes in place of gizmos.

@BastiaanOlij
Copy link
Contributor

Whether or not a CSG should show collision gizmos is a discussion beyond the scope of this PR. The fact is, however, that they are currently not showing gizmos - they are improperly using debug collision shapes in place of gizmos.

Ah, ok, I indeed missed that nuance. Sounds like a shortcut was taken to make something draw. I'd have to take a closer look to give more sensible feedback :)

@KoBeWi KoBeWi modified the milestones: 4.3, 4.4 Jul 29, 2024
@AThousandShips AThousandShips changed the title Fixed CSG debug collision shapes being visible in editor Fix CSG debug collision shapes being visible in editor Jul 29, 2024
@BastiaanOlij
Copy link
Contributor

Ok, as best as I can judge there are a few incorrect assumptions here which means I think a little more work needs to be done here.

When we look at normal collision shapes it is correct that the debug collision shape is drawn at runtime when this is enabled to help find issues with the collision setup in ones game.
However the same shape is also drawn in the IDE, as a transparent shape when the node is selected and as a grey wireframe when the node is not selected, to visualise the collision shapes in the scene. However you can turn this off in the view settings as this can be visually cluttering.

When we look at CSG the problem we have is that we have dual functionality here. The main purpose of CSG is the mesh that is generated and the gizmo controls focus on the manipulation of this mesh. The collision shape that can be added is "extra" but we lack control over whether we want to visualise this shape in the IDE.

This PR is born out of an understandable annoyance that this shape is always drawn, and drawn fully visible. It thus relegates this to the original functionality of just showing the shape during runtime if collision shapes are enabled in the debug menu.

There is however value in seeing the collision shape in the IDE at times and taking that away will frustrate users who rely on seeing that shape.
What is needed is similar functionality as exists on the collision shape node itself. E.g. it should be drawn less obvious when the CSG node is not selected, and you should be able to toggle this on or off.
If that can be added to this PR, I think this would be good functionality to have.

@MajorMcDoom MajorMcDoom changed the title Fix CSG debug collision shapes being visible in editor Fix CSGMesh3D debug collision shapes being visible in editor Sep 9, 2024
@MajorMcDoom
Copy link
Contributor Author

MajorMcDoom commented Sep 9, 2024

@BastiaanOlij is right in that there needs to be a proper gizmo solution for CSGShape3D at some point, but I would like to address an inaccuracy in his assessment regarding the preservation of existing use cases:

There is actually currently no use at all for the CSGShape3D collision visualization as a separate gizmo because:

  • CSG visual geometry is identical to the collision geometry, so visualization is already possible.
  • For the use case of visualizing collision-only CSGs, the aforementioned improper fix (Hide CSGShape's debug_collision_shape when it is invisible #84174) has already made it impossible, by making the collision geometry visualization dependent on CSG visibility.

In other words, the current gizmo solution is entirely useless because it only renders a wireframe over an identical underlying mesh, and only when the underlying mesh is already visible.

As such, this PR:

  • Does not break any existing use cases (they are already broken).
  • Fixes two UX bugs.
  • Represents a small step toward a proper gizmo solution by removing broken bandaid solutions and setting a clean slate.

@MajorMcDoom MajorMcDoom changed the title Fix CSGMesh3D debug collision shapes being visible in editor Fix CSGShape3D debug collision shapes being visible in editor Sep 9, 2024
…an old, incorrect fix which made debug collision visibility depend on CSG visibility.
Copy link
Contributor

@BastiaanOlij BastiaanOlij left a comment

Choose a reason for hiding this comment

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

Speaking to @MajorMcDoom on private channels a couple days ago and his further findings reported here, I'm in agreement that the current state of things are as he says and that in order to move forward, fixing one problem at a time is better than endlessly flipping back and forth.

We just have to be mindful that if anyone complains that we don't go back to a more broken situation but make clear that we will be taking steps after this step.

So I'm for merging this and making sure that the current behaviour makes sense, and then in the future following it up with a proper gizmo implementation for CSG collisions.

@akien-mga akien-mga merged commit 91c66b5 into godotengine:master Sep 10, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@MajorMcDoom
Copy link
Contributor Author

For posterity, I've made a follow-up issue here: #96807

@ydeltastar
Copy link
Contributor

ydeltastar commented Sep 11, 2024

Can this be cherry-picked for 4.3? The debug draw noise in a level full of CSG composites is very high and it can't be disabled.

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