3
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ Does this answer your question? There is a way to add custom split normal use Python API? $\endgroup$
    – brockmann
    Commented Jan 27, 2020 at 23:12
  • $\begingroup$ Nope it doesn't...I still don't know how to set custom split normal only for certain vertex normals in an object $\endgroup$
    – skywalger
    Commented Jan 28, 2020 at 19:38
  • $\begingroup$ Edit your question, add what's wrong with the linked answer, what you've tried or what you'd like to get to your question in order to re-open it @skywalger $\endgroup$
    – brockmann
    Commented Jan 28, 2020 at 19:50
  • $\begingroup$ done, It shoud be now more understandable what I want to achieve $\endgroup$
    – skywalger
    Commented Jan 28, 2020 at 20:02

1 Answer 1

5
$\begingroup$

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

$\endgroup$
5
  • 1
    $\begingroup$ 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 $\endgroup$
    – skywalger
    Commented Jan 29, 2020 at 17:36
  • 1
    $\begingroup$ 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. $\endgroup$
    – brockmann
    Commented Jan 29, 2020 at 18:34
  • $\begingroup$ @brockmann How to enable the option show_split_normal you mentioned in your answer? I was unable to find any information about that option. $\endgroup$
    – vvoovv
    Commented Feb 8, 2020 at 12:10
  • 1
    $\begingroup$ I think for consistency it's now part of the overlays menu as of 2.8x @vvoovv: i.sstatic.net/n6EYh.png $\endgroup$
    – brockmann
    Commented Feb 8, 2020 at 12:43
  • $\begingroup$ I see... It's the middle icon in the Normals section of the Overlays menu. I overlooked it somehow. $\endgroup$
    – vvoovv
    Commented Feb 8, 2020 at 12:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .