示例#1
0
    def __init__(self, 
                 name='mlBreakdownDraggerContext',
                 minValue=None,
                 maxValue=None,
                 defaultValue=0,
                 title = 'Breakdown'):
        
        self.keySel = utl.KeySelection()
        if self.keySel.selectedKeys():
            pass
        elif self.keySel.visibleInGraphEditor():
            self.keySel.setKeyframe()
        elif self.keySel.keyedChannels():
            self.keySel.setKeyframe()
        
        if not self.keySel.curves:
            return
        
        utl.Dragger.__init__(self, defaultValue=defaultValue, minValue=minValue, maxValue=maxValue, name=name, title=title)

        
        #setup tangent type
        itt,ott = utl.getHoldTangentType()
        
        self.time = dict()
        self.value = dict()
        self.next = dict()
        self.prev = dict()
        self.average = dict()

        for curve in self.keySel.curves:
            if self.keySel.selected:
                self.time[curve] = mc.keyframe(curve, query=True, timeChange=True, sl=True)
                self.value[curve] = mc.keyframe(curve, query=True, valueChange=True, sl=True)
            else:
                self.time[curve] = self.keySel.time
                self.value[curve] = mc.keyframe(curve, time=self.keySel.time, query=True, valueChange=True)
                
            self.next[curve] = list()
            self.prev[curve] = list()
            self.average[curve] = list()
            
            for i in self.time[curve]:
                next = mc.findKeyframe(curve, time=(i,), which='next')
                prev = mc.findKeyframe(curve, time=(i,), which='previous')
                n = mc.keyframe(curve, time=(next,), query=True, valueChange=True)[0]
                p = mc.keyframe(curve, time=(prev,), query=True, valueChange=True)[0]
                
                self.next[curve].append(n)
                self.prev[curve].append(p)
                self.average[curve].append((n+p)/2)
                
                #set the tangents on this key, and the next and previous, so they flatten properly
                mc.keyTangent(curve, time=(i,), itt=itt, ott=ott)
                mc.keyTangent(curve, time=(next,), itt=itt)
                mc.keyTangent(curve, time=(prev,), ott=ott)
        
        self.setTool()
        self.drawString('Left: Weight Prev/Next, Middle: Weight Average')
        OpenMaya.MGlobal.displayWarning('Left: Weight Prev/Next, Middle: Weight Average')
示例#2
0
def frameGraphEditor(centerCurrentTime=False):
    '''
    If graph editor has focus, frame the selected or visible animation curves.
    '''

    panel = mc.getPanel(up=True)
    if not panel:
        panel = mc.getPanel(withFocus=True)
    if not panel:
        return False
    panelType = mc.getPanel(to=panel)
    if panelType != 'scriptedPanel':
        return False
    scriptedType = mc.scriptedPanel(panel, query=True, type=True)
    if scriptedType != 'graphEditor':
        return False

    graphEditor = panel + 'GraphEd'

    keySel = utl.KeySelection()
    if keySel.selectedKeys():
        pass
    elif keySel.visibleInGraphEditor():
        pass

    if keySel.selected:
        times = keySel.getSortedKeyTimes()
        start = times[0]
        end = times[-1]
    else:
        keySel.frameRange()
        start = keySel._timeRangeStart
        end = keySel._timeRangeEnd

    values = sorted(keySel.keyframe(query=True, valueChange=True))
    minValue = values[0]
    maxValue = values[-1]

    if start == end:
        start = start - 1
        end = end + 1

    if maxValue == minValue:
        minValue = minValue - 0.5
        maxValue = maxValue + 0.5

    #add a 10% padding
    timePadding = (end - start) / 10.0
    valuePadding = (maxValue - minValue) / 10.0

    mc.animView(graphEditor,
                startTime=start - timePadding,
                endTime=end + timePadding,
                minValue=minValue - valuePadding,
                maxValue=maxValue + valuePadding)

    if centerCurrentTime:
        mc.animCurveEditor(graphEditor, edit=True, lookAt='currentTime')

    return True
