Skip to content
attackgoatPublic

About

A data pak format for games

Resources

Stars

5 stars

Watchers

1 watching

Forks

Latest commit

 

History

143 Commits

Folders and files

Repository files navigation

.pak Asset Crate

Crates.io Docs.rs

Bundles assets with compression, string tables, and other game-related special handling functions. Release baking produces a self-contained .pak. Debug baking stores content-group payloads in generation-named .pakseg files beside the root so unchanged groups can be reused. Keep the root and its referenced segments together; segment placement is internal, not a manifest setting. During Cargo build scripts the baker uses the target's PROFILE; standalone baking falls back to the baker's debug assertions.

See the changelog for archive compatibility and upgrade instructions.

A .pak file is written at build time and streamed in at runtime. Each asset package is "baked" from a configuration source file. Example:

Rust code

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

When generating bake inputs into a build/artifact directory, keep those generated files outside the source tree and pass the source asset root explicitly:

PakBuf::bake_with_dir(
    out_dir.join("generated/game_art.toml"),
    out_dir.join("game_art.pak"),
    manifest_dir.join("assets"),
)?;

The explicit directory is used for asset globs, project-rooted asset paths, and pak keys. The existing PakBuf::bake(src, dst) API remains available and uses the content file's parent directory as before.

Main .pak Configuration File

game_art.toml:

[content]
compression = 'snap'
default-lods = [{ layout = 'POSITION', simplify = true }]

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

[content] Schema

All fields are optional.

Item Description
compression 'snap', 'brotli', or unspecified (no compression).
default-lods (array, default []) Default layout requests inherited by meshes, each containing layout and simplify.
default-source-lods (boolean, default false) Request complete source-layout chains for static primitives. Meshes can override with source-lods or opt out of inheritance.
buffer-size (unsigned integer) Brotli buffer size. Used only when compression = 'brotli'. Defaults to 4096.
quality (unsigned integer) Brotli compression quality. Used only when compression = 'brotli'. Defaults to 8.
window-size (unsigned integer) Brotli window size. Used only when compression = 'brotli'. Defaults to 22.

Mesh LOD defaults are content-wide, not group settings. Direct .glb/.gltf assets, keyed mesh recipes, and inline or referenced scene meshes all inherit the root [content].default-lods. Mesh lods adds requests to these defaults.

[content.group] Schema

All fields are optional.

Note:

Additional [[content.group]] tables may be appended. All groups are added to the same logical package. Debug baking uses enabled groups as internal segment boundaries; release baking stores their payloads in the root file.

Item Description
name (string) Optional display name used in diagnostics and debug segment filenames.
assets (string array) File paths or glob patterns of assets to bake. Assets may be native file types (such as .png and .glb) or asset (.toml) files as detailed in the following sections.
exclude (string array) File paths or glob patterns to exclude from the baking process when considering assets.
enabled (boolean) Global flag which may be used to prevent baking of this group.

3D Animations

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

Example, cool-walk.toml:

[animation]
src = 'some_file.gltf'

Or to simply load some_file.gltf using some_file.toml:

[animation]

[animation] Schema

All fields are optional.

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

3D Meshes

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

Example, large-goblet.toml:

[mesh]
src = 'some_file.gltf'
lods = [{ layout = 'PACKED_NORMAL', simplify = true }]
max-index = 'u16'

[mesh] Schema

All fields are optional.

