-
Notifications
You must be signed in to change notification settings - Fork 7
/
v1_to_v2.py
39 lines (27 loc) · 1.2 KB
/
v1_to_v2.py
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
import json
from collections import defaultdict
def ForJSONFile(srcFile, dstFile=None):
with open(srcFile, 'r', encoding='utf-8') as f:
originData = json.load(f)
newData = defaultdict(list)
for data in originData["joint"].values():
newData["joint"].append(data)
for jointID, vector in originData["force"].items():
newData["force"].append([int(jointID), vector])
for data in originData["member"].values():
newData["member"].append(data)
if "displace" in originData:
for jointID, vector in originData["displace"].items():
newData["displace"].append([int(jointID), vector])
if "external" in originData:
for jointID, vector in originData["external"].items():
newData["external"].append([int(jointID), vector])
if "internal" in originData:
for memberID, force in originData["internal"].items():
newData["internal"].append([int(memberID), force])
if "weight" in originData:
newData["weight"] = originData["weight"]
if dstFile is not None:
with open(dstFile, 'w', encoding='utf-8') as f:
json.dump(newData, f)
return newData