Best approach for flipping faces of imported meshes in code?

Godot Version

v4.5.1.stable.mono.official [f62fdbde1]

Question

I have a complex 3D scene produced by a niche external application with a large amount of objects that I’m importing into Godot using a .gltf file, but because of some quirk of the application, the faces of the meshes are pointed the wrong way, i.e. inwards.

I have no other options for source application or file format, and taking the file through Blender and flipping the faces back around manually (or even using Blender automation) would be a huge pain as an added step in the pipeline because the scene is large and being worked on in the source application concurrently with development, changing and being re-imported constantly.

So, I need to flip the mesh faces in Godot as part of the import process. I don’t want to simply change the materials to cull the front side instead of the back, since the meshes will be used for collision and likely with non-standard shaders and so on … I need the geometry to be corrected as it comes in, so it doesn’t become an extra thing I have to remember to handle in all its subsequent uses.

I already successfully flipped the vertex normals in the EditorScenePostImport script I have set up for other processing of the scene, but simply doing that apparently doesn’t change the inherent “facing” of faces.

What would be the best approach to flip the faces of a mesh (using C#)?

Unless I’m missing something, none of the mesh editing classes seem to have anything that’d directly help with this. Would I have to break the meshes down and re-construct them “in the right order” somehow? Might there be an add-on that’d do it?

You’ll need to change triangle winding i.e. the order of vertices in triangles. I’m not aware of a way to do this automatically with Godot’s mesh classes. You’ll likely need to iterate through mesh data and rebuild it using ArrayMesh or SurfaceTool.

Godot uses clockwise winding for front faces and your application uses counterclockwise, so you’ll have to swap the order of vertices from counterclockwise to clockwise.