polysmelt
Pure-Rust 3D asset interchange, with glTF as the hub. Read what other tools write, keep what you don't understand, and write compact or plain files back out.
Status
Early. What exists today:
meshopt: theEXT_meshopt_compressionandKHR_meshopt_compressionbitstreams. It has meshoptimizer's attribute (v0), triangle and index-sequence encoders, the octahedral filter's encoder, and decoders for every mode (attributes v0 and v1, triangles, indices) and filter (octahedral, quaternion, exponential, color).gltf:decompressturns a meshopt-compressed GLB into a plain one (quantization is kept);compressdoes the reverse, losslessly;pack_glbandpack_glb_decompressedturn a.gltfand its files into one GLB, withfiles_inas a fetch that stays inside the model's folder.cargo run --example meshopt -- sample out.glbwrites a small test file.formats: readers for STL (binary and ASCII), PLY, MagicaVoxel.vox, OBJ with MTL materials and textures, FBX (binary and ASCII), 3DS, 3MF, USD (.usda,.usdc,.usdz) and glTF 2.0 (.gltf,.glb, meshopt- or Draco-compressed or not), and glTF 1.0 (withKHR_binary_glTFandKHR_materials_common), upgraded to 2.0 as it's read.formats::loadreads a file andformats::load_bytesa model already in memory; both dispatch on the extension and return adocument::Document.document: the common form, a glTF 2.0 document (its JSON and its buffers' bytes). glTF passes through untouched: nothing is decoded, andDocument::to_glbwrites the buffers back as they are, compression included, with images embedded. The other formats are converted into it.Document::flatten(Pose)derives a flat, posed trianglemesh::Mesh(transforms, instances, skins and morphs baked in), andDocument::countscounts triangles, points and lines from the JSON alone.Document::decoderewrites it as plain glTF any reader takes: meshopt views and Draco primitives decoded, quantized attributes turned into floats, the scene graph, animation and materials untouched. AKeeppassed to the load says what to keep: everything by default, or for instanceKeep { animations: false, ..Keep::ALL }for static meshes that still carry their skins.- Conformance corpus: 549 cases under
tests/corpus, each a file and the GLB it must become. They cover every format above and the variants exporters really write: OBJ's face forms and MTL dialects, both PLY byte orders, every FBX version and axis system, and USD's three encodings and its composition, and glTF's accessor types, node hierarchy, skins and extensions. Most are generated against the specifications; the rest are Blender 5.2 exports. See tests/corpus/README.md. Every GLB the conformance tests write passes the Khronos glTF validator (tools/validate), which CI runs. - Benchmarks:
bench/races Polysmelt's readers against tobj, stl_io, ply-rs and gltf on load time and peak heap. Run it on a clean GitHub runner withgh workflow run bench.yml(or from the Actions tab); the tables land in the run summary. mesh: the flat triangle-list modelflattenproduces (primitives, materials, images), written out as a plain GLB bymesh::to_glb.assets: theAssetstrait readers use to find and read referenced files (MTL libraries, textures, glTF buffers, USD layers) and turn texture bytes into embeddable images.Foldersearches a pack's folder tree;Memoryholds files by path, for models loaded from memory. By default only PNG and JPEG embed; overrideAssets::imageto convert TGA, DDS, PSD and others.
Cargo features
| Feature | Format | Extra dependencies |
|---|---|---|
stl |
STL | none |
ply |
PLY | none |
vox |
MagicaVoxel | none |
obj |
OBJ + MTL | none |
3ds |
3DS | none |
gltf |
glTF 2.0 + GLB, and glTF 1.0 | none |
fbx |
FBX | fbxcel, base64 |
3mf |
3MF | zip, quick-xml |
usd |
USD | openusd, openusd-schemas, zip |
draco |
Draco-compressed glTF (KHR_draco_mesh_compression) | draco-core |
webp |
WebP textures (EXT_texture_webp, .webp files), re-encoded as PNG for the flat mesh |
image-webp, flate2 |
fs |
Reading files: formats::load, assets::Folder, gltf::files_in |
none |
Every reader is on by default, and so are fs and webp. minimal is the six readers with no
dependencies, plus fs, for default-features = false, features = ["minimal"]. Asking
formats::load for a format whose feature is off returns an error that names the feature.
Without fs the file APIs don't exist, so a build that has no file system (such as
wasm32-unknown-unknown) fails to compile rather than failing when it runs. Models load from
memory instead:
= { = "0.1", = false, = ["stl", "ply", "obj", "gltf", "usd"] }
use ;
let assets = new.with.with;
let mut doc = load_bytes?;
let glb = doc.to_glb?; // the scene, losslessly
let mesh = doc.flatten?; // or flat triangles
doc.decode?; // or plain glTF, for a reader without Draco, meshopt or quantization
Minimum Rust
Rust 1.88, with any features but usd. The usd feature, and so the default build, needs
1.96, because openusd does. CI builds minimal on 1.88 and everything on 1.96.
Planned scope
- Lossless conversion: every format is converted into the document with its hierarchy,
animations, cameras and lights, and its source's units, axes and raw values in extras.
Materials are written in full: the core model plus
KHR_materials_*(ior, specular, transmission, volume, clearcoat, sheen, anisotropy, emissive strength, unlit) andKHR_texture_transform, from each format's own values. Still to come: readers that skip more of whatKeepdrops. - Typed views over the document's meshes, accessors, nodes, skins and animations.
- Accessors: typed access through the document (the mesh reader already reads every component type, normalized and sparse).
- Compression: meshopt v1 encoding and filter encoders beyond octahedral, and
writing
KHR_mesh_quantization. - Scene: animations read and written, and instancing kept rather than baked.
- Writer: a builder with plain output (any viewer, Blender) or compact output (quantized and meshopt-compressed).
- Validation of glTF documents.
- Texture slots (
KHR_texture_basisu/KTX2), so a cook step can swap textures without touching geometry.
Out of scope: rendering, material semantics, and conversion through external tools such as Blender.
License
MIT-0. See LICENSE.