Suppress the `clippy::type_complexity` lint (#8313)
# Objective
The clippy lint `type_complexity` is known not to play well with bevy.
It frequently triggers when writing complex queries, and taking the
lint's advice of using a type alias almost always just obfuscates the
code with no benefit. Because of this, this lint is currently ignored in
CI, but unfortunately it still shows up when viewing bevy code in an
IDE.
As someone who's made a fair amount of pull requests to this repo, I
will say that this issue has been a consistent thorn in my side. Since
bevy code is filled with spurious, ignorable warnings, it can be very
difficult to spot the *real* warnings that must be fixed -- most of the
time I just ignore all warnings, only to later find out that one of them
was real after I'm done when CI runs.
## Solution
Suppress this lint in all bevy crates. This was previously attempted in
#7050, but the review process ended up making it more complicated than
it needs to be and landed on a subpar solution.
The discussion in https://github.com/rust-lang/rust-clippy/pull/10571
explores some better long-term solutions to this problem. Since there is
no timeline on when these solutions may land, we should resolve this
issue in the meantime by locally suppressing these lints.
### Unresolved issues
Currently, these lints are not suppressed in our examples, since that
would require suppressing the lint in every single source file. They are
still ignored in CI.
2023-04-06 21:27:36 +00:00
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
|
2022-04-02 22:36:02 +00:00
|
|
|
#[cfg(feature = "bevy_animation")]
|
|
|
|
use bevy_animation::AnimationClip;
|
2021-12-14 03:58:23 +00:00
|
|
|
use bevy_utils::HashMap;
|
2020-12-31 20:57:15 +00:00
|
|
|
|
2020-05-15 23:55:44 +00:00
|
|
|
mod loader;
|
2023-04-24 14:20:13 +00:00
|
|
|
mod vertex_attributes;
|
2020-05-15 23:55:44 +00:00
|
|
|
pub use loader::*;
|
2020-04-19 17:08:47 +00:00
|
|
|
|
2020-07-17 01:47:51 +00:00
|
|
|
use bevy_app::prelude::*;
|
2020-12-31 20:57:15 +00:00
|
|
|
use bevy_asset::{AddAsset, Handle};
|
2022-04-07 21:30:52 +00:00
|
|
|
use bevy_ecs::{prelude::Component, reflect::ReflectComponent};
|
2021-12-14 03:58:23 +00:00
|
|
|
use bevy_pbr::StandardMaterial;
|
2023-06-05 20:31:20 +00:00
|
|
|
use bevy_reflect::{Reflect, TypePath, TypeUuid};
|
2023-04-24 14:20:13 +00:00
|
|
|
use bevy_render::{
|
|
|
|
mesh::{Mesh, MeshVertexAttribute},
|
|
|
|
renderer::RenderDevice,
|
|
|
|
texture::CompressedImageFormats,
|
|
|
|
};
|
2020-12-31 20:57:15 +00:00
|
|
|
use bevy_scene::Scene;
|
2020-04-19 17:08:47 +00:00
|
|
|
|
2021-12-14 03:58:23 +00:00
|
|
|
/// Adds support for glTF file loading to the app.
|
2020-05-15 23:55:44 +00:00
|
|
|
#[derive(Default)]
|
2023-04-24 14:20:13 +00:00
|
|
|
pub struct GltfPlugin {
|
|
|
|
custom_vertex_attributes: HashMap<String, MeshVertexAttribute>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GltfPlugin {
|
|
|
|
pub fn add_custom_vertex_attribute(
|
|
|
|
mut self,
|
|
|
|
name: &str,
|
|
|
|
attribute: MeshVertexAttribute,
|
|
|
|
) -> Self {
|
|
|
|
self.custom_vertex_attributes
|
|
|
|
.insert(name.to_string(), attribute);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
2020-04-20 02:29:33 +00:00
|
|
|
|
2020-08-08 03:22:17 +00:00
|
|
|
impl Plugin for GltfPlugin {
|
2021-07-27 20:21:06 +00:00
|
|
|
fn build(&self, app: &mut App) {
|
2023-04-24 14:20:13 +00:00
|
|
|
let supported_compressed_formats = match app.world.get_resource::<RenderDevice>() {
|
|
|
|
Some(render_device) => CompressedImageFormats::from_features(render_device.features()),
|
|
|
|
|
|
|
|
None => CompressedImageFormats::all(),
|
|
|
|
};
|
|
|
|
app.add_asset_loader::<GltfLoader>(GltfLoader {
|
|
|
|
supported_compressed_formats,
|
|
|
|
custom_vertex_attributes: self.custom_vertex_attributes.clone(),
|
|
|
|
})
|
|
|
|
.register_type::<GltfExtras>()
|
|
|
|
.add_asset::<Gltf>()
|
|
|
|
.add_asset::<GltfNode>()
|
|
|
|
.add_asset::<GltfPrimitive>()
|
|
|
|
.add_asset::<GltfMesh>();
|
2020-04-19 17:08:47 +00:00
|
|
|
}
|
2020-05-16 07:27:30 +00:00
|
|
|
}
|
2020-12-31 20:57:15 +00:00
|
|
|
|
2021-12-14 03:58:23 +00:00
|
|
|
/// Representation of a loaded glTF file.
|
2023-06-05 20:31:20 +00:00
|
|
|
#[derive(Debug, TypeUuid, TypePath)]
|
2020-12-31 20:57:15 +00:00
|
|
|
#[uuid = "5c7d5f8a-f7b0-4e45-a09e-406c0372fea2"]
|
|
|
|
pub struct Gltf {
|
|
|
|
pub scenes: Vec<Handle<Scene>>,
|
|
|
|
pub named_scenes: HashMap<String, Handle<Scene>>,
|
|
|
|
pub meshes: Vec<Handle<GltfMesh>>,
|
|
|
|
pub named_meshes: HashMap<String, Handle<GltfMesh>>,
|
|
|
|
pub materials: Vec<Handle<StandardMaterial>>,
|
|
|
|
pub named_materials: HashMap<String, Handle<StandardMaterial>>,
|
|
|
|
pub nodes: Vec<Handle<GltfNode>>,
|
|
|
|
pub named_nodes: HashMap<String, Handle<GltfNode>>,
|
|
|
|
pub default_scene: Option<Handle<Scene>>,
|
2022-04-02 22:36:02 +00:00
|
|
|
#[cfg(feature = "bevy_animation")]
|
|
|
|
pub animations: Vec<Handle<AnimationClip>>,
|
|
|
|
#[cfg(feature = "bevy_animation")]
|
|
|
|
pub named_animations: HashMap<String, Handle<AnimationClip>>,
|
2020-12-31 20:57:15 +00:00
|
|
|
}
|
|
|
|
|
2023-02-13 17:56:36 +00:00
|
|
|
/// A glTF node with all of its child nodes, its [`GltfMesh`],
|
|
|
|
/// [`Transform`](bevy_transform::prelude::Transform) and an optional [`GltfExtras`].
|
2023-06-05 20:31:20 +00:00
|
|
|
#[derive(Debug, Clone, TypeUuid, TypePath)]
|
2020-12-31 20:57:15 +00:00
|
|
|
#[uuid = "dad74750-1fd6-460f-ac51-0a7937563865"]
|
|
|
|
pub struct GltfNode {
|
|
|
|
pub children: Vec<GltfNode>,
|
|
|
|
pub mesh: Option<Handle<GltfMesh>>,
|
|
|
|
pub transform: bevy_transform::prelude::Transform,
|
2023-02-13 17:56:36 +00:00
|
|
|
pub extras: Option<GltfExtras>,
|
2020-12-31 20:57:15 +00:00
|
|
|
}
|
|
|
|
|
2023-02-13 17:56:36 +00:00
|
|
|
/// A glTF mesh, which may consist of multiple [`GltfPrimitives`](GltfPrimitive)
|
|
|
|
/// and an optional [`GltfExtras`].
|
2023-06-05 20:31:20 +00:00
|
|
|
#[derive(Debug, Clone, TypeUuid, TypePath)]
|
2020-12-31 20:57:15 +00:00
|
|
|
#[uuid = "8ceaec9a-926a-4f29-8ee3-578a69f42315"]
|
|
|
|
pub struct GltfMesh {
|
|
|
|
pub primitives: Vec<GltfPrimitive>,
|
2023-02-13 17:56:36 +00:00
|
|
|
pub extras: Option<GltfExtras>,
|
2020-12-31 20:57:15 +00:00
|
|
|
}
|
|
|
|
|
2023-02-13 17:56:36 +00:00
|
|
|
/// Part of a [`GltfMesh`] that consists of a [`Mesh`], an optional [`StandardMaterial`] and [`GltfExtras`].
|
2023-06-05 20:31:20 +00:00
|
|
|
#[derive(Debug, Clone, TypeUuid, TypePath)]
|
2020-12-31 20:57:15 +00:00
|
|
|
#[uuid = "cbfca302-82fd-41cb-af77-cab6b3d50af1"]
|
|
|
|
pub struct GltfPrimitive {
|
|
|
|
pub mesh: Handle<Mesh>,
|
|
|
|
pub material: Option<Handle<StandardMaterial>>,
|
2023-02-13 17:56:36 +00:00
|
|
|
pub extras: Option<GltfExtras>,
|
|
|
|
pub material_extras: Option<GltfExtras>,
|
2020-12-31 20:57:15 +00:00
|
|
|
}
|
2022-04-07 21:30:52 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, Reflect, Default, Component)]
|
|
|
|
#[reflect(Component)]
|
|
|
|
pub struct GltfExtras {
|
|
|
|
pub value: String,
|
|
|
|
}
|