Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity optimization + bugfix #746

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions rust/src/unity/types/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ pub struct Mesh {
pub keep_vertices: u8,
pub keep_indices: u8,
pub index_format: IndexFormat,
pub index_buffer: UnityArray<u8>,
pub index_buffer: ByteArray,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment2: Vec<u8>,
#[deku(ctx = "version")]
pub vertex_data: VertexData,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment3: Vec<u8>,
pub compressed_mesh: CompressedMesh,
pub local_aabb: AABB,
pub mesh_usage_flags: i32,
pub baked_convex_collision_mesh: UnityArray<u8>,
pub baked_convex_collision_mesh: ByteArray,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment4: Vec<u8>,
pub baked_triangle_collision_mesh: UnityArray<u8>,
pub baked_triangle_collision_mesh: ByteArray,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment5: Vec<u8>,
pub mesh_metrics: [f32; 2],
#[deku(ctx = "version")]
Expand Down Expand Up @@ -211,10 +211,39 @@ pub struct SubMesh {
pub struct VertexData {
pub vertex_count: u32,
pub channels: UnityArray<ChannelInfo>,
pub data: UnityArray<u8>,
pub data: ByteArray,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment: Vec<u8>,
}

#[derive(Default, Debug, Clone)]
pub struct ByteArray {
pub data: Vec<u8>,
}

impl<'a> DekuRead<'a> for ByteArray {
fn read(
input: &'a deku::bitvec::BitSlice<u8, deku::bitvec::Msb0>,
ctx: (),
) -> Result<(&'a deku::bitvec::BitSlice<u8, deku::bitvec::Msb0>, Self), DekuError>
where Self: Sized {
let (rest, count) = i32::read(input, ctx)?;
let (data_bits, rest) = rest.split_at(count as usize * 8);
let bytes = data_bits.domain().region().unwrap().1;
Ok((
rest,
Self {
data: bytes.to_vec(),
},
))
}
}

impl From<ByteArray> for Vec<u8> {
fn from(value: ByteArray) -> Self {
value.data
}
}

#[derive(DekuRead, Clone, Debug)]
pub struct CompressedMesh {
pub vertices: Packedf32Vec,
Expand Down Expand Up @@ -323,9 +352,9 @@ pub struct Texture2D {
pub lightmap_format: i32,
pub color_space: ColorSpace,
#[deku(cond = "version >= UnityVersion::V2020_3_16f1")]
pub platform_blob: UnityArray<u8>,
pub platform_blob: ByteArray,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment2: Vec<u8>,
pub data: UnityArray<u8>,
pub data: ByteArray,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment3: Vec<u8>,
#[deku(ctx = "version")]
pub streaming_info: StreamingInfo,
Expand Down
6 changes: 4 additions & 2 deletions src/Common/Unity/AssetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ export class AssetFile {
this.waitForHeaderPromise = null;
}

public waitForHeader(): Promise<void> {
return assertExists(this.waitForHeaderPromise);
public async waitForHeader() {
if (this.waitForHeaderPromise !== null) {
await this.waitForHeaderPromise;
}
}

private async initFullInternal(dataFetcher: DataFetcher): Promise<void> {
Expand Down
Loading