1

I'm trying to extract the vertex normal of a mesh object at a particular vertex. I've noticed that I get different results when using the python API instead of the maya python commands.

Python commands (gives me the result i want):

cmds.polyNormalPerVertex("<myshapename>.vtx[523]", q=True,normalXYZ=True)

The maya python API call (gives me a different result):

# empty selection list
selectionList = om.MSelectionList()
selectionList.add(<myshapename>)

# create empty dag path object
dagPath = selectionList.getDagPath(0)

# get mesh 
mesh = om.MFnTransform(dagPath)

# get vertex normal
mesh.getVertexNormal(523, False, space=om.MSpace.kWorld)

I noticed this discrepancy when trying to extract normals on an object whose vertices are on the seam border with another object. The normals have been averaged in maya using Normals > Average Normals from the Polygons menu set.

I know it's difficult without an example object, but I'm hoping somebody has seen this problem before.

Can anyone provide a possible explanation for this discrepancy?

ejmoli
  • 145
  • 1
  • 9

1 Answers1

2

I think you just got lucky with your cmds call. The usual behavior for polyNormalPerVertex is to return all of the normals associated with the vert -- which, if it is part of more than one face, will be multiple answers to the same question. For example on a vanilla polyCube

import maya.cmds as cmds cmds.polyNormalPerVertex('pCube1.vtx[0]', q=True, normalXYZ=True) # Result: [-1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0] #

since the vert is part of three different faces.

The API call to getVertexNormal will return the averaged normal, according to the docs.

You should have better luck if you use vertexFaces in both ends -- those are less ambiguous.

theodox
  • 12,028
  • 3
  • 23
  • 36
  • ok, thanks for your answer. However, even averaging the results from `polyNormalPerVertex` does not equal the vector returned by `getVertexNormal` (and I've tried all combinations of parameters). Shouldn't they be the same? – ejmoli Feb 07 '17 at 15:32
  • They should be the same if you pick the correct weighting function -- but that is going to be recalculated each time you ask and could change if, for example, you move a vert on the other side of the same face. – theodox Feb 07 '17 at 20:23