Skip to content

Commit 375af64

Browse files
authored
Finish documenting bevy_gltf (#9998)
# Objective - Finish documenting `bevy_gltf`. ## Solution - Document the remaining items, add links to the glTF spec where relevant. Add the `warn(missing_doc)` attribute.
1 parent 4eb9b9f commit 375af64

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

crates/bevy_gltf/src/lib.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
//! Plugin providing an [`AssetLoader`](bevy_asset::AssetLoader) and type definitions
2+
//! for loading glTF 2.0 (a standard 3D scene definition format) files in Bevy.
3+
//!
4+
//! The [glTF 2.0 specification](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html) defines the format of the glTF files.
15
#![allow(clippy::type_complexity)]
6+
#![warn(missing_docs)]
27

38
#[cfg(feature = "bevy_animation")]
49
use bevy_animation::AnimationClip;
@@ -27,6 +32,11 @@ pub struct GltfPlugin {
2732
}
2833

2934
impl GltfPlugin {
35+
/// Register a custom vertex attribute so that it is recognized when loading a glTF file with the [`GltfLoader`].
36+
///
37+
/// `name` must be the attribute name as found in the glTF data, which must start with an underscore.
38+
/// See [this section of the glTF specification](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
39+
/// for additional details on custom attributes.
3040
pub fn add_custom_vertex_attribute(
3141
mut self,
3242
name: &str,
@@ -64,50 +74,81 @@ impl Plugin for GltfPlugin {
6474
/// Representation of a loaded glTF file.
6575
#[derive(Asset, Debug, TypePath)]
6676
pub struct Gltf {
77+
/// All scenes loaded from the glTF file.
6778
pub scenes: Vec<Handle<Scene>>,
79+
/// Named scenes loaded from the glTF file.
6880
pub named_scenes: HashMap<String, Handle<Scene>>,
81+
/// All meshes loaded from the glTF file.
6982
pub meshes: Vec<Handle<GltfMesh>>,
83+
/// Named meshes loaded from the glTF file.
7084
pub named_meshes: HashMap<String, Handle<GltfMesh>>,
85+
/// All materials loaded from the glTF file.
7186
pub materials: Vec<Handle<StandardMaterial>>,
87+
/// Named materials loaded from the glTF file.
7288
pub named_materials: HashMap<String, Handle<StandardMaterial>>,
89+
/// All nodes loaded from the glTF file.
7390
pub nodes: Vec<Handle<GltfNode>>,
91+
/// Named nodes loaded from the glTF file.
7492
pub named_nodes: HashMap<String, Handle<GltfNode>>,
93+
/// Default scene to be displayed.
7594
pub default_scene: Option<Handle<Scene>>,
95+
/// All animations loaded from the glTF file.
7696
#[cfg(feature = "bevy_animation")]
7797
pub animations: Vec<Handle<AnimationClip>>,
98+
/// Named animations loaded from the glTF file.
7899
#[cfg(feature = "bevy_animation")]
79100
pub named_animations: HashMap<String, Handle<AnimationClip>>,
80101
}
81102

82103
/// A glTF node with all of its child nodes, its [`GltfMesh`],
83104
/// [`Transform`](bevy_transform::prelude::Transform) and an optional [`GltfExtras`].
105+
///
106+
/// See [the relevant glTF specification section](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-node).
84107
#[derive(Asset, Debug, Clone, TypePath)]
85108
pub struct GltfNode {
109+
/// Direct children of the node.
86110
pub children: Vec<GltfNode>,
111+
/// Mesh of the node.
87112
pub mesh: Option<Handle<GltfMesh>>,
113+
/// Local transform.
88114
pub transform: bevy_transform::prelude::Transform,
115+
/// Additional data.
89116
pub extras: Option<GltfExtras>,
90117
}
91118

92119
/// A glTF mesh, which may consist of multiple [`GltfPrimitives`](GltfPrimitive)
93120
/// and an optional [`GltfExtras`].
121+
///
122+
/// See [the relevant glTF specification section](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-mesh).
94123
#[derive(Asset, Debug, Clone, TypePath)]
95124
pub struct GltfMesh {
125+
/// Primitives of the glTF mesh.
96126
pub primitives: Vec<GltfPrimitive>,
127+
/// Additional data.
97128
pub extras: Option<GltfExtras>,
98129
}
99130

100131
/// Part of a [`GltfMesh`] that consists of a [`Mesh`], an optional [`StandardMaterial`] and [`GltfExtras`].
132+
///
133+
/// See [the relevant glTF specification section](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-mesh-primitive).
101134
#[derive(Asset, Debug, Clone, TypePath)]
102135
pub struct GltfPrimitive {
136+
/// Topology to be rendered.
103137
pub mesh: Handle<Mesh>,
138+
/// Material to apply to the `mesh`.
104139
pub material: Option<Handle<StandardMaterial>>,
140+
/// Additional data.
105141
pub extras: Option<GltfExtras>,
142+
/// Additional data of the `material`.
106143
pub material_extras: Option<GltfExtras>,
107144
}
108145

146+
/// Additional untyped data that can be present on most glTF types.
147+
///
148+
/// See [the relevant glTF specification section](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-extras).
109149
#[derive(Clone, Debug, Reflect, Default, Component)]
110150
#[reflect(Component)]
111151
pub struct GltfExtras {
152+
/// Content of the extra data.
112153
pub value: String,
113154
}

crates/bevy_gltf/src/loader.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,56 @@ use thiserror::Error;
4949
/// An error that occurs when loading a glTF file.
5050
#[derive(Error, Debug)]
5151
pub enum GltfError {
52+
/// Unsupported primitive mode.
5253
#[error("unsupported primitive mode")]
53-
UnsupportedPrimitive { mode: Mode },
54+
UnsupportedPrimitive {
55+
/// The primitive mode.
56+
mode: Mode,
57+
},
58+
/// Invalid glTF file.
5459
#[error("invalid glTF file: {0}")]
5560
Gltf(#[from] gltf::Error),
61+
/// Binary blob is missing.
5662
#[error("binary blob is missing")]
5763
MissingBlob,
64+
/// Decoding the base64 mesh data failed.
5865
#[error("failed to decode base64 mesh data")]
5966
Base64Decode(#[from] base64::DecodeError),
67+
/// Unsupported buffer format.
6068
#[error("unsupported buffer format")]
6169
BufferFormatUnsupported,
70+
/// Invalid image mime type.
6271
#[error("invalid image mime type: {0}")]
6372
InvalidImageMimeType(String),
73+
/// Error when loading a texture. Might be due to a disabled image file format feature.
6474
#[error("You may need to add the feature for the file format: {0}")]
6575
ImageError(#[from] TextureError),
76+
/// Failed to read bytes from an asset path.
6677
#[error("failed to read bytes from an asset path: {0}")]
6778
ReadAssetBytesError(#[from] ReadAssetBytesError),
79+
/// Failed to load asset from an asset path.
6880
#[error("failed to load asset from an asset path: {0}")]
6981
AssetLoadError(#[from] AssetLoadError),
82+
/// Missing sampler for an animation.
7083
#[error("Missing sampler for animation {0}")]
7184
MissingAnimationSampler(usize),
85+
/// Failed to generate tangents.
7286
#[error("failed to generate tangents: {0}")]
7387
GenerateTangentsError(#[from] bevy_render::mesh::GenerateTangentsError),
88+
/// Failed to generate morph targets.
7489
#[error("failed to generate morph targets: {0}")]
7590
MorphTarget(#[from] bevy_render::mesh::morph::MorphBuildError),
7691
}
7792

7893
/// Loads glTF files with all of their data as their corresponding bevy representations.
7994
pub struct GltfLoader {
95+
/// List of compressed image formats handled by the loader.
8096
pub supported_compressed_formats: CompressedImageFormats,
97+
/// Custom vertex attributes that will be recognized when loading a glTF file.
98+
///
99+
/// Keys must be the attribute names as found in the glTF data, which must start with an underscore.
100+
/// See [this section of the glTF specification](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
101+
/// for additional details on custom attributes.
81102
pub custom_vertex_attributes: HashMap<String, MeshVertexAttribute>,
82103
}
83104

0 commit comments

Comments
 (0)