forked from StrafesNET/strafe-client
fix graphics
This commit is contained in:
parent
6c3e0ba84c
commit
4a7cd0a146
@ -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,51 +214,59 @@ 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){
|
for graphics_group in mesh.graphics_groups.iter(){
|
||||||
for graphics_group in mesh.graphics_groups.iter(){
|
let render_config=&map.render_configs[graphics_group.render.get() as usize];
|
||||||
let render_config=&map.render_configs[graphics_group.render.get() as usize];
|
if model.color.w==0.0&&render_config.texture.is_none(){
|
||||||
if model.color.w==0.0&&render_config.texture.is_none(){
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
//get or create owned mesh
|
||||||
//get or create owned mesh
|
let owned_mesh_id=if let Some(&owned_mesh_id)=owned_mesh_map.get(&graphics_group.render){
|
||||||
let owned_mesh_id=if let Some(&owned_mesh_id)=owned_mesh_map.get(&graphics_group.render){
|
owned_mesh_id
|
||||||
owned_mesh_id
|
}else{
|
||||||
}else{
|
//create
|
||||||
//create
|
let owned_mesh_id=IndexedGraphicsMeshOwnedRenderConfigId::new(unique_render_config_models.len() as u32);
|
||||||
let owned_mesh_id=IndexedGraphicsMeshOwnedRenderConfigId::new(unique_render_config_models.len() as u32);
|
owned_mesh_map.insert(graphics_group.render,owned_mesh_id);
|
||||||
owned_mesh_map.insert(graphics_group.render,owned_mesh_id);
|
unique_render_config_models.push(IndexedGraphicsMeshOwnedRenderConfig{
|
||||||
unique_render_config_models.push(IndexedGraphicsMeshOwnedRenderConfig{
|
unique_pos:mesh.unique_pos.iter().map(|&v|*Into::<glam::Vec3>::into(v).as_ref()).collect(),
|
||||||
unique_pos:mesh.unique_pos.iter().map(|&v|*Into::<glam::Vec3>::into(v).as_ref()).collect(),
|
unique_tex:mesh.unique_tex.iter().map(|v|*v.as_ref()).collect(),
|
||||||
unique_tex:mesh.unique_tex.iter().map(|v|*v.as_ref()).collect(),
|
unique_normal:mesh.unique_normal.iter().map(|&v|*Into::<glam::Vec3>::into(v).as_ref()).collect(),
|
||||||
unique_normal:mesh.unique_normal.iter().map(|&v|*Into::<glam::Vec3>::into(v).as_ref()).collect(),
|
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(Vec::new())),
|
||||||
polys:model::PolygonGroup::PolygonList(model::PolygonList::new(
|
instances:vec![instance.clone()],
|
||||||
|
});
|
||||||
|
owned_mesh_id
|
||||||
|
};
|
||||||
|
let owned_mesh=unique_render_config_models.get_mut(owned_mesh_id.get() as usize).unwrap();
|
||||||
|
match &mut owned_mesh.polys{
|
||||||
|
model::PolygonGroup::PolygonList(polygon_list)=>polygon_list.extend(
|
||||||
graphics_group.groups.iter().flat_map(|polygon_group_id|{
|
graphics_group.groups.iter().flat_map(|polygon_group_id|{
|
||||||
mesh.polygon_groups[polygon_group_id.get() as usize].polys()
|
mesh.polygon_groups[polygon_group_id.get() as usize].polys()
|
||||||
})
|
})
|
||||||
.map(|vertex_id_slice|
|
.map(|vertex_id_slice|
|
||||||
vertex_id_slice.iter().copied().collect()
|
vertex_id_slice.to_vec()
|
||||||
).collect()
|
)
|
||||||
)),
|
),
|
||||||
instances:Vec::new(),
|
}
|
||||||
});
|
}
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user