比較バージョン

キー

  • この行は追加されました。
  • この行は削除されました。
  • 書式設定が変更されました。

...

コード ブロック
languagepy
themeEclipse
linenumberstrue
from PySide import QtGui, QtCore

from maya import cmds

import imathAtomsMath
import AtomsCore
import Atoms
import AtomsUtils

from Atoms.ui.atomsAeGui import ModuleWidget, ModuleOptionsWidget
from
AtomsMaya.ui.atomsAeGuiMaya
import GlobalData


class MarchingQueueModule(Atoms.BehaviourModule):
    """
    This module assumes all agent are ofatomsRobots
the same type     """

    def __init__(self):
        Atoms.BehaviourModule.__init__(self)

    def endFrame(self, agents, agroup):

        for i in range(1, len(agents)):
            skeleton = agents[i].agentType().skeleton()
            root_id = skeleton.jointId("LeftArm")
            mid_id = skeleton.jointId("LeftForeArm")
            ik_id = skeleton.jointId("LeftHand")

            if -1 in [root_id, mid_id, ik_id]:
                AtomsUtils.Logger.warning("couldn't find one or more joint ids")
                continue

            poser = AtomsCore.Poser(skeleton)
            other_pose = agents[i - 1].pose()
            wm = poser.getWorldMatrix(other_pose, root_id)
            target_pos = imathAtomsMath.V3d(wm[3][0], wm[3][1], wm[3][2])
            #adding a small offset to have less mesh intersection
            target_pos.y += 510

            pose = agents[i].pose()
            AtomsCore.solveTwoJointsIKNoPoleVector(pose, skeleton, target_pos,
                                                   root_id, mid_id, ik_id, 0,
                                                   True, 0.3)


'''
MAYA SETUP 
'''
def register():
    Atoms.BehaviourModules.instance().registerBehaviourModule("marchingQueue",
                                                    MarchingQueueModule, True)


def setup():
    cmds.tcAtoms(init=True)
    agn = cmds.createNode('tcAgentGroupNode')
    cmds.setAttr(agn + ".displayType", 1)

    register()

    cmds.setAttr(agn + ".modules[0].moduleType", "pointsLayout", type="string")
    cmds.setAttr(agn + ".modules[0].moduleName", "pointsLayout", type="string")

    count = 6
    for i in range(count):
        cmds.setAttr("%s.atoms_pointsLayout_agentTypes[%d]" % (agn, i),
                     "atomsMaleatomsRobot", type="string")
        cmds.setAttr("%s.atoms_pointsLayout_directions[%d]" % (agn, i),
                     1, 0, 0)
        cmds.setAttr("%s.atoms_pointsLayout_points[%d]" % (agn, i),
                     (count - i) * 5060, 0, 0)

    cmds.setAttr(agn + ".modules[1].moduleType", "stateMachine", type="string")
    cmds.setAttr(agn + ".modules[1].moduleName", "stateMachine", type="string")
    cmds.setAttr(agn + ".atoms_stateMachine_state", 1)

    cmds.setAttr(agn + ".modules[2].moduleType", "marchingQueue", type="string")
    cmds.setAttr(agn + ".modules[2].moduleName", "marchingQueue", type="string")

...