Skip to content

PRM mesh decoding

WS7 step 4. port/engine/drawing/old/_sdl/primdecodesdl.{h,cpp} turns the PS2 prim records of an installed .PRM buffer into host vertex and index arrays. tools/port/prm_dump.py is the Python reference: it decodes the same way, writes OBJ files, a JSON summary, PNG previews and a survey, and prints per-submesh hashes that tools/port/tests/prim_decode_test.cpp compares with the C++ output.

API

  • PrimDecodeQuery(lPrim, &Sizes) walks the lNextPrim chain and returns the submesh, vertex, index and key-vertex counts. PrimDecode(lPrim, &Mesh) fills caller-owned arrays of at least that size (Mesh.Capacity) and reports what it used in Mesh.Used.
  • PrimDecodeQueryStrips and PrimDecodeStrips do the same for one resolved SPrimStripsPS2 * (a bone variant record is accepted too) without following the chain.
  • Handles resolve through g_apPrimHandleToPointerTable with bit 31 masked, so the functions work on a buffer installed by ZRenderBaseDll::InstallPrimBuffer. Bit 31 of lColors is the 16-bit colour flag. No pointer is ever stored in a 32-bit field.
  • Each sub-prim of a decodable type (strips 0, bone strips 1, wire strips 3, splines 4, bone variant 5, dot3 strips 6) becomes one SPrimDecodeSubMesh. Lights, sprite arrays, scatter, shadow meshes and water patches in a chain are skipped. A chain ends at a link that does not resolve or is not a prim type (five chains on the disc end that way).
  • Indices are uint16, relative to the submesh's lFirstVertex, three per triangle. A sub-prim has at most 255 chunks of fewer than 0x44 elements, so 16 bits are enough.
  • Key-framed sub-prims add lNrKeys full vertex arrays at pKeyVertices[lFirstKeyVertex + key * lNrVertices].

Vertex (SPrimDecodeVertex, 68 bytes): position, normal, UV, colour RGBA8 in PS2 units (0x80 is 1.0), four bone indices and four weights (uint8, summing to 255), tangent and binormal.

Submesh flags: NORMALS, COLORS, COLORS16, BONES, RIGID_BONE (pack type 8: the whole sub-prim follows DeformBones()[lRigidBoneId]), TANGENTS, KEYS, VARIANT, UVS, HIDDEN (draw mode 0x800000).

Data layout

  • File: SPrimBufferHeader, data, then the SHandleTableEntry table at lHandleTableOffset. 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_lDMAVertexSize quadwords: words 0 to 3 are the STROW start values, word 6 is STMOD 2 (difference mode), word 7 is UNPACK V4-8 (0x6e) or V4-16 (0x6d) with NUM = m_lNrElems and 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 times m_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 times fUVScale. Unpack addresses are elems + 3 and elems + 4 for strips and dot3, 0x5d and 0x5e for bone strips.
  • Colours: one RGBA8 word per element (V4-8 unsigned), or one RGBA5551 half-word (V4-5) when bit 31 of lColors is set, consecutive across chunks. With no colour handle the PS2 uploads g_WhiteChunk (0x80808080).
  • Strip lengths: m_lNrStrips bytes at m_lLengths, summing to m_lNrElems. Each strip owns its vertices; there are no restarts inside a strip and no vertices shared between strips. AddPrimChunksToDMAChain draws only the first lNrStrips strips of a type 0, 3 or 4 sub-prim; bone and dot3 sub-prims draw every strip.
  • Keys: SPrimKeyHeader then lNrKeys SPrimKey records, 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: lTangents and lBiNormals hold one signed byte vector per element (x, y, z, 0). Dot3 records converted from PC data keep both in one block: lBiNormals is the tangent handle with bit 31 set, and the binormals follow the tangents (PRIMDECODE_BINORMALS_AFTER_TANGENTS). No disc record sets that bit.
  • Bone strips: lCopyBones is lNrCopyBones pairs (rows, offset). Each pair uploads rows/4 matrices starting at DeformBones()[offset / 16] to VU1 at 0x388, in order; that order defines the bone slots (at most 30). Each chunk's weight block, m_lWeightsSize bytes at lVU1Weights + m_lWeights, is unpacked to VU1 address 2 as V4-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

Not decoded:

Record Count Why
sprite array (type 2) 30,309 SPRITETYPE_ARRAY_UV records, mostly in the pre-mission menus; 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

No real prim fails validation. The 3,381 records that look like prims by type and size but fail are other data that happens to match (VIF fragments, tables); none is referenced from a chain.

Static shadow meshes

port/engine/drawing/old/_sdl/shadowdecodesdl.{h,cpp} decodes the 1,726 static shadow meshes (type 10, 819,778 triangles on the disc). 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:

  • STROW with the batch's integer origin (x, y, z, 0);
  • UNPACK S-32 of the bounding sphere radius to TOPS+1 and UNPACK V2-32 of (index count, vertex scale) to TOPS+0;
  • UNPACK S-8 unsigned, one intensity byte per vertex, to TOPS+2;
  • STMOD 1 (offset mode), a masked UNPACK V3-8 of zeros to TOPS+1 (the sphere centre is the row) and a masked UNPACK V3-16 of signed per-vertex offsets to TOPS+2 (the mask keeps the intensity in W), then STMOD 0;
  • UNPACK V4-8 of 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); the decoder writes it in the strip decoder's winding, (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].

prm_dump.py shadows FILE.PRM and tools/port/tests/shadow_decode_test.cpp both print one line per mesh (handle, vertices, indices, a hash of positions, intensities and indices) and mark a mesh whose triangle count differs from lNumTriangles. On 14 November 2026 the two agreed on all 71 files, under AddressSanitizer and UndefinedBehaviorSanitizer:

python3 tools/port/prm_dump.py shadows build/prm/all/M00_M00_MAIN.PRM > build/prm/m00.shadows
clang++ $F port/engine/drawing/old/_sdl/shadowdecodesdl.cpp tools/port/tests/shadow_decode_test.cpp -o build/prm/shadow_decode_test
build/prm/shadow_decode_test build/prm/all/M00_M00_MAIN.PRM | diff - build/prm/m00.shadows

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), DRAWMODE_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) in SetPrimExtraData. Hidden sub-prims have no UV stream and so no normal X or Y; their Z alone is meaningless.
  • Triangle winding. The decoder emits 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-5 rules: 5-bit channels shifted left by 3, the alpha bit becomes 0x80. Alpha 0x80 is 1.0, like g_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. SetKeyChainFramePointers resolves key handles with ResolvePrim, which reads bit 31 as a raw pointer, and steps colours by four bytes per element, so those keys look broken on the PS2. The port masks the bit and decodes RGBA5551 like the base colours.
  • Bone variant alpha cutoff. AddBonePrimStripChainStart reads lAlphaCutoff from the variant record, past its 0x20 bytes. The port takes it from the target mesh.
  • LOD control on bone strips. 0x03 and 0x7c split high and low detail; 0x80 marks sub-prims that use DeformBones2(). Passed through, not interpreted.

Cross-check

python3 tools/port/prm_dump.py hashes build/prm/all/M00_M00_MAIN.PRM > build/prm/m00.hashes
F="-std=gnu++98 -fsigned-char -fno-strict-aliasing -fno-exceptions -fno-rtti -nostdinc++ -DNON_MATCHING -I port -isystem include"
clang++ $F port/engine/drawing/old/_sdl/primdecodesdl.cpp tools/port/tests/prim_decode_test.cpp -o build/prm/prim_decode_test
build/prm/prim_decode_test build/prm/all/M00_M00_MAIN.PRM build/prm/m00.hashes

The harness installs the buffer the way InstallPrimBuffer does, decodes every root the Python lists, and compares a hash of each submesh's fields, vertices, indices and key vertices. On all 71 files, 71,655 of 71,655 submeshes match bit for bit, with no decode failures, also under AddressSanitizer and UndefinedBehaviorSanitizer.

Previews

prm_dump.py dump FILE.PRM OUT --png --sheet --lod 0 --cull writes PNG previews (--mode normal colours by normal; --cull drops back faces so room interiors show; back faces are red otherwise). prm_dump.py survey FILE.PRM ... prints the survey above as JSON.

PC meshes

The conversion

PcConvertPrims(pPrm, lPrmSize, pMat, lMatSize, pOct, lOctSize, pPrp, lPrpSize, &pOut, &lOut, &Report) writes:

  • each object header becomes a chain at its own handle. Static and tweened objects become strips (type 0; pack 4 for PC pack 4, else 0); a header with rigid parts becomes a zero-chunk bone strips root (type 1, pack 8, the bone handles, an SPrimHeaderStripBones temp header with NumBonesUsedLOD and the constraints) followed by pack-8 strips with lRigidBoneId; a skinned header becomes bone strips (type 1, pack 7) with VU1 weight blocks and copy-bone lists. Static shadows become SPrimShadowMesh records (type 10). Objects keep the PC object-table order. The header's handle holds the first sub-prim's record (sharing its streams), each object's handle its own first sub-prim, so a handle that named a PC object still names a prim;
  • the root's temp header holds the header's bounds with the planes disabled (1e38), and the other strips of the chain share it; lColiId is on the root. Given the scene's .OCT (PcConvertPrims(..., pOct, lOct, ...)), the collision trees are rebuilt for the converted strips (oct.md "PC version") and the root's lColiId names the rebuilt record; without it the PC value stays, which only the PC OCT matches;
  • a skinned chain whose objects carry more than one non-zero variant id gets a variant array indexed by variant id (lNumVariants = largest id + 1), each entry the list of SPrimBoneStripVariant copies of that variant's sub-prims, as ZOldDrawBase::GeomCreate reads them; the PS2 indexes its arrays the same way (variants 1, 5, 9, 13, 17 of the M00 bikini girl);
  • vertex colours are the D3DCOLOR halved into PS2 units (0x80 = 1.0); the alpha of an object whose material blends by source alpha (TRANS, TRANS_ON_OPAQUE, ADD, ADD_ON_OPAQUE, ADD_BEFORE_TRANS) and has a diffuse map is quartered instead. The PC multiplies vertex alpha and texel alpha, both 255 = 1.0; the GS reads a texel's 255 as 2.0, and the disc's records carry a quarter of the PC's alpha for the same meshes (the pause map's noise layers: PC 64, 90, 128, disc 16, 22, 32; its glow 76 against 19). SHADOW (ZERO, INVSRCCOLOR on the PC) and TRANSADD_ON_OPAQUE (ONE, INVSRCALPHA) keep the half, as do opaque materials, whose 0x80 matches the disc's (PC rendering);
  • key-framed objects get an SPrimKeyHeader and one vertex stream per key (the base stream is key 0; UVs and colours are the base streams);
  • InsideBound boxes (material name containing "InsideBound") get lInsideCheckData: one outward plane per distinct face plane, 6 for every box, like the 67 PS2 ones of M00_main;
  • water patches become PS2 water records (type 11, 0x50 bytes, no chunks) with an SPrimWaterPatch temp header, at the object's handle and, for a header that holds only the patch, at the header's handle as the root (ZEngineDataBase counts the geoms whose root prim is a water patch to size ZWaterManager; in PC-data mode the port also counts patches inside chains, pc-data.md "Water"). The patch takes the PC grid, size, position, waves and group; the flags are 1 (the projective, true reflection) when the material has Reflection2DEnabled and 2 (the refraction pass) when it has Refraction2DEnabled; the Fresnel range, the reflection and refraction scales and the two pass colours (alpha 0x7f, as on the PS2) are the material's, pass 0 taking the diffuse colour when the material has no reflection pass. The record has the PS2 records' draw mode 4 and alpha cutoff 0x80 and lColiId 0 (the PC collision trees of water headers are empty); its texture is 0xffff when the material reflects, which puts the patch in a mirror group (ZOldDrawBase::GeomCreate, g_bUseTrueReflections) so the engine gathers the reflected view, and 0 otherwise (the PC's water shader never samples the diffuse map). After the 0xc4 bytes of SPrimWaterPatch the temp header carries an SPcWaterExtension (port/engine/system/_sdl/pcdata/pcwater.h, magic PCWS): the normal map, bump scale, specular colour, power and level, Fresnel power, scroll speed, the UV rectangle and the material's colours and scales as floats, which the port's PC-data water draw reads. Hidden patches (the two collision-only ones) are left out, as the engine draws every water patch it finds;
  • a header holding one scatter object becomes the PS2 scatter record (below);
  • with the scene's .PRP, one decal prim per decal mark after the PC handles (below);
  • lights get the PS2 extension, particle sprite arrays draw destination 0x81;
  • every other block stays at its handle byte for byte, and the PC vertex and index buffers, mesh lists and records, palettes and object tables (freed when the converted structures held all their references) are reused for the new blocks before the table grows.

Decal prims

ZBloodTrails, ZBloodSplatters, ZBloodStains and ZBulletMarks (zprojectmarks.cpp) give their m_PreCalcPrims array to IDraw::AddPrimArray on their first mark (CreateMark); ZArrayPrimAlloc::Create copies the first m_lMaxNrMarks handles and Flush reads each prim's lDrawEntryId, and ZGeometryDecal later fills a prim per mark with SetActiveNrTriangles and SetPrimExtraData (at most 96 vertices). On the PS2 those handles are prims the tool appended to the PRM: 16, 16, 16 and 32 per scene (the PS2 PRPs halve the PC's m_lMaxNrMarks of 32, 32, 32 and 64 in all 25 scenes that have decal systems). The PC engine makes its decal prims at run time (FUN_004f4480 sets up "rBulletMarks" with 16 marks), so the PC PRM has none and the PC PRP's arrays hold whatever the tool's memory held (5,195,856, 1, 2, 20, ...): the M09 and M12 crashes in ZArrayPrimAlloc::Flush were a bullet mark reading those.

A PS2 decal prim is seven handles in this order: two 16-byte strip-length blocks (sixteen 3s), the UV stream (0x360 bytes), the vertex stream (0x340), the chunk table (two ZPrimChunks: 0x1a and 0x1b quadwords, 16 strips, 48 elements, m_fVertexScale 1000/32,767, sphere radius 1e38), the temp header (planes disabled, vMax (1000, 1000, 31.007), vMin 0) and the 0x50 strips record (draw destination 1, texture 1, LOD 0xff, draw mode 0x10, 32 strips and 96 entries, two chunks, fUVScale 1/512). Its 32 placeholder triangles are (0, 1000, z), (0, 0, z), (1000, 0, z) for z = 31 down to 0 in 16-bit packets, UVs (0, 1), (0, 0), (1, 0). ZGeometryDecal overwrites the positions, UVs, normals, triangle count, draw setup and the bias of each prim it uses; only the bias differs between the PS2 tool's prims (12 + index for trails and splatters, 44 and 76 + index for stains and bullet marks).

pcdecals.{h,cpp} finds the decal systems in a PRP without the class schema: the IOPacked stream is self-describing, and a decal system is the only object whose 13 values are ZGEOM's five properties, Invisible, m_lMaxNrMarks, m_fFade, m_fRemove and an Int32 array (m_PreCalcPrims) with m_bMakeVisible and two floats before or after it. On all 139 PRPs of both releases this finds exactly the 200 decal systems the schema decode finds. PcConvertPrims, given the PRP, appends one decal prim per mark right after the PC handles (handles lNumPcHandles + 7 × mark to + 6, the prim last, bias 12 + index), before any other new block, and PcConvertProperties (the .PRP converter) writes m_lMaxNrMarks = half the PC count (a power of two, at most the array size) and the prims' handles into each array, zeroing the rest. Both need only the PRP and the PC PRM's handle count, so they agree without seeing each other's output; every later new handle moves by 7 × marks, so PcConvertCollision takes the same PRP. The 2,000 decal prims of the 25 scenes are byte for byte the PS2 tool's 2,000 (handles relative to the prim, the bias aside), and the PRP keeps its size with 531 bytes changed in M09_main.

Streams follow add_mesh above: greedy strips (longest first within a sub-prim), chunks of at most 62 elements and 16 strips (bone chunks also at most 352 weight-block bytes, the disc's largest), 16-bit deltas, m_fVertexScale one grid per object, 1/64 unit times the smallest power of two whose steps carry the largest delta between consecutive vertices of any of its chunks in 16 bits and every coordinate in 30 bits (ObjectVertexScale; 1/64 for 3,606 of M01_main's 3,938 strip objects); with a scale per chunk, as before 25 November 2026 for every chunk and until 26 November for chunks wider than 500 units (extent / 32,000), positions that two chunks share decoded apart by a fraction of a step and the background showed through faces and seams as single pixels (pc-data.md: Seams and white dots), normals (int)(n × 63), one power-of-two fUVScale per sub-prim (the finest from 1/1024 whose deltas fit), colours RGBA8 only when a vertex is not white, no UV stream on hidden sub-prims, more than 127 chunks split into chained sub-prims (collision ids have seven chunk bits). Chunks share strip-length blocks: the decoders read m_lNrStrips bytes, so any block that starts with a chunk's lengths serves it (238,728 of 270,061 chunks share one). A bone chunk's weight block is the header, the one-bone pairs to 0xff, the two-, three- and four-bone entries and an empty copy list; weights are the PC weights (same-slot weights summed, largest first) quantised to 255.

Static shadows: strips of the shadow triangles packed into batches of at most 126 vertices and 380 indices (the disc's largest are 127 and 382), each strip starting on an even index with the ADC bit on its first two indices, the batch's integer centre in STROW, the radius, index count and scale (one power-of-two grid for all of a mesh's batches since 26 November 2026, ShadowMeshScale; before, half the batch's extent / 32,000 each), one intensity byte per vertex (the PC colour's alpha: the PS2/PC ratio is 1.0 on the most common pairs), masked 16-bit offsets and the index bytes, then MSCAL 8. bIsLerp is 1 (as 489 of 505 PS2 meshes), vCen/vSize the bounds. Textured shadows (the StaticShadowTextureShadow class) get the material's texture and a 12-float projection: columns 0, 1 and 3 of the object's matrix rows, which are the PS2 header's numbers (Palm_Shadow_M10_01a: PC row 0 (−7.1949, 1.52325, −0.79129, −0.79126), PS2 P0 (−7.19485, 1.5233, −0.79126)). The PS2 shadow colours are a few units per channel; the converter writes about a 21st of the PC colour (exact on the most common pair, ff436580 → 0x060503, near on the others). Since 25 November 2026 the record is 0x6c bytes: after the 0x60 of SPrimShadowMesh comes an SPcStaticShadowExtension (pcstaticshadow.h: the magic "PCSS", the PC colour as it is, and the kind from the material's blend: 0 subtractive for STATICSHADOW, 1 additive for the ADD modes, 2 other), which the port's PC formula reads (pc-data.md: Scenery shadows); the PS2 code never reads past 0x60. StaticShadowTextureAdditive materials are textured too (mat.md "Static shadow materials"), and an additive mesh is written as the disc's light pools are, bIsLerp 0 and half the PC colour (0x80 = 1.0).

Draw setup from the object and its material, as measured over 19,831 sub-prims of the 13 mission scenes paired by triangle count with their PS2 twins:

  • an opaque Standard material with BumpEnabled and a normal map, on a static or rigid object, makes the sub-prim a dot3 record (SPrimStripsDot3PS2, type 6, 0x60 bytes): lNormalMapId from mapNormal, lSpecularMapId from mapSpecularMask (with SpecularEnabled), lSpecularColor from v4SpecularColor × vSpecularLevel × 128 per byte, fDisableDot3AtDistSq 4,000,000 and fDisableSpecularAtDistSq 9,000,000 (the values 519 of the 1,008 disc records carry), and the PC vertices' tangents and binormals as signed bytes (x, y, z, 0) at 1/127. The two vectors share one block: lTangents is its handle and lBiNormals the same handle with bit 31 set (the binormals follow the tangents; PrimDecodeStrips reads it, FreePrimData masks it), one handle per dot3 sub-prim. A scene that would pass the handle limit is converted again with dot3 only for objects of at least 32, 128 or 512 triangles, then without (only M06 needs it, at 32). 22,035 sub-prims of the 68 archives become dot3. With pc_shading (PcPrimsSetPcShading; pc-data.md "PC material shading") the record is followed by an SPcMaterialExtension (pcmaterialfx.h, 0x13c bytes since round 3: the PC material's maps, colours, levels and switches, mat.md "Standard materials", and its technique, PC blend, alpha fade, scroll, Glass, Mirror and Anisotropic terms), Standard materials that reflect or self-illuminate without a normal map and blended (TRANS) bump-mapped ones become dot3 records as well, and skinned objects with a bump-mapped Standard or SkinCloth material carry the extension after their 0x90-byte bone record. Over the 68 archives (pc_prims_test --pc-shading) that makes 28,030 dot3 sub-prims, the largest handle table 36,382 (M06_main, still with dot3 from 32 triangles) and 380.6 MB of converted prims against 364.1 MB without. Since round 3 the Glow, Glass, GlassSurface, Mirror and Anisotropic classes and the TRANSADD_ON_OPAQUE and SHADOW blends keep plain strips records but carry the extension from 0x48 (the record is written 0x50 bytes long, so the magic lies inside it), Glass and GlassSurface get DRAWMODE_ALPHA_BLEND (sorting), and a Mirror-class chain with a flat bound gets DRAWMODE_MIRROR_MASK and an 0x80-byte SPrimHeaderStripMirror as its shared temp header (pc-data.md "Other material classes"); pc_prims_test --pc-shading still passes over the 68 archives (25 November 2026: every triangle matched, 388.3 MB of converted prims);
  • the PC object's draw-mode bits carry over except 0x400000 (CalcGSRegs would read it as alpha blending) and 0x2000; a PC destination with RGB and without DD_MIRROR adds SKIP_MIRROR_VIEW, and DD_MIRROR is dropped (the PS2 never sets it); 0x10, which no PS2 code reads, is added as the PS2 data has it;
  • blend modes: TRANS and SHADOW add ALPHA_BLEND, TRANS_ON_OPAQUE ALPHA_BLEND | NO_ZWRITE, ADD and ADD_BEFORE_TRANS ADDITIVE | FORCE_NO_ZWRITE, ADD_ON_OPAQUE and TRANSADD_ON_OPAQUE ADDITIVE | NO_ZWRITE; blending drops RECEIVE_SHADOWS; an opacity below 1 adds TRANSPARENT; hidden objects get LIT | RECEIVE_SHADOWS and TRANSPARENT or 0x10, InsideBound boxes TRANSPARENT only;
  • OneSided culling adds ONE_SIDED, TILU/TILV other than "TILED" the clamp bits;
  • a material whose RenderState has FENA 0 adds PRIMDRAWMODE_NO_FOG (0x100000), the bit the PC's effects also test before they turn fog on (M00's sky, clouds and sun; pc-data.md "Post filters");
  • lTextureId is the diffuse map's PC texture id, lAlphaCutoff AREF / 2 with alpha test (else 0x80), lBias the z bias, lDiffuseColor the diffuse colour (truncated, 255 = 1.0) with alpha 0xff, or opacity × 255 when the opacity is below 1 (the disc's records carry opacity × 127, which the PS2 draws at half; pc-data.md "Blended surfaces");
Field Same as the PS2
sub-prim type / pack type 97.9% / 100% (measured before dot3: the 2.1% were PS2 dot3 strips the converter wrote as plain strips; it now writes every opaque bump-mapped material as dot3, about a quarter of the sub-prims, where the PS2 chose 2.1%)
draw mode, all / drawn sub-prims 86.4% / 89.2%
alpha cutoff 98.9%
diffuse colour 77.8% (the PS2 colours were tuned separately: PC 0.22 grey materials are 0.44 on the PS2)
collision bits, LOD control, bias, rigid bone 99.97%, 99.89%, 99.66%, 100%
chain triangle count, root bounds (to 1 unit) 91.8%, 91.4% (the PC meshes are finer: 2 to 3 times the PS2's triangles)
bone count of paired bone sub-prims 100%

The remaining draw-mode differences are the Glow class's angle blending (the PS2 sets 0x40, 0x400000, 0x10000000 and 0x20000000 on alpha-faded glows; see mat.md), RECEIVE_SHADOWS kept on some blended PS2 meshes and LIT on a few unlit PC ones.

Measurements

tools/port/tests/pc_prims_test.cpp converts every PC PRM with its MAT, installs the result as InstallPrimBuffer does and decodes every chain with the port's decoders (primdecodesdl.cpp, shadowdecodesdl.cpp) against its own reading of the PC objects:

F="-target x86_64-windows-gnu -O2 -DNON_MATCHING -fsigned-char -fno-strict-aliasing -fno-delete-null-pointer-checks
   -ffp-contract=off -std=gnu++98 -fno-exceptions -fno-rtti -nostdinc++ -Isrc -Iport -w"
zig c++ $F tools/port/tests/pc_prims_test.cpp port/engine/system/_sdl/pcdata/pcprims.cpp \
    port/engine/system/_sdl/pcdata/pcmaterials.cpp port/engine/system/_sdl/pcdata/pccollision.cpp \
    port/engine/system/_sdl/pcdata/pcdecals.cpp \
    port/engine/drawing/old/_sdl/primdecodesdl.cpp port/engine/drawing/old/_sdl/shadowdecodesdl.cpp \
    -o build/pc-only/prm/pc_prims_test.exe
build/pc-only/prm/pc_prims_test.exe [-v] [--out DIR] build/pc-only/corpus-pc
build/pc-only/prm/pc_prims_test.exe --fuzz build/pc-only/corpus-pc/M01_M01_POSTMISSION/Scenes/M01/M01_postmission.PRM 2000

On 24 November 2026, over all 68 archives (each PRM with its sibling MAT, OCT and PRP):

  • 68 of 68 convert; all 32,351 object headers decode, each to exactly its PC triangles: 9,128,191 of 9,128,191 mesh triangles matched vertex by vertex (positions within half a chunk step, at most 7 units on a 100,000-unit sky dome and float precision elsewhere; the PS2 winding), with no UV error beyond fUVScale, 1,834 normals of 27 million vertex checks more than 0.06 away (degenerate PC normals), and for skinned meshes the bone of the largest weight and that weight right on every vertex. 2,017 static shadows decode to 1,177,275 of 1,177,282 PC triangles (the 7 are sliver triangles the test pairs with a neighbour) with 1,571 intensity mismatches at coincident vertices. Since 26 November 2026 the test pairs shadow triangles with a maximum matching (best fit, then augmenting paths) and matches all 1,177,282, with the object and mesh grids (pc-data.md: Seams and white dots), 2,310 intensity mismatches;
  • every handle the PRP, GMS and BUF name is valid: 129,372 Prim properties and GMS lPrims resolve to prims of the right kind with the PC header's bounds, 2,614 particle prim tables and 3 particle prims to prims, 22,753 GUI picture resources, 87 camera overlays and 55 post-filter tables are unchanged. With the PRP converted by PcConvertProperties, the first m_lMaxNrMarks entries of all 100 decal systems (2,000 marks) name distinct strips prims with no draw entry, 16-bit packets where SetPrimExtraData expects them, room for 96 vertices and 32 decodable triangles (build/pc-only/prm/extcheck.py checks the same from the PRP side). The Loader_Sequence buffers have no meshes and come out byte-identical, so the ZLoader_Sequence_Setup byte offsets still point at their script text;
  • 0.03 to 0.11 s per mission scene (1.5 s for all 68) on one core of the test machine, twice that with the collision rebuild (which runs the prim conversion again; oct.md "PC version");
  • --fuzz changes 1 to 64 random bytes of a PRM and its MAT per round: 2,000 rounds of M01_postmission, 300 of HitmanBloodMoney and 300 of M01_premission convert or are rejected without a crash, and every converted chain decodes without one; PRP rounds (400 of M09_main: 101 PRP rounds, 16 converted) never crash, and the PRM and PRP converters always agree on accepting a PRP and on its decal count;
  • water: 40 of the 42 PC patches become water records whose SPrimWaterPatch repeats the PC fields and whose PC extension has the object's UV rectangle, with texture 0xffff and the projective flag exactly when the material reflects; the 2 hidden ones are left out;
  • scatter: all 361 fields decode as the port's grass draw reads them, within half a quantisation step (above), with the PC master tiles;
  • dot3: 22,035 dot3 sub-prims; 6,333,210 matched vertices of dot3 sub-prims carry the PC tangent and binormal within 1/254 (148 more than 0.06 away, where the triangle pairing meets degenerate PC vertices, as with the normals);
  • handles: the largest table is 36,156 of 40,960 (M06_main, with dot3 for objects of 32 triangles or more; 560 decal prims; the PC original uses 28,455, the PS2 23,747). The converter refuses a result above 36,864 handles to leave 4,096 for run-time allocations;
  • sizes: 364 MB from 376 MB of PC PRMs (the PS2's are 158 MB); the mission scenes are 7 to 26 MB, 1.2 to 3.5 times the PS2's, with 0.9 to 2.6 times the strip chunks and up to 3.1 times the triangles (the table counts strip and shadow triangles). The figures below are from 25 November 2026, with water extensions, scatter and dot3.
Scene ms PC handles out PS2 PC MB out MB sub-prims chunks triangles
HitmanBloodMoney 68 9,110 12,397 — 12.4 13.9 1,559 9,656 427,682
hideout_main 33 13,413 15,382 12,643 9.3 7.2 1,895 5,402 174,150
M00_main 82 22,351 27,431 19,345 16.8 14.0 4,308 10,586 378,978
M06_main 248 28,455 36,156 23,747 18.5 22.7 5,597 17,473 667,244
M09_main 126 25,933 33,594 20,890 25.0 25.8 5,067 19,266 773,202
M11_main 118 24,118 34,566 20,539 18.2 26.0 5,184 20,303 763,254
M13_main 53 13,460 15,827 12,885 13.6 11.5 2,064 7,590 333,139

The Python probes behind these numbers are in build/pc-only/prm/ (pcprm.py, pcmat.py, pcdecode.py, compare.py, convcmp.py, extcheck.py; decalsig.py, decalcmp.py and decalall.py for the decal prims, water3.py to water5.py for the water patches).

PC character levels of detail

The PC characters have one level of detail more than the disc's: where the disc draws one mesh at levels 0 and 1 (mask 0x03), the PC draws a finer mesh at level 0 (mask 0x01) and the disc's mesh at level 1 (0x02); 0x7c and 0x80 are the same on both. The PC's level 1 is the disc's mesh triangle for triangle: in every paired character the disc's level-1 sub-prims lie on the vertices of the PC's level-1 objects of one material, and each PC material gets exactly its triangles. PC-data mode draws the PC level 0 as it is: PcConvertPrims keeps every object's lLODMask as the sub-prim's lLODControl and puts each variant's objects in that variant's list (pc_models_test --pc: in M00 the 16 PC characters with a finer level 0 draw 71,073 triangles there against 52,216 at level 1).

PcMergeCharacterModels (port/engine/system/_sdl/pcdata/pcmodels.h, in pcprims.cpp) puts the PC level 0 into a disc .PRM (the pc_models setting; docs/development/port/pc-assets.md):

  • Characters. A disc root is a bone strips record (pack 7) no strips, dot3 or bone strips record links to (a record is told from a stream block by its exact size and handle-sized temp header and chunk table words). Its chain is the bone strips records after it.
  • Pairing with a PC skinned header (lPropertyFlags bits 0 and 3). Bones: every disc bone must be on the PC under the same name with the same global (bind) matrix to 1e-3, and the PC may have at most a ninth more. The PC adds muscle helpers the disc drops (xtra_lmus_forearm and xtra_rmus_forearm on the M00 Scoop, Swing King and lawyer, nine xtra_ bones on the M06 guests); a PC bone the disc lacks is drawn with its nearest PC ancestor the disc has, and a bone at or past the disc's level-0 bone count (NumBonesUsedLOD[7]) with its nearest disc ancestor below it. Variants: the disc's non-empty lists and the PC's variant ids must be the same set; without a variant array the PC must use one id. Level 1, per variant: the disc records with bit 1 and the PC objects with bit 1 must have the same triangles; the disc records are grouped by their sub-prim's material slot (lVariantId), each group goes to the PC material most of its vertices lie on (within 0.05 units), with a search over the groups that lie on several equally well, and every PC material must get exactly its triangles.
  • Draw setup. Each PC object of level 0 only (bit 0 without bit 1) takes the draw setup of the disc record with the most triangles on the PC level-1 material that is the same instance, else that has the same diffuse map (6 objects over the corpora), the same name, or on whose vertices at least 75% of its vertices lie (12). Left out as PC-only layers: materials without a diffuse map (Characters/_Nude/Eyes_outer, a 108-triangle shell over the eyes, ADD_BEFORE_TRANS with a black diffuse colour, drawn for its specular highlight), blended materials and the Glass class (Accessories_Glass_Transp, glasses lenses with reflection and refraction, which the disc's characters do not have), and hidden objects. A character with another object that finds no setup stays the disc's.
  • Writing. Each distinct PC object (by vertex and index buffer; the PC copies objects per variant) is converted once with the PC-data converter (ReadObject, ConvertObject), its palette rewritten as one copy pair per slot in disc bones. The new bone strips records take the source record's destination, texture, bias, lVariantId, draw mode, diffuse colour, temp header, collision bits, z offset, alpha cutoff and bone fields (with references added), keep the PC mask (0x01) and their own streams, weights and copy pairs, and are linked after the chain's last record, which passes its old link on. Each variant list that gains objects is rewritten in place with its old records and one record per new sub-prim (a copy of the source variant record with the PC mask and lPrim), and the array's counts follow. Disc records (sub-prims and variant records) on a PC material whose level-1 objects lack bit 0 lose bit 0. A character whose PC level 0 is no finer than its level 1 (the burned actor and the body bag in M00, the same 1,138 and 374 triangles) is left alone, and so is one the disc already gives a level 0 of its own (records with bit 0 and without bit 1: the M09 dog's 966 triangles in 0x01 sub-prims, which are the PC's level 0, and M06's crowd guests), which would otherwise draw both. Everything else keeps its handle and bytes; the new blocks get handles after the disc's.

Over the 68 scene pairs (tools/port/tests/pc_models_test.cpp, 25 November 2026): 374 disc skinned chains; 164 have a bone-compatible PC header with a level 0; 17 of those are no finer, 118 are merged, 29 stay the disc's (12 with a level 0 of their own on the disc, 9 whose level 1 differs between the releases, 5 whose variants differ, 3 with a level-0 material that finds no setup: a redneck torso, a wedding guest's and an M06 assassin costume's head). The merged characters' level 0 goes from 253,163 to 326,882 triangles (1.29 times; per character 1.17 for 47 to 1.46), with 1,616 new sub-prims and 541 PC-only layers left out (counted per variant). The largest table is M06's 24,658 handles (23,747 on the disc); M00 grows from 6.4 MB to 7.5 MB and takes 69 ms. Every chain and variant list decodes; level 1 draws the same triangles as before; every vertex is weighted to a disc bone with weights summing to 255.

Scene Skinned chains Merged / candidates Level 0 triangles
HitmanBloodMoney (title) 14 11 / 14 23,102 → 30,439
M00_main 15 8 / 10 17,062 → 22,202
M01_main 16 10 / 11 22,285 → 28,453
M02_main 16 9 / 11 19,868 → 25,972
M03_main 21 9 / 10 19,453 → 25,366
M04_main 14 8 / 9 17,931 → 23,140
M05_main 16 9 / 12 19,167 → 24,604
M06_main 89 6 / 24 12,956 → 16,830
M08_main 14 8 / 10 17,598 → 21,983
M09_main 20 9 / 12 19,412 → 24,561
M10_main 15 10 / 11 21,219 → 27,741
M11_main 31 6 / 10 12,210 → 15,590
M12_main 14 7 / 10 14,244 → 18,619
M13_main 14 7 / 8 14,381 → 18,719
hideout_main 10 1 / 2 2,275 → 2,663

The pre-mission scenes' five chains have no PC level 0, and the other scenes have no skinned chains.

Not converted yet

  • angle-blended glows (see mat.md), wobble, texture scrolling of Standard materials and the header normal planes;
  • the PC-only parts of the materials that have no PS2 record field: cube-map environment reflections, illumination maps, rim light, sub-surface, parallax, bump detail maps, and the bump scale and specular power of dot3 materials (mat.md "Standard materials"). The opacity of M08's backdrop tree scatter (0.12) is not among them: the PC's scatter effect never reads it (pc-data.md "Scatter");
  • 8-bit packets (the converter always writes 16-bit ones).