How to generate tile faces based on vertices?

Post questions about game models here, or help out others!
Post Reply
majidemo
advanced
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?

Post by majidemo » 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:

Image

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)   

User avatar
Bigchillghost
ultra-veteran
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?

Post by Bigchillghost » Sat Mar 02, 2019 1:57 am

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? :D
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 Image when you get helped.:)

majidemo
advanced
Posts: 73
Joined: Sun Aug 21, 2016 12:00 am
Has thanked: 30 times
Been thanked: 39 times

Re: How to generate tile faces based on vertices?

Post by majidemo » Sat Mar 02, 2019 5:12 am

I just tried my code and it made Noesis freeze for about a minute but ultimately loaded a map with faces. Altough the freeze is annoying me. The game I’m working with only works with tris. No quads. I’ll check your link.

Post Reply