forked from rerun-io/rerun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demo helpers & examples for Getting Started (rs) (rerun-io#1260)
* new helpers for creating an appid * introducing Session::init * update all examples * cranky * Rust SDK: `save()`/`--save` support (rerun-io#1227) * implement spawn() support * api_demo_rs: spawn support * objectron_rs: spawn support * raw_mesh_rs: spawn support * slightly better doc, maybe * Update crates/re_sdk/src/session.rs Co-authored-by: Emil Ernerfeldt <[email protected]> * Update crates/re_sdk/src/session.rs Co-authored-by: Emil Ernerfeldt <[email protected]> * addressed PR comments * backporting arg refactorings from next PR * some vertical whitespace for emil * implement Session::save * api_demo_rs: handle --save * objectron_rs: handle --save * raw_mesh_rs: handle --save * todo * don't add wake_up_ui_thread_on_each_msg on wasm32 builds (we have no threads!) * who are you and what do you want from me * Update crates/re_sdk/src/session.rs Co-authored-by: Emil Ernerfeldt <[email protected]> * Update crates/re_sdk/src/session.rs Co-authored-by: Emil Ernerfeldt <[email protected]> --------- Co-authored-by: Emil Ernerfeldt <[email protected]> * Rust SDK: `--serve` support (rerun-io#1228) * implement spawn() support * api_demo_rs: spawn support * objectron_rs: spawn support * raw_mesh_rs: spawn support * slightly better doc, maybe * Update crates/re_sdk/src/session.rs Co-authored-by: Emil Ernerfeldt <[email protected]> * Update crates/re_sdk/src/session.rs Co-authored-by: Emil Ernerfeldt <[email protected]> * addressed PR comments * backporting arg refactorings from next PR * some vertical whitespace for emil * implement Session::save * api_demo_rs: handle --save * objectron_rs: handle --save * raw_mesh_rs: handle --save * todo * api_demo_rs: --serve * objectron_rs: --serve * raw_mesh_rs: --serve * less verbose websocket logs * serve or save * don't add wake_up_ui_thread_on_each_msg on wasm32 builds (we have no threads!) * who are you and what do you want from me --------- Co-authored-by: Emil Ernerfeldt <[email protected]> * add color_spiral demo util * add dna rust example --------- Co-authored-by: Emil Ernerfeldt <[email protected]>
- Loading branch information
Showing
6 changed files
with
160 additions
and
1 deletion.
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.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "dna" | ||
version.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
license.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
rerun = { workspace = true, features = ["glam"] } | ||
|
||
itertools = "0.10" | ||
rand = "0.8" |
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,100 @@ | ||
//! The example from our Getting Started page. | ||
use std::f32::consts::TAU; | ||
|
||
use itertools::Itertools as _; | ||
|
||
use rerun::components::{ | ||
ColorRGBA, LineStrip3D, Point3D, Quaternion, Radius, Rigid3, Transform, Vec3D, | ||
}; | ||
use rerun::demo_util::{bounce_lerp, color_spiral}; | ||
use rerun::external::glam; | ||
use rerun::time::{Time, TimeType, Timeline}; | ||
use rerun::{MsgSender, Session}; | ||
|
||
const NUM_POINTS: usize = 100; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut session = Session::init("DNA Abacus", true); | ||
|
||
let stable_time = Timeline::new("stable_time", TimeType::Time); | ||
|
||
let (points1, colors1) = color_spiral(NUM_POINTS, 2.0, 0.02, 0.0, 0.1); | ||
let (points2, colors2) = color_spiral(NUM_POINTS, 2.0, 0.02, TAU * 0.5, 0.1); | ||
|
||
MsgSender::new("dna/structure/left") | ||
.with_time(stable_time, 0) | ||
.with_component(&points1.iter().copied().map(Point3D::from).collect_vec())? | ||
.with_component(&colors1.iter().copied().map(ColorRGBA::from).collect_vec())? | ||
.with_splat(Radius(0.08))? | ||
.send(&mut session)?; | ||
|
||
MsgSender::new("dna/structure/right") | ||
.with_time(stable_time, 0) | ||
.with_component(&points2.iter().copied().map(Point3D::from).collect_vec())? | ||
.with_component(&colors2.iter().copied().map(ColorRGBA::from).collect_vec())? | ||
.with_splat(Radius(0.08))? | ||
.send(&mut session)?; | ||
|
||
let scaffolding = points1 | ||
.iter() | ||
.interleave(points2.iter()) | ||
.copied() | ||
.map(Vec3D::from) | ||
.chunks(2) | ||
.into_iter() | ||
.map(|positions| LineStrip3D(positions.collect_vec())) | ||
.collect_vec(); | ||
MsgSender::new("dna/structure/scaffolding") | ||
.with_time(stable_time, 0) | ||
.with_component(&scaffolding)? | ||
.with_splat(ColorRGBA::from([128, 128, 128, 255]))? | ||
.send(&mut session)?; | ||
|
||
use rand::Rng as _; | ||
let mut rng = rand::thread_rng(); | ||
let offsets = (0..NUM_POINTS).map(|_| rng.gen::<f32>()).collect_vec(); | ||
|
||
for i in 0..400 { | ||
let time = i as f32 * 0.01; | ||
|
||
let times = offsets.iter().map(|offset| time + offset).collect_vec(); | ||
let (beads, colors): (Vec<_>, Vec<_>) = points1 | ||
.iter() | ||
.interleave(points2.iter()) | ||
.copied() | ||
.chunks(2) | ||
.into_iter() | ||
.enumerate() | ||
.map(|(n, mut points)| { | ||
let (p1, p2) = (points.next().unwrap(), points.next().unwrap()); | ||
let c = bounce_lerp(80.0, 230.0, times[n] * 2.0) as u8; | ||
( | ||
Point3D::from(bounce_lerp(p1, p2, times[n])), | ||
ColorRGBA::from_rgb(c, c, c), | ||
) | ||
}) | ||
.unzip(); | ||
MsgSender::new("dna/structure/scaffolding/beads") | ||
.with_time(stable_time, Time::from_seconds_since_epoch(time as _)) | ||
.with_component(&beads)? | ||
.with_component(&colors)? | ||
.with_splat(Radius(0.06))? | ||
.send(&mut session)?; | ||
|
||
MsgSender::new("dna/structure") | ||
.with_time(stable_time, Time::from_seconds_since_epoch(time as _)) | ||
.with_component(&[Transform::Rigid3(Rigid3 { | ||
rotation: Quaternion::from(glam::Quat::from_axis_angle( | ||
glam::Vec3::Z, | ||
time / 4.0 * TAU, | ||
)), | ||
..Default::default() | ||
})])? | ||
.send(&mut session)?; | ||
} | ||
|
||
session.show()?; | ||
|
||
Ok(()) | ||
} |