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

+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 |