Krycztij

TAW terrain format

979 posts in this topic

Anyone has resources on how TAWs terrain is encoded?

I could not find something on google.

I found out by myself, the ENV and MAP files are indexes for the terrain tiles (see screenshot)

tilemaps.jpg

Does anyone have a list which index means which tile? Are the tiles .3 files?

- Pjotr

Share this post


Link to post
Share on other sites

Anyone has resources on how TAWs terrain is encoded?

I could not find something on google.

As I recall, there was some definitive information, regarding the game terrain encoding process, on the SIMHQ forum some time ago, however, they locked it down and made it inaccessible to the public. The basic process of game terrain encoding involves three files: redsea.env, redsea.asc and redsea.lst.

I found out by myself, the ENV and MAP files are indexes for the terrain tiles

Redsea.env is the primary index for the game terrain tiles. It consists of a 2-byte index structure which contains indices for 999 files. A randomization process within the .lst file allows the game terrain to utilize greater than 999 files, however, the index itself is limited at a maximum of 999 by the first line in the redsea.asc file.

The redse_.map file is the index for the moving map of the terrain found in the cockpit Situation MFD.

Does anyone have a list which index means which tile? Are the tiles .3 files?

Yes, there is a list. Mike compiled the list so perhaps he will also respond to this inquiry.

No, the tiles called are not .3 files but .ssd files.

Hope that helps :)

Share this post


Link to post
Share on other sites

Thank you, this is very valuable!

The redse_.map file is the index for the moving map of the terrain found in the cockpit Situation MFD.

I would never have found that out myself.

I see the structure of the redsea.lst file as following:


offset		size		content

0		4 B		"LST1"

4		999 x 8 B	???

8000		1016 x 4 B	string offsets

12068				1016 zero-terminated strings with SSD names

So I guess tile indexes are looked up at 4+index*8 B.

Then there are two DWORD, the first always either 1 or 4 and the second is an index for the next lookup (highest value is 1015, so 1016, 1017 and others seem unused).

Then at 79968000+second_index*4 there is a DWORD with the offset of the SSD name.

Eventually you find the SSD name at 12068+offset B (without ".SSD" extension).

Now that I know which tile is which SSD, I will try to squeeze information out of them. My luck SSDs are documented on TAW Wiki. I ask again when I have new questions.

Share this post


Link to post
Share on other sites

I made a python script to sort through these files and produce a text file showing the grid of tiles that could be opened in Excel....although it looks like I'm a bit late. :)

# Read in all data from redsea.env into byte array

input=file("redsea.env","rb")

env=input.read()


# We only want the first line from redsea.asc

input=file("redsea.asc","r")

asc=input.readline()


# Read in all data from redsea.lst into byte array

input=file("redsea.lst","rb")

lst=input.read()


# Handle .asc: Convert the first line from text to an integer form

ascnum=int(asc,10)


#Handle .env: Calculate the 160000 2-byte indices and put them in a list called env_index

env_index=[]

max=0

d=0

while d < 320000:

    g=ord(env[20+d])+ord(env[21+d])*256

    env_index.append(g)

    if g>max:

        max=g

    d=d+2


# Consistency check: The maximum env index number can't be bigger than that given in asc file

if max+1>ascnum:

    print 'ERROR: Max ENV index greater then value in first line of ASC file.'


#Handle .lst file, which consists of 3 parts after a 4 byte header

#The size of Part 1 is ascnum x 8 bytes

#Of the 8 bytes, the first 4 give the randomization number, and the 2nd 4 give the jump in Part 2

part1_rand=[]

part1_jump=[]

d=0

while d < ascnum*8:

    g=ord(lst[4+d])+ord(lst[5+d])*256

    part1_rand.append(g)

    g=ord(lst[8+d])+ord(lst[9+d])*256

    part1_jump.append(g) 

    d=d+8


#Right at the end of Part 1, there is a 4 byte number giving the number of elements in Part 2

part2num=ord(lst[4+ascnum*8])+ord(lst[5+ascnum*8])*256

#The base address of Part 2 will be 4+ascnum*8 +4

part2base=4+ascnum*8+4


#For some reason there is actually one extra 4 byte number in part 2

#Therefore Part 3 (containing the names) will start at part2base+part2num*4 +4

part3base=part2base+part2num*4+4


#Let us repackage Part 2 into a list with 'normal' numbers instead of byte reversed.

part2_list=[]

d=part2base

while d < part2base+(part2num+1)*4:

    g=ord(lst[d])+ord(lst[d+1])*256

    part2_list.append(g)

    d=d+4


# and we'll split out Part 3 into a separate list, but leave it as a collection of bytes

part3_list=[]

d=part3base

while d < len(lst):

    part3_list.append(lst[d])

    d=d+1


# So, now we have the following arrays, all starting from zero:

# env_index containing the env file pointers

# part1_rand containing the Part 1 randomization number

# part1_jump containing the jump in Part 2

# part2_list containing the index to part 3

# part3_list containing the actual ssd names


# In order to use this data, we could try and visualize the TAW map in Microsoft Excel, by

# producing a semicolon delimited text file.


# The env_index file starts at the top left hand corner of the map and then each subsequent

# index corresponds to the tile below. This is not how we want to visualize it. To get a 

# horizontal raster we have to do some calculations.

# So if the top left is index 0, the tile to the right will be index 400 etc

x=0

y=0


outfile=file('tawmap.txt','w')

