discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: STL best practices & tools

CA
Carsten Arnholm
Sun, Jun 4, 2023 4:40 AM

I imagine using an approach similar to that of my near-perfect retro
line-drawing algorithm,
in order to implement an STL cleanup tool which combines STL pieces
that "touch" into one solid
object.  ("Touch" within an epsilon value which is configurable.)

Hi, I wrote such a tool. It is called 'polyfix' and it is part of the
AngelCAD suite
https://github.com/arnholm/angelcad/releases/tag/V1.5-06

Regards
Carsten Arnholm

P.S: Good decision on the 'jab'. It is a crime against humanity

> I imagine using an approach similar to that of my near-perfect retro > line-drawing algorithm, > in order to implement an STL cleanup tool which combines STL pieces > that "touch" into one solid > object. ("Touch" within an epsilon value which is configurable.) Hi, I wrote such a tool. It is called 'polyfix' and it is part of the AngelCAD suite https://github.com/arnholm/angelcad/releases/tag/V1.5-06 Regards Carsten Arnholm P.S: Good decision on the 'jab'. It is a crime against humanity
NH
nop head
Sun, Jun 4, 2023 11:02 AM

I manage to make solid STL files without extra vertices or gaps. Yes
objects need to overlap to be unioned but once unioned they don't have
extra vertices if they overlap is in the right place.

Also cleaning up the STL isn't sufficient unless you have a deliberate gap
between objects because you can run into CGAL errors if objects share just
an edge instead of face, for example. Then bits of the model are missing.

On Sun, 4 Jun 2023 at 05:40, Carsten Arnholm arnholm@arnholm.org wrote:

I imagine using an approach similar to that of my near-perfect retro
line-drawing algorithm,
in order to implement an STL cleanup tool which combines STL pieces
that "touch" into one solid
object.  ("Touch" within an epsilon value which is configurable.)

Hi, I wrote such a tool. It is called 'polyfix' and it is part of the
AngelCAD suite
https://github.com/arnholm/angelcad/releases/tag/V1.5-06

Regards
Carsten Arnholm

P.S: Good decision on the 'jab'. It is a crime against humanity


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I manage to make solid STL files without extra vertices or gaps. Yes objects need to overlap to be unioned but once unioned they don't have extra vertices if they overlap is in the right place. Also cleaning up the STL isn't sufficient unless you have a deliberate gap between objects because you can run into CGAL errors if objects share just an edge instead of face, for example. Then bits of the model are missing. On Sun, 4 Jun 2023 at 05:40, Carsten Arnholm <arnholm@arnholm.org> wrote: > > I imagine using an approach similar to that of my near-perfect retro > > line-drawing algorithm, > > in order to implement an STL cleanup tool which combines STL pieces > > that "touch" into one solid > > object. ("Touch" within an epsilon value which is configurable.) > > Hi, I wrote such a tool. It is called 'polyfix' and it is part of the > AngelCAD suite > https://github.com/arnholm/angelcad/releases/tag/V1.5-06 > > Regards > Carsten Arnholm > > P.S: Good decision on the 'jab'. It is a crime against humanity > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
N
neri-engineering
Wed, Jun 7, 2023 5:04 PM

Thanks, I did find a Youtube video as well on AngelCAD: https://www.youtube.com/watch?v=h-qDzG9bwnQ

I downloaded your source code and have it on my filesystem.  I see it's C++.  Great.  I found the source code for polyfix, it's quite short, but may be using some other libs that you wrote.

Are there any tips/docs on how to use polyfix.  In the short term I want to pass in a single STL file and have it reconcile faces that are coplanar and overlapping by area, facing in opposite directions (relative to "outside").  This operation could be done on a single connected polyhedron which has "spikes" that touch or very nearly touch, as well.  I presume that an epsilon value is being used; I saw something in the source code.

Meanwhile I'm doing more independent investigation into what's going on behind the scenes in OpenSCAD, and why some simple cases are creating polyhedron that won't union()ize inside the STL.  I suspect that one of the problems might possibly be that a conversion from 64 bit float to 32 bit float is happening too soon.  I know from the STL spec that coordinates specified in STL are 32 bit float (from the best of my recollection - but I could check this again).

Sent with Proton Mail secure email.

------- Original Message -------
On Saturday, June 3rd, 2023 at 11:40 PM, Carsten Arnholm arnholm@arnholm.org wrote:

I imagine using an approach similar to that of my near-perfect retro
line-drawing algorithm,
in order to implement an STL cleanup tool which combines STL pieces
that "touch" into one solid
object. ("Touch" within an epsilon value which is configurable.)

Hi, I wrote such a tool. It is called 'polyfix' and it is part of the
AngelCAD suite
https://github.com/arnholm/angelcad/releases/tag/V1.5-06

Regards
Carsten Arnholm

P.S: Good decision on the 'jab'. It is a crime against humanity


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Thanks, I did find a Youtube video as well on AngelCAD: https://www.youtube.com/watch?v=h-qDzG9bwnQ I downloaded your source code and have it on my filesystem. I see it's C++. Great. I found the source code for polyfix, it's quite short, but may be using some other libs that you wrote. Are there any tips/docs on how to use polyfix. In the short term I want to pass in a single STL file and have it reconcile faces that are coplanar and overlapping by area, facing in opposite directions (relative to "outside"). This operation could be done on a single connected polyhedron which has "spikes" that touch or very nearly touch, as well. I presume that an epsilon value is being used; I saw something in the source code. Meanwhile I'm doing more independent investigation into what's going on behind the scenes in OpenSCAD, and why some simple cases are creating polyhedron that won't union()ize inside the STL. I suspect that one of the problems might possibly be that a conversion from 64 bit float to 32 bit float is happening too soon. I know from the STL spec that coordinates specified in STL are 32 bit float (from the best of my recollection - but I could check this again). Sent with Proton Mail secure email. ------- Original Message ------- On Saturday, June 3rd, 2023 at 11:40 PM, Carsten Arnholm <arnholm@arnholm.org> wrote: > > I imagine using an approach similar to that of my near-perfect retro > > line-drawing algorithm, > > in order to implement an STL cleanup tool which combines STL pieces > > that "touch" into one solid > > object. ("Touch" within an epsilon value which is configurable.) > > > Hi, I wrote such a tool. It is called 'polyfix' and it is part of the > AngelCAD suite > https://github.com/arnholm/angelcad/releases/tag/V1.5-06 > > Regards > Carsten Arnholm > > P.S: Good decision on the 'jab'. It is a crime against humanity > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
CA
Carsten Arnholm
Wed, Jun 7, 2023 7:32 PM

On 07.06.2023 19:04, neri-engineering wrote:

Are there any tips/docs on how to use polyfix.

It is a command line program with these options

Usage: polyfix [-verbose] [-maxiter <str>] [-dtol <str>] [-atol <str>]
[-lumps] [-nflip] [-remesh <str>] [-overwrite] [-out <str>] [-zip]
[-v] <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
 -v                    Show version number only

In the short term I want to pass in a single STL file and have it reconcile faces that are coplanar and overlapping by area, facing in opposite directions (relative to "outside").  This operation could be done on a single connected polyhedron which has "spikes" that touch or very nearly touch, as well.  I presume that an epsilon value is being used; I saw something in the source code.

The dtol parameter is your epsilon parameter, it is the tolerance for
merging vertices of the "triangle soup" that is STL.

The atol parameter is the minimal triangle area required for an STL
triangle to be valid.

example use, merge STL vertices and remove resulting zero area faces,
output as *.off format

$ polyfix vase_with_handle.stl -out=off

Parameters:
 input_file = vase_with_handle.stl
        out = off

polyhedron 0 ================= volume=3789.18, dtol=0.01, atol=1e-06,
maxiter=10
iteration 0: vertices=108390 faces=36130
            warning: nonmanifold edges: uc(1)=108390
            merged 90337 vertices
            removed 24 collapsed or zero area faces
            total changes=90361
            no warnings

iteration 1: vertices=18053 faces=36106
            total changes=0
            no warnings

Summary:
            polyhedron 0: vertices=18053 faces=36106 : no warnings

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

Obviously you can override the defaults for dtol, atol etc.

Good luck

Carsten Arnholm

