ikpil / UniRecast

UniRecast - navigation mesh toolset for Unity3D using DotRecast
MIT License
57 stars 11 forks source link

Can I use Unity's navigation workflow to generate navmesh? #6

Closed JohnYoung404 closed 8 months ago

JohnYoung404 commented 8 months ago

Hey, thank you for integrating Recast Navigation into Unity; I've benefited a lot. I'm also working on server-authoritative pathfinding project, and I feel your work has been very helpful. Thank you!

I have a question, can we use Unity's navigation workflow unity.ai.navigation to generate a navmesh and then load it with recast.detour?

I think Unity's underlying pathfinding is also based on Recast Navigation, and there are some unity-related concepts like NavmeshModifier and Volume, I am more accustomed to this workflow.

This is just my thought. I hope to get your advice. Thanks!

ikpil commented 8 months ago

I heard previously that it is constructed by extracting using CalculateTriangulation(), but I haven't tried it, so I'm not sure.

To understand the actual data format, it seems challenging as it is hidden.

Here is a sample code:

UnityEditor.AI.NavMeshBuilder.ClearAllNavMeshes();
UnityEditor.AI.NavMeshBuilder.BuildNavMesh();
NavMeshTriangulation navmesh = NavMesh.CalculateTriangulation();

for (int i = 0; i < navmesh.indices.Length; ++i)
{
    // ..
}

for (int i = 0; i < navmesh.vertices.Length; ++i)
{
    // ..
}

for (int i = 0; i < navmesh.areas.Length; ++i)
{
    // ..
}

In this code, it builds the navigation mesh, uses the CalculateTriangulation() method to extract triangulated information, and stores the extracted data in arrays named indices, vertices, and areas.

JohnYoung404 commented 8 months ago

Thank you for your answer!

I will dive deeper into this issue. My project has just been upgraded to Unity 2022.3, and they have introduced a new navigation system, which seems to be open source. I am not sure if it provides a more convenient way to access navigation mesh data. I will look into it.

Thanks again for your patient responses! :blush:

JohnYoung404 commented 8 months ago

So I tried to export Unity navigation meshes to Recast navigation, and succeeded:

Snipaste_2024-01-11_19-37-56 Snipaste_2024-01-11_19-41-40

It's quite a lot of efforts, but it's doable :blush:

ikpil commented 8 months ago

wow! good!!