gltf: per mesh primitive

This commit is contained in:
Robin Appelman 2023-12-16 22:21:58 +01:00
commit a45ce6dfb9
5 changed files with 253 additions and 152 deletions

View file

@ -87,6 +87,28 @@ impl Model {
vtx,
})
}
/// 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)
}
pub fn name(&self) -> &str {
self.mdl.name.as_str()
}
}
pub struct SkinTable<'a> {

View file

@ -15,6 +15,7 @@ type Result<T> = std::result::Result<T, ModelError>;
#[derive(Debug, Clone)]
pub struct Mdl {
pub name: FixedString<64>,
pub header: StudioHeader,
pub bones: Vec<Bone>,
pub body_parts: Vec<BodyPart>,
@ -26,6 +27,7 @@ pub struct Mdl {
impl Mdl {
pub fn read(data: &[u8]) -> Result<Self> {
let header = <StudioHeader as Readable>::read(data)?;
let name = header.name.try_into()?;
let mut textures = read_relative_iter(data, header.texture_indexes())
.collect::<Result<Vec<TextureInfo>>>()?;
let texture_dirs_indexes =
@ -44,6 +46,7 @@ impl Mdl {
let bones = read_indexes(header.bone_indexes(), data).collect::<Result<_>>()?;
Ok(Mdl {
name,
bones,
body_parts: header
.body_part_indexes()

View file

@ -130,7 +130,7 @@ impl From<RadianEuler> for Euler<Deg<f32>> {
}
/// Fixed length, null-terminated string
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default, Copy)]
pub struct FixedString<const LEN: usize>(ArrayString<LEN>);
impl<const LEN: usize> TryFrom<[u8; LEN]> for FixedString<LEN> {