Scene room trees (.RMC, .RMI)¶
Every scene archive (SCENES/**.ZIP) holds a .RMC and a .RMI. ZEngineDataBase::LoadRoomTrees (src/engine/enginedata/enginedatabase.cpp:1420) reads each one into its own buffer: GetRoomColiTreeData (line 300) and GetRoomInsideTreeData (line 312). It installs them as compiled octrees: ZCollisionBase::InstallCollisionBuffer builds m_pRoomColiTree (zcollisionbaseold.cpp:207) and InstallInsideBuffer builds m_pRoomInsideTree (line 215). The two files have the same format. Each is a spatial index of room boxes in world space. They answer "which rooms does this line, box or point touch". The rooms themselves, their exits (portals) and their neighbour lists are ZROOM geoms. Their exits and neighbours live in the .BUF, through the ExitsOffset and NeighborsOffset properties in the .PRP (docs/internals/formats/buf.md).
tools/port/scene/rooms.py reads, writes and builds both. All 71 RMC and 71 RMI files on the disc round-trip byte for byte.
File layout¶
| Offset | Size | Part |
|---|---|---|
| 0 | tree size | a compiled octree (ZOctreeCompiled): SCompiledTreeHeader, nodes, 0xcd padding, CObjectInfo objects. This is the format of docs/internals/formats/oct.md#compiled-tree-zoctreecompiled-srcenginecollisionoctreecompiledh. |
| tree size | 0x54 × boxes | SRoomTreeBox records, back to back, to the end of the file |
A leaf id is the byte offset of its box from the start of the file. The callbacks add it to GetTreeDataPtr(): InnerRoomFuncPoint (zcollisionbaseold.cpp:73), InnerRoomFuncBox (line 110) and CalcRoomLineCallBack (line 256). In every file, each box is referenced by exactly one object, and the boxes follow the tree with no gap. The boxes of one room are contiguous. The tree objects were inserted in box order, so each node lists its objects in descending offset.
An empty file is 32 bytes: a header, the root node with no objects, and 10 bytes of 0xcd. 11 of each kind on the disc are empty: the eleven _premission scenes. Their .OCT still has collision trees, but no static query can reach them without rooms.
SRoomTreeBox (zcollisionbaseold.h:81, 0x54 bytes)¶
| Offset | Field | Meaning | Read by |
|---|---|---|---|
| 0x00 | m_lMatIsAxisAligned |
non-zero: m_vSize is the half extent along the world axes and the box tests ignore m_mMat |
both box callbacks |
| 0x04 | m_mMat |
M33, 9 floats. The rotation of the box (world to local with vmtmul). It is orthonormal with determinant −1 in every record. Axis-aligned boxes usually carry (0,0,1, 0,1,0, 1,0,0), which is the identity in IOI's axis convention. |
box tests when not axis-aligned; the bound-prim test always |
| 0x28 | m_vCen |
box centre, world space | box tests; the box-query bound test |
| 0x34 | m_vPos |
origin of the room's ZBound prim, world space | the point-query bound test (InnerRoomFuncPoint line 92) |
| 0x40 | m_vSize |
half extents | box tests |
| 0x4c | m_rRoom |
REF of the ZROOM (or ZBackdrop) geom |
every callback (ZGEOM::RefToPtr) |
| 0x50 | m_rZBound |
REF of a ZBound whose prim refines the inside test, or 0 |
InnerRoomFuncPoint and InnerRoomFuncBox (CheckPointInsidePrim, CheckBoxInsidePrim) |
REFs are run-time ZBaseGeom slot numbers + 1, as in the .OCT bound trees (docs/internals/formats/oct.md). Nothing remaps them. The root ZROOM "ROOT" is REF 1, and in single-room scenes (loader, M00_albino) the only box names it. The room REFs of a file match the root's GT_TreeGroups bound-tree entries in the .OCT where the root lists its rooms (for example M00_news: rooms 9 and 5, root GT_TreeGroups 5 and 9).
RMC and RMI¶
.RMC, room collision tree |
.RMI, room inside tree |
|
|---|---|---|
| Installed as | m_pRoomColiTree |
m_pRoomInsideTree |
| Queries | CalcLineColi_ (line 727): every static line test (sight, bullets, CheckLineColi); GetGeomsInBox (line 799), which GetStripsInsideBox and character movement (ZCollisionBox::GetStrips) use; GetColiRoomsLst |
GetInnerRoomsLst (line 615): the rooms the camera is in, which start the portal walk (zoldviewbase.cpp:2360), automatic room assignment of geoms (ZBaseGeom::AutoAssignToRooms, zbasegeom.cpp:1415), actors, sound, explosions; GetInsideRoomsLst |
| Boxes on the disc | 1,980 (0 to 266 per file); 1,959 axis-aligned | 2,136 (0 to 225); 1,915 axis-aligned |
m_rZBound |
always 0 | set on 397 boxes |
m_vPos |
always (0, 0, 0) | equal to m_vCen on 1,453 boxes, another point on 683 (240 of them zero) |
| Same boxes as the other file | in 46 of 71 scenes (43 files are byte-identical) |
Both trees always contain the same set of rooms.
What each query reads¶
- Line (
CalcRoomLineCallBack, line 254): the tree objects' bounds are the only spatial test. The callback does not look at the box. It takes the room if the geom is active and visible. A 16-entry ring ofROOMCONTROL_InInnerRoomListmarks avoids testing a room twice. It then line-tests the room'sGT_StdObjsbound tree in room-local space. An RMC object must therefore cover all of the room's collision geometry, not only its box. - Box (
InnerRoomFuncBox, line 108). Axis-aligned:|C − m_vCen| ≤ m_vSize + TransformBox(query)per axis. OtherwiserectBoxColiof the query box against (m_mMat,m_vCen,m_vSize). Ifm_rZBoundis set and resolves,CheckBoxInsidePrimruns on the bound's prim, with the query moved bym_vCenandm_mMat. At most 256 rooms are returned. - Point (
InnerRoomFuncPoint, line 71):|R(P − m_vCen)| ≤ m_vSizeper axis, where R =m_mMatunless axis-aligned. ThenCheckPointInsidePrimon the bound prim, with P moved bym_vPosandm_mMat. GetInnerRoomsLsttries a point query first and falls back to a box query. It then drops every room that is an ancestor group of another room it found, so the innermost room wins. It also dropsZBackdroprooms unless asked to keep them.
How the files were built¶
- Tree layout: the rules in
docs/internals/formats/oct.md#how-the-tool-built-the-trees. They rebuild all 142 trees from their own objects (rooms.py rebuild). - Object bounds: on 1,677 of 1,980 RMC objects and 1,794 of 2,136 RMI objects, the object is the box's world AABB, quantised as in the
.OCT: double precision,int, max + 1. The AABB ism_vCen ± m_vSizefor axis-aligned boxes, andm_vCen ± TransformBox(m_mMat, m_vSize)otherwise. On the other objects the object is larger, by up to thousands of units (231 RMC and 119 RMI of them contain the box), or offset. It is not the union of the room's boxes. Probably it is the bounds of the room's geometry, or the boxes were edited after the trees were built. - Frame: scale is
16000 / largest half extent, so the indexed extent fills the middle half of the octree range on its largest axis (attractmode, the loaders and the small scenes span 16767 to 48769 at most). In the menu scenes the extent is that of the boxes (tree_frame, which reproduces 21 of the 60 non-empty files). In the missions it is a larger scene bound with the same origin as the.OCTroot block (23 files). There the half extent is the root's32000 / scaleminus the 0.1 margin (exact in 11 files). RMC and RMI share the frame in 68 of 71 scenes. rooms.py build(boxes)writes the boxes in the given order with idstree size + 0x54 × i.bounds=takes per-box object bounds, for an RMC that must also cover geometry outside the box. With the file's own frame, it reproduces 23 RMC and 25 RMI files exactly from their boxes alone. The rest differ only in the objects that are not the box AABB.
What a new scene needs¶
- One room, the root: the smallest working pair is what
M00_albinoand the loader do. Write one axis-aligned box per file naming REF 1 (the rootZROOM):m_lMatIsAxisAligned1, matrix (0,0,1, 0,1,0, 1,0,0),m_vCenandm_vSizearound the playable space,m_vPos0,m_rZBound0. Use the same file for RMC and RMI.rooms.py selftestbuilds it (132 bytes). - Several rooms: one or more boxes per
ZROOM, grouped by room. Make the RMC objects cover each room's collision geometry. Passbounds=with the union of the box and the room'sGT_StdObjsextent. Give the RMI boxes that tile the space, because the camera's room comes from the RMI. A camera outside every RMI box starts the portal walk with no rooms. Exits between rooms areZROOMproperties (ExitsOffset,NeighborsOffsetinto the.BUF), not part of these files. The two-room mission in new-scene.md uses one axis-aligned box per room in both files, adjacent at the shared wall, and that is enough for the portal walk. - Do not leave the RMC out of a scene with collision.
CalcLineColi_andGetGeomsInBoxdereferencem_pRoomColiTreewithout a null check, and it stays null when the file is missing. An empty 32-byte tree is safe and finds no rooms. A missing RMI only makesGetInnerRoomsLstreturn nothing. - Each room REF must be a static container with its own block in the
.OCT, and itsGT_StdObjstree must list the room's mesh geoms.
Unknown¶
- What the tool used for the RMC and RMI objects that are not the box AABB (303 and 342 objects).
- Where the mission frame comes from exactly (a scene bound wider than the root's lights-included bound, apparently without the 0.1 margin). It does not matter to the engine as long as the rooms fit in the range.
- The meaning of
m_vPoson RMI boxes without am_rZBound(570 of them differ fromm_vCen). Only the bound test reads it. - Why the box sets of RMC and RMI differ in 25 scenes: different box sources in the tool, perhaps collision volumes against visibility volumes.
m_mMaton axis-aligned boxes: 814 RMC and 449 RMI axis-aligned boxes carry a rotation, which only the bound-prim test reads.