while y < 400:

    xline=""

    x=0

    while x<255: #Note, this needs to be 400 for the whole map, but my Office2000 Excel only supports 256 columns

        tileindex=y+(x*400)

        part1index=env_index[tileindex]

        part2index=part1_jump[part1index]

        part3index=part2_list[part2index]

        char=part3_list[part3index]

        if ord(char)==0:

            print "ERROR: Invalid character in ssd name"

        z=0

        ssdname=""

        while ord(char)!=0:

            char=part3_list[part3index+z]

            ssdname=ssdname+char

            z=z+1

        ssdname=ssdname[0:len(ssdname)-1]

        xline=xline+str(x)+" "+str(399-y)+" "+ssdname+";" 

        x=x+1

    outfile.write(xline+'\n')        

    y=y+1    


Share this post


Link to post
Share on other sites

Great! I used the wrong offset 7996 instead of 8000 for part 2 and it didn't work. It does now with your code.

All SSD files are found and every does have a 7A 00 mark where I suspect the .3 file index. I don't know if I am correct with this but the WORD after the mark never exceeded the first line of ssinfo.fn and when interpreted as an index all expected .3 files exist. I'll try to decode them now.

Another question: What does the random number in redsea.lst exactly?

Share this post


Link to post
Share on other sites

You seem to be picking this up very quickly. :thumbsup:

Yes, the numbers between the 7A00 and FFFF are index numbers to the .3 files listed in the file ssinfo.fn.

We already have scripts to decode this list. I'll dig them out later.

The 'random' number allows a single terrain pointer to produce more than one tile, which makes repetitive terrain look better. So, in part 1 of the .lst file, if the 'random' number is 4, there will be 4 pointers in part 2 giving 4 different ssd files in part 3. We're not sure if this is random or whether the terrain just cycles around the 4 values.

Share this post


Link to post
Share on other sites

Thank you for your help! I know now: every SSD points to one or more .3 files. Of whom at least one has a TEX_xx string hardcoded which is the tm texture file of the tile (you see only 0,0 96,96 coordinates in the screenshot here):

tiletest.jpg

I followed this article, but now I have a problem with the correct texture coordinates. Take, for example, desrtm_3.3:

000000F0 00 00 00 03 00 17 00 47

000000F8 00 00 00 5F 00 00 00 47

00000100 00 2F 00 03 00 06 00 00

00000108 00 09 00 2E 00 00 00 03

00000110 00 00 00 5F 00 17 00 47

00000118 00 17 00 5F 00 2F 00 03

It's no problem to find the textured polygon markers 00 47, but

1) there is no texture index (probably because the texture is hardcoded)

2) there is no indicator for the number of vertexes in the polygon

