Expand description
Plugin providing an AssetLoader
and type definitions
for loading glTF 2.0 (a standard 3D scene definition format) files in Bevy.
The glTF 2.0 specification defines the format of the glTF files.
§Quick Start
Here’s how to spawn a simple glTF scene
fn spawn_gltf(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn((
// This is equivalent to "models/FlightHelmet/FlightHelmet.gltf#Scene0"
// The `#Scene0` label here is very important because it tells bevy to load the first scene in the glTF file.
// If this isn't specified bevy doesn't know which part of the glTF file to load.
SceneRoot(asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/FlightHelmet/FlightHelmet.gltf"))),
// You can use the transform to give it a position
Transform::from_xyz(2.0, 0.0, -5.0),
));
}
§Loading parts of a glTF asset
§Using Gltf
If you want to access part of the asset, you can load the entire Gltf
using the AssetServer
.
Once the Handle<Gltf>
is loaded you can then use it to access named parts of it.
// Holds the scene handle
#[derive(Resource)]
struct HelmetScene(Handle<Gltf>);
fn load_gltf(mut commands: Commands, asset_server: Res<AssetServer>) {
let gltf = asset_server.load("models/FlightHelmet/FlightHelmet.gltf");
commands.insert_resource(HelmetScene(gltf));
}
fn spawn_gltf_objects(
mut commands: Commands,
helmet_scene: Res<HelmetScene>,
gltf_assets: Res<Assets<Gltf>>,
mut loaded: Local<bool>,
) {
// Only do this once
if *loaded {
return;
}
// Wait until the scene is loaded
let Some(gltf) = gltf_assets.get(&helmet_scene.0) else {
return;
};
*loaded = true;
// Spawns the first scene in the file
commands.spawn(SceneRoot(gltf.scenes[0].clone()));
// Spawns the scene named "Lenses_low"
commands.spawn((
SceneRoot(gltf.named_scenes["Lenses_low"].clone()),
Transform::from_xyz(1.0, 2.0, 3.0),
));
}
§Asset Labels
The glTF loader let’s you specify labels that let you target specific parts of the glTF.
Be careful when using this feature, if you misspell a label it will simply ignore it without warning.
You can use GltfAssetLabel
to ensure you are using the correct label.
Modules§
- prelude
- The glTF prelude.
Structs§
- Gltf
- Representation of a loaded glTF file.
- Gltf
Extras - Additional untyped data that can be present on most glTF types at the primitive level.
- Gltf
Loader - Loads glTF files with all of their data as their corresponding bevy representations.
- Gltf
Loader Settings - Specifies optional settings for processing gltfs at load time. By default, all recognized contents of the gltf will be loaded.
- Gltf
Material Extras - Additional untyped data that can be present on most glTF types at the material level.
- Gltf
Material Name - The material name of a glTF primitive.
- Gltf
Mesh - A glTF mesh, which may consist of multiple
GltfPrimitives
and an optionalGltfExtras
. - Gltf
Mesh Extras - Additional untyped data that can be present on most glTF types at the mesh level.
- Gltf
Node - A glTF node with all of its child nodes, its
GltfMesh
,Transform
, its optionalGltfSkin
and an optionalGltfExtras
. - Gltf
Plugin - Adds support for glTF file loading to the app.
- Gltf
Primitive - Part of a
GltfMesh
that consists of aMesh
, an optional [G::Material
] andGltfExtras
. - Gltf
Scene Extras - Additional untyped data that can be present on most glTF types at the scene level.
- Gltf
Skin - A glTF skin with all of its joint nodes,
SkinnedMeshInversiveBindposes
and an optionalGltfExtras
. - Gltf
Trait Default - Gltf
Trait Entity - Struct to simplify parameters of the GltfTrait light parent method
- Gltf
Trait Light - Struct to simplify parameters of GltfTraits light methods
- Gltf
Trait Material - Struct to simplify parameters of the GltfTrait light parent method
- Gltf
Trait Mesh - Struct to simplify parameters of the GltfTrait light parent method
- Gltf
Trait Parent - Struct to simplify parameters of the GltfTrait light parent method
Enums§
- Gltf
Asset Label - Labels that can be used to load part of a glTF
- Gltf
Error - An error that occurs when loading a glTF file.