Transfer Vertex Normal Value between different vertexes in different meshes, need help!

Hello everyone,
In order to making 2 meshes seamless between them, I’m coding a tool to transfer(copy) Vertex Normal Value between different vertexes in different meshes.
First, I get the Vertex Normal Value by MFnMesh.getVertexNormal() method in world space from the source mesh’s vertex. Then, using the normal value above, I set the Vertex Normal Value by MFnMesh.setVertexNormal() method in world space to the target mesh’s vertex. The source and target mesh vertexes are in the same position. I think, with the same vertex normal value, the seam between 2 vertex meshes will disappear. But it doesn’t! I display the vertex normal in Maya and find that the normal direction of two vertexes are different, it’s a very small different!
How could I fixed the difference? Or what’s wrong with my solution?
Thank you very much.
Yours,
Yixiong Xu
2019.11.14

If I were to guess I would say that it’s because the normals returned from getVertexNormal are calculated on the fly. According to the documentation:

So I would try the getFaceVertexNormal and setFaceVertexNormal methods.
Possibly, you could use getVertexNormal, then set all the face-vertex normals of both meshes to that value.

def copyNormal(self):
    vertex =mc.ls(sl=1,fl=1)
    global vertexNormal
    vertexNormal=mc.polyNormalPerVertex(q=1, xyz=1)

def pasteNormal(self):
    vertex =mc.ls(sl=1,fl=1)
    mc.polyNormalPerVertex(xyz=(vertexNormal[0],vertexNormal[1],vertexNormal[2]))

I used copy and paste and I hope that helped you

2 Likes

Hello StrongBread,
Thank you for your solution, it works for me!
But I want to know what happened behind the command polyNormalPerVertex. It really interests me!
How can I use maya python api to get the same result?
Yours,
Yixiong Xu
2019.11.15

Hello tfox_TD,
Really thank you for your explanation.
Unfortunately, I try the getFaceVertexNormal and setFaceVertexNormal method. But it fails.
As StrongBread’s reply, his suggestion really works for me.
I want to know what happened behind the maya.cmds.polyNormalPerVertex command, do you know it?
Anyway, thank you again for your explanation about the difference between vertex normals.
Yours,
Yixiong Xu
2019.11.15

http://download.autodesk.com/global/docs/maya2013/zh_cn/CommandsPython/polyNormalPerVertex.html
If you look at the documentation, I guess I just replaced the vector data, and I don’t know any more!