From 0e1b9494c2699543584716fc653bce2d415f57c0 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 9 Jan 2024 18:44:57 -0800 Subject: [PATCH] decode vmt and attempt to grab some texture --- src/main.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/main.rs b/src/main.rs index bd67fd4..51e86dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1148,6 +1148,48 @@ fn extract_textures(paths:Vec,vpk_path:std::path::PathBuf)-> let texture_name=texture_name.clone(); thread_handles.push(s.spawn(move||write_image(stuff,texture_name))); } + if let Some(stuff)=find_stuff(texture_file_name2.as_os_str().to_str().unwrap())?{ + println!("woahh its a vmt {:?}",texture_file_name2); + //decode vmt and then write + let stuff=String::from_utf8(stuff)?; + + //just grab some texture from somewhere for now + let vmt=vmt_parser::from_str(stuff.as_str())?; + println!("le vmt {:?}",vmt); + let some_texture=match vmt{ + vmt_parser::material::Material::LightMappedGeneric(mat)=>Some(mat.base_texture), + vmt_parser::material::Material::VertexLitGeneric(mat)=>mat.base_texture.or(mat.decal_texture),//this just dies if there is none + vmt_parser::material::Material::VertexLitGenericDx6(mat)=>mat.base_texture.or(mat.decal_texture), + vmt_parser::material::Material::UnlitGeneric(mat)=>mat.base_texture, + vmt_parser::material::Material::UnlitTwoTexture(mat)=>mat.base_texture, + vmt_parser::material::Material::Water(mat)=>mat.base_texture, + vmt_parser::material::Material::WorldVertexTransition(mat)=>Some(mat.base_texture), + vmt_parser::material::Material::EyeRefract(mat)=>Some(mat.cornea_texture), + vmt_parser::material::Material::SubRect(_mat)=>None,//recursive + vmt_parser::material::Material::Sprite(mat)=>Some(mat.base_texture), + vmt_parser::material::Material::SpriteCard(mat)=>mat.base_texture, + vmt_parser::material::Material::Cable(mat)=>Some(mat.base_texture), + vmt_parser::material::Material::Refract(mat)=>mat.base_texture, + vmt_parser::material::Material::Modulate(mat)=>Some(mat.base_texture), + vmt_parser::material::Material::DecalModulate(mat)=>Some(mat.base_texture), + vmt_parser::material::Material::Sky(mat)=>Some(mat.base_texture), + vmt_parser::material::Material::Replacements(_mat)=>None, + vmt_parser::material::Material::Patch(_mat)=>None,//recursive + _=>return Err(anyhow::Error::msg("vmt failed to parse")), + }; + if let Some(search_texture_name)=some_texture{ + println!("searching for some random texture: {}",search_texture_name); + let mut texture_file_name=std::path::PathBuf::from("materials"); + texture_file_name.push(search_texture_name); + texture_file_name.set_extension("vtf"); + if let Some(stuff)=find_stuff(texture_file_name.as_os_str().to_str().unwrap())?{ + println!("got it! writing to {:?}",texture_name); + found_texture=true; + let texture_name=texture_name.clone(); + thread_handles.push(s.spawn(move||write_image(stuff,texture_name))); + } + } + } if !found_texture{ println!("no data"); }