srctools.vmt

Parses material files.

class srctools.vmt.VarType(
value,
names=None,
*,
module=None,
qualname=None,
type=None,
start=1,
boundary=None,
)

Bases: Enum

The different types shader variables can be.

The value is the name used in the game code.

FLAG = 0
MATERIAL = 'SHADER_PARAM_TYPE_MATERIAL'
STR = 'SHADER_PARAM_TYPE_STRING'
TEXTURE = 'SHADER_PARAM_TYPE_TEXTURE'
INT = 'SHADER_PARAM_TYPE_INTEGER'
FLOAT = 'SHADER_PARAM_TYPE_FLOAT'
BOOL = 'SHADER_PARAM_TYPE_BOOL'
COLOR = 'SHADER_PARAM_TYPE_COLOR'
VEC2 = 'SHADER_PARAM_TYPE_VEC2'
VEC3 = 'SHADER_PARAM_TYPE_VEC3'
VEC4 = 'SHADER_PARAM_TYPE_VEC4'
MATRIX = 'SHADER_PARAM_TYPE_MATRIX'
MATRIX_4X2 = 'SHADER_PARAM_TYPE_MATRIX4X2'
FOUR_CC = 'SHADER_PARAM_TYPE_FOURCC'
from_name = <bound method VarType.from_name of <enum 'VarType'>>
class srctools.vmt.Material(
shader: str,
params: Mapping[str, str] = srctools.EmptyMapping,
blocks: Iterable[Keyvalues] = (),
proxies: Iterable[Keyvalues] = (),
)

Represents a material.

This behaves as a mapping, storing the shader parameters.

shader: str

The name of the shader.

blocks: List[Keyvalues]

Other sub-blocks inside the material definition. These are usually fallbacks or other similar definitions.

proxies: List[Keyvalues]

List of Material Proxies defined for the material. Each is a tuple of the string name and a dict of keys-> values. “Empty” proxies are removed.

classmethod parse(
data: Iterable[str],
filename: str = '',
) Material

Parse a VMT from the file.

export(f: TextIO) None

Write the material back to a file.

apply_patches(
fsys: FileSystem,
*,
limit: int = 100,
parent_func: Callable[[str], None] | None = None,
) Material

If the material is a Patch <https://developer.valvesoftware.com/wiki/Patch> shader expand to the full material.

Parameters:
  • fsys – This reads from the supplied filesystem as required.

  • limit – If more than this many files are parsed, a RecursionError is raised.

  • parent_func – If this is provided, it will be called with the filenames of the VMTs which are looked up. This allows tracking which are used.

srctools.vmt.get_parm_type(name: str) VarType | None
srctools.vmt.get_parm_type(
name: str,
default: ArgT,
) VarType | ArgT

Retrieve the type a parameter has, or return the default.