def set_active_layer(layer):
    all = [obj.name() for obj in pm.ls(type='animLayer')]
    for item in all:
        if item == layer:
            pm.animLayer(item, e=1, selected=1, lock=0)
        else:
            pm.animLayer(item, e=1, selected=0, lock=1)
Esempio n. 2
0
 def buttonPressed(self):
     self.selected = self.getControl()
     ctrlName = str(self.selected)
     pm.animLayer(ctrlName + '_1', selected = True, addSelectedObjects = True)
     #gets a list off all layer affecting the current control 
     self.affectingLayers = pm.animLayer(query = True, afl = True)
     #deselects all the affecting layers 
     for layer in self.affectingLayers:
         pm.animLayer(layer, edit = True, selected = False)
     self.affectingLayers[0].setSelected(True)
     
     self.textBox.setText(ctrlName)
Esempio n. 3
0
    def __enter__(self):
        self.bufferLayers = self._getActiveLayers()

        for each in self._getAnimLayers():
            if each.name() not in self.layers:
                pmc.mel.eval('animLayerMuteCallBack "{0}" "1";'.format(
                    each.name()))
                pmc.animLayer(each, edit=True, mute=True, lock=True)
            else:
                pmc.mel.eval('animLayerMuteCallBack "{0}" "1";'.format(
                    each.name()))
                pmc.animLayer(each, edit=True, mute=False, lock=False)

        pmc.mel.eval('updateEditorFeedbackAnimLayers("AnimLayerTab")')
Esempio n. 4
0
def set_mute_on_parent_anim_layer(obj, a_mute):
    '''
    Set lock and mute of the parent animation layer for the given object

    Args:
        obj (PyNode): Object to query anim layers from
        a_mute (bool): Value to set mute and lock to
    '''
    pm.select(obj)
    parentLayers = pm.animLayer(query=True, afl=True)
    root_layer = pm.animLayer(query=True, root=True)
    if (parentLayers != None and len(parentLayers) > 0):
        for layer in parentLayers:
            if (layer == root_layer):
                continue
            pm.animLayer(layer, edit=True, mute=a_mute, lock=a_mute)

    pm.select(clear=True)
Esempio n. 5
0
 def update_items(self):
     self.clear()
     base_layer = pm.animLayer(root=True,
                               q=1)  # type: luna_rig.nt.AnimLayer
     if not base_layer:
         return
     self.addItem(str(base_layer), base_layer)
     for child_layer in base_layer.getChildren():
         self.addItem(str(child_layer), child_layer)
Esempio n. 6
0
    def _getAnimLayers(self, predicate=None):
        baseAnimLayer = self._getBaseAnimLayer()
        animLayers = []
        if baseAnimLayer:
            animLayers.append(baseAnimLayer)
            childrenLayers = pmc.animLayer(baseAnimLayer,
                                           query=True,
                                           children=True)
            animLayers.extend(childrenLayers)

        return animLayers
Esempio n. 7
0
    def __exit__(self, *_):
        if self.bufferLayers:
            for each in self._getAnimLayers():
                if each in self.bufferLayers:
                    pmc.mel.eval('animLayerMuteCallBack "{0}" "1";'.format(
                        each.name()))
                    pmc.animLayer(each.name(), edit=True, lock=True)
                    pmc.animLayer(each.name(), edit=True, mute=True)
                else:
                    pmc.mel.eval('animLayerMuteCallBack "{0}" "1";'.format(
                        each.name()))
                    pmc.animLayer(each.name(), edit=True, lock=False)
                    pmc.animLayer(each.name(), edit=True, mute=False)
            pmc.mel.eval('updateEditorFeedbackAnimLayers("AnimLayerTab")')

            print(_)
Esempio n. 8
0
def CreateLayers(animLayerName, hirarchy, nrOfFrames, rotations, orent, orentInvert, perentMatrixList, perentMatrixListInvers, jointMatrixesList, animLayerList):
    animLayer1 = pm.animLayer(animLayerName)
    animLayerList.append(animLayer1)
    
    for index, h in enumerate(hirarchy):
        
        pm.select(h, replace=True)
        
        pm.animLayer(animLayerName, edit=True, addSelectedObjects=True)
        
        # Loop through Keys: 
        for i in range(0, (nrOfFrames + 1)):
            
            # Get Final source rotation at this keyframe:
            pm.currentTime(i)
    
            kBiss = orent[index] * perentMatrixList[index] * jointMatrixesList[index][i] * perentMatrixListInvers[index] * orentInvert[index]
                    
            # Final rotation:
            finalRotation = rotations[index] * kBiss
            
            #=====================================================================
            # Get the right format for rotations:
            keyRotQ = dt.EulerRotation(finalRotation)
            keyRotDegree = dt.degrees(keyRotQ)
            
            #=====================================================================
            # Set rotations at current time:
            h.setRotation(keyRotDegree)
            
            # Save to keyframe:
            pm.setKeyframe(h, time = (i,i), edit = True, animLayer = animLayerName)
    
    #Set weights to 0.0 so they dont influence other layers when baked:        
    pm.animLayer(animLayerName, edit = True, w=0.0)
    sys.stdout.write('Info: Animation layers successfully created.\n')
Esempio n. 9
0
def import_w3_mimicPoses(poses, mimicSkeleton, actor, mimic_namespace):
    # ns = "ciri"
    # if not pm.namespace( exists=ns ):
    #     pm.namespace( add=ns )
    # ns = ns+":"
    # root_ctrl = None
    # try:
    #     root_ctrl = pm.PyNode('torso3')
    # except:
    #     root_ctrl = pm.PyNode(ns + 'torso3')

    ##create the layers
    for pose in poses:
        # if pose.name == 'lips_blow':
        #   break
        if not pm.animLayer(actor + "_" + pose.name, ex=True, q=True):
            pm.animation.animLayer(actor + "_" + pose.name, weight=0.0)

    for pose in poses:
        # if pose.name == 'lips_blow':
        #   break
        animBuffer = pose.animBuffer
        select_list = []  #select only the bones moved by the pose.

        for bone in animBuffer.bones:
            all_zeros = bone.positionFrames[0].count(0.0)
            all_zerosQ = bone.rotationFrames[0].count(0.0)
            if bone.positionFrames[0].count(
                    0.0) is 3 and bone.rotationFrames[0].count(0.0) is 3:
                pass
            else:
                select_list.append(mimic_namespace + ":" + bone.BoneName)
        pm.select(select_list)
        pm.animation.animLayer(actor + "_" + pose.name,
                               edit=True,
                               addSelectedObjects=True)
        anims.import_w3_animation2(pose, mimic_namespace, "face",
                                   actor + "_" + pose.name)
Esempio n. 10
0
def fix_solo_keyframe_layers():
    '''
    Find all animation layers with a single keyframe and place a second keyframe 1 frame after the first for all objects in the layer.
    '''
    for anim_layer in pm.ls(type='animLayer'):
        anim_curve_list = pm.animLayer(anim_layer, query=True, animCurves=True)
        # Ignore anim layers with no animation
        single_keyframe = True if anim_curve_list else False
        keyed_frame = None
        for anim_curve in anim_curve_list:
            if anim_curve.numKeyframes() > 1:
                single_keyframe = False
                break
            else:
                keyed_frame = anim_curve.getTime(0)
        if single_keyframe:
            layer_obj_list = list(
                set(anim_layer.dagSetMembers.listConnections()))
            if layer_obj_list:
                pm.copyKey(layer_obj_list, animLayer=anim_layer, t=keyed_frame)
                pm.pasteKey(layer_obj_list,
                            animLayer=anim_layer,
                            t=keyed_frame + 1)
