FyroxEngine/Fyrox · error

: Mesh has a triangle with edge length

Error message

{}: Mesh has a triangle with edge length: {}

What it means

Same degenerate-triangle check as the zero-length case, but for edges that are non-zero yet still at or below f32::EPSILON (~1.19e-7). Such near-degenerate triangles cause floating-point instability in normals and physics, so the glTF importer warns with the measured edge length.

Solutions

  1. Scale the model to sane world units in the DCC tool before export so triangle edges are far above float epsilon.
  2. Apply a decimate/remesh pass to remove sub-epsilon micro-triangles, then re-export.
  3. Increase the mesh's export scale in the glTF exporter settings (e.g. Blender's scene unit scale).

Example fix

// before: model scaled 0.001 in exporter, edges ~1e-6 but authored mm
export_scale = 0.001

// after: bake scale into mesh and use meters
# Blender: Apply Scale (Ctrl+A) before glTF export
Defensive patterns

Strategy: validation

Validate before calling

// Validate min edge length in authored units before export:
fn min_edge_ok(positions: &[[f32; 3]], indices: &[u32]) -> bool {
    const EPS: f32 = 1e-5; // well above f32::EPSILON
    indices.chunks(3).all(|t| {
        let d = |a: usize, b: usize| {
            let (p, q) = (positions[t[a] as usize], positions[t[b] as usize]);
            ((q[0]-p[0]).powi(2)+(q[1]-p[1]).powi(2)+(q[2]-p[2]).powi(2)).sqrt()
        };
        d(0,1) > EPS && d(1,2) > EPS && d(0,2) > EPS
    })
}

Prevention

When it happens

Trigger: Loading a glTF/GLB where the minimum triangle edge length is > 0.0 but <= f32::EPSILON, detected during import_meshes (called from import_from_slice).

Common situations: Highly subdivided or heavily scaled-down meshes, unit-mismatch exports (e.g. model authored in millimeters then scaled by 0.001), or LOD generators producing micro-triangles.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10). Data as JSON: /api/errors/92d17ed25955c3bb. Report an issue: GitHub.

Appendix: source

Thrown at fyrox-impl/src/resource/gltf/mod.rs:477

            result.push(import_mesh(mesh, mats, bufs, &mut stats)?);
        }
    }
    if cfg!(feature = "mesh_analysis") {
        if stats.repeated_index_count > 0 {
            Log::err(format!(
                "{}: Model has triangles with repeated vertices: {}",
                path.to_string_lossy(),
                stats.repeated_index_count
            ));
        }
        let min_length = stats.min_edge_length();
        if min_length == 0.0 {
            Log::err(format!(
                "{}: Mesh has a triangle with a zero-length edge!",
                path.to_string_lossy()
            ));
        } else if min_length <= f32::EPSILON {
            Log::err(format!(
                "{}: Mesh has a triangle with edge length: {}",
                path.to_string_lossy(),
                min_length
            ));
        } else {
            Log::info(format!(
                "{}: Smallest triangle edge: {}",
                path.to_string_lossy(),
                min_length
            ));
        }
    }
    Ok(result)
}

fn import_mesh(
    mesh: gltf::Mesh,
    mats: &[MaterialResource],

View on GitHub (pinned to 76c91aad8e)