2023-09-29 17:00:33 +00:00
|
|
|
use crate::{Texture, ResHandle};
|
|
|
|
|
|
|
|
/// PBR metallic roughness
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct PbrRoughness {
|
|
|
|
/// The rgba base color of the PBR material
|
|
|
|
pub base_color: [f32; 4],
|
|
|
|
/// The metalness of the material
|
|
|
|
/// From 0.0 (non-metal) to 1.0 (metal)
|
|
|
|
pub metallic: f32,
|
|
|
|
/// The roughness of the material
|
|
|
|
/// From 0.0 (smooth) to 1.0 (rough)
|
|
|
|
pub roughness: f32,
|
|
|
|
// TODO: base_color_texture and metallic_roughness_texture
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<gltf::material::PbrMetallicRoughness<'_>> for PbrRoughness {
|
|
|
|
fn from(value: gltf::material::PbrMetallicRoughness) -> Self {
|
|
|
|
PbrRoughness {
|
|
|
|
base_color: value.base_color_factor(),
|
|
|
|
metallic: value.metallic_factor(),
|
|
|
|
roughness: value.roughness_factor(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct PbrGlossiness {
|
|
|
|
/// The rgba diffuse color of the material
|
|
|
|
pub diffuse_color: [f32; 4],
|
|
|
|
// The base color texture
|
|
|
|
// pub diffuse_texture // TODO
|
|
|
|
pub specular: [f32; 3],
|
|
|
|
/// The glossiness factor of the material.
|
|
|
|
/// From 0.0 (no glossiness) to 1.0 (full glossiness)
|
|
|
|
pub glossiness: f32,
|
|
|
|
// pub glossiness_texture // TODO
|
|
|
|
}
|
|
|
|
|
2023-09-29 18:20:28 +00:00
|
|
|
impl From<gltf::material::PbrSpecularGlossiness<'_>> for PbrGlossiness {
|
|
|
|
fn from(value: gltf::material::PbrSpecularGlossiness) -> Self {
|
|
|
|
PbrGlossiness {
|
|
|
|
diffuse_color: value.diffuse_factor(),
|
|
|
|
specular: value.specular_factor(),
|
|
|
|
glossiness: value.glossiness_factor()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-29 17:00:33 +00:00
|
|
|
#[derive(Clone, Default)]
|
|
|
|
pub struct Material {
|
|
|
|
pub shader_uuid: Option<u64>,
|
|
|
|
pub name: Option<String>,
|
|
|
|
pub double_sided: bool,
|
|
|
|
pub pbr_roughness: PbrRoughness,
|
|
|
|
pub pbr_glossiness: Option<PbrGlossiness>,
|
|
|
|
pub alpha_cutoff: Option<f32>,
|
|
|
|
pub alpha_mode: gltf::material::AlphaMode,
|
|
|
|
|
|
|
|
pub texture: Option<ResHandle<Texture>>,
|
2023-09-29 18:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<gltf::Material<'_>> for Material {
|
|
|
|
fn from(value: gltf::Material) -> Self {
|
|
|
|
Material {
|
|
|
|
name: value.name()
|
|
|
|
.map(|s| s.to_string()),
|
|
|
|
double_sided: value.double_sided(),
|
|
|
|
pbr_roughness: value.pbr_metallic_roughness().into(),
|
|
|
|
pbr_glossiness: value.pbr_specular_glossiness()
|
|
|
|
.map(|o| o.into()),
|
|
|
|
alpha_cutoff: value.alpha_cutoff(),
|
|
|
|
alpha_mode: value.alpha_mode(),
|
|
|
|
shader_uuid: None,
|
|
|
|
texture: None,
|
|
|
|
}
|
|
|
|
}
|
2023-09-29 17:00:33 +00:00
|
|
|
}
|