---
title: "Recipe: a 3D model viewer"
description: "@exact/model-viewer draws a GLB model on a canvas, with camera controls, preset views, picked parts, hotspot labels and see-through shells."
modificationDate: "2026-11-18"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: a 3D model viewer

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/model-viewer: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

Run `bun exact.mjs add <exact2>/packages/model-viewer`.
Copy [assembly.glb](https://github.com/expo/exact/blob/41ded8c5ede0b2959ef0daa83b1ff78545dd4428/packages/model-viewer/test/fixture/assets/assembly.glb)
into your app's `assets/`. For a new app, replace its starter `app.ts` with
[this empty data module](https://github.com/expo/exact/blob/41ded8c5ede0b2959ef0daa83b1ff78545dd4428/packages/fixtures/sky/test/fixture/app.ts).
Write:

```prompt Show a 3D model in my app
Add a 3D model viewer to the Exact app in this folder: a glTF model with a camera, picking and labels. Use https://github.com/expo/exact/blob/main/docs/recipes/model-viewer.md as the source for each step. The Exact checkout has the same page at docs/recipes/model-viewer.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me. Find the Exact checkout (the folder with scripts/exact.mjs); if you cannot find it, ask me where it is.
2. If I did not give a GLB file, or did not say which parts a person can pick and which views the app offers, ask me before you write code. If I have no file, offer the recipe's `assembly.glb` (`packages/model-viewer/test/fixture/assets/` in the Exact checkout).
3. Install the package: `bun exact.mjs add <exact2>/packages/model-viewer`. Copy the GLB into the app's `assets/`. A URL as `src` is refused: for a downloaded GLB, bind its `app:/data/`, `app:/cache/` or `app:/tmp/` path.
4. In app.contract, import `ModelNode`, `ModelHotspot` and `ModelViewerState` from `@exact/model-viewer`, and place a `canvas` with the `modelViewer` surface as the recipe shows, with a size, `role="group"` and an `aria-label`. Write `cameraControls=true` for orbit and zoom. Handle a pick with `message=`: the action gets a mesh node name, or `""`.
5. Style parts with `nodes`, and label them with `hotspots`: a hotspot matches a direct child of the canvas by `testId`. Give each hotspot button the same picking action as the model. Add view buttons that set `cameraOrbit` and run `postMessage("reset", "modelViewer")`.
6. Read `exactSurface("modelViewer")` as a resource. Show a loading text while `presented` is false, and show its `error`. Controls reserve touches and wheels at mount: leave room beside the canvas to scroll.
7. Add a test in app.test.contract that taps a hotspot button and expects the picked name.
8. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. Also build with `bun exact.mjs web-build` or `EXACT_IDENTITY=- bun exact.mjs mac`, run `bun exact.mjs agent web "clock settle" state` (or `macos`), and confirm that the model is presented with no error. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 9) and report it; do not keep trying.
9. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
10. Tell me the model, its parts, hotspots and views, what the tests and checks reported, and the launch command for each target platform.
```

```contract
use ModelNode, ModelHotspot, ModelViewerState from "@exact/model-viewer"

component App
  state picked = ""
  state orbit = "0deg 90deg 105%"
  state clipped = false
  resource viewer = exactSurface("modelViewer") as shape ModelViewerState
  action pick(name: string)
    picked = name
  action front
    orbit = "0deg 90deg 105%"
    postMessage("reset", "modelViewer")
  action top
    orbit = "0deg 0deg 105%"
    postMessage("reset", "modelViewer")
  action reset
    postMessage("reset", "modelViewer")
  action toggleClip
    clipped = not clipped
  view
    column gap=8 padding=8
      canvas surface=modelViewer(src="assets/assembly.glb", cameraControls=true, cameraOrbit=orbit, cameraTarget="0m 0m 0m", fieldOfView="30deg", nodes=[ModelNode(name="Housing", color="", opacity=1, visibility="visible", occlusion="occluder", occludedOpacity=0.3), ModelNode(name="Impeller", color="#0080ff", opacity=1, visibility="visible", occlusion="revealed", occludedOpacity=0.3)], hotspots=[ModelHotspot(child="inlet", node="Inlet", position="0m 0.8m 0.85m", normal="0 0 1")], clipPosition="0m 0m 0m", clipNormal=(clipped ? "0 0 -1" : "")) message=pick width=320 height=320 flex-shrink=0 role="group" aria-label="Pump assembly" testId="pump"
        if not viewer.presented
          text "Loading model" position="absolute" inset=0 aria-busy=true testId="loading"
        button "Inlet" press=pick("Inlet") position="absolute" testId="inlet"
      row gap=8
        button "Front" press=front testId="front"
        button "Top" press=top testId="top"
        button "Reset" press=reset testId="reset"
        button "Clip" press=toggleClip testId="clip"
      text picked testId="picked"
      text viewer.error testId="error"
      text viewer.cameraOrbit testId="camera-orbit" font-variant-numeric="tabular-nums"
```

`cameraOrbit` is azimuth, polar angle, radius; `105%` frames with a margin.
`nodes` style subtrees: `revealed` parts fade behind opaque `occluder` shells.
For a translucent shell, use `occlusion="none"` and `opacity` below 1.

Hotspots match direct children by `testId`; hidden anchors hide their labels.
Picks return a mesh node name, or `""`.

Bind a downloaded GLB's `app:/data/`, `app:/cache/` or `app:/tmp/` path
as `src`; direct URLs are refused. Meshopt and quantization are supported.

`viewer` gives loading, errors, nodes and the settled camera to save.
Its record is the first live viewer's. Controls reserve touches and wheels
at mount; leave room beside the canvas to scroll.

Build with `bun exact.mjs web-build` or `EXACT_IDENTITY=- bun exact.mjs mac`;
run `bun exact.mjs agent web "clock settle" state` (or `macos`).
See [values and limits](https://exact.expo.dev/learn/contract-for-agents/views-layout-and-interaction.md#model-viewer).
