merge ws/idtech: UDMF (codecs/model/DoomMap), Doom 3 / Quake 4 .map + .proc, Wolf3D VSWAP + GAMEMAPS, codecs/text/Lexer

This commit is contained in:
4DBug committed 2026-11-01 19:48:30 -06:00
commit 0e0b213a80
38 files changed
+11791 -2566

No files matched your search

+7
View File
@@ -68,6 +68,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | b3d | .b3d | yes | - | materials: true, textures: true, skins: true, animation: true, colors: true | `tests/model/b3d.luau` |
| model | bsp | .bsp | yes | - | variants: "quake", "halflife", "quake2", "quake3", lightmaps: "quake3" | `tests/model/bsp.luau` |
| model | buildmap | .map | yes | yes | sprites: true, slopes: true | `tests/model/buildmap.luau` |
| model | d3map | .map | yes | - | patches: true, variants: "doom3", "quake4" | `tests/model/d3map.luau` |
| model | dae | .dae .zae | yes | yes | materials: true, polygons: true, skins: true, morphTargets: true, animation: true, cameras: true, lights: true, zae: true | `tests/model/dae.luau` |
| model | fbx | .fbx | yes | yes | binary: true, ascii: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, polygons: true | `tests/model/fbx.luau` |
| model | gltf | .gltf .glb | yes | yes | binary: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, draco: true | `tests/model/gltf.luau` |
@@ -85,6 +86,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | off | .off | yes | yes | polygons: true, points: true, colors: true, binary: false | `tests/model/off.luau` |
| model | ply | .ply | yes | yes | ascii: true, binary: true, polygons: true, points: true, colors: true | `tests/model/ply.luau` |
| model | pmx | .pmx .pmd | yes | - | materials: true, skins: true, morphTargets: true, pmd: true | `tests/model/pmx.luau` |
| model | proc | .proc | yes | - | portals: true | `tests/model/proc.luau` |
| model | qb | .qb | yes | yes | voxels: true, truecolor: true | `tests/model/qb.luau` |
| model | rbxm | .rbxm .rbxl | yes | yes | tree: true, compression: "none", "lz4", "zstd" | `tests/model/rbxm.luau` |
| model | rbxmx | .rbxmx .rbxlx | yes | yes | tree: true | `tests/model/rbxmx.luau` |
@@ -93,6 +95,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | smd | .smd | yes | yes | skins: true, animation: true | `tests/model/smd.luau` |
| model | sourcemdl | .mdl | yes | - | skins: true, morph: true, animation: true, lods: true | `tests/model/sourcemdl.luau` |
| model | stl | .stl | yes | yes | ascii: true, binary: true, colors: true, indexed: false | `tests/model/stl.luau` |
| model | udmf | .udmf .textmap | yes | - | maps: true | `tests/model/udmf.luau` |
| model | usda | .usda .usd .usdz | yes | yes | materials: true, animation: true, cameras: true, lights: true, polygons: true, vertexColors: true, usdz: "read", usdc: false | `tests/model/usda.luau` |
| model | vbsp | .bsp | yes | - | versions: 19, 20, 21, displacements: true, staticProps: true, pak: true | `tests/model/vbsp.luau` |
| model | vmf | .vmf .vmx | yes | yes | displacements: true, roundTrip: true | `tests/model/vmf.luau` |
@@ -136,6 +139,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| archive | tar | .tar | yes | yes | variants: "ustar", "pax", "gnu" | `tests/archive/tar.luau` |
| archive | uu | .uu .uue .xxe .b64 | yes | yes | variants: "uu", "xx", "base64" | `tests/archive/uu.luau` |
| archive | vpk | .vpk | yes | yes | versions: 1, 2, multipart: true | `tests/archive/vpk.luau` |
| archive | vswap | .wl6 .wl1 .sod .sdm .vswap | yes | - | images: true, sounds: true | `tests/archive/vswap.luau` |
| archive | wad | .wad | yes | yes | images: true, maps: true, variants: "iwad", "pwad" | `tests/archive/wad.luau` |
| archive | xz | .xz .txz .lzma | yes | - | stream: true, filters: "lzma2", "lzma", "delta", "x86", "powerpc", "arm", "armthumb", "sparc", "arm64" | `tests/archive/xz.luau` |
| archive | yenc | .yenc .ync | yes | yes | multipart: true | `tests/archive/yenc.luau` |
@@ -155,6 +159,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| data | vdf | .vdf .acf .res .kv | yes | yes | ordered: true, binary: true | `tests/data/vdf.luau` |
| data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | namespaces: true, streaming: true | `tests/data/xml.luau` |
| data | yaml | .yaml .yml | yes | yes | ordered: true, multiDocument: true, anchors: true | `tests/data/yaml.luau` |
| vector | gamemaps | .wl6 .wl1 .sod .sdm | yes | - | tilemap: true | `tests/vector/gamemaps.luau` |
| vector | svg | .svg | yes | yes | rasterize: true, text: false | `tests/vector/svg.luau` |
| vector | tiled | .tmx .tmj .tsx .tsj | yes | yes | tilesets: true, infinite: true | `tests/vector/tiled.luau` |
| layered | aseprite | .aseprite .ase | yes | yes | layers: true, groups: true, animation: true, depths: 8, 16, 32 | `tests/layered/aseprite.luau` |
@@ -255,6 +260,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- **model**
- codecs/model/Brush: convex plane brushes -> polygons and Scene primitives, with Quake-family texture projection.
- codecs/model/Displacement: Source engine displacement surfaces (VBSP ddispinfo_t / Hammer dispinfo), as
- codecs/model/DoomMap: Doom / Heretic / Hexen binary map lumps (Hexen when BEHAVIOR is present) and UDMF TEXTMAP to
- codecs/model/Draco: Google Draco geometry decompression (.drc; glTF KHR_draco_mesh_compression; Roblox mesh v6 / v7).
- codecs/model/Mat4: 4x4 matrix (column-major, glTF / Types.Scene layout) and quaternion { x, y, z, w } helpers.
- codecs/model/MeshFlatten: a Scene to one world-space mesh, for the writers of mesh-only formats (STL, PLY, OFF).
@@ -269,6 +275,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- **text**
- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code.
- codecs/text/KeyValues: Valve KeyValues text (tier1/KeyValues.cpp of the Source SDK 2013, srctools' reading of it)
- codecs/text/Lexer: C-style tokens for id Tech / UDMF text (idLib idLexer conventions, UDMF 1.1 §I; no code taken):
- codecs/text/Nbt: Minecraft's Named Binary Tag format and SNBT (Minecraft wiki "NBT format", wiki.vg "NBT").
- codecs/text/Text: text decoding helpers: BOM stripping, Windows-1252 for text that is not UTF-8, line splitting.
- codecs/text/Url: RFC 3986 reference resolution (section 5.2), local-path classification and percent-encoding.
+5
View File
@@ -36,6 +36,9 @@ src/Rosetta/
text/ Json KeyValues Nbt Text Url Xml
font/ Bitmap Cff GlyphNames TrueType
model/ Brush Displacement Draco Mat4 MeshFlatten Minecraft Patch Polygon Rbx Rig Sampler SourceAnim Vrml
text/ Json Lexer Nbt Text Url Xml
font/ Bitmap Cff GlyphNames TrueType
model/ Brush DoomMap Draco Mat4 MeshFlatten Minecraft Patch Polygon Rbx Rig Sampler Vrml
host/ host (layer 2) runtime adapters; only the api uses them
Types.luau types (layer 1) standard types + constructors
core/ core (layer 0) Adler32 Base64 Bits Bytes Crc16 Crc32 Err Input
@@ -243,6 +246,8 @@ them. Anything generic goes down a layer and is called:
| animation channels sampled at a time; game-model frames, joints and skins -> Scene | `codecs/model/Sampler`, `codecs/model/Rig` |
| polygons with holes -> triangles | `codecs/model/Polygon` |
| studio model animation values (GoldSrc / Source run-length shorts, Quaternion48 / 64, bone records) | `codecs/model/SourceAnim` |
| Doom-engine maps (binary lumps, UDMF) -> tables and a Scene | `codecs/model/DoomMap` |
| C-style tokens (id Tech / UDMF text: comments, strings, numbers, words) | `codecs/text/Lexer` |
| plane brushes -> polygons (CSG hull, coplanar merge, Quake / Valve 220 / brush-primitive texturing); Bezier patches | `codecs/model/Brush`, `codecs/model/Patch` |
| Quake / GoldSrc mip textures, WAD2 / WAD3 directories; palettes (keyed index, grey, colormap) | `codecs/image/Miptex`, `codecs/image/Pixels` |
| NBT / SNBT values; Minecraft block states and colours | `codecs/text/Nbt`, `codecs/model/Minecraft` |
+19 -2
View File
@@ -210,7 +210,7 @@ assert(F.archive.load(bytes):read("maps/e1m1.bsp"))
A WAD's lumps keep their order; lumps of a map are named `"<map>/<lump>"` (`"E1M1/THINGS"`) and repeated names get
`"~2"`, `"~3"`, ... so every entry is unique (writing strips both again). The format module turns lumps into game
data: graphics (flats, patches, sprites, menu pictures) into Images through the `PLAYPAL` palette, wall textures
composed from their patches, and maps into a Scene (z up, map units: floors and ceilings triangulated from the
composed from their patches, and maps (binary lumps or UDMF `TEXTMAP`) into a Scene (z up, map units: floors and ceilings triangulated from the
sector outlines, walls, things as nodes standing on their floor).
```luau
@@ -254,6 +254,22 @@ local named = assert(F.archive.load(mpqBytes, { names = { "war3map.w3e" } }))
assert(#named:list() >= 2)
```
Wolfenstein 3D's page file (`VSWAP.WL6`, also `.WL1`, Spear of Destiny's `.SOD` / `.SDM`) loads as an Archive of
its pages (`walls/000`, `sprites/000`, `sounds/000`, `soundinfo`). The format module turns walls and sprites into
64 x 64 Images and the digitized sounds into Audio. The game's palette is not part of the file (nor redistributable):
pass its 768 bytes as `palette` (6-bit VGA values are scaled up); without it the images are grey.
```luau
local Vswap = F.format("vswap")
local pages = assert(F.archive.load(vswapBytes, { name = "VSWAP.WL6" }))
assert(pages:list()[1].name == "walls/000")
local wall = assert(Vswap.image(pages, "wall", 0, { palette = wolfPaletteBytes }))
local guard = assert(Vswap.image(pages, "sprite", 0, { palette = wolfPaletteBytes })) -- alpha 0 = hole
assert(wall.width == 64 and guard.height == 64)
local sound = assert(Vswap.sound(pages, 1)) -- u8 PCM at 7042 Hz, as f32 Audio
assert(sound.sampleRate == 7042 and Vswap.sounds(pages) == 2)
```
## Unix, package and disc archives
### cpio
@@ -431,7 +447,8 @@ assert(F.archive.load(out):list()[1].method == "store")
| bzip2 (`.bz2`, `.tbz2`) | yes | - | single stream |
| Brotli (`.br`) | yes | - | single stream; no magic number, so pass a `.br` name or `format = "br"` |
| PAK (`.pak`) | yes | yes | Quake / Quake II / Half-Life (and SiN `SPAK`) |
| WAD (`.wad`) | yes | yes | IWAD / PWAD; lumps, graphics, wall textures and maps through `F.format("wad")` |
| WAD (`.wad`) | yes | yes | IWAD / PWAD; lumps, graphics, wall textures and maps (binary and UDMF) through `F.format("wad")` |
| VSWAP (Wolfenstein 3D `.wl6` / `.wl1` / `.sod` / `.sdm`) | yes | | pages; walls, sprites and sounds through `F.format("vswap")` |
| GRP (`.grp`) | yes | yes | Build engine |
| VPK (`.vpk`) | yes | yes | versions 1 / 2, multi-part reading, preload bytes; writes one directory file |
| MPQ (`.mpq`, `.w3x`, `.sc2map`, ...) | yes | - | versions 1-4 (classic tables), encryption; no Huffman / ADPCM (WAVE) sectors |
+53
View File
@@ -625,6 +625,56 @@ local built = assert(F.model.load(assert(F.saveString(doc, { format = "vmf" })),
assert(#built.meshes[1].primitives == 1 and built.meta.entities[2].classname == "info_player_start")
```
## Doom maps (UDMF)
Doom-engine maps load as Scenes (z up, map units): floors and ceilings triangulated from the sector outlines, walls
with vanilla texture alignment, things as child nodes standing on their floor. Maps inside a WAD (binary lumps or a
UDMF `TEXTMAP`) load through `F.format("wad").map(wad, name)` (see the archive page); a standalone UDMF text
(`.udmf`, or a `TEXTMAP` lump saved alone) loads directly, with texture sizes from `textureSize` (else 64 x 128 walls
and 64 x 64 flats) and the textures as URIs. `F.format("udmf").data` gives the tables: every UDMF block keeps its
fields as written (`fields`, lower-case keys: namespace and `user_` keys too), flags are rebuilt in the binary layout
(Doom bits for the Doom / Heretic / Strife namespaces, Hexen bits otherwise), and unknown blocks stay in `blocks`.
```luau
local room = assert(F.model.load(udmfText))
assert(room.meta.source.format == "udmf" and room.meta.source.namespace == "ZDoom")
assert(room.nodes[3].translation[3] == 40) -- a thing 8 units above the 32-unit pillar
local Udmf = F.format("udmf")
local data = assert(Udmf.data(F.Bytes.reader(buffer.fromstring(udmfText))))
assert(data.sectors[1].fields.user_gravity == 0.5)
assert(data.linedefs[4].tag == 7 and data.blocks[1].type == "vavoombox")
```
## Doom 3 / Quake 4 levels
A compiled `.proc` file (dmap's render geometry: `mapProcFile003`, Quake 4's `PROC "4"`) loads as a Scene: each model
(the areas `_area0`, `_area1`, ... and the inline models of entities) is a mesh with a primitive per surface
(positions, normals, texture coordinates, Quake 4 vertex colours as `COLOR_0`) and a child node of the root; the
materials are URIs. id Tech 4 triangles are clockwise-front, so they are turned counter-clockwise. The portals between
areas, the BSP nodes and the shadow models load as data in `meta.proc`.
The editor's `.map` (`Version 2` for Doom 3, `Version 3` for Quake 4; told apart from Quake's `.map` by that line)
loads as a Scene too: `brushDef3` brushes (plane equations) become polygons through the same brush clipper as the
Quake maps, with Doom 3's texture matrices, and `patchDef2` / `patchDef3` surfaces become triangle grids (patchDef3 at
its stored subdivisions, patchDef2 at `patchLevel` segments per sub-patch). Each entity is a node with its keys in
`extras.keys`; entities with geometry get a mesh (in world coordinates), point entities their `origin`, `rotation`
or `angle`. `skip` leaves materials out (`"textures/common/caulk"`), `hull` drops faces hidden inside other brushes.
```luau
local level = assert(F.model.load(procText))
assert(level.meshes[1].name == "_area0" and level.meta.up == "z")
local proc = level.meta.proc
assert(proc.areas == 2 and proc.portals[1].positive == 1 and #proc.portals[1].points == 12)
assert(proc.nodes[1].negative == -1) -- < 0: area -1 - n; > 0: a node (1-based); 0: solid
assert(level.materials[1].name == "textures/base_wall/lfwall1")
local room = assert(F.model.load(d3mapText, { name = "room.map", skip = { "textures/common/caulk" } }))
assert(room.meta.source.format == "d3map" and room.meta.source.variant == "doom3")
assert(#room.meshes[1].primitives == 1) -- the floor material; caulk skipped
local start = room.nodes[3]
assert(start.extras.classname == "info_player_start" and start.translation[3] == 1)
```
## Blitz3D (B3D)
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
@@ -868,6 +918,9 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
| MD2, MD3, MDL, MD5, BSP, VBSP | yes | - | game models and maps: see "Game models" above |
| VMF | yes | yes (round trip, builders) | Hammer maps: see "Hammer maps (VMF)" above |
| SMD | yes | yes | Valve studiomdl data |
| Doom 3 / Quake 4 `.proc` | yes | | render geometry per area, portals and BSP nodes as data |
| Doom 3 / Quake 4 `.map` (d3map) | yes | | brushDef3, patchDef2 / 3, entities as nodes |
| UDMF (`.udmf`, `TEXTMAP`) | yes | | Doom maps as text: see "Doom maps (UDMF)" above |
| Roblox `.mesh` (robloxmesh) | yes | yes | see [roblox.md](roblox.md) |
| Roblox `.rbxm` / `.rbxl`, `.rbxmx` / `.rbxlx` | as an `RbxTree` | yes | instance trees with typed properties: see [roblox.md](roblox.md) |
+20 -1
View File
@@ -194,14 +194,33 @@ local back = assert(F.load(tmx))
assert(back.layers[1].data[6] == 0x80000009)
```
## Wolfenstein 3D maps
Wolfenstein 3D / Spear of Destiny maps are two files: `GAMEMAPS.WL6` (the Carmack + RLEW compressed planes) and
`MAPHEAD.WL6` (the RLEW tag and where each map starts). Load either one: the other comes through `files` /
`resolve` (loading a path finds it next to the file) or `mapHead` / `gameMaps`. A map loads as a TileMap with one
tile layer per plane (`walls`, `objects`, `plane3`) holding the raw tile values (1..63 walls, 90..101 doors, 106+
floor areas; things in `objects`), without a tileset; `map` picks the slot (default: the first present) and
`F.format("gamemaps").maps` lists them.
```luau
local files = { ["MAPHEAD.WL6"] = mapheadBytes }
local level = assert(F.load(gamemapsBytes, { name = "GAMEMAPS.WL6", files = files }))
assert(level.kind == "tilemap" and level.width == 16 and level.properties.name == "Tiny map")
assert(level.layers[1].name == "walls" and level.layers[1].data[1] == 1) -- the border wall
local maps = assert(F.format("gamemaps").maps(F.Bytes.reader(mapheadBytes), { gameMaps = gamemapsBytes }))
assert(#maps == 1 and maps[1].slot == 1)
```
## Formats
| Format | Read | Write | Notes |
|---|---|---|---|
| TMX / TSX | yes | yes | CSV, base64 (raw, zlib, gzip) and `<tile>` data; zstd data returns `UNSUPPORTED` |
| TMJ / TSJ | yes | yes | |
| Wolfenstein 3D GAMEMAPS + MAPHEAD | yes | | the `gamemaps` format: raw tile values, no tileset |
Both are the `tiled` format in [FORMATS.md](../FORMATS.md). Wang sets and terrains are dropped.
TMX and TMJ are the `tiled` format in [FORMATS.md](../FORMATS.md). Wang sets and terrains are dropped.
## Gotchas