3

I am struggling to set custom vertex normal vector just for certain/selected vertices in an object with python. I searched through the documentation and forums but nothing really helps so far.

This question/answer answers only to how to set split normal to a whole object. However, I want to set custom normals to just some parts of the object. See the picture below:

Changing jut one or several normals

Q: How can I add custom normals just to certain vertices in and object?

Would be helpful if someone could share something simple as possible.

brockmann
  • 12,613
  • 4
  • 50
  • 93
skywalger
  • 65
  • 1
  • 6

1 Answers1

5

Example of assigning custom normals based on vertex selection. It's just a slight modification of the code given in this answer and assigns a custom vector to vertices in selection.

enter image description here

Run the script in Object Mode and enable show_split_normal property in Edit Mode:

import bpy

context = bpy.context
ob = context.object
me = ob.data

me.use_auto_smooth = True

# Normal custom verts on each axis
me.normals_split_custom_set([(0, 0, 0) for l in me.loops])

# Set normal for selected vertices
normals = []
for v in me.vertices:
    if v.select:
    # if v.index in (0, 1, 4): # Alternatively you can ask for certain indices
        normals.append((0, 0, -0.5))
    else:
        normals.append(v.normal)

# make csn's all face up.  
me.normals_split_custom_set_from_vertices(normals)

#me.free_normals_split()

Note: As of 2.8x show_split_normal property is part of the Overlays menu:

enter image description here

brockmann
  • 12,613
  • 4
  • 50
  • 93
  • 1
    thank you thank you thank you :), that is exactly what i needed and didn't know how to. I just replace the condition "if v.select" by "if v == me.vertices[n]" and that is it – skywalger Jan 29 '20 at 17:36
  • 1
    Better ask for the index of the vertex: if v.index == 1: @skywalger For the sake of completeness, I added how to ask for multiple indices to the answer. – brockmann Jan 29 '20 at 18:34
  • @brockmann How to enable the option show_split_normal you mentioned in your answer? I was unable to find any information about that option. – vvoovv Feb 08 '20 at 12:10
  • 1
    I think for consistency it's now part of the overlays menu as of 2.8x @vvoovv: https://i.stack.imgur.com/n6EYh.png – brockmann Feb 08 '20 at 12:43
  • I see... It's the middle icon in the Normals section of the Overlays menu. I overlooked it somehow. – vvoovv Feb 08 '20 at 12:52