Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add components for RotationAxisAngle and RotationQuat #6929

Merged
merged 15 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading