Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
themeEclipse
linenumberstrue
from PySide import QtGui, QtCore

from maya import cmds

import imath
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 of 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("l_armJA_JNTLeftArm")
            mid_id = skeleton.jointId("l_armJB_JNTLeftForeArm")
            ik_id = skeleton.jointId("l_handJA_JNTLeftHand")

            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 = imath.V3d(wm[3][0], wm[3][1], wm[3][2])
            #adding a small offset to have less mesh intersection
            target_pos.y += 5

            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),
                     "atomsMale", 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) * 50, 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")

...