Ensure ExtendedMaterial works with reflection (to enable bevy_egui_inspector integration) (#10548)
# Objective - Ensure ExtendedMaterial can be referenced in bevy_egui_inspector correctly ## Solution Add a more manual `TypePath` implementation to work around bugs in the derive macro.
This commit is contained in:
parent
782f1863b9
commit
bad55c1ad8
@ -1,5 +1,5 @@
|
|||||||
use bevy_asset::{Asset, Handle};
|
use bevy_asset::{Asset, Handle};
|
||||||
use bevy_reflect::TypePath;
|
use bevy_reflect::{impl_type_path, Reflect};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
mesh::MeshVertexBufferLayout,
|
mesh::MeshVertexBufferLayout,
|
||||||
render_asset::RenderAssets,
|
render_asset::RenderAssets,
|
||||||
@ -97,12 +97,17 @@ pub trait MaterialExtension: Asset + AsBindGroup + Clone + Sized {
|
|||||||
/// When used with `StandardMaterial` as the base, all the standard material fields are
|
/// When used with `StandardMaterial` as the base, all the standard material fields are
|
||||||
/// present, so the `pbr_fragment` shader functions can be called from the extension shader (see
|
/// present, so the `pbr_fragment` shader functions can be called from the extension shader (see
|
||||||
/// the `extended_material` example).
|
/// the `extended_material` example).
|
||||||
#[derive(Asset, Clone, TypePath)]
|
#[derive(Asset, Clone, Reflect)]
|
||||||
|
#[reflect(type_path = false)]
|
||||||
pub struct ExtendedMaterial<B: Material, E: MaterialExtension> {
|
pub struct ExtendedMaterial<B: Material, E: MaterialExtension> {
|
||||||
pub base: B,
|
pub base: B,
|
||||||
pub extension: E,
|
pub extension: E,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We don't use the `TypePath` derive here due to a bug where `#[reflect(type_path = false)]`
|
||||||
|
// causes the `TypePath` derive to not generate an implementation.
|
||||||
|
impl_type_path!((in bevy_pbr::extended_material) ExtendedMaterial<B: Material, E: MaterialExtension>);
|
||||||
|
|
||||||
impl<B: Material, E: MaterialExtension> AsBindGroup for ExtendedMaterial<B, E> {
|
impl<B: Material, E: MaterialExtension> AsBindGroup for ExtendedMaterial<B, E> {
|
||||||
type Data = (<B as AsBindGroup>::Data, <E as AsBindGroup>::Data);
|
type Data = (<B as AsBindGroup>::Data, <E as AsBindGroup>::Data);
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
//! Demonstrates using a custom extension to the `StandardMaterial` to modify the results of the builtin pbr shader.
|
//! Demonstrates using a custom extension to the `StandardMaterial` to modify the results of the builtin pbr shader.
|
||||||
|
|
||||||
use bevy::reflect::TypePath;
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
pbr::{ExtendedMaterial, MaterialExtension, OpaqueRendererMethod},
|
pbr::{ExtendedMaterial, MaterialExtension, OpaqueRendererMethod},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
@ -73,7 +72,7 @@ fn rotate_things(mut q: Query<&mut Transform, With<Rotate>>, time: Res<Time>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Asset, AsBindGroup, TypePath, Debug, Clone)]
|
#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)]
|
||||||
struct MyExtension {
|
struct MyExtension {
|
||||||
// We need to ensure that the bindings of the base material and the extension do not conflict,
|
// We need to ensure that the bindings of the base material and the extension do not conflict,
|
||||||
// so we start from binding slot 100, leaving slots 0-99 for the base material.
|
// so we start from binding slot 100, leaving slots 0-99 for the base material.
|
||||||
|
Loading…
Reference in New Issue
Block a user