## How to generate tile faces based on vertices?

Post questions about game models here, or help out others!
majidemo
Posts: 73
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 30 times
Been thanked: 39 times

### How to generate tile faces based on vertices?

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)

Code: Select all

``````    width  = struct.unpack("<I", bin.read(4))[0]

for x in range(width*height):

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

Bigchillghost
ultra-veteran
Posts: 426
Joined: Tue Jul 05, 2016 9:37 am
Has thanked: 21 times
Been thanked: 271 times

### Re: How to generate tile faces based on vertices?

majidemo wrote:
Fri Mar 01, 2019 10:41 pm
Here is my idea: (feel free to correct me)
Why not just run your code and see if it works?
majidemo wrote:
Fri Mar 01, 2019 10:41 pm

Code: Select all

``````        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)
``````
I'm sure it'd be much simpler and more appropriate to generate two triangles at a time. You can refer to the method in this post:
viewtopic.php?p=141503#p141503
You may break the quad to triangles if required.
May you find peace in this puzzle-solving game. Say it with action: click the when you get helped.

majidemo