Kekouan

Q2Model, Part 4

2023-02-25

Ah, here's where the rubber hits the road. The first part of the problem was loading the Quake 2 Model and getting the information about the model.

md2_header(
    ident: 844121161, 
    version: 8, 
    skinwidth: 296, 
    skinheight: 164, 
    framesize: 1404, 
    num_skins: 0, 
    num_vertices: 341, 
    num_st: 465, 
    num_tris: 552, 
    num_glcmds: 2861, 
    num_frames: 198, 
    offset_skins: 68, 
    offset_st: 68, 
    offset_tris: 1928, 
    offset_frames: 8552, 
    offset_glcmds: 286544, 
    offset_end: 297988
)

That's the information/metadata provided by the Astroboy model. The ident is the magic number used to identify the file.

A "magic number" used to identify the file. The magic number is 844121161 in decimal (0x32504449 in hexadecimal). The magic number is equal to the int "IDP2" (id polygon 2), which is formed by ('I' + ('D' << 8) + ('P' << 16) + ('2' << 24)).

The GL commands, are an optimized way of sending in the model geometry into an OpenGL renderer. This was not something that was part of the Quake 1 Model format.

The next interesting bits are the vertices, the texture coordinates, the triangles, and the frames. The offsets tell you how many bytes into the file you need to read to access them.

With that information, you can begin to construct a version of the model, which is what I did:

Astroboy rendered in points, small Astroboy rendered in points, large

That's each vertex being drawn, potentially all 341 of them. From those 341 points you can create 552 triangles:

Astroboy rendered in wireframe