Skip to content

Commit

Permalink
New transform components: Translation3D & TransformMat3x3 (rerun-…
Browse files Browse the repository at this point in the history
…io#6866)

### What

* Part of #6831
* Followed by rerun-io#6892

Starts the process of splitting up `Transform3D` into several
components.
Far from done overall, but establishes a lot of the new documentation &
test patterns for this effort.

This PR fully replaces the `TranslationAndMat3x3` variant & datatype and
puts `Translation3D` & `TransformMat3x3` into existence and to work.
It does not touch on anything directly related to out of tree transforms
and does not do away from the `Transform3D` component yet.

I added a new component edit/view ui for consistency:
<img width="532" alt="image"
src="https://github.com/rerun-io/rerun/assets/1220815/1e7122f0-bf27-4f50-bc23-2824c2607ab2">


<img width="552" alt="image"
src="https://github.com/rerun-io/rerun/assets/1220815/1b30af25-905f-49ed-952b-961350dfab1f">
Unfortunately, transform hierarchy doesn't get affected by overrides yet
(see rerun-io#6743), which is why I had
to turn off editing itself for the moment. Also, we don't yet show
multiline on hover, so matrix3x3 inspection regressed a little bit for
the moment (part of the only partially solved
rerun-io#6661)


### Checklist
* [x] pass `main` ci checks
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6866?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6866?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!
* [x] If have noted any breaking changes to the log API in
`CHANGELOG.md` and the migration guide

- [PR Build Summary](https://build.rerun.io/pr/6866)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
Wumpf authored Jul 16, 2024
1 parent 698a92e commit e5d9535
Show file tree
Hide file tree
Showing 102 changed files with 1,984 additions and 2,030 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# ⚠️ Breaking changes
* `mesh_material: Material` has been renamed to `albedo_factor: AlbedoFactor` [#6841](https://github.com/rerun-io/rerun/pull/6841)
* 3D transform APIs: Previously, the transform component was represented as one of several variants (an Arrow union, `enum` in Rust) depending on how the transform was expressed. Instead, there are now several components for translation/scale/rotation/matrices that can live side-by-side in the 3D transform archetype.
* Python: `NV12/YUY2` are now logged with the new `ImageChromaDownsampled`
* `ImageEncoded`:s `format` parameter has been replaced with `media_type` (MIME)

Expand Down
23 changes: 20 additions & 3 deletions crates/store/re_types/definitions/rerun/archetypes/transform3d.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@ namespace rerun.archetypes;

/// A transform between two 3D spaces, i.e. a pose.
///
/// All components are applied in the order they are listed here.
/// E.g. if both a 4x4 matrix with a translation and a translation vector are present,
/// the matrix is applied first, then the translation vector on top.
///
/// Each transform component can be listed multiple times, but transform tree propagation is only possible
/// if there's only one instance for each transform component.
/// TODO(#6831): write more about the exact interaction with the to be written `OutOfTreeTransform` component.
///
/// \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"
// TODO(#6831): provide example with out of tree transform.
table Transform3D (
"attr.rust.derive": "PartialEq",
"attr.rust.derive": "Default, PartialEq",
"attr.docs.category": "Spatial 3D",
"attr.docs.view_types": "Spatial3DView, Spatial2DView: if logged above active projection"
) {
/// The transform
transform: rerun.components.Transform3D ("attr.rerun.component_required", order: 1000);
// TODO(#6831): remove.
transform: rerun.components.Transform3D ("attr.rerun.component_optional", order: 1000);

/// 3x3 transformation matrices.
mat3x3: [rerun.components.TransformMat3x3] ("attr.rerun.component_optional", nullable, order: 1100);

/// Translation vectors.
translation: [rerun.components.Translation3D] ("attr.rerun.component_optional", nullable, order: 1200);

// --- Optional ---
// --- visual representation

/// Visual length of the 3 axes.
///
/// The length is interpreted in the local coordinate system of the transform.
/// If the transform is scaled, the axes will be scaled accordingly.
// TODO(#6831): Should be an array as well.
axis_length: rerun.components.AxisLength ("attr.rerun.component_optional", nullable, order: 2000);
}
2 changes: 2 additions & 0 deletions crates/store/re_types/definitions/rerun/components.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ include "./components/tensor_dimension_selection.fbs";
include "./components/texcoord2d.fbs";
include "./components/text_log_level.fbs";
include "./components/text.fbs";
include "./components/transform_mat3x3.fbs";
include "./components/transform3d.fbs";
include "./components/translation3d.fbs";
include "./components/triangle_indices.fbs";
include "./components/vector2d.fbs";
include "./components/vector3d.fbs";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace rerun.components;

/// A 3x3 transformation matrix Matrix.
///
/// 3x3 matrixes are able to represent any affine transformation in 3D space,
/// i.e. rotation, scaling, shearing, reflection etc.
///
/// Matrices in Rerun are stored as flat list of coefficients in column-major order:
/// ```text
/// column 0 column 1 column 2
/// -------------------------------------------------
/// row 0 | flat_columns[0] flat_columns[3] flat_columns[6]
/// row 1 | flat_columns[1] flat_columns[4] flat_columns[7]
/// row 2 | flat_columns[2] flat_columns[5] flat_columns[8]
/// ```
///
/// \py However, construction is done from a list of rows, which follows NumPy's convention:
/// \py ```python
/// \py np.testing.assert_array_equal(
/// \py rr.components.TransformMat3x3([1, 2, 3, 4, 5, 6, 7, 8, 9]).flat_columns, np.array([1, 4, 7, 2, 5, 8, 3, 6, 9], dtype=np.float32)
/// \py )
/// \py np.testing.assert_array_equal(
/// \py rr.components.TransformMat3x3([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).flat_columns,
/// \py np.array([1, 4, 7, 2, 5, 8, 3, 6, 9], dtype=np.float32),
/// \py )
/// \py ```
/// \py If you want to construct a matrix from a list of columns instead, use the named `columns` parameter:
/// \py ```python
/// \py np.testing.assert_array_equal(
/// \py rr.components.TransformMat3x3(columns=[1, 2, 3, 4, 5, 6, 7, 8, 9]).flat_columns,
/// \py np.array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=np.float32),
/// \py )
/// \py np.testing.assert_array_equal(
/// \py rr.components.TransformMat3x3(columns=[[1, 2, 3], [4, 5, 6], [7, 8, 9]]).flat_columns,
/// \py np.array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=np.float32),
/// \py )
/// \py ```
struct TransformMat3x3 (
"attr.docs.unreleased",
"attr.rust.derive": "Default, Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent"
) {
matrix: rerun.datatypes.Mat3x3 (order: 100);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace rerun.components;

/// A translation vector in 3D space.
struct Translation3D (
"attr.docs.unreleased",
"attr.rust.derive": "Default, Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent"
) {
vector: rerun.datatypes.Vec3D (order: 100);
}
1 change: 0 additions & 1 deletion crates/store/re_types/definitions/rerun/datatypes.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ include "./datatypes/tensor_dimension_selection.fbs";
include "./datatypes/tensor_dimension.fbs";
include "./datatypes/time_int.fbs";
include "./datatypes/transform3d.fbs";
include "./datatypes/translation_and_mat3x3.fbs";
include "./datatypes/translation_rotation_scale3d.fbs";
include "./datatypes/uint32.fbs";
include "./datatypes/uint64.fbs";
Expand Down
3 changes: 2 additions & 1 deletion crates/store/re_types/definitions/rerun/datatypes/mat3x3.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace rerun.datatypes;
struct Mat3x3 (
"attr.arrow.transparent",
"attr.python.aliases": "npt.ArrayLike",
"attr.rust.derive": "Copy, PartialEq, PartialOrd",
"attr.rust.derive": "Copy, PartialEq, PartialOrd, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent",
"attr.rust.tuple_struct"
) {
/// Flat list of matrix coefficients in column-major order.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ namespace rerun.datatypes;
union Transform3D (
"attr.rust.derive": "Copy, PartialEq"
) {
/// Translation plus a 3x3 matrix for scale, rotation, skew, etc.
TranslationAndMat3x3: TranslationAndMat3x3,

/// Translation, rotation and scale, decomposed.
TranslationRotationScale: TranslationRotationScale3D,

Expand Down

This file was deleted.

103 changes: 93 additions & 10 deletions crates/store/re_types/src/archetypes/transform3d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e5d9535

Please sign in to comment.