deduplicate ahead of time
This commit is contained in:
parent
4f3254e67e
commit
64fb36ec23
@ -43,16 +43,10 @@ impl std::fmt::Display for BrushToMeshError{
|
|||||||
}
|
}
|
||||||
impl core::error::Error for BrushToMeshError{}
|
impl core::error::Error for BrushToMeshError{}
|
||||||
|
|
||||||
fn planes_to_faces(face_list:Vec<Face>)->Option<Faces>{
|
fn planes_to_faces(face_list:std::collections::HashSet<Face>)->Option<Faces>{
|
||||||
let mut faces=Vec::new();
|
let mut faces=Vec::new();
|
||||||
// for each face, determine one edge at a time until you complete the face
|
// for each face, determine one edge at a time until you complete the face
|
||||||
let mut dedup=std::collections::HashSet::new();
|
|
||||||
'face: for face0 in &face_list{
|
'face: for face0 in &face_list{
|
||||||
// don't generate duplicate faces
|
|
||||||
if !dedup.insert(face0){
|
|
||||||
continue 'face;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. find first edge
|
// 1. find first edge
|
||||||
// 2. follow edges around face
|
// 2. follow edges around face
|
||||||
|
|
||||||
@ -156,7 +150,7 @@ fn planes_to_faces(face_list:Vec<Face>)->Option<Faces>{
|
|||||||
|
|
||||||
// find the next face moving clockwise around face0
|
// find the next face moving clockwise around face0
|
||||||
let (new_face,new_intersection,_)=face_list.iter().filter_map(|new_face|{
|
let (new_face,new_intersection,_)=face_list.iter().filter_map(|new_face|{
|
||||||
// ignore faces we've seen before
|
// ignore faces that are part of the current edge
|
||||||
if core::ptr::eq(face0,new_face)
|
if core::ptr::eq(face0,new_face)
|
||||||
|core::ptr::eq(face2,new_face){
|
|core::ptr::eq(face2,new_face){
|
||||||
return None;
|
return None;
|
||||||
@ -168,6 +162,7 @@ fn planes_to_faces(face_list:Vec<Face>)->Option<Faces>{
|
|||||||
if d_new_intersection.le_ratio(d_intersection){
|
if d_new_intersection.le_ratio(d_intersection){
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some((new_face,new_intersection,d_new_intersection))
|
Some((new_face,new_intersection,d_new_intersection))
|
||||||
}).min_by_key(|&(_,_,d)|d)?;
|
}).min_by_key(|&(_,_,d)|d)?;
|
||||||
|
|
||||||
@ -202,7 +197,7 @@ pub fn brush_to_mesh(bsp:&vbsp::Bsp,brush:&vbsp::Brush)->Result<model::Mesh,Brus
|
|||||||
normal:valve_transform(plane.normal.into()),
|
normal:valve_transform(plane.normal.into()),
|
||||||
dot:valve_transform_dist(plane.dist.into()),
|
dot:valve_transform_dist(plane.dist.into()),
|
||||||
})
|
})
|
||||||
}).collect::<Option<Vec<_>>>().ok_or(BrushToMeshError::MissingPlane)?;
|
}).collect::<Option<std::collections::HashSet<_>>>().ok_or(BrushToMeshError::MissingPlane)?;
|
||||||
|
|
||||||
if face_list.len()<4{
|
if face_list.len()<4{
|
||||||
return Err(BrushToMeshError::InvalidFaceCount{count:face_list.len()});
|
return Err(BrushToMeshError::InvalidFaceCount{count:face_list.len()});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user