fix edge faces ordering

This commit is contained in:
Quaternions 2023-11-15 17:59:24 -08:00
parent 8f63699d45
commit 020c704968

View File

@ -94,15 +94,16 @@ struct EdgePool{
edge_id_from_guy:std::collections::HashMap<EdgeIdGuy,usize>, edge_id_from_guy:std::collections::HashMap<EdgeIdGuy,usize>,
} }
impl EdgePool{ impl EdgePool{
fn push(&mut self,edge_id_guy:EdgeIdGuy)->(&mut EdgeRefGuy,EdgeId,bool){ fn push(&mut self,edge_id_guy:EdgeIdGuy)->(&mut EdgeRefGuy,EdgeId){
if let Some(&edge_id)=self.edge_id_from_guy.get(&edge_id_guy){ let edge_id=if let Some(&edge_id)=self.edge_id_from_guy.get(&edge_id_guy){
(&mut unsafe{self.edge_guys.get_unchecked_mut(edge_id)}.1,EdgeId(edge_id),true) edge_id
}else{ }else{
let edge_id=self.edge_guys.len(); let edge_id=self.edge_guys.len();
self.edge_guys.push((edge_id_guy.clone(),EdgeRefGuy::new())); self.edge_guys.push((edge_id_guy.clone(),EdgeRefGuy::new()));
self.edge_id_from_guy.insert(edge_id_guy,edge_id); self.edge_id_from_guy.insert(edge_id_guy,edge_id);
(&mut unsafe{self.edge_guys.get_unchecked_mut(edge_id)}.1,EdgeId(edge_id),false) edge_id
} };
(&mut unsafe{self.edge_guys.get_unchecked_mut(edge_id)}.1,EdgeId(edge_id))
} }
} }
impl From<&crate::model::IndexedModel> for PhysicsMesh{ impl From<&crate::model::IndexedModel> for PhysicsMesh{
@ -131,12 +132,10 @@ impl From<&crate::model::IndexedModel> for PhysicsMesh{
); );
//get/create edge and push face into it //get/create edge and push face into it
let (edge_id_guy,is_sorted)=EdgeIdGuy::new(VertId(vert0_id),VertId(vert1_id)); let (edge_id_guy,is_sorted)=EdgeIdGuy::new(VertId(vert0_id),VertId(vert1_id));
let (edge_ref_guy,edge_id,exists)=edge_pool.push(edge_id_guy); let (edge_ref_guy,edge_id)=edge_pool.push(edge_id_guy);
if exists{ //polygon vertices as assumed to be listed clockwise
edge_ref_guy.push(1,face_id); //populate the edge face on the left or right depending on how the edge vertices got sorted
}else{ edge_ref_guy.push(is_sorted as usize,face_id);
edge_ref_guy.push(0,face_id);
}
//index edges & face into vertices //index edges & face into vertices
{ {
let vert_ref_guy=unsafe{vert_ref_guys.get_unchecked_mut(vert0_id)}; let vert_ref_guy=unsafe{vert_ref_guys.get_unchecked_mut(vert0_id)};