Skip to content

Instantly share code, notes, and snippets.

@arnholm
Last active May 13, 2020 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnholm/49c52c130240184460668c281e8307c2 to your computer and use it in GitHub Desktop.
Save arnholm/49c52c130240184460668c281e8307c2 to your computer and use it in GitHub Desktop.
union()
{
translate([0, 0, 6])
scale([0.9842519685, 0.9842519685, 1])
import("floor.stl");
cube([50, 50, 6]);
}

Original problem using OpenSCAD to import an STL fils

union()
{
  translate([0, 0, 6])
  scale([0.9842519685, 0.9842519685, 1])
  import("floor.stl");
  cube([50, 50, 6]);
}

Error message Rendering Polygon Mesh using CGAL... ERROR: CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: e_below != SHalfedge_handle() File: /usr/include/CGAL/Nef_3/SNC_FM_decorator.h Line: 426

Fix the problem using AngelCADs polyfix utility:

$ polyfix floor.stl 

Parameters:
  input_file = floor.stl


polyhedron 0 ================= volume=10890.5, dtol=0.01, atol=1e-06, maxiter=10
iteration 0: vertices=92100 faces=30700
         warning: 1 zero area faces.
         warning: nonmanifold edges: uc(1)=92100 
         merged 76748 vertices
         removed 1 collapsed or zero area face
         split 1 face
         total changes=76750
         no warnings

iteration 1: vertices=15352 faces=30700
         total changes=0
         no warnings

Summary: 
         polyhedron 0: vertices=15352 faces=30700 : no warnings

Writing: floor_1.stl

... polyfix finished, time used: 0d 00h 00m 01s

Then import the repaired file into OpenSCAD and press F6

union()
{
  translate([0, 0, 6])
  scale([0.9842519685, 0.9842519685, 1])
  import("floor_1.stl");
  cube([50, 50, 6]);
}

The problem is now gone

Display the source blob
Display the rendered blob
Raw
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

@Kevigsp
Copy link

Kevigsp commented May 13, 2020

I installed Angelcad and vcredist_X64 for the mscv dll
Angelcad starts but if i enter the above code:
$ polyfix floor.stl

       Parameters:
            input_file = floor.stl

i get an error:
as_csg started.
asERR : (line 1, col 1) : Unexpected token '' : asFILE=C:/Users/Henk/Documents/floor.as
asERR : Please correct the errors in the script and try again.
asINFO: (line 0 , col 0 ) : Script execution failed.

what am i doing wrong?

windows 10, x64
the floor.stl file in:
documents
documents\xcsg
c:\programfiles\angelcad
C:
and tried with the path in the name (c:\floor.stl)

henk

@arnholm
Copy link
Author

arnholm commented May 13, 2020

Polyfix and Angelcad are 2 different executables (polyfix is installed alongside AngelCAD though). You must run polyfix from the command line, outside AngelCAD.

This gist is about running polyfix to fix a bad STL. The .scad scripts shown here are for OpenSCAD.

The error you describe is from "as_csg" which is AngelCADs language interpreter. If you want to import the file into AngelCAD you must first use polyfix to convert/fix the original STL into .off or .obj format

polyfix floor.stl -out=floor.off
Parameters:
    input_file = floor.stl
    out = floor.off

Then you can import it in AngelCAD

floor_angelcad.as

// AngelCAD code.
shape@ main_shape()
{
   return polyhedron("floor.off");
}

void main()
{
   shape@ obj = main_shape();
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:-1.0);
}

For general support questions relating to anything AngelCAD, consider using the AngelCAD forum at https://forum.abmesh.com/

@Kevigsp
Copy link

Kevigsp commented May 13, 2020

thanks,
just tried running from command prompt and it works like a charm!
where can i find (if there are any) other parameters for polyfix?

rgrds
Henk

@arnholm
Copy link
Author

arnholm commented May 13, 2020

Just type on command line (without any parameters)

polyfix

then you get

Usage: polyfix [-verbose] [-maxiter <str>] [-dtol <str>] [-atol <str>] [-lumps] [-nflip] [-remesh <str>] [-overwrite] [-out <str>] [-zip]  <input_filename>
  -verbose              Verbose messages
  -maxiter=<str>        [heal]          Max iterations (def=10)
  -dtol=<str>           [heal]          Distance tolerance (def=1.0E-2)
  -atol=<str>           [heal]          Area tolerance (def=1.0E-6)
  -lumps                [heal]          Split into lumps (not supported for stl output)
  -nflip                [heal]          Flip faces with inward normals (experimental)
  -remesh=<str>         [remesh]        Heal & remesh surfaces to given edge length (set dtol to small value ~1.E-6)
  -overwrite            [output]        allow file overwrite, including input file.
  -out=<str>            [output]        output filename/format (.obj, .off, .amf, .stl, .astl)
  -zip                  [output]        save output also to compressed zip file

@Kevigsp
Copy link

Kevigsp commented May 13, 2020

thank again,
this is very helpfull an solved a lot of troubles for me

rgrds
Henk

@arnholm
Copy link
Author

arnholm commented May 13, 2020

You are welcome, please tell your friends/colleagues about the software so it becomes better known.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment