Skip to content

Asset Pipeline

This doc covers how source files (images, models) become engine resources:

  • where paths resolve;
  • how .mfmeta sidecars 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.

  • ContentPaths resolves engine files (shaders, built-in content) against the application folder. It never uses the working directory.
  • AssetDatabase.Current is rooted at ContentPaths.BaseDirectory, the folder holding Assets/. 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.Current to 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 was Content/; ContentPaths.UpgradeLegacyPath still reads Content/… as Assets/…, in ContentPaths.Resolve, the RmlUi file interface and AssetDatabase.ToAbsolutePath. The editor renames an old project’s folder when it opens it (Projects).

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.

ExtensionWhat it isBefore ADR 0249
.mfscenea scene (JSON, its own UID).mscene
.mfresa resource (JSON, its own UID).mres
.mfmusican adaptive music manifest.mmusic
.mfsongan editor song.msong
.mfsavea save slot.msave
.mfmetaan imported asset’s sidecar: UID and import settings.meta
.mfprobesa light-probe bake’s coefficients (the data file of an .mfres).probes
x.slang.mfspvlocka surface shader’s build lockx.slang.spvlock
x.slang.mflayout.jsona surface shader’s reflected layoutx.slang.layout.json
.mfprojthe project file
.mfpakan export’s content pack
.mftimelinea video timeline
.mfcap.jsona recording’s capture sidecar
.mftranscript.jsona 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.Matches accepts the legacy name wherever a loader dispatches on the extension (ResourceLoader, the asset scan, export staging, the l10n extractor).
  • FileExtensions.FindExisting reads a legacy sidecar (x.png.meta, x.slang.layout.json, x.slang.spvlock) when there is no current one.
  • AssetDatabase.ToAbsolutePath and ContentPaths.Resolve send a legacy path whose file is gone to the renamed file, so ChangeSceneToFile("Assets/Scenes/Main.mscene") and an old mainScene keep working after the migration.
  • SaveServer renames slot.msave and its copies to .mfsave once at start.
  • The editor offers FileExtensionMigration when it opens such a project (Projects).

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 File takes, so each call site is a one-for-one swap: absolute paths (what ContentPaths.Resolve and AssetDatabase.ToAbsolutePath return, 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, as File would (tools such as mf-shaders check pass repository-relative paths). Resolve "Assets/…" paths first.
  • Mounts. ContentFiles.Mount(IContentSource, priority) serves the paths under the source’s Root directory 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’s Assets.mfpak is mounted at ContentPaths.BaseDirectory (Packs); tests mount a MemoryContentSource or a pack.
  • Native readers. RmlUi reads documents and font faces through the managed file interface, which opens ContentFiles streams. Assimp is given an aiFileIO (AssimpContentIO) when the model lies under a mount, so a glTF’s .bin buffers 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. Exists on an absolute path allocates nothing (the canvas renderer asks while drawing); sources take ReadOnlySpan<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 on File. A read that must see the disk carries a // disk-io: <reason> comment, and ContentIoAuditTests.RuntimeContentCodeDoesNotCallFileApis fails on any other File/Directory read in MainframeEngine/Src outside its list of user-data and build files.
  • Games read their own data files through ContentFiles too, 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), from Aes in ECB through one reused ICryptoTransform per 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, so PackReader.Open throws PackKeyException (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 a nativeAot export (G19 phase 4) that is machine code, not IL, and the module initializer still runs before GameHost mounts 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 take ReadOnlySpan<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 InvalidDataException naming the pack when it is opened, not mid-load; a missing or wrong key throws PackKeyException.

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 .mfmeta sidecar (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.

ImporterExtensionsResultSettings type
TextureImporter (texture).png .jpg .jpeg .tga .bmpTexture2D (pixels decoded on first use)TextureImportSettings
ModelImporter (model).gltf .glb .fbx .obj .daeimported PackedScene (IsImported)ModelImportSettings

Games can AssetImporters.Register their own importers.

{ "uid": "tex_7e57c4ec4e70", "importer": "texture",
"settings": { "colorSpace": "auto", "mipmaps": true, "filter": "linear", "wrap": "repeat", "anisotropy": 8 } }
KeyValues (default)Effect
colorSpaceauto, srgb, linear (auto)auto: sRGB in colour slots (albedo, emission), UNORM in data slots (normal maps) — see Materials & meshes
mipmapsbool (true)full mip chain generated on the GPU (blits)
filterlinear, nearest (linear)sampler filter
wraprepeat, clamp, mirror (repeat)sampler addressing
anisotropy1–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)
fixAlphaBorderbool (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.

{ "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).
AssimpEngine
fileroot Node3D named after the file, Scale = scale; Assimp’s synthetic root is skipped when it is empty
nodeNode3D, or MeshInstance3D when it has meshes; transform decomposed into position / rotation / scale
the node’s meshesone ArrayMesh, one MeshSurface per Assimp mesh; nodes using the same meshes share it; points and lines are dropped
materialStandardMaterial3D: name, base colour or diffuse (linear → sRGB), opacity, emissive + intensity, shininess, two-sided, glTF alpha mode (MASK → cutout, BLEND → blend) and cutoff
texturesbase 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 meshesa MeshInstance3D under the skeleton with a Skin (inverse bind matrices) and MeshSurface.Joints/Weights
animationsAnimations (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.

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:

  • Metallic from $mat.metallicFactor (0 without one), Roughness from $mat.roughnessFactor, or from the shininess (√(2 / (n + 2))) for files without it (FBX, OBJ);
  • glTF’s metallicRoughnessTexture (Assimp’s Metalness/DiffuseRoughness, Unknown in older builds) and occlusionTexture (Lightmap, or AmbientOcclusion) become one OrmTexture: the image itself when both are the same packed ORM file, else OrmPacker.PackGltf (occlusion’s R, the metallic-roughness map’s G and B; nearest resampling to the larger size).

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.

"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": { "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).

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).

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).

  • Assimp is a native library from the Ultz.Native.Assimp package (loaded by Silk.NET’s resolver). Where it cannot load, model imports throw InvalidOperationException and 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 .mfmeta decides), and UV sets beyond the first. Format 1 sidecars read no PBR data unless they say "shading": "pbr"; generated LODs skip skinned surfaces. "importMaterials": false surfaces 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).

Materials & meshes · Scene serialization · GPU resources · Build & platforms