示例#3
0
def deleteKey(deleteSubFrames=False,
              selectedKeys=False,
              selectedChannels=False,
              visibleInGraphEditor=False,
              currentFrame=False):
    '''
    The main function arguments:

        selectedKeys:           Delete the keys selected in the graph editor
        selectedChannels:       Delete all the keys on selected channels
        visibleInGraphEditor:   Only delete keys that are visible in the graph editor
        currentFrame:           Delete the keys on the current frame
        deleteSubFrames:        Delete sub-frame keys surrounding the current frame
    '''

    if selectedChannels:
        print 'selectedChannels flag is deprecated, please use the deleteChannels() function instead'

    keySel = utl.KeySelection()

    if selectedKeys and keySel.selectedKeys():
        pass
    elif visibleInGraphEditor and keySel.visibleInGraphEditor():
        keySel.currentFrame()
    elif keySel.selectedObjects():
        keySel.currentFrame()

    if not keySel.curves:
        return

    keySel.cutKey(includeSubFrames=deleteSubFrames)
示例#4
0
def goToKeyframe(option='next',
                 roundFrame=False,
                 selected=False,
                 selectKeys=False,
                 searchHierarchy=False):
    '''

    '''

    if option != 'next' and option != 'previous':
        OpenMaya.MGlobal.displayWarning(
            'Option argument should be "next" or "previous"')
        return

    if selected and selectKeys:
        OpenMaya.MGlobal.displayWarning(
            'Cannot use selectKeys flag in conjunction with selected flag.')
        selectKeys = False

    sel = mc.ls(sl=True)
    currentTime = mc.currentTime(query=True)
    time = currentTime

    if not sel:
        if option == 'next':
            time += 1
        elif option == 'previous':
            time -= 1
        else:
            return
        #if nothing is selected, just go to the next or previous keyframe
        with utl.SkipUndo():
            mc.currentTime(time)
        return

    keySel = utl.KeySelection()

    if searchHierarchy:
        #if we're looking through the hierarchy,
        keySel.keyedInHierarchy()

    else:
        #create the keySelection object.
        #all the heavy lifting is done in ml_utilities.
        if selected and keySel.selectedKeys():
            pass
        if keySel.visibleInGraphEditor():
            pass
        if keySel.selectedObjects():
            pass

    time = keySel.findKeyframe(which=option, roundFrame=roundFrame, loop=True)

    if selectKeys:
        mc.selectKey(keySel.curves, time=(time, ))

    #finally, set the time without adding to the undo queue
    with utl.SkipUndo():
        mc.currentTime(time, edit=True)
示例#5
0
def selectKeyed(nodes, *args):
    if nodes:
        mc.select(nodes)
    keySel = utl.KeySelection()
    if keySel.keyedInHierarchy():
        mc.select(keySel.nodes, replace=True)
    else:
        mc.select(clear=True)
示例#6
0
def weightBreakdownStep(direction='next', weight=0.2):

    keySel = utl.KeySelection()
    if keySel.selectedKeys():
        pass
    elif keySel.visibleInGraphEditor():
        keySel.setKeyframe()
    elif keySel.keyedChannels():
        keySel.setKeyframe()

    if not keySel.curves:
        return

    times = list()
    values = list()

    data = list()

    for curve in keySel.curves:
        if keySel.selected:
            times = mc.keyframe(curve, query=True, timeChange=True, sl=True)
            values = mc.keyframe(curve, query=True, valueChange=True, sl=True)
        else:
            times = [keySel.time]
            values = mc.keyframe(curve,
                                 time=keySel.time,
                                 query=True,
                                 valueChange=True)

        for i, v in zip(times, values):
            nextTime = mc.findKeyframe(curve, time=(i, ), which='next')
            n = mc.keyframe(curve,
                            time=(nextTime, ),
                            query=True,
                            valueChange=True)[0]
            prevTime = mc.findKeyframe(curve, time=(i, ), which='previous')
            p = mc.keyframe(curve,
                            time=(prevTime, ),
                            query=True,
                            valueChange=True)[0]

            data.append([curve, i, v, n, p])

    for d in data:

        value = None
        if direction == 'next':
            value = d[2] + ((d[3] - d[2]) * weight)
        elif direction == 'previous':
            value = d[2] + ((d[4] - d[2]) * weight)
        elif direction == 'average':
            value = d[2] + (((d[3] + d[4]) / 2 - d[2]) * weight)
        else:
            break

        mc.keyframe(d[0], time=(d[1], ), valueChange=value)
示例#7
0
def main():
    '''
    Select any node in a hierarchy, and run the script.
    It will select all keyed objects within the hierarchy
    except the root node. If the selected object has a namespace,
    only nodes within that namespace will be selected.
    '''

    keySel = utl.KeySelection()
    if keySel.keyedInHierarchy():
        mc.select(keySel.nodes, replace=True)
示例#8
0
def setKey(deleteSubFrames=False,
           insert=False,
           selectedChannels=False,
           visibleInGraphEditor=False,
           keyKeyed=False,
           keyShapes=False):
    '''
    The main function arguments:

        deleteSubFrames:        Delete sub-frame keys surrounding the current frame
        insert:                 Insert key (preserve tangents)
        selectedChannels:       Only key channels that are selected in the Channel Box
        visibleInGraphEditor:   Only key curves visible in Graph Editor
        keyKeyed:               Only set keys on channels that are already keyed
        keyShapes:              Set keyframes on shapes as well as transforms
    '''

    keySel = utl.KeySelection()

    if selectedChannels and keySel.selectedChannels():
        pass
    elif visibleInGraphEditor and keySel.visibleInGraphEditor():
        pass
    elif keyKeyed and keySel.keyedChannels(includeShapes=keyShapes):
        pass
    else:
        keySel.selectedObjects()

    if not keySel.initialized:
        return

    #if the user has middle-mouse dragged, we don't want to insert
    #test this by comparing the current attribute value with the evaluated animation curve
    if keySel.curves and insert:
        #pretty sure curve and channel are linked properly, but this might be an issue.
        for curve, chan in zip(keySel.curves, keySel.channels):
            #chan = utl.getChannelFromAnimCurve(each)
            curveValue = mc.keyframe(curve, query=True, eval=True)
            if not curveValue:
                insert = False
                break
            if round(mc.getAttr(chan), 3) != round(curveValue[0], 3):
                insert = False
                break

    #set the actual keyframe
    keySel.setKeyframe(insert=insert,
                       shape=keyShapes,
                       deleteSubFrames=deleteSubFrames)
示例#9
0
    def __init__(self,
                 name='mlKeyValueDraggerContext',
                 minValue=0,
                 maxValue=None,
                 defaultValue=1,
                 title = 'Scale'):

        self.keySel = utl.KeySelection()
        selected = False
        if self.keySel.selectedKeys():
            selected = True
            pass
        elif self.keySel.visibleInGraphEditor():
            self.keySel.setKeyframe()
        elif self.keySel.keyedChannels():
            self.keySel.setKeyframe()
        elif self.keySel.selectedObjects():
            self.keySel.setKeyframe()

        if not self.keySel.initialized:
            return

        utl.Dragger.__init__(self, defaultValue=defaultValue, minValue=minValue, maxValue=maxValue, name=name, title=title)

        self.time = dict()
        self.default = dict()
        self.value = dict()
        self.curves = self.keySel.curves

        for curve in self.curves:
            if selected:
                self.time[curve] = mc.keyframe(curve, query=True, timeChange=True, sl=True)
                self.value[curve] = mc.keyframe(curve, query=True, valueChange=True, sl=True)
            else:
                self.time[curve] = self.keySel.time
                self.value[curve] = mc.keyframe(curve, time=self.keySel.time, query=True, valueChange=True)

            #get the attribute's default value
            node, attr = mc.listConnections('.'.join((curve,'output')), source=False, plugs=True)[0].split('.')
            self.default[curve] = mc.attributeQuery(attr, listDefault=True, node=node)[0]

        self.setTool()
        onscreenInstructions = 'Drag left to scale toward default, and right to go in the opposite direction.'
        self.drawString(onscreenInstructions)
        OpenMaya.MGlobal.displayWarning(onscreenInstructions)
