bevy/examples/shader
Torstein Grindvik 174819be83 ExtractComponent output optional associated type (#6699)
# Objective

Allow more use cases where the user may benefit from both `ExtractComponentPlugin` _and_ `UniformComponentPlugin`.

## Solution

Add an associated type to `ExtractComponent` in order to allow specifying the output component (or bundle).

Make `extract_component` return an `Option<_>` such that components can be extracted only when needed.

What problem does this solve?

`ExtractComponentPlugin` allows extracting components, but currently the output type is the same as the input.
This means that use cases such as having a settings struct which turns into a uniform is awkward.

For example we might have:

```rust
struct MyStruct {
    enabled: bool,
    val: f32
}

struct MyStructUniform {
    val: f32
}
```

With the new approach, we can extract `MyStruct` only when it is enabled, and turn it into its related uniform.

This chains well with `UniformComponentPlugin`.

The user may then:

```rust
app.add_plugin(ExtractComponentPlugin::<MyStruct>::default());
app.add_plugin(UniformComponentPlugin::<MyStructUniform>::default());
```

This then saves the user a fair amount of boilerplate.


## Changelog

### Changed

- `ExtractComponent` can specify output type, and outputting is optional.



Co-authored-by: Torstein Grindvik <52322338+torsteingrindvik@users.noreply.github.com>
2022-11-21 13:19:44 +00:00
..
animate_shader.rs add globals to mesh view bind group (#5409) 2022-09-28 04:20:27 +00:00
array_texture.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
compute_shader_game_of_life.rs Plugins own their settings. Rework PluginGroup trait. (#6336) 2022-10-24 21:20:33 +00:00
custom_vertex_attribute.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
post_processing.rs Update post_processing example to not render UI with first pass camera (#6469) 2022-11-14 22:34:26 +00:00
shader_defs.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
shader_instancing.rs ExtractComponent output optional associated type (#6699) 2022-11-21 13:19:44 +00:00
shader_material.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
shader_material_glsl.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
shader_material_screenspace_texture.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00