MCPcopy Create free account
hub / github.com/PerroEngine/Perro / build_topology

Function build_topology

perro_source/render_stack/perro_meshlets/src/lib.rs:424–448  ·  view source on GitHub ↗
(vertices: &[LodVertex], triangles: &[[u32; 3]], scratch: &mut SimplifyScratch)

Source from the content-addressed store, hash-verified

422 let mut lods = Vec::with_capacity(ratios.len());
423 for &ratio in ratios {
424 let target = ((original_tri_count as f32) * ratio).ceil() as usize;
425 let target = target.clamp(1, original_tri_count);
426 let current_tris = current.len() / 3;
427 if target < current_tris {
428 current = simplify_surface(vertices, &current, target);
429 }
430 lods.push(current.clone());
431 }
432 lods
433}
434
435fn simplify_surface(vertices: &[LodVertex], surface_indices: &[u32], keep_tris: usize) -> Vec<u32> {
436 let tri_count = surface_indices.len() / 3;
437 let source = &surface_indices[..tri_count * 3];
438 if keep_tris >= tri_count || tri_count == 0 {
439 return source.to_vec();
440 }
441 if source.iter().any(|&idx| idx as usize >= vertices.len()) {
442 return source.to_vec();
443 }
444 let mut triangles = source
445 .chunks_exact(3)
446 .map(|tri| [tri[0], tri[1], tri[2]])
447 .filter(|tri| !tri_degenerate(*tri))
448 .collect::<Vec<_>>();
449 if triangles.len() <= keep_tris {
450 return flatten_tris(&triangles);
451 }

Callers 1

simplify_surfaceFunction · 0.85

Calls 5

tri_normalFunction · 0.85
extendMethod · 0.80
iterMethod · 0.45
get_mutMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected