discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

A faces( ) function for simple polyhedrons

R
runsun
Sat, Jun 6, 2015 8:31 AM

Just released a faces.scad that can generate faces for simple polyhedrons:
https://github.com/runsun/faces.scad/blob/master/faces.scad.
https://github.com/runsun/faces.scad/blob/master/faces.scad

This is part of a lib that I am working on. During my course of learning
polyhedron, the faces is the most frustrating obstacle. So I think that I'd
make my face() a stand-alone lib so this might help people like me.

This lib currently only supports 5 very basic polyhedrons. And it use
4-point faces. I do hope that, in the future, openscad will consider having
a better faces() as the builtin.

The function api:

faces( shape  // cubesides|rod|chain|ring|tube    , nside  // # of sides
, nseg  // # of segments for chain    )

Its currently-supported 5 shapes are demonstrated below. The points, pts
are given in the example files in the release. The construction of those
pts is beyond the scope of this work.

http://forum.openscad.org/file/n12809/demo_cubesides.png
  cubesides
  Needed for building other shape faces.

f=faces( "cubesides", nside=4 );polyhedron( points=pts, faces=f );

polyhedron( points=pts, faces=faces( "rod", nside=4 ));polyhedron(
points=pts , faces=faces( "rod", nside=6 ));

f=faces( "tube", nside=20 );polyhedron( points= pts , faces=f );

f=faces( "chain", nside=4, nseg=5 );polyhedron( points=pts, faces=f );

http://forum.openscad.org/file/n12809/demo_ring.png
  ring
  A ring is like a closed chain.

f=faces( "ring", nside=4, nseg=10 );polyhedron( points=pts, faces= f );


$  Runsun Pan, PhD

$ -- OpenScad_DocTest: doc and unit test ( Github , Thingiverse  )

$ -- hash parameter model: here , here

$ -- Linux Mint 17.1 Rebecca x64  + OpenSCAD 2015.03.15/2015.04.01.nightly

--
View this message in context: http://forum.openscad.org/A-faces-function-for-simple-polyhedrons-tp12809.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Just released a *faces.scad* that can generate faces for simple polyhedrons: https://github.com/runsun/faces.scad/blob/master/faces.scad. <https://github.com/runsun/faces.scad/blob/master/faces.scad> This is part of a lib that I am working on. During my course of learning polyhedron, the faces is the most frustrating obstacle. So I think that I'd make my face() a stand-alone lib so this might help people like me. This lib currently only supports 5 very basic polyhedrons. And it use 4-point faces. I do hope that, in the future, openscad will consider having a better faces() as the builtin. The function api: > faces( shape // cubesides|rod|chain|ring|tube , nside // # of sides > , nseg // # of segments for chain ) Its currently-supported 5 shapes are demonstrated below. The points, *pts* are given in the example files in the release. The construction of those *pts* is beyond the scope of this work. <http://forum.openscad.org/file/n12809/demo_cubesides.png> &nbsp;&nbsp;cubesides &nbsp;&nbsp;Needed for building other shape faces. > f=faces( "cubesides", nside=4 );polyhedron( points=pts, faces=f ); <http://forum.openscad.org/file/n12809/demo_rod.png> &nbsp;&nbsp;rod &nbsp;&nbsp;Same as a cylinder > polyhedron( points=pts, faces=faces( "rod", nside=4 ));polyhedron( > points=pts , faces=faces( "rod", nside=6 )); <http://forum.openscad.org/file/n12809/demo_tube.png> &nbsp;&nbsp;tube > f=faces( "tube", nside=20 );polyhedron( points= pts , faces=f ); <http://forum.openscad.org/file/n12809/demo_chain.png> &nbsp;&nbsp;chain > f=faces( "chain", nside=4, nseg=5 );polyhedron( points=pts, faces=f ); <http://forum.openscad.org/file/n12809/demo_ring.png> &nbsp;&nbsp;ring &nbsp;&nbsp;A ring is like a closed chain. > f=faces( "ring", nside=4, nseg=10 );polyhedron( points=pts, faces= f ); ----- $ Runsun Pan, PhD $ -- OpenScad_DocTest: doc and unit test ( Github , Thingiverse ) $ -- hash parameter model: here , here $ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly -- View this message in context: http://forum.openscad.org/A-faces-function-for-simple-polyhedrons-tp12809.html Sent from the OpenSCAD mailing list archive at Nabble.com.
JL
Jean-Paul Louis
Sat, Jun 6, 2015 9:18 PM

Hi runsun,

Nice utilities.
I downloaded your file faces.scad, and tested it with the latest mac OS X version.
The preview work fine, but the rendering fails when trying to render the ring.
This happen using showall();

when loading, the console looks like below:

Compiling design (CSG Tree generation)...
ECHO: ""
ECHO: "ring_faces ( "darkslategray" )"
ECHO: "cubesides_faces ( "olive" )"
ECHO: "rod_faces1 ( "olive" )"
ECHO: "rod_faces2 ( "red" )"
ECHO: "tube_faces ( "green" )"
ECHO: "chain_faces ( "darkcyan" )"
ECHO: ""
Compiling design (CSG Products generation)...
Geometries in cache: 6
Geometry cache size in bytes: 16752
CGAL Polyhedrons in cache: 0
CGAL cache size in bytes: 0
Compiling design (CSG Products normalization)...
Normalized CSG tree has 6 elements
Compile and preview finished.
Total rendering time: 0 hours, 0 minutes, 0 seconds

When rendering, I get:

Compiling design (CSG Tree generation)...
ECHO: ""
ECHO: "ring_faces ( "darkslategray" )"
ECHO: "cubesides_faces ( "olive" )"
ECHO: "rod_faces1 ( "olive" )"
ECHO: "rod_faces2 ( "red" )"
ECHO: "tube_faces ( "green" )"
ECHO: "chain_faces ( "darkcyan" )"
ECHO: ""
Rendering Polygon Mesh using CGAL...
PolySet has nonplanar faces. Attempting alternate construction
ERROR: Alternate construction failed. CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: e->incident_sface() != SFace_const_handle() File: /Users/kintel/code/OpenSCAD/openscad/../libraries/install/include/CGAL/Nef_S2/SM_const_decorator.h Line: 326
PolySet has nonplanar faces. Attempting alternate construction
PolySet has nonplanar faces. Attempting alternate construction
PolySet has nonplanar faces. Attempting alternate construction
Geometries in cache: 20
Geometry cache size in bytes: 50256
CGAL Polyhedrons in cache: 2
CGAL cache size in bytes: 616688
Total rendering time: 0 hours, 0 minutes, 0 seconds
Top level object is a 3D object:
Simple:        no
Vertices:      132
Halfedges:    734
Edges:        367
Halffacets:    482
Facets:        241
Volumes:        5
WARNING: Object may not be a valid 2-manifold and may need repair!
Rendering finished.

All the object are rendered except the ring.

Regards,
Jean-Paul
AC9GH

On Jun 6, 2015, at 4:31 AM, runsun runsun@gmail.com wrote:

Just released a faces.scad that can generate faces for simple polyhedrons:
https://github.com/runsun/faces.scad/blob/master/faces.scad.

This is part of a lib that I am working on. During my course of learning polyhedron, the faces is the most frustrating obstacle. So I think that I'd make my face() a stand-alone lib so this might help people like me.

This lib currently only supports 5 very basic polyhedrons. And it use 4-point faces. I do hope that, in the future, openscad will consider having a better faces() as the builtin.

The function api:
faces( shape  // cubesides|rod|chain|ring|tube
, nside  // # of sides
, nseg  // # of segments for chain
)

Its currently-supported 5 shapes are demonstrated below. The points, pts are given in the example files in the release. The construction of those pts is beyond the scope of this work.

cubesides

Needed for building other shape faces.
f=faces( "cubesides", nside=4 );
polyhedron( points=pts, faces=f );

rod

Same as a cylinder
polyhedron( points=pts, faces=faces( "rod", nside=4 ));
polyhedron( points=pts , faces=faces( "rod", nside=6 ));

tube

f=faces( "tube", nside=20 );
polyhedron( points= pts , faces=f );

chain

f=faces( "chain", nside=4, nseg=5 );
polyhedron( points=pts, faces=f );

ring

A ring is like a closed chain.
f=faces( "ring", nside=4, nseg=10 );
polyhedron( points=pts, faces= f );

$ Runsun Pan, PhD
$ -- OpenScad_DocTest: doc and unit test ( Github, Thingiverse )
$ -- hash parameter model: here, here
$ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly

View this message in context: A faces( ) function for simple polyhedrons
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Hi runsun, Nice utilities. I downloaded your file faces.scad, and tested it with the latest mac OS X version. The preview work fine, but the rendering fails when trying to render the ring. This happen using showall(); when loading, the console looks like below: Compiling design (CSG Tree generation)... ECHO: "" ECHO: "ring_faces ( "darkslategray" )" ECHO: "cubesides_faces ( "olive" )" ECHO: "rod_faces1 ( "olive" )" ECHO: "rod_faces2 ( "red" )" ECHO: "tube_faces ( "green" )" ECHO: "chain_faces ( "darkcyan" )" ECHO: "" Compiling design (CSG Products generation)... Geometries in cache: 6 Geometry cache size in bytes: 16752 CGAL Polyhedrons in cache: 0 CGAL cache size in bytes: 0 Compiling design (CSG Products normalization)... Normalized CSG tree has 6 elements Compile and preview finished. Total rendering time: 0 hours, 0 minutes, 0 seconds When rendering, I get: Compiling design (CSG Tree generation)... ECHO: "" ECHO: "ring_faces ( "darkslategray" )" ECHO: "cubesides_faces ( "olive" )" ECHO: "rod_faces1 ( "olive" )" ECHO: "rod_faces2 ( "red" )" ECHO: "tube_faces ( "green" )" ECHO: "chain_faces ( "darkcyan" )" ECHO: "" Rendering Polygon Mesh using CGAL... PolySet has nonplanar faces. Attempting alternate construction ERROR: Alternate construction failed. CGAL error in CGAL_Nef_polyhedron3(): CGAL ERROR: assertion violation! Expr: e->incident_sface() != SFace_const_handle() File: /Users/kintel/code/OpenSCAD/openscad/../libraries/install/include/CGAL/Nef_S2/SM_const_decorator.h Line: 326 PolySet has nonplanar faces. Attempting alternate construction PolySet has nonplanar faces. Attempting alternate construction PolySet has nonplanar faces. Attempting alternate construction Geometries in cache: 20 Geometry cache size in bytes: 50256 CGAL Polyhedrons in cache: 2 CGAL cache size in bytes: 616688 Total rendering time: 0 hours, 0 minutes, 0 seconds Top level object is a 3D object: Simple: no Vertices: 132 Halfedges: 734 Edges: 367 Halffacets: 482 Facets: 241 Volumes: 5 WARNING: Object may not be a valid 2-manifold and may need repair! Rendering finished. All the object are rendered except the ring. Regards, Jean-Paul AC9GH > On Jun 6, 2015, at 4:31 AM, runsun <runsun@gmail.com> wrote: > > Just released a faces.scad that can generate faces for simple polyhedrons: > https://github.com/runsun/faces.scad/blob/master/faces.scad. > > This is part of a lib that I am working on. During my course of learning polyhedron, the faces is the most frustrating obstacle. So I think that I'd make my face() a stand-alone lib so this might help people like me. > > This lib currently only supports 5 very basic polyhedrons. And it use 4-point faces. I do hope that, in the future, openscad will consider having a better faces() as the builtin. > > The function api: > faces( shape // cubesides|rod|chain|ring|tube > , nside // # of sides > , nseg // # of segments for chain > ) > > Its currently-supported 5 shapes are demonstrated below. The points, pts are given in the example files in the release. The construction of those pts is beyond the scope of this work. > > > cubesides > > Needed for building other shape faces. > f=faces( "cubesides", nside=4 ); > polyhedron( points=pts, faces=f ); > > > rod > > Same as a cylinder > polyhedron( points=pts, faces=faces( "rod", nside=4 )); > polyhedron( points=pts , faces=faces( "rod", nside=6 )); > > > tube > > f=faces( "tube", nside=20 ); > polyhedron( points= pts , faces=f ); > > > chain > > f=faces( "chain", nside=4, nseg=5 ); > polyhedron( points=pts, faces=f ); > > > ring > > A ring is like a closed chain. > f=faces( "ring", nside=4, nseg=10 ); > polyhedron( points=pts, faces= f ); > > $ Runsun Pan, PhD > $ -- OpenScad_DocTest: doc and unit test ( Github, Thingiverse ) > $ -- hash parameter model: here, here > $ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly > > View this message in context: A faces( ) function for simple polyhedrons > Sent from the OpenSCAD mailing list archive at Nabble.com. > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
R
runsun
Sat, Jun 6, 2015 11:31 PM

I believe the error is trying to render two or more separate objects.

Try do this:

module showall(){
cubesides_faces("olive");
rod_faces1("olive");
}

and it still gives you the same rendering error.

Render them one at a time will be ok.


$  Runsun Pan, PhD

$ -- OpenScad_DocTest: doc and unit test ( Github , Thingiverse  )

$ -- hash parameter model: here , here

$ -- Linux Mint 17.1 Rebecca x64  + OpenSCAD 2015.03.15/2015.04.01.nightly

--
View this message in context: http://forum.openscad.org/A-faces-function-for-simple-polyhedrons-tp12809p12812.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I believe the error is trying to render two or more separate objects. Try do this: module showall(){ cubesides_faces("olive"); rod_faces1("olive"); } and it still gives you the same rendering error. Render them one at a time will be ok. ----- $ Runsun Pan, PhD $ -- OpenScad_DocTest: doc and unit test ( Github , Thingiverse ) $ -- hash parameter model: here , here $ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly -- View this message in context: http://forum.openscad.org/A-faces-function-for-simple-polyhedrons-tp12809p12812.html Sent from the OpenSCAD mailing list archive at Nabble.com.
I
Ivo
Sun, Jun 7, 2015 1:09 PM

runsun wrote

<br/> The function api:
<code style="font-size:13px"> <pre> faces( shape // cubesides|rod|chain|ring|tube , nside // # of sides , nseg // # of segments for chain ) </pre> </code>

This would be a great way discourage / deprecate the nasty $fs=6 i've seen
in models where hexagons are created by degrading the quality of cylinders.

imho $fa, $fs and $fn should only be user to control the rendering
resolution of quality.

Cheers, Ivo

--
View this message in context: http://forum.openscad.org/A-faces-function-for-simple-polyhedrons-tp12809p12822.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

runsun wrote > <br/> > The function api: >> <code style="font-size:13px"> >> <pre> >> faces( shape // cubesides|rod|chain|ring|tube >> , nside // # of sides >> , nseg // # of segments for chain >> ) >> </pre> >> </code> This would be a great way discourage / deprecate the nasty $fs=6 i've seen in models where hexagons are created by degrading the quality of cylinders. imho $fa, $fs and $fn should only be user to control the rendering resolution of quality. Cheers, Ivo -- View this message in context: http://forum.openscad.org/A-faces-function-for-simple-polyhedrons-tp12809p12822.html Sent from the OpenSCAD mailing list archive at Nabble.com.