2
$\begingroup$

I have a question concerning BMesh and custom vertex normals editing. At the moment I am writing a little blender importer for a custom data format and I am stuck with importing/manipulating custom vertex normals. I am using the bmesh module because I want to use it's functionalities before transforming the bmesh into a real mesh.

Can anyone tell me if it is possible to set the normals with bmesh? Do I need to import them with the Mesh module?

Thanks a lot in advance for any tipp!

$\endgroup$
3

2 Answers 2

2
$\begingroup$

I believe since Blender 2.74, this was made possible for the bpy Mesh type. You can use the mesh normals_split_custom_set method to do this.

In this example, I only have per-vertex normals so I create a new list with one normal corresponding to each loop.

normals2 = []
for l in mesh.loops:
    normals2.append(normals[l.vertex_index])
mesh.normals_split_custom_set(normals2)
mesh.use_auto_smooth = True

Note that auto smooth needs to be enabled for this to work.

In my case, I could have used the normals_split_custom_set_from_vertices method, and passed in normals directly.

$\endgroup$
1
  • $\begingroup$ Yes, thats what I am doing now. Thanks. I WANT to use the Bmesh module though because of it's functionalities. Vertex normals are not supported (yet) though - it turns out - and the information gets lost if you transform the mesh to bmesh. $\endgroup$ May 8, 2016 at 10:49
0
$\begingroup$

It is probably as simple as

mesh = obj.data
bm = bmesh.new()
bm.from_mesh(mesh)

bm.verts[i].normal = [ x,y,z]

bm.to_mesh(mesh)
$\endgroup$
3
  • $\begingroup$ Thanks for your suggestion, sadly it's not that easy since I need to set the normals per face loop (one vertex can habe multiple normals, which is the whole purpose of split normals) $\endgroup$ Mar 24, 2016 at 12:44
  • $\begingroup$ The few things I have read imply that blender does not fully support per-face vertex normals yet. I don't know if it is on the roadmap. $\endgroup$
    – Mutant Bob
    Mar 24, 2016 at 15:01
  • 2
    $\begingroup$ And even setting per-vertex normals seems to be ineffective. You can even do obj.data.vertices[0].normal = [1,0,0] and the value will be reset to default if you go in and out of edit mode. $\endgroup$
    – Mutant Bob
    Mar 24, 2016 at 15:12

You must log in to answer this question.

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