# Mesh viewer

The mesh viewer displays MED meshes in VS Code with every named group of the file: volume groups (shown as the skin of each 3D sub-domain), face groups, edge groups and node groups. It is built on VTK.js. The extension reads MED files itself, so the viewer needs no Python and nothing to install, on any platform.

![The mesh viewer](/assets/viewer-screenshot.png)

## Opening it

- **From a MED file**: open any `.med`, `.mmed` or `.rmed` file. It opens directly in the viewer (the **MED Mesh Viewer** editor).
- **From a `.comm` file**: click the eye icon **Open visualizer** in the editor title bar, or **Open mesh viewer** in the sidebar's Quick actions. The extension looks for a `.export` in the folder of the `.comm` and its parents (up to the workspace root), and loads every MED input (`F *med … D`) it declares. The viewer opens beside the editor and comes back when you return to that `.comm`.

Possible messages: "No .export file found for: …", "The file "X" mentioned in "Y" does not exist." and "No .export file references any input med file associated with …".

The first time a mesh is opened it is converted for display ("Creating .obj file for: X"), and the result is cached. Large meshes load progressively ("Parsing…", then "Building scene…"). Mixed solid, shell and beam meshes are displayed whole.

### MED files with other extensions

code_aster also writes MED data under numeric extensions matching the unit, such as `.21` or `.71`. Add them to `vs-code-aster.medFileExtensions` to open them in the viewer. The extension helps:

- When a file with an unknown extension is recognised as MED, it asks "`<file>` looks like a MED mesh file. Add .xx to the MED extensions list?" with **Add .xx and open**, **Not now** and **Don't ask for .xx**.
- **Open as MED mesh** in the editor title bar or the explorer context menu adds the extension and opens the file.

The list is kept in sync with `files.associations`, and files with these extensions are redirected to the viewer when opened as text.

## Objects and groups

The sidebar lists each loaded mesh (object) with its groups, bucketed by kind (volumes, faces, edges, nodes) or in one list.

- **Highlight**: click a group name. The object it belongs to fades (see Group selection transparency in the settings) so the group stands out. Click again to remove the highlight. **Clear highlighted groups** (the icon button) removes all of them.
- **Browse with the arrow keys**: after clicking a group, `↑` and `↓` turn it off and highlight the previous or next group of the list, in the order shown (search and filters included). Turn this off with **Arrow keys move between groups** in the Groups tab of the settings, or `vs-code-aster.viewer.groupArrowKeys`.
- **From the `.comm`**: select a group name in the editor to highlight it. Selecting a mesh name shows that object alone.
- **Search groups…**: filters the list as you type (case-insensitive).
- **Select groups to show in sidebar**: opens the "Sidebar groups" popup to choose which groups are listed (**Show all**, **Hide all**, **Reset**).
- **Hide/show mesh**: the eye button of an object. Hidden objects stay visible as a ghost when `vs-code-aster.viewer.hiddenObjectOpacity` is above 0. Right-click it for **Hide all other objects**.
- A counter shows the real element and node counts of the mesh.

## Camera

| Action | Control |
| --- | --- |
| Rotate | Left drag |
| Roll around the view direction | `Ctrl` or `Alt` + left drag |
| Pan | `Shift` + left drag |
| Zoom | Mouse wheel, or `Shift` + `Ctrl`/`Alt` + left drag |
| Align with an axis | The `X`, `Y` and `Z` buttons at the bottom of the sidebar |

The zoom widget has presets (0.5× to 10×) and **Reset zoom**. An orientation widget shows the axes in the corner.

## Toolbar

- **Bounding box**: a wireframe box with colored axes (X red, Y green, Z blue), corner dots and dimension labels, to read the size of the part.
- **Wireframe**: switch between solid and wireframe rendering to inspect the mesh density.
- **Auto-rotate**: turntable rotation around the current vertical. Right-click for **Rotation speed** (5 to 180 °/s) and **Reverse direction**, for the current view only.
- **Screenshot**: saves the view as a PNG and copies it to the clipboard. Right-click for **Screenshot whole screen** (with the toolbar and sidebar).
- **Record**: records a video (mp4 when supported, webm otherwise). Click again to stop. Right-click for **Record whole webview** or **Record without sidebar**. The button shows the elapsed time while recording.

A toolbar click changes the current view only. Defaults are set in the viewer settings.

## Viewer settings

The settings popup has four tabs, each with its own reset, and **Reset defaults**:

- **Rendering**: mesh edge display (`edgeMode`, `edgeThresholdMultiplier`), orientation widget, frame rate counter (off by default; shows the frames drawn per second under the element counter, or idle when the view is still), dream background (animated EDF colors behind the mesh).
- **Groups**: edge group thickness and depth offset, node group size, sidebar order, grouping by kind, and browsing with the arrow keys.
- **Visibility**: opacity of hidden objects, transparency of an object when one of its groups is highlighted.
- **Toolbar**: default state of the bounding box, wireframe and auto-rotate, default speed and direction.

Every change is saved to the matching `vs-code-aster.viewer.*` setting in your user settings (see [Configuration](/configuration)). The **Help** popup summarises the controls (Camera, Toolbar, Objects, Groups, Files, About).

## Files the viewer writes

A hidden `.vs-code-aster/` folder is created:

- `mesh_cache/` in the folder of the MED file: the converted meshes, reused on the next open and regenerated when the converter changes.
- `screenshots/` and `recordings/` in the folder of the opened MED or `.comm` file: `screenshot-<date and time>.png` and the videos.
