Showing posts with label plugin. Show all posts
Showing posts with label plugin. Show all posts

Wednesday, 14 December 2011

Locking vertex normals using Maya API

OpenMaya.MFnMesh.lockFaceVertexNormals is the function to use but it's got not very clear from the documentation what you need to pass to it. It needs an array of faces and of vertices formed like this:
faces = ( 0, 0, 0, 0, 1, 1, 1, 1 )
verts = ( 1, 2, 3, 4, 1, 2, 5, 6 )
In this example the face with index 0 will have vertices 1, 2, 3 and 4 locked. Face 1 will have vertices 1, 2, 5, 6 locked. This code will lock all vertex face normals:

verts = OpenMaya.MIntArray()
faces = OpenMaya.MIntArray()
vertsForFace = OpenMaya.MIntArray()
for faceID in range( meshFn.numPolygons() ) :
meshFn.getPolygonVertices( faceID, vertsForFace )
for i in range( vertsForFace.length() ) :
faces.append( faceID )
verts.append( vertsForFace[i] )
meshFn.lockFaceVertexNormals( faces, verts )

Tuesday, 18 October 2011

Handling HasNoEffect state on a plugin node.

If you're writing a Maya plugin node, you might want to handle the case where the user sets the node state to HasNoEffect. The state is an input attribute that is implicitly defined for any node. You can query it in a similar way to any other input attribute:
stateHnd = dataBlock.inputValue( self.state ) #MDataHandle
if stateHnd.asInt() == 1 :
inMeshHnd = dataBlock.inputValue( self.inMesh )
outMeshHnd = dataBlock.outputValue( self.outMesh )
inMeshObj = inMeshHnd.asMesh() # MObject
outMeshHnd.setMObject( inMeshObj )
dataBlock.setClean( plug )
return OpenMaya.MStatus.kSuccess