1 from __future__
import division
83 from builtins
import range
84 import maya.OpenMaya
as OpenMaya
85 import maya.OpenMayaMPx
as OpenMayaMPx
88 kPluginNodeTypeName =
"spCustomImagePlane"
92 class customImagePlane(OpenMayaMPx.MPxImagePlane):
100 OpenMayaMPx.MPxImagePlane.__init__(self)
102 def getInternalValue(self, plug, handle ):
103 if plug == self.aTransparency:
104 handle.setDouble( self.fTransparency )
107 return OpenMayaMPx.MPxImagePlane.getInternalValue(self, plug, handle )
109 def setInternalValue(self, plug, handle ):
110 if plug == self.aTransparency:
111 self.fTransparency = handle.asDouble()
115 return OpenMayaMPx.MPxImagePlane.setInternalValue(self, plug, handle )
117 def loadImageMap(self, fileName, frame, image):
119 image.readFromFile(fileName)
123 widthUtil = OpenMaya.MScriptUtil(0)
124 widthPtr = widthUtil.asUintPtr()
125 heightUtil = OpenMaya.MScriptUtil(0)
126 heightPtr = heightUtil.asUintPtr()
127 image.getSize( widthPtr, heightPtr )
129 width = widthUtil.getUint(widthPtr)
130 height = heightUtil.getUint(heightPtr)
131 size = width * height
134 charPixelPtr = image.pixels()
135 for i
in range( 0, size, 4 ):
137 alpha = OpenMayaScript.getCharArrayItem(charPixelPtr,alphaIndex)
138 OpenMayaScript.setCharArray( alpha * (1.0 - self.fTransparency), alphaIndex )
141 thisNode = self.thisMObject()
143 useDepthMap = fnThisNode.attribute(
"useDepthMap")
145 value = depthMap.asBool()
150 for i
in range( 0, height ):
151 for j
in range( 0, width ):
153 buffer.insert(c, -1.0)
155 buffer.insert(c, 0.0)
158 depthMapArray = OpenMaya.MScriptUtil()
159 depthMapArray.createFromList( buffer )
160 depthMapArrayFloatPtr = depthMapArray.asFloatPtr()
161 image.setDepthMap( depthMapArrayFloatPtr, width, height )
168 return OpenMayaMPx.asMPxPtr( customImagePlane() )
171 def nodeInitializer():
175 customImagePlane.aTransparency = nAttr.create(
"transparency",
"tp", OpenMaya.MFnNumericData.kDouble, 0.0)
176 nAttr.setStorable(
True)
177 nAttr.setInternal(
True)
180 nAttr.setKeyable(
True)
182 customImagePlane.addAttribute(customImagePlane.aTransparency)
185 def initializePlugin(mobject):
186 mplugin = OpenMayaMPx.MFnPlugin(mobject,
"Autodesk",
"1.0",
"Any")
188 mplugin.registerNode( kPluginNodeTypeName, kPluginNodeId, nodeCreator, nodeInitializer, OpenMayaMPx.MPxNode.kImagePlaneNode )
190 sys.stderr.write(
"Failed to register node: %s" % kPluginNodeTypeName )
195 def uninitializePlugin(mobject):
196 mplugin = OpenMayaMPx.MFnPlugin(mobject)
198 mplugin.deregisterNode( kPluginNodeId )
200 sys.stderr.write(
"Failed to register node: %s" % kPluginNodeTypeName )