Vertex normal direction not updating after setting manually?

so I have some vertex selected and I hit the Alt-L shortcut of “Point to target”, then “O” to aim this normal to the object’s origin and then I confirm this action by pressing Enter. (To see this happen, it is good to enable “Display Split Normals” in the scene)

I have just changed the vertex normal direction.
In console is something like this:
bpy.ops.mesh.point_normals(target_location=(3.32336, 4.02014, -1.43947))

now if I would print the selected vertex’s direction by some console command like: print(selectedVertex.normal)
https://docs.blender.org/api/current/bpy.types.MeshVertex.html?highlight=vertex%20normal#bpy.types.MeshVertex.normal

it would give me some direction vector like: <Vector (1, 1, 1)>

My problem is, whatever direction I point this normal onto using Alt-L method, the <Vector (1, 1, 1)> will never get updated and will always stay the same!

Does somebody know how to manually update this Vector, or different method how to point Vertex Normal onto desired target?

Thanks!

MeshVertex.normal is vertex normal, not split normals
bpy.ops.mesh.point_normals changes split normals
To get split normals try running this code in the blender text editor

import bpy, bmesh

def get_vertex_normal():
        ob = bpy.context.edit_object
        ob.update_from_editmode()
        ob_matrix = ob.matrix_world
        mesh = ob.data
        mesh.calc_normals_split()
        bm = bmesh.from_edit_mesh(mesh)

        # Determine which vertex is selected.
        selected_vert = [v for v in bm.verts if v.select][0]

        # Gather world space normal vectors associated with selected vertex.
        normals = set(
            (ob_matrix @ mesh.loops[loop.index].normal).to_tuple()
            for loop in selected_vert.link_loops
        )
        
        normals = list(normals)
        num_normals = len(normals)
        
        # Return early if selected vertex is not part of a face.
        if not num_normals:
            return {'CANCELLED'}

        return normals


print(get_vertex_normal())
bpy.ops.mesh.point_normals(target_location=(3.32336, 4.02014, -1.43947))
print(get_vertex_normal())

If you select vert and run this code it will print split normals before and after bpy.ops.mesh.point_normals command

1 Like

I knew it!! I was using the wrong function!
Thanks! I think that is exactly what I am looking for.

Can you tell me where did you find this info or how you learned this? I spent a week looking for solution myself and I couldn’t find much information about this topic. Where are the best places / sources to look?

I am going to implement this into my code and later I will share here for everyone the final add-on I am working on.

Thanks again for a very clean code!

I found it in the source of addon for editing normals https://github.com/fedackb/yavne/blob/master/operators.py line 365

1 Like

Do you know if editing normals make changes permanent? I remember in older versions of Blender that normals would be recalculated automatically (without asking) and result into loosing your edits.

I think it will make changes permanent when you use the bpy.ops.mesh.point_normals() function.

For me this was successful when I edited the split Normals like this and then used the .blend file in Unity where the normals were showing exactly as I set them.

EDIT: Yes, changes are permanent even after transporting .blend file into Unity.

I finally finished the whole addon and it is available for download on my github. I decided to share it here since it is related to the topic:

I had to figure out few workarounds but it somehow works now :slight_smile:

Thanks everyone for help and feel free to contact me regarding any suggestions.

Cheers!

1 Like