1
0
Fork 0
mirror of https://codeberg.org/icewind/vbsp.git synced 2026-06-03 10:44:07 +02:00

more object convert work

This commit is contained in:
Robin Appelman 2020-06-28 15:04:23 +02:00
commit bdaa8fe6bc
3 changed files with 56 additions and 44 deletions

View file

@ -1,6 +1,5 @@
use main_error::MainError;
use obj::{Group, IndexTuple, Obj, ObjData, Object, SimplePolygon};
use vbsp::TextureFlags;
fn main() -> Result<(), MainError> {
let mut args = std::env::args();
@ -8,58 +7,40 @@ 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
let vertices: Vec<_> = bsp
.vertices
.iter()
.map(|vertex| <[f32; 3]>::from(&vertex.position))
.map(|vertex| <[f32; 3]>::from(vertex.position))
.collect();
let objects = bsp
.models()
.next() // only do "worldspawn" for now
.into_iter()
.map(|model| Group {
let world_model = bsp.models().next().unwrap();
let world_polygons = world_model
.faces()
.filter(|face| face.is_visible())
.map(|face| {
face.vertex_indexes()
.map(|vertex_index| IndexTuple(vertex_index as usize, None, None))
.collect()
})
.map(SimplePolygon)
.collect();
let world_object = Object {
name: "".to_string(),
groups: vec![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(),
)
})
.collect(),
})
.map(|group| Object {
name: "".to_string(),
groups: vec![group],
})
.collect();
polys: world_polygons,
}],
};
let obj_data = ObjData {
position: vertices,
texture: Vec::new(),
normal: Vec::new(),
objects,
objects: vec![world_object],
material_libs: Vec::new(),
};