Crate gltf [] [src]

glTF 2.0 loader

This crate is intended to load glTF 2.0, a file format designed for the efficient runtime transmission of 3D scenes. The crate aims to provide rustic utilities that make working with glTF simple and intuitive.

Installation

Add gltf version 0.6 to your Cargo.toml.

[dependencies.gltf]
version = "0.6"

Examples

Loading glTF from the file system

The crate provides a from_path method whereby one can import glTF from the system.

extern crate gltf;

fn main() {
    let path = "path/to/asset.gltf";
    // This creates a `Future` that drives the loading
    // of glTF and all of its data.
    let import = gltf::Import::from_path(path);
    // The simpliest way of working with futures is to
    // block the thread until the glTF is ready.
    match import.sync() {
        Ok(gltf) => println!("{:#?}", gltf),
        Err(err) => println!("error: {:?}", err),
    }
}

An Import resolves to Gltf, a data structure that provides helpful utilities such as iterators for working with glTF.

Walking the node hierarchy

Below demonstates visiting the root Nodes of every Scene, printing the number of children each node has.

let gltf = gltf::Import::from_path(path).sync()?;
for scene in gltf.scenes() {
    for node in scene.nodes() {
        // Do something with this node
        println!(
            "Node {} has {} children",
            node.index(),
            node.children().count(),
        );
    }
}

Reexports

pub use self::gltf::Gltf;
pub use self::import::Data;
pub use self::import::Import;

Modules

accessor

Contains Accessor and other related data structures.

animation

Contains Animation and other related data structures.

buffer

Contains Buffer, View, and other related data structures.

camera

Contains Camera and other related data structures.

extensions

Contains extension specific data structures.

gltf

Contains Gltf, and other related data structures.

image

Contains Image and other related data structures.

import

Contains functions for importing glTF 2.0 assets.

json

Contains (de)serializable data structures that match the glTF JSON text.

material

Contains Material and other related data structures.

mesh

Contains Mesh and other related data structures.

root

Contains Root.

scene

Contains Scene, Node, and other related data structures.

skin

Contains Skin and other related data structures.

texture

Contains Texture, Sampler, and other related data structures.

validation

Contains functions that validate glTF JSON data against the specification.