From a7f0d583b69f0ab3c0bf146c999462b68903b7ce Mon Sep 17 00:00:00 2001 From: Will Greenberg Date: Sat, 9 Nov 2024 23:53:33 -0800 Subject: [PATCH] wip --- rust/src/unity/types/v2019_4_39f1.rs | 6 ++++ rust/src/unity/types/v2020_3_16f1.rs | 1 + rust/src/unity/types/v2021_3_27f1.rs | 1 + src/Common/Unity/AssetManager.ts | 43 +++++++++++++++++----------- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/rust/src/unity/types/v2019_4_39f1.rs b/rust/src/unity/types/v2019_4_39f1.rs index 925809277..37f1d0e0e 100644 --- a/rust/src/unity/types/v2019_4_39f1.rs +++ b/rust/src/unity/types/v2019_4_39f1.rs @@ -101,14 +101,19 @@ 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, pub vertex_data: VertexData, + #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment3: Vec, pub compressed_mesh: CompressedMesh, pub local_aabb: AABB, pub mesh_usage_flags: i32, pub baked_convex_collision_mesh: UnityArray, + #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment4: Vec, pub baked_triangle_collision_mesh: UnityArray, + #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment5: Vec, pub mesh_metrics: [f32; 2], pub streaming_info: StreamingInfo, } @@ -151,6 +156,7 @@ pub struct SubMesh { pub struct VertexData { pub vertex_count: u32, pub channels: UnityArray, + #[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment: Vec, pub data: UnityArray, } diff --git a/rust/src/unity/types/v2020_3_16f1.rs b/rust/src/unity/types/v2020_3_16f1.rs index 3a7111730..e01535b37 100644 --- a/rust/src/unity/types/v2020_3_16f1.rs +++ b/rust/src/unity/types/v2020_3_16f1.rs @@ -2,4 +2,5 @@ // https://github.com/AssetRipper/TypeTreeDumps/blob/main/StructsDump/release/2020.3.16f1.dump // e.g. Neon White +// hack: just re-export all older types until we need to override one w/ changes pub use super::v2019_4_39f1::*; diff --git a/rust/src/unity/types/v2021_3_27f1.rs b/rust/src/unity/types/v2021_3_27f1.rs index 5037e984a..8aac88c72 100644 --- a/rust/src/unity/types/v2021_3_27f1.rs +++ b/rust/src/unity/types/v2021_3_27f1.rs @@ -5,6 +5,7 @@ use deku::prelude::*; use crate::unity::common::{PPtr, UnityArray, Vec4}; +// hack: just re-export all older types until we need to override one w/ changes pub use super::v2019_4_39f1::*; #[derive(DekuRead, Clone, Debug)] diff --git a/src/Common/Unity/AssetManager.ts b/src/Common/Unity/AssetManager.ts index 5b97f0847..f907c05b3 100644 --- a/src/Common/Unity/AssetManager.ts +++ b/src/Common/Unity/AssetManager.ts @@ -254,18 +254,24 @@ export class AssetFile { } private createMeshData = async (assetSystem: UnityAssetSystem, objData: AssetObjectData): Promise => { - const mesh = rust.UnityMesh.create(UnityVersion.V2019_4_39f1, objData.data); - const streamingInfo: UnityStreamingInfo = mesh.streaming_info; - if (streamingInfo.path.length !== 0) { - const buf = await assetSystem.fetchStreamingInfo(streamingInfo); - const vertexData = rust.UnityVertexData.create(UnityVersion.V2019_4_39f1, buf.createTypedArray(Uint8Array)); - mesh.set_vertex_data(vertexData); - } + try { + console.log("f") + const mesh = rust.UnityMesh.create(assetSystem.version, objData.data); + const streamingInfo: UnityStreamingInfo = mesh.streaming_info; + if (streamingInfo.path.length !== 0) { + const buf = await assetSystem.fetchStreamingInfo(streamingInfo); + const vertexData = rust.UnityVertexData.create(assetSystem.version, buf.createTypedArray(Uint8Array)); + mesh.set_vertex_data(vertexData); + } - if (mesh.mesh_compression !== UnityMeshCompression.Off) { - return loadCompressedMesh(assetSystem.device, mesh); - } else { - return loadMesh(assetSystem.device, mesh); + if (mesh.mesh_compression !== UnityMeshCompression.Off) { + return loadCompressedMesh(assetSystem.device, mesh); + } else { + return loadMesh(assetSystem.device, mesh); + } + } catch (e) { + console.error(objData); + throw e; } }; @@ -273,7 +279,7 @@ export class AssetFile { if (objData.classID !== rust.UnityClassID.Texture2D) return null; - const header = rust.UnityTexture2D.create(UnityVersion.V2019_4_39f1, objData.data); + const header = rust.UnityTexture2D.create(assetSystem.version, objData.data); let data = header.data; if (data.length === 0) { const streaming_info = header.streaming_info; @@ -285,7 +291,7 @@ export class AssetFile { }; private createMaterialData = async (assetSystem: UnityAssetSystem, objData: AssetObjectData): Promise => { - const header = rust.UnityMaterial.create(UnityVersion.V2019_4_39f1, objData.data); + const header = rust.UnityMaterial.create(assetSystem.version, objData.data); const materialData = new UnityMaterialData(objData.location, header); await materialData.load(assetSystem); return materialData; @@ -296,10 +302,13 @@ export class AssetFile { return this.promiseCache.get(pathID)! as Promise; const promise = this.fetchObject(pathID).then((objData) => { - return createFunc(assetSystem, objData).then((v) => { - this.dataCache.set(pathID, v); - return v; - }); + return createFunc(assetSystem, objData).then((v) => { + this.dataCache.set(pathID, v); + return v; + }).catch(e => { + console.error(`fufckcf to fetch ${pathID}`); + throw e; + }); }); this.promiseCache.set(pathID, promise); return promise;