Blog · · Andrii Shylenko

Import a closed PLY polygon mesh as a solid

lib.fromPLY(path) imports a closed ASCII or binary little-endian PLY polygon mesh as faceted B-rep geometry. The result supports booleans, volume, mass properties and export:

const bracket = await lib.fromPLY('./l-bracket.ply');
const drilled = bracket.subtract(cylinder(7, 2).translate(25, 5, -1));
return drilled;

Relative paths resolve from the .kcad.ts script directory. PLY has no standard length unit, so KernelCAD reads coordinates as millimetres; scale the result if the source used another unit.

The supported PLY 1.0 subset contains vertex and face elements in that order. Vertices need scalar x, y and z properties. Faces need a vertex_indices or vertex_index list. Additional scalar vertex or face properties such as colour, normal and material values are ignored. Planar simple polygons are ear-clipped in their own plane, including non-convex caps. Non-planar or self-intersecting polygons, unsupported elements, big-endian files, and open, non-manifold or inward-facing meshes are refused instead of being silently changed. { tolerance } sets the vertex-weld distance (default 1e-6 mm) and { maxTriangles } caps the triangle count after triangulation (default 200000).

The retained L-bracket fixture has 8 polygon faces, including two non-convex caps. Local API replay and OCCT recompute measured 20 triangles, one valid solid, 3000 mm³ volume, 1900 mm² surface area and 40 × 30 × 5 mm bounds. A 4 mm through hole removes 20π mm³ and leaves one valid solid. These are measurements for this fixture, not guarantees for arbitrary PLY files.

PLY import preserves triangle facets, not analytic source surfaces or feature history. Prefer lib.fromSTEP or lib.fromBREP when an exact source is available. See the demo bundle for the replay source, measured geometry, and inspected MP4. The capture demonstrates local API replay and OCCT B-rep recompute; it does not show solver simulation, deployed behavior, or hardware acceptance.