Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

animations: convert skinning weights from unorm8x4 to float32x4 #9338

Merged
merged 2 commits into from
Aug 16, 2023
Merged
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
21 changes: 19 additions & 2 deletions crates/bevy_gltf/src/vertex_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_render::{
use bevy_utils::HashMap;
use gltf::{
accessor::{DataType, Dimensions},
mesh::util::{ReadColors, ReadJoints, ReadTexCoords},
mesh::util::{ReadColors, ReadJoints, ReadTexCoords, ReadWeights},
};
use thiserror::Error;

Expand Down Expand Up @@ -206,6 +206,19 @@ impl<'a> VertexAttributeIter<'a> {
}
}

/// Materializes joint weight values, converting compatible formats to Float32x4
fn into_joint_weight_values(self) -> Result<Values, AccessFailed> {
match self {
VertexAttributeIter::U8x4(it, Normalization(true)) => {
Ok(Values::Float32x4(ReadWeights::U8(it).into_f32().collect()))
}
VertexAttributeIter::U16x4(it, Normalization(true)) => {
Ok(Values::Float32x4(ReadWeights::U16(it).into_f32().collect()))
}
s => s.into_any_values(),
}
}

/// Materializes texture coordinate values, converting compatible formats to Float32x2
fn into_tex_coord_values(self) -> Result<Values, AccessFailed> {
match self {
Expand All @@ -224,6 +237,7 @@ enum ConversionMode {
Any,
Rgba,
JointIndex,
JointWeight,
TexCoord,
}

Expand Down Expand Up @@ -252,7 +266,9 @@ pub(crate) fn convert_attribute(
gltf::Semantic::Joints(0) => {
Some((Mesh::ATTRIBUTE_JOINT_INDEX, ConversionMode::JointIndex))
}
gltf::Semantic::Weights(0) => Some((Mesh::ATTRIBUTE_JOINT_WEIGHT, ConversionMode::Any)),
gltf::Semantic::Weights(0) => {
Some((Mesh::ATTRIBUTE_JOINT_WEIGHT, ConversionMode::JointWeight))
}
gltf::Semantic::Extras(name) => custom_vertex_attributes
.get(name)
.map(|attr| (attr.clone(), ConversionMode::Any)),
Expand All @@ -264,6 +280,7 @@ pub(crate) fn convert_attribute(
ConversionMode::Rgba => iter.into_rgba_values(),
ConversionMode::TexCoord => iter.into_tex_coord_values(),
ConversionMode::JointIndex => iter.into_joint_index_values(),
ConversionMode::JointWeight => iter.into_joint_weight_values(),
});
match converted_values {
Ok(values) => {
Expand Down