57 import maya.OpenMaya
as OpenMaya
58 import maya.OpenMayaMPx
as OpenMayaMPx
60 kPluginNodeName =
"spGeomShader"
61 kPluginNodeClassify =
"utility/color"
64 class geomShader(OpenMayaMPx.MPxNode):
66 OpenMayaMPx.MPxNode.__init__(self)
72 def compute(self, plug, block):
73 if plug == geomShader.aOutColor
or plug.parent() == geomShader.aOutColor:
76 point = block.inputValue( geomShader.aPoint ).asFloatVector()
77 scale = block.inputValue( geomShader.aScale ).asFloatVector()
78 offset = block.inputValue( geomShader.aOffset ).asFloatVector()
80 resultColor.x = point.x * scale.x + offset.x
81 resultColor.y = point.y * scale.y + offset.y
82 resultColor.x = point.z * scale.z + offset.z
84 outColorHandle = block.outputValue( geomShader.aOutColor )
85 outColorHandle.setMFloatVector(resultColor)
86 outColorHandle.setClean()
88 return OpenMaya.kUnknownParameter
92 return OpenMayaMPx.asMPxPtr( geomShader() )
94 def nodeInitializer():
98 geomShader.aPoint = nAttr.createPoint(
"pointObj",
"p")
102 geomShader.aScale = nAttr.createPoint(
"scale",
"s")
107 nAttr.setDefault(1.0, 1.0, 1.0)
109 geomShader.aOffset = nAttr.createPoint(
"offset",
"o")
115 geomShader.aOutColor = nAttr.createColor(
"outColor",
"oc")
122 sys.stderr.write(
"Failed to create attributes\n")
126 geomShader.addAttribute(geomShader.aPoint)
127 geomShader.addAttribute(geomShader.aScale)
128 geomShader.addAttribute(geomShader.aOffset)
129 geomShader.addAttribute(geomShader.aOutColor)
131 sys.stderr.write(
"Failed to add attributes\n")
135 geomShader.attributeAffects (geomShader.aPoint, geomShader.aOutColor)
136 geomShader.attributeAffects (geomShader.aScale, geomShader.aOutColor)
137 geomShader.attributeAffects (geomShader.aOffset, geomShader.aOutColor)
139 sys.stderr.write(
"Failed in setting attributeAffects\n")
144 def initializePlugin(mobject):
145 mplugin = OpenMayaMPx.MFnPlugin(mobject)
147 mplugin.registerNode( kPluginNodeName, kPluginNodeId, nodeCreator,
148 nodeInitializer, OpenMayaMPx.MPxNode.kDependNode, kPluginNodeClassify )
150 sys.stderr.write(
"Failed to register node: %s" % kPluginNodeName )
154 def uninitializePlugin(mobject):
155 mplugin = OpenMayaMPx.MFnPlugin(mobject)
157 mplugin.deregisterNode( kPluginNodeId )
159 sys.stderr.write(
"Failed to deregister node: %s" % kPluginNodeName )