model/sourcemdl: .vmt materials through codecs/text/KeyValues (cdmaterials search, patch include / insert / replace, $basetexture / $bumpmap as .vtf references), docs/guide scene section
This commit is contained in:
1 parent
d8212c6839
commit
80fd9cf1e8
6 files changed
+280
-7
No files matched your search
@@ -507,6 +507,49 @@ local again = assert(F.save(barney, nil, { format = "smd" })) -- SMD writes ba
|
||||
assert(F.model.load(again).skins[1])
|
||||
```
|
||||
|
||||
## 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)
|
||||
|
||||
`.b3d` files (Blitz3D, also written by many old game tools) load read-only. The node tree keeps its names and TRS;
|
||||
@@ -745,6 +788,7 @@ assert(back.meshes[1].primitives[1].indices.count == 3)
|
||||
| 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 |
|
||||
| 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