Skip to content

Conversation

superdump
Copy link
Contributor

Objective

  • Visualise vertex normals

Solution

  • Add DebugLinesPlugin which adds a DebugLines resource which can be used to draw arbitrary lines with customisable colour
  • Add DebugNormalsPlugin which enables drawing lines to visualise vertex normals, leveraging DebugLinesPlugin

Changelog

  • Added DebugLinesPlugin which adds a DebugLines resource which can be used to draw arbitrary lines with customizable color
  • Added DebugNormalsPlugin which enables drawing lines to visualize vertex normals, leveraging DebugLinesPlugin

DebugLinesPlugin adds a DebugLines resource which can be used to draw arbitrary
lines with customisable colour.

DebugNormalsPlugin enables drawing lines to visualise vertex normals.
@IceSentry
Copy link
Contributor

IceSentry commented Aug 19, 2022

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.

@IceSentry IceSentry added A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible labels Aug 19, 2022
Comment on lines +130 to +132
if app.world.get_resource::<DebugNormalsSettings>().is_none() {
app.init_resource::<DebugNormalsSettings>();
}
Copy link
Member

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.

Comment on lines +178 to +190
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);
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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);
}
}
}

Comment on lines +142 to +144
pub global: bool,
pub color: Color,
pub scale: f32,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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,

Copy link
Member

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.

cart added a commit that referenced this pull request Mar 20, 2023
# 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 <[email protected]>
Co-Authored By: @The5-1 <[email protected]> 
Co-Authored By: @Toqozz <[email protected]>
Co-Authored By: @nicopap <[email protected]>

---------

Co-authored-by: Robert Swain <[email protected]>
Co-authored-by: IceSentry <[email protected]>
Co-authored-by: Carter Anderson <[email protected]>
@superdump
Copy link
Contributor Author

@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? :)

@tim-blackbird
Copy link
Contributor

tim-blackbird commented Nov 5, 2023

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.

@bas-ie
Copy link
Contributor

bas-ie commented Oct 5, 2024

Backlog cleanup: lack of activity, also note cart's #6529 as a partial alternative.

@bas-ie bas-ie closed this Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants