fix graphics

This commit is contained in:
Quaternions 2024-02-12 19:43:32 -08:00
parent 6c3e0ba84c
commit 4a7cd0a146

View File

@ -205,7 +205,7 @@ impl GraphicsState{
let indexed_models_len=map.models.len();
//models split into graphics_group.RenderConfigId
let mut owned_mesh_id_from_mesh_id_render_config_id:HashMap<model::MeshId,HashMap<RenderConfigId,IndexedGraphicsMeshOwnedRenderConfigId>>=HashMap::new();
let mut unique_render_config_models=Vec::with_capacity(indexed_models_len);
let mut unique_render_config_models:Vec<IndexedGraphicsMeshOwnedRenderConfig>=Vec::with_capacity(indexed_models_len);
for model in &map.models{
//wow
let instance=GraphicsModelOwned{
@ -214,13 +214,17 @@ impl GraphicsState{
color:GraphicsModelColor4::new(model.color),
};
//get or create owned mesh map
let owned_mesh_map=if let Some(map)=owned_mesh_id_from_mesh_id_render_config_id.get_mut(&model.mesh){
map
if let Some(owned_mesh_map)=owned_mesh_id_from_mesh_id_render_config_id.get(&model.mesh){
//the mesh has already been split into a set of unique renderconfig meshes
//simply add one instance to each of them
for owned_mesh_id in owned_mesh_map.values(){
let owned_mesh=unique_render_config_models.get_mut(owned_mesh_id.get() as usize).unwrap();
owned_mesh.instances.push(instance.clone());
}
}else{
let map=HashMap::new();
owned_mesh_id_from_mesh_id_render_config_id.insert(model.mesh,map);
owned_mesh_id_from_mesh_id_render_config_id.get_mut(&model.mesh).unwrap()
};
let mut owned_mesh_map=HashMap::new();
//add mesh if renderid never before seen for this model
//add instance
//convert Model into GraphicsModelOwned
//check each group, if it's using a new render config then make a new clone of the model
if let Some(mesh)=map.meshes.get(model.mesh.get() as usize){
@ -243,23 +247,27 @@ impl GraphicsState{
unique_color:mesh.unique_color.iter().map(|v|*v.as_ref()).collect(),
unique_vertices:mesh.unique_vertices.clone(),
render_config:graphics_group.render,
polys:model::PolygonGroup::PolygonList(model::PolygonList::new(
graphics_group.groups.iter().flat_map(|polygon_group_id|{
mesh.polygon_groups[polygon_group_id.get() as usize].polys()
})
.map(|vertex_id_slice|
vertex_id_slice.iter().copied().collect()
).collect()
)),
instances:Vec::new(),
polys:model::PolygonGroup::PolygonList(model::PolygonList::new(Vec::new())),
instances:vec![instance.clone()],
});
owned_mesh_id
};
let owned_mesh=unique_render_config_models.get_mut(owned_mesh_id.get() as usize).unwrap();
owned_mesh.instances.push(instance.clone());
match &mut owned_mesh.polys{
model::PolygonGroup::PolygonList(polygon_list)=>polygon_list.extend(
graphics_group.groups.iter().flat_map(|polygon_group_id|{
mesh.polygon_groups[polygon_group_id.get() as usize].polys()
})
.map(|vertex_id_slice|
vertex_id_slice.to_vec()
)
),
}
}
}
owned_mesh_id_from_mesh_id_render_config_id.insert(model.mesh,owned_mesh_map);
};
}
//check every model to see if it's using the same (texture,color) but has few instances,if it is combine it into one model
//1. collect unique instances of texture and color,note model id
//2. for each model id,check if removing it from the pool decreases both the model count and instance count by more than one