-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunpack_flcg.py
More file actions
69 lines (51 loc) · 1.9 KB
/
unpack_flcg.py
File metadata and controls
69 lines (51 loc) · 1.9 KB
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
import os
from pathlib import Path
import sys
from lib.kaitai_defs.flcg import Flcg
from glob import glob
TOOL_NAME = "Jyl's FLCG exporter"
DIR = "filesystem/DATA/files/STG_HI"
OUT_DIR = "out/STG_HI"
def unpack(in_path: str, out_dir: str):
os.makedirs(out_dir, exist_ok=True)
print(in_path)
gcl: Flcg = Flcg.from_file(in_path)
out_path = os.path.join(out_dir, Path(in_path).stem + ".obj")
with open(out_path, "w") as f:
f.write("# OBJ file\n")
f.write(f"# Generated by {TOOL_NAME}\n")
last_index = 0
for i in range(gcl.num_areas):
area = gcl.areas[i]
f.write(f"o {area.name}_{i}\n")
area = gcl.areas[i]
for tri in area.data.col_mesh:
f.write(vert_2_obj(tri.v0, area.origin))
f.write(vert_2_obj(tri.v1, area.origin))
f.write(vert_2_obj(tri.v2, area.origin))
for ii in range(last_index, last_index + area.data.num_col_tris):
f.write(f"f {ii * 3 + 1} {ii * 3 + 2} {ii * 3 + 3}\n")
last_index += area.data.num_col_tris
def vert_2_obj(v: Flcg.FlVector, origin: Flcg.FlVector) -> str:
"""
This bakes in object origin, because I don't think wavefront supports it.
Coords are divided by 10 because the unit seems to be 10m.
"""
x = (v.x + origin.x) * 0.1
y = (v.y + origin.y) * 0.1
z = (v.z + origin.z) * 0.1
return f"v {x} {y} {z}\n"
if __name__ == "__main__":
match len(sys.argv):
case 2:
in_path = sys.argv[1]
out_path = os.path.join(".", Path(in_path).stem + "_extracted")
unpack(in_path, out_path)
case 3:
in_path = sys.argv[1]
out_path = sys.argv[2]
unpack(in_path, out_path)
case _:
print(
"Provide 1 or 2 args:\n - input file path\n - output dir path (optional)"
)