-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
bevy_pbr: Add DebugLinesPlugin and DebugNormalsPlugin #5734
Conversation
DebugLinesPlugin adds a DebugLines resource which can be used to draw arbitrary lines with customisable colour. DebugNormalsPlugin enables drawing lines to visualise vertex normals.
So, while I really want something like this and I even already had something locally. I never made a PR because it was covered by the not yet merged primitive shapes RFC. I'm also not sure if this needs to live in bevy_pbr, we really need some sort of debug module. As for the api, I generally like the idea of building a line with a resource, but I would prefer if the color was passed as the argument of draw_line. It's also a bit inconsistent with most other bevy apis. I would have expected that it would just be spawning some sort of LineBundle, personally I still prefer the style of api you went with though. |
if app.world.get_resource::<DebugNormalsSettings>().is_none() { | ||
app.init_resource::<DebugNormalsSettings>(); | ||
} |
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 don't think we need this check here, init_resource::<_>()
will already check this.
for (transform, mesh) in &debug_normals { | ||
if let Some(mesh) = meshes.get(mesh) { | ||
draw_mesh_normals(&transform.affine(), mesh, scale, debug_lines); | ||
} | ||
} | ||
if debug_normal_settings.global { | ||
for (transform, mesh) in &no_debug_normals { | ||
if let Some(mesh) = meshes.get(mesh) { | ||
draw_mesh_normals(&transform.affine(), mesh, scale, debug_lines); | ||
} | ||
} | ||
} | ||
} |
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.
for (transform, mesh) in &debug_normals { | |
if let Some(mesh) = meshes.get(mesh) { | |
draw_mesh_normals(&transform.affine(), mesh, scale, debug_lines); | |
} | |
} | |
if debug_normal_settings.global { | |
for (transform, mesh) in &no_debug_normals { | |
if let Some(mesh) = meshes.get(mesh) { | |
draw_mesh_normals(&transform.affine(), mesh, scale, debug_lines); | |
} | |
} | |
} | |
} | |
let mesh_normals_to_draw = if debug_normal_settings.global { | |
&debug_normals | |
} else { | |
&no_debug_normals | |
}; | |
for (transform, mesh) in &mesh_normals_to_draw { | |
if let Some(mesh) = meshes.get(mesh) { | |
draw_mesh_normals(&transform.affine(), mesh, scale, debug_lines); | |
} | |
} | |
} |
pub global: bool, | ||
pub color: Color, | ||
pub scale: f32, |
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.
pub global: bool, | |
pub color: Color, | |
pub scale: f32, | |
/// Draw mesh normals on every mesh. | |
pub global: bool, | |
/// Color to use for drawing normals. | |
pub color: Color, | |
/// How far out the line will extrude to display the normal. | |
pub scale: f32, |
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.
was mainly just confused about the global
one until I read the code more.
# Objective Add a convenient immediate mode drawing API for visual debugging. Fixes #5619 Alternative to #1625 Partial alternative to #5734 Based off https://github.com/Toqozz/bevy_debug_lines with some changes: * Simultaneous support for 2D and 3D. * Methods for basic shapes; circles, spheres, rectangles, boxes, etc. * 2D methods. * Removed durations. Seemed niche, and can be handled by users. <details> <summary>Performance</summary> Stress tested using Bevy's recommended optimization settings for the dev profile with the following command. ```bash cargo run --example many_debug_lines \ --config "profile.dev.package.\"*\".opt-level=3" \ --config "profile.dev.opt-level=1" ``` I dipped to 65-70 FPS at 300,000 lines CPU: 3700x RAM Speed: 3200 Mhz GPU: 2070 super - probably not very relevant, mostly cpu/memory bound </details> <details> <summary>Fancy bloom screenshot</summary> ![Screenshot_20230207_155033](https://user-images.githubusercontent.com/29694403/217291980-f1e0500e-7a14-4131-8c96-eaaaf52596ae.png) </details> ## Changelog * Added `GizmoPlugin` * Added `Gizmos` system parameter for drawing lines and wireshapes. ### TODO - [ ] Update changelog - [x] Update performance numbers - [x] Add credit to PR description ### Future work - Cache rendering primitives instead of constructing them out of line segments each frame. - Support for drawing solid meshes - Interactions. (See [bevy_mod_gizmos](https://github.com/LiamGallagher737/bevy_mod_gizmos)) - Fancier line drawing. (See [bevy_polyline](https://github.com/ForesightMiningSoftwareCorporation/bevy_polyline)) - Support for `RenderLayers` - Display gizmos for a certain duration. Currently everything displays for one frame (ie. immediate mode) - Changing settings per drawn item like drawing on top or drawing to different `RenderLayers` Co-Authored By: @lassade <felipe.jorge.pereira@gmail.com> Co-Authored By: @The5-1 <agaku@hotmail.de> Co-Authored By: @Toqozz <toqoz@hotmail.com> Co-Authored By: @nicopap <nico@nicopap.ch> --------- Co-authored-by: Robert Swain <robert.swain@gmail.com> Co-authored-by: IceSentry <c.giguere42@gmail.com> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
@devil-ira do we have support for visualising normals with the gizmos plugin? If not, should I update this PR to make use of our line drawing functionality to do it? :) |
No, I do have some local code that does it more efficiently than this, buuut.. it's 5 months old and way more complicated. If you want something to use now you could update this PR to be a part of bevy_gizmos and get it merged pretty quickly. I'll clean up my code at-some-point:tm: and PR it after as a performance boost if need be. |
Backlog cleanup: lack of activity, also note cart's #6529 as a partial alternative. |
Objective
Solution
DebugLinesPlugin
which adds aDebugLines
resource which can be used to draw arbitrary lines with customisable colourDebugNormalsPlugin
which enables drawing lines to visualise vertex normals, leveragingDebugLinesPlugin
Changelog
DebugLinesPlugin
which adds aDebugLines
resource which can be used to draw arbitrary lines with customizable colorDebugNormalsPlugin
which enables drawing lines to visualize vertex normals, leveragingDebugLinesPlugin