Skip to content

Commit

Permalink
handle non-invertible matrix (may be caused by zero scale for instance)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Dec 6, 2024
1 parent a49cf46 commit 1ac4263
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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
};
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

0 comments on commit 1ac4263

Please sign in to comment.