Changed Mesh::attributes* functions to return MeshVertexAttribute (#14394)
# Objective Fixes #14365 ## Migration Guide - When using the iterator returned by `Mesh::attributes` or `Mesh::attributes_mut` the first value of the tuple is not the `MeshVertexAttribute` instead of `MeshVertexAttributeId`. To access the `MeshVertexAttributeId` use the `MeshVertexAttribute.id` field. Signed-off-by: Sarthak Singh <sarthak.singh99@gmail.com>
This commit is contained in:
parent
47c4e3084a
commit
2c4ef37b76
@ -272,7 +272,7 @@ pub(crate) fn convert_attribute(
|
|||||||
}
|
}
|
||||||
gltf::Semantic::Extras(name) => custom_vertex_attributes
|
gltf::Semantic::Extras(name) => custom_vertex_attributes
|
||||||
.get(name.as_str())
|
.get(name.as_str())
|
||||||
.map(|attr| (attr.clone(), ConversionMode::Any)),
|
.map(|attr| (*attr, ConversionMode::Any)),
|
||||||
_ => None,
|
_ => None,
|
||||||
} {
|
} {
|
||||||
let raw_iter = VertexAttributeIter::from_accessor(accessor.clone(), buffer_data);
|
let raw_iter = VertexAttributeIter::from_accessor(accessor.clone(), buffer_data);
|
||||||
|
|||||||
@ -160,7 +160,7 @@ fn validate_input_mesh(mesh: &Mesh) -> Result<Cow<'_, [u32]>, MeshToMeshletMeshC
|
|||||||
return Err(MeshToMeshletMeshConversionError::WrongMeshPrimitiveTopology);
|
return Err(MeshToMeshletMeshConversionError::WrongMeshPrimitiveTopology);
|
||||||
}
|
}
|
||||||
|
|
||||||
if mesh.attributes().map(|(id, _)| id).ne([
|
if mesh.attributes().map(|(attribute, _)| attribute.id).ne([
|
||||||
Mesh::ATTRIBUTE_POSITION.id,
|
Mesh::ATTRIBUTE_POSITION.id,
|
||||||
Mesh::ATTRIBUTE_NORMAL.id,
|
Mesh::ATTRIBUTE_NORMAL.id,
|
||||||
Mesh::ATTRIBUTE_UV_0.id,
|
Mesh::ATTRIBUTE_UV_0.id,
|
||||||
|
|||||||
@ -314,17 +314,19 @@ impl Mesh {
|
|||||||
/// Returns an iterator that yields references to the data of each vertex attribute.
|
/// Returns an iterator that yields references to the data of each vertex attribute.
|
||||||
pub fn attributes(
|
pub fn attributes(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<Item = (MeshVertexAttributeId, &VertexAttributeValues)> {
|
) -> impl Iterator<Item = (&MeshVertexAttribute, &VertexAttributeValues)> {
|
||||||
self.attributes.iter().map(|(id, data)| (*id, &data.values))
|
self.attributes
|
||||||
|
.values()
|
||||||
|
.map(|data| (&data.attribute, &data.values))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator that yields mutable references to the data of each vertex attribute.
|
/// Returns an iterator that yields mutable references to the data of each vertex attribute.
|
||||||
pub fn attributes_mut(
|
pub fn attributes_mut(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> impl Iterator<Item = (MeshVertexAttributeId, &mut VertexAttributeValues)> {
|
) -> impl Iterator<Item = (&MeshVertexAttribute, &mut VertexAttributeValues)> {
|
||||||
self.attributes
|
self.attributes
|
||||||
.iter_mut()
|
.values_mut()
|
||||||
.map(|(id, data)| (*id, &mut data.values))
|
.map(|data| (&data.attribute, &mut data.values))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the vertex indices of the mesh. They describe how triangles are constructed out of the
|
/// Sets the vertex indices of the mesh. They describe how triangles are constructed out of the
|
||||||
@ -803,9 +805,9 @@ impl Mesh {
|
|||||||
.len();
|
.len();
|
||||||
|
|
||||||
// Extend attributes of `self` with attributes of `other`.
|
// Extend attributes of `self` with attributes of `other`.
|
||||||
for (id, values) in self.attributes_mut() {
|
for (attribute, values) in self.attributes_mut() {
|
||||||
let enum_variant_name = values.enum_variant_name();
|
let enum_variant_name = values.enum_variant_name();
|
||||||
if let Some(other_values) = other.attribute(id) {
|
if let Some(other_values) = other.attribute(attribute.id) {
|
||||||
match (values, other_values) {
|
match (values, other_values) {
|
||||||
(Float32(vec1), Float32(vec2)) => vec1.extend(vec2),
|
(Float32(vec1), Float32(vec2)) => vec1.extend(vec2),
|
||||||
(Sint32(vec1), Sint32(vec2)) => vec1.extend(vec2),
|
(Sint32(vec1), Sint32(vec2)) => vec1.extend(vec2),
|
||||||
@ -1280,7 +1282,7 @@ impl core::ops::Mul<Mesh> for Transform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct MeshVertexAttribute {
|
pub struct MeshVertexAttribute {
|
||||||
/// The friendly name of the vertex attribute
|
/// The friendly name of the vertex attribute
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user