예제 #1
0
def getFocalParameters(lensTmp):
    # get the captor size
    fbxTmp = tde4.getLensFBackWidth(lensTmp)
    fbyTmp = tde4.getLensFBackHeight(lensTmp)

    # get lensTmp Parameters
    folcalParameter = dict()
    folcalParameter["filmW"] = fbxTmp
    folcalParameter["filmH"] = fbyTmp
    folcalParameter["focalLength"] = tde4.getLensFocalLength(lensTmp)
    folcalParameter["pixelAspect"] = tde4.getLensPixelAspect(lensTmp)  #TODO

    log.debug(folcalParameter)

    return folcalParameter
예제 #2
0
def buildUICamera(req, cameraIndex, cameraTmp):
    imageHeightOuttmp, imageWidthOuttmp = getOutSize(req, cameraIndex,
                                                     cameraTmp)

    nametmp = "exportCamera" + str(cameraIndex)
    texttmp = "Export Camera " + str(tde4.getCameraName(cameraTmp))
    tde4.addToggleWidget(req, nametmp, texttmp, 1)
    tde4.setWidgetCallbackFunction(req, nametmp, "callBackExportCamera")

    firstFrame = tde4.getCameraSequenceAttr(cameraTmp)[0]

    strRes = camWidgetFormat.format(imageWidth=str(imageWidthOuttmp),
                                    sep=resSpliter,
                                    imageHeight=str(imageHeightOuttmp),
                                    firstFrame=firstFrame)

    camResWidgetName = camWidgetPrefix + str(cameraIndex)
    log.debug('camResWidgetName (creation): ' + camResWidgetName)

    tde4.addTextFieldWidget(req, camResWidgetName, camResWidgetText, strRes)

    tde4.addSeparatorWidget(req, "sep" + str(cameraIndex))
예제 #3
0
def getOutSize(req, cameraIndex, cameraTmp):
    # get the actual image size from cameraTmp
    imageHeightInTmp = tde4.getCameraImageHeight(cameraTmp)
    imageWidthInTmp = tde4.getCameraImageWidth(cameraTmp)

    lensTmp = tde4.getCameraLens(cameraTmp)

    folcalParameter = getFocalParameters(lensTmp)

    # distorsionMode
    dyndistmode = tde4.getLensDynamicDistortionMode(lensTmp)

    log.debug('dyndistmode : ' + str(dyndistmode))

    if dyndistmode == "DISTORTION_STATIC":
        lensModelParameter = getLensModelParameter(camera=None,
                                                   lens=lensTmp,
                                                   frame=None)
        resOutTmp = get_bounding_box.calculateBoundigBox(
            imageWidthInTmp, imageHeightInTmp, "undistort", folcalParameter,
            lensModelParameter)
        imageWidthOuttmp = resOutTmp.width
        imageHeightOuttmp = resOutTmp.height
    else:
        imageHeightOuttmp = imageHeightInTmp
        imageWidthOuttmp = imageWidthInTmp
        for frame in range(1, tde4.getCameraNoFrames(cameraTmp) + 1):
            lensModelParameter = getLensModelParameter(camera=cameraTmp,
                                                       lens=lensTmp,
                                                       frame=frame)
            resOuttmp = get_bounding_box.calculateBoundigBox(
                imageWidthInTmp, imageHeightInTmp, "undistort",
                folcalParameter, lensModelParameter)
            if imageHeightOuttmp < resOuttmp.height:
                imageHeightOuttmp = resOuttmp.height
            if imageWidthOuttmp < resOuttmp.width:
                imageWidthOuttmp = resOuttmp.width

    if imageHeightInTmp > imageHeightOuttmp:
        imageHeightOuttmp = imageHeightInTmp
    if imageWidthInTmp > imageWidthOuttmp:
        imageWidthOuttmp = imageWidthInTmp

    log.debug('****************** lensModelParameter ********************')
    for key in lensModelParameter.keys():
        log.debug(key + ' : ' + str(lensModelParameter.get(key)))

    return imageHeightOuttmp, imageWidthOuttmp
예제 #4
0
def exportNOID():
    # print 'Start exportNOID'
    req = buildUI()
    ret = tde4.postCustomRequester(req, "Export NOID - (Maya & Nuke)", 0, 0,
                                   "Export", "Cancel")

    if ret == 1:  # Canceled by the user
        # get the parameters selecteds
        params = {}
        params['file_browser'] = tde4.getWidgetValue(req, "file_browser")
        #params['nukeVersion'] = tde4.getWidgetValue(req, "nukeVersion")
        #params['openNuke'] = tde4.getWidgetValue(req, "openNuke")

        params['cameras'] = []
        params['camerasOutSize'] = []
        params['camerasFirstFrame'] = list()

        date = strftime("%y%m%d%H%M%S", gmtime())  # YYMMDDhhmmss
        params['date'] = date

        for cameraIndex in range(tde4.getNoCameras()):
            cameraObj = tde4.getIndexCamera(cameraIndex)
            # cameraName = str(tde4.getCameraName(cameraObj)) # NO USED
            exprtCamWidgetName = "exportCamera" + str(cameraIndex)

            exprtCamWidgetExists = tde4.widgetExists(req, exprtCamWidgetName)
            exprtCamWidgetValue = tde4.getWidgetValue(req, exprtCamWidgetName)

            if exprtCamWidgetExists and exprtCamWidgetValue:

                camResWidgetName = camWidgetPrefix + str(cameraIndex)
                log.debug('camResWidgetName : ' + str(camResWidgetName))
                camResWidgetValue = tde4.getWidgetValue(req, camResWidgetName)

                log.debug('camResWidgetValue: ' + str(camResWidgetValue))

                imageWidth, imageHeight, firstFrame = camResWidgetValue.split(
                    resSpliter)

                imageResolution = tools.Resolution(width=imageWidth,
                                                   height=imageHeight)

                params['cameras'].append(cameraObj)
                params['camerasOutSize'].append(imageResolution)
                params['camerasFirstFrame'].append(firstFrame)

                log.debug('imageResolution : ' + str(imageResolution))

        if params['cameras'] == []:
            message = 'Aborting, Nothing selected to Export'
            log.debug(message)
            return

        # debug params
        for paramName in params:
            paramValue = params[paramName]
            log.debug('param : ' + str(paramName))
            log.debug('value : ' + str(paramValue))

        # Export to Maya
        mayaExporter.toMaya(params)

        # Export to Nuke
        nukeFilesPath = nukeExporter.toNuke(params)

        # open Nuke or not
        #        if params['openNuke']:
        #            for nukeFilePath in nukeFilesPath:
        #                nukeExePath = findNukeExe(int(params['nukeVersion']))
        #                toExecute = [nukeExePath, '-q', nukeFilePath]
        #
        #                log.debug(toExecute)
        #
        #                useSubProcess = True
        #                if useSubProcess:
        #                    subprocess.Popen(toExecute, executable=nukeExePath)
        #                else:
        #                    os.system(toExecute)

        tde4.postQuestionRequester('Export finished',
                                   'All the cameras selected were exported',
                                   'OK')
    else:
        message = 'Canceled by user'
        log.debug(message)

    message = 'End exportCGEV'
    log.debug(message)
예제 #5
0
def toNuke(params, oneFile=False):
    log.debug('To Nuke - Start')

    cameras = params['cameras']
    camerasOutSize = params['camerasOutSize']
    camerasFrameStart = params['camerasFirstFrame']

    filesGenerated = []
    argsToBatchs = []

    if oneFile:
        filepath = params['file_browser'] + '_undisto.nk'
        tools.ensure_dir(filepath)
        fileObj = open(filepath, 'w')
        for index, cam in enumerate(cameras):
            fileLines = []
            argsExportNuke = [
                cam, index, camerasOutSize[index], filepath, params['date'],
                camerasFrameStart[index]
            ]

            fileLines, argsToBatch = exportNuke(*argsExportNuke)

            if fileLines == -1:
                # print ("Problem with camera "+ str(cam) )
                continue

            writeLines(fileObj, fileLines)
            argsToBatchs.append(argsToBatch)
        filesGenerated.append(filepath)

    else:
        # create Directory
        folderCameras = params['file_browser'] + '_undisto/'
        try:
            os.makedirs(folderCameras)
        except:
            pass  # Todo check if is only that the folder exists

        for index, cam in enumerate(cameras):
            cameraName = "%s_%s_1" % (tools.validName(
                tde4.getCameraName(cam)), index)
            filepath = folderCameras + cameraName + '_undisto.nk'
            tools.ensure_dir(filepath)
            fileObj = open(filepath, 'w')
            fileLines = []
            argsExportNuke = [
                cam, index, camerasOutSize[index], filepath, params['date'],
                camerasFrameStart[index]
            ]

            fileLines, argsToBatch = exportNuke(*argsExportNuke)

            if fileLines == -1:
                # print ("Problem with camera "+ str(cam) )
                continue

            writeLines(fileObj, fileLines)
            argsToBatchs.append(argsToBatch)
            filesGenerated.append(filepath)

    # Launch batch Render
    log.debug('Launching batch Render')

    import toBatch
    for argsToBatch in argsToBatchs:
        toBatch.batch3DE(*(argsToBatch))
    return filesGenerated

    log.debug('To Nuke - End')
예제 #6
0
def exportNuke(cam, index, size, filepath, date, frameStart):
    # print 'Nuke ',nukeVersion,' version'
    offsetXNodes = str(index * 400)

    camInfo = tools.TDECamInfo(cam, index)
    camShortName = camInfo.getShortName()
    readFilePath = camInfo.cameraPath
    projectName = camInfo.projectName
    projectPath = camInfo.projectPath
    imagesName = camInfo.imagesName
    shot = camInfo.shot

    rez_x = camInfo.rez_x  # width
    rez_y = camInfo.rez_y  # height

    firstFrame = camInfo.firstFrame
    lastFrame = camInfo.lastFrame
    offset = int(frameStart) - 1

    if camInfo.lens is None:
        return -1

    lensInfo = tools.TDELensInfo(camInfo.lens)
    p_aspect = lensInfo.p_aspect

    readFormat = fmatNameBase.format(rX=str(rez_x),
                                     rY=str(rez_y),
                                     pAspect=str(p_aspect),
                                     projName=str(projectName))

    undistoGroupName = 'UNDISTO'

    if camInfo.isSeq():
        undistoGroupLabel = '"' + projectName + '\\n' + imagesName + '"'
    else:
        undistoGroupLabel = '"Reference frame\\n' + camShortName + '"'
    '''
    projectConfig = newconfig.ProjectCFile(projectName,
                                           projectPath,
                                           checkConfigured=False)

    # Working on OCIO prod
    if projectConfig.isOCIO():
        cspaceInName = 'Workingspace_to_LogC'
        cspaceOutName = 'LogC_to_Workingspace'
        OCIOConfig = projectConfig.getOCIOConfig()

        if readFilePath.endswith('.exr'):
            readColorSpace = OCIOConfig['floatLut']
        elif readFilePath.endswith('.dpx'):
            readColorSpace = OCIOConfig['logLut']
        else:
            readColorSpace = OCIOConfig['int8Lut']

        readColorSpace = OCIOConfig['floatLut']
        colorspaceInLine = 'in_colorspace ' + OCIOConfig['workingSpaceLut']
        colorspaceInLine += '\n  out_colorspace ' + OCIOConfig['logLut']

    # Working on normal prod
    else:
        cspaceInName = 'Lin_to_Log'
        cspaceOutName = 'Log_to_Lin'

        if readFilePath.endswith('.exr'):
            readColorSpace = 'linear'
        elif readFilePath.endswith('.dpx'):
            readColorSpace = getdata.getRootColorSpace(projectName)
        else:
            readColorSpace = 'sRGB'

        colorspaceInLine = 'out_colorspace ' + readColorSpace
    '''

    cspaceInName = 'Lin_to_Log'
    cspaceOutName = 'Log_to_Lin'
    readColorSpace = 'sRGB'
    colorspaceInLine = 'out_colorspace ' + readColorSpace

    log.debug("rez_x : " + str(rez_x))
    log.debug("rez_y : " + str(rez_y))
    log.debug("size width : " + str(size.width))
    log.debug("size height : " + str(size.height))

    undistoW = str(max(int(rez_x), int(size.width)))
    undistoH = str(max(int(rez_y), int(size.height)))

    Reformat_REZ_UNDISTO_Format = fundNameBase.format(rX=str(undistoW),
                                                      rY=str(undistoH),
                                                      pAspect=str(p_aspect),
                                                      projName=projectName,
                                                      imagesName=imagesName)

    writeNodeFile = camInfo.getUndistoImagePath(app='nuke', date=date)
    writeNodeName = camInfo.getWriteNodeName()

    Reformat_BASE_REZ_Format = readFormat
    Reformat_BASE_BOX_Format = readFormat

    redistoGroupName = 'REDISTO'
    redistoGroupLabel = undistoGroupLabel

    # check if there is or not disto
    # distortion = tools.cameraHasDistortion(cam)

    # Compose File Lines
    # Root
    rootString = [
        'Root { ',
        ' inputs 0',
        ' frame ' + firstFrame,
        ' first_frame ' + firstFrame,
        ' last_frame ' + lastFrame,
        ' lock_range true',
        '}',
    ]
    # Read
    readString = [
        'Read {',
        ' inputs 0',
        ' file ' + readFilePath,
        ' format ' + readFormat,
        ' first ' + firstFrame,
        ' last ' + lastFrame,
        ' colorspace ' + readColorSpace,
        ' name Master',
        ' xpos ' + offsetXNodes,
        ' ypos 0',
        '}',
    ]
    # Group UNDISTO
    LDNodeName = getLDNodeName(cam, "undistort", offset, index=0)
    undistroGroupString = [
        'Group {',
        ' name ' + undistoGroupName,
        ' label ' + undistoGroupLabel,
        ' xpos ' + offsetXNodes,
        ' ypos 150',
        ' knobChanged "\nif nuke.thisKnob().name().endswith(\'_solo\') and nuke.thisKnob().value() is True:\n    for knob in \[knob for knob in nuke.thisNode().knobs().values() if knob != nuke.thisKnob() and knob.name().endswith(\'_solo\')]:\n        knob.setValue(False)\n"',
        ' addUserKnob {20 User l UNDISTO}',
        ' addUserKnob {41 out_colorspace l "@b; ColorSpace" T ' +
        cspaceInName + '.out_colorspace}',
        ' addUserKnob {26 S01 l " "}',
        ' addUserKnob {41 filter_LD l "@b; Filter" T ' + LDNodeName +
        '.filter}',
        ' addUserKnob {26 S02 l " "}',
        ' addUserKnob {26 Clamp l "@b; Clamp" T " "}',
        ' addUserKnob {41 minimum l min T Clamp2.minimum}',
        ' addUserKnob {41 minimum_enable l enable -STARTLINE T Clamp2.minimum_enable}',
        ' addUserKnob {41 maximum l max T Clamp2.maximum}',
        ' addUserKnob {41 maximum_enable l enable -STARTLINE T Clamp2.maximum_enable}',
        ' addUserKnob {26 S03 l " "}',
        ' addUserKnob {26 bbox l "@b; Bounding Box" T " "}',
        ' addUserKnob {6 bbox_input_solo l "Preserve Input" +STARTLINE}',
        ' bbox_input_solo true',
        ' addUserKnob {6 bbox_crop_solo l "Crop to Format" +STARTLINE}',
        ' addUserKnob {6 bbox_addpixel_solo l "Add Pixels              " +STARTLINE}',
        ' addUserKnob {41 numpixels l "" -STARTLINE T AdjBBox1.numpixels}',
        ' addUserKnob {26 by1 l " " T " "}',
        ' addUserKnob {26 by2 l " " T "                                                                                               "}',
        ' addUserKnob {26 CGEV l " " t "\nEn cas de probleme, contacter Gaetan Baldy sur le chat\n" -STARTLINE T "<font color=\\"#1C1C1C\\"> v02 - CGEV - 2016"}',
        '}',
        ' Input {',
        '  inputs 0',
        '  name Input1',
        '  xpos ' + offsetXNodes,
        '  ypos 0',
        ' }',
        ' Clamp {',
        '  maximum 10',
        '  name Clamp2',
        '  xpos ' + offsetXNodes,
        '  ypos 40',
        ' }',
        ' Clamp {',
        '  channels alpha',
        '  name Clamp1',
        '  xpos ' + offsetXNodes,
        '  ypos 80',
        ' }',
        ' OCIOColorSpace {',
        '  ' + colorspaceInLine,
        '  name ' + cspaceInName,
        '  xpos ' + offsetXNodes,
        '  ypos 120',
        ' }',
    ]

    undistroGroupString.extend(
        generateNukeNode(cam, "undistort", offset, index=0))

    undistroGroupString.extend([
        ' Reformat {',
        '  format ' + Reformat_REZ_UNDISTO_Format,
        '  resize none',
        '  filter {{input0.filter}}',
        '  clamp false',
        '  pbb {{parent.bbox_input_solo}}',
        '  name Reformat_REZ_UNDISTO',
        '  xpos ' + offsetXNodes,
        '  ypos 160',
        ' }',
        ' AdjBBox {',
        '  numpixels {100 100}',
        '  name AdjBBox1',
        '    label ADD_PIXELS',
        '  xpos ' + offsetXNodes,
        '  ypos 200',
        '  disable {{!parent.bbox_addpixel_solo}}',
        ' }',
        ' OCIOColorSpace {',
        '  in_colorspace {{' + cspaceInName + '.out_colorspace}}',
        '  out_colorspace {{' + cspaceInName + '.in_colorspace}}',
        '  name ' + cspaceOutName,
        '  xpos ' + offsetXNodes,
        '  ypos 240',
        ' }',
        ' Clamp {',
        '  minimum {{parent.Clamp2.minimum}}',
        '  minimum_enable {{parent.Clamp2.minimum_enable}}',
        '  maximum {{parent.Clamp2.maximum}}',
        '  maximum_enable {{parent.Clamp2.maximum_enable}}',
        '  name Clamp3',
        '  xpos ' + offsetXNodes,
        '  ypos 280',
        ' }',
        ' Clamp {',
        '  channels alpha',
        '  minimum {{parent.Clamp1.minimum}}',
        '  maximum {{parent.Clamp1.maximum}}',
        '  name Clamp4',
        '  xpos ' + offsetXNodes,
        '  ypos 320',
        ' }',
        ' Output {',
        '  name Output1',
        '  xpos ' + offsetXNodes,
        '  ypos 360',
        ' }',
        'end_group',
    ])
    # node Write
    writeNodeString = [
        'Write {',
        ' inputs 1',
        ' file ' + writeNodeFile,
        ' file_type jpeg',
        ' checkHashOnRead false',
        ' name ' + writeNodeName,
        ' xpos ' + str(200 + 400 * index),
        ' ypos 156',
        '}',
    ]
    # Group REDISTO
    LDNodeName = getLDNodeName(cam, "distort", offset, index)
    redistroGroupString = [
        'Group {',
        ' inputs 0',
        ' name ' + redistoGroupName,
        ' label ' + redistoGroupLabel,
        ' xpos ' + offsetXNodes,
        ' ypos 250',
        ' knobChanged "\nif nuke.thisKnob().name().endswith(\'_solo\') and nuke.thisKnob().value()  == True:\n    for knob in \[knob for knob in nuke.thisNode().knobs().values() if knob != nuke.thisKnob() and knob.name().endswith(\'_solo\')]:\n        knob.setValue(False)\n"',
        ' addUserKnob {20 User l REDISTO}',
        ' addUserKnob {41 out_colorspace l "@b; ColorSpace" T ' +
        cspaceInName + '.out_colorspace}',
        ' addUserKnob {26 S01 l " "}',
        ' addUserKnob {41 filter_LD l "@b; Filter" T ' + LDNodeName +
        '.filter}',
        ' addUserKnob {26 S02 l " "}',
        ' addUserKnob {26 Clamp l "@b; Clamp" T " "}',
        ' addUserKnob {41 minimum l min T Clamp2.minimum}',
        ' addUserKnob {41 minimum_enable l enable -STARTLINE T Clamp2.minimum_enable}',
        ' addUserKnob {41 maximum l max T Clamp2.maximum}',
        ' addUserKnob {41 maximum_enable l enable -STARTLINE T Clamp2.maximum_enable}',
        ' addUserKnob {26 S03 l " "}',
        ' addUserKnob {26 bbox l "@b; Bounding Box" T " "}',
        ' addUserKnob {6 bbox_input_solo l "Preserve Input" +STARTLINE}',
        ' bbox_input_solo true',
        ' addUserKnob {6 bbox_crop_solo l "Crop to Format" +STARTLINE}',
        ' addUserKnob {26 by2 l " " T "                                                                                               "}',
        ' addUserKnob {26 CGEV l " " t "\nEn cas de probleme, contacter Gaetan Baldy sur le chat\n" -STARTLINE T "<font color=\\"#1C1C1C\\"> v02 - CGEV - 2016"}',
        '}',
        ' Input {',
        '  inputs 0',
        '  name Input1',
        '  xpos ' + offsetXNodes,
        '  ypos 0',
        ' }',
        ' Clamp {',
        '  maximum 10',
        '  name Clamp2',
        '  xpos ' + offsetXNodes,
        '  ypos 40',
        ' }',
        ' Clamp {',
        '  channels alpha',
        '  name Clamp1',
        '  xpos ' + offsetXNodes,
        '  ypos 80',
        ' }',
        ' OCIOColorSpace {',
        '  ' + colorspaceInLine,
        '  name ' + cspaceInName,
        '  xpos ' + offsetXNodes,
        '  ypos 120',
        ' }',
        ' Reformat {',
        '  format ' + Reformat_BASE_REZ_Format,
        '  resize none',
        '  filter {{' + LDNodeName + '.filter}}',
        '  clamp false',
        '  pbb true',
        '  name Reformat_BASE_REZ',
        '  xpos ' + offsetXNodes,
        '  ypos 160',
        ' }',
    ]

    redistroGroupString.extend(generateNukeNode(cam, "distort", offset, index))

    redistroGroupString.extend([
        ' Reformat {',
        '  format ' + Reformat_BASE_BOX_Format,
        '  resize none',
        '  filter {{' + LDNodeName + '.filter}}',
        '  pbb {{!parent.bbox_crop_solo}}',
        '  name Reformat_BASE_BOX',
        '  xpos ' + offsetXNodes,
        '  ypos 200',
        '  clamp {{Reformat_BASE_REZ.clamp}}'
        ' }',
        ' OCIOColorSpace {',
        '  in_colorspace {{' + cspaceInName + '.out_colorspace}}',
        '  out_colorspace {{' + cspaceInName + '.in_colorspace}}',
        '  name ' + cspaceOutName,
        '  xpos ' + offsetXNodes,
        '  ypos 240',
        ' }',
        ' Clamp {',
        '  minimum {{parent.Clamp2.minimum}}',
        '  minimum_enable {{parent.Clamp2.minimum_enable}}',
        '  maximum {{parent.Clamp2.maximum}}',
        '  maximum_enable {{parent.Clamp2.maximum_enable}}',
        '  name Clamp3',
        '  xpos ' + offsetXNodes,
        '  ypos 280',
        ' }',
        ' Clamp {',
        '  channels alpha',
        '  minimum {{parent.Clamp1.minimum}}',
        '  maximum {{parent.Clamp1.maximum}}',
        '  name Clamp4',
        '  xpos ' + offsetXNodes,
        '  ypos 320',
        ' }',
        ' Output {',
        '  name Output1',
        '  xpos ' + offsetXNodes,
        '  ypos 360',
        ' }',
        'end_group',
    ])

    allstring = rootString + readString + undistroGroupString +\
        writeNodeString + redistroGroupString

    argsToBatch = [
        filepath, writeNodeFile, firstFrame, lastFrame, writeNodeName, 1
    ]

    return allstring, argsToBatch