14 releases

Uses new Rust 2024

0.6.2 Mar 16, 2025
0.6.0 Sep 23, 2024
0.5.0 May 29, 2024
0.4.0 Jan 23, 2024
0.0.0 Sep 19, 2017

#172 in Game dev

Download history 4/week @ 2025-02-05 8/week @ 2025-02-19 13/week @ 2025-02-26 255/week @ 2025-03-12

276 downloads per month

MIT/Apache

225KB
5K SLoC

.pak Asset Crate

Crates.io Docs.rs

.pak Configuration File

Each asset package is "baked" from a configuration source file. Example:

Rust code

PakBuf::bake("game_art.toml", "game_art.pak")?;

game_art.toml

[content]
compression = 'snap'

[[content.group]]
assets = [
    'bitmap/**/*.png',
    'font/**/*.toml',
    'mesh/**/*.toml',
    'sound/**/*.ogg',
    'music/*.mp3',
    'ui/*.png',
]

Note:

Additional [[content.group]] tables may be appended. All groups are added to the package and these individual groups are not distinct entities in the runtime file.

[content] Schema

Item Description
compression (Optional) 'snap' or 'brotli'

3D Animations

Bone structures and per-channel frame sample data may be loaded from .gltf or .glb files.

Example:

[animation]
src = 'some_file.gltf'

[animation] Schema

Item Description
src File path to the .gltf or .glb animation file. May be relative to the [animation] TOML file or absolute where the root is the same folder as the [content] TOML file.
name (Optional) Specific animation name (for use with files containing more than one animation).
exclude (Optional) Array of animation channel names to exclude from the import.

3D Meshes

Geometry may be loaded from .gltf or .glb files.

Example:

[mesh]
src = 'some_file.gltf'

[mesh] Schema

Item Description
src File path to the .gltf or .glb mesh file. May be relative to the [mesh] TOML file or absolute where the root is the same folder as the [content] TOML file.
euler (Optional, string) Order of operations applied to 3-channel rotation values (example: xyz, zyx, etc).
flip-x (Optional, boolean) When set, flips the X component of all position vertices.
flip-y (Optional, boolean) When set, flips the Y component of all position vertices.
flip-z (Optional, boolean) When set, flips the Z component of all position vertices.
ignore-skin (Optional, boolean) When set, any embedded boke structure data is ignored.
lod (Optional, boolean) When set, generates level of detail meshes using MeshOpt.
lod-lock-border (Optional, boolean) When set, tells MeshOpt to generate level of detail meshes using only interior vertices.
lod-target-error (Optional, float) When set, tells MeshOpt to attempt to hit a certain error threshold between level of detail meshes.
min-lod-triangles (Optional, unsigned integer) When set, tells MeshOpt to stop generating level of detail meshes below this threshold.
name (Optional, string) When set, imports this named mesh. Otherwise, imports the first mesh.
normals (Optional, boolean) When set (default true), imports geometry normals.
offset (Optional, array of float with a length of 3) When set, offsets geometry positions by the given amount.
optimize (Optional, boolean) When set (default true), reorders geometry indices and vertices using MeshOpt.
overdraw-threshold (Optional, float) When set (default 1.05), controls MeshOpt optimization.
rotation (Optional, array of float with a length of 3 or 4) When set, the vector (XYZ) or quaternion (XYZW) rotation applied to geometry.
scale (Optional, array of float with a length of 3) When set, the vector (XYZ) scale applied to geometry.
scene-name (Optional, string) When set, controls which GLTF scene is imported from the source file.
shadow (Optional, boolean) When set, imports position-only geometry optimized for use in shadow or other similiar rendering techniques.
tangents (Optional, boolean) When set (default true), imports geometry tangents. If missing, tangents are generated using the MikkTSpace algorithm

PBR Materials

Material data for use in rendering.

Example:

[material]
color = 'my-texture.png'

[material] Schema

Item Description
color Hex string, path string, inline bitmap asset, or seqeunce.
displacement (Optional) Hex string, path string, inline bitmap asset, or floating point value.
double-sided (Optional, boolean) When set, indicates the material is double-sided.
emissive (Optional) Hex string, path string, inline bitmap asset, or array of three floating point values.
metal (Optional) Hex string, path string, inline bitmap asset, or floating point value.
normal (Optional) Path string or inline bitmap asset.
rough (Optional) Hex string, path string, inline bitmap asset, or floating point value.

