Ejemplo n.º 1
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
Ejemplo n.º 2
0
    def drawGraph(self, *args):
        """
        This function draws the soundWave on the UI
        """
        if not self.reader:
            cmds.warning("Please apply an audio first")
            return

        if cmds.objExists("AudioVisHelper"):
            cmds.delete("AudioVisHelper")

        visualizer = cmds.polySphere(name="AudioVisHelper")[0]

        cmds.setAttr(visualizer + ".visibility", 0)

        frameRate = mel.eval('currentTimeUnitToFPS()')
        values = self.reader.sampleStepped(int(frameRate))

        for f in xrange(len(values)):
            cmds.currentTime(f)
            cmds.setAttr("{}.translateY".format(visualizer), values[int(f)][0])
            cmds.setKeyframe("{}.translateY".format(visualizer))

        cmds.setParent(self.mainLayout)
        cmds.deleteUI(self.graph)
        self.graph = cmds.frameLayout(height=200,
                                      width=500,
                                      labelVisible=False)
        cmds.animCurveEditor(autoFit=True,
                             displayKeys=False,
                             displayNormalized=True)
        cmds.setParent("..")
Ejemplo n.º 3
0
def toggle_normalized():
    normalized_state = cmds.animCurveEditor( ANIM_CURVE_EDITOR
                                           , query=True
                                           , displayNormalized=True
                                           )
    cmds.animCurveEditor( ANIM_CURVE_EDITOR
                        , edit=True
                        , displayNormalized=not(normalized_state)
                        )
Ejemplo n.º 4
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   
Ejemplo n.º 5
0
def set_time_to_selected():
    current_frames = cmds.keyframe(q=True, selected=True) or []
    if current_frames:
        start_selection_frame = min(current_frames)
        # Use this line to go to the middle
        # middle_frame = (current_frames[0] + current_frames[-1]) / 2
        cmds.currentTime(start_selection_frame)
        cmds.animCurveEditor(ANIM_CURVE_EDITOR, e=True, lookAt='selected')
    else:
        frame_current_time()
Ejemplo n.º 6
0
def getMinMax():            
          
    rangeStart  = cmds.playbackOptions(query=True, minTime=True)
    rangeEnd    = cmds.playbackOptions(query=True, maxTime=True)
    curvesShown = cmds.animCurveEditor( 'graphEditor1GraphEd', query=True, curvesShown=True)
    keysTimes   = []
    keysValues  = []
    keysShown   = []
    
    if curvesShown:
        for aCurve in curvesShown:
            keysTimes.extend(cmds.keyframe(aCurve, query=True, timeChange=True))
            keysValues.extend(cmds.keyframe(aCurve, query=True, valueChange=True))
            for n, key in enumerate(keysTimes):
                if rangeStart <= key <= rangeEnd:
                    keysShown.append(keysValues[n])
                    
        keyMax = max(keysShown)
        keyMin = min(keysShown)
        total  = keyMax - keyMin
        if total == 0: total = 1
        border = total * .1
        
        return [keyMax+border, keyMin-border]
    else:
        return [0, 100]
Ejemplo n.º 7
0
def getMinMax():

    rangeStart = cmds.playbackOptions(query=True, minTime=True)
    rangeEnd = cmds.playbackOptions(query=True, maxTime=True)
    curvesShown = cmds.animCurveEditor('graphEditor1GraphEd',
                                       query=True,
                                       curvesShown=True)
    keysTimes = []
    keysValues = []
    keysShown = []

    if curvesShown:
        for aCurve in curvesShown:
            keysTimes.extend(cmds.keyframe(aCurve, query=True,
                                           timeChange=True))
            keysValues.extend(
                cmds.keyframe(aCurve, query=True, valueChange=True))
            for n, key in enumerate(keysTimes):
                if rangeStart <= key <= rangeEnd:
                    keysShown.append(keysValues[n])

        keyMax = max(keysShown)
        keyMin = min(keysShown)
        total = keyMax - keyMin
        if total == 0: total = 1
        border = total * .1

        return [keyMax + border, keyMin - border]
    else:
        return [0, 100]
