Maya Python API自定义父约束节点计算异常求助
问题根源:矩阵乘法顺序错误
你的compute方法核心问题是矩阵乘法顺序完全颠倒,这是由Maya的列主序矩阵规则导致的。
为什么顺序会出错?
Maya的multMatrix节点对输入矩阵的计算逻辑是从最后一个输入到第一个输入依次相乘:假设你在节点编辑器里把offset接在multMatrix.input[0]、source接在input[1]、parentInverseMtx接在input[2],那么multMatrix的实际计算式是:
parentInverseMtx * source * offset
而你的代码里写的是:
output = offset * source * parentInverseMtx
完全颠倒的计算顺序直接导致了输出矩阵的位移、缩放异常。
修正后的compute代码
调整矩阵乘法顺序,对齐multMatrix的计算逻辑即可解决问题:
def compute(self, plug, data): if plug == AmysMathsNode.output_obj: source = data.inputValue(AmysMathsNode.source_obj).asMatrix() parentInverseMtx = data.inputValue(AmysMathsNode.parentInverseMtx_obj).asMatrix() offset = data.inputValue(AmysMathsNode.offset_obj).asMatrix() # 修正矩阵乘法顺序,与multMatrix计算逻辑一致 output = parentInverseMtx * source * offset output_data_handle = data.outputValue(AmysMathsNode.output_obj) output_data_handle.setMMatrix(output) data.setClean(plug)
额外验证提示
如果你的原节点网络中multMatrix的输入顺序不同(比如从左到右是parentInverseMtx、source、offset),需要对应调整代码里的乘法顺序,但核心原则不变:代码中的矩阵乘法顺序必须和mult节点从后到前的输入顺序完全一致。
内容的提问来源于stack exchange,提问作者anotherAmy
相关产品推荐
相关产品推荐

