Skip to content

Commit

Permalink
mesh load fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Nov 10, 2024
1 parent b509f14 commit 964de3f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
18 changes: 12 additions & 6 deletions rust/src/unity/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ impl<'a> DekuRead<'a> for Packedi32Vec {
fn read(input: &'a BitSlice<u8, Msb0>, ctx: ()) -> Result<(&'a BitSlice<u8, Msb0>, 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 {
Expand All @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions rust/src/unity/serialized_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();},
Expand Down
20 changes: 1 addition & 19 deletions rust/src/unity/types/v2019_4_39f1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct MeshRenderer {
pub struct Mesh {
pub name: CharArray,
pub submeshes: UnityArray<SubMesh>,
pub shapes: UnityArray<BlendShapeData>,
pub shapes: BlendShapeData,
pub bind_pose: UnityArray<Matrix4x4>,
pub bone_name_hashes: UnityArray<u32>,
pub root_bone_name_hash: u32,
Expand All @@ -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<u8>,
pub index_format: IndexFormat,
pub index_buffer: UnityArray<u8>,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment2: Vec<u8>,
Expand Down Expand Up @@ -141,12 +140,6 @@ pub struct StreamingInfo {
pub path: CharArray,
}

fn read_dbg<'a>(input: &'a BitSlice<u8, Msb0>, _bit_offset: usize) -> Result<(&'a BitSlice<u8, Msb0>, 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,
Expand All @@ -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<u8>,
pub uv: Packedf32Vec,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment2: Vec<u8>,
pub normals: Packedf32Vec,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment3: Vec<u8>,
pub tangents: Packedf32Vec,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment4: Vec<u8>,
pub weights: Packedi32Vec,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment5: Vec<u8>,
pub normal_signs: Packedi32Vec,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment6: Vec<u8>,
pub tangent_signs: Packedi32Vec,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment7: Vec<u8>,
pub float_colors: Packedf32Vec,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment8: Vec<u8>,
pub bone_indices: Packedi32Vec,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment9: Vec<u8>,
pub triangles: Packedi32Vec,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment10: Vec<u8>,
pub uv_info: u32,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment11: Vec<u8>,
}

#[derive(DekuRead, Clone, Debug)]
Expand Down

0 comments on commit 964de3f

Please sign in to comment.