Hi,
I have been working a few days in my first plugin node. Is just a pose
reader with a editable cone angle value and 3 world matrix input.
It works perfectly, but sometimes, when some automated process affects the
whole rig (like adding a constraint to the global rig and adding rotation
to it) maya freezes.
I assume it's an unexpected loop on the plugin node, but I have not enough
experience creating maya nodes to catch this error.
This is the code:
import maya.OpenMayaMPx as OpenMayaMPx
import maya.OpenMaya as om
import math
class PoseReaderNode(OpenMayaMPx.MPxNode):
kPluginNodeId = om.MTypeId(0x00000120)
coneTarget = om.MObject()
coneAperture = om.MObject()
coneBase = om.MObject()
distance = om.MObject()
coneRadius = om.MObject()
coneTargetMatrix = om.MObject()
def __init__(self):
OpenMayaMPx.MPxNode.__init__(self)
def compute(self, plug, data): #ok - the actual computation
targetInputMatrixDataHandle = om.MDataHandle(data.inputValue(
PoseReaderNode.coneTarget ))
targetValue = targetInputMatrixDataHandle.asMatrix()
apertureInputMatrixDataHandle = om.MDataHandle(data.inputValue(
PoseReaderNode.coneAperture ))
apertureValue = apertureInputMatrixDataHandle.asMatrix()
baseInputMatrixDataHandle = om.MDataHandle(data.inputValue(
PoseReaderNode.coneBase ))
baseValue = baseInputMatrixDataHandle.asMatrix()
coneRadius = data.inputValue(PoseReaderNode.coneRadius).asFloat()
disOutput = data.outputValue(PoseReaderNode.distance)
# FORM A
targetMatrix = om.MTransformationMatrix(targetValue)
apertureMatrix = om.MTransformationMatrix(apertureValue)
baseMatrix = om.MTransformationMatrix(baseValue)
target = targetMatrix.translation(om.MSpace.kWorld)
aperture = apertureMatrix.translation(om.MSpace.kWorld)
base = baseMatrix.translation(om.MSpace.kWorld)
targetVec = target - base
currentPoseVec = aperture - base
angle = math.degrees(targetVec.angle(currentPoseVec))
halfCone = float(coneRadius)*0.5
ratioAngle = float(angle)/float(halfCone)
if ratioAngle > 1:
d = 0
else:
d = 1-ratioAngle
disOutput.setFloat(float(d))
data.setClean(plug)
def creator():
return OpenMayaMPx.asMPxPtr(PoseReaderNode())
def initialize():
nAttr = om.MFnNumericAttribute()
PoseReaderNode.coneRadius = nAttr.create("coneRadius","radius",
om.MFnNumericData.kFloat,90.0)
nAttr.setWritable(True)
nAttr.setStorable(True)
PoseReaderNode.addAttribute(PoseReaderNode.coneRadius)
nAttr = om.MFnNumericAttribute()
PoseReaderNode.distance = nAttr.create("distance","dist",
om.MFnNumericData.kFloat,0.0)
nAttr.setWritable(False)
nAttr.setStorable(True)
PoseReaderNode.addAttribute(PoseReaderNode.distance)
nMatrixAttr = om.MFnMatrixAttribute()
PoseReaderNode.coneBase = nMatrixAttr.create("coneBase","base",
om.MFnMatrixAttribute.kDouble)
nMatrixAttr.setWritable(True)
nMatrixAttr.setHidden(True)
PoseReaderNode.addAttribute(PoseReaderNode.coneBase)
nMatrixAttr = om.MFnMatrixAttribute()
PoseReaderNode.coneTarget = nMatrixAttr.create("coneTarget","target",
om.MFnMatrixAttribute.kDouble)
nMatrixAttr.setWritable(True)
nMatrixAttr.setHidden(True)
PoseReaderNode.addAttribute(PoseReaderNode.coneTarget)
nMatrixAttr = om.MFnMatrixAttribute()
PoseReaderNode.coneAperture =
nMatrixAttr.create("coneAperture","aperture", om.MFnMatrixAttribute.kDouble)
nMatrixAttr.setWritable(True)
nMatrixAttr.setHidden(True)
PoseReaderNode.addAttribute(PoseReaderNode.coneAperture)
PoseReaderNode.attributeAffects(PoseReaderNode.coneTarget,
PoseReaderNode.distance)
PoseReaderNode.attributeAffects(PoseReaderNode.coneRadius,
PoseReaderNode.distance)
PoseReaderNode.attributeAffects(PoseReaderNode.coneAperture,
PoseReaderNode.distance)
def initializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj, 'AnimaPoseReader', '0.1', 'macka')
try:
plugin.registerNode('AnimaPoseReader',
PoseReaderNode.kPluginNodeId, creator, initialize)
except:
raise RuntimeError, 'initialization fail'
def uninitializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj)
try:
plugin.deregisterNode(PoseReaderNode.kPluginNodeId)
except:
raise RuntimeError, 'not unloading!'
I thought about the attributeAffects, but commenting those lines works the
same (crappy)
Any idea about that would be really welcome guys, I really don't know where
to look at my code.
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/33839d93-e110-4479-8f10-fed20e4b3e28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.