use bevy::{prelude::*, sprite::Anchor};
#[derive(Component, Debug, Reflect)]
#[require(Transform, Visibility)]
#[reflect(Component, Debug)]
pub struct Sprite3d {
pub image: Handle<Image>,
pub texture_atlas: Option<TextureAtlas>,
pub color: Color,
pub flip_x: bool,
pub flip_y: bool,
pub custom_size: Option<Vec2>,
pub anchor: Anchor,
pub alpha_mode: AlphaMode,
pub unlit: bool,
pub emissive: LinearRgba,
pub double_sided: bool,
}
impl Default for Sprite3d {
fn default() -> Self {
Self {
image: default(),
texture_atlas: default(),
color: default(),
flip_x: default(),
flip_y: default(),
custom_size: default(),
anchor: default(),
alpha_mode: AlphaMode::Mask(0.5),
unlit: true,
emissive: Color::BLACK.into(),
double_sided: false,
}
}
}
impl Sprite3d {
pub fn from_image(image: Handle<Image>) -> Self {
Self { image, ..default() }
}
pub fn from_atlas_image(image: Handle<Image>, atlas: TextureAtlas) -> Self {
Self {
image,
texture_atlas: Some(atlas),
..default()
}
}
pub fn with_alpha_mode(mut self, alpha_mode: AlphaMode) -> Self {
self.alpha_mode = alpha_mode;
self
}
pub fn with_unlit(mut self, unlit: bool) -> Self {
self.unlit = unlit;
self
}
pub fn with_emissive(mut self, emissive: LinearRgba) -> Self {
self.emissive = emissive;
self
}
pub fn with_color(mut self, color: impl Into<Color>) -> Self {
self.color = color.into();
self
}
pub fn with_flip(mut self, x: bool, y: bool) -> Self {
self.flip_x = x;
self.flip_y = y;
self
}
pub fn with_custom_size(mut self, size: impl Into<Vec2>) -> Self {
self.custom_size = Some(size.into());
self
}
pub fn with_anchor(mut self, anchor: impl Into<Anchor>) -> Self {
self.anchor = anchor.into();
self
}
pub fn with_double_sided(mut self, ds: bool) -> Self {
self.double_sided = ds;
self
}
}