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

fix(expanded): correctly update mesh info #51

Merged
merged 1 commit into from
Apr 2, 2024
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
20 changes: 16 additions & 4 deletions src/vpx/expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ fn read_sounds<P: AsRef<Path>>(expanded_dir: &P) -> io::Result<Vec<SoundData>> {

fn write_fonts<P: AsRef<Path>>(vpx: &VPX, expanded_dir: &P) -> Result<(), WriteError> {
let fonts_json_path = expanded_dir.as_ref().join("fonts.json");
let mut fonts_index_file = std::fs::File::create(&fonts_json_path)?;
let mut fonts_index_file = File::create(&fonts_json_path)?;
let fonts_index: Vec<FontDataJson> = vpx
.fonts
.iter()
Expand Down Expand Up @@ -1014,8 +1014,13 @@ fn read_gameitem_binaries(
let gameitem_file_name = gameitem_file_name.trim_end_matches(".json");
let obj_path = gameitems_dir.join(format!("{}.obj", gameitem_file_name));
if obj_path.exists() {
let (compressed_vertices, compressed_indices) = read_obj(&obj_path)?;
let (vertices_len, indices_len, compressed_vertices, compressed_indices) =
read_obj(&obj_path)?;
primitive.num_vertices = Some(vertices_len as u32);
primitive.compressed_vertices_len = Some(compressed_vertices.len() as u32);
primitive.compressed_vertices_data = Some(compressed_vertices);
primitive.num_indices = Some(indices_len as u32);
primitive.compressed_indices_len = Some(compressed_indices.len() as u32);
primitive.compressed_indices_data = Some(compressed_indices);
}
let frame0_file_name = animation_frame_file_name(&gameitem_file_name, 0);
Expand Down Expand Up @@ -1062,7 +1067,7 @@ fn animation_frame_file_name(gameitem_file_name: &str, index: usize) -> String {
format!("{}_anim_{}.obj", gameitem_file_name, index)
}

fn read_obj(obj_path: &PathBuf) -> io::Result<(Vec<u8>, Vec<u8>)> {
fn read_obj(obj_path: &PathBuf) -> io::Result<(usize, usize, Vec<u8>, Vec<u8>)> {
let ObjData {
name: _,
vertices,
Expand Down Expand Up @@ -1117,13 +1122,20 @@ fn read_obj(obj_path: &PathBuf) -> io::Result<(Vec<u8>, Vec<u8>)> {
write_vertex_index_for_vpx(bytes_per_index, &mut vpx_indices, v2);
write_vertex_index_for_vpx(bytes_per_index, &mut vpx_indices, v1);
}
let vertices_len = vertices.len();
let incices_len = indices.len();

let vertices = vpx_vertices.to_vec();
let indices = vpx_indices.to_vec();

let compressed_vertices = compress_data(&vertices)?;
let compressed_indices = compress_data(&indices)?;
Ok((compressed_vertices, compressed_indices))
Ok((
vertices_len,
incices_len,
compressed_vertices,
compressed_indices,
))
}

fn read_obj_as_frame(obj_path: &PathBuf) -> io::Result<Vec<VertData>> {
Expand Down
32 changes: 11 additions & 21 deletions src/vpx/gameitem/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ struct PrimitiveJson {
min_aa_bound: Option<Vec<u8>>,
max_aa_bound: Option<Vec<u8>>,
mesh_file_name: Option<String>,
// TODO remove this as we don't need it
num_vertices: Option<u32>,
// TODO remove this as we don't need it
compressed_vertices: Option<u32>,
//compressed_vertices_data: Option<Vec<u8>>,
// TODO remove this as we don't need it
num_indices: Option<u32>,
// TODO remove this as we don't need it
compressed_indices: Option<u32>,
//compressed_indices_data: Option<Vec<u8>>,
depth_bias: f32,
add_blend: Option<bool>,
use_depth_mask: Option<bool>,
Expand Down Expand Up @@ -169,11 +159,11 @@ impl PrimitiveJson {
min_aa_bound: primitive.min_aa_bound.clone(),
max_aa_bound: primitive.max_aa_bound.clone(),
mesh_file_name: primitive.mesh_file_name.clone(),
num_vertices: primitive.num_vertices,
compressed_vertices: primitive.compressed_vertices_len,
// num_vertices: primitive.num_vertices,
// compressed_vertices: primitive.compressed_vertices_len,
//compressed_vertices_data: primitive.m3cx.clone(),
num_indices: primitive.num_indices,
compressed_indices: primitive.compressed_indices_len,
// num_indices: primitive.num_indices,
// compressed_indices: primitive.compressed_indices_len,
// compressed_indices_Data: primitive.m3ci.clone(),
// compressed_animation_vertices: primitive.compressed_animation_vertices_len.clone(),
// compressed_animation_vertices_data: primitive
Expand Down Expand Up @@ -228,13 +218,13 @@ impl PrimitiveJson {
min_aa_bound: self.min_aa_bound.clone(),
max_aa_bound: self.max_aa_bound.clone(),
mesh_file_name: self.mesh_file_name.clone(),
num_vertices: self.num_vertices,
compressed_vertices_len: self.compressed_vertices,
compressed_vertices_data: None, //self.m3cx.clone(),
num_indices: self.num_indices,
compressed_indices_len: self.compressed_indices,
compressed_indices_data: None, //self.m3ci.clone(),
compressed_animation_vertices_len: None, // self.compressed_animation_vertices.clone(),
num_vertices: None, //self.num_vertices,
compressed_vertices_len: None, //self.compressed_vertices,
compressed_vertices_data: None, //self.m3cx.clone(),
num_indices: None, //self.num_indices,
compressed_indices_len: None, //self.compressed_indices,
compressed_indices_data: None, //self.m3ci.clone(),
compressed_animation_vertices_len: None, //self.compressed_animation_vertices.clone(),
compressed_animation_vertices_data: None, //self.compressed_animation_vertices_data.clone(),
depth_bias: self.depth_bias,
add_blend: self.add_blend,
Expand Down
46 changes: 37 additions & 9 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,22 @@ fn biff_tags_and_hashes(reader: &mut BiffReader) -> Vec<(String, usize, u64)> {
let tag_str = tag.as_str();
match tag_str {
"FONT" => {
let _header = reader.get_data(3); // always? 0x01, 0x0, 0x0
let _style = reader.get_u8_no_remaining_update();
let _weight = reader.get_u16_no_remaining_update();
let _size = reader.get_u32_no_remaining_update();
let header = reader.get_data(3).to_owned(); // always? 0x01, 0x0, 0x0
let style = reader.get_u8_no_remaining_update();
let weight = reader.get_u16_no_remaining_update();
let size = reader.get_u32_no_remaining_update();
let name_len = reader.get_u8_no_remaining_update();
let _name = reader.get_str_no_remaining_update(name_len as usize);
let name = reader.get_str_no_remaining_update(name_len as usize);
// reconstruct the bytes that were read
let mut data = Vec::new();
data.extend_from_slice(&header);
data.push(style);
data.extend_from_slice(&weight.to_le_bytes());
data.extend_from_slice(&size.to_le_bytes());
data.push(name_len);
data.extend_from_slice(name.as_bytes());
let hash = hash_data(&data);
tags.push(("FONT".to_string(), name.len(), hash));
}
"JPEG" => {
let remaining = reader.remaining_in_record();
Expand Down Expand Up @@ -194,7 +204,7 @@ fn biff_tags_and_hashes(reader: &mut BiffReader) -> Vec<(String, usize, u64)> {
// TODO one solution could be overwriting padding areas with 0's
// For now we ignore the contents of this field
let hash = 0;
tags.push(("MATE".to_string(), data.len(), hash));
tags.push(("MATE (ignored)".to_string(), data.len(), hash));
}
"PHMA" => {
let data = reader.get_record_data(false);
Expand All @@ -203,18 +213,36 @@ fn biff_tags_and_hashes(reader: &mut BiffReader) -> Vec<(String, usize, u64)> {
// TODO one solution could be overwriting padding areas with 0's
// For now we ignore the contents of this field
let hash = 0;
tags.push(("PHMA".to_string(), data.len(), hash));
tags.push(("PHMA (ignored)".to_string(), data.len(), hash));
}
"M3CY" => {
// Since the compressed indices size is depending on the selected compression
// algorithm we can't expect the same size. So we just read the data and ignore it.
let data = reader.get_record_data(false);
tags.push(("M3CY (ignored)".to_string(), data.len(), 0));
}
"M3CX" => {
let mut data = read_to_end_decompress(reader);
let data = read_to_end_decompress(reader);
let hash = hash_data(&data);
tags.push(("M3CX (decompressed)".to_string(), data.len(), hash));
}
"M3CJ" => {
// Since the compressed indices size is depending on the selected compression
// algorithm we can't expect the same size. So we just read the data and ignore it.
let data = reader.get_record_data(false);
tags.push(("M3CJ (ignored)".to_string(), data.len(), 0));
}
"M3CI" => {
let mut data = read_to_end_decompress(reader);
let data = read_to_end_decompress(reader);
let hash = hash_data(&data);
tags.push(("M3CI (decompressed)".to_string(), data.len(), hash));
}
"M3AY" => {
// Since the compressed indices size is depending on the selected compression
// algorithm we can't expect the same size. So we just read the data and ignore it.
let data = reader.get_record_data(false);
tags.push(("M3AY (ignored)".to_string(), data.len(), 0));
}
"M3AX" => {
let data = read_to_end_decompress(reader);
let hash = hash_data(&data);
Expand Down