I'm trying to make a script to apply vertex normals based on selected faces. So far I have written the script and it works fine, but if I exit edit mode and then re-enter edit mode, the normals get automatically recalculated by blender and look wrong again. Is there some way to stop blender recalculating the normals when entering edit mode? I have set autosmooth on the model.
Here is the script:
import bpy import bmesh import mathutils me = bpy.context.object.data bm = bmesh.from_edit_mesh(me) selected_verts = [v for v in bm.verts if v.select] for v in selected_verts: # get all the selected faces linked to the vertex ls_faces = [f for f in v.link_faces if f.select] # set vertex normal to average of face normals if len(ls_faces) > 0: average_normal = mathutils.Vector() for f in ls_faces: average_normal += f.normal average_normal /= len(ls_faces) v.normal = average_normal bmesh.update_edit_mesh(me, False, False)
Here are some images that show what the script is for (this kind of thing is very handy for game models, especially toon shaded models). The script appears to be working fine, but whenever I go back to edit mode after leaving it, the normals revert to how the object looks in the left image.