discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

points list from stl

SP
Sanjeev Prabhakar
Sun, Oct 23, 2022 1:34 AM

Hi All,

is there a way to extract points list from a stl file.

How can a polyhedron be created from that points list?

I am trying to create a complex part and it needs the points list to be
changed a little bit and then create a polyhedron again.

I don't have much understanding as to how stl files work.

Thanks

Hi All, is there a way to extract points list from a stl file. How can a polyhedron be created from that points list? I am trying to create a complex part and it needs the points list to be changed a little bit and then create a polyhedron again. I don't have much understanding as to how stl files work. Thanks
JB
Jordan Brown
Sun, Oct 23, 2022 1:38 AM

On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote:

is there a way to extract points list from a stl file.

In a conventional language, yes, especially if it is an ASCII STL file.

In OpenSCAD, no.

How can a polyhedron be created from that points list?

STL is organized as sets of points collected into triangles, so you'd
just collect up all of the points into a points array and generate an
appropriate faces array.

I don't have much understanding as to how stl files work.

They are pretty easy.  Generate an ASCII STL file and look at it.

Wikipedia has minimal documentation, but that might be all you need: 
https://en.wikipedia.org/wiki/STL_(file_format)#ASCII_STL

On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote: > is there a way to extract points list from a stl file. In a conventional language, yes, especially if it is an ASCII STL file. In OpenSCAD, no. > How can a polyhedron be created from that points list? STL is organized as sets of points collected into triangles, so you'd just collect up all of the points into a points array and generate an appropriate faces array. > I don't have much understanding as to how stl files work. They are pretty easy.  Generate an ASCII STL file and look at it. Wikipedia has minimal documentation, but that might be all you need:  https://en.wikipedia.org/wiki/STL_(file_format)#ASCII_STL
SP
Sanjeev Prabhakar
Sun, Oct 23, 2022 3:46 AM

Ok thank you, will check if this can help

On Sun, 23 Oct 2022 at 07:08, Jordan Brown openscad@jordan.maileater.net
wrote:

On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote:

is there a way to extract points list from a stl file.

In a conventional language, yes, especially if it is an ASCII STL file.

In OpenSCAD, no.

How can a polyhedron be created from that points list?

STL is organized as sets of points collected into triangles, so you'd just
collect up all of the points into a points array and generate an
appropriate faces array.

I don't have much understanding as to how stl files work.

They are pretty easy.  Generate an ASCII STL file and look at it.

Wikipedia has minimal documentation, but that might be all you need:
https://en.wikipedia.org/wiki/STL_(file_format)#ASCII_STL

Ok thank you, will check if this can help On Sun, 23 Oct 2022 at 07:08, Jordan Brown <openscad@jordan.maileater.net> wrote: > On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote: > > is there a way to extract points list from a stl file. > > > In a conventional language, yes, especially if it is an ASCII STL file. > > In OpenSCAD, no. > > How can a polyhedron be created from that points list? > > > STL is organized as sets of points collected into triangles, so you'd just > collect up all of the points into a points array and generate an > appropriate faces array. > > I don't have much understanding as to how stl files work. > > > They are pretty easy. Generate an ASCII STL file and look at it. > > Wikipedia has minimal documentation, but that might be all you need: > https://en.wikipedia.org/wiki/STL_(file_format)#ASCII_STL > >
MM
Michael Marx
Sun, Oct 23, 2022 5:35 AM

and as per the SVG thread, you can use 'include <>' for bulk input of items from an external script

You need the script to format it:

var= [
[ x, y] ,        // or multi points, ending in comma
... ,
[ etc-x, etc-y]  // no comma on last point
];


From: Sanjeev Prabhakar [mailto:sprabhakar2006@gmail.com]
Sent: Sun, 23 Oct 2022 14:46
To: Jordan Brown
Cc: OpenSCAD general discussion Mailing-list
Subject: [OpenSCAD] Re: points list from stl

Ok thank you, will check if this can help

On Sun, 23 Oct 2022 at 07:08, Jordan Brown openscad@jordan.maileater.net wrote:

On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote:

is there a way to extract points list from a stl file.

In a conventional language, yes, especially if it is an ASCII STL file.

In OpenSCAD, no.

How can a polyhedron be created from that points list?

STL is organized as sets of points collected into triangles, so you'd just collect up all of the points into a points array and generate an appropriate faces array.

I don't have much understanding as to how stl files work.

They are pretty easy.  Generate an ASCII STL file and look at it.

Wikipedia has minimal documentation, but that might be all you need:  https://en.wikipedia.org/wiki/STL_(file_format)#ASCII_STL

