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

Function best_collapse

perro_source/render_stack/perro_meshlets/src/lib.rs:378–422  ·  view source on GitHub ↗
(
    vertices: &[LodVertex],
    triangles: &[[u32; 3]],
    quadrics: &[[f64; 10]],
    edges: &[EdgeCandidate],
    adjacency: &[Vec<usize>],
    tri_normals: &[Option<[f32; 3]>],
)

Source from the content-addressed store, hash-verified

376 return ratios.iter().map(|_| Vec::new()).collect();
377 };
378 let min_vertex = min_index as usize;
379 let max_vertex = max_index as usize;
380 if max_vertex < vertices.len()
381 && (min_vertex > 0 || max_vertex.saturating_add(1) < vertices.len())
382 {
383 let local_indices = surface_indices
384 .iter()
385 .map(|index| index - min_index)
386 .collect::<Vec<_>>();
387 let mut lods =
388 build_surface_lods_dense(&vertices[min_vertex..=max_vertex], &local_indices, ratios);
389 for lod in &mut lods {
390 for index in lod {
391 *index += min_index;
392 }
393 }
394 return lods;
395 }
396 build_surface_lods_dense(vertices, surface_indices, ratios)
397}
398
399fn build_surface_lods_dense(
400 vertices: &[LodVertex],
401 surface_indices: &[u32],
402 ratios: &[f32],
403) -> Vec<Vec<u32>> {
404 let original_tri_count = surface_indices.len() / 3;
405 if original_tri_count == 0 {
406 return ratios.iter().map(|_| Vec::new()).collect();
407 }
408 let source = &surface_indices[..original_tri_count * 3];
409 if (PARALLEL_LOD_RATIO_TRI_THRESHOLD..=PARALLEL_LOD_RATIO_TRI_MAX).contains(&original_tri_count)
410 && ratios.len() > 1
411 {
412 return ratios
413 .par_iter()
414 .map(|&ratio| {
415 let target = ((original_tri_count as f32) * ratio).ceil() as usize;
416 simplify_surface(vertices, source, target.clamp(1, original_tri_count))
417 })
418 .collect();
419 }
420
421 let mut current = source.to_vec();
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);

Callers 1

simplify_surfaceFunction · 0.85

Calls 5

collapse_costFunction · 0.85
better_collapseFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected