9

これはかなり複雑な質問かもしれません。なぜなら、私が書いているソフトウェア、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')
4

4 に答える 4

32

質問がよくわかりません。お探しですか?

import itertools
for a, b, c in itertools.izip(lst1, lst2, lst3):
    ...

可変数の引数をizip取り、引数のそれぞれの項目(最初の実行で最初の引数のタプル、2番目の実行で2番目の引数のタプルなど)を常に生成するイテレーターを返します。など)。

于 2011-06-27T19:54:13.870 に答える
1

「同じオブジェクト TYPE の 3 つの異なるリストがある」のはなぜですか? 3 つのオブジェクトすべてが正しく一致する 1 つのリストを作成するように修正できないのはなぜですか?

単純なマッピングが 3 つの並列リストよりも優れている可能性は十分にあります。

具体的には、このように動作するように修正する必要があります chHipIK = cmds.listRelatives(IKJoint, ad = True, type = 'joint')

chHipIK = [ { 'IK': ik } for ik in mds.listRelatives(IKJoint, ad = True, type = 'joint') ]
for i, fk in enumerate(cmds.listRelatives(FKJoint, ad = True, type = 'joint')):
    chHipIK[i]['FK']= fk
for i, bind in enumerate(cmds.listRelatives(bindJoint, ad = True, type = 'joint')):
    chHipIK[i]['FK']= bind

これchHipIKは、3 つの情報すべてを含むマッピングのリストです。

于 2011-06-27T19:30:30.430 に答える
1

Python3 の回答:

for a, b, c in zip(lst1, lst2, lst3):
    ...
于 2021-01-28T20:29:22.263 に答える
1

zip または izip を使用した @florian mayer の方法は非常にうまく機能しますが、enumerate を使用してリストの数を取得することもできます。

list_a  = ["x", "y"]
list_b  = ["k", "j"]
list_c  = ["m", "n"]

for count, item in enumerate(list_a):
    print item, list_b[count], list_c[count]
于 2016-09-13T09:36:51.960 に答える