wobblyhead hg > 3dprints > house_number
view main.scad @ 3:f5ff6f1a5454
better decal handling
| author | ark |
|---|---|
| date | 2026-11-03 13:54 +0100 |
| parents | fe29ace8155e |
| children | 4836a7408849 |
line wrap: on
line source
// House number: glyphs of a text, printed face down, screwed to a wall // with distance washers or held by magnets in the washers. Glyph outlines and hole positions come from // glyphs.scad, written by make_glyphs.py. /* [part selection] */ // part to show or export part = "all"; // [all, body, decal:"decal, two-colour mode", washer, template:"template, export as SVG for make_template.py"] /* [layout] */ // whole text in one print, or one glyph per print layout = "glyph"; // [text, glyph] // glyph to print in the glyph layout, counted from 0, spaces not counted glyph_index = 0; // [0:1:30] // height of the tallest glyph, 0 for the largest that fits size = 0; // [0:.1:500] // rotation on the bed in degrees, -1 for the best angle angle = 0; // [-1:1:90] // bed size bed_size = 300; // [100:1:500] // unusable margin along the bed edges bed_margin = 10; // [0:.5:50] /* [glyph] */ // glyph thickness in layers, decal layers included glyph_layers = 6; // [3:1:60] // backing behind the glyph, covering its outline and connecting separate parts backing = false; // backing thickness in layers backing_layers = 4; // [1:1:20] /* [attachment] */ // screws through the glyph, or magnets in the washers attachment = "screw"; // [screw, magnet] // minimum material around the screw head or magnet, in line widths, for the fit check fit_wall_lines = 2; // [0:1:10] /* [screws] */ // screw diameter screw_d = 4; // [2:.5:8] // countersunk holes, 90 degrees countersink = true; // screw head diameter head_d = 8; // [3:.5:16] /* [magnets] */ // magnet pocket diameter, used as given for the press fit, without clearance magnet_d = 10; // [1:.05:30] // magnet pocket depth, used as given; flush with the washer end when open magnet_h = 3; // [.5:.05:20] // close the pockets with 2 layers, the magnets are inserted during a print pause seal_magnets = false; /* [two-colour] */ // split into body and decal, for a filament change on a single-colour printer two_colour = false; // width of the decal band along the outline, on the face; it narrows by one layer height per layer band_width = 4; // [.5:.1:20] // decal thickness in layers, at most the glyph thickness less 2 layers decal_layers = 2; // [1:1:10] /* [washer] */ // print the washers as part of the body, on the back of the glyph washers_on_body = false; // washer wall around the screw hole or magnet, in line widths washer_wall_lines = 8; // [1:1:40] // washer height, rounded to whole layers; raised to the countersink part or the magnet pocket inside the washer plus 4 layers washer_height = 10; // [0:.5:30] /* [print settings] */ line_width = .4; // [0:.01:1] layer_height = .2; // [0:.01:.5] clearance = .1; // [0:.01:.5] module dummy() {} include <glyphs.scad> epsilon = .001; $fn = $preview ? 60 : 180; lw = line_width; lh = layer_height; // thicknesses glyph_t = glyph_layers * lh; backing_t = backing ? backing_layers * lh : 0; total_t = glyph_t + backing_t; // decal layers, leaving at least 2 layers of body decal_n = max(1, min(decal_layers, glyph_layers - 2)); decal_t = decal_n * lh; // band width of the top decal layer band_top = band_width - (decal_n - 1) * lh; frame_t = lh; // 1 layer magnet = attachment == "magnet"; // screw holes: 90 degree countersink, depth is half the diameter difference hole_d = screw_d + 2 * clearance; cs_d = head_d + 2 * clearance; cs_depth = !magnet && countersink ? (cs_d - hole_d) / 2 : 0; // part of the countersink that reaches beyond the glyph into the washer cs_washer = max(0, cs_depth - total_t); // magnet pockets at the wall end of the washers. A sealed pocket is deepened // to whole layers, so the print pause falls on its top cover_t = seal_magnets ? 2 * lh : 0; // 2 layers over the magnet pocket_h = seal_magnets ? _layers_up(magnet_h) : magnet_h; // washer bore_d = magnet ? magnet_d : hole_d; washer_od = bore_d + 2 * washer_wall_lines * lw; // 4 layers below the countersink or the pocket washer_min = _layers_up((magnet ? pocket_h + cover_t : cs_washer) + 4 * lh); washer_set = round(washer_height / lh) * lh; washer_h = max(washer_set, washer_min); // print height of the top of a sealed pocket, on the body or on the bed pause_z = (washers_on_body ? total_t : 0) + washer_h - cover_t; // magnet pocket for file names: diameter and depth in 1/100 mm, s if sealed magnet_str = str("mg", round(100 * magnet_d), "x", round(100 * magnet_h), seal_magnets ? "s" : ""); // layout and size n_glyphs = len(g_glyphs); sel = layout == "text" ? [for (i = [0 : n_glyphs - 1]) i] : [glyph_index]; usable = bed_size - 2 * bed_margin - 4 * lw; // frame and gap, 1 line width each best_angle = layout == "text" ? g_max_text[1] : g_max_glyph[1]; print_angle = angle < 0 ? best_angle : angle; // glyphs are drawn unrotated in the assembly view ang = part == "all" ? 0 : print_angle; fit_extent = layout == "text" ? _extent([for (g = g_glyphs) for (p = g[4]) [p.x + g[2], p.y]], print_angle) : max([for (g = g_glyphs) _extent(g[4], print_angle)]); max_size = usable / fit_extent * g_size; final_size = size > 0 ? size : max_size; k = final_size / g_size; // scale from the data file to the print // placement: centre the bounding box of the shown glyphs on the origin raw_pts = [for (i = sel) for (p = g_glyphs[i][4]) _tf0([p.x + _off(i), p.y])]; bb = [min([for (p = raw_pts) p.x]), min([for (p = raw_pts) p.y]), max([for (p = raw_pts) p.x]), max([for (p = raw_pts) p.y])]; centre = [(bb[0] + bb[2]) / 2, (bb[1] + bb[3]) / 2]; // holes of the shown glyphs: [position, largest circle radius at the print size] holes = [for (i = sel) for (h = g_glyphs[i][5]) [_tf([h.x + _off(i), h.y]), h[2] * k]]; fit_r_req = (magnet ? magnet_d : head_d) / 2 + fit_wall_lines * lw; assert(glyph_index < n_glyphs, str("glyph_index must be below ", n_glyphs)); assert(part != "decal" || two_colour, "the decal needs two_colour"); echo(str("size: ", final_size, " mm, largest that fits ", max_size, " mm at ", print_angle, " degrees")); echo(str("glyph thickness: ", glyph_t, " mm, with backing ", total_t, " mm")); if (magnet) echo(str("magnet pocket: ", magnet_d, " mm, depth ", pocket_h, " mm", seal_magnets ? str(", sealed by ", cover_t, " mm") : ", open")); else echo(str("hole: ", hole_d, " mm, countersink ", cs_d, " mm, depth ", cs_depth, " mm, of which in the washer ", cs_washer, " mm")); echo(str("washer: ", washer_od, " mm outside, ", washer_h, " mm high, wall ", washer_wall_lines, " line widths")); if (size > max_size + .01) echo(str("WARNING: size ", size, " mm does not fit the bed, largest is ", max_size, " mm")); if (magnet && seal_magnets) echo(str("pause: insert the magnets after the layer ending at ", pause_z, " mm, layer ", round(pause_z / lh), washers_on_body ? " of the body" : " of the washer")); if (magnet && seal_magnets && pocket_h > magnet_h + epsilon) echo(str("WARNING: pocket depth raised to ", pocket_h, " mm, whole layers")); if (two_colour) { echo(str("decal: ", decal_n, " layers, ", decal_t, " mm, band ", band_width, " mm on the face, ", band_top, " mm on the top layer")); if (decal_n < decal_layers) echo(str("WARNING: decal reduced to ", decal_n, " layers, glyph thickness less 2 layers")); if (band_top < lw) echo(str("WARNING: band on the top decal layer is ", band_top, " mm, less than a line width")); } if (washer_set < washer_min) echo(str("WARNING: washer height raised to ", washer_min, " mm")); for (h = holes) if (h[1] < fit_r_req) echo(str("WARNING: hole at ", h[0], ": largest circle radius ", h[1], " mm, ", magnet ? "magnet" : "head", " plus wall needs ", fit_r_req, " mm")); if (washers_on_body) for (h = holes) if (h[1] < washer_od / 2) echo(str("WARNING: washer at ", h[0], " is cut back to the glyph outline")); // Length rounded up to whole layers, ignoring rounding errors. // x: length in mm. function _layers_up(x) = ceil(x / lh - .01) * lh; // Size of the bounding box of points rotated by a degrees, along its longer side. // pts: list of 2D points. a: angle in degrees. function _extent(pts, a) = let (r = [for (p = pts) [p.x * cos(a) - p.y * sin(a), p.x * sin(a) + p.y * cos(a)]]) max(max([for (q = r) q.x]) - min([for (q = r) q.x]), max([for (q = r) q.y]) - min([for (q = r) q.y])); // x offset of glyph i: its place in the text in the text layout, else 0. function _off(i) = layout == "text" ? g_glyphs[i][2] : 0; // Point from the data file to the print, before centring: scaled, rotated, // mirrored for printing face down. function _tf0(p) = let (q = k * p, r = [q.x * cos(ang) - q.y * sin(ang), q.x * sin(ang) + q.y * cos(ang)]) [-r.x, r.y]; // Point from the data file to its place in the print. function _tf(p) = _tf0(p) - centre; // Apply the placement of _tf() to 2D children given in data file coordinates. module _place() { translate(-centre) mirror([1, 0]) rotate(ang) scale(k) children(); } // Outline of glyph i in data file coordinates, at its place in the layout. module _glyph2d(i) { translate([_off(i), 0]) import(g_glyphs[i][1]); } // Backing outline of glyph i in data file coordinates: the outline itself, // grown and shrunk to connect separate parts, or the convex hull. module _backing2d(i) { r = g_glyphs[i][7]; if (r > 0) offset(r = -r) offset(r = r) _glyph2d(i); else if (r < 0) hull() _glyph2d(i); else _glyph2d(i); } // Outline of all shown glyphs, placed for printing. module _placed2d() { for (i = sel) _place() _glyph2d(i); } // Decal band of one layer: the outline minus the outline shrunk by the band // width. The band narrows by one layer height per layer, so its inner edge // slopes away from the body and the nozzle can reach the body's lower layers. // i: decal layer, 0 on the bed. module _band2d(i) { difference() { _placed2d(); offset(r = -(band_width - i * lh)) _placed2d(); } } // Decal layers in print orientation, one slab per layer. // e: downward extension of each slab, for subtracting from the body. module _decal3d(e = 0) { for (i = [0 : decal_n - 1]) translate([0, 0, i * lh - e]) linear_extrude(lh + e) _band2d(i); } // Screw holes and countersinks, opening towards the bed, through washers // printed on the body. Nothing for magnets. module _holes() { if (!magnet) for (h = holes) translate(h[0]) { translate([0, 0, -1]) cylinder(d = hole_d, h = total_t + (washers_on_body ? washer_h : 0) + 2); if (countersink) translate([0, 0, -epsilon]) cylinder(d1 = cs_d + 2 * epsilon, d2 = hole_d, h = cs_depth + epsilon); } } // Magnet pocket below z = 0, the wall end of a washer: open, or closed by // the cover layers. module _pocket() { translate([0, 0, -cover_t - pocket_h]) cylinder(d = magnet_d, h = pocket_h + (seal_magnets ? 0 : 1)); } // Frame of one layer and one line width, one line width around the shown // glyphs. Decal and body both contain it, so the slicer places them alike. module _frame() { linear_extrude(frame_t) difference() { translate([bb[0] - centre.x - 2 * lw, bb[1] - centre.y - 2 * lw]) square([bb[2] - bb[0] + 4 * lw, bb[3] - bb[1] + 4 * lw]); translate([bb[0] - centre.x - lw, bb[1] - centre.y - lw]) square([bb[2] - bb[0] + 2 * lw, bb[3] - bb[1] + 2 * lw]); } } // Outline of the back of the shown glyphs, placed for printing: the backing // if there is one, else the glyph outline. module _back2d() { if (backing) for (i = sel) _place() _backing2d(i); else _placed2d(); } // Glyph body in print orientation, face on the bed. In two-colour mode the // decal is left out of the decal layers. Washers // printed on the body stand on its back, cut back to the outline of the back // so they do not overhang, with the magnet pockets at their top. // frame: include the frame (two-colour mode only). module body(frame = true) { difference() { union() { linear_extrude(glyph_t) _placed2d(); if (backing) translate([0, 0, glyph_t - epsilon]) linear_extrude(backing_t + epsilon) _back2d(); if (washers_on_body) translate([0, 0, total_t - epsilon]) intersection() { for (h = holes) translate(h[0]) cylinder(d = washer_od, h = washer_h + epsilon); linear_extrude(washer_h + epsilon) _back2d(); } } if (washers_on_body && magnet) for (h = holes) translate([h[0].x, h[0].y, total_t + washer_h]) _pocket(); _holes(); if (two_colour) _decal3d(epsilon); } if (two_colour && frame) _frame(); } // Decal in print orientation: the band along the outline, with the frame. // frame: include the frame. module decal(frame = true) { difference() { _decal3d(); _holes(); } if (frame) _frame(); } // Distance washer. For screws it prints with the glyph side up; with // countersinks deeper than the glyph, the cone continues in its top. For // magnets it prints with the wall side up, the pocket in its top. module washer() { difference() { cylinder(d = washer_od, h = washer_h); if (magnet) translate([0, 0, washer_h]) _pocket(); else translate([0, 0, -1]) cylinder(d = hole_d, h = washer_h + 2); if (cs_washer > 0) translate([0, 0, washer_h - cs_washer]) cylinder(d1 = hole_d, d2 = hole_d + 2 * cs_washer + 2 * epsilon, h = cs_washer + epsilon); } } // Drilling template in 2D, as seen on the wall: all glyphs of the text at // their place, a circle of the hole or magnet diameter and a cross at each // hole, a level line along the // baseline and a 100 mm scale bar with 10 mm ticks. Everything is made of // thin strips, so the outlines of the SVG export show each line. module template() { t = .2; // strip width // wall layout: text positions, no rotation, no mirroring function pos(g, p) = k * [p.x + g[2], p.y]; pts = [for (g = g_glyphs) for (p = g[4]) pos(g, p)]; x0 = min([for (p = pts) p.x]); x1 = max([for (p = pts) p.x]); y0 = min([for (p = pts) p.y]); arm = washer_od / 2 + 5; for (g = g_glyphs) { scale(k) translate([g[2], 0]) difference() { import(g[1]); offset(delta = -t / k) import(g[1]); } for (h = g[5]) translate(pos(g, h)) { difference() { circle(d = bore_d); circle(d = bore_d - 2 * t); } square([2 * arm, t], center = true); square([t, 2 * arm], center = true); } } // level line along the baseline translate([x0 - 20, -t / 2]) square([x1 - x0 + 40, t]); // scale bar below the text translate([x0, y0 - 20]) { square([100, t]); for (i = [0 : 10]) translate([10 * i - t / 2, 0]) square([t, i % 5 == 0 ? 6 : 3]); } } // Assembly view: glyphs face up as on the wall, washers behind the holes. module assembly() { rotate([0, 180, 0]) { color("lightgray") body(frame = false); if (two_colour) color("firebrick") decal(frame = false); if (!washers_on_body) color("steelblue") for (h = holes) if (magnet) translate([h[0].x, h[0].y, total_t]) washer(); else translate([h[0].x, h[0].y, total_t + washer_h]) mirror([0, 0, 1]) washer(); } } // Output the selected part. module main() { if (part == "all") assembly(); else if (part == "body") body(); else if (part == "decal") decal(); else if (part == "washer") washer(); else if (part == "template") template(); } main(); // Export file name without extension, see the print settings for lw and lh. // prefix: project name with trailing underscore. suffix: appended as is. function paramstring(prefix = "", suffix = "") = str( prefix, part == "all" ? "" : str(part, "_"), part == "template" ? str(g_name, "_s", round(10 * final_size)) : part == "washer" ? magnet ? str(magnet_str, "_w", washer_wall_lines, "h", round(10 * washer_h)) : str(countersink ? "cs_" : "", "d", round(10 * screw_d), "w", washer_wall_lines, "h", round(10 * washer_h), countersink ? str("c", round(10 * cs_washer)) : "") : str(g_name, "_", layout == "glyph" ? str("g", glyph_index, "_") : "", two_colour ? str("2cd", decal_n, "_") : "", backing ? "bk_" : "", magnet ? (washers_on_body ? str(magnet_str, "_") : "mg_") : countersink ? "cs_" : "", washers_on_body ? str("wh", round(10 * washer_h), "_") : "", "s", round(10 * final_size), "a", round(print_angle), "t", glyph_layers), "_lw", round(100 * line_width), "lh", round(100 * layer_height), suffix); echo(paramstring("house_number_"));