Ejemplo n.º 8
0
def frameSection(nudge=24):

    curvesShown = cmds.animCurveEditor("graphEditor1GraphEd", query=True, curvesShown=True)
    if not curvesShown:
        return

    firstSelKey = cmds.keyframe(selected=True, query=True, timeChange=True)
    # lastKey     = max(cmds.keyframe(selected=False, query=True, timeChange=True))
    lastKey = cmds.playbackOptions(query=True, maxTime=True)

    if firstSelKey:  # if key is selected
        firstSelKey = min(firstSelKey)
    else:
        # firstSelKey = min(cmds.keyframe(selected=False, query=True, timeChange=True))
        firstSelKey = cmds.playbackOptions(query=True, minTime=True)

        try:
            if G.AM_lastFrameSection + nudge < lastKey and G.AM_lastCurvesShown == curvesShown:
                firstSelKey = G.AM_lastFrameSection + nudge
        except:
            pass

    G.AM_lastFrameSection = firstSelKey
    G.AM_lastCurvesShown = curvesShown

    framePlaybackRange.framePlaybackRangeFn(rangeStart=(firstSelKey - 1), rangeEnd=(firstSelKey + nudge + 2))
    cmds.currentTime(firstSelKey, edit=True)
Ejemplo n.º 9
0
def getGraphEditorOutliner():
    graphEditor = mc.getPanel(scriptType='graphEditor')
    if graphEditor:
        return mc.animCurveEditor(graphEditor[0] + 'GraphEd',
                                  query=True,
                                  outliner=True)
    return None
Ejemplo n.º 10
0
def createInfinityMM():
	# pmn = 'graphEditor1GraphEdanimCurveEditorMenu' # standard rmb popupmenu
	gEd = 'graphEditor1GraphEd' # graph editor name
	if not m.control( gEd, ex=1 ):
		print ('the graph editor: ' + str(gEd) + ' does not (yet) exist!! :/')
		return
	# our new popup
	pup = 'tweakGraphEditPopup'
	if not m.popupMenu( pup, ex=1 ):
		m.popupMenu( pup, parent=gEd, markingMenu=1, ctrlModifier=1 )

	m.popupMenu( pup, edit=1, deleteAllItems=1 )
	m.setParent( pup, menu=1 )

	# display infinities checkbox
	cmd = 'from maya.cmds import animCurveEditor; animCurveEditor( "' +gEd+ '", e=1, displayInfinities=int(not animCurveEditor( "' +gEd+ '", q=1, displayInfinities=1 )) )'
	m.menuItem( 'displayInfinitiesMenuItem', label='Display Infinities', checkBox=m.animCurveEditor( gEd, q=1, displayInfinities=1 ), c=cmd, radialPosition='N' )

	m.menuItem( 'preInfinityMenuItem', label='< Pre Infinity', subMenu=True, parent=pup ) # radialPosition='W'
	m.menuItem( 'postInfinityMenuItem', label='Post Infinity >', subMenu=True, parent=pup ) # , radialPosition='E'
	m.menuItem( 'bothInfinityMenuItem', label='< Both Infinity >', subMenu=True, parent=pup ) # , radialPosition='S'

	infType = ['cycle', 'linear', 'constant', 'cycleRelative', 'oscillate']
	itemList = ['preInfinityMenuItem', 'postInfinityMenuItem', 'bothInfinityMenuItem']
	for i in range(3):
		for type in infType:
			cmd = 'from maya.cmds import setInfinity;'
			if i != 0:
				cmd += 'setInfinity( poi="' + type + '" );'
			if i != 1:
				cmd += 'setInfinity( pri="' + type + '" );'
			m.menuItem( label=type, parent=itemList[i], c=cmd )
Ejemplo n.º 11
0
def frameSection(nudge=24):

    curvesShown = cmds.animCurveEditor('graphEditor1GraphEd',
                                       query=True,
                                       curvesShown=True)
    if not curvesShown: return

    firstSelKey = cmds.keyframe(selected=True, query=True, timeChange=True)
    #lastKey     = max(cmds.keyframe(selected=False, query=True, timeChange=True))
    lastKey = cmds.playbackOptions(query=True, maxTime=True)

    if firstSelKey:  #if key is selected
        firstSelKey = min(firstSelKey)
    else:
        #firstSelKey = min(cmds.keyframe(selected=False, query=True, timeChange=True))
        firstSelKey = cmds.playbackOptions(query=True, minTime=True)

        try:
            if G.AM_lastFrameSection + nudge < lastKey and G.AM_lastCurvesShown == curvesShown:
                firstSelKey = G.AM_lastFrameSection + nudge
        except:
            pass

    G.AM_lastFrameSection = firstSelKey
    G.AM_lastCurvesShown = curvesShown

    framePlaybackRange.framePlaybackRangeFn(rangeStart=(firstSelKey - 1),
                                            rangeEnd=(firstSelKey + nudge + 2))
    cmds.currentTime(firstSelKey, edit=True)
Ejemplo n.º 12
0
def showAll(*args):

    try:
        mc.delete(ATTR_FILTER_NAME)
    except:pass

    for ge in mc.getPanel(scriptType='graphEditor'):
        mm.eval('filterUIClearFilter  {};'.format(mc.animCurveEditor(ge+'GraphEd', query=True, outliner=True)))
Ejemplo n.º 13
0
def graphFilterScale():
	sels = mc.ls(sl=1)
	mlc = mc.animCurveEditor('graphEditor1GraphEd', q=1, mlc=1)
	mc.selectionConnection(mlc, e=1, clear=1)
	for sel in sels:
		mc.selectionConnection(mlc, e=1, s=(sel+'.scaleX'))
		mc.selectionConnection(mlc, e=1, s=(sel+'.scaleY'))
		mc.selectionConnection(mlc, e=1, s=(sel+'.scaleZ'))
Ejemplo n.º 14
0
def centerView():
    """
    //Center time cursor in graph/dopesheet

    string $panType = `getPanel -withFocus`;
    {
    if ($panType == "dopeSheetPanel1") {
        dopeSheetEditor -edit -lookAt currentTime dopeSheetPanel1DopeSheetEd;
        }
    else animCurveEditor -edit -lookAt currentTime graphEditor1GraphEd;
    }
    """

    panType = cmds.getPanel(wf=True)
    print(panType)
    if panType == "dopeSheetPanel1":
        cmds.dopeSheetEditor('dopeSheetPanel1DopeSheetEd', e=True, la='currentTime')
    elif panType == "graphEditor1":
        cmds.animCurveEditor('graphEditor1GraphEd', e=True, la='currentTime')
Ejemplo n.º 15
0
def showAll(*args):

    try:
        mc.delete(ATTR_FILTER_NAME)
    except:
        pass

    for ge in mc.getPanel(scriptType='graphEditor'):
        mm.eval('filterUIClearFilter  {};'.format(
            mc.animCurveEditor(ge + 'GraphEd', query=True, outliner=True)))
Ejemplo n.º 16
0
def centerView():
    """
    //Center time cursor in graph/dopesheet

    string $panType = `getPanel -withFocus`;
    {
    if ($panType == "dopeSheetPanel1") {
        dopeSheetEditor -edit -lookAt currentTime dopeSheetPanel1DopeSheetEd;
        }
    else animCurveEditor -edit -lookAt currentTime graphEditor1GraphEd;
    }
    """

    panType = cmds.getPanel(wf=True)
    print(panType)
    if panType == "dopeSheetPanel1":
        cmds.dopeSheetEditor('dopeSheetPanel1DopeSheetEd', e=True, la='currentTime')
    elif panType == "graphEditor1":
        cmds.animCurveEditor('graphEditor1GraphEd', e=True, la='currentTime')
Ejemplo n.º 17
0
def getMinMax(rangeStart=None, rangeEnd=None):

    displayNormalized = cmds.animCurveEditor('graphEditor1GraphEd',
                                             query=True,
                                             displayNormalized=True)
    if displayNormalized: return [-1.1, 1.1]

    if not rangeStart:
        rangeStart = cmds.playbackOptions(query=True, minTime=True)
        rangeEnd = cmds.playbackOptions(query=True, maxTime=True)
    curvesShown = cmds.animCurveEditor('graphEditor1GraphEd',
                                       query=True,
                                       curvesShown=True)
    keysTimes = []
    keysValues = []
    keysShown = []

    if curvesShown:
        for aCurve in curvesShown:
            kTimes = cmds.keyframe(aCurve, query=True, timeChange=True)
            if kTimes:
                keysTimes.extend(kTimes)
                keysValues.extend(
                    cmds.keyframe(aCurve, query=True, valueChange=True))
                for n, key in enumerate(keysTimes):
                    if rangeStart <= key <= rangeEnd:
                        keysShown.append(keysValues[n])

        if not keysShown:
            keyMax = 0
            keyMin = 0
        else:
            keyMax = max(keysShown)
            keyMin = min(keysShown)

        total = keyMax - keyMin
        if total == 0: total = 10
        border = total * .1

        return [keyMax + border, keyMin - border]
    else:
        return [0, 100]
