bone weight cleanup

This commit is contained in:
Robin Appelman 2023-12-30 20:50:28 +01:00
commit 38e44207ea
3 changed files with 23 additions and 8 deletions

View file

@ -10,9 +10,9 @@ pub const MDL_VERSION: i32 = 48;
pub struct StudioHeader {
pub id: i32,
pub version: i32,
pub checksum: [u8; 4], // This has to be the same in the phy and vtx files to load!
checksum: [u8; 4], // This has to be the same in the phy and vtx files to load!
pub name: [u8; 64],
pub data_length: i32,
data_length: i32,
pub eye_position: Vector, // Position of player viewpoint relative to model origin
pub illumination_position: Vector, // Position (relative to model origin) used to calculate ambient light contribution and cubemap reflections for the entire model.

View file

@ -2,7 +2,7 @@ mod raw;
use crate::vvd::raw::{VertexFileFixup, VvdHeader};
use crate::{read_relative, read_relative_iter, ModelError, Readable};
pub use raw::{BoneWeight, Tangent, Vertex};
pub use raw::{BoneWeights, Tangent, Vertex};
type Result<T> = std::result::Result<T, ModelError>;

View file

@ -1,5 +1,6 @@
use crate::{index_range, ReadableRelative, Vector};
use bytemuck::{Pod, Zeroable};
use std::cmp::min;
use std::mem::size_of;
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
@ -67,7 +68,7 @@ impl ReadableRelative for VertexFileFixup {}
#[derive(Debug, Clone, Zeroable, Pod, Copy)]
#[repr(C)]
pub struct Vertex {
pub bone_weights: BoneWeight,
pub bone_weights: BoneWeights,
pub position: Vector,
pub normal: Vector,
pub texture_coordinates: [f32; 2],
@ -79,13 +80,27 @@ static_assertions::const_assert_eq!(size_of::<Vertex>(), 48);
#[derive(Debug, Clone, Zeroable, Pod, Copy)]
#[repr(C)]
pub struct BoneWeight {
pub weight: [f32; 3],
pub bone: [u8; 3],
pub bone_count: u8,
pub struct BoneWeights {
weight: [f32; 3],
bone: [u8; 3],
bone_count: u8,
}
static_assertions::const_assert_eq!(size_of::<BoneWeight>(), 16);
impl BoneWeights {
pub fn weights(&self) -> impl Iterator<Item = BoneWeight> + '_ {
(0..min(self.bone_count as usize, 2)).map(|i| BoneWeight {
weight: self.weight[i],
bone_id: self.bone[i],
})
}
}
pub struct BoneWeight {
pub bone_id: u8,
pub weight: f32,
}
static_assertions::const_assert_eq!(size_of::<BoneWeights>(), 16);
#[derive(Debug, Clone, Zeroable, Pod, Copy)]
#[repr(C)]