SzPreview3D
SzPreview3D is a self-contained VS Code extension for interactive finite-element
and scientific-mesh previews. Opening a supported file uses the 3D preview as
the default editor.
- VTK XML UnstructuredGrid (
.vtu): ASCII, inline binary, appended raw/base64,
and zlib-compressed arrays
- Legacy VTK (
.vtk): ASCII and classic big-endian binary unstructured grids;
polygonal surface data is also accepted
- AVS UCD (
.inp): ASCII and binary unstructured grids with point/cell data,
material IDs, tetrahedra, hexahedra, wedges, pyramids, triangles, and quads;
numbered .inp and .bin.inp files are exposed as time series
- Fastmag (
.dat, .ijk, .knt): raw binary point-field series backed by
Cub.knt/Cub.ijk, or mesh-only previews opened from either companion file
- XDMF (
.xdmf, .xmf): uniform unstructured grids and temporal collections
with inline XML, external binary, or HDF5 heavy data
The extension is TypeScript/JavaScript only. HDF5 support is bundled through
h5wasm; Python, ParaView, and a native VTK installation are not required.
Fastmag .dat, .ijk, and .knt previews are optional editors available
through Reopen Editor With…, so ordinary .dat files are not claimed by
default. A .dat preview searches its directory and then its parent directory
for Cub.knt and Cub.ijk.
Viewer features
- Tabbed 3D View and Analysis workspaces
- Straight and safe-expression parametric line definitions with configurable
sample counts, distance/parameter axes, and scalar or vector-component plots
- Lazy Morton BVH point location over original tetrahedra/hexahedra, exact
element containment, and finite-element interpolation of point fields
- Automatic exterior-face extraction for volume cells
- Triangle and quadrilateral boundary rendering
- Point- and cell-associated scalar/vector/tensor fields
- Vector magnitude or individual-component coloring
- Viridis, cool-to-warm, and grayscale maps
- Toggleable vertical scalar legend on the right with editable range, uniform
tick step, unit, and a twenty-tick limit
- Separate Settings and Inspect tabs; inspect vertices or elements by native
AVS ID or zero-based index
- Vertex coordinates, incident elements, cell/point field tables, and isolated
vertex/element highlight overlays without rebuilding the displayed mesh
- Surface, single-pass shader surface edges and edge-only rendering, and a unique-vertex point-cloud shader path
- Scalar thresholding of visible boundary faces
- Safe point-field and element expression filters that rebuild the volume boundary
- Interactive X/Y/Z clipping plane
- Opacity, line/point size, camera reset, and mesh statistics
- AVS UCD material IDs exposed as the
material_id cell field
- Compact one-row Blender-style bottom timeline with
first/previous/play/next/last controls, scrubber, frame/time readout, and a
completion-driven 1–60 FPS cap
- Typed point/element field calculator with scalar and vector expressions,
including cross-frame
frame(index, field) and prev(field) references
- Point-vector arrows placed at mesh nodes
- Cell-vector arrows placed at boundary-face centers
- Vector density, maximum-arrow count, normalization, relative length, and
magnitude/component coloring controls
- Vector scale and color ranges retained across loaded XDMF timesteps
For XDMF temporal collections, every supported uniform step is indexed. Time
values may come from each child grid or a collection-level List, HyperSlab, or
Range. The XML is pre-scanned into lightweight step and mesh descriptors, while
HDF5 geometry and fields remain lazy. Static topology and geometry declared on
the collection are inherited by its steps, and field-backed HyperSlab DataItems
are expanded in TypeScript.
Only one mesh is active at a time. Consecutive steps with the same canonical
geometry/topology key reuse coordinates, boundary faces, and vtk.js geometry;
only changing fields are loaded. Selecting a different mesh releases the active
buffers and loads the requested mesh on demand. Coordinates, connectivity,
boundary faces, owners, and field values use contiguous typed-array storage.
Large tetrahedral meshes are extracted in bounded cell partitions. Interior
faces are cancelled inside each partition, the remaining faces are gathered
into one contiguous array, and only that reduced array is globally sorted.
XDMF integer connectivity is also read from HDF5 in bounded chunks. This keeps
peak memory substantially below a full two-buffer global face sort.
Point-field filters can use x, y, z, and point-associated field names.
By default, coordinates and point fields are interpolated to each element
center and the complete element is retained when the expression passes.
Alternative modes retain elements touched by the matching region (any vertex)
or only elements fully inside it (every vertex). Element filters use
element-centroid x, y, z and cell-associated field names. Vector fields
expose their magnitude under the base name and components with .x, .y,
.z, or .w suffixes, such as data.x. Expressions support arithmetic,
^ exponentiation,
comparisons, &&, ||, !, parentheses, and common functions such as abs,
sqrt, min, and max. Filtered connectivity is fed back into the same
optimized tetrahedral/hexahedral boundary extractor, so newly exposed internal
faces are rendered. Spaces and punctuation in field names are represented by
underscores in expression variables. Across XDMF time steps, filtered
boundaries are reused when an expression depends only on coordinates or
time-invariant fields; filters using changing fields rebuild as required.
The field calculator creates point- or element-associated fields without
executing arbitrary JavaScript. Scalar broadcasting and vector arithmetic are
supported, along with mag, dot, cross, normalize, common math
functions, and component references such as data.x. For a time series,
frame(0, data) reads data from frame zero and prev(data) reads it from
the preceding frame (clamped to frame zero at the start). Derived fields appear
in scalar coloring, vector arrows, and filter-variable lists, and persist while
the timeline plays. Cross-frame evaluation reuses the active mesh and lazily
loads only referenced frame fields.
Development
Requirements: Node.js 22+ and npm 10+.
npm install
npm run check
npm test
Press F5 in VS Code to launch an Extension Development Host. Open a .vtu,
.vtk, .inp, .xdmf, or .xmf file; SzPreview3D is registered with default
priority. For .dat, .ijk, or .knt, use Reopen Editor With… and select
SzPreview3D (Fastmag).
Create an installable VSIX with:
npm run package
- Boundary extraction keeps a face only when it belongs to exactly one
supported volume element. Explicit triangle and quad surface elements are
preserved.
- Binary AVS UCD files may use little- or big-endian int32/float32 data; the
byte order is detected from the complete file layout.
- Vector glyphs accept fields with two or three components. Two-component
vectors are rendered in the XY plane.
- XDMF
Function DataItems, arbitrary polyhedra, and multiblock composition
are not yet supported. Spatial collections still display the first supported
uniform grid.
- Very large meshes can be limited with
szPreview3d.maxMessageSizeMB.