facett-demo/examples/clip_lab.rs
//! **Clip lab** — the rabbit logo and the glTF avocado, side by side, on the real
//! window, with no tab to click. The two panes the clipping report is about, hosted
//! exactly the way `facett-demo`'s deck hosts them (a `Facet` in a `ui.scope`), so a
//! screenshot of this window is a screenshot of the reported surface.
//!
//! `FACETT_CLIP_LAB_YAW` / `_TILT` pin the pose (radians) for a reproducible shot;
//! unset, both panes auto-spin.
//!
//! `cargo run -p facett-demo --example clip_lab`
use eframe::egui;
use facett_core::Facet;
struct App {
rabbit: facett::graph3d::RabbitLogo3D,
avocado: facett_model3d::Model3D,
clock: f64,
pinned: bool,
}
impl Default for App {
fn default() -> Self {
let yaw = std::env::var("FACETT_CLIP_LAB_YAW").ok().and_then(|v| v.parse::<f32>().ok());
let tilt = std::env::var("FACETT_CLIP_LAB_TILT").ok().and_then(|v| v.parse::<f32>().ok());
let mut rabbit = facett::graph3d::RabbitLogo3D::new("rabbit3d");
let mut avocado =
facett_model3d::Model3D::avocado("avocado3d").with_status(1.0).with_status_control(true);
if let Some(y) = yaw {
rabbit.spin = false;
rabbit.yaw = y;
avocado.update(facett_model3d::Msg::SetYaw(y));
avocado.update(facett_model3d::Msg::SetSpin(false));
}
if let Some(t) = tilt {
rabbit.tilt = t;
avocado.update(facett_model3d::Msg::SetTilt(t));
}
Self { rabbit, avocado, clock: 0.0, pinned: yaw.is_some() }
}
}
impl eframe::App for App {
fn ui(&mut self, root: &mut egui::Ui, _frame: &mut eframe::Frame) {
if !self.pinned {
self.clock += 0.016;
}
egui::CentralPanel::default().show(root, |ui| {
let full = ui.available_rect_before_wrap();
let half = full.width() * 0.5;
ui.horizontal_top(|ui| {
ui.allocate_ui(egui::vec2(half - 4.0, full.height()), |ui| {
self.rabbit.ui(ui);
});
ui.allocate_ui(egui::vec2(half - 4.0, full.height()), |ui| {
self.avocado.ui(ui);
});
});
});
root.ctx().request_repaint();
}
}
fn main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size(egui::Vec2::new(1400.0, 760.0)),
..Default::default()
};
eframe::run_native("facett · clip_lab", options, Box::new(|_cc| Ok(Box::<App>::default())))
}