3) the number of texture coordinates is not even dividable by two (so it's not UV)

But 0/17/2F/5F (0/23/47/95 decimal) are clearly terrain texture coordinates. Any clue how to decode them?

Share this post


Link to post
Share on other sites

Thank you for your help!

Welcome Kryzctij. Nice to see another inputing to this vexing detail. :thumbsup: Its all beyond me. :lol:

Share this post


Link to post
Share on other sites

Here is desrtm_3.3 decoded to the rules as we understand them. There aren't any 0047 polygon descriptors in this file and the 002e descriptor is used instead. This uses the texture that is given in the header, TEX_28 in this case. The associated 002f line gives the vertices.

The 0047 polygon descriptors use an index to a texture list in the redxxxx.ini files.

header ;fc003e80000000007fff00000000000007d0000000020003000300000000000000a3000e000b000c000d0000000000000000000000000000215445585f3238002b52000102030001020300000020000000200000002000000019

0000; 00271770000e    ; If Distance >6000 then jump to line 5

0001; 007b000a    ; If 007b flag set, jump to line 5

0002; 00930004    ; If 0093 flag set, jump to line 4

0003; 0000    ;

0004; 0000    ;

0005; 00760004    ; If 0076 flag set, jump to line 7

0006; 0000    ;

0007; 00620000fc00ffb0fc00    ; Vertex :0  X=-1024  Y=80  Z=-1024

0008; 00640200    ; Vertex :1  X=-512  Y=80  Z=-1024

0009; 00640200    ; Vertex :2  X=0  Y=80  Z=-1024

0010; 00640200    ; Vertex :3  X=512  Y=80  Z=-1024

0011; 00640200    ; Vertex :4  X=1024  Y=80  Z=-1024

0012; 00660200    ; Vertex :5  X=1024  Y=80  Z=-512

0013; 0064fa00    ; Vertex :6  X=-512  Y=80  Z=-512

0014; 006401fc    ; Vertex :7  X=-4  Y=80  Z=-512

0015; 006401ff    ; Vertex :8  X=507  Y=80  Z=-512

0016; 0064fa05    ; Vertex :9  X=-1024  Y=80  Z=-512

0017; 00660200    ; Vertex :10  X=-1024  Y=80  Z=0

0018; 00640414    ; Vertex :11  X=20  Y=80  Z=0

0019; 006403ec    ; Vertex :12  X=1024  Y=80  Z=0

0020; 00660200    ; Vertex :13  X=1024  Y=80  Z=512

0021; 0064f800    ; Vertex :14  X=-1024  Y=80  Z=512

0022; 0064040a    ; Vertex :15  X=10  Y=80  Z=512

0023; 006401f6    ; Vertex :16  X=512  Y=80  Z=512

0024; 00660200    ; Vertex :17  X=512  Y=80  Z=1024

0025; 0064fa00    ; Vertex :18  X=-1024  Y=80  Z=1024

0026; 00640200    ; Vertex :19  X=-512  Y=80  Z=1024

0027; 00640200    ; Vertex :20  X=0  Y=80  Z=1024

0028; 00640400    ; Vertex :21  X=1024  Y=80  Z=1024

0029; 0068fa04fe05    ; Vertex :22  X=-508  Y=80  Z=517

0030; 0068002afdf3    ; Vertex :23  X=-466  Y=80  Z=-8

0031; 006803d60014    ; Vertex :24  X=516  Y=80  Z=12

0032; 006100190000    ;

0033; 002717700384    ; If Distance >6000 then jump to line 99

0034; 002e00000003001700470000005f00000047    ;UV Coords: 23,71  0,95   0,71

0035; 002f0003000600000009    ; Texture = TEX_28

0036; 002e000000030000005f001700470017005f    ;UV Coords: 0,95  23,71   23,95

0037; 002f0003000000060001    ; Texture = TEX_28

0038; 002e00000003002f00470017005f00170047    ;UV Coords: 47,71  23,95   23,71

0039; 002f0003000700010006    ; Texture = TEX_28

0040; 002e000000030017005f002f0047002f005f    ;UV Coords: 23,95  47,71   47,95

0041; 002f0003000100070002    ; Texture = TEX_28

0042; 002e00000003002f00470047005f002f005f    ;UV Coords: 47,71  71,95   47,95

0043; 002f0003000700030002    ; Texture = TEX_28

0044; 002e000000030047005f002f004700470047    ;UV Coords: 71,95  47,71   71,71

0045; 002f0003000300070008    ; Texture = TEX_28

0046; 002e0000000300470047005f005f0047005f    ;UV Coords: 71,71  95,95   71,95

0047; 002f0003000800040003    ; Texture = TEX_28

0048; 002e00000003005f005f00470047005f0047    ;UV Coords: 95,95  71,71   95,71

0049; 002f0003000400080005    ; Texture = TEX_28

0050; 002e000000030019002f000000470000002f    ;UV Coords: 25,47  0,71   0,47

0051; 002f000300170009000a    ; Texture = TEX_28

0052; 002e00000003000000470019002f00170047    ;UV Coords: 0,71  25,47   23,71

0053; 002f0003000900170006    ; Texture = TEX_28

0054; 002e000000030030002f001700470019002f    ;UV Coords: 48,47  23,71   25,47

0055; 002f0003000b00060017    ; Texture = TEX_28

0056; 002e00000003001700470030002f002f0047    ;UV Coords: 23,71  48,47   47,71

0057; 002f00030006000b0007    ; Texture = TEX_28

0058; 002e000000030030002f00470047002f0047    ;UV Coords: 48,47  71,71   47,71

0059; 002f0003000b00080007    ; Texture = TEX_28

0060; 002e00000003004700470030002f0047002e    ;UV Coords: 71,71  48,47   71,46

0061; 002f00030008000b0018    ; Texture = TEX_28

0062; 002e000000030047002e005f004700470047    ;UV Coords: 71,46  95,71   71,71

0063; 002f0003001800050008    ; Texture = TEX_28

0064; 002e00000003005f00470047002e005f002f    ;UV Coords: 95,71  71,46   95,47

0065; 002f000300050018000c    ; Texture = TEX_28

0066; 002e00000003000000170019002f0000002f    ;UV Coords: 0,23  25,47   0,47

0067; 002f0003000e0017000a    ; Texture = TEX_28

0068; 002e000000030019002f0000001700170017    ;UV Coords: 25,47  0,23   23,23

0069; 002f00030017000e0016    ; Texture = TEX_28

0070; 002e00000003001700170030002f0019002f    ;UV Coords: 23,23  48,47   25,47

0071; 002f00030016000b0017    ; Texture = TEX_28

0072; 002e000000030030002f00170017002f0017    ;UV Coords: 48,47  23,23   47,23

0073; 002f0003000b0016000f    ; Texture = TEX_28

0074; 002e00000003004700170030002f002f0017    ;UV Coords: 71,23  48,47   47,23

0075; 002f00030010000b000f    ; Texture = TEX_28

0076; 002e000000030030002f004700170047002e    ;UV Coords: 48,47  71,23   71,46

0077; 002f0003000b00100018    ; Texture = TEX_28

0078; 002e00000003005f00170047002e00470017    ;UV Coords: 95,23  71,46   71,23

0079; 002f0003000d00180010    ; Texture = TEX_28

0080; 002e000000030047002e005f0017005f002f    ;UV Coords: 71,46  95,23   95,47

0081; 002f00030018000d000c    ; Texture = TEX_28

0082; 002e00000003000000000017001700000017    ;UV Coords: 0,0  23,23   0,23

0083; 002f000300120016000e    ; Texture = TEX_28

0084; 002e00000003001700170000000000170000    ;UV Coords: 23,23  0,0   23,0

0085; 002f0003001600120013    ; Texture = TEX_28

0086; 002e0000000300170000002f001700170017    ;UV Coords: 23,0  47,23   23,23

0087; 002f00030013000f0016    ; Texture = TEX_28

0088; 002e00000003002f001700170000002f0000    ;UV Coords: 47,23  23,0   47,0

0089; 002f0003000f00130014    ; Texture = TEX_28

0090; 002e0000000300470000002f0017002f0000    ;UV Coords: 71,0  47,23   47,0

0091; 002f00030011000f0014    ; Texture = TEX_28

0092; 002e00000003002f00170047000000470017    ;UV Coords: 47,23  71,0   71,23

0093; 002f0003000f00110010    ; Texture = TEX_28

0094; 002e00000003005f00000047001700470000    ;UV Coords: 95,0  71,23   71,0

0095; 002f0003001500100011    ; Texture = TEX_28

0096; 002e0000000300470017005f0000005f0017    ;UV Coords: 71,23  95,0   95,23

0097; 002f000300100015000d    ; Texture = TEX_28

0098; 0000    ;

0099; 00020018000600000009    ; Flat Shaded Triangle, Palette:24  Vertices: 6,0,9

0100; 0071000000060001    ; Flat Shaded Triangle, Palette:24  Vertices: 0,6,1

0101; 0071000700010006    ; Flat Shaded Triangle, Palette:24  Vertices: 7,1,6

0102; 0071000100070002    ; Flat Shaded Triangle, Palette:24  Vertices: 1,7,2

0103; 0071000700030002    ; Flat Shaded Triangle, Palette:24  Vertices: 7,3,2

0104; 0071000300070008    ; Flat Shaded Triangle, Palette:24  Vertices: 3,7,8

0105; 0071000800040003    ; Flat Shaded Triangle, Palette:24  Vertices: 8,4,3

0106; 0071000400080005    ; Flat Shaded Triangle, Palette:24  Vertices: 4,8,5

0107; 007100170009000a    ; Flat Shaded Triangle, Palette:24  Vertices: 23,9,10

0108; 0071000900170006    ; Flat Shaded Triangle, Palette:24  Vertices: 9,23,6

0109; 0071000b00060017    ; Flat Shaded Triangle, Palette:24  Vertices: 11,6,23

0110; 00710006000b0007    ; Flat Shaded Triangle, Palette:24  Vertices: 6,11,7

0111; 0071000b00080007    ; Flat Shaded Triangle, Palette:24  Vertices: 11,8,7

0112; 00710008000b0018    ; Flat Shaded Triangle, Palette:24  Vertices: 8,11,24

0113; 0071001800050008    ; Flat Shaded Triangle, Palette:24  Vertices: 24,5,8

0114; 007100050018000c    ; Flat Shaded Triangle, Palette:24  Vertices: 5,24,12

0115; 0071000e0017000a    ; Flat Shaded Triangle, Palette:24  Vertices: 14,23,10

0116; 00710017000e0016    ; Flat Shaded Triangle, Palette:24  Vertices: 23,14,22

0117; 00710016000b0017    ; Flat Shaded Triangle, Palette:24  Vertices: 22,11,23

0118; 0071000b0016000f    ; Flat Shaded Triangle, Palette:24  Vertices: 11,22,15

0119; 00710010000b000f    ; Flat Shaded Triangle, Palette:24  Vertices: 16,11,15

0120; 0071000b00100018    ; Flat Shaded Triangle, Palette:24  Vertices: 11,16,24

0121; 0071000d00180010    ; Flat Shaded Triangle, Palette:24  Vertices: 13,24,16

0122; 00710018000d000c    ; Flat Shaded Triangle, Palette:24  Vertices: 24,13,12

0123; 007100120016000e    ; Flat Shaded Triangle, Palette:24  Vertices: 18,22,14

0124; 0071001600120013    ; Flat Shaded Triangle, Palette:24  Vertices: 22,18,19

0125; 00710013000f0016    ; Flat Shaded Triangle, Palette:24  Vertices: 19,15,22

0126; 0071000f00130014    ; Flat Shaded Triangle, Palette:24  Vertices: 15,19,20

0127; 00710011000f0014    ; Flat Shaded Triangle, Palette:24  Vertices: 17,15,20

0128; 0071000f00110010    ; Flat Shaded Triangle, Palette:24  Vertices: 15,17,16

0129; 0071001500100011    ; Flat Shaded Triangle, Palette:24  Vertices: 21,16,17

0130; 007100100015000d    ; Flat Shaded Triangle, Palette:24  Vertices: 16,21,13

0131; 0000    ;

0132; ffff    ;

0133; ffff    ;

Share this post


Link to post
Share on other sites

Wombat1940,

thank you!

mikew,

thank you again for your help, it really pushes me forward. Very mean of TAW to use big endian numbers ... unless they wrote the files by their hand :) I have a few questions remaining though.

