header cleanup

This commit is contained in:
Robin Appelman 2023-12-29 19:42:16 +01:00
commit cfba159890
5 changed files with 43 additions and 54 deletions

View file

@ -83,6 +83,7 @@
clippy
cargo-audit
cargo-msrv
cargo-semver-checks
] ++ exampleBuildInputs;
LD_LIBRARY_PATH = with pkgs; "/run/opengl-driver/lib/:${lib.makeLibraryPath ([libGL libGLU])}";

View file

@ -119,20 +119,10 @@ impl Model {
/// Calculate bounding coordinates of the model
pub fn bounding_box(&self) -> (Vector, Vector) {
let mut min = Vector::from([f32::MAX, f32::MAX, f32::MAX]);
let mut max = Vector::from([f32::MIN, f32::MIN, f32::MIN]);
for point in self.vertices() {
let p = point.position;
min.x = f32::min(min.x, p.x);
min.y = f32::min(min.y, p.y);
min.z = f32::min(min.z, p.z);
max.x = f32::max(max.x, p.x);
max.y = f32::max(max.y, p.y);
max.z = f32::max(max.z, p.z);
}
(min, max)
(
self.mdl.header.bounding_box[0],
self.mdl.header.bounding_box[1],
)
}
pub fn name(&self) -> &str {
@ -147,8 +137,8 @@ impl Model {
self.bones()
.next()
.map(|bone| Quaternion::from(bone.rot))
.map(|rotation| Matrix4::from(rotation))
.unwrap_or_else(|| Matrix4::identity())
.map(Matrix4::from)
.unwrap_or_else(Matrix4::identity)
}
}

View file

@ -24,7 +24,7 @@ pub struct BoneHeader {
pub proc_index: i32, // procedural rule
pub physics_bone: i32, // index into physically simulated bone
pub surface_prop_idx: i32, // index into string table for property name
pub contents: BoneContentFlags,
pub contents: ContentFlags,
#[allow(dead_code)]
reserved: [i32; 8], // remove as appropriate
@ -51,7 +51,7 @@ pub struct Bone {
pub procedural_rules: Option<ProceduralBone>,
pub physics_bone: i32, // index into physically simulated bone
pub surface_prop: String,
pub contents: BoneContentFlags,
pub contents: ContentFlags,
}
impl ReadRelative for Bone {
@ -60,13 +60,13 @@ impl ReadRelative for Bone {
fn read(data: &[u8], header: Self::Header) -> Result<Self, ModelError> {
let name_bytes =
data.get(header.sz_name_index as usize..)
.ok_or_else(|| ModelError::OutOfBounds {
.ok_or(ModelError::OutOfBounds {
data: "bone name",
offset: header.sz_name_index as usize,
})?;
let surface_prop_bytes = data
.get(header.surface_prop_idx as usize..)
.ok_or_else(|| ModelError::OutOfBounds {
let surface_prop_bytes =
data.get(header.surface_prop_idx as usize..)
.ok_or(ModelError::OutOfBounds {
data: "bone surface property",
offset: header.surface_prop_idx as usize,
})?;
@ -75,7 +75,7 @@ impl ReadRelative for Bone {
let proc_bytes = (header.proc_index != 0)
.then(|| {
data.get(header.proc_index as usize..)
.ok_or_else(|| ModelError::OutOfBounds {
.ok_or(ModelError::OutOfBounds {
data: "bone surface property",
offset: header.proc_index as usize,
})
@ -272,10 +272,10 @@ bitflags! {
#[derive(Zeroable, Pod, Copy, Clone, Debug)]
#[repr(C)]
pub struct BoneContentFlags(u32);
pub struct ContentFlags(u32);
bitflags! {
impl BoneContentFlags: u32 {
impl ContentFlags: u32 {
const CONTENTS_SOLID = 0x01;
const CONTENTS_WINDOW = 0x02;
const CONTENTS_AUX = 0x04;

View file

@ -16,10 +16,8 @@ pub struct StudioHeader {
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.
pub hull_min: Vector, // Corner of model hull box with the least X/Y/Z values
pub hull_max: Vector, // Opposite corner of model hull box
pub view_bb_min: Vector,
pub view_bb_max: Vector,
pub bounding_box: [Vector; 2],
pub view_bounding_box: [Vector; 2],
pub flags: ModelFlags,
@ -43,8 +41,8 @@ pub struct StudioHeader {
local_seq_count: i32,
local_seq_offset: i32,
pub activity_list_version: i32, // ??
pub events_indexed: i32, // ??
activity_list_version: i32, // ??
events_indexed: i32, // ??
// VMT texture filenames
// mstudiotexture_t
@ -58,9 +56,9 @@ pub struct StudioHeader {
texture_dir_offset: i32,
// Each skin-family assigns a texture-id to a skin location
pub skin_reference_count: i32,
pub skin_family_count: i32,
pub skin_reference_offset: i32,
pub(crate) skin_reference_count: i32,
pub(crate) skin_family_count: i32,
pub(crate) skin_reference_offset: i32,
// mstudiobodyparts_t
body_part_count: i32,
@ -109,7 +107,7 @@ pub struct StudioHeader {
* from the start of the file.
*/
// Surface property value (single null-terminated string)
pub surface_prop_index: i32,
surface_prop_index: i32,
// Unusual: In this one index comes first, then count.
// Key-value mdl is a series of strings. If you can't find
@ -123,7 +121,7 @@ pub struct StudioHeader {
ik_lock_index: i32,
pub mass: f32, // Mass of object (4-bytes)
pub contents: i32, // ??
pub contents: ContentFlags, // ??
// Other models can be referenced for re-used sequences and animations
// (See also: The $includemodel QC option.)
@ -131,7 +129,7 @@ pub struct StudioHeader {
include_model_count: i32,
include_model_index: i32,
pub virtual_model: i32, // Placeholder for mutable-void*
virtual_model: i32, // Placeholder for mutable-void*
// Note that the SDK only compiles as 32-bit, so an int and a pointer are the same size (4 bytes)
// mstudioanimblock_t
@ -139,35 +137,35 @@ pub struct StudioHeader {
anim_blocks_count: i32,
anim_blocks_index: i32,
pub anim_block_model: i32, // Placeholder for mutable-void*
anim_block_model: i32, // Placeholder for mutable-void*
// Points to a series of bytes?
pub bone_table_name_index: i32,
bone_table_name_index: i32,
pub vertex_base: i32, // Placeholder for void*
pub offset_base: i32, // Placeholder for void*
vertex_base: i32, // Placeholder for void*
offset_base: i32, // Placeholder for void*
// Used with $constantdirectionallight from the QC
// Model should have flag #13 set if enabled
pub directional_dot_product: u8,
directional_dot_product: u8,
pub root_lod: u8, // Preferred rather than clamped
root_lod: u8, // Preferred rather than clamped
// 0 means any allowed, N means Lod 0 -> (N-1)
pub num_allowed_root_lods: u8,
num_allowed_root_lods: u8,
#[allow(dead_code)]
unused0: u8, // ??
#[allow(dead_code)]
unused1: i32, // ??
pub flex_controller_ui_count: i32,
pub flex_controller_ui_index: i32,
flex_controller_ui_count: i32,
flex_controller_ui_index: i32,
pub vert_anim_fixed_point_scale: f32,
pub unused2: i32,
vert_anim_fixed_point_scale: f32,
unused2: i32,
pub studio_hdr2_index: i32,
studio_hdr2_index: i32,
#[allow(dead_code)]
unused3: i32,

View file

@ -6,7 +6,7 @@ use std::fmt;
use std::fmt::{Display, Formatter};
use std::ops::{Add, Mul};
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
#[derive(Debug, Clone, Copy, Zeroable, Pod, PartialEq)]
#[repr(C)]
pub struct Vector {
pub x: f32,