示例#10
0
def deleteChannels():
    '''
    Deletes selected channels, otherwise all keys on the selected objects.
    '''

    keySel = utl.KeySelection()

    if keySel.selectedChannels():
        pass
    elif keySel.visibleInGraphEditor():
        pass
    elif keySel.selectedObjects():
        pass

    if not keySel.initialized:
        return

    keySel.cutKey()
示例#11
0
def _getKeySelection(selectionOption):

    keySel = utl.KeySelection()

    if selectionOption == 1:
        keySel.selectedObjects()
    elif selectionOption == 2:
        keySel.selectedChannels()
    elif selectionOption == 3:
        keySel.keyedInHierarchy()
    elif selectionOption == 4:
        keySel.visibleInGraphEditor()
    elif selectionOption == 5:
        keySel.scene()
    elif selectionOption == 6:
        keySel.selectedLayers()

    return keySel
示例#12
0
def _getKeySelection(selectionOption):
    
    selectedPreset = mc.optionMenuGrp('ml_animCurveEditor_selection_menu', query=True, select=True)
    
    keySel = utl.KeySelection()
    
    if selectionOption == 1:
        keySel.selectedObjects()
    elif selectionOption == 2:
        keySel.selectedChannels()
    elif selectionOption == 3:
        keySel.keyedInHierarchy()
    elif selectionOption == 4:
        keySel.visibleInGraphEditor()
    elif selectionOption == 5:
        keySel.scene()
    elif selectionOption == 6:
        keySel.selectedLayers()
        
    return keySel
示例#13
0
def holdFrame(next=False, previous=False):
    '''
    Creates a hold between the specified key or frame and the next or previous key
    Arguments:
        next: Match the value of the specified frame to the next key in time.
        previous: Match the value of the specified frame to the previous key in time.
    '''

    if (next and previous) or (not next and not previous):
        OpenMaya.MGlobal.displayWarning(
            'This function requires exactly one argument to be true.')
        return

    sel = mc.ls(sl=True)

    if not sel:
        OpenMaya.MGlobal.displayWarning('Nothing selected.')
        return

    curves = None
    start = None
    end = None
    value = None
    currentTime = mc.currentTime(query=True)

    keySel = utl.KeySelection()
    if keySel.selectedKeys():
        pass
    elif keySel.visibleInGraphEditor():
        pass
    elif keySel.keyedChannels():
        pass

    if keySel.selectedFrameRange():
        pass
    elif keySel.keyRange():
        pass
    else:
        keySel.setKeyframe()

    start = None
    end = None

    #if you're using maya before 2011, python doesn't undo properly
    with utl.UndoChunk():
        itt, ott = utl.getHoldTangentType()
        selected = mc.keyframe(query=True, name=True, selected=True)

        for curve in keySel.curves:
            value = None
            start = currentTime
            end = currentTime
            findFrom = currentTime
            if selected:
                keyTimes = mc.keyframe(curve,
                                       query=True,
                                       timeChange=True,
                                       selected=True)
                if next:
                    start = keyTimes[0]
                    findFrom = keyTimes[-1]
                elif previous:
                    end = keyTimes[-1]
                    findFrom = keyTimes[0]
            if next:
                end = mc.findKeyframe(curve, time=(findFrom, ), which='next')
                value = mc.keyframe(curve,
                                    time=(end, ),
                                    query=True,
                                    valueChange=True)[0]
            elif previous:
                start = mc.findKeyframe(curve,
                                        time=(findFrom, ),
                                        which='previous')
                value = mc.keyframe(curve,
                                    time=(start, ),
                                    query=True,
                                    valueChange=True)[0]

            #TODO: delete redundant keys

            if (end - start) > 1:
                mc.cutKey(curve, time=(start + 0.1, end - 0.1))

            mc.keyframe(curve, time=(start, end), edit=True, valueChange=value)

            #set tangents
            mc.keyTangent(curve, time=(start, end), itt=itt, ott=ott)