use entities & brushes instead of models

This commit is contained in:
Quaternions 2024-03-02 05:11:01 -08:00
parent 4f166e0d5c
commit a051f442df

View File

@ -47,8 +47,7 @@ where
//the generated MeshIds in here will collide with the Loader Mesh Ids //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. //but I can't think of a good workaround other than just remapping one later.
let (world_meshes,world_models):(Vec<model::Mesh>,Vec<model::Model>)=bsp.models().enumerate().map(|(mesh_id,world_model)|{ let world_meshes:Vec<model::Mesh>=bsp.models().map(|world_model|{
let mesh_id=model::MeshId::new(mesh_id as u32);
//non-deduplicated //non-deduplicated
let mut spam_pos=Vec::new(); let mut spam_pos=Vec::new();
let mut spam_tex=Vec::new(); let mut spam_tex=Vec::new();
@ -73,7 +72,8 @@ where
let normal_idx=spam_normal.len() as u32; let normal_idx=spam_normal.len() as u32;
spam_normal.push(valve_transform(normal.into())); spam_normal.push(valve_transform(normal.into()));
let mut polygon_iter=face.vertex_positions().map(|vertex_position|{ 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(); let pos_idx=spam_pos.len();
spam_pos.push(valve_transform(vertex_xyz)); spam_pos.push(valve_transform(vertex_xyz));
@ -109,28 +109,54 @@ where
physics_group.groups.push(polygon_group_id); physics_group.groups.push(polygon_group_id);
model::PolygonGroup::PolygonList(model::PolygonList::new(polygon_list)) model::PolygonGroup::PolygonList(model::PolygonList::new(polygon_list))
}).collect(); }).collect();
( model::Mesh{
model::Mesh{ unique_pos:spam_pos,
unique_pos:spam_pos, unique_tex:spam_tex,
unique_tex:spam_tex, unique_normal:spam_normal,
unique_normal:spam_normal, unique_color:vec![glam::Vec4::ONE],
unique_color:vec![glam::Vec4::ONE], unique_vertices:spam_vertices,
unique_vertices:spam_vertices, polygon_groups,
polygon_groups, graphics_groups,
graphics_groups, physics_groups:vec![physics_group],
physics_groups:vec![physics_group], }
}, }).collect();
model::Model{
mesh:mesh_id, let world_models:Vec<model::Model>=
attributes:TEMP_TOUCH_ME_ATTRIBUTE, //one instance of the main world mesh
transform:integer::Planar64Affine3::new( std::iter::once((
integer::Planar64Mat3::default(), //world_model
valve_transform(world_model.origin.into()) model::MeshId::new(0),
), //model_origin
color:glam::Vec4::ONE, 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{ PartialMap1{
attributes:unique_attributes, attributes:unique_attributes,