Reference ยท Formats

The CCSF Model chunk

Covers11
INF SLUS_202.67:0x0014bce0 Decode_Model0x0014b890 Decode_Mmat01 (0x0014badc its extremes)0x001388c0 ccBbox_SetBox0x0014a600 Decode_Mmat020x00140920 DecodeShadowModel0x0013a440 ccModel::InitVU1 micro 0x063 mc_DrawTriFast0x00147c20 ccStream::CompleteChunk0x00151950 ccAnm::SetAnm0x0013f860 ccModel::DrawBoneTypeVU1 micro 0x433 mc03b_DrawModel1

Kind 0x0800 in a CCSF file: one model, made of "mmats" - runs of vertices that share a material - in one of three layouts chosen by mtype. Read by ccStream::Decode_Model (0x0014bce0). The chunk's size field is wrong for mtype & 4 models (15 words per mmat too many); use the layout.

Layout

All little-endian.

header
  u32       model            object index, the MDL_ entry
  f32       vertexScale      ccModelChunk+0x40
  u16       mtype            ccModelChunk+0x50; & 0xff if version < 0x100
  u16       mmatNum          0: no model, the decoder returns here
  u16       flag             blendType = flag & 3; the rest dropped
  s16       zoffs            ccModelChunk+0x4e; 0 in every file
  u8        unknown_10       read and dropped; 0x70 in every file
            padding to 4

mmat[mmatNum], each: header words, then a body

What the decoder keeps of the header:

  • flag. Only flag & 3, as ccModelChunk.blendType (+0x4c). Over the 11,010 models in DATA.BIN with mmats, flag is 0 (9,990), 1 (532), 9 (266), 8 (136), 10 (82), 3 (3) or 2 (1). Bit 3, on 484 of them, is dropped at load like any bit above 1.
  • zoffs. ccModel::Init (0x0013a440) turns it into the float ccModel.zoffs (+0x1c), and ccModel::Copy and Duplicate copy it. Nothing else loads either field, so it has no effect; it is 0 in all 11,010.
  • unknown_10. Read and not stored; 0x70 in all 11,010.

Header words per mmat

mtypewords
& 2name, material, vertexNum, boneNum, offsetNum - never in the data
& 4material, vertexNum, offsetNum
& 8none
otherwisename, material, vertexNum

name is an object index (MDL_x_N) whose index entry the decoder clears; material is the MAT_ object.

Body: rigid (Decode_Mmat01, 0x0014b890)

s16[3]    position[vertexNum]
          padding to 4
u32       normal[vertexNum]      unless mtype & 0x40
u32       colour[vertexNum]      unless mtype & 0x200; read but dropped if mtype & 1
u32       st[vertexNum]          unless mtype & 0x400

mtype & 2 here is a deliberate crash (0x0014b8d8).

Body: bone and skin (Decode_Mmat02, 0x0014a600)

With offsetNum = 0, "bone" - every vertex follows one clump node:

u32       node                   clump node slot
s16[3]    position[vertexNum]    in that node's space
          padding to 4
u32       normal[vertexNum]
u32       st[vertexNum]

With offsetNum > 0, "skin" - a vertex is one or more weighted entries:

entry[offsetNum]                 8 bytes each
  s16[3]  position               in the entry's node's space
  u16     w                      bits 0-8 weight (256 = 1.0)
                                 bit 9    last entry of this vertex
                                 bits 10-15 clump node slot
u32       normal[offsetNum]
u32       st[number of vertices] = number of entries with bit 9 set

In all data the count of bit-9 entries equals vertexNum.

Body: shadow (DecodeShadowModel, 0x00140920)

s32       vNum                   0: nothing follows
s32       iNum
s16[3]    position[vNum]
          padding to 4
s32[3]    triangle[iNum / 3]

A closed mesh (every edge shared by two triangles, bar four edges in all of DATA.BIN) that the engine stretches into a shadow volume: the shadow volumes. Every shadow model has one mmat.

Values

fieldmeaning
positions16 * vertexScale / 4096 (VU1 itof12, render page)
normalbytes 0-2: s8 / 64 each (length 64); byte 3: strip flag
strip flag1 = start a strip, no triangle; 0 = triangle with the previous two vertices
colourR, G, B, A, 0x80 = 1.0
stu16 S, u16 T, 256 = one texture repeat (see below); T = 0 is the first stored texture row

The ST scale. The model packet unpacks ST as V2-16 in STMOD offset mode, with STROW [(u >> 4) & 0xff, (v >> 4) & 0xff, 1/16, 1.0] (the draw path). mc_DrawTriFast and the other programs load the slot as xyz, convert only x and y (itof12.xy), and multiply all three by the vertex's Q. The z they send as the GS's Q is the slot's z taken as float bits. The EE manual calls a V2 unpack's z and w indeterminate; PCSX2's unpacker, tested on the console, puts x and y there (Vif_UnpackSSE.cpp, "v1v0v1v0"). With the row added in offset mode, z is then S + bits(1/16) as an integer, the float 1/16 * (1 + S * 2^-23), and a vertex's texture coordinate is

u = (S + row.x) / (256 * (1 + S * 2^-23))

one repeat per 256 to within S * 2^-23: 3 * 10^-5 at S = 256, under 0.8% at the largest S. The port takes z as exactly 1/16.

Strips always open with two vertices flagged 1, and run on across the 48-vertex batches the engine splits a mmat into. VU1 turns the flag into the GS ADC bit. Nothing culls back faces, and winding is not consistent across models. See the draw path.

After the mmats ccBbox_SetBox(chunk+0x10, vmm, vertexScale) (0x001388c0) stores the model's box: per axis the integer extremes the decoders kept (starting at 0x10000 and -0x10000, Decode_Model 0x0014bddc), first doubled about the centre for mtype & 6. Decode_Mmat01 (0x0014badc) and DecodeShadowModel (0x00140ab4) test a value against the least so far and only otherwise against the greatest, so a vertex that lowers the minimum never raises the maximum: the first vertex sets only minima. With unit = vertexScale / 4096 (div.s): min at +0x10, max at +0x20, each cvt.s.w times unit, and the centre at +0x30, ((min + max) >> 1) * unit, w 1 (piney_data::model::VertexBox). Of 7,691 rigid models with mmats in Infection's DATA.BIN, 68 have a greatest corner other than the vertices' own maxima (title1-3's among them). ccModel::Init (0x0013a550) points ccModel +4 at it for a model without mtype & 6 and leaves it null for a bone or skin model; ccModel::Draw culls by it (_ccCheckBoundingBoxEx, which leaves VU0's vf21 its matrix times the greatest corner, the shadows) and keys the sorted group on its centre (the desktop's draw order). The centre matches the game's decoder in eemu for all 41 models of xdttopen0 and 138 of xddesk01.

Posing

Bone and skin positions are in clump-node space. Local matrix = T * Rx * Ry * Rz * S, rotation in degrees (SetMatrix_PosRotZYXScale, 0x00138120); world = parent world * local (0x00138380); a vertex lands at node world * position. Slot i is the i-th node of the model's clump: the clump whose node list holds the model's object, which need not be the clump a character is made from. Three steps give a bone or skin model its slots:

  • ccStream::CompleteChunk (0x00147c20), once the file is decoded: for every clump, and every node of it whose model has mtype & 6, it stores the clump's node list and count in the model data (+0x44, +0x48).
  • ccAnm::SetAnm (0x00151950; QUA 0x00150610): for every such model among the objects the clump applied or the animation made, it allocates ccModel+0x10 with +0x14 entries. Entry i is the object made for node i of that list.
  • ccModel::DrawBoneType (0x0013f860) poses slot i by entry i, with no null test.

The packet. Decode_Mmat02 writes what VU1 unpacks (the codes on the draw path): a bone vertex's position as three floats, its normal bytes with its strip flag, its ST; a skin entry's weight * 16, its slot's matrix address 20 + 4 slot and the entries left of its vertex (u16s), its position, its normal bytes with its vertex's strip flag (every entry of a vertex stores the same flag), then each vertex's ST. An ST half goes as (S & 0xfff) << 4 (no stored ST reaches 0x1000). The port's Model::body_words and model::body_st are those words, word for word on every disc.

The skin blend. Decode_Mmat02 turns each stored position into floats in the packet: sceVu0ITOF4Vector of the s16 triple, then sceVu0ScaleVector by vertexScale / 256 (0x0014ad04; the divisor's div.s at 0x0014a68c), so not s16 * vertexScale / 4096 to the bit when the product needs more than 24 bits. Each skin entry also carries its weight times 16 (0x0014ab74) and its slot's matrix address 20 + 4 * slot. DrawBoneType sends slot i's matrix to VU1 qword 20 + 4i as sceVu0InversMatrix2(model world) * node world (0x0013fa24, sceVu0MulMatrix at 0x0013fa78). VU1's mc03b_DrawModel1 (0x433) is the skin program: per vertex it starts at (0, 0, 0) and, for each entry (0(vi11): x the weight, y the matrix address, z on the first entry the entry count; 1(vi11) the position; 2(vi11) the normal), adds the matrix times the position (mulax, madday, maddaz, maddw with w 1, each product rounded) times itof12 of the weight (0x443-0x452); the blend lands two qwords past the vertex's first entry (sq vf22, 2(vi04), 0x45d) before the second pass projects it. mc03m is the bone program: one matrix for the batch, multiplied into the screen matrix first, so a bone vertex never has a model-space position. tools/ccsmodel.py's skin_positions is that blend in the game's arithmetic, and tools/test_ccs.py compares it with the microcode run in tools/vu.py, word for word, for every vertex of MDL_cbalbody posed at frame 0 of ANM_cbu1nut0 on each disc.

No bone or skin model's object is in no clump or in two on any volume (tools/ccs.py survey: 190 objects on Infection, 194 on each later volume, each in one clump). Tartarga's cts1 (and cts2, cts4) has CMP_trall with OBJ_trall alone, which ccRtownPC makes him from, and CMP_t0 with 49 nodes. His skin MDL_cts1body hangs on OBJ_cts1body, the 49th of CMP_t0, so it is posed through CMP_t0's nodes as the animation moves them. Through CMP_trall every vertex fell to his feet (issue #80). Axes are Z-up, right-handed.

Types seen

mtypewhat
0unlit, vertex colours (6,244 are empty skeleton placeholders)
1lit
5bone and skin
8shadow
0x600, 0x601no colour, no ST

DATA.BIN holds 17,254 models: 16,407 rigid, 3,129 shadow, 2,994 bone and 185 skin mmats, 5,417,645 vertices, 2,819,008 triangles.

Notes

The size field of an mtype & 4 model is 15 words per mmat longer than the chunk. Nothing reads a chunk's size: DecodeSetupSection dispatches on the kind and each decoder reads what its fields say, so the game is not affected. Why the exporter wrote it so is not on the discs.

Unknown

None.

How this was found out

docs/formats/ccs-model.md