Esempio n. 11
0
def addAnimation(animData, scene_actor, start, end, firstFrame, type, al):
    global_weight = 1.0  #0.66

    #
    face_animation = False
    if (animData.tracks):
        face_animation = True

    #CODE TO CREATE AND NEW LAYER FOR THIS ANIMATION
    # pm.animation.animLayer(scene_actor+"_addLayer", weight=1.0)
    # al = scene_actor+"_addLayer"

    for fi in range(int(start), int(end)):
        time_index = firstFrame + fi
        #if not animData.tracks:

        for bone in animData.bones:
            ## NEED TO CHECK DT AND SKIP PROPER FRAMES
            boneName = bone.BoneName + ""
            if scene_actor:
                boneName = scene_actor + ":" + bone.BoneName

            #CODE TO CREATE AND NEW LAYER FOR THIS ANIMATION
            # pm.select(boneName)
            # pm.animation.animLayer(scene_actor+"_addLayer", edit=True, addSelectedObjects=True)

            if cmds.objExists(boneName):
                cmds.select(boneName)
                sel_list = om.MSelectionList()
                sel_list.add(boneName)
                obj = sel_list.getDependNode(0)
                xform = om.MFnTransform(obj)
                orig_rotation = xform.rotation(om.MSpace.kObject,
                                               asQuaternion=True)
                try:
                    bone_frames = len(bone.positionFrames)
                    if bone_frames is 1 and bone.positionFrames[0].count(
                            0.0
                    ) == 3:  #for face animations that pass in 0s that are not used, might cause issues?
                        pass
                    else:
                        total_frames = animData.numFrames
                        frame_skip = round(
                            float(total_frames) / float(bone_frames))
                        frame_array = [
                            frame_skip * n for n in range(0, bone_frames)
                        ]
                        if float(fi) in frame_array:
                            cmds.xform(t=(
                                bone.positionFrames[frame_array.index(fi)][0],
                                bone.positionFrames[frame_array.index(fi)][1],
                                bone.positionFrames[frame_array.index(fi)][2]))
                            if al:
                                pm.setKeyframe(boneName,
                                               t=time_index,
                                               at='translate',
                                               al=al)
                            else:
                                pm.setKeyframe(boneName,
                                               t=time_index,
                                               at='translate')
                            #cmds.setKeyframe( at='translate', itt='spline', ott='spline', al=al )
                except IndexError:
                    print(IndexError.message)
                try:
                    bone_frames = len(bone.rotationFrames)
                    total_frames = animData.numFrames
                    frame_skip = round(
                        float(total_frames) / float(bone_frames))
                    frame_array = [
                        frame_skip * n for n in range(0, bone_frames)
                    ]
                    frame_quat_prev = False
                    if float(fi) in frame_array:
                        frame_quat = bone.rotationFramesQuat[frame_array.index(
                            fi)]
                        #MIMIC POSES DON'T GET INVERTED
                        if type is "face":
                            # cmds.xform( ro=(-bone.rotationFrames[frame_array.index(fi)][0],
                            #                 -bone.rotationFrames[frame_array.index(fi)][1],
                            #                 -bone.rotationFrames[frame_array.index(fi)][2]))
                            xform.setRotation(frame_quat.invertIt(),
                                              om.MSpace.kObject)
                        else:
                            ## temp solution to blend face animations on top of current animations
                            ## maybe create a new animLayer if this is the case
                            ## could get messy without a bind pose
                            ## an animLayer based off the bind pose could work so there is something to export.
                            ## exports of face animation will be borken in-game if exported as-is.
                            if face_animation:
                                xform.rotateBy(frame_quat, om.MSpace.kObject)
                            else:
                                xform.setRotation(frame_quat,
                                                  om.MSpace.kObject)
                        # if type is "face":
                        #     cmds.xform( ro=(bone.rotationFrames[frame_array.index(fi)][0],
                        #                     bone.rotationFrames[frame_array.index(fi)][1],
                        #                     bone.rotationFrames[frame_array.index(fi)][2]))
                        # else:
                        #     cmds.xform( ro=(-bone.rotationFrames[frame_array.index(fi)][0],
                        #                     -bone.rotationFrames[frame_array.index(fi)][1],
                        #                     -bone.rotationFrames[frame_array.index(fi)][2]))
                        #cmds.setKeyframe( at='rotate', itt='auto', ott='auto', al=al )
                        if al:
                            pm.setKeyframe(boneName,
                                           t=time_index,
                                           at='rotate',
                                           al=al,
                                           minimizeRotation=True,
                                           itt='linear',
                                           ott='linear')
                        else:
                            pm.setKeyframe(boneName,
                                           t=time_index,
                                           at='rotate',
                                           minimizeRotation=True,
                                           itt='linear',
                                           ott='linear')
                        ## temp solution to blend face animations
                        ## restore the orignal frame after every rotateBy keyframe
                        if face_animation:
                            xform.setRotation(orig_rotation, om.MSpace.kObject)
                except IndexError:
                    print(IndexError.message)

        if animData.tracks:
            for track in animData.tracks:
                trackname = scene_actor + "_" + track.trackName
                if pm.animLayer(trackname, query=True, ex=True):
                    try:
                        track_frames = len(track.trackFrames)
                        total_frames = animData.numFrames
                        frame_skip = round(
                            float(total_frames) / float(track_frames))
                        frame_array = [
                            frame_skip * n for n in range(0, track_frames)
                        ]
                        if float(fi) in frame_array:
                            weight = round(
                                track.trackFrames[frame_array.index(fi)], 5)
                            pm.select(trackname)
                            pm.animLayer(trackname,
                                         edit=True,
                                         weight=weight * global_weight)
                            pm.setKeyframe(trackname,
                                           attribute='weight',
                                           t=time_index)

                            #cmds.setKeyframe( at='translate', itt='spline', ott='spline', al=al )
                    except IndexError:
                        pass
def Slider4Moved():
    newValue = bakeAnimUI.WeightSlider4.value()
    newValue = float(newValue) / 100.0
    pm.animLayer(pathsList4[1], edit=True, w=newValue)
Esempio n. 13
0
 def _isMuted(self, layer):
     return pmc.animLayer(layer, query=True, mute=True)
Esempio n. 14
0
 def _getBaseAnimLayer(self):
     return pmc.animLayer(query=True, root=True)
Esempio n. 15
0
def import_w3_animation_OLD(w3Data, SkeletalAnimation, type, al=False):
    bone_frames = {}
    for rig_bone in w3Data.bones:
        bone_frames[rig_bone.name] = {
            "positionFrames": [],
            "rotationFrames": [],
            "scaleFrames": []
        }
    animData = SkeletalAnimation.animBuffer
    multipart = False
    if animData.parts:
        multipart = True

    # start time of playback
    #cmds.playbackOptions(q= 1, min= 1)
    # end time of playback
    #cmds.playbackOptions(q= 1, max= animData.numFrames, aet=animData.numFrames)
    cmds.playbackOptions(min='1',
                         max=str(animData.numFrames),
                         ast='1',
                         aet=str(animData.numFrames))
    # start time of playback
    start = 1  #cmds.playbackOptions(q= 1, min= 1)
    # end time of playback
    end = animData.numFrames + 1  #cmds.playbackOptions(q= 1, max= 1)
    for fi in range(int(start), int(end)):
        time_index = fi
        fi = fi - 1
        # move frame
        #cmds.currentTime(i, e= 1)
        # for bone in animData.bones:

        #     ## NEED TO CHECK DT AND SKIP PROPER FRAMES
        #     if cmds.objExists(bone.BoneName):
        #         cmds.select(bone.BoneName);
        #         sel_list = om.MSelectionList()
        #         sel_list.add(bone.BoneName)
        #         obj = sel_list.getDependNode(0)
        #         xform = om.MFnTransform(obj)
        #         try:
        #             bone_frames = len(bone.positionFrames)
        #             total_frames = animData.numFrames
        #             frame_skip = round(float(total_frames)/float(bone_frames))
        #             frame_array = [frame_skip*n for n in range(0,bone_frames)]
        #             if float(fi) in frame_array:
        #                 cmds.xform( t=(bone.positionFrames[frame_array.index(fi)][0],
        #                                 bone.positionFrames[frame_array.index(fi)][1],
        #                                 bone.positionFrames[frame_array.index(fi)][2]))
        #                 if al:
        #                     pm.setKeyframe(bone.BoneName, t=time_index, at='translate', al=al)
        #                 else:
        #                     pm.setKeyframe(bone.BoneName, t=time_index, at='translate')
        #                 #cmds.setKeyframe( at='translate', itt='spline', ott='spline', al=al )
        #         except IndexError:
        #             pass
        #             # handle this
        #         try:
        #             bone_frames = len(bone.rotationFrames)
        #             total_frames = animData.numFrames
        #             frame_skip = round(float(total_frames)/float(bone_frames))
        #             frame_array = [frame_skip*n for n in range(0,bone_frames)]
        #             if float(fi) in frame_array:
        #                 #MIMIC POSES DON'T GET INVERTED
        #                 if type is "face":
        #                     cmds.xform( ro=(-bone.rotationFrames[frame_array.index(fi)][0],
        #                                     -bone.rotationFrames[frame_array.index(fi)][1],
        #                                     -bone.rotationFrames[frame_array.index(fi)][2]))
        #                 else:
        #                     xform.setRotation(bone.rotationFramesQuat[frame_array.index(fi)], om.MSpace.kObject)
        #                 # if type is "face":
        #                 #     cmds.xform( ro=(bone.rotationFrames[frame_array.index(fi)][0],
        #                 #                     bone.rotationFrames[frame_array.index(fi)][1],
        #                 #                     bone.rotationFrames[frame_array.index(fi)][2]))
        #                 # else:
        #                 #     cmds.xform( ro=(-bone.rotationFrames[frame_array.index(fi)][0],
        #                 #                     -bone.rotationFrames[frame_array.index(fi)][1],
        #                 #                     -bone.rotationFrames[frame_array.index(fi)][2]))
        #                 #cmds.setKeyframe( at='rotate', itt='auto', ott='auto', al=al )
        #                 if al:
        #                     pm.setKeyframe(bone.BoneName, t=time_index, at='rotate', al=al)
        #                 else:
        #                     pm.setKeyframe(bone.BoneName, t=time_index, at='rotate')
        #         except IndexError:
        #             pass
        for track in animData.tracks:
            ns = "ciri_"
            trackname = ns + track.trackName
            if pm.animLayer(trackname, query=True, ex=True):
                try:
                    track_frames = len(track.trackFrames)
                    total_frames = animData.numFrames
                    frame_skip = round(
                        float(total_frames) / float(track_frames))
                    frame_array = [
                        frame_skip * n for n in range(0, track_frames)
                    ]
                    if float(fi) in frame_array:
                        weight = round(
                            track.trackFrames[frame_array.index(fi)], 5)
                        pm.select(trackname)
                        pm.animLayer(trackname, edit=True, weight=weight)
                        pm.setKeyframe(trackname,
                                       attribute='weight',
                                       t=time_index)

                        #cmds.setKeyframe( at='translate', itt='spline', ott='spline', al=al )
                except IndexError:
                    pass
                    # handle this
    return SkeletalAnimation