Expand description
§assetc
The runtime SDK of assetc, the asset compiler. Learn more about the project, its GUI and every source and output format in the main README.
§The project
assetc compiles source assets (textures, meshes, shaders, materials, fonts) into runtime-friendly binary formats for video games. Supports octahedral-packed normals/tangents and meshletized geometry; mesh files reference materials by stable 64-bit hashes so the engine can share resources across assets. Mesh additionally emits a companion material table plus one content-addressed .ktx2 per referenced image. Embedded textures are written to a shared flat store keyed by content, so the same texture used by two different models is encoded once and shares one runtime handle.
Texture refs are stored as 64-bit hashes, not paths. A single global manifest maps each hash back to the file on disk. Load it once into a hash → path map and you can resolve any asset by a stable id - textures (baseColorTex etc.), but also meshes, materials, animations, fonts, shaders, and embeds - through one uniform lookup.
§What the SDK does
assetc runs at build time; this crate runs in your game. It reads everything assetc build and assetc pack write, so the game never parses a binary layout itself:
- Opens the assets from a
.pak(the whole output in one file) or from an output directory, the same way, so you can ship a pack and develop against loose files. - Lists and finds them by kind, by asset ID (the stable 64-bit hash every asset and reference uses) or by output path.
- Decodes every format into plain Rust values: KTX2 textures with all mip levels, PBR and custom materials, meshes (vertices with unpacked normals and tangents, meshlets, levels of detail, skin, locators, shapes, regions, paths), animations (with sampling), SDF fonts (with text layout), atlases, gradients (with sampling), palettes, shader interfaces with SPIR-V, schemas, data instances, graphs, trees and attached structs.
- Stays engine-neutral and light: no dependencies but
std. Turning the values into GPU resources is your engine’s part; the repository’s demo does it for Bevy.
The format specs it follows are in docs/spec/, and its API in docs/features/sdk.md.
§Usage
[dependencies]
assetc = "0.2"use assetc::{Assets, Kind, Mesh, Texture};
fn main() -> assetc::Result<()> {
// A `.pak` from `assetc pack`, or the output directory of `assetc build`.
let assets = Assets::open("build/assetc.pak")?;
for entry in assets.of_kind(Kind::Mesh) {
let mesh: Mesh = assets.load(entry.id)?;
println!("{}: {} vertices", entry.path, mesh.vertices.len());
}
let texture: Texture = assets.load_path("ui/fire.ktx2")?;
println!("{}x{}", texture.width, texture.height);
Ok(())
}Licensed under either of MIT (LICENSE-MIT) or Apache-2.0 (LICENSE-APACHE), at your option.
Start with Assets::open on a .pak file or an output directory, then
Assets::load any asset by ID into one of the format types.
Re-exports§
pub use anim::Animation;pub use assets::Assets;pub use assets::Decode;pub use assets::Entry;pub use atlas::Atlas;pub use custom_material::CustomMaterial;pub use data::Data;pub use font::Font;pub use gradient::GradientSet;pub use graph::Graph;pub use manifest::Manifest;pub use material::Material;pub use mesh::Mesh;pub use pack::Pack;pub use palette::Palette;pub use property::Property;pub use property::PropertyValue;pub use schema::Schema;pub use shader::Shader;pub use structs::Attached;pub use structs::Scope;pub use structs::Structs;pub use texture::Texture;pub use tree::Tree;
Modules§
- anim
.aanim.binanimation clips; see docs/spec/aanim.bin.md.- assets
- One way in to a pack or an output directory; see docs/features/sdk.md#opening-assets.
- atlas
.aatlas.binatlas metadata: where each frame is in its texture; see docs/spec/aatlas.bin.md.- chunks
- The container shared by assetc’s binary formats; see docs/spec/chunks.md.
- custom_
material .acmat.bincustom materials: a shader’s values (GPU block bytes, texture IDs, params); see docs/spec/acmat.bin.md.- data
.adata.bincompiled data: instances as trees of typed values, every field resolved; see docs/spec/adata.bin.md.- font
.afont.binSDF fonts: metrics, glyphs, kerning, and laying out text; see docs/spec/afont.bin.md.- gradient
.agradient.bingradients: their stops by name, beside the image baked from them; see docs/spec/agradient.bin.md.- graph
.agraph.bindirected graphs; see docs/spec/agraph.bin.md.- hash
- FNV-1a 64, the hash behind asset IDs and name hashes; see docs/features/build.md#asset-ids.
- manifest
assetc.aman.bin, asset ID to output file; see docs/spec/aman.bin.md.- material
.amat.binPBR materials; see docs/spec/amat.bin.md.- mesh
.amesh.binmeshes; see docs/spec/amesh.bin.md.- pack
.pakpacks; see docs/spec/pak.md.- palette
.apalette.binpalettes: their colors by name, beside the image baked from them; see docs/spec/apalette.bin.md.- property
- Key / value properties of meshes, shapes, paths, animation events, graphs and trees; see docs/spec/amesh.bin.md#property-32-bytes.
- schema
.aschema.bincompiled schemas: types, fields and enum values; see docs/spec/aschema.bin.md.- shader
.ashader.binshaders: a custom material’s interface (params block layout, textures, state, the resources its stages declare) and its SPIR-V; see docs/spec/ashader.bin.md.- structs
- Attached structs: the
STRUCTS,SVALUES,SREFSandSSTRINGSchunks any format may carry, and the standaloneASTRUCTfile after a material’s record; see docs/spec/astruct.md. - texture
.ktx2textures as assetc writes them; see docs/spec/ktx2.md.- tree
.atree.bintrees, nodes breadth first; see docs/spec/atree.bin.md.
Enums§
- Error
- Why reading assets failed; see docs/features/sdk.md#errors.
- Kind
- What an asset is, with the values of the manifest and
.pakcontents.