use std::collections::HashMap;
use crate::scene::TextureId;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TextureRef {
pub texture: TextureId,
pub uv_set: u32,
}
impl TextureRef {
pub fn new(texture: TextureId) -> Self {
Self { texture, uv_set: 0 }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub enum AlphaMode {
#[default]
Opaque,
Mask { cutoff: f32 },
Blend,
}
#[derive(Clone, Debug)]
pub struct Material {
pub name: Option<String>,
pub base_color: [f32; 4],
pub base_color_texture: Option<TextureRef>,
pub metallic: f32,
pub roughness: f32,
pub metallic_roughness_texture: Option<TextureRef>,
pub normal_texture: Option<TextureRef>,
pub normal_scale: f32,
pub occlusion_texture: Option<TextureRef>,
pub occlusion_strength: f32,
pub emissive_factor: [f32; 3],
pub emissive_texture: Option<TextureRef>,
pub alpha_mode: AlphaMode,
pub double_sided: bool,
pub extras: HashMap<String, serde_json::Value>,
}
impl Material {
pub fn new() -> Self {
Self {
name: None,
base_color: [1.0, 1.0, 1.0, 1.0],
base_color_texture: None,
metallic: 1.0,
roughness: 1.0,
metallic_roughness_texture: None,
normal_texture: None,
normal_scale: 1.0,
occlusion_texture: None,
occlusion_strength: 1.0,
emissive_factor: [0.0, 0.0, 0.0],
emissive_texture: None,
alpha_mode: AlphaMode::Opaque,
double_sided: false,
extras: HashMap::new(),
}
}
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
pub fn with_base_color(mut self, rgba: [f32; 4]) -> Self {
self.base_color = rgba;
self
}
}
impl Default for Material {
fn default() -> Self {
Self::new()
}
}