예제 #1
0
 def _revert_scene_fn(*args, **kwargs):
     _cur_file = host.cur_scene()
     _tmp_file = abs_path('{}/_psyhive_tmp.mb'.format(
         tempfile.gettempdir()))
     host.save_as(_tmp_file, force=True)
     _result = func(*args, **kwargs)
     host.open_scene(_tmp_file, force=True)
     if _cur_file:
         cmds.file(rename=_cur_file)
     return _result
예제 #2
0
    def save_inc(self, comment, safe=True):
        """Save increment file.

        Args:
            comment (str): comment
            safe (bool): error if we are saving over an existing scene file
                without incrementing
        """
        _fileops = find_tank_app('psy-multi-fileops')

        if not host.cur_scene() == self.path:
            if safe:
                print 'CUR', host.cur_scene()
                print 'TRG', self.path
                raise ValueError
            host.save_as(self.path, revert_filename=False)
            _fileops.init_app()

        _fileops.save_increment_file(comment=comment)
예제 #3
0
def build_aistandin_output(output):
    """Build aiStandIn ma file output.

    Args:
        output (str): path to aiStandIn output

    Returns:
        (str): path to output file
    """
    print 'BUILD aiStandIn MA', output

    # Get paths for standin + rest cache + shade
    _out = tk2.TTOutput(output)
    assert _out.format == 'aistandin'
    _standin = _out.map_to(tk2.TTOutputFile, extension='ma')
    print ' - STANDIN', _standin
    assert _standin.extn == 'ma'
    _ver = tk2.TTOutputVersion(output)
    print ' - VER', _ver
    _rest_cache = get_single(_ver.find(extn='abc', filter_='restCache'))
    print ' - REST CACHE', _rest_cache
    _shade = _ver.find_file(extn='mb', format_='maya')
    print ' - SHADE', _shade
    assert not _shade == _out.path

    # Build aiStandIn node
    dprint('OPENING SHADE SCENE')
    host.open_scene(_shade.path, force=True)
    build_aistandin_from_shade(archive=_rest_cache,
                               shade=_ShadeScene(),
                               animated=False,
                               name='AIS',
                               deferred=False)

    # Strip out scene
    cmds.delete('GEO')

    host.save_as(file_=_standin.path, force=True)

    return _standin.path
예제 #4
0
def build_shader_outputs(output, force=True, verbose=1):
    """Build shader outputs for the given shade asset.

    This consists of:

        - mb file containing just shaders for this asset
        - yml file containing list of shaders
        - standin file containing shaders attached to aiStandIn node

    Args:
        output (str): path to aiStandIn output
        force (bool): overrwrite existing files without confirmation
        verbose (int): print process data

    Returns:
        (str): path to output file
    """
    lprint('BUILD aiStandIn MA', output, verbose=verbose)

    # Get paths for standin + rest cache + shade
    _out = tk2.TTOutput(output)
    _shaders = _out.map_to(tk2.TTOutputFile, format='shaders', extension='mb')
    _yml = _out.map_to(tk2.TTOutputFile, format='shaders', extension='yml')
    _standin = _out.map_to(tk2.TTOutputFile,
                           format='aistandin',
                           extension='ma')
    _ver = tk2.TTOutputVersion(output)
    _rest_cache = get_single(_ver.find(extn='abc', filter_='restCache'),
                             catch=True)
    _shade = _ver.find_file(extn='mb', format_='maya')
    lprint(' - VER       ', _ver.path, verbose=verbose)
    lprint(' - SHADE     ', _shade.path, verbose=verbose)
    lprint(' - REST CACHE', _rest_cache, verbose=verbose)
    lprint(' - STANDIN   ', _standin.path, verbose=verbose)
    lprint(' - SHADERS   ', _shaders.path, verbose=verbose)
    assert not _shade == _out.path

    # Build aiStandIn node
    lprint(' - OPENING SHADE SCENE', verbose=verbose)
    host.open_scene(_shade.path, force=True)
    build_aistandin_from_shade(archive=_rest_cache,
                               shade=_ShadeScene(),
                               animated=False,
                               name='AIS',
                               deferred=False)

    # Remove + save aistandin
    cmds.delete('GEO')
    host.save_as(file_=_standin.path, force=force)

    # Remove standin + save shaders
    if cmds.objExists('AIS'):
        cmds.delete('AIS')
    _ses = [
        str(_se) for _se in cmds.ls(type='shadingEngine')
        if _se not in DEFAULT_NODES
    ]
    lprint(" - SHADING ENGINES", _ses, verbose=verbose)
    host.save_as(_shaders.path, force=force)
    write_yaml(file_=_yml.path, data=_ses, force=True)

    return _standin.path
