Forums » Modern Era - Air Combat » F-22 Total Air War » .3 Files

Page 1 of 10 1 2 3 ... 9 10 >
Topic Options
Rate This Topic
Hop to:
#2735378 - 06/01/09 12:35 PM .3 Files
mikew Online   smile
SimHQ Member

Registered: 02/26/01
Posts: 1703
Loc: UK
Due to overwhelming demand, I'm starting a thread to summarize the current knowledge of .3 files, and to spur a new thrust for additional insights. The idea is to break down this task into smaller chunks, producing simple tools as necessary.

The .3 files are scripts which tell the game engine how to draw objects. On first glance, they are just binary data. But, after some research, it has been found that the files can be broken down into lines of 'opcodes' which describe how the vertices and polygons go together.

First, we need a tool to take the binary data and reformat it into ASCII text, so it can be edited more easily, then be able to produce a binary file again for testing in the game.

I've created an extremely user-unfriendly tool here:
http://rapidshare.com/files/239704747/parse_3.zip

You can put any .3 files you want to process in the '3_in' directory. When you press the 'Convert to Text' button, all the files in the directory will be processed and the results placed in the '3txt_out' directory. A similar procedure is used to convert back to .3 format again.


Top Bookmark and Share
#2735600 - 06/01/09 07:37 PM Re: .3 Files [Re: mikew]
DrKevDog Offline
SimHQ Member

Registered: 06/27/06
Posts: 596
Thanks M,

I will look forward to working on this when I dig out from the meltdown that once was my TAW data/test PC. I lost about three years worth of unsalvagable data and am currently reformatting the HDD by necessity. Fortunately I think most of it can be reconstructed from my backup files so please make sure your files are backed up.

Thanks for your continuing work on this project cool

Top Bookmark and Share
#2736042 - 06/02/09 11:45 AM Re: .3 Files [Re: DrKevDog]
mikew Online   smile
SimHQ Member

Registered: 02/26/01
Posts: 1703
Loc: UK
DKD, hope you get sorted out soon. I need all the help I can get, especially since Polak is absent.

Anyway, if we take one of the simplest examples of a .3 file, one of the F22 control surfaces, 'f22_30.3' and pass it through the parser in verbose mode, we get this:

Code:
f22_30.3;
header;FEC03E80000000007FFF00000000000000000000
header;0002000300030000000000000087000700040005
header;00060000000000000020000000200000002000000007
0000;007B0004
0001;0000
0002;00620000000000000000
0003;00750000
0004;00490000E3C0000000000000000000000000000000000004
0005;0000
0006;00620001FEF000000140
0007;0066FFA8
0008;00650007
0009;00680228FE20
0010;0065FFF9
0011;00660050
0012;006100060001
0013;0048000A
0014;002100000016
0015;0021000100AE
0016;002100020146
0017;0021000301DE
0018;0000
0019;0047001D00030000008900B70089000E007B
0020;002F0003000500020006
0021;0047001D000300C5007B000E007B00B70089
0022;002F0003000100060002
0023;0047001D0003000E006B00B7007900000079
0024;002F0003000600030004
0025;0047001D000300B70079000E006B00C5006B
0026;002F0003000300060001
0027;004CBABAC000
0028;0080000500060004
0029;004CC0BABA00
0030;0080000300010002
0031;004EBAC0C0BA
0032;00810005000400030002
0033;0000
0034;0047004500030000008900B70089000E007B
0035;002F0003000500020006
0036;00470045000300C5007B000E007B00B70089
0037;002F0003000100060002
0038;004700450003000E006B00B7007900000079
0039;002F0003000600030004
0040;00470045000300B70079000E006B00C5006B
0041;002F0003000300060001
0042;004CBABAC000
0043;0080000500060004
0044;004CC0BABA00
0045;0080000300010002
0046;004EBAC0C0BA
0047;00810005000400030002
0048;0000
0049;0047000C00030000008900B70089000E007B
0050;002F0003000500020006
0051;0047000C000300C5007B000E007B00B70089
0052;002F0003000100060002
0053;0047000C0003000E006B00B7007900000079
0054;002F0003000600030004
0055;0047000C000300B70079000E006B00C5006B
0056;002F0003000300060001
0057;004CBABAC000
0058;0080000500060004
0059;004CC0BABA00
0060;0080000300010002
0061;004EBAC0C0BA
0062;00810005000400030002
0063;0000
0064;0047002700030000008900B70089000E007B
0065;002F0003000500020006
0066;00470027000300C5007B000E007B00B70089
0067;002F0003000100060002
0068;004700270003000E006B00B7007900000079
0069;002F0003000600030004
0070;00470027000300B70079000E006B00C5006B
0071;002F0003000300060001
0072;004CBABAC000
0073;0080000500060004
0074;004CC0BABA00
0075;0080000300010002
0076;004EBAC0C0BA
0077;00810005000400030002
0078;0000
0079;FFFF
0080;FFFF 


The 2nd,3rd and 4th lines can be classed as a 'header'. The header is likely the area where data specific to a particular object is placed during runtime. Other than that, not much is known. The last two bytes (0007) do give the total number of vertices used by the model.

Top Bookmark and Share
#2736059 - 06/02/09 12:09 PM Re: .3 Files [Re: mikew]
mikew Online   smile
SimHQ Member

Registered: 02/26/01
Posts: 1703
Loc: UK
In verbose mode, the parser puts in line numbers which may help with navigating the file.

I have no idea what line numbers 0000 through 0005 do, although the '0049' opcode has something to do with rotation, in this case relating to vertex index 0.

Lines 0006 to 0012 describe the XYZ coordinates of the 6 remaining vertices. The starting point is set with the '0062' opcode on line 0006:
00620001FEF000000140
This can be broken down to the following:
0062=opcode
0001=vertex index=1
FEF0=X coordinate=-272 decimal
0000=Y coordinate=0
0140=Z coordinate=320

The following lines 0007-0011 then give the positions of the subsequent vertices relative to the one before, so for line 0007:
0066FFA8 (FFA8=-88 decimal)
The '0066' operator only gives the Z-axis translation, so that vertex 2 will be positioned at:
X,Y,Z
X=-272,Y=0,Z=320-88=232

Lines 0008 to 0011 are similarly handled according to the following rules for each opcode:
0062 vvvv xxxx yyyy zzzz
0063 xxxx yyyy zzzz
0064 xxxx
0065 yyyy
0066 zzzz
0067 xxxx yyyy
0068 xxxx zzzz
0069 yyyy zzzz

I'm not sure of the exact purpose of line 12:
006100060001
but the '0061' operator gives the number of vertices described in the preceding lines (6) and the starting vertex (1).

Top Bookmark and Share
#2736075 - 06/02/09 12:23 PM Re: .3 Files [Re: mikew]
mikew Online   smile
SimHQ Member

Registered: 02/26/01
Posts: 1703
Loc: UK
Next, comes lines 0013 to 0018:
0048000A
002100000016
0021000100AE
002100020146
0021000301DE
0000

This is a decision block, identified by the '0048' opcode. The decision in this case is based on the value contained in 'variable 000A'. I don't know where this variable is actually stored, but it is very possibly in the 'header'.

The '0021' opcode can be considered as an '=' operator followed by a jump.
Thus, 002100000016 can be read as 'If the value of variable 000A=0 then jump 0016 bytes'. The jump distance includes the '0016' itself.

If we count the bytes, this takes us to the start of line 0019.

The other 3 '0021' lines take us to the start of lines 0034,0049 and 0064 respectively. The blocks starting at these lines are practically identical to that starting at 0019, which is the only one I'm going to go through in detail.

Top Bookmark and Share
#2736086 - 06/02/09 12:44 PM Re: .3 Files [Re: mikew]
mikew Online   smile
SimHQ Member

Registered: 02/26/01
Posts: 1703
Loc: UK
Finally, we have lines 0019 to 0033 which describe the polygons.
Lines 0019 & 0020 should be treated as a pair:
0047001D00030000008900B70089000E007B
002F0003000500020006

This can be broken down as follows:
0047 This is the opcode for a textured polygon
001D Index number of texture from the file 'redXXXX.ini' in the 3 folder (cam3_7)
0003 Three sided figure, ie triangle
0000 0089 Texture coordinate of vertex 5 (taken from 002F line)
00B7 0089 Texture coordinate of vertex 2
000E 007B Texture coordinate of vertex 6

The texture coordinates are referenced to the top left corner of the texture, with an X coordinate between 0-255dec, and a Y coordinate in the range 0-191dec.

Lines 0021 to 0026 describe 3 more textured polygons.

Then comes 3 shaded polygons in lines 0027 to 0032. The following must be trated as a pair:
004CBABAC000
0080000500060004

The '004C' opcode is for shaded triangle, and taken together with the following '0080' line, can be interpreted thus:

Vertex 0005 uses palette colour BA
Vertex 0006 uses palette colour BA
Vertex 0004 uses palette colour C0

In this case,vertices 0005 and 0006 will be the same colour and there should be a smooth gradient across the triangle to the colour at vertex 0004.

The following lines can be treated similarly, noting that the 004E/0081 opcode combination relates to 4 sided polygons.

Top Bookmark and Share
#2736113 - 06/02/09 01:11 PM Re: .3 Files [Re: mikew]
mikew Online   smile
SimHQ Member

Registered: 02/26/01
Posts: 1703
Loc: UK
If we want to create some sort of viewer, the only things we need to worry about are the vertices and one of the 4 sets of polygons, ie the following lines:
00620001FEF000000140
0066FFA8
00650007
00680228FE20
0065FFF9
00660050

0047002700030000008900B70089000E007B002F0003000500020006
00470027000300C5007B000E007B00B70089002F0003000100060002
004700270003000E006B00B7007900000079002F0003000600030004
00470027000300B70079000E006B00C5006B002F0003000300060001
004CBABAC000
0080000500060004
004CC0BABA00
0080000300010002
004EBAC0C0BA
00810005000400030002

A script can then be created to transform these lines into a file that can be read by a 3d modelling program. I use AC3d because it has an ASCII text file format. You don't need to buy the program if only using it as a viewer, and it can be downloaded here:
http://www.inivis.com/
I've uploaded the 'f22_30.ac' example file here:
http://rapidshare.com/files/240108397/f22_30.ac

If all goes well, you should see something like this:

Top Bookmark and Share
#2736120 - 06/02/09 01:19 PM Re: .3 Files [Re: mikew]
mikew Online   smile
SimHQ Member

Registered: 02/26/01
Posts: 1703
Loc: UK
So,to summarize, 'f22_30.3' produces one of the F22 control surfaces. It contains 4 sets of polygon descriptors differing only with the texture used for the different camouflage schemes.

This is one of the simplest models, but it is by no means totally understood. frown

Any questions before we move on? smile

Top Bookmark and Share
#2736302 - 06/02/09 07:25 PM Re: .3 Files [Re: mikew]
DrKevDog Offline
SimHQ Member

Registered: 06/27/06
Posts: 596
Originally Posted By: mikew

Any questions before we move on? smile


Captivating display of knowledge and insight. Most appreciated!
One question on the decision blocks, are they exclusively identified by the '0048' opcode?

Top Bookmark and Share
#2736624 - 06/03/09 10:48 AM Re: .3 Files [Re: DrKevDog]
mikew Online   smile
SimHQ Member

Registered: 02/26/01
Posts: 1703
Loc: UK
The '0048' opcode is used for certain types of decisions. We've seen that '0048000A' for camo selection. '00480007' is used to select different damage states in other .3 files. I don't know whether this is a general rule. I guess I should find out.

In some .3 files, the '0027' opcode is used to make decisions based on distance. Also '0043' is used for time of day.

Even more speculative is the theory for the '0015' opcode. This looks like it's making a decision on whether a polygon's 'normal' is positive or negative for backface culling purposes ( http://en.wikipedia.org/wiki/Back_face_culling ) . Again, I don't know whether this is relevant in anything other than software mode since DirectX is supposed to handle that.

After looking at these files for a while, it wouldn't surprise me if this .3 file system has evolved over many years...even going back to the Amiga days.

Top Bookmark and Share
Page 1 of 10 1 2 3 ... 9 10 >



Forum Use Agreement | Privacy Statement | SimHQ Staff
Copyright 2009, SimHQ Inc. All Rights Reserved.