# Import built-in modules from collections import defaultdict import json import os
# Import local modules import unreal
DIR = os.path.dirname(os.path.abspath(__file__))
defunreal_progress(tasks, label="进度", total=None): total = total if total elselen(tasks) with unreal.ScopedSlowTask(total, label) as task: task.make_dialog(True) for i, item inenumerate(tasks): if task.should_cancel(): break task.enter_progress_frame(1, "%s %s/%s" % (label, i, total)) yield item
# NOTE: 遍历命名为 Face 的 binding for binding in unreal_progress(binding_dict.get("Face", []), "导出 Face 数据"): # NOTE: 获取关键帧 channel 数据 keys_dict = {} for track in binding.get_tracks(): for section in track.get_sections(): for channel in unreal_progress(section.get_channels(), "导出关键帧"): ifnot channel.get_num_keys(): continue keys = [] for key in channel.get_keys(): frame_time = key.get_time() frame = frame_time.frame_number.value + frame_time.sub_frame keys.append({"frame": frame, "value": key.get_value()})
keys_dict[channel.get_name()] = keys
# NOTE: 导出 json name = binding.get_parent().get_name() export_path = os.path.join(DIR, "{0}.json".format(name)) withopen(export_path, "w") as wf: json.dump(keys_dict, wf, indent=4)
# Import built-in modules import json import os import traceback
# Import third-party modules import pymel.core as pm
DIR = os.path.dirname(os.path.abspath(__file__))
defprogress(seq, status="", title=""): pm.progressWindow(status=status, title=title, progress=0.0, isInterruptable=True) total = len(seq) for i, item inenumerate(seq): try: if pm.progressWindow(query=True, isCancelled=True): break pm.progressWindow(e=True, progress=float(i) / total * 100) yield item # with body executes here except: traceback.print_exc() pm.progressWindow(ep=1) pm.progressWindow(ep=1)
defmain():
# NOTE: 读取数据 withopen(os.path.join(DIR, "BP_metahuman_001.json"), "r") as rf: data = json.load(rf)