11use bevy:: { prelude:: * , render:: alpha:: AlphaMode } ;
22use std:: ops:: Deref ;
33
4+ /// A component that holds an untyped handle to a material. This allows the main render loop
5+ /// to be agnostic of the specific material types being used, and allows for dynamic material
6+ /// creation based on the `MaterialKey`.
47#[ derive( Component , Deref ) ]
58pub struct UntypedMaterial ( pub UntypedHandle ) ;
69
@@ -10,6 +13,8 @@ pub enum MaterialSource {
1013 Explicit ( Entity ) ,
1114}
1215
16+ /// Defines the current material for a batch, which can be used to determine when to flush the
17+ /// current batch and start a new one.
1318#[ derive( Clone , PartialEq , Eq , Hash , Debug ) ]
1419pub enum MaterialKey {
1520 Color {
@@ -26,20 +31,6 @@ pub enum MaterialKey {
2631}
2732
2833impl MaterialKey {
29- pub fn simple_2d ( transparent : bool ) -> Self {
30- Self :: Color {
31- transparent,
32- background_image : None ,
33- }
34- }
35-
36- pub fn with_image ( image : Handle < Image > , transparent : bool ) -> Self {
37- Self :: Color {
38- transparent,
39- background_image : Some ( image) ,
40- }
41- }
42-
4334 pub fn to_material ( & self , materials : & mut ResMut < Assets < StandardMaterial > > ) -> UntypedHandle {
4435 match self {
4536 MaterialKey :: Color {
@@ -95,6 +86,8 @@ impl MaterialKey {
9586 }
9687}
9788
89+ /// A system that adds a `MeshMaterial3d` component to any entity with an `UntypedMaterial` that can
90+ /// be typed as a `StandardMaterial`.
9891pub fn add_standard_materials (
9992 mut commands : Commands ,
10093 meshes : Query < ( Entity , & UntypedMaterial ) > ,
0 commit comments