Ejemplo n.º 18
0
 def _get_attribute_names_from_graph_editor(self):
     animCurves = cmds.animCurveEditor(GRAPH_EDITOR_NAME, q=True, cs=True)
     channels = set()
     for a in animCurves:
         connections = cmds.listConnections("%s.output" % a,
                                            s=False,
                                            d=True,
                                            plugs=True)
         tokens = connections[0].split(".")
         channels.add(str(tokens[len(tokens) - 1]))
     return list(channels)
Ejemplo n.º 19
0
def graphFilter():
	sels = mc.ls(sl=1)
	if len(sels):
		mlc = mc.animCurveEditor('graphEditor1GraphEd', q=1, mlc=1)
		selectedAttrs = mc.selectionConnection(mlc, q=1, obj=1)
		attrs = []
		for selectedAttr in selectedAttrs:
			attrs.append(selectedAttr.split('.')[1])

		mc.selectionConnection(mlc, e=1, cl=1)
		for sel in sels:
			for attr in set(attrs):
				mc.selectionConnection(mlc, e=1, s=(sel+'.'+attr))
Ejemplo n.º 20
0
def makeInfinity():
    """Set the infinity type"""
    if checkSelected() is None:
        cmds.warning("Nothing Selected!")
        return
    if checkKeys(checkSelected()) is None:
        cmds.warning("Object has no keys!")
        return

    preInfi, proInfi = queryInfinity()
    newPre = switchSetting(preInfi)
    newPro = switchSetting(proInfi)

    cmds.setInfinity(graphEditor, pri=newPre)
    cmds.setInfinity(graphEditor, poi=newPro)

    print "Pre Infinity is now {0}. Post Infinity is now {1}.".format(
        newPre, newPro),

    #Display infinity
    graphEditorAC = "graphEditor1GraphEd"
    cmds.animCurveEditor(graphEditorAC, e=True, displayInfinities="on")
Ejemplo n.º 21
0
def animCurveEditor(*args, **kwargs):
    if len(args):
        doPassSelf = kwargs.pop('passSelf', False)
    else:
        doPassSelf = False
    for key in ['dcc', 'denormalizeCurvesCommand', 'm', 'menu', 'ncc', 'normalizeCurvesCommand']:
        try:
            cb = kwargs[key]
            if callable(cb):
                kwargs[key] = _factories.makeUICallback(cb, args, doPassSelf)
        except KeyError:
            pass
    res = cmds.animCurveEditor(*args, **kwargs)
    return res
Ejemplo n.º 22
0
def getMinMax(rangeStart=None, rangeEnd=None):            
    
    displayNormalized = cmds.animCurveEditor( 'graphEditor1GraphEd', query=True, displayNormalized=True)
    if displayNormalized: return [-1.1, 1.1]  
   
    if not rangeStart:
        rangeStart  = cmds.playbackOptions(query=True, minTime=True)
        rangeEnd    = cmds.playbackOptions(query=True, maxTime=True)
    curvesShown = cmds.animCurveEditor( 'graphEditor1GraphEd', query=True, curvesShown=True)
    keysTimes   = []
    keysValues  = []
    keysShown   = []
    
    if curvesShown:
        for aCurve in curvesShown:
            kTimes = cmds.keyframe(aCurve, query=True, timeChange=True)
            if kTimes:
                keysTimes.extend(kTimes)
                keysValues.extend(cmds.keyframe(aCurve, query=True, valueChange=True))
                for n, key in enumerate(keysTimes):
                    if rangeStart <= key <= rangeEnd:
                        keysShown.append(keysValues[n])
        
        if not keysShown:
            keyMax = 0
            keyMin = 0
        else:                  
            keyMax = max(keysShown)
            keyMin = min(keysShown)
        
        total  = keyMax - keyMin
        if total == 0: total = 10
        border = total * .1
        
        return [keyMax+border, keyMin-border]
    else:
        return [0, 100]
Ejemplo n.º 23
0
def filterNonAnimatedCurves():
    
    curvesShown = cmds.animCurveEditor( 'graphEditor1GraphEd', query=True, curvesShown=True)
    
    if curvesShown:
        objsAttrs = getTarget("", curvesShown)
        cmds.selectionConnection( 'graphEditor1FromOutliner', e=True, clear=True)        
        
        cmds.waitCursor(state=True)
        
        for n, loopCurve in enumerate(curvesShown):
            keyValues    = cmds.keyframe(loopCurve, query=True, valueChange=True)
            if max(keyValues) != min(keyValues):
                cmds.selectionConnection('graphEditor1FromOutliner', edit=True, select="%s.%s"%(objsAttrs[0][n], objsAttrs[1][n]))
            
        #framePlaybackRange.framePlaybackRangeFn()    
        cmds.waitCursor(state=False)
Ejemplo n.º 24
0
def filterNonAnimatedCurves():

    curvesShown = cmds.animCurveEditor("graphEditor1GraphEd", query=True, curvesShown=True)

    if curvesShown:
        objsAttrs = getTarget("", curvesShown)
        cmds.selectionConnection("graphEditor1FromOutliner", e=True, clear=True)

        cmds.waitCursor(state=True)

        for n, loopCurve in enumerate(curvesShown):
            keyValues = cmds.keyframe(loopCurve, query=True, valueChange=True)
            if max(keyValues) != min(keyValues):
                cmds.selectionConnection(
                    "graphEditor1FromOutliner", edit=True, select="%s.%s" % (objsAttrs[0][n], objsAttrs[1][n])
                )

        # framePlaybackRange.framePlaybackRangeFn()
        cmds.waitCursor(state=False)
Ejemplo n.º 25
0
def get_selected_keyframes():
    ''' Returns a dictionary where the keys are curve names and the values are 
        [times, values]
        ie, {'curve_name' : [times, values]}
    '''

    # get the key selection
    if not cmds.animCurveEditor(GRAPH_EDITOR, exists=True):
        cmds.error("{} not found.".format(GRAPH_EDITOR))
        return  # Cannot find graph editor?

    if not cmds.animCurveEditor(GRAPH_EDITOR, q=True, areCurvesSelected=True):
        cmds.warning("Must select some keys to fit.")
        return

    selected_curves = cmds.keyframe(q=True, selected=True, name=True) or []
    if not selected_curves: return None  # Bounce early

    # The Data dictionary
    key_data = {}

    for curve in selected_curves:

        selected_index = cmds.keyframe(curve,
                                       q=True,
                                       selected=True,
                                       indexValue=True)
        if len(selected_index) == 1: continue  # Bounce
        selected_times = cmds.keyframe(curve, q=True, selected=True)
        num_keys = cmds.keyframe(curve, q=True, keyframeCount=True)

        # Now expand ranges to include pivots
        time_range = []
        index_range = []
        if min(selected_index) == 0:
            left_pivot_index = min(selected_index)
        else:
            left_pivot_index = min(selected_index) - 1
        index_range.append(left_pivot_index)
        left_pivot_time = cmds.keyframe(curve,
                                        q=True,
                                        index=(left_pivot_index, ))
        time_range.extend(left_pivot_time)

        time_range.extend(selected_times)
        index_range.extend(selected_index)

        if max(selected_index) == num_keys - 1:
            right_pivot_index = max(selected_index)
        else:
            right_pivot_index = max(selected_index) + 1
        index_range.append(right_pivot_index)
        right_pivot_time = cmds.keyframe(curve,
                                         q=True,
                                         index=(right_pivot_index, ))
        time_range.extend(right_pivot_time)

        # Now grab values
        if len(index_range) == len(
                set(index_range
                    )):  # Optimization to run one call if all index are unique
            value_range = cmds.keyframe(curve,
                                        q=True,
                                        index=(index_range[0],
                                               index_range[-1]),
                                        valueChange=True)
        else:  # Old fashioned way
            value_range = []
            for index in index_range:
                value = cmds.keyframe(curve,
                                      q=True,
                                      index=(index, ),
                                      valueChange=True)
                value_range.extend(value)

        if is_equal(value_range): continue  # Ignore flat curves

        key_data[curve] = [time_range, value_range]

    if key_data:
        return key_data
    else:
        return None
Ejemplo n.º 26
0
def getGraphEditorOutliner():
    graphEditor = mc.getPanel(scriptType='graphEditor')
    if graphEditor:
        return mc.animCurveEditor(graphEditor[0]+'GraphEd', query=True, outliner=True)
    return None
Ejemplo n.º 27
0
def get_anim_curve_editor():
    return cmds.animCurveEditor('graphEditor1GraphEd', q=True, control=True)
Ejemplo n.º 28
0
def infinity_visibility():
    cmds.animCurveEditor(ANIM_CURVE_EDITOR, e=True, displayInfinities='tgl')
Ejemplo n.º 29
0
def buffer_curve_visibility():
    cmds.animCurveEditor(ANIM_CURVE_EDITOR, e=True, showBufferCurves='tgl')
Ejemplo n.º 30
0
def frame_current_time():
    cmds.animCurveEditor(ANIM_CURVE_EDITOR, e=True, lookAt='currentTime')
Ejemplo n.º 31
0
                      option='replace')
        for k in range(
                0,
                cmds.keyframe(GetBredCurves(),
                              attribute=pop.organisms[o].keyCurve,
                              query=True,
                              keyframeCount=True)):
            if random.random() < pop.mutationChance:
                cmds.keyframe(GetBredCurves(),
                              attribute=pop.organisms[o].keyCurve,
                              edit=True,
                              index=(k, k),
                              relative=True,
                              valueChange=-pop.mutAmount +
                              (random.random() * pop.mutAmount * 2))


origCurve = cmds.animCurveEditor('graphEditor1GraphEd',
                                 query=True,
                                 curvesShown=True)
pop = None
pop = population(30, 0.5, 2.5, 3)

pop.mutChance = 0.25
pop.mutAmount = 1

while pop.organisms[0].cost > 0.25:
    NextGen()
    pop.mutAmount = 1 * pop.organisms[0].cost if pop.organisms[
        0].cost < 3 else 1
def get_state_infinity(graphEd):
	infinityState = cmds.animCurveEditor(graphEd,q=True,di=True)
	return infinityState
def set_state_infinity(graphEd,state):
	if state == 2:
		state = 1
	cmds.animCurveEditor(graphEd,e=True,di=state)
Ejemplo n.º 34
0
def get_state_bufferCurve(graphEd):
    showBufferCurvesState = cmds.animCurveEditor(graphEd,
                                                 q=True,
                                                 showBufferCurves=True)
    return showBufferCurvesState
Ejemplo n.º 35
0
def set_state_bufferCurve(graphEd, state):
    if state == 2:
        state = 1
    cmds.animCurveEditor(graphEd, e=True, showBufferCurves=state)
Ejemplo n.º 36
0
def matchKeys(pivot=None):
    # Feed it a string
    # 'first' to pivot first key
    # 'last' to pivot from last
    # hur dur
    if not pivot:
        pivot = 'first'
    if not pivot == 'first':
        if not pivot == 'last':
            mapi.MGlobal.displayError(\
                'Check the spelling of your matchKeys call. '\
                'It should either be calling "first" or "last"')
            return None

    selectedAttrs = cmds.keyframe(q=True, sl=True, shape=True, name=True)
    if not selectedAttrs:
        shownCurves = cmds.animCurveEditor('graphEditor1GraphEd',
                                           q=True,
                                           cs=True)
        selectedAttrs = shownCurves

    for attr in selectedAttrs:
        firstKey = 0
        lastKey = cmds.keyframe(attr, q=True,
                                keyframeCount=True) - 1  # count starts at 0

        if pivot == 'first':
            pivotKey = 0  # indexth key, not frame
            targetKey = lastKey
        elif pivot == 'last':
            pivotKey = lastKey
            targetKey = firstKey

        keyValue = cmds.keyframe(attr,
                                 q=True,
                                 index=(pivotKey, ),
                                 valueChange=True)

        itt = cmds.keyTangent(attr,
                              index=(pivotKey, ),
                              q=True,
                              inTangentType=True)
        ott = cmds.keyTangent(attr,
                              index=(pivotKey, ),
                              q=True,
                              outTangentType=True)
        ia = cmds.keyTangent(attr, index=(pivotKey, ), q=True, inAngle=True)
        oa = cmds.keyTangent(attr, index=(pivotKey, ), q=True, outAngle=True)

        cmds.keyframe(attr,
                      edit=True,
                      index=(targetKey, ),
                      valueChange=keyValue[0])

        isWeighted = cmds.keyTangent(attr,
                                     index=(pivotKey, ),
                                     q=True,
                                     weightedTangents=True)
        if isWeighted:
            iw = cmds.keyTangent(attr,
                                 index=(pivotKey, ),
                                 q=True,
                                 inWeight=True)
            ow = cmds.keyTangent(attr,
                                 index=(pivotKey, ),
                                 q=True,
                                 outWeight=True)
            cmds.keyTangent(attr,
                            index=(targetKey, ),
                            edit=True,
                            itt=itt[0],
                            ott=ott[0],
                            ia=ia[0],
                            oa=oa[0],
                            iw=iw[0],
                            ow=ow[0])
        else:
            cmds.keyTangent(attr,
                            index=(targetKey, ),
                            edit=True,
                            itt=itt[0],
                            ott=ott[0],
                            ia=ia[0],
                            oa=oa[0])