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(); let indexed_models_len=map.models.len();
//models split into graphics_group.RenderConfigId //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 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{ for model in &map.models{
//wow //wow
let instance=GraphicsModelOwned{ let instance=GraphicsModelOwned{
@ -214,13 +214,17 @@ impl GraphicsState{
color:GraphicsModelColor4::new(model.color), color:GraphicsModelColor4::new(model.color),
}; };
//get or create owned mesh map //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){ if let Some(owned_mesh_map)=owned_mesh_id_from_mesh_id_render_config_id.get(&model.mesh){
map //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{ }else{
let map=HashMap::new(); let mut owned_mesh_map=HashMap::new();
owned_mesh_id_from_mesh_id_render_config_id.insert(model.mesh,map); //add mesh if renderid never before seen for this model
owned_mesh_id_from_mesh_id_render_config_id.get_mut(&model.mesh).unwrap() //add instance
};
//convert Model into GraphicsModelOwned //convert Model into GraphicsModelOwned
//check each group, if it's using a new render config then make a new clone of the model //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){ 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_color:mesh.unique_color.iter().map(|v|*v.as_ref()).collect(),
unique_vertices:mesh.unique_vertices.clone(), unique_vertices:mesh.unique_vertices.clone(),
render_config:graphics_group.render, render_config:graphics_group.render,
polys:model::PolygonGroup::PolygonList(model::PolygonList::new( polys:model::PolygonGroup::PolygonList(model::PolygonList::new(Vec::new())),
graphics_group.groups.iter().flat_map(|polygon_group_id|{ instances:vec![instance.clone()],
mesh.polygon_groups[polygon_group_id.get() as usize].polys()
})
.map(|vertex_id_slice|
vertex_id_slice.iter().copied().collect()
).collect()
)),
instances:Vec::new(),
}); });
owned_mesh_id owned_mesh_id
}; };
let owned_mesh=unique_render_config_models.get_mut(owned_mesh_id.get() as usize).unwrap(); 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 //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 //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 //2. for each model id,check if removing it from the pool decreases both the model count and instance count by more than one