Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wgreenberg committed Nov 10, 2024
1 parent 37bcf14 commit a7f0d58
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
6 changes: 6 additions & 0 deletions rust/src/unity/types/v2019_4_39f1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
pub index_format: IndexFormat,
pub index_buffer: UnityArray<u8>,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment2: Vec<u8>,
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>,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment4: Vec<u8>,
pub baked_triangle_collision_mesh: UnityArray<u8>,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment5: Vec<u8>,
pub mesh_metrics: [f32; 2],
pub streaming_info: StreamingInfo,
}
Expand Down Expand Up @@ -151,6 +156,7 @@ pub struct SubMesh {
pub struct VertexData {
pub vertex_count: u32,
pub channels: UnityArray<ChannelInfo>,
#[deku(count = "(4 - deku::byte_offset % 4) % 4")] _alignment: Vec<u8>,
pub data: UnityArray<u8>,
}

Expand Down
1 change: 1 addition & 0 deletions rust/src/unity/types/v2020_3_16f1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
1 change: 1 addition & 0 deletions rust/src/unity/types/v2021_3_27f1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
43 changes: 26 additions & 17 deletions src/Common/Unity/AssetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,32 @@ export class AssetFile {
}

private createMeshData = async (assetSystem: UnityAssetSystem, objData: AssetObjectData): Promise<UnityMeshData> => {
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;
}
};

private createTexture2DData = async (assetSystem: UnityAssetSystem, objData: AssetObjectData): Promise<UnityTexture2DData | null> => {
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;
Expand All @@ -285,7 +291,7 @@ export class AssetFile {
};

private createMaterialData = async (assetSystem: UnityAssetSystem, objData: AssetObjectData): Promise<UnityMaterialData> => {
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;
Expand All @@ -296,10 +302,13 @@ export class AssetFile {
return this.promiseCache.get(pathID)! as Promise<T>;

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;
Expand Down

0 comments on commit a7f0d58

Please sign in to comment.