//! Serializable material asset files under `assets/materials/`. use serde::{Deserialize, Serialize}; use crate::{MaterialDesc, MaterialParameter, MaterialShaderKind, MaterialTextureBinding}; /// RON material asset: label plus authoring [`MaterialDesc`]. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MaterialAsset { pub label: String, #[serde(default)] pub shader: Option, pub material: MaterialDesc, } impl MaterialAsset { pub fn load_from_path(catalog_path: &str) -> Result { let text = std::fs::read_to_string(catalog_path) .map_err(|err| format!("could not read {catalog_path}: {err}"))?; ron::from_str(&text).map_err(|err| format!("invalid material RON in {catalog_path}: {err}")) } } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub enum ShaderPropertyType { Bool, Float { min: Option, max: Option }, Vec2, Vec3, Color, Enum { options: Vec }, Texture, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ShaderPropertyDesc { pub name: String, pub display_name: String, #[serde(default)] pub group: String, pub property_type: ShaderPropertyType, } /// RON shader schema describing material inspector parameters. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct ShaderSchemaAsset { pub label: String, pub kind: MaterialShaderKind, #[serde(default)] pub wgsl_path: Option, #[serde(default)] pub parameters: Vec, #[serde(default)] pub default_values: Vec, #[serde(default)] pub default_textures: Vec, } impl ShaderSchemaAsset { pub fn load_from_path(catalog_path: &str) -> Result { let text = std::fs::read_to_string(catalog_path) .map_err(|err| format!("could not read {catalog_path}: {err}"))?; ron::from_str(&text) .map_err(|err| format!("invalid shader schema RON in {catalog_path}: {err}")) } }