Blog · · Andrii Shylenko
Import a closed OBJ mesh as a solid
lib.fromOBJ(path) imports a closed Wavefront OBJ polygon mesh as faceted B-rep geometry. The result accepts booleans, volume, mass properties and export, like a closed lib.fromSTL or lib.from3MF import:
const bracket = await lib.fromOBJ('./l-bracket.obj');
const drilled = bracket.subtract(cylinder(7, 2).translate(25, 5, -1));
return drilled;
Relative paths resolve from the .kcad.ts script directory. OBJ declares no unit, so coordinates are read as millimetres; scale the result if the source used another unit.
OBJ faces can have more than three corners. Each polygon is ear-clipped in its own plane, so a non-convex face such as the cap of an L or U profile keeps its shape. A polygon that is not planar has more than one possible triangulation, so it is refused; triangulate it in the source tool. Self-intersecting polygons are also refused.
Texture coordinates, normals, groups, smoothing and materials do not change the solid and are ignored. Point, line and free-form curve or surface statements are refused so that geometry is not silently dropped. The mesh must be closed, manifold and wound outward. Separate shells and sealed voids follow the 3MF import rules. { 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. In the local API and OCCT recompute capture, it imports as 20 triangles and one valid solid of 3000 mm³ and 1900 mm². A 4 mm through hole removes 20π mm³ and leaves one valid solid. These are measured results for this fixture, not guarantees for arbitrary OBJ files.
OBJ 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.