mirror of
https://codeberg.org/icewind/vmdl.git
synced 2026-06-04 00:54:14 +02:00
fully switch to bytemuck for reading
This commit is contained in:
parent
473d6eecc5
commit
bb4dfddde2
11 changed files with 38 additions and 130 deletions
|
|
@ -5,8 +5,6 @@ pub use raw::header2::*;
|
|||
|
||||
use crate::mdl::raw::{BodyPartHeader, Bone, MeshHeader, ModelHeader};
|
||||
use crate::{read_indexes, read_relative, FixedString, ModelError, ReadRelative, Readable};
|
||||
use binrw::BinReaderExt;
|
||||
use std::io::Cursor;
|
||||
|
||||
type Result<T> = std::result::Result<T, ModelError>;
|
||||
|
||||
|
|
@ -19,8 +17,7 @@ pub struct Mdl {
|
|||
|
||||
impl Mdl {
|
||||
pub fn read(data: &[u8]) -> Result<Self> {
|
||||
let mut reader = Cursor::new(data);
|
||||
let header: StudioHeader = reader.read_le()?;
|
||||
let header = <StudioHeader as Readable>::read(data)?;
|
||||
let bones = read_indexes(header.bone_indexes(), data).collect::<Result<_>>()?;
|
||||
Ok(Mdl {
|
||||
bones,
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
use crate::mdl::raw::*;
|
||||
use crate::mdl::Bone;
|
||||
use crate::{index_range, FixedString, Vector};
|
||||
use binrw::BinRead;
|
||||
use crate::{index_range, Vector};
|
||||
use std::mem::size_of;
|
||||
|
||||
pub const FILETYPE_ID: i32 = i32::from_be_bytes(*b"IDST");
|
||||
pub const MDL_VERSION: i32 = 48;
|
||||
|
||||
#[derive(Debug, Clone, BinRead)]
|
||||
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
|
||||
#[repr(C)]
|
||||
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!
|
||||
pub name: FixedString<64>,
|
||||
pub name: [u8; 64],
|
||||
pub data_length: i32,
|
||||
|
||||
pub eye_position: Vector, // Position of player viewpoint relative to model origin
|
||||
|
|
@ -175,7 +175,8 @@ pub struct StudioHeader {
|
|||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(BinRead)]
|
||||
#[derive(Zeroable, Pod)]
|
||||
#[repr(C)]
|
||||
pub struct ModelFlags: u32 {
|
||||
const AUTOGENERATED_HITBOX = 0x00000001;
|
||||
const USES_ENV_CUBEMAP = 0x00000002;
|
||||
|
|
@ -308,4 +309,4 @@ impl StudioHeader {
|
|||
}
|
||||
}
|
||||
|
||||
static_assertions::const_assert_eq!(size_of::<StudioHeader>() - size_of::<FixedString<0>>(), 408);
|
||||
static_assertions::const_assert_eq!(size_of::<StudioHeader>(), 408);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use crate::{index_range, FixedString, Pod};
|
||||
use crate::{index_range, FixedString};
|
||||
use crate::{Quaternion, RadianEuler, Vector};
|
||||
use binrw::BinRead;
|
||||
use bitflags::bitflags;
|
||||
use bytemuck::Zeroable;
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use std::mem::size_of;
|
||||
|
||||
pub mod header;
|
||||
pub mod header2;
|
||||
|
||||
#[derive(Debug, Clone, BinRead)]
|
||||
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
|
||||
#[repr(C)]
|
||||
pub struct Bone {
|
||||
pub sz_name_index: i32,
|
||||
pub parent: i32, // parent bone
|
||||
|
|
@ -34,7 +34,8 @@ pub struct Bone {
|
|||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(BinRead)]
|
||||
#[derive(Zeroable, Pod)]
|
||||
#[repr(C)]
|
||||
pub struct BoneFlags: u32 {
|
||||
const BONE_PHYSICALLY_SIMULATED = 0x00000001;
|
||||
const BONE_PHYSICS_PROCEDURAL = 0x00000002;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue