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.8 to your Cargo.toml
.
[dependencies.gltf]
version = "0.8"
Examples
Walking the node hierarchy
Below demonstates visiting the root Node
s of every Scene
, printing the
number of children each node has.
let file = std::fs::File::open("examples/Box.gltf")?; let reader = std::io::BufReader::new(file); let json = gltf::json::from_reader(reader)?; let gltf = gltf::Gltf::from_json(json); for scene in gltf.scenes() { for node in scene.nodes() { // Do something with this node. println!( "Node {} has {} children", node.index(), node.children().count(), ); } }
Providing Gltf
with external buffer data
The Source
trait provides glTF
objects with their buffer data. This allows
the crate to provide more abstractions such as iterating over the positions of
a Primitive
. See the documentation of Loaded
for all the methods available
for loaded glTF
.
The gltf-importer
crate contains the reference implementation of the
Source
trait and may be used to read buffer data from the file system.
#[derive(Debug)] struct BoxExampleData(&'static [u8]); impl gltf::Source for BoxExampleData { fn source_buffer(&self, _: &gltf::Buffer) -> &[u8] { // In a real implementation, the `Source` must provide all the data // necessary to load the object, and must not fail. // // This example meets the above criteria, since it provides all the data // for the 'Box' sample model, which has exactly one external buffer. self.0 } } let data = BoxExampleData(include_bytes!("examples/Box0.bin")); let loaded_gltf = gltf.loaded(&data); for mesh in loaded_gltf.meshes() { for primitive in mesh.primitives() { if let Some(iter) = primitive.indices_u32() { // Do something with the primitive data. let indices: Vec<u32> = iter.collect(); println!("{:?}", indices); } } }
Reexports
pub extern crate gltf_json as json; |
pub use self::animation::Animation; |
pub use self::accessor::Accessor; |
pub use self::buffer::Buffer; |
pub use self::camera::Camera; |
pub use self::gltf::Gltf; |
pub use self::image::Image; |
pub use self::material::Material; |
pub use self::mesh::Mesh; |
pub use self::mesh::Primitive; |
pub use self::scene::Node; |
pub use self::scene::Scene; |
pub use self::skin::Skin; |
pub use self::texture::Texture; |
Modules
accessor |
Contains |
animation |
Contains |
buffer |
Contains |
camera |
Contains |
gltf |
Contains |
image |
Contains |
material |
Contains |
mesh |
Contains |
root |
Contains |
scene |
Contains |
skin |
Contains |
texture |
Contains |
Structs
Loaded |
Wrapper type representing a |
Traits
Source |
Represents sources of buffer data. |