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

Fix handling unnormalized axis for (Pose)RotationAxisAngle #8341

Merged
merged 2 commits into from
Dec 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ impl PoseRotationAxisAngle {
impl From<PoseRotationAxisAngle> for glam::Affine3A {
#[inline]
fn from(val: PoseRotationAxisAngle) -> Self {
Self::from_axis_angle(val.0.axis.into(), val.0.angle.radians())
if let Some(normalized) = glam::Vec3::from(val.0.axis).try_normalize() {
Self::from_axis_angle(normalized, val.0.angle.radians())
} else {
// If the axis is zero length, we can't normalize it, so we just use the identity rotation.
Self::IDENTITY
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ impl RotationAxisAngle {
impl From<RotationAxisAngle> for glam::Affine3A {
#[inline]
fn from(val: RotationAxisAngle) -> Self {
Self::from_axis_angle(val.0.axis.into(), val.0.angle.radians())
if let Some(normalized) = glam::Vec3::from(val.0.axis).try_normalize() {
Self::from_axis_angle(normalized, val.0.angle.radians())
} else {
// If the axis is zero length, we can't normalize it, so we just use the identity rotation.
Self::IDENTITY
}
}
}
9 changes: 8 additions & 1 deletion crates/viewer/re_renderer/src/renderer/mesh_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,15 @@ impl MeshDrawData {
count_with_outlines += instance.outline_mask_ids.is_some() as u32;

let world_from_mesh_mat3 = instance.world_from_mesh.matrix3;
// If the matrix is not invertible the draw result is likely invalid as well.
// However, at this point it's really hard to bail out!
// Also, by skipping drawing here, we'd make the result worse as there would be no mesh draw calls that could be debugged.
let world_from_mesh_normal =
instance.world_from_mesh.matrix3.inverse().transpose();
if instance.world_from_mesh.matrix3.determinant() != 0.0 {
instance.world_from_mesh.matrix3.inverse().transpose()
} else {
glam::Mat3A::ZERO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, you meant it to be zero and not identity?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. zero. Which is the most likely reason the determinant was zero to begin with 🤷

};
instance_buffer_staging.push(gpu_data::InstanceData {
world_from_mesh_row_0: world_from_mesh_mat3
.row(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,14 @@ fn query_and_resolve_tree_transform_at_entity(
if let Some(mat3x3) = result.component_instance::<TransformMat3x3>(0) {
transform *= glam::Affine3A::from(mat3x3);
}

if result.component_instance::<TransformRelation>(0) == Some(TransformRelation::ChildFromParent)
{
if transform.matrix3.determinant() != 0.0 {
// TODO(andreas): Should we warn? This might be intentionally caused by zero scale.
transform = transform.inverse();
}

transform = transform.inverse();
}

Expand Down
Loading