回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>这可能是一个相当复杂的问题,因为可能很多人不知道我为其编写的软件:Autodesk Maya 2011。我试图通过编写一个自动执行的脚本来加速一个冗长而缓慢的过程(装配:赋予3d角色移动的能力)。</p>
<p>我会尽力解释情况的。</p>
<p>我有一个脚本,它接受一个对象,遍历该对象的子对象,将它们存储在一个列表中,然后将初始对象放在列表的末尾,由于列表的方式不对而反转列表,然后将初始对象放在前面。</p>
<p>问题:有三个不同的列表,都是相同的对象类型,但名称不同,它们实际上是不同的对象。我的目标是通过生成名为“blendcolors”的节点将它们连接在一起。但是如果我有一个循环来为列表a中的每个对象生成它们,那么我需要一个循环来将它们连接到其他列表中的对象,而我无法理解这一点。</p>
<p>这是我的代码,它已经播放,所以比以前更不完整的实际循环去。</p>
<pre><code> import maya.cmds as cmds
def crBC(IKJoint, FKJoint, bindJoint, xQuan, switch):
# gets children joints of the selected joint
chHipIK = cmds.listRelatives(IKJoint, ad = True, type = 'joint')
chHipFK = cmds.listRelatives(FKJoint, ad = True, type = 'joint')
chHipBind = cmds.listRelatives(bindJoint, ad = True, type = 'joint')
# list is built backwards, this reverses the list
chHipIK.reverse()
chHipFK.reverse()
chHipBind.reverse()
# <a href="https://www.cnpython.com/list/append" class="inner-link">append</a>s the initial joint to the list
chHipIK.append(IKJoint)
chHipFK.append(FKJoint)
chHipBind.append(bindJoint)
# puts the last joint at the start of the list because the initial joint
# was added to the end
chHipIK.insert(0, chHipIK.pop())
chHipFK.insert(0, chHipFK.pop())
chHipBind.insert(0, chHipBind.pop())
# pops off the remaining joints in the list the user does not wish to be blended
chHipBind[xQuan:] = []
chHipIK[xQuan:] = []
chHipFK[xQuan:] = []
# goes through the bind joints, makes a blend colors for each one, connects
# the switch to the blender
for a in chHipBind
rotBC = cmds.shadingNode('blendColors', asUtility = True, n = a + 'rotate_BC')
tranBC = cmds.shadingNode('blendColors', asUtility = True, n = a + 'tran_BC')
scaleBC = cmds.shadingNode('blendColors', asUtility = True, n = a + 'scale_BC')
cmds.connectAttr(switch + '.ikFkSwitch', rotBC + '.blender')
cmds.connectAttr(switch + '.ikFkSwitch', tranBC + '.blender')
cmds.connectAttr(switch + '.ikFkSwitch', scaleBC + '.blender')
# goes through the ik joints, connects to the blend colors
for b in chHipIK:
cmds.connectAttr(b + '.rotate', rotBC + '.color1')
cmds.connectAttr(b + '.translate', tranBC + '.color1')
cmds.connectAttr(b + '.scale', scaleBC + '.color1')
# connects FK joints to the blend colors
for c in chHipFK:
cmds.connectAttr(c + '.rotate', rotBC + '.color2')
cmds.connectAttr(c + '.translate', tranBC + '.color2')
cmds.connectAttr(c + '.scale', scaleBC + '.color2')
# connects blend colors to bind joints
cmds.connectAttr(rotBC + '.output', d + '.rotate')
cmds.connectAttr(tranBC + '.output', d + '.translate')
cmds.connectAttr(scaleBC + '.output', d + '.scale')
# executes function
crBC('L_hip_IK', 'L_hip_FK', 'L_hip_JNT', 6, 'L_legSwitch_CTRL')
</code></pre>