Confusing discrepancy between mesh.setVertexNormal and mesh.getVertexNormal

Confusing discrepancy between mesh.setVertexNormal and mesh.getVertexNormal

Anonymous
Not applicable
457 Views
2 Replies
Message 1 of 3

Confusing discrepancy between mesh.setVertexNormal and mesh.getVertexNormal

Anonymous
Not applicable

I'm trying to reproduce an issue where geometries loaded in maya have a zero-length normal. I try to create a shape and set the normal to 0,0,0, using "setVertexNormal" command, but when I query the MfnMesh using "getVertexNormal" command I don't see the same vector i.e. 0,0,0. The view port does show the effects of a zero-normal (black around the vertex) and I've tried deleting history, but no luck.

 

Please help.

 

Consider the code below:

 

api.py

import maya.api.OpenMaya as om
import maya.api.OpenMayaAnim as anim

# API interfaces ==========================================================================================

def getDag(id):
'''
'''
# add object path string a selection list
selectionList = om.MSelectionList()
selectionList.add(id)

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

return dagPath

def getMesh(id):
'''
:param id:
:return: MFnMesh object
'''
dag = getDag(id)
return om.MFnMesh(dag)
def createSpace(spaceName):

if spaceName == "kInvalid":
return om.MSpace.kInvalid
elif spaceName == "kTransform":
return om.MSpace.kTransform
elif spaceName == "kPreTransform":
return om.MSpace.kPreTransform
elif spaceName == "kPostTransform":
return om.MSpace.kPostTransform
elif spaceName == "kWorld":
return om.MSpace.kWorld
elif spaceName == "kObject":
return om.MSpace.kObject
elif spaceName == "kLast":
return om.MSpace.kLast
else:
return om.MSpace.kInvalid
 
def convertVector(mVec):
return [mVec.x, mVec.y, mVec.z]

def createVector(seq):
if len(seq)>3:
return None
return om.MVector(seq)


main.py

 

import api as api
#create
shapeId = "myTestSphere"
cmds.polySphere(name="myTestSphere",radius=1.0)
mesh = api.getMesh(shapeId)

#set
badNormal = api.createVector([0.0, 0.0,0.0])
space = api.createSpace("kPreTransform")
mesh.setVertexNormal(badNormal, 1,space=space)

#query
mesh = None
mesh = api.getMesh(shapeId)
spaces = ["kTransform","kPreTransform","kPostTransform","kWorld","kObject"]
for spaceType in spaces:
space = api.createSpace(spaceType)
print mesh.getVertexNormal(79,False,space=space)
0 Likes
458 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Correction:

 

The vertex is 1 for both set and get, so ... the main.py script is

 

#create
shapeId = "myTestSphere"
cmds.polySphere(name="myTestSphere",radius=1.0)
mesh = api.getMesh(shapeId)

#set
badVertex = 1
badNormal = api.createVector([0.0, 0.0,0.0])
space = api.createSpace("kPreTransform")
mesh.setVertexNormal(badNormal, badVertex, space=space)

#query
mesh = None
mesh = api.getMesh(shapeId)

spaces = ["kTransform","kPreTransform","kPostTransform","kWorld","kObject"]
for spaceType in spaces:
space = api.createSpace(spaceType)
print mesh.getVertexNormal(badVertex, False, space=space)

And the output is

 

(0.126539, -0.987692, -0.0919362)
(0.126539, -0.987692, -0.0919362)
(0.126539, -0.987692, -0.0919362)
(0.126539, -0.987692, -0.0919362)
(0.126539, -0.987692, -0.0919362)

 

 

0 Likes
Message 3 of 3

Anonymous
Not applicable

I may finally understand what is actually happening. In order to reproduce the case I was seeing where a vertex's normal vector was 0,0,0, I took a cube and took four vertices of the same face and snapped them together. In such a case the vertex normal is [0,0,0].

 

In the test case I tried to make by setting the normal to 0,0,0 directly, I"m guessing that maya doesn't really change the true shape normals? It seems to know to draw that normal as if it were 0,0,0, perhaps like a normal map mapping to 0,0,0. 

 

Is that correct?

0 Likes