Jondolf / avian

ECS-driven 2D and 3D physics engine for the Bevy game engine.
https://crates.io/crates/avian3d
Apache License 2.0
1.4k stars 112 forks source link

Allow not overwriting entity visibility with debug renderer #470

Open Dentosal opened 2 months ago

Dentosal commented 2 months ago

Objective

Currently PhysicsDebugPlugin always overwrites Visibility component of the entity with Collider. This is sometimes undesirable, as I want to have entities whose visibilty is part of the game logic.

Solution

This PR allows the debug renderer to instead not overwrite the visibilty when configured to do so. The PR also changes the default value to not overwrite, as it always forced colliders to be visibile before.

Alternatives

An Option<Visibility> could be used instead of an enum, but I hope this version is more readable. We could also just not change visibility if hide_meshes is set to false, but this would unexpectedly affect visibility if this is toggled.


Changelog

This section is optional. If this was a trivial fix, or has no externally-visible impact, you can delete this section.

Migration Guide

The hide_meshes: bool field of PhysicsGizmos (global) and DebugRender (entity) has been replaced with mesh_visibility: MeshVisibility. The old value false should be MeshVisibility::Overwrite(Visibility::Visible), and true should be MeshVisibility::Overwrite(Visibility::Hidden).

The debug renderer no longer forces entities with Collider to be visible by default To restore old behavior, we have to set the mesh_visibility field to one of the variants described above.