Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Adrian Mariano
2022-11-24 10:38:55 -05:00
4 changed files with 83 additions and 262 deletions

129
skin.scad
View File

@@ -3637,134 +3637,5 @@ module _textured_revolution(
}
/// Function&Module: _textured_cylinder()
/// Usage: As Function
/// vnf = _textured_cylinder(h|l=, r|d=, texture, tex_size|counts=, [tex_scale=], [inset=], [rot=], ...);
/// vnf = _textured_cylinder(h|l=, r1=|d1=, r2=|d2=, texture=, tex_size=|counts=, [tex_scale=], [inset=], [rot=], ...);
/// Usage: As Module
/// _textured_cylinder(h, r|d=, texture, tex_size|counts=, [tex_scale=], [inset=], [rot=], ...) [ATTACHMENTS];
/// _textured_cylinder(h, r1=|d1=, r2=|d2=, texture=, tex_size=|counts=, [tex_scale=], [inset=], [rot=], ...) [ATTACHMENTS];
/// Topics: Sweep, Extrusion, Textures, Knurling
/// Description:
/// Creates a cylinder or cone with optional chamfers or roundings, covered in a textured surface.
/// The texture can be given in one of three ways:
/// - As a texture name string. (See {{texture()}} for supported named textures.)
/// - As a 2D array of evenly spread height values. (AKA a heightfield.)
/// - As a VNF texture tile. A VNF tile exactly defines a surface from `[0,0]` to `[1,1]`, with the Z coordinates
/// being the height of the texture point from the surface. VNF tiles MUST be able to tile in both X and Y
/// directions with no gaps, with the front and back edges aligned exactly, and the left and right edges as well.
/// One script to convert a grayscale image to a texture heightfield array in a .scad file can be found at:
/// https://raw.githubusercontent.com/revarbat/BOSL2/master/scripts/img2scad.py
/// Arguments:
/// h | l = The height of the cylinder.
/// r = The radius of the cylinder.
/// texture = A texture name string, or a rectangular array of scalar height values (0.0 to 1.0), or a VNF tile that defines the texture to apply to the cylinder wall surfaces. See {{texture()}} for what named textures are supported.
/// tex_size = An optional 2D target size for the textures. Actual texture sizes will be scaled somewhat to evenly fit the available surface. Default: `[5,5]`
/// ---
/// r1 = The radius of the bottom of the cylinder.
/// r2 = The radius of the top of the cylinder.
/// d = The diameter of the cylinder.
/// d1 = The diameter of the bottom of the cylinder.
/// d2 = The diameter of the top of the cylinder.
/// tex_scale = Scaling multiplier for the texture depth.
/// inset = If numeric, lowers the texture into the surface by that amount, before the tex_scale multiplier is applied. If `true`, insets by exactly `1`. Default: `false`
/// rot = If true, rotates the texture 90º.
/// caps = (function only) If true, create endcaps for the extruded shape. Default: `true`
/// shift = [X,Y] amount to translate the top, relative to the bottom. Default: [0,0]
/// style = The triangulation style used. See {{vnf_vertex_array()}} for valid styles. Default: `"min_edge"`
/// taper = If given, tapers the texture height to zero over the given percentage of the top and bottom of the cylinder face. Default: `undef` (no taper)
/// counts = If given instead of tex_size, gives the tile repetition counts for textures over the surface length and height.
/// chamfer = If given, chamfers the top and bottom of the cylinder by the given size. If given a negative size, creates a chamfer that juts *outward* from the cylinder.
/// chamfer1 = If given, chamfers the bottom of the cylinder by the given size. If given a negative size, creates a chamfer that juts *outward* from the cylinder.
/// chamfer2 = If given, chamfers the top of the cylinder by the given size. If given a negative size, creates a chamfer that juts *outward* from the cylinder.
/// rounding = If given, rounds the top and bottom of the cylinder to the given radius. If given a negative size, creates a roundover that juts *outward* from the cylinder.
/// rounding1 = If given, rounds the bottom of the cylinder to the given radius. If given a negative size, creates a roundover that juts *outward* from the cylinder.
/// rounding2 = If given, rounds the top of the cylinder to the given radius. If given a negative size, creates a roundover that juts *outward* from the cylinder.
/// samples = Minimum number of "bend points" to have in VNF texture tiles. Default: 8
/// 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`
/// See Also: heightfield(), cylindrical_heightfield(), texture()
function _textured_cylinder(
h, r, texture, tex_size=[1,1], counts,
tex_scale=1, inset=false, rot=false,
caps=true, style="min_edge", taper,
shift=[0,0], l, r1, r2, d, d1, d2,
chamfer, chamfer1, chamfer2,
rounding, rounding1, rounding2,
samples
) =
let(
h = first_defined([h, l, 1]),
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=1),
r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=1),
chamf1 = first_defined([chamfer1, chamfer, 0]),
chamf2 = first_defined([chamfer2, chamfer, 0]),
round1 = first_defined([rounding1, rounding, 0]),
round2 = first_defined([rounding2, rounding, 0]),
needed_h = chamf1 + chamf2 + round1 + round2,
needed_r1 = chamf1 + round1,
needed_r2 = chamf2 + round2,
checks =
assert(needed_h <= h, "Cylinder not tall enough for specified roundings and chamfers.")
assert(needed_r1 <= r1, "Cylinder bottom radius too small for given rounding or chamfer.")
assert(needed_r2 <= r2, "Cylinder top radius too small for given rounding or chamfer.")
,
path = [
if (is_finite(chamf1) && !approx(chamf1,0))
each arc(n=2, r=abs(chamf1), corner=[[(chamf1>0?0:1e6),-h/2],[r1,-h/2],[r2,h/2]])
else if (is_finite(round1) && !approx(round1,0))
each arc(r=abs(round1), corner=[[(round1>0?0:1e6),-h/2],[r1,-h/2],[r2,h/2]])
else [r1,-h/2],
if (is_finite(chamf2) && !approx(chamf2,0))
each arc(n=2, r=abs(chamf2), corner=[[r1,-h/2],[r2,h/2],[(chamf2>0?0:1e6),h/2]])
else if (is_finite(round2) && !approx(round2,0))
each arc(r=abs(round2), corner=[[r1,-h/2],[r2,h/2],[(round2>0?0:1e6),h/2]])
else [r2,h/2],
],
vnf = _textured_revolution(
reverse(path), texture, closed=false,
tex_size=tex_size, counts=counts,
tex_scale=tex_scale, inset=inset, rot=rot,
style=style, shift=shift, taper=taper,
samples=samples
)
) vnf;
module _textured_cylinder(
h, r, texture, tex_size=[1,1],
counts, tex_scale=1, inset=false, rot=false,
style="min_edge", shift=[0,0], taper,
l, r1, r2, d, d1, d2,
chamfer, chamfer1, chamfer2,
rounding, rounding1, rounding2,
convexity=10, samples,
anchor=CENTER, spin=0, orient=UP
) {
h = first_defined([h, l, 1]);
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=1);
r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=1);
chamf1 = first_defined([chamfer1, chamfer]);
chamf2 = first_defined([chamfer2, chamfer]);
round1 = first_defined([rounding1, rounding]);
round2 = first_defined([rounding2, rounding]);
vnf = _textured_cylinder(
texture=texture, h=h, r1=r1, r2=r2,
tex_scale=tex_scale, inset=inset, rot=rot,
counts=counts, tex_size=tex_size,
caps=true, style=style, taper=taper,
shift=shift, samples=samples,
chamfer1=chamf1, chamfer2=chamf2,
rounding1=round1, rounding2=round2
);
attachable(anchor,spin,orient, r1=r1, r2=r2, h=h, shift=shift) {
vnf_polyhedron(vnf, convexity=convexity);
children();
}
}
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap