Skip to main content

Module preview

Module preview 

Source
Expand description

3D preview of CAD files – pure Rust, no browser plug-ins or downloads.

The server converts a file once into the compact mesh of crate::mesh and caches it next to the vault (previews/ab/<sha256>.v<N>.tcm); the browser (shared/js/viewer.js) and the desktop app only draw it. Meshes, point clouds, STEP B-reps (tessellated with the truck kernel) and simulation results (VTK, VTU/VTP, CalculiX FRD with result fields, see crate::simmesh) are supported, see PreviewFormat.

The conversion never blocks the web server: it runs in a separate teamcraft preview-mesh process with a time limit (in tests, where there is no such binary, on a blocking thread), at most MAX_PARALLEL at a time, and concurrent requests for the same file share one conversion. Failures are cached as well, so a broken file is not converted again and again.

Structs§

PreviewLimits
Size and memory limits of the preview (TEAMCRAFT_PREVIEW_MAX_*).
Previews
Cached, isolated conversions (one per server, part of AppState).

Enums§

CacheEntry
What a file in the preview cache (previews/ab/…) is, by its name.
PreviewFormat
3D formats the preview understands.

Constants§

CACHED_MESH
--format of teamcraft preview-mesh for an already converted preview mesh (only its shape signature is computed).
CACHE_VERSION
Bump to invalidate every cached preview (reader fixes, new format). Bump shape::VERSION with it: the shape signatures stored in the database are computed from these meshes. 3: Inventor files with Zstandard segments (#271), cached as failed before. 4: Creo parts in millimetres (inch parts were 25.4 times too small), turned Creo parts.
MAX_PARALLEL
Conversions that run at the same time.
MAX_RENDERS
Thumbnails drawn and assembly previews composed at the same time (Previews::render): each keeps one CPU busy and holds its meshes in memory.

Functions§

cache_entry
Classifies a file name of the preview cache: the meshes and failures of this module (<sha256>.v<N>.tcm|err), their shape signatures (<sha256>.v<N>.s<M>.json) and the thumbnails of crate::thumbnail (<sha256>.thumb.v<N>.png|bmp|jpg|none); every temporary name ends in .tmp.
convert
Reads the file at input as a preview mesh.
convert_file
Converts the file at input (tests and tools).
convert_within
Like convert; a file above max_bytes is refused before it is opened.
limit_memory
Limits the address space of this process (the preview child), so a file that needs more memory fails cleanly instead of taking the server host down. Linux and macOS; elsewhere (Windows) the limit is not enforced. Returns whether a limit is in force.
run_job
One job of the preview process (teamcraft preview-mesh): converts input into the preview mesh at output and/or writes the shape signature (a shape::Outcome as JSON) to signature. With CACHED_MESH as format, input is a cached preview mesh. A failed signature does not fail the conversion – the outcome records why. The mass properties (a massprops::Outcome as JSON) go to mass the same way. Returns the mesh (the CLI prints its size).
worker_exe
The teamcraft binary that runs isolated jobs (preview-mesh, text-extract); None in tests and other binaries, which run them in-process. The desktop downloads with local server ship the same binary as teamcraft-server (crate::localserver::SIDECAR_NAME): next to the app’s own TeamCraft executable, teamcraft would be the same file name on Windows and macOS.