Skip to content

Commit

Permalink
Port Transform3D to eager serialization & update API (#8682)
Browse files Browse the repository at this point in the history
### Related

* Part of #7245

### What

Use new eager serialization & update API for transforms.

The only breaking change here is that Transform3D is no longer copy,
otherwise it's fully compatible.

---------

Co-authored-by: Clement Rey <[email protected]>
  • Loading branch information
Wumpf and teh-cmc authored Jan 14, 2025
1 parent 3a8c22f commit 209547c
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 300 deletions.
47 changes: 7 additions & 40 deletions crates/build/re_types_builder/src/codegen/rust/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,34 +1182,12 @@ fn quote_trait_impls_for_archetype(obj: &Object) -> TokenStream {
// NOTE: The nullability we're dealing with here is the nullability of an entire array of components,
// not the nullability of individual elements (i.e. instances)!
let batch = if is_nullable {
if obj.attrs.has(ATTR_RERUN_LOG_MISSING_AS_EMPTY) {
if is_plural {
// Always log Option<Vec<C>> as Vec<V>, mapping None to empty batch
let component_type = quote_field_type_from_typ(&obj_field.typ, false).0;
quote! {
Some(
if let Some(comp_batch) = &self.#field_name {
(comp_batch as &dyn ComponentBatch)
} else {
// We need a reference to something that outives the function call
static EMPTY_BATCH: once_cell::sync::OnceCell<#component_type> = once_cell::sync::OnceCell::new();
let empty_batch: &#component_type = EMPTY_BATCH.get_or_init(|| Vec::new());
(empty_batch as &dyn ComponentBatch)
}
)
}
} else {
// Always log Option<C>, mapping None to empty batch
quote!{ Some(&self.#field_name as &dyn ComponentBatch) }
}
if is_plural {
// Maybe logging an Option<Vec<C>>
quote!{ self.#field_name.as_ref().map(|comp_batch| (comp_batch as &dyn ComponentBatch)) }
} else {
if is_plural {
// Maybe logging an Option<Vec<C>>
quote!{ self.#field_name.as_ref().map(|comp_batch| (comp_batch as &dyn ComponentBatch)) }
} else {
// Maybe logging an Option<C>
quote!{ self.#field_name.as_ref().map(|comp| (comp as &dyn ComponentBatch)) }
}
// Maybe logging an Option<C>
quote!{ self.#field_name.as_ref().map(|comp| (comp as &dyn ComponentBatch)) }
}
} else {
// Always logging a Vec<C> or C
Expand Down Expand Up @@ -1683,19 +1661,8 @@ fn quote_builder_from_obj(reporter: &Reporter, objects: &Objects, obj: &Object)
};

if required.is_empty() && obj.attrs.has(ATTR_RERUN_LOG_MISSING_AS_EMPTY) {
let docstring = quote_doc_line(&format!(
"Create a new `{name}` which when logged will clear the values of all components."
));

quote! {
#docstring
#[inline]
#fn_new_pub fn clear() -> Self {
Self {
#(#quoted_optional,)*
}
}
}
// Skip the `new` method.
quote!()
} else {
let docstring = quote_doc_line(&format!("Create a new `{name}`."));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ namespace rerun.archetypes;
/// \example archetypes/transform3d_simple title="Variety of 3D transforms" image="https://static.rerun.io/transform3d_simple/141368b07360ce3fcb1553079258ae3f42bdb9ac/1200w.png"
/// \example archetypes/transform3d_hierarchy title="Transform hierarchy" image="https://static.rerun.io/transform_hierarchy/cb7be7a5a31fcb2efc02ba38e434849248f87554/1200w.png"
table Transform3D (
"attr.rust.archetype_eager",
"attr.docs.category": "Spatial 3D",
"attr.docs.view_types": "Spatial3DView, Spatial2DView: if logged above active projection",
"attr.rerun.log_missing_as_empty", // See https://github.com/rerun-io/rerun/issues/6909
"attr.rust.derive": "Copy, PartialEq"
"attr.rust.derive": "PartialEq"
) {
/// Translation vector.
translation: rerun.components.Translation3D ("attr.rerun.component_optional", nullable, order: 1100);
Expand Down
Loading

0 comments on commit 209547c

Please sign in to comment.