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
|
||||
.get(name.as_str())
|
||||
.map(|attr| (attr.clone(), ConversionMode::Any)),
|
||||
.map(|attr| (*attr, ConversionMode::Any)),
|
||||
_ => None,
|
||||
} {
|
||||
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);
|
||||
}
|
||||
|
||||
if mesh.attributes().map(|(id, _)| id).ne([
|
||||
if mesh.attributes().map(|(attribute, _)| attribute.id).ne([
|
||||
Mesh::ATTRIBUTE_POSITION.id,
|
||||
Mesh::ATTRIBUTE_NORMAL.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.
|
||||
pub fn attributes(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (MeshVertexAttributeId, &VertexAttributeValues)> {
|
||||
self.attributes.iter().map(|(id, data)| (*id, &data.values))
|
||||
) -> impl Iterator<Item = (&MeshVertexAttribute, &VertexAttributeValues)> {
|
||||
self.attributes
|
||||
.values()
|
||||
.map(|data| (&data.attribute, &data.values))
|
||||
}
|
||||
|
||||
/// Returns an iterator that yields mutable references to the data of each vertex attribute.
|
||||
pub fn attributes_mut(
|
||||
&mut self,
|
||||
) -> impl Iterator<Item = (MeshVertexAttributeId, &mut VertexAttributeValues)> {
|
||||
) -> impl Iterator<Item = (&MeshVertexAttribute, &mut VertexAttributeValues)> {
|
||||
self.attributes
|
||||
.iter_mut()
|
||||
.map(|(id, data)| (*id, &mut data.values))
|
||||
.values_mut()
|
||||
.map(|data| (&data.attribute, &mut data.values))
|
||||
}
|
||||
|
||||
/// Sets the vertex indices of the mesh. They describe how triangles are constructed out of the
|
||||
@ -803,9 +805,9 @@ impl Mesh {
|
||||
.len();
|
||||
|
||||
// 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();
|
||||
if let Some(other_values) = other.attribute(id) {
|
||||
if let Some(other_values) = other.attribute(attribute.id) {
|
||||
match (values, other_values) {
|
||||
(Float32(vec1), Float32(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 {
|
||||
/// The friendly name of the vertex attribute
|
||||
pub name: &'static str,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user