-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconvert_camera_data.py
75 lines (50 loc) · 2.03 KB
/
convert_camera_data.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
from pathlib import Path
from SourceIO.library.utils.datamodel import DataModel, load, Color, _dmxtypes, _dmxtypes_all, _dmxtypes_str, Element
import sys
class FixedColor(Color):
def __repr__(self):
return " ".join([str(int(ord)) for ord in self])
class EmptyElement(Element):
def get_kv2(self, deep=True):
return ''
def __repr__(self):
return ''
_dmxtypes.append(FixedColor)
_dmxtypes_all.append(FixedColor)
_dmxtypes_str.append('color')
_dmxtypes.append(EmptyElement)
_dmxtypes_all.append(EmptyElement)
_dmxtypes_str.append('element')
if __name__ == '__main__':
if len(sys.argv) != 2:
dmx_file = input("Source2 camera animation DMX file:")
# print("Provide exactly 1 camera animation dmx file as an argument!")
else:
dmx_file = sys.argv[1]
dmx_file = dmx_file.strip('"\'')
s2 = load(dmx_file)
for elem in s2.find_elements(elemtype='DmeChannelsClip'):
elem['color'] = FixedColor([int(a) for a in elem['color']])
def get_elemnts(elem_type):
return s2.find_elements(elemtype=elem_type) or []
elements_to_fix = get_elemnts('DmeFloatLog') + \
get_elemnts('DmeVector3Log') + \
get_elemnts('DmeQuaternionLog') + \
get_elemnts('DmeBoolLog')
for elem in elements_to_fix:
if elem['curveinfo'] is None:
elem['curveinfo'] = EmptyElement(s2, '', 'element')
elements_to_fix = get_elemnts('DmeChannel')
for elem in elements_to_fix:
if elem['fromElement'] is None:
elem['fromElement'] = EmptyElement(s2, '', 'element')
if elem['toElement'] is None:
elem['toElement'] = EmptyElement(s2, '', 'element')
elements_to_fix = get_elemnts('DmeCamera')
for elem in elements_to_fix:
if elem['shape'] is None:
elem['shape'] = EmptyElement(s2, '', 'element')
s2.format_ver = 18
path = Path(dmx_file)
path = path.with_name(path.stem + "_s1cvt").with_suffix('.dmx')
s2.write(path, 'keyvalues2', 1)