python类currentTime()的实例源码

zbw_animTools.py 文件源码 项目:zTools 作者: zethwillie 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def zbw_pullDownAnim():
    #eventually pull these out to be two separate operations, grab controls, grab master
    #select controls to pull down (create a visible list to see these controls)
    controls =  cmds.ls(sl=True)
    controlSize = len(controls)

    #select master control
    master = controls[0]

    def zbw_getWSTranslate(obj):
        transT = cmds.xform(obj, query=True, t=True, ws=True) #gets translation from obj
        #currentFrame = cmds.currentTime(query=True) #gets current frame.
        return transT

    def zbw_getWSRotation(obj): #do I need to decompose matrix here? or create and discard locator with rot orders
        rotateT = cmds.xform(obj, query=True, ro=True, ws=True) #gets WS rotation from obj
        #rotateNew = [rotateT[0][0], rotateT[0][1], rotateT[0][2]]
        #currentFrame = int(cmds.currentTime(query=True)) #gets current frame.
        return rotateT

    #for each control selected grab the ws pos and rotation for each key, store these in a dictionary
    for i in range(1,controlSize):
        transKeys = {} #initialize dictionary for this control
        rotKeys = {}  #initialize dictionary for this control
        thisControl = controls[i]
        #create list of master control keys too (create set to contain keys
        #from master, translate,rotate)

        ###### loop here for each keyframe
        for nowKey in keyList:
            cmds.currentTime(nowKey)
            #at each key location, grab ws translation
            thisTrans = zbw_getWSTranslate(thisControl)
            transKeys[nowKey] = thisTrans
            #at each key location, grab ws rotation/orientation
            thisRot = zbw_getWSRotation(thisControl)
            rotKeys[nowKey] = thisRot
            ###### end loop

        #at each key location, apply the pos and rot
        for thisKey in keyList:
            cmds.setKey(thisControl, at='tx', t=thisKey, value=transKeys[thisKey[0]])

    #zero out master control

#change frame rate
mddWriter.py 文件源码 项目:pw_mGeoExporter 作者: paulwinex 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def export(self, path, start, end, step, scale):
        #open file
        res = True
        try:
            mddFile = open(path, 'wb')
        except IOError:
            self.par.msg2(1, 'Error open file ' + path)
            return False
        #get objects
        selection = om.MSelectionList()
        om.MGlobal.getActiveSelectionList(selection)
        pivotFilterSelection = self.filterObjects(selection)

        #first frame
        cmds.currentTime(start, edit=True)
        vertexPositionList = self.getPoints(selection, scale, pivotFilterSelection)
        #variables
        fps = float(mel.eval('currentTimeUnitToFPS'))
        self.par.msg2(2, 'FPS:', fps)
        numframes = int((end - start + 1)/step)
        numverts = len(vertexPositionList)/3
        self.pointCount = numverts
        print 'Frames', numframes
        print  'Point count', numverts
        #start write to file
        mddFile.write(struct.pack(">2i", numframes, numverts))
        times = [(frame/fps)*step for frame in xrange(numframes)]
        # print times
        mddFile.write(struct.pack(">%df" % numframes, *times))
        mddFile.write(struct.pack(">%df" % (numverts*3), *[v for v in vertexPositionList]))
        prev = 0
        #write sequence
        cmds.progressBar(self.par.progress, edit=True, pr=0)
        frame = start
        while frame < end+1:
            # if cmds.progressBar(self.par.progress, q=1, ic=1):
            if self.par.isCacneled():
                self.par.caselExport()
                res =  False
                break
            rng = end-start
            prc = (frame*100.0)/(end-start)
            cmds.progressBar(self.par.progress, edit=True, pr=int(prc))
            prev = int(prc)
            cmds.currentTime(frame, edit=True)
            self.par.statusMsg('Write cache frame '+str(frame))
            vertexPositionList = self.getPoints(selection, scale, pivotFilterSelection)
            if not (numverts*3) == len(vertexPositionList):
                om.MGlobal.displayError('TOPOLOGY HAS CHANGED!!!')
                self.par.msg2(1, 'TOPOLOGY HAS CHANGED!!!')
                res =  False
                break
            mddFile.write(struct.pack(">%df" % (numverts*3), *[v for v in vertexPositionList]))
            frame += step
        #close file
        mddFile.close()
        cmds.currentTime(start, edit=True)
        return res
ml_stopwatch.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def ui(self):
        '''
        Launch a UI to display the marks that were recorded.
        '''

        with utl.MlUi('ml_stopwatchReport', 'Stopwatch Report', width=400, height=400, info='''This is the report from the stopwatch you just ran.
Adjust the start frame, and then press the frame buttons to jump to that frame.
The fields on the right can be used for notes.''', menu=False) as win:

            self.uiSlider = mc.intSliderGrp(field=True, label='Start Frame', value=self.startFrame, 
                minValue=((-0.5*self.frameMarks[-1])+self.startFrame), maxValue=(self.frameMarks[-1]/2)+self.startFrame, 
                fieldMinValue=-1000, fieldMaxValue=1000,
                changeCommand=self.uiUpdateStartFrame)

            self.frameRateField = mc.intFieldGrp(label='Frame Rate', value1=self.frameRate, enable1=False, extraLabel='fps', annotation='')

            mc.scrollLayout()
            mc.rowColumnLayout(numberOfColumns=3, columnWidth=[(1, 50), (2, 80), (3, 340)])
            mc.text('Frame')
            mc.text('Duration')
            mc.text('Notes')

            for i in range(3):
                mc.separator(style='single', height=15)

            self.uiButton = list()

            for i in range(len(self.frameMarks)):

                #frame button
                frame = self.frameMarks[i]+self.startFrame
                self.uiButton.append(mc.button(label=str(frame), annotation='Go to frame %i' % frame,command='import maya.cmds;maya.cmds.currentTime(%i,edit=True)' % frame))

                #duration text
                if i:
                    mc.text(label=str(self.frameMarks[i]-self.frameMarks[i-1]))
                else:
                    mc.text(label='Start')

                #notes field
                mc.textField()

            #add the stop
            mc.text(label='')
            mc.text(label='Stop')
            mc.setParent('..')
            mc.setParent('..')

            #next and prev buttons!
            mc.paneLayout(configuration='vertical2',separatorThickness=1)
            mc.button(label='<< Previous', command=self.previousFrame, annotation='Go to the previous frame in the list.')
            mc.button(label='Next >>', command=self.nextFrame, annotation='Go to the next frame in the list.')
ml_tangentWeight.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def tangentScale(value, outValue=None):

    if outValue == None:
        outValue = value

    curves = None

    #order of operations:
    #selected keys, visible in graph editor on current frame
    selected = False
    time = mc.currentTime(query=True)
    curves = mc.keyframe(query=True, name=True, selected=True)
    if curves:
        #try selected keys first
        selected = True
    else:
        #then visible in graph editor
        graphVis = mc.selectionConnection('graphEditor1FromOutliner', query=True, obj=True)
        if graphVis:
            curves = mc.keyframe(graphVis, query=True, name=True)
        else:
            #otherwise try keyed channels.
            sel = mc.ls(sl=True)
            if not sel:
                return
            curves = mc.listConnections(sel, s=True, d=False, type='animCurve')
            if not curves:
                return

    for curve in curves:

        keyTimes = list()

        #set tangents weighted if they aren't already
        if mc.keyTangent(curve, query=True, weightedTangents=True):
            mc.keyTangent(curve, edit=True, weightedTangents=True)

        if selected:
            keyTimes = mc.keyframe(curve, query=True, timeChange=True, selected=True)
        else:
            keyTimes = [time]

        for t in keyTimes:

            weight = mc.keyTangent(curve, time=(t,), query=True, inWeight=True, outWeight=True)
            if not weight:
                continue

            inOut = list()

            for w,v in zip(weight,[value,outValue]):
                if v<1 and w < 0.1:
                    inOut.append(0)
                elif v>1 and w == 0:
                    inOut.append(0.1)
                else:
                    inOut.append(w*v)

            mc.keyTangent(curve, time=(t,), edit=True, absolute=True, inWeight=inOut[0], outWeight=inOut[1])
ml_goToKeyframe.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 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)
ml_utilities.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def setKeyframe(self, deleteSubFrames=False, **kwargs):
        '''
        Wrapper for the setKeyframe command. Curve and time arguments will be provided based on 
        how this object was intitialized, otherwise usage is the same as maya's setKeyframe command.
        Option to delete sub-frames after keying.
        '''

        if not 'time' in kwargs:
            #still not sure about how I want to do this, but we need a discrete time.
            #if time is a string set to current time
            if isinstance(self.time, tuple) and (isinstance(self.time[0], str) or len(self.time)>1):
                kwargs['time'] = mc.currentTime(query=True)
            else:
                kwargs['time'] = self.time

        if 'insert' in kwargs and kwargs['insert'] == True:
            #setKeyframe fails if insert option is used but there's no keyframes on the channels.
            #key any curves with insert, then key everything again without it

            if self.curves:
                mc.setKeyframe(self.curves, **kwargs)
            kwargs['insert'] = False

        #want to try setting keys on nodes first, since certain setKeyframe arguments wont work
        #as expected with channels
        if self._nodes:
            mc.setKeyframe(self.nodes, **kwargs)
            self._curves = mc.keyframe(self.nodes, query=True, name=True)
        else:
            mc.setKeyframe(self.channels, **kwargs)
            self._curves = mc.keyframe(self.channels, query=True, name=True)

        #there's a new selection of curves, so reset the member variables
        self._channels = list()
        self._nodes = list()
        self._time = kwargs['time']

        if deleteSubFrames:
            #remove nearby sub-frames
            #this breaks at higher frame ranges because maya doesn't keep enough digits
            #this value is also different for different frame rates
            if self.currentTime % 1 == 0 and -9999 < self.currentTime < 9999:
                #the distance that keys can be is independent of frame rate, so we have to convert based on the frame rate.
                tol = self.shortestTime
                self.cutKey(time=(self.currentTime+tol, self.currentTime+0.5))
                self.cutKey(time=(self.currentTime-0.5, self.currentTime-tol))
ml_utilities.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def findKeyframe(self, which='next', loop=False, roundFrame=False, **kwargs):
        '''
        This is similar to maya's findKeyframe, but operates on the keySelection and has options
        for rounding and looping.
        '''

        if which not in ('next','previous','first','last'):
            return

        if not roundFrame:
            if not loop or which == 'first' or which == 'last':
                #if there's not special options, just use default maya command for speed
                return mc.findKeyframe(self.args, which=which, **kwargs)

        keyTimes = self.getSortedKeyTimes()

        #if we don't find any, we're done
        if not keyTimes:
            return

        tolerence = 0.0
        if roundFrame:
            tolerence = 0.5

        if which == 'previous':
            findTime = keyTimes[-1]
            for x in reversed(keyTimes):
                if self.currentTime - x > tolerence:
                    findTime=x
                    break
        elif which == 'next':
            findTime = keyTimes[0]
            for x in keyTimes:
                if x - self.currentTime > tolerence:
                    findTime=x
                    break        
        elif which == 'first':
            findTime = keyTimes[0]
        elif which == 'last':
            findTime = keyTimes[-1]

        if roundFrame:
            #round to nearest frame, if that option is selected
            findTime = round(findTime)

        return findTime


问题


面经


文章

微信
公众号

扫码关注公众号