merge ws/game
This commit is contained in:
commit
3cebe7d4e7
72 files changed
+10473
-6
No files matched your search
@@ -185,6 +185,70 @@ local gzipped = assert(F.save("some text", nil, { format = "gzip", name = "note.
|
||||
assert(F.archive.load(gzipped, { unwrap = false }):list()[1].name == "note.txt")
|
||||
```
|
||||
|
||||
## Game archives
|
||||
|
||||
The game archive formats load as the same `Archive`: Quake / Half-Life PAK, Doom WAD, Build GRP, Valve VPK and
|
||||
Blizzard MPQ (read-only). PAK, WAD, GRP and VPK are writable (and any Archive converts to them).
|
||||
|
||||
```luau
|
||||
local pak = assert(F.archive.load(pakBytes)) -- Quake PAK: 56-byte names, stored files
|
||||
assert(pak.format == "pak" and pak:read("default.cfg"))
|
||||
local grp = assert(F.archive.load(grpBytes)) -- Duke Nukem 3D GRP
|
||||
assert(grp:list()[1].name == "GAME.CON")
|
||||
|
||||
local new = F.format("pak").new()
|
||||
new:add("maps/e1m1.bsp", "...")
|
||||
local bytes = assert(F.save(new)) -- a PAK; F.save(zip, nil, { format = "pak" }) converts
|
||||
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
|
||||
sector outlines, walls, things as nodes standing on their floor).
|
||||
|
||||
```luau
|
||||
local Wad = F.format("wad")
|
||||
local wad = assert(F.archive.load(wadBytes))
|
||||
for _, l in Wad.lumps(wad) do
|
||||
print(l.name, l.size, l.namespace, l.map) -- "FLOOR" 4096 "flats" nil, "THINGS" 20 nil "E1M1", ...
|
||||
end
|
||||
local flat = assert(Wad.image(wad, "FLOOR")) -- 64 x 64 rgba8
|
||||
local patch = assert(Wad.image(wad, "TALL")) -- a picture: meta.offset = { left, top }, alpha 0 = hole
|
||||
assert(flat.width == 64 and patch.height == 300)
|
||||
|
||||
assert(Wad.maps(wad)[1] == "E1M1")
|
||||
local map = assert(Wad.map(wad, "E1M1")) -- a Scene; Wad.mapData(wad, "E1M1") gives the raw tables
|
||||
assert(map.meta.up == "z" and #map.meshes[1].primitives > 0)
|
||||
local thing = map.nodes[2] -- things are child nodes of the map node
|
||||
assert(thing.extras.thing.type == 1) -- player 1 start
|
||||
local data = assert(Wad.mapData(wad, "E1M1"))
|
||||
assert(#data.sectors == 2 and #data.things == 2)
|
||||
```
|
||||
|
||||
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):
|
||||
|
||||
```luau
|
||||
local vpk = assert(F.archive.load(vpkBytes))
|
||||
assert(vpk:read("scripts/game.txt")) -- CRC-32 checked on read
|
||||
-- multi-part: F.archive.load(dir, { name = "pak01_dir.vpk", files = { ["pak01_000.vpk"] = part0 } })
|
||||
local out = assert(F.save(vpk)) -- one self-contained version 2 file (with its MD5s)
|
||||
assert(F.archive.load(out):read("materials/brick/wall.vmt"))
|
||||
```
|
||||
|
||||
MPQ archives are read through their hash table, so names come from the archive's `(listfile)`; files it does not
|
||||
list appear as `File00000012.xxx` (their block index), and `names` adds names to look up:
|
||||
|
||||
```luau
|
||||
local mpq = assert(F.archive.load(mpqBytes)) -- also .w3x / .w3m / .SC2Map
|
||||
local script = assert(mpq:read("war3map.j")) -- zlib / PKWARE implode / bzip2 / LZMA / sparse sectors
|
||||
assert(buffer.len(script) == buffer.len(assert(mpq:read("readme.txt"))))
|
||||
local named = assert(F.archive.load(mpqBytes, { names = { "war3map.w3e" } }))
|
||||
assert(#named:list() >= 2)
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -197,6 +261,11 @@ assert(F.archive.load(gzipped, { unwrap = false }):list()[1].name == "note.txt")
|
||||
| zstd (`.zst`, `.tzst`) | yes | - | single stream; no dictionaries |
|
||||
| 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")` |
|
||||
| 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 |
|
||||
|
||||
Full capability list: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
|
||||
@@ -194,6 +194,28 @@ Encoder options:
|
||||
| ICO | `cursor`, `png` (PNG entries); `frames` become entries (each up to 256 x 256) |
|
||||
| PNM | the subtype from the extension or `format`: `pbm`, `pgm`, `ppm`, `pam`, `pfm` |
|
||||
|
||||
## Game textures
|
||||
|
||||
PlayStation TIM, Blizzard BLP and Valve VTF load as Images too (rgba8; the mip and texel facts in
|
||||
`meta.source`):
|
||||
|
||||
```luau
|
||||
local face = assert(F.image.load(timBytes)) -- 4 / 8-bit CLUT, 15 or 24-bit
|
||||
assert(face.meta.source.bpp == 16)
|
||||
local tim = assert(F.save(face, nil, { format = "tim", bpp = 16 })) -- TIM writes 4 / 8 / 16 / 24-bit
|
||||
|
||||
local icon = assert(F.image.load(blpBytes)) -- BLP1 JPEG / palette, BLP2 palette / DXT / BGRA
|
||||
assert(icon.width == 4 and icon.meta.source.compression == "bgra")
|
||||
|
||||
local wall = assert(F.image.load(vtfBytes)) -- every common VTF texel format, frames, mips
|
||||
assert(wall.meta.source.texel == "RGBA8888")
|
||||
local small = assert(F.image.load(vtfBytes, { mip = 1 })) -- or face = n (cube maps), slice = n (volumes)
|
||||
assert(F.detect(tim) == "tim")
|
||||
```
|
||||
|
||||
Doom's graphics come from WAD lumps rather than files: `F.format("wad").image(wad, name)` (see
|
||||
[archive.md](archive.md#game-archives)).
|
||||
|
||||
## Formats
|
||||
|
||||
Read and write unless noted; see [FORMATS.md](../FORMATS.md) for depths and details.
|
||||
@@ -207,6 +229,9 @@ Read and write unless noted; see [FORMATS.md](../FORMATS.md) for depths and deta
|
||||
| TIFF | pages | yes | 1..32-bit, float |
|
||||
| BMP, TGA, QOI, ICO / CUR, PNM / PAM / PFM | ICO entries | yes | |
|
||||
| HDR | | no | float (`native` gives rgbaf32) |
|
||||
| TIM | | yes | PlayStation; 4 / 8-bit CLUT, 15 / 24-bit |
|
||||
| BLP | | yes | Blizzard BLP1 / BLP2 (DXT through the BCn codec); writes BLP2 BGRA |
|
||||
| VTF | frames | yes | Valve; read only; mips / faces / slices by option |
|
||||
| DDS, KTX / KTX2 | faces / layers / slices | yes | GPU textures: BC1..BC7, ETC / EAC, every uncompressed layout; mips in `meta.mipmaps` |
|
||||
| OpenEXR | parts (`opts.part`) | yes | half / float / uint, NONE / RLE / ZIPS / ZIP / PIZ, tiles; writes NONE / ZIPS / ZIP |
|
||||
| PCX, SGI, Sun Raster, IFF ILBM / PBM, XPM, XBM | | yes (XBM 1-bit) | old paint / workstation formats; ILBM reads HAM and EHB |
|
||||
|
||||
@@ -455,6 +455,57 @@ local vox = assert(F.save(grid, nil, { format = "vox" })) -- a grid alone saves
|
||||
assert(F.load(vox).voxels[1].size[1] == 4)
|
||||
```
|
||||
|
||||
## Game models
|
||||
|
||||
Game model formats load as Scenes too, with what games need: skins (joints + inverse bind matrices, `JOINTS_0` /
|
||||
`WEIGHTS_0`) and animations, vertex-animated models as morph targets. Units are as the game stores them, z up
|
||||
(`meta.up = "z"`).
|
||||
|
||||
| Format | What loads | Animations |
|
||||
|---|---|---|
|
||||
| MD2 (Quake II) | one primitive; skins as texture URIs | every frame a morph target (weight k = 1 shows frame k); one animation per frame-name group (`run1`..`run6` -> `run`) |
|
||||
| MD3 (Quake III) | a primitive per surface; shaders as URIs; tags as nodes | frames as morph targets, tag motion, one animation |
|
||||
| MDL (Quake 1, Half-Life 1) | Quake: skins decoded through the palette; Half-Life: bones, body parts, textures with their own palettes | Quake: morph targets per frame group; Half-Life: every sequence |
|
||||
| MD5 (Doom 3 `.md5mesh` / `.md5anim`) | skeleton, weighted meshes, shaders as URIs | the `.md5anim` files named in `anims` |
|
||||
| SMD (Valve, read + write) | skeleton, weight links, a primitive per material | the skeleton frames |
|
||||
| BSP (Quake 1 / 2 / 3, Half-Life) | each model a mesh, a primitive per texture (and Quake III lightmap); entities in `meta.entities` | - |
|
||||
|
||||
```luau
|
||||
local tank = assert(F.model.load(md2Bytes))
|
||||
local prim = tank.meshes[1].primitives[1]
|
||||
assert(#prim.targets == 5 and #tank.meshes[1].weights == 5) -- 5 frames
|
||||
assert(tank.animations[1].name == "stand" and tank.animations[2].name == "run")
|
||||
assert(tank.textures[1].uri == "models/tank/skin.pcx")
|
||||
assert(tank.meta.up == "z")
|
||||
```
|
||||
|
||||
MD5 animations are separate files: name them in `anims` (they are found through `files` or `resolve`, which the api
|
||||
fills in for paths), or load a `.md5anim` alone as a skeleton with its animation:
|
||||
|
||||
```luau
|
||||
local imp = assert(F.model.load(md5meshBytes, { anims = { "idle.md5anim" }, files = { ["idle.md5anim"] = md5animBytes } }))
|
||||
assert(#imp.skins == 1 and imp.animations[1].name == "idle")
|
||||
assert(imp.meshes[1].primitives[1].attributes.JOINTS_0)
|
||||
local idle = assert(F.model.load(md5animBytes, { format = "md5" }))
|
||||
assert(#idle.animations == 1)
|
||||
```
|
||||
|
||||
Quake's palette (`gfx/palette.lmp`, inside the game's PAK) is not redistributable, so Quake MDL skins and Quake 1
|
||||
BSP textures need it passed in (`palette`, or through `files` / `resolve`); without it they decode as grey ramps
|
||||
(`meta.source.palette = false`). Half-Life models and maps carry their own palettes.
|
||||
|
||||
```luau
|
||||
local map = assert(F.model.load(bspBytes)) -- a Half-Life map
|
||||
assert(map.meta.source.variant == "halflife")
|
||||
assert(map.meta.entities[1].classname == "worldspawn")
|
||||
local world = map.meshes[1] -- "world"; brush entities are "*1", "*2", ...
|
||||
assert(world.name == "world" and map.meshes[2].name == "*1")
|
||||
|
||||
local barney = assert(F.model.load(smdBytes))
|
||||
local again = assert(F.save(barney, nil, { format = "smd" })) -- SMD writes back (bind pose, weights)
|
||||
assert(F.model.load(again).skins[1])
|
||||
```
|
||||
|
||||
## Blitz3D (B3D)
|
||||
|
||||
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
|
||||
@@ -692,6 +743,8 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
|
||||
| VRML97 (WRL / WRZ) | yes | yes | primitives, PROTO, Inline, ROUTE animations, cameras, lights |
|
||||
| X3D (XML / classic) | yes | yes | the VRML reader plus the X3D triangle / quad / line sets; no binary `.x3db` |
|
||||
| STEP | via the CAD plug-in | | see [cad.md](cad.md) |
|
||||
| MD2, MD3, MDL, MD5, BSP | yes | - | game models and maps: see "Game models" above |
|
||||
| SMD | yes | yes | Valve studiomdl data |
|
||||
|
||||
Capabilities per format: [FORMATS.md](../FORMATS.md).
|
||||
|
||||
|
||||
Reference in new issue
Block a user