Skip to content

Commit 1ac4263

Browse files
committed
handle non-invertible matrix (may be caused by zero scale for instance)
1 parent a49cf46 commit 1ac4263

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

crates/viewer/re_renderer/src/renderer/mesh_renderer.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,15 @@ impl MeshDrawData {
220220
count_with_outlines += instance.outline_mask_ids.is_some() as u32;
221221

222222
let world_from_mesh_mat3 = instance.world_from_mesh.matrix3;
223+
// If the matrix is not invertible the draw result is likely invalid as well.
224+
// However, at this point it's really hard to bail out!
225+
// Also, by skipping drawing here, we'd make the result worse as there would be no mesh draw calls that could be debugged.
223226
let world_from_mesh_normal =
224-
instance.world_from_mesh.matrix3.inverse().transpose();
227+
if instance.world_from_mesh.matrix3.determinant() != 0.0 {
228+
instance.world_from_mesh.matrix3.inverse().transpose()
229+
} else {
230+
glam::Mat3A::ZERO
231+
};
225232
instance_buffer_staging.push(gpu_data::InstanceData {
226233
world_from_mesh_row_0: world_from_mesh_mat3
227234
.row(0)

crates/viewer/re_space_view_spatial/src/contexts/transform_context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,14 @@ fn query_and_resolve_tree_transform_at_entity(
555555
if let Some(mat3x3) = result.component_instance::<TransformMat3x3>(0) {
556556
transform *= glam::Affine3A::from(mat3x3);
557557
}
558+
558559
if result.component_instance::<TransformRelation>(0) == Some(TransformRelation::ChildFromParent)
559560
{
561+
if transform.matrix3.determinant() != 0.0 {
562+
// TODO(andreas): Should we warn? This might be intentionally caused by zero scale.
563+
transform = transform.inverse();
564+
}
565+
560566
transform = transform.inverse();
561567
}
562568

0 commit comments

Comments
 (0)