mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-04 03:09:45 +00:00
Added corner_mask()
This commit is contained in:
parent
d765450cc3
commit
a3d9c9bdba
3 changed files with 47 additions and 10 deletions
|
@ -464,7 +464,6 @@ module edge_mask(edges=EDGES_ALL, except=[]) {
|
||||||
$attach_anchor = anch;
|
$attach_anchor = anch;
|
||||||
$attach_norot = true;
|
$attach_norot = true;
|
||||||
$tags = "mask";
|
$tags = "mask";
|
||||||
length = sum(vmul($parent_size, [for (x=vec) x?0:1]))+0.1;
|
|
||||||
rotang =
|
rotang =
|
||||||
vec.z<0? [90,0,180+vang(point2d(vec))] :
|
vec.z<0? [90,0,180+vang(point2d(vec))] :
|
||||||
vec.z==0 && sign(vec.x)==sign(vec.y)? 135+vang(point2d(vec)) :
|
vec.z==0 && sign(vec.x)==sign(vec.y)? 135+vang(point2d(vec)) :
|
||||||
|
@ -475,6 +474,46 @@ module edge_mask(edges=EDGES_ALL, except=[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Module: corner_mask()
|
||||||
|
// Usage:
|
||||||
|
// corner_mask([corners], [except]) ...
|
||||||
|
// Description:
|
||||||
|
// Takes a 3D mask shape, and attaches it to the given corners, with the appropriate
|
||||||
|
// orientation to be `diff()`ed away. The 3D corner mask shape should be designed to
|
||||||
|
// mask away the X+Y+Z+ octant.
|
||||||
|
// Arguments:
|
||||||
|
// corners = Edges to mask. See the docs for [`corners()`](edges.scad#corners) to see acceptable values. Default: All corners.
|
||||||
|
// except = Edges to explicitly NOT mask. See the docs for [`corners()`](edges.scad#corners) to see acceptable values. Default: No corners.
|
||||||
|
// Side Effects:
|
||||||
|
// Sets `$tags = "mask"` for all children.
|
||||||
|
// Example:
|
||||||
|
// diff("mask")
|
||||||
|
// cube(100, center=true)
|
||||||
|
// corner_mask([TOP,FRONT],LEFT+FRONT+TOP)
|
||||||
|
// difference() {
|
||||||
|
// translate(-0.01*[1,1,1]) cube(20);
|
||||||
|
// translate([20,20,20]) sphere(r=20);
|
||||||
|
// }
|
||||||
|
module corner_mask(corners=CORNERS_ALL, except=[]) {
|
||||||
|
assert($parent_size != undef, "No object to attach to!");
|
||||||
|
corners = corners(corners, except=except);
|
||||||
|
vecs = [for (i = [0:7]) if (corners[i]>0) CORNER_OFFSETS[i]];
|
||||||
|
for (vec = vecs) {
|
||||||
|
vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0);
|
||||||
|
assert(vcount == 3, "Not an edge vector!");
|
||||||
|
anch = find_anchor(vec, $parent_size.z, point2d($parent_size), size2=$parent_size2, shift=$parent_shift, offset=$parent_offset, anchors=$parent_anchors, geometry=$parent_geom, two_d=$parent_2d);
|
||||||
|
$attach_to = undef;
|
||||||
|
$attach_anchor = anch;
|
||||||
|
$attach_norot = true;
|
||||||
|
$tags = "mask";
|
||||||
|
rotang = vec.z<0?
|
||||||
|
[ 0,0,180+vang(point2d(vec))-45] :
|
||||||
|
[180,0,-90+vang(point2d(vec))-45];
|
||||||
|
translate(anch[1]) rot(rotang) children();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Module: tags()
|
// Module: tags()
|
||||||
// Usage:
|
// Usage:
|
||||||
// tags(tags) ...
|
// tags(tags) ...
|
||||||
|
|
14
edges.scad
14
edges.scad
|
@ -35,7 +35,6 @@
|
||||||
// }
|
// }
|
||||||
// module corner_cube(size=20, txtsize=3, corners="ALL") {
|
// module corner_cube(size=20, txtsize=3, corners="ALL") {
|
||||||
// corner_set = _corner_set(corners);
|
// corner_set = _corner_set(corners);
|
||||||
// echo(corners=corners, corner_set=corner_set);
|
|
||||||
// lbl = is_string(corners)? [str("\"",corners,"\"")] : concat(
|
// lbl = is_string(corners)? [str("\"",corners,"\"")] : concat(
|
||||||
// corners.z>0? ["TOP"] : corners.z<0? ["BTM"] : [],
|
// corners.z>0? ["TOP"] : corners.z<0? ["BTM"] : [],
|
||||||
// corners.y>0? ["BACK"] : corners.y<0? ["FWD"] : [],
|
// corners.y>0? ["BACK"] : corners.y<0? ["FWD"] : [],
|
||||||
|
@ -281,7 +280,6 @@ function _corner_set(v) =
|
||||||
str(v, " must be a vector, corner array, or one of ", valid_values)
|
str(v, " must be a vector, corner array, or one of ", valid_values)
|
||||||
) v
|
) v
|
||||||
) :
|
) :
|
||||||
echo("A", v=v, v2=v2, [for (i=[0:2]) !v[i] || (v[i]==v2[i])])
|
|
||||||
all([for (i=[0:2]) !v[i] || (v[i]==v2[i])])
|
all([for (i=[0:2]) !v[i] || (v[i]==v2[i])])
|
||||||
)? 1 : 0
|
)? 1 : 0
|
||||||
];
|
];
|
||||||
|
@ -372,13 +370,13 @@ function _corner_set(v) =
|
||||||
// Example: All corners around the bottom or front faces, except those on the bottom-front edge.
|
// Example: All corners around the bottom or front faces, except those on the bottom-front edge.
|
||||||
// corners([BOTTOM,FRONT], except=BOTTOM+FRONT)
|
// corners([BOTTOM,FRONT], except=BOTTOM+FRONT)
|
||||||
function corners(v, except=[]) =
|
function corners(v, except=[]) =
|
||||||
(is_string(v) || is_corner_array(v))? corners([v], except=except) :
|
(is_string(v) || is_vector(v) || is_corner_array(v))? corners([v], except=except) :
|
||||||
(is_string(except) || is_corner_array(except))? corners(v, except=[except]) :
|
(is_string(except) || is_vector(except) || is_corner_array(except))? corners(v, except=[except]) :
|
||||||
except==[]? normalize_corners(sum([for (x=v) _corner_set(x)])) :
|
except==[]? normalize_corners(sum([for (x=v) _corner_set(x)])) :
|
||||||
normalize_corners(
|
let(
|
||||||
normalize_corners(sum([for (x=v) _corner_set(x)])) -
|
a = normalize_corners(sum([for (x=v) _corner_set(x)])),
|
||||||
sum([for (x=except) _corner_set(x)])
|
b = normalize_corners(sum([for (x=except) _corner_set(x)]))
|
||||||
);
|
) normalize_corners(a - b);
|
||||||
|
|
||||||
|
|
||||||
CORNER_OFFSETS = [ // Array of XYZ offsets to each corner.
|
CORNER_OFFSETS = [ // Array of XYZ offsets to each corner.
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,122];
|
BOSL_VERSION = [2,0,123];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
Loading…
Reference in a new issue