Esempio n. 1
0
def bakeSequenceScale(s):

    print "baking shot camera: ", s

    #create shot render cam
    renderCam = mc.shot(s, cc=True, q=True)
    copiedRenderCam = mc.duplicate(renderCam,
                                   name=renderCam + "_baked_" + s,
                                   un=True)[0]
    print "copied render cam for ", s, " : ", copiedRenderCam

    #shot sequence vars
    seq_startTime = mc.shot(s, sst=True, q=True)
    seq_endTime = mc.shot(s, set=True, q=True)
    seq_duration = mc.shot(s, sequenceDuration=True, q=True)

    #get shot info
    #this assumes start time is never subframe
    startTime = mc.shot(s, st=True, q=True)
    #get actual end time, api endtime doesnt return subframe.
    mc.sequenceManager(currentTime=seq_endTime)
    endTime = mc.currentTime(q=True)

    print renderCam, ":"
    print "camera time:", startTime, "=>", endTime

    #set current time to start time
    mc.setKeyframe(copiedRenderCam, hi="both", t=startTime)
    print "Created initial keys"
    mc.setKeyframe(copiedRenderCam, hi="both", t=endTime)
    print "Created ending keys"

    #remove any keyframes that's not in this frame range
    print "cleanup keyframes."
    mc.cutKey(copiedRenderCam,
              clear=True,
              time=(":" + str(startTime - 0.01), ),
              option="keys")
    mc.cutKey(copiedRenderCam,
              clear=True,
              time=(str(endTime + 0.01) + ":", ),
              option="keys")

    #set end time to scale
    scaleEndTime = startTime + seq_duration - 1

    print "scaling to: ", startTime, " => ", scaleEndTime

    mc.scaleKey(copiedRenderCam,
                time=(startTime, endTime),
                newStartTime=startTime,
                newEndTime=scaleEndTime,
                timePivot=0)

    return copiedRenderCam
Esempio n. 2
0
    def connectLoc(self, arg):
        locName = mc.ls(sl=True)
        self.listSel = []
        for loc in locName:
            print loc
            gpu_name = loc.split('_loc')
            self.listSel.append(gpu_name[0])

        #self.listSel = mc.ls(selection = True)
        mc.select(clear=True)
        for self.sel in self.listSel:
            self.locName = self.sel + "_loc"
            #mc.cutKey(self.sel, option='keys')
            self.parentCon = mc.parentConstraint(self.locName,
                                                 self.sel,
                                                 maintainOffset=False)  #True
            self.scaleCon = mc.scaleConstraint(self.locName,
                                               self.sel,
                                               maintainOffset=False)
            mc.parent(self.locName, 'ARLoc_Grp')
            for shotSq in mc.sequenceManager(listShots=True):
                self.currentShotStart = mc.shot(shotSq, q=True, st=True)
                self.currentShotEnd = mc.shot(shotSq, q=True, et=True)

                mc.cutKey(self.locName,
                          time=((self.currentShotStart + 1),
                                (self.currentShotEnd - 1)),
                          option='keys')
Esempio n. 3
0
    def connectLoc (self,arg):
        locName = mc.ls(sl=True)
        self.listSel = []
        for loc in locName:
            print loc
            #gpu_name = loc.split('_loc')
            gpuNameSpace = loc.rsplit('_',5)[0] #060117 edit because namespace AD_AR are change
            nameSplit = loc.split(gpuNameSpace)[1].split('_',1)[1].split('_loc')[0]
            gpu_name = '%s:%s'%(gpuNameSpace,nameSplit)
            self.listSel.append(gpu_name)

        #self.listSel = mc.ls(selection = True)

        mc.select(clear=True)
        for self.sel in self.listSel:
            #self.locName = self.sel+"_loc"

            self.locName = self.sel.replace(':','_')+"_loc" #060117 edit because namespace AD_AR are change
            #mc.cutKey(self.sel, option='keys')
            self.parentCon = mc.parentConstraint(self.locName,self.sel,maintainOffset = False) #True
            self.scaleCon = mc.scaleConstraint(self.locName,self.sel,maintainOffset = False)
            mc.parent(self.locName,'ARLoc_Grp')
            for shotSq in mc.sequenceManager(listShots = True):
                self.currentShotStart = mc.shot( shotSq,q=True,st=True)
                self.currentShotEnd = mc.shot (shotSq,q=True,et=True )

                mc.cutKey(self.locName,time=((self.currentShotStart+1), (self.currentShotEnd-1)), option='keys')
