Asset Pipeline
Purpose
Section titled “Purpose”This doc covers how source files (images, models) become engine resources:
- where paths resolve;
- how
.mfmetasidecars carry UIDs and import settings; - which importer handles which file;
- how imports are cached.
Scene and resource files (.mfscene/.mfres) are covered in Scene serialization. This page
covers everything ResourceLoader imports.
ContentPathsresolves engine files (shaders, built-in content) against the application folder. It never uses the working directory.AssetDatabase.Currentis rooted atContentPaths.BaseDirectory, the folder holdingAssets/. Since M3 it no longer uses the working directory either, so a game loads the same files however it is launched (dotnet run, an IDE, a test runner, a published app). The render-test host and games no longer change directory at startup.- Tools assign
AssetDatabase.Currentto the open project. Tests assign it to a temporary project. - Relative asset paths (
"Assets/Models/Crate.gltf") are project-relative with/separators. UIDs resolve through the database first, and the path is only a hint. - The content folder is
Assets/(ADR 0197;ContentPaths.FolderName). Before project format 4 it wasContent/;ContentPaths.UpgradeLegacyPathstill readsContent/…asAssets/…, inContentPaths.Resolve, the RmlUi file interface andAssetDatabase.ToAbsolutePath. The editor renames an old project’s folder when it opens it (Projects).
File extensions
Section titled “File extensions”Every extension the engine, editor, video library or tools define starts with .mf (ADR 0249). The constants are in
FileExtensions, and FileExtensionRuleTests fails on a new extension constant without the prefix, unless the test’s
exempt list names it with a reason.
| Extension | What it is | Before ADR 0249 |
|---|---|---|
.mfscene | a scene (JSON, its own UID) | .mscene |
.mfres | a resource (JSON, its own UID) | .mres |
.mfmusic | an adaptive music manifest | .mmusic |
.mfsong | an editor song | .msong |
.mfsave | a save slot | .msave |
.mfmeta | an imported asset’s sidecar: UID and import settings | .meta |
.mfprobes | a light-probe bake’s coefficients (the data file of an .mfres) | .probes |
x.slang.mfspvlock | a surface shader’s build lock | x.slang.spvlock |
x.slang.mflayout.json | a surface shader’s reflected layout | x.slang.layout.json |
.mfproj | the project file | |
.mfpak | an export’s content pack | |
.mftimeline | a video timeline | |
.mfcap.json | a recording’s capture sidecar | |
.mftranscript.json | a media file’s cached transcript |
Third-party formats keep their names (.slang, .spv, .rml, .rcss, .po/.mo, Spine’s .atlas/.skel, media),
as do temporary and fixed names (.tmp, .bakN, .partial, .stems, shaders.lock).
Projects made before ADR 0249 still load:
FileExtensions.Matchesaccepts the legacy name wherever a loader dispatches on the extension (ResourceLoader, the asset scan, export staging, the l10n extractor).FileExtensions.FindExistingreads a legacy sidecar (x.png.meta,x.slang.layout.json,x.slang.spvlock) when there is no current one.AssetDatabase.ToAbsolutePathandContentPaths.Resolvesend a legacy path whose file is gone to the renamed file, soChangeSceneToFile("Assets/Scenes/Main.mscene")and an oldmainScenekeep working after the migration.SaveServerrenamesslot.msaveand its copies to.mfsaveonce at start.- The editor offers
FileExtensionMigrationwhen it opens such a project (Projects).
Content file system
Section titled “Content file system”Every runtime content read goes through ContentFiles (Src/Core/Content/, G19 phase 1,
ADR 0239): shaders and their locks, textures, scenes and resources,
the asset index and .mfmeta files, RmlUi documents, stylesheets and fonts, audio (streamed too), music manifests, .mo
catalogs and locale folders, Spine exports, terrain and light-probe data, models, and project.mfproj. It replaces the
File/Directory read calls one for one: Exists, DirectoryExists, GetInfo (length and last write),
OpenRead (seekable), ReadAllBytes, ReadAllText, EnumerateFiles, EnumerateDirectories.
- Paths stay what they were. It takes the paths
Filetakes, so each call site is a one-for-one swap: absolute paths (whatContentPaths.ResolveandAssetDatabase.ToAbsolutePathreturn,Texture2D’s file path, a shader’s SPIR-V paths) are used as they are, and any other relative path resolves against the working directory, asFilewould (tools such asmf-shaders checkpass repository-relative paths). Resolve"Assets/…"paths first. - Mounts.
ContentFiles.Mount(IContentSource, priority)serves the paths under the source’sRootdirectory until the returned handle is disposed: a path under a mounted root is looked up in the mounts holding it (highest priority first, then mount order), then on the disk. Paths outside every mount, and every path when nothing is mounted, read the disk exactly as before. Enumeration unions the mounts and the disk, ordinal-sorted. An export’sAssets.mfpakis mounted atContentPaths.BaseDirectory(Packs); tests mount aMemoryContentSourceor a pack. - Native readers. RmlUi reads documents and font faces through the managed file interface, which opens
ContentFilesstreams. Assimp is given anaiFileIO(AssimpContentIO) when the model lies under a mount, so a glTF’s.binbuffers and images come from the mount too; otherwise it opens the path itself. Spine exports are read through the vendored runtime’s stream overloads (SpineContent). - Threads and allocation. Mounts are an immutable array swapped under a lock, so the loader worker and the audio
streamer read while a mount changes.
Existson an absolute path allocates nothing (the canvas renderer asks while drawing); sources takeReadOnlySpan<char>paths for it. - Not content. Writes (saves,
settings.json, logs, crash reports, recordings, the pipeline cache, bake caches, editor saves) and native libraries stay onFile. A read that must see the disk carries a// disk-io: <reason>comment, andContentIoAuditTests.RuntimeContentCodeDoesNotCallFileApisfails on any otherFile/Directoryread inMainframeEngine/Srcoutside its list of user-data and build files. - Games read their own data files through
ContentFilestoo, so they keep loading once an export packs them.
An export’s Assets.mfpak (G19 phase 2, Game export → Packed content) is read by
PackReader and mounted as a PackContentSource (Src/Core/Content/). PackWriter writes it; the export’s stage step,
tests and ContentLoadBenchmarks use it.
- Format v1 (
PackFormat, little-endian): a 64-byte header (MFPK, version, options, the index’s offset, stored and decoded lengths, the index nonce, 4 reserved bytes, a 16-byte key check), the entries in ordinal path order, then the Brotli-compressed index (count; per entry its UTF-8 path, offset, stored length, length, codec and a 12-byte nonce). The nonce is the first 12 bytes of SHA-256(path ‖ content). - Encryption (G19 phase 3,
PackCipher). With a key, every entry’s stored bytes and the compressed index are AES-256-CTR: keystream block i is AES(key, nonce ‖ big-endian i), fromAesin ECB through one reusedICryptoTransformper stream, so any range decrypts on its own (seeks), in place in the caller’s buffer, with 0 B per read. There is no authentication tag (tamper resistance is a non-goal). The header’s 16-byte key check is the first keystream block of a fixed nonce, soPackReader.OpenthrowsPackKeyException(PackKeyMissing,PackKeyMismatch) at open. Nonces come from content, so a stable key keeps packs byte-identical and a change to one asset changes only its entry’s bytes and the index. The key reaches the game through a generated module initializer of the game assembly; in anativeAotexport (G19 phase 4) that is machine code, not IL, and the module initializer still runs beforeGameHostmounts the pack. - Codecs. Media that is already compressed or is streamed with seeks (
.ogg,.wav,.mp3,.flac,.opus,.png,.jpg,.webp,.ktx2, video,.zip) is stored 16 KB aligned. Everything else is Brotli (quality 9, window 22) when that saves at least 1/16 of the file, else stored. Stored entries are read straight from the pack; Brotli entries are decoded whole when opened. - Layout for patches (ADR 0247). SteamPipe diffs in
~1 MB chunks. An entry of a page (1 MB) or more, and about one entry per 16 MB chosen from its path’s hash and its own
size (
PackFormat.IsAnchor), starts on a page boundary. A changed, added or removed asset re-lays out only the entries up to the next anchor; later entries move by whole pages, so their chunks still match. The padding costs about 3 %. - Deterministic. The same files give the same bytes: sorted paths, no timestamps, content-derived nonces.
- Reads. One read-only handle per pack and positional reads (
RandomAccess), so the loader worker and the audio streamer read at once. A stored entry’s stream reads and seeks without allocating, and lookups takeReadOnlySpan<char>(0 B). Every packed file reports the same last write time. - Errors. A file that is not a pack, a newer format, or a damaged index or entry throws
InvalidDataExceptionnaming the pack when it is opened, not mid-load; a missing or wrong key throwsPackKeyException.
Importers
Section titled “Importers”ResourceLoader.Load hands every file that is not .mfscene/.mfres to the IAssetImporter registered for its
extension (AssetImporters). The importer receives:
- the absolute path;
- the project path;
- the file’s
.mfmetasidecar (AssetMeta:format,uid,importer,settings).
A sidecar’s format (ADR 0255) is the version of the defaults it was written under: new sidecars get
AssetMeta.CurrentFormat (2), sidecars written before have none (read as 1), and rewriting an existing sidecar keeps
its format. Format 1 model sidecars import Blinn-Phong unless they say "shading" (PBR materials).
The loader gives the result the file’s ResourcePath and the meta’s UID, and caches it like any other resource:
by UID and path, reference-counted.
| Importer | Extensions | Result | Settings type |
|---|---|---|---|
TextureImporter (texture) | .png .jpg .jpeg .tga .bmp | Texture2D (pixels decoded on first use) | TextureImportSettings |
ModelImporter (model) | .gltf .glb .fbx .obj .dae | imported PackedScene (IsImported) | ModelImportSettings |
Games can AssetImporters.Register their own importers.
Textures
Section titled “Textures”{ "uid": "tex_7e57c4ec4e70", "importer": "texture", "settings": { "colorSpace": "auto", "mipmaps": true, "filter": "linear", "wrap": "repeat", "anisotropy": 8 } }| Key | Values (default) | Effect |
|---|---|---|
colorSpace | auto, srgb, linear (auto) | auto: sRGB in colour slots (albedo, emission), UNORM in data slots (normal maps) — see Materials & meshes |
mipmaps | bool (true) | full mip chain generated on the GPU (blits) |
filter | linear, nearest (linear) | sampler filter |
wrap | repeat, clamp, mirror (repeat) | sampler addressing |
anisotropy | 1–16 (8) | clamped to the device; 1 = off |
svgScale | > 0 (1) | .svg only: rasterisation scale (Godot’s svg/scale); SVGs are rasterised at load by mfsvg (ThorVG as in Godot, ADR 0112) |
fixAlphaBorder | bool (false) | Godot’s process/fix_alpha_border: nearly transparent pixels take their nearest opaque neighbour’s colour |
Missing keys take the defaults. Invalid values are logged and replaced by the default, and unknown keys are
ignored with a warning. TextureImportSettings.ToMetaSettings() writes the object, for tools. Changing
Texture2D.ImportSettings at runtime re-uploads the texture.
Models
Section titled “Models”{ "format": 2, "uid": "mdl_7e57a55e7000", "importer": "model", "settings": { "scale": 1, "generateNormals": true, "importMaterials": true, "optimizeMeshes": false, "importAnimations": true, "optimizeAnimations": true, "clips": [ { "name": "run", "loop": "Linear" } ], "shading": "pbr", "lodErrors": [], "generateLods": false } }Models import through Silk.NET.Assimp (ADR 0013). The post-processing steps are:
- Triangulate, join identical vertices, sort by primitive type, improve cache locality, validate.
FlipUVs, because Vulkan samples with a top-left UV origin, like glTF.- Optionally, smooth normals and mesh optimisation.
LimitBoneWeights(four influences per vertex), and FBX pivots not preserved (IMPORT_FBX_PRESERVE_PIVOTS= 0).
| Assimp | Engine |
|---|---|
| file | root Node3D named after the file, Scale = scale; Assimp’s synthetic root is skipped when it is empty |
| node | Node3D, or MeshInstance3D when it has meshes; transform decomposed into position / rotation / scale |
| the node’s meshes | one ArrayMesh, one MeshSurface per Assimp mesh; nodes using the same meshes share it; points and lines are dropped |
| material | StandardMaterial3D: name, base colour or diffuse (linear → sRGB), opacity, emissive + intensity, shininess, two-sided, glTF alpha mode (MASK → cutout, BLEND → blend) and cutoff |
| textures | base colour or diffuse → albedo, normals → normal map, emissive → emission. Files next to the model load through ResourceLoader, so their own .mfmeta applies; embedded images (*N, e.g. GLB, or by file name, e.g. FBX) decode in memory |
| bones (ADR 0208) | one Skeleton3D at the armature node (bones, rests); nodes under bones → BoneAttachment3Ds |
| skinned meshes | a MeshInstance3D under the skeleton with a Skin (inverse bind matrices) and MeshSurface.Joints/Weights |
| animations | Animations (named after the actions) in an AnimationLibrary on an AnimationPlayer child of the root; loop modes and events from a -loop suffix, glTF animation extras and the .mfmeta clips |
Skeletons, skins and clips are described in Animation and skinning → Import.
PBR materials (G6.1)
Section titled “PBR materials (G6.1)”Materials import as ShadingMode.Pbr by default (ADR 0255); "shading": "blinnPhong" imports the file’s shininess as
a Blinn-Phong highlight instead. A sidecar written before ADR 0255 (no format) without "shading" imports
Blinn-Phong, the default it was written under, so existing projects keep their look; a model without a sidecar is new
and imports PBR. Surfaces the file gives no material get a material of the same mode. PBR reads:
Metallicfrom$mat.metallicFactor(0 without one),Roughnessfrom$mat.roughnessFactor, or from the shininess (√(2 / (n + 2))) for files without it (FBX, OBJ);- glTF’s
metallicRoughnessTexture(Assimp’sMetalness/DiffuseRoughness,Unknownin older builds) andocclusionTexture(Lightmap, orAmbientOcclusion) become oneOrmTexture: the image itself when both are the same packed ORM file, elseOrmPacker.PackGltf(occlusion’s R, the metallic-roughness map’s G and B; nearest resampling to the larger size).
Authored levels of detail (G6.4)
Section titled “Authored levels of detail (G6.4)”Sibling mesh nodes named <name>_LOD0 … <name>_LOD7 merge into one MeshInstance3D <name> whose surfaces carry the
other levels as MeshLods with their own geometry; "lodErrors" gives their errors as fractions of the LOD0 bounds
radius (default 1 %, doubling). "generateLods": true simplifies every other surface into index-only levels with
meshoptimizer (skinned surfaces excepted; ADR 0256). Details:
Rendering features → Authored LODs on import and
Generated LODs.
Linked animation libraries (G1c)
Section titled “Linked animation libraries (G1c)”"libraries": [ "Assets/Characters/hero_anims.mfres" ] puts those AnimationLibrary files on the model’s
AnimationPlayer before its imported clips (the importer creates a player for a model without clips of its own),
so every instance plays them and a library clip wins over an imported clip of the same name. The pose baker adds the
library it writes (Animation and skinning → Pose scripts and baking). A
library that fails to load is skipped with a warning. The editor follows changes to both: a rewritten library reloads in place and a model whose .mfmeta
now links one reopens the clean scenes that use it (Editor → Files changed on disk).
Humanoid map overrides (G1c)
Section titled “Humanoid map overrides (G1c)”"humanoid": { "LeftUpperLeg": "Thigh.L", "LeftLowerLeg": "Shin.L" } maps canonical humanoid bones to the rig’s bones
by name, winning over what HumanoidMap.Detect finds from names and structure; an
empty name ("LeftToes": "") unmaps a bone. It is written only when set, and nothing reads it at import: detection runs
on demand, so the setting never changes what imports (ADR 0281).
PackedScene.Instantiate() on an imported scene clones the imported template. Exported properties are copied, so
meshes, materials and textures are shared, and every node is owned by the instance root, as for scene files. A
scene that instances a model stores only the model’s UID and path and the instance’s overrides, never mesh data
(see Scene serialization).
Import cache
Section titled “Import cache”ModelImporter keeps a cache of imported templates, keyed by full path, file size, modification time and settings
(at most 32 entries, oldest dropped first). Loading a model again, or after the loader released it, does not re-run
Assimp. A changed file or .mfmeta re-imports. ResourceLoader.ClearCache() clears it, and so does engine shutdown.
ModelImporter.ImportCount and CacheCount are for diagnostics and tests.
There is no on-disk cache of imported data: scenes stay JSON and never bake binary data (ADR 0011).
The test model
Section titled “The test model”Tests/MainframeEngine.Tests/TestAssets/TestModel.cs generates a small CC0 glTF (test_model.gltf/.bin, a
checker PNG and their .mfmeta files). It contains a two-level node hierarchy, one box mesh shared by two nodes, a
two-primitive mesh with an opaque double-sided material and a blended one, and an empty node. The committed copy
lives in Tests/Assets/Models/TestModel/ (the shared test assets) and in Examples/Demo/Assets/Models/TestModel/, where the Demo uses it. To
regenerate it, run UPDATE_TEST_ASSETS=1 dotnet test Tests/MainframeEngine.Tests --filter TheCommittedTestModel.
A unit test fails if the committed copy and the generator drift apart.
SkinnedCharacter.cs next to it generates the skinned character (Tests/Assets/Models/Character/character.glb, also
in the Demo): a 31-bone Blender-style rig, a two-primitive skinned mesh of about 6 000 triangles and ten clips
(Animation and skinning → Testing).
Known issues
Section titled “Known issues”- Assimp is a native library from the
Ultz.Native.Assimppackage (loaded by Silk.NET’s resolver). Where it cannot load, model imports throwInvalidOperationExceptionand the import tests fail. See the M3 risks in the progress log for the Linux CI loader. - Not imported: morph targets, cameras, lights, glTF sampler settings (the image’s
.mfmetadecides), and UV sets beyond the first. Format 1 sidecars read no PBR data unless they say"shading": "pbr"; generated LODs skip skinned surfaces."importMaterials": falsesurfaces draw the engine’s default material, which is PBR since ADR 0255. - Silk.NET’s animation key structs are larger than the bundled Assimp’s; the importer detects the key stride from the data (ADR 0208).
Related docs
Section titled “Related docs”Materials & meshes · Scene serialization · GPU resources · Build & platforms