bevy/crates/bevy_render/src
davier 06d9384447 Add FromReflect trait to convert dynamic types to concrete types (#1395)
Dynamic types (`DynamicStruct`, `DynamicTupleStruct`, `DynamicTuple`, `DynamicList` and `DynamicMap`) are used when deserializing scenes, but currently they can only be applied to existing concrete types. This leads to issues when trying to spawn non trivial deserialized scene.
For components, the issue is avoided by requiring that reflected components implement ~~`FromResources`~~ `FromWorld` (or `Default`). When spawning, a new concrete type is created that way, and the dynamic type is applied to it. Unfortunately, some components don't have any valid implementation of these traits.
In addition, any `Vec` or `HashMap` inside a component will panic when a dynamic type is pushed into it (for instance, `Text` panics when adding a text section).

To solve this issue, this PR adds the `FromReflect` trait that creates a concrete type from a dynamic type that represent it, derives the trait alongside the `Reflect` trait, drops the ~~`FromResources`~~ `FromWorld` requirement on reflected components, ~~and enables reflection for UI and Text bundles~~. It also adds the requirement that fields ignored with `#[reflect(ignore)]` implement `Default`, since we need to initialize them somehow.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-12-26 18:49:01 +00:00
..
camera make sub_app return an &App and add sub_app_mut() -> &mut App (#3309) 2021-12-24 06:57:30 +00:00
color Add FromReflect trait to convert dynamic types to concrete types (#1395) 2021-12-26 18:49:01 +00:00
mesh Implement non-indexed mesh rendering (#3415) 2021-12-23 19:19:13 +00:00
primitives Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
render_graph Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
render_phase Add some of the missing methods to TrackedRenderPass (#3401) 2021-12-20 23:16:54 +00:00
render_resource re-export BufferBinding and BufferDescriptor (#3429) 2021-12-24 16:53:49 +00:00
renderer enable Webgl2 optimisation in pbr under feature (#3291) 2021-12-22 20:59:48 +00:00
texture make sub_app return an &App and add sub_app_mut() -> &mut App (#3309) 2021-12-24 06:57:30 +00:00
view Add Visibility component to UI (#3426) 2021-12-24 07:10:12 +00:00
lib.rs Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
options.rs Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
render_asset.rs make sub_app return an &App and add sub_app_mut() -> &mut App (#3309) 2021-12-24 06:57:30 +00:00
render_component.rs make sub_app return an &App and add sub_app_mut() -> &mut App (#3309) 2021-12-24 06:57:30 +00:00