From 62b5ba2b33c05e28f5a5f84f43ad15cbe3800c69 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 18 Mar 2024 20:51:52 -0700 Subject: [PATCH] pretty polygon fanning from vbsp code --- src/graphics.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/graphics.rs b/src/graphics.rs index ebdfbbd..4c824d2 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -419,22 +419,26 @@ impl GraphicsState{ //this mut be combined in a more complex way if the models use different render patterns per group let mut indices=Vec::new(); for poly in model.polys.polys(){ - for end_index in 2..poly.len(){ - for index in [0,end_index-1,end_index]{ - let vertex_index=poly[index]; - indices.push(*index_from_vertex.entry(vertex_index).or_insert_with(||{ - let i=vertices.len(); - let vertex=&model.unique_vertices[vertex_index.get() as usize]; - vertices.push(GraphicsVertex{ - pos:model.unique_pos[vertex.pos.get() as usize], - tex:model.unique_tex[vertex.tex.get() as usize], - normal:model.unique_normal[vertex.normal.get() as usize], - color:model.unique_color[vertex.color.get() as usize], - }); - i - })); - } - } + let mut poly_vertices=poly.iter() + .map(|&vertex_index|*index_from_vertex.entry(vertex_index).or_insert_with(||{ + let i=vertices.len(); + let vertex=&model.unique_vertices[vertex_index.get() as usize]; + vertices.push(GraphicsVertex{ + pos:model.unique_pos[vertex.pos.get() as usize], + tex:model.unique_tex[vertex.tex.get() as usize], + normal:model.unique_normal[vertex.normal.get() as usize], + color:model.unique_color[vertex.color.get() as usize], + }); + i + })); + + let a=poly_vertices.next().unwrap(); + let mut b=poly_vertices.next().unwrap(); + + poly_vertices.for_each(|c|{ + indices.extend([a,b,c]); + b=c; + }); } GraphicsMeshOwnedRenderConfig{ instances:model.instances,