rbx_loader: do not generate empty polygon groups
This commit is contained in:
@@ -172,12 +172,12 @@ pub fn convert(
|
||||
size:glam::Vec3,
|
||||
RobloxPartDescription(part_texture_description):RobloxPartDescription,
|
||||
)->Result<MeshWithSize,Error>{
|
||||
let mut polygon_groups_normal_id:[_;NORMAL_FACES]=[vec![],vec![],vec![],vec![],vec![],vec![]];
|
||||
|
||||
// build graphics and physics meshes
|
||||
let mut mb=MeshBuilder::new();
|
||||
// graphics
|
||||
let graphics_groups=if !roblox_mesh_data.is_empty(){
|
||||
let (polygon_groups_normal_id,graphics_groups)=if !roblox_mesh_data.is_empty(){
|
||||
let mut polygon_groups_normal_id:[_;NORMAL_FACES]=[vec![],vec![],vec![],vec![],vec![],vec![]];
|
||||
// create per-face texture coordinate affine transforms
|
||||
let cube_face_description=part_texture_description.map(|opt|opt.map(|mut t|{
|
||||
t.transform.set_size(1.0,1.0);
|
||||
@@ -193,18 +193,24 @@ pub fn convert(
|
||||
rbx_mesh::mesh_data::MeshData::CSGMDL(rbx_mesh::mesh_data::CSGMDL::V4(mesh_data4))=>build_mesh2(&mut mb,&mut polygon_groups_normal_id,&cube_face_description,mesh_data4.mesh)?,
|
||||
rbx_mesh::mesh_data::MeshData::CSGMDL(rbx_mesh::mesh_data::CSGMDL::V5(mesh_data4))=>build_mesh5(&mut mb,&mut polygon_groups_normal_id,&cube_face_description,mesh_data4)?,
|
||||
};
|
||||
(0..NORMAL_FACES).map(|polygon_group_id|{
|
||||
model::IndexedGraphicsGroup{
|
||||
render:cube_face_description[polygon_group_id].as_ref().map_or(RenderConfigId::new(0),|face_description|face_description.render),
|
||||
groups:vec![PolygonGroupId::new(polygon_group_id as u32)]
|
||||
}
|
||||
}).collect()
|
||||
let graphics_groups=polygon_groups_normal_id
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&(_,group)|!group.is_empty())
|
||||
.enumerate()
|
||||
.map(|(polygon_group_id,(normal_id,_))|{
|
||||
model::IndexedGraphicsGroup{
|
||||
render:cube_face_description[normal_id].as_ref().map_or(RenderConfigId::new(0),|face_description|face_description.render),
|
||||
groups:vec![PolygonGroupId::new(polygon_group_id as u32)]
|
||||
}
|
||||
}).collect();
|
||||
(polygon_groups_normal_id,graphics_groups)
|
||||
}else{
|
||||
Vec::new()
|
||||
([vec![],vec![],vec![],vec![],vec![],vec![]],Vec::new())
|
||||
};
|
||||
|
||||
//physics
|
||||
let polygon_groups_normal_it=polygon_groups_normal_id.into_iter().map(|faces|
|
||||
let polygon_groups_normal_it=polygon_groups_normal_id.into_iter().filter(|group|!group.is_empty()).map(|faces|
|
||||
// graphics polygon groups (to be rendered)
|
||||
PolygonGroup::PolygonList(PolygonList::new(faces))
|
||||
);
|
||||
@@ -257,7 +263,7 @@ pub fn convert(
|
||||
).to_vec()).to_vec()));
|
||||
polygon_groups_normal_it.chain([polygon_group]).collect()
|
||||
};
|
||||
let physics_groups=(NORMAL_FACES..polygon_groups.len()).map(|id|model::IndexedPhysicsGroup{
|
||||
let physics_groups=(graphics_groups.len()..polygon_groups.len()).map(|id|model::IndexedPhysicsGroup{
|
||||
groups:vec![PolygonGroupId::new(id as u32)]
|
||||
}).collect();
|
||||
let mesh=mb.build(
|
||||
|
||||
Reference in New Issue
Block a user