Skip to content

Commit

Permalink
Remove thiserror from bevy_mesh (#15768)
Browse files Browse the repository at this point in the history
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_mesh`
  • Loading branch information
bushrat011899 authored Oct 9, 2024
1 parent 1f4adec commit 80fe269
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
6 changes: 5 additions & 1 deletion crates/bevy_mesh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ bytemuck = { version = "1.5" }
wgpu = { version = "22", default-features = false }
serde = { version = "1", features = ["derive"] }
hexasphere = "15.0"
thiserror = "1.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }

[lints]
workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_mesh/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

use super::VertexAttributeValues;
use bevy_math::{IVec2, IVec3, IVec4, UVec2, UVec3, UVec4, Vec2, Vec3, Vec3A, Vec4};
use thiserror::Error;
use derive_more::derive::{Display, Error};

#[derive(Debug, Clone, Error)]
#[error("cannot convert VertexAttributeValues::{variant} to {into}")]
#[derive(Debug, Clone, Error, Display)]
#[display("cannot convert VertexAttributeValues::{variant} to {into}")]
pub struct FromVertexAttributeError {
from: VertexAttributeValues,
variant: &'static str,
Expand Down
20 changes: 10 additions & 10 deletions crates/bevy_mesh/src/index.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy_reflect::Reflect;
use core::iter::FusedIterator;
use thiserror::Error;
use derive_more::derive::{Display, Error};
use wgpu::IndexFormat;

/// A disjunction of four iterators. This is necessary to have a well-formed type for the output
Expand Down Expand Up @@ -33,35 +33,35 @@ where
}

/// An error that occurred while trying to invert the winding of a [`Mesh`](super::Mesh).
#[derive(Debug, Error)]
#[derive(Debug, Error, Display)]
pub enum MeshWindingInvertError {
/// This error occurs when you try to invert the winding for a mesh with [`PrimitiveTopology::PointList`](super::PrimitiveTopology::PointList).
#[error("Mesh winding invertation does not work for primitive topology `PointList`")]
#[display("Mesh winding invertation does not work for primitive topology `PointList`")]
WrongTopology,

/// This error occurs when you try to invert the winding for a mesh with
/// * [`PrimitiveTopology::TriangleList`](super::PrimitiveTopology::TriangleList), but the indices are not in chunks of 3.
/// * [`PrimitiveTopology::LineList`](super::PrimitiveTopology::LineList), but the indices are not in chunks of 2.
#[error("Indices weren't in chunks according to topology")]
#[display("Indices weren't in chunks according to topology")]
AbruptIndicesEnd,
}

/// An error that occurred while trying to extract a collection of triangles from a [`Mesh`](super::Mesh).
#[derive(Debug, Error)]
#[derive(Debug, Error, Display)]
pub enum MeshTrianglesError {
#[error("Source mesh does not have primitive topology TriangleList or TriangleStrip")]
#[display("Source mesh does not have primitive topology TriangleList or TriangleStrip")]
WrongTopology,

#[error("Source mesh lacks position data")]
#[display("Source mesh lacks position data")]
MissingPositions,

#[error("Source mesh position data is not Float32x3")]
#[display("Source mesh position data is not Float32x3")]
PositionsFormat,

#[error("Source mesh lacks face index data")]
#[display("Source mesh lacks face index data")]
MissingIndices,

#[error("Face index data references vertices that do not exist")]
#[display("Face index data references vertices that do not exist")]
BadIndices,
}

Expand Down
17 changes: 10 additions & 7 deletions crates/bevy_mesh/src/mikktspace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Indices, Mesh, VertexAttributeValues};
use bevy_math::Vec3;
use thiserror::Error;
use derive_more::derive::{Display, Error};
use wgpu::{PrimitiveTopology, VertexFormat};

struct MikktspaceGeometryHelper<'a> {
Expand Down Expand Up @@ -53,18 +53,21 @@ impl bevy_mikktspace::Geometry for MikktspaceGeometryHelper<'_> {
}
}

#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
/// Failed to generate tangents for the mesh.
pub enum GenerateTangentsError {
#[error("cannot generate tangents for {0:?}")]
#[display("cannot generate tangents for {_0:?}")]
#[error(ignore)]
UnsupportedTopology(PrimitiveTopology),
#[error("missing indices")]
#[display("missing indices")]
MissingIndices,
#[error("missing vertex attributes '{0}'")]
#[display("missing vertex attributes '{_0}'")]
#[error(ignore)]
MissingVertexAttribute(&'static str),
#[error("the '{0}' vertex attribute should have {1:?} format")]
#[display("the '{_0}' vertex attribute should have {_1:?} format")]
#[error(ignore)]
InvalidVertexAttributeFormat(&'static str, VertexFormat),
#[error("mesh not suitable for tangent generation")]
#[display("mesh not suitable for tangent generation")]
MikktspaceError,
}

Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_mesh/src/morph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_math::Vec3;
use bevy_reflect::prelude::*;
use bytemuck::{Pod, Zeroable};
use core::iter;
use thiserror::Error;
use derive_more::derive::{Display, Error};
use wgpu::{Extent3d, TextureDimension, TextureFormat};

const MAX_TEXTURE_WIDTH: u32 = 2048;
Expand All @@ -17,9 +17,9 @@ const MAX_COMPONENTS: u32 = MAX_TEXTURE_WIDTH * MAX_TEXTURE_WIDTH;
/// Max target count available for [morph targets](MorphWeights).
pub const MAX_MORPH_WEIGHTS: usize = 64;

#[derive(Error, Clone, Debug)]
#[derive(Error, Display, Clone, Debug)]
pub enum MorphBuildError {
#[error(
#[display(
"Too many vertex×components in morph target, max is {MAX_COMPONENTS}, \
got {vertex_count}×{component_count} = {}",
*vertex_count * *component_count as usize
Expand All @@ -28,7 +28,7 @@ pub enum MorphBuildError {
vertex_count: usize,
component_count: u32,
},
#[error(
#[display(
"Bevy only supports up to {} morph targets (individual poses), tried to \
create a model with {target_count} morph targets",
MAX_MORPH_WEIGHTS
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_mesh/src/primitives/dim3/sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use crate::{Indices, Mesh, MeshBuilder, Meshable};
use bevy_asset::RenderAssetUsages;
use bevy_math::{ops, primitives::Sphere};
use core::f32::consts::PI;
use derive_more::derive::{Display, Error};
use hexasphere::shapes::IcoSphere;
use thiserror::Error;
use wgpu::PrimitiveTopology;

/// An error when creating an icosphere [`Mesh`] from a [`SphereMeshBuilder`].
#[derive(Clone, Copy, Debug, Error)]
#[derive(Clone, Copy, Debug, Error, Display)]
pub enum IcosphereError {
/// The icosphere has too many vertices.
#[error("Cannot create an icosphere of {subdivisions} subdivisions due to there being too many vertices being generated: {number_of_resulting_points}. (Limited to 65535 vertices or 79 subdivisions)")]
#[display("Cannot create an icosphere of {subdivisions} subdivisions due to there being too many vertices being generated: {number_of_resulting_points}. (Limited to 65535 vertices or 79 subdivisions)")]
TooManyVertices {
/// The number of subdivisions used. 79 is the largest allowed value for a mesh to be generated.
subdivisions: u32,
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_mesh/src/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy_math::Vec3;
use bevy_utils::HashSet;
use bytemuck::cast_slice;
use core::hash::{Hash, Hasher};
use thiserror::Error;
use derive_more::derive::{Display, Error};
use wgpu::{BufferAddress, VertexAttribute, VertexFormat, VertexStepMode};

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -108,8 +108,8 @@ impl MeshVertexBufferLayout {
}
}

#[derive(Error, Debug)]
#[error("Mesh is missing requested attribute: {name} ({id:?}, pipeline type: {pipeline_type:?})")]
#[derive(Error, Display, Debug)]
#[display("Mesh is missing requested attribute: {name} ({id:?}, pipeline type: {pipeline_type:?})")]
pub struct MissingVertexAttributeError {
pub pipeline_type: Option<&'static str>,
id: MeshVertexAttributeId,
Expand Down

0 comments on commit 80fe269

Please sign in to comment.