On 07.06.2023 19:04, neri-engineering wrote: > Are there any tips/docs on how to use polyfix. It is a command line program with these options Usage: polyfix [-verbose] [-maxiter <str>] [-dtol <str>] [-atol <str>] [-lumps] [-nflip] [-remesh <str>] [-overwrite] [-out <str>] [-zip] [-v] <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  -v                    Show version number only > In the short term I want to pass in a single STL file and have it reconcile faces that are coplanar and overlapping by area, facing in opposite directions (relative to "outside"). This operation could be done on a single connected polyhedron which has "spikes" that touch or very nearly touch, as well. I presume that an epsilon value is being used; I saw something in the source code. The dtol parameter is your epsilon parameter, it is the tolerance for merging vertices of the "triangle soup" that is STL. The atol parameter is the minimal triangle area required for an STL triangle to be valid. example use, merge STL vertices and remove resulting zero area faces, output as *.off format $ polyfix vase_with_handle.stl -out=off Parameters:  input_file = vase_with_handle.stl         out = off polyhedron 0 ================= volume=3789.18, dtol=0.01, atol=1e-06, maxiter=10 iteration 0: vertices=108390 faces=36130             warning: nonmanifold edges: uc(1)=108390             merged 90337 vertices             removed 24 collapsed or zero area faces             total changes=90361             no warnings iteration 1: vertices=18053 faces=36106             total changes=0             no warnings Summary:             polyhedron 0: vertices=18053 faces=36106 : no warnings Writing: vase_with_handle.off ... polyfix finished, time used: 0d 00h 00m 01s Obviously you can override the defaults for dtol, atol etc. Good luck Carsten Arnholm
N
neri-engineering
Wed, Jun 7, 2023 8:12 PM

By the way I'm not necessarily looking for a solution. I am studying an interesting issue because that study itself is a very worthwhile endeavor; such studies oftentimes lead to very interesting new techniques for solving problems.

I'm going bottom-up and top-down at the same time to try to nail down a simple example (consisting of two simple polyhedron) which demonstrates my "issue that I am studying" - which is an STL file compiled without warnings or errors, yet which contains more than one volume (where two polyhedron are touching at a face, in a very natural and non-disturbing manner).
I am starting on the bottom-up approach, but I did manage to isolate something from the top-down avenue; this screenshot below shows that I'm able to compile a part without errors or warnings from CGAL yet it consists of more than one 3D piece. So no, I wasn't imagining things, and I wasn't delusional, in my earlier statements.

[screw.png]

I'm still working on the bottom-up so I can give code for exposing this issue, then I will continue further on studying possible workarounds to this issue (whether post-STL-generation or actually finding an easy fix in OpenSCAD and/or CGAL, e.g. maybe it's just a matter of casting to 32 bits too early).
I'm not looking for a temporary workaround; I find the study itself to be fascinating. I want to get to the bottom of this to see if there are any elegant low-hanging-fruit solutions that can be suggested.

The fact that my models consist of many pieces does not bother me whatsoever. However, eventually it will become an issue. For example working with other tools sometimes leads to issues, e.g. the to->FreeCAD importer, and I also had some machinists complain about my STL files, which was embarrassing to me.

Sent with Proton Mail secure email.

------- Original Message -------
On Wednesday, June 7th, 2023 at 2:32 PM, Carsten Arnholm arnholm@arnholm.org wrote:

On 07.06.2023 19:04, neri-engineering wrote:

Are there any tips/docs on how to use polyfix.

It is a command line program with these options

Usage: polyfix [-verbose] [-maxiter <str>] [-dtol <str>] [-atol <str>] [-lumps] [-nflip] [-remesh <str>] [-overwrite] [-out <str>] [-zip]
[-v] <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
-v Show version number only

In the short term I want to pass in a single STL file and have it reconcile faces that are coplanar and overlapping by area, facing in opposite directions (relative to "outside").  This operation could be done on a single connected polyhedron which has "spikes" that touch or very nearly touch, as well.  I presume that an epsilon value is being used; I saw something in the source code.

The dtol parameter is your epsilon parameter, it is the tolerance for merging vertices of the "triangle soup" that is STL.

The atol parameter is the minimal triangle area required for an STL triangle to be valid.

example use, merge STL vertices and remove resulting zero area faces, output as *.off format

$ polyfix vase_with_handle.stl -out=off

Parameters:
input_file = vase_with_handle.stl
out = off

polyhedron 0 ================= volume=3789.18, dtol=0.01, atol=1e-06, maxiter=10
iteration 0: vertices=108390 faces=36130
warning: nonmanifold edges: uc(1)=108390
merged 90337 vertices
removed 24 collapsed or zero area faces
total changes=90361
no warnings

iteration 1: vertices=18053 faces=36106
total changes=0
no warnings

Summary:
polyhedron 0: vertices=18053 faces=36106 : no warnings

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

Obviously you can override the defaults for dtol, atol etc.

Good luck

Carsten Arnholm

By the way I'm not necessarily looking for a solution. I am studying an interesting issue because that study itself is a very worthwhile endeavor; such studies oftentimes lead to very interesting new techniques for solving problems. I'm going bottom-up and top-down at the same time to try to nail down a simple example (consisting of two simple polyhedron) which demonstrates my "issue that I am studying" - which is an STL file compiled without warnings or errors, yet which contains more than one volume (where two polyhedron are touching at a face, in a very natural and non-disturbing manner). I am starting on the bottom-up approach, but I did manage to isolate something from the top-down avenue; this screenshot below shows that I'm able to compile a part without errors or warnings from CGAL yet it consists of more than one 3D piece. So no, I wasn't imagining things, and I wasn't delusional, in my earlier statements. [screw.png] I'm still working on the bottom-up so I can give code for exposing this issue, then I will continue further on studying possible workarounds to this issue (whether post-STL-generation or actually finding an easy fix in OpenSCAD and/or CGAL, e.g. maybe it's just a matter of casting to 32 bits too early). I'm not looking for a temporary workaround; I find the study itself to be fascinating. I want to get to the bottom of this to see if there are any elegant low-hanging-fruit solutions that can be suggested. The fact that my models consist of many pieces does not bother me whatsoever. However, eventually it will become an issue. For example working with other tools sometimes leads to issues, e.g. the to->FreeCAD importer, and I also had some machinists complain about my STL files, which was embarrassing to me. Sent with [Proton Mail](https://proton.me/) secure email. ------- Original Message ------- On Wednesday, June 7th, 2023 at 2:32 PM, Carsten Arnholm <arnholm@arnholm.org> wrote: > On 07.06.2023 19:04, neri-engineering wrote: > >> Are there any tips/docs on how to use polyfix. > > It is a command line program with these options > > Usage: polyfix [-verbose] [-maxiter <str>] [-dtol <str>] [-atol <str>] [-lumps] [-nflip] [-remesh <str>] [-overwrite] [-out <str>] [-zip] > [-v] <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 > -v Show version number only > >> In the short term I want to pass in a single STL file and have it reconcile faces that are coplanar and overlapping by area, facing in opposite directions (relative to "outside"). This operation could be done on a single connected polyhedron which has "spikes" that touch or very nearly touch, as well. I presume that an epsilon value is being used; I saw something in the source code. > > The dtol parameter is your epsilon parameter, it is the tolerance for merging vertices of the "triangle soup" that is STL. > > The atol parameter is the minimal triangle area required for an STL triangle to be valid. > > example use, merge STL vertices and remove resulting zero area faces, output as *.off format > > $ polyfix vase_with_handle.stl -out=off > > Parameters: > input_file = vase_with_handle.stl > out = off > > polyhedron 0 ================= volume=3789.18, dtol=0.01, atol=1e-06, maxiter=10 > iteration 0: vertices=108390 faces=36130 > warning: nonmanifold edges: uc(1)=108390 > merged 90337 vertices > removed 24 collapsed or zero area faces > total changes=90361 > no warnings > > iteration 1: vertices=18053 faces=36106 > total changes=0 > no warnings > > Summary: > polyhedron 0: vertices=18053 faces=36106 : no warnings > > Writing: vase_with_handle.off... polyfix finished, time used: 0d 00h 00m 01s > > Obviously you can override the defaults for dtol, atol etc. > > Good luck > > Carsten Arnholm