Item Description
blob File path to an optional unstructured byte blob associated with this mesh.
authored-lods (string array) Ordered names of reduced mesh nodes in the same source file. Replaces automatic complete-layout generation; each level must retain primitive/material order and vertex layout and strictly reduce triangle count. Skinned levels must share joint order, names, parents and inverse binds, with at most 256 joints and four influences per vertex. Weights must be normalized and round to an exact 255-unit UNORM8 sum. The measured geometric error describes the rest pose, not arbitrary deformation.
data TOML table of application-defined metadata, using the same value types as material data. Included in mesh identity and deduplication.
src File path to a .gltf or .glb mesh. May be relative to the [mesh] TOML file or absolute where the root is the same folder as the [content] TOML file. When unspecified, attempts to load a mesh with the same name as the [mesh] TOML file.
euler (string) Order of operations applied to 3-channel rotation values (example: xyz, zyx, etc).
flip-x (boolean) When set, flips the X component of all position vertices.
flip-y (boolean) When set, flips the Y component of all position vertices.
flip-z (boolean) When set, flips the Z component of all position vertices.
ignore-skin (boolean) When set, any embedded skin data is ignored.
ignore-texture1 (boolean) When set, the second texture coordinate channel is ignored.
inherit-lods (boolean, default true) Include [content].default-lods and default-source-lods. Set false to use only local requests; this does not disable inheritance of [content.lod] processing settings.
lods (array, default []) Local layout requests added to inherited defaults, overriding matching layouts. An empty list does not disable inheritance. Use simplify = false for a source-only request.
lod-lock-border (boolean) When set, tells MeshOpt to generate level of detail meshes using only interior vertices.
lod-target-error (float, default 0.05) Finite nonnegative base-relative MeshOpt error budget. Overrides nested target-error; iterative group errors accumulate within the original absolute budget.
max-index (string or unsigned integer) When set, reduces and compacts the baked mesh so no LOD references an index greater than this value. Accepts 'u8', 'u16', or an exact value such as 4095 or 65535. Uses MeshOpt simplification and may reduce the base mesh before generating LODs.
min-lod-triangles (unsigned integer) When set, tells MeshOpt to stop generating level of detail meshes below this threshold.
name (string) When set, imports this named mesh. Otherwise, imports the first mesh.
normals (boolean) When set (default true), imports geometry normals.
offset (array of float with a length of 3) When set, offsets geometry positions by the given amount.
optimize (boolean) When set (default true), reorders geometry indices and vertices using MeshOpt.
optimize-vertex-cache (boolean) Overrides the vertex-cache part of optimize. Defaults to the value of optimize; explicitly setting true with optimize = false reorders triangles only, retaining vertex bytes and leaving overdraw/fetch optimization disabled. Triangle IDs change, so derive triangle-indexed metadata from the baked result.
overdraw-threshold (float) When set (default 1.05), controls MeshOpt optimization.
rotation (array of float with a length of 3 or 4) When set, the vector (XYZ) or quaternion (XYZW) rotation applied to geometry.
scale (float or array of float with a length of 3) When set, the uniform or vector (XYZ) scale applied to geometry.
scene-name (string) When set, controls which GLTF scene is imported from the source file.
source-lods (boolean) Generate complete source-layout chains independently for each static primitive. Overrides [content].default-source-lods, including when inherit-lods = false.
tangents (boolean) When set (default true), imports geometry tangents. If missing, tangents are generated using the MikkTSpace algorithm

max-index is a hard cap on the maximum index value, not just a triangle-count target. If a mesh initially needs indices above the cap, baking simplifies the mesh and compacts the vertex buffer so IndexBuffer can store the result as u8 or u16 where possible. Lower generated LODs are derived from the capped mesh.

Meshes expose blob() / set_blob(BlobId) separately from data(key) and the public data: DataMap. Use mesh.data.insert(key, pak::scene::DataData::Float(value)) to add or replace metadata while preserving other authored entries. MeshAsset accepts blob = 'payload.bin' alongside [mesh.data]; its public data map matches materials. The derived-asset baking entry points call DerivedAssetBaker::bake_mesh(&mut Mesh) once per unique final mesh, after transforms, optimization, and primitive construction, even without scene references or eligible opacity micromaps. The hook defaults to no-op. Pak writes pak.mesh-lod.* for LOD generation reports; other mesh metadata is application-defined.

Complete source-layout LODs

Use this when consumers need each retained triangle's original attributes and material slot, rather than a projected guide or a joined material partition:

[content]
default-source-lods = true

[content.lod]
min-triangles = 64
target-error = 0.05
normal-weight = 0.5
texture-weight = 1.0

A per-model [mesh] source-lods = false disables automatic source-layout requests. Existing primitive-local lods take precedence when they already request the complete source layout, including simplify = false. Grouped requests remain separate families. Selecting a model recipe requires referencing its TOML file; a reference to its GLB does not read a neighboring recipe.

Each chain is stored in Primitive::lod_sets() and starts with the unchanged final canonical geometry, after transforms, optimization, and max-index. Reduced levels compact only retained source vertex records; they preserve normals, UV0/UV1, tangents, and the primitive's material slot without creating replacement materials. Normals and UV channels contribute weighted simplification error. texture-weight defaults to 1.0 and must be finite and nonnegative. Errors are estimates, not texture or alpha- coverage guarantees; tangent bytes are retained but tangent interpolation error is not measured separately.

Automatic requests skip skinned and morph-target primitives. Valid chains may contain only the canonical level if reduction stalls. Shared material-seam positions stay locked, so a consumer may retain one primitive's canonical geometry while simplifying another. This guarantee applies to these independent chains, not to arbitrary members of a grouped snapshot. Automatic source-layout requests ignore join/voxelize; existing explicit grouped requests continue to use those settings separately.

Direct LodRequest::process also accepts non-joint-weighted complete layouts for simplification. Requested normals, texture coordinates, and tangents must be finite. Generation does not select a runtime level or enable any consumer feature.

Authored complete-layout LODs

[mesh]
name = 'bench'
authored-lods = ['bench_lod1', 'bench_lod2']
source-lods = false
inherit-lods = false
optimize = false

The canonical node is selected from the requested source scene; authored levels are named nodes anywhere in the same file. Separate scenes can keep alternatives out of canonical-only collision or acoustic exports. Their transforms and the recipe's import options apply normally. Lower levels may contain new positions, normals, UVs and tangents; they need not be subsets of the canonical mesh. Primitive count, original glTF material indices, material order and imported vertex layouts must match. Skins, morph targets, duplicate names, conflicting full-layout requests and max-index reduction are rejected. The source level remains unchanged.

Errors use SampledGeometricAbsolute: bidirectional nearest-surface distances at triangle corners and seven interior samples, measured directly against LOD0 in transformed mesh-local units. These estimates do not bound unsampled displacement, normal, texture, silhouette or coverage changes. No simplification is performed on the authored family. Independent projected layout requests are still separate.

Joined and voxelized LODs

Opt in per mesh (or through [content.lod] defaults):

[mesh]
src = 'prop.glb'
lods = [{ layout = 'POSITION', simplify = true }]

[mesh.lod]
join = true
voxelize = true
voxel-size = 0.05

join and voxelize independently default to false. Joining operates across material primitives in one mesh. Voxelization reconstructs a smooth surface from closed, outward-wound shells; voxel-size is a positive length in transformed mesh-local units. voxel-max-cells defaults to 262144 and bounds sparse reconstruction work; exceeding the limit fails baking.

Generated triangles are assigned whole to original materials using the unsimplified source. Final buffers, patches, bounds, and diagnostics are stored in Mesh::lod_groups(). Consumers must select a complete group snapshot together; an omitted material partition means zero triangles at that level. Mesh::bounds() encloses canonical and alternative geometry.

See grouped surface LODs for the API, error metrics, limitations, and consumer migration. Archives now use V1.11 and must be rebaked; include pak::buf::MESH_LOD_PRODUCER in consumer cache keys.

Raw Blobs

Arbitrary files may be baked as raw byte blobs.

Example, nav-data.toml:

[blob]
src = 'nav-data.bin'

[blob] Schema

All fields are optional.

Item Description
src File path to the blob. May be relative to the [blob] TOML file or absolute where the root is the same folder as the [content] TOML file. When unspecified, attempts to load a blob with the same name as the [blob] TOML file.

PBR Materials

Material data for use in rendering.

All fields are optional.

Example, glowing-lava.toml:

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

[material] Schema

Item Description
alpha-test (boolean) Reject base-color alpha below the consumer's alpha-test cutoff.
color Hex string, path string, inline bitmap asset, or sequence.
height Hex string, path string, inline bitmap asset, or floating point value.
double-sided (boolean_) When set, indicates the material is double-sided.
emissive Hex string, path string, inline bitmap asset, or array of three floating point values.
metal Hex string, path string, inline bitmap asset, or floating point value.
mip-quality 'default' (also when omitted) or 'high'. See High-Quality Mips below.
normal Path string or inline bitmap asset.
occlusion Hex string, path string, inline bitmap asset, or floating point value. Mutually exclusive with height.
rough Hex string, path string, inline bitmap asset, or floating point value.
transmission Hex string, path string, inline bitmap asset, or floating point value.

When any material parameter is set, MaterialInfo::params stores the packed RGBA parameter map as R = metal, G = rough, B = height or occlusion, and A = transmission. Height and occlusion cannot both be authored. MaterialInfo::params_used indicates which channels were authored; missing channels are default-filled, with occlusion's neutral value being 1.

