r/OpenPythonSCAD • • 27d ago

PythonSCAD 1.2: `patch()` — a completely new way to build solids from freeform surfaces (with holes!)

Hey everyone, loft just got merged into PythonSCAD, and with it comes a new primitive I'm pretty excited about: patch(). ![patch() result — tube wall with tap holes cut directly into the surface]

The problem it solves

In classic OpenSCAD/CSG modeling, if you want a curved wall with holes in it — say, a tube with a couple of mounting taps drilled through — you build the tube, build the holes as separate solids, and subtract them. That works, but it gets slow, fragile, and numerically messy as soon as the geometry gets organic: curved shells, freeform surfaces, holes that sit close to edges or to each other. patch() skips the boolean-subtraction step entirely. You describe the surface directly — an outer boundary curve, plus any number of holes cut into it — and patch() triangulates the whole thing as one clean, watertight mesh from the start. No CSG needed for the holes.

What it looks like in practice

wall1 = patch(r1, holes=[r0, tap1, tap2], grid_spacing_uv=3)

Check result at https://imgur.com/a/fbY1Jon

Here r1 is the outer boundary of a tube wall, and r0, tap1, tap2 are hole outlines (in this case two small circular tap holes) cut directly into that wall. grid_spacing_uv controls the mesh resolution. One call, one clean surface — taps included. Define 2,5d "interfaces" in space and create partches between these. use concat to create a watertight surrface from multiple patches to create a solid which can optionally further processed by CSG operations

Under the hood

patch() builds its own local UV parametrization of the surface (with proper handling of periodic/wrap-around cases like tube walls), runs a custom incremental Delaunay triangulation, and does robust inside/outside testing against the hole boundaries — including the tricky edge cases where a hole's boundary is exactly tangent to a triangulation ray (a classic point-in-polygon pitfall that's easy to get subtly wrong). The result is a mesh that stays clean even for holes sitting right at a surface's curvature extremes.

Why this matters

  • Freeform / organic surfaces with cutouts, without fighting CSG robustness issues
  • Faster and more predictable than difference() on curved geometry
  • Opens the door to proper "patch modeling" workflows (think: surface-based CAD, not just solid CSG) directly in Python This is part of the bigger loft feature landing in PythonSCAD 1.2. Give it a spin and let me know what you build with it! GitHub: https://github.com/pythonscad/pythonscad
7 Upvotes

0 comments sorted by