How to generate tile faces based on vertices?
Posted: Fri Mar 01, 2019 10:41 pm
I have a terrain/map file that only contains vertices data, no faces. I guess the game generates the faces when loading the map.
Considering it is a map all vertices are in square tiles. For example:

As you can see a terrain is visible through all this vertex points. But how do I create the faces based on the vertices?
Here is my idea: (feel free to correct me)
Considering it is a map all vertices are in square tiles. For example:

As you can see a terrain is visible through all this vertex points. But how do I create the faces based on the vertices?
Here is my idea: (feel free to correct me)
Code: Select all
width = struct.unpack("<I", bin.read(4))[0]
height = struct.unpack("<I", bin.read(4))[0]
for x in range(width*height):
texture_index = struct.unpack("<H", bin.read(2))[0]
output = output + "g tile_%d\n" % (x)
output = output + "usemtl mat_%d\n" % (texture_index)
for y1 in range(8):
x1 = (x*9)+1
x2 = (x*9)+y1+2
x3 = (x*9)+y1+3
if y1 == 7:
x3 = (x*9)+0+2
output = output + "f %d/%d/%d %d/%d/%d %d/%d/%d\n" % (x1,x1,x1,x2,x2,x2,x3,x3,x3)