model/vbsp: Source BSP 19-21 (L4D2 header, LZMA lumps): faces, displacements, static props v4-v13, brush entities, lights, entities, the pak lump as an Archive; KeyValues bench

This commit is contained in:
4DBug committed 2026-11-01 18:53:15 -06:00
1 parent 1c79609ecb
commit 52d2d7ebf9
11 files changed
+1459 -2

No files matched your search

+1
View File
@@ -90,6 +90,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | smd | .smd | yes | yes | skins: true, animation: true | `tests/model/smd.luau` |
| model | stl | .stl | yes | yes | ascii: true, binary: true, colors: true, indexed: false | `tests/model/stl.luau` |
| model | usda | .usda .usd .usdz | yes | yes | materials: true, animation: true, cameras: true, lights: true, polygons: true, vertexColors: true, usdz: "read", usdc: false | `tests/model/usda.luau` |
| model | vbsp | .bsp | yes | - | versions: 19, 20, 21, displacements: true, staticProps: true, pak: true | `tests/model/vbsp.luau` |
| model | vox | .vox | yes | yes | voxels: true, sceneGraph: true, materials: true | `tests/model/vox.luau` |
| model | vrml | .wrl .wrz .vrml | yes | yes | materials: true, polygons: true, animation: true, cameras: true, lights: true, lines: true, points: true | `tests/model/vrml.luau` |
| model | x | .x | yes | - | text: true, binary: true, compressed: true, materials: true, skins: true, animation: true, polygons: true, vertexColors: true | `tests/model/x.luau` |
+27 -1
View File
@@ -470,6 +470,7 @@ Game model formats load as Scenes too, with what games need: skins (joints + inv
| 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` | - |
| VBSP (Source 19 / 20 / 21) | each model a mesh, a primitive per material, displacements; static props as nodes; lights; entities; the pak lump | - |
```luau
local tank = assert(F.model.load(md2Bytes))
@@ -507,6 +508,31 @@ local again = assert(F.save(barney, nil, { format = "smd" })) -- SMD writes ba
assert(F.model.load(again).skins[1])
```
### Source maps (VBSP)
Compiled Source maps (`.bsp` with the `VBSP` magic: HL2, TF2, Portal, L4D2, CS:GO) load as one mesh per brush model
(`world`, `*1`, ...) with a primitive per material; brush entities place their model by `origin` / `angles`.
Displacements are tessellated (their blend alpha is the `_BLEND` attribute), tool faces (nodraw, skip, hint, sky) are
left out unless `tools = true`. Static props are nodes with `extras.model` (the `.mdl` path) and
`extras.vbsp` (skin, solid, fade, ...); `light`, `light_spot` and `light_environment` become lights. Entities are
`meta.entities` (KeyValues objects: a repeated output is an array), the pak lump `meta.pak` (an Archive), and a
material's texture is `materials/<name>.vtf`, embedded when the pak has it. LZMA-compressed lumps and the L4D2 lump
header are read; lightmaps and visibility are not.
```luau
local room = assert(F.model.load(vbspBytes, { name = "room.bsp" }))
assert(room.meta.source.format == "vbsp" and room.meta.source.version == 21)
local props = {}
for _, n in room.nodes do
if n.extras and n.extras.model then
table.insert(props, n.extras.model)
end
end
assert(props[1] == "models/props_junk/wood_crate001a.mdl")
assert(room.meta.entities[1].classname == "worldspawn")
assert(room.meta.pak:read("materials/custom/note.txt"))
```
## Blitz3D (B3D)
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
@@ -744,7 +770,7 @@ 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 |
| MD2, MD3, MDL, MD5, BSP, VBSP | yes | - | game models and maps: see "Game models" 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) |