BREP_stream_client 0.1.0

Embed the next.BREP.io CAD application in a Rust program: launch `brep-app --stream` headless (or connect to one), receive its whole window as RGBA frames and drive it with pointer, keyboard and touch input. No browser and no GUI toolkit required.
Documentation

BREP_stream_client — the BREP CAD application inside your Rust program

Part of the next.BREP.io Rust B-rep kernel: cargo add BREP_stream_client · licence summary

brep-app --stream runs the next.BREP.io CAD application with no window and no display, and streams its whole user interface (menus, panels, dialogs, the 3D view) while taking every input. This crate is the native end of that stream: start the app from Rust, get its picture as RGBA pixels, and send it pointer, wheel, keyboard, text, clipboard and touch input. Show the pixels in any GUI toolkit's window, or in none. No browser is involved.

Quick start

The CAD application must be installed: cargo install BREP_app puts brep-app on your PATH (or use the desktop download from next.brep.io and give its path).

use brep_stream_client::{Input, Launcher, Mods, PointerButton};
use std::time::Duration;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Start the app headless at 1280 x 800 logical pixels, density 1.
    let session = Launcher::new("brep-app").size(1280.0, 800.0, 1.0).launch()?;
    session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;

    // Click its File menu, and wait for the picture to change.
    let (x, y) = (148.0, 19.0);
    session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
    session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
    session.wait_frame(Duration::from_secs(10))?;

    let frame = session.frame();
    println!("{} x {} pixels, {} frames", frame.width, frame.height, frame.frames);
    Ok(())
} // dropping the session ends the app

In a window

A complete eframe (egui) program is on next.brep.io/developers/embedding.html: its own side panel, and the CAD session in the rest of the window, drawn 1:1 at the screen's density, following the window's size, with the pointer, wheel, keys, typed text, the clipboard, touch and the cursor shape passed through. Put it in src/main.rs of a project with this crate and eframe 0.35.

The pattern carries to any toolkit:

  1. Launcher::new(path).size(w, h, density).launch() starts the app in a child process (--stream 127.0.0.1:0, a private token file, and --stream-until-stdin-closes, so the app never outlives your program).
  2. session.set_waker(...) asks your UI to repaint when a frame arrives.
  3. Each repaint, session.take_update() says which rectangle changed (or that the size did); copy that part of session.frame().rgba into your texture.
  4. Send what happens over your view with session.send(Input::...), in logical pixels from the view's corner; call session.resize(w, h, density) when the view's size or the screen's density changes.
  5. Handle session.poll_events(): the cursor shape, copied text for your clipboard, links to open.

examples/snapshot.rs (cargo run --example snapshot -- /path/to/brep-app) does the same with no window: launch, click, and save the picture as a PNG.

Attaching to a running session

brep-app --stream ADDR can also run on its own (a server, a container), with a browser page at http://ADDR/stream/. Client::connect("ADDR", token, options) attaches to it, with the token from its token file; any number of clients (and browser pages) can watch, one controls, and take_control() switches. Plain ws:// only: reach a remote session through an SSH tunnel or a reverse proxy that ends TLS.

Licence

In plain words: the crates are free to use as they are, including in a commercial project. If you fix or change something in the kernel, send the change back as a pull request to github.com/mmiscool/next.BREP.io_RUST_BREP_KERNEL. If you do not want to share your changes, buy a commercial licence from Autodrop3d LLC; with it you never have to share your code back.

The exact terms are in LICENSE.md, shipped in the crate (license-file in the manifest) and at LICENSE.md; if this summary and the file ever differ, the file wins.