Materials can also carry application-defined data using the same value types as scene data: booleans, f32 floats, i32 numbers, strings, and recursively nested arrays. Pak stores these values without application-specific interpretation or validation. Data participates in material deduplication; key order does not matter.

[material]
rough = 0.5

[material.data]
category = "fabric"
enabled = true
layers = [1, 2, 3]
settings = [0.25, ["detail", false]]

Inline scene materials also accept a data table. At runtime, MaterialInfo::data(key) and MaterialInfo::data.get(key) return a borrowed pak::scene::DataRef; MaterialInfo::data.iter() yields (&str, DataRef) entries in key order, including application-unknown keys. Absent authored data produces an empty DataMap. MaterialInfo is owned and cloneable, not Copy; material reads return clones.

Bitmaps

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

Example, ui-skin-001.toml:

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

[bitmap] Schema

All fields are optional.

Item Description
src File path to an image. May be relative to the [bitmap] TOML file or absolute where the root is the same folder as the [content] TOML file. When unspecified, attempts to load a bitmap with the same name as the [bitmap] TOML file.
mip-levels (boolean or non-zero unsigned integer) When set (default 1), allows configuration of the desired count of mip levels to be stored with a bitmap for later use by a program.
mip-quality 'default' (also when omitted) or 'high'.
resize (unsigned integer) When set, the image is uniformly resized to have this maximum dimension.
color (string) When set (default srgb), the image is imported as either linear or srgb color data.
swizzle (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).

High-Quality Mips

Set mip-quality = 'high' on a material or standalone bitmap:

[material]
mip-quality = 'high'
color = 'face-color.png'

High requires BC compression; materials require texture-compression = true. Standalone bitmaps may instead set compression to bc1-srgb, bc1-rgb, bc3, bc4 or bc5. Base pixels are preserved; mips extend to 1x1 regardless of mip-levels. Color uses linear-light, premultiplied-alpha Lanczos3 filtering. Linear data and packed parameters use area averages. Material normals require BC5 and filter vector moments reconstructed from RG, normalizing only emitted directions. Filtering stays float32 between levels; RGB encoding uses IterativeClusterFit regardless of PROFILE.

High rejects resize, uncompressed output, material height and alpha-test color. Parameter images must match dimensions.

Bitmap Fonts

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

Example, font-h4.toml:

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

[bitmap-font] Schema

All fields are optional.

Item Description
src File path to a bitmap font definition. May be relative to the [bitmap-font] TOML file or absolute where the root is the same folder as the [content] TOML file. When unspecified, attempts to load a bitmap font definition with the same name as the [bitmap-font] TOML file.

Scenes

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

Example, large-castle.toml:

[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

[scene] Schema

All fields are optional.

Item Description
[[scene.geometry]] Inline indexed triangle geometry tables.
[[scene.ref]] Scene reference tables for meshes, materials, transforms, tags, and custom data.

[[scene.geometry]] Schema

Item Description
id (string) Optional identifier. It is not required to be unique.
euler (string) Order of operations applied to 3-channel rotation values (example: xyz, zyx, etc).
indices (array of unsigned integer) Triangle index list. Length must be a multiple of 3.
rotation (array of float with a length of 3 or 4) Euler XYZ degrees or quaternion XYZW rotation.
translation (array of float with a length of 3) Translation applied to the geometry.
vertices (array of float) Packed XYZ position values.
tags (array of string) Program-specific tags. Tags are trimmed, lowercased, and sorted during baking.
data TOML table of program-specific values. Values may be booleans, strings, i32 integers, floats, or arrays of those values.

[[scene.ref]] Schema

Item Description
id (string) Optional identifier. It is not required to be unique.
euler (string) Order of operations applied to 3-channel rotation values (example: xyz, zyx, etc).
materials (array) Material asset references. Each entry may be a material TOML path, image path, or inline material asset.
mesh Mesh asset reference. May be a mesh TOML path, .gltf/.glb path, or inline mesh asset.
rotation (array of float with a length of 3 or 4) Euler XYZ degrees or quaternion XYZW rotation.
translation (array of float with a length of 3) Translation applied to the reference.
tags (array of string) Program-specific tags. Tags are trimmed, lowercased, and sorted during baking.
data TOML table of program-specific values. Values may be booleans, strings, i32 integers, floats, or arrays of those values.

Tests

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

cargo test --all-features

About

A data pak format for games

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages