jcornaz / heron

[DISCONTINUED] An ergonomic physics API for bevy games
MIT License
292 stars 44 forks source link

Add 3d debugging facility #151

Closed nicopap closed 3 years ago

nicopap commented 3 years ago

Add the "debug-3d" cargo feature. When enabled, we draw the approximate shape of the physics object. The user can chose to toggle "see-through" mode to draw the physics object boundaries in front of everything or with occlusion.

I say "approximate shape" because:

  1. Cuboid with radius are draw as cuboids with a bevel
  2. ConvexHull with radius will be drawn as not having any radius

To enable see-through, add the DebugLines resource re-exported in heron_debug, setting the depth_test field as specified in (1)

(1) https://github.com/Toqozz/bevy_debug_lines

Note on the implementation:

The bevy wireframe render mode (2) could replace some of the shape drawing functions. I didn't use it because I learned about it after completing the implementation. But I think it makes sense to not mix usage of wireframe mode and debug-lines.

We expose the bevy_debug_lines DebugLines struct in the API, which means we are tightly bound to it, and it would be a breaking change to switch backend for the 3d debug rendering. This is important to consider, event if this is only for debugging. What could be the alternative?

(2) https://docs.rs/bevy/0.5.0/bevy/render/wireframe/index.html

nicopap commented 3 years ago

The error is caused by a clippy flag. I notice the clippy warnings only show up when running with cargo clippy --workspace --all-features, in fact there is a lot of already existing unfixed clippy lints in the code. I opted to not fix them to restrict the scope of the PR strictly to the debug change. I'll remove the clippy flag and it should be alright.

nicopap commented 3 years ago

A few things I need to clear up:

  1. The height maps wireframes are not accurate in the corners in certain situations
  2. I want to support #141
  3. I actually didn't test if the depth occlusion toggle works (my bad here)
  4. If you need to add any new shape, feel free to ping me, I'll be happy to contribute
jcornaz commented 3 years ago

Cool. Thank you very much for your help :-)

jcornaz commented 3 years ago

I converted the PR to draft. You can mark it "Ready for review" when you are done working on it ;-)

nicopap commented 3 years ago

Ok, I gave up on the depth_test toggle. I still think it's useful but it's not ergonomic enough to add it yet. The issue is that you currently must specify it before initializing DebugLinesPlugin, this is a limitation of the bevy_debug_lines library.

I refactored the code, now the rounded corners on the cuboids display as rounded corners rather than bevel.

I also fixed the issue with the height maps, turns out its more a series of triangles than a series of squares.

I'll work on pulling edgarssilva's changes tomorrow. And it will be good to go.