merge ws/sourcemdl: Source MDL v44-49 (+vvd/vtx/phy/ani, flexes, animations), VMT materials, codecs/model/SourceAnim

This commit is contained in:
4DBug committed 2026-11-01 19:25:04 -06:00
commit c19a68dfae
33 files changed
+14429 -1224

No files matched your search

+4
View File
@@ -90,6 +90,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| model | robloxmesh | .mesh | yes | yes | skinning: true, lods: true, versions: "1.00", "1.01", "2.00", "3.00", "3.01", "4.00", "4.01", "5.00", "6.00", "7.00" | `tests/model/robloxmesh.luau` |
| model | schematic | .schem .schematic .litematic | yes | yes | voxels: true, blocks: true, variants: "schem", "schematic", "litematic" | `tests/model/schematic.luau` |
| model | smd | .smd | yes | yes | skins: true, animation: true | `tests/model/smd.luau` |
| 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 | vox | .vox | yes | yes | voxels: true, sceneGraph: true, materials: true | `tests/model/vox.luau` |
@@ -148,6 +149,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| data | plist | .plist | yes | yes | binary: "read", ordered: true | `tests/data/plist.luau` |
| data | snbt | .snbt | yes | yes | ordered: true, typed: true | `tests/data/snbt.luau` |
| data | toml | .toml | yes | yes | ordered: true, dates: true | `tests/data/toml.luau` |
| data | vdf | .vdf .acf .res .kv | yes | yes | ordered: true, binary: true | `tests/data/vdf.luau` |
| data | xml | .xml .xsd .xsl .xslt .rss .atom .xhtml | yes | yes | namespaces: true, streaming: true | `tests/data/xml.luau` |
| data | yaml | .yaml .yml | yes | yes | ordered: true, multiDocument: true, anchors: true | `tests/data/yaml.luau` |
| vector | svg | .svg | yes | yes | rasterize: true, text: false | `tests/vector/svg.luau` |
@@ -255,9 +257,11 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- 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.
- codecs/model/Sampler: Scene animation sampling, STEP / LINEAR (slerp) / CUBICSPLINE as in glTF 2.0 animations. New code.
- codecs/model/SourceAnim: studio model animation data: the run-length coded mstudioanimvalue_t shorts (GoldSrc and
- codecs/model/Vrml: VRML97 / X3D scene-graph engine (classic and XML encodings) for model/vrml and model/x3d.
- **text**
- codecs/text/Json: JSON (RFC 8259 / ECMA-404) parse and serialize, the engine data/json, glTF, TMJ, ... use. New code.
- codecs/text/KeyValues: Valve KeyValues text (tier1/KeyValues.cpp of the Source SDK 2013, srctools' reading of it)
- codecs/text/Nbt: Minecraft's Named Binary Tag format and SNBT (Minecraft wiki "NBT format", wiki.vg "NBT").
- codecs/text/Text: text decoding helpers: BOM stripping, Windows-1252 for text that is not UTF-8, line splitting.
- codecs/text/Url: RFC 3986 reference resolution (section 5.2), local-path classification and percent-encoding.
+4 -2
View File
@@ -33,9 +33,9 @@ src/Rosetta/
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 Nbt Text Url Xml
text/ Json KeyValues Nbt Text Url Xml
font/ Bitmap Cff GlyphNames TrueType
model/ Draco Mat4 MeshFlatten Minecraft Polygon Rbx Rig Sampler Vrml
model/ Draco Mat4 MeshFlatten Minecraft 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
@@ -242,7 +242,9 @@ them. Anything generic goes down a layer and is called:
| GPU texture pixels (BCn, ETC / EAC, uncompressed texel layouts, half floats) | `codecs/image/Texture` (`Bcn`, `Etc`, `Texel`, `Half`) |
| 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` |
| 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` |
| 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` |
+22 -1
View File
@@ -306,6 +306,26 @@ local xml = assert(F.saveString(p, { format = "plist" }))
assert(string.find(xml, "<key>CFBundleName</key>\n\t<string>Demo</string>", 1, true))
```
## VDF (Valve KeyValues)
`.vdf`, `.acf`, `.res` and other KeyValues files decode to `Types.object`s of strings; a key that repeats gets an array
of its values (`duplicates = "last"` / `"first"` keep one). `[$CONDITION]`s are evaluated for a PC (`defines =
{ OSX = true }` changes the flags, `defines = false` keeps every pair), `#include` / `#base` files come through
`resolve`, `escapes = false` reads backslashes as they are. `pairs = true` gives the ordered pair list of
`codecs/text/KeyValues` (`{ key, value, cond?, type? }`), which keeps everything. Binary KeyValues (`shortcuts.vdf`)
are sniffed; encode with `binary = true`.
```luau
local acf = assert(F.data.load('"AppState"\n{\n\t"appid"\t"440"\n\t"x" "1"\n\t"x" "2"\n}\n', { format = "vdf" }))
assert(acf.AppState.appid == "440" and acf.AppState.x[2] == "2")
local text = assert(F.saveString(acf, { format = "vdf" }))
assert(string.find(text, '\t"x"\t"1"\n\t"x"\t"2"\n', 1, true))
local pairs = assert(F.data.load('"r" { "a" "1" [$X360] }', { format = "vdf", pairs = true, defines = false }))
assert(pairs[1].value[1].cond == "$X360")
local bin = assert(F.save(acf, nil, { format = "vdf", binary = true }))
assert(F.data.load(bin, { format = "vdf" }).AppState.appid == "440")
```
## Save and convert
Data values have no `kind`, so saving needs `opts.format` or a destination extension (an `XmlNode` document too):
@@ -337,6 +357,7 @@ is an error there), CSV needs rows, INI needs sections of scalars, JSON has no b
| toml (`.toml`) | yes | yes | ordered tables, Dates |
| csv (`.csv`, `.tsv`) | yes | yes | rows (arrays or records) |
| ini (`.ini`, `.cfg`, `.conf`, `.desktop`) | yes | yes | sections of strings |
| vdf (`.vdf`, `.acf`, `.res`, `.kv`) | text + binary | text + binary | ordered objects of strings, or pairs |
| msgpack (`.msgpack`, `.mpk`) | yes | yes | values, buffers, Dates |
| cbor (`.cbor`) | yes | yes | values, buffers, Dates, tagged values |
| plist (`.plist`) | XML + binary | XML | values, buffers, Dates |
@@ -351,7 +372,7 @@ Full capability list: [FORMATS.md](../FORMATS.md).
- Luau has one number type: `1.0` reads back as `1`, and TOML / plist write integral floats as integers. Integers
past 2^53 need `bigInts = "string"` to survive.
- An empty plain table `{}` is written as an array; use `F.Types.object()` (or `emptyTable = "object"`) for `{}`.
- Text formats sniff weakly: give `format` (or a file name) for YAML, TOML, INI, CSV, MessagePack and CBOR without
- Text formats sniff weakly: give `format` (or a file name) for YAML, TOML, INI, VDF, CSV, MessagePack and CBOR without
its self-describe tag.
- XML whitespace-only text between elements is dropped by default (`whitespace = true` keeps it); text is never
trimmed otherwise.
+42
View File
@@ -528,6 +528,47 @@ 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)
## Source engine models (MDL v44-49)
`sourcemdl` reads Source studio models (Half-Life 2 to CS:GO-era v44-49; GoldSrc v10 stays `mdl`). The geometry is
in sibling files found through `files` / `resolve` (or `vvd` / `vtx` / `phy` / `ani` buffers): `<name>.vvd`
vertices, `<name>.dx90.vtx` (else `.dx80` / `.sw` / `.vtx`) strips, optional `<name>.phy` collision and the `.ani`
animation blocks; `<name>` is the stem of `opts.name`, else of the name stored in the MDL. Without them the Scene has
the skeleton and the animations only (`meta.source.warnings` says what was missing).
- Bones become a skin (`poseToBone` as the inverse bind matrices); procedural bones (jiggle, aim-at, ...) are data in
the joint nodes' `extras.procedural`.
- Each body part model is a mesh (one primitive per studio mesh); `bodies` picks the model per body part for the
nodes (default 1), the others are in `scene.meshes` and `meta.source.bodyParts`. `lod` picks the LOD of
`prim.indices`; every LOD's indices are in `prim.extras.lods`.
- Flexes are morph targets (stereo flexes split by side), named in `mesh.extras.targetNames`; attachments are nodes
under their bones; hitboxes, sequences (activities, events, blends), pose parameters and flex rules are in
`meta.source`.
- Each animation (decoded from the run-length / Quaternion48 / 64 data, sections and `.ani` blocks; delta
animations added to the rest pose) is named after the first sequence that plays it.
- Materials: each texture name is looked up as `materials/<cdmaterials dir><name>.vmt`; `$basetexture` / `$bumpmap`
become `.vtf` texture URIs (`F.model.loadTextures` with a `resolve` for the game's files decodes them),
`$translucent` / `$alphatest` / `$nocull` / `$color` map to the material, and every parameter is kept in
`material.extras.vmt`.
```luau
local files = {
["model.vvd"] = sourceVvdBytes,
["model.dx90.vtx"] = sourceVtxBytes,
["model.phy"] = sourcePhyBytes,
["materials/models/test/skin_a.vmt"] = skinVmtText,
}
local model = assert(F.model.load(sourceMdlBytes, { name = "model.mdl", files = files }))
local src = model.meta.source
assert(src.format == "sourcemdl" and src.version == 49 and model.meta.up == "z")
assert(#model.skins[1].joints == 6)
local body = model.meshes[src.bodyParts[1].models[1].mesh]
assert(#body.primitives == 2 and body.extras.targetNames[1] == "AU1L")
assert(#body.primitives[1].extras.lods == 2)
assert(model.animations[1].name == "idle" and src.sequences[1].activity == "ACT_IDLE")
local skinA = model.materials[1]
assert(model.textures[skinA.baseColorTexture.texture].uri == "materials/models/test/skin_a.vtf")
assert(#src.physics.solids[1].hulls == 2)
```
## Blitz3D (B3D)
@@ -769,6 +810,7 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
| 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 |
| Source MDL (v44-49) + VVD / VTX / PHY | yes | - | skeleton, body parts, LODs, flexes, animations, VMT materials: see 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) |