Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal_options example for Rust SDK #1773

Merged
merged 2 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_options", default_enabled, move |session| {
run(&session, &args).unwrap();
})
}