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,7 +109,6 @@ 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,
@ -119,18 +118,45 @@ where
polygon_groups, polygon_groups,
graphics_groups, graphics_groups,
physics_groups:vec![physics_group], physics_groups:vec![physics_group],
}, }
}).collect();
let world_models:Vec<model::Model>=
//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)
)
)
).map(|(mesh_id,model_origin,model_color)|{
model::Model{ model::Model{
mesh:mesh_id, mesh:mesh_id,
attributes:TEMP_TOUCH_ME_ATTRIBUTE, attributes:TEMP_TOUCH_ME_ATTRIBUTE,
transform:integer::Planar64Affine3::new( transform:integer::Planar64Affine3::new(
integer::Planar64Mat3::default(), integer::Planar64Mat3::default(),
valve_transform(world_model.origin.into()) valve_transform(model_origin.into())
), ),
color:glam::Vec4::ONE, color:(glam::Vec3::from_array(model_color)/255.0).extend(1.0),
}, }
) }).collect();
}).unzip();
PartialMap1{ PartialMap1{
attributes:unique_attributes, attributes:unique_attributes,