From f6c2b98b8082d711c1d24d4f0212ef6f6c03e6c4 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 3 Nov 2024 11:00:33 -0500 Subject: [PATCH] Model: Make vertex declarations and enums public --- src/lib.rs | 2 +- src/model_vertex_declarations.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 309acae..5f50d89 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,7 +108,7 @@ mod sha1; mod model_file_operations; #[cfg(feature = "visual_data")] -mod model_vertex_declarations; +pub mod model_vertex_declarations; #[cfg(feature = "visual_data")] pub mod lgb; diff --git a/src/model_vertex_declarations.rs b/src/model_vertex_declarations.rs index e83f1c7..55502cf 100644 --- a/src/model_vertex_declarations.rs +++ b/src/model_vertex_declarations.rs @@ -11,6 +11,7 @@ const END_OF_STREAM: u8 = 0xFF; /// The format of the vertex stream. #[binrw] #[brw(repr = u8)] +#[repr(C)] #[derive(Copy, Clone, Debug, PartialEq)] pub enum VertexType { /// 1 32-bit float @@ -49,9 +50,31 @@ pub enum VertexType { UnsignedShort4 = 17, } +/// In bytes +pub fn get_vertex_type_size(vertex_type: VertexType) -> usize { + // TODO: Most of these are wrong + match vertex_type { + VertexType::Single1 => 4, + VertexType::Single2 => 8, + VertexType::Single3 => 12, + VertexType::Single4 => 16, + VertexType::Byte4 => 4, + VertexType::Short2 => 4, + VertexType::Short4 => 8, + VertexType::ByteFloat4 => 4, + VertexType::Short2n => 4, + VertexType::Short4n => 4, + VertexType::Half2 => 4, + VertexType::Half4 => 8, + VertexType::UnsignedShort2 => 4, + VertexType::UnsignedShort4 => 8, + } +} + /// What the vertex stream is used for. #[binrw] #[brw(repr = u8)] +#[repr(C)] #[derive(Copy, Clone, Debug, PartialEq)] pub enum VertexUsage { Position = 0, @@ -68,6 +91,7 @@ pub enum VertexUsage { #[binrw] #[derive(Copy, Clone, Debug, PartialEq)] #[allow(dead_code)] +#[repr(C)] #[brw(little)] pub struct VertexElement { pub stream: u8,