3
$\begingroup$

I'm trying to create an exporter for a format, which includes shape key support. This format requires both vertex coordinates and normals to be specified. This should be logical, because the vertex selected on the image below won't have the same normals:

http://i.imgur.com/PztY8Qz.png

Comparing it to this one:

http://i.imgur.com/GHZkNXS.png

But I actually haven't found any way to export shape key normals. Both Bmesh Vertex and ShapeKey Vertex only store the coordinates.

Is there any way to get them?

$\endgroup$

2 Answers 2

3
$\begingroup$

The only way I can think of is to use Object.to_mesh() and read normals from this temp mesh datablock, before freeing it (see also the doc):

me = my_ob.to_mesh(scene, True, 'Render', False, False)
for v in me.vertices:
    print(v.normal)
bpy.data.meshes.remove(me)

Quite obviously, you need to set the influence of your shape key accordingly first.

$\endgroup$
0
2
$\begingroup$

Blender isn't storing these normals for each shape key, so its not simply a matter of accessing some data.

While you could calculate them yourself, this isn't very convenient.

Temporary Mesh

  • Pin the shape key so its active an no others are taken into account.
  • Read the mesh using the Object.to_mesh method.
  • Read the normals from the mesh.
  • Remove the mesh.

Existing Mesh

  • (optionally) store the vertex coordinates.
  • temporarily apply the shape-key to the mesh.
  • calculate the normals.
  • read them from the mesh (can store how you like, but be sure to copy them so as not to hold a reference to the original mesh data).
  • restore the original coordinates and optionally re-calculate normals again
    (though this could be postponed until after you're done with all of the shape-keys).
$\endgroup$

You must log in to answer this question.

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