aboutsummaryrefslogtreecommitdiff
path: root/exporter/src/bin/textures.rs
blob: 56cfc9b44d34e79e5358eb88f6767bc1195ed09d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use log::warn;
use std::{
    env::args,
    fs::{File, create_dir_all},
    io::BufReader,
};
use unity_tools::{assetbundle::AssetBundle, classes::texture2d::Texture2D};

fn main() -> anyhow::Result<()> {
    env_logger::init_from_env("LOG");
    let file = BufReader::new(File::open(args().nth(1).unwrap()).unwrap());
    let mut bundle = AssetBundle::open(file)?;

    let mut i = 0;
    create_dir_all("/tmp/a").unwrap();

    for ob in bundle
        .all_toplevel_of_class("Texture2D")
        .collect::<Vec<_>>()
    {
        let mut texture = ob.load(&mut bundle)?.parse::<Texture2D>()?;
        if texture.image_data.is_empty() {
            texture.image_data = texture.stream_data.read(&bundle.fs)?;
        }
        let path = format!(
            "/tmp/a/{}_{i}.png",
            texture.name.replace("/", "-").replace(".", "-")
        );
        match texture.to_image() {
            Ok(im) => {
                if !im.as_rgba32f().is_some() {
                    im.save(&path).unwrap();
                    println!("{path}");
                }
            }
            Err(e) => warn!("{e}"),
        }
        i += 1;
    }

    Ok(())
}