-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal example, with a couple of command line arguments (--num-point…
…s-per-axis --radius) * Allows connecting to remote server through rerun's RerunArgs.
- Loading branch information
1 parent
8ab1155
commit 9e77754
Showing
3 changed files
with
90 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.
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,14 @@ | ||
[package] | ||
name = "minimal_options" | ||
version.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
license.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
rerun = { workspace = true, features = ["web_viewer"] } | ||
|
||
anyhow.workspace = true | ||
clap = { workspace = true, features = ["derive"] } | ||
glam.workspace = true |
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,66 @@ | ||
//! Demonstrates how to accept arguments and connect to running rerun servers. | ||
//! | ||
//! Usage: | ||
//! ``` | ||
//! cargo run -p minimal_options -- --help | ||
//! ``` | ||
use rerun::components::{ColorRGBA, Point3D}; | ||
use rerun::time::{TimeType, Timeline}; | ||
use rerun::{external::re_log, MsgSender, Session}; | ||
|
||
use rerun::demo_util::grid; | ||
|
||
#[derive(Debug, clap::Parser)] | ||
#[clap(author, version, about)] | ||
struct Args { | ||
#[command(flatten)] | ||
rerun: rerun::clap::RerunArgs, | ||
|
||
#[clap(long, default_value = "10")] | ||
num_points_per_axis: usize, | ||
|
||
#[clap(long, default_value = "5.0")] | ||
radius: f32, | ||
} | ||
|
||
fn run(session: &Session, args: &Args) -> anyhow::Result<()> { | ||
let timeline_keyframe = Timeline::new("keyframe", TimeType::Sequence); | ||
|
||
let points = grid( | ||
glam::Vec3::splat(-args.radius), | ||
glam::Vec3::splat(args.radius), | ||
args.num_points_per_axis, | ||
) | ||
.map(Point3D::from) | ||
.collect::<Vec<_>>(); | ||
let colors = grid( | ||
glam::Vec3::ZERO, | ||
glam::Vec3::splat(255.0), | ||
args.num_points_per_axis, | ||
) | ||
.map(|v| ColorRGBA::from_rgb(v.x as u8, v.y as u8, v.z as u8)) | ||
.collect::<Vec<_>>(); | ||
|
||
MsgSender::new("my_points") | ||
.with_component(&points)? | ||
.with_component(&colors)? | ||
.with_time(timeline_keyframe, 0) | ||
.send(session)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
re_log::setup_native_logging(); | ||
|
||
use clap::Parser as _; | ||
let args = Args::parse(); | ||
|
||
let default_enabled = true; | ||
args.rerun | ||
.clone() | ||
.run("minimal_options", default_enabled, move |session| { | ||
run(&session, &args).unwrap(); | ||
}) | ||
} |