handle empty skin tables

This commit is contained in:
Robin Appelman 2023-12-27 20:46:49 +01:00
commit 8d8f7e6158

View file

@ -13,9 +13,11 @@ pub use crate::vvd::Vvd;
use bytemuck::{pod_read_unaligned, Pod}; use bytemuck::{pod_read_unaligned, Pod};
pub use error::*; pub use error::*;
pub use handle::Handle; pub use handle::Handle;
use itertools::Either;
pub use shared::*; pub use shared::*;
use std::any::type_name; use std::any::type_name;
use std::fs; use std::fs;
use std::iter::once;
use std::mem::size_of; use std::mem::size_of;
use std::path::Path; use std::path::Path;
@ -63,13 +65,22 @@ impl Model {
} }
pub fn skin_tables(&self) -> impl Iterator<Item = SkinTable> { pub fn skin_tables(&self) -> impl Iterator<Item = SkinTable> {
self.mdl if self.mdl.header.skin_reference_count > 0 {
.skin_table Either::Left(
.chunks(self.mdl.header.skin_reference_count as usize) self.mdl
.map(|chunk| SkinTable { .skin_table
table: chunk, .chunks(self.mdl.header.skin_reference_count as usize)
textures: &self.mdl.textures, .map(|chunk| SkinTable {
}) table: chunk,
textures: &self.mdl.textures,
}),
)
} else {
Either::Right(once(SkinTable {
table: &[],
textures: &[],
}))
}
} }
pub fn meshes(&self) -> impl Iterator<Item = Mesh> { pub fn meshes(&self) -> impl Iterator<Item = Mesh> {