Skip to content

Commit

Permalink
Add components for RotationAxisAngle and RotationQuat (rerun-io#6929
Browse files Browse the repository at this point in the history
)

### What

* Part of rerun-io#6831 

Very similar to previous PRs in the series. Still doesn't remove
existing components since `Transform3D` datatype is still used in
`OutOfTreeTransform` and the `Transform3D` datatype is still used to
describe `from_parent` (that's the next thing to fix!)

### Checklist
* [x] don't regress `main` checks further
* [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/6929?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/6929?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/6929)
- [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 22, 2024
1 parent ddf60c4 commit 9c26c5a
Show file tree
Hide file tree
Showing 50 changed files with 1,174 additions and 204 deletions.
3 changes: 2 additions & 1 deletion crates/build/re_types_builder/src/codegen/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,8 @@ fn single_field_constructor_methods(
// but ran into some issues when init archetypes with initializer lists.
if let Type::Object(field_type_fqname) = &field.typ {
let field_type_obj = &objects[field_type_fqname];
if field_type_obj.fields.len() == 1 {
if field_type_obj.fields.len() == 1 && !field_type_obj.is_attr_set(ATTR_CPP_NO_FIELD_CTORS)
{
methods.extend(add_copy_assignment_and_constructor(
hpp_includes,
&field_type_obj.fields[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ table Transform3D (
/// Translation vectors.
translation: [rerun.components.Translation3D] ("attr.rerun.component_optional", nullable, order: 1100);

/// Rotation via axis + angle.
rotation_axis_angle: [rerun.components.RotationAxisAngle] ("attr.rerun.component_optional", nullable, order: 1200);

/// Rotation via quaternion.
quaternion: [rerun.components.RotationQuat] ("attr.rerun.component_optional", nullable, order: 1300);

/// Scaling factor.
scale: [rerun.components.Scale3D] ("attr.rerun.component_optional", nullable, order: 1200);
scale: [rerun.components.Scale3D] ("attr.rerun.component_optional", nullable, order: 1400);

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

// --- visual representation

Expand Down
2 changes: 2 additions & 0 deletions crates/store/re_types/definitions/rerun/components.fbs

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

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

/// 3D rotation represented by a rotation around a given axis.
table RotationAxisAngle (
"attr.docs.unreleased",
"attr.rust.derive": "Default, Copy, PartialEq",
"attr.rust.repr": "transparent"
) {
rotation: rerun.datatypes.RotationAxisAngle (order: 100);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace rerun.components;

/// A 3D rotation expressed as a quaternion.
///
/// Note: although the x,y,z,w components of the quaternion will be passed through to the
/// datastore as provided, when used in the Viewer Quaternions will always be normalized.
struct RotationQuat (
"attr.docs.unreleased",
"attr.rust.derive": "Default, Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent"
) {
quaternion: rerun.datatypes.Quaternion (order: 100);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ namespace rerun.datatypes;
///
/// Note: although the x,y,z,w components of the quaternion will be passed through to the
/// datastore as provided, when used in the Viewer Quaternions will always be normalized.
//
// Expectations:
struct Quaternion (
"attr.arrow.transparent",
"attr.rust.derive": "Copy, PartialEq, PartialOrd",
"attr.rust.derive": "Copy, PartialEq, PartialOrd, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.tuple_struct",
"attr.rust.repr": "C",
"attr.cpp.no_field_ctors" // Always be explicit about the values of the fields.
) {
xyzw: [float: 4] (order: 100);
Expand Down
77 changes: 73 additions & 4 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.

28 changes: 20 additions & 8 deletions crates/store/re_types/src/archetypes/transform3d_ext.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
use crate::{
components::{Scale3D, TransformMat3x3, Translation3D},
datatypes::{Rotation3D, TranslationRotationScale3D},
Rotation3D,
};

use super::Transform3D;

impl Transform3D {
/// Convenience method that takes any kind of (single) rotation representation and sets it on this transform.
#[inline]
pub fn with_rotation(self, rotation: impl Into<Rotation3D>) -> Self {
match rotation.into() {
Rotation3D::Quaternion(quaternion) => Self {
quaternion: Some(vec![quaternion]),
..self
},
Rotation3D::AxisAngle(rotation_axis_angle) => Self {
rotation_axis_angle: Some(vec![rotation_axis_angle]),
..self
},
}
}

/// From a translation.
#[inline]
pub fn from_translation(translation: impl Into<Translation3D>) -> Self {
Expand All @@ -27,10 +42,7 @@ impl Transform3D {
/// From a rotation
#[inline]
pub fn from_rotation(rotation: impl Into<Rotation3D>) -> Self {
Self {
transform: TranslationRotationScale3D::from_rotation(rotation).into(),
..Self::default()
}
Self::default().with_rotation(rotation)
}

/// From a scale
Expand All @@ -49,10 +61,10 @@ impl Transform3D {
rotation: impl Into<Rotation3D>,
) -> Self {
Self {
transform: TranslationRotationScale3D::from_rotation(rotation).into(),
translation: Some(vec![translation.into()]),
..Self::default()
}
.with_rotation(rotation)
}

/// From a translation applied after a 3x3 matrix.
Expand Down Expand Up @@ -89,21 +101,21 @@ impl Transform3D {
scale: impl Into<Scale3D>,
) -> Self {
Self {
transform: TranslationRotationScale3D::from_rotation(rotation).into(),
scale: Some(vec![scale.into()]),
translation: Some(vec![translation.into()]),
..Self::default()
}
.with_rotation(rotation)
}

/// From a rotation & scale
#[inline]
pub fn from_rotation_scale(rotation: impl Into<Rotation3D>, scale: impl Into<Scale3D>) -> Self {
Self {
transform: TranslationRotationScale3D::from_rotation(rotation).into(),
scale: Some(vec![scale.into()]),
..Self::default()
}
.with_rotation(rotation)
}

/// Indicate that this transform is from parent to child.
Expand Down
2 changes: 2 additions & 0 deletions crates/store/re_types/src/components/.gitattributes

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

6 changes: 6 additions & 0 deletions crates/store/re_types/src/components/mod.rs

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

Loading

0 comments on commit 9c26c5a

Please sign in to comment.