source-vmt
A high-performance, ergonomic Rust library for parsing, manipulating, and resolving Source Engine VMT (Valve Material Type) files.
Beyond basic parsing, source-vmt provides a complete material management ecosystem, including VFS integration, recursive patch resolution, and material proxy support.
Key Features
- Ergonomic API: Automatic handling of
$and%prefixes, with type-safe getters for Source-specific formats (e.g., parsing[0.0 0.5 1.0]or{255 128 0}into normalized colors). - Patch Resolution: Deep inheritance support for the
patchshader, automatically merginginsertandreplaceblocks. - Material System: An optional high-level manager integrating with
source-fsfor caching, file path tracking, fallback materials, and procedural material registration. - Serde Integration: Extract and deserialize custom VMT blocks directly into strongly-typed Rust structs.
- Material Proxies: Dedicated API for extracting, modifying, and adding material proxies.
- Memory Optimization: Optional string interning (
intern_keysfeature) via global pooling to drastically reduce memory footprint when loading thousands of materials.
Feature Flags
material_system— Enables theMaterialSystemand pulls insource-fsfor virtual filesystem integration.intern_keys— Enables key deduplication usingdashmapwtihArcto optimize memory usage.
Quick Start
1. Basic Editing & Fluent API
use Vmt;
2. Type-Safe Access & Serde Blocks
The library automatically handles key normalization (case-insensitivity, prefixes).
// Automatically parses Source color vectors/bytes into [f32; 3]
if let Some = vmt.get_color
// Extract a nested block into a custom struct using Serde
if let Some = vmt.?
3. Managing Material Proxies
You can easily read and construct Proxies blocks.
// Add a new proxy
vmt.add_proxy;
// Iterate over existing proxies
for proxy in vmt.proxies
4. Patch Resolution & Material System (Requires material_system)
Use the MaterialSystem to automatically locate materials via gameinfo.txt search paths and resolve recursive patch shaders.
use MaterialSystem;
License
MIT License.