1use core::fmt;
4
5#[non_exhaustive]
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum MeshValidationError {
9 IncompleteTriangle { index_count: usize },
11 PositionIndexOutOfRange { index: u32, position_count: usize },
13 NormalCount { expected: usize, actual: usize },
15 NormalIndexCount { expected: usize, actual: usize },
17 NormalIndexOutOfRange { index: u32, normal_count: usize },
19 AttributeCount {
21 name: String,
23 expected: usize,
25 actual: usize,
27 },
28 AttributeZeroWidth {
30 name: String,
32 },
33 AttributeDuplicateName {
35 name: String,
37 },
38 AttributeRaggedValues {
40 name: String,
42 values: usize,
44 width: usize,
46 },
47 AttributeCornerCount {
49 name: String,
51 expected: usize,
53 actual: usize,
55 },
56 AttributeCornerIndexOutOfRange {
58 name: String,
60 index: u32,
62 value_count: usize,
64 },
65 AttributePartiallyMapped {
67 name: String,
69 triangle: usize,
71 },
72}
73
74impl fmt::Display for MeshValidationError {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 match self {
77 Self::IncompleteTriangle { index_count } => {
78 write!(f, "index count {index_count} is not divisible by three")
79 }
80 Self::PositionIndexOutOfRange {
81 index,
82 position_count,
83 } => write!(
84 f,
85 "position index {index} exceeds {position_count} positions"
86 ),
87 Self::NormalCount { expected, actual } => {
88 write!(f, "expected {expected} normals, found {actual}")
89 }
90 Self::NormalIndexCount { expected, actual } => {
91 write!(f, "expected {expected} normal indices, found {actual}")
92 }
93 Self::NormalIndexOutOfRange {
94 index,
95 normal_count,
96 } => write!(f, "normal index {index} exceeds {normal_count} normals"),
97 Self::AttributeCount {
98 name,
99 expected,
100 actual,
101 } => write!(
102 f,
103 "attribute channel {name} covers {actual} vertices, mesh has {expected}"
104 ),
105 Self::AttributeZeroWidth { name } => {
106 write!(f, "attribute channel {name} declares a zero tuple width")
107 }
108 Self::AttributeDuplicateName { name } => {
109 write!(f, "attribute channel name {name} is used more than once")
110 }
111 Self::AttributeRaggedValues {
112 name,
113 values,
114 width,
115 } => write!(
116 f,
117 "attribute channel {name} has {values} scalars, not a multiple of width {width}"
118 ),
119 Self::AttributeCornerCount {
120 name,
121 expected,
122 actual,
123 } => write!(
124 f,
125 "attribute channel {name} has {actual} corner indices, mesh has {expected} corners"
126 ),
127 Self::AttributeCornerIndexOutOfRange {
128 name,
129 index,
130 value_count,
131 } => write!(
132 f,
133 "attribute channel {name} corner index {index} exceeds {value_count} values"
134 ),
135 Self::AttributePartiallyMapped { name, triangle } => write!(
136 f,
137 "attribute channel {name} maps only some corners of triangle {triangle}"
138 ),
139 }
140 }
141}
142
143impl std::error::Error for MeshValidationError {}