renderg-sdk 0.1.29
www.renderg.com

### 准备

1. 创建虚拟环境

   ```shell
   python -m venv venv
   ```

2. 安装 renderg-sdk

   ```shell
   pip install renderg-sdk
   ```

3. 创建配置文件 `config.json`

   ```shell
   {
     "AUTH_KEY": "*******************",
     "CLUSTER_ID": 27,
     "PROJECT_ID": 21479,
     "ENV_ID": 7715,
     "ZONE_ID": 1009,
     "RAM_LIMIT": "64G"
   }
   ```

- AUTH_KEY 用户身份认证，请联系 [RenderG 渲染农场](https://www.renderg.com/)平台技术支持获取；
- CLUSTER_ID 区域 ID ，一般为固定；可通过 api.config.get_cluster_list() 获取
- PROJECT_ID，提交任务默认项目，在客户端项目管理中创建；可通过 api.project.get_project_list() 获取
- ENV_ID ，提交任务默认环境，在客户端环境管理中创建；可通过 api.env.get_env_list() 获取
- ZONE_ID，提交任务默认配置；可通过 api.config.get_zone_list() 获取
- RAM_LIMIT，提交任务默认内存配置，64G、128G、256G 可选；可通过 api.config.get_zone_list() 获取

### 分析资产并上传

```python
import os

from renderg_utils import utils, log
from analyze_houdini import AnalyzeHoudini, ParamChecker
from renderg_api import RenderGAPI
from renderg_api.constants import TransferLines
from renderg_transfer.RGUpload import RenderGUpload
from renderg_transfer.RGDownload import RenderGDownload


# ========分析资产和设置渲染参数==========

# 1. 读取配置文件并设置工作目录
config = utils.read_json("./config.json")
workspace = config.get("WORKSPACE", os.path.expandvars("%userprofile%/RenderG_WorkSpace"))

# 2. 设置日志模块
log.init_logging(log_dir=utils.get_workspace(workspace), console=True)
logger = log.get_logger()
logger.info("SDK Version: {}".format(utils.get_version()))


# 3.  实例化API
api = RenderGAPI(auth_key=config["AUTH_KEY"], cluster_id=config["CLUSTER_ID"])

# 分析所需环境信息
analyze_info = {
    "dcc_file": r"E:\Work\Scene\Houdini\20.5.584.hip", # DCC 文件路径
    "dcc_version": "20.5.584", # DCC 版本号
    "api": api, # RenderGAPI 实例
    "project_id": 42310,  # 项目ID, 可通过 api.project.get_project_list() 获取
    "env_id": 16884,  # 环境ID, 可通过 api.env.get_env_list() 获取
    "workspace": workspace,  # 工作目录
    "logger": logger, # 日志记录器
}
# 4. 分析资产列表和场景渲染参数
analyze_obj = AnalyzeHoudini(**analyze_info)
analyze_obj.analyze()
logger.info(analyze_obj.info_path)

# 5. 设置渲染参数信息
param_check_obj = ParamChecker(api, analyze_obj)
render_params = {
    "ChunkSize": 1,  # 一机多帧
    "Mark": "",  # 任务备注信息
    "PriorityFrames": "010:",  # 优先渲染帧 例：101:100-108x2 代表渲染首尾帧和100-108步长为2的帧

    "zone_id": config["ZONE_ID"],  # CPU 配置信息
    "ram_limit": config["RAM_LIMIT"],  # 内存配置
}
# 设置提交的渲染节点及帧范围
param_check_obj.set_render_nodes({
    "/out/mantra1": "1-5"
})

param_check_obj.execute(**render_params)

# ========上传任务并提交==========
# 1. 获取 info.cfg 和 任务 ID 信息
info_path = analyze_obj.info_path
job_id = analyze_obj.job_id

# 2. 配置上传任务信息 
upload_kwargs = {
    "api": api,
    "job_id": job_id,
    "info_path": info_path,
    "line": TransferLines.LINE_UNICOM,
    "speed": 200  # 上传速度限制，单位为 Mbps
}
# 3. 开始上传
renderg_upload = RenderGUpload(**upload_kwargs)
renderg_upload.upload()

# 4. 上传完成，提交任务，开始渲染
submit = api.job.submit_job(job_id)
logger.info(submit["msg"])

# 5. 下载
# 等待任务完成下载
download_kwargs = {
    "api": api,
    "job_id": job_id,
    "download_path": "d:/test",  # 下载保存到本地路径
    "line": TransferLines.LINE_UNICOM,
    "cluster_id": config["CLUSTER_ID"],
    "speed": 500  # 上传速度限制，单位为 Mbps
}
renderg_sync = RenderGDownload(**download_kwargs)
result = renderg_sync.auto_download_after_job_completed()

'''
# 自定义下载
download_others_json = {
    "api": api,
    "job_id": None,
    "download_path": "d:/test",  # 下载保存到本地路径
    "line": TransferLines.LINE_UNICOM,
    "cluster_id": config["CLUSTER_ID"],
    "speed": 3000  # 上传速度限制，单位为 Mbps
}
server_path = {
    "/{job_id}".format(job_id=job_id)
}  # 提供待下载目录列表
renderg_sync = RenderGDownload(**download_others_json)
renderg_sync.custom_download(server_path)
'''
```