Blog · · Andrii Shylenko

Import a sealed cavity from 3MF

lib.from3MF(path) imports core 3MF triangle meshes as faceted B-rep geometry. It converts the model unit to millimetres, applies build and component transforms, and supports mesh instances in Production-extension model parts. An outward-facing mesh shell becomes a solid. An inward-facing shell that is strictly nested and classified inside an outward shell is retained as a sealed void of that solid:

const shell = await lib.from3MF('./sealed-cube.3mf');
const drilled = shell.subtract(cylinder(30, 1).translate(5, 5, -10));
return drilled;

Relative paths resolve from the .kcad.ts script directory. The retained fixture and generator contain a 10 mm cube and a 4 mm inward-wound cube shell, giving 3 mm walls. In the local API and OCCT recompute capture, the import measures 936 mm³ with one valid solid and two shells. The axial 2 mm bore removes 6π mm³ of wall material and leaves one valid solid. These are measured results for this fixture, not guarantees for arbitrary 3MF files.

The 3MF Core specification defines the Positive fill rule for triangle meshes. KernelCAD's supported cavity path requires closed, consistently oriented manifold shells. Shell hosting uses strict axis-aligned bounds and a point-in-shell test; shell-to-shell triangle intersections are not separately tested, and the assembled B-rep must pass OCCT validity checks. Touching or overlapping outer-shell bounds, nested void bounds, zero-volume shells, open or non-manifold meshes, non-mesh resources, and unsupported required extensions are refused.

3MF import preserves triangle facets, not analytic source surfaces or feature history. This local capture demonstrates API replay and OCCT B-rep recompute; it does not show solver simulation, deployed behavior, slicer acceptance, or hardware acceptance. See the demo bundle for the replay source, measured geometry, and inspected MP4.