From 964de3f66ab533bf864ac301dbb98fe6792618e0 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 10 Nov 2024 10:22:15 -0800 Subject: [PATCH] mesh load fixes --- rust/src/unity/common.rs | 18 ++++++++++++------ rust/src/unity/serialized_file.rs | 7 +++++-- rust/src/unity/types/v2019_4_39f1.rs | 20 +------------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/rust/src/unity/common.rs b/rust/src/unity/common.rs index db5146417..8711404d6 100644 --- a/rust/src/unity/common.rs +++ b/rust/src/unity/common.rs @@ -222,8 +222,12 @@ impl<'a> DekuRead<'a> for Packedi32Vec { fn read(input: &'a BitSlice, ctx: ()) -> Result<(&'a BitSlice, Self), DekuError> where Self: Sized { - let (rest, num_items) = u32::read(input, ctx)?; - let (last_rest, bit_size) = u8::read(&rest[4 * num_items as usize..], ctx)?; + let (mut rest, num_items) = u32::read(input, ctx)?; + let (new_rest, byte_array_count) = u32::read(rest, ctx)?; + rest = new_rest; + let (new_rest, bit_size) = u8::read(&rest[8 * byte_array_count as usize..], ctx)?; + // align + let last_rest = &new_rest[3*8..]; let (_, data) = unpack_i32s(rest, num_items as usize, bit_size as usize)?; Ok((last_rest, Packedi32Vec { @@ -248,14 +252,16 @@ impl<'a> DekuRead<'a> for Packedf32Vec { where Self: Sized { let (mut rest, num_items) = u32::read(input, ctx)?; - // dbg!("JJJ AAA", num_items); let (new_rest, scale) = f32::read(rest, ctx)?; - // dbg!("JJJ AAA", scale); rest = new_rest; let (new_rest, start) = f32::read(rest, ctx)?; - // dbg!("JJJ AAA", start); rest = new_rest; - let (last_rest, bit_size) = u8::read(&rest[4 * num_items as usize..], ctx)?; + let (new_rest, byte_array_count) = u32::read(rest, ctx)?; + rest = new_rest; + let (new_rest, bit_size) = u8::read(&rest[8 * byte_array_count as usize..], ctx)?; + // align + let last_rest = &new_rest[3*8..]; + let max = ((1 << bit_size) as f32) - 1.0; let (_, ints) = unpack_i32s(rest, num_items as usize, bit_size as usize)?; let mut result = Vec::with_capacity(num_items as usize); diff --git a/rust/src/unity/serialized_file.rs b/rust/src/unity/serialized_file.rs index 67df4e336..3d19ff2c1 100644 --- a/rust/src/unity/serialized_file.rs +++ b/rust/src/unity/serialized_file.rs @@ -304,8 +304,11 @@ mod tests { let byte_size = obj.byte_size as usize; let data = &bigdata[byte_start..byte_start + byte_size]; - if (filter.mesh.path_id == 42) { - let _mesh = Mesh::create(version, data).unwrap(); + if filter.mesh.path_id == 42 { + let mut mesh = Mesh::create(version, data).unwrap(); + mesh.submeshes.clear(); + mesh.index_buffer.clear(); + dbg!("JJJ BBB", mesh); } }, ClassID::MeshRenderer => {MeshRenderer::create(version, data).unwrap();}, diff --git a/rust/src/unity/types/v2019_4_39f1.rs b/rust/src/unity/types/v2019_4_39f1.rs index edc0a064d..1cacb881c 100644 --- a/rust/src/unity/types/v2019_4_39f1.rs +++ b/rust/src/unity/types/v2019_4_39f1.rs @@ -91,7 +91,7 @@ pub struct MeshRenderer { pub struct Mesh { pub name: CharArray, pub submeshes: UnityArray, - pub shapes: UnityArray, + pub shapes: BlendShapeData, pub bind_pose: UnityArray, pub bone_name_hashes: UnityArray, pub root_bone_name_hash: u32, @@ -101,7 +101,6 @@ pub struct Mesh { pub is_readable: u8, pub keep_vertices: u8, pub keep_indices: u8, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment: Vec, pub index_format: IndexFormat, pub index_buffer: UnityArray, #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment2: Vec, @@ -141,12 +140,6 @@ pub struct StreamingInfo { pub path: CharArray, } -fn read_dbg<'a>(input: &'a BitSlice, _bit_offset: usize) -> Result<(&'a BitSlice, i32), DekuError> { - let r = i32::read(input, ())?; - dbg!("JJJ AAA", r.1); - return Ok(r); -} - #[derive(DekuRead, Clone, Debug)] pub struct SubMesh { pub first_byte: u32, @@ -169,27 +162,16 @@ pub struct VertexData { #[derive(DekuRead, Clone, Debug)] pub struct CompressedMesh { pub vertices: Packedf32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment1: Vec, pub uv: Packedf32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment2: Vec, pub normals: Packedf32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment3: Vec, pub tangents: Packedf32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment4: Vec, pub weights: Packedi32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment5: Vec, pub normal_signs: Packedi32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment6: Vec, pub tangent_signs: Packedi32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment7: Vec, pub float_colors: Packedf32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment8: Vec, pub bone_indices: Packedi32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment9: Vec, pub triangles: Packedi32Vec, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment10: Vec, pub uv_info: u32, - #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment11: Vec, } #[derive(DekuRead, Clone, Debug)]