use bevy_pbr::prelude::StandardMaterial;
use bevy_render::color::Color;
use blend::runtime::Instance;
use crate::BevyBlenderError;
#[macro_export]
macro_rules! blender_material {
($blend_file:literal, $material_name:literal) => {
format!("{}#MA{}", $blend_file, $material_name).as_str()
};
}
pub(crate) fn instance_to_material(
instance: Instance,
_blend_version: (u8, u8, u8),
) -> anyhow::Result<StandardMaterial> {
if instance.type_name != "Material" {
return Err(anyhow::Error::new(BevyBlenderError::InvalidInstanceType {
expected: String::from("Material"),
found: instance.type_name,
}));
}
if (instance.get_char("use_nodes") as u8) == 0 {
return Ok(StandardMaterial {
base_color: Color::rgba(
instance.get_f32("r"),
instance.get_f32("g"),
instance.get_f32("b"),
instance.get_f32("a"),
),
perceptual_roughness: instance.get_f32("roughness"),
metallic: instance.get_f32("metallic"),
reflectance: instance.get_f32("spec"),
..Default::default()
});
}
Err(anyhow::Error::new(BevyBlenderError::UnsupportedAsset {
asset_type: String::from("Nodes based material"),
}))
}