Pikmin 2 collision format

From Pikmin Technical Knowledge Base
Revision as of 06:19, 5 April 2018 by Kai (talk | contribs) (5 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The following describes the format of Pikmin 2's grid.bin files, which describe the collision of overworld levels and cave units. The information might be incorrect or incomplete.

The format has no header and directly starts off with data. The Y coordinate points upwards. All values are big endian. Size of data is in bytes.

General data[edit]

Size of data Description
0x4 Unsigned integer describing how many vertices are defined.
0xC*(vertex count) 3 32-bit floats describing the XYZ coordinates for each vertex.
0x4 Unsigned integer describing how many triangles are defined.
0x4C*(triangle count) For each triangle in the collision there are 76 bytes of data describing the vertices of the triangle, normals, tangents, and more.
0x18 Unknown, maybe data about the level size.[unsure]
0x8 Two 32 bit unsigned integers describing the width and length of a grid of triangle groups. Is not related to the actual size of the map.
0x8 Unknown.[unsure]
Remaining data Contains groups of triangles. Each group starts with one 32 bit unsigned integer describing the amount of triangles in the group, followed by that many 32 bit unsigned integers describing the index of each triangle (0-indexed). Amount of groups equals to the width of the grid multiplied by its length.

Triangle data[edit]

Size of data Description
0xC 3 32 bit unsigned integers describing the (0-based) indices of the vertices v1, v2, v3 in this triangle.
0xC 3 floats describing the normal vector of the triangle.
0x4 float that affects collision in the direction of the normal, distance_normal.
0xC 3 floats describing the tangent of the edge (v1, v2).
0x4 float that affects collision in the direction of the tangent of (v1,v2), distance_tan1.
0xC 3 floats describing the tangent of the edge (v2, v3).
0x4 float that affects collision in the direction of the tangent of (v2,v3), distance_tan2.
0xC 3 floats describing the tangent of the edge (v3, v1).
0x4 float that affects collision in the direction of the tangent of (v3, v1), distance_tan3.

The values distance_normal, distance_tan1, distance_tan2, distance_tan3 can be calculated as follows:

distance_normal = normal_x*middle_x + normal_y*middle_y + normal_z*middle_z, where middle_x/y/z are the coordinates of the middle between vertices v1, v2, v3

distance_tan1 = tan1_x*v1_x + tan1_y*v1_y + tan1_z*v1_z, where tan1_x/y/z are the xyz components of the tangent of (v1,v2), and v1_x/y/z are the coordinates of the vertex v1

distance_tan2 = tan2_x*v2_x + tan2_y*v2_y + tan2_z*v2_z, similar to above but for tangent of (v2, v3)

distance_tan3 = tan3_x*v3_x + tan3_y*v3_y + tan3_z*v3_z, similar to above but for tangent of (v3, v1)