예제 #5
0
def _build_bad_scene(force=True):

    _root = pipe.TMP+'/psyhive/remote_scene_check'

    # Built test refs
    _cube_mb = File('{}/cube.mb'.format(_root))
    if not _cube_mb.exists():
        print 'CREATING', _cube_mb
        cmds.polyCube()
        host.save_as(_cube_mb, export_selection=True)
    _deep_cube_mb = File('{}/dir/deep_cube.mb'.format(_root))
    if not _deep_cube_mb.exists():
        print 'CREATING', _deep_cube_mb
        cmds.polyCube()
        host.save_as(_deep_cube_mb, export_selection=True)
    _2_cube_mb = File('{}/2cube.mb'.format(_root))
    if not _2_cube_mb.exists():
        print 'CREATING', _cube_mb
        cmds.select([cmds.polyCube()[0] for _ in range(2)])
        host.save_as(_2_cube_mb, export_selection=True)
    _asset_cube_mb = File('{}/dir/cube_rig_v001.mb'.format(_root))
    if not _asset_cube_mb.exists():
        print 'CREATING', _asset_cube_mb
        cmds.polyCube()
        host.save_as(_asset_cube_mb, export_selection=True)
    _psy_asset_cube_mb = File('{}/dir/cube_rig_main_v001.mb'.format(_root))
    if not _psy_asset_cube_mb.exists():
        print 'CREATING', _psy_asset_cube_mb
        cmds.polyCube()
        host.save_as(_psy_asset_cube_mb, export_selection=True)

    # Build scene
    host.new_scene(force=force)

    _ref = ref.create_ref(_cube_mb, namespace='bad_namespace')
    _ref.find_top_node().add_to_grp('CHAR')

    # Good ref
    _ref = ref.create_ref(_cube_mb, namespace='cube_1')
    _ref.find_top_node().add_to_grp('CHAR')

    # Good asset ref
    _ref = ref.create_ref(_asset_cube_mb, namespace='cube_2')
    _ref.find_top_node().add_to_grp('CHAR')

    # Good psy asset ref
    _ref = ref.create_ref(_psy_asset_cube_mb, namespace='cube_3')
    _ref.find_top_node().add_to_grp('CHAR')

    # Missing ref
    _ref = ref.create_ref(_deep_cube_mb, namespace='deepRef_7')
    _ref.find_top_node().add_to_grp('CHAR')

    # Multi top node
    _ref = ref.create_ref(_2_cube_mb, namespace='multiTop')
    assert not _ref.find_top_node(catch=True)

    # Without namespace
    hom.CMDS.polyCube().add_to_dlayer('test_LYR')

    # In bad group
    _ref = ref.create_ref(_cube_mb, namespace='badParent')
    _ref.find_top_node().add_to_grp('RANDOM')

    # In junk
    _ref = ref.create_ref(_cube_mb, namespace='junkRef_1')
    _ref.find_top_node().add_to_grp('JUNK')

    # No namespace
    cmds.file(_cube_mb.path, reference=True, renamingPrefix='blah')

    host.save_scene('{}/test2009_animation_v003.mb'.format(_root), force=True)