merge ws/quake
This commit is contained in:
commit
58df9e8a3a
39 files changed
+10044
-1413
No files matched your search
@@ -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):
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 |
|
||||
|
||||
Reference in new issue
Block a user