mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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
a3a7376034
commit
520a09a083
2 changed files with 8 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
use bevy_asset::{Asset, Handle};
|
||||
use bevy_reflect::TypePath;
|
||||
use bevy_reflect::{impl_type_path, Reflect};
|
||||
use bevy_render::{
|
||||
mesh::MeshVertexBufferLayout,
|
||||
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
|
||||
/// present, so the `pbr_fragment` shader functions can be called from the extension shader (see
|
||||
/// the `extended_material` example).
|
||||
#[derive(Asset, Clone, TypePath)]
|
||||
#[derive(Asset, Clone, Reflect)]
|
||||
#[reflect(type_path = false)]
|
||||
pub struct ExtendedMaterial<B: Material, E: MaterialExtension> {
|
||||
pub base: B,
|
||||
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> {
|
||||
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.
|
||||
|
||||
use bevy::reflect::TypePath;
|
||||
use bevy::{
|
||||
pbr::{ExtendedMaterial, MaterialExtension, OpaqueRendererMethod},
|
||||
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 {
|
||||
// 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.
|
||||
|
|
Loading…
Reference in a new issue