decode vmt and attempt to grab some texture

This commit is contained in:
Quaternions 2024-01-09 18:44:57 -08:00
parent 7b1b381064
commit 0e1b9494c2

View File

@ -1148,6 +1148,48 @@ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_path:std::path::PathBuf)->
let texture_name=texture_name.clone(); let texture_name=texture_name.clone();
thread_handles.push(s.spawn(move||write_image(stuff,texture_name))); 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{ if !found_texture{
println!("no data"); println!("no data");
} }