attachements wip

This commit is contained in:
Robin Appelman 2024-06-12 21:07:13 +02:00
commit 317518a821
3 changed files with 52 additions and 5 deletions

View file

@ -4,11 +4,10 @@ pub use raw::header::*;
pub use raw::header2::*;
pub use raw::*;
use std::mem::size_of;
use bytemuck::{Pod, Zeroable};
use crate::vvd::Vertex;
use crate::{
read_relative, read_relative_iter, read_single, FixedString, ModelError, ReadRelative, Readable,
};
use crate::{read_relative, read_relative_iter, read_single, FixedString, ModelError, ReadRelative, Readable, Transform3x4};
type Result<T> = std::result::Result<T, ModelError>;
@ -26,6 +25,7 @@ pub struct Mdl {
pub key_values: Option<String>,
pub local_animations: Vec<AnimationDescription>,
pub pose_parameters: Vec<PoseParameterDescription>,
pub attachments: Vec<StudioAttachment>,
}
impl Mdl {
@ -62,6 +62,7 @@ impl Mdl {
.transpose()?;
let local_animations = read_relative(data, header.local_animation_indexes())?;
let pose_parameters = read_relative(data, header.local_pose_param_indexes())?;
let attachments = read_relative(data, header.attachment_indexes())?;
Ok(Mdl {
name,
@ -86,6 +87,7 @@ impl Mdl {
key_values,
pose_parameters,
local_animations,
attachments,
})
}
}
@ -166,3 +168,24 @@ impl ReadRelative for TextureInfo {
})
}
}
#[derive(Debug, Clone)]
pub struct StudioAttachment {
pub name: String,
pub flags: AttachmentFlags,
pub local_bone: i32,
pub local: Transform3x4,
}
impl ReadRelative for StudioAttachment {
type Header = StudioAttachmentHeader;
fn read(data: &[u8], header: Self::Header) -> Result<Self> {
Ok(StudioAttachment {
name: String::read(&data[header.name_index as usize..], ())?.replace('\\', "/"),
flags: header.flags,
local: header.local,
local_bone: header.local_bone,
})
}
}

View file

@ -265,7 +265,7 @@ impl StudioHeader {
}
pub fn attachment_indexes(&self) -> impl Iterator<Item = usize> {
index_range(self.attachment_offset, self.attachment_count, 1)
index_range(self.attachment_offset, self.attachment_count, size_of::<StudioAttachmentHeader>())
}
pub fn local_node_indexes(&self) -> impl Iterator<Item = usize> {

View file

@ -1,4 +1,4 @@
use crate::{index_range, FixedString};
use crate::{index_range, FixedString, Transform3x4};
use crate::{ModelError, ReadRelative, Vector};
use bitflags::bitflags;
use bytemuck::{Pod, Zeroable};
@ -109,3 +109,27 @@ pub struct MeshTexture {
}
static_assertions::const_assert_eq!(size_of::<MeshTexture>(), 16 * 4);
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
#[repr(C)]
#[allow(dead_code)]
pub struct StudioAttachmentHeader {
pub name_index: i32,
pub flags: AttachmentFlags,
pub local_bone: i32,
pub local: Transform3x4,
pub padding: [i32; 8],
}
#[derive(Zeroable, Pod, Copy, Clone, Debug)]
#[repr(C)]
pub struct AttachmentFlags(i32);
bitflags! {
impl AttachmentFlags: i32 {
/// Vector48
const ATTACHMENT_WORLD_ALIGN = 0x10000;
}
}
static_assertions::const_assert_eq!(size_of::<StudioAttachmentHeader>(), 23 * 4);