---
name: mz-3d-viewer
description: Use MZ 3D Viewer to inspect local CAD or pressure files, embed the browser SDK, or verify changes to STEP streaming, WebGPU picking, navigation and offline loading in the viewer repository.
---

# MZ 3D Viewer

## Choose the entry point

| Task | Entry point | What to return or observe |
| --- | --- | --- |
| Inspect a user's model visually | Open the local file in the viewer. Drop an OBJ or glTF and its companion files together. Use Parts to isolate a component, or Measure for a distance or angle. | Report the model, source unit and selected entity. For an STL with unknown units, ask for the scale before reporting physical dimensions. |
| Read geometry or probe pressure | Import `readSurfaceData` and `probePressure` from `@mizy/mz-3d-viewer/data` in a browser. Pass a local `File`. | The CPU reader accepts STL, STEP, IGES, BREP and ASCII triangular pressure VTP. It returns part-local arrays, units and warnings and works without Three or a GPU adapter. |
| Embed a viewer or populate a Three scene | Import `createModelViewer` or `parseModel` from `@mizy/mz-3d-viewer`. Supply sibling assets through `viewer.load(files)` or the parser's `companions` option. | Keep the returned viewer for subsequent loads and call `dispose()` on unmount. A custom scene takes ownership of the parsed render resources. |
| Change the viewer | In the source checkout read `AGENTS.md` and `docs/architecture.md`. Trace the app from `src/main.ts` or the SDK from `src/lib/`. | Use the relevant browser check below and report what happened with the actual file. |

CAD files open with their authored body and face colors. The edge overlay uses CAD face boundaries and stays visible during navigation. Triangle-mesh formats open in solid mode. Use the separate wireframe display when inspecting triangulation.

For a numerical pressure probe, pass the source part, zero-based triangle index and point **in that part's coordinates**. Node pressure is interpolated and cell pressure is constant on its triangle. Return the field's declared unit alongside the reading. The bundled `samples/pressure/plate.vtp` gives **100 Pa** at `probePressure(dataset.parts[0], 0, [0, 0, 0])`. A bare STEP contains geometry. A matching pressure result must come from a field file.

In the web app, use Scene Settings → 保存截图 for a pressure PNG with its scale, unit and current probe. Where WebMCP is exposed, query `mz_model_info` for the active ID, units, pressure and paged parts, then `mz_probe_pressure` with that model ID, part, source triangle and local surface point. Both tools are read-only.

For a screenshot of an embedded viewer, await `viewer.stage.captureNextFrame()` for a full-resolution PNG data URL. The pressure legend is a separate DOM element. Record its range, unit and probe value with the image when reporting a pressure result.

The SDK resolves OpenCascade from its packaged `dist-lib/occt/`. If the consuming bundler relocates the JavaScript, serve the entire `occt/` directory locally and call `configureCadAssets({ baseUrl })` before the first CAD read. Preserve the typed arrays returned by the CPU reader as read-only. [SDK usage](https://github.com/mizy/mz-3d-viewer#use-it-as-a-package)

## Verify in the viewer source checkout

Use Node 24 and pnpm 12.18.0, as in CI. Run `pnpm install --frozen-lockfile`. For the checks that take a URL, run `pnpm build && pnpm preview` in a separate terminal and use its printed URL. The examples use the default preview port.

| Change | Focused check |
| --- | --- |
| CPU reader, SDK entry or packaged assets | `pnpm build:pkg && pnpm verify:package` exercises the built package in Chrome, including CPU-only imports. |
| Pressure colors, units or probes | `pnpm verify:pressure --url=http://localhost:8901/ --offline` checks colors and known point and cell readings. |
| Picking, wheel zoom, or navigation quality | `pnpm verify:inspection --url=http://localhost:8901/` for geometry and cursor anchoring. Use `pnpm verify:performance --url=http://localhost:8901/` for moving resolution, draw calls and idle restoration. |
| CAD circle, edge or planar measurements | `pnpm verify:measure-features --url=http://localhost:8901/ --offline` checks a 10 mm CAD cube, an inch circle, curved-face rejection and offline operation. For an original STEP, pass `--model=/path/to/file.step` and a matching analytic reference from `scripts/measure-desktop-step.py --mode circles`. |
| Section contours, caps or generated-face picking | `pnpm verify:section --url=http://localhost:8901/ --offline` checks a known solid with a through-hole, an open shell, two planes, source picks and cached offline assets. Pass `--model=/path/to/file.step` for a real assembly. |
| Window, crossing or overlapping CAD selection | `pnpm verify:selection-tools --url=http://localhost:8901/` checks both drag directions, clipping and choosing an occluded part. Add `--model=/path/to/large.step` for bulk highlighting and pointer-query timings. |
| Inspection views or oriented CAD sections | `pnpm verify:preprocessing --url=http://localhost:8901/` checks multi-select, batch display, an oblique face section and offline restore. Pass `--model=/path/to/assembly.step` to check an original assembly. |
| CAD explosion | `pnpm verify:explode --url=http://localhost:8901/ --model=/path/to/assembly.step` compares radial and planned bounds at 25%, 100% and 200%, and checks original transforms after reassembly. |
| Geometry health, automatic face groups or part clearance | `pnpm verify:geometry-checks --url=http://localhost:8901/` checks open mesh edges, source-color connectivity, finite clearance, contact and mesh interference offline. Pass the original GT8 back assembly as `--model` for its camera trims. |
| Assembly tree or visibility | `pnpm verify:entities --url=http://localhost:8901/` opens a nested STEP and a flat STL and exercises right-click hide/show in the tree and canvas. |
| Streaming or CAD batches | `pnpm verify:large-step --url=http://localhost:8901/` uses the generated assembly. For a real-file offline run use the command below. |
| Domain boundaries | `pnpm typecheck` checks TypeScript and the architecture import rules. |

For the 93 MiB regression, set `STEP_FILE` to the path of the user's original assembly, including its spaces. Run from the source checkout with the production preview already serving.

```sh
pnpm verify:large-step --url=http://localhost:8901/ --model="$STEP_FILE" --model-only --offline --check-stream
```

Add `--check-edge-visibility` to compare packed and individual segments after hiding and isolating parts. With `verify:performance --model="$STEP_FILE" --check-edge-visibility`, report draw calls, CPU submit time and frame intervals for the same rotation with one part hidden.

For a batching comparison, append `--member-states --save-states=/tmp/mz-before.json` on the baseline. Use the same file, CAD precision and camera on the candidate with `--member-states --compare-states=/tmp/mz-before.json`. Keep the baseline JSON and its adjacent PNGs together. Report first drawable frame, complete scene, source part and triangle counts, draw calls and exact picks. A warm reopen in the same tab uses an in-memory cache. Add `--disk-reopen` to verify a fresh tab uses OPFS and skips conversion. Compare native and fallback picking using `--measure-picks` and `--legacy-picks`. The offline test clears the HTTP cache and reloads after the service worker has cached the app and CAD engine.
