-
-
Save MizunagiKB/7fd109925e56db0ed88b77450cdea579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import json | |
def load_json(pathname: str) -> dict: | |
with open(pathname, "r", encoding="utf-8") as rf: | |
return json.load(rf) | |
def save_json(pathname: str, dict_motion3: dict): | |
with open(pathname, "w", encoding="utf-8") as wf: | |
return json.dump(dict_motion3, wf, indent=4) | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-i", "--INPUT", type=str, required=True) | |
parser.add_argument("-o", "--OUTPUT", type=str, default="") | |
args = parser.parse_args() | |
dict_motion3: dict = load_json(args.INPUT) | |
list_curve: list = dict_motion3["Curves"] | |
totalPointCount: int = 0 | |
segmentCount: int = 0 | |
for o in list_curve: | |
segmetns = o["Segments"] | |
segmetns_size: int = len(segmetns) | |
pos: int = 2 | |
totalPointCount += 1 | |
while pos < segmetns_size: | |
curve_type = segmetns[pos + 0] | |
match curve_type: | |
case 0: | |
totalPointCount += 1 | |
segmentCount += 1 | |
pos += 3 | |
case 1: | |
totalPointCount += 3 | |
segmentCount += 1 | |
pos += 7 | |
case 2: | |
totalPointCount += 1 | |
segmentCount += 1 | |
pos += 3 | |
case 3: | |
totalPointCount += 1 | |
segmentCount += 1 | |
pos += 3 | |
case _: | |
assert False | |
print( | |
"CurveCount = {:5d} -> {:5d}".format( | |
dict_motion3["Meta"]["CurveCount"], len(list_curve) | |
) | |
) | |
print( | |
"TotalSegmentCount = {:5d} -> {:5d}".format( | |
dict_motion3["Meta"]["TotalSegmentCount"], segmentCount | |
) | |
) | |
print( | |
"TotalPointCount = {:5d} -> {:5d}".format( | |
dict_motion3["Meta"]["TotalPointCount"], totalPointCount | |
) | |
) | |
dict_motion3["Meta"]["TotalSegmentCount"] = segmentCount | |
dict_motion3["Meta"]["TotalPointCount"] = totalPointCount | |
if args.OUTPUT != "": | |
save_json(args.OUTPUT, dict_motion3) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment