GPUI Box GitHub

Components / media

ModelViewer builder

A bounded viewer for one 3D model.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::media::ModelViewer;

Reviewed in model-viewer.

Construct
new(ident: impl Into<Ident>) -> Self
Options

Chain onto the value.

title(title: impl Into<SharedString>) -> Self
state(state: ModelState) -> Self
scene(scene: Rc<ModelScene>) -> Self
rejected(error: ModelError) -> Self
loading() -> Self
shading(shading: ModelShading) -> Self
orbit(yaw: f32, pitch: f32) -> Self
height(height: f32) -> Self
on_event(handler: impl Fn(&ModelViewerEvent, &mut Window, &mut App) + 'static) -> Self
Reports

The variants of the event it emits. It never applies the change itself.

  • OrbitChanged
  • ShadingChanged
Example · model-viewer
fn model_viewer(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    let read = || ModelState::read(CUBE, ModelBounds::default());
    stack(&theme)
        .w(px(720.0))
        .child(
            div()
                .row()
                .items_start()
                .gap(px(theme.spacing.lg))
                .child(
                    div().flex_1().min_w_0().child(
                        ModelViewer::new("scene.model.flat")
                            .title("cube.gltf")
                            .state(read())
                            .orbit(0.62, 0.42)
                            .height(240.0)
                            .on_event(|_, _, _| {}),
                    ),
                )
                .child(
                    div().flex_1().min_w_0().child(
                        ModelViewer::new("scene.model.wireframe")
                            .title("cube.gltf")
                            .state(read())
                            .shading(ModelShading::Wireframe)
                            .orbit(0.62, 0.42)
                            .height(240.0)
                            .on_event(|_, _, _| {}),
                    ),
                ),
        )
        .child(
            Divider::new()
                .id("scene.model.rule.refused")
                .label("A document past a bound"),
        )
        .child(
            ModelViewer::new("scene.model.refused")
                .title("city-block.glb")
                .rejected(ModelError::TooLarge {
                    limit: ModelLimit::Triangles,
                    found: 412_930,
                    allowed: 24_576,
                })
                .height(160.0)
                .on_event(|_, _, _| {}),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/media/model_viewer.rs