From 82d84ee07ca94d5e616610d79bbbf65b478bba8a Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 6 Nov 2023 15:57:55 -0800 Subject: [PATCH] fix mesh gen algorithm --- src/model_physics.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/model_physics.rs b/src/model_physics.rs index d72167e..6c5e6fe 100644 --- a/src/model_physics.rs +++ b/src/model_physics.rs @@ -91,10 +91,13 @@ impl EdgePool{ impl From<&crate::model::IndexedModel> for PhysicsMesh{ fn from(indexed_model:&crate::model::IndexedModel)->Self{ let verts=indexed_model.unique_pos.iter().map(|v|Vert(v.clone())).collect(); - let mut vert_edges=vec![VertRefGuy::default();indexed_model.unique_vertices.len()]; + let mut vert_edges=vec![VertRefGuy::default();indexed_model.unique_pos.len()]; let mut edge_pool=EdgePool::default(); - let (faces,face_ref_guys):(Vec,Vec)=indexed_model.groups[0].polys.iter().enumerate().map(|(i,poly)|{ - let face_id=FaceId(i); + let mut face_i=0; + let mut faces=Vec::new(); + let mut face_ref_guys=Vec::new(); + for group in indexed_model.groups.iter(){for poly in group.polys.iter(){ + let face_id=FaceId(face_i); //one face per poly let mut normal=Planar64Vec3::ZERO; let len=poly.vertices.len(); @@ -129,8 +132,10 @@ impl From<&crate::model::IndexedModel> for PhysicsMesh{ for &v in poly.vertices.iter(){ dot+=normal.dot(indexed_model.unique_pos[indexed_model.unique_vertices[v as usize].pos as usize]); } - (Face{normal,dot:dot/len as i64},FaceRefGuy(face_edges)) - }).unzip(); + faces.push(Face{normal,dot:dot/len as i64}); + face_ref_guys.push(FaceRefGuy(face_edges)); + face_i+=1; + }} //conceivably faces, edges, and vertices exist now Self{ faces,