Tube mesh extrusion library for OpenSCAD by arpruss 3d model
3dmdb logo
Thingiverse
Tube mesh extrusion library for OpenSCAD by arpruss

Tube mesh extrusion library for OpenSCAD by arpruss

by Thingiverse
Last crawled date: 3 years ago
This is a library for generating "tube-like" meshes that join a number of cross-sections. For instance, one could use this for a wing profile, or a sphere, or thread.
The cross-sections don't have to planar, nor do they have to have the same number of points, but self-intersection of the resulting tube is likely to be a problem.
There is some optimization done to make triangles in the meshes be closer to equilateral.
One of the cool things one can do with this is "morph" between two plane shapes. For instance,
morphExtrude(ngonPoints(30,d=6), ngonPoints(2,d=4), height=10);
produces a wedge whose bottom is a circle of radius 3, and whose top is a line of length 4, while
morphExtrude([ [0,0], [20,0], [20,10], [0,10] ], [ [ 5,10 ] ], height=20 );
makes a pyramid with a rectangular base.
The main low-level API is the module
tubeMesh(sections,startCap=true,endCap=true,optimize=1)
which takes a vector of three-dimensional counterclockwise cross-sections, and generates a polyhedron. The optimize parameter controls triangle optimization. For smooth twisty things, you might want to increase it to 4 or 5, but for less smooth things, it might screw things up. If you are having problems, set it to 0 or 1.
There is also the higher-level module
morphExtrude(section1,section2=undef,height=undef,numSlices=10,startCap=true,endCap=true,optimize=1,twist=0,curve="t")
This has two modes of operation. If height is undefined, you feed it two three-dimensional sections (if you omit section2, it is the same as section1), and it interpolates between them to generate numSlices layers. If height is defined, you feed it two two-dimensional sections, and interpolation between the two sections separated by the specified height is generated. The twist is mainly for fun.
If you specify the curve parameter, and height is defined, then the interpolation parameter, which normally linearly changes from 0 to 1 with the z coordinate, is transformed according to the function specified by curve. For instance, the pointy pyramid in the demo is done with:
morphExtrude([ [0,0], [20,0], [20,10], [0,10] ], [ [ 10,5 ] ], height=20, curve="sin(90*t)" );
You can use most of the standard OpenSCAD functions and operations for specifying the curve. See here for details. If you want to reference some parameters in your formula, you can add a curveParams=[["paramA",valueA],["paramB",valueB],...] argument to morphExtrude().
If you want access to the points and faces behind tubeMesh(), call pointsAndFaces() with the same arguments. This returns a [points,faces] vector. In fact, tubeMesh() is equivalent to calling polyhedron() with the output of pointsAndFaces().
As a demo, there is a cone() module and a mySphere() module. The latter has the same parameters as the built-in sphere() primitive, but it uses a golden-angle spiral to generate a sphere whose triangles are more uniformly sized than those from the built-in module.
There are also some useful utility functions:
ngonPoints(n=4,r=10,d=undef,rotate=0,z=undef): generate the points of a regular n-gon; 2D unless z is specified
starPoints(n=10,r1=5,r2=10,rotate=0,z=undef): generate the points of a star; 2D unless z is specified
roundedSquarePoints(size=[10,10],radius=2,z=undef): generate the points of a rounded square; 2D unless z is specified
sectionZ(section,z): takes a list of 2D points and add a z-coordinate to them all
shiftSection(section,delta): adds delta to every point in the section list.
Updates:July 8, 2020: Updated to latest eval.scad, fixing pow() bug.May 31, 2020: Optional triangulateEnds argument to allow for ends to be properly triangulated. Added triangulation.scad to project.March 13, 2019: Better mesh optimization for smooth twisting things; twist parameter reversed in direction to match linear_extrude()March 11, 2019: Can omit section2 parameter to morphExtrude().January 14, 2019: Works without the eval.scad library if you don't use the curve parameter. There will be some warnings, but they can be ignored.November 18, 2018: Added curve parameter to morphExtrude().November 21, 2017: Added roundedSquarePoints(), sectionZ() and shiftSection().September 17, 2017: Added tubeMesh() module for convenience.

Tags