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

Godot winding direction for SurfaceTool, ArrayMesh, and MeshDataTool are incorrect #10757

Open
Kevin-Jonaitis opened this issue Mar 11, 2025 · 1 comment

Comments

@Kevin-Jonaitis
Copy link

Your Godot version:
v4.4.beta4.official.93d270693

Issue description:

In the documentation for SurfaceTool, ArrayMesh, and MeshDataTool it states:

Note: Godot uses clockwise winding order for front faces of triangle primitive modes.

I've been banging my head against this problem for quite a few hours, googled all around, and I think this is just incorrect in the documentation.

I believe Godot uses counterclockwise winding order when dealing with primitive triangles.

And indeed, in the documentation that the godot docs link to on https://learnopengl.com/ it says

By default, triangles defined with counter-clockwise vertices are processed as front-facing triangles.

And on the official openGL documentation it states:

On a freshly created OpenGL Context, the default front face is GL_CCW.

I tested a project that I'll link below, but I wrote some code to do the winding order as follows:

var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_vertex(Vector3(0, 2, 0))
st.add_vertex(Vector3(2, 2, 2))
st.add_vertex(Vector3(0, 2, 2))
var mesh = st.commit()

I think you can agree this is a clockwise winding order, and assuming godot is a right-handed coordinate system, you'd expect the normal face to point "down"(-Y axis in 3D godot).

However, I created a simple project, and that's simply not the case; you can see the triangle from "above" but not below, which implies that the triangle normal is actually facing "up"(+Y). See the yellow triangle below:

Image

Looking "down"(-Y):

Image

Here's the project with the above code:

winding_direction_test.zip

URL to the documentation page:
https://docs.godotengine.org/en/stable/classes/class_surfacetool.html#description
https://docs.godotengine.org/en/stable/classes/class_arraymesh.html
https://docs.godotengine.org/en/stable/classes/class_meshdatatool.html

Maybe I'm misunderstanding something here, so please double check me if I've got this right. I'll attach the sample project with the above code to the issue.

If the docs are wrong, I'm happy to submit a pull request to update the docs.

@pyramid3d
Copy link

Your camera is facing toward Y-. The viewport axes are X+ to the right and Z+ down.
Hence, seen from the camera toward the triangle, the face is drawn clockwise (x,z: 0,0 > 2,2 > 0,2), and therefore the front face is towards the camera.
This means Godot face winding order is clockwise, because the clockwise ordered vertices of the triangle are facing toward the viewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants