Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the orientation of generated NavigationMeshes so they face up #23818

Closed
wants to merge 3 commits into from

Conversation

needleful
Copy link
Contributor

@needleful needleful commented Nov 19, 2018

Now the faces of a navigation mesh point towards the specified "up" vector.

Fixes #23817

This should not (and from my testing, doesn't) affect the path-finding behavior of a navmesh, only its appearance in the editor, but feel free to double-check.

I think (and I only looked at this for like an hour so I'm no expert) this bug was because the ReCast library orients the faces of meshes counter-clockwise, while Godot orients them clockwise. This was taken into account when inputting meshes to ReCast, but apparently forgotten about when getting the generated navmesh.

@needleful needleful changed the title Changed the orientation of generated NavigationMeshes Change the orientation of generated NavigationMeshes so they face up Nov 19, 2018
@akien-mga akien-mga added this to the 3.1 milestone Nov 19, 2018
Now the faces of a navigation mesh point towards the specified "up"
vector, as intended.

Fixes godotengine#23817
@slapin
Copy link
Contributor

slapin commented Nov 20, 2018

If the problem is just visual representation I'd suggest changing of debug mesh generation only.

@needleful
Copy link
Contributor Author

Sorry, I don't know what you mean. I'm only seeing one mesh being referred to in a NavigationMeshInstance, so I'm not sure if you mean a "debug mesh" that I haven't noticed that's only used for viewing, or only changing the orientation if the engine is built targeting debug, or something else.

Imported navmeshes are rendered as expected, so I wouldn't want to change how all of them are rendered, just the meshes baked by the editor.

@slapin
Copy link
Contributor

slapin commented Nov 21, 2018 via email

@slapin
Copy link
Contributor

slapin commented Nov 21, 2018

basically just set material's cull_mode to CULL_DISABLED. This way it will disable cull mode and navmeshes will work as intended.

@needleful
Copy link
Contributor Author

Sorry for irregular responses, I'm traveling right now. I'll change the commit so it just changes the material.

@needleful
Copy link
Contributor Author

After some thinking, I'd argue we flip the faces, since this is a bug in the mesh generation, rather than the rendering. I'd rather not change how all navmeshes are rendered just to make the generated meshes look good.
I made a brute-force test to see if there were any differences between the regular and flipped navmeshes: navmesh-test.zip. It generated several thousand paths using the two navmeshes, and they always generated the exact same paths, so I feel confident that the polygon orientation doesn't affect the navigation, since it doesn't change the edges or vertices.

@slapin
Copy link
Contributor

slapin commented Nov 23, 2018 via email

@needleful
Copy link
Contributor Author

Ok, fair enough. You know more about the navmeshes and Recast than I do, so I'll take your word that there's behavior depending on the order of the edges. I just didn't want to be masking over a bug, if this fixed it. Even if it were a small bug, that's not a pattern I want to fall into.

@needleful
Copy link
Contributor Author

needleful commented Nov 24, 2018

After trying to get this working, I've discovered that NavigationMesh::get_debug_mesh and SceneTree::get_debug_navigation_material are never called when editing, and NavigationMesh::debug_mesh and NavigationMeshInstance::debug_view are both null. Those are only used when --navigation-debug is passed at the start of a game.
In the editor, the navmesh is rendered through NavigationMeshSpatialGizmoPlugin. In order to change the culling on the material for the gizmo, I had to change the EditorSpatialGizmoPlugin::create_material method to accept the culling mode as an optional parameter. While other gizmos could require a specific culling mode for various reasons, I'm not sure I want to be touching basic editor methods.

@needleful
Copy link
Contributor Author

I still feel like changing the mesh generation, even if what I had wasn't the solution, is preferable to changing the material. It's possible some users will want to know what direction the face of a navmesh is oriented, for example to align their navigation agent as it goes up walls/on ceilings/etc. With generated navmeshes being oriented the wrong way, that would be harder to do, especially if they mix generated and hand-made navmeshes. While ignoring the orientation fixes the basic uses, it only hides potential problems for more advanced cases.

@slapin
Copy link
Contributor

slapin commented Nov 24, 2018 via email

@needleful
Copy link
Contributor Author

I'll look into it more. I wasn't previously aware that winding order was used for anything, so I'll experiment and see what the best way to go about it is. It seems the issue is with how the navmesh is converted from Recast's format to Godot's, so I bet there's a way to preserve any relevant information about the graph while fixing the mesh.

@needleful
Copy link
Contributor Author

I'll close this pull request, and come back when I've got a way to fix the meshes while preserving the graph.

@needleful needleful closed this Nov 26, 2018
@needleful needleful deleted the navmesh-orientation branch March 18, 2023 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants