dear-implot3d 0.23.0

High-level Rust bindings to ImPlot3D with dear-imgui-rs integration
Documentation

dear-implot3d

Crates.io Documentation

High-level Rust bindings for ImPlot3D, integrating with dear-imgui-rs.

This crate sits on top of dear-implot3d-sys (FFI to cimplot3d) and mirrors the ergonomics of dear-implot.

Links

Compatibility

Use Rust 1.95 or newer and keep all dear-* dependencies on the 0.23 release train. See the 0.23 migration notes.

Item Version
Crate 0.23.0
dear-imgui-rs 0.23.0
dear-implot3d-sys 0.23.0

WASM (WebAssembly) support

For the experimental wasm32-unknown-unknown target, enable wasm on both direct dependencies.

[dependencies]
dear-imgui-rs = { version = "0.23", features = ["wasm"] }
dear-implot3d = { version = "0.23", features = ["wasm"] }

From the matching workspace checkout, build the demo and its imgui-sys-v1 provider with the checked-in bindings.

cargo run -p xtask -- web-demo implot3d
cargo run -p xtask -- build-cimgui-provider
python -m http.server -d target/web-demo 8080

The 0.23 browser application uses WasmProviderAllocator and imports the provider's memory and function table. Rebuild and deploy both modules together when upgrading from 0.22. See the tool versions and local demo and application setup.

Features

  • Safe, idiomatic Rust API - Type-safe wrappers over the C API
  • Builder pattern - Fluent API for configuring plots
  • Scoped plots - Separate setup and drawing closures with automatic native cleanup
  • Type-safe flags - Using bitflags! for compile-time safety
  • Modular plot types - Separate modules for each plot type
  • f32/f64 support - Separate functions for different numeric types
  • Optional mint support - Interoperability with math libraries (glam, nalgebra, cgmath, etc.)
  • Predefined meshes - Cube, sphere meshes included
  • Comprehensive API - Line, scatter, surface, triangle, quad, mesh, image, and text plots

Quick Start

Create Plot3DContext once alongside your ImGui context. Call the drawing function from an initialized frame.

use dear_imgui_rs::Ui;
use dear_implot3d::*;

fn draw(ui: &Ui, context: &Plot3DContext) {
    let plot_ui = context.get_plot_ui(ui);
    plot_ui.begin_plot("3D Demo").size([600.0, 400.0]).build_with_setup(
        |setup| {
            setup.setup_axes("X", "Y", "Z", Axis3DFlags::NONE, Axis3DFlags::NONE, Axis3DFlags::NONE);
        },
        |plot| {
            let xs = [0.0, 1.0, 2.0];
            let ys = [0.0, 1.0, 0.0];
            let zs = [0.0, 0.5, 1.0];
            plot.plot_line_f32("Line", &xs, &ys, &zs, Line3DFlags::NONE);
        },
    );
}

Use .build(|plot| { ... }) for a plot with default axes. With .build_with_setup, the first closure receives &Plot3DSetup and the second receives &Plot3DScope. Submit each Plot3D item with .plot(plot) or .try_plot(plot). Both builders return None when the plot is skipped. The builder ends each open plot in its original window and table cell, including on unwind.

Examples

Start with examples/03-features/implot3d_minimal.rs for a copy-ready integration. See examples/03-features/implot3d_showcase.rs for the comprehensive demo that mirrors the official ImPlot3D C++ demo.

Run either target with:

cargo run -p dear-imgui-examples --bin implot3d_minimal --features implot3d
cargo run -p dear-imgui-examples --bin implot3d_showcase --features implot3d

Predefined Meshes

The meshes module provides ready-to-use mesh data. Submit it inside the plot's drawing closure.

use dear_implot3d::meshes::*;

plot_ui.begin_plot("Meshes").build(|plot| {
    plot.mesh("Cube", CUBE_VERTICES, CUBE_INDICES).plot();
    plot.mesh("Sphere", SPHERE_VERTICES, SPHERE_INDICES).plot();
});

For application-supplied indices, plot.mesh(label, vertices, indices).try_plot() returns a Plot3DError if the mesh cannot be submitted.

Mint Support

When the mint feature is enabled, you can use mint::Point3<f32> types:

use mint::Point3;

let points = vec![
    Point3 { x: 0.0, y: 0.0, z: 0.0 },
    Point3 { x: 1.0, y: 1.0, z: 1.0 },
];

plot.plot_line_mint("Line", &points, Line3DFlags::NONE);

Item Styling

Spec-backed plot builders expose a shared per-item styling surface through Plot3DItemStyle / Plot3DItemStyled, plus common item flags through Plot3DItemFlagged:

use dear_implot3d::*;

let line = Line3D::f32("Line", &xs, &ys, &zs)
    .with_line_color([0.15, 0.70, 0.35, 1.0])
    .with_line_weight(2.0)
    .with_marker(Marker3D::Auto)
    .with_marker_size(4.0)
    .with_item_flags(Item3DFlags::NO_LEGEND);

line.plot(plot);

plot
    .surface_f32("Surface", &grid_x, &grid_y, &grid_z)
    .with_fill_alpha(0.35)
    .with_line_color([0.95, 0.95, 0.95, 1.0])
    .plot()
    .expect("valid surface grid");

Surface axis inputs are validated and expanded to one X/Y value per Z sample in row-major order. For callers that already own contiguous per-vertex arrays, use the allocation-free safe surface_f32_flat path. Custom offsets and strides are available only through the explicitly unsafe surface_f32_raw escape hatch.

plot.set_next_line_style, set_next_fill_style, and set_next_marker_style apply to the next item in that open plot. Use plot_ui.with_style_vars(&[Plot3DStyleVar::FillAlpha(0.5)], || { ... }), with_style_colors, or with_colormap to override context style across several submissions or plots. These closures restore all pushed values on return or unwind.

Notes

  • The underlying C API comes from cimplot3d which depends on implot3d. Ensure git submodules are initialized with --recursive.

License

See workspace root.