Made various masks3d.scad shapes attachable. Added bbox atype to linear_sweep()

This commit is contained in:
Revar Desmera 2022-09-25 20:56:04 -07:00
parent ea7bb49fa7
commit ee248ec74d
2 changed files with 54 additions and 25 deletions

View file

@ -385,6 +385,9 @@ module rounding_angled_corner_mask(r, ang=90, d, anchor=CENTER, spin=0, orient=U
// rounding = Radius of the edge rounding. // rounding = Radius of the edge rounding.
// --- // ---
// d = Diameter of cylinder. // d = Diameter of cylinder.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example: // Example:
// difference() { // difference() {
// cylinder(r=50, h=50, center=false); // cylinder(r=50, h=50, center=false);
@ -402,14 +405,16 @@ module rounding_angled_corner_mask(r, ang=90, d, anchor=CENTER, spin=0, orient=U
// #tag("remove") // #tag("remove")
// rounding_cylinder_mask(d=30, rounding=5); // rounding_cylinder_mask(d=30, rounding=5);
// } // }
function rounding_cylinder_mask(r, rounding, d) = no_function("rounding_cylinder_mask"); function rounding_cylinder_mask(r, rounding, d, anchor, spin, orient) = no_function("rounding_cylinder_mask");
module rounding_cylinder_mask(r, rounding, d) module rounding_cylinder_mask(r, rounding, d, anchor=CENTER, spin=0, orient=UP)
{ {
no_children($children);
r = get_radius(r=r, d=d, dflt=1); r = get_radius(r=r, d=d, dflt=1);
difference() { attachable(anchor,spin,orient, r=r+rounding, l=rounding*2) {
cyl(r=r+rounding, l=rounding*2, anchor=CENTER); difference() {
cyl(r=r, l=rounding*3, rounding=rounding, anchor=TOP); cyl(r=r+rounding, l=rounding*2, anchor=CENTER);
cyl(r=r, l=rounding*3, rounding=rounding, anchor=TOP);
}
children();
} }
} }
@ -428,6 +433,7 @@ module rounding_cylinder_mask(r, rounding, d)
// d = Diameter of hole to rounding. // d = Diameter of hole to rounding.
// rounding = Radius of the rounding. // rounding = Radius of the rounding.
// excess = The extra thickness of the mask. Default: `0.1`. // excess = The extra thickness of the mask. Default: `0.1`.
// ---
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
@ -473,6 +479,10 @@ module rounding_hole_mask(r, rounding, excess=0.1, d, anchor=CENTER, spin=0, ori
// d = Diameter of the mask rounding. // d = Diameter of the mask rounding.
// angle = Maximum angle from vertical. Default: 45 // angle = Maximum angle from vertical. Default: 45
// excess = Excess mask size. Default: 0.1 // excess = Excess mask size. Default: 0.1
// ---
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example(VPD=50,VPR=[55,0,120]): // Example(VPD=50,VPR=[55,0,120]):
// teardrop_edge_mask(l=20, r=10, angle=40); // teardrop_edge_mask(l=20, r=10, angle=40);
// Example(VPD=300,VPR=[75,0,25]): // Example(VPD=300,VPR=[75,0,25]):
@ -483,19 +493,16 @@ module rounding_hole_mask(r, rounding, excess=0.1, d, anchor=CENTER, spin=0, ori
// corner_mask(BOT) // corner_mask(BOT)
// teardrop_corner_mask(r=10, angle=40); // teardrop_corner_mask(r=10, angle=40);
// } // }
function teardrop_edge_mask(l, r, angle, excess=0.1, d) = no_function("teardrop_edge_mask"); function teardrop_edge_mask(l, r, angle, excess=0.1, d, anchor, spin, orient) = no_function("teardrop_edge_mask");
module teardrop_edge_mask(l, r, angle, excess=0.1, d) module teardrop_edge_mask(l, r, angle, excess=0.1, d, anchor=CTR, spin=0, orient=UP)
{ {
no_children($children);
assert(is_num(l)); assert(is_num(l));
assert(is_num(angle)); assert(is_num(angle));
assert(is_num(excess)); assert(is_num(excess));
assert(angle>0 && angle<90); assert(angle>0 && angle<90);
r = get_radius(r=r, d=d, dflt=1); r = get_radius(r=r, d=d, dflt=1);
difference() { path = mask2d_teardrop(r=r, angle=angle, excess=excess);
translate(-[1,1,0]*excess) cube([r+excess,r+excess,l], anchor=FWD+LEFT); linear_sweep(path, height=l, center=true, atype="bbox", anchor=anchor, spin=spin, orient=orient) children();
translate([r,r,0]) teardrop(r=r, l=l+1, cap_h=r, ang=angle, orient=FWD);
}
} }
@ -510,6 +517,9 @@ module teardrop_edge_mask(l, r, angle, excess=0.1, d)
// excess = Excess mask size. Default: 0.1 // excess = Excess mask size. Default: 0.1
// --- // ---
// d = Diameter of the mask rounding. // d = Diameter of the mask rounding.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example: // Example:
// teardrop_corner_mask(r=20, angle=40); // teardrop_corner_mask(r=20, angle=40);
// Example: // Example:
@ -520,17 +530,21 @@ module teardrop_edge_mask(l, r, angle, excess=0.1, d)
// corner_mask(BOT) // corner_mask(BOT)
// teardrop_corner_mask(r=10, angle=40); // teardrop_corner_mask(r=10, angle=40);
// } // }
function teardrop_corner_mask(r, angle, excess=0.1, d) = no_function("teardrop_corner_mask"); function teardrop_corner_mask(r, angle, excess=0.1, d, anchor, spin, orient) = no_function("teardrop_corner_mask");
module teardrop_corner_mask(r, angle, excess=0.1, d) module teardrop_corner_mask(r, angle, excess=0.1, d, anchor=CTR, spin=0, orient=UP)
{ {
no_children($children);
assert(is_num(angle)); assert(is_num(angle));
assert(is_num(excess)); assert(is_num(excess));
assert(angle>0 && angle<90); assert(angle>0 && angle<90);
r = get_radius(r=r, d=d, dflt=1); r = get_radius(r=r, d=d, dflt=1);
difference() { size = (r+excess) * [1,1,1];
translate(-[1,1,1]*excess) cube(r+excess, center=false); midpt = (r-excess)/2 * [1,1,1];
translate([1,1,1]*r) onion(r=r, ang=angle, orient=DOWN); attachable(anchor,spin,orient, size=size, offset=midpt) {
difference() {
translate(-[1,1,1]*excess) cube(r+excess, center=false);
translate([1,1,1]*r) onion(r=r, ang=angle, orient=DOWN);
}
children();
} }
} }

View file

@ -541,6 +541,7 @@ function skin(profiles, slices, refine=1, method="direct", sampling, caps, close
// Anchor Types: // Anchor Types:
// "hull" = Anchors to the virtual convex hull of the shape. // "hull" = Anchors to the virtual convex hull of the shape.
// "intersect" = Anchors to the surface of the shape. // "intersect" = Anchors to the surface of the shape.
// "bbox" = Anchors to the bounding box of the extruded shape.
// Extra Anchors: // Extra Anchors:
// "origin" = Centers the extruded shape vertically only, but keeps the original path positions in the X and Y. Oriented UP. // "origin" = Centers the extruded shape vertically only, but keeps the original path positions in the X and Y. Oriented UP.
// "original_base" = Keeps the original path positions in the X and Y, but at the bottom of the extrusion. Oriented UP. // "original_base" = Keeps the original path positions in the X and Y, but at the bottom of the extrusion. Oriented UP.
@ -662,9 +663,16 @@ module linear_sweep(
named_anchor("original_base", [0,0,-h/2], UP) named_anchor("original_base", [0,0,-h/2], UP)
]; ];
cp = default(cp, "centroid"); cp = default(cp, "centroid");
geom = atype=="hull"? attach_geom(cp=cp, region=region, h=h, extent=true, shift=shift, scale=scale, twist=twist, anchors=anchors) : geom = atype=="hull"? attach_geom(cp=cp, region=region, h=h, extent=true, shift=shift, scale=scale, twist=twist, anchors=anchors) :
atype=="intersect"? attach_geom(cp=cp, region=region, h=h, extent=false, shift=shift, scale=scale, twist=twist, anchors=anchors) : atype=="intersect"? attach_geom(cp=cp, region=region, h=h, extent=false, shift=shift, scale=scale, twist=twist, anchors=anchors) :
assert(in_list(atype, _ANCHOR_TYPES), "Anchor type must be \"hull\" or \"intersect\""); atype=="bbox"?
let(
bounds = pointlist_bounds(flatten(region)),
size = bounds[1] - bounds[0],
midpt = (bounds[0] + bounds[1])/2
)
attach_geom(cp=[0,0,0], size=point3d(size,h), offset=point3d(midpt), shift=shift, scale=scale, twist=twist, anchors=anchors) :
assert(in_list(atype, ["hull","intersect","bbox"]), "Anchor type must be \"hull\", \"intersect\", or \"bbox\".");
attachable(anchor,spin,orient, geom=geom) { attachable(anchor,spin,orient, geom=geom) {
vnf_polyhedron(vnf, convexity=convexity); vnf_polyhedron(vnf, convexity=convexity);
children(); children();
@ -744,9 +752,16 @@ function linear_sweep(
named_anchor("original_base", [0,0,-h/2], UP) named_anchor("original_base", [0,0,-h/2], UP)
], ],
cp = default(cp, "centroid"), cp = default(cp, "centroid"),
geom = atype=="hull"? attach_geom(cp=cp, region=region, h=h, extent=true, shift=shift, scale=scale, twist=twist, anchors=anchors) : geom = atype=="hull"? attach_geom(cp=cp, region=region, h=h, extent=true, shift=shift, scale=scale, twist=twist, anchors=anchors) :
atype=="intersect"? attach_geom(cp=cp, region=region, h=h, extent=false, shift=shift, scale=scale, twist=twist, anchors=anchors) : atype=="intersect"? attach_geom(cp=cp, region=region, h=h, extent=false, shift=shift, scale=scale, twist=twist, anchors=anchors) :
assert(in_list(atype, _ANCHOR_TYPES), "Anchor type must be \"hull\" or \"intersect\"") atype=="bbox"?
let(
bounds = pointlist_bounds(flatten(region)),
size = bounds[1] - bounds[0],
midpt = (bounds[0] + bounds[1])/2
)
attach_geom(cp=[0,0,0], size=point3d(size,h), offset=point3d(midpt), shift=shift, scale=scale, twist=twist, anchors=anchors) :
assert(in_list(atype, ["hull","intersect","bbox"]), "Anchor type must be \"hull\", \"intersect\", or \"bbox\".")
) reorient(anchor,spin,orient, geom=geom, p=vnf); ) reorient(anchor,spin,orient, geom=geom, p=vnf);