1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import json import os import traceback
import pymel.core as pm
DIR = os.path.dirname(os.path.abspath(__file__))
def progress(seq, status="", title=""): pm.progressWindow(status=status, title=title, progress=0.0, isInterruptable=True) total = len(seq) for i, item in enumerate(seq): try: if pm.progressWindow(query=True, isCancelled=True): break pm.progressWindow(e=True, progress=float(i) / total * 100) yield item except: traceback.print_exc() pm.progressWindow(ep=1) pm.progressWindow(ep=1)
def main():
with open(os.path.join(DIR, "BP_metahuman_001.json"), "r") as rf: data = json.load(rf)
attr_map = {"location": "t", "rotation": "r"} status = "Import Keyframe to metahuman controller" pm.undoInfo(ock=1) for channel, frame_list in progress(data.items(), status=status): has_attr = channel.count(".") if not has_attr: ctrl_name = channel.rsplit("_", 1)[0] attr = "ty" else: parts = iter(channel.split(".")) ctrl_name = next(parts, "") param = next(parts, "") axis = next(parts, "") if not axis: attr = "t" axis = param else: attr = attr_map.get(param.lower()) attr += axis.split("_")[0].lower()
attribute = pm.PyNode(".".join([ctrl_name, attr])) for frame_data in frame_list: frame = frame_data.get("frame") value = frame_data.get("value") attribute.setKey(t=frame, v=value)
pm.undoInfo(cck=1)
|