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

Function simplify_surface

perro_source/render_stack/perro_meshlets/src/lib.rs:271–325  ·  view source on GitHub ↗
(vertices: &[LodVertex], surface_indices: &[u32], keep_tris: usize)

Source from the content-addressed store, hash-verified

269 vec![LodSurfaceRange {
270 index_start: 0,
271 index_count: indices.len() as u32,
272 }]
273 } else {
274 surface_ranges.to_vec()
275 };
276 for range in &base_surfaces {
277 let start = range.index_start as usize;
278 let end = start.checked_add(range.index_count as usize).ok_or(
279 MeshletBuildError::SurfaceRangeOutOfBounds {
280 index_start: range.index_start,
281 index_count: range.index_count,
282 index_len: indices.len(),
283 },
284 )?;
285 if end > indices.len() {
286 return Err(MeshletBuildError::SurfaceRangeOutOfBounds {
287 index_start: range.index_start,
288 index_count: range.index_count,
289 index_len: indices.len(),
290 });
291 }
292 }
293
294 let tri_count = indices.len() / 3;
295 if tri_count == 0 || target_ratios.is_empty() {
296 return Ok(vec![LodSet {
297 indices: indices.to_vec(),
298 surface_ranges: base_surfaces,
299 }]);
300 }
301
302 let ratios = target_ratios
303 .iter()
304 .map(|ratio| {
305 if ratio.is_finite() {
306 ratio.clamp(0.0, 1.0)
307 } else {
308 1.0
309 }
310 })
311 .collect::<Vec<_>>();
312 let build_surface = |range: &LodSurfaceRange| {
313 let start = range.index_start as usize;
314 let end = start + range.index_count as usize;
315 build_surface_lods(vertices, &indices[start..end], &ratios)
316 };
317 let per_surface_lods = if base_surfaces.len() >= 4 && tri_count >= 512 {
318 base_surfaces
319 .par_iter()
320 .map(build_surface)
321 .collect::<Vec<_>>()
322 } else {
323 base_surfaces.iter().map(build_surface).collect::<Vec<_>>()
324 };
325
326 let mut lods = Vec::new();
327 for ratio_index in 0..ratios.len() {
328 let mut lod_indices = Vec::new();

Callers 1

build_surface_lodsFunction · 0.85

Calls 12

tri_degenerateFunction · 0.85
flatten_trisFunction · 0.85
build_vertex_quadricsFunction · 0.85
build_topologyFunction · 0.85
best_collapseFunction · 0.85
apply_collapse_intoFunction · 0.85
to_vecMethod · 0.80
anyMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
maxMethod · 0.45
prepareMethod · 0.45

Tested by

no test coverage detected