示例#1
0
def publish_alembic(*args, **kwargs):
    """ 上传模型abc文件
        args: entity_type, entity_id, attr_id
    """

    _task_id, _output_attr_id = args

    _output_attr_handle = zfused_api.attr.Output(_output_attr_id)
    _file_format = _output_attr_handle.format()
    _suffix = _output_attr_handle.suffix()
    _attr_code = _output_attr_handle.code()

    _task = zfused_api.task.Task(_task_id)
    _production_path = _task.production_path()
    _project_entity_production_path = _task.project_entity().production_path()
    _temp_path = _task.temp_path()
    _file_code = _task.file_code()
    if kwargs.get("fix_version"):
        _file_index = "{:0>4d}".format(_task.last_version_index(0))
    else:
        _file_index = "{:0>4d}".format(_task.last_version_index() + 1)

    _production_file = "{}/{}/{}.{}{}".format(_production_path, _attr_code,
                                              _file_code, _file_index, _suffix)
    _cover_file = "{}/{}/{}{}".format(_production_path, _attr_code, _file_code,
                                      _suffix)
    _publish_file = "{}/{}/{}.{}{}".format(_temp_path, _attr_code, _file_code,
                                           _file_index, _suffix)
    _publish_file_dir = os.path.dirname(_publish_file)
    if not os.path.isdir(_publish_file_dir):
        os.makedirs(_publish_file_dir)
    try:
        # 添加顶点色

        # get rendering group
        _rendering_group = renderinggroup.nodes()
        if _rendering_group:
            _job = "-frameRange 1 1 -attr rendering -stripNamespaces -uvWrite -writeColorSets -writeFaceSets -worldSpace -writeVisibility -writeUVSets -root {} -file {}".format(
                " ".join(_rendering_group), _publish_file)
            cmds.AbcExport(j=[_job])
            transfer.send_file_to_server(_publish_file, _production_file)
            transfer.send_file_to_server(_publish_file, _cover_file)

        # record in file
        _file_info = zfile.get_file_info(_publish_file, _production_file)
        _cover_file_info = zfile.get_file_info(_cover_file, _cover_file)
        zfused_api.task.new_production_file([_file_info, _cover_file_info],
                                            _task_id, _output_attr_id,
                                            int(_file_index))

    except Exception as e:
        logger.error(e)
        return False

    return True
示例#2
0
def publish_file(files, src, dst):
    _file_infos = []
    _texture_files = files
    for _texture_file in _texture_files:
        #  backup texture file
        # _extend_file = _texture_file.split(src)[-1]
        _extend_file = os.path.basename(_texture_file)
        while _extend_file.startswith("/"):
            _extend_file = _extend_file[1:]
        _backup_texture_file = os.path.join(dst, _extend_file)
        #  upload texture file
        logger.info("upload file {} to {}".format(_texture_file, _backup_texture_file))
        
        _result = filefunc.publish_file(_texture_file, _backup_texture_file)
        # transfer.send_file_to_server(_texture_file, _backup_texture_file)

        # 记录贴图数据
        _file_info = zfile.get_file_info(_texture_file, _backup_texture_file)
        _file_infos.append(_file_info)

        #  if has .tx file and will upload
        _except_suffix, _ = os.path.splitext(_texture_file)
        _tx_texture_file = "{}.tx".format(_except_suffix)
        if os.path.isfile(_tx_texture_file):
            # _extend_file = _tx_texture_file.split(src)[-1]
            _extend_file = os.path.basename(_tx_texture_file)
            while _extend_file.startswith("/"):
                _extend_file = _extend_file[1:]
            _backup_tx_texture_file = os.path.join(dst, _extend_file)
            #  upload tx file
            _result = filefunc.publish_file(_tx_texture_file, _backup_tx_texture_file)
            # transfer.send_file_to_server(_tx_texture_file, _backup_tx_texture_file)

    return _file_infos
示例#3
0
def publish_file(*args, **kwargs):
    """ 上传任务模型文件
    """

    _task_id, _output_attr_id = args

    _output_attr_handle = zfused_api.attr.Output(_output_attr_id)
    _file_format = _output_attr_handle.format()
    _suffix = _output_attr_handle.suffix()
    _attr_code = _output_attr_handle.code()

    _task = zfused_api.task.Task(_task_id)
    _production_path = _task.production_path()
    _project_entity_production_path = _task.project_entity().production_path()
    _temp_path = _task.temp_path()
    _file_code = _task.file_code()
    if kwargs.get("fix_version"):
        _file_index = "{:0>4d}".format(_task.last_version_index(0))
    else:
        _file_index = "{:0>4d}".format(_task.last_version_index() + 1)

    _production_file = "{}/{}/{}.{}{}".format(_production_path, _attr_code,
                                              _file_code, _file_index, _suffix)
    _cover_file = "{}/{}/{}{}".format(_production_path, _attr_code, _file_code,
                                      _suffix)
    _publish_file = "{}/{}/{}.{}{}".format(_temp_path, _attr_code, _file_code,
                                           _file_index, _suffix)
    _publish_file_dir = os.path.dirname(_publish_file)
    if not os.path.isdir(_publish_file_dir):
        os.makedirs(_publish_file_dir)
    try:
        # save publish file
        cmds.file(rename=_publish_file)
        cmds.file(save=True, type=_file_format, f=True, options="v=0;")

        # fix mesh name
        _is_rendering = renderinggroup.nodes()
        fixmeshname.fix_mesh_name("_rendering", _is_rendering)

        # recore material
        material.record()

        # publish texture
        _texture_infos = []
        _texture_files = texture.files()
        if _texture_files:
            _path_set = texture.paths(_texture_files)[0]
            _intersection_path = max(_path_set)
            _texture_infos = texture.publish_file(
                _texture_files, _intersection_path,
                _project_entity_production_path + "/texture/production")
            # change maya texture node path
            _file_nodes = texture.nodes()
            if _file_nodes:
                texture.change_node_path(
                    _file_nodes, _intersection_path,
                    _project_entity_production_path + "/texture/production")

        # save publish file
        cmds.file(save=True, type=_file_format, f=True, options="v=0;")

        # publish file
        _result = filefunc.publish_file(_publish_file, _production_file)
        _result = filefunc.publish_file(_publish_file, _cover_file)

        # link files
        zfused_api.files.new_file("task", _task_id, _production_file,
                                  int(_file_index))
        zfused_api.files.new_file("task", _task_id, _cover_file,
                                  int(_file_index))

        # production file
        _file_info = zfile.get_file_info(_publish_file, _production_file)
        _cover_file_info = zfile.get_file_info(_cover_file, _cover_file)
        zfused_api.task.new_production_file([_file_info, _cover_file_info] +
                                            _texture_infos, _task_id,
                                            _output_attr_id, int(_file_index))

    except Exception as e:
        logger.error(e)
        return False

    return True
示例#4
0
def publish_gpu(*args, **kwargs):
    """ 上传模型abc文件
        args: entity_type, entity_id, attr_id
    """

    _task_id, _output_attr_id = args

    _output_attr_handle = zfused_api.attr.Output(_output_attr_id)
    _file_format = _output_attr_handle.format()
    _suffix = _output_attr_handle.suffix()
    _attr_code = _output_attr_handle.code()

    _task = zfused_api.task.Task(_task_id)
    _production_path = _task.production_path()
    _project_entity_production_path = _task.project_entity().production_path()
    _temp_path = _task.temp_path()
    _file_code = _task.file_code()
    if kwargs.get("fix_version"):
        _file_index = "{:0>4d}".format(_task.last_version_index(0))
    else:
        _file_index = "{:0>4d}".format(_task.last_version_index() + 1)

    _production_file = "{}/{}/{}.{}{}".format(_production_path, _attr_code,
                                              _file_code, _file_index, _suffix)
    _cover_file = "{}/{}/{}{}".format(_production_path, _attr_code, _file_code,
                                      _suffix)
    _publish_file = "{}/{}/{}.{}{}".format(_temp_path, _attr_code, _file_code,
                                           _file_index, _suffix)
    _publish_file_dir = os.path.dirname(_publish_file)
    if not os.path.isdir(_publish_file_dir):
        os.makedirs(_publish_file_dir)

    _file_name = "{}.{}".format(_file_code, _file_index)

    try:
        # 添加顶点色

        # change shading color
        _engines = shadingengine.get_shading_engines()
        #
        for _index, _engine in enumerate(_engines):
            _color = shadingengine.get_node_shading_color(_engine)
            # 可能会出问题
            if _color:
                shadingengine.set_node_shading_color(_engine, _color)
        shadingengine.switch_color_shader(_engines)

        # get rendering group
        _is_rendering = renderinggroup.nodes()
        _rendering_groups = " ".join(_is_rendering)

        _alembic_nodes = cmds.ls(type="AlembicNode")
        if _alembic_nodes:
            _start_time = cmds.playbackOptions(q=True, min=True)
            _end_time = cmds.playbackOptions(q=True, max=True)
            cmds.gpuCache(_rendering_groups,
                          useBaseTessellation=True,
                          startTime=_start_time,
                          endTime=_end_time,
                          writeMaterials=True,
                          directory=_publish_file_dir,
                          fileName=_file_name)  #allDagObjects = True)
        else:
            # will reduce mesh
            # get gpu reduce percentage
            _reduce_percentage = _task.project_entity().xattr(
                "gpu_reduce_percentage")
            if _reduce_percentage == "100":
                cmds.gpuCache(_rendering_groups,
                              useBaseTessellation=True,
                              startTime=1,
                              endTime=1,
                              writeMaterials=True,
                              directory=_publish_file_dir,
                              fileName=_file_name)  #allDagObjects = True)
            else:
                reducemesh.reduce_mesh(float(_reduce_percentage),
                                       _publish_file_dir, _file_name)

    except Exception as e:
        logger.error(e)
        return False

    # publish file
    _result = filefunc.publish_file(_publish_file, _production_file)
    _result = filefunc.publish_file(_publish_file, _cover_file)

    # record in file
    _file_info = zfile.get_file_info(_publish_file, _production_file)
    _cover_file_info = zfile.get_file_info(_cover_file, _cover_file)
    zfused_api.task.new_production_file([_file_info, _cover_file_info],
                                        _task_id, _output_attr_id,
                                        int(_file_index))

    return True
示例#5
0
def publish_material(*args, **kwargs):
    """ 上传任务模型文件
        args: output_entity_type, output_entity_id, output_attr_id
    """

    _task_id, _output_attr_id = args

    _output_attr_handle = zfused_api.attr.Output(_output_attr_id)
    _file_format = _output_attr_handle.format()
    _suffix = _output_attr_handle.suffix()
    _attr_code = _output_attr_handle.code()

    _task = zfused_api.task.Task(_task_id)
    _production_path = _task.production_path()
    _project_entity_production_path = _task.project_entity().production_path()
    _temp_path = _task.temp_path()
    _file_code = _task.file_code()
    if kwargs.get("fix_version"):
        _file_index = "{:0>4d}".format(_task.last_version_index(0))
    else:
        _file_index = "{:0>4d}".format(_task.last_version_index() + 1)

    _production_file = "{}/{}/{}.{}{}".format(_production_path, _attr_code,
                                              _file_code, _file_index, _suffix)
    _cover_file = "{}/{}/{}{}".format(_production_path, _attr_code, _file_code,
                                      _suffix)
    _publish_file = "{}/{}/{}.{}{}".format(_temp_path, _attr_code, _file_code,
                                           _file_index, _suffix)
    _publish_file_dir = os.path.dirname(_publish_file)
    if not os.path.isdir(_publish_file_dir):
        os.makedirs(_publish_file_dir)
    try:
        # # save publish file
        # cmds.file(rename = _publish_file)
        # cmds.file(save = True, type = _file_format, f = True, options = "v=0;")

        # # fix mesh name
        # _is_rendering = renderinggroup.nodes()
        # fixmeshname.fix_mesh_name("_rendering", _is_rendering)

        # # recore material
        # material.record()

        # get all material
        _meshs = _get_rendering_mesh()
        if not _meshs:
            return
        # 对大量模型操作时会卡死,弃用
        # cmds.select(_meshs, replace = True)
        # cmds.hyperShade(shaderNetworksSelectMaterialNodes = True)
        _sgs = cmds.listConnections(_meshs, d=1, type="shadingEngine")
        # _mat = [cmds.listConnections("{}.surfaceShader".format(i),d = 1)[0] for i in set(_sgs)]
        # cmds.select(_mat,r =1)
        cmds.select(cl=True)
        cmds.select(_sgs, r=True, ne=True)
        cmds.file(_publish_file,
                  op="v=0;",
                  type="mayaBinary",
                  pr=True,
                  es=True,
                  f=True)

        # publish file
        _result = filefunc.publish_file(_publish_file, _production_file)
        _result = filefunc.publish_file(_publish_file, _cover_file)

        # link files
        zfused_api.files.new_file("task", _task_id, _production_file,
                                  int(_file_index))
        zfused_api.files.new_file("task", _task_id, _cover_file,
                                  int(_file_index))

        # production file
        _file_info = zfile.get_file_info(_publish_file, _production_file)
        _cover_file_info = zfile.get_file_info(_cover_file, _cover_file)
        zfused_api.task.new_production_file([_file_info, _cover_file_info],
                                            _task_id, _output_attr_id,
                                            int(_file_index))

    except Exception as e:
        logger.error(e)
        return False

    return True
def publish_file(*args, **kwargs):
    """ 上传绑定文件
    """
    _task_id, _output_attr_id = args

    _output_attr_handle = zfused_api.attr.Output(_output_attr_id)
    _file_format = _output_attr_handle.format()
    _suffix = _output_attr_handle.suffix()
    _attr_code = _output_attr_handle.code()

    _task = zfused_api.task.Task(_task_id)    
    _production_path = _task.production_path()
    _project_entity_production_path = _task.project_entity().production_path()
    _temp_path = _task.temp_path()
    _file_code = _task.file_code()
    if kwargs.get("fix_version"):
        _file_index = "{:0>4d}".format(_task.last_version_index( 0 ))
    else:
        _file_index = "{:0>4d}".format(_task.last_version_index() + 1)

    _production_file = "{}/{}/{}.{}{}".format( _production_path, _attr_code, _file_code, _file_index, _suffix )
    _cover_file = "{}/{}/{}{}".format(_production_path, _attr_code, _file_code, _suffix)
    _publish_file = "{}/{}/{}.{}{}".format( _temp_path, _attr_code, _file_code, _file_index, _suffix )
    _publish_file_dir = os.path.dirname(_publish_file)

    if not os.path.isdir(_publish_file_dir):
        os.makedirs(_publish_file_dir)
    try:
        # save publish file
        cmds.file(rename = _publish_file)
        cmds.file(save = True, type = _file_format, f = True)
        
        # publish texture
        _texture_infos = []
        _texture_files = texture.files()
        if _texture_files:
            _path_set = texture.paths(_texture_files)[0]
            _intersection_path = max(_path_set)
            _texture_infos = texture.publish_file(_texture_files, _intersection_path, _project_entity_production_path + "/texture/production")
            # change maya texture node path
            _file_nodes = texture.nodes()
            if _file_nodes:
                texture.change_node_path(_file_nodes, _intersection_path, _project_entity_production_path + "/texture/production")
        
        # publish yeti node texture
        _yeti_texture_dict = yeti._get_yeti_attr("texture","file_name")
        if _yeti_texture_dict:
            _path_set = yeti.paths([i.replace("\\","/") for i in _yeti_texture_dict.values()])[0]
            _intersection_path = max(_path_set)
            yeti.publish_file(_yeti_texture_dict.values(), _intersection_path, _project_entity_production_path + "/texture/yeti")
            yeti.change_node_path(_yeti_texture_dict,_intersection_path, _project_entity_production_path + "/texture/yeti")

        # publish alembic cache
        _alembic_files = alembiccache.files()
        if _alembic_files:
            _path_set = alembiccache.paths(_alembic_files)[0]
            _intersection_path = max(_path_set)
            alembiccache.publish_file(_alembic_files, _intersection_path, _project_entity_production_path + "/cache/alembic")
            _file_nodes = alembiccache.nodes()
            if _file_nodes:
                alembiccache.change_node_path(_file_nodes, _intersection_path, _project_entity_production_path + "/cache/alembic")

        # import all reference
        referencefile.import_all_references()
        # remove all namesapce
        referencefile.remove_all_namespaces()
        # delete unused material
        material.delete_unused()
        # delete ngskin nodes
        try:
            _nodes = cmds.ls(type = ["ngSkinLayerData", "ngSkinLayerDisplay"])
            if _nodes:
                for _node in _nodes:
                    cmds.lockNode(_node, l = False)
                    cmds.delete(_node)
        except:
            pass

        # fix mesh name
        _is_rendering = renderinggroup.nodes()
        shader_dict = fixmeshname.fix_mesh_name("_rendering", _is_rendering, True)

        # # repair shader
        # cmds.file(save = True, type = _file_format, f = True)
        # if shader_dict:
        #     for k2,v2 in shader_dict.items():
        #         cmds.select(v2)
        #         cmds.hyperShade(assign = "lambert1")
        #         cmds.hyperShade(assign = k2)

        # repair arnold id
        _meshs = cmds.ls(type = "mesh", ap = True)
        for _mesh in _meshs:
            _attrs = cmds.listAttr(_mesh, st = "mtoa_constant*")
            if not _attrs:
                continue
            if not len(_attrs) == 4:
                continue
            if not _mesh.endswith("_orig"):
                continue 
            _parent = cmds.listRelatives(_mesh, p = True, f = True)
            # #print(_parent)
            if not _parent:
                continue
            _parent = _parent[0]
            _fix_mesh = cmds.listRelatives(_parent, f = True, children=True, shapes=True, noIntermediate=True, type="mesh")[0] 
            _id_attr_name  = _attrs[0]
            _id_attr_number = [
                cmds.getAttr("{}.{}".format(_mesh, _attrs[1])),
                cmds.getAttr("{}.{}".format(_mesh, _attrs[2])),
                cmds.getAttr("{}.{}".format(_mesh, _attrs[3]))
            ]                
            if cmds.objExists("{}.{}".format(_fix_mesh, _id_attr_name)):
                cmds.deleteAttr( "{}.{}".format(_fix_mesh, _id_attr_name) )
            _attr_name = _id_attr_name
            cmds.addAttr(_fix_mesh, ln = _attr_name, at = "double3");
            cmds.addAttr(_fix_mesh, ln = "{}X".format(_attr_name), at = "double", p = _attr_name) 
            cmds.addAttr(_fix_mesh, ln = "{}Y".format(_attr_name), at = "double", p = _attr_name)
            cmds.addAttr(_fix_mesh, ln = "{}Z".format(_attr_name), at = "double", p = _attr_name)
            cmds.setAttr("{}.{}X".format(_fix_mesh, _attr_name), e = True, k = True ) 
            cmds.setAttr("{}.{}Y".format(_fix_mesh, _attr_name), e = True, k = True )
            cmds.setAttr("{}.{}Z".format(_fix_mesh, _attr_name), e = True, k = True )
            cmds.setAttr("{}.{}X".format(_fix_mesh, _attr_name), _id_attr_number[0] )
            cmds.setAttr("{}.{}Y".format(_fix_mesh, _attr_name), _id_attr_number[1] )
            cmds.setAttr("{}.{}Z".format(_fix_mesh, _attr_name), _id_attr_number[2] )

        cmds.file(save = True, type = _file_format, f = True)

        # publish file
        _result = filefunc.publish_file(_publish_file, _production_file)
        _result = filefunc.publish_file(_publish_file, _cover_file)

        # link files
        zfused_api.files.new_file("task", _task_id, _production_file, int(_file_index))
        zfused_api.files.new_file("task", _task_id, _cover_file, int(_file_index))

        # record to database
        _file_info = zfile.get_file_info(_publish_file, _production_file)
        _cover_file_info = zfile.get_file_info(_cover_file, _cover_file)
        zfused_api.task.new_production_file([_file_info, _cover_file_info] + _texture_infos, _task_id, _output_attr_id, int(_file_index) )

    except Exception as e:
        logger.error(e)
        return False
        
    return True
def publish_file(*args, **kwargs):
    """ 上传任务模型文件
    """

    _task_id, _output_attr_id = args

    _output_attr_handle = zfused_api.attr.Output(_output_attr_id)
    _file_format = _output_attr_handle.format()
    _suffix = _output_attr_handle.suffix()
    _attr_code = _output_attr_handle.code()

    _task = zfused_api.task.Task(_task_id)
    _production_path = _task.production_path()
    _project_entity_production_path = _task.project_entity().production_path()
    _temp_path = _task.temp_path()
    _file_code = _task.file_code()
    if kwargs.get("fix_version"):
        _file_index = "{:0>4d}".format(_task.last_version_index(0))
    else:
        _file_index = "{:0>4d}".format(_task.last_version_index() + 1)

    _production_file = "{}/{}/{}.{}{}".format(_production_path, _attr_code,
                                              _file_code, _file_index, _suffix)
    _cover_file = "{}/{}/{}{}".format(_production_path, _attr_code, _file_code,
                                      _suffix)
    _publish_file = "{}/{}/{}.{}{}".format(_temp_path, _attr_code, _file_code,
                                           _file_index, _suffix)
    _publish_file_dir = os.path.dirname(_publish_file)
    if not os.path.isdir(_publish_file_dir):
        os.makedirs(_publish_file_dir)

    # _xgen_list = xgen.xgenfile()
    # if _xgen_list:
    #     xgen.publishxgen()

    try:
        # save publish file
        cmds.file(rename=_publish_file)
        cmds.file(save=True, type=_file_format, f=True, options="v=0;")

        # _xgen_list = xgen.xgenfile()
        # if _xgen_list:
        #     xgen.publishxgen()

        # # 暂时取消 后面通过检测判定错误 不直接修复问题
        # # fix camera aspect ratio
        # _cameras = cmds.ls("{}*".format(_file_code), type="camera")
        # if _cameras:
        #     for _camera in _cameras:
        #         # get
        #         if cmds.getAttr("{}.filmFit".format(_camera)) == 3:
        #             _v_f = cmds.getAttr("{}.verticalFilmAperture".format(_camera))
        #             cmds.setAttr("{}.horizontalFilmAperture".format(_camera), _v_f * 2.503)

        # publish texture
        _texture_infos = []
        _texture_files = texture.files()
        if _texture_files:
            _path_set = texture.paths(_texture_files)[0]
            _intersection_path = max(_path_set)
            _texture_infos = texture.publish_file(
                _texture_files, _intersection_path,
                _project_entity_production_path + "/texture/preview")
            # change maya texture node path
            _file_nodes = texture.nodes()
            if _file_nodes:
                texture.change_node_path(
                    _file_nodes, _intersection_path,
                    _project_entity_production_path + "/texture/preview")

        # publish alembic
        _alembic_files = alembiccache.files()
        if _alembic_files:
            _path_set = alembiccache.paths(_alembic_files)[0]
            _intersection_path = max(_path_set)
            alembiccache.publish_file(_alembic_files, _intersection_path,
                                      _production_path + "/cache/alembic")
            _file_nodes = alembiccache.nodes()
            if _file_nodes:
                alembiccache.change_node_path(
                    _file_nodes, _intersection_path,
                    _production_path + "/cache/alembic")

        # save publish file
        cmds.file(save=True, type=_file_format, f=True, options="v=0;")

        # publish file
        _result = filefunc.publish_file(_publish_file, _production_file)
        _result = filefunc.publish_file(_publish_file, _cover_file)

        # link files
        zfused_api.files.new_file("task", _task_id, _production_file,
                                  int(_file_index))
        zfused_api.files.new_file("task", _task_id, _cover_file,
                                  int(_file_index))

        # production file
        _file_info = zfile.get_file_info(_publish_file, _production_file)
        _cover_file_info = zfile.get_file_info(_cover_file, _cover_file)
        zfused_api.task.new_production_file([_file_info, _cover_file_info],
                                            _task_id, _output_attr_id,
                                            int(_file_index))

        # if _xgen_list:
        #     for _xgen_node in _xgen_list:

        #         _xgen_name = xgen._getxgenfilename(_xgen_node)
        #         _xgen_path = xgen._getxgenfile(_xgen_node)
        #         _cover_xgen_file = "{}/{}/{}/{}/{}".format(_production_path, _step_code, _software_code, _attr_code,
        #                                                    _xgen_name)
        #         _backup_xgenfile = "{}/{}".format(_backup_path, _xgen_name)
        #         if os.path.exists(_xgen_path):
        #             filefunc.publish_file(_xgen_path, _cover_xgen_file)
        #             filefunc.publish_file(_xgen_path, _backup_xgenfile)

    except Exception as e:
        logger.error(e)
        return False

    return True