Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ gltf = { version = "1.4.0", default-features = false, features = [
"names",
"utils",
] }
thiserror = "1.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
base64 = "0.22.0"
percent-encoding = "2.1"
serde = { version = "1.0", features = ["derive"] }
Expand Down
54 changes: 30 additions & 24 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use bevy_utils::{
tracing::{error, info_span, warn},
HashMap, HashSet,
};
use derive_more::derive::{Display, Error, From};
use gltf::{
accessor::Iter,
image::Source,
Expand All @@ -59,61 +60,66 @@ use std::{
io::Error,
path::{Path, PathBuf},
};
use thiserror::Error;
#[cfg(feature = "bevy_animation")]
use {
bevy_animation::{prelude::*, AnimationTarget, AnimationTargetId},
smallvec::SmallVec,
};

/// An error that occurs when loading a glTF file.
#[derive(Error, Debug)]
#[derive(Error, Display, Debug, From)]
pub enum GltfError {
/// Unsupported primitive mode.
#[error("unsupported primitive mode")]
#[display("unsupported primitive mode")]
UnsupportedPrimitive {
/// The primitive mode.
mode: Mode,
},
/// Invalid glTF file.
#[error("invalid glTF file: {0}")]
Gltf(#[from] gltf::Error),
#[display("invalid glTF file: {_0}")]
Gltf(gltf::Error),
/// Binary blob is missing.
#[error("binary blob is missing")]
#[display("binary blob is missing")]
MissingBlob,
/// Decoding the base64 mesh data failed.
#[error("failed to decode base64 mesh data")]
Base64Decode(#[from] base64::DecodeError),
#[display("failed to decode base64 mesh data")]
Base64Decode(base64::DecodeError),
/// Unsupported buffer format.
#[error("unsupported buffer format")]
#[display("unsupported buffer format")]
BufferFormatUnsupported,
/// Invalid image mime type.
#[error("invalid image mime type: {0}")]
#[display("invalid image mime type: {_0}")]
#[error(ignore)]
#[from(ignore)]
InvalidImageMimeType(String),
/// Error when loading a texture. Might be due to a disabled image file format feature.
#[error("You may need to add the feature for the file format: {0}")]
ImageError(#[from] TextureError),
#[display("You may need to add the feature for the file format: {_0}")]
ImageError(TextureError),
/// Failed to read bytes from an asset path.
#[error("failed to read bytes from an asset path: {0}")]
ReadAssetBytesError(#[from] ReadAssetBytesError),
#[display("failed to read bytes from an asset path: {_0}")]
ReadAssetBytesError(ReadAssetBytesError),
/// Failed to load asset from an asset path.
#[error("failed to load asset from an asset path: {0}")]
AssetLoadError(#[from] AssetLoadError),
#[display("failed to load asset from an asset path: {_0}")]
AssetLoadError(AssetLoadError),
/// Missing sampler for an animation.
#[error("Missing sampler for animation {0}")]
#[display("Missing sampler for animation {_0}")]
#[error(ignore)]
#[from(ignore)]
MissingAnimationSampler(usize),
/// Failed to generate tangents.
#[error("failed to generate tangents: {0}")]
GenerateTangentsError(#[from] bevy_render::mesh::GenerateTangentsError),
#[display("failed to generate tangents: {_0}")]
GenerateTangentsError(bevy_render::mesh::GenerateTangentsError),
/// Failed to generate morph targets.
#[error("failed to generate morph targets: {0}")]
MorphTarget(#[from] bevy_render::mesh::morph::MorphBuildError),
#[display("failed to generate morph targets: {_0}")]
MorphTarget(bevy_render::mesh::morph::MorphBuildError),
/// Circular children in Nodes
#[error("GLTF model must be a tree, found cycle instead at node indices: {0:?}")]
#[display("GLTF model must be a tree, found cycle instead at node indices: {_0:?}")]
#[error(ignore)]
#[from(ignore)]
CircularChildren(String),
/// Failed to load a file.
#[error("failed to load file: {0}")]
Io(#[from] Error),
#[display("failed to load file: {_0}")]
Io(Error),
}

/// Loads glTF files with all of their data as their corresponding bevy representations.
Expand Down
19 changes: 11 additions & 8 deletions crates/bevy_gltf/src/vertex_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use bevy_render::{
render_resource::VertexFormat,
};
use bevy_utils::HashMap;
use derive_more::derive::{Display, Error};
use gltf::{
accessor::{DataType, Dimensions},
mesh::util::{ReadColors, ReadJoints, ReadTexCoords, ReadWeights},
};
use thiserror::Error;

/// Represents whether integer data requires normalization
#[derive(Copy, Clone)]
Expand All @@ -30,11 +30,11 @@ impl Normalization {
}

/// An error that occurs when accessing buffer data
#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
pub(crate) enum AccessFailed {
#[error("Malformed vertex attribute data")]
#[display("Malformed vertex attribute data")]
MalformedData,
#[error("Unsupported vertex attribute format")]
#[display("Unsupported vertex attribute format")]
UnsupportedFormat,
}

Expand Down Expand Up @@ -241,13 +241,16 @@ enum ConversionMode {
TexCoord,
}

#[derive(Error, Debug)]
#[derive(Error, Display, Debug)]
#[error(ignore)]
pub(crate) enum ConvertAttributeError {
#[error("Vertex attribute {0} has format {1:?} but expected {3:?} for target attribute {2}")]
#[display(
"Vertex attribute {_0} has format {_1:?} but expected {_3:?} for target attribute {_2}"
)]
WrongFormat(String, VertexFormat, String, VertexFormat),
#[error("{0} in accessor {1}")]
#[display("{0} in accessor {_1}")]
AccessFailed(AccessFailed, usize),
#[error("Unknown vertex attribute {0}")]
#[display("Unknown vertex attribute {_0}")]
UnknownName(String),
}

Expand Down
Loading