142 lines
5.2 KiB
Python
142 lines
5.2 KiB
Python
import os
|
|
import json
|
|
|
|
decoded_dir = "/home/tasty/Nextcloud/docs/giants_private/binlnk (compiler for xxbin files)/all/"
|
|
|
|
|
|
def _all_gbs():
|
|
all_gbs = {}
|
|
objdata = {}
|
|
objsets = {}
|
|
files = os.listdir(decoded_dir)
|
|
for file in files:
|
|
fullpath = decoded_dir + file
|
|
print("reading %s" % fullpath)
|
|
with open(fullpath) as fp:
|
|
currblock = None
|
|
curr_objset = None
|
|
curr_obj = None
|
|
lod_found = False
|
|
|
|
audio_wav = None
|
|
audio_dist = None
|
|
for line in fp.readlines():
|
|
line = line.strip()
|
|
if not line:
|
|
continue
|
|
if line == "[objdata]":
|
|
currblock = line
|
|
continue
|
|
if line == "[objset]":
|
|
currblock = line
|
|
continue
|
|
if line == "[object]":
|
|
currblock = line
|
|
continue
|
|
if line.startswith("[") and line.endswith("]"):
|
|
currblock = None
|
|
continue
|
|
|
|
if currblock == "[objdata]":
|
|
objdata_id, gbs_name = line.split(" ")
|
|
objdata_id = int(objdata_id)
|
|
if objdata_id in objdata:
|
|
# raise Exception("%s was already in objdata ?! %s" % (objdata_id, objdata[objdata_id]))
|
|
pass
|
|
gbs_name = gbs_name.replace("\"", "")
|
|
print("OBJDATA[%s] = %s" % (objdata_id, gbs_name))
|
|
objdata[objdata_id] = gbs_name
|
|
|
|
if currblock == "[objset]":
|
|
line_attrs = line.split(" ")
|
|
if line_attrs[0] == "ID":
|
|
curr_objset = int(line_attrs[1])
|
|
lod_found = False
|
|
if line_attrs[0] == "LOD" and not lod_found:
|
|
lod_found = True
|
|
objset_objdata = int(line_attrs[1])
|
|
print("OBJSETS[%s] = %s" % (curr_objset, objset_objdata))
|
|
objsets[curr_objset] = objset_objdata
|
|
|
|
if currblock == "[object]":
|
|
line_attrs = line.split(" ")
|
|
if line_attrs[0] == "ID":
|
|
curr_obj = int(line_attrs[1])
|
|
if line_attrs[0] == "OS":
|
|
obj_objset = int(line_attrs[1])
|
|
if line_attrs[0] == "AmbientStreamLoop":
|
|
audio_wav = line_attrs[2].strip("\"")
|
|
audio_dist = float(line_attrs[4])
|
|
|
|
if line_attrs[0] == "Done":
|
|
try:
|
|
print("OBJ[%s] = OBJSETS[%s] = OBJDATA[%s] = %s" % (
|
|
curr_obj, obj_objset, objsets[obj_objset], objdata[objsets[obj_objset]]))
|
|
all_gbs[curr_obj] = {"model": objdata[objsets[obj_objset]]}
|
|
if audio_wav:
|
|
all_gbs[curr_obj]["audio"] = audio_wav
|
|
all_gbs[curr_obj]["audiodist"] = audio_dist
|
|
except KeyError:
|
|
print("ERR: could not find OBJSET %s" % obj_objset)
|
|
continue
|
|
audio_wav = None
|
|
audio_dist = None
|
|
return all_gbs
|
|
|
|
|
|
def map_txt_to_json(map_txt_path):
|
|
all_objs = []
|
|
curr_obj = None
|
|
with open(map_txt_path) as fp:
|
|
for line in fp.readlines():
|
|
line = line.strip()
|
|
if not line:
|
|
continue
|
|
|
|
line_attrs = line.split(" ")
|
|
|
|
if line_attrs[0] == "ObjectRef6":
|
|
if curr_obj:
|
|
all_objs.append(curr_obj)
|
|
curr_obj = {
|
|
"id": int(line_attrs[1]),
|
|
"x": float(line_attrs[2]),
|
|
"y": float(line_attrs[3]),
|
|
"z": float(line_attrs[4]),
|
|
"angle": float(line_attrs[5]),
|
|
"angle_2": float(line_attrs[6]),
|
|
"angle_3": float(line_attrs[7]),
|
|
"scale": 1
|
|
}
|
|
|
|
if line_attrs[0] == "ObjectRef":
|
|
if curr_obj:
|
|
all_objs.append(curr_obj)
|
|
curr_obj = {
|
|
"id": int(line_attrs[1]),
|
|
"x": float(line_attrs[2]),
|
|
"y": float(line_attrs[3]),
|
|
"z": float(line_attrs[4]),
|
|
"angle": float(line_attrs[5]),
|
|
"angle_2": 0,
|
|
"angle_3": 0,
|
|
"scale": 1
|
|
}
|
|
if line_attrs[0] == "Scale":
|
|
curr_obj["scale"] = float(line_attrs[1])
|
|
with open(map_txt_path+".json", "w") as fp:
|
|
json.dump(all_objs, fp)
|
|
return all_objs
|
|
|
|
|
|
def create_id_to_gbs_json():
|
|
g = _all_gbs()
|
|
with open("id_to_gbs.json", "w") as fp:
|
|
json.dump(g, fp)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
create_id_to_gbs_json()
|
|
# m = map_txt_to_json("/home/tasty/Projects/Giants/assets/terrains/square_one_1/w_M_3Way_Tigs - Threeway - Square One.bin.txt")
|
|
# print(m)
|