diff --git a/crates/bevy_pbr/src/bundle.rs b/crates/bevy_pbr/src/bundle.rs index cb4db6e96290d..3a8cd075ab0f7 100644 --- a/crates/bevy_pbr/src/bundle.rs +++ b/crates/bevy_pbr/src/bundle.rs @@ -1,4 +1,4 @@ -use crate::{DirectionalLight, PointLight, StandardMaterial}; +use crate::{DirectionalLight, PointLight, StandardMaterial, DEFAULT_STANDARD_MATERIAL_HANDLE}; use bevy_asset::Handle; use bevy_ecs::{bundle::Bundle, component::Component}; use bevy_render::{ @@ -9,7 +9,7 @@ use bevy_render::{ use bevy_transform::components::{GlobalTransform, Transform}; /// A component bundle for PBR entities with a [`Mesh`] and a [`StandardMaterial`]. -#[derive(Bundle, Clone, Default)] +#[derive(Bundle, Clone)] pub struct PbrBundle { pub mesh: Handle, pub material: Handle, @@ -21,6 +21,19 @@ pub struct PbrBundle { pub computed_visibility: ComputedVisibility, } +impl Default for PbrBundle { + fn default() -> Self { + Self { + mesh: Default::default(), + material: DEFAULT_STANDARD_MATERIAL_HANDLE.typed(), + transform: Default::default(), + global_transform: Default::default(), + visibility: Default::default(), + computed_visibility: Default::default(), + } + } +} + #[derive(Component, Clone, Debug, Default)] pub struct CubemapVisibleEntities { data: [VisibleEntities; 6], diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 1b979c32eb40c..a95df2d4108a3 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -35,6 +35,7 @@ use bevy_core_pipeline::{AlphaMask3d, Opaque3d, Transparent3d}; use bevy_ecs::prelude::*; use bevy_reflect::TypeUuid; use bevy_render::{ + prelude::Color, render_component::ExtractComponentPlugin, render_graph::RenderGraph, render_phase::{sort_phase_system, AddRenderCommand, DrawFunctions}, @@ -122,6 +123,18 @@ impl Plugin for PbrPlugin { .after(VisibilitySystems::CheckVisibility), ); + app.world + .get_resource_mut::>() + .unwrap() + .set_untracked( + DEFAULT_STANDARD_MATERIAL_HANDLE, + StandardMaterial { + base_color: Color::rgb(1.0, 0.0, 0.5), + unlit: true, + ..Default::default() + }, + ); + let render_app = app.sub_app(RenderApp); render_app .add_system_to_stage( diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 7bf96bebd8701..e2a4a23f7c36f 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -1,6 +1,6 @@ use crate::{AlphaMode, PbrPipeline, StandardMaterialFlags}; use bevy_app::{App, Plugin}; -use bevy_asset::{AddAsset, Handle}; +use bevy_asset::{AddAsset, Handle, HandleUntyped}; use bevy_ecs::system::{lifetimeless::SRes, SystemParamItem}; use bevy_math::Vec4; use bevy_reflect::TypeUuid; @@ -14,6 +14,9 @@ use bevy_render::{ use crevice::std140::{AsStd140, Std140}; use wgpu::{BindGroupDescriptor, BindGroupEntry, BindingResource}; +pub const DEFAULT_STANDARD_MATERIAL_HANDLE: HandleUntyped = + HandleUntyped::weak_from_u64(StandardMaterial::TYPE_UUID, 13142262394054731189); + /// A material with "standard" properties used in PBR lighting /// Standard property values with pictures here /// .