mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
convert models in obj
This commit is contained in:
parent
0bad24a370
commit
88c6afce95
1 changed files with 36 additions and 27 deletions
|
|
@ -8,33 +8,50 @@ fn main() -> Result<(), MainError> {
|
|||
let data = std::fs::read(args.next().expect("No demo file provided"))?;
|
||||
let bsp = vbsp::Bsp::read(&data)?;
|
||||
|
||||
let exclude_faces = TextureFlags::LIGHT
|
||||
| TextureFlags::SKY2D
|
||||
| TextureFlags::SKY
|
||||
| TextureFlags::WARP
|
||||
| TextureFlags::TRANS
|
||||
| TextureFlags::TRIGGER
|
||||
| TextureFlags::HINT
|
||||
| TextureFlags::SKIP
|
||||
| TextureFlags::NODRAW
|
||||
| TextureFlags::HITBOX;
|
||||
|
||||
let vertices = bsp
|
||||
.vertices
|
||||
.iter()
|
||||
.map(|vertex| <[f32; 3]>::from(&vertex.position))
|
||||
.collect();
|
||||
|
||||
let polygons = bsp
|
||||
.original_faces()
|
||||
.filter(|face| {
|
||||
face.texture()
|
||||
.map(|texture| {
|
||||
!texture.flags.intersects(
|
||||
TextureFlags::LIGHT
|
||||
| TextureFlags::SKY2D
|
||||
| TextureFlags::SKY
|
||||
| TextureFlags::SKIP
|
||||
| TextureFlags::NODRAW,
|
||||
let objects = bsp
|
||||
.models()
|
||||
.next() // only do "worldspawn" for now
|
||||
.into_iter()
|
||||
.map(|model| Group {
|
||||
name: "".to_string(),
|
||||
index: 0,
|
||||
material: None,
|
||||
polys: model
|
||||
.faces()
|
||||
.filter(|face| {
|
||||
face.texture()
|
||||
.map(|texture| !texture.flags.intersects(exclude_faces))
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.map(|face| {
|
||||
SimplePolygon(
|
||||
face.vertex_indexes()
|
||||
.map(|vertex| IndexTuple(vertex as usize, None, None))
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
.unwrap_or_default()
|
||||
.collect(),
|
||||
})
|
||||
.map(|face| {
|
||||
SimplePolygon(
|
||||
face.vertex_indexes()
|
||||
.map(|vertex| IndexTuple(vertex as usize, None, None))
|
||||
.collect(),
|
||||
)
|
||||
.map(|group| Object {
|
||||
name: "".to_string(),
|
||||
groups: vec![group],
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
@ -42,15 +59,7 @@ fn main() -> Result<(), MainError> {
|
|||
position: vertices,
|
||||
texture: Vec::new(),
|
||||
normal: Vec::new(),
|
||||
objects: vec![Object {
|
||||
name: "".to_string(),
|
||||
groups: vec![Group {
|
||||
name: "".to_string(),
|
||||
index: 0,
|
||||
material: None,
|
||||
polys: polygons,
|
||||
}],
|
||||
}],
|
||||
objects,
|
||||
material_libs: Vec::new(),
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue