-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new
Transform3D
partial updates snippet for all languages (#8690)
Adds some much needed snippet for partial updates on `Transform3D`. Much needed because A) `Transform3D` has a long history of custom partial updatability hacks and B) users are very very likely to use that one. * Part of #8580
- Loading branch information
Showing
6 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
docs/snippets/all/archetypes/transform3d_partial_updates.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Log different transforms with visualized coordinates axes. | ||
|
||
#include <rerun.hpp> | ||
|
||
float truncated_radians(int deg) { | ||
auto degf = static_cast<float>(deg); | ||
const auto pi = 3.14159265358979323846; | ||
return static_cast<float>(static_cast<int>(degf * pi / 180.0f * 1000.0f)) / 1000.0f; | ||
} | ||
|
||
int main() { | ||
const auto rec = rerun::RecordingStream("rerun_example_transform3d_partial_updates"); | ||
rec.spawn().exit_on_failure(); | ||
|
||
// Set up a 3D box. | ||
rec.log( | ||
"box", | ||
rerun::Boxes3D::from_half_sizes({{4.f, 2.f, 1.0f}}).with_fill_mode(rerun::FillMode::Solid), | ||
rerun::Transform3D().with_axis_length(10.0) | ||
); | ||
|
||
// Update only the rotation of the box. | ||
for (int deg = 0; deg <= 45; deg++) { | ||
auto rad = truncated_radians(deg * 4); | ||
// TODO(#8583): update_fields | ||
rec.log( | ||
"box", | ||
rerun::Transform3D().with_rotation_axis_angle( | ||
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad)) | ||
) | ||
); | ||
} | ||
|
||
// Update only the position of the box. | ||
for (int t = 0; t <= 45; t++) { | ||
rec.log( | ||
"box", | ||
rerun::Transform3D().with_translation({0.0f, 0.0f, static_cast<float>(t) / 10.0f}) | ||
); | ||
} | ||
|
||
// Update only the rotation of the box. | ||
for (int deg = 0; deg <= 45; deg++) { | ||
auto rad = truncated_radians((deg + 45) * 4); | ||
// TODO(#8583): update_fields | ||
rec.log( | ||
"box", | ||
rerun::Transform3D().with_rotation_axis_angle( | ||
rerun::RotationAxisAngle({0.0f, 1.0f, 0.0f}, rerun::Angle::radians(rad)) | ||
) | ||
); | ||
} | ||
|
||
// Clear all of the box's attributes, and reset its axis length. | ||
// TODO(#8583): clear_fields | ||
rec.log("box", rerun::Transform3D().with_axis_length(15.0)); | ||
} |
53 changes: 53 additions & 0 deletions
53
docs/snippets/all/archetypes/transform3d_partial_updates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Log different transforms with visualized coordinates axes.""" | ||
|
||
import math | ||
|
||
import rerun as rr | ||
|
||
|
||
def truncated_radians(deg: float) -> float: | ||
return float(int(math.radians(deg) * 1000.0)) / 1000.0 | ||
|
||
|
||
rr.init("rerun_example_transform3d_partial_updates", spawn=True) | ||
|
||
rr.log( | ||
"box", | ||
rr.Boxes3D(half_sizes=[4.0, 2.0, 1.0], fill_mode=rr.components.FillMode.Solid), | ||
rr.Transform3D(axis_length=10), | ||
) | ||
|
||
for deg in range(46): | ||
rad = truncated_radians(deg * 4) | ||
# TODO(#8582): update_fields | ||
rr.log( | ||
"box", | ||
rr.Transform3D( | ||
# TODO(cmc): we should have access to all the fields of the extended constructor too. | ||
rotation_axis_angle=rr.RotationAxisAngle(axis=[0.0, 1.0, 0.0], radians=rad), | ||
), | ||
) | ||
|
||
for t in range(51): | ||
# TODO(#8582): update_fields | ||
rr.log( | ||
"box", | ||
rr.Transform3D(translation=[0, 0, t / 10.0]), | ||
) | ||
|
||
for deg in range(46): | ||
rad = truncated_radians((deg + 45) * 4) | ||
# TODO(#8582): update_fields | ||
rr.log( | ||
"box", | ||
rr.Transform3D( | ||
# TODO(cmc): we should have access to all the fields of the extended constructor too. | ||
rotation_axis_angle=rr.RotationAxisAngle(axis=[0.0, 1.0, 0.0], radians=rad), | ||
), | ||
) | ||
|
||
# TODO(#8582): update_fields(clear=True) | ||
rr.log( | ||
"box", | ||
rr.Transform3D(axis_length=15), | ||
) |
60 changes: 60 additions & 0 deletions
60
docs/snippets/all/archetypes/transform3d_partial_updates.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Log different transforms with visualized coordinates axes. | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let rec = | ||
rerun::RecordingStreamBuilder::new("rerun_example_transform3d_partial_updates").spawn()?; | ||
|
||
// Set up a 3D box. | ||
rec.log( | ||
"box", | ||
&[ | ||
&rerun::Boxes3D::from_half_sizes([(4.0, 2.0, 1.0)]) | ||
.with_fill_mode(rerun::FillMode::Solid) as &dyn rerun::AsComponents, | ||
&rerun::Transform3D::default().with_axis_length(10.0), | ||
], | ||
)?; | ||
|
||
// Update only the rotation of the box. | ||
for deg in 0..=45 { | ||
let rad = truncated_radians((deg * 4) as f32); | ||
rec.log( | ||
"box", | ||
&rerun::Transform3D::update_fields().with_rotation(rerun::RotationAxisAngle::new( | ||
[0.0, 1.0, 0.0], | ||
rerun::Angle::from_radians(rad), | ||
)), | ||
)?; | ||
} | ||
|
||
// Update only the position of the box. | ||
for t in 0..=50 { | ||
rec.log( | ||
"box", | ||
&rerun::Transform3D::update_fields().with_translation([0.0, 0.0, t as f32 / 10.0]), | ||
)?; | ||
} | ||
|
||
// Update only the rotation of the box. | ||
for deg in 0..=45 { | ||
let rad = truncated_radians(((deg + 45) * 4) as f32); | ||
rec.log( | ||
"box", | ||
&rerun::Transform3D::update_fields().with_rotation(rerun::RotationAxisAngle::new( | ||
[0.0, 1.0, 0.0], | ||
rerun::Angle::from_radians(rad), | ||
)), | ||
)?; | ||
} | ||
|
||
// Clear all of the box's attributes, and reset its axis length. | ||
rec.log( | ||
"box", | ||
&rerun::Transform3D::clear_fields().with_axis_length(15.0), | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn truncated_radians(deg: f32) -> f32 { | ||
((deg.to_radians() * 1000.0) as i32) as f32 / 1000.0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters