Skip to content

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 of ROOMCONTROL_InInnerRoomList marks avoids testing a room twice. It then line-tests the room's GT_StdObjs bound 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. Otherwise rectBoxColi of the query box against (m_mMat, m_vCen, m_vSize). If m_rZBound is set and resolves, CheckBoxInsidePrim runs on the bound's prim, with the query moved by m_vCen and m_mMat. At most 256 rooms are returned.
  • Point (InnerRoomFuncPoint, line 71): |R(P − m_vCen)| ≤ m_vSize per axis, where R = m_mMat unless axis-aligned. Then CheckPointInsidePrim on the bound prim, with P moved by m_vPos and m_mMat.
  • GetInnerRoomsLst tries 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 drops ZBackdrop rooms 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 is m_vCen ± m_vSize for axis-aligned boxes, and m_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 .OCT root block (23 files). There the half extent is the root's 32000 / scale minus 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 ids tree 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_albino and the loader do. Write one axis-aligned box per file naming REF 1 (the root ZROOM): m_lMatIsAxisAligned 1, matrix (0,0,1, 0,1,0, 1,0,0), m_vCen and m_vSize around the playable space, m_vPos 0, m_rZBound 0. Use the same file for RMC and RMI. rooms.py selftest builds it (132 bytes).
  • Several rooms: one or more boxes per ZROOM, grouped by room. Make the RMC objects cover each room's collision geometry. Pass bounds= with the union of the box and the room's GT_StdObjs extent. 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 are ZROOM properties (ExitsOffset, NeighborsOffset into 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_ and GetGeomsInBox dereference m_pRoomColiTree without 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 makes GetInnerRoomsLst return nothing.
  • Each room REF must be a static container with its own block in the .OCT, and its GT_StdObjs tree 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_vPos on RMI boxes without a m_rZBound (570 of them differ from m_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_mMat on axis-aligned boxes: 814 RMC and 449 RMI axis-aligned boxes carry a rotation, which only the bound-prim test reads.