mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 00:09:41 +00:00
mutators-> misc, add flip1/flip2 styles to vnf
This commit is contained in:
parent
e36cdc03ce
commit
a036802cea
6 changed files with 251 additions and 245 deletions
|
@ -23,7 +23,7 @@ PrioritizeFiles:
|
||||||
distributors.scad
|
distributors.scad
|
||||||
color.scad
|
color.scad
|
||||||
partitions.scad
|
partitions.scad
|
||||||
mutators.scad
|
miscellaneous.scad
|
||||||
paths.scad
|
paths.scad
|
||||||
regions.scad
|
regions.scad
|
||||||
skin.scad
|
skin.scad
|
||||||
|
|
|
@ -1,159 +1,55 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// LibFile: mutators.scad
|
// LibFile: miscellaneous.scad
|
||||||
// Functions and modules to mutate children in various ways.
|
// Miscellaneous modules that didn't fit in anywhere else, including
|
||||||
|
// bounding box, chain hull, extrusions, and minkowski based
|
||||||
|
// modules.
|
||||||
// Includes:
|
// Includes:
|
||||||
// include <BOSL2/std.scad>
|
// include <BOSL2/std.scad>
|
||||||
// FileGroup: Basic Modeling
|
// FileGroup: Basic Modeling
|
||||||
// FileSummary: Modules and Functions to mutate items.
|
// FileSummary: Extrusion, bounding box, chain hull and minkowski-based transforms.
|
||||||
// FileFootnotes: STD=Included in std.scad
|
// FileFootnotes: STD=Included in std.scad
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
// Section: Extrusion
|
||||||
// Section: Bounding Box
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// Module: bounding_box()
|
// Module: extrude_from_to()
|
||||||
// Synopsis: Creates the smallest bounding box that contains all the children.
|
// Synopsis: Extrudes 2D children between two points in 3D space.
|
||||||
// SynTags: Geom
|
// SynTags: Geom
|
||||||
// Topics: Mutators, Bounds, Bounding Boxes
|
// Topics: Extrusion, Miscellaneous
|
||||||
// See Also: pointlist_bounds()
|
// See Also: path_sweep(), path_extrude2d()
|
||||||
// Usage:
|
// Usage:
|
||||||
// bounding_box([excess],[planar]) CHILDREN;
|
// extrude_from_to(pt1, pt2, [convexity=], [twist=], [scale=], [slices=]) 2D-CHILDREN;
|
||||||
// Description:
|
// Description:
|
||||||
// Returns the smallest axis-aligned square (or cube) shape that contains all the 2D (or 3D)
|
// Extrudes the 2D children linearly between the 3d points pt1 and pt2. The origin of the 2D children are placed on
|
||||||
// children given. The module children() must 3d when planar=false and
|
// pt1 and pt2, and oriented perpendicular to the line between the points.
|
||||||
// 2d when planar=true, or you will get a warning of mixing dimension
|
|
||||||
// or scaling by 0.
|
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// excess = The amount that the bounding box should be larger than needed to bound the children, in each axis.
|
// pt1 = starting point of extrusion.
|
||||||
// planar = If true, creates a 2D bounding rectangle. Is false, creates a 3D bounding cube. Default: false
|
// pt2 = ending point of extrusion.
|
||||||
// Example(3D):
|
// ---
|
||||||
// module shapes() {
|
// convexity = max number of times a line could intersect a wall of the 2D shape being extruded.
|
||||||
// translate([10,8,4]) cube(5);
|
// twist = number of degrees to twist the 2D shape over the entire extrusion length.
|
||||||
// translate([3,0,12]) cube(2);
|
// scale = scale multiplier for end of extrusion compared the start.
|
||||||
|
// slices = Number of slices along the extrusion to break the extrusion into. Useful for refining `twist` extrusions.
|
||||||
|
// Example(FlatSpin,VPD=200,VPT=[0,0,15]):
|
||||||
|
// extrude_from_to([0,0,0], [10,20,30], convexity=4, twist=360, scale=3.0, slices=40) {
|
||||||
|
// xcopies(3) circle(3, $fn=32);
|
||||||
// }
|
// }
|
||||||
// #bounding_box() shapes();
|
module extrude_from_to(pt1, pt2, convexity, twist, scale, slices) {
|
||||||
// shapes();
|
|
||||||
// Example(2D):
|
|
||||||
// module shapes() {
|
|
||||||
// translate([10,8]) square(5);
|
|
||||||
// translate([3,0]) square(2);
|
|
||||||
// }
|
|
||||||
// #bounding_box(planar=true) shapes();
|
|
||||||
// shapes();
|
|
||||||
module bounding_box(excess=0, planar=false) {
|
|
||||||
// a 3d (or 2d when planar=true) approx. of the children projection on X axis
|
|
||||||
module _xProjection() {
|
|
||||||
if (planar) {
|
|
||||||
projection()
|
|
||||||
rotate([90,0,0])
|
|
||||||
linear_extrude(1, center=true)
|
|
||||||
hull()
|
|
||||||
children();
|
|
||||||
} else {
|
|
||||||
xs = excess<.1? 1: excess;
|
|
||||||
linear_extrude(xs, center=true)
|
|
||||||
projection()
|
|
||||||
rotate([90,0,0])
|
|
||||||
linear_extrude(xs, center=true)
|
|
||||||
projection()
|
|
||||||
hull()
|
|
||||||
children();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// a bounding box with an offset of 1 in all axis
|
|
||||||
module _oversize_bbox() {
|
|
||||||
if (planar) {
|
|
||||||
minkowski() {
|
|
||||||
_xProjection() children(); // x axis
|
|
||||||
rotate(-90) _xProjection() rotate(90) children(); // y axis
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
minkowski() {
|
|
||||||
_xProjection() children(); // x axis
|
|
||||||
rotate(-90) _xProjection() rotate(90) children(); // y axis
|
|
||||||
rotate([0,-90,0]) _xProjection() rotate([0,90,0]) children(); // z axis
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// offsets a cube by `excess`
|
|
||||||
module _shrink_cube() {
|
|
||||||
intersection() {
|
|
||||||
translate((1-excess)*[ 1, 1, 1]) children();
|
|
||||||
translate((1-excess)*[-1,-1,-1]) children();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
req_children($children);
|
req_children($children);
|
||||||
attachable(){
|
check =
|
||||||
if(planar) {
|
assert(is_vector(pt1),"First point must be a vector")
|
||||||
offset(excess-1/2) _oversize_bbox() children();
|
assert(is_vector(pt2),"Second point must be a vector");
|
||||||
} else {
|
pt1 = point3d(pt1);
|
||||||
render(convexity=2)
|
pt2 = point3d(pt2);
|
||||||
if (excess>.1) {
|
rtp = xyz_to_spherical(pt2-pt1);
|
||||||
_oversize_bbox() children();
|
attachable()
|
||||||
} else {
|
|
||||||
_shrink_cube() _oversize_bbox() children();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
union();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
// Section: Warp Mutators
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
// Module: chain_hull()
|
|
||||||
// Synopsis: Performs the union of hull operations between consecutive pairs of children.
|
|
||||||
// SynTags: Geom
|
|
||||||
// Topics: Mutators
|
|
||||||
// See Also: hull()
|
|
||||||
// Usage:
|
|
||||||
// chain_hull() CHILDREN;
|
|
||||||
//
|
|
||||||
// Description:
|
|
||||||
// Performs hull operations between consecutive pairs of children,
|
|
||||||
// then unions all of the hull results. This can be a very slow
|
|
||||||
// operation, but it can provide results that are hard to get
|
|
||||||
// otherwise.
|
|
||||||
//
|
|
||||||
// Side Effects:
|
|
||||||
// `$idx` is set to the index value of the first child of each hulling pair, and can be used to modify each child pair individually.
|
|
||||||
// `$primary` is set to true when the child is the first in a chain pair.
|
|
||||||
//
|
|
||||||
// Example:
|
|
||||||
// chain_hull() {
|
|
||||||
// cube(5, center=true);
|
|
||||||
// translate([30, 0, 0]) sphere(d=15);
|
|
||||||
// translate([60, 30, 0]) cylinder(d=10, h=20);
|
|
||||||
// translate([60, 60, 0]) cube([10,1,20], center=false);
|
|
||||||
// }
|
|
||||||
// Example: Using `$idx` and `$primary`
|
|
||||||
// chain_hull() {
|
|
||||||
// zrot( 0) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
|
||||||
// zrot( 45) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
|
||||||
// zrot( 90) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
|
||||||
// zrot(135) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
|
||||||
// zrot(180) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
|
||||||
// }
|
|
||||||
module chain_hull()
|
|
||||||
{
|
{
|
||||||
req_children($children);
|
translate(pt1) {
|
||||||
attachable(){
|
rotate([0, rtp[2], rtp[1]]) {
|
||||||
if ($children == 1) {
|
if (rtp[0] > 0) {
|
||||||
|
linear_extrude(height=rtp[0], convexity=convexity, center=false, slices=slices, twist=twist, scale=scale) {
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
for (i =[1:1:$children-1]) {
|
|
||||||
$idx = i;
|
|
||||||
hull() {
|
|
||||||
let($primary=true) children(i-1);
|
|
||||||
let($primary=false) children(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +61,7 @@ module chain_hull()
|
||||||
// Module: path_extrude2d()
|
// Module: path_extrude2d()
|
||||||
// Synopsis: Extrudes 2D children along a 2D path.
|
// Synopsis: Extrudes 2D children along a 2D path.
|
||||||
// SynTags: Geom
|
// SynTags: Geom
|
||||||
// Topics: Mutators, Extrusion
|
// Topics: Miscellaneous, Extrusion
|
||||||
// See Also: path_sweep(), path_extrude()
|
// See Also: path_sweep(), path_extrude()
|
||||||
// Usage:
|
// Usage:
|
||||||
// path_extrude2d(path, [caps=], [closed=], [s=], [convexity=]) 2D-CHILDREN;
|
// path_extrude2d(path, [caps=], [closed=], [s=], [convexity=]) 2D-CHILDREN;
|
||||||
|
@ -285,10 +181,72 @@ module path_extrude2d(path, caps=false, closed=false, s, convexity=10) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Module: path_extrude()
|
||||||
|
// Synopsis: Extrudes 2D children along a 3D path.
|
||||||
|
// SynTags: Geom
|
||||||
|
// Topics: Paths, Extrusion, Miscellaneous
|
||||||
|
// See Also: path_sweep(), path_extrude2d()
|
||||||
|
// Usage:
|
||||||
|
// path_extrude(path, [convexity], [clipsize]) 2D-CHILDREN;
|
||||||
|
// Description:
|
||||||
|
// Extrudes 2D children along a 3D path. This may be slow and can have problems with twisting.
|
||||||
|
// Arguments:
|
||||||
|
// path = Array of points for the bezier path to extrude along.
|
||||||
|
// convexity = Maximum number of walls a ray can pass through.
|
||||||
|
// clipsize = Increase if artifacts are left. Default: 100
|
||||||
|
// Example(FlatSpin,VPD=600,VPT=[75,16,20]):
|
||||||
|
// path = [ [0, 0, 0], [33, 33, 33], [66, 33, 40], [100, 0, 0], [150,0,0] ];
|
||||||
|
// path_extrude(path) circle(r=10, $fn=6);
|
||||||
|
module path_extrude(path, convexity=10, clipsize=100) {
|
||||||
|
req_children($children);
|
||||||
|
rotmats = cumprod([
|
||||||
|
for (i = idx(path,e=-2)) let(
|
||||||
|
vec1 = i==0? UP : unit(path[i]-path[i-1], UP),
|
||||||
|
vec2 = unit(path[i+1]-path[i], UP)
|
||||||
|
) rot(from=vec1,to=vec2)
|
||||||
|
]);
|
||||||
|
// This adds a rotation midway between each item on the list
|
||||||
|
interp = rot_resample(rotmats,n=2,method="count");
|
||||||
|
epsilon = 0.0001; // Make segments ever so slightly too long so they overlap.
|
||||||
|
ptcount = len(path);
|
||||||
|
attachable(){
|
||||||
|
for (i = [0:1:ptcount-2]) {
|
||||||
|
pt1 = path[i];
|
||||||
|
pt2 = path[i+1];
|
||||||
|
dist = norm(pt2-pt1);
|
||||||
|
T = rotmats[i];
|
||||||
|
difference() {
|
||||||
|
translate(pt1) {
|
||||||
|
multmatrix(T) {
|
||||||
|
down(clipsize/2/2) {
|
||||||
|
if ((dist+clipsize/2) > 0) {
|
||||||
|
linear_extrude(height=dist+clipsize/2, convexity=convexity) {
|
||||||
|
children();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
translate(pt1) {
|
||||||
|
hq = (i > 0)? interp[2*i-1] : T;
|
||||||
|
multmatrix(hq) down(clipsize/2+epsilon) cube(clipsize, center=true);
|
||||||
|
}
|
||||||
|
translate(pt2) {
|
||||||
|
hq = (i < ptcount-2)? interp[2*i+1] : T;
|
||||||
|
multmatrix(hq) up(clipsize/2+epsilon) cube(clipsize, center=true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
union();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Module: cylindrical_extrude()
|
// Module: cylindrical_extrude()
|
||||||
// Synopsis: Extrudes 2D children outwards around a cylinder.
|
// Synopsis: Extrudes 2D children outwards around a cylinder.
|
||||||
// SynTags: Geom
|
// SynTags: Geom
|
||||||
// Topics: Mutators, Extrusion, Rotation
|
// Topics: Miscellaneous, Extrusion, Rotation
|
||||||
// See Also: heightfield(), cylindrical_heightfield(), cyl()
|
// See Also: heightfield(), cylindrical_heightfield(), cyl()
|
||||||
// Usage:
|
// Usage:
|
||||||
// cylindrical_extrude(ir|id=, or|od=, [size=], [convexity=], [spin=], [orient=]) 2D-CHILDREN;
|
// cylindrical_extrude(ir|id=, or|od=, [size=], [convexity=], [spin=], [orient=]) 2D-CHILDREN;
|
||||||
|
@ -352,107 +310,95 @@ module cylindrical_extrude(ir, or, od, id, size=1000, convexity=10, spin=0, orie
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Module: extrude_from_to()
|
|
||||||
// Synopsis: Extrudes 2D children between two points in 3D space.
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// Section: Bounding Box
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Module: bounding_box()
|
||||||
|
// Synopsis: Creates the smallest bounding box that contains all the children.
|
||||||
// SynTags: Geom
|
// SynTags: Geom
|
||||||
// Topics: Extrusion, Mutators
|
// Topics: Miscellaneous, Bounds, Bounding Boxes
|
||||||
// See Also: path_sweep(), path_extrude2d()
|
// See Also: pointlist_bounds()
|
||||||
// Usage:
|
// Usage:
|
||||||
// extrude_from_to(pt1, pt2, [convexity=], [twist=], [scale=], [slices=]) 2D-CHILDREN;
|
// bounding_box([excess],[planar]) CHILDREN;
|
||||||
// Description:
|
// Description:
|
||||||
// Extrudes the 2D children linearly between the 3d points pt1 and pt2. The origin of the 2D children are placed on
|
// Returns the smallest axis-aligned square (or cube) shape that contains all the 2D (or 3D)
|
||||||
// pt1 and pt2, and oriented perpendicular to the line between the points.
|
// children given. The module children() must 3d when planar=false and
|
||||||
|
// 2d when planar=true, or you will get a warning of mixing dimension
|
||||||
|
// or scaling by 0.
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// pt1 = starting point of extrusion.
|
// excess = The amount that the bounding box should be larger than needed to bound the children, in each axis.
|
||||||
// pt2 = ending point of extrusion.
|
// planar = If true, creates a 2D bounding rectangle. Is false, creates a 3D bounding cube. Default: false
|
||||||
// ---
|
// Example(3D):
|
||||||
// convexity = max number of times a line could intersect a wall of the 2D shape being extruded.
|
// module shapes() {
|
||||||
// twist = number of degrees to twist the 2D shape over the entire extrusion length.
|
// translate([10,8,4]) cube(5);
|
||||||
// scale = scale multiplier for end of extrusion compared the start.
|
// translate([3,0,12]) cube(2);
|
||||||
// slices = Number of slices along the extrusion to break the extrusion into. Useful for refining `twist` extrusions.
|
|
||||||
// Example(FlatSpin,VPD=200,VPT=[0,0,15]):
|
|
||||||
// extrude_from_to([0,0,0], [10,20,30], convexity=4, twist=360, scale=3.0, slices=40) {
|
|
||||||
// xcopies(3) circle(3, $fn=32);
|
|
||||||
// }
|
// }
|
||||||
module extrude_from_to(pt1, pt2, convexity, twist, scale, slices) {
|
// #bounding_box() shapes();
|
||||||
req_children($children);
|
// shapes();
|
||||||
check =
|
// Example(2D):
|
||||||
assert(is_vector(pt1),"First point must be a vector")
|
// module shapes() {
|
||||||
assert(is_vector(pt2),"Second point must be a vector");
|
// translate([10,8]) square(5);
|
||||||
pt1 = point3d(pt1);
|
// translate([3,0]) square(2);
|
||||||
pt2 = point3d(pt2);
|
// }
|
||||||
rtp = xyz_to_spherical(pt2-pt1);
|
// #bounding_box(planar=true) shapes();
|
||||||
attachable()
|
// shapes();
|
||||||
{
|
module bounding_box(excess=0, planar=false) {
|
||||||
translate(pt1) {
|
// a 3d (or 2d when planar=true) approx. of the children projection on X axis
|
||||||
rotate([0, rtp[2], rtp[1]]) {
|
module _xProjection() {
|
||||||
if (rtp[0] > 0) {
|
if (planar) {
|
||||||
linear_extrude(height=rtp[0], convexity=convexity, center=false, slices=slices, twist=twist, scale=scale) {
|
projection()
|
||||||
|
rotate([90,0,0])
|
||||||
|
linear_extrude(1, center=true)
|
||||||
|
hull()
|
||||||
|
children();
|
||||||
|
} else {
|
||||||
|
xs = excess<.1? 1: excess;
|
||||||
|
linear_extrude(xs, center=true)
|
||||||
|
projection()
|
||||||
|
rotate([90,0,0])
|
||||||
|
linear_extrude(xs, center=true)
|
||||||
|
projection()
|
||||||
|
hull()
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a bounding box with an offset of 1 in all axis
|
||||||
|
module _oversize_bbox() {
|
||||||
|
if (planar) {
|
||||||
|
minkowski() {
|
||||||
|
_xProjection() children(); // x axis
|
||||||
|
rotate(-90) _xProjection() rotate(90) children(); // y axis
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
minkowski() {
|
||||||
|
_xProjection() children(); // x axis
|
||||||
|
rotate(-90) _xProjection() rotate(90) children(); // y axis
|
||||||
|
rotate([0,-90,0]) _xProjection() rotate([0,90,0]) children(); // z axis
|
||||||
}
|
}
|
||||||
union();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// offsets a cube by `excess`
|
||||||
|
module _shrink_cube() {
|
||||||
|
intersection() {
|
||||||
|
translate((1-excess)*[ 1, 1, 1]) children();
|
||||||
|
translate((1-excess)*[-1,-1,-1]) children();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Module: path_extrude()
|
|
||||||
// Synopsis: Extrudes 2D children along a 3D path.
|
|
||||||
// SynTags: Geom
|
|
||||||
// Topics: Paths, Extrusion, Mutators
|
|
||||||
// See Also: path_sweep(), path_extrude2d()
|
|
||||||
// Usage:
|
|
||||||
// path_extrude(path, [convexity], [clipsize]) 2D-CHILDREN;
|
|
||||||
// Description:
|
|
||||||
// Extrudes 2D children along a 3D path. This may be slow and can have problems with twisting.
|
|
||||||
// Arguments:
|
|
||||||
// path = Array of points for the bezier path to extrude along.
|
|
||||||
// convexity = Maximum number of walls a ray can pass through.
|
|
||||||
// clipsize = Increase if artifacts are left. Default: 100
|
|
||||||
// Example(FlatSpin,VPD=600,VPT=[75,16,20]):
|
|
||||||
// path = [ [0, 0, 0], [33, 33, 33], [66, 33, 40], [100, 0, 0], [150,0,0] ];
|
|
||||||
// path_extrude(path) circle(r=10, $fn=6);
|
|
||||||
module path_extrude(path, convexity=10, clipsize=100) {
|
|
||||||
req_children($children);
|
req_children($children);
|
||||||
rotmats = cumprod([
|
|
||||||
for (i = idx(path,e=-2)) let(
|
|
||||||
vec1 = i==0? UP : unit(path[i]-path[i-1], UP),
|
|
||||||
vec2 = unit(path[i+1]-path[i], UP)
|
|
||||||
) rot(from=vec1,to=vec2)
|
|
||||||
]);
|
|
||||||
// This adds a rotation midway between each item on the list
|
|
||||||
interp = rot_resample(rotmats,n=2,method="count");
|
|
||||||
epsilon = 0.0001; // Make segments ever so slightly too long so they overlap.
|
|
||||||
ptcount = len(path);
|
|
||||||
attachable(){
|
attachable(){
|
||||||
for (i = [0:1:ptcount-2]) {
|
if(planar) {
|
||||||
pt1 = path[i];
|
offset(excess-1/2) _oversize_bbox() children();
|
||||||
pt2 = path[i+1];
|
} else {
|
||||||
dist = norm(pt2-pt1);
|
render(convexity=2)
|
||||||
T = rotmats[i];
|
if (excess>.1) {
|
||||||
difference() {
|
_oversize_bbox() children();
|
||||||
translate(pt1) {
|
} else {
|
||||||
multmatrix(T) {
|
_shrink_cube() _oversize_bbox() children();
|
||||||
down(clipsize/2/2) {
|
|
||||||
if ((dist+clipsize/2) > 0) {
|
|
||||||
linear_extrude(height=dist+clipsize/2, convexity=convexity) {
|
|
||||||
children();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
translate(pt1) {
|
|
||||||
hq = (i > 0)? interp[2*i-1] : T;
|
|
||||||
multmatrix(hq) down(clipsize/2+epsilon) cube(clipsize, center=true);
|
|
||||||
}
|
|
||||||
translate(pt2) {
|
|
||||||
hq = (i < ptcount-2)? interp[2*i+1] : T;
|
|
||||||
multmatrix(hq) up(clipsize/2+epsilon) cube(clipsize, center=true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
union();
|
union();
|
||||||
|
@ -460,16 +406,74 @@ module path_extrude(path, convexity=10, clipsize=100) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// Section: Hull Based Modules
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
// Module: chain_hull()
|
||||||
|
// Synopsis: Performs the union of hull operations between consecutive pairs of children.
|
||||||
|
// SynTags: Geom
|
||||||
|
// Topics: Miscellaneous
|
||||||
|
// See Also: hull()
|
||||||
|
// Usage:
|
||||||
|
// chain_hull() CHILDREN;
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Performs hull operations between consecutive pairs of children,
|
||||||
|
// then unions all of the hull results. This can be a very slow
|
||||||
|
// operation, but it can provide results that are hard to get
|
||||||
|
// otherwise.
|
||||||
|
//
|
||||||
|
// Side Effects:
|
||||||
|
// `$idx` is set to the index value of the first child of each hulling pair, and can be used to modify each child pair individually.
|
||||||
|
// `$primary` is set to true when the child is the first in a chain pair.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// chain_hull() {
|
||||||
|
// cube(5, center=true);
|
||||||
|
// translate([30, 0, 0]) sphere(d=15);
|
||||||
|
// translate([60, 30, 0]) cylinder(d=10, h=20);
|
||||||
|
// translate([60, 60, 0]) cube([10,1,20], center=false);
|
||||||
|
// }
|
||||||
|
// Example: Using `$idx` and `$primary`
|
||||||
|
// chain_hull() {
|
||||||
|
// zrot( 0) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
||||||
|
// zrot( 45) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
||||||
|
// zrot( 90) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
||||||
|
// zrot(135) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
||||||
|
// zrot(180) right(100) if ($primary) cube(5+3*$idx,center=true); else sphere(r=10+3*$idx);
|
||||||
|
// }
|
||||||
|
module chain_hull()
|
||||||
|
{
|
||||||
|
req_children($children);
|
||||||
|
attachable(){
|
||||||
|
if ($children == 1) {
|
||||||
|
children();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (i =[1:1:$children-1]) {
|
||||||
|
$idx = i;
|
||||||
|
hull() {
|
||||||
|
let($primary=true) children(i-1);
|
||||||
|
let($primary=false) children(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
union();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Section: Offset Mutators
|
// Section: Minkowski and 3D Offset
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Module: minkowski_difference()
|
// Module: minkowski_difference()
|
||||||
// Synopsis: Removes diff shapes from base shape surface.
|
// Synopsis: Removes diff shapes from base shape surface.
|
||||||
// SynTags: Geom
|
// SynTags: Geom
|
||||||
// Topics: Mutators
|
// Topics: Miscellaneous
|
||||||
// See Also: offset3d()
|
// See Also: offset3d()
|
||||||
// Usage:
|
// Usage:
|
||||||
// minkowski_difference() { BASE; DIFF1; DIFF2; ... }
|
// minkowski_difference() { BASE; DIFF1; DIFF2; ... }
|
||||||
|
@ -513,7 +517,7 @@ module minkowski_difference(planar=false) {
|
||||||
// Module: offset3d()
|
// Module: offset3d()
|
||||||
// Synopsis: Expands or contracts the surface of a 3D object.
|
// Synopsis: Expands or contracts the surface of a 3D object.
|
||||||
// SynTags: Geom
|
// SynTags: Geom
|
||||||
// Topics: Mutators
|
// Topics: Miscellaneous
|
||||||
// See Also: minkowski_difference(), round3d()
|
// See Also: minkowski_difference(), round3d()
|
||||||
// Usage:
|
// Usage:
|
||||||
// offset3d(r, [size], [convexity]) CHILDREN;
|
// offset3d(r, [size], [convexity]) CHILDREN;
|
||||||
|
@ -560,7 +564,7 @@ module offset3d(r, size=100, convexity=10) {
|
||||||
// Module: round3d()
|
// Module: round3d()
|
||||||
// Synopsis: Rounds arbitrary 3d objects.
|
// Synopsis: Rounds arbitrary 3d objects.
|
||||||
// SynTags: Geom
|
// SynTags: Geom
|
||||||
// Topics: Rounding, Mutators
|
// Topics: Rounding, Miscellaneous
|
||||||
// See Also: offset3d(), minkowski_difference()
|
// See Also: offset3d(), minkowski_difference()
|
||||||
// Usage:
|
// Usage:
|
||||||
// round3d(r) CHILDREN;
|
// round3d(r) CHILDREN;
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
OUTFILE_BASE="BOSL2_Docs"
|
OUTFILE_BASE="BOSL2_Docs"
|
||||||
FORMATS="html5"
|
FORMATS="html5"
|
||||||
SOURCES="constants.scad.md transforms.scad.md attachments.scad.md shapes2d.scad.md shapes3d.scad.md drawing.scad.md masks2d.scad.md masks3d.scad.md distributors.scad.md color.scad.md partitions.scad.md mutators.scad.md paths.scad.md regions.scad.md skin.scad.md vnf.scad.md beziers.scad.md rounding.scad.md turtle3d.scad.md math.scad.md linalg.scad.md vectors.scad.md coords.scad.md geometry.scad.md trigonometry.scad.md version.scad.md comparisons.scad.md lists.scad.md utility.scad.md strings.scad.md structs.scad.md fnliterals.scad.md threading.scad.md screws.scad.md screw_drive.scad.md bottlecaps.scad.md ball_bearings.scad.md cubetruss.scad.md gears.scad.md hinges.scad.md joiners.scad.md linear_bearings.scad.md modular_hose.scad.md nema_steppers.scad.md polyhedra.scad.md sliders.scad.md tripod_mounts.scad.md walls.scad.md wiring.scad.md Tutorial-*.md Topics.md AlphaIndex.md"
|
SOURCES="constants.scad.md transforms.scad.md attachments.scad.md shapes2d.scad.md shapes3d.scad.md drawing.scad.md masks2d.scad.md masks3d.scad.md distributors.scad.md color.scad.md partitions.scad.md miscellaneous.scad.md paths.scad.md regions.scad.md skin.scad.md vnf.scad.md beziers.scad.md rounding.scad.md turtle3d.scad.md math.scad.md linalg.scad.md vectors.scad.md coords.scad.md geometry.scad.md trigonometry.scad.md version.scad.md comparisons.scad.md lists.scad.md utility.scad.md strings.scad.md structs.scad.md fnliterals.scad.md threading.scad.md screws.scad.md screw_drive.scad.md bottlecaps.scad.md ball_bearings.scad.md cubetruss.scad.md gears.scad.md hinges.scad.md joiners.scad.md linear_bearings.scad.md modular_hose.scad.md nema_steppers.scad.md polyhedra.scad.md sliders.scad.md tripod_mounts.scad.md walls.scad.md wiring.scad.md Tutorial-*.md Topics.md AlphaIndex.md"
|
||||||
PANDOC="/usr/local/Cellar/pandoc/3.1/bin/pandoc"
|
PANDOC="/usr/local/Cellar/pandoc/3.1/bin/pandoc"
|
||||||
TITLE="Documentation for the Belfry OpenSCAD Library v2"
|
TITLE="Documentation for the Belfry OpenSCAD Library v2"
|
||||||
AUTHOR="Garth Minette"
|
AUTHOR="Garth Minette"
|
||||||
|
|
2
std.scad
2
std.scad
|
@ -13,7 +13,7 @@ include <version.scad>
|
||||||
include <constants.scad>
|
include <constants.scad>
|
||||||
include <transforms.scad>
|
include <transforms.scad>
|
||||||
include <distributors.scad>
|
include <distributors.scad>
|
||||||
include <mutators.scad>
|
include <miscellaneous.scad>
|
||||||
include <color.scad>
|
include <color.scad>
|
||||||
include <attachments.scad>
|
include <attachments.scad>
|
||||||
include <shapes3d.scad>
|
include <shapes3d.scad>
|
||||||
|
|
16
vnf.scad
16
vnf.scad
|
@ -35,15 +35,17 @@ EMPTY_VNF = [[],[]]; // The standard empty VNF with no vertices or faces.
|
||||||
// Usage:
|
// Usage:
|
||||||
// vnf = vnf_vertex_array(points, [caps=], [cap1=], [cap2=], [style=], [reverse=], [col_wrap=], [row_wrap=], [triangulate=]);
|
// vnf = vnf_vertex_array(points, [caps=], [cap1=], [cap2=], [style=], [reverse=], [col_wrap=], [row_wrap=], [triangulate=]);
|
||||||
// Description:
|
// Description:
|
||||||
// Creates a VNF structure from a rectangular vertex list, by dividing the vertices into columns and rows,
|
// Creates a VNF structure from a rectangular vertex list, creating edges that connect the adjacent vertices in the vertex list
|
||||||
// adding faces to tile the surface. You can optionally have faces added to wrap the last column
|
// and creating the faces defined by those edges. You can optionally create the edges and faces to wrap the last column
|
||||||
// back to the first column, or wrap the last row to the first. Endcaps can be added to either
|
// back to the first column, or wrap the last row to the first. Endcaps can be added to either
|
||||||
// the first and/or last rows. The style parameter determines how the quadrilaterals are divided into
|
// the first and/or last rows. The style parameter determines how the quadrilaterals are divided into
|
||||||
// triangles. The default style is an arbitrary, systematic subdivision in the same direction. The "alt" style
|
// triangles. The default style is an arbitrary, systematic subdivision in the same direction. The "alt" style
|
||||||
// is the uniform subdivision in the other (alternate) direction. The "min_edge" style picks the shorter edge to
|
// is the uniform subdivision in the other (alternate) direction. The "flip1" style is an arbitrary division which alternates the
|
||||||
|
// direction for any adjacent pair of quadrilaterals. The "flip2" style is the alternating division that is the opposite of "flip1".
|
||||||
|
// The "min_edge" style picks the shorter edge to
|
||||||
// subdivide for each quadrilateral, so the division may not be uniform across the shape. The "quincunx" style
|
// subdivide for each quadrilateral, so the division may not be uniform across the shape. The "quincunx" style
|
||||||
// adds a vertex in the center of each quadrilateral and creates four triangles, and the "convex" and "concave" styles
|
// adds a vertex in the center of each quadrilateral and creates four triangles, and the "convex" and "concave" styles
|
||||||
// chooses the locally convex/concave subdivision. Degenerate faces
|
// choose the locally convex/concave subdivision. The "min_area" option creates the triangulation with the minimal area. Degenerate faces
|
||||||
// are not included in the output, but if this results in unused vertices they will still appear in the output.
|
// are not included in the output, but if this results in unused vertices they will still appear in the output.
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// points = A list of vertices to divide into columns and rows.
|
// points = A list of vertices to divide into columns and rows.
|
||||||
|
@ -54,7 +56,7 @@ EMPTY_VNF = [[],[]]; // The standard empty VNF with no vertices or faces.
|
||||||
// col_wrap = If true, add faces to connect the last column to the first.
|
// col_wrap = If true, add faces to connect the last column to the first.
|
||||||
// row_wrap = If true, add faces to connect the last row to the first.
|
// row_wrap = If true, add faces to connect the last row to the first.
|
||||||
// reverse = If true, reverse all face normals.
|
// reverse = If true, reverse all face normals.
|
||||||
// style = The style of subdividing the quads into faces. Valid options are "default", "alt", "min_edge", "min_area", "quincunx", "convex" and "concave".
|
// style = The style of subdividing the quads into faces. Valid options are "default", "alt", "flip1", "flip2", "min_edge", "min_area", "quincunx", "convex" and "concave".
|
||||||
// triangulate = If true, triangulates endcaps to resolve possible CGAL issues. This can be an expensive operation if the endcaps are complex. Default: false
|
// triangulate = If true, triangulates endcaps to resolve possible CGAL issues. This can be an expensive operation if the endcaps are complex. Default: false
|
||||||
// Example(3D):
|
// Example(3D):
|
||||||
// vnf = vnf_vertex_array(
|
// vnf = vnf_vertex_array(
|
||||||
|
@ -137,7 +139,7 @@ function vnf_vertex_array(
|
||||||
) =
|
) =
|
||||||
assert(!(any([caps,cap1,cap2]) && !col_wrap), "col_wrap must be true if caps are requested")
|
assert(!(any([caps,cap1,cap2]) && !col_wrap), "col_wrap must be true if caps are requested")
|
||||||
assert(!(any([caps,cap1,cap2]) && row_wrap), "Cannot combine caps with row_wrap")
|
assert(!(any([caps,cap1,cap2]) && row_wrap), "Cannot combine caps with row_wrap")
|
||||||
assert(in_list(style,["default","alt","quincunx", "convex","concave", "min_edge","min_area"]))
|
assert(in_list(style,["default","alt","quincunx", "convex","concave", "min_edge","min_area","flip1","flip2"]))
|
||||||
assert(is_matrix(points[0], n=3),"Point array has the wrong shape or points are not 3d")
|
assert(is_matrix(points[0], n=3),"Point array has the wrong shape or points are not 3d")
|
||||||
assert(is_consistent(points), "Non-rectangular or invalid point array")
|
assert(is_consistent(points), "Non-rectangular or invalid point array")
|
||||||
assert(is_bool(triangulate))
|
assert(is_bool(triangulate))
|
||||||
|
@ -179,7 +181,7 @@ function vnf_vertex_array(
|
||||||
style=="quincunx"?
|
style=="quincunx"?
|
||||||
let(i5 = pcnt + r*colcnt + c)
|
let(i5 = pcnt + r*colcnt + c)
|
||||||
[[i1,i5,i2],[i2,i5,i3],[i3,i5,i4],[i4,i5,i1]]
|
[[i1,i5,i2],[i2,i5,i3],[i3,i5,i4],[i4,i5,i1]]
|
||||||
: style=="alt"?
|
: style=="alt" || (style=="flip1" && ((r+c)%2==0)) || (style=="flip2" && ((r+c)%2==1)) || (style=="random" && rands(0,1,1)[0]<.5)?
|
||||||
[[i1,i4,i2],[i2,i4,i3]]
|
[[i1,i4,i2],[i2,i4,i3]]
|
||||||
: style=="min_area"?
|
: style=="min_area"?
|
||||||
let(
|
let(
|
||||||
|
|
Loading…
Reference in a new issue