use crate::Material; use bevy_asset::{AssetId, Handle}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use derive_more::derive::From; /// A [material](Material) used for rendering a [`Mesh3d`]. /// /// See [`Material`] for general information about 3D materials and how to implement your own materials. /// /// [`Mesh3d`]: bevy_render::mesh::Mesh3d /// /// # Example /// /// ``` /// # use bevy_pbr::{Material, MeshMaterial3d, StandardMaterial}; /// # use bevy_ecs::prelude::*; /// # use bevy_render::mesh::{Mesh, Mesh3d}; /// # use bevy_color::palettes::basic::RED; /// # use bevy_asset::Assets; /// # use bevy_math::primitives::Capsule3d; /// # /// // Spawn an entity with a mesh using `StandardMaterial`. /// fn setup( /// mut commands: Commands, /// mut meshes: ResMut>, /// mut materials: ResMut>, /// ) { /// commands.spawn(( /// Mesh3d(meshes.add(Capsule3d::default())), /// MeshMaterial3d(materials.add(StandardMaterial { /// base_color: RED.into(), /// ..Default::default() /// })), /// )); /// } /// ``` #[derive(Component, Clone, Debug, Deref, DerefMut, Reflect, PartialEq, Eq, From)] #[reflect(Component, Default)] pub struct MeshMaterial3d(pub Handle); impl Default for MeshMaterial3d { fn default() -> Self { Self(Handle::default()) } } impl From> for AssetId { fn from(material: MeshMaterial3d) -> Self { material.id() } } impl From<&MeshMaterial3d> for AssetId { fn from(material: &MeshMaterial3d) -> Self { material.id() } }