2

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!

2 Answers2

2

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.

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
Petar
  • 21
  • 3
  • 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. – Madlaina Kalunder May 08 '16 at 10:49
0

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)
Mutant Bob
  • 9,243
  • 2
  • 29
  • 55
  • 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) – Madlaina Kalunder Mar 24 '16 at 12:44
  • 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. – Mutant Bob Mar 24 '16 at 15:01
  • 2
    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. – Mutant Bob Mar 24 '16 at 15:12