Repository: godot
Issue: NavmeshRegions seem to not be quite thought through
Labels: discussion,topic:navigation

### Godot version

4.1.1

### System information

-

### Issue description

So I have been playing around a bit with the new navigation system for the last couple of days. But it seems I either don't understand how it's supposed to work or it has some major flaws. Since nobody on Discord answered any of my questions and there is no dedicated navigation channel I am now making this issue in the hopes of either understanding what I am doing wrong, or demonstrating what is wrong with the current system.

### Two areas in the same plane

With that said let's start with a very simple map; Suppose we have a map with 2 areas, where one of the areas is sometimes non-walkable:

![image](https://github.com/godotengine/godot/assets/11277588/a51447ac-1856-4e03-8334-d4866ed07672)

Now what I gather from the [doc ](https://docs.godotengine.org/en/stable/tutorials/navigation/navigation_different_actor_area_access.html) it should be pretty simple to implement a navigation mesh for this. We just create 2 navigation areas and assign them to each of the 2 meshes, bake the navmesh and oops:

![image](https://github.com/godotengine/godot/assets/11277588/0dceba43-b340-4c22-83af-378a5c5af7f3)


The navmeshes can never overlap since they don't consider the edge geometry. The only possible way I can see to fix this is to do this: 
![image](https://github.com/godotengine/godot/assets/11277588/b67cb148-2c54-4bbb-93cb-f8caa7c4c656)

and then try to painstakingly adjust the baking aabb; which honestly could use some editor gizmo similar to the box shape to define. and what's the aabb offset for anyways? The only point in the code I could find where this value is used is here: https://github.com/godotengine/godot/blob/237bd0a615df8a0e57bc3d299894abece7b43a0c/modules/navigation/navigation_mesh_generator.cpp#L636-L639 where its added to the baking aabb position. So why not set that one correctly? The purpose of this parameter eludes me.

Then the doc also gives conflicting information about how areas are merged. [Using NavigationLayers](https://docs.godotengine.org/en/stable/tutorials/navigation/navigation_using_navigationlayers.html#doc-navigation-advanced-using-navigationlayers) states:

> If two regions have not a single compatible layer they will **not** be merged by the NavigationServer.

[Support different actor area access](https://docs.godotengine.org/en/stable/tutorials/navigation/navigation_different_actor_area_access.html) has a screenshot with only the "DoorOpen" layer enabled on the door mesh.

Looking in the Editor "Support different actor area access" seems to be correct because it draws the connection and I also can't find any filtering on layers in the code that is connecting the different NavigationAreas. Given that you couldn't actually query for a path that is either including or excluding doors the doc in "Using NavigationLayers" seems to be wrong.

Also I have yet to find a way to create an actual door with this technique. Everything I have come up with so far would require placing 4 regions around the door and then one at the door, since you can't really carve out the door of the navmesh. And then you still need to manually adjust the baking aabb in just such a way that you somehow manage to create a connected navmesh.

### Two areas in different planes
Now in the example above we basically had a 2d mesh that we wanted to connect. Now lets consider a slightly more advanced 3d scenario where we have a water plane and some ground and our agents can go through the water only if they meet certain conditions. I don't know maybe they can't swim and need to pick up some floats first. In any case here is the basic level:

![image](https://github.com/godotengine/godot/assets/11277588/788ba21a-ecda-42bc-ac06-52bcc6766d7c)
 (I made the water plane black so its easier to see the navmesh later)

Now, from our first try, we already know that placing the ground in one NavmeshRegion and the water in a different one is not going to work. In this case, the water mesh would even just clip straight through the two "ramps" since they would not be considered as part of the baking. So again, we have to painstakingly adjust some baking aabb to somehow try and make this work.

So I try to manually set the 2 baking aabbs of the regions (again why is there no editor gizmo?) and build the maps. But its now a bit more complicated because of the angled surfaces. Even offsetting the 2 regions by `Agent Max Climb + Cell Height`. The water navmesh just clips through the ramps? 

![image](https://github.com/godotengine/godot/assets/11277588/d695bf9e-77ca-4d6c-91c1-8975ad588be7)
(The water plane is at y=0)

Only if I put it at `Agent Max Climb + 2xCell Height` does the water mesh no longer clip through the ramp. Fine, I guess I could just place the visible mesh a bit higher/have my water collision a bit lower. But I can't seem to get the two meshes to connect at all. Even if I increase the connection margin. Moving the meshes around it seems something has bugged out because they only connect once they are quite far apart?

![image](https://github.com/godotengine/godot/assets/11277588/736080bf-ea27-47d6-8c65-5daf322d6def)

This by the way also only "works" in the editor. Once I actually start the map the connection disappears:

![image](https://github.com/godotengine/godot/assets/11277588/4cfe94b0-8810-45bf-9778-fde2b942127c)

And forget getting both ramps to connect at the same time. So I also would need to create separate meshes for each piece of geometry that leads into the water. No matter what I tried I couldn't get this map to work at all.

### rcMarkXXArea

Now, given the limitations of NavigationRegions (only square regions) and all the issues I have faced so far trying to implement 2 very basic maps. I do wonder why [rcMarkXXArea](http://rwindegger.github.io/recastnavigation/group__recast.html#ga6eb47f730138abd401f6f4dc8847e0a1) is not exposed in any way. This seems like the obvious solution to all my issues, you can mark door areas and other temporary "unwakable" areas, you can easily mark areas like water which might have a different pathing cost or be unpathable in some circumstances and you can have way more complex shapes than "Cube". Also, given that the namesh is baked considering all the geometry surrounding the areas, everything is correctly connected.

### Parsed Geometry Type defaults to MeshInstances

This is another thing that I don't quite understand. Why does this default to visible Geometry? Given that the Collision is actually the only thing that can impede your pathing and that using the visible geometry violates every point related to navmesh baking in this [list](https://docs.godotengine.org/en/stable/tutorials/navigation/navigation_optimizing_performance.html) I do wonder why it's set like that.

### Using the PhysicsServer to gather source geometry
Using the SceneTree to define what geometry to consider when baking the navmesh is fine for very simple maps, but if you have more complex maps with a lot of objects and layers, it seems to me having the option to use the PhysicsServer to query for all Colliders in the NavigationRegion bounding box would be a way better option. Sure you can theoretically implement this yourself using some areas and then assigning groups to the included nodes or using NavigationMeshSourceGeometryData3D, but the first one kinda pollutes the node groups and the second one does not allow to directly add CollisionShapes and also kinda seems like an afterthought for compatibility reasons with the older system since it's never mentioned in the [Navigation Manual](https://docs.godotengine.org/en/stable/tutorials/navigation/index.html) as far as I can tell.

### Final thoughts
All in all, it seems to me that I either overlook something crucial, or the current implementation of NavmeshRegions got "lost in translation" between all the changes that have been made over the last couple of revisions.

### Steps to reproduce

Actually try to use multiple NavigationRegions

### Minimal reproduction project

[navtest.zip](https://github.com/godotengine/godot/files/12247786/navtest.zip)