merge ws/quake

This commit is contained in:
4DBug committed 2026-11-01 20:08:48 -06:00
commit 58df9e8a3a
39 files changed
+10044 -1413

No files matched your search

+6 -1
View File
@@ -18,11 +18,13 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| image | ilbm | .iff .ilbm .lbm .pbm | yes | yes | alpha: true, palette: true, depths: 1, 2, 3, 4, 5, 6, 7, 8, 24, 32 | `tests/image/ilbm.luau` |
| image | jpeg | .jpg .jpeg .jpe .jfif | yes | yes | lossy: true, alpha: false, depths: 8, 12, progressive: true, arithmetic: true | `tests/image/jpeg.luau` |
| image | ktx | .ktx2 .ktx | yes | yes | alpha: true, float: true, mipmaps: true, cubemap: true, compressed: "bc1", "bc2", "bc3", "bc4", "bc5", "bc6h", "bc7", "etc1", "etc2", "eac" | `tests/image/ktx.luau` |
| image | lmp | .lmp | yes | yes | alpha: true, depths: 8, variants: "qpic", "palette", "colormap" | `tests/image/lmp.luau` |
| image | pcx | .pcx .pcc .dcx | yes | yes | alpha: true, palette: true, depths: 1, 2, 4, 8, 24, 32 | `tests/image/pcx.luau` |
| image | png | .png .apng | yes | yes | animation: true, alpha: true, depths: 1, 2, 4, 8, 16 | `tests/image/png.luau` |
| image | pnm | .pnm .pbm .pgm .ppm .pam .pfm | yes | yes | alpha: true, depths: 1, 8, 16, 32, float: true | `tests/image/pnm.luau` |
| image | qoi | .qoi | yes | yes | alpha: true, depths: 8 | `tests/image/qoi.luau` |
| image | sgi | .sgi .rgb .rgba .bw .int .inta | yes | yes | alpha: true, depths: 8, 16 | `tests/image/sgi.luau` |
| image | spr | .spr | yes | yes | alpha: true, animation: true, variants: "quake", "halflife", "spr32" | `tests/image/spr.luau` |
| image | sunras | .ras .sun .rs .im1 .im8 .im24 .im32 | yes | yes | alpha: true, palette: true, depths: 1, 8, 24, 32 | `tests/image/sunras.luau` |
| image | tga | .tga .icb .vda .vst .tpic | yes | yes | alpha: true, palette: true, depths: 8, 15, 16, 24, 32 | `tests/image/tga.luau` |
| image | tiff | .tif .tiff | yes | yes | alpha: true, pages: true, depths: 1, 2, 4, 8, 16, 32, float: true | `tests/image/tiff.luau` |
@@ -67,7 +69,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | 3mf | .3mf | yes | yes | materials: true, vertexColors: true, textures: true, units: true | `tests/model/3mf.luau` |
| model | b3d | .b3d | yes | - | materials: true, textures: true, skins: true, animation: true, colors: true | `tests/model/b3d.luau` |
| model | blend | .blend | yes | - | materials: true, textures: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true, polygons: true, compressed: true | `tests/model/blend.luau` |
| model | bsp | .bsp | yes | - | variants: "quake", "halflife", "quake2", "quake3", lightmaps: "quake3" | `tests/model/bsp.luau` |
| model | bsp | .bsp | yes | - | variants: "quake", "bsp2", "2psb", "halflife", "quake2", "quake3", lightmaps: true, collision: true, visibility: true | `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` |
@@ -142,6 +144,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| 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 | wad2 | .wad | yes | yes | images: true, variants: "wad2", "wad3" | `tests/archive/wad2.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` |
| archive | z | .z .taz .tz | yes | yes | stream: true, bits: 9, 16 | `tests/archive/z.luau` |
@@ -155,6 +158,8 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| data | msgpack | .msgpack .mpk | yes | yes | binary: true, ordered: true | `tests/data/msgpack.luau` |
| data | nbt | .nbt .dat .mcstructure .dat_old | yes | yes | binary: true, ordered: true, typed: true | `tests/data/nbt.luau` |
| data | plist | .plist | yes | yes | binary: "read", ordered: true | `tests/data/plist.luau` |
| data | q3shader | .shader | yes | yes | | `tests/data/q3shader.luau` |
| data | q3skin | .skin | yes | yes | | `tests/data/q3skin.luau` |
| data | snbt | .snbt | yes | yes | ordered: true, typed: true | `tests/data/snbt.luau` |
| data | toml | .toml | yes | yes | ordered: true, dates: true | `tests/data/toml.luau` |
| data | vdf | .vdf .acf .res .kv | yes | yes | ordered: true, binary: true | `tests/data/vdf.luau` |
+22
View File
@@ -232,6 +232,28 @@ local data = assert(Wad.mapData(wad, "E1M1"))
assert(#data.sectors == 2 and #data.things == 2)
```
Quake's and Half-Life's texture WADs (WAD2 / WAD3, format `wad2`; Doom's IWAD / PWAD is `wad`) list their lumps
by name; `image` decodes miptex textures (any mip level), qpic pictures, the console font and the palette lump. Quake 1
lumps use the WAD's own `palette` lump (gfx.wad), `palette` or `gfx/palette.lmp` through `files` / `resolve` (Quake's
palette is not redistributable, so rosetta never embeds it); WAD3 lumps carry their own. `addImage` writes images
back as lumps (WAD3: with a palette made by median cut):
```luau
local Wad2 = F.format("wad2")
local gfx = assert(F.archive.load(gfxWadBytes))
assert(gfx.format == "wad2" and gfx.meta.source.variant == "wad2")
local brick = assert(Wad2.image(gfx, "brick")) -- through the WAD's palette lump
local small = assert(Wad2.image(gfx, "brick", { mip = 2 })) -- 8 x 8
assert(brick.width == 32 and small.width == 8)
local disc = assert(Wad2.image(gfx, "disc")) -- a qpic: index 255 transparent
assert(disc.meta.source.kind == "qpic")
local hl = Wad2.new("wad3")
assert(Wad2.addImage(hl, "{FENCE", brick)) -- '{' textures key index 255
local wad3 = assert(F.save(hl))
assert(F.archive.load(wad3).meta.source.variant == "wad3")
```
VPK directories (`pak01_dir.vpk`) hold small files themselves and point to numbered part files for the rest; pass
those through `files` or `resolve` (loading a path does it for you):
+19
View File
@@ -326,6 +326,25 @@ local bin = assert(F.save(acf, nil, { format = "vdf", binary = true }))
assert(F.data.load(bin, { format = "vdf" }).AppState.appid == "440")
```
## Quake III shaders and skins
Quake III `.shader` scripts load as a list of shaders: `{ name, directives, stages }`, each directive its tokens
(`{ "surfaceparm", "nolightmap" }`), each stage a list of directives; they write back. `.skin` files (format
`q3skin`) are lists of `{ surface, shader }` (tags have an empty shader).
```luau
local Q3Shader = F.format("q3shader")
local shaders = assert(F.data.load(shaderText, { format = "q3shader" }))
local wall = assert(Q3Shader.find(shaders, "textures/base_wall/metalfloor_wall_10"))
assert(Q3Shader.directive(wall.directives, "surfaceparm")[2] == "metalsteps")
assert(wall.stages[1][1][2] == "$lightmap" and #wall.stages == 2)
local again = assert(F.saveString(shaders, { format = "q3shader" }))
assert(#assert(F.data.load(again, { format = "q3shader" })) == #shaders)
local skin = assert(F.data.load(skinText, { format = "q3skin" }))
assert(F.format("q3skin").shader(skin, "h_head") == "models/players/sarge/band.tga")
```
## Save and convert
Data values have no `kind`, so saving needs `opts.format` or a destination extension (an `XmlNode` document too):
+22
View File
@@ -233,6 +233,28 @@ assert(buffer.tostring(assert(F.save(raw, nil, { format = "art" }))) == buffer.t
Doom's graphics come from WAD lumps rather than files: `F.format("wad").image(wad, name)` (see
[archive.md](archive.md#game-archives)).
Quake's `.lmp` pictures (qpics), `palette.lmp` and `colormap.lmp`, and Quake / Half-Life sprites (`.spr`) load
too. Quake pictures and sprites are 8-bit images over Quake's palette, which is not redistributable: pass it as
`palette` (768 bytes) or as `gfx/palette.lmp` through `files` / `resolve` (without it they load grey,
`meta.source.palette = false`). Half-Life sprites carry their own palette. Sprite frames are `img.frames` on one
canvas around the sprite's origin (`meta.origin`); frame groups give the delays.
```luau
local disc = assert(F.image.load(discLmpBytes, { name = "disc.lmp", palette = quakePaletteBytes }))
assert(disc.width == 24 and disc.meta.source.palette) -- index 255 is transparent
local pal = assert(F.image.load(quakePaletteBytes, { format = "lmp" })) -- a 16 x 16 swatch
assert(#pal.meta.palette == 256)
local back = assert(F.save(disc, nil, { format = "lmp", palette = quakePaletteBytes }))
assert(buffer.len(back) == buffer.len(discLmpBytes))
local flame = assert(F.image.load(flameSprBytes)) -- Half-Life: its own palette
assert(#flame.frames == 3 and flame.meta.source.texFormat == "alphatest")
local spr = assert(F.save(flame, nil, { format = "spr" })) -- version 2; version = 1 (Quake) needs palette
assert(#F.image.load(spr).frames == 3)
```
Doom's graphics come from WAD lumps rather than files: `F.format("wad").image(wad, name)`, and Quake / Half-Life
textures from WAD2 / WAD3: `F.format("wad2").image(wad, name)` (see [archive.md](archive.md#game-archives)).
## Formats
+61
View File
@@ -472,6 +472,7 @@ Game model formats load as Scenes too, with what games need: skins (joints + inv
| BSP (Quake 1 / 2 / 3, Half-Life) | each model a mesh, a primitive per texture (and Quake III lightmap); entities in `meta.entities` | - |
| VBSP (Source 19 / 20 / 21) | each model a mesh, a primitive per material, displacements; static props as nodes; lights; entities; the pak lump | - |
| VMF (Hammer, read + write) | a mesh per entity with solids, displacements; point entities as nodes; cameras; visgroups | - |
| BSP (Quake 1 / 2 / 3, Half-Life; BSP2, 2PSB) | each model a mesh, a primitive per texture; lightmaps as `TEXCOORD_1`; entities in `meta.entities`; tree, hulls and PVS in `meta.bsp` | - |
```luau
local tank = assert(F.model.load(md2Bytes))
@@ -675,6 +676,64 @@ local start = room.nodes[3]
assert(start.extras.classname == "info_player_start" and start.translation[3] == 1)
```
## Quake maps: editor `.map` and compiled BSP
`model/map` reads and writes the editor maps of Quake, Half-Life (Valve 220), Quake II (with content / surface flags)
and Quake III (`brushDef` brush primitives, `patchDef2` / `patchDef3` patches). Every entity is a node (child of the
`map` root) with `extras.classname`, `extras.keys` (an ordered object) and `extras.brushes` (the brushes as written);
entities with brushes get a mesh, a primitive per texture. Point entities stand at their `origin`. Brushes become
polygons the way qbsp builds them (`codecs/model/Brush`; tested against ericw-tools); `hull = true` drops the faces
inside or touching other brushes of the same entity, `merge = true` merges coplanar faces. Texture coordinates need
texture sizes: they come from `textureSizes`, the worldspawn's WADs (`"wad"` key), Quake II `.wal` files or Quake III
images (with `decodeImage`) through `files` / `resolve`; unknown textures count as 64 x 64
(`material.extras.map.sizeKnown = false`).
```luau
local Map = F.format("map")
local room = assert(F.model.load(roomMapText, { files = { ["gfx/tex.wad"] = texWadBytes }, hull = true }))
assert(room.meta.source.variant == "quake" and room.meta.up == "z")
local world = room.nodes[2] -- node 1 is the "map" root
assert(world.extras.classname == "worldspawn" and world.mesh)
local door = room.nodes[3]
assert(door.name == "door1" and door.extras.keys.angle == "90")
assert(room.materials[1].extras.map.sizeKnown) -- sizes from the WAD
local start = room.nodes[4] -- a point entity at its origin
assert(start.translation[1] == -128)
start.translation = { 0, 0, 24 } -- edit and write back
door.extras.keys.speed = "200"
local text = buffer.tostring(assert(F.save(room, nil, { format = "map" })))
assert(string.find(text, '"origin" "0 0 24"', 1, true))
local valve = assert(F.save(room, nil, { format = "map", variant = "valve220" })) -- Quake standard -> Valve 220 axes
assert(F.model.load(valve).meta.source.variant == "valve220")
local parsed = assert(Map.parse(roomMapText)) -- the raw entities: keys, brushes, faces as written
assert(#parsed.entities == 4 and parsed.entities[1].brushes[1].faces[1].texture)
```
Compiled `.bsp` maps carry what the engines need beyond the triangles. Quake 1 (BSP 29, BSP2, 2PSB), Half-Life and
Quake II lightmaps (the first light style) are packed into one atlas texture named `"lightmap"`, mapped by
`TEXCOORD_1` and named by each material's `extras.bsp.lightmap` (Quake III keeps its own 128 x 128 pages). Coloured
Quake light comes from the map's `.lit` (`lit`, or `<map>.lit` through `files` / `resolve` with `name`). The BSP tree,
the collision hulls (Quake 1 clipnodes, Quake II / III brushes) and the visibility data are tables in `meta.bsp`,
with point queries on the format module:
```luau
local Bsp = F.format("bsp")
local map = assert(F.model.load(roomBspBytes))
assert(map.meta.source.variant == "quake")
local prim = map.meshes[1].primitives[1]
assert(prim.attributes.TEXCOORD_1) -- lightmap coordinates
local atlas = map.textures[map.materials[prim.material].extras.bsp.lightmap]
assert(atlas.name == "lightmap" and atlas.image.width > 0)
assert(Bsp.contents(map, -128, -128, 100) == -1) -- CONTENTS_EMPTY in the room
assert(Bsp.contents(map, 0, 0, -8) == -2) -- CONTENTS_SOLID: the floor
assert(Bsp.contents(map, -250, 0, 100, 1) == -2) -- hull 1 (player size) touches the wall
local here = assert(Bsp.leafAt(map, -128, -128, 24))
local seen = assert(Bsp.pvs(map, here)) -- leaves potentially visible from here
assert(table.find(seen, Bsp.leafAt(map, 0, 0, 220)))
assert(#map.meta.bsp.planes > 0 and #map.meta.bsp.clipnodes > 0)
```
## Blitz3D (B3D)
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
@@ -965,6 +1024,8 @@ assert(bones[1]:str("name") == "lower" and bones[1]:list("childbase")[1]:str("na
| Source MDL (v44-49) + VVD / VTX / PHY | yes | - | skeleton, body parts, LODs, flexes, animations, VMT materials: see above |
| 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 |
| MD2, MD3, MDL, MD5, BSP | yes | - | game models and maps: see "Game models" above; BSP lightmaps, hulls, PVS: "Quake maps" |
| Quake / Half-Life / Quake II / Quake III `.map` | yes | yes | entities as nodes, brushes CSG'd, patches: see "Quake maps" |
| 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 |