Jump to content

Recommended Posts

  • 1 month later...
  • 7 months later...
Posted
'''
Parsing Method:
     - Read 12 bytes (unk001, unk002, mesh_count) from the top-level fmtD8G.
     - For each mesh (mesh_count times):
         - Read unk003 (4 bytes).
         - Read position (16 bytes).
         - Read bound_sphere, unk004, unk005 (each 4 bytes).
         - Attempt to read unk006[1]. If it’s > 0, backtrack 4 bytes; otherwise read the remaining 12 bytes for unk006[2..4].
         - Read vertices via fmtD8G_Vertex:
             - Read definition_count.
             - If > 0, read exactly that many fmtD8G_Vertex_FVF.
             - Else read until flag == 0xFF.
             - Read stride and count.
             - For each vertex in count, read data from positions indicated by each FVF definition.
         - Read face_count (4 bytes).
            - If face_count > 0, read that many uint16_t face indices.
         - Read node_count (4 bytes).
            - If node_count > 0, read that many fmtD8G_Transform blocks (64 bytes each).
     - End of file once all meshes have been processed.
'''

==========================================================================================
 D8G MAIN HEADER
==========================================================================================
    +---------------+----------------------+----------------+--------------+--------------------------------------------+
    | Relative      | Variable Name        | Data Type      | Size (bytes) | Comments                                   |
    | Address (Hex) |                      |                |              |                                            |
    +---------------+----------------------+----------------+--------------+--------------------------------------------+
    | 0x00          | vert_type            | uint32_t       | 4            | 1 = vertices sprites, 2 = normal           |
    | 0x04          | face_type            | uint32_t       | 4            | 1 = triangle list 2 = triangle strips      |
    | 0x08          | mesh_count           | uint32_t       | 4            | Number of mesh entries to follow           |
    | 0x0C          | meshes[mesh_count]   | fmtD8G_Mesh[]  | variable     | Each mesh is read in sequence              |
    +---------------+----------------------+----------------+--------------+--------------------------------------------+
     * After reading mesh_count, you then iterate mesh_count times, reading a fmtD8G_Mesh each time (see next section).


==========================================================================================
 MESH STRUCTURE (fmtD8G_Mesh)
==========================================================================================
    +---------------+-------------------+----------------+--------------+---------------------------------------------+
    | Relative      | Variable Name     | Data Type      | Size (bytes) | Comments                                    |
    | Address (Hex) |                   |                |              |                                             |
    +---------------+-------------------+----------------+--------------+---------------------------------------------+
    | 0x00          | unk003            | uint32_t       | 4            | Possibly texture index?                     |
    | 0x04          | position          | float[4]       | 16           | X, Y, Z, W?                                 |
    | 0x14          | bound_sphere      | float          | 4            | Bounding sphere radius?                     |
    | 0x18          | unk004            | float          | 4            | Possibly min LOD distance?                  |
    | 0x1C          | unk005            | float          | 4            | Possibly max LOD distance?                  |
    +---------------+-------------------+----------------+--------------+---------------------------------------------+

     * Immediately after reading unk005, check for 16 bytes that may or may not be present (stored in unk006).
       The logic is:
        - Read 4 bytes
        - If > 0, seek backward 4 bytes and do not read the rest of the 12 bytes.
        - Otherwise, reads the next three uint32_t (total of 16 bytes).
     * After this conditional block, the next pieces are:

    +---------------+----------------------+---------------------+--------------+--------------------------------------------------+
    | Relative      | Variable Name        | Data Type           | Size (bytes) | Comments                                         |
    | Address (Hex) |                      |                     |              |                                                  |
    +---------------+----------------------+---------------------+--------------+--------------------------------------------------+
    | ...           | vertices             | fmtD8G_Vertex       | variable     | See "fmtD8G_Vertex" structure below              |
    | ...           | face_count           | uint32_t            | 4            | Number of faces (triangles)                      |
    | ...           | faces[face_count]    | uint16_t[face_count]| face_count*2 | Each face index is 2 bytes                       |
    | ...           | node_count           | uint32_t            | 4            | Number of transform nodes                        |
    | ...           | nodes[node_count]    | fmtD8G_Transform[]  | node_count*64| 64 bytes per transform matrix                    |
    +---------------+----------------------+---------------------+--------------+--------------------------------------------------+


==========================================================================================
 VERTEX BLOCK (fmtD8G_Vertex)
==========================================================================================
    +---------------+----------------------+---------------------+--------------+----------------------------------------------------+
    | Relative      | Variable Name        | Data Type           | Size (bytes) | Comments                                           |
    | Address (Hex) |                      |                     |              |                                                    |
    +---------------+----------------------+---------------------+--------------+----------------------------------------------------+
    | 0x00          | definition_count     | uint32_t            | 4            | If > 0, read exactly 'definition_count' FVF items  |
    |               |                      |                     |              | If == 0, read FVF items until flag==0xFF           |
    | ...           | definitions[]        | fmtD8G_Vertex_FVF[] | variable     | Each entry is 8 bytes (see 'fmtD8G_Vertex_FVF')    |
    | ...           | stride               | uint32_t            | 4            | Bytes between vertices                             |
    | ...           | count                | uint32_t            | 4            | Number of vertices                                 |
    +---------------+----------------------+---------------------+--------------+----------------------------------------------------+

     * For each fmtD8G_Vertex_FVF in definitions, jump to (start_of_vertex + pos) within that stride, 
       read the data accordingly (based on data field).


==========================================================================================
 FVF DEFINITION (fmtD8G_Vertex_FVF) - 8 bytes
==========================================================================================
    +---------------+--------------+-----------+--------------+---------------------------------------------------+
    | Relative      | Variable     | Data Type | Size (bytes) | Comments                                          |
    | Address (Hex) | Name         |           |              |                                                   |
    +---------------+--------------+-----------+--------------+---------------------------------------------------+
    | 0x00          | flag         | uint16_t  | 2            | Often 0; 0xFF signals end of definitions if found |
    | 0x02          | pos          | uint16_t  | 2            | Offset within the vertex stride block             |
    | 0x04          | data         | uint16_t  | 2            | 1=Float2, 2=Float3, 4=byte[3..4]? (color?), etc.  |
    | 0x06          | type         | uint8_t   | 1            | 0x00=Pos,0x03=Normal,0x05=TexCoord,0x0A=Color,... |
    | 0x07          | map          | uint8_t   | 1            | For UV channel index (0 or 1, etc.)               |
    +---------------+--------------+-----------+--------------+---------------------------------------------------+

==========================================================================================
 TRANSFORM (fmtD8G_Transform) - 64 bytes
==========================================================================================
    +---------------+--------------------+-----------+--------------+-----------------------------------------------+
    | Relative      | Variable Name      | Data Type | Size (bytes) | Comments                                      |
    | Address (Hex) |                    |           |              |                                               |
    +---------------+--------------------+-----------+--------------+-----------------------------------------------+
    | 0x00          | matrix4x4          | float[4x4]| 16*4 = 64    | 4 rows × 4 columns, read in row-major format  |
    +---------------+--------------------+-----------+--------------+-----------------------------------------------+

Recently someone has wrote a file format specification for *.d8g. Could anyone take a look?

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
×
×
  • Create New...