Mdl (Where it starts)¶
- class valvemdl.Mdl(path=None)[source]¶
Contains all the data from an Mdl file.
An mdl is small (a couple of kilobytes is typical) and its contents form one interlinked graph rather than a set of independent blocks, so the file is parsed eagerly and in full.
Its sidecars are not. A model is really a set of files –
.mdl,.vvd, and one.vtxper graphics backend – and most callers only ever want the mdl. Opening an mdl therefore only detects the sidecars sitting next to it; they are parsed on first access tovvdorvtx, and cached from then on.- __init__(path=None)[source]¶
Creates an empty instance of Mdl.
- Parameters:
path (str, optional) – A path to an existing mdl file.
- header¶
- Type:
(construct.Container) - The parsed studiohdr_t.
- header2¶
- Type:
(construct.Container) - The parsed studiohdr2_t, None when absent.
- linearbones¶
- Type:
(construct.Container) - studiohdr2’s linear bone table, or None.
- property version¶
Team Fortress 2 ships 44 through 48. See the constants page.
- Type:
(int) - The mdl version.
- property checksum¶
The engine refuses to load a set whose checksums disagree.
- Type:
(int) - Ties the mdl to its vvd and vtx files.
- property name¶
The model’s own idea of its path, as baked in at compile time.
studiohdr_t.nameis a fixed 64 byte buffer, so studiomdl spills longer paths intostudiohdr2_t.sznameindexinstead. This resolves whichever one is live, the same way the engine’spszName()does.- Type:
(str) - The model’s path.
- property surfaceprop¶
The model-wide surface property, named in the qc by
$surfaceprop. Individual bones carry their own, which is what the engine actually uses when it needs to know what a given bone is made of.- Type:
(str) - A surfaceprop name, e.g.
'metal'.
- property models¶
Every model in the file, flattened out of the bodypart tree.
Note that these are alternatives – a model here is one option inside one bodypart, not one model in the everyday sense. Only one per bodypart is ever drawn at a time.
- Type:
(list[construct.Container]) - All the models.
- property meshes¶
Every mesh in the file, flattened out of the bodypart tree.
- Type:
(list[construct.Container]) - All the meshes.
- bodygroup(bodynum)[source]¶
Decodes a packed bodygroup int into one model per bodypart.
studiomdl packs the whole choice of alternatives into a single integer, which entities carry as
m_nBody. Each bodypart pulls its own choice back out with itsbaseas the stride.
- save(destination=None)[source]¶
Writes the model back out.
The bytes are rebuilt from the object graph rather than copied from the file, so what lands on disk reflects the model as it now is.
- Parameters:
destination (str, optional) – Where to write. Overwrites the original when not given.
- coverage()[source]¶
Reports how much of the file ValveMDL can account for.
Rebuilding into an empty buffer means every byte has to be put there by something; anything left is something we have not understood. This reports what happened, which is more honest than a bare “it worked”:
struct– bytes regenerated from parsed structures.opaque– bytes copied at an extent we worked out ourselves, the compressed animation streams above all.unclaimed– bytes nothing wrote. Harmless where the original is zero (alignment padding, which the rebuild gets for free) and a real gap where it is not.
- Returns:
Byte counts, plus
differ: how many bytes the rebuild got wrong. Zero means the round trip is byte-exact.- Return type:
- skin_texture(skin, material)[source]¶
Resolves a mesh’s material through the skin table.
A mesh does not name its texture directly.
mstudiomesh_t.materialis a column in the skin table, and the row is whichever skin the entity happens to be using – which is how one model ships red and blu variants without duplicating any geometry.
- property vvd¶
The model’s vertex file, parsed on first access.
- Type:
(Vvd) - The vertex file.
- Raises:
MdlSidecarMissingError – when there is no vvd next to the mdl.
- property vtx¶
Defaults to the
dx90flavour; useget_vtx()for the others.- Type:
(Vtx) - The model’s optimized mesh file, parsed on first access.
- get_vtx(extension='.dx90.vtx')[source]¶
Provides one of the model’s vtx files, parsing it on first access.
studiomdl emits a vtx per graphics backend. They describe the same meshes optimized differently, so they are not interchangeable.
- Parameters:
extension (str, optional) – Which flavour to load. See the constants page for the available values.
- Returns:
The parsed vtx.
- Return type:
- Raises:
MdlSidecarMissingError – when that flavour is not next to the mdl.