texture gaming

This commit is contained in:
Quaternions 2024-01-08 23:08:35 -08:00
parent 9e30f5dca7
commit f639047980

View File

@ -1047,25 +1047,17 @@ fn write_attributes() -> AResult<()>{
fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_path:std::path::PathBuf)->AResult<()>{ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_path:std::path::PathBuf)->AResult<()>{
let vpk_index=vpk::VPK::read(&vpk_path)?; let vpk_index=vpk::VPK::read(&vpk_path)?;
let mut vpk_cache=std::collections::HashMap::new(); let mut deduplicate=std::collections::HashSet::new();
for path in paths{ for path in paths{
let bsp=vbsp::Bsp::read(std::fs::read(path)?.as_ref())?; let bsp=vbsp::Bsp::read(std::fs::read(path)?.as_ref())?;
for texture in bsp.textures(){ for texture in bsp.textures(){
let texture_name=texture.texture_data().name(); let texture_name=texture.texture_data().name();
let texture_file_name=format!("materials/{}.vtf",texture_name); let texture_file_name=format!("materials/{}.vtf",texture_name.to_lowercase());
if !deduplicate.insert(texture_file_name.clone()){
continue;
}
println!("texture_name={}",texture_file_name); println!("texture_name={}",texture_file_name);
if let Some(stuff)=vpk_index.tree.get(texture_file_name.as_str()){ if let Some(stuff)=vpk_index.tree.get(texture_file_name.as_str()){
let vpk=if let Some(vpk)=vpk_cache.get(stuff.archive_path.as_str()){
println!("ayyyy");
vpk
}else{
println!("hiii");
let vpk=vpk::VPK::read(&std::path::PathBuf::from(&stuff.archive_path))?;
println!("hiiiiii");
vpk_cache.insert(stuff.archive_path.as_str(),vpk);
vpk_cache.get(stuff.archive_path.as_str()).unwrap()
};
if let Some(stuff)=vpk.tree.get(texture_file_name.as_str()){
let image=vtf::from_bytes(&mut stuff.get()?.to_vec())?.highres_image.decode(0)?.to_rgba8(); let image=vtf::from_bytes(&mut stuff.get()?.to_vec())?.highres_image.decode(0)?.to_rgba8();
let format=if image.width()%4!=0||image.height()%4!=0{ let format=if image.width()%4!=0||image.height()%4!=0{
@ -1088,9 +1080,6 @@ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_path:std::path::PathBuf)->
std::fs::create_dir_all(dest.parent().unwrap())?; std::fs::create_dir_all(dest.parent().unwrap())?;
let mut writer = std::io::BufWriter::new(std::fs::File::create(dest)?); let mut writer = std::io::BufWriter::new(std::fs::File::create(dest)?);
dds.write(&mut writer)?; dds.write(&mut writer)?;
}else{
println!("zip");
}
}else{ }else{
println!("nonadat"); println!("nonadat");
} }