Esempio n. 4
0
    def autoTranfer (self,arg):
        self.listSel = mc.ls(selection = True) 

        if not mc.objExists('ARLoc_Grp'):
                mc.group( em=True, name='ARLoc_Grp')
        self.bakeLoc = []
        self.delPar = []
        self.delScale = []
        self.selList = []
        for self.sel in self.listSel:
            #self.locName = self.sel+"_loc"
            self.locName = self.sel.replace(':','_')+"_loc" #060117 edit because namespace AD_AR are change
            self.loc = mc.spaceLocator(p=(0,0,0),name = self.locName )
            self.parentLoc = mc.parentConstraint(self.sel,self.loc,maintainOffset = False)
            self.scaleLoc = mc.scaleConstraint(self.sel,self.loc,maintainOffset = False) #
            self.bakeLoc.append(self.loc[0]) #because loc is list
            self.delPar.append(self.parentLoc[0]) #because delPar is list
            self.selList.append(self.sel)
            #mc.bakeResults(self.loc,simulation=True,time = (self.timeSliderMin,self.timeSliderMax))
            #mc.delete(self.parentLoc)
            #mc.cutKey(self.sel, option='keys')
            #self.parentCon = mc.parentConstraint(self.loc,self.sel,maintainOffset = True)
            #self.scaleCon = mc.scaleConstraint(self.loc,self.sel,maintainOffset = True)
            #mc.parent(self.loc,'ARLoc_Grp')
            #mc.cutKey(self.loc,time=((self.timeSliderMin+1), (self.timeSliderMax-1)), option='keys')
        
        print self.delPar
        self.animNodes = mc.ls (type='animCurve')
        self.firstKey = mc.findKeyframe(self.animNodes,which='first')
        self.lastKey = mc.findKeyframe(self.animNodes,which='last')

        if self.firstKey < 101:
            self.firstKey = 101

        # isolate viewport for faster baking 
        mayaTools.isolateObj(True) 

        # bake locator 
        mc.bakeResults(self.bakeLoc,simulation=True,time = (self.firstKey,self.lastKey))

        # restore viewport back
        mayaTools.isolateObj(False)

        mc.delete(self.delPar)
        mc.delete(self.delScale)
        mc.cutKey(self.selList, option='keys')
        #return
        for self.sel in self.listSel:
            #self.locName = self.sel+"_loc"
            self.locName = self.sel.replace(':','_')+"_loc" #060117 edit because namespace AD_AR are change
            #mc.cutKey(self.sel, option='keys')
            self.parentCon = mc.parentConstraint(self.locName,self.sel,maintainOffset = False) #True
            self.scaleCon = mc.scaleConstraint(self.locName,self.sel,maintainOffset = False)
            mc.parent(self.locName,'ARLoc_Grp')
            for shotSq in mc.sequenceManager(listShots = True):
                self.currentShotStart = mc.shot( shotSq,q=True,st=True)
                self.currentShotEnd = mc.shot (shotSq,q=True,et=True )

                mc.cutKey(self.locName,time=((self.currentShotStart+1), (self.currentShotEnd-1)), option='keys')
Esempio n. 5
0
def camDict():
    list = []
    seqShots = cmds.sequenceManager(listShots=True)
    
    for each in seqShots:
        startFrame = cmds.getAttr(each+".startFrame")
        endFrame = cmds.getAttr(each+".endFrame")
        dict = {'shot': each, 'camera' : cmds.shot(each, q=True, cc = True), 'startFrame': int(startFrame), 'endFrame': int(endFrame)};
        list.append(dict)
    return list
Esempio n. 6
0
def get_camera():
    sel = mc.ls(selection=True)
    cam_shot = mc.sequenceManager(currentShot=True, query=True)
    cam_list = []
    cam_panel = []

    if sel:
        for c in sel:
            if mc.listRelatives(c, type='camera'):
                cam_list.append(c)

            elif mc.listRelatives(c, type='nurbsCurve') and mc.listRelatives(
                    c, allDescendents=True, type='camera'):
                cam_shape = mc.listRelatives(c,
                                             allDescendents=True,
                                             type='camera')[0]
                parent_node = mc.listRelatives(cam_shape, parent=True)[0]
                cam_list.append(parent_node)

    if cam_list:
        cam = cam_list[0]

    elif not cam_list and cam_shot:
        if not mc.listRelatives(mc.shot(
                cam_shot, currentCamera=True, query=True),
                                shapes=True):
            cam = mc.listRelatives(mc.shot(cam_shot,
                                           currentCamera=True,
                                           query=True),
                                   parent=True)[0]
        else:
            cam = mc.shot(cam_shot, currentCamera=True, query=True)

    else:
        all_cam = mc.ls(type='camera')
        cam = mc.listRelatives(all_cam[1], parent=True)[0]

    for p in mc.getPanel(type="modelPanel"):
        if mc.modelPanel(p, query=True, camera=True) == cam:
            cam_panel = p

        elif mc.modelPanel(p, query=True,
                           camera=True) == mc.listRelatives(cam,
                                                            shapes=True)[0]:
            cam_panel = p

        else:
            continue

    if not cam_panel:
        mc.warning('No Panel with this camera. Put one and refresh')

    camera = Camera(cam, mc.getAttr(cam + '.focalLength'),
                    mc.getAttr(cam + '.nearClipPlane'), cam_panel)
    return camera
Esempio n. 7
0
def run(pre_roll=0, ao=True):

    movpaths = []
    shot_selected = cmds.ls(sl=True, type='shot')

    shot_list = shot_selected if shot_selected else cmds.sequenceManager(listShots=True)

    for shot_node in shot_list:
        start = cmds.getAttr(shot_node + '.sequenceStartFrame') - pre_roll
        end   = cmds.getAttr(shot_node + '.sequenceEndFrame') + (1 if pre_roll else 0)
        camera = cmds.shot(shot_node, q=True, currentCamera=True)

        print shot_node, start, end, camera, ao
        cmds.currentTime(start, e=True)
        movie_path,version_file = playblastControl.setPlayblast(shot_node, start, end, camera, AOswitch=ao)

        if os.path.exists(movie_path):
            movpaths.append([movie_path,version_file])

    return movpaths
Esempio n. 8
0
	def getSequencerData(self):
		#List to be populated and then returned
		sequencerData = []
		#Store shot names as a list
		sequencerVar = ma.sequenceManager(lsh = True)
		#In case of there being no data to pull, return empty list
		try:
			#For each shot on the list, retrieve its information
			for sVT in sequencerVar:
				#tempList for storing data
				sVTListTemp = []
				#append cameraName, frameStart and frameEnd
				sVTListTemp.append(str(ma.shot(sVT, q = True, cc = True)))
				sVTListTemp.append(int(ma.shot(sVT, q = True, st = True)))
				sVTListTemp.append(int(ma.shot(sVT, q = True, et = True)))
				#append information to shotPulledList
				sequencerData.append(sVTListTemp)
				#once all shot info has been stored within shotPulledList return
			return sequencerData
		except TypeError:
			return sequencerData
Esempio n. 9
0
def camSeqRender(sh):
    allshots = mc.sequenceManager(lsh=True)
    print allshots
    for rs in allshots:
        if rs == sh:
            s=rs

    print s
    
    renderCam = mc.shot(s, cc=True, q=True)
    startTime = mc.shot(s, st=True, q=True)
    endTime = mc.shot(s, et=True, q=True)
    
    #get it for nuke 
    seq_startTime = mc.shot(s, sst=True, q=True)
    seq_endTime = mc.shot(s, set=True, q=True)
    
    offsetTime = int(seq_startTime-startTime)
    
    print s, startTime, endTime,"(",seq_startTime, seq_endTime, ")", renderCam

    print "start rendering: ", renderCam
    
    camTransform = mc.listRelatives(renderCam, p=True)[0]

    #mel.eval("lookThroughModelPanel %s modelPanel4;"%(renderCam))

    mel.eval('currentTime %s ;'%(startTime))
    while(startTime <= endTime):
        mel.eval('renderWindowRender redoPreviousRender renderView;')
        startTime += 1
        mel.eval('currentTime %s ;'%(startTime))
    
    callString = "mv /X/projects/luna/SHOTS/"+os.getenv("SHOT")+"/chichang/images/elements/tmp/ /X/projects/luna/SHOTS/"+os.getenv("SHOT")+"/chichang/images/elements/"+camTransform+"_"+str(offsetTime)+"/"
    mycmd=subprocess.Popen(callString, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    output, error=mycmd.communicate()
Esempio n. 10
0
def sequenceManager(*args, **kwargs):
    res = cmds.sequenceManager(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res
Esempio n. 11
0
    def _readClip(self, clip, isVideo, start, end, in_adjustment):
        # TODO: ensure that we don't already have a shot with
        # the same shot name in the scene
        # TODO: ensure that the rate associated with the clip
        # is the same as the rate of the whole sequence. Can
        # Maya support playback of different shots at different
        # rates? (I'm guessing no)
        # TODO: figure out how the naming should work. Should the
        # shot/audio node's name also match the "name" specified in
        # the EDL?

        if start == -1:
            self.logger.warning(
                "Importer._readClip, start parameter == -1, clip not loaded")
            return

        if end == -1:
            self.logger.warning(
                "Importer._readClip, end parameter == -1, clip not loaded")
            return

        clip_info = self.translator.getClip(clip)

        # Ensure that clip frame rate matches sequence frame rate
        self._checkFrameRates(clip, clip_info)

        clipIn = float(clip_info.get("in", 0))
        clipIn += in_adjustment

        clipNode = None

        clip_name = clip_info.get("name", "")
        # Note: The XML file could be utf-8, but Maya's nodes and attrs cannot be unicode.
        # So only use the name if it's valid
        try:
            clip_name = clip_name.encode("ascii")
        except:
            self.translator.logger.warning(
                "Clip name contains multi-byte characters, using default name")
            clip_name = ""

        clipObjectName = _getValidClipObjectName(clip_name, isVideo)

        if isVideo:
            clipNode = cmds.shot(clipObjectName)

            adjustedEnd = float(end)
            adjustedEnd -= 1  #Final frame in editorial is always exclusive bug 342715

            cmds.shot(
                clipNode,
                e=1,
                shotName=clip_name,
                sequenceStartTime=start,
                sequenceEndTime=adjustedEnd,
                clipZeroOffset=clipIn,
                startTime=start,  # Make Maya start/end the same as
                endTime=
                adjustedEnd,  # sequence start/end. Maya sequenceStart/end is not transoorted through EDL
                mute=(clip_info.get("enabled", True) == False))

            # create a custom camera
            # TODO: write out camera info as meta-data, perhaps??
            cameraNodes = cmds.camera(name=(clipNode + "Camera"))
            cmds.shot(clipNode, e=1, currentCamera=cameraNodes[0])

        else:
            clipNode = cmds.createNode("audio", name=clipObjectName)

            cmds.sequenceManager(attachSequencerAudio=clipNode)

            cmds.sound(clipNode,
                       e=1,
                       offset=start,
                       sourceStart=clipIn,
                       sourceEnd=float(clip_info.get("out", 1)),
                       endTime=end,
                       mute=(clip_info.get("enabled", True) == False))

        # Store the minimum frame of the sequence
        if self.minFrameInFile is None or start < self.minFrameInFile:
            self.minFrameInFile = start

        file_elem = clip_info.get("file", None)
        if file_elem is not None:
            file_info = self.translator.getFile(file_elem)

            # Ensure that file frame rate matches sequence frame rate
            self._checkFrameRates(file_elem, file_info)

            # TODO: convert from pathurl to an abs path that maya knows how to read
            # Or, just use the file-name and assume it's in the Maya project?
            if "pathurl" in file_info:
                if isVideo:
                    # query the frameCount. If this raises an error, it could be because
                    # the movie format is not supported on this platform
                    try:
                        frameCount = cmds.movieInfo(file_info["pathurl"],
                                                    frameCount=1)[0]
                    except:
                        self.translator.logger.warning(
                            "Could not open video file %s. File could be corrupt, or movie format is not supported on this platform"
                            % file_info["pathurl"])
                        frameCount = 0

                    video_height = file_info.get("height", None)
                    if video_height is not None:
                        cmds.setAttr((clipNode + ".hResolution"),
                                     int(video_height))
                    video_width = file_info.get("width", None)
                    if video_width is not None:
                        cmds.setAttr((clipNode + ".wResolution"),
                                     int(video_width))

                    cmds.shot(clipNode, e=1, clip=file_info["pathurl"])

                    cmds.setAttr((clipNode + ".clipDuration"), frameCount)
                    cmds.setAttr((clipNode + ".clipValid"), 1)
                    cmds.setAttr((clipNode + ".clipScale"),
                                 1)  #FCP Speed Effect not supported yet

                else:
                    try:
                        cmds.sound(clipNode, e=1, file=file_info["pathurl"])
                    except:
                        self.translator.logger.warning(
                            "Could not open audio file %s. File not found, or audio format not supported"
                            % file_info["pathurl"])
        self.clip_dict[clip] = clipNode
        return clipNode
Esempio n. 12
0
def camSeqRenderAll(deleteBakedCam=True):
    '''
    render all shots in sequence manager.
    '''
    #path variables
    userShotDir = os.getenv("USER_SHOT_DIR")
    fileRuleImages = mc.workspace("images", fre=True, q=True)[3:]
    renderGlobalPath = os.path.join(userShotDir, fileRuleImages)
    renderTempPath = os.path.join(renderGlobalPath, "tmp")

    #setup output path
    currentFile = mc.file(q=True, sn=True).split("/")[-1]
    fileName = os.path.splitext(currentFile)[0]
    outputDir = os.path.join(renderGlobalPath, fileName)

    #if shot render already exists. stop the render
    if os.path.exists(outputDir):
        mc.warning("output directory already exist. render canceled.")
        return
    else:
        pass

    #query render settings
    #todo
    #check if active panel is
    allMdPanel = mc.getPanel(type="modelPanel")
    activePanel = mc.getPanel(wf=True)
    if activePanel not in allMdPanel:
        mc.warning("please select the view you want to render.")
        return

    #create shot output dir
    try:
        #create dir
        callString = "mkdir " + outputDir
        mycmd = subprocess.Popen(callString,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 shell=True)
        output, error = mycmd.communicate()
    except:
        print error

    #delete current tmp if found
    #for my local hacking rendering only ...
    if os.path.exists(renderTempPath):
        try:
            print "deleting current tmp dir: ", renderTempPath
            callString = "rm -rf " + renderTempPath
            mycmd = subprocess.Popen(callString,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE,
                                     shell=True)
            output, error = mycmd.communicate()
        except:
            print error
    else:
        print "no temp dir found."

    #get all shots in sequence
    allshots = mc.sequenceManager(lsh=True)

    renderedShots = []
    #playblast each shot
    for s in allshots:

        deleteCam = False

        #shot render cam vars
        renderCam = mc.shot(s, cc=True, q=True)
        startTime = math.floor(mc.shot(s, st=True, q=True))
        endTime = math.floor(mc.shot(s, et=True, q=True))

        #shot sequence vars
        seq_startTime = math.floor(mc.shot(s, sst=True, q=True))
        seq_endTime = math.floor(mc.shot(s, set=True, q=True))
        seq_duration = mc.shot(s, sequenceDuration=True, q=True)
        seq_scale = mc.shot(s, scale=True, q=True)
        offsetTime = int(seq_startTime - startTime)

        #setup render time
        renderStartFrame = startTime
        renderEndFrame = startTime + seq_duration - 1

        print s, startTime, endTime, "(", seq_startTime, seq_endTime, ")", renderCam, seq_duration

        if seq_scale != 1.0:
            print "sequnce scale is not uniform. baking camera animation for endering."
            renderCam = bakeSequenceScale(s)
            deleteCam = True

        print "start rendering: ", renderCam

        #set current panel to the current shot cam
        mel.eval("lookThroughModelPanel %s %s;" % (renderCam, activePanel))

        #initialize render! note this will render out an image!
        mel.eval('currentTime %s ;' % (renderStartFrame))
        mel.eval('RenderIntoNewWindow;')

        #close render view
        mel.eval('removeRenderWindowPanel renderView;')

        #do the render
        mel.eval('currentTime %s ;' % (renderStartFrame))
        while (renderStartFrame <= renderEndFrame):
            mel.eval('renderWindowRender redoPreviousRender renderView;')
            renderStartFrame += 1
            mel.eval('currentTime %s ;' % (renderStartFrame))

        #remove render camera
        if deleteBakedCam and deleteCam:
            print "deleting camera: ", renderCam
            mc.delete(renderCam)

        #File Operations
        #rename and move shot renders
        shotDirName = s + "_" + str(offsetTime)
        shotDir = os.path.join(renderGlobalPath, shotDirName)

        #TODO: handle this better
        #if there is a same found. this will move the tmp into it instead of rename tmp.
        #for now just remove the old one assume it's from a preveus failed render
        if os.path.exists(shotDir):
            print "found " + shotDir + "removing it..."
            callString = "rm -rf " + shotDir
            mycmd = subprocess.Popen(callString,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE,
                                     shell=True)
            output, error = mycmd.communicate()
        else:
            pass

        #rename the tmp dir to the shot name
        callString = "mv " + renderTempPath + " " + shotDir
        mycmd = subprocess.Popen(callString,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 shell=True)
        output, error = mycmd.communicate()

        #move into output dir
        callString = "mv " + shotDir + " " + outputDir
        mycmd = subprocess.Popen(callString,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 shell=True)
        output, error = mycmd.communicate()

    #write nuke comp
    makeSeqComp(elementsDir=outputDir)

    #display result
    mc.confirmDialog(title='render finished: ',
                     message=outputDir,
                     button=['OK'],
                     defaultButton='OK')

    #done.
    mc.warning(
        "all shots submited for render, Check script editer for more detail.")
Esempio n. 13
0
import maya.cmds as cmds

#get list of shots from camera sequencer
shotList = cmds.sequenceManager(lsh=True)
print(shotList)
previousCameras = []
aimConstraintNum = 1
leftConstrainList = []
rightConstrainList = []

for x in shotList:
    #get camera for the current shot
    currentShot = str(x)
    currentCamera = cmds.shot(currentShot, q=True, currentCamera=True)
    if currentCamera.endswith('Shape'):
        currentCamera = currentCamera[:-5]

    #if not already used, set up locator and parent constraint system for the camera
    if currentCamera not in previousCameras:
        #Now is a previous camera so this doesn't get done twice
        previousCameras.append(currentCamera)

        #Put a locator in the same position as the camera and directly parent it in
        cameraPosition = cmds.camera(currentCamera, q=True, position=True)
        locator = cmds.spaceLocator(name=currentCamera + "_locator",
                                    position=cameraPosition)
        cmds.parent(locator, currentCamera)

        #Create aim constraints between the new locator and the eye controls
        cmds.aimConstraint(locator, "seq005_LUExport:LU:LEye_ctrlgrp")
        cmds.aimConstraint(locator, "seq005_LUExport:LU:REye_ctrlgrp")
Esempio n. 14
0
def set_first_frame(shotName):
    st = mc.getAttr('%s.startFrame' %(shotName))
    mc.currentTime(st)
    mc.sequenceManager(currentTime=st)
Esempio n. 15
0
def get_current_shot():
    return mc.sequenceManager(q=True,currentShot=True)