Skip to content

Commit

Permalink
warn for non-mono transform lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Jan 15, 2025
1 parent bbf8290 commit 0d499f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions crates/store/re_chunk/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl UnitChunkShared {

/// Returns the raw data for the specified component, assuming a mono-batch.
///
/// Returns an error if the underlying batch is not of unit length.
/// Returns none if the underlying batch is not of unit length.
#[inline]
pub fn component_mono_raw(
&self,
Expand All @@ -369,7 +369,7 @@ impl UnitChunkShared {

/// Returns the deserialized data for the specified component, assuming a mono-batch.
///
/// Returns an error if the data cannot be deserialized, or if the underlying batch is not of unit length.
/// Returns none if the data cannot be deserialized, or if the underlying batch is not of unit length.
#[inline]
pub fn component_mono<C: Component>(&self) -> Option<ChunkResult<C>> {
let res = self.component_mono_raw(&C::name())?;
Expand Down
4 changes: 2 additions & 2 deletions crates/store/re_query/src/latest_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,15 +508,15 @@ impl LatestAtResults {

/// Returns the deserialized data for the specified component, assuming a mono-batch.
///
/// Returns an error if the data cannot be deserialized, or if the underlying batch is not of unit length.
/// Logs an error if the data cannot be deserialized, or if the underlying batch is not of unit length.
#[inline]
pub fn component_mono<C: Component>(&self) -> Option<C> {
self.component_mono_with_log_level(re_log::Level::Error)
}

/// Returns the deserialized data for the specified component, assuming a mono-batch.
///
/// Returns an error if the data cannot be deserialized, or if the underlying batch is not of unit length.
/// Returns none if the data cannot be deserialized, or if the underlying batch is not of unit length.
#[inline]
pub fn component_mono_quiet<C: Component>(&self) -> Option<C> {
self.components
Expand Down
29 changes: 21 additions & 8 deletions crates/viewer/re_view_spatial/src/transform_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,46 +445,59 @@ fn query_and_resolve_tree_transform_at_entity(
// TODO(andreas): Filter out styling components.
let components = archetypes::Transform3D::all_components();
let component_names = components.iter().map(|descr| descr.component_name);
let result = entity_db.latest_at(query, entity_path, component_names);
if result.components.is_empty() {
let results = entity_db.latest_at(query, entity_path, component_names);
if results.components.is_empty() {
return None;
}

let mut transform = Affine3A::IDENTITY;

// It's an error if there's more than one component. Warn in that case.
let mono_log_level = re_log::Level::Warn;

// The order of the components here is important, and checked by `debug_assert_transform_field_order`
if let Some(translation) = result.component_instance::<components::Translation3D>(0) {
if let Some(translation) =
results.component_mono_with_log_level::<components::Translation3D>(mono_log_level)
{
transform = Affine3A::from(translation);
}
if let Some(axis_angle) = result.component_instance::<components::RotationAxisAngle>(0) {
if let Some(axis_angle) =
results.component_mono_with_log_level::<components::RotationAxisAngle>(mono_log_level)
{
if let Ok(axis_angle) = Affine3A::try_from(axis_angle) {
transform *= axis_angle;
} else {
return Some(Affine3A::ZERO);
}
}
if let Some(quaternion) = result.component_instance::<components::RotationQuat>(0) {
if let Some(quaternion) =
results.component_mono_with_log_level::<components::RotationQuat>(mono_log_level)
{
if let Ok(quaternion) = Affine3A::try_from(quaternion) {
transform *= quaternion;
} else {
return Some(Affine3A::ZERO);
}
}
if let Some(scale) = result.component_instance::<components::Scale3D>(0) {
if let Some(scale) =
results.component_mono_with_log_level::<components::Scale3D>(mono_log_level)
{
if scale.x() == 0.0 && scale.y() == 0.0 && scale.z() == 0.0 {
return Some(Affine3A::ZERO);
}
transform *= Affine3A::from(scale);
}
if let Some(mat3x3) = result.component_instance::<components::TransformMat3x3>(0) {
if let Some(mat3x3) =
results.component_mono_with_log_level::<components::TransformMat3x3>(mono_log_level)
{
let affine_transform = Affine3A::from(mat3x3);
if affine_transform.matrix3.determinant() == 0.0 {
return Some(Affine3A::ZERO);
}
transform *= affine_transform;
}

if result.component_instance::<components::TransformRelation>(0)
if results.component_mono_with_log_level::<components::TransformRelation>(mono_log_level)
== Some(components::TransformRelation::ChildFromParent)
{
let determinant = transform.matrix3.determinant();
Expand Down

0 comments on commit 0d499f8

Please sign in to comment.