diff --git a/attachments.scad b/attachments.scad index 14c252b..4be6ffa 100644 --- a/attachments.scad +++ b/attachments.scad @@ -464,7 +464,6 @@ module edge_mask(edges=EDGES_ALL, except=[]) { $attach_anchor = anch; $attach_norot = true; $tags = "mask"; - length = sum(vmul($parent_size, [for (x=vec) x?0:1]))+0.1; rotang = vec.z<0? [90,0,180+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() // Usage: // tags(tags) ... diff --git a/edges.scad b/edges.scad index f6227f0..c434455 100644 --- a/edges.scad +++ b/edges.scad @@ -35,7 +35,6 @@ // } // module corner_cube(size=20, txtsize=3, corners="ALL") { // corner_set = _corner_set(corners); -// echo(corners=corners, corner_set=corner_set); // lbl = is_string(corners)? [str("\"",corners,"\"")] : concat( // corners.z>0? ["TOP"] : corners.z<0? ["BTM"] : [], // 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) ) 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])]) )? 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. // corners([BOTTOM,FRONT], except=BOTTOM+FRONT) function corners(v, except=[]) = - (is_string(v) || is_corner_array(v))? corners([v], except=except) : - (is_string(except) || is_corner_array(except))? corners(v, except=[except]) : + (is_string(v) || is_vector(v) || is_corner_array(v))? 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)])) : - normalize_corners( - normalize_corners(sum([for (x=v) _corner_set(x)])) - - sum([for (x=except) _corner_set(x)]) - ); + let( + a = normalize_corners(sum([for (x=v) _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. diff --git a/version.scad b/version.scad index aa19ebb..72e5530 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,122]; +BOSL_VERSION = [2,0,123]; // Section: BOSL Library Version Functions