use crate::prelude::LightIntensity;
use bevy_color::Color;
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*;
use bevy_math::Vec2;
use bevy_reflect::Reflect;
#[derive(Component, Clone, Debug, Reflect, Default)]
#[reflect(Component, Clone, Debug)]
#[require(Roughness, Metallic, Reflectance)]
pub struct StandardPbr;
#[derive(Component, Clone, Debug, Reflect, Deref, DerefMut)]
#[reflect(Component, Clone, Debug)]
pub struct Roughness(pub f32);
impl Default for Roughness {
fn default() -> Self {
Self(0.5)
}
}
#[derive(Component, Clone, Default, Debug, Reflect, Deref, DerefMut)]
#[reflect(Component, Clone, Debug)]
pub struct Metallic(pub f32);
#[derive(Component, Clone, Debug, Reflect, Deref, DerefMut)]
#[reflect(Component, Clone, Debug)]
pub struct Reflectance(pub f32);
impl Default for Reflectance {
fn default() -> Self {
Self(0.1)
}
}
#[derive(Component, Clone, Debug, Reflect, Deref, DerefMut)]
#[reflect(Component, Clone, Debug)]
pub struct SpecularPower(pub f32);
impl Default for SpecularPower {
fn default() -> Self {
Self(32.0)
}
}
#[derive(Component, Clone, Debug, Reflect, Default)]
#[reflect(Component, Clone, Debug)]
pub struct AmbientOcclusion;
#[derive(Component, Clone, Debug, Reflect, Deref, DerefMut)]
#[reflect(Component, Clone, Debug)]
pub struct SpecularStrength(pub f32);
impl Default for SpecularStrength {
fn default() -> Self {
Self(0.1)
}
}
#[derive(Component, Clone, Debug, Reflect, Deref, DerefMut)]
#[reflect(Component, Clone, Debug)]
pub struct DiffuseScaling(pub f32);
impl Default for DiffuseScaling {
fn default() -> Self {
Self(1.0)
}
}
#[derive(Component, Clone, Debug, Reflect, Deref, DerefMut)]
#[reflect(Component, Clone, Debug)]
pub struct AmbientLightIntensity(pub f32);
impl Default for AmbientLightIntensity {
fn default() -> Self {
Self(0.0001)
}
}
#[derive(Component, Clone, Debug, Reflect, Deref, DerefMut)]
#[reflect(Component, Clone, Debug)]
pub struct Translucency(pub f32);
impl Default for Translucency {
fn default() -> Self {
Self(0.6)
}
}
#[derive(Component, Clone, Debug, Reflect, Default)]
#[reflect(Component, Clone, Debug)]
#[require(
Translucency,
SpecularPower,
SpecularStrength,
DiffuseScaling,
LightIntensity(0.0001),
AmbientLightIntensity(0.0001)
)]
pub struct DirectionalLights;
#[derive(Component, Clone, Debug, Reflect, Default)]
#[reflect(Component, Clone, Debug)]
#[require(
Translucency,
SpecularPower,
SpecularStrength,
DiffuseScaling,
LightIntensity(0.0001),
AmbientLightIntensity(0.0001)
)]
pub struct PointLights;
#[derive(Component, Clone, Copy, Debug, Reflect, Default)]
#[reflect(Component, Clone, Debug)]
#[require(CurveFactor)]
pub struct CurveNormals;
#[derive(Component, Deref, DerefMut, Clone, Copy, Debug, Reflect)]
#[reflect(Component, Clone, Debug)]
pub struct CurveFactor(pub f32);
impl Default for CurveFactor {
fn default() -> Self {
Self(0.2)
}
}
#[derive(Component, Clone, Copy, Debug, Reflect, Default)]
#[reflect(Component, Clone, Debug)]
#[require(StaticBendStrength)]
pub struct StaticBend;
#[derive(Component, Deref, DerefMut, Clone, Copy, Debug, Reflect)]
#[reflect(Component, Clone, Debug)]
#[require(StaticBendDirection, StaticBendControlPoint, StaticBendMinMax)]
pub struct StaticBendStrength(pub f32);
impl Default for StaticBendStrength {
fn default() -> Self {
Self(0.5)
}
}
#[derive(Component, Clone, Copy, Debug, Reflect)]
#[reflect(Component, Clone, Debug)]
pub struct StaticBendMinMax {
min: f32,
max: f32,
}
impl StaticBendMinMax {
pub fn new(min: f32, max: f32) -> Self {
Self { min, max }
}
}
impl From<StaticBendMinMax> for Vec2 {
fn from(val: StaticBendMinMax) -> Self {
Vec2::new(val.min, val.max)
}
}
impl From<Vec2> for StaticBendMinMax {
fn from(vec: Vec2) -> Self {
Self {
min: vec.x,
max: vec.y,
}
}
}
impl Default for StaticBendMinMax {
fn default() -> Self {
Self { min: 0.2, max: 0.7 }
}
}
#[derive(Component, Deref, DerefMut, Clone, Copy, Debug, Reflect)]
#[reflect(Component, Clone, Debug)]
pub struct StaticBendDirection(pub Vec2);
impl Default for StaticBendDirection {
fn default() -> Self {
Self(Vec2::new(0.309017, -0.951056))
}
}
impl StaticBendDirection {
pub fn new(x: f32, y: f32) -> Self {
Self(Vec2::new(x, y))
}
}
#[derive(Component, Clone, Copy, Debug, Reflect)]
#[reflect(Component, Clone, Debug)]
pub struct StaticBendControlPoint {
pub stiffness: f32,
pub height: f32,
}
impl Default for StaticBendControlPoint {
fn default() -> Self {
Self::new(0.33, 0.55)
}
}
impl StaticBendControlPoint {
pub fn new(stiffness: f32, height: f32) -> Self {
Self { stiffness, height }
}
}
impl From<Vec2> for StaticBendControlPoint {
fn from(value: Vec2) -> Self {
Self::new(value.x, value.y)
}
}
impl From<StaticBendControlPoint> for Vec2 {
fn from(val: StaticBendControlPoint) -> Self {
Vec2::new(val.stiffness, val.height)
}
}
#[derive(Component, Clone, Copy, Debug, Reflect, Default)]
#[reflect(Component, Clone, Debug)]
pub struct InstanceColorGradient {
pub top: Color,
pub bottom: Color,
pub tint: f32,
pub start: f32,
pub end: f32,
}
impl InstanceColorGradient {
pub fn new(top: impl Into<Color>, bottom: impl Into<Color>) -> Self {
Self {
top: top.into(),
bottom: bottom.into(),
tint: 0.5,
start: 0.2,
end: 0.8,
}
}
}