scripted/pyVertexBufferMutator.py
         
    
    9 import maya.api.OpenMayaRender 
as omr
 
   10 import maya.api.OpenMaya 
as om
 
   24     The presence of this function tells Maya that the plugin produces, and 
   25     expects to be passed, objects created using the Maya Python API 2.0. 
   29 class MyCustomBufferMutator(omr.MPxVertexBufferMutator):
 
   31         omr.MPxVertexBufferMutator.__init__(self)
 
   33     def modifyVertexStream(self, object, vertexBuffer, targetIndexing):
 
   36         descriptor = vertexBuffer.descriptor()
 
   39         if descriptor.dataType != omr.MGeometry.kFloat:
 
   43         if descriptor.dimension != 3:
 
   47         if descriptor.semantic != omr.MGeometry.kPosition:
 
   52         mesh = om.MFnMesh(object)
 
   54         vertexCount = vertexBuffer.vertexCount()
 
   59         buffer = vertexBuffer.acquire(vertexCount, 
False)   
 
   64         for i 
in range(0, vertexCount):
 
   71             x = c_float.from_address(xaddr).value
 
   72             c_float.from_address(xaddr).value = c_float.from_address(yaddr).value   
 
   73             c_float.from_address(yaddr).value = c_float.from_address(zaddr).value   
 
   74             c_float.from_address(zaddr).value = x                                   
 
   77         vertexBuffer.commit(buffer)
 
   81 def createMyCustomBufferMutator():
 
   82     return MyCustomBufferMutator()
 
   86 def initializePlugin(obj):
 
   88     omr.MDrawRegistry.registerVertexBufferMutator(
"swizzlePosition", createMyCustomBufferMutator)
 
   90 def uninitializePlugin(obj):
 
   92     omr.MDrawRegistry.deregisterVertexBufferMutator(
"swizzlePosition")