bevy/examples/3d
Kristoffer Søholm 2d1b4939d2
Synchronize removed components with the render world (#15582)
# Objective

Fixes #15560
Fixes (most of) #15570

Currently a lot of examples (and presumably some user code) depend on
toggling certain render features by adding/removing a single component
to an entity, e.g. `SpotLight` to toggle a light. Because of the
retained render world this no longer works: Extract will add any new
components, but when it is removed the entity persists unchanged in the
render world.

## Solution

Add `SyncComponentPlugin<C: Component>` that registers
`SyncToRenderWorld` as a required component for `C`, and adds a
component hook that will clear all components from the render world
entity when `C` is removed. We add this plugin to
`ExtractComponentPlugin` which fixes most instances of the problem. For
custom extraction logic we can manually add `SyncComponentPlugin` for
that component.

We also rename `WorldSyncPlugin` to `SyncWorldPlugin` so we start a
naming convention like all the `Extract` plugins.

In this PR I also fixed a bunch of breakage related to the retained
render world, stemming from old code that assumed that `Entity` would be
the same in both worlds.

I found that using the `RenderEntity` wrapper instead of `Entity` in
data structures when referring to render world entities makes intent
much clearer, so I propose we make this an official pattern.

## Testing

Run examples like

```
cargo run --features pbr_multi_layer_material_textures --example clearcoat
cargo run --example volumetric_fog
```

and see that they work, and that toggles work correctly. But really we
should test every single example, as we might not even have caught all
the breakage yet.

---

## Migration Guide

The retained render world notes should be updated to explain this edge
case and `SyncComponentPlugin`

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Trashtalk217 <trashtalk217@gmail.com>
2024-10-08 22:23:17 +00:00
..
3d_scene.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
3d_shapes.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
3d_viewport_to_world.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
animated_material.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
anisotropy.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
anti_aliasing.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
atmospheric_fog.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
auto_exposure.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
blend_modes.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
bloom_3d.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
camera_sub_view.rs improve sub view example with dynamic viewports (#15681) 2024-10-08 16:07:31 +00:00
clearcoat.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
color_grading.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
deferred_rendering.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
depth_of_field.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
fog.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
fog_volumes.rs Synchronize removed components with the render world (#15582) 2024-10-08 22:23:17 +00:00
generate_custom_mesh.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
irradiance_volumes.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
lighting.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
lightmaps.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
lines.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
load_gltf.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
load_gltf_extras.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
meshlet.rs Per-meshlet compressed vertex data (#15643) 2024-10-08 18:42:55 +00:00
motion_blur.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
order_independent_transparency.rs Add Order Independent Transparency (#14876) 2024-10-07 23:50:28 +00:00
orthographic.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
parallax_mapping.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
parenting.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
pbr.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
pcss.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
post_processing.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
query_gltf_primitives.rs Fix query_gltf_primitives example (#15715) 2024-10-07 23:03:16 +00:00
reflection_probes.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
render_to_texture.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
rotate_environment_map.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
scrolling_fog.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
shadow_biases.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
shadow_caster_receiver.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
skybox.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
spherical_area_lights.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
split_screen.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
spotlight.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ssao.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ssr.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
texture.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
tonemapping.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
transmission.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
transparency_3d.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
two_passes.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
update_gltf_scene.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
vertex_colors.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
visibility_range.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
volumetric_fog.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
wireframe.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00