Untitled

mail@pastecode.io avatar
unknown
python
a year ago
3.2 kB
3
Indexable
Never
"""

Weapon Animation Trasfer Tool
Created by William Wheeler, 1047 Games.

Transfers Animation from Joints to controls to aid in the transfer of animation from Unreal Engine 5 or blender into Maya.

TODO:
    Dumb rig:
        Rig Specfic to the weapon as it sits now.
        Detect joints and attach to similarly named controls.

    Smart Rig:
        Auto detect joints, attmept to find appropriate controls through 1)Naming 2)Global Position 3)Local Position

    UX:
        need a User experiance that can allow for utilization of Dumb rig, Smart rig or to create a manual setup.

    AutoTransfer for all files in a Windows folder.

"""

#class animationTransferUX:

import maya.cmds as cmds
import json

class weaponRigDictionaryExport:

    def __init__(self):

        __jointList__ = self.jointDetect
        __controlDetect__ = self.controlDetect
        __ctrlJntDict__ = self.controlJointDictionary(__controlDetect__,__jointList__,dict = {})
        print(__ctrlJntDict__)
        self.exportDict(__ctrlJntDict__)





    def jointDetect(self):
        """
        Detect all joints in scene and create a list of them.
        """
        jointList = cmds.ls(typ = "joint")

        return jointList



    def controlDetect(self):
        """
        Detect all Controls in scene and create a list of them.
        """
        controlList = cmds.ls('*_Ctrl')
        return controlList


    def controlJointDictionary(self,ctrl,jnt,dict):
        """
        create a dictionary of controls to joints. for future tasks
        @param ctrl: The paired control
        @param jnt: The paired joint
        @param dict: if a dictionary already exists, load it.
        """

        #check for badnaming with numbers randomly. Im looking at you trigger1
        dirtyName = []
        uncontrolled = []
        for eachJnt in jnt:

            try:
                 foundCtrl = ctrl[(eachJnt + '_Ctrl')]
                 dict[foundCtrl] = jnt

            except:

                suffix = eachJnt(-1)
                if suffix.isnumeric():
                    if (cmds.ls((eachJnt.pop(-1)))) <1:
                        uncontrolled.append(eachJnt)

                else:
                    cleanJnt = eachJnt[:-1] + ''
                    foundCtrl = ctrl[(cleanJnt + '_Ctrl')]
                    dict[foundCtrl] = jnt


        return dict


    def exportDict(self, data):
        """
        here we export our dictionary so this can be loadedinto and used in an animation scene
        so we dont have to worry about extra joints like the fps or tps character
        @param weapon:
        @param data: this is the dictionary
        """
        weapon = "NOPE"
        file_path = "Q:/1047/rigDicts/" + weapon +".json"
        with open(file_path, "w") as json_file:
            json.dump(data, json_file)




weaponRigDictionaryExport()





class animationExport:




    def transferAnimation(self):
        """
        Transfer animation from the listed joint to the apropriate control
        """
        pass



    def alterBaseOrientation(self):
        """
        Apply an offset due to the diffeerent orientation of the old and new setup
        """
        pass