diff options
author | metamuffin <metamuffin@disroot.org> | 2025-03-14 11:20:02 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-03-14 11:20:02 +0100 |
commit | 6debd2c0a230d623c06869ca4c4f13519f53eb5d (patch) | |
tree | a6a2ea4163599833be71fc240ce5fc219eb57afe | |
parent | b9affdc70b3fa206c44e1fee352a85dc4f7a27b0 (diff) | |
download | unity-tools-6debd2c0a230d623c06869ca4c4f13519f53eb5d.tar unity-tools-6debd2c0a230d623c06869ca4c4f13519f53eb5d.tar.bz2 unity-tools-6debd2c0a230d623c06869ca4c4f13519f53eb5d.tar.zst |
improve PPtr functions
-rw-r--r-- | Cargo.lock | 74 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/bin/meshes.rs | 1 | ||||
-rw-r--r-- | src/bin/typegraph.rs | 9 | ||||
-rw-r--r-- | src/classes/mesh.rs | 1 | ||||
-rw-r--r-- | src/classes/pptr.rs | 34 | ||||
-rw-r--r-- | src/classes/transform.rs | 2 | ||||
-rw-r--r-- | src/object/parser.rs | 5 |
8 files changed, 116 insertions, 13 deletions
@@ -132,6 +132,12 @@ dependencies = [ ] [[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] name = "bit_field" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -174,6 +180,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" [[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] name = "byteorder-lite" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -358,6 +370,45 @@ dependencies = [ ] [[package]] +name = "gltf" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ce1918195723ce6ac74e80542c5a96a40c2b26162c1957a5cd70799b8cacf7" +dependencies = [ + "base64", + "byteorder 1.5.0", + "gltf-json", + "image", + "lazy_static", + "serde_json", + "urlencoding", +] + +[[package]] +name = "gltf-derive" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14070e711538afba5d6c807edb74bcb84e5dbb9211a3bf5dea0dfab5b24f4c51" +dependencies = [ + "inflections", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "gltf-json" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6176f9d60a7eab0a877e8e96548605dedbde9190a7ae1e80bbcc1c9af03ab14" +dependencies = [ + "gltf-derive", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] name = "half" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -444,6 +495,12 @@ dependencies = [ ] [[package]] +name = "inflections" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a257582fdcde896fd96463bf2d40eefea0580021c0712a0e2b028b60b47a837a" + +[[package]] name = "interpolate_name" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -491,6 +548,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" [[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] name = "lebe" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -558,7 +621,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "782ba3f542e8bc1349386c15e9dc3119ae6da96479f96b3863cc7a88bbdfd4e4" dependencies = [ - "byteorder", + "byteorder 0.5.3", ] [[package]] @@ -1035,7 +1098,7 @@ dependencies = [ [[package]] name = "texture2ddecoder" version = "0.1.1" -source = "git+https://github.com/UniversalGameExtraction/texture2ddecoder#d2b4653fda298f1da39917da86bc509b17879808" +source = "git+https://github.com/UniversalGameExtraction/texture2ddecoder?rev=d2b4653fda298f1da39917da86bc509b17879808#d2b4653fda298f1da39917da86bc509b17879808" dependencies = [ "paste", ] @@ -1128,6 +1191,7 @@ dependencies = [ "anyhow", "env_logger", "glam", + "gltf", "humansize", "image", "log", @@ -1141,6 +1205,12 @@ dependencies = [ ] [[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + +[[package]] name = "utf8parse" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -16,4 +16,5 @@ serde_yml = "0.0.12" glam = { version = "0.30.0", features = ["serde"] } texpresso = "2.0.1" image = "0.25.5" -texture2ddecoder = { git = "https://github.com/UniversalGameExtraction/texture2ddecoder" } +texture2ddecoder = { git = "https://github.com/UniversalGameExtraction/texture2ddecoder", rev = "d2b4653fda298f1da39917da86bc509b17879808" } +gltf = "1.4.1" diff --git a/src/bin/meshes.rs b/src/bin/meshes.rs index d59b496..e3758c4 100644 --- a/src/bin/meshes.rs +++ b/src/bin/meshes.rs @@ -16,7 +16,6 @@ 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 fs2 = UnityFS::open(file())?; let mut i = 0; create_dir_all("/tmp/a").unwrap(); diff --git a/src/bin/typegraph.rs b/src/bin/typegraph.rs index 7425778..ea55e05 100644 --- a/src/bin/typegraph.rs +++ b/src/bin/typegraph.rs @@ -41,7 +41,10 @@ fn main() -> anyhow::Result<()> { if let Some(inner) = c.type_string.strip_prefix("PPtr<") { c.type_string = inner.strip_suffix(">").unwrap().to_owned(); f = true; - } else if matches!(c.type_string.as_str(), "Array" | "pair" | "map") { + } else if matches!( + c.type_string.as_str(), + "Array" | "pair" | "map" | "vector" + ) { nc.extend(c.children); f = true } else { @@ -105,7 +108,6 @@ fn is_primitive(s: &str) -> bool { | "SInt64" | "bool" | "float" - | "vector" | "string" | "float3" | "float4" @@ -113,6 +115,9 @@ fn is_primitive(s: &str) -> bool { | "Vector2f" | "Vector3f" | "Vector4f" + | "Matrix4x4f" + | "ColorRGBA" + | "Rectf" | "Quaternionf" | "xform" ) diff --git a/src/classes/mesh.rs b/src/classes/mesh.rs index b8b9e90..f0b2173 100644 --- a/src/classes/mesh.rs +++ b/src/classes/mesh.rs @@ -85,6 +85,7 @@ impl FromValue for Mesh { }) } } + impl Mesh { pub fn read_indecies(&self) -> Vec<[u32; 3]> { if self.index_format == 0 { diff --git a/src/classes/pptr.rs b/src/classes/pptr.rs index d6e4bb6..30f37ad 100644 --- a/src/classes/pptr.rs +++ b/src/classes/pptr.rs @@ -1,11 +1,17 @@ -use super::HValue; -use crate::object::{Value, parser::FromValue}; +use crate::{ + object::{Value, parser::FromValue}, + serialized_file::SerializedFile, +}; use anyhow::{Result, anyhow, bail}; +use log::debug; use serde::Serialize; -use std::marker::PhantomData; +use std::{ + io::{Read, Seek}, + marker::PhantomData, +}; #[derive(Debug, Serialize)] -pub struct PPtr<T = HValue> { +pub struct PPtr<T = Value> { #[serde(skip, default)] _class: PhantomData<T>, pub class: String, @@ -36,8 +42,8 @@ impl<T> FromValue for PPtr<T> { } } -impl PPtr { - pub fn cast<T>(self) -> PPtr<T> { +impl<T: FromValue> PPtr<T> { + pub fn cast<U>(self) -> PPtr<U> { PPtr { _class: PhantomData, class: self.class, @@ -45,4 +51,20 @@ impl PPtr { path_id: self.path_id, } } + pub fn is_null(&self) -> bool { + self.path_id == 0 && self.file_id == 0 + } + pub fn load(&self, file: &mut SerializedFile<impl Read + Seek>) -> Result<T> { + debug!( + "loading PPtr<{}> file_id={} path_id={}", + self.class, self.file_id, self.path_id + ); + let ob = file + .objects + .iter() + .find(|o| o.path_id == self.path_id) + .ok_or(anyhow!("object with path id {} not found", self.path_id))? + .to_owned(); + file.read_object(ob)?.parse() + } } diff --git a/src/classes/transform.rs b/src/classes/transform.rs index 2ec515a..880eb9a 100644 --- a/src/classes/transform.rs +++ b/src/classes/transform.rs @@ -29,7 +29,7 @@ impl FromValue for Transform { .as_vector() .unwrap() .into_iter() - .map(|e| PPtr::from_value(e).unwrap().cast()) + .map(|e| PPtr::from_value(e).unwrap()) .collect(), }) } diff --git a/src/object/parser.rs b/src/object/parser.rs index 2e5d027..b9cc1d4 100644 --- a/src/object/parser.rs +++ b/src/object/parser.rs @@ -44,6 +44,11 @@ impl Fields { } } +impl FromValue for Value { + fn from_value(v: Value) -> Result<Self> { + Ok(v) + } +} impl FromValue for u8 { fn from_value(v: Value) -> anyhow::Result<Self> { v.as_u8().ok_or(anyhow!("expected u8")) |