animation blocks

This commit is contained in:
Robin Appelman 2024-08-26 14:59:38 +02:00
commit 67fed7fbaf
5 changed files with 42 additions and 11 deletions

View file

@ -6,7 +6,7 @@ pub mod vtx;
pub mod vvd;
pub use crate::mdl::Mdl;
use crate::mdl::{Bone, PoseParameterDescription, TextureInfo};
use crate::mdl::{Bone, ModelFlags, PoseParameterDescription, TextureInfo};
pub use crate::vtx::Vtx;
use crate::vvd::Vertex;
pub use crate::vvd::Vvd;
@ -134,9 +134,10 @@ impl Model {
}
pub fn root_transform(&self) -> Matrix4<f32> {
if self.bones().next().map(|bone| bone.name.as_str()) == Some("static_prop") {
if self.mdl.header.flags.contains(ModelFlags::STATIC_PROP) {
return Matrix4::identity();
}
self.bones()
.find(|bone| bone.name != "root")
.map(|bone| bone.pose_to_bone)

View file

@ -27,6 +27,8 @@ pub struct Mdl {
pub surface_prop: String,
pub key_values: Option<String>,
pub local_animations: Vec<AnimationDescription>,
pub animation_block_source: String,
pub animation_blocks: Vec<AnimationBlock>,
pub pose_parameters: Vec<PoseParameterDescription>,
pub attachments: Vec<StudioAttachment>,
pub hit_boxes: Vec<HitBoxSet>,
@ -62,6 +64,9 @@ impl Mdl {
.then(|| read_single(data, header.key_value_index))
.transpose()?;
let local_animations = read_relative(data, header.local_animation_indexes())?;
let animation_block_source: String = read_single(data, header.anim_blocks_name_index)?;
let animation_blocks = read_relative(data, header.animation_block_indexes())?;
let pose_parameters = read_relative(data, header.local_pose_param_indexes())?;
let attachments = read_relative(data, header.attachment_indexes())?;
let hit_boxes = read_relative(data, header.hitbox_set_indexes())?;
@ -89,6 +94,8 @@ impl Mdl {
key_values,
pose_parameters,
local_animations,
animation_block_source,
animation_blocks,
attachments,
hit_boxes,
})

View file

@ -1,4 +1,5 @@
use crate::{ModelError, ReadRelative};
use crate::vvd::Vertex;
use crate::{ModelError, ReadRelative, ReadableRelative};
use bitflags::bitflags;
use bytemuck::{Pod, Zeroable};
use std::mem::size_of;
@ -86,6 +87,8 @@ pub struct AnimationDescription {
pub name: String,
pub fps: f32,
pub frame_count: i32,
pub animation_block: i32,
pub animation: i32,
}
impl ReadRelative for AnimationDescription {
@ -102,10 +105,21 @@ impl ReadRelative for AnimationDescription {
name: String::read(name_bytes, ())?,
fps: header.fps,
frame_count: header.frame_count,
animation_block: header.animation_block,
animation: header.animation_index,
})
}
}
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
#[repr(C)]
pub struct AnimationBlock {
start: i32,
end: i32,
}
impl ReadableRelative for AnimationBlock {}
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
#[repr(C)]
pub struct AnimationHeader {

View file

@ -134,7 +134,7 @@ pub struct StudioHeader {
// Note that the SDK only compiles as 32-bit, so an int and a pointer are the same size (4 bytes)
// mstudioanimblock_t
anim_blocks_name_index: i32,
pub(crate) anim_blocks_name_index: i32,
anim_blocks_count: i32,
anim_blocks_index: i32,
@ -217,7 +217,11 @@ impl StudioHeader {
}
pub fn hitbox_set_indexes(&self) -> impl Iterator<Item = usize> {
index_range(self.hitbox_set_offset, self.hitbox_set_count, size_of::<HitBoxSetHeader>())
index_range(
self.hitbox_set_offset,
self.hitbox_set_count,
size_of::<HitBoxSetHeader>(),
)
}
pub fn local_animation_indexes(&self) -> impl Iterator<Item = usize> {
@ -265,7 +269,11 @@ impl StudioHeader {
}
pub fn attachment_indexes(&self) -> impl Iterator<Item = usize> {
index_range(self.attachment_offset, self.attachment_count, size_of::<StudioAttachmentHeader>())
index_range(
self.attachment_offset,
self.attachment_count,
size_of::<StudioAttachmentHeader>(),
)
}
pub fn local_node_indexes(&self) -> impl Iterator<Item = usize> {
@ -313,11 +321,11 @@ impl StudioHeader {
}
pub fn animation_block_indexes(&self) -> impl Iterator<Item = usize> {
index_range(self.anim_blocks_index, self.anim_blocks_count, 1)
}
pub fn animation_block_name_indexes(&self) -> impl Iterator<Item = usize> {
index_range(self.anim_blocks_name_index, self.anim_blocks_count, 1)
index_range(
self.anim_blocks_index,
self.anim_blocks_count,
size_of::<AnimationBlock>(),
)
}
pub fn flex_controller_ui_indexes(&self) -> impl Iterator<Item = usize> {