--
This email has been checked for viruses by AVG antivirus software.
www.avg.com

and as per the SVG thread, you can use 'include <>' for bulk input of items from an external script You need the script to format it: var= [ [ x, y] , // or multi points, ending in comma ... , [ etc-x, etc-y] // no comma on last point ]; _____ From: Sanjeev Prabhakar [mailto:sprabhakar2006@gmail.com] Sent: Sun, 23 Oct 2022 14:46 To: Jordan Brown Cc: OpenSCAD general discussion Mailing-list Subject: [OpenSCAD] Re: points list from stl Ok thank you, will check if this can help On Sun, 23 Oct 2022 at 07:08, Jordan Brown <openscad@jordan.maileater.net> wrote: On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote: is there a way to extract points list from a stl file. In a conventional language, yes, especially if it is an ASCII STL file. In OpenSCAD, no. How can a polyhedron be created from that points list? STL is organized as sets of points collected into triangles, so you'd just collect up all of the points into a points array and generate an appropriate faces array. I don't have much understanding as to how stl files work. They are pretty easy. Generate an ASCII STL file and look at it. Wikipedia has minimal documentation, but that might be all you need: https://en.wikipedia.org/wiki/STL_(file_format)#ASCII_STL -- This email has been checked for viruses by AVG antivirus software. www.avg.com
A
arnholm@arnholm.org
Sun, Oct 23, 2022 8:56 AM

On 2022-10-23 03:34, Sanjeev Prabhakar wrote:

is there a way to extract points list from a stl file.

STL files contain a "triangle soup", that means triangles are not
explicitly connected, every triangle has its own coordinates not shared
with neighbour triangles. The neighbours have their own coordinates, and
often there is no exact match. This is why STL is particularly
unsuitable for sharing models between applications and why doing what
you ask becomes harder than it should be.

What you can do is use a model repair tool and save the result as *.obj,
*.off or similar but not stl. If you do, the answer to your question
becomes trivial. Those formats contain a unique points list (i.e.
vertices). There are several such tools out there, one is 'polyfix' part
of AngelCAD.

How can a polyhedron be created from that points list?

You cannot generally create a polyhedron from just a points list without
additional information. A polyhedron is a collection of polygons
(usually triangles) referring to vertices (points in 3d space) in a
list. This is exactly what is found in file formats such as *.obj, *.off
and more (but not STL).

I am trying to create a complex part and it needs the points list to
be changed a little bit and then create a polyhedron again.

Your part can typically be represented as polyhedron (or several). You
need the whole definition, not just the points. In the general case you
can tweak the point coordinates to slightly modify a polyhedron, except
you cannot use OpenSCAD to do it. You can however import into OpenSAD
from *.off

I don't have much understanding as to how stl files work.

See above. Note that STL as saved is not the same as a polyhedron, even
for the simplest model. This is different from the other formats
mentioned.

Carsten Arnholm

On 2022-10-23 03:34, Sanjeev Prabhakar wrote: > is there a way to extract points list from a stl file. STL files contain a "triangle soup", that means triangles are not explicitly connected, every triangle has its own coordinates not shared with neighbour triangles. The neighbours have their own coordinates, and often there is no exact match. This is why STL is particularly unsuitable for sharing models between applications and why doing what you ask becomes harder than it should be. What you can do is use a model repair tool and save the result as *.obj, *.off or similar but not stl. If you do, the answer to your question becomes trivial. Those formats contain a unique points list (i.e. vertices). There are several such tools out there, one is 'polyfix' part of AngelCAD. > How can a polyhedron be created from that points list? You cannot generally create a polyhedron from just a points list without additional information. A polyhedron is a collection of polygons (usually triangles) referring to vertices (points in 3d space) in a list. This is exactly what is found in file formats such as *.obj, *.off and more (but not STL). > I am trying to create a complex part and it needs the points list to > be changed a little bit and then create a polyhedron again. Your part can typically be represented as polyhedron (or several). You need the whole definition, not just the points. In the general case you can tweak the point coordinates to slightly modify a polyhedron, except you cannot use OpenSCAD to do it. You can however import into OpenSAD from *.off > I don't have much understanding as to how stl files work. See above. Note that STL as saved is not the same as a polyhedron, even for the simplest model. This is different from the other formats mentioned. Carsten Arnholm
NH
nop head
Sun, Oct 23, 2022 9:03 AM

STL works fine if there are no self intersections and the vertex
coordinates are distinct and numerically exactly the same when they are
shared between triangles. I have no idea why an application would spit out
slightly different numbers for identical vertices but it is rumored some
apps do. I have never encountered that problem but a lot of STLs have self
intersections where curves meet, etc.

On Sun, 23 Oct 2022 at 09:57, arnholm@arnholm.org wrote:

On 2022-10-23 03:34, Sanjeev Prabhakar wrote:

is there a way to extract points list from a stl file.

STL files contain a "triangle soup", that means triangles are not
explicitly connected, every triangle has its own coordinates not shared
with neighbour triangles. The neighbours have their own coordinates, and
often there is no exact match. This is why STL is particularly
unsuitable for sharing models between applications and why doing what
you ask becomes harder than it should be.

What you can do is use a model repair tool and save the result as *.obj,
*.off or similar but not stl. If you do, the answer to your question
becomes trivial. Those formats contain a unique points list (i.e.
vertices). There are several such tools out there, one is 'polyfix' part
of AngelCAD.

How can a polyhedron be created from that points list?

You cannot generally create a polyhedron from just a points list without
additional information. A polyhedron is a collection of polygons
(usually triangles) referring to vertices (points in 3d space) in a
list. This is exactly what is found in file formats such as *.obj, *.off
and more (but not STL).

I am trying to create a complex part and it needs the points list to
be changed a little bit and then create a polyhedron again.

Your part can typically be represented as polyhedron (or several). You
need the whole definition, not just the points. In the general case you
can tweak the point coordinates to slightly modify a polyhedron, except
you cannot use OpenSCAD to do it. You can however import into OpenSAD
from *.off

I don't have much understanding as to how stl files work.

See above. Note that STL as saved is not the same as a polyhedron, even
for the simplest model. This is different from the other formats
mentioned.

Carsten Arnholm


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

STL works fine if there are no self intersections and the vertex coordinates are distinct and numerically exactly the same when they are shared between triangles. I have no idea why an application would spit out slightly different numbers for identical vertices but it is rumored some apps do. I have never encountered that problem but a lot of STLs have self intersections where curves meet, etc. On Sun, 23 Oct 2022 at 09:57, <arnholm@arnholm.org> wrote: > On 2022-10-23 03:34, Sanjeev Prabhakar wrote: > > is there a way to extract points list from a stl file. > > STL files contain a "triangle soup", that means triangles are not > explicitly connected, every triangle has its own coordinates not shared > with neighbour triangles. The neighbours have their own coordinates, and > often there is no exact match. This is why STL is particularly > unsuitable for sharing models between applications and why doing what > you ask becomes harder than it should be. > > What you can do is use a model repair tool and save the result as *.obj, > *.off or similar but not stl. If you do, the answer to your question > becomes trivial. Those formats contain a unique points list (i.e. > vertices). There are several such tools out there, one is 'polyfix' part > of AngelCAD. > > > How can a polyhedron be created from that points list? > > You cannot generally create a polyhedron from just a points list without > additional information. A polyhedron is a collection of polygons > (usually triangles) referring to vertices (points in 3d space) in a > list. This is exactly what is found in file formats such as *.obj, *.off > and more (but not STL). > > > I am trying to create a complex part and it needs the points list to > > be changed a little bit and then create a polyhedron again. > > Your part can typically be represented as polyhedron (or several). You > need the whole definition, not just the points. In the general case you > can tweak the point coordinates to slightly modify a polyhedron, except > you cannot use OpenSCAD to do it. You can however import into OpenSAD > from *.off > > > I don't have much understanding as to how stl files work. > > See above. Note that STL as saved is not the same as a polyhedron, even > for the simplest model. This is different from the other formats > mentioned. > > Carsten Arnholm > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
RW
Rogier Wolff
Sun, Oct 23, 2022 10:05 AM

On Sat, Oct 22, 2022 at 06:38:32PM -0700, Jordan Brown wrote:

On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote:

is there a way to extract points list from a stl file.

In a conventional language, yes, especially if it is an ASCII STL file.

In OpenSCAD, no.

How can a polyhedron be created from that points list?

STL is organized as sets of points collected into triangles, so you'd
just collect up all of the points into a points array and generate an
appropriate faces array.

Right! And then... what import_stl () (*) does is: call polyhedron
with the points list and triangles list.

Would it be an idea to make the internal "get the points list from
STL" and the "get the triangles list from an STL" available to the
users? The import_stl would then become:

module import_stl (fname)
{
polyhedron( points = points_from_STL (fname), faces = triangles_from_STL (fname));
}

Of course, the user-visible routines would here be inefficient because
it would parse the STL twice. But that can be easily fixed.
There will be an parse_stl (fname, &points, &triangles) function that
returns both and the user-visible routines will be:

list_of_points get_points_from_stl (fname)
{
if (cached_fname != fname) {
parse_stl (fname, &cached_points, &cached_triangles);
cached_fname = fname;
}
return cached_points;
}

All reasonably straightforward.

Caching more than one STL is more difficult. Until then you might warn
users: "Don't do:

p1 = get_points_from_stl("f1.stl");
p2 = get_points_from_stl("f2.stl");
f1 = get_triangles_from_stl ("f1.stl");
f2 = get_triangles_from_stl ("f2.stl");
but swap the 2nd and third line. "....

Roger. 

(*) it's written differently nowadays I think.

--
** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
f equals m times a. When your f is steady, and your m is going down
your a is going up.  -- Chris Hadfield about flying up the space shuttle.

On Sat, Oct 22, 2022 at 06:38:32PM -0700, Jordan Brown wrote: > On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote: > > is there a way to extract points list from a stl file. > > In a conventional language, yes, especially if it is an ASCII STL file. > > In OpenSCAD, no. > > > How can a polyhedron be created from that points list? > > STL is organized as sets of points collected into triangles, so you'd > just collect up all of the points into a points array and generate an > appropriate faces array. Right! And then... what import_stl () (*) does is: call polyhedron with the points list and triangles list. Would it be an idea to make the internal "get the points list from STL" and the "get the triangles list from an STL" available to the users? The import_stl would then become: module import_stl (fname) { polyhedron( points = points_from_STL (fname), faces = triangles_from_STL (fname)); } Of course, the user-visible routines would here be inefficient because it would parse the STL twice. But that can be easily fixed. There will be an parse_stl (fname, &points, &triangles) function that returns both and the user-visible routines will be: list_of_points get_points_from_stl (fname) { if (cached_fname != fname) { parse_stl (fname, &cached_points, &cached_triangles); cached_fname = fname; } return cached_points; } All reasonably straightforward. Caching more than one STL is more difficult. Until then you might warn users: "Don't do: p1 = get_points_from_stl("f1.stl"); p2 = get_points_from_stl("f2.stl"); f1 = get_triangles_from_stl ("f1.stl"); f2 = get_triangles_from_stl ("f2.stl"); but swap the 2nd and third line. ".... Roger. (*) it's written differently nowadays I think. -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ** ** Delftechpark 11 2628 XJ Delft, The Netherlands. KVK: 27239233 ** f equals m times a. When your f is steady, and your m is going down your a is going up. -- Chris Hadfield about flying up the space shuttle.
RW
Raymond West
Sun, Oct 23, 2022 10:27 AM

Would it be an idea to make the internal "get the points list from
STL" and the "get the triangles list from an STL" available to the
users? The import_stl would then become:

module import_stl (fname)
{
polyhedron( points = points_from_STL (fname), faces = triangles_from_STL (fname));
}

It would help if it was true for all imports dxf, svg, off/whatever.

But, it is not too difficult locating a point or two within a list of a few thousand, but finding the face is a bit more tricky.

On 23/10/2022 11:05, Rogier Wolff wrote:

On Sat, Oct 22, 2022 at 06:38:32PM -0700, Jordan Brown wrote:

On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote:

is there a way to extract points list from a stl file.
In a conventional language, yes, especially if it is an ASCII STL file.

In OpenSCAD, no.

How can a polyhedron be created from that points list?
STL is organized as sets of points collected into triangles, so you'd
just collect up all of the points into a points array and generate an
appropriate faces array.
Right! And then... what import_stl () (*) does is: call polyhedron
with the points list and triangles list.

Would it be an idea to make the internal "get the points list from
STL" and the "get the triangles list from an STL" available to the
users? The import_stl would then become:

module import_stl (fname)
{
polyhedron( points = points_from_STL (fname), faces = triangles_from_STL (fname));
}

Of course, the user-visible routines would here be inefficient because
it would parse the STL twice. But that can be easily fixed.
There will be an parse_stl (fname, &points, &triangles) function that
returns both and the user-visible routines will be:

list_of_points get_points_from_stl (fname)
{
if (cached_fname != fname) {
parse_stl (fname, &cached_points, &cached_triangles);
cached_fname = fname;
}
return cached_points;
}

All reasonably straightforward.

Caching more than one STL is more difficult. Until then you might warn
users: "Don't do:

p1 = get_points_from_stl("f1.stl");
p2 = get_points_from_stl("f2.stl");
f1 = get_triangles_from_stl ("f1.stl");
f2 = get_triangles_from_stl ("f2.stl");

but swap the 2nd and third line. "....

Roger.

(*) it's written differently nowadays I think.

> Would it be an idea to make the internal "get the points list from > STL" and the "get the triangles list from an STL" available to the > users? The import_stl would then become: > > module import_stl (fname) > { > polyhedron( points = points_from_STL (fname), faces = triangles_from_STL (fname)); > } It would help if it was true for all imports dxf, svg, off/whatever. But, it is not too difficult locating a point or two within a list of a few thousand, but finding the face is a bit more tricky. On 23/10/2022 11:05, Rogier Wolff wrote: > On Sat, Oct 22, 2022 at 06:38:32PM -0700, Jordan Brown wrote: >> On 10/22/2022 6:34 PM, Sanjeev Prabhakar wrote: >>> is there a way to extract points list from a stl file. >> In a conventional language, yes, especially if it is an ASCII STL file. >> >> In OpenSCAD, no. >> >>> How can a polyhedron be created from that points list? >> STL is organized as sets of points collected into triangles, so you'd >> just collect up all of the points into a points array and generate an >> appropriate faces array. > Right! And then... what import_stl () (*) does is: call polyhedron > with the points list and triangles list. > > Would it be an idea to make the internal "get the points list from > STL" and the "get the triangles list from an STL" available to the > users? The import_stl would then become: > > module import_stl (fname) > { > polyhedron( points = points_from_STL (fname), faces = triangles_from_STL (fname)); > } > > Of course, the user-visible routines would here be inefficient because > it would parse the STL twice. But that can be easily fixed. > There will be an parse_stl (fname, &points, &triangles) function that > returns both and the user-visible routines will be: > > list_of_points get_points_from_stl (fname) > { > if (cached_fname != fname) { > parse_stl (fname, &cached_points, &cached_triangles); > cached_fname = fname; > } > return cached_points; > } > > All reasonably straightforward. > > Caching more than one STL is more difficult. Until then you might warn > users: "Don't do: > > p1 = get_points_from_stl("f1.stl"); > p2 = get_points_from_stl("f2.stl"); > f1 = get_triangles_from_stl ("f1.stl"); > f2 = get_triangles_from_stl ("f2.stl"); > but swap the 2nd and third line. ".... > > Roger. > > > (*) it's written differently nowadays I think. >
JB
Jordan Brown
Sun, Oct 23, 2022 5:46 PM

On 10/23/2022 3:05 AM, Rogier Wolff wrote:

Would it be an idea to make the internal "get the points list from
STL" and the "get the triangles list from an STL" available to the users?

It's certainly been discussed.  (The "returning two things" problem you
mention is easy:  return them both, as two members of one object.  Or,
if you want to be old-fashioned, as two elements of an array.)

