1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-22 12:47:45 +00:00

Write out a proper end of stream vertex element

This commit is contained in:
Joshua Goins 2024-02-25 09:01:59 -05:00
parent f43812fa55
commit 36027c9a9f
2 changed files with 12 additions and 5 deletions

View file

@ -10,6 +10,8 @@ use binrw::BinReaderExt;
use crate::{ByteBuffer, ByteSpan}; use crate::{ByteBuffer, ByteSpan};
use crate::model_vertex_declarations::{vertex_element_parser, VERTEX_ELEMENT_SIZE, vertex_element_writer, VertexDeclaration, VertexElement, VertexType, VertexUsage}; use crate::model_vertex_declarations::{vertex_element_parser, VERTEX_ELEMENT_SIZE, vertex_element_writer, VertexDeclaration, VertexElement, VertexType, VertexUsage};
pub const NUM_VERTICES: u32 = 17;
#[binrw] #[binrw]
#[derive(Debug)] #[derive(Debug)]
#[brw(little)] #[brw(little)]
@ -836,7 +838,6 @@ impl MDL {
impl ModelFileHeader { impl ModelFileHeader {
pub fn calculate_stack_size(&self) -> u32 { pub fn calculate_stack_size(&self) -> u32 {
// From https://github.com/Ottermandias/Penumbra.GameData/blob/44021b93e6901c84b739bbf4d1c6350f4486cdbf/Files/MdlFile.cs#L11 // From https://github.com/Ottermandias/Penumbra.GameData/blob/44021b93e6901c84b739bbf4d1c6350f4486cdbf/Files/MdlFile.cs#L11
const NUM_VERTICES: u32 = 17;
self.vertex_declaration_count as u32 * NUM_VERTICES * VERTEX_ELEMENT_SIZE as u32 self.vertex_declaration_count as u32 * NUM_VERTICES * VERTEX_ELEMENT_SIZE as u32
} }
} }

View file

@ -3,6 +3,7 @@
use std::io::SeekFrom; use std::io::SeekFrom;
use binrw::{BinRead, BinResult, binrw, BinWrite}; use binrw::{BinRead, BinResult, binrw, BinWrite};
use crate::model::NUM_VERTICES;
// Marker for end of stream (0xFF) // Marker for end of stream (0xFF)
const END_OF_STREAM: u8 = 0xFF; const END_OF_STREAM: u8 = 0xFF;
@ -75,7 +76,7 @@ pub(crate) fn vertex_element_parser(count: u16) -> BinResult<Vec<VertexDeclarati
} }
} }
let to_seek = 17 * 8 - (declaration.elements.len() + 1) * 8; let to_seek = NUM_VERTICES as usize * 8 - (declaration.elements.len() + 1) * 8;
reader.seek(SeekFrom::Current(to_seek as i64))?; reader.seek(SeekFrom::Current(to_seek as i64))?;
} }
@ -92,10 +93,15 @@ pub(crate) fn vertex_element_writer(
element.write_options(writer, endian, ())?; element.write_options(writer, endian, ())?;
} }
writer.write_all(&[END_OF_STREAM])?; VertexElement {
stream: END_OF_STREAM,
offset: 0,
vertex_type: VertexType::Single1,
vertex_usage: VertexUsage::Position,
usage_index: 0
}.write_options(writer, endian, ())?;
// We have a -1 here like we do in read, because writing the EOF (255) pushes our cursor forward. let to_seek = (NUM_VERTICES as usize - 1 - declaration.elements.len()) * 8;
let to_seek = 17 * 8 - (declaration.elements.len()) * 8 - 1;
writer.seek(SeekFrom::Current(to_seek as i64))?; writer.seek(SeekFrom::Current(to_seek as i64))?;
} }