In your example, the vertexes have a Y coordinate of 80. But the original value is FFB0 (-80). Do I have to invert all Y coordinates of all models?

You marked all lines starting with 002F as "Texture = TEX_28". How is this texture information? From what I see, 002F means "textured polygon", 0003 is the number of vertexes and the three other words are indexes (they are identical to the indexes in the flat-shaded triangle at the end).

Share this post


Link to post
Share on other sites

I've inverted the Y coordinates for now, since it seems to make more sense when plotting out the models. eg for the terrain, 0 is sea level and hills have a height given in negative numbers.

I put the "Texture = TEX_28" comment on the 002f line simply because there is more room. It should be associated with the line above. The value TEX_28 is read from the 'header' where it is gven in plain ascii (215445585f3238)

Share this post


Link to post
Share on other sites

O.K., so it was just a little misunderstanding :)

I'm now able to parse many .3 files, but not all. A few questions:

  1. Can you please post an analysis of DIS_1RWY.3? It is particular difficult to me: While in most other models I can just skip the unknown sections, my parser always crashes with this file (after the 4th textured triangle). There are a lot of sections unknown to me in it (e.g. 0008 and 0048).
  2. What is the 0015 section (14x2 B data e.g. in ARABLC_2.3 and usually half as many as triangles)? This is quite a huge chunk of data and I feel I will miss it if I just skip.
  3. What is the 002D section (2x2 B data)?
  4. Is there a special meaning to some vertex lists being padded with 0000 (e.g. DESERTM_1.3), others with 0001 (e.g. DUNESC_2.3)?

Share this post


Link to post
Share on other sites

Question 1....

The .3 file branches based on some external parameter. It's either 0, where the model continues, or 2 where we effectively exit the model and draw nothing else.

header;fc003e80000000007fff00000000000007d0000000020003000300000000000000a3000e000b000c000d0000000000000000000000000000215445585f3238002b520c0d0e0f0001020300000020000000200000002000000019

0000; 00271770000e    ; If Distance >6000 then jump to line 5

0001; 007b000a    ; If 007b flag set, jump to line 5

0002; 00930004    ; If 0093 flag set, jump to line 4

0003; 0000    ;

0004; 0000    ;

0005; 00760004    ; If 0076 flag set, jump to line 7

0006; 0000    ;

0007; 00620000fc00ffb0fc00    ; Vertex :0  X=-1024  Y=80  Z=-1024

0008; 00640200    ; Vertex :1  X=-512  Y=80  Z=-1024

0009; 00640200    ; Vertex :2  X=0  Y=80  Z=-1024

0010; 00640200    ; Vertex :3  X=512  Y=80  Z=-1024

0011; 00640200    ; Vertex :4  X=1024  Y=80  Z=-1024

0012; 00660200    ; Vertex :5  X=1024  Y=80  Z=-512

0013; 0064fa00    ; Vertex :6  X=-512  Y=80  Z=-512

0014; 00640200    ; Vertex :7  X=0  Y=80  Z=-512

0015; 00640200    ; Vertex :8  X=512  Y=80  Z=-512

0016; 0064fa00    ; Vertex :9  X=-1024  Y=80  Z=-512

0017; 00660200    ; Vertex :10  X=-1024  Y=80  Z=0

0018; 00640200    ; Vertex :11  X=-512  Y=80  Z=0

0019; 00640200    ; Vertex :12  X=0  Y=80  Z=0

0020; 00640200    ; Vertex :13  X=512  Y=80  Z=0

0021; 00640200    ; Vertex :14  X=1024  Y=80  Z=0

0022; 00660200    ; Vertex :15  X=1024  Y=80  Z=512

0023; 0064fa00    ; Vertex :16  X=-512  Y=80  Z=512

0024; 00640200    ; Vertex :17  X=0  Y=80  Z=512

0025; 00640200    ; Vertex :18  X=512  Y=80  Z=512

0026; 0064fa00    ; Vertex :19  X=-1024  Y=80  Z=512

0027; 00660200    ; Vertex :20  X=-1024  Y=80  Z=1024

0028; 00640200    ; Vertex :21  X=-512  Y=80  Z=1024

0029; 00640200    ; Vertex :22  X=0  Y=80  Z=1024

0030; 00640200    ; Vertex :23  X=512  Y=80  Z=1024

0031; 00640200    ; Vertex :24  X=1024  Y=80  Z=1024

0032; 006100190000    ;

0033; 0027177005fc    ; If Distance >6000 then jump to line 188

0034; 0008003e    ; Jump to Sub at line 50

0035; 00080074    ; Jump to Sub at line 55

0036; 000800e2    ; Jump to Sub at line 66

0037; 00080150    ; Jump to Sub at line 77

0038; 000801be    ; Jump to Sub at line 88

0039; 0008022c    ; Jump to Sub at line 99

0040; 0008029a    ; Jump to Sub at line 110

0041; 000802ba    ; Jump to Sub at line 113

0042; 00080328    ; Jump to Sub at line 124

0043; 00080396    ; Jump to Sub at line 135

0044; 00080404    ; Jump to Sub at line 146

0045; 00080472    ; Jump to Sub at line 157

0046; 000804e0    ; Jump to Sub at line 168

0047; 00080516    ; Jump to Sub at line 173

0048; 0008054c    ; Jump to Sub at line 178

0049; 00080582    ; Jump to Sub at line 183

0050; 002e00000003007700a7006000bf006000a7    ;UV Coords: 119,167  96,191   96,167

0051; 002f0003000600000009    ; Texture = TEX_28

0052; 002e00000003006000bf007700a7007700bf    ;UV Coords: 96,191  119,167   119,191

0053; 002f0003000000060001    ; Texture = TEX_28

0054; 0000    ;

0055; 002e00000003008f00a7007700bf007700a7    ;UV Coords: 143,167  119,191   119,167

0056; 002f0003000700010006    ; Texture = TEX_28

0057; 002e00000003007700bf008f00a7008f00bf    ;UV Coords: 119,191  143,167   143,191

0058; 002f0003000100070002    ; Texture = TEX_28

0059; 00480000    ;

0060; 00210000000e    ; If Parameter 0000 = 0 then jump to line 63

0061; 00210002063e    ; If Parameter 0000 = 2 then jump to line 221

0062; 00270fa00638    ; If Distance >4000 then jump to line 221

0063; 00470022000400c0003000ef003000ef005f00c0005f    ;UV Coords: 192,48 239,48  239,95  192,95

0064; 008e00040006000700020001    ; Texture = TRG_2

0065; 0000    ;

0066; 002e00000003008f00a700a700bf008f00bf    ;UV Coords: 143,167  167,191   143,191

0067; 002f0003000700030002    ; Texture = TEX_28

0068; 002e0000000300a700bf008f00a700a700a7    ;UV Coords: 167,191  143,167   167,167

0069; 002f0003000300070008    ; Texture = TEX_28

0070; 00480000    ;

0071; 00210000000e    ; If Parameter 0000 = 0 then jump to line 74

0072; 0021000205cc    ; If Parameter 0000 = 2 then jump to line 221

0073; 00270fa005c6    ; If Distance >4000 then jump to line 221

0074; 00470021000400c0000000ef000000ef002f00c0002f    ;UV Coords: 192,0 239,0  239,47  192,47

0075; 008e00040007000800030002    ; Texture = TRG_1

0076; 0000    ;

0077; 002e0000000300a700a700bf00bf00a700bf    ;UV Coords: 167,167  191,191   167,191

0078; 002f0003000800040003    ; Texture = TEX_28

0079; 002e0000000300bf00bf00a700a700bf00a7    ;UV Coords: 191,191  167,167   191,167

0080; 002f0003000400080005    ; Texture = TEX_28

0081; 00480000    ;

0082; 00210000000e    ; If Parameter 0000 = 0 then jump to line 85

