Found some code for creating custom locator and added a keyable attribute.
Question: How can I cause the locator to be re-drawn when the attribute
value changes?
Code:
import sys
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
import maya.OpenMayaRender as OpenMayaRender
nodeTypeName = "jointLocator"
nodeTypeId = OpenMaya.MTypeId(0x87079)
glRenderer = OpenMayaRender.MHardwareRenderer.theRenderer()
glFT = glRenderer.glFunctionTable()
class myNode(OpenMayaMPx.MPxLocatorNode):
jointLength = OpenMaya.MObject()
jointRadius = OpenMaya.MObject()
def __init__(self):
OpenMayaMPx.MPxLocatorNode.__init__(self)
self._jointLength = 100
self._jointRadius = 100
def draw(self, view, path, style, status):
drawOnTop = True
if drawOnTop == True:
glFT.glPushAttrib(OpenMayaRender.MGL_ALL_ATTRIB_BITS)
view.beginGL()
if drawOnTop == True:
glFT.glClearDepth(0.0)
glFT.glDepthFunc(OpenMayaRender.MGL_ALWAYS)
glFT.glBegin(OpenMayaRender.MGL_LINES)
glFT.glVertex3f(0.0, self._jointLength, 0.0)
glFT.glVertex3f(0.0, 0.0, 0.0)
glFT.glEnd()
view.endGL()
if drawOnTop == True:
glFT.glPopAttrib()
def compute(self, plug, data):
if plug == myNode.jointLength:
self._jointLength = data.inputValue(myNode.jointLength).asFloat()
hOutput = data.outputValue(myNode.jointLength)
hOutput.setFloat(self._jointLength)
data.setClean(plug)
""" TODO: INVALIDATE LOCATOR SHAPE HERE """
return OpenMaya.MStatus.kSuccess
if plug == myNode.jointLength:
self._jointRadius = data.inputValue(myNode.jointRadius).asFloat()
hOutput = data.outputValue(myNode.jointRadius)
hOutput.setFloat(self._jointRadius)
data.setClean(plug)
""" TODO: INVALIDATE LOCATOR SHAPE HERE """
return OpenMaya.MStatus.kSuccess
return OpenMaya.MStatus.kUnknownParameter
def nodeCreator():
return OpenMayaMPx.asMPxPtr(myNode())
def nodeInitializer():
nAttr = OpenMaya.MFnNumericAttribute()
myNode.jointRadius = nAttr.create('jointRadius', 'out',
OpenMaya.MFnNumericData.kFloat)
nAttr.setKeyable(True)
myNode.addAttribute(myNode.jointRadius)
myNode.jointLength = nAttr.create('jointLength', 'in',
OpenMaya.MFnNumericData.kFloat)
nAttr.setKeyable(True)
myNode.addAttribute(myNode.jointLength)
def initializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj)
try:
plugin.registerNode(nodeTypeName, nodeTypeId, nodeCreator, nodeInitializer,
OpenMayaMPx.MPxNode.kLocatorNode)
except:
sys.stderr.write( "Failed to register node: %s" % nodeTypeName)
def uninitializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj)
try:
plugin.deregisterNode(nodeTypeId)
except:
sys.stderr.write( "Failed to deregister node: %s" % nodeTypeName)
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe