merge ws/source: VBSP v19-21, VMF, KeyValues / data/vdf, codecs/model/Displacement (with ws/quake's Brush / Patch / Miptex)

This commit is contained in:
4DBug committed 2026-11-01 19:46:56 -06:00
commit e100366cb8
44 files changed
+18855 -1508

No files matched your search

+8 -1
View File
@@ -74,6 +74,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | iqm | .iqm | yes | yes | materials: true, skins: true, animation: true, vertexColors: true | `tests/model/iqm.luau` |
| model | ldraw | .ldr .mpd .dat | yes | - | materials: true, lines: true, instancing: true | `tests/model/ldraw.luau` |
| model | lwo | .lwo .lxo | yes | - | materials: true, polygons: true, vertexColors: true, morphTargets: true | `tests/model/lwo.luau` |
| model | map | .map | yes | yes | variants: "quake", "valve220", "quake2", "quake3", patches: true | `tests/model/map.luau` |
| model | mca | .mca .mcr | yes | - | voxels: true, blocks: true | `tests/model/mca.luau` |
| model | md2 | .md2 | yes | - | morph: true, animation: true | `tests/model/md2.luau` |
| model | md3 | .md3 | yes | - | morph: true, animation: true, tags: true | `tests/model/md3.luau` |
@@ -93,6 +94,8 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | sourcemdl | .mdl | yes | - | skins: true, morph: true, animation: true, lods: true | `tests/model/sourcemdl.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 | vmf | .vmf .vmx | yes | yes | displacements: true, roundTrip: true | `tests/model/vmf.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` |
@@ -240,7 +243,8 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- codecs/image/Etc: ETC1 / ETC2 / EAC block texture decoding (Khronos Data Format Specification 1.3, section 21).
- codecs/image/Half: IEEE 754 binary16 <-> number (round to nearest even, overflow to infinity). New in rosetta.
- codecs/image/Jpeg: the JPEG codec (ITU T.81), bit-exact with libjpeg-turbo's djpeg and byte-identical with cjpeg.
- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB.
- codecs/image/Miptex: Quake / GoldSrc mip textures and the WAD2 / WAD3 lump directory, read and write.
- codecs/image/Pixels: row loops between packed pixel layouts and rgba8 for BMP / DIB, and palette helpers.
- codecs/image/Quantize: palette quantization of rgba8 pixels (median cut or octree, Floyd-Steinberg dithering).
- codecs/image/Raster: an antialiased scanline rasterizer (nonzero / even-odd) for line and Bézier paths, plus a stroker.
- codecs/image/Texel: uncompressed GPU texel formats -> the standard pixel formats. New in rosetta.
@@ -249,10 +253,13 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- codecs/image/Vp8L: WebP lossless (VP8L, RFC 9649 section 3).
- codecs/image/Yuv: planar 4:2:0 Y'CbCr <-> rgba8, BT.601 / BT.709, limited or full range.
- **model**
- codecs/model/Brush: convex plane brushes -> polygons and Scene primitives, with Quake-family texture projection.
- codecs/model/Displacement: Source engine displacement surfaces (VBSP ddispinfo_t / Hammer dispinfo), as
- codecs/model/Draco: Google Draco geometry decompression (.drc; glTF KHR_draco_mesh_compression; Roblox mesh v6 / v7).
- codecs/model/Mat4: 4x4 matrix (column-major, glTF / Types.Scene layout) and quaternion { x, y, z, w } helpers.
- codecs/model/MeshFlatten: a Scene to one world-space mesh, for the writers of mesh-only formats (STL, PLY, OFF).
- codecs/model/Minecraft: what Minecraft's voxel formats share (model/schematic, model/mca). New code.
- codecs/model/Patch: Quake III / Doom 3 Bezier patches (control grids) -> evaluated grids, triangles, normals.
- codecs/model/Polygon: 2D polygons with holes to triangles by hole bridging and ear clipping. New code.
- codecs/model/Rbx: the Roblox instance tree and property values shared by model/rbxm and model/rbxmx.
- codecs/model/Rig: the Scene mapping shared by game model formats (MD2 / MD3 / MDL / MD5 / SMD / ...). New code.
+5 -3
View File
@@ -29,13 +29,13 @@ src/Rosetta/
codecs/<domain>/<Name> codecs (layer 3) generic algorithms, by domain:
compress/ Brotli Bzip2 Deflate Explode Lz4 Lzh Lzma Lzw Lzx PackBits Quantum UnixCompress Xxh32 Zstd
entropy/ Huffman RangeCoder
image/ Bcn Blend Dct Etc Half Jpeg Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv
image/ Bcn Blend Dct Etc Half Jpeg Miptex Pixels Quantize Raster Texel Texture Vp8 Vp8L Yuv
audio/ Aac Ac3 Adpcm Alac Ape ApeTag Flac Hively Mdct MidiRender Mpa Musepack Opus Pcm Qoa Resample
SoundFont Stream Tracker Tta Vorbis VorbisComment WavPack
video/ Dsp H263 H264 Legacy Mpeg1 Mpeg2 Theora Video (the video codec registry)
text/ Json KeyValues Nbt Text Url Xml
font/ Bitmap Cff GlyphNames TrueType
model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler SourceAnim Vrml
model/ Brush Displacement Draco Mat4 MeshFlatten Minecraft Patch Polygon Rbx Rig Sampler SourceAnim Vrml
host/ host (layer 2) runtime adapters; only the api uses them
Types.luau types (layer 1) standard types + constructors
core/ core (layer 0) Adler32 Base64 Bits Bytes Crc16 Crc32 Err Input
@@ -243,8 +243,10 @@ them. Anything generic goes down a layer and is called:
| animation channels sampled at a time; game-model frames, joints and skins -> Scene | `codecs/model/Sampler`, `codecs/model/Rig` |
| polygons with holes -> triangles | `codecs/model/Polygon` |
| studio model animation values (GoldSrc / Source run-length shorts, Quaternion48 / 64, bone records) | `codecs/model/SourceAnim` |
| plane brushes -> polygons (CSG hull, coplanar merge, Quake / Valve 220 / brush-primitive texturing); Bezier patches | `codecs/model/Brush`, `codecs/model/Patch` |
| Quake / GoldSrc mip textures, WAD2 / WAD3 directories; palettes (keyed index, grey, colormap) | `codecs/image/Miptex`, `codecs/image/Pixels` |
| NBT / SNBT values; Minecraft block states and colours | `codecs/text/Nbt`, `codecs/model/Minecraft` |
| Valve KeyValues (text, binary, the BSP entity lump) | `codecs/text/KeyValues` |
| Valve KeyValues (text, binary, the BSP entity lump); Source displacement surfaces | `codecs/text/KeyValues`, `codecs/model/Displacement` |
| Roblox instance trees and property values | `codecs/model/Rbx` |
| bitmap fonts as a Font; PostScript glyph names | `codecs/font/Bitmap`, `codecs/font/GlyphNames` |
| CRC-16 (XMODEM / ARC), xxHash32 | `core/Crc16`, `codecs/compress/Xxh32` |
+54
View File
@@ -470,6 +470,8 @@ 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 | - |
| VMF (Hammer, read + write) | a mesh per entity with solids, displacements; point entities as nodes; cameras; visgroups | - |
```luau
local tank = assert(F.model.load(md2Bytes))
@@ -573,6 +575,56 @@ assert(model.textures[skinA.baseColorTexture.texture].uri == "materials/models/t
assert(#src.physics.solids[1].hulls == 2)
```
### 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"))
```
### Hammer maps (VMF)
`.vmf` sources load like `.map` files: a mesh per entity with solids (Valve 220 texture axes through
`codecs/model/Brush`), displacements tessellated as the compiler does (a brush with a displaced side keeps only its
displaced sides), point entities as nodes (`extras.model` for props), Hammer cameras as cameras. `tools/*` materials
are left out unless `tools = true`; texture sizes come from `textureSizes`, or `materials/<name>.vtf` through
`resolve` and `decodeImage`, else 512 x 512. `meta.entities` holds the keys (outputs under `connections`),
`meta.visgroups`, `meta.groups` and `meta.solids` the editor data, and `meta.vmf` the parsed document, which `F.save`
writes back exactly as Hammer lays it out. `F.format("vmf")` builds documents: `document`, `world`, `box`, `solid`,
`entity`.
```luau
local hammer = assert(F.model.load(vmfText, { format = "vmf" }))
assert(hammer.meta.entities[1].classname == "worldspawn" and hammer.meta.visgroups[1].name == "Walls")
assert(#hammer.cameras == 2)
assert(F.saveString(hammer, { format = "vmf" }) == vmfText) -- unchanged documents write back byte for byte
local Vmf = F.format("vmf")
local doc = Vmf.document({ skyname = "sky_day01_01" })
table.insert(Vmf.world(doc), Vmf.box({ -128, -128, -16 }, { 128, 128, 0 }, "DEV/DEV_MEASUREGENERIC01B"))
Vmf.entity(doc, { { "classname", "info_player_start" }, { "origin", "0 0 8" } })
local built = assert(F.model.load(assert(F.saveString(doc, { format = "vmf" })), { format = "vmf" }))
assert(#built.meshes[1].primitives == 1 and built.meta.entities[2].classname == "info_player_start")
```
## Blitz3D (B3D)
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
@@ -813,6 +865,8 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
| 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 |
| 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 |
| 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) |