Skip to content

Commit cd57354

Browse files
committed
snippetize the basic hierarchy snippet
1 parent 89f15b0 commit cd57354

File tree

4 files changed

+94
-15
lines changed

4 files changed

+94
-15
lines changed

docs/content/concepts/transforms.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,7 @@ The [`Transform3D`](https://rerun.io/docs/reference/types/archetypes/transform3d
1515
The simplest way to use transforms is through entity path hierarchies, where each transform describes the relationship between an entity and its parent path.
1616
Note that by default, all entities are connected via identity transforms (to opt out of that, you have to use explicit transform frames, more on that later).
1717

18-
TODO: make tested cross language snippet
19-
```python
20-
import rerun as rr
21-
22-
rr.init("transform_hierarchy_example", spawn=True)
23-
24-
# Log entities at their hierarchy positions
25-
rr.log("sun", rr.Ellipsoids3D(centers=[0, 0, 0], half_sizes=[1, 1, 1], colors=[255, 200, 10]))
26-
rr.log("sun/planet", rr.Ellipsoids3D(centers=[0, 0, 0], half_sizes=[0.4, 0.4, 0.4], colors=[40, 80, 200]))
27-
rr.log("sun/planet/moon", rr.Ellipsoids3D(centers=[0, 0, 0], half_sizes=[0.15, 0.15, 0.15], colors=[180, 180, 180]))
28-
29-
# Define transforms - each describes the relationship to its parent
30-
rr.log("sun/planet", rr.Transform3D(translation=[6.0, 0.0, 0.0])) # Planet 6 units from sun
31-
rr.log("sun/planet/moon", rr.Transform3D(translation=[3.0, 0.0, 0.0])) # Moon 3 units from planet
32-
```
18+
snippet: concepts/transform3d_hierarchy_simple
3319

3420
In this hierarchy:
3521
- The `sun` entity exists at the origin of its own coordinate system
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//! Logs a simple transform hierarchy.
2+
3+
#include <rerun.hpp>
4+
5+
int main() {
6+
const auto rec = rerun::RecordingStream("rerun_example_transform3d_hierarchy_simple");
7+
rec.spawn().exit_on_failure();
8+
9+
// Log entities at their hierarchy positions
10+
rec.log(
11+
"sun",
12+
rerun::Ellipsoids3D::from_centers_and_half_sizes({{0.0f, 0.0f, 0.0f}}, {{1.0f, 1.0f, 1.0f}})
13+
.with_colors(rerun::Color(255, 200, 10))
14+
);
15+
16+
rec.log(
17+
"sun/planet",
18+
rerun::Ellipsoids3D::from_centers_and_half_sizes({{0.0f, 0.0f, 0.0f}}, {{0.4f, 0.4f, 0.4f}})
19+
.with_colors(rerun::Color(40, 80, 200))
20+
);
21+
22+
rec.log(
23+
"sun/planet/moon",
24+
rerun::Ellipsoids3D::from_centers_and_half_sizes(
25+
{{0.0f, 0.0f, 0.0f}},
26+
{{0.15f, 0.15f, 0.15f}}
27+
).with_colors(rerun::Color(180, 180, 180))
28+
);
29+
30+
// Define transforms - each describes the relationship to its parent
31+
rec.log(
32+
"sun/planet",
33+
rerun::Transform3D::from_translation({6.0f, 0.0f, 0.0f})
34+
); // Planet 6 units from sun
35+
36+
rec.log(
37+
"sun/planet/moon",
38+
rerun::Transform3D::from_translation({3.0f, 0.0f, 0.0f})
39+
); // Moon 3 units from planet
40+
41+
return 0;
42+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Logs a simple transform hierarchy."""
2+
3+
import rerun as rr
4+
5+
rr.init("rerun_example_transform3d_hierarchy_simple", spawn=True)
6+
7+
# Log entities at their hierarchy positions
8+
rr.log("sun", rr.Ellipsoids3D(centers=[0, 0, 0], half_sizes=[1, 1, 1], colors=[255, 200, 10]))
9+
rr.log("sun/planet", rr.Ellipsoids3D(centers=[0, 0, 0], half_sizes=[0.4, 0.4, 0.4], colors=[40, 80, 200]))
10+
rr.log("sun/planet/moon", rr.Ellipsoids3D(centers=[0, 0, 0], half_sizes=[0.15, 0.15, 0.15], colors=[180, 180, 180]))
11+
12+
# Define transforms - each describes the relationship to its parent
13+
rr.log("sun/planet", rr.Transform3D(translation=[6.0, 0.0, 0.0])) # Planet 6 units from sun
14+
rr.log("sun/planet/moon", rr.Transform3D(translation=[3.0, 0.0, 0.0])) # Moon 3 units from planet
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! Logs a simple transform hierarchy.
2+
3+
fn main() -> Result<(), Box<dyn std::error::Error>> {
4+
let rec =
5+
rerun::RecordingStreamBuilder::new("rerun_example_transform3d_hierarchy_simple").spawn()?;
6+
7+
// Log entities at their hierarchy positions
8+
rec.log(
9+
"sun",
10+
&rerun::Ellipsoids3D::from_centers_and_half_sizes([[0.0, 0.0, 0.0]], [[1.0, 1.0, 1.0]])
11+
.with_colors([rerun::Color::from_rgb(255, 200, 10)]),
12+
)?;
13+
14+
rec.log(
15+
"sun/planet",
16+
&rerun::Ellipsoids3D::from_centers_and_half_sizes([[0.0, 0.0, 0.0]], [[0.4, 0.4, 0.4]])
17+
.with_colors([rerun::Color::from_rgb(40, 80, 200)]),
18+
)?;
19+
20+
rec.log(
21+
"sun/planet/moon",
22+
&rerun::Ellipsoids3D::from_centers_and_half_sizes([[0.0, 0.0, 0.0]], [[0.15, 0.15, 0.15]])
23+
.with_colors([rerun::Color::from_rgb(180, 180, 180)]),
24+
)?;
25+
26+
// Define transforms - each describes the relationship to its parent
27+
rec.log(
28+
"sun/planet",
29+
&rerun::Transform3D::from_translation([6.0, 0.0, 0.0]),
30+
)?; // Planet 6 units from sun
31+
rec.log(
32+
"sun/planet/moon",
33+
&rerun::Transform3D::from_translation([3.0, 0.0, 0.0]),
34+
)?; // Moon 3 units from planet
35+
36+
Ok(())
37+
}

0 commit comments

Comments
 (0)