diff options
Diffstat (limited to 'exporter/src/bin')
-rw-r--r-- | exporter/src/bin/material_stats.rs | 36 | ||||
-rw-r--r-- | exporter/src/bin/meshes.rs | 34 | ||||
-rw-r--r-- | exporter/src/bin/textures.rs | 28 |
3 files changed, 21 insertions, 77 deletions
diff --git a/exporter/src/bin/material_stats.rs b/exporter/src/bin/material_stats.rs index 3eb4dc0..b853442 100644 --- a/exporter/src/bin/material_stats.rs +++ b/exporter/src/bin/material_stats.rs @@ -1,48 +1,22 @@ -use anyhow::anyhow; use std::{env::args, fs::File, io::BufReader}; -use unity_tools::{classes::material::Material, serialized_file::SerializedFile, unityfs::UnityFS}; +use unity_tools::{assetbundle::AssetBundle, classes::material::Material}; fn main() -> anyhow::Result<()> { env_logger::init_from_env("LOG"); let file = BufReader::new(File::open(args().nth(1).unwrap()).unwrap()); - let fs = UnityFS::open(file)?; + let mut bundle = AssetBundle::open(file)?; let mode = args().nth(2).unwrap(); - let cabfile = fs - .find_main_file() - .ok_or(anyhow!("no CAB file found"))? - .to_owned(); - - let cab = fs.read(&cabfile)?; - let mut file = SerializedFile::read(cab)?; - let mut sharedassets = file - .find_fs_shared_assets(&fs) - .map(|n| { - let f = fs.read(&n)?; - let f = SerializedFile::read(f)?; - Ok::<_, anyhow::Error>(f) - }) - .transpose()?; - - for ob in file.objects.clone() { - if file.get_object_type_tree(&ob)?.type_string != "Material" { - continue; - } - let mat = file.read_object(ob)?.parse::<Material>()?; + for ob in bundle.all_toplevel_of_class("Material").collect::<Vec<_>>() { + let mat = ob.load(&mut bundle)?.parse::<Material>()?; match mode.as_str() { "material" => { println!("{}", mat.name) } "shader" => { - println!( - "{}", - mat.shader - .load(&mut file, sharedassets.as_mut())? - .parsed - .name - ) + println!("{}", mat.shader.load(&mut bundle)?.parsed.name) } x => panic!("unknown mode {x:?}"), } diff --git a/exporter/src/bin/meshes.rs b/exporter/src/bin/meshes.rs index db8f2f8..4cd86e8 100644 --- a/exporter/src/bin/meshes.rs +++ b/exporter/src/bin/meshes.rs @@ -1,53 +1,35 @@ #![feature(array_chunks)] -use anyhow::anyhow; +use glam::Vec3; use std::{ env::args, fs::{File, create_dir_all}, io::{BufReader, BufWriter, Write}, }; use unity_tools::{ + assetbundle::AssetBundle, classes::mesh::{Mesh, VertexDataChannel}, - object::parser::FromValue, - serialized_file::SerializedFile, - unityfs::UnityFS, }; fn main() -> anyhow::Result<()> { env_logger::init_from_env("LOG"); let file = BufReader::new(File::open(args().nth(1).unwrap()).unwrap()); - let fs = UnityFS::open(file)?; + let mut bundle = AssetBundle::open(file)?; let mut i = 0; create_dir_all("/tmp/a").unwrap(); - let cabfile = fs - .header - .nodes() - .iter() - .find(|n| !n.name.ends_with(".resource") && !n.name.ends_with(".resS")) - .ok_or(anyhow!("no CAB file found"))? - .to_owned(); - - let mut cab = fs.read(&cabfile)?; - let mut file = SerializedFile::read(&mut cab)?; - for ob in file.objects.clone() { - if file.get_object_type_tree(&ob)?.type_string != "Mesh" { - continue; - } - let value = file.read_object(ob)?; - let mesh = Mesh::from_value(value).unwrap(); + for ob in bundle.all_toplevel_of_class("Mesh").collect::<Vec<_>>() { + let mesh = ob.load(&mut bundle)?.parse::<Mesh>()?; let mut obj = BufWriter::new(File::create(format!( "/tmp/a/{}_{i}.obj", mesh.name.replace("/", "-").replace(".", "-") ))?); - let (pos_dims, positions) = mesh + let positions = mesh .vertex_data - .read_channel(VertexDataChannel::Position) + .read_channel_vec::<Vec3>(VertexDataChannel::Position)? .unwrap(); - assert_eq!(pos_dims, 3); - - for [x, y, z] in positions.array_chunks() { + for Vec3 { x, y, z } in positions { writeln!(obj, "v {x} {y} {z}")?; } for [a, b, c] in mesh.read_indecies() { diff --git a/exporter/src/bin/textures.rs b/exporter/src/bin/textures.rs index a3b6cec..56cfc9b 100644 --- a/exporter/src/bin/textures.rs +++ b/exporter/src/bin/textures.rs @@ -1,38 +1,26 @@ -use anyhow::anyhow; use log::warn; use std::{ env::args, fs::{File, create_dir_all}, io::BufReader, }; -use unity_tools::{ - classes::texture2d::Texture2D, object::parser::FromValue, serialized_file::SerializedFile, - unityfs::UnityFS, -}; +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 fs = UnityFS::open(file)?; + let mut bundle = AssetBundle::open(file)?; let mut i = 0; create_dir_all("/tmp/a").unwrap(); - let cabfile = fs - .find_main_file() - .ok_or(anyhow!("no CAB file found"))? - .to_owned(); - - let mut cab = fs.read(&cabfile)?; - let mut file = SerializedFile::read(&mut cab)?; - for ob in file.objects.clone() { - if file.get_object_type_tree(&ob)?.type_string != "Texture2D" { - continue; - } - let value = file.read_object(ob)?; - let mut texture = Texture2D::from_value(value)?; + 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(&mut fs)?; + texture.image_data = texture.stream_data.read(&bundle.fs)?; } let path = format!( "/tmp/a/{}_{i}.png", |