fully switch to bytemuck for reading

This commit is contained in:
Robin Appelman 2022-03-19 16:46:32 +01:00
commit bb4dfddde2
11 changed files with 38 additions and 130 deletions

View file

@ -1,11 +1,9 @@
mod raw;
use crate::{read_relative, ModelError, ReadRelative};
use binrw::BinReaderExt;
use crate::{read_relative, ModelError, ReadRelative, Readable};
use itertools::Either;
use raw::*;
pub use raw::{MeshFlags, StripFlags, StripGroupFlags, Vertex};
use std::io::Cursor;
use std::ops::Range;
pub const MDL_VERSION: i32 = 7;
@ -20,8 +18,7 @@ pub struct Vtx {
impl Vtx {
pub fn read(data: &[u8]) -> Result<Self> {
let mut reader = Cursor::new(data);
let header: VtxHeader = reader.read_le()?;
let header = <VtxHeader as Readable>::read(data)?;
Ok(Vtx {
body_parts: read_relative(data, header.body_indexes())?,
header,

View file

@ -1,11 +1,11 @@
use crate::{index_range, Pod};
use binrw::BinRead;
use bitflags::bitflags;
use bytemuck::Zeroable;
use std::mem::size_of;
use std::ops::Range;
#[derive(Debug, Clone, BinRead)]
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
#[repr(C)]
pub struct VtxHeader {
pub version: i32,
pub vertex_cache_size: i32,
@ -103,7 +103,7 @@ impl MeshHeader {
}
bitflags! {
#[derive(BinRead, Zeroable, Pod)]
#[derive(Zeroable, Pod)]
#[repr(C)]
pub struct MeshFlags: u8 {
const IS_TEETH = 0x01;
@ -150,7 +150,7 @@ impl StripGroupHeader {
}
bitflags! {
#[derive(BinRead, Zeroable, Pod)]
#[derive(Zeroable, Pod)]
#[repr(C)]
pub struct StripGroupFlags: u8 {
const IS_FLEXED = 0x01;
@ -177,7 +177,7 @@ pub struct StripHeader {
static_assertions::const_assert_eq!(size_of::<StripHeader>(), 27);
bitflags! {
#[derive(BinRead, Zeroable, Pod)]
#[derive(Zeroable, Pod)]
#[repr(C)]
pub struct StripFlags: u8 {
const IS_TRI_LIST = 0x01;