2
$\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 Jan 27 '20 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 Jan 28 '20 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 Jan 28 '20 at 19:50
  • $\begingroup$ done, It shoud be now more understandable what I want to achieve $\endgroup$ – skywalger Jan 28 '20 at 20:02
4
$\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
  • $\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 Jan 29 '20 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 Jan 29 '20 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 Feb 8 '20 at 12:10
  • 1
    $\begingroup$ I think for consistency it's now part of the overlays menu as of 2.8x @vvoovv: i.stack.imgur.com/n6EYh.png $\endgroup$ – brockmann Feb 8 '20 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 Feb 8 '20 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.