Bitmaps

Variable-channel bitap data (stored raw and compressed using the setting of the [content] compression).

Example:

[bitmap]
src = 'my-texture.png'

[bitmap] Schema

Item Description
src File path to an image file. May be relative to the [bitmap] TOML file or absolute where the root is the same folder as the [content] TOML file.
resize (Optional, unsigned integer) When set, the image is uniformally resized to have this maximum dimension.
color (Optional, string) When set (default srgb), the image is imported as either linear or srgb color data.
swizzle (Optional, string) When set (default rgba for four channel images), the specified image color channels are imported in the given order (example: r, rg or bgr).

Bitmap Fonts

Special handling is given to [bitmap-font] asset files.

Example:

[bitmap-font]
src = 'blocky-letters.fon'

The specified file is imported as a raw AngelCode bitmap font file, and any associated page images are loaded as bitmaps.

Scenes

Scene files may contain custom geometry and spatial reference data, each with the ability to store generic data as well.

Example:

[scene]

[[scene.ref]]
id = 'EnemySpawn'
rotation = [0.0, 0.0, 0.0, 1.0]
translation = [-1.0, 0.1, -6.0]
tags = [
    'bot',
]
data.type = 'monster3'

[[scene.ref]]
id = 'red-door'
rotation = [0.0, 0.0, 0.0, 1.0]
translation = [-0.9, 0.0, -12.0]
tags = [
    'door',
]
data.require = 'red-key'
data.joins = 'a,b'

[[scene.ref]]
mesh = '../kaykit/dungeon/floor_tile_large_grates.toml'
materials = [
    '../kaykit/dungeon/texture.toml',
]
rotation = [0.0, 0.0, -0.0, 1.0]
translation = [0.0, 0.0, -0.0]

[[scene.ref]]
mesh = '../kaykit/dungeon/floor_tile_large.toml'
materials = [
    '../kaykit/dungeon/texture.toml',
]
rotation = [0.0, 0.0, -0.0, 1.0]
translation = [6.0, 0.0, -2.0]

[[scene.geometry]]
id = 'a'
indices = [
    2, 0, 1,
    1, 3, 4,
    9, 11, 8,
    1, 4, 9,
    5, 2, 1,
    12, 10, 6,
    6, 5, 1,
    6, 1, 9,
    13, 14, 12,
    12, 6, 9,
    8, 13, 12,
    9, 8, 12,
]
vertices = [
    -8.399999618530273, 0.0, 7.400000095367432,
    6.400000095367432, 0.0, 7.400000095367432,
    -8.399999618530273, 0.0, -7.400000095367432,
    6.400000095367432, 0.0, -7.400000095367432,
    1.0, 0.0, -7.400000095367432,
    -3.0, 0.0, -7.400000095367432,
    -2.4000000953674316, 0.0, -8.0,
    1.0, 0.0, -7.400000095367432,
    -0.09999996423721313, 0.0, -11.40000057220459,
    0.3999999761581421, 0.0, -8.0,
    -2.4000000953674316, 0.0, -11.40000057220459,
    0.3999999761581421, 0.0, -11.40000057220459,
    -1.9000000953674316, 0.0, -11.40000057220459,
    -0.09999996423721313, 0.0, -12.0,
    -1.9000000953674316, 0.0, -12.0,
]
rotation = [0.0, 0.0, -0.0, 1.0]
translation = [1.0, 0.10000000149011612, -0.0]
tags = [
    'nav-mesh',
]

[[scene.ref]]
id = 'Camera'
rotation = [0.06613656878471375, -0.8706687092781067, 0.4718790054321289, 0.12203358113765717]
translation = [-19.0, 61.0, -53.0]
tags = [
    'camera',
]
data.type = 'persp'
data.z-near = 1.0
data.z-far = 200.0
data.fov-y = 0.349344402551651

Tests

Run tests with all features in order to include the baking code:

cargo test --all-features

Dependencies

~14–22MB
~532K SLoC