Maya python api乘法节点

2024-06-06 05:43:15 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我创建了一个基本的乘法节点,它可以有多个输入

我想将两个属性相乘,并在第三个属性中得到输出。它工作得很好,但不是活的

基本上我创建了3个属性2个输入1个输出,创建了复合属性,并在其中添加了所有3个属性

只有在节点编辑器中取消选择并重新选择节点时,才能看到输出得到更新。但它并没有起到积极的作用

谢谢




    input1VecAttr = om.MObject()
    input2VecAttr = om.MObject()
    outputVecAttr = om.MObject()
    uniqueArrayComp = om.MObject()


    def __init__(self):
        OpenMayaMPx.MPxNode.__init__(self)
    

    def compute(self, plug, dataBlock):
        
        
        if plug == arrayTest2.uniqueArrayComp:


            #input value
            #arrayDataHandle = om.MArrayDataHandle(dataBlock.inputArrayValue(arrayTest2.uniqueArrayComp))
            arrayDataHandle = dataBlock.inputArrayValue(arrayTest2.uniqueArrayComp)
            elementCount = arrayDataHandle.elementCount()



            #output array

            for i in range(elementCount):


    

                bindData = arrayDataHandle.inputValue()

                myElementHandleChildInput1 = bindData.child(arrayTest2.input1VecAttr)
                inVal1 = myElementHandleChildInput1.asFloat()
                myElementHandleChildInput2 = bindData.child(arrayTest2.input2VecAttr)
                inVal2 = myElementHandleChildInput2.asFloat()

                output = inVal1 * inVal2


                myElementHandleChildOutput = bindData.child(arrayTest2.outputVecAttr)
                myElementHandleChildOutput.setFloat(output)
                
                print i
                try:
                    arrayDataHandle.next()
                except:
                    pass


  
            dataBlock.setClean(plug)
 


Tags: selfchildoutput属性节点plugomdatablock