Scene prim data (.PRM)¶
Every scene archive (SCENES/**.ZIP) holds one .PRM prim buffer, which ZRenderBaseDll::InstallPrimBuffer installs. This file describes the mesh records in it, read from the code that draws them (zolddrawps2.cpp, zoldviewps2.cpp, zprimcontrolbase.cpp) and from the VU1 programs (docs/internals/formats/vu-programs.md), and checked against all 71 scene buffers on the disc. Reproduce the survey with python3 tools/port/prm_dump.py survey FILE.PRM ....
Records¶
- Handles resolve through
g_apPrimHandleToPointerTable. Bit 31 oflColorsis the 16-bit colour flag, not part of the handle. - A root prim is a chain of sub-prims linked by
lNextPrim. The mesh types are strips 0, bone strips 1, wire strips 3, splines 4, bone variant 5 and dot3 strips 6. Lights, sprite arrays, scatter, shadow meshes and water patches also sit in chains. A chain ends at a link that does not resolve or is not a prim type (five chains on the disc end that way). - A sub-prim holds up to 255 chunks. Each bone strips chunk has fewer than 0x44 elements. Other chunks have fewer than 0x3f.
- Colours are RGBA8 in PS2 units (0x80 is 1.0). Pack type 8 marks a rigid part: the whole sub-prim follows
DeformBones()[lRigidBoneId]. Draw mode 0x800000 marks a hidden sub-prim.
Data layout¶
- File:
SPrimBufferHeader, data, then theSHandleTableEntrytable atlHandleTableOffset. Records are padded to 16 bytes, so record type and padded size identify prim records (0x50 strips, splines and water patches, 0x60 dot3, 0x90 bone strips, 0x20 bone variants). - Vertex packet per chunk,
m_lDMAVertexSizequadwords: words 0 to 3 are the STROW start values, word 6 isSTMOD 2(difference mode), word 7 isUNPACK V4-8(0x6e) orV4-16(0x6d) withNUM = m_lNrElemsand the FLG bit, then one signed X, Y, Z, W delta per element. Every element, the first included, adds its delta to the running value. Position is the running X, Y, Z timesm_fVertexScale; W is normal Z times 63. - UV packet, same layout with
m_lDMAUVSize: U, V, normal X times 63, normal Y times 63. UV is the running value timesfUVScale. Unpack addresses areelems + 3andelems + 4for strips and dot3, 0x5d and 0x5e for bone strips. - Colours: one RGBA8 word per element (
V4-8unsigned), or one RGBA5551 half-word (V4-5) when bit 31 oflColorsis set, consecutive across chunks. With no colour handle the PS2 uploadsg_WhiteChunk(0x80808080). - Strip lengths:
m_lNrStripsbytes atm_lLengths, summing tom_lNrElems. Each strip owns its vertices; there are no restarts inside a strip and no vertices shared between strips.AddPrimChunksToDMAChaindraws only the firstlNrStripsstrips of a type 0, 3 or 4 sub-prim; bone and dot3 sub-prims draw every strip. - Keys:
SPrimKeyHeaderthenlNrKeysSPrimKeyrecords, each with its own vertex, UV and colour handles in the base layout. A zero vertex or UV handle falls back to the base stream; a zero colour handle means white. - Dot3:
lTangentsandlBiNormalshold one signed byte vector per element (x, y, z, 0). - Bone strips:
lCopyBonesislNrCopyBonespairs (rows, offset). Each pair uploads rows/4 matrices starting atDeformBones()[offset / 16]to VU1 at 0x388, in order; that order defines the bone slots (at most 30). Each chunk's weight block,m_lWeightsSizebytes atlVU1Weights + m_lWeights, is unpacked to VU1 address 2 asV4-8:- header: two-bone list address (VU1 quadword), two-bone count, three-bone count, four-bone count;
- one-bone pairs (vertex × 2, slot × 4) from byte 4 up to a 0xff vertex byte;
- two-bone entries (vertex × 2, slot A × 4, weight A, slot B × 4);
- three-bone entries (vertex × 2, weight A, weight B, slot A, slot B, slot C, 0, 0);
- four-bone entries (vertex × 2, weight A, weight B, weight C, slot A, slot B, slot C, slot D);
- copy pairs (source vertex × 2, target vertex × 2) up to a 0xff byte; the target is a duplicated strip vertex and takes the source's bones. The last bone gets 255 minus the listed weights. Across the disc every vertex of every chunk gets an assignment.
Survey of the 71 scene PRMs¶
28,303 root prims, 71,655 submeshes, 176,047 chunks, 7,882,258 vertices, 5,526,884 triangles, 32,358 key vertices.
| Sub-prim | Pack type | Count | Notes |
|---|---|---|---|
| strips | 0 | 45,697 | static and dynamic geometry |
| strips | 4 | 300 | sky and background (drawn without the far plane) |
| strips | 8 | 13,501 | rigid parts of a bone object, one bone each |
| bone strips | 7 | 5,006 | skinned characters and animals |
| bone strips | 8 | 1,770 | zero-chunk header of a rigid-bone chain (bones only) |
| bone variant | 7 | 2 | material override of a bone strips mesh |
| splines | 0 | 15 | strips with spline data; all unlit, no normals |
| dot3 strips | 0 | 2,075 | normal-mapped |
| dot3 strips | 8 | 3,289 | normal-mapped rigid parts |
| Stream variant | Count |
|---|---|
| vertex packets 16-bit / 8-bit | 119,732 / 58,280 chunks |
| UV packets 8-bit / 16-bit / none | 113,585 / 54,646 / 9,781 chunks |
| colours RGBA8 / RGBA5551 / none | 5,322 / 10,650 / 55,683 submeshes |
| hidden (draw mode 0x800000); the sub-prims with chunks and no UV stream are exactly these | 7,424 submeshes |
| key-framed (strips only, 2 to 101 keys) | 81 submeshes |
| bone vertices with 1 / 2 / 3 / 4 bones / copies | 436,824 / 262,941 / 99,602 / 7,211 / 238,498 |
| temp header with normal planes / angle blend (0x40) / wobble (0x200000) | 415 / 605 / 0 |
Records without strip chunks:
| Record | Count | Contents |
|---|---|---|
| sprite array (type 2) | 30,309 | SPRITETYPE_ARRAY_UV records, half in pre-mission scenes and most of the rest in post-mission, news and loader scenes; quads are built at draw time from sprite elements |
| scatter (type 9) | 355 | tiles instanced by a VU1 program from the scatter header |
| water patch (type 11) | 19 | a grid of m_iXSegs × m_iZSegs built by ZWaterManager from SPrimWaterPatch; the record has no chunks |
| light (type 12) | 3,613 | no geometry |
Static shadow meshes¶
The disc holds 1,726 static shadow meshes (type 10, 819,778 triangles). SPrimShadowMesh points at a raw VIF stream for VUStaticShadowDraw (uVifStreamPrim, iSizeOfVifStream bytes); its layout comes from the microprogram (docs/internals/formats/vu-programs.md). Each batch is:
STROWwith the batch's integer origin (x, y, z, 0);UNPACK S-32of the bounding sphere radius to TOPS+1 andUNPACK V2-32of (index count, vertex scale) to TOPS+0;UNPACK S-8unsigned, one intensity byte per vertex, to TOPS+2;STMOD 1(offset mode), a maskedUNPACK V3-8of zeros to TOPS+1 (the sphere centre is the row) and a maskedUNPACK V3-16of signed per-vertex offsets to TOPS+2 (the mask keeps the intensity in W), thenSTMOD 0;UNPACK V4-8of the index bytes to TOPS+0x82, padded to whole quadwords;MSCAL 8.
A batch holds at most 128 vertices. Position is (origin + offset) × scale in root space. Index bits 0 to 6 select a vertex of the batch; bit 7 is the GS ADC flag, so an index with it set starts a strip without drawing a triangle. Every other index k ≥ 2 draws the triangle (k−2, k−1, k); in the strip winding below that is (k−2, k, k−1) for even k and (k−2, k−1, k) for odd k, counting k from the start of the batch as the VU does. Indices share vertices within a batch. With this reading all 1,726 meshes yield exactly lNumTriangles triangles; the largest has 10,223 vertices, so 16-bit indices suffice.
Textured shadows (880 on the disc) carry 12 floats at lTempHeader: (s, t, q) = x·P0 + y·P1 + z·P2 + P3 per vertex, and s/q, t/q address the shadow texture in [0, 1].
Inferred meanings¶
Read from code: positions, the 8/16-bit delta coding, normal Z in vertex W at 1/63, normal X and Y in UV Z and W at 63 (SetPrimExtraData writes them), UV scale, colour formats, strip lengths, the drawn-strip limit, key layout, the copy-bones upload, DeformBones = Bones × InvertGlobalBones, the 0x800000 hidden bit (ZOldDrawBase drops those sub-prims from the active list), PRIMDRAWMODE_ONE_SIDED (0x4000000) setting VU1 control bit 2.
Inferred from the data:
- Normal X and Y scale. 1/63 like Z. Every vertex of a drawn lit sub-prim has a raw length of 61.3 to 63.0 (median 62.3), matching the truncating
(int)(n * 63.0f)inSetPrimExtraData. Hidden sub-prims have no UV stream and so no normal X or Y; their Z alone is meaningless. - Triangle winding. Read each strip triangle as (a, a+2, a+1) on even steps and (a, a+1, a+2) on odd ones, the reverse of the strip order. Then the right-handed face normal agrees with the stored vertex normals for 99.8% of strip, 99.7% of bone and 99.95% of dot3 triangles on drawn sub-prims, and for all 516 one-sided meshes. Whether VU1 culls on control bit 2, and with which sign after projection, is for the VU1 analysis to confirm.
- Up axis. Y is up: characters stand from Y = 0 to about 190 in bind pose.
- RGBA5551 expansion. VIF
V4-5rules: 5-bit channels shifted left by 3, the alpha bit becomes 0x80. Alpha 0x80 is 1.0, likeg_WhiteChunk. - Tangent and binormal scale. 1/127. Their byte lengths are 126.3 to 127.9 and the fourth byte is always 0; tangents are perpendicular to the normals (median |t·n| = 0).
- Weight-block header and sections. The first header byte is a VU1 quadword address (unpack base 2, four bytes per quadword); the other three bytes count the two-, three- and four-bone sections. With this parse every vertex of all 19,309 bone chunks on the disc gets an assignment and no entry points outside its chunk.
- Slot to bone. Weight slot bytes index the copied matrices in upload order (byte / 4). With this mapping a bone's bind-pose joint lies a median 6.8 units from the centroid of its one-bone vertices; shifting the slot by one or using the slot as a bone index gives 10.3, 19.5 and 65.1.
- Weight order. A listed weight belongs to the bone in the same position, and the last bone gets the remainder. Rotating one bone about its joint and measuring edge stretch: for two-bone vertices this order stretches edges 2.4 times less than the swapped order; for three-bone vertices it beats all five other permutations.
- Copy pairs. The target takes the source's bones and weights and keeps its own stored position. In 238,480 of 238,498 copies the positions are identical; the other 18 differ by one quantisation step. If VU1 copies the transformed vertex instead, the result differs by at most that step.
- Key colours with bit 31. 5,029 keys have 16-bit colour handles.
SetKeyChainFramePointersresolves key handles withResolvePrim, which reads bit 31 as a raw pointer, and steps colours by four bytes per element, so those keys look broken on the PS2. - Bone variant alpha cutoff.
AddBonePrimStripChainStartreadslAlphaCutofffrom the variant record, past its 0x20 bytes. - LOD control on bone strips. 0x03 and 0x7c split high and low detail; 0x80 marks sub-prims that use
DeformBones2(). Read from code since: see Character levels of detail.
Character levels of detail¶
Read from code (zoldviewbase.cpp, zolddrawbase.cpp, zdrawidlist.cpp, zdrawresources.cpp, zhitman3.cpp, renderbase.cpp) and checked against the M00 to M13 buffers of both releases.
- Levels. Every frame each geom gets one LOD level k (
m_lLODLevelNew = 1 << k), and a sub-prim is drawn whenlLODControl & (1 << k). For aZLNKOBJ(characters, animals) k comes fromm_LODTableCharacters, whichZRender::Initializefills withSetLOD(table, 4, 6): the index is the distance from the camera timesfCameraFarInv(about distance / 100 at the default 67.4° field of view), and indices 0 to 2 are level 0, 3 to 7 level 1, 8 to 11 level 2, 12–23 level 3, 24–47 level 4, 48–95 level 5 and 96 upwards level 6.character_detaildivides the index in the port. - 47.
ZHitman3::GetLODMaskOverridereturns 0xff andWantViewPrimHideUnhideRequesttrue, soAddActivePrimitiveInstancesasksWantViewPrimHidefor every sub-prim: in third person (and in mirrors,WantViewPrimHideMirrors) 47 draws the sub-prims with bit 0 at every distance, and with the first-person bones only those with 0x80 (the arms). 47 is always drawn at level 0. - Masks on the disc. A character's sub-prims carry 0x03 (levels 0 and 1), 0x7c (levels 2 to 6) and 0x80 (first person, with
DeformBones2); a few small skinned objects (birds, flags, bullet-hole meshes) carry 0xff. The PC splits 0x03 into 0x01 and 0x02 (below). - Bones per level.
ZGeomDrawEntry::UpdateActiveNumBonestakes the bone count from the root'sSPrimHeaderStripBones::NumBonesUsedLOD, indexed backwards: level k uses entry 7 − k (the loop shifts the mask left and tests 0x80). For 47 the eight entries are (99, 25, 25, 25, 25, 25, 99, 99): levels 0 and 1 animate all 99 bones, levels 2 to 6 the first 25. - Variants. A root with
lNumVariantsandlVariantArray(SPrimVariantArray: count, list handle, indexed by variant id) is drawn, for a geom with a variant id, from that variant's list alone (ZOldDrawBase::GeomCreate); with variant id 0 it draws the whole chain. A list isSPrimBoneStripVariantrecords (0x20 bytes: a copy of the draw setup, thenlPrim, the bone strips sub-prim it draws), and the engine uses the record itself as the active prim, so the record's texture, draw mode andlLODControlare what is drawn. The disc shares sub-prims between variants and overrides the texture in the record (M00's chemist: variant 3 draws sub-prim 3045 with texture 221 where the sub-prim says 214); the chain is the union of all variants' sub-prims. The PC instead copies every object into every variant that uses it (variant ids 1, 5, 9, 13, 17 of the M00 gate guard each have their own 820-triangle head). lVariantIdof a bone strips sub-prim is 0x8000 plus the index of its material within the character (47 in M00: 0 the head texture 221, 1 the body 223, 2 the legs 224). Several sub-prims of one material share it: the disc splits a PC object into pieces of at most 30 bones (47's 872-triangle head is 623, 107, 108 and 34). OnlyZPrimControlBase::IsVariantAvailableandGetNumVariantsread the field, and the PS2 build replaces both withZPrimControlPS2versions that read the variant array instead.- Bone definitions. Each 0x40-byte
SBoneDefinitionholds a V3 center at 0x00, parent index at 0x0c (−1 for the root), V3 size at 0x10, 34-byte name at 0x1c, ID at 0x3e and body part at 0x3f. - Positions. Multiply the decoded coordinates by the chunk’s
m_fVertexScale. The most common values are 0.1 (136,531 chunks), 0.01 (18,177) and 1.0 (14,471). Decals also use 1000/32,767 and some sky strips use 10.
Writing a buffer¶
tools/port/scene/prm.py parses and rewrites all 71 buffers byte for byte (PRM: 71/71 identical; also in roundtrip.py). The container rule it relies on holds in every file:
SPrimBufferHeaderislHandleTableOffset,lNumHandles,lUsedSizeand a fourth word that is always 0. Each 16-byte handle entry has four 32-bit words for offset, size, reference count and padding. Handle 0 is this header:SHandleTableEntry(0, 0x10, 1, 0).- Handles 1 to n−1 are blocks laid out back to back in handle order from offset 0x10, each a multiple of 16 bytes. The table follows the last block and ends the file.
lUsedSizeequalslHandleTableOffset.InstallPrimBuffer(renderbase.cpp:871) starts run-time allocations there (m_pCurrentPrimBuffer), over the table it no longer needs, inside the 0x10000 bytesAllocSequenceadds to the allocation. - Every reference is a handle, so appending blocks never invalidates one. The pointer table has 0xa000 slots and
InstallPrimBufferhands out run-time handles downward from 0x9fff, so a file should stay well below that. The largest on the disc has 23,747 handles (M06 main). CompactPrimBuffer(renderbase.cpp:716) only runs when prims were freed before install (PurgePrimBuffer, the weapon prims of_mainscenes). It copies live blocks down in handle order, which is the on-disc layout again.
Facts about drawn static strips (type 0, pack type 0, with UVs) that add_mesh follows. They were measured over all 38,713 such sub-prims:
lNrEntriesis the sum of the chunks'm_lNrElems, andlNrStripsthe sum of theirm_lNrStrips.- The vertex stream and the UV stream are one handle each, holding every chunk's packet in order. Each chunk's strip lengths are their own 16-byte handle, and the chunk table is one handle padded to 16 bytes. Chunks have at most 62 elements and 16 strips.
- A vertex packet is
ceil((32 + elems × step) / 16)quadwords (step 4 forV4-8, 8 forV4-16). Words 4 and 5 are 0 and word 6 isSTMOD 2(0x05000002). A UV packet isfloor((32 + elems × step) / 16) + 1quadwords (all 146,243 chunks), with words 4 to 6 zero. lTempHeaderis never 0:CalcPrimCenSizebreaks into the debugger without it (zprimcontrolbase.cpp:387). It is anSPrimHeaderStrip:Plane0[4],Plane1[4],vMax,vMin, padded to 0x40.GetNormalPlanes(zolddrawps2.cpp) uses the planes only whenPlane0[0] < 2. A value of 1e38 disables the plane test. Sub-prims of a chain have their own header in 22,602 cases and share the root's in 20,750.lDrawEntryIdis 0 in the file;ZOldDrawBaseassigns it at run time.- Common values:
lDrawDestination0x81 (PRIMDEST_CUSTOM | DD_RGB),lLODControl0xff,lBias0,lAlphaCutoff0x80,lDiffuseColor0xffffffff, draw mode 0x890 (LIT | RECEIVE_SHADOWS | 0x10; 0x10 has no name inzprimcontrolbase.h),fUVScale1/32 or 1/512.
Adding a static mesh¶
prm.add_mesh(buf, positions, uvs, triangles, normals=None, colors=None, texture_id=0, ...) appends one strips prim and returns its handle:
- It builds strips greedily so that
prm_dump.strip_trianglesdecodes exactly the input triangles with their winding, and cuts them into chunks of at most 62 elements and 16 strips, restarting a split strip on an even step. - Positions are 16-bit deltas from a
STROWstart at the chunk's first vertex.m_fVertexScaleis the chunk's extent / 32,000. Normals are(int)(n × 63): Z in the vertex W, X and Y in the UV packet. UVs share one power-of-twofUVScale. Colours are RGBA8 per vertex (or RGBA5551 withcolors16=True), in PS2 units. - Each chunk gets a bounding sphere, and the prim gets a temp header with the planes disabled and the prim's bounds.
link(buf, handles)chains several prims throughlNextPrim.
The prim is drawn once a geom names its handle (the .PRP Prim property; see gms.md and prp.md), and textured once texture_id is a m_lTextureId of the scene's TEX (tex.add_texture). prm.py selftest FILE adds a 12-triangle box and a 2,304-triangle sphere (48 chunks) to a real buffer. It checks that every existing block is unchanged and that the file re-parses. Decoding with prm_dump.decode_subprim gives back the same triangles, positions within one quantisation step (0.009 units on a 300-unit sphere), UVs within one fUVScale step, normals within 1/63 and exact colours.
Not checked: lighting (lColiBits, the geom's light colours) and collision. A new mesh has no collision unless the scene's collision data (.OCT/.RMC) gets matching geometry.
PC version¶
The Steam release keeps the container (the SPrimBufferHeader, blocks back to back in handle order from 0x10, the SHandleTableEntry table at the end, handle 0 the header, lUsedSize = lHandleTableOffset) and the light, sprite-array and bone-data records, but its meshes are object headers whose objects name a material (.MAT, mat.md) and point at Direct3D vertex and index buffers. port/engine/system/_sdl/pcdata/pcprims.{h,cpp} (PcConvertPrims) turns a PC member into the PS2 buffer described above. Everything here was measured on the 68 PC scene archives (491,614 handles, 32,351 object headers, 81,802 mesh objects, 10.3 million triangles) and, where both releases name a geom the same way, against the 71 PS2 buffers. The PC executable's loaders (Ghidra, HitmanBloodMoney.exe unpacked) settled what the data left open; addresses below are in it.
Reference counts in the PC table count references: the shared empty property table of the front end has 538, one per object header that uses it; lights and sprite arrays that the GMS and PRP name have 2.
Object header (type 7, 0x40 bytes)¶
SPrimObjectHeader in zprimcontrolbase.h is this record:
| Offset | Field | Values |
|---|---|---|
| 0x00 | lDrawDestination, lPackType, lType |
0, 1, 7 |
| 0x0c | lPropertyFlags |
bit 0 bones (HAS_BONES), bit 1 always set, bit 2 rigid parts, bit 3 skinned, bit 5, bit 6 two-sided materials, bit 8 USE_BOUNDS: 2 (27,073 headers), 0x42 (3,018), 7 (1,597), 0x47 (144), 0x10b (280), 0x14b (76), 0x16b (17), others under 50 |
| 0x10 | lPropertyData |
a 16-byte property table: entry 1 (PROPERTY_BONES) is an SPropertyBones handle when bit 0 is set; headers without properties share one all-zero table |
| 0x14 | lNumObjects |
|
| 0x18 | lObjectTable |
lNumObjects handles: mesh objects (type 8), scatter records (type 9, 0x80 bytes, 361) or water patches (type 11, 0xb0 bytes, 42; below) |
| 0x1c | lColiId |
23,724 non-zero: the offset of the geom's packed collision tree in the PC .OCT, the PS2 SPrimStrips::lColiId (zcollisionbaseold.cpp reads both). The values differ from the PS2's, as the OCT does |
| 0x20, 0x2c | vMin, vMax |
the bounds; CalcPrimCenSize and hm3items read them on the PC |
| 0x38 | lPlanes |
153 non-zero; not converted (the PS2 headers' normal planes stay disabled) |
Mesh object (type 8)¶
| Offset | Field | Values |
|---|---|---|
| 0x00 | lDrawDestination |
0x89 (custom, mirror, RGB) for most, 0x81 without mirror, 0x82 and 0x8b with bloom |
| 0x01 | lPackType |
1 static (51,508), 4 sky and background (307), 3 (66), 0 bones (29,921) |
| 0x0c | lSubType |
the material's STYP: 0 standard (51,754, 2,017 of them static shadows), 1 tweened (127), 2 rigid (14,937), 3 weighted (14,984) |
| 0x0d | lProperties |
the PS2 draw mode's bits 28 and 29 (0x10000000, plane align, and 0x20000000): 3 on the 7,204 glows, glow-system discs, dust, candle flames and billboard palms of the 68 archives (659 of them tweened), else 0. Of the mesh objects that a mission scene's PC and PS2 data both name, the 1,583 with 3 are exactly those whose PS2 twin has 0x30000000 in its draw mode (build/light10/pair.py in the matfx worktree); the converter ORs lProperties << 28 into the draw mode (pc-data.md: Plane align) |
| 0x0e | lLODMask |
0xff; 1, 2, 0x7c and 0x80 on characters, 3 and 0xfc on rigid parts. The shared ZOldViewBase LOD code reads it like the PS2 lLODControl |
| 0x0f | lVariantId |
0, or a character variant: 1, 2, 3, 5, 6, 7, 9, ... (see below) |
| 0x12 | lMaterialId |
the .MAT instance |
| 0x14 | lColiBits |
the PS2 lColiBits (identical on 99.97% of paired sub-prims) |
| 0x18 | lWireColor |
|
| 0x1c | lDrawMode |
PS2 draw-mode bits: 0x80 LIT, 0x800 RECEIVE_SHADOWS, 0x40000 FORCE_NO_ZWRITE, 0x80000, 0x400000 (a PC flag), 0x800000 hidden; 0x2000 on static shadows |
| 0x28 | mesh list | a 16-byte block; word 0 is the mesh record |
| 0x2c | tweened: key count | 1 otherwise; 0 on weighted objects |
| 0x30 | tweened: frame start (u16), frame step (u16) | 0x10000 and 0x20000 seen; the PS2 key headers have the same start, step and lFrameEnd = start + (keys − 1) × step |
| 0x34 | a colour | not needed |
| 0x38, 0x3c | rigid: 1, the bone index (the PS2 lRigidBoneId, equal on every pair); weighted: the palette's pair count and handle |
Static shadow objects are 0x80 bytes: words 0x38 to 0x74 are a 4×4 row-vector texture projection (identity on untextured ones) and 0x78 the shadow colour (D3DCOLOR).
A mesh record is four words: vertex count, vertex buffer, a third count (at most the vertex count; not needed) and the index buffer. An index buffer is u16 1 (triangle list; every buffer on the disc), u16 index count, then the indices. PC triangles wind the other way from the PS2 decoder's: (i0, i1, i2) has its right-handed normal against the vertex normals on 99.7% of triangles, so the converter feeds (i0, i2, i1) to the strip builder.
The vertex stride follows the material class: the PC builds a ZPrimAccess through the material (0x0047c910), ZPrimAccessOldMeshD3D for the "Old" (Bad) class.
| Stride | Objects | Layout |
|---|---|---|
| 0x28 | 61,217 | position (3 floats), normal (u32), colour (D3DCOLOR), UV (2 floats), tangent (u32), binormal (u32), 0xcdcdcdcd |
| 0x24 | 3,584 | position, normal (3 floats), colour, UV: the Old (Bad) class, collision helpers |
| 0x34 | 14,984 | position, three weights (floats; the fourth is 1 minus their sum), four bone bytes, normal, colour, UV, tangent, binormal: weighted objects |
| 0x10 | 2,017 | position, colour (the alpha byte is the shadow intensity): static shadows |
Packed normals, tangents and binormals hold x in byte 2, y in byte 1 and z in byte 0, each b / 127.5 − 1 (against the PS2 normals of the same vertices the mean squared distance is 0.19 with this order, 1.28 with the bytes reversed). Colours are A8R8G8B8 with 255 = 1.0; the PS2 colour is (c + 1) / 2. A tweened object's vertex buffer holds its keys one after the other, vertex count vertices each.
Weighted objects: the palette is pairs (12 × bone count, 12 × first bone), the PS2 lCopyBones (rows, offset) pairs in other units ((4 × count, 16 × first)); the slots are the pairs' bones in order, at most 30 (no PC palette reaches 30). A vertex's bone bytes are 3 × slot (Direct3D shader constant registers); bytes that name the same slot add their weights.
Water patch (type 11, 0xb0 bytes)¶
42 objects in 15 scenes, each the only object of its header except the M12 toilet (three meshes and the water). The record is the PS2 SPrimHeaderStripWaterPatch and its four waves, wrapped in an object; the rest of the PS2 SPrimWaterPatch (Fresnel range, scales, pass colours) is in the WaterSurface material (mat.md).
| Offset | Field | Values |
|---|---|---|
| 0x00 | lDrawDestination, lPackType, lType |
1, 1, 11 |
| 0x0e | LOD mask | 0xff; 0x7f, 0x3f, 0x1f and 0xc0 on some |
| 0x12 | lMaterialId |
a WaterSurface instance |
| 0x14 | lColiBits |
2, 0, 4; 0x40 on the two M09 collision-only surfaces |
| 0x18 | 0xffffffff | |
| 0x1c | lDrawMode |
0x80, 0x880, 0x400080; 0x800000 (hidden) on the two WorldColi_SurfaceWater patches of M09 |
| 0x28, 0x2c | m_iXSegs, m_iZSegs |
1 to 30 |
| 0x30, 0x34 | m_fXSize, m_fZSize |
|
| 0x38 | m_vPos |
y is 0 (the PS2 has 0xcdcdcdcd there) |
| 0x48 | m_pWavesDesc[4] |
direction (2 floats), speed, length, amplitude; unused waves are (0, 0, 0, 1, 0) |
| 0x98 | m_lGroupID |
0 to 3 (the four M00 sea tiles) |
| 0x9c | four floats | the normal map's UV rectangle: u and v at the first grid vertex, then the u and v spans over the grid (ZRenderObjectWaterPatchD3D, PC 0x4a1360: vertex (x, z) gets u0 + x × uspan / xsegs); (0, 0, 1, 1) on most, (−22, −2, 22, 9) on M01's long river tile; no PS2 field |
The PS2 keeps the same surfaces as a type 11 record (0x50 bytes: draw destination 1, pack 0, a "Reflection" environment texture that the PC TEX does not have (one face of a reflection cube map cut down to 32 or 64 pixels: Reflection_06_FX_H3#Reflection_d in M01 and M11, Reflection_10#Back_a in M02, M04 and M05, Reflection_09#Reflection_a in M09, Reflection_M10_01#Diffuse_a in M10; the PC scenes keep the six-face cubes), draw mode 4, alpha cutoff 0x80, no chunks, lColiId 0) whose temp header is the SPrimWaterPatch. On the 4 geoms both releases name once, sizes, positions, groups and flags agree; the grid, waves, Fresnel range and colours were tuned per release (M02 30 × 35 on the PS2, 30 × 30 on the PC; M01's PS2 patch has four waves, the PC's two). Where the PS2 values match PC ones they are the material's: M09's PS2 surfaces have M00's sea material (reflection scale 0.4, refraction 0.7, Fresnel 0 to 1, colour 249, 249, 249 = gm_vReflection2DColor 0.976), M11's the refraction scale 0.06 of its own.
Scatter field (type 9, 0x80 bytes)¶
361 objects in M01 (190), M13 (67), M04 and M05 (8 each), M02 (7), M08 (6, backdrop trees the PS2 does not have) and the title scene, each the only object of its header. The PS2 has the same fields as SScatterHeader records (type 9, 0xa0 bytes, src/engine/drawing/old/_ps2/zolddrawps2.h), one per geom, in the same order.
| PC offset | Field | PS2 SScatterHeader |
|---|---|---|
| 0x00 | draw destination 9, pack 1, type 9 | 1, 1, 9 |
| 0x0e | LOD mask 0xff | lLODControl 1 |
| 0x12 | lMaterialId: a ScatterMaterial |
lTextureId (the material's mapDiffuse), fWidth, fHeight, fRandomHeight 0x3c to 0x44 (ScatterWidth, ScatterHeight, ScatterRandomHeight), lAlphaRef 0x9c (AREF) |
| 0x1c | draw mode 0x400080 | 0 |
| 0x28 | tile X, tile Z, density, billboard types (bytes) | 0x38, the same bytes |
| 0x2c, 0x30 | master tiles (handle), its size | lMasterPrim 0x48 (eight 16-byte tiles, then the objects), lMasterSize 0x4c = 3 × objects |
| 0x34 | distribution (handle): one byte per object, the billboard (0 to 7, 4 to 7 mirrored) | lDistributionPrim 0x50 |
| 0x38 | objects | lDistributionSize 0x54, lObjsInMaster 0x5c |
| 0x3c | 100.0 | (fTileSize 0x58 is 0) |
| 0x40, 0x4c | vCen, vSize |
0x78, 0x84 |
| 0x58 | fDrawDist (1500 to 4800, 500 for M08's trees, or 1e38); the PC never reads it, and the converter writes 1e38 (pc-data.md "Scatter") |
0x90 |
| 0x5c, 0x68 | colour A, colour B (three floats each) | lColorA 0x94, lColorB 0x98 (R in the low byte, 255 = 1.0, truncated: (1.0, 0.675, 0.651) is 0xa6acff) |
| 0x74 | 1 | |
vBaseline 0x60, vScale 0x6c: the tile grid's quantisation |
A master tile is (count in the first triangle, count in the second, first object, 0); the eight are identical in both releases. A PC object is four floats (barycentric a, b, 0.08, random height), a PS2 object three bytes (a, b, random height, × 255 truncated: (0.767, 0.232, 0.255) is 195, 59, 65). The tile grid is the block after the PC object's handle (handle + 1): (X + 1) × (Z + 1) vertices of 20 bytes, row by row: the tile id (master tile 0 to 7, 8 and up for no grass), the size (the billboard scale, 255 = 1.0), R, G, B, three pad bytes and the position (three floats, object space). The PS2 packs it right after the record (the engine reads it at pScatter + 1) in 8 × 8 sub-grids, sharing their edge rows and columns: per sub-grid a 16-byte header (the first vertex's position and (stop Z << 4) | stop X, 0x35 for a 5 × 3 field) and one TileFlexVertexPS2_t per vertex (three delta bytes, the tile id, R, G, B, the size), padded to 16 bytes. A vertex is the previous vertex of its row, or for a row's first the previous row's first (the header for the first row), plus delta × vScale + vBaseline per axis.
The converter writes the PS2 record at the header's handle with the packed grid in the same block, the master tiles and the three-byte objects in one new block and the distribution in another. vBaseline and vScale span the smallest and largest of the deltas the packing needs (zero included), and each delta is rounded against the position the decoder rebuilds, so the error never adds up along a row: over the 361 fields every one of the 5,742 vertices lies within half a step per axis of its PC position (at most 32.7 units, on M08's 100,000-unit backdrop; a few units on grass fields), with the PC tile id, colour and size.
Bones, lights, sprites and other blocks¶
SPropertyBones is the record in zprimcontrolbase.h. Its blocks are the PS2 bone blocks: for the 99-bone character in M00_main the global, local and inverse-global bones, conv bones, local quaternions, both id/index lookups, the id-to-position lookup, the parent lookup, the parent bones and the constraints are byte-identical to the PS2 ones; the bone definitions differ only in the padding after the names (0xcd on the PS2, 0 on the PC), and the pose header in the handles it holds. 30 of the 33 bone sets of M00_main have the same bone names on both releases. The converter keeps these blocks at their PC handles and points the PS2 bone-strip records at them.
Lights (type 12) are the base records (SPrimLightOmni, ...; type 1 is the 0x2c-byte omni light, 0 the spot, 2 the square spot, 3 and 4 environment lights) without the PS2 extension. With ZPrimControlPS2::Modify*Light's arithmetic added, all 1,537 lights of geoms both releases name the same way equal the PS2 records: 1,213 byte for byte, 324 within float rounding (9.5e-7).
Sprite arrays (type 2) have the PS2 layout and PC texture ids; particle sprite arrays carry draw destination 0 (the PS2's 0x81). GUI picture resources (ZWINPIC PicResourcePrim), post-filter tables and the other data blocks the PRP names are unchanged.
See PC mesh conversion for translation to PS2 strips, decal generation and measured limits.