mirror of
https://codeberg.org/icewind/vmdl.git
synced 2026-06-04 00:54:14 +02:00
better vertex indices
This commit is contained in:
parent
88bcdb35e7
commit
3649ffd9b2
7 changed files with 75 additions and 56 deletions
|
|
@ -2,9 +2,11 @@ mod raw;
|
|||
|
||||
use crate::ModelError;
|
||||
use binrw::BinReaderExt;
|
||||
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;
|
||||
|
||||
|
|
@ -140,7 +142,6 @@ impl Mesh {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StripGroup {
|
||||
// todo vertex indexes
|
||||
// todo topologies
|
||||
pub indices: Vec<u16>,
|
||||
pub vertices: Vec<Vertex>,
|
||||
|
|
@ -192,27 +193,35 @@ impl StripGroup {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Strip {
|
||||
// todo vertex indexes
|
||||
// todo bone state changes
|
||||
pub vertices: Vec<Vertex>,
|
||||
vertices: Range<usize>,
|
||||
pub flags: StripFlags,
|
||||
indices: Range<usize>,
|
||||
}
|
||||
|
||||
impl Strip {
|
||||
fn read(data: &[u8], header: StripHeader) -> Result<Self> {
|
||||
fn read(_data: &[u8], header: StripHeader) -> Result<Self> {
|
||||
Ok(Strip {
|
||||
vertices: header
|
||||
.vertex_indexes()
|
||||
.map(|index| {
|
||||
let data = data.get(index..).ok_or_else(|| ModelError::OutOfBounds {
|
||||
data: "Vertex",
|
||||
offset: index,
|
||||
})?;
|
||||
let mut reader = Cursor::new(data);
|
||||
reader.read_le().map_err(ModelError::from)
|
||||
})
|
||||
.collect::<Result<_>>()?,
|
||||
vertices: header.vertex_indexes(),
|
||||
indices: header.index_indexes(),
|
||||
flags: header.flags,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn vertices(&self) -> impl Iterator<Item = usize> + 'static {
|
||||
self.vertices.clone()
|
||||
}
|
||||
|
||||
pub fn indices(&self) -> impl Iterator<Item = [usize; 3]> + 'static {
|
||||
if self.flags.contains(StripFlags::IS_TRI_STRIP) {
|
||||
let offset = self.indices.start;
|
||||
Either::Left((0..self.indices.len()).map(move |i| {
|
||||
let cw = i & 1;
|
||||
let idx = offset + i;
|
||||
[idx, idx + 1 - cw, idx + 2 - cw]
|
||||
}))
|
||||
} else {
|
||||
Either::Right(self.indices.clone().step_by(3).map(|i| [i, i + 1, i + 2]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use crate::index_range;
|
|||
use binrw::BinRead;
|
||||
use bitflags::bitflags;
|
||||
use std::mem::size_of;
|
||||
use std::ops::Range;
|
||||
|
||||
#[derive(Debug, Clone, BinRead)]
|
||||
pub struct VtxHeader {
|
||||
|
|
@ -169,18 +170,15 @@ bitflags! {
|
|||
|
||||
impl StripHeader {
|
||||
/// Index into the VVD file vertexes
|
||||
pub fn vertex_indexes(&self) -> impl Iterator<Item = usize> {
|
||||
index_range(
|
||||
self.vertex_offset,
|
||||
self.vertex_count,
|
||||
size_of::<u16>(), // Vertex index from .VVD's vertex array
|
||||
)
|
||||
pub fn vertex_indexes(&self) -> Range<usize> {
|
||||
self.vertex_offset as usize..(self.vertex_offset + self.vertex_count) as usize
|
||||
}
|
||||
|
||||
pub fn index_indexes(&self) -> impl Iterator<Item = usize> {
|
||||
index_range(self.index_offset, self.index_count, size_of::<Vertex>())
|
||||
pub fn index_indexes(&self) -> Range<usize> {
|
||||
self.index_offset as usize..(self.index_offset + self.index_count) as usize
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn bone_state_change_indexes(&self) -> impl Iterator<Item = usize> {
|
||||
index_range(
|
||||
self.bone_state_change_offset,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue