User Tools

Site Tools


kirby64_the_crystal_shards:geometry_blocks

This is an old revision of the document!


Geometry blocks

Kirby 64's “Geometry blocks” are containers holding display lists, vertices, transformation data, and texture scroll settings for a group of meshes. The high level structure of a geometry block is as follows (in order):

  1. HEADER
  2. VERTICES
  3. DISPLAY LISTS
  4. G_SETTIMG REFERENCES
  5. G_VTX REFERENCES
  6. ENTRY POINTS
  7. LAYOUTS
  8. TEXTURE SCROLL SETTINGS
  9. TEXTURE SCROLL DATA BLOCKS

This section contains the header. Structure definition below.

struct GeometryBlockHeader
{
    /*0x00*/ segptr layout;         // segment-offset pointer to the LAYOUT section
    /*0x04*/ segptr texScroll;      // segment-offset pointer to the TEXTURE SCROLL section
    /*0x08*/ int    layoutMode;     // interpretation mode of the LAYOUT section
    /*0x0C*/ segptr imgRefs;        // segment-offset pointer to the G_SETTIMG REFERENCES section
    /*0x10*/ segptr vtxRefs;        // segment-offset pointer to the G_VTX REFERENCES section
    /*0x14*/ int    lenScrollData;  // defines length of the Scroll DATA section
    /*0x18*/ segptr scrollData;     // segment-offset pointer to the Scroll DATA section
    /*0x1C*/ int    lenLayout;      // length of the Layout section
};

VERTICES

This section simply contains an array of RSP vertices to be used by the geometry block's display lists.


DISPLAY LISTS

This section contains F3DEX2 display list commands. Instead of containing addresses, the address field of each G_SETTIMG command contains a bank-index pair referencing an image in ROM or RAM.


G_SETTIMG REFERENCES

This section is a zero-terminated array of segment-offset pointers to every G_SETTIMG command in the DISPLAY LISTS section. After a geometry block is loaded into memory, the engine uses this section to convert the G_SETTIMG commands' bank-index pairs to virtual addresses in place, loading images as necessary.


G_VTX REFERENCES

This section is a zero-terminated array of segment-offset pointers to every G_VTX command in the DISPLAY LISTS section. It does not seem to be used by the game.


ENTRY POINTS

This is an optional section that is enabled when using layout mode 0x18 (and possibly others). When enabled, it contains of a list of display list “groups”.

Each group is an array of the following structure:

struct EntryPoint
{
    /*0x00*/ int    marker;      // 0x00: start of group, 0x01: continue group, 0x04 end of group
    /*0x04*/ segptr displayList; /* segment-offset pointer to a display list in the DISPLAY LISTS section
                                    (NULL when marker is 0x04) */
};

LAYOUT

The interpretation of this section varies depending on the value of the layoutMode field in the HEADER section. Modes 0x13, 0x14, 0x17, 0x18, 0x1B and 0x1C are used by the game.

Layout structure for each mode:

  • 0x13: Unknown
  • 0x14: A zero-terminated array of segment-offset pointers to display lists in the DISPLAY LISTS section.
  • 0x17: An array of GeoTransformGfx structures.
  • 0x18: An array of GeoTransformGroup structures.
  • 0x1B: Unknown, only used for developer test level
  • 0x1C: Unknown, only used for test level, 5-4-7 and 5-4-8
struct GeoTransformGfx  // Transform single display list
{
    u16    flag;
    u16    command;
    segptr displayList; // segment-offset pointer to display list in the DISPLAY LISTS section
    vec3f  position;    // x, y, z position
    vec3f  rotation;    // x, y, z rotation radians
    vec3f  scale;       // x, y, z scale
};
struct GeoTransformGroup // Transform group of display lists
{
    u16    flag;
    u16    command;
    segptr displayListGroup; // segment-offset pointer to an entry point
    vec3f  position;         // x, y, z position
    vec3f  rotation;         // x, y, z rotation radians
    vec3f  scale;            // x, y, z scale
};

A command of 0 is used to start a layout, and a command of 12 is used to end it. If the msb of the Display List of Entry Point pointer is set, afterwards another series of layouts will be used for environment effects. These environment effects dont have any pointers but are just placements of Loc, Rot, Scale.


TEXTURE SCROLL SETTINGS

This is an optional section that is enabled when a pointer exists in the Geo Block Header. When enabled, the engine uses this section to add G_DL branches and dynamic G_SETTILESIZE commands to RSP segment 0x0E. The display lists in the DISPLAY LISTS section may jump to these commands for texture scrolling effects.

This section contains three subsections (in order):

  1. Main Header
  2. ScrollStruct
  3. Sub Headers

MAIN HEADER

The texture scroll header is an array of segptrs terminated by an 0x99999999. Each segptr in this section points to a subheader.

SUB HEADER

Each subheader is an array of segptrs to texture scroll structs. Each sub header is terminated by an 0x99999999.

TEXTURE SCROLLS

This section is an array of uvScrollData structs each pointed to by an item in the subheader arrays. Following this uvScrollData struct is an optional bank-index list to textures which is also terminated by 0x9999.

struct uvScrollData {
    ushort field_0x0;
    byte fmt1;
    byte siz1;
    uint * textures;
    ushort stretch;
    ushort sharedOffset;
    ushort t0_w;
    ushort t0_h;
    int halve;
    float t0_xShift;
    float t0_yShift;
    float xScale;
    float yScale;
    float field_0x24;
    float field_0x28;
    pointer palettes;
    ushort flags;
    byte fmt2;
    byte siz2;
    ushort w2;
    ushort h2;
    ushort t1_w;
    ushort t1_h;
    float t1_xShift;
    float t1_yShift;
    float field_0x44;
    float field_0x48;
    int field_0x4c;
    struct color prim;
    byte primLODFrac;
    byte field_0x55;
    byte field_0x56;
    undefined field_0x57;
    struct color env;
    struct color blend;
    struct color light1;
    struct color light2;
    int field_0x68;
    int field_0x6c;
    int field_0x70;
    int field_0x74;
};

TEXTURE SCROLL DATA

Texture Scroll data is an array of bank-index pairs. The length of the array is defined in the HEADER section's lenScrollData field. Each Texture Scroll Data section is loaded into bank 0xE on level start and is used as graphics data that the uvScrollData structs will be built around.

kirby64_the_crystal_shards/geometry_blocks.1590578355.txt.gz · Last modified: 2020/05/27 11:19 by jesusyoshi54