|
| 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. |
1 | 5 | #![allow(clippy::type_complexity)] |
| 6 | +#![warn(missing_docs)] |
2 | 7 |
|
3 | 8 | #[cfg(feature = "bevy_animation")] |
4 | 9 | use bevy_animation::AnimationClip; |
@@ -27,6 +32,11 @@ pub struct GltfPlugin { |
27 | 32 | } |
28 | 33 |
|
29 | 34 | 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. |
30 | 40 | pub fn add_custom_vertex_attribute( |
31 | 41 | mut self, |
32 | 42 | name: &str, |
@@ -64,50 +74,81 @@ impl Plugin for GltfPlugin { |
64 | 74 | /// Representation of a loaded glTF file. |
65 | 75 | #[derive(Asset, Debug, TypePath)] |
66 | 76 | pub struct Gltf { |
| 77 | + /// All scenes loaded from the glTF file. |
67 | 78 | pub scenes: Vec<Handle<Scene>>, |
| 79 | + /// Named scenes loaded from the glTF file. |
68 | 80 | pub named_scenes: HashMap<String, Handle<Scene>>, |
| 81 | + /// All meshes loaded from the glTF file. |
69 | 82 | pub meshes: Vec<Handle<GltfMesh>>, |
| 83 | + /// Named meshes loaded from the glTF file. |
70 | 84 | pub named_meshes: HashMap<String, Handle<GltfMesh>>, |
| 85 | + /// All materials loaded from the glTF file. |
71 | 86 | pub materials: Vec<Handle<StandardMaterial>>, |
| 87 | + /// Named materials loaded from the glTF file. |
72 | 88 | pub named_materials: HashMap<String, Handle<StandardMaterial>>, |
| 89 | + /// All nodes loaded from the glTF file. |
73 | 90 | pub nodes: Vec<Handle<GltfNode>>, |
| 91 | + /// Named nodes loaded from the glTF file. |
74 | 92 | pub named_nodes: HashMap<String, Handle<GltfNode>>, |
| 93 | + /// Default scene to be displayed. |
75 | 94 | pub default_scene: Option<Handle<Scene>>, |
| 95 | + /// All animations loaded from the glTF file. |
76 | 96 | #[cfg(feature = "bevy_animation")] |
77 | 97 | pub animations: Vec<Handle<AnimationClip>>, |
| 98 | + /// Named animations loaded from the glTF file. |
78 | 99 | #[cfg(feature = "bevy_animation")] |
79 | 100 | pub named_animations: HashMap<String, Handle<AnimationClip>>, |
80 | 101 | } |
81 | 102 |
|
82 | 103 | /// A glTF node with all of its child nodes, its [`GltfMesh`], |
83 | 104 | /// [`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). |
84 | 107 | #[derive(Asset, Debug, Clone, TypePath)] |
85 | 108 | pub struct GltfNode { |
| 109 | + /// Direct children of the node. |
86 | 110 | pub children: Vec<GltfNode>, |
| 111 | + /// Mesh of the node. |
87 | 112 | pub mesh: Option<Handle<GltfMesh>>, |
| 113 | + /// Local transform. |
88 | 114 | pub transform: bevy_transform::prelude::Transform, |
| 115 | + /// Additional data. |
89 | 116 | pub extras: Option<GltfExtras>, |
90 | 117 | } |
91 | 118 |
|
92 | 119 | /// A glTF mesh, which may consist of multiple [`GltfPrimitives`](GltfPrimitive) |
93 | 120 | /// 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). |
94 | 123 | #[derive(Asset, Debug, Clone, TypePath)] |
95 | 124 | pub struct GltfMesh { |
| 125 | + /// Primitives of the glTF mesh. |
96 | 126 | pub primitives: Vec<GltfPrimitive>, |
| 127 | + /// Additional data. |
97 | 128 | pub extras: Option<GltfExtras>, |
98 | 129 | } |
99 | 130 |
|
100 | 131 | /// 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). |
101 | 134 | #[derive(Asset, Debug, Clone, TypePath)] |
102 | 135 | pub struct GltfPrimitive { |
| 136 | + /// Topology to be rendered. |
103 | 137 | pub mesh: Handle<Mesh>, |
| 138 | + /// Material to apply to the `mesh`. |
104 | 139 | pub material: Option<Handle<StandardMaterial>>, |
| 140 | + /// Additional data. |
105 | 141 | pub extras: Option<GltfExtras>, |
| 142 | + /// Additional data of the `material`. |
106 | 143 | pub material_extras: Option<GltfExtras>, |
107 | 144 | } |
108 | 145 |
|
| 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). |
109 | 149 | #[derive(Clone, Debug, Reflect, Default, Component)] |
110 | 150 | #[reflect(Component)] |
111 | 151 | pub struct GltfExtras { |
| 152 | + /// Content of the extra data. |
112 | 153 | pub value: String, |
113 | 154 | } |
0 commit comments