Skip to content

Added 3d2scad.py to convert 3MF and STL files to SCAD #1738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025

Conversation

amatulic
Copy link
Contributor

@amatulic amatulic commented Jun 26, 2025

This Python utility takes a STL or 3MF file as input, and does these things (in this order):

  • creates list of vertices and faces as the mesh is loaded
  • separates object into shells if multiple objects are detected
  • removes invalid triangles
  • optionally simplifies mesh (reduces polygon count) using quadric decimation (a robust method of simplification)
  • attempts repairs if a shell is detected as non-watertight (fill holes, remove unreferenced vertices, fix inversion and winding order, remove duplicate faces)
  • ensure normals are consistently pointing outward
  • quantizes coordinates to nearest 0.001 (or whatever you specify) for more compact output
  • removes zero-area triangles
  • removes duplicate vertices for significant size reduction (often a STL vertex is repeated six times)
  • another pass of removing unreferenced vertices
  • removes shared edges from coplanar polygons

In some cases, the operations above can result in non-manifold shapes, such as when two objects share an edge, the resulting edge may be shared by more than two faces.

The output .scad file has the form:

model0 = [ <vertex array>, <polygon array> ];

This is compatible with BOSL2's vnf_polyhedron(). That is, to render:

include <BOSL2/std.scad>
vnf_polyhedron(model0);

If more than one shell is in the original STL or 3MF file, then the output file has separate parts, labeled model0, model1, model2, and so on. The model string is the root name of your output file.

This Python script requires several libraries not typically installed with Python. The script prompts you to install them if any are missing.

@adrianVmariano adrianVmariano merged commit 821f80f into BelfrySCAD:master Jun 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants