Blender – Flatten normals of mesh data in bulk

Recently I had to fix per-face-vertex normals for a project and I had to come up with a script snippet to ease the manual touches involved in the task.

Run this script on any selected object in Object Mode.

import bpy
print("Flattening per face normals ..")
current_obj = bpy.context.active_object
# Calc
current_obj.data.calc_normals_split()
# Vertex-per-face Normals
n = []
for face in current_obj.data.loops:
    n.append(face.normal.copy())
    n[face.index][1] = 0
    n[face.index] = n[face.index].normalized()
    print("i", face.index , "n", face.normal, "n2", n[face.index])

current_obj.data.normals_split_custom_set(n)
current_obj.data.update()    
current_obj.data.free_normals_split()
print("Done.")

After execution you may change into Edit Mode and see the normals flattened.

Leave a Reply

Your email address will not be published. Required fields are marked *