Skip to content

Custom TriMesh colliders from ColliderConstructor::TrimeshFromMesh don't affect NavMesh generation #95

@peterkunsay

Description

@peterkunsay

Hello! First of all, thank you for creating this library - it's a very cool project!

I've been trying to set up vleue_navigator with Avian3D using custom colliders created via ColliderConstructor::TrimeshFromMesh. However, I couldn't get these custom colliders to affect the NavMesh generation, regardless of what I tried. The NavMesh generation works perfectly with primitive colliders like cuboid, etc., but custom TriMesh colliders did not work for me.

After downloading the repository and debugging, I found that the issue lies in how the InnerObstacleSource::get_polygons implementation handles TypedShape::TriMesh in obstacles/avian3d.rs.

The current implementation doesn't transform the trimesh vertices to world space before performing the plane intersection, which causes the intersection to fail or produce incorrect results for transformed colliders.

I've modified the TypedShape::TriMesh case to properly transform vertices to world space before intersection:

TypedShape::TriMesh(collider) => {
    let vertices: Vec<OPoint<f32, Const<3>>> = collider
        .vertices()
        .iter()
        .map(|v| {
            let world_pos = transform.transform_point(vec3(v.x, v.y, v.z));
            OPoint::from([world_pos.x, world_pos.y, world_pos.z])
        })
        .collect();
                
    let transformed_trimesh = TriMesh::new(vertices, collider.indices().to_vec());
                
    let intersection = transformed_trimesh.intersection_with_local_plane(&up_axis, shift, f32::EPSILON);
                
    let polygons = match intersection {
        IntersectResult::Intersect(polyline) => {
            polyline
            .extract_connected_components()
            .iter()
            .map(|p| {
                p.segments()
                .map(|s| {
                    world_to_mesh.transform_point(vec3(s.a.x, s.a.y, s.a.z)).xy()
                })
                .collect()
            })
            .collect()
        }
        IntersectResult::Negative => vec![],
        IntersectResult::Positive => vec![],
    };
                
    vec![polygons]
}

With this change, colliders generated using ColliderConstructor::TrimeshFromMesh now correctly affect the NavMesh generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions