Exemple #1
0
    def importAnimation(self, scenePath, charactersData):
        '''
        Import character animation for the current render scene: set FileCache nodes paths.

        pathCache = $JOB/geo/SHOTS/010/SHOT_010/ROMA/GEO/001/E010_S010_ROMA_001.$F.bgeo.sc
        :param charactersData: list of characters dics for the current shot
        :param scenePath: Full path to Houdini render scene
        :return:
        '''

        for characterData in charactersData:
            characterName = characterData['code']

            # BUILD CACHE PATH (LATEST VERSION)
            # Build a path to the 001 version of cache

            pathCache = dna.buildFliePath('001',
                                          dna.fileTypes['cacheAnim'],
                                          scenePath=scenePath,
                                          characterName=characterName)

            # Check latest existing version, build new path if exists
            pathCacheFolder = self.convertPathCache(pathCache)
            latestCacheVersion = dna.extractLatestVersionFolder(pathCacheFolder)
            if latestCacheVersion != '001':
                pathCache = dna.buildFliePath(latestCacheVersion,
                                              dna.fileTypes['cacheAnim'],
                                              scenePath=scenePath,
                                              characterName=characterName)

            # SET FILE CACHE NODE PARAM
            # Get cache node
            cache = hou.node('{0}/{1}/CACHE_{2}'.format(sceneRoot, dna.nameChars, characterName))
            # Set path
            cache.parm('file').set(pathCache)
Exemple #2
0
def createFlipbook():
    # Setup flipbook settings
    settings.resolution(dna.resolution)
    settings.frameRange((dna.frameStart, hou.playbar.frameRange()[1]))

    # Build 001 version of flipbook file path
    flipbookPath = dna.buildFliePath('001',
                                     dna.fileTypes['flipbook'],
                                     scenePath=hou.hipFile.path())
    fileLocation = dna.analyzeFliePath(flipbookPath)['fileLocation']

    if not os.path.exists(fileLocation):
        # Write flipbook if not exists
        os.makedirs(fileLocation)
        runFB(flipbookPath)
    else:
        # If 001 file exists get latest version
        latestVersion = dna.extractLatestVersionFolder(fileLocation)
        # Build latest existing path
        flipbookPath = dna.buildFliePath(latestVersion,
                                         dna.fileTypes['flipbook'],
                                         scenePath=hou.hipFile.path())
        # Ask user to save next version or overwrite latest
        win = SNV(flipbookPath)
        win.show()
Exemple #3
0
    def createScene(self, sceneType, catch=None):
        '''
        Save new scene, build scene content.
        :param sceneType: type of created scene, Render, Animation etc
        :param catch: determinate if procedure were run for the firs time from this class,
        or it returns user reply from SNV class
        :return:
        '''

        # Get episode and shot from UI
        episode = self.ui.lin_episode.text()
        shot = self.ui.lin_shot.text()

        # If createRenderScene() runs first time
        if catch == None:

            # Build path to 001 version
            pathScene = dna.buildFliePath(episode, shot, '001', sceneType)

            # Start new Houdini session without saving current
            hou.hipFile.clear(suppress_save_prompt=True)

            # Check if file exists
            if not os.path.exists(pathScene):
                # Save first version if NOT EXISTS
                hou.hipFile.save(pathScene)
                hou.ui.displayMessage('File created:\n{}'.format(
                    pathScene.split('/')[-1]))
                # print '>> First version of file saved!'
            else:
                # If 001 version exists, get latest existing version
                pathScene = dna.buildPathLatestVersion(pathScene)
                # Run Save Next Version dialog if EXISTS
                winSNV = SNV(pathScene, sceneType)
                winSNV.show()
                return

        # If createRenderScene() runs from SNV class: return user choice, OVR or SNV
        elif catch == 'SNV':
            # Save latest version
            newPath = dna.buildPathNextVersion(
                dna.buildPathLatestVersion(
                    dna.buildFliePath(episode, shot, '001', sceneType)))
            hou.hipFile.save(newPath)
            hou.ui.displayMessage('New version saved:\n{}'.format(
                newPath.split('/')[-1]))
        elif catch == 'OVR':
            # Overwrite existing file
            pathScene = dna.buildPathLatestVersion(
                dna.buildFliePath(episode, shot, '001', sceneType))
            hou.hipFile.save(pathScene)
            hou.ui.displayMessage('File overwited:\n{}'.format(
                pathScene.split('/')[-1]))
        else:
            return

        # Build scene content
        self.buildSceneContent(sceneType)
Exemple #4
0
    def buildCharacterLoaders(self, CHARACTERS, charactersData):
        '''
        Create network to load characters data (geo cache, hairs, etc)

        TBD: merge loaders in several chars are in shot
        :param CHARACTERS: Characters container - geometry node object
        :param charactersData: dictionaries with character data linked to a shot
        :return:
        '''

        for characterData in charactersData:
            # Create nodes network for each character
            characterName = characterData['code']
            cache = CHARACTERS.createNode('filecache', 'CACHE_{0}'.format(characterName))
            cache.parm('loadfromdisk').set(1)
            null = CHARACTERS.createNode('null', 'OUT_{0}'.format(characterName))
            null.setInput(0, cache)

            # Build and set path to the 001 cache version
            pathCache = dna.buildFliePath('001',
                                          dna.fileTypes['cacheAnim'],
                                          scenePath=hou.hipFile.path(),
                                          characterName=characterName)

            cache.parm('file').set(pathCache)

            # Set render flags
            null.setDisplayFlag(1)
            null.setRenderFlag(1)


        CHARACTERS.layoutChildren()
Exemple #5
0
def createCacheNetwork():
    '''
    Create output character nodes for exporting cache from animation scene

    :return:
    '''
    renderNode = getRenderNode(CHARACTERS)

    # Create Cache node
    cache = CHARACTERS.createNode('filecache', 'CACHE_{}'.format(characterName))

    # Build path to a file cache
    pathCache = dna.buildFliePath('001',
                                   dna.fileTypes['cacheAnim'],
                                   scenePath=hou.hipFile.path(),
                                   characterName=characterName)

    # Setup FileCacheSOP and other nodes
    cache.parm('file').set(pathCache)
    cache.parm('loadfromdisk').set(1)
    null = CHARACTERS.createNode('null', 'OUT_{}'.format(characterName))
    cache.setInput(0, renderNode)
    null.setInput(0, cache)
    null.setDisplayFlag(1)
    null.setRenderFlag(1)
    CHARACTERS.layoutChildren()
Exemple #6
0
 def SNV(self, filePath):
     # Save NEXT version of flipbook
     fileLocation = dna.analyzeFliePath(filePath)['fileLocation']
     fileName = dna.analyzeFliePath(filePath)['fileName']
     latestVersion = dna.extractLatestVersionFolder(fileLocation)  # '002'
     nextVersion = '{:03d}'.format(int(latestVersion) + 1)
     filePath = dna.buildFliePath(nextVersion,
                                  dna.fileTypes['flipbook'],
                                  scenePath=hou.hipFile.path())
     os.makedirs(dna.analyzeFliePath(filePath)['fileLocation'])
     runFB(filePath)
Exemple #7
0
def buildFBName_(version):
    '''
    Build file name for the flipbook based on scene name
    Expected naming convention for animation and render scenes:
    ANM_E010_S010_001.hip
    RND_E010_S010_001.hip

    param version: string flipbook file version (001)
    '''

    try:
        # Get current scene name
        scenePath = hou.hipFile.path()
        filePathMap = dna.analyzeFliePath(scenePath)
        flipbookPath = dna.buildFliePath(filePathMap['episodeCode'],
                                         filePathMap['shotCode'], version,
                                         dna.fileTypes['flipbook'])

        return flipbookPath

    except:
        hou.ui.displayMessage('Unsupported Current Scene Name!')
Exemple #8
0
def createCacheNetwork():
    '''
    Create output character nodes for exporting cache from animation scene

    :return:
    '''

    # Build path to a file cache
    pathCache = dna.buildFliePath('001',
                                  dna.fileTypes['cacheAnim'],
                                  scenePath=hou.hipFile.path(),
                                  characterName=characterName)

    renderNode = getRenderNode(CHARACTERS)

    # Create trail for Motion Blur
    trail = CHARACTERS.createNode('trail', 'MB_{}'.format(characterName))
    trail.parm('result').set(3)

    # Create Cache node
    cache = CHARACTERS.createNode('filecache',
                                  'CACHE_{}'.format(characterName))
    cache.parm('file').set(pathCache)
    cache.parm('loadfromdisk').set(1)

    # Create OUT null
    null = CHARACTERS.createNode('null', 'OUT_{}'.format(characterName))

    # Link nodes
    trail.setInput(0, renderNode)
    cache.setInput(0, trail)
    null.setInput(0, cache)

    # Layout and set render flag
    null.setDisplayFlag(1)
    null.setRenderFlag(1)
    CHARACTERS.layoutChildren()
Exemple #9
0
    def buildSceneContent(self, fileType, sequenceNumber, shotNumber):
        '''
        Create scene content: import characters, environments, materials etc.
        :param fileType:
        :param sequenceNumber:
        :param shotNumber:
        :return:
        '''

        # Create Render scene
        if fileType == dna.fileTypes['renderScene']:
            # Get shot data
            shotData, assetsData, environmentData, charactersData = dna.getShotGenes(sequenceNumber, shotNumber)

            # Initialize scene
            scenePath = hou.hipFile.path()

            # BUILD ENVIRONMENT
            # Proxy
            ENV_PRX = self.createContainer(sceneRoot, dna.nameEnvProxy)
            self.createHDA(ENV_PRX, environmentData['proxy_hda']['hda_name'], environmentData['proxy_hda']['name'])
            ENV_PRX.setPosition([0, 0])
            # Base
            ENVIRONMENT = self.createContainer(sceneRoot, dna.nameEnv, bbox=2, disp=0)
            self.createHDA(ENVIRONMENT, environmentData['hda_name'], environmentData['code'])
            ENVIRONMENT.setPosition([0, -dna.nodeDistance_y])
            # Animation
            ENV_ANM = self.createContainer(sceneRoot, dna.nameEnvAnim, bbox=2, mb=1)
            self.createHDA(ENV_ANM, environmentData['animation_hda']['hda_name'], environmentData['animation_hda']['name'])
            ENV_ANM.setPosition([0, -2 * dna.nodeDistance_y])

            CROWDS = self.createContainer(sceneRoot, dna.nameCrowds, bbox=2, mb=1)
            self.createHDA(CROWDS, environmentData['crowds_hda']['hda_name'], environmentData['crowds_hda']['name'])
            CROWDS.setPosition([0, -3 * dna.nodeDistance_y])

            # BUILD CHARACTERS
            # Create characters container
            CHARACTERS = self.createContainer(sceneRoot, dna.nameChars, mb=1)
            CHARACTERS.setPosition([0, -4 * dna.nodeDistance_y])

            # Create nodes to pull character caches
            self.buildCharacterLoaders(CHARACTERS, charactersData)

            # IMPORT MATERIALS
            # Create Geometry node in scene root
            ML = sceneRoot.createNode('ml_general', dna.nameMats)
            ML.setPosition([dna.nodeDistance_x, 0])

            # IMPORT ENV LIGHTS
            LIT = sceneRoot.createNode(environmentData['light_hda']['hda_name'], environmentData['light_hda']['name'])
            LIT.setPosition([dna.nodeDistance_x, -dna.nodeDistance_y])

            # SETUP OUTPUT
            # Create mantra render node
            mantra = outRoot.createNode('ifd', 'RENDER')

            # Render file version setup
            # renderFile = '$JOB/render/010/SHOT_040/001/E010_S040_001.$F.exr'
            renderFile = dna.buildFliePath('001', dna.fileTypes['renderFile'], scenePath=scenePath)
            fileLocation = dna.analyzeFliePath(renderFile)['fileLocation']
            if not os.path.exists(fileLocation):
                # Make 001 folder
                os.makedirs(fileLocation)
            else:
                # If 001 file exists get latest version
                latestVersion = dna.extractLatestVersionFolder(fileLocation)
                nextVersion = '{:03d}'.format(int(latestVersion) + 1)
                # Build latest existing path
                renderFile = dna.buildFliePath(nextVersion, dna.fileTypes['renderFile'], scenePath=scenePath)
                os.makedirs(dna.analyzeFliePath(renderFile)['fileLocation'])
                # Localize path (add $JOB)
                renderFile = renderFile.replace(dna.root3D, '$JOB')

            # Setup Mantra parameters
            mantra.parm('vm_picture').set(renderFile)
            mantra.parm('camera').set('/obj/E{0}_S{1}'.format(sequenceNumber, shotNumber))
            # Set common parameters from preset
            for param, value in dna.renderSettings['common'].iteritems():
                mantra.parm(param).set(value)
            # Set DRAFT parameters
            for param, value in dna.renderSettings['draft'].iteritems():
                mantra.parm(param).set(value)

            # SETUP SCENE (end frame ...)
            frameEnd = shotData['sg_cut_out']
            hou.playbar.setFrameRange(dna.frameStart, frameEnd)
            hou.playbar.setPlaybackRange(dna.frameStart, frameEnd)

            # IMPORT ANIMATION
            # Import characters caches
            self.importAnimation(scenePath, charactersData)

        # Save scene
        hou.hipFile.save()