When working with mesh geometry through the bmesh object, we can “recalculate” the normals – rotate the normals in the opposite direction, starting from the direction of the normals of neighboring polygons.
Let’s create a bmesh object and store the geometry of the currently selected mesh into it.
1 2 |
bm = bmesh.new() bm.from_mesh(bpy.context.object.data) |
To recalculate the direction of the normals, we can use the recalc_face_normals() operator.
1 2 3 4 |
bmesh.ops.recalc_face_normals( bm, faces=[face for face in bm.faces] ) |
The parameters passed to the operator are the bmesh object and the list of polygons for which normals need to be recalculated.
Then we will return the corrected geometry to the active mesh.
1 2 |
bm.to_mesh(bpy.context.object.data) bm.free() |