Ensure the PhysicsData's bvh respects the original model ordering

There's no importance in worrying about the core HashMap ordering since it's not used as an iterator except for outside of this very function for bvh purposes
This commit is contained in:
2025-11-18 18:49:44 +00:00
parent 128e137829
commit 255bed4803

View File

@@ -978,6 +978,8 @@ impl PhysicsData{
let mut contact_models=HashMap::new();
let mut intersect_models=HashMap::new();
let mut contacts_in_order=Vec::new();
let mut intersects_in_order=Vec::new();
let mut physics_attr_id_from_model_attr_id=HashMap::<CollisionAttributesId,PhysicsAttributesId>::new();
let mut used_meshes=Vec::new();
@@ -1033,18 +1035,22 @@ impl PhysicsData{
let transform=PhysicsMeshTransform::new(model.transform);
match attr_id{
PhysicsAttributesId::Contact(attr_id)=>{
contact_models.insert(ContactModelId::new(model_id as u32),ContactModel{
let contact_model_id=ContactModelId::new(model_id as u32);
contact_models.insert(contact_model_id,ContactModel{
mesh_id,
attr_id,
transform,
});
contacts_in_order.push(contact_model_id);
},
PhysicsAttributesId::Intersect(attr_id)=>{
intersect_models.insert(IntersectModelId::new(model_id as u32),IntersectModel{
let intersect_model_id=IntersectModelId::new(model_id as u32);
intersect_models.insert(intersect_model_id,IntersectModel{
mesh_id,
attr_id,
transform,
});
intersects_in_order.push(intersect_model_id);
},
}
}
@@ -1055,11 +1061,13 @@ impl PhysicsData{
).collect();
let convex_mesh_aabb_list=
//map the two lists into a single type so they can be processed with one closure
contact_models.iter().map(|(&model_id,model)|
(PhysicsModelId::Contact(model_id),&model.mesh_id,&model.transform)
).chain(intersect_models.iter().map(|(&model_id,model)|
(PhysicsModelId::Intersect(model_id),&model.mesh_id,&model.transform)
))
contacts_in_order.iter().map(|model_id|{
let model=contact_models.get(model_id).unwrap();
(PhysicsModelId::Contact(*model_id),&model.mesh_id,&model.transform)
}).chain(intersects_in_order.iter().map(|model_id|{
let model=intersect_models.get(model_id).unwrap();
(PhysicsModelId::Intersect(*model_id),&model.mesh_id,&model.transform)
}))
.flat_map(|(model_id,mesh_id,transform)|{
meshes[mesh_id].submesh_views()
.enumerate().map(move|(submesh_id,view)|{