stuff, idk
parent
1477d5263e
commit
8a946952ad
@ -0,0 +1,141 @@
|
||||
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)
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,32 @@
|
||||
from giantslib.game.map import Map
|
||||
|
||||
|
||||
def main():
|
||||
basedir = "/home/tasty/Projects/gck-map-extract-objects/intro_island/"
|
||||
map_path = basedir + "intro_island.zip"
|
||||
m = Map(map_path)
|
||||
m.save_heightmap(basedir + "heightmap.png")
|
||||
m.save_colormap(basedir + "lightmap.png")
|
||||
print(m.minheight, m.maxheight, m.stretch)
|
||||
return
|
||||
|
||||
indexes = []
|
||||
for tri in m.triangles:
|
||||
index = m.vertices.index(tri)
|
||||
indexes.append(index)
|
||||
print(indexes)
|
||||
assert(len(indexes) % 3 == 0)
|
||||
|
||||
assert(max(indexes) < len(m.vertices))
|
||||
with open("/home/tasty/Projects/Giants/assets/terrains/test.obj", "w") as fp:
|
||||
for v in m.vertices:
|
||||
fp.write("v %s %s %s\n" % (v[0], v[1], v[2]))
|
||||
|
||||
t = 0
|
||||
while t < len(indexes):
|
||||
fp.write("f %s/%s %s/%s %s/%s\n" % (indexes[t]+1, indexes[t]+1, indexes[t+1]+1, indexes[t+1]+1, indexes[t+2]+1, indexes[t+2]+1))
|
||||
t += 3
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue