mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
more object convert work
This commit is contained in:
parent
88c6afce95
commit
bdaa8fe6bc
3 changed files with 56 additions and 44 deletions
|
|
@ -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(),
|
||||
};
|
||||
|
||||
|
|
|
|||
16
src/data.rs
16
src/data.rs
|
|
@ -9,7 +9,7 @@ use std::fmt;
|
|||
use std::io::{Error, ErrorKind};
|
||||
use std::iter::once;
|
||||
use std::mem::size_of;
|
||||
use std::ops::Index;
|
||||
use std::ops::{Add, Index};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Directories {
|
||||
|
|
@ -216,7 +216,7 @@ impl BinRead for Name {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, BinRead)]
|
||||
#[derive(Debug, Clone, Copy, BinRead)]
|
||||
pub struct Vector {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
|
|
@ -229,6 +229,18 @@ impl Vector {
|
|||
}
|
||||
}
|
||||
|
||||
impl Add<Vector> for Vector {
|
||||
type Output = Vector;
|
||||
|
||||
fn add(self, rhs: Vector) -> Self::Output {
|
||||
Vector {
|
||||
x: self.x + rhs.x,
|
||||
y: self.y + rhs.y,
|
||||
z: self.z + rhs.z,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vector> for [f32; 3] {
|
||||
fn from(vector: Vector) -> Self {
|
||||
[vector.x, vector.y, vector.z]
|
||||
|
|
|
|||
21
src/lib.rs
21
src/lib.rs
|
|
@ -1,5 +1,5 @@
|
|||
mod bspfile;
|
||||
mod data;
|
||||
pub mod data;
|
||||
mod reader;
|
||||
|
||||
use crate::bspfile::LumpType;
|
||||
|
|
@ -371,6 +371,25 @@ impl<'a> Handle<'a, Face> {
|
|||
EdgeDirection::LastToFirst => edge.end_index,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn is_visible(&self) -> bool {
|
||||
self.texture()
|
||||
.map(|texture| {
|
||||
!texture.flags.intersects(
|
||||
TextureFlags::LIGHT
|
||||
| TextureFlags::SKY2D
|
||||
| TextureFlags::SKY
|
||||
| TextureFlags::WARP
|
||||
| TextureFlags::TRANS
|
||||
| TextureFlags::TRIGGER
|
||||
| TextureFlags::HINT
|
||||
| TextureFlags::SKIP
|
||||
| TextureFlags::NODRAW
|
||||
| TextureFlags::HITBOX,
|
||||
)
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<'_, Node> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue