mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
face normals
This commit is contained in:
parent
cdf52722f8
commit
7702ca17a6
3 changed files with 31 additions and 0 deletions
|
|
@ -425,6 +425,16 @@ impl VisData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, BinRead)]
|
||||||
|
pub struct VertNormal {
|
||||||
|
pub normal: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, BinRead)]
|
||||||
|
pub struct VertNormalIndex {
|
||||||
|
pub index: i16,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Packfile {
|
pub struct Packfile {
|
||||||
zip: Mutex<ZipArchive<Cursor<Vec<u8>>>>,
|
zip: Mutex<ZipArchive<Cursor<Vec<u8>>>>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,4 +87,8 @@ impl<'a> Handle<'a, Face> {
|
||||||
.map(Either::Left)
|
.map(Either::Left)
|
||||||
.unwrap_or_else(|| Either::Right(self.triangulate().flatten()))
|
.unwrap_or_else(|| Either::Right(self.triangulate().flatten()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn normal(&self) -> Vector {
|
||||||
|
self.bsp.plane(self.plane_num as usize).unwrap().normal
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
src/lib.rs
17
src/lib.rs
|
|
@ -155,6 +155,7 @@ impl<'a> IntoIterator for &'a mut Leaves {
|
||||||
// TODO: Store all the allocated objects inline to improve cache usage
|
// TODO: Store all the allocated objects inline to improve cache usage
|
||||||
/// A parsed bsp file
|
/// A parsed bsp file
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct Bsp {
|
pub struct Bsp {
|
||||||
pub header: Header,
|
pub header: Header,
|
||||||
pub entities: Entities,
|
pub entities: Entities,
|
||||||
|
|
@ -179,6 +180,8 @@ pub struct Bsp {
|
||||||
pub displacements: Vec<DisplacementInfo>,
|
pub displacements: Vec<DisplacementInfo>,
|
||||||
pub displacement_vertices: Vec<DisplacementVertex>,
|
pub displacement_vertices: Vec<DisplacementVertex>,
|
||||||
pub displacement_triangles: Vec<DisplacementTriangle>,
|
pub displacement_triangles: Vec<DisplacementTriangle>,
|
||||||
|
vertex_normals: Vec<VertNormal>,
|
||||||
|
vertex_normal_indices: Vec<VertNormalIndex>,
|
||||||
pub static_props: PropStaticGameLump,
|
pub static_props: PropStaticGameLump,
|
||||||
pub pack: Packfile,
|
pub pack: Packfile,
|
||||||
}
|
}
|
||||||
|
|
@ -253,6 +256,12 @@ impl Bsp {
|
||||||
let displacement_triangles = bsp_file
|
let displacement_triangles = bsp_file
|
||||||
.lump_reader(LumpType::DisplacementTris)?
|
.lump_reader(LumpType::DisplacementTris)?
|
||||||
.read_vec(|r| r.read())?;
|
.read_vec(|r| r.read())?;
|
||||||
|
let vertex_normals = bsp_file
|
||||||
|
.lump_reader(LumpType::VertNormals)?
|
||||||
|
.read_vec(|r| r.read())?;
|
||||||
|
let vertex_normal_indices = bsp_file
|
||||||
|
.lump_reader(LumpType::VertNormalIndices)?
|
||||||
|
.read_vec(|r| r.read())?;
|
||||||
let game_lumps: GameLumpHeader = bsp_file.lump_reader(LumpType::GameLump)?.read()?;
|
let game_lumps: GameLumpHeader = bsp_file.lump_reader(LumpType::GameLump)?.read()?;
|
||||||
let pack = Packfile::read(bsp_file.lump_reader(LumpType::PakFile)?.into_data())?;
|
let pack = Packfile::read(bsp_file.lump_reader(LumpType::PakFile)?.into_data())?;
|
||||||
|
|
||||||
|
|
@ -284,6 +293,8 @@ impl Bsp {
|
||||||
displacements,
|
displacements,
|
||||||
displacement_vertices,
|
displacement_vertices,
|
||||||
displacement_triangles,
|
displacement_triangles,
|
||||||
|
vertex_normals,
|
||||||
|
vertex_normal_indices,
|
||||||
static_props,
|
static_props,
|
||||||
pack,
|
pack,
|
||||||
};
|
};
|
||||||
|
|
@ -487,6 +498,12 @@ impl Bsp {
|
||||||
"static props",
|
"static props",
|
||||||
"static prop models",
|
"static prop models",
|
||||||
)?;
|
)?;
|
||||||
|
self.validate_indexes(
|
||||||
|
self.vertex_normal_indices.iter().map(|i| i.index),
|
||||||
|
&self.vertex_normals,
|
||||||
|
"vertex normal indices",
|
||||||
|
"vertex normals",
|
||||||
|
)?;
|
||||||
|
|
||||||
if self.nodes.is_empty() {
|
if self.nodes.is_empty() {
|
||||||
return Err(ValidationError::NoRootNode.into());
|
return Err(ValidationError::NoRootNode.into());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue