forked from Arathain/Vigorem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converterer.py
executable file
·127 lines (115 loc) · 6.76 KB
/
converterer.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import json
# Open
f = open('anim_to_read.json')
data = json.load(f)
conversion = {"Body" : "body", "RightArm" : "right_arm", "LeftArm" : "left_arm", "RightHand" : "right_hand", "LeftHand" : "left_hand", "Head" : "head", "RightLeg" : "right_leg", "LeftLeg" : "left_leg",}
convertEasing = {"linear" : "LINEAR", "easeInSine" : "SINE_IN", "easeOutSine" : "SINE_OUT", "easeInOutSine" : "SINE_IN_OUT", "easeInQuad" : "QUAD_IN", "easeOutQuad" : "QUAD_OUT", "easeInOutQuad" : "QUAD_IN_OUT", "easeInQuart" : "QUARTIC_IN", "easeOutQuart" : "QUARTIC_OUT", "easeInOutQuart" : "QUARTIC_IN_OUT", "easeInQuint" : "QUINTIC_IN", "easeOutQuint" : "QUINTIC_OUT", "easeInOutQuint" : "QUINTIC_IN_OUT", "easeInBack" : "BACK_IN", "easeOutBack" : "BACK_OUT", "easeInOutBack" : "BACK_IN_OUT", "easeInExpo" : "EXPO_IN", "easeOutExpo" : "EXPO_OUT", "easeInOutExpo" : "EXPO_IN_OUT"}
uberlist = []
def getMolang(value):
return "new MoLangVec3fSupplier((math, query) -> " + str(value[2][0]) +", (math, query) -> " + str(value[2][1]) +", (math, query) -> " + str(value[2][2]) + ")"
def getMolangDeg(value):
return "new MoLangVec3fSupplier((math, query) -> " + str(value[2][0]) +", (math, query) -> " + str(value[2][1]) +", (math, query) -> " + str(value[2][2]) + ", true)"
def isMolang(value):
if 'math' in str(value[2][0]) or 'query' in str(value[2][0]):
return True
if 'math' in str(value[2][1]) or 'query' in str(value[2][1]):
return True
if 'math' in str(value[2][2]) or 'query' in str(value[2][2]):
return True
return False
# the son of the J
# future arathain here, no fucking idea what this is supposed to mean.
for i in data['animations']:
animList = []
for k in data['animations'][i]['bones']:
frames = {}
if 'rotation' in data['animations'][i]['bones'][k]:
frameTimes = []
easings = []
vecs = []
for keyframe in data['animations'][i]['bones'][k]['rotation']:
frameTimes.append(float(keyframe))
if 'easing' in data['animations'][i]['bones'][k]['rotation'][keyframe]:
easings.append(data['animations'][i]['bones'][k]['rotation'][keyframe]['easing'])
else:
easings.append("linear")
vecs.append(data['animations'][i]['bones'][k]['rotation'][keyframe]['vector'])
easings.pop(0)
easings.append("linear")
for soup in range(len(easings)):
frames[frameTimes[soup]] = [("rot", easings[soup], vecs[soup])]
if 'position' in data['animations'][i]['bones'][k]:
frameTimes = []
easings = []
vecs = []
for keyframe in data['animations'][i]['bones'][k]['position']:
frameTimes.append(float(keyframe))
if 'easing' in data['animations'][i]['bones'][k]['position'][keyframe]:
easings.append(data['animations'][i]['bones'][k]['position'][keyframe]['easing'])
else:
easings.append("linear")
vecs.append(data['animations'][i]['bones'][k]['position'][keyframe]['vector'])
easings.pop(0)
easings.append("linear")
for soup in range(len(easings)):
if frameTimes[soup] in frames.keys():
frames[frameTimes[soup]].append(("pos", easings[soup], vecs[soup]))
else:
frames[frameTimes[soup]] = [("pos", easings[soup], vecs[soup])]
if 'scale' in data['animations'][i]['bones'][k]:
frameTimes = []
easings = []
vecs = []
for keyframe in data['animations'][i]['bones'][k]['scale']:
frameTimes.append(float(keyframe))
if 'easing' in data['animations'][i]['bones'][k]['scale'][keyframe]:
easings.append(data['animations'][i]['bones'][k]['scale'][keyframe]['easing'])
else:
easings.append("linear")
vecs.append(data['animations'][i]['bones'][k]['scale'][keyframe]['vector'])
easings.pop(0)
easings.append("linear")
for soup in range(len(easings)):
if frameTimes[soup] in frames.keys():
frames[frameTimes[soup]].append(("scale", easings[soup], vecs[soup]))
else:
frames[frameTimes[soup]] = [("scale", easings[soup], vecs[soup])]
animList.append((conversion[k] if k in conversion else k, (frames)))
uberlist.append((animList, int(data['animations'][i]['animation_length']*20), str(i)))
# data extracted, you can now pray
f.close()
with open('export.txt', 'a') as f:
for anim in uberlist:
for jointAnim in anim[0]:
for frame in range(len(jointAnim[1])):
key = list(jointAnim[1].keys())[frame]
value = list(jointAnim[1].values())[frame]
rot = "ProperVec3fSupplier.ZERO"
pos = "ProperVec3fSupplier.ZERO"
scale = "ProperVec3fSupplier.ZERO"
easing = "LINEAR"
for val in value:
match val[0]:
case "pos":
if isMolang(val):
pos = getMolang(val)
else:
pos = "new ProperVec3fSupplier(" + str(val[2][0]) +"f, " + str(val[2][1]) +"f, " + str(val[2][2]) + "f)"
easing = val[1]
case "scale":
if isMolang(val):
scale = getMolang(val)
else:
scale = "new ProperVec3fSupplier(" + str(val[2][0]) +"f, " + str(val[2][1]) +"f, " + str(val[2][2]) + "f)"
easing = val[1]
case "rot":
if isMolang(val):
rot = getMolangDeg(val)
else:
rot = "deg(" + str(round(val[2][0], 2)) +"f, " + str(round(val[2][1], 2)) +"f, " + str(round(val[2][2], 2)) + "f)"
easing = val[1]
f.write("cache.add(new Keyframe(Easing." + (convertEasing[easing] if easing in convertEasing else easing) + ", " + pos + ", " + rot + ", " + scale + ", " + "" + ("new ProperVec3fSupplier(0, -12, 0), " if jointAnim[0] == "body" else "ProperVec3fSupplier.ZERO, ") + str(round(key*20, 2 if frame != len(jointAnim[1])-1 else 0))+ "f));\n")
f.write(anim[2].upper() + ".put(\"" + jointAnim[0] + "\", new ArrayList<>(cache));\n")
f.write("cache.clear();\n")
f.write("Animations.put(id(\"" + anim[2] + "\"), () -> new Animation(" + str(anim[1]) + ", " + anim[2].upper() +"));\n")
f.close()