Skip to content

Commit

Permalink
Minimal example, with a couple of command line arguments (--num-point…
Browse files Browse the repository at this point in the history
…s-per-axis --radius)

* Allows connecting to remote server through rerun's RerunArgs.
  • Loading branch information
h3mosphere committed Apr 7, 2023
1 parent 8ab1155 commit 95d7e77
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions examples/rust/minimal_options/Cargo.toml
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
66 changes: 66 additions & 0 deletions examples/rust/minimal_options/src/main.rs
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_opts", default_enabled, move |session| {
run(&session, &args).unwrap();
})
}

0 comments on commit 95d7e77

Please sign in to comment.