Message 1 of 3
Confusing discrepancy between mesh.setVertexNormal and mesh.getVertexNormal

Not applicable
09-15-2016
11:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)