Assets
An asset is a raw file under your game's assets/ folder: a mesh, a texture, a
shader, a font or a sound. Assets have no behavior. You refer to them by their path
relative to assets/, for example "models/crate.gltf" or "audio/hum.wav".
Supported files
| Kind | Source formats | Used by |
|---|---|---|
| Mesh | glTF (.gltf, .glb) |
Mesh.mesh, Collider.mesh |
| Texture | PNG, JPG, TGA | Mesh.texture, <image src> in UI |
| Shader | Slang (.slang) |
Mesh.shader |
| Font | TrueType (.ttf) |
font-family: "path.ttf" in .style |
| Sound | WAV (mono or stereo), Ogg Vorbis | AudioSource.asset, audioPlay* calls |
A glTF file is flattened into one mesh. Fonts are baked into signed-distance-field
atlases covering Latin-1. The default UI font is Inter (font-family: Inter).
A custom shader's "world" position is relative to the render origin, a point near the camera on the level's chunk grid (see Large worlds). It stays precise however far the level reaches, but it jumps by whole chunks when the origin moves, so don't key patterns that must stay put (noise, grids) to it.
How importing works
You never run the importer yourself while developing. When a game first asks for an
asset, the engine runs molten-import on a worker thread and caches the result in
<work dir>/imported/, as a runtime file named after the source plus an extension
(models/crate.gltf becomes models/crate.gltf.mmesh). Gameplay keeps using the source
path.
While the game runs, Molten watches the source file. When you save a new version, it is re-imported and swapped in behind the same handle, so every object using it updates. A file that fails to import keeps the previous version and logs the error.
molten-import also runs by hand, which is useful in scripts:
molten-import <source file> <source root> <output root> [--include dir]
Using assets
In files, write the path:
export default object({
mesh: { mesh: "models/crate.gltf", texture: "textures/wood.png" },
});
In Cast, load an asset to get its handle (an asset value), for example to swap a mesh:
node.mesh.mesh = loadAsset("models/pole.gltf");
loadAsset returns the same handle every time for the same path. Sound calls take the
path directly: audioPlay("audio/click.wav", "ui", 0.5, false, 0).
Binary data stays out of text
Heavy data (meshes, terrain, baked lighting) never goes into concept files. Text files refer to binary files by path.
In a shipped game
molten build --release imports every asset ahead of time and packs the results into
game.mtpack next to the executable. See Shipping.