0083; 00210002055a    ; If Parameter 0000 = 2 then jump to line 221

0084; 00270fa00554    ; If Distance >4000 then jump to line 221

0085; 00470022000400c0000000ef000000ef002f00c0002f    ;UV Coords: 192,0 239,0  239,47  192,47

0086; 008e00040008000500040003    ; Texture = TRG_2

0087; 0000    ;

0088; 002e000000030079008f006000a70060008f    ;UV Coords: 121,143  96,167   96,143

0089; 002f0003000b0009000a    ; Texture = TEX_28

0090; 002e00000003006000a70079008f007700a7    ;UV Coords: 96,167  121,143   119,167

0091; 002f00030009000b0006    ; Texture = TEX_28

0092; 00480000    ;

0093; 00210000000e    ; If Parameter 0000 = 0 then jump to line 96

0094; 0021000204e8    ; If Parameter 0000 = 2 then jump to line 221

0095; 00270fa004e2    ; If Distance >4000 then jump to line 221

0096; 00470022000400c0003000ef003000ef005f00c0005f    ;UV Coords: 192,48 239,48  239,95  192,95

0097; 008e0004000a000b00060009    ; Texture = TRG_2

0098; 0000    ;

0099; 002e000000030090008f007700a70079008f    ;UV Coords: 144,143  119,167   121,143

0100; 002f0003000c0006000b    ; Texture = TEX_28

0101; 002e00000003007700a70090008f008f00a7    ;UV Coords: 119,167  144,143   143,167

0102; 002f00030006000c0007    ; Texture = TEX_28

0103; 00480000    ;

0104; 00210000000e    ; If Parameter 0000 = 0 then jump to line 107

0105; 002100020476    ; If Parameter 0000 = 2 then jump to line 221

0106; 00270fa00470    ; If Distance >4000 then jump to line 221

0107; 00470023000400c0003000ef003000ef005f00c0005f    ;UV Coords: 192,48 239,48  239,95  192,95

0108; 008e0004000b000c00070006    ; Texture = TRG_3

0109; 0000    ;

0110; 00470024000400c1003000ef003000ef005f00c1005f    ;UV Coords: 193,48 239,48  239,95  193,95

0111; 002f0004000c000d00080007    ; Texture = TRG_4

0112; 0000    ;

0113; 002e0000000300a7008e00bf00a700a700a7    ;UV Coords: 167,142  191,167   167,167

0114; 002f0003000d00050008    ; Texture = TEX_28

0115; 002e0000000300bf00a700a7008e00bf008f    ;UV Coords: 191,167  167,142   191,143

0116; 002f00030005000d000e    ; Texture = TEX_28

0117; 00480000    ;

0118; 00210000000e    ; If Parameter 0000 = 0 then jump to line 121

0119; 0021000203e0    ; If Parameter 0000 = 2 then jump to line 221

0120; 00270fa003da    ; If Distance >4000 then jump to line 221

0121; 00470021000400c0009000ef009000ef00bf00c000bf    ;UV Coords: 192,144 239,144  239,191  192,191

0122; 008e0004000d000e00050008    ; Texture = TRG_1

0123; 0000    ;

0124; 002e00000003006000770079008f0060008f    ;UV Coords: 96,119  121,143   96,143

0125; 002f00030013000b000a    ; Texture = TEX_28

0126; 002e000000030079008f0060007700770077    ;UV Coords: 121,143  96,119   119,119

0127; 002f0003000b00130010    ; Texture = TEX_28

0128; 00480000    ;

0129; 00210000000e    ; If Parameter 0000 = 0 then jump to line 132

0130; 00210002036e    ; If Parameter 0000 = 2 then jump to line 221

0131; 00270fa00368    ; If Distance >4000 then jump to line 221

0132; 00470022000400c0006000ef006000ef008f00c0008f    ;UV Coords: 192,96 239,96  239,143  192,143

0133; 008e000400130010000b000a    ; Texture = TRG_2

0134; 0000    ;

0135; 002e00000003007700770090008f0079008f    ;UV Coords: 119,119  144,143   121,143

0136; 002f00030010000c000b    ; Texture = TEX_28

0137; 002e000000030090008f00770077008f0077    ;UV Coords: 144,143  119,119   143,119

0138; 002f0003000c00100011    ; Texture = TEX_28

0139; 00480000    ;

0140; 00210000000e    ; If Parameter 0000 = 0 then jump to line 143

0141; 0021000202fc    ; If Parameter 0000 = 2 then jump to line 221

0142; 00270fa002f6    ; If Distance >4000 then jump to line 221

0143; 00470021000400c0006000ef006000ef008f00c0008f    ;UV Coords: 192,96 239,96  239,143  192,143

0144; 008e000400100011000c000b    ; Texture = TRG_1

0145; 0000    ;

0146; 002e0000000300a700770090008f008f0077    ;UV Coords: 167,119  144,143   143,119

0147; 002f00030012000c0011    ; Texture = TEX_28

0148; 002e000000030090008f00a7007700a7008e    ;UV Coords: 144,143  167,119   167,142

0149; 002f0003000c0012000d    ; Texture = TEX_28

0150; 00480000    ;

0151; 00210000000e    ; If Parameter 0000 = 0 then jump to line 154

0152; 00210002028a    ; If Parameter 0000 = 2 then jump to line 221

0153; 00270fa00284    ; If Distance >4000 then jump to line 221

0154; 00470021000400c0006000ef006000ef008f00c0008f    ;UV Coords: 192,96 239,96  239,143  192,143

0155; 008e000400110012000d000c    ; Texture = TRG_1

0156; 0000    ;

0157; 002e0000000300bf007700a7008e00a70077    ;UV Coords: 191,119  167,142   167,119

0158; 002f0003000f000d0012    ; Texture = TEX_28

0159; 002e0000000300a7008e00bf007700bf008f    ;UV Coords: 167,142  191,119   191,143

0160; 002f0003000d000f000e    ; Texture = TEX_28

0161; 00480000    ;

0162; 00210000000e    ; If Parameter 0000 = 0 then jump to line 165

0163; 002100020218    ; If Parameter 0000 = 2 then jump to line 221

0164; 00270fa00212    ; If Distance >4000 then jump to line 221

0165; 00470022000400c0009000ef009000ef00bf00c000bf    ;UV Coords: 192,144 239,144  239,191  192,191

0166; 008e00040012000f000e000d    ; Texture = TRG_2

0167; 0000    ;

0168; 002e00000003006000600077007700600077    ;UV Coords: 96,96  119,119   96,119

0169; 002f0003001400100013    ; Texture = TEX_28

0170; 002e00000003007700770060006000770060    ;UV Coords: 119,119  96,96   119,96

0171; 002f0003001000140015    ; Texture = TEX_28

0172; 0000    ;

0173; 002e0000000300770060008f007700770077    ;UV Coords: 119,96  143,119   119,119

0174; 002f0003001500110010    ; Texture = TEX_28

0175; 002e00000003008f007700770060008f0060    ;UV Coords: 143,119  119,96   143,96

0176; 002f0003001100150016    ; Texture = TEX_28

0177; 0000    ;

0178; 002e0000000300a70060008f0077008f0060    ;UV Coords: 167,96  143,119   143,96

0179; 002f0003001700110016    ; Texture = TEX_28

0180; 002e00000003008f007700a7006000a70077    ;UV Coords: 143,119  167,96   167,119

0181; 002f0003001100170012    ; Texture = TEX_28

0182; 0000    ;

0183; 002e0000000300bf006000a7007700a70060    ;UV Coords: 191,96  167,119   167,96

0184; 002f0003001800120017    ; Texture = TEX_28

0185; 002e0000000300a7007700bf006000bf0077    ;UV Coords: 167,119  191,96   191,119

0186; 002f000300120018000f    ; Texture = TEX_28

0187; 0000    ;

0188; 00020018000600000009    ; Flat Shaded Triangle, Palette:24  Vertices: 6,0,9

0189; 0071000000060001    ; Flat Shaded Triangle, Palette:24  Vertices: 0,6,1

0190; 0071000700010006    ; Flat Shaded Triangle, Palette:24  Vertices: 7,1,6

0191; 0071000100070002    ; Flat Shaded Triangle, Palette:24  Vertices: 1,7,2

0192; 0071000700030002    ; Flat Shaded Triangle, Palette:24  Vertices: 7,3,2

0193; 0071000300070008    ; Flat Shaded Triangle, Palette:24  Vertices: 3,7,8

0194; 0071000800040003    ; Flat Shaded Triangle, Palette:24  Vertices: 8,4,3

0195; 0071000400080005    ; Flat Shaded Triangle, Palette:24  Vertices: 4,8,5

0196; 0071000b0009000a    ; Flat Shaded Triangle, Palette:24  Vertices: 11,9,10

0197; 00710009000b0006    ; Flat Shaded Triangle, Palette:24  Vertices: 9,11,6

0198; 0071000c0006000b    ; Flat Shaded Triangle, Palette:24  Vertices: 12,6,11

0199; 00710006000c0007    ; Flat Shaded Triangle, Palette:24  Vertices: 6,12,7

0200; 0071000c00080007    ; Flat Shaded Triangle, Palette:24  Vertices: 12,8,7

0201; 00710008000c000d    ; Flat Shaded Triangle, Palette:24  Vertices: 8,12,13

0202; 0071000d00050008    ; Flat Shaded Triangle, Palette:24  Vertices: 13,5,8

0203; 00710005000d000e    ; Flat Shaded Triangle, Palette:24  Vertices: 5,13,14

0204; 00710013000b000a    ; Flat Shaded Triangle, Palette:24  Vertices: 19,11,10

0205; 0071000b00130010    ; Flat Shaded Triangle, Palette:24  Vertices: 11,19,16

0206; 00710010000c000b    ; Flat Shaded Triangle, Palette:24  Vertices: 16,12,11

0207; 0071000c00100011    ; Flat Shaded Triangle, Palette:24  Vertices: 12,16,17

0208; 00710012000c0011    ; Flat Shaded Triangle, Palette:24  Vertices: 18,12,17

0209; 0071000c0012000d    ; Flat Shaded Triangle, Palette:24  Vertices: 12,18,13

0210; 0071000f000d0012    ; Flat Shaded Triangle, Palette:24  Vertices: 15,13,18

0211; 0071000d000f000e    ; Flat Shaded Triangle, Palette:24  Vertices: 13,15,14

0212; 0071001400100013    ; Flat Shaded Triangle, Palette:24  Vertices: 20,16,19

0213; 0071001000140015    ; Flat Shaded Triangle, Palette:24  Vertices: 16,20,21

0214; 0071001500110010    ; Flat Shaded Triangle, Palette:24  Vertices: 21,17,16

0215; 0071001100150016    ; Flat Shaded Triangle, Palette:24  Vertices: 17,21,22

0216; 0071001700110016    ; Flat Shaded Triangle, Palette:24  Vertices: 23,17,22

0217; 0071001100170012    ; Flat Shaded Triangle, Palette:24  Vertices: 17,23,18

0218; 0071001800120017    ; Flat Shaded Triangle, Palette:24  Vertices: 24,18,23

0219; 007100120018000f    ; Flat Shaded Triangle, Palette:24  Vertices: 18,24,15

0220; 0000    ;

0221; 0000    ;

0222; ffff    ;

0223; ffff    ;

Share this post


Link to post
Share on other sites

Question 2.

The 0015 block gives a rendering order based on some test of 3 vertices.

Here's an example:

0038; 00150014001b0011000c    ; If 0015 test on vertices 20,27,17 fails, jump to 42

0039; 00080030    ; Jump to Sub at line 52

0040; 0008000e    ; Jump to Sub at line 45

0041; 0000    ;

0042; 00080008    ; Jump to Sub at line 45

0043; 00080022    ; Jump to Sub at line 52

0044; 0000    ;

Question 3.

No idea...and I'd really like to know what this does.

It appears to be sort of vertex test, which if true (or false) jumps by the amount given in the third pair of bytes.

Question 4.

I assume you mean the 2 bytes immediately following 0062?

This gives the vertex index number which acts as a base for a group of vertex descriptors.

In the case of dunesc_2.3, the first vertex 0000 looks like it's being used for the 002d test, while vertex 0001 may be the start of the vertex list linked to the visible polygons....or something like that. :)

Share this post


Link to post
Share on other sites

Thank you again for your patience. It helps me a lot!

Question 4.

I assume you mean the 2 bytes immediately following 0062?

This gives the vertex index number which acts as a base for a group of vertex descriptors.

No, I meant the 0061 opcode. There are 2 bytes giving you the number of vertices before and then there are 2 bytes which are often 0000 or sometimes 0001. It was wrong me calling them padding, sorry.

The two bytes after 0062, btw, are an arbitrary base index if this is the first 0062 in the file. Afterwards, they are always the total number of vertexes until that point + base index. (Or at least this is true for any terrain .3 file.)

Share this post


Link to post
Share on other sites

Ah, the 0061 opcode seems to be some sort of operation on the vertices, maybe to load them into a buffer or something.

0061001e0001

So, this may mean "Load 001E (30) vertices starting at vertex index 0001"

This is pure speculation though. The 0061 (and 0075) codes are not really needed to understand what a model will look like, but must be an important part of how the engine works.

Share this post


Link to post
Share on other sites

Just wanting to show you the first .3 file I rendered a few moments ago. It is DESRTM_3.3 with 1200PAL.COL palette. Very very simple but I am hopeful that by next weekend I have a working viewer for very basic .3 files (it is unstable prototype atm) :)

viewern.jpg

The model is first parsed, then a virtual machine runs the bytecode and writes the output from all commands to a vertex buffer where Direct3D 9 can render it from. I already see a typo where 002F is written instead of 002E, I'm stupid :)

Share this post


Link to post
Share on other sites

Just wanting to show you the first .3 file I rendered a few moments ago. It is DESRTM_3.3 with 1200PAL.COL palette. Very very simple but I am hopeful that by next weekend I have a working viewer for very basic .3 files (it is unstable prototype atm) :)

viewern.jpg

The model is first parsed, then a virtual machine runs the bytecode and writes the output from all commands to a vertex buffer where Direct3D 9 can render it from. I already see a typo where 002F is written instead of 002E, I'm stupid :)

Nice! I'll be interested to see your working viewer, every additional tool is a benefit :thumbsup:

Share this post


Link to post
Share on other sites

Thank you! I see got dunesc_4.3 working:

dunev.jpg

Still long way to go, but I sleep first because sun is already rising on the horizon.

Share this post


Link to post
Share on other sites

Well if this starts to get big and you need some extra processing power, I might be able to give you some number crunchers.

My own computer with a 4GHz i7 and of course an older Core 2 Quad that is 100% availible should it need some number crunching, cracking this engine open is indeed the first step we have to take.

Share this post


Link to post
Share on other sites

Excellent work Krycztij!

Great to see someone else take this on. :thumbsup:

Share this post


Link to post
Share on other sites

Thank you again. At the moment I am not low on processor. I am low on brain :) I can now render almost all terrain tiles:

tilese.jpg

But I have failed at loading any other model. I will now implement multitextureing so rivers and cities are visible on the tiles. Then I'll look into other models. Still way to go but it's always going forward :)

Share this post


Link to post
Share on other sites

You're making excellent progress, but there are a few fundamental things that need to be understood before tackling the more complicated models.

This basically involves setting the attributes needed to draw the model, and knowing where the camera position is in relation to the model so that polygons are drawn in the correct order.

Even in the simplest terrain models, the terrain is drawn either with textured polyons when close, or shaded polygons when further away. This decision is made with a 0027 opcode.

I kind of know what needs to be done, but not how to do it. You seem to be a skilled programmer, so now we have some hope. :)

Share this post


Link to post
Share on other sites

What do you mean with the correct order? From what I see the order is encoded in the .3 program and the 0015 tests (occlusion tests?) say in what order the triangles are rendererd. So as long as I follow the .3 program, everything should be fine is my thinking. At the moment I have depth buffering enabled and always just return TRUE for the 0015 test so everything is drawn.

I already implemented flat shading, but it does not look good and so I never showed screenshots :) This is bottom-left tile from a distance of 10000:

flatn.jpg

Your answers are always much helpful to me. Now even more because I must see how to organize the polygons in the program instead of study hex code all the time ;) Can you tell me what the difference between 008E and 002F is? I think they do exactly the same (render polygons with texture coordinates from previous instruction, e.g. 0047 or 002E).

Share this post


Link to post
Share on other sites

TAW doesn't use depth buffering, so the 0015 lines are important if we want to see a model as TAW would display it, since it may be helpful in hunting down problems etc.

If you just want to see what the model looks like, then its fine to just render everything and let the depth buffer handle it.

002F seems to apply bilinear (or some other) filtering, since polygons look a lot smoother than those using 008E.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now