use source_vmt::Vmt;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct PbrSettings {
#[serde(rename = "$metalness")]
metalness: f32,
#[serde(rename = "$roughness")]
roughness: f32,
#[serde(rename = "$ao")]
ambient_occlusion: f32,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct ReplaceSettings {
#[serde(rename = "$phongboost")]
boost: f32,
#[serde(rename = "$phongexponent")]
exponent: i32,
#[serde(rename = "$phongfresnelranges")]
fresnel_ranges: String,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== set_block Example: Creating Materials with Structured Blocks ===\n");
println!("--- Example 1: Creating PBR Material ---");
let mut pbr_material = Vmt::new("PBR");
pbr_material.set_string("$basetexture", "materials/metal/steel_plate");
let pbr_settings = PbrSettings {
metalness: 0.9,
roughness: 0.3,
ambient_occlusion: 1.0,
};
pbr_material.set_block("pbr_settings", &pbr_settings)?;
println!("Created PBR material:");
println!("{}", pbr_material.to_string()?);
let retrieved_pbr: PbrSettings = pbr_material.get_block("pbr_settings")?.unwrap();
println!("Retrieved PBR settings: metalness={}, roughness={}, ao={}\n",
retrieved_pbr.metalness, retrieved_pbr.roughness, retrieved_pbr.ambient_occlusion);
println!("--- Example 2: Patch with set_block ---");
let mut patch_material = Vmt::new("Patch");
patch_material.set_string("include", "materials/base_material.vmt");
let patch_phong = ReplaceSettings {
boost: 3.0,
exponent: 50,
fresnel_ranges: "[1.0 2.0 3.0]".to_string(),
};
patch_material.set_block("replace", &patch_phong)?;
println!("Patch material:");
println!("{}", patch_material.to_string()?);
Ok(())
}