bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Allow overriding global wireframe setting.

Open Wcubed opened this issue 2 years ago • 5 comments

Objective

Allow the user to choose between "Add wireframes to these specific entities" or "Add wireframes to everything except these specific entities". Fixes #7309

Solution

Make the Wireframe component act like an override to the global configuration. Having global set to false, and adding a Wireframe with enable: true acts exactly as before. But now the opposite is also possible: Set global to false and add a Wireframe with enable: false will draw wireframes for everything except that entity.

Updated the example to show how overriding the global config works.

Wcubed avatar Jan 22 '23 12:01 Wcubed

Setting wireframe.enable = true to disable displaying wireframes feels wrong to me.

I'd suggest changing the local per-entity Wireframe "policy" to be more explicit (bikeshed the names of the enum variants):

/// Local per-entity wireframe config.
// ... attributes ...
pub enum Wireframe { // or `WireframePolicy` or `LocalWireframeConfig` as a field of `struct Wireframe`
    /// Follow the global config, for example if `WireframeConfig { global: true }`, this entity will show a wireframe, but if `WireframeConfig { global: false }`, this entity won't show a wireframe
    UseGlobalConfig,
    /// Use the opposite of the global config, for example if `WireframeConfig { global: true }`, this entity won't show a wireframe, but if `WireframeConfig { global: false }`, this entity will show a wireframe
    InvertGlobalConfig,
    /// Ignore the global config, and show a wireframe
    Always,
    /// Ignore the global config, and don't show the wireframe
    Never,
}

These first two *GlobalConfig variants correspond to your Wireframe { enable: bool }.

These additional variants Always and Never means that for specific entities, you can know for certain that a specific entity shows or does not show a wireframe, without querying the WireframeConfig.

tigregalis avatar Jan 25 '23 01:01 tigregalis

@tigregalis I think you misunderstood. It was wireframe.enable = false that would make it never show the wireframe, regardless of global config. Which did show to me that my implementation was probably not as clear as it could be 😃.

I changed the wireframe component to WireframeOverride::AlwaysRender and WireframeOverride::NeverRender, to make it clear that it will make the mesh not care about the global config.

Wcubed avatar Jan 26 '23 19:01 Wcubed

I've had a play with this and the new API makes sense to me. I've extended the example to show what toggling the global config does for entities with different local wireframe configs (red = never, yellow = no component, green = always); is this updated example something we want?

https://user-images.githubusercontent.com/38416468/215453389-c56b9dd1-bc80-4617-9c76-96cfbeac2678.mp4

tigregalis avatar Jan 30 '23 10:01 tigregalis

I like it. I hadn't even thought of doing that. Makes it very clear what effects each option has.

Wcubed avatar Jan 30 '23 15:01 Wcubed

Example alien_cake_addict failed to run, please try running it locally and check the result.

github-actions[bot] avatar Jan 31 '23 09:01 github-actions[bot]

I'm not sure if I like the new name WireframeOverride. Maybe keep the original Wireframe name? It shorter and still makes sense since it works regardless of global config.

Good point. The AlwaysRender and NeverRender names already indicate it is an override, so the additional Override in the name is redundant 👍

Wcubed avatar Mar 31 '23 19:03 Wcubed

Brought up to date with 0.11, and fixed typo pointed out by shatur

Wcubed avatar Jul 15 '23 15:07 Wcubed

@Wcubed could you resolve conflicts?

Shatur avatar Sep 30 '23 14:09 Shatur

So, I wasn't aware of this PR and I think the merged api should have been different. I'd like to suggest it here first to see what people think and see if there's agreement.

I believe the api should have used 2 separate components Wireframe and NoWireframe (or maybe NoGlobalWireframe, NeverRenderWireframe, naming isn't really the point)

I think this is better for a few reasons:

  • Easier to migrate since it doesn't change the old behaviour. Essentially nothing to migrate. Right now this PR is a breaking change but I don't think it has to be.
  • It's similar to other "per mesh" rendering features like NotShadowCaster/NotShadowReceiver
  • It doesn't force new users to also think about global vs not global if all they want is to render a wireframe
  • This would also let you filter at the query definition level instead of filtering when running the query

IceSentry avatar Oct 04 '23 05:10 IceSentry

If we decide to keep this api, please consider adding a migration guide section to the PR description.

IceSentry avatar Oct 04 '23 05:10 IceSentry

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy? It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

github-actions[bot] avatar Oct 04 '23 05:10 github-actions[bot]

it seems this PR broke rendering wireframes on windows / DX12 4a70c28683d006612a308b440640b77d41660816281512fad182519013d51071

mockersf avatar Oct 04 '23 07:10 mockersf

I don't think this was caused by this PR. It's also broken when using DX12 on the commit before this PR. The issue seems to be be with the DX12 backend.

Here's a screenshot from before this PR image

IceSentry avatar Oct 04 '23 15:10 IceSentry

@IceSentry two PRs that were merged at the same time, this one and #9895. I assumed wireframe being broken was due to the PR changing wireframes. It worked before those two, could you check the commit before (375af64e8cd0c9a1a64b88738d2d253aa9929d5a)?

mockersf avatar Oct 04 '23 16:10 mockersf

I went back to https://github.com/bevyengine/bevy/pull/9796 and it's still broken when using DX12 for me.

Back to f69e923c270fbc7eb57cc4424aa16b8802af3dd2 and it still doesn't work correctly.

IceSentry avatar Oct 04 '23 16:10 IceSentry

I created this PR with my proposed changes to make the API non breaking while keeping the override feature https://github.com/bevyengine/bevy/pull/10023

IceSentry avatar Oct 04 '23 18:10 IceSentry