On 10/23/2022 3:05 AM, Rogier Wolff wrote: > Would it be an idea to make the internal "get the points list from > STL" and the "get the triangles list from an STL" available to the users? It's certainly been discussed.  (The "returning two things" problem you mention is easy:  return them both, as two members of one object.  Or, if you want to be old-fashioned, as two elements of an array.)
NH
nop head
Sun, Oct 23, 2022 6:21 PM

If we had module references we could have a render(module_ref) function
that returns points and faces to pass to polyhedron, or polygon or
iterate through with for loops. You can wrap any geometry in a module, so
you could use an import to get data from any importable file. Then you
could calculate its bounds and centre it, etc, or do any arbitrary
transformation.

You could also generate complex polygons using union, etc, and pass it to
sweep. Seems like a simple way of getting access to geometry that doesn't
break things.

On Sun, 23 Oct 2022 at 18:46, Jordan Brown openscad@jordan.maileater.net
wrote:

On 10/23/2022 3:05 AM, Rogier Wolff wrote:

Would it be an idea to make the internal "get the points list from STL"
and the "get the triangles list from an STL" available to the users?

It's certainly been discussed.  (The "returning two things" problem you
mention is easy:  return them both, as two members of one object.  Or, if
you want to be old-fashioned, as two elements of an array.)


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

If we had module references we could have a render(module_ref) function that returns points and faces to pass to polyhedron, or polygon or iterate through with for loops. You can wrap any geometry in a module, so you could use an import to get data from any importable file. Then you could calculate its bounds and centre it, etc, or do any arbitrary transformation. You could also generate complex polygons using union, etc, and pass it to sweep. Seems like a simple way of getting access to geometry that doesn't break things. On Sun, 23 Oct 2022 at 18:46, Jordan Brown <openscad@jordan.maileater.net> wrote: > On 10/23/2022 3:05 AM, Rogier Wolff wrote: > > Would it be an idea to make the internal "get the points list from STL" > and the "get the triangles list from an STL" available to the users? > > > It's certainly been discussed. (The "returning two things" problem you > mention is easy: return them both, as two members of one object. Or, if > you want to be old-fashioned, as two elements of an array.) > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >