gck-map-extract-objects/map2obj.py
2021-09-29 20:37:29 +02:00

33 lines
969 B
Python

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()