merge ws/sourcemdl: Source MDL v44-49 (+vvd/vtx/phy/ani, flexes, animations), VMT materials, codecs/model/SourceAnim
This commit is contained in:
commit
c19a68dfae
33 files changed
+14429
-1224
No files matched your search
+22
-1
@@ -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.
|
||||
|
||||
@@ -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) |
|
||||
|
||||
Reference in new issue
Block a user