lab00
02-14-2008, 09:33 AM
Hi all,
i'm trying to create in Python a node with 2 input vectors and 1 output vector.
The compute function does the vector sum between the 2 inputs and store
the result in the output vector. The problem is that it stores totally crazy and random
numbers inside the output vectors.
This is the code:
import math, sys
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
kPluginNodeTypeName = "testNode"
kPluginNodeId = OpenMaya.MTypeId(0x87003)
# Node definition
class testMe(OpenMayaMPx.MPxNode):
# class variables
aInput = OpenMaya.MObject()
bInput = OpenMaya.MObject()
aOutput = OpenMaya.MObject()
def __init__(self):
OpenMayaMPx.MPxNode.__init__(self)
def compute(self, plug, data):
# Check that the requested recompute is one of the output values
if (plug == testMe.aOutput):
# Read the input values
inputA = OpenMaya.MVector()
inputB = OpenMaya.MVector()
result = OpenMaya.MVector()
hValue = data.inputValue(testMe.aInput)
inputA = hValue.asVector()
hValue = data.inputValue(testMe.bInput)
inputB = hValue.asVector()
result = inputA + inputB
# Set the output values
hOutValue = data.outputValue(testMe.aOutput)
hOutValue.setMVector(result)
data.setClean(plug)
else:
return OpenMaya.MStatus.kUnknownParameter
return OpenMaya.MStatus.kSuccess
# creator
def nodeCreator():
return OpenMayaMPx.asMPxPtr( testMe() )
# initializer
def nodeInitializer():
nAttr = OpenMaya.MFnNumericAttribute()
# Setup the input attributes
testMe.aInput = nAttr.create("aInput", "aIn", OpenMaya.MFnNumericData.k3Float, 0.0 )
nAttr.setStorable(True)
nAttr.setKeyable(True)
testMe.bInput = nAttr.create("bInput", "bIn", OpenMaya.MFnNumericData.k3Float, 0.0 )
nAttr.setStorable(True)
nAttr.setKeyable(True)
testMe.aOutput = nAttr.create("output", "out", OpenMaya.MFnNumericData.k3Float, 0.0)
nAttr.setWritable(False)
nAttr.setStorable(False)
# Add the attributes to the node
testMe.addAttribute(testMe.aInput)
testMe.addAttribute(testMe.bInput)
testMe.addAttribute(testMe.aOutput)
# Set the attribute dependencies
testMe.attributeAffects(testMe.aInput, testMe.aOutput)
testMe.attributeAffects(testMe.bInput, testMe.aOutput)
def initializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:
mplugin.registerNode( kPluginNodeTypeName, kPluginNodeId, nodeCreator, nodeInitializer )
except:
sys.stderr.write( "Failed to register node: %s" % kPluginNodeTypeName )
raise
# uninitialize the script plug-in
def uninitializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:
mplugin.deregisterNode( kPluginNodeId )
except:
sys.stderr.write( "Failed to deregister node: %s" % kPluginNodeTypeName )
raise
I tried to change this line:
result = inputA + inputB
with this:
result = inputA
and with this too:
result = inputB
And in this two cases the resultant vector is the same as the input one.
So i believe the problem is in the vector sum...
result = inputA + inputB
I don't know...
Could anyone tell me where's the error?
Thanks
i'm trying to create in Python a node with 2 input vectors and 1 output vector.
The compute function does the vector sum between the 2 inputs and store
the result in the output vector. The problem is that it stores totally crazy and random
numbers inside the output vectors.
This is the code:
import math, sys
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
kPluginNodeTypeName = "testNode"
kPluginNodeId = OpenMaya.MTypeId(0x87003)
# Node definition
class testMe(OpenMayaMPx.MPxNode):
# class variables
aInput = OpenMaya.MObject()
bInput = OpenMaya.MObject()
aOutput = OpenMaya.MObject()
def __init__(self):
OpenMayaMPx.MPxNode.__init__(self)
def compute(self, plug, data):
# Check that the requested recompute is one of the output values
if (plug == testMe.aOutput):
# Read the input values
inputA = OpenMaya.MVector()
inputB = OpenMaya.MVector()
result = OpenMaya.MVector()
hValue = data.inputValue(testMe.aInput)
inputA = hValue.asVector()
hValue = data.inputValue(testMe.bInput)
inputB = hValue.asVector()
result = inputA + inputB
# Set the output values
hOutValue = data.outputValue(testMe.aOutput)
hOutValue.setMVector(result)
data.setClean(plug)
else:
return OpenMaya.MStatus.kUnknownParameter
return OpenMaya.MStatus.kSuccess
# creator
def nodeCreator():
return OpenMayaMPx.asMPxPtr( testMe() )
# initializer
def nodeInitializer():
nAttr = OpenMaya.MFnNumericAttribute()
# Setup the input attributes
testMe.aInput = nAttr.create("aInput", "aIn", OpenMaya.MFnNumericData.k3Float, 0.0 )
nAttr.setStorable(True)
nAttr.setKeyable(True)
testMe.bInput = nAttr.create("bInput", "bIn", OpenMaya.MFnNumericData.k3Float, 0.0 )
nAttr.setStorable(True)
nAttr.setKeyable(True)
testMe.aOutput = nAttr.create("output", "out", OpenMaya.MFnNumericData.k3Float, 0.0)
nAttr.setWritable(False)
nAttr.setStorable(False)
# Add the attributes to the node
testMe.addAttribute(testMe.aInput)
testMe.addAttribute(testMe.bInput)
testMe.addAttribute(testMe.aOutput)
# Set the attribute dependencies
testMe.attributeAffects(testMe.aInput, testMe.aOutput)
testMe.attributeAffects(testMe.bInput, testMe.aOutput)
def initializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:
mplugin.registerNode( kPluginNodeTypeName, kPluginNodeId, nodeCreator, nodeInitializer )
except:
sys.stderr.write( "Failed to register node: %s" % kPluginNodeTypeName )
raise
# uninitialize the script plug-in
def uninitializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:
mplugin.deregisterNode( kPluginNodeId )
except:
sys.stderr.write( "Failed to deregister node: %s" % kPluginNodeTypeName )
raise
I tried to change this line:
result = inputA + inputB
with this:
result = inputA
and with this too:
result = inputB
And in this two cases the resultant vector is the same as the input one.
So i believe the problem is in the vector sum...
result = inputA + inputB
I don't know...
Could anyone tell me where's the error?
Thanks
