これはかなり複雑な質問かもしれません。なぜなら、私が書いているソフトウェア、Autodesk Maya 2011 を知らない人が多いからです。退屈で遅いプロセスを高速化しようとしています (リギング: 3D キャラクターに能力を与える移動する) を自動的に実行するスクリプトを記述します。
状況を説明するために最善を尽くします。
オブジェクトを取得し、そのオブジェクトの子を反復処理し、それらをリストに格納し、最初のオブジェクトをリストの最後に配置し、リストを逆にするスクリプトを持っています。これは間違った方法であるためです。前面に。
問題: 3 つの異なるリストがあり、すべて同じオブジェクト TYPE ですが、名前が異なり、実際には異なるオブジェクトです。私の目標は、「blendcolors」と呼ばれるノードを生成して、それらを接続することです。しかし、リストAの各オブジェクトに対してそれらを生成するループがある場合、それらを他のリストのオブジェクトにも接続するループが必要であり、これを理解できません。
これが私のコードです。これは再生されているため、実際のループに関する限り、以前よりも不完全です。
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()
# appends 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')