示例#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 __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')
示例#3
0
def holdRange(current=False, average=False):
    '''
    Create a hold over a range of frames. 
    Arguments:
        current: hold value comes from current frame
        average: hold value comes from the average of all keys over the range.
    '''

    if (current and average) or (not current and not average):
        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)
    graphVis = mc.selectionConnection('graphEditor1FromOutliner',
                                      query=True,
                                      obj=True)

    # first check if a range is selected
    gPlayBackSlider = mm.eval('$temp=$gPlayBackSlider')
    if mc.timeControl(gPlayBackSlider, query=True, rangeVisible=True):
        pbRange = mc.timeControl(gPlayBackSlider, query=True, rangeArray=True)
        start = float(pbRange[0])
        end = float(pbRange[1]) - 1

        #visible in graph editor
        if graphVis:
            curves = mc.keyframe(graphVis, query=True, name=True)
        else:
            curves = mc.keyframe(sel, query=True, name=True)
    else:
        #selected key range
        curves = mc.keyframe(query=True, name=True, selected=True)
        if curves:
            keyTimes = mc.keyframe(query=True, timeChange=True, selected=True)
            keyTimes.sort()
            if keyTimes[0] == keyTimes[-1]:
                return

            start = keyTimes[0]
            end = keyTimes[-1]

        else:
            if graphVis:
                curves = mc.keyframe(graphVis, query=True, name=True)
            else:
                curves = mc.keyframe(sel, query=True, name=True)

            start = mc.findKeyframe(curves,
                                    time=(currentTime, ),
                                    which='previous')
            end = mc.findKeyframe(curves, time=(currentTime, ), which='next')

    #set start and end frames
    mc.setKeyframe(curves, time=(start, end))

    #if you're using maya before 2011, python doesn't undo properly
    with utl.UndoChunk():
        for curve in curves:
            if average:
                v = mc.keyframe(curve,
                                time=(start, end),
                                query=True,
                                valueChange=True)
                value = sum(v) / len(v)
            elif current:
                if 'animCurveT' in mc.nodeType(curve):
                    plug = mc.listConnections('.'.join((curve, 'output')),
                                              source=False,
                                              plugs=True)[0]
                    value = mc.getAttr(plug)

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

        #delete inbetweens
        if (end - start) > 1:
            mc.cutKey(curves, time=(start + 0.1, end - 0.1))
        itt, ott = utl.getHoldTangentType()
        mc.keyTangent(curves, time=(start, end), itt=itt, ott=ott)
示例#4
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)
示例#5
0
def holdRange(current=False, average=False):
    '''
    Create a hold over a range of frames. 
    Arguments:
        current: hold value comes from current frame
        average: hold value comes from the average of all keys over the range.
    '''


    if (current and average) or (not current and not average):
        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)
    graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True)

    # first check if a range is selected
    gPlayBackSlider = mm.eval('$temp=$gPlayBackSlider')
    if mc.timeControl(gPlayBackSlider, query=True, rangeVisible=True):
        pbRange = mc.timeControl(gPlayBackSlider, query=True, rangeArray=True)
        start = float(pbRange[0])
        end = float(pbRange[1])-1

        #visible in graph editor
        if graphVis:
            curves = mc.keyframe(graphVis, query=True, name=True)
        else:
            curves = mc.keyframe(sel, query=True, name=True)
    else:
        #selected key range
        curves = mc.keyframe(query=True, name=True, selected=True)
        if curves:
            keyTimes = mc.keyframe(query=True, timeChange=True, selected=True)
            keyTimes.sort()
            if keyTimes[0] == keyTimes[-1]:
                return
            
            start = keyTimes[0]
            end = keyTimes[-1]
            
        else:
            if graphVis:
                curves = mc.keyframe(graphVis, query=True, name=True)
            else:
                curves = mc.keyframe(sel, query=True, name=True)
                
            start = mc.findKeyframe(curves, time=(currentTime,), which='previous')
            end = mc.findKeyframe(curves, time=(currentTime,), which='next')
            
    #set start and end frames
    mc.setKeyframe(curves, time=(start,end))

    #if you're using maya before 2011, python doesn't undo properly
    with utl.UndoChunk():
        for curve in curves:
            if average:
                v = mc.keyframe(curve, time=(start,end), query=True, valueChange=True)
                value = sum(v)/len(v)
            elif current:
                if 'animCurveT' in mc.nodeType(curve):
                    plug = mc.listConnections('.'.join((curve,'output')), source=False, plugs=True)[0]
                    value = mc.getAttr(plug)
                
            mc.keyframe(curve, time=(start,end), edit=True, valueChange=value)
            
        #delete inbetweens
        if (end-start) > 1:
            mc.cutKey(curves, time=(start+0.1, end-0.1))
        itt,ott = utl.getHoldTangentType()
        mc.keyTangent(curves, time=(start,end), itt=itt, ott=ott)
示例#6
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)