From bf1d7cb20f38584d36ff37010fbd1647d8cfa298 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 8 Jan 2024 18:06:18 -0800 Subject: [PATCH] milestone: polygons on screen --- src/load_bsp.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/load_bsp.rs b/src/load_bsp.rs index 4bcf1a5..697ffe3 100644 --- a/src/load_bsp.rs +++ b/src/load_bsp.rs @@ -7,12 +7,62 @@ pub fn generate_indexed_models(input:&mut R)->Res Err(e)=>println!("load_bsp::generate_indexed_models read_to_end failed: {:?}",e), } - match vbsp::Bsp::read(s.as_slice()){ Ok(bsp)=>{ let mut spawn_point=crate::integer::Planar64Vec3::ZERO; let mut indexed_models=Vec::new(); + + let vertices: Vec<_> = bsp + .vertices + .iter() + .map(|vertex| <[f32; 3]>::from(vertex.position*0.01)) + .collect(); + + println!("num vertices={}",vertices.len()); + + for world_model in bsp.models(){ + + let world_polygons:Vec = world_model + .faces() + .filter(|face| face.is_visible()) + .map(|face| { + face.vertex_indexes() + .map(|vertex_index| obj::IndexTuple(vertex_index as usize, Some(0), Some(0))) + .collect() + }) + .map(obj::SimplePolygon) + .collect(); + + println!("num world_polygons={}",world_polygons.len()); + + let world_object = obj::Object { + name: "".to_string(), + groups: vec![obj::Group { + name: "".to_string(), + index: 0, + material: None, + polys: world_polygons, + }], + }; + + let obj_data = obj::ObjData { + position: vertices.clone(),//TODO: don't clone all vertices lmao + texture: vec![[0.0,0.0]], + normal: vec![[1.0,0.0,0.0]], + objects: vec![world_object], + material_libs: Vec::new(), + }; + + let mut new_indexed_models=crate::model::generate_indexed_model_list_from_obj(obj_data,glam::Vec4::ONE); + + for indexed_model in &mut new_indexed_models{ + indexed_model.instances.push(crate::model::ModelInstance{attributes:crate::model::CollisionAttributes::Decoration,..Default::default()}); + } + + indexed_models.append(&mut new_indexed_models); + } + Ok(crate::model::IndexedModelInstances{ textures:Vec::new(), models:indexed_models,