From a051f442df2479a3677640e01845bb690a0c6f43 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 2 Mar 2024 05:11:01 -0800 Subject: [PATCH] use entities & brushes instead of models --- src/bsp.rs | 74 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/src/bsp.rs b/src/bsp.rs index 9c83d51..0d215fe 100644 --- a/src/bsp.rs +++ b/src/bsp.rs @@ -47,8 +47,7 @@ where //the generated MeshIds in here will collide with the Loader Mesh Ids //but I can't think of a good workaround other than just remapping one later. - let (world_meshes,world_models):(Vec,Vec)=bsp.models().enumerate().map(|(mesh_id,world_model)|{ - let mesh_id=model::MeshId::new(mesh_id as u32); + let world_meshes:Vec=bsp.models().map(|world_model|{ //non-deduplicated let mut spam_pos=Vec::new(); let mut spam_tex=Vec::new(); @@ -73,7 +72,8 @@ where let normal_idx=spam_normal.len() as u32; spam_normal.push(valve_transform(normal.into())); let mut polygon_iter=face.vertex_positions().map(|vertex_position|{ - let vertex_xyz=vertex_position.into(); + //world_model.origin seems to always be 0,0,0 + let vertex_xyz=(world_model.origin+vertex_position).into(); let pos_idx=spam_pos.len(); spam_pos.push(valve_transform(vertex_xyz)); @@ -109,28 +109,54 @@ where physics_group.groups.push(polygon_group_id); model::PolygonGroup::PolygonList(model::PolygonList::new(polygon_list)) }).collect(); - ( - model::Mesh{ - unique_pos:spam_pos, - unique_tex:spam_tex, - unique_normal:spam_normal, - unique_color:vec![glam::Vec4::ONE], - unique_vertices:spam_vertices, - polygon_groups, - graphics_groups, - physics_groups:vec![physics_group], - }, - model::Model{ - mesh:mesh_id, - attributes:TEMP_TOUCH_ME_ATTRIBUTE, - transform:integer::Planar64Affine3::new( - integer::Planar64Mat3::default(), - valve_transform(world_model.origin.into()) - ), - color:glam::Vec4::ONE, - }, + model::Mesh{ + unique_pos:spam_pos, + unique_tex:spam_tex, + unique_normal:spam_normal, + unique_color:vec![glam::Vec4::ONE], + unique_vertices:spam_vertices, + polygon_groups, + graphics_groups, + physics_groups:vec![physics_group], + } + }).collect(); + + let world_models:Vec= + //one instance of the main world mesh + std::iter::once(( + //world_model + model::MeshId::new(0), + //model_origin + vbsp::Vector::from([0.0,0.0,0.0]), + //model_color + [255.0,255.0,255.0] + )).chain( + //entities sprinkle instances of the other meshes around + bsp.entities.iter() + .flat_map(|ent|ent.parse())//ignore entity parsing errors + .filter_map(|ent|match ent{ + vbsp::Entity::Brush(brush)=>Some(brush), + vbsp::Entity::BrushIllusionary(brush)=>Some(brush), + vbsp::Entity::BrushWall(brush)=>Some(brush), + vbsp::Entity::BrushWallToggle(brush)=>Some(brush), + _=>None, + }).flat_map(|brush| + //The first character of brush.model is '*' + brush.model[1..].parse().map(|mesh_id|//ignore parse int errors + (model::MeshId::new(mesh_id),brush.origin,brush.color) + ) ) - }).unzip(); + ).map(|(mesh_id,model_origin,model_color)|{ + model::Model{ + mesh:mesh_id, + attributes:TEMP_TOUCH_ME_ATTRIBUTE, + transform:integer::Planar64Affine3::new( + integer::Planar64Mat3::default(), + valve_transform(model_origin.into()) + ), + color:(glam::Vec3::from_array(model_color)/255.0).extend(1.0), + } + }).collect(); PartialMap1{ attributes:unique_attributes,