build engine: docs/guide sections (ART tiles, Build maps) with inputs from tools/fixtures/docs_build.py, bench lines, type fixes; bundles rebuilt

This commit is contained in:
4DBug committed 2026-11-01 18:46:54 -06:00
1 parent aacc78fac2
commit 082ea2019e
10 files changed
+3575 -1085

No files matched your search

+1187
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+1187
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+19 -1
View File
@@ -1,7 +1,7 @@
# Images
Every image format (PNG / APNG, JPEG, WebP, GIF, BMP, TGA, QOI, TIFF, ICO / CUR, PNM / PAM / PFM, Radiance HDR,
OpenEXR, the [game textures](#game-textures) DDS / KTX / VTF / BLP / TIM, and the [older formats](#formats) PCX, SGI,
OpenEXR, the [game textures](#game-textures) DDS / KTX / VTF / BLP / TIM / ART, and the [older formats](#formats) PCX, SGI,
Sun Raster, ILBM, XPM, XBM, ICNS, ANI) loads as one `Image`: a width, a height, a pixel format and one tightly packed `buffer`. Animations (GIF, APNG, animated
WebP) and multi-image files (TIFF pages, ICO entries) add a list of `Frame`s. Editing goes through `F.ops.image`.
@@ -214,6 +214,23 @@ local small = assert(F.image.load(vtfBytes, { mip = 1 })) -- or face = n (cub
assert(F.detect(tim) == "tim")
```
Build engine ART files (`TILES000.ART` ..., Duke Nukem 3D, Shadow Warrior) hold many tiles: each is one entry of
`frames` (in tile order, empty tiles 0 x 0), with its tile number in `meta.tile` and its picanm animation and centre
offsets in `meta.picanm`; the top-level image is the first non-empty tile. Colours come from the game's
`PALETTE.DAT`, passed as `palette` or found next to the file through `resolve` (without it the tiles decode as a grey
ramp). Index 255 is transparent. `shade` / `pal` apply a PALETTE.DAT shade table / a LOOKUP.DAT palookup, `native`
keeps the palette indices (gray8), and ART writes back from either form:
```luau
local tiles = assert(F.image.load(artBytes, { palette = paletteBytes }))
local second = tiles.frames[2].image
assert(second.meta.tile == 1 and second.width == 8)
assert(second.meta.picanm.type == "forward" and second.meta.picanm.frames == 2)
local raw = assert(F.image.load(artBytes, { format = "art", native = true }))
assert(raw.frames[1].image.format == "gray8")
assert(buffer.tostring(assert(F.save(raw, nil, { format = "art" }))) == buffer.tostring(artBytes))
```
Doom's graphics come from WAD lumps rather than files: `F.format("wad").image(wad, name)` (see
[archive.md](archive.md#game-archives)).
@@ -233,6 +250,7 @@ Read and write unless noted; see [FORMATS.md](../FORMATS.md) for depths and deta
| 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 |
| ART | tiles as frames | index 255 | Build engine tiles; palette from PALETTE.DAT (`palette` / `resolve`), picanm in `meta.picanm` |
| 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 |
+24
View File
@@ -507,6 +507,29 @@ local again = assert(F.save(barney, nil, { format = "smd" })) -- SMD writes ba
assert(F.model.load(again).skins[1])
```
## Build engine maps
Duke Nukem 3D / Shadow Warrior `.map` files (versions 7-9; the text Quake `.map` is a different format, told apart by
content) load as one mesh: floors and ceilings triangulated with their slopes, walls with upper and lower parts at red
walls (and masked walls), a primitive per surface kind and tile (`extras.build = { kind, tile }`); materials and
textures are named `tile<n>`. Sprites become nodes under the map with their tile in `extras.build.tile` (the raw
sprite in `extras.build.sprite`), and the player start is the node `start`. Coordinates turn z up (Build's y and z
point down), z is divided by 16 so all axes share Build's xy unit, and `scale` multiplies everything. `tiles` (tile
number to Image, e.g. from an ART file) gives the texture sizes for the UVs and attaches the images.
The raw sector, wall and sprite tables stay in `meta.build`, and saving writes them back:
```luau
local map = assert(F.model.load(buildmapBytes, { scale = 1 / 512 }))
local level = map.meta.build
assert(level.version == 7 and #level.sectors == 3)
assert(map.nodes[2].name == "start" and map.nodes[3].extras.build.tile == level.sprites[1].picnum)
local again = assert(F.save(map, nil, { format = "buildmap" }))
assert(buffer.tostring(again) == buffer.tostring(buildmapBytes))
local Build = F.format("buildmap") -- the floor height under a point, slopes included
assert(Build.slopeZ(level, 0, true, 100, 100) == level.sectors[1].floorz)
```
## Blitz3D (B3D)
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
@@ -745,6 +768,7 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
| 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 |
| Build engine MAP (v7-9) | yes | yes | sloped sectors, walls, sprites as nodes, raw tables in `meta.build`; see "Build engine maps" above |
| SMD | yes | yes | Valve studiomdl data |
| 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) |
+8 -8
View File
@@ -62,11 +62,11 @@ local function header(b: buffer, o: number, limit: number): (number?, number?, n
prefixed = true
end
if limit - p < 16 or readu32(b, p) ~= 1 then
return nil
return nil, nil, nil, nil, nil
end
local first, last = readu32(b, p + 8), readu32(b, p + 12)
if last < first or last - first >= 65536 then
return nil
return nil, nil, nil, nil, nil
end
return p + 16, first, last, readu32(b, p + 4), prefixed
end
@@ -151,7 +151,7 @@ local function makePalette(src: any, dat: buffer?): buffer
end
local function paletteList(pal: buffer): { { number } }
local list: { { number } } = table.create(256)
local list = table.create(256) :: { { number } }
for i = 0, 255 do
local v = readu32(pal, i * 4)
list[i + 1] = { bit32.band(v, 255), bit32.band(bit32.rshift(v, 8), 255), bit32.band(bit32.rshift(v, 16), 255), 255 }
@@ -239,7 +239,7 @@ function Art.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
return nil, Err.new(Err.TRUNCATED, "tile tables", p)
end
local maxPixels = o.maxPixels or 2 ^ 26
local sizes: { number } = table.create(n * 2)
local sizes = table.create(n * 2) :: { number }
local total = 0
for i = 0, n - 1 do
local w, h = readi16(b, p + i * 2), readi16(b, p + n * 2 + i * 2)
@@ -283,7 +283,7 @@ function Art.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Image?, Err.E
shadeAt = shade * 256
end
local native = o.native == true
local frames: { Types.Frame } = table.create(n)
local frames = table.create(n) :: { Types.Frame }
local truncated = false
local q = datStart
local main: Types.Image? = nil
@@ -401,8 +401,8 @@ function Art.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
else
list[1] = img
end
local meta = img.meta or {}
local src = meta.source or {}
local meta: any = img.meta or {}
local src: any = meta.source or {}
local palSrc: any = o.palette or meta.palette
local palList: { { number } }? = nil
if palSrc ~= nil then
@@ -457,7 +457,7 @@ function Art.encode(img: Types.Image, opts: EncodeOptions?): (buffer?, Err.Err?)
out:u16le(t.height)
end
for _, t in list do
local m = t.meta or {}
local m: any = t.meta or {}
out:u32le(picanmWord(m.picanm, m.source and tonumber(m.source.picanm)))
end
for _, t in list do
+6 -6
View File
@@ -60,17 +60,17 @@ local readu16 = buffer.readu16
-- ------------------------------------------------------------------------------------------------ sniff
local function layout(b: buffer, o: number, limit: number): (number?, number?, number?, number?)
if limit - o < HEADER then
return nil
return nil, nil, nil, nil
end
local ns = readu16(b, o + 20)
local p = o + HEADER + ns * SECTOR_SIZE
if p + 2 > limit then
return nil
return nil, nil, nil, nil
end
local nw = readu16(b, p)
p += 2 + nw * WALL_SIZE
if p + 2 > limit then
return nil
return nil, nil, nil, nil
end
local nsp = readu16(b, p)
p += 2 + nsp * SPRITE_SIZE
@@ -148,9 +148,9 @@ function BuildMap.parse(r: Bytes.Reader, opts: DecodeOptions?): (Map?, Err.Err?)
z = buffer.readi32(b, o + 12),
ang = buffer.readi16(b, o + 16),
cursectnum = buffer.readi16(b, o + 18),
sectors = table.create(ns),
walls = table.create(nw),
sprites = table.create(nsp),
sectors = table.create(ns) :: { Sector },
walls = table.create(nw) :: { Wall },
sprites = table.create(nsp) :: { Sprite },
}
local p = o + HEADER
for i = 1, ns do
+30
View File
@@ -1902,3 +1902,33 @@ do
jitTune(false)
end
end
do
-- Build engine (ws-build): an ART of 64 random 128 x 128 tiles to rgba8 through a palette (MB/s of rgba8 output),
-- and the two-room map of tools/fixtures/buildmap.py to a Scene (MB/s of map bytes)
local Art = require("@rosetta/image/art")
local BuildMap = require("@rosetta/model/buildmap")
local AF = require("@tests/gen/art")
local BF = require("@tests/gen/buildmap")
local rnd = 12345
local frames: { Types.Frame } = {}
for i = 1, 64 do
local img = Types.Image.new(128, 128, "gray8")
for k = 0, 128 * 128 - 1 do
rnd = (rnd * 1103515245 + 12345) % 2147483648
buffer.writeu8(img.pixels, k, rnd % 256)
end
img.meta.tile = i - 1
frames[i] = { image = img, delay = 0, x = 0, y = 0, dispose = "none", blend = "source" }
end
local top = Types.Image.new(1, 1, "gray8")
top.frames = frames
local art = assert(Art.encode(top))
local pal = buffer.fromstring(AF.palette)
bench("art decode 64 x 128x128 -> rgba8", 3, 64 * 128 * 128 * 4, function()
Art.decode(Bytes.reader(art), { palette = pal })
end)
local map = buffer.fromstring(BF.maps[1].data)
bench("buildmap rooms -> Scene", 20, buffer.len(map), function()
BuildMap.decode(Bytes.reader(map))
end)
end
+38
View File
@@ -0,0 +1,38 @@
# Docs inputs for the Build engine sections of the image / scene pages (tools/fixtures.py; tools/docs_check.py explains
# the inputs): an ART file of three tiles and a random PALETTE.DAT written here (BUILDINF.TXT layout), and the two-room
# map of tools/fixtures/buildmap.py.
# tests/gen/docs_build.luau { files = { [name] = bytes }, vars = { artBytes = "TILES000.ART", ... } }
import importlib.util, os, struct
INPUTS = ["tools/docs_check.py", "tools/fixtures/buildmap.py"]
def mod(ctx, path, name):
spec = importlib.util.spec_from_file_location(name, os.path.join(ctx.root, path))
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
return m
def art(rng, first, tiles):
"""tiles: [(w, h, picanm)]; column-major random indices"""
out = bytearray(struct.pack("<4I", 1, 0, first, first + len(tiles) - 1))
out += b"".join(struct.pack("<h", w) for w, _, _ in tiles)
out += b"".join(struct.pack("<h", h) for _, h, _ in tiles)
out += b"".join(struct.pack("<I", a) for _, _, a in tiles)
for w, h, _ in tiles:
out += bytes(rng.randrange(255) for _ in range(w * h))
return bytes(out)
def generate(ctx):
rng = ctx.rng(5)
check = mod(ctx, "tools/docs_check.py", "docs_check")
bm = mod(ctx, "tools/fixtures/buildmap.py", "fx_buildmap")
pal = bytes(rng.randrange(64) for _ in range(768)) + struct.pack("<H", 1) + bytes(range(256))
files = {
"TILES000.ART": art(rng, 0, [(16, 16, 0), (8, 4, 2 | (2 << 6) | (3 << 24)), (0, 0, 0)]),
"PALETTE.DAT": pal,
"E1L1.MAP": bm.rooms(rng).write(7),
}
check.emit_inputs(ctx, files, {"artBytes": "TILES000.ART", "paletteBytes": "PALETTE.DAT", "buildmapBytes": "E1L1.MAP"})