mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
linear_sweep() fixes.
This commit is contained in:
parent
f87b5b8c2f
commit
f35639629f
1 changed files with 22 additions and 24 deletions
36
skin.scad
36
skin.scad
|
@ -511,10 +511,6 @@ function skin(profiles, slices, refine=1, method="direct", sampling, caps, close
|
||||||
// of the given 2D region or polygon. The benefit of using this, over using `linear_extrude region(rgn)` is
|
// of the given 2D region or polygon. The benefit of using this, over using `linear_extrude region(rgn)` is
|
||||||
// that it supports `anchor`, `spin`, `orient` and attachments. You can also make more refined
|
// that it supports `anchor`, `spin`, `orient` and attachments. You can also make more refined
|
||||||
// twisted extrusions by using `maxseg` to subsample flat faces.
|
// twisted extrusions by using `maxseg` to subsample flat faces.
|
||||||
// Note that the center option centers vertically using the named anchor "zcenter" whereas
|
|
||||||
// `anchor=CENTER` centers the entire shape relative to
|
|
||||||
// the shape's centroid, or other centerpoint you specify. The centerpoint can be "centroid", "mean", "box" or
|
|
||||||
// a custom point location.
|
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// region = The 2D [Region](regions.scad) or polygon that is to be extruded.
|
// region = The 2D [Region](regions.scad) or polygon that is to be extruded.
|
||||||
// h | height = The height to extrude the region. Default: 1
|
// h | height = The height to extrude the region. Default: 1
|
||||||
|
@ -527,7 +523,7 @@ function skin(profiles, slices, refine=1, method="direct", sampling, caps, close
|
||||||
// maxseg = If given, then any long segments of the region will be subdivided to be shorter than this length. This can refine twisting flat faces a lot. Default: `undef` (no subsampling)
|
// maxseg = If given, then any long segments of the region will be subdivided to be shorter than this length. This can refine twisting flat faces a lot. Default: `undef` (no subsampling)
|
||||||
// style = The style to use when triangulating the surface of the object. Valid values are `"default"`, `"alt"`, or `"quincunx"`.
|
// style = The style to use when triangulating the surface of the object. Valid values are `"default"`, `"alt"`, or `"quincunx"`.
|
||||||
// convexity = Max number of surfaces any single ray could pass through. Module use only.
|
// convexity = Max number of surfaces any single ray could pass through. Module use only.
|
||||||
// cp = Centerpoint for determining intersection anchors or centering the shape. Determintes the base of the anchor vector. Can be "centroid", "mean", "box" or a 3D point. Default: "centroid"
|
// cp = Centerpoint for determining intersection anchors or centering the shape. Determines the base of the anchor vector. Can be "centroid", "mean", "box" or a 3D point. Default: `[0,0,0]`
|
||||||
// atype = Set to "hull" or "intersect" to select anchor type. Default: "hull"
|
// atype = Set to "hull" or "intersect" to select anchor type. Default: "hull"
|
||||||
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `"origin"`
|
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `"origin"`
|
||||||
// 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`
|
||||||
|
@ -578,19 +574,20 @@ module linear_sweep(
|
||||||
region, height, center,
|
region, height, center,
|
||||||
twist=0, scale=1, shift=[0,0],
|
twist=0, scale=1, shift=[0,0],
|
||||||
slices, maxseg, style="default", convexity,
|
slices, maxseg, style="default", convexity,
|
||||||
cp="centroid", atype="hull", h,
|
cp=[0,0,0], atype="hull", h,
|
||||||
anchor, spin=0, orient=UP
|
anchor, spin=0, orient=UP
|
||||||
) {
|
) {
|
||||||
h = first_defined([h, height, 1]);
|
h = first_defined([h, height, 1]);
|
||||||
region = force_region(region);
|
region = force_region(region);
|
||||||
dummy=assert(is_region(region),"Input is not a region");
|
check = assert(is_region(region),"Input is not a region");
|
||||||
anchor = get_anchor(anchor, center, BOT, BOT);
|
anchor = get_anchor(anchor, center, BOT, BOT);
|
||||||
vnf = linear_sweep(
|
vnf = linear_sweep(
|
||||||
region, height=h,
|
region, height=h, style=style,
|
||||||
twist=twist, scale=scale, shift=shift,
|
twist=twist, scale=scale, shift=shift,
|
||||||
slices=slices, maxseg=maxseg, style=style
|
slices=slices, maxseg=maxseg,
|
||||||
|
anchor=CTR
|
||||||
);
|
);
|
||||||
cent = centroid(path);
|
cent = centroid(region);
|
||||||
anchors = [
|
anchors = [
|
||||||
named_anchor("centroid_top", point3d(cent, h/2), UP),
|
named_anchor("centroid_top", point3d(cent, h/2), UP),
|
||||||
named_anchor("centroid", point3d(cent), UP),
|
named_anchor("centroid", point3d(cent), UP),
|
||||||
|
@ -610,17 +607,18 @@ function linear_sweep(
|
||||||
region, height, center,
|
region, height, center,
|
||||||
twist=0, scale=1, shift=[0,0],
|
twist=0, scale=1, shift=[0,0],
|
||||||
slices, maxseg, style="default",
|
slices, maxseg, style="default",
|
||||||
cp="centroid", atype="hull", h,
|
cp=[0,0,0], atype="hull", h,
|
||||||
anchor, spin=0, orient=UP
|
anchor, spin=0, orient=UP
|
||||||
) = let(
|
) =
|
||||||
region = force_region(region)
|
let( region = force_region(region) )
|
||||||
)
|
|
||||||
assert(is_region(region), "Input is not a region or polygon.")
|
assert(is_region(region), "Input is not a region or polygon.")
|
||||||
|
assert(is_num(scale) || is_vector(scale))
|
||||||
|
assert(is_vector(shift, 2), str(shift))
|
||||||
let(
|
let(
|
||||||
h = first_defined([h, height, 1]),
|
h = first_defined([h, height, 1]),
|
||||||
anchor = get_anchor(anchor, center, BOT, BOT),
|
anchor = get_anchor(anchor, center, BOT, BOT),
|
||||||
regions = region_parts(region),
|
regions = region_parts(region),
|
||||||
slices = default(slices, ceil(abs(twist)/5)),
|
slices = default(slices, max(1,ceil(abs(twist)/5))),
|
||||||
scale = is_num(scale)? [scale,scale] : point2d(scale),
|
scale = is_num(scale)? [scale,scale] : point2d(scale),
|
||||||
topmat = move(shift) * scale(scale) * rot(-twist),
|
topmat = move(shift) * scale(scale) * rot(-twist),
|
||||||
trgns = [
|
trgns = [
|
||||||
|
@ -649,15 +647,15 @@ function linear_sweep(
|
||||||
u = i / slices,
|
u = i / slices,
|
||||||
scl = lerp([1,1], scale, u),
|
scl = lerp([1,1], scale, u),
|
||||||
ang = lerp(0, -twist, u),
|
ang = lerp(0, -twist, u),
|
||||||
off = lerp([0,0,0], point3d(shift,h), u),
|
off = lerp([0,0,-h/2], point3d(shift,h/2), u),
|
||||||
m = move(off) * scale(scl) * rot(ang)
|
m = move(off) * scale(scl) * rot(ang)
|
||||||
) apply(m, path3d(path))
|
) apply(m, path3d(path))
|
||||||
]
|
]
|
||||||
) vnf_vertex_array(verts, caps=false, col_wrap=true, style=style),
|
) vnf_vertex_array(verts, caps=false, col_wrap=true, style=style),
|
||||||
for (rgn = regions) vnf_from_region(rgn, ident(4), reverse=true),
|
for (rgn = regions) vnf_from_region(rgn, down(h/2), reverse=true),
|
||||||
for (rgn = trgns) vnf_from_region(rgn, up(h), reverse=false)
|
for (rgn = trgns) vnf_from_region(rgn, up(h/2), reverse=false)
|
||||||
]),
|
]),
|
||||||
cent = centroid(path),
|
cent = centroid(region),
|
||||||
anchors = [
|
anchors = [
|
||||||
named_anchor("centroid_top", point3d(cent, h/2), UP),
|
named_anchor("centroid_top", point3d(cent, h/2), UP),
|
||||||
named_anchor("centroid", point3d(cent), UP),
|
named_anchor("centroid", point3d(cent), UP),
|
||||||
|
|
Loading…
Reference in a new issue