oxidized_navigation icon indicating copy to clipboard operation
oxidized_navigation copied to clipboard

Custom colliders support

Open Shatur opened this issue 2 years ago • 7 comments

Currently the plugin uses only Rapier colliders for calculating the navigation. But it would be great to make this integration optional for games that does not use physics like mine. I would like to suggest to add support for using AABB and mesh for path navigation calculation. So I proposing to turn NavMeshAffector into enum with the following fields:

enum NavMeshAffector {
    #[cfg(feature = "rapier")]
    RapierCollider,
    Mesh,
    Aabb,
}

Shatur avatar May 05 '23 10:05 Shatur

This is definitely something on my roadmap.

TheGrimsey avatar May 05 '23 12:05 TheGrimsey

Especially important with the release of bevy_xpbd.

Shatur avatar Jul 04 '23 13:07 Shatur

I came up with something that might work for this. https://github.com/TheGrimsey/oxidized_navigation/pull/14

It changes the internals from using bevy_rapier3d to using parry3d, and uses a generic on plugin creation to know what Collider to query for.

The Collider is just a thin wrapper around a parry collider, but it should be possible for people/crates that aren't using parry3d to create a wrapper that converts their collider type to a parry3d collider.

bevy_xpbd support only required

impl Collider for XpbdCollider {
    fn into_typed_shape(&self) -> TypedShape {
        self.as_typed_shape()
    }

    fn t_compute_local_aabb(&self) -> Aabb {
        self.compute_local_aabb()
    }
}

Elabajaba avatar Jul 16 '23 03:07 Elabajaba

Could work, but I think that the suggested enum is a better solution, it could work even without physics. There is no reason to depend on parry for navigation crate.

Shatur avatar Jul 16 '23 09:07 Shatur

I quite like @Elabajaba's solution for being generic over colliders.

Seems to me it should be possible to combine it with the enum but simply have a generic collider variant instead (for example):

enum NavMeshAffector {
    #[cfg(any(feature = "rapier", feature = "xpbd"))]
    Collider,
    Mesh,
    Aabb,
}

Parry dependency should also then be optional behind any of the physics features.

TheGrimsey avatar Jul 16 '23 11:07 TheGrimsey

You are right, this does makes sense.

Shatur avatar Jul 16 '23 11:07 Shatur

I originally tried something similar to the NavMeshAffector enum, but on Collider, and it got really ugly very quickly and ended up with a lot of duplicated code and #[cfg(feature="...")] everywhere, so I dropped it and just moved to parry+generics since it would let you use it without a physics engine.

Elabajaba avatar Jul 17 '23 01:07 Elabajaba