Difference between revisions of "FF7/P"
Qhimm>Mirex (added what I know / mirex / first version, have to fix up inconsistencies, typos and looks) |
Qhimm>Mirex (updated and cleaned up) |
||
Line 1: | Line 1: | ||
<i> | <i>Feel free to add more information.</i> | ||
== "P" Polygon File Format == | == "P" Polygon File Format == | ||
Line 38: | Line 38: | ||
The .p files have a 128-Byte-long Header. The following is the known structure of the header. | The .p files have a 128-Byte-long Header. The following is the known structure of the header. | ||
{| border=" | {| border="2" cellspacing="1" cellpadding="3" align="center" style="border: 2px solid black; border-collapse: collapse;" | ||
|+'''Table 1: P File header''' | |+'''Table 1: P File header''' | ||
! style="background:rgb(204,204,204)" align="center" | Off | ! style="background:rgb(204,204,204)" align="center" | Off | ||
Line 58: | Line 58: | ||
! style="background:rgb(204,204,204)" align="center" | 0F | ! style="background:rgb(204,204,204)" align="center" | 0F | ||
|- | |- | ||
| 00 | ! style="background:rgb(204,204,204)" align="center" | 00 | ||
| 01 | | 01 | ||
Line 72: | Line 72: | ||
| colspan="4" align="center"| A | | colspan="4" align="center"| A | ||
|- | |- | ||
| 10 | ! style="background:rgb(204,204,204)" align="center" | 10 | ||
| colspan="4" align="center"| NumNormals | | colspan="4" align="center"| NumNormals | ||
Line 85: | Line 85: | ||
| colspan="4" align="center"| NumVertices | | colspan="4" align="center"| NumVertices | ||
|- | |- | ||
| 20 | ! style="background:rgb(204,204,204)" align="center" | 20 | ||
| colspan="4" align="center"| NumEdges | | colspan="4" align="center"| NumEdges | ||
Line 101: | Line 101: | ||
| 00 | | 00 | ||
|- | |- | ||
| 30 | ! style="background:rgb(204,204,204)" align="center" | 30 | ||
| colspan="4" align="center"| H | | colspan="4" align="center"| H | ||
Line 115: | Line 115: | ||
|} | |} | ||
All Values, that can be | All Values, that can be read out in this part of the header are 4-Byte-Integers | ||
This 64 bytes long header is followed by 64 bytes of unknown data which are to be skipped. These 64 bytes of data look like offsets of parts of file, but in one large file. One (not allways first) long is smallest, and others are little larger. | |||
<pre> | <pre> | ||
typedef struct | typedef struct | ||
Line 126: | Line 126: | ||
long off04; | long off04; | ||
long VertexColor; | long VertexColor; | ||
long | long a; | ||
long NumNormals; | long NumNormals; | ||
long off14; | long off14; | ||
long NumTexCs; | long NumTexCs; | ||
long | long NumVertices; | ||
long NumEdges; | long NumEdges; | ||
long NumPolys; | long NumPolys; | ||
long off28; | long off28; | ||
long off2c; | long off2c; | ||
long | long h; | ||
long NumGroups; | long NumGroups; | ||
long | long g; | ||
long off3c; | long off3c; | ||
long unknown[16]; | long unknown[16]; | ||
Line 143: | Line 143: | ||
t_p_header; | t_p_header; | ||
</pre> | </pre> | ||
Here are the meanings of values from header: | |||
<table CELLSPACING="0" style="margin-bottom: 0px;"> | <table CELLSPACING="0" style="margin-bottom: 0px;"> | ||
Line 190: | Line 192: | ||
Count of Polygons </td> | Count of Polygons </td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td style="border: 1px solid rgb(0, 0, 0); width: 106px; height: 25px;"> | <td style="border: 1px solid rgb(0, 0, 0); width: 106px; height: 25px;"> | ||
H </td> | |||
<td style="border: 1px solid rgb(0, 0, 0); width: 394px; height: 25px;"> | <td style="border: 1px solid rgb(0, 0, 0); width: 394px; height: 25px;"> | ||
Count of Hundrets Chunk Entries (Textures?) </td> | Count of Hundrets Chunk Entries (Textures?) </td> | ||
Line 211: | Line 208: | ||
<tr> | <tr> | ||
<td style="border: 1px solid rgb(0, 0, 0); width: 106px; height: 25px;"> | <td style="border: 1px solid rgb(0, 0, 0); width: 106px; height: 25px;"> | ||
G </td> | |||
<td style="border: 1px solid rgb(0, 0, 0); width: 394px; height: 25px;"> | <td style="border: 1px solid rgb(0, 0, 0); width: 394px; height: 25px;"> | ||
? (sometimes 0 or 1)(but usually 1) </td> | ? (sometimes 0 or 1)(but usually 1), something to do with texturing probably </td> | ||
</tr> | |||
<tr> | |||
<td style="border: 1px solid rgb(0, 0, 0); width: 106px; height: 25px;"> | |||
A </td> | |||
<td style="border: 1px solid rgb(0, 0, 0); width: 394px; height: 25px;"> | |||
Unknown, usually equal to NumVertices </td> | |||
</tr> | </tr> | ||
</table> | </table> | ||
=== Vertices === | === Vertices === | ||
Vertices are stored as array of structure ‘vertex’ below, which is triplet of float numbers. Numbers specify point in 3D space. Size of this array is specified in header. Size of vertex section is ( 12 * NumVertices ) | Vertices are stored as array of structure ‘vertex’ below, which is triplet of float numbers. Numbers specify point in 3D space. Size of this array is specified in header. Size of vertex section is ( 12 * NumVertices ). Section is allways present in the file. | ||
<pre> | <pre> | ||
struct s_vertex { | struct s_vertex { | ||
Line 228: | Line 230: | ||
// structure size = 12 bytes | // structure size = 12 bytes | ||
=== Vertex normals === | === Vertex normals === | ||
Same format as vertices. Though, each of coordinate means vertex normal orientation instead of position. Size of this section is ( 12 * NumNormals ) | Same format as vertices. Though, each of coordinate means vertex normal orientation instead of position. Size of this section is ( 12 * NumNormals ). Section is allways present in the file. | ||
=== Texture coordinates === | === Texture coordinates === | ||
Array of vertex texture coordinates. Size of this section is ( 8 * NumTexCoords ) | Array of vertex texture coordinates. Size of this section is ( 8 * NumTexCoords ). Section is optinally present in the file ( sometimes NumTexCoords is 0 ). Texture coord references are to be read through group information. | ||
=== Vertex colors === | === Vertex colors === | ||
Vertex colors are stored as array of colors, each color is specified by four bytes. Color is in B8G8R8A8 format, that means that first byte specifies Blue, second specifies Green, third specifies Red and fourth specifies Alpha. Alpha byte has usually value ‘255’, so its at full opacity. Size of this section is ( 4 * NumVertices ). | Vertex colors are stored as array of colors, each color is specified by four bytes. Color is in B8G8R8A8 format, that means that first byte specifies Blue, second specifies Green, third specifies Red and fourth specifies Alpha. Alpha byte has usually value ‘255’, so its at full opacity. Size of this section is ( 4 * NumVertices ). Section is allways present in the file. | ||
=== Polygon colors === | === Polygon colors === | ||
Polygon colors are stored in the same manner as vertex colors. Size of this section is ( 4 * NumPolygons ). | Polygon colors are stored in the same manner as vertex colors. Size of this section is ( 4 * NumPolygons ). Section is allways present in the file. | ||
=== Edges === | === Edges === | ||
Dunno. Size of this section is ( 4 * NumEdges ). | Dunno. Looks like a array of indexes. Each index has value in range 0 .. NumVertices. Size of this section is ( 4 * NumEdges ). Section is optionally present in the file ( sometimes NumEdges is 0 ). | ||
=== Polygons === | === Polygons === | ||
Array of polygon definitions. I know only meaning of values which specify vertex indexes. Vertex indexes can’t be used directly to select vertices, you have first to read | Array of polygon definitions. I know only meaning of values which specify vertex indexes. Vertex indexes can’t be used directly to select vertices, you have first to read group information, there you will find information on which polygons and vertices you should be used to form a model part. Polygons have group-relative indexes to vertices (that means that in each group these indexes start from 0 ). | ||
I guess that 'ps' indexes have something to do with normals and 'pu' with edges. In battle models all three 'pu' indexes seem to be unintialized (all have the same values for all polygons). | |||
Size of this section is ( 24 * NumPolygons ). Section is allways present in the file. | |||
<pre> | <pre> | ||
Line 273: | Line 283: | ||
! style="background:rgb(204,204,204)" align="center" | 0F | ! style="background:rgb(204,204,204)" align="center" | 0F | ||
|- | |- | ||
| 00 | ! style="background:rgb(204,204,204)" align="center" | 00 | ||
| colspan="2" align="center"| 00 00 | | colspan="2" align="center"| 00 00 | ||
Line 285: | Line 295: | ||
| colspan="2" align="center"| pu1 | | colspan="2" align="center"| pu1 | ||
|- | |- | ||
| | ! style="background:rgb(204,204,204)" align="center" | 10 | ||
| colspan="2" align="center"| pu2 | | colspan="2" align="center"| pu2 | ||
| colspan="2" align="center"| pu3 | |||
| colspan="2" align="center"| u1 | | colspan="2" align="center"| u1 | ||
| colspan="2" align="center"| u2 | | colspan="2" align="center"| u2 | ||
Line 294: | Line 304: | ||
| colspan="8" align="center"| | | colspan="8" align="center"| | ||
|} | |} | ||
=== Hundreds === | === Hundreds === | ||
No idea. Size of this section is ( 100 * H ). | No idea. Size of this section is ( 100 * H ). | ||
Line 321: | Line 333: | ||
! style="background:rgb(204,204,204)" align="center" | 0F | ! style="background:rgb(204,204,204)" align="center" | 0F | ||
|- | |- | ||
| 00 | ! style="background:rgb(204,204,204)" align="center" | 00 | ||
| colspan="4" align="center"| PrimitiveType | | colspan="4" align="center"| PrimitiveType | ||
Line 328: | Line 340: | ||
| colspan="4" align="center"| VerticesStartIndex | | colspan="4" align="center"| VerticesStartIndex | ||
|- | |- | ||
| 10 | ! style="background:rgb(204,204,204)" align="center" | 10 | ||
| colspan="4" align="center"| NumVertices | | colspan="4" align="center"| NumVertices | ||
Line 335: | Line 347: | ||
| colspan="4" align="center"| ? | | colspan="4" align="center"| ? | ||
|- | |- | ||
| 20 | ! style="background:rgb(204,204,204)" align="center" | 20 | ||
| colspan="4" align="center"| ? | | colspan="4" align="center"| ? | ||
Line 342: | Line 354: | ||
| colspan="4" align="center"| TexCoordStartIndex | | colspan="4" align="center"| TexCoordStartIndex | ||
|- | |- | ||
| 30 | ! style="background:rgb(204,204,204)" align="center" | 30 | ||
| colspan="4" align="center"| AreTexturesUsed | | colspan="4" align="center"| AreTexturesUsed | ||
Line 370: | Line 382: | ||
</pre> | </pre> | ||
Each group specifies group of polygons. | Section contains array of group information. Each group specifies group of polygons. To read this group’s geometry you have to read polygons from polygon segment. First polygon is one with index ''group.PolygonStartIndex'', number of polygons is defined by ''group.NumPolygons''. Polygon has indexes of vertices. These indexes are group-relative and that means that you have to add ''group.VerticesStartIndex'' to each vertex index. | ||
To read this group’s geometry you have to read polygons from polygon segment. First polygon is one with index | It’s the same with vertex texture coords. Their indexes are group-relative too, to each index you have to add ''group.TexCoordStartIndex''. | ||
It’s the same with vertex texture coords. Their indexes are group-relative, to each index you have to add | |||
If | If ''group.textures_used'' is equal 1 then texture is applied on all polygons of current group. If its 0 there is no texture. If its 1 then ''group.TextureNumber'' defines which texture to use on polygons. Though, texture name is not specified inside the P-file, it is specified in HRC or DA file, which loads model as a whole ( it points to texture files, P-files, animation files etc.) | ||
Size of this section is ( | Size of this section is ( 56 * NumGroups ). | ||
=== Bounding box === | === Bounding box === | ||
Six 4-byte floats in order max( x, y, z ), min( x, y, z ). Sometimes just zeroes. Size of this section is 24 bytes. | |||
=== Normal index table === | === Normal index table === | ||
Not checked yet. Size of this section is ( 4 * NumVertices ). | Not checked yet. Size of this section is ( 4 * NumVertices ). |
Revision as of 11:59, 16 February 2009
Feel free to add more information.
"P" Polygon File Format
This is a short diagram of the file structure
.p-File | +- Header | +- Vertices[] | (+- Normals[]) | (+- Texture Coords[]) | +- Vertice Colors[] | +- Polygon Colors[] | +- Edges[] | +- Polygons[] | +- Hundrets[] | +- Groups[] | +- BoundingBox | +- Normal Index Table[] [] = a variable-sized array
.P File Header
The .p files have a 128-Byte-long Header. The following is the known structure of the header.
Off | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 0A | 0B | 0C | 0D | 0E | 0F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
00 | 01 | 00 | 00 | 00 | 01 | 00 | 00 | 00 | VertexColor | A | ||||||
10 | NumNormals | 00 | 00 | 00 | 00 | NumTexCoords | NumVertices | |||||||||
20 | NumEdges | NumPolygons | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | ||||||
30 | H | NumGroups | G | 01 | 00 | 00 | 00 |
All Values, that can be read out in this part of the header are 4-Byte-Integers
This 64 bytes long header is followed by 64 bytes of unknown data which are to be skipped. These 64 bytes of data look like offsets of parts of file, but in one large file. One (not allways first) long is smallest, and others are little larger.
typedef struct { long off00; long off04; long VertexColor; long a; long NumNormals; long off14; long NumTexCs; long NumVertices; long NumEdges; long NumPolys; long off28; long off2c; long h; long NumGroups; long g; long off3c; long unknown[16]; } t_p_header;
Here are the meanings of values from header:
VertexColor | Specifies if Vertex-Colors are used (0=no,1=yes; default: 1) |
NumVerts | Count of Vertices |
NumNormals | Count of Normals (always 0 in Battle files) |
NumTexCs | Count of Texture Coords |
NumNormInds | Count of Normal Indices |
NumEdges | Count of Lines for WireFrame-Model |
NumPolys | Count of Polygons |
H | Count of Hundrets Chunk Entries (Textures?) |
NumGroups | Count of Groups |
G | ? (sometimes 0 or 1)(but usually 1), something to do with texturing probably |
A | Unknown, usually equal to NumVertices |
Vertices
Vertices are stored as array of structure ‘vertex’ below, which is triplet of float numbers. Numbers specify point in 3D space. Size of this array is specified in header. Size of vertex section is ( 12 * NumVertices ). Section is allways present in the file.
struct s_vertex { float x, y, z; } vertex;
// structure size = 12 bytes
Vertex normals
Same format as vertices. Though, each of coordinate means vertex normal orientation instead of position. Size of this section is ( 12 * NumNormals ). Section is allways present in the file.
Texture coordinates
Array of vertex texture coordinates. Size of this section is ( 8 * NumTexCoords ). Section is optinally present in the file ( sometimes NumTexCoords is 0 ). Texture coord references are to be read through group information.
Vertex colors
Vertex colors are stored as array of colors, each color is specified by four bytes. Color is in B8G8R8A8 format, that means that first byte specifies Blue, second specifies Green, third specifies Red and fourth specifies Alpha. Alpha byte has usually value ‘255’, so its at full opacity. Size of this section is ( 4 * NumVertices ). Section is allways present in the file.
Polygon colors
Polygon colors are stored in the same manner as vertex colors. Size of this section is ( 4 * NumPolygons ). Section is allways present in the file.
Edges
Dunno. Looks like a array of indexes. Each index has value in range 0 .. NumVertices. Size of this section is ( 4 * NumEdges ). Section is optionally present in the file ( sometimes NumEdges is 0 ).
Polygons
Array of polygon definitions. I know only meaning of values which specify vertex indexes. Vertex indexes can’t be used directly to select vertices, you have first to read group information, there you will find information on which polygons and vertices you should be used to form a model part. Polygons have group-relative indexes to vertices (that means that in each group these indexes start from 0 ). I guess that 'ps' indexes have something to do with normals and 'pu' with edges. In battle models all three 'pu' indexes seem to be unintialized (all have the same values for all polygons). Size of this section is ( 24 * NumPolygons ). Section is allways present in the file.
struct { unsigned short zero, VertexIndex[3], ps[3], pu[3], u[2]; } Ppolygon;
Off | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 0A | 0B | 0C | 0D | 0E | 0F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
00 | 00 00 | VertexIndex1 | VertexIndex2 | VertexIndex3 | ps1 | ps2 | ps3 | pu1 | ||||||||
10 | pu2 | pu3 | u1 | u2 |
Hundreds
No idea. Size of this section is ( 100 * H ).
Groups
Off | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 0A | 0B | 0C | 0D | 0E | 0F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
00 | PrimitiveType | PolygonStartIndex | NumPolygons | VerticesStartIndex | ||||||||||||
10 | NumVertices | ? | ? | ? | ||||||||||||
20 | ? | ? | ? | TexCoordStartIndex | ||||||||||||
30 | AreTexturesUsed | TextureNumber |
struct { unsigned long PrimitiveType; unsigned long PolygonStartIndex; unsigned long NumPolygons; unsigned long VerticesStartIndex; unsigned long NumVertices; unsigned long u1; unsigned long u2; unsigned long u3t; unsigned long u4; unsigned long u5; unsigned long u6; unsigned long TexCoordStartIndex; unsigned long AreTexturesUsed; unsigned long TextureNumber; } group; // also called pool56, size is 56 bytes
Section contains array of group information. Each group specifies group of polygons. To read this group’s geometry you have to read polygons from polygon segment. First polygon is one with index group.PolygonStartIndex, number of polygons is defined by group.NumPolygons. Polygon has indexes of vertices. These indexes are group-relative and that means that you have to add group.VerticesStartIndex to each vertex index. It’s the same with vertex texture coords. Their indexes are group-relative too, to each index you have to add group.TexCoordStartIndex.
If group.textures_used is equal 1 then texture is applied on all polygons of current group. If its 0 there is no texture. If its 1 then group.TextureNumber defines which texture to use on polygons. Though, texture name is not specified inside the P-file, it is specified in HRC or DA file, which loads model as a whole ( it points to texture files, P-files, animation files etc.) Size of this section is ( 56 * NumGroups ).
Bounding box
Six 4-byte floats in order max( x, y, z ), min( x, y, z ). Sometimes just zeroes. Size of this section is 24 bytes.
Normal index table
Not checked yet. Size of this section is ( 4 * NumVertices ).