libsm64/import-test-collision.py

59 lines
1.8 KiB
Python
Raw Normal View History

2020-10-20 00:17:32 -04:00
#!/usr/bin/env python3
import os
import shutil
2020-10-25 03:36:47 -04:00
import urllib.request
2020-10-20 00:17:32 -04:00
BOB_COLLISION_URL = "https://raw.githubusercontent.com/n64decomp/sm64/06ec56df7f951f88da05f468cdcacecba496145a/levels/bob/areas/1/collision.inc.c"
2020-10-20 00:17:32 -04:00
LEVEL_H = """#pragma once
#include "../src/libsm64.h"
extern const struct SM64Surface surfaces[];
extern const size_t surfaces_count;
"""
def main():
print("Downloading " + BOB_COLLISION_URL)
2020-10-25 03:36:47 -04:00
in_lines = urllib.request.urlopen(BOB_COLLISION_URL).read().decode('utf8').splitlines()
2020-10-20 00:17:32 -04:00
verts = []
tris = []
mode = ""
for line in in_lines:
if not line.strip().startswith("COL_"):
continue;
tokens = line.strip().replace("(", ",").replace(")", "").split(",")
if tokens[0] == "COL_VERTEX":
verts.append([ int(tokens[1]), int(tokens[2]), int(tokens[3]) ])
2020-10-25 03:36:47 -04:00
elif tokens[0] == "COL_TRI_INIT":
2020-10-20 00:17:32 -04:00
mode = tokens[1]
2020-10-25 03:36:47 -04:00
elif tokens[0] == "COL_TRI":
2020-10-20 00:17:32 -04:00
tris.append([ int(tokens[1]), int(tokens[2]), int(tokens[3]), mode ])
out_lines = []
for tri in tris:
out_lines.append("{%s,0,TERRAIN_SNOW,{{%s,%s,%s},{%s,%s,%s},{%s,%s,%s}}}"%(tri[3], \
2020-10-20 00:17:32 -04:00
verts[tri[0]][0], verts[tri[0]][1], verts[tri[0]][2], \
verts[tri[1]][0], verts[tri[1]][1], verts[tri[1]][2], \
verts[tri[2]][0], verts[tri[2]][1], verts[tri[2]][2]))
out_str = ",\n".join(out_lines)
out_str = "const struct SM64Surface surfaces[] = {\n" + out_str + "};\n\n"
out_str += "const size_t surfaces_count = sizeof( surfaces ) / sizeof( surfaces[0] );"
out_str = '#include "../src/decomp/include/surface_terrains.h"\n' + out_str
2020-10-20 00:17:32 -04:00
out_str = '#include "level.h"\n' + out_str
with open("test/level.c", "w") as file:
file.write(out_str)
with open("test/level.h", "w") as file:
file.write(LEVEL_H)
if __name__ == "__main__":
2020-10-25 03:36:47 -04:00
main()