-
Notifications
You must be signed in to change notification settings - Fork 18
/
upgrade_assets.py
61 lines (46 loc) · 2.08 KB
/
upgrade_assets.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import json
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--fname")
opts = parser.parse_args()
dirname = os.path.dirname(__file__)
assets = os.path.join(dirname, "ragdoll", "resources", "assets")
for asset in [opts.fname] if opts.fname else os.listdir(assets):
fname = os.path.join(assets, asset)
with open(fname) as f:
content = json.load(f)
for entity, data in content["entities"].items():
components = data["components"]
if "GroupUIComponent" in components:
ui = components["GroupUIComponent"]["members"]
ui["useLinearAngularStiffness"] = True
ang_stiffness = ui["stiffness"]
ang_damping = ui["dampingRatio"]
lin_stiffness = ui["driveRelativeLinearStiffness"]
lin_damping = ui["driveRelativeLinearDampingRatio"]
ui["angularStiffness"] = ang_stiffness
ui["angularDampingRatio"] = ang_damping
ui["linearStiffness"] = lin_stiffness
ui["linearDampingRatio"] = lin_damping
if "MarkerUIComponent" in components:
ui = components["MarkerUIComponent"]["members"]
ui["useLinearAngularStiffness"] = True
ang_stiffness = ui["driveStiffness"]
ang_damping = ui["driveDampingRatio"]
lin_stiffness = ui["driveRelativeLinearStiffness"]
lin_damping = ui["driveRelativeLinearDampingRatio"]
ui["angularStiffness"] = ang_stiffness
ui["angularDampingRatio"] = ang_damping
ui["linearStiffness"] = lin_stiffness
ui["linearDampingRatio"] = lin_damping
if "PinJointUIComponent" in components:
con = components["PinJointUIComponent"]["members"]
con["useScale"] = True
if "DistanceJointUIComponent" in components:
con = components["DistanceJointUIComponent"]["members"]
con["useScale"] = True
con["useScaleForDistance"] = True
with open(fname, "w") as f:
json.dump(content, f, sort_keys=True, indent=4)
print("Upgraded %s" % fname)